/* Return the list of projects for which it requires a resource delta. This builder's project
   * is implicitly included and need not be specified. Builders must re-specify the list
   * of interesting projects every time they are run as this is not carried forward
   * beyond the next build. Missing projects should be specified but will be ignored until
   * they are added to the workspace.
   */
  private IProject[] getRequiredProjects(boolean includeBinaryPrerequisites) {
    if (this.javaProject == null || this.workspaceRoot == null) return new IProject[0];

    ArrayList projects = new ArrayList();
    ExternalFoldersManager externalFoldersManager = JavaModelManager.getExternalManager();
    try {
      IClasspathEntry[] entries = this.javaProject.getExpandedClasspath();
      for (int i = 0, l = entries.length; i < l; i++) {
        IClasspathEntry entry = entries[i];
        IPath path = entry.getPath();
        IProject p = null;
        switch (entry.getEntryKind()) {
          case IClasspathEntry.CPE_PROJECT:
            p =
                this.workspaceRoot.getProject(
                    path.lastSegment()); // missing projects are considered too
            if (((ClasspathEntry) entry).isOptional()
                && !JavaProject.hasJavaNature(p)) // except if entry is optional
            p = null;
            break;
          case IClasspathEntry.CPE_LIBRARY:
            if (includeBinaryPrerequisites && path.segmentCount() > 0) {
              // some binary resources on the class path can come from projects that are not
              // included in the project references
              IResource resource = this.workspaceRoot.findMember(path.segment(0));
              if (resource instanceof IProject) {
                p = (IProject) resource;
              } else {
                resource = externalFoldersManager.getFolder(path);
                if (resource != null) p = resource.getProject();
              }
            }
        }
        if (p != null && !projects.contains(p)) projects.add(p);
      }
    } catch (JavaModelException e) {
      return new IProject[0];
    }
    IProject[] result = new IProject[projects.size()];
    projects.toArray(result);
    return result;
  }
Beispiel #2
0
 public String toString() {
   StringBuffer result = new StringBuffer("JavaSearchScope on "); // $NON-NLS-1$
   if (this.elements != null) {
     result.append("["); // $NON-NLS-1$
     for (int i = 0, length = this.elements.size(); i < length; i++) {
       JavaElement element = (JavaElement) this.elements.get(i);
       result.append("\n\t"); // $NON-NLS-1$
       result.append(element.toStringWithAncestors());
     }
     result.append("\n]"); // $NON-NLS-1$
   } else {
     if (this.pathsCount == 0) {
       result.append("[empty scope]"); // $NON-NLS-1$
     } else {
       result.append("["); // $NON-NLS-1$
       String[] paths = new String[this.relativePaths.length];
       int index = 0;
       for (int i = 0; i < this.relativePaths.length; i++) {
         String path = this.relativePaths[i];
         if (path == null) continue;
         String containerPath;
         if (ExternalFoldersManager.isInternalPathForExternalFolder(
             new Path(this.containerPaths[i]))) {
           Object target = JavaModel.getWorkspaceTarget(new Path(this.containerPaths[i]));
           containerPath = ((IFolder) target).getLocation().toOSString();
         } else {
           containerPath = this.containerPaths[i];
         }
         if (path.length() > 0) {
           paths[index++] = containerPath + '/' + path;
         } else {
           paths[index++] = containerPath;
         }
       }
       System.arraycopy(paths, 0, paths = new String[index], 0, index);
       Util.sort(paths);
       for (int i = 0; i < index; i++) {
         result.append("\n\t"); // $NON-NLS-1$
         result.append(paths[i]);
       }
       result.append("\n]"); // $NON-NLS-1$
     }
   }
   return result.toString();
 }