예제 #1
0
  private void createInconsistentBuildMarker(CoreException coreException) throws CoreException {
    String message = null;
    IStatus status = coreException.getStatus();
    if (status.isMultiStatus()) {
      IStatus[] children = status.getChildren();
      if (children != null && children.length > 0) message = children[0].getMessage();
    }
    if (message == null) message = coreException.getMessage();

    IMarker marker = this.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_inconsistentProject, message),
          new Integer(IMarker.SEVERITY_ERROR),
          new Integer(CategorizedProblem.CAT_BUILDPATH),
          JavaBuilder.SOURCE_ID
        });
  }
예제 #2
0
  private boolean isWorthBuilding() throws CoreException {
    boolean abortBuilds =
        JavaCore.ABORT.equals(
            this.javaProject.getOption(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH, true));
    if (!abortBuilds) {
      if (DEBUG) System.out.println("JavaBuilder: Ignoring invalid classpath"); // $NON-NLS-1$
      return true;
    }

    // Abort build only if there are classpath errors
    if (isClasspathBroken(this.javaProject, true)) {
      if (DEBUG)
        System.out.println(
            "JavaBuilder: Aborted build because project has classpath errors (incomplete or involved in cycle)"); //$NON-NLS-1$

      removeProblemsAndTasksFor(this.currentProject); // remove all compilation problems

      IMarker marker = this.currentProject.createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);
      marker.setAttributes(
          new String[] {
            IMarker.MESSAGE, IMarker.SEVERITY, IJavaModelMarker.CATEGORY_ID, IMarker.SOURCE_ID
          },
          new Object[] {
            Messages.build_abortDueToClasspathProblems,
            new Integer(IMarker.SEVERITY_ERROR),
            new Integer(CategorizedProblem.CAT_BUILDPATH),
            JavaBuilder.SOURCE_ID
          });
      return false;
    }

    if (JavaCore.WARNING.equals(
        this.javaProject.getOption(JavaCore.CORE_INCOMPLETE_CLASSPATH, true))) return true;

    // make sure all prereq projects have valid build states... only when aborting builds since
    // projects in cycles do not have build states
    // except for projects involved in a 'warning' cycle (see below)
    IProject[] requiredProjects = getRequiredProjects(false);
    for (int i = 0, l = requiredProjects.length; i < l; i++) {
      IProject p = requiredProjects[i];
      if (getLastState(p) == null) {
        // The prereq project has no build state: if this prereq project has a 'warning' cycle
        // marker then allow build (see bug id 23357)
        JavaProject prereq = (JavaProject) JavaCore.create(p);
        if (prereq.hasCycleMarker()
            && JavaCore.WARNING.equals(
                this.javaProject.getOption(JavaCore.CORE_CIRCULAR_CLASSPATH, true))) {
          if (DEBUG)
            System.out.println(
                "JavaBuilder: Continued to build even though prereq project "
                    + p.getName() // $NON-NLS-1$
                    + " was not built since its part of a cycle"); //$NON-NLS-1$
          continue;
        }
        if (!hasJavaBuilder(p)) {
          if (DEBUG)
            System.out.println(
                "JavaBuilder: Continued to build even though prereq project "
                    + p.getName() // $NON-NLS-1$
                    + " is not built by JavaBuilder"); //$NON-NLS-1$
          continue;
        }
        if (DEBUG)
          System.out.println(
              "JavaBuilder: Aborted build because prereq project "
                  + p.getName() // $NON-NLS-1$
                  + " was not built"); //$NON-NLS-1$

        removeProblemsAndTasksFor(
            this.currentProject); // make this the only problem for this project
        IMarker marker =
            this.currentProject.createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);
        marker.setAttributes(
            new String[] {
              IMarker.MESSAGE, IMarker.SEVERITY, IJavaModelMarker.CATEGORY_ID, IMarker.SOURCE_ID
            },
            new Object[] {
              isClasspathBroken(prereq, true)
                  ? Messages.bind(Messages.build_prereqProjectHasClasspathProblems, p.getName())
                  : Messages.bind(Messages.build_prereqProjectMustBeRebuilt, p.getName()),
              new Integer(IMarker.SEVERITY_ERROR),
              new Integer(CategorizedProblem.CAT_BUILDPATH),
              JavaBuilder.SOURCE_ID
            });
        return false;
      }
    }
    return true;
  }
예제 #3
0
  protected IProject[] build(int kind, Map ignored, IProgressMonitor monitor) throws CoreException {
    this.currentProject = getProject();
    if (this.currentProject == null || !this.currentProject.isAccessible()) return new IProject[0];

    if (DEBUG)
      System.out.println(
          "\nJavaBuilder: Starting build of "
              + this.currentProject.getName() // $NON-NLS-1$
              + " @ "
              + new Date(System.currentTimeMillis())); // $NON-NLS-1$
    this.notifier = new BuildNotifier(monitor, this.currentProject);
    this.notifier.begin();
    boolean ok = false;
    try {
      this.notifier.checkCancel();
      kind = initializeBuilder(kind, true);

      if (isWorthBuilding()) {
        if (kind == FULL_BUILD) {
          if (DEBUG)
            System.out.println("JavaBuilder: Performing full build as requested"); // $NON-NLS-1$
          buildAll();
        } else {
          if ((this.lastState = getLastState(this.currentProject)) == null) {
            if (DEBUG)
              System.out.println(
                  "JavaBuilder: Performing full build since last saved state was not found"); //$NON-NLS-1$
            buildAll();
          } else if (hasClasspathChanged()) {
            // if the output location changes, do not delete the binary files from old location
            // the user may be trying something
            if (DEBUG)
              System.out.println(
                  "JavaBuilder: Performing full build since classpath has changed"); //$NON-NLS-1$
            buildAll();
          } else if (this.nameEnvironment.sourceLocations.length > 0) {
            // if there is no source to compile & no classpath changes then we are done
            SimpleLookupTable deltas = findDeltas();
            if (deltas == null) {
              if (DEBUG)
                System.out.println(
                    "JavaBuilder: Performing full build since deltas are missing after incremental request"); //$NON-NLS-1$
              buildAll();
            } else if (deltas.elementSize > 0) {
              buildDeltas(deltas);
            } else if (DEBUG) {
              System.out.println(
                  "JavaBuilder: Nothing to build since deltas were empty"); //$NON-NLS-1$
            }
          } else {
            if (hasStructuralDelta()) { // double check that a jar file didn't get replaced in a
              // binary project
              if (DEBUG)
                System.out.println(
                    "JavaBuilder: Performing full build since there are structural deltas"); //$NON-NLS-1$
              buildAll();
            } else {
              if (DEBUG)
                System.out.println(
                    "JavaBuilder: Nothing to build since there are no source folders and no deltas"); //$NON-NLS-1$
              this.lastState.tagAsNoopBuild();
            }
          }
        }
        ok = true;
      }
    } catch (CoreException e) {
      Util.log(
          e,
          "JavaBuilder handling CoreException while building: "
              + this.currentProject.getName()); // $NON-NLS-1$
      createInconsistentBuildMarker(e);
    } catch (ImageBuilderInternalException e) {
      Util.log(
          e.getThrowable(),
          "JavaBuilder handling ImageBuilderInternalException while building: "
              + this.currentProject.getName()); // $NON-NLS-1$
      createInconsistentBuildMarker(e.coreException);
    } catch (MissingSourceFileException e) {
      // do not log this exception since its thrown to handle aborted compiles because of missing
      // source files
      if (DEBUG)
        System.out.println(Messages.bind(Messages.build_missingSourceFile, e.missingSourceFile));
      removeProblemsAndTasksFor(this.currentProject); // make this the only problem for this project
      IMarker marker = this.currentProject.createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);
      marker.setAttributes(
          new String[] {IMarker.MESSAGE, IMarker.SEVERITY, IMarker.SOURCE_ID},
          new Object[] {
            Messages.bind(Messages.build_missingSourceFile, e.missingSourceFile),
            new Integer(IMarker.SEVERITY_ERROR),
            JavaBuilder.SOURCE_ID
          });
    } finally {
      for (int i = 0, l = this.participants == null ? 0 : this.participants.length; i < l; i++)
        this.participants[i].buildFinished(this.javaProject);
      if (!ok)
        // If the build failed, clear the previously built state, forcing a full build next time.
        clearLastState();
      this.notifier.done();
      cleanup();
    }
    IProject[] requiredProjects = getRequiredProjects(true);
    if (DEBUG)
      System.out.println(
          "JavaBuilder: Finished build of "
              + this.currentProject.getName() // $NON-NLS-1$
              + " @ "
              + new Date(System.currentTimeMillis())
              + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
    return requiredProjects;
  }