Exemplo n.º 1
0
  private void doCommit(ArtifactModelImpl artifactModel) {
    boolean hasChanges;
    LOG.assertTrue(!myInsideCommit, "Recursive commit");
    myInsideCommit = true;
    try {

      final List<ArtifactImpl> allArtifacts = artifactModel.getOriginalArtifacts();

      final Set<ArtifactImpl> removed = new THashSet<ArtifactImpl>(myModel.myArtifactsList);
      final List<ArtifactImpl> added = new ArrayList<ArtifactImpl>();
      final List<Pair<ArtifactImpl, String>> changed = new ArrayList<Pair<ArtifactImpl, String>>();

      for (ArtifactImpl artifact : allArtifacts) {
        final boolean isAdded = !removed.remove(artifact);
        final ArtifactImpl modifiableCopy = artifactModel.getModifiableCopy(artifact);
        if (isAdded) {
          added.add(artifact);
        } else if (modifiableCopy != null && !modifiableCopy.equals(artifact)) {
          final String oldName = artifact.getName();
          artifact.copyFrom(modifiableCopy);
          changed.add(Pair.create(artifact, oldName));
        }
      }

      myModel.setArtifactsList(allArtifacts);
      myModificationTracker.incModificationCount();
      final ArtifactListener publisher = myProject.getMessageBus().syncPublisher(TOPIC);
      hasChanges = !removed.isEmpty() || !added.isEmpty() || !changed.isEmpty();
      ProjectRootManagerEx.getInstanceEx(myProject)
          .mergeRootsChangesDuring(
              new Runnable() {
                @Override
                public void run() {
                  for (ArtifactImpl artifact : removed) {
                    publisher.artifactRemoved(artifact);
                  }
                  // it's important to send 'removed' events before 'added'. Otherwise when
                  // artifacts are reloaded from xml artifact pointers will be damaged
                  for (ArtifactImpl artifact : added) {
                    publisher.artifactAdded(artifact);
                  }
                  for (Pair<ArtifactImpl, String> pair : changed) {
                    publisher.artifactChanged(pair.getFirst(), pair.getSecond());
                  }
                }
              });
    } finally {
      myInsideCommit = false;
    }
    updateWatchedRoots();
    if (hasChanges) {
      BuildManager.getInstance().clearState(myProject);
    }
  }
 public void dropCaches() {
   myTracker.incModificationCount();
 }