Search in sources :

Example 1 with ModuleOutputPackagingElement

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

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

Aggregations

Artifact (com.intellij.packaging.artifacts.Artifact)2 ModuleOutputPackagingElement (com.intellij.packaging.impl.elements.ModuleOutputPackagingElement)2 Module (com.intellij.openapi.module.Module)1 MultiValuesMap (com.intellij.openapi.util.MultiValuesMap)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ArtifactManager (com.intellij.packaging.artifacts.ArtifactManager)1 PackagingElement (com.intellij.packaging.elements.PackagingElement)1 PackagingElementResolvingContext (com.intellij.packaging.elements.PackagingElementResolvingContext)1 ArtifactPackagingElement (com.intellij.packaging.impl.elements.ArtifactPackagingElement)1 FileOrDirectoryCopyPackagingElement (com.intellij.packaging.impl.elements.FileOrDirectoryCopyPackagingElement)1 ArrayList (java.util.ArrayList)1