Search in sources :

Example 1 with PackagingElement

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

the class ArtifactBySourceFileFinderImpl method computeFileToArtifactsMap.

private MultiValuesMap<VirtualFile, Artifact> computeFileToArtifactsMap() {
    final MultiValuesMap<VirtualFile, Artifact> result = new MultiValuesMap<>();
    final ArtifactManager artifactManager = ArtifactManager.getInstance(myProject);
    for (final Artifact artifact : artifactManager.getArtifacts()) {
        final PackagingElementResolvingContext context = artifactManager.getResolvingContext();
        ArtifactUtil.processPackagingElements(artifact, null, new PackagingElementProcessor<PackagingElement<?>>() {

            @Override
            public boolean process(@NotNull PackagingElement<?> element, @NotNull PackagingElementPath path) {
                if (element instanceof FileOrDirectoryCopyPackagingElement<?>) {
                    final VirtualFile root = ((FileOrDirectoryCopyPackagingElement) element).findFile();
                    if (root != null) {
                        result.put(root, artifact);
                    }
                } else if (element instanceof ModuleOutputPackagingElement) {
                    for (VirtualFile sourceRoot : ((ModuleOutputPackagingElement) element).getSourceRoots(context)) {
                        result.put(sourceRoot, artifact);
                    }
                }
                return true;
            }
        }, context, true);
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MultiValuesMap(com.intellij.openapi.util.MultiValuesMap) PackagingElementResolvingContext(com.intellij.packaging.elements.PackagingElementResolvingContext) PackagingElement(com.intellij.packaging.elements.PackagingElement) FileOrDirectoryCopyPackagingElement(com.intellij.packaging.impl.elements.FileOrDirectoryCopyPackagingElement) ModuleOutputPackagingElement(com.intellij.packaging.impl.elements.ModuleOutputPackagingElement) Artifact(com.intellij.packaging.artifacts.Artifact) ArtifactManager(com.intellij.packaging.artifacts.ArtifactManager) ModuleOutputPackagingElement(com.intellij.packaging.impl.elements.ModuleOutputPackagingElement)

Example 2 with PackagingElement

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

the class ExtractedDirectoryElementType method chooseAndCreate.

@NotNull
public List<? extends PackagingElement<?>> chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact, @NotNull CompositePackagingElement<?> parent) {
    final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, true, false, true, true) {

        @Override
        public boolean isFileSelectable(VirtualFile file) {
            if (file.isInLocalFileSystem() && file.isDirectory())
                return false;
            return super.isFileSelectable(file);
        }
    };
    final VirtualFile[] files = FileChooser.chooseFiles(descriptor, context.getProject(), null);
    final List<PackagingElement<?>> list = new ArrayList<>();
    final PackagingElementFactory factory = PackagingElementFactory.getInstance();
    for (VirtualFile file : files) {
        list.add(factory.createExtractedDirectory(file));
    }
    return list;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) ArrayList(java.util.ArrayList) PackagingElement(com.intellij.packaging.elements.PackagingElement) CompositePackagingElement(com.intellij.packaging.elements.CompositePackagingElement) PackagingElementFactory(com.intellij.packaging.elements.PackagingElementFactory) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with PackagingElement

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

the class LibraryPackagingElement method getSubstitution.

public List<? extends PackagingElement<?>> getSubstitution(@NotNull PackagingElementResolvingContext context, @NotNull ArtifactType artifactType) {
    final Library library = findLibrary(context);
    if (library != null) {
        final VirtualFile[] files = library.getFiles(OrderRootType.CLASSES);
        final List<PackagingElement<?>> elements = new ArrayList<>();
        for (VirtualFile file : files) {
            String localPath = PathUtil.getLocalPath(file);
            if (localPath != null) {
                final String path = FileUtil.toSystemIndependentName(localPath);
                elements.add(file.isDirectory() && file.isInLocalFileSystem() ? new DirectoryCopyPackagingElement(path) : new FileCopyPackagingElement(path));
            }
        }
        return elements;
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) PackagingElement(com.intellij.packaging.elements.PackagingElement) ComplexPackagingElement(com.intellij.packaging.elements.ComplexPackagingElement) Library(com.intellij.openapi.roots.libraries.Library)

Example 4 with PackagingElement

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

the class ModuleOutputElementTypeBase method chooseAndCreate.

@NotNull
public List<? extends PackagingElement<?>> chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact, @NotNull CompositePackagingElement<?> parent) {
    List<Module> suitableModules = getSuitableModules(context);
    List<Module> selected = context.chooseModules(suitableModules, ProjectBundle.message("dialog.title.packaging.choose.module"));
    final List<PackagingElement<?>> elements = new ArrayList<>();
    final ModulePointerManager pointerManager = ModulePointerManager.getInstance(context.getProject());
    for (Module module : selected) {
        elements.add(createElement(context.getProject(), pointerManager.create(module)));
    }
    return elements;
}
Also used : ArrayList(java.util.ArrayList) PackagingElement(com.intellij.packaging.elements.PackagingElement) CompositePackagingElement(com.intellij.packaging.elements.CompositePackagingElement) ModulePointerManager(com.intellij.openapi.module.ModulePointerManager) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with PackagingElement

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

the class SurroundElementWithAction 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 CompositePackagingElementType<?>[] types = PackagingElementFactory.getInstance().getCompositeElementTypes();
    final List<PackagingElement<?>> selected = selection.getElements();
    if (types.length == 1) {
        surroundWith(types[0], parent, selected, treeComponent);
    } else {
        JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<CompositePackagingElementType>("Surround With...", types) {

            @Override
            public Icon getIconFor(CompositePackagingElementType aValue) {
                return aValue.getCreateElementIcon();
            }

            @NotNull
            @Override
            public String getTextFor(CompositePackagingElementType value) {
                return value.getPresentableName();
            }

            @Override
            public PopupStep onChosen(final CompositePackagingElementType selectedValue, boolean finalChoice) {
                return doFinalStep(() -> surroundWith(selectedValue, parent, selected, treeComponent));
            }
        }).showInBestPositionFor(e.getDataContext());
    }
}
Also used : LayoutTreeSelection(com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeSelection) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) CompositePackagingElementType(com.intellij.packaging.elements.CompositePackagingElementType) PackagingElement(com.intellij.packaging.elements.PackagingElement) CompositePackagingElement(com.intellij.packaging.elements.CompositePackagingElement) LayoutTreeComponent(com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeComponent)

Aggregations

PackagingElement (com.intellij.packaging.elements.PackagingElement)18 CompositePackagingElement (com.intellij.packaging.elements.CompositePackagingElement)13 ArrayList (java.util.ArrayList)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 Artifact (com.intellij.packaging.artifacts.Artifact)4 PackagingElementPath (com.intellij.packaging.impl.artifacts.PackagingElementPath)4 DirectoryPackagingElement (com.intellij.packaging.impl.elements.DirectoryPackagingElement)4 NotNull (org.jetbrains.annotations.NotNull)4 ArtifactPackagingElement (com.intellij.packaging.impl.elements.ArtifactPackagingElement)3 PackagingSourceItem (com.intellij.packaging.ui.PackagingSourceItem)3 Module (com.intellij.openapi.module.Module)2 Project (com.intellij.openapi.project.Project)2 LayoutTreeComponent (com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeComponent)2 LayoutTreeSelection (com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeSelection)2 CompositePackagingElementNode (com.intellij.openapi.roots.ui.configuration.artifacts.nodes.CompositePackagingElementNode)2 PackagingElementNode (com.intellij.openapi.roots.ui.configuration.artifacts.nodes.PackagingElementNode)2 ArtifactType (com.intellij.packaging.artifacts.ArtifactType)2 PackagingElementFactory (com.intellij.packaging.elements.PackagingElementFactory)2 FileCopyPackagingElement (com.intellij.packaging.impl.elements.FileCopyPackagingElement)2 ModuleOutputPackagingElement (com.intellij.packaging.impl.elements.ModuleOutputPackagingElement)2