private void handleChange(IResourceDelta delta) { if ((delta.getFlags() & IResourceDelta.REPLACED) != 0) { // A replace was added in place of a removed resource handleAdded(delta); } else if (delta.getResource().getType() == IResource.FILE) { ensureResourceCovered(delta.getResource(), changedRoots); } }
private void handleRemoved(IResourceDelta delta) { if ((delta.getFlags() & IResourceDelta.OPEN) != 0) { closedProjects.add(delta.getResource()); } else if ((delta.getFlags() & IResourceDelta.MOVED_TO) != 0) { handleMove(delta); } else { ensureResourceCovered(delta.getResource(), removedRoots); } }
protected boolean checkForClassFileChanges( IResourceDelta binaryDelta, ClasspathMultiDirectory md, int segmentCount) throws CoreException { IResource resource = binaryDelta.getResource(); // remember that if inclusion & exclusion patterns change then a full build is done boolean isExcluded = (md.exclusionPatterns != null || md.inclusionPatterns != null) && Util.isExcluded(resource, md.inclusionPatterns, md.exclusionPatterns); switch (resource.getType()) { case IResource.FOLDER: if (isExcluded && md.inclusionPatterns == null) return true; // no need to go further with this delta since its children cannot be // included IResourceDelta[] children = binaryDelta.getAffectedChildren(); for (int i = 0, l = children.length; i < l; i++) if (!checkForClassFileChanges(children[i], md, segmentCount)) return false; return true; case IResource.FILE: if (!isExcluded && org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(resource.getName())) { // perform full build if a managed class file has been changed IPath typePath = resource.getFullPath().removeFirstSegments(segmentCount).removeFileExtension(); if (this.newState.isKnownType(typePath.toString())) { if (JavaBuilder.DEBUG) System.out.println( "MUST DO FULL BUILD. Found change to class file " + typePath); // $NON-NLS-1$ return false; } return true; } } return true; }
private void handleMove(IResourceDelta delta) { if ((delta.getFlags() & IResourceDelta.MOVED_TO) != 0) { ensureResourceCovered(delta.getResource(), movedRoots); } else if ((delta.getFlags() & IResourceDelta.MOVED_FROM) != 0) { IResource source = createSourceResource(delta); ensureResourceCovered(source, movedRoots); } }
private void handleAdded(IResourceDelta delta) { if ((delta.getFlags() & IResourceDelta.MOVED_FROM) != 0) { handleMove(delta); } else if ((delta.getFlags() & IResourceDelta.COPIED_FROM) != 0) { handleCopy(delta); } else { ensureResourceCovered(delta.getResource(), addedRoots); } }
private IResource createSourceResource(IResourceDelta delta) { IPath sourcePath = delta.getMovedFromPath(); IResource resource = delta.getResource(); IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); switch (resource.getType()) { case IResource.PROJECT: return wsRoot.getProject(sourcePath.segment(0)); case IResource.FOLDER: return wsRoot.getFolder(sourcePath); case IResource.FILE: return wsRoot.getFile(sourcePath); } return null; }
private boolean moveSettingsIfDerivedChanged( IResourceDelta parent, IProject currentProject, Preferences projectPrefs, String[] affectedResources) { boolean resourceChanges = false; if ((parent.getFlags() & IResourceDelta.DERIVED_CHANGED) != 0) { // if derived changed, move encoding to correct preferences IPath parentPath = parent.getResource().getProjectRelativePath(); for (int i = 0; i < affectedResources.length; i++) { IPath affectedPath = new Path(affectedResources[i]); // if parentPath is an ancestor of affectedPath if (parentPath.isPrefixOf(affectedPath)) { IResource member = currentProject.findMember(affectedPath); if (member != null) { Preferences targetPrefs = getPreferences(currentProject, true, member.isDerived(IResource.CHECK_ANCESTORS)); // if new preferences are different than current if (!projectPrefs.absolutePath().equals(targetPrefs.absolutePath())) { // remove encoding from old preferences and save in correct preferences String currentValue = projectPrefs.get(affectedResources[i], null); projectPrefs.remove(affectedResources[i]); targetPrefs.put(affectedResources[i], currentValue); resourceChanges = true; } } } } } IResourceDelta[] children = parent.getAffectedChildren(); for (int i = 0; i < children.length; i++) { resourceChanges = moveSettingsIfDerivedChanged( children[i], currentProject, projectPrefs, affectedResources) || resourceChanges; } return resourceChanges; }
protected boolean findSourceFiles( IResourceDelta sourceDelta, ClasspathMultiDirectory md, int segmentCount) throws CoreException { // When a package becomes a type or vice versa, expect 2 deltas, // one on the folder & one on the source file IResource resource = sourceDelta.getResource(); // remember that if inclusion & exclusion patterns change then a full build is done boolean isExcluded = (md.exclusionPatterns != null || md.inclusionPatterns != null) && Util.isExcluded(resource, md.inclusionPatterns, md.exclusionPatterns); switch (resource.getType()) { case IResource.FOLDER: if (isExcluded && md.inclusionPatterns == null) return true; // no need to go further with this delta since its children cannot be // included switch (sourceDelta.getKind()) { case IResourceDelta.ADDED: if (!isExcluded) { IPath addedPackagePath = resource.getFullPath().removeFirstSegments(segmentCount); createFolder( addedPackagePath, md.binaryFolder); // ensure package exists in the output folder // see if any known source file is from the same package... classpath already includes // new package if (this.sourceLocations.length > 1 && this.newState.isKnownPackage(addedPackagePath.toString())) { if (JavaBuilder.DEBUG) System.out.println( "Skipped dependents of added package " + addedPackagePath); // $NON-NLS-1$ } else { if (JavaBuilder.DEBUG) System.out.println("Found added package " + addedPackagePath); // $NON-NLS-1$ addDependentsOf(addedPackagePath, true); } } // $FALL-THROUGH$ collect all the source files case IResourceDelta.CHANGED: IResourceDelta[] children = sourceDelta.getAffectedChildren(); for (int i = 0, l = children.length; i < l; i++) if (!findSourceFiles(children[i], md, segmentCount)) return false; return true; case IResourceDelta.REMOVED: if (isExcluded) { // since this folder is excluded then there is nothing to delete (from this md), but // must walk any included subfolders children = sourceDelta.getAffectedChildren(); for (int i = 0, l = children.length; i < l; i++) if (!findSourceFiles(children[i], md, segmentCount)) return false; return true; } IPath removedPackagePath = resource.getFullPath().removeFirstSegments(segmentCount); if (this.sourceLocations.length > 1) { for (int i = 0, l = this.sourceLocations.length; i < l; i++) { if (this.sourceLocations[i].sourceFolder.getFolder(removedPackagePath).exists()) { // only a package fragment was removed, same as removing multiple source files createFolder( removedPackagePath, md.binaryFolder); // ensure package exists in the output folder IResourceDelta[] removedChildren = sourceDelta.getAffectedChildren(); for (int j = 0, m = removedChildren.length; j < m; j++) if (!findSourceFiles(removedChildren[j], md, segmentCount)) return false; return true; } } } if ((sourceDelta.getFlags() & IResourceDelta.MOVED_TO) != 0) { // same idea as moving a source file // see bug 163200 IResource movedFolder = this.javaBuilder.workspaceRoot.getFolder(sourceDelta.getMovedToPath()); JavaBuilder.removeProblemsAndTasksFor(movedFolder); } IFolder removedPackageFolder = md.binaryFolder.getFolder(removedPackagePath); if (removedPackageFolder.exists()) removedPackageFolder.delete(IResource.FORCE, null); // add dependents even when the package thinks it does not exist to be on the safe side if (JavaBuilder.DEBUG) System.out.println("Found removed package " + removedPackagePath); // $NON-NLS-1$ addDependentsOf(removedPackagePath, true); this.newState.removePackage(sourceDelta); } return true; case IResource.FILE: if (isExcluded) return true; String resourceName = resource.getName(); // GROOVY start // determine if this is a Groovy project final boolean isInterestingProject = LanguageSupportFactory.isInterestingProject(this.javaBuilder.getProject()); // GROOVY end // GROOVY start /* old { if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(resourceName)) { } new */ // GRECLIPSE-404 must call 'isJavaLikeFile' directly in order to make the Scala-Eclipse // plugin's weaving happy if ((!isInterestingProject && org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(resourceName) && !LanguageSupportFactory.isInterestingSourceFile(resourceName)) || (isInterestingProject && LanguageSupportFactory.isSourceFile(resourceName, isInterestingProject))) { // GROOVY end IPath typePath = resource.getFullPath().removeFirstSegments(segmentCount).removeFileExtension(); String typeLocator = resource.getProjectRelativePath().toString(); switch (sourceDelta.getKind()) { case IResourceDelta.ADDED: if (JavaBuilder.DEBUG) System.out.println("Compile this added source file " + typeLocator); // $NON-NLS-1$ this.sourceFiles.add(new SourceFile((IFile) resource, md, true)); String typeName = typePath.toString(); if (!this.newState.isDuplicateLocator( typeName, typeLocator)) { // adding dependents results in 2 duplicate errors if (JavaBuilder.DEBUG) System.out.println("Found added source file " + typeName); // $NON-NLS-1$ addDependentsOf(typePath, true); } return true; case IResourceDelta.REMOVED: char[][] definedTypeNames = this.newState.getDefinedTypeNamesFor(typeLocator); if (definedTypeNames == null) { // defined a single type matching typePath removeClassFile(typePath, md.binaryFolder); if ((sourceDelta.getFlags() & IResourceDelta.MOVED_TO) != 0) { // remove problems and tasks for a compilation unit that is being moved (to // another package or renamed) // if the target file is a compilation unit, the new cu will be recompiled // if the target file is a non-java resource, then markers are removed // see bug 2857 IResource movedFile = this.javaBuilder.workspaceRoot.getFile(sourceDelta.getMovedToPath()); JavaBuilder.removeProblemsAndTasksFor(movedFile); } } else { if (JavaBuilder.DEBUG) System.out.println( "Found removed source file " + typePath.toString()); // $NON-NLS-1$ addDependentsOf( typePath, true); // add dependents of the source file since it may be involved in a name // collision if (definedTypeNames.length > 0) { // skip it if it failed to successfully define a type IPath packagePath = typePath.removeLastSegments(1); for (int i = 0, l = definedTypeNames.length; i < l; i++) removeClassFile( packagePath.append(new String(definedTypeNames[i])), md.binaryFolder); } } this.newState.removeLocator(typeLocator); return true; case IResourceDelta.CHANGED: if ((sourceDelta.getFlags() & IResourceDelta.CONTENT) == 0 && (sourceDelta.getFlags() & IResourceDelta.ENCODING) == 0) return true; // skip it since it really isn't changed if (JavaBuilder.DEBUG) System.out.println( "Compile this changed source file " + typeLocator); // $NON-NLS-1$ this.sourceFiles.add(new SourceFile((IFile) resource, md, true)); } return true; } else if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(resourceName)) { // perform full build if a managed class file has been changed if (this.makeOutputFolderConsistent) { IPath typePath = resource.getFullPath().removeFirstSegments(segmentCount).removeFileExtension(); if (this.newState.isKnownType(typePath.toString())) { if (JavaBuilder.DEBUG) System.out.println( "MUST DO FULL BUILD. Found change to class file " + typePath); // $NON-NLS-1$ return false; } } return true; } else if (md.hasIndependentOutputFolder) { if (this.javaBuilder.filterExtraResource(resource)) return true; // copy all other resource deltas to the output folder IPath resourcePath = resource.getFullPath().removeFirstSegments(segmentCount); IResource outputFile = md.binaryFolder.getFile(resourcePath); switch (sourceDelta.getKind()) { case IResourceDelta.ADDED: if (outputFile.exists()) { if (JavaBuilder.DEBUG) System.out.println("Deleting existing file " + resourcePath); // $NON-NLS-1$ outputFile.delete(IResource.FORCE, null); } if (JavaBuilder.DEBUG) System.out.println("Copying added file " + resourcePath); // $NON-NLS-1$ createFolder( resourcePath.removeLastSegments(1), md.binaryFolder); // ensure package exists in the output folder copyResource(resource, outputFile); return true; case IResourceDelta.REMOVED: if (outputFile.exists()) { if (JavaBuilder.DEBUG) System.out.println("Deleting removed file " + resourcePath); // $NON-NLS-1$ outputFile.delete(IResource.FORCE, null); } return true; case IResourceDelta.CHANGED: if ((sourceDelta.getFlags() & IResourceDelta.CONTENT) == 0 && (sourceDelta.getFlags() & IResourceDelta.ENCODING) == 0) return true; // skip it since it really isn't changed if (outputFile.exists()) { if (JavaBuilder.DEBUG) System.out.println("Deleting existing file " + resourcePath); // $NON-NLS-1$ outputFile.delete(IResource.FORCE, null); } if (JavaBuilder.DEBUG) System.out.println("Copying changed file " + resourcePath); // $NON-NLS-1$ createFolder( resourcePath.removeLastSegments(1), md.binaryFolder); // ensure package exists in the output folder copyResource(resource, outputFile); } return true; } } return true; }
protected void findAffectedSourceFiles( IResourceDelta binaryDelta, int segmentCount, StringSet structurallyChangedTypes) { // When a package becomes a type or vice versa, expect 2 deltas, // one on the folder & one on the class file IResource resource = binaryDelta.getResource(); switch (resource.getType()) { case IResource.FOLDER: switch (binaryDelta.getKind()) { case IResourceDelta.ADDED: case IResourceDelta.REMOVED: IPath packagePath = resource.getFullPath().removeFirstSegments(segmentCount); String packageName = packagePath.toString(); if (binaryDelta.getKind() == IResourceDelta.ADDED) { // see if any known source file is from the same package... classpath already includes // new package if (!this.newState.isKnownPackage(packageName)) { if (JavaBuilder.DEBUG) System.out.println("Found added package " + packageName); // $NON-NLS-1$ addDependentsOf(packagePath, false); return; } if (JavaBuilder.DEBUG) System.out.println( "Skipped dependents of added package " + packageName); // $NON-NLS-1$ } else { // see if the package still exists on the classpath if (!this.nameEnvironment.isPackage(packageName)) { if (JavaBuilder.DEBUG) System.out.println("Found removed package " + packageName); // $NON-NLS-1$ addDependentsOf(packagePath, false); return; } if (JavaBuilder.DEBUG) System.out.println( "Skipped dependents of removed package " + packageName); // $NON-NLS-1$ } // $FALL-THROUGH$ traverse the sub-packages and .class files case IResourceDelta.CHANGED: IResourceDelta[] children = binaryDelta.getAffectedChildren(); for (int i = 0, l = children.length; i < l; i++) findAffectedSourceFiles(children[i], segmentCount, structurallyChangedTypes); } return; case IResource.FILE: if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(resource.getName())) { IPath typePath = resource.getFullPath().removeFirstSegments(segmentCount).removeFileExtension(); switch (binaryDelta.getKind()) { case IResourceDelta.ADDED: case IResourceDelta.REMOVED: if (JavaBuilder.DEBUG) System.out.println("Found added/removed class file " + typePath); // $NON-NLS-1$ addDependentsOf(typePath, false); return; case IResourceDelta.CHANGED: if ((binaryDelta.getFlags() & IResourceDelta.CONTENT) == 0) return; // skip it since it really isn't changed if (structurallyChangedTypes != null && !structurallyChangedTypes.includes(typePath.toString())) return; // skip since it wasn't a structural change if (JavaBuilder.DEBUG) System.out.println("Found changed class file " + typePath); // $NON-NLS-1$ addDependentsOf(typePath, false); } return; } } }
private void processEntryChanges( IResourceDelta projectDelta, Map<IProject, Boolean> projectsToSave) { // check each resource with user-set encoding to see if it has // been moved/deleted or if derived state has been changed IProject currentProject = (IProject) projectDelta.getResource(); Preferences projectRegularPrefs = getPreferences(currentProject, false, false, true); Preferences projectDerivedPrefs = getPreferences(currentProject, false, true, true); Map<Boolean, String[]> affectedResourcesMap = new HashMap<>(); try { // no regular preferences for this project if (projectRegularPrefs == null) affectedResourcesMap.put(Boolean.FALSE, new String[0]); else affectedResourcesMap.put(Boolean.FALSE, projectRegularPrefs.keys()); // no derived preferences for this project if (projectDerivedPrefs == null) affectedResourcesMap.put(Boolean.TRUE, new String[0]); else affectedResourcesMap.put(Boolean.TRUE, projectDerivedPrefs.keys()); } catch (BackingStoreException e) { // problems with the project scope... we will miss the changes (but will log) String message = Messages.resources_readingEncoding; Policy.log( new ResourceStatus( IResourceStatus.FAILED_GETTING_CHARSET, currentProject.getFullPath(), message, e)); return; } for (Iterator<Boolean> it = affectedResourcesMap.keySet().iterator(); it.hasNext(); ) { Boolean isDerived = it.next(); String[] affectedResources = affectedResourcesMap.get(isDerived); Preferences projectPrefs = isDerived.booleanValue() ? projectDerivedPrefs : projectRegularPrefs; for (int i = 0; i < affectedResources.length; i++) { IResourceDelta memberDelta = projectDelta.findMember(new Path(affectedResources[i])); // no changes for the given resource if (memberDelta == null) continue; if (memberDelta.getKind() == IResourceDelta.REMOVED) { boolean shouldDisableCharsetDeltaJobForCurrentProject = false; // remove the setting for the original location - save its value though String currentValue = projectPrefs.get(affectedResources[i], null); projectPrefs.remove(affectedResources[i]); if ((memberDelta.getFlags() & IResourceDelta.MOVED_TO) != 0) { IPath movedToPath = memberDelta.getMovedToPath(); IResource resource = workspace.getRoot().findMember(movedToPath); if (resource != null) { Preferences encodingSettings = getPreferences( resource.getProject(), true, resource.isDerived(IResource.CHECK_ANCESTORS)); if (currentValue == null || currentValue.trim().length() == 0) encodingSettings.remove(getKeyFor(movedToPath)); else encodingSettings.put(getKeyFor(movedToPath), currentValue); IProject targetProject = workspace.getRoot().getProject(movedToPath.segment(0)); if (targetProject.equals(currentProject)) // if the file was moved inside the same project disable charset listener shouldDisableCharsetDeltaJobForCurrentProject = true; else projectsToSave.put(targetProject, Boolean.FALSE); } } projectsToSave.put( currentProject, Boolean.valueOf(shouldDisableCharsetDeltaJobForCurrentProject)); } } if (moveSettingsIfDerivedChanged( projectDelta, currentProject, projectPrefs, affectedResources)) { // if settings were moved between preferences files disable charset listener so we don't // react to changes made by ourselves projectsToSave.put(currentProject, Boolean.TRUE); } } }