示例#1
0
  private int initializeBuilder(int kind, boolean forBuild) throws CoreException {
    // some calls just need the nameEnvironment initialized so skip the rest
    this.javaProject = (JavaProject) JavaCore.create(this.currentProject);
    this.workspaceRoot = this.currentProject.getWorkspace().getRoot();

    if (forBuild) {
      // cache the known participants for this project
      this.participants =
          JavaModelManager.getJavaModelManager()
              .compilationParticipants
              .getCompilationParticipants(this.javaProject);
      if (this.participants != null)
        for (int i = 0, l = this.participants.length; i < l; i++)
          if (this.participants[i].aboutToBuild(this.javaProject)
              == CompilationParticipant.NEEDS_FULL_BUILD) kind = FULL_BUILD;

      // Flush the existing external files cache if this is the beginning of a build cycle
      String projectName = this.currentProject.getName();
      if (builtProjects == null || builtProjects.contains(projectName)) {
        builtProjects = new ArrayList();
      }
      builtProjects.add(projectName);
    }

    this.binaryLocationsPerProject = new SimpleLookupTable(3);
    this.nameEnvironment =
        new NameEnvironment(
            this.workspaceRoot, this.javaProject, this.binaryLocationsPerProject, this.notifier);

    if (forBuild) {
      String filterSequence =
          this.javaProject.getOption(JavaCore.CORE_JAVA_BUILD_RESOURCE_COPY_FILTER, true);
      char[][] filters =
          filterSequence != null && filterSequence.length() > 0
              ? CharOperation.splitAndTrimOn(',', filterSequence.toCharArray())
              : null;
      if (filters == null) {
        this.extraResourceFileFilters = null;
        this.extraResourceFolderFilters = null;
      } else {
        int fileCount = 0, folderCount = 0;
        for (int i = 0, l = filters.length; i < l; i++) {
          char[] f = filters[i];
          if (f.length == 0) continue;
          if (f[f.length - 1] == '/') folderCount++;
          else fileCount++;
        }
        this.extraResourceFileFilters = new char[fileCount][];
        this.extraResourceFolderFilters = new String[folderCount];
        for (int i = 0, l = filters.length; i < l; i++) {
          char[] f = filters[i];
          if (f.length == 0) continue;
          if (f[f.length - 1] == '/')
            this.extraResourceFolderFilters[--folderCount] = new String(f, 0, f.length - 1);
          else this.extraResourceFileFilters[--fileCount] = f;
        }
      }
    }
    return kind;
  }
示例#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;
  }