Ejemplo n.º 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;
  }
Ejemplo n.º 2
0
  /**
   * Create an in-memory document for the given file and user iff one does not exist.
   *
   * @param file file to edit
   */
  public synchronized PadDocument create(IFile file) throws IOException, JavaModelException {
    String path = file.getFullPath().toString();
    if (documents.containsKey(path)) {
      return get(path);
    }

    if (JavaCore.isJavaLikeFileName(file.getName())) {
      JavaCore.createCompilationUnitFrom(file).getWorkingCopy(this, null);
      // now that the Java model is settled, install the highlighter, which causes reconciliation
      new PadSemanticHighlighter(get(path, JavaPadDocument.class));
    } else {
      documents.put(path, new PadDocument(this, collaboration.get(file)));
    }

    return get(path);
  }
 CompilationUnit buildCompilationUnit(BuildContext file) {
   IJavaProject javaProject = JavaCore.create(file.getFile().getProject());
   ASTParser p = ASTParser.newParser(JavaConstants.AST_LEVEL);
   p.setProject(javaProject);
   p.setSource(file.getContents());
   p.setResolveBindings(true);
   p.setKind(ASTParser.K_COMPILATION_UNIT);
   p.setUnitName(file.getFile().getName());
   return (CompilationUnit) p.createAST(null);
 }
 private HashMap<?, ?> createCurrentExportPackageMap() {
   // Dummy hash map created in order to return a defined but empty map
   HashMap<?, ?> packageFragments = new HashMap<>(0);
   // Get the model
   IPluginModelBase model = getModel();
   // Ensure model is defined
   if (model == null) {
     return packageFragments;
   }
   // Get the underlying resource
   IResource resource = model.getUnderlyingResource();
   // Ensure resource is defined
   if (resource == null) {
     return packageFragments;
   }
   // Get the project
   IProject project = resource.getProject();
   // Ensure the project is defined
   if (project == null) {
     return packageFragments;
   }
   // Ensure the project is a Java project
   try {
     if (project.hasNature(JavaCore.NATURE_ID) == false) {
       return packageFragments;
     }
   } catch (CoreException e) {
     return packageFragments;
   }
   // Get the Java project
   IJavaProject javaProject = JavaCore.create(project);
   // Ensure the Java project is defined
   if (javaProject == null) {
     return packageFragments;
   }
   // Get the current packages associated with the export package header
   Vector<?> currentExportPackages = null;
   if (fHeader == null) {
     currentExportPackages = new Vector<>();
   } else {
     currentExportPackages = fHeader.getPackageNames();
   }
   // Get a hashtable of all the package fragments that are allowed to
   // be added to the current export package header
   // Generally, all package fragments contained in the same Java project
   // as the plugin manifest file
   // No duplicates are allowed and all current packages are excluded
   return PDEJavaHelper.getPackageFragmentsHash(
       javaProject, currentExportPackages, allowJavaPackages());
 }
  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 ISourceContainer getArchiveSourceContainer(String location) throws JavaModelException {
    IWorkspaceRoot root = PDELaunchingPlugin.getWorkspace().getRoot();
    IFile[] containers = root.findFilesForLocationURI(URIUtil.toURI(location));
    for (int i = 0; i < containers.length; i++) {
      IJavaElement element = JavaCore.create(containers[i]);
      if (element instanceof IPackageFragmentRoot) {
        IPackageFragmentRoot archive = (IPackageFragmentRoot) element;
        IPath path = archive.getSourceAttachmentPath();
        if (path == null || path.segmentCount() == 0) continue;

        IPath rootPath = archive.getSourceAttachmentRootPath();
        boolean detectRootPath = rootPath != null && rootPath.segmentCount() > 0;

        IFile archiveFile = root.getFile(path);
        if (archiveFile.exists()) return new ArchiveSourceContainer(archiveFile, detectRootPath);

        File file = path.toFile();
        if (file.exists())
          return new ExternalArchiveSourceContainer(file.getAbsolutePath(), detectRootPath);
      }
    }
    return null;
  }
Ejemplo n.º 7
0
 public static ProjectTestsOwner of(IProject project) {
   return of(JavaCore.create(project));
 }
Ejemplo n.º 8
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;
  }