protected void rebuildTypesAffectedBySecondaryTypes() { // to compile types that could not find 'missing' secondary types because of multiple // compile groups, we need to incrementally recompile all affected types as if the missing // secondary types have just been added, see bug 146324 if (this.incrementalBuilder == null) this.incrementalBuilder = new IncrementalImageBuilder(this, this.compilationGroup); int count = this.secondaryTypes.size(); Set<String> qualifiedNames = new HashSet<>(count * 2); Set<String> simpleNames = new HashSet<>(count); Set<String> rootNames = new HashSet<>(3); while (--count >=0) { char[] secondaryTypeName = (char[]) this.secondaryTypes.get(count); IPath path = new Path(null, new String(secondaryTypeName)); this.incrementalBuilder.addDependentsOf(path, false, qualifiedNames, simpleNames, rootNames); } this.incrementalBuilder.addAffectedSourceFiles( qualifiedNames, simpleNames, rootNames, this.typeLocatorsWithUndefinedTypes); }
protected void buildAfterBatchBuild() { // called from a batch builder once all source files have been compiled AND some changes // need to be propagated incrementally (annotations, missing secondary types) if (JavaBuilder.DEBUG) System.out.println("INCREMENTAL build after batch build @ " + new Date(System.currentTimeMillis())); //$NON-NLS-1$ // this is a copy of the incremental build loop try { addAffectedSourceFiles(); while (this.sourceFiles.size() > 0) { this.notifier.checkCancel(); SourceFile[] allSourceFiles = new SourceFile[this.sourceFiles.size()]; this.sourceFiles.toArray(allSourceFiles); resetCollections(); this.notifier.setProgressPerCompilationUnit(0.08f / allSourceFiles.length); this.workQueue.addAll(allSourceFiles); compile(allSourceFiles); removeSecondaryTypes(); addAffectedSourceFiles(); } } catch (CoreException e) { throw internalException(e); } finally { cleanUp(); } }
protected void processAnnotationResults(CompilationParticipantResult[] results) { // to compile the compilation participant results, we need to incrementally recompile all affected types // whenever the generated types are initially added or structurally changed if (this.incrementalBuilder == null) this.incrementalBuilder = new IncrementalImageBuilder(this); this.incrementalBuilder.processAnnotationResults(results); }
protected IncrementalImageBuilder(JavaBuilder javaBuilder, State buildState, CompilationGroup compilationGroup) { super(javaBuilder, true, buildState, compilationGroup); this.nameEnvironment.isIncrementalBuild = true; this.makeOutputFolderConsistent = JavaCore.ENABLED.equals( javaBuilder.javaProject.getOption(JavaCore.CORE_JAVA_BUILD_RECREATE_MODIFIED_CLASS_FILES_IN_OUTPUT_FOLDER, true)); if (compilationGroup == CompilationGroup.MAIN) { final IncrementalImageBuilder builder = new IncrementalImageBuilder(javaBuilder, this.newState, CompilationGroup.TEST); if (builder.sourceLocations.length > 0) { this.testImageBuilder = builder; this.testImageBuilder.resetCollections(); } } }
resetCollections(); System.out.println("COMPILING all source files since the buildpath has errors "); //$NON-NLS-1$ this.javaBuilder.currentProject.deleteMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_ZERO); addAllSourceFiles(this.sourceFiles); this.notifier.updateProgressDelta(0.25f); } else { IResourceDelta sourceDelta = (IResourceDelta) deltas.get(this.javaBuilder.currentProject); if (sourceDelta != null) if (!findSourceFiles(sourceDelta)) return false; this.notifier.updateProgressDelta(0.10f); ClasspathLocation[] classFoldersAndJars = (ClasspathLocation[]) this.javaBuilder.binaryLocationsPerProject.get(p); if (classFoldersAndJars != null) if (!findAffectedSourceFiles(delta, classFoldersAndJars, p)) return false; addAffectedSourceFiles(); this.notifier.updateProgressDelta(0.05f); resetCollections(); compile(allSourceFiles); removeSecondaryTypes(); addAffectedSourceFiles(); return false; } catch (CoreException e) { throw internalException(e); } finally {
if (!isExcluded) { IPath addedPackagePath = resource.getFullPath().removeFirstSegments(segmentCount); createFolder(addedPackagePath, md.binaryFolder); // ensure package exists in the output folder if (JavaBuilder.DEBUG) System.out.println("Found added package " + addedPackagePath); //$NON-NLS-1$ addDependentsOf(addedPackagePath, true); IResourceDelta[] children = sourceDelta.getAffectedChildren(); for (int i = 0, l = children.length; i < l; i++) if (!findSourceFiles(children[i], md, segmentCount)) return false; return true; if (!findSourceFiles(children[i], md, segmentCount)) return false; return true; 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; addDependentsOf(removedPackagePath, true); this.newState.removePackage(sourceDelta); if (JavaBuilder.DEBUG)
public boolean build(SimpleLookupTable deltas) { if(this.sourceLocations.length == 0) { if (this.testImageBuilder != null) { return this.testImageBuilder.build(deltas); } else { return true; resetCollections(); System.out.println("COMPILING all source files since the buildpath has errors "); //$NON-NLS-1$ this.javaBuilder.currentProject.deleteMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_ZERO); addAllSourceFiles(this.sourceFiles); this.notifier.updateProgressDelta(0.25f); } else { IResourceDelta sourceDelta = (IResourceDelta) deltas.get(this.javaBuilder.currentProject); if (sourceDelta != null) { if (!findSourceFiles(sourceDelta)) return this.testImageBuilder != null ? this.testImageBuilder.build(deltas) : false; if(this.testImageBuilder != null) { this.testImageBuilder.findSourceFiles(sourceDelta); ClasspathLocation[] classFoldersAndJars = (ClasspathLocation[]) this.javaBuilder.binaryLocationsPerProject.get(p); if (classFoldersAndJars != null) if (!findAffectedSourceFiles(delta, classFoldersAndJars, p)) return false; addAffectedSourceFiles(); this.notifier.updateProgressDelta(0.05f); if (incrementalBuildLoop() == false) { return false;
if (deletedFile.exists()) continue; // only delete .class files for source files that were actually deleted SourceFile sourceFile = findSourceFile(deletedFile, false); String typeLocator = sourceFile.typeLocator(); int mdSegmentCount = sourceFile.sourceLocation.sourceFolder.getFullPath().segmentCount(); IPath typePath = sourceFile.resource.getFullPath().removeFirstSegments(mdSegmentCount).removeFileExtension(); addDependentsOf(typePath, true); // add dependents of the source file since its now deleted this.previousSourceFiles = null; // existing source files did not see it as deleted since they were compiled before it was char[][] definedTypeNames = this.newState.getDefinedTypeNamesFor(typeLocator); if (definedTypeNames == null) { // defined a single type matching typePath removeClassFile(typePath, sourceFile.sourceLocation.binaryFolder); } else { if (definedTypeNames.length > 0) { // skip it if it failed to successfully define a type IPath packagePath = typePath.removeLastSegments(1); for (int d = 0, l = definedTypeNames.length; d < l; d++) removeClassFile(packagePath.append(new String(definedTypeNames[d])), sourceFile.sourceLocation.binaryFolder);
IResourceDelta[] children = binaryDelta.getAffectedChildren(); for (int j = 0, m = children.length; j < m; j++) if (!checkForClassFileChanges(children[j], md, segmentCount)) return false; 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 { try { for (int j = 0, m = children.length; j < m; j++) if (!findSourceFiles(children[j], md, segmentCount)) return false; } catch (CoreException e) {
private boolean incrementalBuildLoop() throws CoreException { int compileLoop = 0; float increment = 0.40f; while (this.sourceFiles.size() > 0) { // added to in acceptResult if (++compileLoop > MaxCompileLoop) { if (JavaBuilder.DEBUG) System.out.println("ABORTING incremental build... exceeded loop count"); //$NON-NLS-1$ return false; } this.notifier.checkCancel(); SourceFile[] allSourceFiles = new SourceFile[this.sourceFiles.size()]; this.sourceFiles.toArray(allSourceFiles); resetCollections(); this.workQueue.addAll(allSourceFiles); this.notifier.setProgressPerCompilationUnit(increment / allSourceFiles.length); increment = increment / 2; compile(allSourceFiles); removeSecondaryTypes(); addAffectedSourceFiles(); } return true; }
private void buildDeltas(SimpleLookupTable deltas) { this.notifier.checkCancel(); this.notifier.subTask(Messages.bind(Messages.build_preparingBuild, this.currentProject.getName())); if (DEBUG && this.lastState != null) System.out.println("JavaBuilder: Clearing last state : " + this.lastState); //$NON-NLS-1$ clearLastState(); // clear the previously built state so if the build fails, a full build will occur next time IncrementalImageBuilder imageBuilder = new IncrementalImageBuilder(this); if (imageBuilder.build(deltas)) { recordNewState(imageBuilder.newState); } else { if (DEBUG) System.out.println("JavaBuilder: Performing full build since incremental build failed"); //$NON-NLS-1$ buildAll(); } }
if (JavaBuilder.DEBUG) System.out.println("Found added package " + packageName); //$NON-NLS-1$ addDependentsOf(packagePath, false); return; if (JavaBuilder.DEBUG) System.out.println("Found removed package " + packageName); //$NON-NLS-1$ addDependentsOf(packagePath, false); return; IResourceDelta[] children = binaryDelta.getAffectedChildren(); for (int i = 0, l = children.length; i < l; i++) findAffectedSourceFiles(children[i], segmentCount, structurallyChangedTypes); if (JavaBuilder.DEBUG) System.out.println("Found added/removed class file " + typePath); //$NON-NLS-1$ addDependentsOf(typePath, false); return; case IResourceDelta.CHANGED : if (JavaBuilder.DEBUG) System.out.println("Found changed class file " + typePath); //$NON-NLS-1$ addDependentsOf(typePath, false);
if (writeClassFileCheck(file, qualifiedFileName, bytes) || compilationUnit.updateClassFile) { // see 46093 if (JavaBuilder.DEBUG) System.out.println("Writing changed class file " + file.getName());//$NON-NLS-1$ addDependentsOf(new Path(qualifiedFileName), true); // new type if (JavaBuilder.DEBUG) System.out.println("Writing new class file " + file.getName());//$NON-NLS-1$
protected void addDependentsOf(IPath path, boolean isStructuralChange) { addDependentsOf(path, isStructuralChange, this.qualifiedStrings, this.simpleStrings, this.rootStrings); }
protected void addAffectedSourceFiles() { if (this.qualifiedStrings.elementSize == 0 && this.simpleStrings.elementSize == 0) return; addAffectedSourceFiles(this.qualifiedStrings, this.simpleStrings, this.rootStrings, null); }
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; }
rebuildTypesAffectedBySecondaryTypes(); if (this.incrementalBuilder != null) this.incrementalBuilder.buildAfterBatchBuild();
resetCollections(); System.out.println("COMPILING all source files since the buildpath has errors "); //$NON-NLS-1$ this.javaBuilder.currentProject.deleteMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_ZERO); addAllSourceFiles(this.sourceFiles); this.notifier.updateProgressDelta(0.25f); } else { IResourceDelta sourceDelta = (IResourceDelta) deltas.get(this.javaBuilder.currentProject); if (sourceDelta != null) if (!findSourceFiles(sourceDelta)) return false; this.notifier.updateProgressDelta(0.10f); ClasspathLocation[] classFoldersAndJars = (ClasspathLocation[]) this.javaBuilder.binaryLocationsPerProject.get(p); if (classFoldersAndJars != null) if (!findAffectedSourceFiles(delta, classFoldersAndJars, p)) return false; addAffectedSourceFiles(); this.notifier.updateProgressDelta(0.05f); resetCollections(); compile(allSourceFiles); removeSecondaryTypes(); addAffectedSourceFiles(); return false; } catch (CoreException e) { throw internalException(e); } finally {
if (!isExcluded) { IPath addedPackagePath = resource.getFullPath().removeFirstSegments(segmentCount); createFolder(addedPackagePath, md.binaryFolder); // ensure package exists in the output folder if (JavaBuilder.DEBUG) System.out.println("Found added package " + addedPackagePath); //$NON-NLS-1$ addDependentsOf(addedPackagePath, true); IResourceDelta[] children = sourceDelta.getAffectedChildren(); for (int i = 0, l = children.length; i < l; i++) if (!findSourceFiles(children[i], md, segmentCount)) return false; return true; if (!findSourceFiles(children[i], md, segmentCount)) return false; return true; 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; addDependentsOf(removedPackagePath, true); this.newState.removePackage(sourceDelta); if (JavaBuilder.DEBUG)
if (deletedFile.exists()) continue; // only delete .class files for source files that were actually deleted SourceFile sourceFile = findSourceFile(deletedFile, false); String typeLocator = sourceFile.typeLocator(); int mdSegmentCount = sourceFile.sourceLocation.sourceFolder.getFullPath().segmentCount(); IPath typePath = sourceFile.resource.getFullPath().removeFirstSegments(mdSegmentCount).removeFileExtension(); addDependentsOf(typePath, true); // add dependents of the source file since its now deleted this.previousSourceFiles = null; // existing source files did not see it as deleted since they were compiled before it was char[][] definedTypeNames = this.newState.getDefinedTypeNamesFor(typeLocator); if (definedTypeNames == null) { // defined a single type matching typePath removeClassFile(typePath, sourceFile.sourceLocation.binaryFolder); } else { if (definedTypeNames.length > 0) { // skip it if it failed to successfully define a type IPath packagePath = typePath.removeLastSegments(1); for (int d = 0, l = definedTypeNames.length; d < l; d++) removeClassFile(packagePath.append(new String(definedTypeNames[d])), sourceFile.sourceLocation.binaryFolder);