示例#1
0
 private void buildAll() {
   this.notifier.checkCancel();
   this.notifier.subTask(
       Messages.bind(Messages.build_preparingBuild, this.currentProject.getName()));
   if (DEBUG && this.lastState != null)
     System.out.println("JavaBuilder: Clearing last state : " + this.lastState); // $NON-NLS-1$
   clearLastState();
   BatchImageBuilder imageBuilder = new BatchImageBuilder(this, true);
   imageBuilder.build();
   recordNewState(imageBuilder.newState);
 }
示例#2
0
 private void buildDeltas(SimpleLookupTable deltas) {
   this.notifier.checkCancel();
   this.notifier.subTask(
       Messages.bind(Messages.build_preparingBuild, this.currentProject.getName()));
   if (DEBUG && this.lastState != null)
     System.out.println("JavaBuilder: Clearing last state : " + this.lastState); // $NON-NLS-1$
   clearLastState(); // clear the previously built state so if the build fails, a full build will
   // occur next time
   IncrementalImageBuilder imageBuilder = new IncrementalImageBuilder(this);
   if (imageBuilder.build(deltas)) {
     recordNewState(imageBuilder.newState);
   } else {
     if (DEBUG)
       System.out.println(
           "JavaBuilder: Performing full build since incremental build failed"); //$NON-NLS-1$
     buildAll();
   }
 }
示例#3
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
        });
  }
示例#4
0
 protected IStatus run(IProgressMonitor monitor) {
   IJob job = currentJob();
   while (!monitor.isCanceled() && job != null) {
     String taskName =
         new StringBuffer(Messages.jobmanager_indexing)
             .append(
                 Messages.bind(
                     Messages.jobmanager_filesToIndex,
                     job.getJobFamily(),
                     Integer.toString(awaitingJobsCount())))
             .toString();
     monitor.subTask(taskName);
     setName(taskName);
     try {
       Thread.sleep(500);
     } catch (InterruptedException e) {
       // ignore
     }
     job = currentJob();
   }
   return Status.OK_STATUS;
 }
  public void build() {
    if (JavaBuilder.DEBUG) System.out.println("FULL build"); // $NON-NLS-1$

    try {
      this.notifier.subTask(
          Messages.bind(Messages.build_cleaningOutput, this.javaBuilder.currentProject.getName()));
      JavaBuilder.removeProblemsAndTasksFor(this.javaBuilder.currentProject);
      cleanOutputFolders(true);
      this.notifier.updateProgressDelta(0.05f);

      this.notifier.subTask(Messages.build_analyzingSources);
      ArrayList sourceFiles = new ArrayList(33);
      addAllSourceFiles(sourceFiles);
      this.notifier.updateProgressDelta(0.10f);

      if (sourceFiles.size() > 0) {
        SourceFile[] allSourceFiles = new SourceFile[sourceFiles.size()];
        sourceFiles.toArray(allSourceFiles);

        this.notifier.setProgressPerCompilationUnit(0.75f / allSourceFiles.length);
        this.workQueue.addAll(allSourceFiles);
        compile(allSourceFiles);

        if (this.typeLocatorsWithUndefinedTypes != null)
          if (this.secondaryTypes != null && !this.secondaryTypes.isEmpty())
            rebuildTypesAffectedBySecondaryTypes();
        if (this.incrementalBuilder != null) this.incrementalBuilder.buildAfterBatchBuild();
      }

      if (this.javaBuilder.javaProject.hasCycleMarker())
        this.javaBuilder.mustPropagateStructuralChanges();
    } catch (CoreException e) {
      throw internalException(e);
    } finally {
      if (JavaBuilder.SHOW_STATS) printStats();
      cleanUp();
    }
  }
  /**
   * Copies/moves a package fragment with the name <code>newName</code> to the destination package.
   * <br>
   *
   * @exception JavaModelException if the operation is unable to complete
   */
  private void processPackageFragmentResource(
      PackageFragment source, PackageFragmentRoot root, String newName) throws JavaModelException {
    try {
      String[] newFragName = (newName == null) ? source.names : Util.getTrimmedSimpleNames(newName);
      PackageFragment newFrag = root.getPackageFragment(newFragName);
      IResource[] resources = collectResourcesOfInterest(source);

      // if isMove() can we move the folder itself ? (see
      // http://bugs.eclipse.org/bugs/show_bug.cgi?id=22458)
      boolean shouldMoveFolder =
          isMove() && !newFrag.resource().exists(); // if new pkg fragment exists, it is an override
      IFolder srcFolder = (IFolder) source.resource();
      IPath destPath = newFrag.getPath();
      if (shouldMoveFolder) {
        // check if destination is not included in source
        if (srcFolder.getFullPath().isPrefixOf(destPath)) {
          shouldMoveFolder = false;
        } else {
          // check if there are no sub-packages
          IResource[] members = srcFolder.members();
          for (int i = 0; i < members.length; i++) {
            if (members[i] instanceof IFolder) {
              shouldMoveFolder = false;
              break;
            }
          }
        }
      }
      boolean containsReadOnlySubPackageFragments =
          createNeededPackageFragments(
              (IContainer) source.parent.resource(), root, newFragName, shouldMoveFolder);
      boolean sourceIsReadOnly = Util.isReadOnly(srcFolder);

      // Process resources
      if (shouldMoveFolder) {
        // move underlying resource
        // TODO Revisit once bug 43044 is fixed
        if (sourceIsReadOnly) {
          Util.setReadOnly(srcFolder, false);
        }
        srcFolder.move(destPath, this.force, true /* keep history */, getSubProgressMonitor(1));
        if (sourceIsReadOnly) {
          Util.setReadOnly(srcFolder, true);
        }
        setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
      } else {
        // process the leaf resources
        if (resources.length > 0) {
          if (isRename()) {
            if (!destPath.equals(source.getPath())) {
              moveResources(resources, destPath);
            }
          } else if (isMove()) {
            // we need to delete this resource if this operation wants to override existing
            // resources
            for (int i = 0, max = resources.length; i < max; i++) {
              IResource destinationResource =
                  ResourcesPlugin.getWorkspace()
                      .getRoot()
                      .findMember(destPath.append(resources[i].getName()));
              if (destinationResource != null) {
                if (this.force) {
                  deleteResource(destinationResource, IResource.KEEP_HISTORY);
                } else {
                  throw new JavaModelException(
                      new JavaModelStatus(
                          IJavaModelStatusConstants.NAME_COLLISION,
                          Messages.bind(
                              Messages.status_nameCollision,
                              destinationResource.getFullPath().toString())));
                }
              }
            }
            moveResources(resources, destPath);
          } else {
            // we need to delete this resource if this operation wants to override existing
            // resources
            for (int i = 0, max = resources.length; i < max; i++) {
              IResource destinationResource =
                  ResourcesPlugin.getWorkspace()
                      .getRoot()
                      .findMember(destPath.append(resources[i].getName()));
              if (destinationResource != null) {
                if (this.force) {
                  // we need to delete this resource if this operation wants to override existing
                  // resources
                  deleteResource(destinationResource, IResource.KEEP_HISTORY);
                } else {
                  throw new JavaModelException(
                      new JavaModelStatus(
                          IJavaModelStatusConstants.NAME_COLLISION,
                          Messages.bind(
                              Messages.status_nameCollision,
                              destinationResource.getFullPath().toString())));
                }
              }
            }
            copyResources(resources, destPath);
          }
        }
      }

      // Update package statement in compilation unit if needed
      if (!Util.equalArraysOrNull(
          newFragName, source.names)) { // if package has been renamed, update the compilation units
        char[][] inclusionPatterns = root.fullInclusionPatternChars();
        char[][] exclusionPatterns = root.fullExclusionPatternChars();
        for (int i = 0; i < resources.length; i++) {
          String resourceName = resources[i].getName();
          if (Util.isJavaLikeFileName(resourceName)) {
            // we only consider potential compilation units
            ICompilationUnit cu = newFrag.getCompilationUnit(resourceName);
            if (Util.isExcluded(
                cu.getPath(), inclusionPatterns, exclusionPatterns, false /*not a folder*/))
              continue;
            this.parser.setSource(cu);
            CompilationUnit astCU = (CompilationUnit) this.parser.createAST(this.progressMonitor);
            AST ast = astCU.getAST();
            ASTRewrite rewrite = ASTRewrite.create(ast);
            updatePackageStatement(astCU, newFragName, rewrite, cu);
            TextEdit edits = rewrite.rewriteAST();
            applyTextEdit(cu, edits);
            cu.save(null, false);
          }
        }
      }

      // Discard empty old package (if still empty after the rename)
      boolean isEmpty = true;
      if (isMove()) {
        // delete remaining files in this package (.class file in the case where Proj=src=bin)
        // in case of a copy
        updateReadOnlyPackageFragmentsForMove(
            (IContainer) source.parent.resource(), root, newFragName, sourceIsReadOnly);
        if (srcFolder.exists()) {
          IResource[] remaining = srcFolder.members();
          for (int i = 0, length = remaining.length; i < length; i++) {
            IResource file = remaining[i];
            if (file instanceof IFile) {
              if (Util.isReadOnly(file)) {
                Util.setReadOnly(file, false);
              }
              deleteResource(file, IResource.FORCE | IResource.KEEP_HISTORY);
            } else {
              isEmpty = false;
            }
          }
        }
        if (isEmpty) {
          IResource rootResource;
          // check if source is included in destination
          if (destPath.isPrefixOf(srcFolder.getFullPath())) {
            rootResource = newFrag.resource();
          } else {
            rootResource = source.parent.resource();
          }

          // delete recursively empty folders
          deleteEmptyPackageFragment(source, false, rootResource);
        }
      } else if (containsReadOnlySubPackageFragments) {
        // in case of a copy
        updateReadOnlyPackageFragmentsForCopy(
            (IContainer) source.parent.resource(), root, newFragName);
      }
      // workaround for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=24505
      if (isEmpty && isMove() && !(Util.isExcluded(source) || Util.isExcluded(newFrag))) {
        IJavaProject sourceProject = source.getJavaProject();
        getDeltaFor(sourceProject).movedFrom(source, newFrag);
        IJavaProject destProject = newFrag.getJavaProject();
        getDeltaFor(destProject).movedTo(newFrag, source);
      }
    } catch (JavaModelException e) {
      throw e;
    } catch (CoreException ce) {
      throw new JavaModelException(ce);
    }
  }
  /**
   * Copies/moves a compilation unit with the name <code>newCUName</code> to the destination
   * package.<br>
   * The package statement in the compilation unit is updated if necessary. The main type of the
   * compilation unit is renamed if necessary.
   *
   * @exception JavaModelException if the operation is unable to complete
   */
  private void processCompilationUnitResource(ICompilationUnit source, PackageFragment dest)
      throws JavaModelException {
    String newCUName = getNewNameFor(source);
    String destName = (newCUName != null) ? newCUName : source.getElementName();
    TextEdit edit = updateContent(source, dest, newCUName); // null if unchanged

    // TODO (frederic) remove when bug 67606 will be fixed (bug 67823)
    // store encoding (fix bug 66898)
    IFile sourceResource = (IFile) source.getResource();
    String sourceEncoding = null;
    try {
      sourceEncoding = sourceResource.getCharset(false);
    } catch (CoreException ce) {
      // no problem, use default encoding
    }
    // end todo
    // copy resource
    IContainer destFolder = (IContainer) dest.getResource(); // can be an IFolder or an IProject
    IFile destFile = destFolder.getFile(new Path(destName));
    org.eclipse.jdt.internal.core.CompilationUnit destCU =
        new org.eclipse.jdt.internal.core.CompilationUnit(
            dest, destName, DefaultWorkingCopyOwner.PRIMARY);
    if (!destFile.equals(sourceResource)) {
      try {
        if (!destCU.isWorkingCopy()) {
          if (destFile.exists()) {
            if (this.force) {
              // we can remove it
              deleteResource(destFile, IResource.KEEP_HISTORY);
              destCU.close(); // ensure the in-memory buffer for the dest CU is closed
            } else {
              // abort
              throw new JavaModelException(
                  new JavaModelStatus(
                      IJavaModelStatusConstants.NAME_COLLISION,
                      Messages.bind(
                          Messages.status_nameCollision, destFile.getFullPath().toString())));
            }
          }
          int flags = this.force ? IResource.FORCE : IResource.NONE;
          if (isMove()) {
            flags |= IResource.KEEP_HISTORY;
            sourceResource.move(destFile.getFullPath(), flags, getSubProgressMonitor(1));
          } else {
            if (edit != null) flags |= IResource.KEEP_HISTORY;
            sourceResource.copy(destFile.getFullPath(), flags, getSubProgressMonitor(1));
          }
          setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
        } else {
          destCU.getBuffer().setContents(source.getBuffer().getContents());
        }
      } catch (JavaModelException e) {
        throw e;
      } catch (CoreException e) {
        throw new JavaModelException(e);
      }

      // update new resource content
      if (edit != null) {
        boolean wasReadOnly = destFile.isReadOnly();
        try {
          saveContent(dest, destName, edit, sourceEncoding, destFile);
        } catch (CoreException e) {
          if (e instanceof JavaModelException) throw (JavaModelException) e;
          throw new JavaModelException(e);
        } finally {
          Util.setReadOnly(destFile, wasReadOnly);
        }
      }

      // register the correct change deltas
      prepareDeltas(source, destCU, isMove());
      if (newCUName != null) {
        // the main type has been renamed
        String oldName = Util.getNameWithoutJavaLikeExtension(source.getElementName());
        String newName = Util.getNameWithoutJavaLikeExtension(newCUName);
        prepareDeltas(source.getType(oldName), destCU.getType(newName), isMove());
      }
    } else {
      if (!this.force) {
        throw new JavaModelException(
            new JavaModelStatus(
                IJavaModelStatusConstants.NAME_COLLISION,
                Messages.bind(Messages.status_nameCollision, destFile.getFullPath().toString())));
      }
      // update new resource content
      // in case we do a saveas on the same resource we have to simply update the contents
      // see http://dev.eclipse.org/bugs/show_bug.cgi?id=9351
      if (edit != null) {
        saveContent(dest, destName, edit, sourceEncoding, destFile);
      }
    }
  }
示例#8
0
  /** Infinite loop performing resource indexing */
  public void run() {

    long idlingStart = -1;
    activateProcessing();
    try {
      class ProgressJob extends Job {
        ProgressJob(String name) {
          super(name);
        }

        protected IStatus run(IProgressMonitor monitor) {
          IJob job = currentJob();
          while (!monitor.isCanceled() && job != null) {
            String taskName =
                new StringBuffer(Messages.jobmanager_indexing)
                    .append(
                        Messages.bind(
                            Messages.jobmanager_filesToIndex,
                            job.getJobFamily(),
                            Integer.toString(awaitingJobsCount())))
                    .toString();
            monitor.subTask(taskName);
            setName(taskName);
            try {
              Thread.sleep(500);
            } catch (InterruptedException e) {
              // ignore
            }
            job = currentJob();
          }
          return Status.OK_STATUS;
        }
      }
      this.progressJob = null;
      while (this.processingThread != null) {
        try {
          IJob job;
          synchronized (this) {
            // handle shutdown case when notifyAll came before the wait but after the while loop was
            // entered
            if (this.processingThread == null) continue;

            // must check for new job inside this sync block to avoid timing hole
            if ((job = currentJob()) == null) {
              if (this.progressJob != null) {
                this.progressJob.cancel();
                this.progressJob = null;
              }
              if (idlingStart < 0) idlingStart = System.currentTimeMillis();
              else notifyIdle(System.currentTimeMillis() - idlingStart);
              this.wait(); // wait until a new job is posted (or reenabled:38901)
            } else {
              idlingStart = -1;
            }
          }
          if (job == null) {
            notifyIdle(System.currentTimeMillis() - idlingStart);
            // just woke up, delay before processing any new jobs, allow some time for the active
            // thread to finish
            Thread.sleep(500);
            continue;
          }
          if (VERBOSE) {
            Util.verbose(awaitingJobsCount() + " awaiting jobs"); // $NON-NLS-1$
            Util.verbose("STARTING background job - " + job); // $NON-NLS-1$
          }
          try {
            this.executing = true;
            if (this.progressJob == null) {
              this.progressJob =
                  new ProgressJob(
                      Messages.bind(
                          Messages.jobmanager_indexing, "", "")); // $NON-NLS-1$ //$NON-NLS-2$
              this.progressJob.setPriority(Job.LONG);
              this.progressJob.setSystem(true);
              this.progressJob.schedule();
            }
            /*boolean status = */ job.execute(null);
            // if (status == FAILED) request(job);
          } finally {
            this.executing = false;
            if (VERBOSE) Util.verbose("FINISHED background job - " + job); // $NON-NLS-1$
            moveToNextJob();
            if (this.awaitingClients == 0) Thread.sleep(50);
          }
        } catch (InterruptedException e) { // background indexing was interrupted
        }
      }
    } catch (RuntimeException e) {
      if (this.processingThread != null) { // if not shutting down
        // log exception
        Util.log(e, "Background Indexer Crash Recovery"); // $NON-NLS-1$

        // keep job manager alive
        discardJobs(null);
        this.processingThread = null;
        reset(); // this will fork a new thread with no waiting jobs, some indexes will be
        // inconsistent
      }
      throw e;
    } catch (Error e) {
      if (this.processingThread != null && !(e instanceof ThreadDeath)) {
        // log exception
        Util.log(e, "Background Indexer Crash Recovery"); // $NON-NLS-1$

        // keep job manager alive
        discardJobs(null);
        this.processingThread = null;
        reset(); // this will fork a new thread with no waiting jobs, some indexes will be
        // inconsistent
      }
      throw e;
    }
  }
示例#9
0
  /**
   * This API is allowing to run one job in concurrence with background processing. Indeed since
   * other jobs are performed in background, resource sharing might be an issue.Therefore, this
   * functionality allows a given job to be run without colliding with background ones. Note:
   * multiple thread might attempt to perform concurrent jobs at the same time, and should
   * synchronize (it is deliberately left to clients to decide whether concurrent jobs might
   * interfere or not. In general, multiple read jobs are ok).
   *
   * <p>Waiting policy can be: IJobConstants.ForceImmediateSearch
   * IJobConstants.CancelIfNotReadyToSearch IJobConstants.WaitUntilReadyToSearch
   */
  public boolean performConcurrentJob(
      IJob searchJob, int waitingPolicy, IProgressMonitor progress) {
    if (VERBOSE) Util.verbose("STARTING  concurrent job - " + searchJob); // $NON-NLS-1$

    searchJob.ensureReadyToRun();

    boolean status = IJob.FAILED;
    try {
      int concurrentJobWork = 100;
      if (progress != null) progress.beginTask("", concurrentJobWork); // $NON-NLS-1$
      if (awaitingJobsCount() > 0) {
        switch (waitingPolicy) {
          case IJob.ForceImmediate:
            if (VERBOSE)
              Util.verbose("-> NOT READY - forcing immediate - " + searchJob); // $NON-NLS-1$
            try {
              disable(); // pause indexing
              status =
                  searchJob.execute(
                      progress == null
                          ? null
                          : new SubProgressMonitor(progress, concurrentJobWork));
            } finally {
              enable();
            }
            if (VERBOSE) Util.verbose("FINISHED  concurrent job - " + searchJob); // $NON-NLS-1$
            return status;

          case IJob.CancelIfNotReady:
            if (VERBOSE) Util.verbose("-> NOT READY - cancelling - " + searchJob); // $NON-NLS-1$
            if (VERBOSE) Util.verbose("CANCELED concurrent job - " + searchJob); // $NON-NLS-1$
            throw new OperationCanceledException();

          case IJob.WaitUntilReady:
            IProgressMonitor subProgress = null;
            try {
              int totalWork = 1000;
              if (progress != null) {
                subProgress = new SubProgressMonitor(progress, concurrentJobWork * 8 / 10);
                subProgress.beginTask("", totalWork); // $NON-NLS-1$
                concurrentJobWork = concurrentJobWork * 2 / 10;
              }
              // use local variable to avoid potential NPE (see bug 20435 NPE when searching java
              // method
              // and bug 42760 NullPointerException in JobManager when searching)
              Thread t = this.processingThread;
              int originalPriority = t == null ? -1 : t.getPriority();
              try {
                if (t != null) t.setPriority(Thread.currentThread().getPriority());
                synchronized (this) {
                  this.awaitingClients++;
                }
                IJob previousJob = null;
                int awaitingJobsCount;
                int lastJobsCount = totalWork;
                float lastWorked = 0;
                float totalWorked = 0;
                while ((awaitingJobsCount = awaitingJobsCount()) > 0) {
                  if ((subProgress != null && subProgress.isCanceled())
                      || this.processingThread == null) throw new OperationCanceledException();
                  IJob currentJob = currentJob();
                  // currentJob can be null when jobs have been added to the queue but job manager
                  // is not enabled
                  if (currentJob != null && currentJob != previousJob) {
                    if (VERBOSE)
                      Util.verbose(
                          "-> NOT READY - waiting until ready - " + searchJob); // $NON-NLS-1$
                    if (subProgress != null) {
                      String indexing =
                          Messages.bind(
                              Messages.jobmanager_filesToIndex,
                              currentJob.getJobFamily(),
                              Integer.toString(awaitingJobsCount));
                      subProgress.subTask(indexing);
                      // ratio of the amount of work relative to the total work
                      float ratio =
                          awaitingJobsCount < totalWork
                              ? 1
                              : ((float) totalWork) / awaitingJobsCount;
                      if (lastJobsCount > awaitingJobsCount) {
                        totalWorked += (lastJobsCount - awaitingJobsCount) * ratio;
                      } else {
                        // more jobs were added, just increment by the ratio
                        totalWorked += ratio;
                      }
                      if (totalWorked - lastWorked >= 1) {
                        subProgress.worked((int) (totalWorked - lastWorked));
                        lastWorked = totalWorked;
                      }
                      lastJobsCount = awaitingJobsCount;
                    }
                    previousJob = currentJob;
                  }
                  try {
                    if (VERBOSE) Util.verbose("-> GOING TO SLEEP - " + searchJob); // $NON-NLS-1$
                    Thread.sleep(50);
                  } catch (InterruptedException e) {
                    // ignore
                  }
                }
              } finally {
                synchronized (this) {
                  this.awaitingClients--;
                }
                if (t != null && originalPriority > -1 && t.isAlive())
                  t.setPriority(originalPriority);
              }
            } finally {
              if (subProgress != null) subProgress.done();
            }
        }
      }
      status =
          searchJob.execute(
              progress == null ? null : new SubProgressMonitor(progress, concurrentJobWork));
    } finally {
      if (progress != null) progress.done();
      if (VERBOSE) Util.verbose("FINISHED  concurrent job - " + searchJob); // $NON-NLS-1$
    }
    return status;
  }
  protected void cleanOutputFolders(boolean copyBack) throws CoreException {
    boolean deleteAll =
        JavaCore.CLEAN.equals(
            this.javaBuilder.javaProject.getOption(
                JavaCore.CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER, true));
    if (deleteAll) {
      if (this.javaBuilder.participants != null)
        for (int i = 0, l = this.javaBuilder.participants.length; i < l; i++)
          this.javaBuilder.participants[i].cleanStarting(this.javaBuilder.javaProject);

      ArrayList visited = new ArrayList(this.sourceLocations.length);
      for (int i = 0, l = this.sourceLocations.length; i < l; i++) {
        this.notifier.subTask(
            Messages.bind(
                Messages.build_cleaningOutput, this.javaBuilder.currentProject.getName()));
        ClasspathMultiDirectory sourceLocation = this.sourceLocations[i];
        if (sourceLocation.hasIndependentOutputFolder) {
          IContainer outputFolder = sourceLocation.binaryFolder;
          if (!visited.contains(outputFolder)) {
            visited.add(outputFolder);
            IResource[] members = outputFolder.members();
            for (int j = 0, m = members.length; j < m; j++) {
              IResource member = members[j];
              if (!member.isDerived()) {
                member.accept(
                    new IResourceVisitor() {
                      public boolean visit(IResource resource) throws CoreException {
                        resource.setDerived(true, null);
                        return resource.getType() != IResource.FILE;
                      }
                    });
              }
              member.delete(IResource.FORCE, null);
            }
          }
          this.notifier.checkCancel();
          if (copyBack) copyExtraResourcesBack(sourceLocation, true);
        } else {
          boolean isOutputFolder = sourceLocation.sourceFolder.equals(sourceLocation.binaryFolder);
          final char[][] exclusionPatterns =
              isOutputFolder
                  ? sourceLocation.exclusionPatterns
                  : null; // ignore exclusionPatterns if output folder == another source folder...
                          // not this one
          final char[][] inclusionPatterns =
              isOutputFolder
                  ? sourceLocation.inclusionPatterns
                  : null; // ignore inclusionPatterns if output folder == another source folder...
                          // not this one
          sourceLocation.binaryFolder.accept(
              new IResourceProxyVisitor() {
                public boolean visit(IResourceProxy proxy) throws CoreException {
                  if (proxy.getType() == IResource.FILE) {
                    if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(
                        proxy.getName())) {
                      IResource resource = proxy.requestResource();
                      if (exclusionPatterns != null || inclusionPatterns != null)
                        if (Util.isExcluded(
                            resource.getFullPath(), inclusionPatterns, exclusionPatterns, false))
                          return false;
                      if (!resource.isDerived()) resource.setDerived(true, null);
                      resource.delete(IResource.FORCE, null);
                    }
                    return false;
                  }
                  if (exclusionPatterns != null
                      && inclusionPatterns
                          == null) // must walk children if inclusionPatterns != null
                  if (Util.isExcluded(proxy.requestFullPath(), null, exclusionPatterns, true))
                      return false;
                  BatchImageBuilder.this.notifier.checkCancel();
                  return true;
                }
              },
              IResource.NONE);
          this.notifier.checkCancel();
        }
        this.notifier.checkCancel();
      }
    } else if (copyBack) {
      for (int i = 0, l = this.sourceLocations.length; i < l; i++) {
        ClasspathMultiDirectory sourceLocation = this.sourceLocations[i];
        if (sourceLocation.hasIndependentOutputFolder)
          copyExtraResourcesBack(sourceLocation, false);
        this.notifier.checkCancel();
      }
    }
    // GROOVY start
    LanguageSupportFactory.getEventHandler()
        .handle(this.javaBuilder.javaProject, "cleanOutputFolders");
    // GROOVY end
  }
示例#11
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;
  }
示例#12
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;
  }
示例#13
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;
  }