Esempio n. 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;
  }
Esempio n. 2
0
 @Nullable
 private static <S> ArtifactPropertiesState serializeProperties(
     ArtifactPropertiesProvider provider, ArtifactProperties<S> properties) {
   final ArtifactPropertiesState state = new ArtifactPropertiesState();
   state.setId(provider.getId());
   final Element options = new Element("options");
   XmlSerializer.serializeInto(
       properties.getState(), options, new SkipDefaultValuesSerializationFilters());
   if (options.getContent().isEmpty() && options.getAttributes().isEmpty()) return null;
   state.setOptions(options);
   return state;
 }