Search in sources :

Example 1 with PackagingElementPath

use of com.intellij.packaging.impl.artifacts.PackagingElementPath in project intellij-community by JetBrains.

the class PackageFileWorker method packageFile.

public static void packageFile(@NotNull VirtualFile file, @NotNull Project project, final Artifact[] artifacts, final boolean packIntoArchives) throws IOException {
    LOG.debug("Start packaging file: " + file.getPath());
    final Collection<Trinity<Artifact, PackagingElementPath, String>> items = ArtifactUtil.findContainingArtifactsWithOutputPaths(file, project, artifacts);
    File ioFile = VfsUtilCore.virtualToIoFile(file);
    for (Trinity<Artifact, PackagingElementPath, String> item : items) {
        final Artifact artifact = item.getFirst();
        final String outputPath = artifact.getOutputPath();
        if (!StringUtil.isEmpty(outputPath)) {
            PackageFileWorker worker = new PackageFileWorker(ioFile, item.getThird(), packIntoArchives);
            LOG.debug(" package to " + outputPath);
            worker.packageFile(outputPath, item.getSecond().getParents());
        }
    }
}
Also used : Trinity(com.intellij.openapi.util.Trinity) PackagingElementPath(com.intellij.packaging.impl.artifacts.PackagingElementPath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) JBZipFile(com.intellij.util.io.zip.JBZipFile) File(java.io.File) Artifact(com.intellij.packaging.artifacts.Artifact)

Example 2 with PackagingElementPath

use of com.intellij.packaging.impl.artifacts.PackagingElementPath 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 3 with PackagingElementPath

use of com.intellij.packaging.impl.artifacts.PackagingElementPath in project intellij-community by JetBrains.

the class ArtifactProjectStructureElement method getUsagesInElement.

@Override
public List<ProjectStructureElementUsage> getUsagesInElement() {
    final Artifact artifact = myArtifactsStructureContext.getArtifactModel().getArtifactByOriginal(myOriginalArtifact);
    final List<ProjectStructureElementUsage> usages = new ArrayList<>();
    final CompositePackagingElement<?> rootElement = myArtifactsStructureContext.getRootElement(artifact);
    ArtifactUtil.processPackagingElements(rootElement, null, new PackagingElementProcessor<PackagingElement<?>>() {

        @Override
        public boolean process(@NotNull PackagingElement<?> packagingElement, @NotNull PackagingElementPath path) {
            ProjectStructureElement element = getProjectStructureElementFor(packagingElement, ArtifactProjectStructureElement.this.myContext, ArtifactProjectStructureElement.this.myArtifactsStructureContext);
            if (element != null) {
                usages.add(createUsage(packagingElement, element, path.getPathStringFrom("/", rootElement)));
            }
            return true;
        }
    }, myArtifactsStructureContext, false, artifact.getArtifactType());
    return usages;
}
Also used : PackagingElementPath(com.intellij.packaging.impl.artifacts.PackagingElementPath) ArrayList(java.util.ArrayList) ArtifactPackagingElement(com.intellij.packaging.impl.elements.ArtifactPackagingElement) LibraryPackagingElement(com.intellij.packaging.impl.elements.LibraryPackagingElement) FacetBasedPackagingElement(com.intellij.packaging.impl.elements.FacetBasedPackagingElement) PackagingElement(com.intellij.packaging.elements.PackagingElement) CompositePackagingElement(com.intellij.packaging.elements.CompositePackagingElement) ModuleOutputPackagingElement(com.intellij.packaging.impl.elements.ModuleOutputPackagingElement) Artifact(com.intellij.packaging.artifacts.Artifact)

Example 4 with PackagingElementPath

use of com.intellij.packaging.impl.artifacts.PackagingElementPath in project intellij-community by JetBrains.

the class ManifestFileUtil method suggestManifestFileDirectory.

@Nullable
public static VirtualFile suggestManifestFileDirectory(@NotNull CompositePackagingElement<?> root, PackagingElementResolvingContext context, ArtifactType artifactType) {
    final VirtualFile metaInfDir = ArtifactUtil.findSourceFileByOutputPath(root, MANIFEST_DIR_NAME, context, artifactType);
    if (metaInfDir != null) {
        return metaInfDir;
    }
    final Ref<VirtualFile> sourceDir = Ref.create(null);
    final Ref<VirtualFile> sourceFile = Ref.create(null);
    ArtifactUtil.processElementsWithSubstitutions(root.getChildren(), context, artifactType, 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) {
                    sourceFile.set(file);
                }
            } else if (element instanceof DirectoryCopyPackagingElement) {
                final VirtualFile file = ((DirectoryCopyPackagingElement) element).findFile();
                if (file != null) {
                    sourceDir.set(file);
                    return false;
                }
            }
            return true;
        }
    });
    if (!sourceDir.isNull()) {
        return sourceDir.get();
    }
    final Project project = context.getProject();
    return suggestBaseDir(project, sourceFile.get());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) PackagingElementPath(com.intellij.packaging.impl.artifacts.PackagingElementPath) CompositePackagingElement(com.intellij.packaging.elements.CompositePackagingElement) PackagingElement(com.intellij.packaging.elements.PackagingElement) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with PackagingElementPath

use of com.intellij.packaging.impl.artifacts.PackagingElementPath 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

PackagingElementPath (com.intellij.packaging.impl.artifacts.PackagingElementPath)5 PackagingElement (com.intellij.packaging.elements.PackagingElement)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 Artifact (com.intellij.packaging.artifacts.Artifact)3 CompositePackagingElement (com.intellij.packaging.elements.CompositePackagingElement)3 ArrayList (java.util.ArrayList)3 ArtifactPackagingElement (com.intellij.packaging.impl.elements.ArtifactPackagingElement)2 Project (com.intellij.openapi.project.Project)1 Pair (com.intellij.openapi.util.Pair)1 Trinity (com.intellij.openapi.util.Trinity)1 FacetBasedPackagingElement (com.intellij.packaging.impl.elements.FacetBasedPackagingElement)1 FileCopyPackagingElement (com.intellij.packaging.impl.elements.FileCopyPackagingElement)1 LibraryPackagingElement (com.intellij.packaging.impl.elements.LibraryPackagingElement)1 ModuleOutputPackagingElement (com.intellij.packaging.impl.elements.ModuleOutputPackagingElement)1 ArtifactEditorContext (com.intellij.packaging.ui.ArtifactEditorContext)1 PackagingSourceItem (com.intellij.packaging.ui.PackagingSourceItem)1 JBZipFile (com.intellij.util.io.zip.JBZipFile)1 File (java.io.File)1 List (java.util.List)1 Nullable (org.jetbrains.annotations.Nullable)1