Search in sources :

Example 6 with PackagingSourceItem

use of com.intellij.packaging.ui.PackagingSourceItem in project intellij-community by JetBrains.

the class PutSourceItemIntoDefaultLocationAction method update.

@Override
public void update(AnActionEvent e) {
    final List<PackagingSourceItem> items = mySourceItemsTree.getSelectedItems();
    boolean enabled = false;
    final Presentation presentation = e.getPresentation();
    if (!items.isEmpty()) {
        enabled = true;
        Set<String> paths = new HashSet<>();
        for (PackagingSourceItem item : items) {
            final String path = getDefaultPath(item);
            if (path == null) {
                enabled = false;
                break;
            }
            paths.add(StringUtil.trimStart(StringUtil.trimEnd(path, "/"), "/"));
        }
        presentation.setText("Put into " + getTargetLocationText(paths));
    }
    presentation.setVisible(enabled);
    presentation.setEnabled(enabled);
}
Also used : PackagingSourceItem(com.intellij.packaging.ui.PackagingSourceItem) Presentation(com.intellij.openapi.actionSystem.Presentation) HashSet(java.util.HashSet)

Example 7 with PackagingSourceItem

use of com.intellij.packaging.ui.PackagingSourceItem in project intellij-community by JetBrains.

the class PutSourceItemIntoParentAndLinkViaManifestAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final List<PackagingSourceItem> items = mySourceItemsTree.getSelectedItems();
    ParentElementsInfo parentsInfo = findParentAndGrandParent(myArtifactEditor.getArtifact());
    if (parentsInfo == null) {
        return;
    }
    final Artifact artifact = parentsInfo.getGrandparentArtifact();
    final ArtifactEditorContext context = myArtifactEditor.getContext();
    //todo[nik] improve
    final Runnable emptyRunnable = EmptyRunnable.getInstance();
    context.editLayout(artifact, emptyRunnable);
    context.editLayout(parentsInfo.getParentArtifact(), emptyRunnable);
    //find elements under modifiable root
    parentsInfo = findParentAndGrandParent(myArtifactEditor.getArtifact());
    if (parentsInfo == null) {
        return;
    }
    final CompositePackagingElement<?> grandParent = parentsInfo.getGrandparentElement();
    final List<String> classpath = new ArrayList<>();
    context.editLayout(artifact, () -> {
        for (PackagingSourceItem item : items) {
            final List<? extends PackagingElement<?>> elements = item.createElements(context);
            grandParent.addOrFindChildren(elements);
            classpath.addAll(ManifestFileUtil.getClasspathForElements(elements, context, artifact.getArtifactType()));
        }
    });
    final ArtifactEditor parentArtifactEditor = context.getOrCreateEditor(parentsInfo.getParentArtifact());
    parentArtifactEditor.addToClasspath(parentsInfo.getParentElement(), classpath);
    ((ArtifactEditorImpl) context.getOrCreateEditor(parentsInfo.getGrandparentArtifact())).rebuildTries();
}
Also used : PackagingSourceItem(com.intellij.packaging.ui.PackagingSourceItem) ArtifactEditor(com.intellij.packaging.ui.ArtifactEditor) ArrayList(java.util.ArrayList) Artifact(com.intellij.packaging.artifacts.Artifact) EmptyRunnable(com.intellij.openapi.util.EmptyRunnable) ArtifactEditorImpl(com.intellij.openapi.roots.ui.configuration.artifacts.ArtifactEditorImpl) ArtifactEditorContext(com.intellij.packaging.ui.ArtifactEditorContext)

Example 8 with PackagingSourceItem

use of com.intellij.packaging.ui.PackagingSourceItem in project intellij-community by JetBrains.

the class ModulesAndLibrariesSourceItemsProvider method createClasspathItems.

@NotNull
private static Collection<? extends PackagingSourceItem> createClasspathItems(@NotNull ArtifactEditorContext editorContext, @NotNull Artifact artifact, @NotNull Module module) {
    final List<PackagingSourceItem> items = new ArrayList<>();
    final ModuleRootModel rootModel = editorContext.getModulesProvider().getRootModel(module);
    List<Library> libraries = new ArrayList<>();
    for (OrderEntry orderEntry : rootModel.getOrderEntries()) {
        if (orderEntry instanceof LibraryOrderEntry) {
            final LibraryOrderEntry libraryEntry = (LibraryOrderEntry) orderEntry;
            final Library library = libraryEntry.getLibrary();
            final DependencyScope scope = libraryEntry.getScope();
            if (library != null && scope.isForProductionRuntime()) {
                libraries.add(library);
            }
        }
    }
    for (Module toAdd : getNotAddedModules(editorContext, artifact, module)) {
        items.add(new ModuleOutputSourceItem(toAdd));
    }
    for (Library library : getNotAddedLibraries(editorContext, artifact, libraries)) {
        items.add(new LibrarySourceItem(library));
    }
    return items;
}
Also used : PackagingSourceItem(com.intellij.packaging.ui.PackagingSourceItem) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with PackagingSourceItem

use of com.intellij.packaging.ui.PackagingSourceItem in project intellij-community by JetBrains.

the class ExtractIntoDefaultLocationAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final String pathForClasses = myArtifactEditor.getArtifact().getArtifactType().getDefaultPathFor(PackagingElementOutputKind.DIRECTORIES_WITH_CLASSES);
    if (pathForClasses != null) {
        final List<PackagingElement<?>> extracted = new ArrayList<>();
        for (PackagingSourceItem item : mySourceItemsTree.getSelectedItems()) {
            final ArtifactEditorContext context = myArtifactEditor.getContext();
            final List<? extends PackagingElement<?>> elements = item.createElements(context);
            ArtifactUtil.processElementsWithSubstitutions(elements, context, context.getArtifactType(), PackagingElementPath.EMPTY, new PackagingElementProcessor<PackagingElement<?>>() {

                @Override
                public boolean process(@NotNull PackagingElement<?> element, @NotNull PackagingElementPath path) {
                    if (element instanceof FileCopyPackagingElement) {
                        final VirtualFile file = ((FileCopyPackagingElement) element).findFile();
                        if (file != null) {
                            final VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(file);
                            if (jarRoot != null) {
                                extracted.add(PackagingElementFactory.getInstance().createExtractedDirectory(jarRoot));
                            }
                        }
                    }
                    return true;
                }
            });
        }
        myArtifactEditor.getLayoutTreeComponent().putElements(pathForClasses, extracted);
    }
}
Also used : PackagingSourceItem(com.intellij.packaging.ui.PackagingSourceItem) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) FileCopyPackagingElement(com.intellij.packaging.impl.elements.FileCopyPackagingElement) PackagingElement(com.intellij.packaging.elements.PackagingElement) PackagingElementPath(com.intellij.packaging.impl.artifacts.PackagingElementPath) ArtifactEditorContext(com.intellij.packaging.ui.ArtifactEditorContext) FileCopyPackagingElement(com.intellij.packaging.impl.elements.FileCopyPackagingElement)

Example 10 with PackagingSourceItem

use of com.intellij.packaging.ui.PackagingSourceItem in project intellij-community by JetBrains.

the class LayoutTreeComponent method putIntoDefaultLocations.

public void putIntoDefaultLocations(@NotNull final List<? extends PackagingSourceItem> items) {
    final List<PackagingElement<?>> toSelect = new ArrayList<>();
    editLayout(() -> {
        final CompositePackagingElement<?> rootElement = getArtifact().getRootElement();
        final ArtifactType artifactType = getArtifact().getArtifactType();
        for (PackagingSourceItem item : items) {
            final String path = artifactType.getDefaultPathFor(item);
            if (path != null) {
                final CompositePackagingElement<?> parent;
                if (path.endsWith(URLUtil.JAR_SEPARATOR)) {
                    parent = PackagingElementFactory.getInstance().getOrCreateArchive(rootElement, StringUtil.trimEnd(path, URLUtil.JAR_SEPARATOR));
                } else {
                    parent = PackagingElementFactory.getInstance().getOrCreateDirectory(rootElement, path);
                }
                final List<? extends PackagingElement<?>> elements = item.createElements(myContext);
                toSelect.addAll(parent.addOrFindChildren(elements));
            }
        }
    });
    myArtifactsEditor.getSourceItemsTree().rebuildTree();
    updateAndSelect(myTree.getRootPackagingNode(), toSelect);
}
Also used : PackagingSourceItem(com.intellij.packaging.ui.PackagingSourceItem) ArtifactType(com.intellij.packaging.artifacts.ArtifactType) PackagingElement(com.intellij.packaging.elements.PackagingElement) DirectoryPackagingElement(com.intellij.packaging.impl.elements.DirectoryPackagingElement) CompositePackagingElement(com.intellij.packaging.elements.CompositePackagingElement)

Aggregations

PackagingSourceItem (com.intellij.packaging.ui.PackagingSourceItem)10 PackagingElement (com.intellij.packaging.elements.PackagingElement)3 ArrayList (java.util.ArrayList)3 Presentation (com.intellij.openapi.actionSystem.Presentation)2 Module (com.intellij.openapi.module.Module)2 Artifact (com.intellij.packaging.artifacts.Artifact)2 CompositePackagingElement (com.intellij.packaging.elements.CompositePackagingElement)2 DirectoryPackagingElement (com.intellij.packaging.impl.elements.DirectoryPackagingElement)2 ArtifactEditorContext (com.intellij.packaging.ui.ArtifactEditorContext)2 NotNull (org.jetbrains.annotations.NotNull)2 FlexBuildConfiguration (com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration)1 FlexProjectConfigurationEditor (com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor)1 ModuleGrouper (com.intellij.openapi.module.ModuleGrouper)1 Library (com.intellij.openapi.roots.libraries.Library)1 ArtifactEditorImpl (com.intellij.openapi.roots.ui.configuration.artifacts.ArtifactEditorImpl)1 ArtifactsStructureConfigurableContext (com.intellij.openapi.roots.ui.configuration.artifacts.ArtifactsStructureConfigurableContext)1 ArtifactsTreeNode (com.intellij.openapi.roots.ui.configuration.artifacts.nodes.ArtifactsTreeNode)1 StructureConfigurableContext (com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext)1 LibraryProjectStructureElement (com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.LibraryProjectStructureElement)1 ModuleProjectStructureElement (com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ModuleProjectStructureElement)1