Search in sources :

Example 1 with ArtifactPackagingElement

use of com.intellij.packaging.impl.elements.ArtifactPackagingElement in project intellij-community by JetBrains.

the class ArtifactsGenerator method createArtifactTarget.

private Target createArtifactTarget(Artifact artifact) {
    final StringBuilder depends = new StringBuilder(INIT_ARTIFACTS_TARGET);
    ArtifactUtil.processRecursivelySkippingIncludedArtifacts(artifact, packagingElement -> {
        if (packagingElement instanceof ArtifactPackagingElement) {
            final Artifact included = ((ArtifactPackagingElement) packagingElement).findArtifact(myResolvingContext);
            if (included != null) {
                if (depends.length() > 0)
                    depends.append(", ");
                depends.append(myContext.getTargetName(included));
            }
        } else if (packagingElement instanceof ModuleOutputPackagingElement) {
            final Module module = ((ModuleOutputPackagingElement) packagingElement).findModule(myResolvingContext);
            if (module != null) {
                if (depends.length() > 0)
                    depends.append(", ");
                depends.append(BuildProperties.getCompileTargetName(module.getName()));
            }
        }
        return true;
    }, myResolvingContext);
    final Couple<String> xmlNs = getArtifactXmlNs(artifact.getArtifactType());
    final Target artifactTarget = new Target(myContext.getTargetName(artifact), depends.toString(), "Build '" + artifact.getName() + "' artifact", null, xmlNs != null ? xmlNs.first : null, xmlNs != null ? xmlNs.second : null);
    if (myContext.shouldBuildIntoTempDirectory(artifact)) {
        final String outputDirectory = BuildProperties.propertyRelativePath(ArtifactAntGenerationContextImpl.ARTIFACTS_TEMP_DIR_PROPERTY, FileUtil.sanitizeFileName(artifact.getName()));
        artifactTarget.add(new Property(myContext.getArtifactOutputProperty(artifact), outputDirectory));
    }
    final String outputPath = BuildProperties.propertyRef(myContext.getArtifactOutputProperty(artifact));
    artifactTarget.add(new Mkdir(outputPath));
    generateTasksForArtifacts(artifact, artifactTarget, true);
    final DirectoryAntCopyInstructionCreator creator = new DirectoryAntCopyInstructionCreator(outputPath);
    List<Generator> copyInstructions = new ArrayList<>();
    if (needAntArtifactInstructions(artifact.getArtifactType())) {
        copyInstructions.addAll(artifact.getRootElement().computeAntInstructions(myResolvingContext, creator, myContext, artifact.getArtifactType()));
    }
    for (Generator generator : myContext.getAndClearBeforeCurrentArtifact()) {
        artifactTarget.add(generator);
    }
    for (Generator tag : copyInstructions) {
        artifactTarget.add(tag);
    }
    generateTasksForArtifacts(artifact, artifactTarget, false);
    return artifactTarget;
}
Also used : ArtifactPackagingElement(com.intellij.packaging.impl.elements.ArtifactPackagingElement) ArrayList(java.util.ArrayList) Artifact(com.intellij.packaging.artifacts.Artifact) Module(com.intellij.openapi.module.Module) ModuleOutputPackagingElement(com.intellij.packaging.impl.elements.ModuleOutputPackagingElement)

Example 2 with ArtifactPackagingElement

use of com.intellij.packaging.impl.elements.ArtifactPackagingElement in project intellij-community by JetBrains.

the class InlineArtifactAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final LayoutTreeComponent treeComponent = myEditor.getLayoutTreeComponent();
    final LayoutTreeSelection selection = treeComponent.getSelection();
    final PackagingElement<?> element = selection.getElementIfSingle();
    final PackagingElementNode<?> node = selection.getNodeIfSingle();
    if (node == null || !(element instanceof ArtifactPackagingElement))
        return;
    final CompositePackagingElement<?> parent = node.getParentElement(element);
    final CompositePackagingElementNode parentNode = node.getParentNode();
    if (parent == null || parentNode == null) {
        return;
    }
    if (!treeComponent.checkCanModifyChildren(parent, parentNode, Collections.singletonList(node)))
        return;
    treeComponent.editLayout(() -> {
        parent.removeChild(element);
        final ArtifactEditorContext context = myEditor.getContext();
        final Artifact artifact = ((ArtifactPackagingElement) element).findArtifact(context);
        if (artifact != null) {
            final CompositePackagingElement<?> rootElement = artifact.getRootElement();
            if (rootElement instanceof ArtifactRootElement<?>) {
                for (PackagingElement<?> child : rootElement.getChildren()) {
                    parent.addOrFindChild(ArtifactUtil.copyWithChildren(child, context.getProject()));
                }
            } else {
                parent.addOrFindChild(ArtifactUtil.copyWithChildren(rootElement, context.getProject()));
            }
        }
    });
    treeComponent.rebuildTree();
}
Also used : LayoutTreeSelection(com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeSelection) ArtifactPackagingElement(com.intellij.packaging.impl.elements.ArtifactPackagingElement) ArtifactRootElement(com.intellij.packaging.elements.ArtifactRootElement) CompositePackagingElementNode(com.intellij.openapi.roots.ui.configuration.artifacts.nodes.CompositePackagingElementNode) ArtifactEditorContext(com.intellij.packaging.ui.ArtifactEditorContext) Artifact(com.intellij.packaging.artifacts.Artifact) LayoutTreeComponent(com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeComponent)

Example 3 with ArtifactPackagingElement

use of com.intellij.packaging.impl.elements.ArtifactPackagingElement in project intellij-community by JetBrains.

the class ExtractArtifactAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final LayoutTreeComponent treeComponent = myArtifactEditor.getLayoutTreeComponent();
    final LayoutTreeSelection selection = treeComponent.getSelection();
    final CompositePackagingElement<?> parent = selection.getCommonParentElement();
    if (parent == null)
        return;
    final PackagingElementNode<?> parentNode = selection.getNodes().get(0).getParentNode();
    if (parentNode == null)
        return;
    if (!treeComponent.checkCanModifyChildren(parent, parentNode, selection.getNodes())) {
        return;
    }
    final Collection<? extends PackagingElement> selectedElements = selection.getElements();
    String initialName = "artifact";
    if (selectedElements.size() == 1) {
        initialName = PathUtil.suggestFileName(ContainerUtil.getFirstItem(selectedElements, null).createPresentation(myArtifactEditor.getContext()).getPresentableName());
    }
    IExtractArtifactDialog dialog = showDialog(treeComponent, initialName);
    if (dialog == null)
        return;
    final Project project = myArtifactEditor.getContext().getProject();
    final ModifiableArtifactModel model = myArtifactEditor.getContext().getOrCreateModifiableArtifactModel();
    final ModifiableArtifact artifact = model.addArtifact(dialog.getArtifactName(), dialog.getArtifactType());
    treeComponent.editLayout(() -> {
        for (PackagingElement<?> element : selectedElements) {
            artifact.getRootElement().addOrFindChild(ArtifactUtil.copyWithChildren(element, project));
        }
        for (PackagingElement element : selectedElements) {
            parent.removeChild(element);
        }
        parent.addOrFindChild(new ArtifactPackagingElement(project, ArtifactPointerManager.getInstance(project).createPointer(artifact, myArtifactEditor.getContext().getArtifactModel())));
    });
    treeComponent.rebuildTree();
}
Also used : LayoutTreeSelection(com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeSelection) ArtifactPackagingElement(com.intellij.packaging.impl.elements.ArtifactPackagingElement) ModifiableArtifact(com.intellij.packaging.artifacts.ModifiableArtifact) ArtifactPackagingElement(com.intellij.packaging.impl.elements.ArtifactPackagingElement) PackagingElement(com.intellij.packaging.elements.PackagingElement) CompositePackagingElement(com.intellij.packaging.elements.CompositePackagingElement) LayoutTreeComponent(com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeComponent) Project(com.intellij.openapi.project.Project) ModifiableArtifactModel(com.intellij.packaging.artifacts.ModifiableArtifactModel)

Example 4 with ArtifactPackagingElement

use of com.intellij.packaging.impl.elements.ArtifactPackagingElement in project intellij-community by JetBrains.

the class InlineArtifactAction method update.

@Override
public void update(AnActionEvent e) {
    final LayoutTreeSelection selection = myEditor.getLayoutTreeComponent().getSelection();
    final PackagingElementNode<?> node = selection.getNodeIfSingle();
    PackagingElement<?> element = selection.getElementIfSingle();
    e.getPresentation().setEnabled(element instanceof ArtifactPackagingElement && node != null && node.getParentElement(element) != null);
}
Also used : LayoutTreeSelection(com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeSelection) ArtifactPackagingElement(com.intellij.packaging.impl.elements.ArtifactPackagingElement)

Example 5 with ArtifactPackagingElement

use of com.intellij.packaging.impl.elements.ArtifactPackagingElement in project intellij-community by JetBrains.

the class ArtifactExternalDependenciesImporterImpl method applyChanges.

@Override
public void applyChanges(ModifiableArtifactModel artifactModel, final PackagingElementResolvingContext context) {
    myManifestFiles.saveManifestFiles();
    final List<Pair<? extends CompositePackagingElement<?>, List<PackagingElement<?>>>> elementsToInclude = new ArrayList<>();
    for (Artifact artifact : artifactModel.getArtifacts()) {
        ArtifactUtil.processPackagingElements(artifact, ArtifactElementType.ARTIFACT_ELEMENT_TYPE, new PackagingElementProcessor<ArtifactPackagingElement>() {

            @Override
            public boolean process(@NotNull ArtifactPackagingElement artifactPackagingElement, @NotNull PackagingElementPath path) {
                final Artifact included = artifactPackagingElement.findArtifact(context);
                final CompositePackagingElement<?> parent = path.getLastParent();
                if (parent != null && included != null) {
                    final List<PackagingElement<?>> elements = myExternalDependencies.get(included);
                    if (elements != null) {
                        elementsToInclude.add(Pair.create(parent, elements));
                    }
                }
                return true;
            }
        }, context, false);
    }
    for (Pair<? extends CompositePackagingElement<?>, List<PackagingElement<?>>> pair : elementsToInclude) {
        pair.getFirst().addOrFindChildren(pair.getSecond());
    }
}
Also used : ArtifactPackagingElement(com.intellij.packaging.impl.elements.ArtifactPackagingElement) PackagingElementPath(com.intellij.packaging.impl.artifacts.PackagingElementPath) ArrayList(java.util.ArrayList) CompositePackagingElement(com.intellij.packaging.elements.CompositePackagingElement) ArtifactPackagingElement(com.intellij.packaging.impl.elements.ArtifactPackagingElement) PackagingElement(com.intellij.packaging.elements.PackagingElement) CompositePackagingElement(com.intellij.packaging.elements.CompositePackagingElement) ArrayList(java.util.ArrayList) List(java.util.List) Artifact(com.intellij.packaging.artifacts.Artifact) Pair(com.intellij.openapi.util.Pair)

Aggregations

ArtifactPackagingElement (com.intellij.packaging.impl.elements.ArtifactPackagingElement)5 LayoutTreeSelection (com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeSelection)3 Artifact (com.intellij.packaging.artifacts.Artifact)3 LayoutTreeComponent (com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeComponent)2 CompositePackagingElement (com.intellij.packaging.elements.CompositePackagingElement)2 PackagingElement (com.intellij.packaging.elements.PackagingElement)2 ArrayList (java.util.ArrayList)2 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 CompositePackagingElementNode (com.intellij.openapi.roots.ui.configuration.artifacts.nodes.CompositePackagingElementNode)1 Pair (com.intellij.openapi.util.Pair)1 ModifiableArtifact (com.intellij.packaging.artifacts.ModifiableArtifact)1 ModifiableArtifactModel (com.intellij.packaging.artifacts.ModifiableArtifactModel)1 ArtifactRootElement (com.intellij.packaging.elements.ArtifactRootElement)1 PackagingElementPath (com.intellij.packaging.impl.artifacts.PackagingElementPath)1 ModuleOutputPackagingElement (com.intellij.packaging.impl.elements.ModuleOutputPackagingElement)1 ArtifactEditorContext (com.intellij.packaging.ui.ArtifactEditorContext)1 List (java.util.List)1