protected void scheduleRemoveProjectJob(final IProject project) {
    final ToBeBuilt toBeBuilt =
        getToBeBuiltComputer().removeProject(project, new NullProgressMonitor());
    if (toBeBuilt.getToBeDeleted().isEmpty() && toBeBuilt.getToBeUpdated().isEmpty()) return;
    new Job(
        Messages.ProjectOpenedOrClosedListener_RemovingProject
            + project.getName()
            + Messages.ProjectOpenedOrClosedListener_FromIndex) {
      {
        setRule(workspace.getRoot());
      }

      @Override
      public boolean belongsTo(Object family) {
        return family == ResourcesPlugin.FAMILY_AUTO_BUILD;
      }

      @Override
      protected IStatus run(IProgressMonitor monitor) {
        try {
          new WorkspaceModifyOperation(getRule()) {
            @Override
            protected void execute(IProgressMonitor monitor)
                throws CoreException, InvocationTargetException, InterruptedException {
              SubMonitor progress = SubMonitor.convert(monitor, 1);
              try {
                ResourceSet resourceSet = getResourceSetProvider().get(project);
                resourceSet
                    .getLoadOptions()
                    .put(ResourceDescriptionsProvider.NAMED_BUILDER_SCOPE, Boolean.TRUE);
                if (resourceSet instanceof ResourceSetImpl) {
                  ((ResourceSetImpl) resourceSet)
                      .setURIResourceMap(Maps.<URI, Resource>newHashMap());
                }
                BuildData buildData =
                    new BuildData(project.getName(), resourceSet, toBeBuilt, queuedBuildData);
                getBuilderState().update(buildData, progress.newChild(1));

                resourceSet.getResources().clear();
                resourceSet.eAdapters().clear();
              } finally {
                if (monitor != null) monitor.done();
              }
            }
          }.run(monitor);
        } catch (InvocationTargetException e) {
          log.error(e.getMessage(), e);
        } catch (InterruptedException e) {
          log.error(e.getMessage(), e);
        }
        return Status.OK_STATUS;
      }
    }.schedule();
  }
 public boolean removeStorage(
     final IProgressMonitor monitor, final ToBeBuilt toBeBuilt, IStorage storage) {
   if (!isHandled(storage)) return true;
   URI uri = getUri(storage);
   if (uri != null) {
     toBeBuilt.getToBeDeleted().add(uri);
   }
   return true;
 }
 public ToBeBuilt removeProject(IProject project, IProgressMonitor monitor) {
   SubMonitor progress =
       SubMonitor.convert(monitor, Iterables.size(builderState.getAllResourceDescriptions()));
   ToBeBuilt result = new ToBeBuilt();
   Iterable<IResourceDescription> allResourceDescriptions =
       builderState.getAllResourceDescriptions();
   for (IResourceDescription description : allResourceDescriptions) {
     Iterable<Pair<IStorage, IProject>> storages = mapper.getStorages(description.getURI());
     boolean onlyOnThisProject = true;
     Iterator<Pair<IStorage, IProject>> iterator = storages.iterator();
     while (iterator.hasNext() && onlyOnThisProject) {
       Pair<IStorage, IProject> storage2Project = iterator.next();
       onlyOnThisProject = project.equals(storage2Project.getSecond());
     }
     if (onlyOnThisProject) result.getToBeDeleted().add(description.getURI());
     progress.worked(1);
   }
   return result;
 }
 public ToBeBuilt updateProjectNewResourcesOnly(IProject project, IProgressMonitor monitor)
     throws CoreException {
   SubMonitor progress =
       SubMonitor.convert(monitor, Messages.ToBeBuiltComputer_CollectingReosurces, 1);
   progress.subTask(Messages.ToBeBuiltComputer_CollectingReosurces);
   ToBeBuilt toBeBuilt = updateProject(project, progress.newChild(1));
   Iterable<URI> existingURIs =
       Iterables.transform(
           builderState.getAllResourceDescriptions(),
           new Function<IResourceDescription, URI>() {
             public URI apply(IResourceDescription from) {
               return from.getURI();
             }
           });
   for (URI existingURI : existingURIs) {
     toBeBuilt.getToBeDeleted().remove(existingURI);
     toBeBuilt.getToBeUpdated().remove(existingURI);
   }
   return toBeBuilt;
 }
Example #5
0
  /**
   * @param monitor the progress monitor to use for reporting progress to the user. It is the
   *     caller's responsibility to call done() on the given monitor. Accepts null, indicating that
   *     no progress should be reported and that the operation cannot be cancelled.
   */
  protected void doClean(ToBeBuilt toBeBuilt, IProgressMonitor monitor) throws CoreException {
    SubMonitor progress = SubMonitor.convert(monitor, 2);
    ImmutableList<Delta> deltas =
        builderState.clean(toBeBuilt.getToBeDeleted(), progress.newChild(1));
    if (participant != null) {
      Set<URI> sourceURIs =
          new SourceLevelURICache()
              .getSourcesFrom(toBeBuilt.getToBeDeleted(), resourceServiceProvideRegistry);

      participant.build(
          new BuildContext(
              this,
              getResourceSetProvider().get(getProject()),
              deltas,
              sourceURIs,
              BuildType.CLEAN),
          progress.newChild(1));
    } else {
      progress.worked(1);
    }
  }