mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
FileCopyPackagingElement splitted to FileCopy and DirectoryCopy
This commit is contained in:
@@ -62,7 +62,7 @@ public class ArtifactUtil {
|
||||
}
|
||||
|
||||
public static <E extends PackagingElement<?>> boolean processPackagingElements(@NotNull Artifact artifact, @Nullable PackagingElementType<E> type,
|
||||
@NotNull final Processor<E> processor,
|
||||
@NotNull final Processor<? super E> processor,
|
||||
final @NotNull PackagingElementResolvingContext resolvingContext,
|
||||
final boolean processSubstitutions) {
|
||||
return processPackagingElements(artifact, type, new PackagingElementProcessor<E>() {
|
||||
@@ -74,24 +74,24 @@ public class ArtifactUtil {
|
||||
}
|
||||
|
||||
public static <E extends PackagingElement<?>> boolean processPackagingElements(@NotNull Artifact artifact, @Nullable PackagingElementType<E> type,
|
||||
@NotNull PackagingElementProcessor<E> processor,
|
||||
@NotNull PackagingElementProcessor<? super E> processor,
|
||||
final @NotNull PackagingElementResolvingContext resolvingContext,
|
||||
final boolean processSubstitutions) {
|
||||
return processPackagingElements(artifact.getRootElement(), type, processor, resolvingContext, processSubstitutions, artifact.getArtifactType());
|
||||
}
|
||||
|
||||
public static <E extends PackagingElement<?>> boolean processPackagingElements(final PackagingElement<?> rootElement, @Nullable PackagingElementType<E> type,
|
||||
@NotNull PackagingElementProcessor<E> processor,
|
||||
@NotNull PackagingElementProcessor<? super E> 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.<CompositePackagingElement<?>>emptyList(), new HashSet<PackagingElement<?>>());
|
||||
}
|
||||
|
||||
private static <E extends PackagingElement<?>> boolean processElements(final List<? extends PackagingElement<?>> elements,
|
||||
@Nullable PackagingElementType<E> type,
|
||||
@NotNull PackagingElementProcessor<E> processor,
|
||||
@NotNull PackagingElementProcessor<? super E> processor,
|
||||
final @NotNull PackagingElementResolvingContext resolvingContext,
|
||||
final boolean processSubstitutions, ArtifactType artifactType,
|
||||
FList<CompositePackagingElement<?>> parents,
|
||||
@@ -105,7 +105,7 @@ public class ArtifactUtil {
|
||||
}
|
||||
|
||||
private static <E extends PackagingElement<?>> boolean processElements(@NotNull PackagingElement<?> element, @Nullable PackagingElementType<E> type,
|
||||
@NotNull PackagingElementProcessor<E> processor,
|
||||
@NotNull PackagingElementProcessor<? super E> 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<FileOrDirectoryCopyPackagingElement<?>> 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<Pair<Artifact, String>> findContainingArtifactsWithOutputPaths(@NotNull final VirtualFile file, @NotNull Project project) {
|
||||
final List<Pair<Artifact, String>> artifacts = new ArrayList<Pair<Artifact, String>>();
|
||||
for (final Artifact artifact : ArtifactManager.getInstance(project).getArtifacts()) {
|
||||
processPackagingElements(artifact, PackagingElementFactoryImpl.FILE_COPY_ELEMENT_TYPE, new PackagingElementProcessor<FileCopyPackagingElement>() {
|
||||
processFileOrDirectoryCopyElements(artifact, new PackagingElementProcessor<FileOrDirectoryCopyPackagingElement<?>>() {
|
||||
@Override
|
||||
public boolean process(@NotNull List<CompositePackagingElement<?>> 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<CompositePackagingElement<?>> compositeChildren = new SmartList<CompositePackagingElement<?>>();
|
||||
final List<FileCopyPackagingElement> fileCopies = new SmartList<FileCopyPackagingElement>();
|
||||
final List<FileCopyPackagingElement> dirCopies = new SmartList<FileCopyPackagingElement>();
|
||||
final List<DirectoryCopyPackagingElement> dirCopies = new SmartList<DirectoryCopyPackagingElement>();
|
||||
processElements(parent.getChildren(), context, artifactType, new Processor<PackagingElement<?>>() {
|
||||
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);
|
||||
|
||||
+65
@@ -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<DirectoryCopyPackagingElement> {
|
||||
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<? extends Generator> 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;
|
||||
}
|
||||
}
|
||||
+8
-38
@@ -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<FileCopyPackagingElement> implements RenameablePackagingElement {
|
||||
@NonNls public static final String PATH_ATTRIBUTE = "path";
|
||||
public class FileCopyPackagingElement extends FileOrDirectoryCopyPackagingElement<FileCopyPackagingElement> 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<FileCopyPackaging
|
||||
public List<? extends Generator> 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<FileCopyPackaging
|
||||
@NotNull PackagingElementResolvingContext resolvingContext,
|
||||
@NotNull ArtifactIncrementalCompilerContext compilerContext, @NotNull ArtifactType artifactType) {
|
||||
final VirtualFile file = findFile();
|
||||
if (file == null || !file.isValid()) {
|
||||
return;
|
||||
}
|
||||
if (file.isDirectory()) {
|
||||
creator.addDirectoryCopyInstructions(file, null);
|
||||
}
|
||||
else {
|
||||
if (file != null && file.isValid() && !file.isDirectory()) {
|
||||
creator.addFileCopyInstruction(file, getOutputFileName());
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public VirtualFile findFile() {
|
||||
return LocalFileSystem.getInstance().findFileByPath(myFilePath);
|
||||
}
|
||||
|
||||
@NonNls @Override
|
||||
public String toString() {
|
||||
return "file:" + myFilePath + (myRenamedOutputFileName != null ? ",rename to:" + myRenamedOutputFileName : "");
|
||||
}
|
||||
|
||||
public boolean isDirectory() {
|
||||
final VirtualFile file = findFile();
|
||||
return file != null && file.isDirectory();
|
||||
return new File(FileUtil.toSystemDependentName(myFilePath)).isDirectory();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isEqualTo(@NotNull 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<FileCopyPackaging
|
||||
setRenamedOutputFileName(state.getRenamedOutputFileName());
|
||||
}
|
||||
|
||||
@Attribute(PATH_ATTRIBUTE)
|
||||
public String getFilePath() {
|
||||
return myFilePath;
|
||||
}
|
||||
|
||||
public void setFilePath(String filePath) {
|
||||
myFilePath = filePath;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Attribute(OUTPUT_FILE_NAME_ATTRIBUTE)
|
||||
public String getRenamedOutputFileName() {
|
||||
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package com.intellij.packaging.impl.elements;
|
||||
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.packaging.elements.PackagingElement;
|
||||
import com.intellij.packaging.elements.PackagingElementType;
|
||||
import com.intellij.util.xmlb.annotations.Attribute;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class FileOrDirectoryCopyPackagingElement<T extends FileOrDirectoryCopyPackagingElement> extends PackagingElement<T> {
|
||||
@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;
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -47,7 +47,8 @@ public class LibraryPackagingElement extends ComplexPackagingElement<LibraryPack
|
||||
final VirtualFile[] files = library.getFiles(OrderRootType.CLASSES);
|
||||
final List<PackagingElement<?>> elements = new ArrayList<PackagingElement<?>>();
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
+48
-8
@@ -42,12 +42,13 @@ public class PackagingElementFactoryImpl extends PackagingElementFactory {
|
||||
public static final PackagingElementType<DirectoryPackagingElement> DIRECTORY_ELEMENT_TYPE = new DirectoryElementType();
|
||||
public static final PackagingElementType<ArchivePackagingElement> ARCHIVE_ELEMENT_TYPE = new ArchiveElementType();
|
||||
public static final PackagingElementType<FileCopyPackagingElement> FILE_COPY_ELEMENT_TYPE = new FileCopyElementType();
|
||||
public static final PackagingElementType<DirectoryCopyPackagingElement> DIRECTORY_COPY_ELEMENT_TYPE = new DirectoryCopyElementType();
|
||||
public static final PackagingElementType<ArtifactRootElement<?>> 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<PackagingElement<?>> elements = new ArrayList<PackagingElement<?>>();
|
||||
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<FileCopyPackagingElement> {
|
||||
public static class FileCopyElementType extends PackagingElementType<FileCopyPackagingElement> {
|
||||
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<? extends FileCopyPackagingElement> 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<FileCopyPackagingElement> list = new ArrayList<FileCopyPackagingElement>();
|
||||
@@ -359,6 +363,42 @@ public class PackagingElementFactoryImpl extends PackagingElementFactory {
|
||||
}
|
||||
}
|
||||
|
||||
public static class DirectoryCopyElementType extends PackagingElementType<DirectoryCopyPackagingElement> {
|
||||
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<? extends DirectoryCopyPackagingElement> 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<DirectoryCopyPackagingElement> list = new ArrayList<DirectoryCopyPackagingElement>();
|
||||
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<ArtifactRootElement<?>> {
|
||||
protected ArtifactRootElementType() {
|
||||
super("root", "");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-4
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user