From 8473e47f0505ab645dbc4f33944cbd874be89156 Mon Sep 17 00:00:00 2001 From: nik Date: Tue, 17 Nov 2009 12:38:47 +0300 Subject: [PATCH] artifacts processing refactored --- .../compiler/ant/artifacts/ArtifactsGenerator.java | 4 +- .../packaging/impl/artifacts/ArtifactUtil.java | 146 +++++++++++---------- .../artifacts/ArtifactVirtualFileListener.java | 7 +- .../impl/artifacts/PackagingElementPath.java | 117 +++++++++++++++++ .../impl/artifacts/PackagingElementProcessor.java | 16 +-- .../packaging/impl/elements/ManifestFileUtil.java | 15 ++- .../impl/ui/actions/PackageFileWorker.java | 8 +- .../artifacts/ArtifactProjectStructureElement.java | 10 +- .../ArtifactExternalDependenciesImporter.java | 8 +- 9 files changed, 220 insertions(+), 111 deletions(-) create mode 100644 java/compiler/impl/src/com/intellij/packaging/impl/artifacts/PackagingElementPath.java diff --git a/java/compiler/impl/src/com/intellij/compiler/ant/artifacts/ArtifactsGenerator.java b/java/compiler/impl/src/com/intellij/compiler/ant/artifacts/ArtifactsGenerator.java index 4c1f0dd4a4..38365898b5 100644 --- a/java/compiler/impl/src/com/intellij/compiler/ant/artifacts/ArtifactsGenerator.java +++ b/java/compiler/impl/src/com/intellij/compiler/ant/artifacts/ArtifactsGenerator.java @@ -27,10 +27,10 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.packaging.artifacts.Artifact; import com.intellij.packaging.artifacts.ArtifactManager; import com.intellij.packaging.elements.ComplexPackagingElement; -import com.intellij.packaging.elements.CompositePackagingElement; import com.intellij.packaging.elements.PackagingElement; import com.intellij.packaging.elements.PackagingElementResolvingContext; import com.intellij.packaging.impl.artifacts.ArtifactUtil; +import com.intellij.packaging.impl.artifacts.PackagingElementPath; import com.intellij.packaging.impl.artifacts.PackagingElementProcessor; import com.intellij.packaging.impl.elements.ArtifactPackagingElement; import com.intellij.packaging.impl.elements.ModuleOutputPackagingElement; @@ -128,7 +128,7 @@ public class ArtifactsGenerator { } @Override - public boolean process(@NotNull List> parents, @NotNull PackagingElement packagingElement) { + public boolean process(@NotNull PackagingElement packagingElement, @NotNull PackagingElementPath path) { if (packagingElement instanceof ArtifactPackagingElement) { final Artifact included = ((ArtifactPackagingElement)packagingElement).findArtifact(myResolvingContext); if (included != null) { diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactUtil.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactUtil.java index 85006853c9..5908245ce3 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactUtil.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactUtil.java @@ -85,7 +85,7 @@ public class ArtifactUtil { final boolean processSubstitutions) { return processPackagingElements(artifact, type, new PackagingElementProcessor() { @Override - public boolean process(@NotNull List> parents, @NotNull E e) { + public boolean process(@NotNull E e, @NotNull PackagingElementPath path) { return processor.process(e); } }, resolvingContext, processSubstitutions); @@ -103,8 +103,8 @@ public class ArtifactUtil { final @NotNull PackagingElementResolvingContext resolvingContext, final boolean processSubstitutions, final ArtifactType artifactType) { - return processElements(rootElement, type, processor, resolvingContext, processSubstitutions, artifactType, - FList.>emptyList(), new HashSet>()); + return processElement(rootElement, type, processor, resolvingContext, processSubstitutions, artifactType, + PackagingElementPath.EMPTY, new HashSet>()); } private static > boolean processElements(final List> elements, @@ -112,41 +112,42 @@ public class ArtifactUtil { @NotNull PackagingElementProcessor processor, final @NotNull PackagingElementResolvingContext resolvingContext, final boolean processSubstitutions, ArtifactType artifactType, - FList> parents, + @NotNull PackagingElementPath path, Set> processed) { for (PackagingElement element : elements) { - if (!processElements(element, type, processor, resolvingContext, processSubstitutions, artifactType, parents, processed)) { + if (!processElement(element, type, processor, resolvingContext, processSubstitutions, artifactType, path, processed)) { return false; } } return true; } - private static > boolean processElements(@NotNull PackagingElement element, @Nullable PackagingElementType type, + private static > boolean processElement(@NotNull PackagingElement element, @Nullable PackagingElementType type, @NotNull PackagingElementProcessor processor, @NotNull PackagingElementResolvingContext resolvingContext, final boolean processSubstitutions, ArtifactType artifactType, - FList> parents, Set> processed) { + @NotNull PackagingElementPath path, Set> processed) { if (!processor.shouldProcess(element) || !processed.add(element)) { return true; } if (type == null || element.getType().equals(type)) { - if (!processor.process(parents, (E)element)) { + if (!processor.process((E)element, path)) { return false; } } if (element instanceof CompositePackagingElement) { final CompositePackagingElement composite = (CompositePackagingElement)element; return processElements(composite.getChildren(), type, processor, resolvingContext, processSubstitutions, artifactType, - parents.prepend(composite), processed); + path.appendComposite(composite), processed); } else if (element instanceof ComplexPackagingElement && processSubstitutions) { final ComplexPackagingElement complexElement = (ComplexPackagingElement)element; if (processor.shouldProcessSubstitution(complexElement)) { final List> substitution = complexElement.getSubstitution(resolvingContext, artifactType); if (substitution != null) { - return processElements(substitution, type, processor, resolvingContext, processSubstitutions, artifactType, parents, processed); + return processElements(substitution, type, processor, resolvingContext, processSubstitutions, artifactType, + path.appendComplex(complexElement), processed); } } } @@ -203,28 +204,17 @@ public class ArtifactUtil { public static > boolean processElements(@NotNull List> elements, @NotNull PackagingElementResolvingContext context, @NotNull ArtifactType artifactType, - @NotNull final Processor processor) { - return processElements(elements, context, artifactType, new PackagingElementProcessor() { - @Override - public boolean process(@NotNull List> parents, @NotNull E e) { - return processor.process(e); - } - }); - } - - public static > boolean processElements(@NotNull List> elements, - @NotNull PackagingElementResolvingContext context, - @NotNull ArtifactType artifactType, + @NotNull PackagingElementPath parentPath, @NotNull PackagingElementProcessor processor) { for (PackagingElement element : elements) { if (element instanceof ComplexPackagingElement && processor.shouldProcessSubstitution((ComplexPackagingElement)element)) { - final List> substitution = - ((ComplexPackagingElement)element).getSubstitution(context, artifactType); - if (substitution != null && !processElements(substitution, context, artifactType, processor)) { + final ComplexPackagingElement complexElement = (ComplexPackagingElement)element; + final List> substitution = complexElement.getSubstitution(context, artifactType); + if (substitution != null && !processElements(substitution, context, artifactType, parentPath.appendComplex(complexElement), processor)) { return false; } } - else if (!processor.process(FList.>emptyList(), (E)element)) { + else if (!processor.process((E)element, parentPath)) { return false; } } @@ -232,66 +222,82 @@ public class ArtifactUtil { } public static List> findByRelativePath(@NotNull CompositePackagingElement parent, @NotNull String relativePath, - @NotNull PackagingElementResolvingContext context, @NotNull ArtifactType artifactType) { + @NotNull PackagingElementResolvingContext context, @NotNull ArtifactType artifactType) { + final List> result = new ArrayList>(); + processElementsByRelativePath(parent, relativePath, context, artifactType, PackagingElementPath.EMPTY, new PackagingElementProcessor>() { + @Override + public boolean process(@NotNull PackagingElement packagingElement, @NotNull PackagingElementPath path) { + result.add(packagingElement); + return true; + } + }); + return result; + } + + public static boolean processElementsByRelativePath(@NotNull final CompositePackagingElement parent, @NotNull String relativePath, + @NotNull final PackagingElementResolvingContext context, @NotNull final ArtifactType artifactType, + @NotNull PackagingElementPath parentPath, + @NotNull final PackagingElementProcessor> processor) { relativePath = StringUtil.trimStart(relativePath, "/"); if (relativePath.length() == 0) { - return new SmartList>(parent); + return true; } int i = relativePath.indexOf('/'); final String firstName = i != -1 ? relativePath.substring(0, i) : relativePath; - String tail = i != -1 ? relativePath.substring(i+1) : ""; + final String tail = i != -1 ? relativePath.substring(i+1) : ""; - final List> children = new SmartList>(); - processElements(parent.getChildren(), context, artifactType, new Processor>() { - public boolean process(PackagingElement element) { + return processElements(parent.getChildren(), context, artifactType, parentPath.appendComposite(parent), new PackagingElementProcessor>() { + @Override + public boolean process(@NotNull PackagingElement element, @NotNull PackagingElementPath path) { + boolean process = false; if (element instanceof CompositePackagingElement && firstName.equals(((CompositePackagingElement)element).getName())) { - children.add(element); + process = true; } else if (element instanceof FileCopyPackagingElement) { final FileCopyPackagingElement fileCopy = (FileCopyPackagingElement)element; if (firstName.equals(fileCopy.getOutputFileName())) { - children.add(element); + process = true; + } + } + + if (process) { + if (tail.length() == 0) { + if (!processor.process(element, path)) return false; + } + else if (element instanceof CompositePackagingElement) { + return processElementsByRelativePath((CompositePackagingElement)element, tail, context, artifactType, path, processor); } } return true; } }); - - if (tail.length() == 0) { - return children; - } - - List> result = new SmartList>(); - for (PackagingElement child : children) { - if (child instanceof CompositePackagingElement) { - result.addAll(findByRelativePath((CompositePackagingElement)child, tail, context, artifactType)); - } - } - return result; } - public static boolean processDirectoryChildren(@NotNull CompositePackagingElement root, + public static boolean processDirectoryChildren(@NotNull CompositePackagingElement parent, + @NotNull PackagingElementPath pathToParent, @NotNull String relativePath, - @NotNull PackagingElementResolvingContext context, - @NotNull ArtifactType artifactType, - @NotNull Processor> processor) { - final List> dirs = findByRelativePath(root, relativePath, context, artifactType); - for (PackagingElement dir : dirs) { - if (dir instanceof DirectoryPackagingElement) { - final List> children = ((DirectoryPackagingElement)dir).getChildren(); - if (!processElements(children, context, artifactType, processor)) { - return false; + @NotNull final PackagingElementResolvingContext context, + @NotNull final ArtifactType artifactType, + @NotNull final PackagingElementProcessor> processor) { + return processElementsByRelativePath(parent, relativePath, context, artifactType, pathToParent, new PackagingElementProcessor>() { + @Override + public boolean process(@NotNull PackagingElement element, @NotNull PackagingElementPath path) { + if (element instanceof DirectoryPackagingElement) { + final List> children = ((DirectoryPackagingElement)element).getChildren(); + if (!processElements(children, context, artifactType, path.appendComposite((DirectoryPackagingElement)element), processor)) { + return false; + } } + return true; } - } - return true; + }); } public static Collection findArtifactsByFile(@NotNull final VirtualFile file, @NotNull Project project) { - final Collection>, String>> items = findContainingArtifactsWithOutputPaths(file, project); + final Collection> items = findContainingArtifactsWithOutputPaths(file, project); final List result = new ArrayList(); - for (Trinity>, String> item : items) { + for (Trinity item : items) { result.add(item.getFirst()); } return result; @@ -305,13 +311,12 @@ public class ArtifactUtil { processPackagingElements(artifact, PackagingElementFactoryImpl.DIRECTORY_COPY_ELEMENT_TYPE, processor, context, processSubstitutions); } - public static Collection>, String>> findContainingArtifactsWithOutputPaths(@NotNull final VirtualFile file, @NotNull Project project) { - final List>, String>> artifacts = new ArrayList>, String>>(); + public static Collection> findContainingArtifactsWithOutputPaths(@NotNull final VirtualFile file, @NotNull Project project) { + final List> artifacts = new ArrayList>(); for (final Artifact artifact : ArtifactManager.getInstance(project).getArtifacts()) { processFileOrDirectoryCopyElements(artifact, new PackagingElementProcessor>() { @Override - public boolean process(@NotNull List> parents, - @NotNull FileOrDirectoryCopyPackagingElement element) { + public boolean process(@NotNull FileOrDirectoryCopyPackagingElement element, @NotNull PackagingElementPath path) { final VirtualFile root = element.findFile(); if (root != null && VfsUtil.isAncestor(root, file, false)) { final String relativePath; @@ -321,7 +326,7 @@ public class ArtifactUtil { else { relativePath = VfsUtil.getRelativePath(file, root, '/'); } - artifacts.add(Trinity.create(artifact, parents, relativePath)); + artifacts.add(Trinity.create(artifact, path, relativePath)); return false; } return true; @@ -345,7 +350,7 @@ public class ArtifactUtil { } public static List findSourceFilesByOutputPath(CompositePackagingElement parent, final String outputPath, - final PackagingElementResolvingContext context, final ArtifactType artifactType) { + final PackagingElementResolvingContext context, final ArtifactType artifactType) { final String path = StringUtil.trimStart(outputPath, "/"); if (path.length() == 0) { return Collections.emptyList(); @@ -356,8 +361,9 @@ public class ArtifactUtil { final String tail = i != -1 ? path.substring(i+1) : ""; final List result = new SmartList(); - processElements(parent.getChildren(), context, artifactType, new Processor>() { - public boolean process(PackagingElement element) { + processElements(parent.getChildren(), context, artifactType, PackagingElementPath.EMPTY, new PackagingElementProcessor>() { + @Override + public boolean process(@NotNull PackagingElement element, @NotNull PackagingElementPath elementPath) { //todo[nik] replace by method findSourceFile() in PackagingElement if (element instanceof CompositePackagingElement) { final CompositePackagingElement compositeElement = (CompositePackagingElement)element; @@ -435,9 +441,10 @@ public class ArtifactUtil { } @Override - public boolean process(@NotNull List> parents, @NotNull ArtifactPackagingElement element) { + public boolean process(@NotNull ArtifactPackagingElement element, @NotNull PackagingElementPath path) { if (artifact.getName().equals(element.getArtifactName())) { FList>> currentPath = pathFromRoot; + final List> parents = path.getParents(); for (int i = 0, parentsSize = parents.size(); i < parentsSize - 1; i++) { CompositePackagingElement parent = parents.get(i); if (!processor.process(parent, currentPath, anArtifact)) { @@ -494,3 +501,4 @@ public class ArtifactUtil { return !StringUtil.isEmpty(outputPath) && artifact.getRootElement() instanceof ArtifactRootElement; } } + diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactVirtualFileListener.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactVirtualFileListener.java index 04828320c0..a0e22f88bf 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactVirtualFileListener.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactVirtualFileListener.java @@ -24,7 +24,6 @@ import com.intellij.openapi.vfs.VirtualFileMoveEvent; import com.intellij.openapi.vfs.VirtualFilePropertyEvent; import com.intellij.packaging.artifacts.Artifact; import com.intellij.packaging.artifacts.ModifiableArtifactModel; -import com.intellij.packaging.elements.CompositePackagingElement; import com.intellij.packaging.impl.elements.FileOrDirectoryCopyPackagingElement; import com.intellij.psi.util.CachedValue; import com.intellij.psi.util.CachedValueProvider; @@ -33,7 +32,6 @@ import com.intellij.util.PathUtil; import org.jetbrains.annotations.NotNull; import java.util.Collection; -import java.util.List; /** * @author nik @@ -58,7 +56,7 @@ public class ArtifactVirtualFileListener extends VirtualFileAdapter { for (final Artifact artifact : myArtifactManager.getArtifacts()) { ArtifactUtil.processFileOrDirectoryCopyElements(artifact, new PackagingElementProcessor>() { @Override - public boolean process(@NotNull List> parents, @NotNull FileOrDirectoryCopyPackagingElement element) { + public boolean process(@NotNull FileOrDirectoryCopyPackagingElement element, @NotNull PackagingElementPath pathToElement) { String path = element.getFilePath(); while (path.length() > 0) { result.put(path, artifact); @@ -86,8 +84,7 @@ public class ArtifactVirtualFileListener extends VirtualFileAdapter { final Artifact copy = model.getOrCreateModifiableArtifact(artifact); ArtifactUtil.processFileOrDirectoryCopyElements(copy, new PackagingElementProcessor>() { @Override - public boolean process(@NotNull List> parents, - @NotNull FileOrDirectoryCopyPackagingElement element) { + 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())); diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/PackagingElementPath.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/PackagingElementPath.java new file mode 100644 index 0000000000..6bb7e34c4f --- /dev/null +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/PackagingElementPath.java @@ -0,0 +1,117 @@ +/* + * Copyright 2000-2009 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.packaging.impl.artifacts; + +import com.intellij.packaging.elements.ComplexPackagingElement; +import com.intellij.packaging.elements.CompositePackagingElement; +import com.intellij.packaging.elements.PackagingElement; +import com.intellij.util.SmartList; +import com.intellij.util.StringBuilderSpinAllocator; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +/** + * @author nik + */ +public class PackagingElementPath { + public static final PackagingElementPath EMPTY = new PackagingElementPath(null, null); + private final PackagingElementPath myParentPath; + private final PackagingElement myLastElement; + + private PackagingElementPath(PackagingElementPath parentPath, PackagingElement lastElement) { + myParentPath = parentPath; + myLastElement = lastElement; + } + + public PackagingElementPath appendComplex(ComplexPackagingElement element) { + return new PackagingElementPath(this, element); + } + + public PackagingElementPath appendComposite(CompositePackagingElement element) { + return new PackagingElementPath(this, element); + } + + @Nullable + public PackagingElementPath getParentPath() { + return myParentPath; + } + + public PackagingElement getLastElement() { + return myLastElement; + } + + @NotNull + public String getPathString() { + return getPathString("/"); + } + + @NotNull + public String getPathString(String separator) { + final StringBuilder builder = StringBuilderSpinAllocator.alloc(); + try { + final List> parents = getParents(); + for (int i = parents.size() - 1; i >= 0; i--) { + builder.append(parents.get(i).getName()); + if (i > 0) { + builder.append(separator); + } + } + return builder.toString(); + } + finally { + StringBuilderSpinAllocator.dispose(builder); + } + } + + public List> getParents() { + List> result = new SmartList>(); + PackagingElementPath path = this; + while (path != EMPTY) { + if (path.myLastElement instanceof CompositePackagingElement) { + result.add((CompositePackagingElement)path.myLastElement); + } + path = path.myParentPath; + } + return result; + } + + public List> getAllElements() { + List> result = new SmartList>(); + PackagingElementPath path = this; + while (path != EMPTY) { + result.add(path.myLastElement); + path = path.myParentPath; + } + return result; + } + + @Nullable + public CompositePackagingElement getLastParent() { + PackagingElementPath path = this; + while (path != EMPTY) { + if (path.myLastElement instanceof CompositePackagingElement) { + return (CompositePackagingElement)path.myLastElement; + } + } + return null; + } + + public boolean isEmpty() { + return myParentPath == null; + } +} diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/PackagingElementProcessor.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/PackagingElementProcessor.java index 759b99f9cd..048217fd33 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/PackagingElementProcessor.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/PackagingElementProcessor.java @@ -16,12 +16,9 @@ package com.intellij.packaging.impl.artifacts; import com.intellij.packaging.elements.ComplexPackagingElement; -import com.intellij.packaging.elements.CompositePackagingElement; import com.intellij.packaging.elements.PackagingElement; import org.jetbrains.annotations.NotNull; -import java.util.List; - /** * @author nik */ @@ -34,16 +31,5 @@ public abstract class PackagingElementProcessor> { return true; } - public abstract boolean process(@NotNull List> parents, @NotNull E e); - - protected static String getPathFromRoot(List> parents, String separator) { - StringBuilder builder = new StringBuilder(); - for (int i = parents.size() - 1; i >= 0; i--) { - builder.append(parents.get(i).getName()); - if (i > 0) { - builder.append(separator); - } - } - return builder.toString(); - } + public abstract boolean process(@NotNull E element, @NotNull PackagingElementPath path); } diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/ManifestFileUtil.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/ManifestFileUtil.java index 4bea85e59f..11e2212989 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/elements/ManifestFileUtil.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/ManifestFileUtil.java @@ -29,10 +29,10 @@ import com.intellij.packaging.elements.CompositePackagingElement; import com.intellij.packaging.elements.PackagingElement; import com.intellij.packaging.elements.PackagingElementResolvingContext; import com.intellij.packaging.impl.artifacts.ArtifactUtil; +import com.intellij.packaging.impl.artifacts.PackagingElementPath; import com.intellij.packaging.impl.artifacts.PackagingElementProcessor; import com.intellij.packaging.ui.ManifestFileConfiguration; import com.intellij.util.PathUtil; -import com.intellij.util.Processor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -71,8 +71,9 @@ public class ManifestFileUtil { final Ref sourceDir = Ref.create(null); final Ref sourceFile = Ref.create(null); - ArtifactUtil.processElements(root.getChildren(), context, artifactType, new Processor>() { - public boolean process(PackagingElement element) { + ArtifactUtil.processElements(root.getChildren(), context, artifactType, PackagingElementPath.EMPTY, new PackagingElementProcessor>() { + @Override + public boolean process(@NotNull PackagingElement element, @NotNull PackagingElementPath path) { if (element instanceof FileCopyPackagingElement) { final VirtualFile file = ((FileCopyPackagingElement)element).findFile(); if (file != null) { @@ -216,17 +217,17 @@ public class ManifestFileUtil { final List classpath = new ArrayList(); final PackagingElementProcessor> processor = new PackagingElementProcessor>() { @Override - public boolean process(@NotNull List> parents, @NotNull PackagingElement element) { + public boolean process(@NotNull PackagingElement element, @NotNull PackagingElementPath path) { if (element instanceof FileCopyPackagingElement) { final String fileName = ((FileCopyPackagingElement)element).getOutputFileName(); - classpath.add(DeploymentUtil.appendToPath(getPathFromRoot(parents, "/"), fileName)); + classpath.add(DeploymentUtil.appendToPath(path.getPathString(), fileName)); } else if (element instanceof DirectoryCopyPackagingElement) { - classpath.add(getPathFromRoot(parents, "/")); + classpath.add(path.getPathString()); } else if (element instanceof ArchivePackagingElement) { final String archiveName = ((ArchivePackagingElement)element).getName(); - classpath.add(DeploymentUtil.appendToPath(getPathFromRoot(parents, "/"), archiveName)); + classpath.add(DeploymentUtil.appendToPath(path.getPathString(), archiveName)); } return true; } diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/ui/actions/PackageFileWorker.java b/java/compiler/impl/src/com/intellij/packaging/impl/ui/actions/PackageFileWorker.java index 81be7ca024..764b61bc70 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/ui/actions/PackageFileWorker.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/ui/actions/PackageFileWorker.java @@ -26,6 +26,7 @@ import com.intellij.packaging.artifacts.Artifact; import com.intellij.packaging.elements.ArtifactRootElement; import com.intellij.packaging.elements.CompositePackagingElement; import com.intellij.packaging.impl.artifacts.ArtifactUtil; +import com.intellij.packaging.impl.artifacts.PackagingElementPath; import com.intellij.packaging.impl.elements.ArchivePackagingElement; import com.intellij.util.PathUtil; import com.intellij.util.io.zip.JBZipEntry; @@ -52,15 +53,14 @@ public class PackageFileWorker { } public static void packageFile(@NotNull VirtualFile file, @NotNull Project project) throws IOException { - final Collection>,String>> items = ArtifactUtil.findContainingArtifactsWithOutputPaths(file, project); + final Collection> items = ArtifactUtil.findContainingArtifactsWithOutputPaths(file, project); File ioFile = VfsUtil.virtualToIoFile(file); - for (Trinity>, String> item : items) { + for (Trinity item : items) { final Artifact artifact = item.getFirst(); - final List> parents = item.getSecond(); final String outputPath = artifact.getOutputPath(); if (!StringUtil.isEmpty(outputPath)) { PackageFileWorker worker = new PackageFileWorker(ioFile, item.getThird()); - worker.packageFile(outputPath, parents); + worker.packageFile(outputPath, item.getSecond().getParents()); } } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactProjectStructureElement.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactProjectStructureElement.java index d137641004..5663957640 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactProjectStructureElement.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactProjectStructureElement.java @@ -20,9 +20,9 @@ import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext; import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.*; import com.intellij.packaging.artifacts.Artifact; -import com.intellij.packaging.elements.CompositePackagingElement; import com.intellij.packaging.elements.PackagingElement; import com.intellij.packaging.impl.artifacts.ArtifactUtil; +import com.intellij.packaging.impl.artifacts.PackagingElementPath; import com.intellij.packaging.impl.artifacts.PackagingElementProcessor; import com.intellij.packaging.impl.elements.ArtifactPackagingElement; import com.intellij.packaging.impl.elements.LibraryPackagingElement; @@ -64,19 +64,19 @@ public class ArtifactProjectStructureElement extends ProjectStructureElement { final List usages = new ArrayList(); ArtifactUtil.processPackagingElements(myArtifactsStructureContext.getRootElement(artifact), null, new PackagingElementProcessor>() { @Override - public boolean process(@NotNull List> parents, @NotNull PackagingElement packagingElement) { + public boolean process(@NotNull PackagingElement packagingElement, @NotNull PackagingElementPath path) { if (packagingElement instanceof ModuleOutputPackagingElement) { final Module module = ((ModuleOutputPackagingElement)packagingElement).findModule(myArtifactsStructureContext); if (module != null) { usages.add(new UsageInArtifact(myOriginalArtifact, myArtifactsStructureContext, new ModuleProjectStructureElement(myContext, module), - ArtifactProjectStructureElement.this, getPathFromRoot(parents, "/"), packagingElement)); + ArtifactProjectStructureElement.this, path.getPathString(), packagingElement)); } } else if (packagingElement instanceof LibraryPackagingElement) { final Library library = ((LibraryPackagingElement)packagingElement).findLibrary(myArtifactsStructureContext); if (library != null) { usages.add(new UsageInArtifact(myOriginalArtifact, myArtifactsStructureContext, new LibraryProjectStructureElement(myContext, library), - ArtifactProjectStructureElement.this, getPathFromRoot(parents, "/"), packagingElement)); + ArtifactProjectStructureElement.this, path.getPathString(), packagingElement)); } } else if (packagingElement instanceof ArtifactPackagingElement) { @@ -84,7 +84,7 @@ public class ArtifactProjectStructureElement extends ProjectStructureElement { if (usedArtifact != null) { final ArtifactProjectStructureElement artifactElement = myArtifactsStructureContext.getOrCreateArtifactElement(usedArtifact); usages.add(new UsageInArtifact(myOriginalArtifact, myArtifactsStructureContext, artifactElement, - ArtifactProjectStructureElement.this, getPathFromRoot(parents, "/"), packagingElement)); + ArtifactProjectStructureElement.this, path.getPathString(), packagingElement)); } } return true; diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/ArtifactExternalDependenciesImporter.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/ArtifactExternalDependenciesImporter.java index 560b79d7f4..7f49da105f 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/ArtifactExternalDependenciesImporter.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/ArtifactExternalDependenciesImporter.java @@ -23,6 +23,7 @@ import com.intellij.packaging.elements.CompositePackagingElement; import com.intellij.packaging.elements.PackagingElement; import com.intellij.packaging.elements.PackagingElementResolvingContext; import com.intellij.packaging.impl.artifacts.ArtifactUtil; +import com.intellij.packaging.impl.artifacts.PackagingElementPath; import com.intellij.packaging.impl.artifacts.PackagingElementProcessor; import com.intellij.packaging.impl.elements.ArtifactElementType; import com.intellij.packaging.impl.elements.ArtifactPackagingElement; @@ -61,11 +62,10 @@ public class ArtifactExternalDependenciesImporter { for (Artifact artifact : artifactModel.getArtifacts()) { ArtifactUtil.processPackagingElements(artifact, ArtifactElementType.ARTIFACT_ELEMENT_TYPE, new PackagingElementProcessor() { @Override - public boolean process(@NotNull List> parents, - @NotNull ArtifactPackagingElement artifactPackagingElement) { + public boolean process(@NotNull ArtifactPackagingElement artifactPackagingElement, @NotNull PackagingElementPath path) { final Artifact included = artifactPackagingElement.findArtifact(context); - if (!parents.isEmpty() && included != null) { - final CompositePackagingElement parent = parents.get(0); + final CompositePackagingElement parent = path.getLastParent(); + if (parent != null && included != null) { final List> elements = myExternalDependencies.get(included); if (elements != null) { elementsToInclude.add(Pair.create(parent, elements)); -- 2.11.4.GIT