From 4d3897caf05d61352b667d9637677a2c180b219f Mon Sep 17 00:00:00 2001 From: nik Date: Thu, 8 Oct 2009 11:43:32 +0400 Subject: [PATCH] FileCopyPackagingElement splitted to FileCopy and DirectoryCopy --- .../impl/artifacts/ArtifactUtil.java | 46 +++++++------ .../DirectoryCopyPackagingElement.java | 65 +++++++++++++++++++ .../elements/FileCopyPackagingElement.java | 46 +++---------- .../FileOrDirectoryCopyPackagingElement.java | 48 ++++++++++++++ .../elements/LibraryPackagingElement.java | 3 +- .../impl/elements/ManifestFileUtil.java | 14 ++-- .../elements/PackagingElementFactoryImpl.java | 56 +++++++++++++--- .../impl/ui/DirectoryCopyPresentation.java | 60 +++++++++++++++++ .../impl/ui/FileCopyPresentation.java | 31 +++------ .../elements/PackagingElementFactory.java | 9 +-- 10 files changed, 282 insertions(+), 96 deletions(-) create mode 100644 java/compiler/impl/src/com/intellij/packaging/impl/elements/DirectoryCopyPackagingElement.java create mode 100644 java/compiler/impl/src/com/intellij/packaging/impl/elements/FileOrDirectoryCopyPackagingElement.java create mode 100644 java/compiler/impl/src/com/intellij/packaging/impl/ui/DirectoryCopyPresentation.java 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 ebe959ee1606..27b57215446a 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 @@ -62,7 +62,7 @@ public class ArtifactUtil { } public static > boolean processPackagingElements(@NotNull Artifact artifact, @Nullable PackagingElementType type, - @NotNull final Processor processor, + @NotNull final Processor processor, final @NotNull PackagingElementResolvingContext resolvingContext, final boolean processSubstitutions) { return processPackagingElements(artifact, type, new PackagingElementProcessor() { @@ -74,24 +74,24 @@ public class ArtifactUtil { } public static > boolean processPackagingElements(@NotNull Artifact artifact, @Nullable PackagingElementType type, - @NotNull PackagingElementProcessor processor, + @NotNull PackagingElementProcessor processor, final @NotNull PackagingElementResolvingContext resolvingContext, final boolean processSubstitutions) { return processPackagingElements(artifact.getRootElement(), type, processor, resolvingContext, processSubstitutions, artifact.getArtifactType()); } public static > boolean processPackagingElements(final PackagingElement rootElement, @Nullable PackagingElementType type, - @NotNull PackagingElementProcessor processor, + @NotNull PackagingElementProcessor processor, final @NotNull PackagingElementResolvingContext resolvingContext, - final boolean processSubstituions, + final boolean processSubstitutions, final ArtifactType artifactType) { - return processElements(rootElement, type, processor, resolvingContext, processSubstituions, artifactType, + return processElements(rootElement, type, processor, resolvingContext, processSubstitutions, artifactType, FList.>emptyList(), new HashSet>()); } private static > boolean processElements(final List> elements, @Nullable PackagingElementType type, - @NotNull PackagingElementProcessor processor, + @NotNull PackagingElementProcessor processor, final @NotNull PackagingElementResolvingContext resolvingContext, final boolean processSubstitutions, ArtifactType artifactType, FList> parents, @@ -105,7 +105,7 @@ public class ArtifactUtil { } private static > boolean processElements(@NotNull PackagingElement element, @Nullable PackagingElementType type, - @NotNull PackagingElementProcessor processor, + @NotNull PackagingElementProcessor processor, @NotNull PackagingElementResolvingContext resolvingContext, final boolean processSubstitutions, ArtifactType artifactType, @@ -232,7 +232,7 @@ public class ArtifactUtil { } else if (element instanceof FileCopyPackagingElement) { final FileCopyPackagingElement fileCopy = (FileCopyPackagingElement)element; - if (!fileCopy.isDirectory() && firstName.equals(fileCopy.getOutputFileName())) { + if (firstName.equals(fileCopy.getOutputFileName())) { children.add(element); } } @@ -279,14 +279,22 @@ public class ArtifactUtil { return result; } + private static void processFileOrDirectoryCopyElements(Artifact artifact, + PackagingElementProcessor> processor, + PackagingElementResolvingContext context, + boolean processSubstitutions) { + processPackagingElements(artifact, PackagingElementFactoryImpl.FILE_COPY_ELEMENT_TYPE, processor, context, processSubstitutions); + processPackagingElements(artifact, PackagingElementFactoryImpl.DIRECTORY_COPY_ELEMENT_TYPE, processor, context, processSubstitutions); + } + public static Collection> findContainingArtifactsWithOutputPaths(@NotNull final VirtualFile file, @NotNull Project project) { final List> artifacts = new ArrayList>(); for (final Artifact artifact : ArtifactManager.getInstance(project).getArtifacts()) { - processPackagingElements(artifact, PackagingElementFactoryImpl.FILE_COPY_ELEMENT_TYPE, new PackagingElementProcessor() { + processFileOrDirectoryCopyElements(artifact, new PackagingElementProcessor>() { @Override public boolean process(@NotNull List> parents, - @NotNull FileCopyPackagingElement fileCopyPackagingElement) { - final VirtualFile root = fileCopyPackagingElement.findFile(); + @NotNull FileOrDirectoryCopyPackagingElement element) { + final VirtualFile root = element.findFile(); if (root != null && VfsUtil.isAncestor(root, file, false)) { boolean isInArchive = false; for (CompositePackagingElement parent : parents) { @@ -298,8 +306,8 @@ public class ArtifactUtil { String path; if (!isInArchive) { final String relativePath; - if (root.equals(file)) { - relativePath = fileCopyPackagingElement.getOutputFileName(); + if (root.equals(file) && element instanceof FileCopyPackagingElement) { + relativePath = ((FileCopyPackagingElement)element).getOutputFileName(); } else { relativePath = VfsUtil.getRelativePath(file, root, '/'); @@ -345,7 +353,7 @@ public class ArtifactUtil { final List> compositeChildren = new SmartList>(); final List fileCopies = new SmartList(); - final List dirCopies = new SmartList(); + final List dirCopies = new SmartList(); processElements(parent.getChildren(), context, artifactType, new Processor>() { public boolean process(PackagingElement element) { if (element instanceof CompositePackagingElement) { @@ -356,13 +364,13 @@ public class ArtifactUtil { } else if (element instanceof FileCopyPackagingElement) { final FileCopyPackagingElement fileCopyElement = (FileCopyPackagingElement)element; - if (fileCopyElement.isDirectory()) { - dirCopies.add(fileCopyElement); - } - else if (firstName.equals(fileCopyElement.getOutputFileName())) { + if (firstName.equals(fileCopyElement.getOutputFileName())) { fileCopies.add(fileCopyElement); } } + else if (element instanceof DirectoryCopyPackagingElement) { + dirCopies.add((DirectoryCopyPackagingElement)element); + } return true; } }); @@ -376,7 +384,7 @@ public class ArtifactUtil { ContainerUtil.addIfNotNull(fileCopy.findFile(), result); } } - for (FileCopyPackagingElement dirCopy : dirCopies) { + for (DirectoryCopyPackagingElement dirCopy : dirCopies) { final VirtualFile sourceRoot = dirCopy.findFile(); if (sourceRoot != null) { ContainerUtil.addIfNotNull(sourceRoot.findFileByRelativePath(outputPath), result); diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/DirectoryCopyPackagingElement.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/DirectoryCopyPackagingElement.java new file mode 100644 index 000000000000..f2369b5ca1f4 --- /dev/null +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/DirectoryCopyPackagingElement.java @@ -0,0 +1,65 @@ +package com.intellij.packaging.impl.elements; + +import com.intellij.compiler.ant.Generator; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.packaging.artifacts.ArtifactType; +import com.intellij.packaging.elements.*; +import com.intellij.packaging.impl.ui.DirectoryCopyPresentation; +import com.intellij.packaging.ui.ArtifactEditorContext; +import com.intellij.packaging.ui.PackagingElementPresentation; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; + +/** + * @author nik + */ +public class DirectoryCopyPackagingElement extends FileOrDirectoryCopyPackagingElement { + public DirectoryCopyPackagingElement() { + super(PackagingElementFactoryImpl.DIRECTORY_COPY_ELEMENT_TYPE); + } + + public DirectoryCopyPackagingElement(String directoryPath) { + this(); + myFilePath = directoryPath; + } + + @Override + public PackagingElementPresentation createPresentation(@NotNull ArtifactEditorContext context) { + return new DirectoryCopyPresentation(myFilePath); + } + + @Override + public List computeAntInstructions(@NotNull PackagingElementResolvingContext resolvingContext, + @NotNull AntCopyInstructionCreator creator, + @NotNull ArtifactAntGenerationContext generationContext, + @NotNull ArtifactType artifactType) { + final String path = generationContext.getSubstitutedPath(myFilePath); + return Collections.singletonList((Generator)creator.createDirectoryContentCopyInstruction(path)); + } + + @Override + public void computeIncrementalCompilerInstructions(@NotNull IncrementalCompilerInstructionCreator creator, + @NotNull PackagingElementResolvingContext resolvingContext, + @NotNull ArtifactIncrementalCompilerContext compilerContext, + @NotNull ArtifactType artifactType) { + final VirtualFile file = findFile(); + if (file != null && file.isValid() && file.isDirectory()) { + creator.addDirectoryCopyInstructions(file, null); + } + } + + public DirectoryCopyPackagingElement getState() { + return this; + } + + public void loadState(DirectoryCopyPackagingElement state) { + myFilePath = state.getFilePath(); + } + + @Override + public String toString() { + return "dir:" + myFilePath; + } +} diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/FileCopyPackagingElement.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/FileCopyPackagingElement.java index 2e9ba01ea6b8..12976bb0bbce 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/elements/FileCopyPackagingElement.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/FileCopyPackagingElement.java @@ -3,7 +3,6 @@ package com.intellij.packaging.impl.elements; import com.intellij.compiler.ant.Generator; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; @@ -25,10 +24,8 @@ import java.util.List; /** * @author nik */ -public class FileCopyPackagingElement extends PackagingElement implements RenameablePackagingElement { - @NonNls public static final String PATH_ATTRIBUTE = "path"; +public class FileCopyPackagingElement extends FileOrDirectoryCopyPackagingElement implements RenameablePackagingElement { @NonNls public static final String OUTPUT_FILE_NAME_ATTRIBUTE = "output-file-name"; - private String myFilePath; private String myRenamedOutputFileName; public FileCopyPackagingElement() { @@ -53,16 +50,11 @@ public class FileCopyPackagingElement extends PackagingElement computeAntInstructions(@NotNull PackagingElementResolvingContext resolvingContext, @NotNull AntCopyInstructionCreator creator, @NotNull ArtifactAntGenerationContext generationContext, @NotNull ArtifactType artifactType) { - File file = new File(FileUtil.toSystemDependentName(myFilePath)); + if (isDirectory()) { + return Collections.emptyList(); + } final String path = generationContext.getSubstitutedPath(myFilePath); - Generator generator; - if (file.isDirectory()) { - generator = creator.createDirectoryContentCopyInstruction(path); - } - else { - generator = creator.createFileCopyInstruction(path, getOutputFileName()); - } - return Collections.singletonList(generator); + return Collections.singletonList((Generator)creator.createFileCopyInstruction(path, getOutputFileName())); } public String getOutputFileName() { @@ -74,37 +66,24 @@ public class FileCopyPackagingElement extends PackagingElement element) { - return element instanceof FileCopyPackagingElement && myFilePath != null - && myFilePath.equals(((FileCopyPackagingElement)element).getFilePath()) + return element instanceof FileCopyPackagingElement && super.isEqualTo(element) && Comparing.equal(myRenamedOutputFileName, ((FileCopyPackagingElement)element).getRenamedOutputFileName()); } @@ -117,15 +96,6 @@ public class FileCopyPackagingElement extends PackagingElement extends PackagingElement { + @NonNls public static final String PATH_ATTRIBUTE = "path"; + protected String myFilePath; + + public FileOrDirectoryCopyPackagingElement(PackagingElementType type) { + super(type); + } + + protected FileOrDirectoryCopyPackagingElement(PackagingElementType type, String filePath) { + super(type); + myFilePath = filePath; + } + + @Nullable + public VirtualFile findFile() { + return LocalFileSystem.getInstance().findFileByPath(myFilePath); + } + + @Override + public boolean isEqualTo(@NotNull PackagingElement element) { + return element instanceof FileOrDirectoryCopyPackagingElement && + myFilePath != null && + myFilePath.equals(((FileOrDirectoryCopyPackagingElement)element).getFilePath()); + } + + @Attribute(PATH_ATTRIBUTE) + public String getFilePath() { + return myFilePath; + } + + public void setFilePath(String filePath) { + myFilePath = filePath; + } +} diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/LibraryPackagingElement.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/LibraryPackagingElement.java index 0706e54fbc5b..3b3d3ff84482 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/elements/LibraryPackagingElement.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/LibraryPackagingElement.java @@ -47,7 +47,8 @@ public class LibraryPackagingElement extends ComplexPackagingElement> elements = new ArrayList>(); for (VirtualFile file : files) { - elements.add(new FileCopyPackagingElement(FileUtil.toSystemIndependentName(PathUtil.getLocalPath(file)))); + final String path = FileUtil.toSystemIndependentName(PathUtil.getLocalPath(file)); + elements.add(file.isDirectory() && file.isInLocalFileSystem() ? new DirectoryCopyPackagingElement(path) : new FileCopyPackagingElement(path)); } return elements; } 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 a9ee8004cff5..e5ced63da88e 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 @@ -59,13 +59,16 @@ public class ManifestFileUtil { if (element instanceof FileCopyPackagingElement) { final VirtualFile file = ((FileCopyPackagingElement)element).findFile(); if (file != null) { - if (file.isDirectory()) { - sourceDir.set(file); - return false; - } sourceFile.set(file); } } + else if (element instanceof DirectoryCopyPackagingElement) { + final VirtualFile file = ((DirectoryCopyPackagingElement)element).findFile(); + if (file != null) { + sourceDir.set(file); + return false; + } + } return true; } }); @@ -182,6 +185,9 @@ public class ManifestFileUtil { final String fileName = ((FileCopyPackagingElement)element).getOutputFileName(); classpath.add(DeploymentUtil.appendToPath(getPathFromRoot(parents, "/"), fileName)); } + else if (element instanceof DirectoryCopyPackagingElement) { + classpath.add(getPathFromRoot(parents, "/")); + } else if (element instanceof ArchivePackagingElement) { final String archiveName = ((ArchivePackagingElement)element).getName(); classpath.add(DeploymentUtil.appendToPath(getPathFromRoot(parents, "/"), archiveName)); diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/PackagingElementFactoryImpl.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/PackagingElementFactoryImpl.java index 2f385a4ab5c3..be5f9b7e338f 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/elements/PackagingElementFactoryImpl.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/PackagingElementFactoryImpl.java @@ -42,12 +42,13 @@ public class PackagingElementFactoryImpl extends PackagingElementFactory { public static final PackagingElementType DIRECTORY_ELEMENT_TYPE = new DirectoryElementType(); public static final PackagingElementType ARCHIVE_ELEMENT_TYPE = new ArchiveElementType(); public static final PackagingElementType FILE_COPY_ELEMENT_TYPE = new FileCopyElementType(); + public static final PackagingElementType DIRECTORY_COPY_ELEMENT_TYPE = new DirectoryCopyElementType(); public static final PackagingElementType> ARTIFACT_ROOT_ELEMENT_TYPE = new ArtifactRootElementType(); private static final PackagingElementType[] STANDARD_TYPES = { DIRECTORY_ELEMENT_TYPE, ARCHIVE_ELEMENT_TYPE, LibraryElementType.LIBRARY_ELEMENT_TYPE, ModuleOutputElementType.MODULE_OUTPUT_ELEMENT_TYPE, //ModuleWithDependenciesElementType.MODULE_WITH_DEPENDENCIES_TYPE, - ArtifactElementType.ARTIFACT_ELEMENT_TYPE, FILE_COPY_ELEMENT_TYPE, + ArtifactElementType.ARTIFACT_ELEMENT_TYPE, FILE_COPY_ELEMENT_TYPE, DIRECTORY_COPY_ELEMENT_TYPE }; @NotNull @@ -176,7 +177,8 @@ public class PackagingElementFactoryImpl extends PackagingElementFactory { } final List> elements = new ArrayList>(); for (VirtualFile file : library.getFiles(OrderRootType.CLASSES)) { - elements.add(new FileCopyPackagingElement(FileUtil.toSystemIndependentName(PathUtil.getLocalPath(file)))); + final String path = FileUtil.toSystemIndependentName(PathUtil.getLocalPath(file)); + elements.add(file.isDirectory() && file.isInLocalFileSystem() ? new DirectoryCopyPackagingElement(path) : new FileCopyPackagingElement(path)); } return elements; } @@ -213,10 +215,10 @@ public class PackagingElementFactoryImpl extends PackagingElementFactory { return name; } - @Override @NotNull - public FileCopyPackagingElement createFileCopy(@NotNull String filePath) { - return new FileCopyPackagingElement(filePath); + @Override + public PackagingElement createDirectoryCopyWithParentDirectories(@NotNull String filePath, @NotNull String relativeOutputPath) { + return createParentDirectories(relativeOutputPath, new DirectoryCopyPackagingElement(filePath)); } @NotNull @@ -325,14 +327,16 @@ public class PackagingElementFactoryImpl extends PackagingElementFactory { } } - private static class FileCopyElementType extends PackagingElementType { + public static class FileCopyElementType extends PackagingElementType { + public static final Icon ICON = IconLoader.getIcon("/fileTypes/text.png"); + private FileCopyElementType() { super("file-copy", "File"); } @Override public Icon getCreateElementIcon() { - return null; + return ICON; } @Override @@ -343,7 +347,7 @@ public class PackagingElementFactoryImpl extends PackagingElementFactory { @NotNull public List chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact, @NotNull CompositePackagingElement parent) { - final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, true, true, true, false, true); + final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, true, true, false, true); final FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, context.getProject()); final VirtualFile[] files = chooser.choose(null, context.getProject()); final List list = new ArrayList(); @@ -359,6 +363,42 @@ public class PackagingElementFactoryImpl extends PackagingElementFactory { } } + public static class DirectoryCopyElementType extends PackagingElementType { + public static final Icon COPY_OF_FOLDER_ICON = IconLoader.getIcon("/nodes/copyOfFolder.png"); + + private DirectoryCopyElementType() { + super("dir-copy", "Directory Content"); + } + + @Override + public Icon getCreateElementIcon() { + return COPY_OF_FOLDER_ICON; + } + + @Override + public boolean canCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact) { + return true; + } + + @NotNull + public List chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact, + @NotNull CompositePackagingElement parent) { + final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, true); + final FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, context.getProject()); + final VirtualFile[] files = chooser.choose(null, context.getProject()); + final List list = new ArrayList(); + for (VirtualFile file : files) { + list.add(new DirectoryCopyPackagingElement(file.getPath())); + } + return list; + } + + @NotNull + public DirectoryCopyPackagingElement createEmpty(@NotNull Project project) { + return new DirectoryCopyPackagingElement(); + } + } + private static class ArtifactRootElementType extends PackagingElementType> { protected ArtifactRootElementType() { super("root", ""); diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/ui/DirectoryCopyPresentation.java b/java/compiler/impl/src/com/intellij/packaging/impl/ui/DirectoryCopyPresentation.java new file mode 100644 index 000000000000..d87e66eeb319 --- /dev/null +++ b/java/compiler/impl/src/com/intellij/packaging/impl/ui/DirectoryCopyPresentation.java @@ -0,0 +1,60 @@ +package com.intellij.packaging.impl.ui; + +import com.intellij.ide.projectView.PresentationData; +import com.intellij.openapi.compiler.CompilerBundle; +import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.packaging.impl.elements.PackagingElementFactoryImpl; +import com.intellij.packaging.ui.PackagingElementPresentation; +import com.intellij.packaging.ui.PackagingElementWeights; +import com.intellij.ui.SimpleTextAttributes; +import com.intellij.util.PathUtil; +import org.jetbrains.annotations.NotNull; + +/** + * @author nik + */ +public class DirectoryCopyPresentation extends PackagingElementPresentation { + private final String mySourcePath; + private final String mySourceFileName; + private final VirtualFile myFile; + + public DirectoryCopyPresentation(String filePath) { + mySourceFileName = PathUtil.getFileName(filePath); + + String parentPath; + myFile = LocalFileSystem.getInstance().findFileByPath(filePath); + if (myFile != null) { + final VirtualFile parent = myFile.getParent(); + parentPath = parent != null ? FileUtil.toSystemDependentName(parent.getPath()) : ""; + } + else { + parentPath = FileUtil.toSystemDependentName(PathUtil.getParentPath(filePath)); + } + + mySourcePath = parentPath; + } + + public String getPresentableName() { + return mySourceFileName; + } + + public void render(@NotNull PresentationData presentationData, SimpleTextAttributes mainAttributes, SimpleTextAttributes commentAttributes) { + presentationData.setIcons(PackagingElementFactoryImpl.DirectoryCopyElementType.COPY_OF_FOLDER_ICON); + if (myFile == null || !myFile.isDirectory()) { + mainAttributes = SimpleTextAttributes.ERROR_ATTRIBUTES; + final VirtualFile parentFile = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(mySourcePath)); + if (parentFile == null) { + commentAttributes = SimpleTextAttributes.ERROR_ATTRIBUTES; + } + } + presentationData.addText(CompilerBundle.message("node.text.0.directory.content", mySourceFileName), mainAttributes); + presentationData.addText(" (" + mySourcePath + ")", commentAttributes); + } + + @Override + public int getWeight() { + return PackagingElementWeights.DIRECTORY_COPY; + } +} \ No newline at end of file diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/ui/FileCopyPresentation.java b/java/compiler/impl/src/com/intellij/packaging/impl/ui/FileCopyPresentation.java index 5a9e0ceee603..eca61b644960 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/ui/FileCopyPresentation.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/ui/FileCopyPresentation.java @@ -1,32 +1,25 @@ package com.intellij.packaging.impl.ui; import com.intellij.ide.projectView.PresentationData; -import com.intellij.openapi.compiler.CompilerBundle; -import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.packaging.impl.elements.PackagingElementFactoryImpl; import com.intellij.packaging.ui.PackagingElementPresentation; import com.intellij.packaging.ui.PackagingElementWeights; import com.intellij.ui.SimpleTextAttributes; import com.intellij.util.PathUtil; import org.jetbrains.annotations.NotNull; -import javax.swing.*; - /** * @author nik */ public class FileCopyPresentation extends PackagingElementPresentation { - private static final Icon COPY_OF_FOLDER_ICON = IconLoader.getIcon("/nodes/copyOfFolder.png"); private final String mySourcePath; private final String myOutputFileName; - private final String mySourceFileName; private final VirtualFile myFile; - private final boolean myIsDirectory; public FileCopyPresentation(String filePath, String outputFileName) { - mySourceFileName = PathUtil.getFileName(filePath); myOutputFileName = outputFileName; String parentPath; @@ -34,15 +27,14 @@ public class FileCopyPresentation extends PackagingElementPresentation { if (myFile != null) { final VirtualFile parent = myFile.getParent(); parentPath = parent != null ? FileUtil.toSystemDependentName(parent.getPath()) : ""; - myIsDirectory = myFile.isDirectory(); } else { parentPath = FileUtil.toSystemDependentName(PathUtil.getParentPath(filePath)); - myIsDirectory = false; } - if (!myIsDirectory && !mySourceFileName.equals(myOutputFileName)) { - mySourcePath = parentPath + "/" + mySourceFileName; + String sourceFileName = PathUtil.getFileName(filePath); + if (!sourceFileName.equals(myOutputFileName)) { + mySourcePath = parentPath + "/" + sourceFileName; } else { mySourcePath = parentPath; @@ -54,18 +46,13 @@ public class FileCopyPresentation extends PackagingElementPresentation { } public void render(@NotNull PresentationData presentationData, SimpleTextAttributes mainAttributes, SimpleTextAttributes commentAttributes) { - if (myFile != null) { - presentationData.setIcons(myIsDirectory ? COPY_OF_FOLDER_ICON : myFile.getIcon()); - if (myIsDirectory) { - presentationData.addText(CompilerBundle.message("node.text.0.directory.content", mySourceFileName), mainAttributes); - } - else { - presentationData.addText(myOutputFileName, mainAttributes); - } + if (myFile != null && !myFile.isDirectory()) { + presentationData.setIcons(myFile.getIcon()); + presentationData.addText(myOutputFileName, mainAttributes); presentationData.addText(" (" + mySourcePath + ")", commentAttributes); } else { - presentationData.setIcons(COPY_OF_FOLDER_ICON); + presentationData.setIcons(PackagingElementFactoryImpl.FileCopyElementType.ICON); presentationData.addText(myOutputFileName, SimpleTextAttributes.ERROR_ATTRIBUTES); final VirtualFile parentFile = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(mySourcePath)); presentationData.addText("(" + mySourcePath + ")", @@ -75,6 +62,6 @@ public class FileCopyPresentation extends PackagingElementPresentation { @Override public int getWeight() { - return myIsDirectory ? PackagingElementWeights.DIRECTORY_COPY : PackagingElementWeights.FILE_COPY; + return PackagingElementWeights.FILE_COPY; } } diff --git a/java/compiler/openapi/src/com/intellij/packaging/elements/PackagingElementFactory.java b/java/compiler/openapi/src/com/intellij/packaging/elements/PackagingElementFactory.java index 689da63e1ae6..f16ce44e63ef 100644 --- a/java/compiler/openapi/src/com/intellij/packaging/elements/PackagingElementFactory.java +++ b/java/compiler/openapi/src/com/intellij/packaging/elements/PackagingElementFactory.java @@ -44,17 +44,18 @@ public abstract class PackagingElementFactory { @NotNull public abstract PackagingElement createLibraryFiles(@NotNull String level, @NotNull String name); - @NotNull - public abstract PackagingElement createFileCopy(@NotNull String filePath); - @NotNull - public abstract PackagingElement createFileCopyWithParentDirectories(@NotNull String filePath, @NotNull String relativeOutputPath); + public abstract PackagingElement createDirectoryCopyWithParentDirectories(@NotNull String filePath, @NotNull String relativeOutputPath); @NotNull public abstract PackagingElement createFileCopyWithParentDirectories(@NotNull String filePath, @NotNull String relativeOutputPath, @Nullable String outputFileName); + @NotNull + public abstract PackagingElement createFileCopyWithParentDirectories(@NotNull String filePath, @NotNull String relativeOutputPath); + + @NotNull public abstract CompositePackagingElement getOrCreateDirectory(@NotNull CompositePackagingElement parent, @NotNull String relativePath);