private void setProjectNatures(IProject project, IFeatureModel model, IProgressMonitor monitor)
     throws CoreException {
   IProjectDescription desc = project.getDescription();
   if (needsJavaNature(model)) {
     desc.setNatureIds(new String[] {JavaCore.NATURE_ID, MDE.FEATURE_NATURE});
   } else {
     desc.setNatureIds(new String[] {MDE.FEATURE_NATURE});
   }
   project.setDescription(desc, new SubProgressMonitor(monitor, 1));
 }
Example #2
0
 /*
  * Instruct the build manager that this project is involved in a cycle and
  * needs to propagate structural changes to the other projects in the cycle.
  */
 void mustPropagateStructuralChanges() {
   LinkedHashSet cycleParticipants = new LinkedHashSet(3);
   this.javaProject.updateCycleParticipants(
       new ArrayList(), cycleParticipants, this.workspaceRoot, new HashSet(3), null);
   IPath currentPath = this.javaProject.getPath();
   Iterator i = cycleParticipants.iterator();
   while (i.hasNext()) {
     IPath participantPath = (IPath) i.next();
     if (participantPath != currentPath) {
       IProject project = this.workspaceRoot.getProject(participantPath.segment(0));
       if (hasBeenBuilt(project)) {
         if (DEBUG)
           System.out.println(
               "JavaBuilder: Requesting another build iteration since cycle participant "
                   + project.getName() // $NON-NLS-1$
                   + " has not yet seen some structural changes"); //$NON-NLS-1$
         needRebuild();
         return;
       }
     }
   }
 }
  private void setClasspath(IProject project, IFeatureModel model, IProgressMonitor monitor)
      throws JavaModelException {
    IJavaProject jProject = JavaCore.create(project);

    IClasspathEntry jreCPEntry =
        JavaCore.newContainerEntry(
            new Path("org.eclipse.jdt.launching.JRE_CONTAINER")); // $NON-NLS-1$

    String libName = model.getFeature().getInstallHandler().getLibrary();
    IClasspathEntry handlerCPEntry =
        JavaCore.newLibraryEntry(project.getFullPath().append(libName), null, null);

    jProject.setRawClasspath(new IClasspathEntry[] {jreCPEntry, handlerCPEntry}, monitor);
  }
  private void addProjectSourceContainers(IProject project, ArrayList result) throws CoreException {
    if (project == null || !project.hasNature(JavaCore.NATURE_ID)) return;

    IJavaProject jProject = JavaCore.create(project);
    result.add(JavaRuntime.newProjectRuntimeClasspathEntry(jProject));

    IClasspathEntry[] entries = jProject.getRawClasspath();
    for (int i = 0; i < entries.length; i++) {
      IClasspathEntry entry = entries[i];
      if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
        IRuntimeClasspathEntry rte = convertClasspathEntry(entry);
        if (rte != null) result.add(rte);
      }
    }
  }
 private void createBuildProperties(IProject project) {
   IFile file = PDEProject.getBuildProperties(project);
   if (!file.exists()) {
     WorkspaceBuildModel model = new WorkspaceBuildModel(file);
     IBuildEntry ientry = model.getFactory().createEntry("bin.includes"); // $NON-NLS-1$
     try {
       IResource[] res = project.members();
       for (int i = 0; i < res.length; i++) {
         String path = res[i].getProjectRelativePath().toString();
         if (!path.equals(".project")) // $NON-NLS-1$
         ientry.addToken(path);
       }
       model.getBuild().add(ientry);
       model.save();
     } catch (CoreException e) {
     }
   }
 }
Example #6
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;
  }
Example #7
0
 private boolean hasJavaBuilder(IProject project) throws CoreException {
   ICommand[] buildCommands = project.getDescription().getBuildSpec();
   for (int i = 0, l = buildCommands.length; i < l; i++)
     if (buildCommands[i].getBuilderName().equals(JavaCore.BUILDER_ID)) return true;
   return false;
 }
Example #8
0
  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;
  }
  private void createProject(IFeatureModel model, IProgressMonitor monitor) throws CoreException {
    String name = model.getFeature().getId();

    IFeaturePlugin[] plugins = model.getFeature().getPlugins();
    for (int i = 0; i < plugins.length; i++) {
      if (name.equals(plugins[i].getId())) {
        name += "-feature"; // $NON-NLS-1$
        break;
      }
    }

    String task = NLS.bind(MDEUIMessages.FeatureImportWizard_operation_creating2, name);
    monitor.beginTask(task, 9);
    try {
      IProject project = fRoot.getProject(name);

      if (project.exists() || new File(project.getParent().getLocation().toFile(), name).exists()) {
        if (queryReplace(project)) {
          if (!project.exists()) project.create(new SubProgressMonitor(monitor, 1));
          project.delete(true, true, new SubProgressMonitor(monitor, 1));
          try {
            RepositoryProvider.unmap(project);
          } catch (TeamException e) {
          }
        } else {
          return;
        }
      } else {
        monitor.worked(1);
      }

      IProjectDescription description = MDEPlugin.getWorkspace().newProjectDescription(name);
      if (fTargetPath != null) description.setLocation(fTargetPath.append(name));

      project.create(description, new SubProgressMonitor(monitor, 1));
      if (!project.isOpen()) {
        project.open(null);
      }
      File featureDir = new File(model.getInstallLocation());

      importContent(
          featureDir,
          project.getFullPath(),
          FileSystemStructureProvider.INSTANCE,
          null,
          new SubProgressMonitor(monitor, 1));
      IFolder folder = project.getFolder("META-INF"); // $NON-NLS-1$
      if (folder.exists()) {
        folder.delete(true, null);
      }
      if (fBinary) {
        // Mark this project so that we can show image overlay
        // using the label decorator
        project.setPersistentProperty(
            MDECore.EXTERNAL_PROJECT_PROPERTY, MDECore.BINARY_PROJECT_VALUE);
      }
      createBuildProperties(project);
      setProjectNatures(project, model, monitor);
      if (project.hasNature(JavaCore.NATURE_ID)) setClasspath(project, model, monitor);

    } finally {
      monitor.done();
    }
  }