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 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 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 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); } }
@Override public void resourceChanged(IResourceChangeEvent e) { IResourceDelta delta = e.getDelta(); try { if (delta != null && isInstalled) { delta.accept(this); } } catch (CoreException x) { log.warn("Error handling resourceChanged", x); } }
/* * Gathers all the projects that changed in the workspace and sends them * to the conversion method * * (non-Javadoc) * * @see * org.eclipse.core.resources.IResourceChangeListener#resourceChanged * (org.eclipse.core.resources.IResourceChangeEvent) */ public void resourceChanged(IResourceChangeEvent event) { IResourceDelta delta = event.getDelta(); IResourceDelta[] affectedChildren = delta.getAffectedChildren(); IProject[] projects = new IProject[affectedChildren.length]; for (int i = 0; i < affectedChildren.length; i++) { projects[i] = affectedChildren[i].getResource().getProject(); } try { processProjects(projects); } catch (CoreException e) { Logger.logException(e); } }
/** * For any change to the encoding file or any resource with encoding set, just discard the cache * for the corresponding project. */ @Override public void resourceChanged(IResourceChangeEvent event) { IResourceDelta delta = event.getDelta(); if (delta == null) return; IResourceDelta[] projectDeltas = delta.getAffectedChildren(); // process each project in the delta Map<IProject, Boolean> projectsToSave = new HashMap<>(); for (int i = 0; i < projectDeltas.length; i++) // nothing to do if a project has been added/removed/moved if (projectDeltas[i].getKind() == IResourceDelta.CHANGED && (projectDeltas[i].getFlags() & IResourceDelta.OPEN) == 0) processEntryChanges(projectDeltas[i], projectsToSave); job.addChanges(projectsToSave); }
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; }
private boolean hasStructuralDelta() { // handle case when currentProject has only .class file folders and/or jar files... no // source/output folders IResourceDelta delta = getDelta(this.currentProject); if (delta != null && delta.getKind() != IResourceDelta.NO_CHANGE) { ClasspathLocation[] classFoldersAndJars = (ClasspathLocation[]) this.binaryLocationsPerProject.get(this.currentProject); if (classFoldersAndJars != null) { for (int i = 0, l = classFoldersAndJars.length; i < l; i++) { ClasspathLocation classFolderOrJar = classFoldersAndJars[i]; // either a .class file folder or a zip/jar file if (classFolderOrJar != null) { IPath p = classFolderOrJar.getProjectRelativePath(); if (p != null) { IResourceDelta binaryDelta = delta.findMember(p); if (binaryDelta != null && binaryDelta.getKind() != IResourceDelta.NO_CHANGE) return true; } } } } } return false; }
/** * Record the change and return whether any child changes should be visited. * * @param delta the change * @return whether any child changes should be visited */ public boolean recordChange(IResourceDelta delta) { switch (delta.getKind()) { case IResourceDelta.ADDED: handleAdded(delta); return true; // Need to traverse children to look for moves or other changes under added // roots case IResourceDelta.REMOVED: handleRemoved(delta); // No need to look for further changes under a remove (such as moves). // Changes will be discovered in corresponding destination delta return false; case IResourceDelta.CHANGED: handleChange(delta); return true; } return true; }
/* (non-Javadoc) * @see org.eclipse.core.resources.mapping.ModelProvider#validateChange(org.eclipse.core.resources.IResourceDelta, org.eclipse.core.runtime.IProgressMonitor) */ public IStatus validateChange(IResourceDelta rootDelta, IProgressMonitor monitor) { if (!enabled) return new ModelStatus( IStatus.OK, ResourcesPlugin.PI_RESOURCES, ID, Status.OK_STATUS.getMessage()); final ChangeDescription description = new ChangeDescription(); try { rootDelta.accept( new IResourceDeltaVisitor() { public boolean visit(IResourceDelta delta) { return description.recordChange(delta); } }); } catch (CoreException e) { description.addError(e); } return description.asStatus(); }
protected boolean findAffectedSourceFiles( IResourceDelta delta, ClasspathLocation[] classFoldersAndJars, IProject prereqProject) { for (int i = 0, l = classFoldersAndJars.length; i < l; i++) { ClasspathLocation bLocation = classFoldersAndJars[i]; // either a .class file folder or a zip/jar file if (bLocation != null) { // skip unchanged output folder IPath p = bLocation.getProjectRelativePath(); if (p != null) { IResourceDelta binaryDelta = delta.findMember(p); if (binaryDelta != null) { if (bLocation instanceof ClasspathJar) { if (JavaBuilder.DEBUG) System.out.println( "ABORTING incremental build... found delta to jar/zip file"); //$NON-NLS-1$ return false; // do full build since jar file was changed (added/removed were caught // as classpath change) } if (binaryDelta.getKind() == IResourceDelta.ADDED || binaryDelta.getKind() == IResourceDelta.REMOVED) { if (JavaBuilder.DEBUG) System.out.println( "ABORTING incremental build... found added/removed binary folder"); //$NON-NLS-1$ return false; // added/removed binary folder should not make it here (classpath // change), but handle anyways } int segmentCount = binaryDelta.getFullPath().segmentCount(); IResourceDelta[] children = binaryDelta.getAffectedChildren(); // .class files from class folder StringSet structurallyChangedTypes = null; if (bLocation.isOutputFolder()) structurallyChangedTypes = this.newState.getStructurallyChangedTypes( this.javaBuilder.getLastState(prereqProject)); for (int j = 0, m = children.length; j < m; j++) findAffectedSourceFiles(children[j], segmentCount, structurallyChangedTypes); this.notifier.checkCancel(); } } } } 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); } } }
@Override public boolean visit(IResourceDelta delta) throws CoreException { if (delta == null) { return false; } IFile file = getFile(); if (file == null) { return false; } delta = delta.findMember(file.getFullPath()); if (delta == null) { return false; } Runnable runnable = null; switch (delta.getKind()) { case IResourceDelta.CHANGED: FileInfo info = (FileInfo) getElementInfo(fileEditorInput); if (info == null || !canRefreshFromFile(info)) { break; } boolean isSynchronized = computeModificationStamp(file) == info.modificationStamp; if ((IResourceDelta.ENCODING & delta.getFlags()) != 0 && isSynchronized) { runnable = new SafeChange(fileEditorInput) { @Override protected void execute(IEditorInput input) throws Exception { handleElementContentChanged(input); } }; } if (runnable == null && (IResourceDelta.CONTENT & delta.getFlags()) != 0 && !isSynchronized) { runnable = new SafeChange(fileEditorInput) { @Override protected void execute(IEditorInput input) throws Exception { handleElementContentChanged(input); } }; } break; case IResourceDelta.REMOVED: if ((IResourceDelta.MOVED_TO & delta.getFlags()) != 0) { final IPath path = delta.getMovedToPath(); runnable = new SafeChange(fileEditorInput) { @Override protected void execute(IEditorInput input) throws Exception { handleElementMoved(input, path); } }; } else { info = (FileInfo) getElementInfo(fileEditorInput); if (info != null && canRefreshFromFile(info)) { runnable = new SafeChange(fileEditorInput) { @Override protected void execute(IEditorInput input) throws Exception { handleElementDeleted(input); } }; } } break; } if (runnable != null) { update(runnable); } return false; }
private void handleCopy(IResourceDelta delta) { if ((delta.getFlags() & IResourceDelta.COPIED_FROM) != 0) { IResource source = createSourceResource(delta); ensureResourceCovered(source, copiedRoots); } }
protected boolean findSourceFiles(IResourceDelta delta) throws CoreException { ArrayList visited = this.makeOutputFolderConsistent ? new ArrayList(this.sourceLocations.length) : null; for (int i = 0, l = this.sourceLocations.length; i < l; i++) { ClasspathMultiDirectory md = this.sourceLocations[i]; if (this.makeOutputFolderConsistent && md.hasIndependentOutputFolder && !visited.contains(md.binaryFolder)) { // even a project which acts as its own source folder can have an independent/nested output // folder visited.add(md.binaryFolder); IResourceDelta binaryDelta = delta.findMember(md.binaryFolder.getProjectRelativePath()); if (binaryDelta != null) { int segmentCount = binaryDelta.getFullPath().segmentCount(); IResourceDelta[] children = binaryDelta.getAffectedChildren(); for (int j = 0, m = children.length; j < m; j++) if (!checkForClassFileChanges(children[j], md, segmentCount)) return false; } } if (md.sourceFolder.equals(this.javaBuilder.currentProject)) { // skip nested source & output folders when the project is a source folder int segmentCount = delta.getFullPath().segmentCount(); IResourceDelta[] children = delta.getAffectedChildren(); for (int j = 0, m = children.length; j < m; j++) if (!isExcludedFromProject(children[j].getFullPath())) if (!findSourceFiles(children[j], md, segmentCount)) return false; } else { IResourceDelta sourceDelta = delta.findMember(md.sourceFolder.getProjectRelativePath()); if (sourceDelta != null) { if (sourceDelta.getKind() == IResourceDelta.REMOVED) { if (JavaBuilder.DEBUG) System.out.println( "ABORTING incremental build... found removed source folder"); //$NON-NLS-1$ return false; // removed source folder should not make it here, but handle anyways // (ADDED is supported) } int segmentCount = sourceDelta.getFullPath().segmentCount(); IResourceDelta[] children = sourceDelta.getAffectedChildren(); try { for (int j = 0, m = children.length; j < m; j++) if (!findSourceFiles(children[j], md, segmentCount)) return false; } catch (CoreException e) { // catch the case that a package has been renamed and collides on disk with an // as-yet-to-be-deleted package if (e.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) { if (JavaBuilder.DEBUG) System.out.println( "ABORTING incremental build... found renamed package"); //$NON-NLS-1$ return false; } throw e; // rethrow } } } this.notifier.checkCancel(); } return true; }
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; }
private SimpleLookupTable findDeltas() { this.notifier.subTask( Messages.bind(Messages.build_readingDelta, this.currentProject.getName())); IResourceDelta delta = getDelta(this.currentProject); SimpleLookupTable deltas = new SimpleLookupTable(3); if (delta != null) { if (delta.getKind() != IResourceDelta.NO_CHANGE) { if (DEBUG) System.out.println( "JavaBuilder: Found source delta for: " + this.currentProject.getName()); // $NON-NLS-1$ deltas.put(this.currentProject, delta); } } else { if (DEBUG) System.out.println( "JavaBuilder: Missing delta for: " + this.currentProject.getName()); // $NON-NLS-1$ this.notifier.subTask(""); // $NON-NLS-1$ return null; } Object[] keyTable = this.binaryLocationsPerProject.keyTable; Object[] valueTable = this.binaryLocationsPerProject.valueTable; nextProject: for (int i = 0, l = keyTable.length; i < l; i++) { IProject p = (IProject) keyTable[i]; if (p != null && p != this.currentProject) { State s = getLastState(p); if (!this.lastState.wasStructurallyChanged(p, s)) { // see if we can skip its delta if (s.wasNoopBuild()) continue nextProject; // project has no source folders and can be skipped ClasspathLocation[] classFoldersAndJars = (ClasspathLocation[]) valueTable[i]; boolean canSkip = true; for (int j = 0, m = classFoldersAndJars.length; j < m; j++) { if (classFoldersAndJars[j].isOutputFolder()) classFoldersAndJars[j] = null; // can ignore output folder since project was not structurally changed else canSkip = false; } if (canSkip) continue nextProject; // project has no structural changes in its output folders } this.notifier.subTask(Messages.bind(Messages.build_readingDelta, p.getName())); delta = getDelta(p); if (delta != null) { if (delta.getKind() != IResourceDelta.NO_CHANGE) { if (DEBUG) System.out.println( "JavaBuilder: Found binary delta for: " + p.getName()); // $NON-NLS-1$ deltas.put(p, delta); } } else { if (DEBUG) System.out.println("JavaBuilder: Missing delta for: " + p.getName()); // $NON-NLS-1$ this.notifier.subTask(""); // $NON-NLS-1$ return null; } } } this.notifier.subTask(""); // $NON-NLS-1$ return deltas; }