Search in sources :

Example 1 with FileOrDirectoryCopyPackagingElement

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

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

Aggregations

Artifact (com.intellij.packaging.artifacts.Artifact)2 FileOrDirectoryCopyPackagingElement (com.intellij.packaging.impl.elements.FileOrDirectoryCopyPackagingElement)2 MultiValuesMap (com.intellij.openapi.util.MultiValuesMap)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ArtifactManager (com.intellij.packaging.artifacts.ArtifactManager)1 ModifiableArtifactModel (com.intellij.packaging.artifacts.ModifiableArtifactModel)1 PackagingElement (com.intellij.packaging.elements.PackagingElement)1 PackagingElementResolvingContext (com.intellij.packaging.elements.PackagingElementResolvingContext)1 ModuleOutputPackagingElement (com.intellij.packaging.impl.elements.ModuleOutputPackagingElement)1