Example usage for org.eclipse.jdt.internal.core.builder JavaBuilder DEBUG

List of usage examples for org.eclipse.jdt.internal.core.builder JavaBuilder DEBUG

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core.builder JavaBuilder DEBUG.

Prototype

boolean DEBUG

To view the source code for org.eclipse.jdt.internal.core.builder JavaBuilder DEBUG.

Click Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.DeltaProcessor.java

License:Open Source License

protected void touchProjects(final IProject[] projectsToTouch, IProgressMonitor progressMonitor)
        throws CoreException {
    for (int i = 0; i < projectsToTouch.length; i++) {
        IProgressMonitor monitor = progressMonitor == null ? null : new SubProgressMonitor(progressMonitor, 1);
        IProject project = projectsToTouch[i];
        // touch to force a build of this project
        if (JavaBuilder.DEBUG)
            System.out.println("Touching project " + project.getName() + " due to external jar file change"); //$NON-NLS-1$ //$NON-NLS-2$
        project.touch(monitor);/*from  w w  w  .ja  va  2s  . c  o  m*/
    }
}

From source file:org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.java

License:Open Source License

protected void compile(SourceFile[] units) {
    if (this.filesWithAnnotations != null && this.filesWithAnnotations.elementSize > 0)
        // will add files that have annotations in acceptResult() & then processAnnotations() before exitting this method
        this.filesWithAnnotations.clear();

    // notify CompilationParticipants which source files are about to be compiled
    CompilationParticipantResult[] participantResults = this.javaBuilder.participants == null ? null
            : notifyParticipants(units);
    if (participantResults != null && participantResults.length > units.length) {
        units = new SourceFile[participantResults.length];
        for (int i = participantResults.length; --i >= 0;)
            units[i] = participantResults[i].sourceFile;
    }// w w  w . j a  v a 2 s .c  o m

    int unitsLength = units.length;
    this.compiledAllAtOnce = unitsLength <= MAX_AT_ONCE;

    // GROOVY start
    // currently can't easily fault in files from the other group.  Easier to
    // do this than fix that right now.
    if (this.compiler != null && this.compiler.options != null && this.compiler.options.buildGroovyFiles == 2) {
        // System.out.println("although more than "+MAX_AT_ONCE+" still compiling "+unitsLength+" files at once");
        this.compiledAllAtOnce = true;
    }
    // GROOVY end
    if (this.compiledAllAtOnce) {
        // do them all now
        if (JavaBuilder.DEBUG)
            for (int i = 0; i < unitsLength; i++)
                System.out.println("About to compile " + units[i].typeLocator()); //$NON-NLS-1$
        compile(units, null, true);
    } else {
        SourceFile[] remainingUnits = new SourceFile[unitsLength]; // copy of units, removing units when about to compile
        System.arraycopy(units, 0, remainingUnits, 0, unitsLength);
        int doNow = unitsLength < MAX_AT_ONCE ? unitsLength : MAX_AT_ONCE;
        SourceFile[] toCompile = new SourceFile[doNow];
        int remainingIndex = 0;
        boolean compilingFirstGroup = true;
        while (remainingIndex < unitsLength) {
            int count = 0;
            while (remainingIndex < unitsLength && count < doNow) {
                // Although it needed compiling when this method was called, it may have
                // already been compiled when it was referenced by another unit.
                SourceFile unit = remainingUnits[remainingIndex];
                if (unit != null && (compilingFirstGroup || this.workQueue.isWaiting(unit))) {
                    if (JavaBuilder.DEBUG)
                        System.out.println("About to compile #" + remainingIndex + " : " + unit.typeLocator()); //$NON-NLS-1$ //$NON-NLS-2$
                    toCompile[count++] = unit;
                }
                remainingUnits[remainingIndex++] = null;
            }
            if (count < doNow)
                System.arraycopy(toCompile, 0, toCompile = new SourceFile[count], 0, count);
            if (!compilingFirstGroup)
                for (int a = remainingIndex; a < unitsLength; a++)
                    if (remainingUnits[a] != null && this.workQueue.isCompiled(remainingUnits[a]))
                        remainingUnits[a] = null; // use the class file for this source file since its been compiled
            compile(toCompile, remainingUnits, compilingFirstGroup);
            compilingFirstGroup = false;
        }
    }

    if (participantResults != null) {
        for (int i = participantResults.length; --i >= 0;)
            if (participantResults[i] != null)
                recordParticipantResult(participantResults[i]);

        processAnnotations(participantResults);
    }
}

From source file:org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.java

License:Open Source License

/**
 * Creates a marker from each problem and adds it to the resource.
 * The marker is as follows://from  w w w. j  a v a  2  s . co m
 *   - its type is T_PROBLEM
 *   - its plugin ID is the JavaBuilder's plugin ID
 *    - its message is the problem's message
 *    - its priority reflects the severity of the problem
 *    - its range is the problem's range
 *    - it has an extra attribute "ID" which holds the problem's id
 *   - it's {@link IMarker#SOURCE_ID} attribute is positioned to {@link JavaBuilder#SOURCE_ID} if
 *     the problem was generated by JDT; else the {@link IMarker#SOURCE_ID} attribute is
 *     carried from the problem to the marker in extra attributes, if present.
 */
protected void storeProblemsFor(SourceFile sourceFile, CategorizedProblem[] problems) throws CoreException {
    if (sourceFile == null || problems == null || problems.length == 0)
        return;
    // once a classpath error is found, ignore all other problems for this project so the user can see the main error
    // but still try to compile as many source files as possible to help the case when the base libraries are in source
    if (!this.keepStoringProblemMarkers)
        return; // only want the one error recorded on this source file

    IResource resource = sourceFile.resource;
    HashSet managedMarkerTypes = JavaModelManager.getJavaModelManager().compilationParticipants
            .managedMarkerTypes();
    for (int i = 0, l = problems.length; i < l; i++) {
        CategorizedProblem problem = problems[i];
        int id = problem.getID();

        // handle missing classfile situation
        if (id == IProblem.IsClassPathCorrect) {
            String missingClassfileName = problem.getArguments()[0];
            if (JavaBuilder.DEBUG)
                System.out.println(Messages.bind(Messages.build_incompleteClassPath, missingClassfileName));
            boolean isInvalidClasspathError = JavaCore.ERROR
                    .equals(this.javaBuilder.javaProject.getOption(JavaCore.CORE_INCOMPLETE_CLASSPATH, true));
            // insert extra classpath problem, and make it the only problem for this project (optional)
            if (isInvalidClasspathError && JavaCore.ABORT.equals(
                    this.javaBuilder.javaProject.getOption(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH, true))) {
                JavaBuilder.removeProblemsAndTasksFor(this.javaBuilder.currentProject); // make this the only problem for this project
                this.keepStoringProblemMarkers = false;
            }
            IMarker marker = this.javaBuilder.currentProject
                    .createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);
            marker.setAttributes(
                    new String[] { IMarker.MESSAGE, IMarker.SEVERITY, IJavaModelMarker.CATEGORY_ID,
                            IMarker.SOURCE_ID },
                    new Object[] { Messages.bind(Messages.build_incompleteClassPath, missingClassfileName),
                            new Integer(isInvalidClasspathError ? IMarker.SEVERITY_ERROR
                                    : IMarker.SEVERITY_WARNING),
                            new Integer(CategorizedProblem.CAT_BUILDPATH), JavaBuilder.SOURCE_ID });
            // even if we're not keeping more markers, still fall through rest of the problem reporting, so that offending
            // IsClassPathCorrect problem gets recorded since it may help locate the offending reference
        }

        String markerType = problem.getMarkerType();
        boolean managedProblem = false;
        if (IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER.equals(markerType)
                || (managedProblem = managedMarkerTypes.contains(markerType))) {
            IMarker marker = resource.createMarker(markerType);

            String[] attributeNames = JAVA_PROBLEM_MARKER_ATTRIBUTE_NAMES;
            int standardLength = attributeNames.length;
            String[] allNames = attributeNames;
            int managedLength = managedProblem ? 0 : 1;
            String[] extraAttributeNames = problem.getExtraMarkerAttributeNames();
            int extraLength = extraAttributeNames == null ? 0 : extraAttributeNames.length;
            if (managedLength > 0 || extraLength > 0) {
                allNames = new String[standardLength + managedLength + extraLength];
                System.arraycopy(attributeNames, 0, allNames, 0, standardLength);
                if (managedLength > 0)
                    allNames[standardLength] = IMarker.SOURCE_ID;
                System.arraycopy(extraAttributeNames, 0, allNames, standardLength + managedLength, extraLength);
            }

            Object[] allValues = new Object[allNames.length];
            // standard attributes
            int index = 0;
            allValues[index++] = problem.getMessage(); // message
            allValues[index++] = problem.isError() ? S_ERROR : S_WARNING; // severity
            allValues[index++] = new Integer(id); // ID
            allValues[index++] = new Integer(problem.getSourceStart()); // start
            int end = problem.getSourceEnd();
            allValues[index++] = new Integer(end > 0 ? end + 1 : end); // end
            allValues[index++] = new Integer(problem.getSourceLineNumber()); // line
            allValues[index++] = Util.getProblemArgumentsForMarker(problem.getArguments()); // arguments
            allValues[index++] = new Integer(problem.getCategoryID()); // category ID
            // SOURCE_ID attribute for JDT problems
            if (managedLength > 0)
                allValues[index++] = JavaBuilder.SOURCE_ID;
            // optional extra attributes
            if (extraLength > 0)
                System.arraycopy(problem.getExtraMarkerAttributeValues(), 0, allValues, index, extraLength);

            marker.setAttributes(allNames, allValues);

            if (!this.keepStoringProblemMarkers)
                return; // only want the one error recorded on this source file
        }
    }
}

From source file:org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.java

License:Open Source License

protected void writeClassFileContents(ClassFile classFile, IFile file, String qualifiedFileName,
        boolean isTopLevelType, SourceFile compilationUnit) throws CoreException {
    //   InputStream input = new SequenceInputStream(
    //         new ByteArrayInputStream(classFile.header, 0, classFile.headerOffset),
    //         new ByteArrayInputStream(classFile.contents, 0, classFile.contentsOffset));
    InputStream input = new ByteArrayInputStream(classFile.getBytes());
    if (file.exists()) {
        // Deal with shared output folders... last one wins... no collision cases detected
        if (JavaBuilder.DEBUG)
            System.out.println("Writing changed class file " + file.getName());//$NON-NLS-1$
        if (!file.isDerived())
            file.setDerived(true, null);
        file.setContents(input, true, false, null);
    } else {/*  w  w  w  .  jav  a2s .c om*/
        // Default implementation just writes out the bytes for the new class file...
        if (JavaBuilder.DEBUG)
            System.out.println("Writing new class file " + file.getName());//$NON-NLS-1$
        file.create(input, IResource.FORCE | IResource.DERIVED, null);
    }
}

From source file:org.eclipse.jdt.internal.core.builder.BatchImageBuilder.java

License:Open Source License

public void build() {
    if (JavaBuilder.DEBUG)
        System.out.println("FULL build"); //$NON-NLS-1$

    try {//www  .j a  va2  s . com
        this.notifier.subTask(
                Messages.bind(Messages.build_cleaningOutput, this.javaBuilder.currentProject.getName()));
        JavaBuilder.removeProblemsAndTasksFor(this.javaBuilder.currentProject);
        cleanOutputFolders(true);
        this.notifier.updateProgressDelta(0.05f);

        this.notifier.subTask(Messages.build_analyzingSources);
        ArrayList sourceFiles = new ArrayList(33);
        addAllSourceFiles(sourceFiles);
        this.notifier.updateProgressDelta(0.10f);

        if (sourceFiles.size() > 0) {
            SourceFile[] allSourceFiles = new SourceFile[sourceFiles.size()];
            sourceFiles.toArray(allSourceFiles);

            this.notifier.setProgressPerCompilationUnit(0.75f / allSourceFiles.length);
            this.workQueue.addAll(allSourceFiles);
            compile(allSourceFiles);

            if (this.typeLocatorsWithUndefinedTypes != null)
                if (this.secondaryTypes != null && !this.secondaryTypes.isEmpty())
                    rebuildTypesAffectedBySecondaryTypes();
            if (this.incrementalBuilder != null)
                this.incrementalBuilder.buildAfterBatchBuild();
        }

        if (this.javaBuilder.javaProject.hasCycleMarker())
            this.javaBuilder.mustPropagateStructuralChanges();
    } catch (CoreException e) {
        throw internalException(e);
    } finally {
        if (JavaBuilder.SHOW_STATS)
            printStats();
        cleanUp();
    }
}

From source file:org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.java

License:Open Source License

public boolean build(SimpleLookupTable deltas) {
    // initialize builder
    // walk this project's deltas, find changed source files
    // walk prereq projects' deltas, find changed class files & add affected source files
    //   use the build state # to skip the deltas for certain prereq projects
    //   ignore changed zip/jar files since they caused a full build
    // compile the source files & acceptResult()
    // compare the produced class files against the existing ones on disk
    // recompile all dependent source files of any type with structural changes or new/removed secondary type
    // keep a loop counter to abort & perform a full build

    if (JavaBuilder.DEBUG)
        System.out.println("INCREMENTAL build"); //$NON-NLS-1$

    try {//  w ww  .  j  av  a 2s .  co  m
        resetCollections();

        this.notifier.subTask(Messages.build_analyzingDeltas);
        if (this.javaBuilder.hasBuildpathErrors()) {
            // if a mssing class file was detected in the last build, a build state was saved since its no longer fatal
            // but we need to rebuild every source file since problems were not recorded
            // AND to avoid the infinite build scenario if this project is involved in a cycle, see bug 160550
            // we need to avoid unnecessary deltas caused by doing a full build in this case
            if (JavaBuilder.DEBUG)
                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);

            Object[] keyTable = deltas.keyTable;
            Object[] valueTable = deltas.valueTable;
            for (int i = 0, l = valueTable.length; i < l; i++) {
                IResourceDelta delta = (IResourceDelta) valueTable[i];
                if (delta != null) {
                    IProject p = (IProject) keyTable[i];
                    ClasspathLocation[] classFoldersAndJars = (ClasspathLocation[]) this.javaBuilder.binaryLocationsPerProject
                            .get(p);
                    if (classFoldersAndJars != null)
                        if (!findAffectedSourceFiles(delta, classFoldersAndJars, p))
                            return false;
                }
            }
            this.notifier.updateProgressDelta(0.10f);

            this.notifier.subTask(Messages.build_analyzingSources);
            addAffectedSourceFiles();
            this.notifier.updateProgressDelta(0.05f);
        }

        this.compileLoop = 0;
        float increment = 0.40f;
        while (this.sourceFiles.size() > 0) { // added to in acceptResult
            if (++this.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();
        }
        if (this.hasStructuralChanges && this.javaBuilder.javaProject.hasCycleMarker())
            this.javaBuilder.mustPropagateStructuralChanges();
    } catch (AbortIncrementalBuildException e) {
        // abort the incremental build and let the batch builder handle the problem
        if (JavaBuilder.DEBUG)
            System.out.println("ABORTING incremental build... problem with " + e.qualifiedTypeName + //$NON-NLS-1$
                    ". Likely renamed inside its existing source file."); //$NON-NLS-1$
        return false;
    } catch (CoreException e) {
        throw internalException(e);
    } finally {
        cleanUp();
    }
    return true;
}

From source file:org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.java

License:Open Source License

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 {/*w w  w.j a  v  a2  s. c o m*/
        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();
    }
}

From source file:org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.java

License:Open Source License

protected void addAffectedSourceFiles(StringSet qualifiedSet, StringSet simpleSet, StringSet rootSet,
        StringSet affectedTypes) {/*w  ww. ja  v  a 2s.c o  m*/
    // the qualifiedStrings are of the form 'p1/p2' & the simpleStrings are just 'X'
    char[][][] internedQualifiedNames = ReferenceCollection.internQualifiedNames(qualifiedSet);
    // if a well known qualified name was found then we can skip over these
    if (internedQualifiedNames.length < qualifiedSet.elementSize)
        internedQualifiedNames = null;
    char[][] internedSimpleNames = ReferenceCollection.internSimpleNames(simpleSet, true);
    // if a well known name was found then we can skip over these
    if (internedSimpleNames.length < simpleSet.elementSize)
        internedSimpleNames = null;
    char[][] internedRootNames = ReferenceCollection.internSimpleNames(rootSet, false);

    Object[] keyTable = this.newState.references.keyTable;
    Object[] valueTable = this.newState.references.valueTable;
    next: for (int i = 0, l = valueTable.length; i < l; i++) {
        String typeLocator = (String) keyTable[i];
        if (typeLocator != null) {
            if (affectedTypes != null && !affectedTypes.includes(typeLocator))
                continue next;
            ReferenceCollection refs = (ReferenceCollection) valueTable[i];
            if (refs.includes(internedQualifiedNames, internedSimpleNames, internedRootNames)) {
                IFile file = this.javaBuilder.currentProject.getFile(typeLocator);
                SourceFile sourceFile = findSourceFile(file, true);
                if (sourceFile == null)
                    continue next;
                if (this.sourceFiles.contains(sourceFile))
                    continue next;
                if (this.compiledAllAtOnce && this.previousSourceFiles != null
                        && this.previousSourceFiles.contains(sourceFile))
                    continue next; // can skip previously compiled files since already saw hierarchy related problems

                if (JavaBuilder.DEBUG)
                    System.out.println("  adding affected source file " + typeLocator); //$NON-NLS-1$
                this.sourceFiles.add(sourceFile);
            }
        }
    }
}

From source file:org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.java

License:Open Source License

protected void addDependentsOf(IPath path, boolean isStructuralChange, StringSet qualifiedNames,
        StringSet simpleNames, StringSet rootNames) {
    path = path.setDevice(null);/*from w  w w. ja v a 2s.c o  m*/
    if (isStructuralChange) {
        String last = path.lastSegment();
        if (last.length() == TypeConstants.PACKAGE_INFO_NAME.length)
            if (CharOperation.equals(last.toCharArray(), TypeConstants.PACKAGE_INFO_NAME)) {
                path = path.removeLastSegments(1); // the package-info file has changed so blame the package itself
                /* https://bugs.eclipse.org/bugs/show_bug.cgi?id=323785, in the case of default package,
                   there is no need to blame the package itself as there can be no annotations or documentation
                   comment tags in the package-info file that can influence the rest of the package. Just bail out
                   so we don't touch null objects below.
                 */
                if (path.isEmpty())
                    return;
            }
    }

    if (isStructuralChange && !this.hasStructuralChanges) {
        this.newState.tagAsStructurallyChanged();
        this.hasStructuralChanges = true;
    }
    // the qualifiedStrings are of the form 'p1/p2' & the simpleStrings are just 'X'
    rootNames.add(path.segment(0));
    String packageName = path.removeLastSegments(1).toString();
    boolean wasNew = qualifiedNames.add(packageName);
    String typeName = path.lastSegment();
    int memberIndex = typeName.indexOf('$');
    if (memberIndex > 0)
        typeName = typeName.substring(0, memberIndex);
    wasNew = simpleNames.add(typeName) | wasNew;
    if (wasNew && JavaBuilder.DEBUG)
        System.out.println("  will look for dependents of " //$NON-NLS-1$
                + typeName + " in " + packageName); //$NON-NLS-1$
}

From source file:org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.java

License:Open Source License

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;
            }/*w  w w . j av  a  2  s. co  m*/
            return true;
        }
    }
    return true;
}