コード例 #1
0
  private ArtifactImpl loadArtifact(ArtifactState state) {
    ArtifactType type = ArtifactType.findById(state.getArtifactType());
    if (type == null) {
      return createInvalidArtifact(state, "Unknown artifact type: " + state.getArtifactType());
    }

    final Element element = state.getRootElement();
    final String artifactName = state.getName();
    final CompositePackagingElement<?> rootElement;
    if (element != null) {
      try {
        rootElement = (CompositePackagingElement<?>) deserializeElement(element);
      } catch (UnknownPackagingElementTypeException e) {
        return createInvalidArtifact(state, "Unknown element: " + e.getTypeId());
      }
    } else {
      rootElement = type.createRootElement(artifactName);
    }

    final ArtifactImpl artifact =
        new ArtifactImpl(
            artifactName, type, state.isBuildOnMake(), rootElement, state.getOutputPath());
    final List<ArtifactPropertiesState> propertiesList = state.getPropertiesList();
    for (ArtifactPropertiesState propertiesState : propertiesList) {
      final ArtifactPropertiesProvider provider =
          ArtifactPropertiesProvider.findById(propertiesState.getId());
      if (provider != null) {
        deserializeProperties(artifact.getProperties(provider), propertiesState);
      } else {
        return createInvalidArtifact(
            state, "Unknown artifact properties: " + propertiesState.getId());
      }
    }
    return artifact;
  }
コード例 #2
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);
    }
  }