Example #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);
    }
  }
Example #2
0
  @Override
  public void loadState(ArtifactManagerState managerState) {
    final List<ArtifactImpl> artifacts = new ArrayList<ArtifactImpl>();
    for (ArtifactState state : managerState.getArtifacts()) {
      artifacts.add(loadArtifact(state));
    }

    if (myLoaded) {
      final ArtifactModelImpl model = new ArtifactModelImpl(this, artifacts);
      doCommit(model);
    } else {
      myModel.setArtifactsList(artifacts);
      myLoaded = true;
    }
  }
Example #3
0
 @Override
 @NotNull
 public Artifact getOriginalArtifact(@NotNull Artifact artifact) {
   return myModel.getOriginalArtifact(artifact);
 }
Example #4
0
 @Override
 public Artifact findArtifact(@NotNull String name) {
   return myModel.findArtifact(name);
 }
Example #5
0
 @Override
 @NotNull
 public Artifact[] getArtifacts() {
   return myModel.getArtifacts();
 }
Example #6
0
 @Override
 public Artifact[] getSortedArtifacts() {
   return myModel.getSortedArtifacts();
 }
Example #7
0
 @Override
 public List<? extends Artifact> getAllArtifactsIncludingInvalid() {
   return myModel.getAllArtifactsIncludingInvalid();
 }
Example #8
0
 @Override
 @NotNull
 public Collection<? extends Artifact> getArtifactsByType(@NotNull ArtifactType type) {
   return myModel.getArtifactsByType(type);
 }