Search in sources :

Example 6 with Artifact

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

the class ArtifactVirtualFileListener method filePathChanged.

private void filePathChanged(@NotNull final String oldPath, @NotNull final String newPath) {
    final Collection<Artifact> artifacts = myParentPathsToArtifacts.getValue().get(oldPath);
    if (artifacts != null) {
        final ModifiableArtifactModel model = myArtifactManager.createModifiableModel();
        for (Artifact artifact : artifacts) {
            final Artifact copy = model.getOrCreateModifiableArtifact(artifact);
            ArtifactUtil.processFileOrDirectoryCopyElements(copy, new PackagingElementProcessor<FileOrDirectoryCopyPackagingElement<?>>() {

                @Override
                public boolean process(@NotNull FileOrDirectoryCopyPackagingElement<?> element, @NotNull PackagingElementPath pathToElement) {
                    final String path = element.getFilePath();
                    if (FileUtil.startsWith(path, oldPath)) {
                        element.setFilePath(newPath + path.substring(oldPath.length()));
                    }
                    return true;
                }
            }, myArtifactManager.getResolvingContext(), false);
        }
        model.commit();
    }
}
Also used : FileOrDirectoryCopyPackagingElement(com.intellij.packaging.impl.elements.FileOrDirectoryCopyPackagingElement) ModifiableArtifactModel(com.intellij.packaging.artifacts.ModifiableArtifactModel) Artifact(com.intellij.packaging.artifacts.Artifact)

Example 7 with Artifact

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

the class BuildArtifactsBeforeRunTaskProvider method getTaskIcon.

@Override
public Icon getTaskIcon(BuildArtifactsBeforeRunTask task) {
    List<ArtifactPointer> pointers = task.getArtifactPointers();
    if (pointers == null || pointers.isEmpty())
        return getIcon();
    Artifact artifact = pointers.get(0).getArtifact();
    if (artifact == null)
        return getIcon();
    return artifact.getArtifactType().getIcon();
}
Also used : ArtifactPointer(com.intellij.packaging.artifacts.ArtifactPointer) Artifact(com.intellij.packaging.artifacts.Artifact)

Example 8 with Artifact

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

the class PackageFileAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent event) {
    final Project project = event.getData(CommonDataKeys.PROJECT);
    if (project == null)
        return;
    FileDocumentManager.getInstance().saveAllDocuments();
    final List<VirtualFile> files = getFilesToPackage(event, project);
    Artifact[] allArtifacts = ArtifactManager.getInstance(project).getArtifacts();
    PackageFileWorker.startPackagingFiles(project, files, allArtifacts, () -> setStatusText(project, files));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) Artifact(com.intellij.packaging.artifacts.Artifact)

Example 9 with Artifact

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

the class ArtifactsGenerator method generate.

public List<Generator> generate() {
    final List<Generator> generators = new ArrayList<>();
    final Target initTarget = new Target(INIT_ARTIFACTS_TARGET, null, null, null);
    generators.add(initTarget);
    initTarget.add(new Property(ArtifactAntGenerationContextImpl.ARTIFACTS_TEMP_DIR_PROPERTY, BuildProperties.propertyRelativePath(BuildProperties.getProjectBaseDirProperty(), "__artifacts_temp")));
    for (Artifact artifact : myAllArtifacts) {
        if (!myContext.shouldBuildIntoTempDirectory(artifact)) {
            generators.add(new CleanArtifactTarget(artifact, myContext));
        }
        final String outputPath = artifact.getOutputPath();
        if (!StringUtil.isEmpty(outputPath)) {
            initTarget.add(new Property(myContext.getConfiguredArtifactOutputProperty(artifact), myContext.getSubstitutedPath(outputPath)));
        }
    }
    initTarget.add(new Mkdir(BuildProperties.propertyRef(ArtifactAntGenerationContextImpl.ARTIFACTS_TEMP_DIR_PROPERTY)));
    StringBuilder depends = new StringBuilder();
    for (Artifact artifact : myAllArtifacts) {
        Target target = createArtifactTarget(artifact);
        generators.add(target);
        if (!StringUtil.isEmpty(artifact.getOutputPath())) {
            if (depends.length() > 0)
                depends.append(", ");
            depends.append(myContext.getTargetName(artifact));
        }
    }
    for (Generator generator : myContext.getBeforeBuildGenerators()) {
        initTarget.add(generator);
    }
    initArtifacts(myResolvingContext.getProject(), initTarget);
    Target buildAllArtifacts = new Target(BUILD_ALL_ARTIFACTS_TARGET, depends.toString(), "Build all artifacts", null);
    for (Artifact artifact : myAllArtifacts) {
        final String artifactOutputPath = artifact.getOutputPath();
        if (!StringUtil.isEmpty(artifactOutputPath) && myContext.shouldBuildIntoTempDirectory(artifact)) {
            final String outputPath = BuildProperties.propertyRef(myContext.getConfiguredArtifactOutputProperty(artifact));
            buildAllArtifacts.add(new Mkdir(outputPath));
            final Copy copy = new Copy(outputPath);
            copy.add(new FileSet(BuildProperties.propertyRef(myContext.getArtifactOutputProperty(artifact))));
            buildAllArtifacts.add(copy);
        }
    }
    buildAllArtifacts.add(new Comment("Delete temporary files"), 1);
    for (Generator generator : myContext.getAfterBuildGenerators()) {
        buildAllArtifacts.add(generator);
    }
    buildAllArtifacts.add(new Delete(BuildProperties.propertyRef(ArtifactAntGenerationContextImpl.ARTIFACTS_TEMP_DIR_PROPERTY)));
    generators.add(buildAllArtifacts);
    return generators;
}
Also used : ArrayList(java.util.ArrayList) Artifact(com.intellij.packaging.artifacts.Artifact)

Example 10 with Artifact

use of com.intellij.packaging.artifacts.Artifact 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)52 ArrayList (java.util.ArrayList)13 Project (com.intellij.openapi.project.Project)11 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 Module (com.intellij.openapi.module.Module)7 NotNull (org.jetbrains.annotations.NotNull)6 ArtifactManager (com.intellij.packaging.artifacts.ArtifactManager)5 File (java.io.File)5 PackagingElement (com.intellij.packaging.elements.PackagingElement)4 ArtifactCompileScope (com.intellij.packaging.impl.compiler.ArtifactCompileScope)4 ArtifactPackagingElement (com.intellij.packaging.impl.elements.ArtifactPackagingElement)4 Nullable (org.jetbrains.annotations.Nullable)4 ArtifactType (com.intellij.packaging.artifacts.ArtifactType)3 PackagingElementPath (com.intellij.packaging.impl.artifacts.PackagingElementPath)3 ReadAction (com.intellij.openapi.application.ReadAction)2 Result (com.intellij.openapi.application.Result)2 Pair (com.intellij.openapi.util.Pair)2 ModifiableArtifactModel (com.intellij.packaging.artifacts.ModifiableArtifactModel)2 CompositePackagingElement (com.intellij.packaging.elements.CompositePackagingElement)2 PackagingElementFactory (com.intellij.packaging.elements.PackagingElementFactory)2