Пример #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);
    }
  }
 @NotNull
 @Override
 public List<DeploymentSource> createArtifactDeploymentSources(
     @NotNull Project project, @NotNull Collection<? extends Artifact> artifacts) {
   List<DeploymentSource> sources = new ArrayList<>();
   ArtifactPointerManager pointerManager = ArtifactPointerManager.getInstance(project);
   for (Artifact artifact : artifacts) {
     sources.add(createArtifactDeploymentSource(pointerManager.createPointer(artifact)));
   }
   return sources;
 }
Пример #3
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;
    }
  }
 @NotNull
 @Override
 public List<DeploymentSource> createArtifactDeploymentSources(
     Project project, ArtifactType... artifactTypes) {
   if (project.isDefault()) return Collections.emptyList();
   Artifact[] artifacts = ArtifactManager.getInstance(project).getArtifacts();
   List<Artifact> supportedArtifacts = new ArrayList<>();
   Set<ArtifactType> typeSet = ContainerUtil.set(artifactTypes);
   for (Artifact artifact : artifacts) {
     if (typeSet.contains(artifact.getArtifactType())) {
       supportedArtifacts.add(artifact);
     }
   }
   return createArtifactDeploymentSources(project, supportedArtifacts);
 }