Пример #1
0
 @Override
 public void addElementsToDirectory(
     @NotNull Artifact artifact,
     @NotNull String relativePath,
     @NotNull Collection<? extends PackagingElement<?>> elements) {
   final ModifiableArtifactModel model = createModifiableModel();
   final CompositePackagingElement<?> root =
       model.getOrCreateModifiableArtifact(artifact).getRootElement();
   PackagingElementFactory.getInstance()
       .getOrCreateDirectory(root, relativePath)
       .addOrFindChildren(elements);
   new WriteAction() {
     @Override
     protected void run(@NotNull final Result result) {
       model.commit();
     }
   }.execute();
 }
Пример #2
0
  private <T> PackagingElement<T> deserializeElement(Element element)
      throws UnknownPackagingElementTypeException {
    final String id = element.getAttributeValue(TYPE_ID_ATTRIBUTE);
    PackagingElementType<?> type = PackagingElementFactory.getInstance().findElementType(id);
    if (type == null) {
      throw new UnknownPackagingElementTypeException(id);
    }

    PackagingElement<T> packagingElement = (PackagingElement<T>) type.createEmpty(myProject);
    T state = packagingElement.getState();
    if (state != null) {
      XmlSerializer.deserializeInto(state, element);
      packagingElement.loadState(state);
    }
    final List children = element.getChildren(PACKAGING_ELEMENT_NAME);
    //noinspection unchecked
    for (Element child : (List<? extends Element>) children) {
      ((CompositePackagingElement<?>) packagingElement).addOrFindChild(deserializeElement(child));
    }
    return packagingElement;
  }