Search in sources :

Example 1 with CompositePackagingElement

use of com.intellij.packaging.elements.CompositePackagingElement in project azure-tools-for-java by Microsoft.

the class HDInsightModuleBuilder method createDefaultArtifact.

private void createDefaultArtifact(final Module module) {
    final Project project = module.getProject();
    final JarArtifactType type = new JarArtifactType();
    final PackagingElementFactory factory = PackagingElementFactory.getInstance();
    CompositePackagingElement root = factory.createArchive("default_artifact.jar");
    root.addOrFindChild(factory.createModuleOutput(module));
    ArtifactManager.getInstance(project).addArtifact(module.getName() + "_DefaultArtifact", type, root);
}
Also used : Project(com.intellij.openapi.project.Project) CompositePackagingElement(com.intellij.packaging.elements.CompositePackagingElement) PackagingElementFactory(com.intellij.packaging.elements.PackagingElementFactory) JarArtifactType(com.intellij.packaging.impl.artifacts.JarArtifactType)

Example 2 with CompositePackagingElement

use of com.intellij.packaging.elements.CompositePackagingElement 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 CompositePackagingElement

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

the class PackageFileWorker method copyFile.

private void copyFile(String outputPath, List<CompositePackagingElement<?>> parents) throws IOException {
    if (parents.isEmpty()) {
        final String fullOutputPath = DeploymentUtil.appendToPath(outputPath, myRelativeOutputPath);
        File target = new File(fullOutputPath);
        if (FileUtil.filesEqual(myFile, target)) {
            LOG.debug("  skipping copying file to itself");
        } else {
            LOG.debug("  copying to " + fullOutputPath);
            FileUtil.copy(myFile, target);
        }
        return;
    }
    final CompositePackagingElement<?> element = parents.get(0);
    final String nextOutputPath = outputPath + "/" + element.getName();
    final List<CompositePackagingElement<?>> parentsTrail = parents.subList(1, parents.size());
    if (element instanceof ArchivePackagingElement) {
        if (myPackIntoArchives) {
            packFile(nextOutputPath, "", parentsTrail);
        }
    } else {
        copyFile(nextOutputPath, parentsTrail);
    }
}
Also used : CompositePackagingElement(com.intellij.packaging.elements.CompositePackagingElement) ArchivePackagingElement(com.intellij.packaging.impl.elements.ArchivePackagingElement) VirtualFile(com.intellij.openapi.vfs.VirtualFile) JBZipFile(com.intellij.util.io.zip.JBZipFile) File(java.io.File)

Example 4 with CompositePackagingElement

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

the class PackageFileWorker method packFile.

private void packFile(String archivePath, String pathInArchive, List<CompositePackagingElement<?>> parents) throws IOException {
    final File archiveFile = new File(archivePath);
    if (parents.isEmpty()) {
        LOG.debug("  adding to archive " + archivePath);
        JBZipFile file = getOrCreateZipFile(archiveFile);
        try {
            final String fullPathInArchive = DeploymentUtil.trimForwardSlashes(DeploymentUtil.appendToPath(pathInArchive, myRelativeOutputPath));
            final JBZipEntry entry = file.getOrCreateEntry(fullPathInArchive);
            entry.setData(FileUtil.loadFileBytes(myFile));
        } finally {
            file.close();
        }
        return;
    }
    final CompositePackagingElement<?> element = parents.get(0);
    final String nextPathInArchive = DeploymentUtil.trimForwardSlashes(DeploymentUtil.appendToPath(pathInArchive, element.getName()));
    final List<CompositePackagingElement<?>> parentsTrail = parents.subList(1, parents.size());
    if (element instanceof ArchivePackagingElement) {
        JBZipFile zipFile = getOrCreateZipFile(archiveFile);
        try {
            final JBZipEntry entry = zipFile.getOrCreateEntry(nextPathInArchive);
            LOG.debug("  extracting to temp file: " + nextPathInArchive + " from " + archivePath);
            final File tempFile = FileUtil.createTempFile("packageFile" + FileUtil.sanitizeFileName(nextPathInArchive), FileUtilRt.getExtension(PathUtil.getFileName(nextPathInArchive)));
            if (entry.getSize() != -1) {
                FileUtil.writeToFile(tempFile, entry.getData());
            }
            packFile(FileUtil.toSystemIndependentName(tempFile.getAbsolutePath()), "", parentsTrail);
            entry.setData(FileUtil.loadFileBytes(tempFile));
            FileUtil.delete(tempFile);
        } finally {
            zipFile.close();
        }
    } else {
        packFile(archivePath, nextPathInArchive, parentsTrail);
    }
}
Also used : CompositePackagingElement(com.intellij.packaging.elements.CompositePackagingElement) JBZipFile(com.intellij.util.io.zip.JBZipFile) ArchivePackagingElement(com.intellij.packaging.impl.elements.ArchivePackagingElement) VirtualFile(com.intellij.openapi.vfs.VirtualFile) JBZipFile(com.intellij.util.io.zip.JBZipFile) File(java.io.File) JBZipEntry(com.intellij.util.io.zip.JBZipEntry)

Example 5 with CompositePackagingElement

use of com.intellij.packaging.elements.CompositePackagingElement 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)

Aggregations

CompositePackagingElement (com.intellij.packaging.elements.CompositePackagingElement)17 PackagingElement (com.intellij.packaging.elements.PackagingElement)13 ArrayList (java.util.ArrayList)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 DirectoryPackagingElement (com.intellij.packaging.impl.elements.DirectoryPackagingElement)4 Project (com.intellij.openapi.project.Project)3 PackagingElementPath (com.intellij.packaging.impl.artifacts.PackagingElementPath)3 ArtifactPackagingElement (com.intellij.packaging.impl.elements.ArtifactPackagingElement)3 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 Artifact (com.intellij.packaging.artifacts.Artifact)2 PackagingElementFactory (com.intellij.packaging.elements.PackagingElementFactory)2 ArchivePackagingElement (com.intellij.packaging.impl.elements.ArchivePackagingElement)2 PackagingSourceItem (com.intellij.packaging.ui.PackagingSourceItem)2 JBZipFile (com.intellij.util.io.zip.JBZipFile)2 File (java.io.File)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 NotNull (org.jetbrains.annotations.NotNull)2