mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-51729: Ability to include exploded JARs in artifacts
This commit is contained in:
+9
-2
@@ -43,11 +43,18 @@ public class ArchiveAntCopyInstructionCreator implements AntCopyInstructionCreat
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public AntCopyInstructionCreator subFolder(String directoryName) {
|
||||
public AntCopyInstructionCreator subFolder(@NotNull String directoryName) {
|
||||
return new ArchiveAntCopyInstructionCreator(myPrefix + "/" + directoryName);
|
||||
}
|
||||
|
||||
public Generator createSubFolderCommand(String directoryName) {
|
||||
public Generator createSubFolderCommand(@NotNull String directoryName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Generator createExtractedDirectoryInstruction(@NotNull String jarPath, @NotNull String pathInJar) {
|
||||
final String pattern = pathInJar.length() == 0 ? null : pathInJar + "**";
|
||||
return ZipFileSet.createUnpackedSet(jarPath, pathInJar, true, pattern);
|
||||
}
|
||||
}
|
||||
|
||||
+15
-5
@@ -17,9 +17,7 @@ package com.intellij.compiler.ant.artifacts;
|
||||
|
||||
import com.intellij.compiler.ant.Generator;
|
||||
import com.intellij.compiler.ant.Tag;
|
||||
import com.intellij.compiler.ant.taskdefs.Copy;
|
||||
import com.intellij.compiler.ant.taskdefs.FileSet;
|
||||
import com.intellij.compiler.ant.taskdefs.Mkdir;
|
||||
import com.intellij.compiler.ant.taskdefs.*;
|
||||
import com.intellij.packaging.elements.AntCopyInstructionCreator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -50,11 +48,23 @@ public class DirectoryAntCopyInstructionCreator implements AntCopyInstructionCre
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public AntCopyInstructionCreator subFolder(String directoryName) {
|
||||
public AntCopyInstructionCreator subFolder(@NotNull String directoryName) {
|
||||
return new DirectoryAntCopyInstructionCreator(myOutputDirectory + "/" + directoryName);
|
||||
}
|
||||
|
||||
public Generator createSubFolderCommand(String directoryName) {
|
||||
public Generator createSubFolderCommand(@NotNull String directoryName) {
|
||||
return new Mkdir(myOutputDirectory + "/" + directoryName);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Generator createExtractedDirectoryInstruction(@NotNull String jarPath, @NotNull String pathInJar) {
|
||||
final Unzip unzip = new Unzip(jarPath, myOutputDirectory);
|
||||
if (pathInJar.length() > 0) {
|
||||
final PatternSet patterns = new PatternSet(null);
|
||||
patterns.add(new Include(pathInJar + "**"));
|
||||
unzip.add(patterns);
|
||||
}
|
||||
return unzip;
|
||||
}
|
||||
}
|
||||
|
||||
+37
-6
@@ -25,6 +25,7 @@ import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.packaging.impl.compiler.ArtifactCompilerUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.graph.CachingSemiGraph;
|
||||
import com.intellij.util.graph.DFSTBuilder;
|
||||
@@ -159,8 +160,14 @@ public class JarsBuilder {
|
||||
try {
|
||||
final THashSet<String> writtenPaths = new THashSet<String>();
|
||||
for (Pair<String, VirtualFile> pair : jar.getPackedFiles()) {
|
||||
File file = VfsUtil.virtualToIoFile(pair.getSecond());
|
||||
addFileToJar(jarOutputStream, file, pair.getFirst(), writtenPaths);
|
||||
final VirtualFile sourceFile = pair.getSecond();
|
||||
if (sourceFile.isInLocalFileSystem()) {
|
||||
File file = VfsUtil.virtualToIoFile(sourceFile);
|
||||
addFileToJar(jarOutputStream, file, pair.getFirst(), writtenPaths);
|
||||
}
|
||||
else {
|
||||
extractFileAndAddToJar(jarOutputStream, sourceFile, pair.getFirst(), writtenPaths);
|
||||
}
|
||||
}
|
||||
|
||||
for (Pair<String, JarInfo> nestedJar : jar.getPackedJars()) {
|
||||
@@ -178,9 +185,35 @@ public class JarsBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
private void extractFileAndAddToJar(JarOutputStream jarOutputStream, VirtualFile sourceFile, String relativePath, THashSet<String> writtenPaths)
|
||||
throws IOException {
|
||||
relativePath = addParentDirectories(jarOutputStream, writtenPaths, relativePath);
|
||||
myContext.getProgressIndicator().setText2(relativePath);
|
||||
if (!writtenPaths.add(relativePath)) return;
|
||||
|
||||
final BufferedInputStream input = ArtifactCompilerUtil.getJarEntryInputStream(sourceFile, myContext);
|
||||
if (input == null) return;
|
||||
|
||||
ZipEntry entry = new ZipEntry(relativePath);
|
||||
entry.setTime(ArtifactCompilerUtil.getJarFile(sourceFile).lastModified());
|
||||
jarOutputStream.putNextEntry(entry);
|
||||
FileUtil.copy(input, jarOutputStream);
|
||||
jarOutputStream.closeEntry();
|
||||
}
|
||||
|
||||
private void addFileToJar(final @NotNull JarOutputStream jarOutputStream, final @NotNull File file, @NotNull String relativePath,
|
||||
final @NotNull THashSet<String> writtenPaths) throws IOException {
|
||||
//todo[nik] check file exists?
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
relativePath = addParentDirectories(jarOutputStream, writtenPaths, relativePath);
|
||||
myContext.getProgressIndicator().setText2(relativePath);
|
||||
ZipUtil.addFileToZip(jarOutputStream, file, relativePath, writtenPaths, myFileFilter);
|
||||
}
|
||||
|
||||
private static String addParentDirectories(JarOutputStream jarOutputStream, THashSet<String> writtenPaths, String relativePath)
|
||||
throws IOException {
|
||||
while (relativePath.startsWith("/")) {
|
||||
relativePath = relativePath.substring(1);
|
||||
}
|
||||
@@ -193,9 +226,7 @@ public class JarsBuilder {
|
||||
}
|
||||
i = relativePath.indexOf('/', i + 1);
|
||||
}
|
||||
|
||||
myContext.getProgressIndicator().setText2(relativePath);
|
||||
ZipUtil.addFileToZip(jarOutputStream, file, relativePath, writtenPaths, myFileFilter);
|
||||
return relativePath;
|
||||
}
|
||||
|
||||
private static void addEntry(final ZipOutputStream output, @NonNls final String relativePath) throws IOException {
|
||||
|
||||
@@ -320,6 +320,7 @@ public class ArtifactUtil {
|
||||
boolean processSubstitutions) {
|
||||
processPackagingElements(artifact, PackagingElementFactoryImpl.FILE_COPY_ELEMENT_TYPE, processor, context, processSubstitutions);
|
||||
processPackagingElements(artifact, PackagingElementFactoryImpl.DIRECTORY_COPY_ELEMENT_TYPE, processor, context, processSubstitutions);
|
||||
processPackagingElements(artifact, PackagingElementFactoryImpl.EXTRACTED_DIRECTORY_ELEMENT_TYPE, processor, context, processSubstitutions);
|
||||
}
|
||||
|
||||
public static Collection<Trinity<Artifact, PackagingElementPath, String>> findContainingArtifactsWithOutputPaths(@NotNull final VirtualFile file, @NotNull Project project) {
|
||||
@@ -417,8 +418,8 @@ public class ArtifactUtil {
|
||||
ContainerUtil.addIfNotNull(fileCopyElement.findFile(), result);
|
||||
}
|
||||
}
|
||||
else if (element instanceof DirectoryCopyPackagingElement) {
|
||||
final VirtualFile sourceRoot = ((DirectoryCopyPackagingElement)element).findFile();
|
||||
else if (element instanceof DirectoryCopyPackagingElement || element instanceof ExtractedDirectoryPackagingElement) {
|
||||
final VirtualFile sourceRoot = ((FileOrDirectoryCopyPackagingElement<?>)element).findFile();
|
||||
if (sourceRoot != null) {
|
||||
ContainerUtil.addIfNotNull(sourceRoot.findFileByRelativePath(path), result);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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.compiler;
|
||||
|
||||
import com.intellij.openapi.compiler.CompileContext;
|
||||
import com.intellij.openapi.compiler.CompilerMessageCategory;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.JarFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class ArtifactCompilerUtil {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.packaging.impl.compiler.ArtifactCompilerUtil");
|
||||
|
||||
private ArtifactCompilerUtil() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static BufferedInputStream getJarEntryInputStream(VirtualFile sourceFile, final CompileContext context) throws IOException {
|
||||
final String fullPath = sourceFile.getPath();
|
||||
final int jarEnd = fullPath.indexOf(JarFileSystem.JAR_SEPARATOR);
|
||||
LOG.assertTrue(jarEnd != -1, fullPath);
|
||||
String pathInJar = fullPath.substring(jarEnd + JarFileSystem.JAR_SEPARATOR.length());
|
||||
String jarPath = fullPath.substring(0, jarEnd);
|
||||
final ZipFile jarFile = new ZipFile(new File(FileUtil.toSystemDependentName(jarPath)));
|
||||
final ZipEntry entry = jarFile.getEntry(pathInJar);
|
||||
if (entry == null) {
|
||||
context.addMessage(CompilerMessageCategory.ERROR, "Cannot extract '" + pathInJar + "' from '" + jarFile.getName() + "': entry not found", null, -1, -1);
|
||||
return null;
|
||||
}
|
||||
|
||||
return new BufferedInputStream(jarFile.getInputStream(entry)) {
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
super.close();
|
||||
jarFile.close();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static File getJarFile(VirtualFile jarEntry) {
|
||||
String fullPath = jarEntry.getPath();
|
||||
return new File(FileUtil.toSystemDependentName(fullPath.substring(fullPath.indexOf(JarFileSystem.JAR_SEPARATOR))));
|
||||
}
|
||||
}
|
||||
+38
-12
@@ -31,7 +31,7 @@ import com.intellij.openapi.deployment.DeploymentUtil;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
@@ -53,9 +53,7 @@ import com.intellij.util.text.CaseInsensitiveStringHashingStrategy;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@@ -164,7 +162,7 @@ public class ArtifactsCompilerInstance extends CompilerInstance<ArtifactBuildTar
|
||||
|
||||
private boolean doBuild(final List<Pair<ArtifactCompilerCompileItem, ArtifactPackagingItemOutputState>> changedItems,
|
||||
final Set<ArtifactCompilerCompileItem> processedItems,
|
||||
final Set<String> writtenPaths, final Set<String> deletedJars) {
|
||||
final @NotNull Set<String> writtenPaths, final Set<String> deletedJars) {
|
||||
final boolean testMode = ApplicationManager.getApplication().isUnitTestMode();
|
||||
|
||||
final DeploymentUtil deploymentUtil = DeploymentUtil.getInstance();
|
||||
@@ -188,20 +186,26 @@ public class ArtifactsCompilerInstance extends CompilerInstance<ArtifactBuildTar
|
||||
final Ref<IOException> exception = Ref.create(null);
|
||||
new ReadAction() {
|
||||
protected void run(final Result result) {
|
||||
final File fromFile = VfsUtil.virtualToIoFile(sourceItem.getFile());
|
||||
final VirtualFile sourceFile = sourceItem.getFile();
|
||||
for (DestinationInfo destination : sourceItem.getDestinations()) {
|
||||
if (destination instanceof ExplodedDestinationInfo) {
|
||||
final ExplodedDestinationInfo explodedDestination = (ExplodedDestinationInfo)destination;
|
||||
File toFile = new File(FileUtil.toSystemDependentName(explodedDestination.getOutputPath()));
|
||||
if (fromFile.exists()) {
|
||||
try {
|
||||
deploymentUtil.copyFile(fromFile, toFile, myContext, writtenPaths, fileFilter);
|
||||
try {
|
||||
if (sourceFile.isInLocalFileSystem()) {
|
||||
final File ioFromFile = VfsUtil.virtualToIoFile(sourceFile);
|
||||
if (ioFromFile.exists()) {
|
||||
deploymentUtil.copyFile(ioFromFile, toFile, myContext, writtenPaths, fileFilter);
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
exception.set(e);
|
||||
return;
|
||||
else {
|
||||
extractFile(sourceFile, toFile, writtenPaths, fileFilter);
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
exception.set(e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
changedJars.add(((JarDestinationInfo)destination).getJarInfo());
|
||||
@@ -254,6 +258,28 @@ public class ArtifactsCompilerInstance extends CompilerInstance<ArtifactBuildTar
|
||||
return true;
|
||||
}
|
||||
|
||||
private void extractFile(VirtualFile sourceFile, File toFile, Set<String> writtenPaths, FileFilter fileFilter) throws IOException {
|
||||
if (!writtenPaths.add(toFile.getPath())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!FileUtil.createParentDirs(toFile)) {
|
||||
myContext.addMessage(CompilerMessageCategory.ERROR, "Cannot create directory for '" + toFile.getAbsolutePath() + "' file", null, -1, -1);
|
||||
return;
|
||||
}
|
||||
|
||||
final BufferedInputStream input = ArtifactCompilerUtil.getJarEntryInputStream(sourceFile, myContext);
|
||||
if (input == null) return;
|
||||
final BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(toFile));
|
||||
try {
|
||||
FileUtil.copy(input, output);
|
||||
}
|
||||
finally {
|
||||
input.close();
|
||||
output.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void onBuildStartedOrFinished(final boolean finished) throws Exception {
|
||||
final Set<Artifact> artifacts = myContext.getUserData(ArtifactsCompiler.AFFECTED_ARTIFACTS);
|
||||
if (artifacts != null) {
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ public class DirectoryCopyPackagingElement extends FileOrDirectoryCopyPackagingE
|
||||
@NotNull ArtifactAntGenerationContext generationContext,
|
||||
@NotNull ArtifactType artifactType) {
|
||||
final String path = generationContext.getSubstitutedPath(myFilePath);
|
||||
return Collections.singletonList((Generator)creator.createDirectoryContentCopyInstruction(path));
|
||||
return Collections.singletonList(creator.createDirectoryContentCopyInstruction(path));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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.elements;
|
||||
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDialog;
|
||||
import com.intellij.openapi.fileChooser.FileChooserFactory;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.openapi.vfs.JarFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.packaging.artifacts.Artifact;
|
||||
import com.intellij.packaging.elements.CompositePackagingElement;
|
||||
import com.intellij.packaging.elements.PackagingElementType;
|
||||
import com.intellij.packaging.ui.ArtifactEditorContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class ExtractedDirectoryElementType extends PackagingElementType<ExtractedDirectoryPackagingElement> {
|
||||
public static final Icon EXTRACTED_FOLDER_ICON = IconLoader.getIcon("/nodes/extractedFolder.png");
|
||||
|
||||
ExtractedDirectoryElementType() {
|
||||
super("extracted-dir", "Extracted Directory");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getCreateElementIcon() {
|
||||
return EXTRACTED_FOLDER_ICON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<? extends ExtractedDirectoryPackagingElement> chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact,
|
||||
@NotNull CompositePackagingElement<?> parent) {
|
||||
final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, true, false, true, true) {
|
||||
@Override
|
||||
public boolean isFileSelectable(VirtualFile file) {
|
||||
if (file.isInLocalFileSystem() && file.isDirectory()) return false;
|
||||
return super.isFileSelectable(file);
|
||||
}
|
||||
};
|
||||
final FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, context.getProject());
|
||||
final VirtualFile[] files = chooser.choose(null, context.getProject());
|
||||
final List<ExtractedDirectoryPackagingElement> list = new ArrayList<ExtractedDirectoryPackagingElement>();
|
||||
for (VirtualFile file : files) {
|
||||
final String fullPath = file.getPath();
|
||||
final int jarEnd = fullPath.indexOf(JarFileSystem.JAR_SEPARATOR);
|
||||
list.add(new ExtractedDirectoryPackagingElement(fullPath.substring(0, jarEnd), fullPath.substring(jarEnd + 1)));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ExtractedDirectoryPackagingElement createEmpty(@NotNull Project project) {
|
||||
return new ExtractedDirectoryPackagingElement();
|
||||
}
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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.elements;
|
||||
|
||||
import com.intellij.compiler.ant.Generator;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.JarFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.packaging.artifacts.ArtifactType;
|
||||
import com.intellij.packaging.elements.*;
|
||||
import com.intellij.packaging.impl.ui.ExtractedDirectoryPresentation;
|
||||
import com.intellij.packaging.ui.ArtifactEditorContext;
|
||||
import com.intellij.packaging.ui.PackagingElementPresentation;
|
||||
import com.intellij.util.xmlb.annotations.Attribute;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class ExtractedDirectoryPackagingElement extends FileOrDirectoryCopyPackagingElement<ExtractedDirectoryPackagingElement> {
|
||||
private String myPathInJar;
|
||||
|
||||
public ExtractedDirectoryPackagingElement() {
|
||||
super(PackagingElementFactoryImpl.EXTRACTED_DIRECTORY_ELEMENT_TYPE);
|
||||
}
|
||||
|
||||
public ExtractedDirectoryPackagingElement(String jarPath, String pathInJar) {
|
||||
super(PackagingElementFactoryImpl.EXTRACTED_DIRECTORY_ELEMENT_TYPE, jarPath);
|
||||
myPathInJar = pathInJar;
|
||||
if (!StringUtil.startsWithChar(myPathInJar, '/')) {
|
||||
myPathInJar = "/" + myPathInJar;
|
||||
}
|
||||
if (!StringUtil.endsWithChar(myPathInJar, '/')) {
|
||||
myPathInJar += "/";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackagingElementPresentation createPresentation(@NotNull ArtifactEditorContext context) {
|
||||
return new ExtractedDirectoryPresentation(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualFile findFile() {
|
||||
final VirtualFile jarFile = super.findFile();
|
||||
if (jarFile == null) return null;
|
||||
|
||||
final VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(jarFile);
|
||||
if ("/".equals(myPathInJar)) return jarRoot;
|
||||
return jarRoot != null ? jarRoot.findFileByRelativePath(myPathInJar) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Generator> computeAntInstructions(@NotNull PackagingElementResolvingContext resolvingContext,
|
||||
@NotNull AntCopyInstructionCreator creator,
|
||||
@NotNull ArtifactAntGenerationContext generationContext,
|
||||
@NotNull ArtifactType artifactType) {
|
||||
final String jarPath = generationContext.getSubstitutedPath(myFilePath);
|
||||
return Collections.singletonList(creator.createExtractedDirectoryInstruction(jarPath, StringUtil.trimStart(myPathInJar, "/")));
|
||||
}
|
||||
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEqualTo(@NotNull PackagingElement<?> element) {
|
||||
return element instanceof ExtractedDirectoryPackagingElement && super.isEqualTo(element)
|
||||
&& Comparing.equal(myPathInJar, ((ExtractedDirectoryPackagingElement)element).getPathInJar());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExtractedDirectoryPackagingElement getState() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(ExtractedDirectoryPackagingElement state) {
|
||||
myFilePath = state.getFilePath();
|
||||
myPathInJar = state.getPathInJar();
|
||||
}
|
||||
|
||||
@Attribute("path-in-jar")
|
||||
public String getPathInJar() {
|
||||
return myPathInJar;
|
||||
}
|
||||
|
||||
public void setPathInJar(String pathInJar) {
|
||||
myPathInJar = pathInJar;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -58,7 +58,7 @@ public class FileCopyPackagingElement extends FileOrDirectoryCopyPackagingElemen
|
||||
}
|
||||
|
||||
public PackagingElementPresentation createPresentation(@NotNull ArtifactEditorContext context) {
|
||||
return new FileCopyPresentation(myFilePath, getOutputFileName(), context);
|
||||
return new FileCopyPresentation(myFilePath, getOutputFileName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+9
-1
@@ -51,11 +51,12 @@ public class PackagingElementFactoryImpl extends PackagingElementFactory {
|
||||
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<ExtractedDirectoryPackagingElement> EXTRACTED_DIRECTORY_ELEMENT_TYPE = new ExtractedDirectoryElementType();
|
||||
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,
|
||||
ArtifactElementType.ARTIFACT_ELEMENT_TYPE, FILE_COPY_ELEMENT_TYPE, DIRECTORY_COPY_ELEMENT_TYPE
|
||||
ArtifactElementType.ARTIFACT_ELEMENT_TYPE, FILE_COPY_ELEMENT_TYPE, DIRECTORY_COPY_ELEMENT_TYPE, EXTRACTED_DIRECTORY_ELEMENT_TYPE
|
||||
};
|
||||
|
||||
@NotNull
|
||||
@@ -253,6 +254,13 @@ public class PackagingElementFactoryImpl extends PackagingElementFactory {
|
||||
return createParentDirectories(relativeOutputPath, new DirectoryCopyPackagingElement(filePath));
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PackagingElement<?> createExtractedDirectoryWithParentDirectories(@NotNull String jarPath, @NotNull String pathInJar,
|
||||
@NotNull String relativeOutputPath) {
|
||||
return createParentDirectories(relativeOutputPath, new ExtractedDirectoryPackagingElement(jarPath, pathInJar));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PackagingElement<?> createFileCopyWithParentDirectories(@NotNull String filePath, @NotNull String relativeOutputPath) {
|
||||
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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.ui;
|
||||
|
||||
import com.intellij.ide.projectView.PresentationData;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.packaging.impl.elements.ExtractedDirectoryElementType;
|
||||
import com.intellij.packaging.impl.elements.ExtractedDirectoryPackagingElement;
|
||||
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 ExtractedDirectoryPresentation extends PackagingElementPresentation {
|
||||
private final String myJarPath;
|
||||
private final String myPathInJar;
|
||||
private final VirtualFile myFile;
|
||||
|
||||
public ExtractedDirectoryPresentation(ExtractedDirectoryPackagingElement element) {
|
||||
myFile = element.findFile();
|
||||
myJarPath = element.getFilePath();
|
||||
myPathInJar = element.getPathInJar();
|
||||
}
|
||||
|
||||
public String getPresentableName() {
|
||||
return PathUtil.getFileName(myJarPath) + myPathInJar;
|
||||
}
|
||||
|
||||
public void render(@NotNull PresentationData presentationData, SimpleTextAttributes mainAttributes, SimpleTextAttributes commentAttributes) {
|
||||
presentationData.setIcons(ExtractedDirectoryElementType.EXTRACTED_FOLDER_ICON);
|
||||
final String parentPath = PathUtil.getParentPath(myJarPath);
|
||||
if (myFile == null || !myFile.isDirectory()) {
|
||||
mainAttributes = SimpleTextAttributes.ERROR_ATTRIBUTES;
|
||||
final VirtualFile parentFile = LocalFileSystem.getInstance().findFileByPath(parentPath);
|
||||
if (parentFile == null) {
|
||||
commentAttributes = SimpleTextAttributes.ERROR_ATTRIBUTES;
|
||||
}
|
||||
}
|
||||
presentationData.addText("Unpacked '" + PathUtil.getFileName(myJarPath) + myPathInJar + "'", mainAttributes);
|
||||
presentationData.addText(" (" + parentPath + ")", commentAttributes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWeight() {
|
||||
return PackagingElementWeights.EXTRACTED_DIRECTORY;
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,6 @@ 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.FileCopyElementType;
|
||||
import com.intellij.packaging.ui.ArtifactEditorContext;
|
||||
import com.intellij.packaging.ui.PackagingElementPresentation;
|
||||
import com.intellij.packaging.ui.PackagingElementWeights;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
@@ -33,12 +32,10 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class FileCopyPresentation extends PackagingElementPresentation {
|
||||
private final String mySourcePath;
|
||||
private final String myOutputFileName;
|
||||
private final ArtifactEditorContext myContext;
|
||||
private final VirtualFile myFile;
|
||||
|
||||
public FileCopyPresentation(String filePath, String outputFileName, ArtifactEditorContext context) {
|
||||
public FileCopyPresentation(String filePath, String outputFileName) {
|
||||
myOutputFileName = outputFileName;
|
||||
myContext = context;
|
||||
|
||||
String parentPath;
|
||||
myFile = LocalFileSystem.getInstance().findFileByPath(filePath);
|
||||
@@ -65,7 +62,7 @@ public class FileCopyPresentation extends PackagingElementPresentation {
|
||||
|
||||
public void render(@NotNull PresentationData presentationData, SimpleTextAttributes mainAttributes, SimpleTextAttributes commentAttributes) {
|
||||
if (myFile != null && !myFile.isDirectory()) {
|
||||
presentationData.setIcons(myFile != null ? myFile.getIcon() : FileCopyElementType.ICON);
|
||||
presentationData.setIcons(myFile.getIcon());
|
||||
presentationData.addText(myOutputFileName, mainAttributes);
|
||||
presentationData.addText(" (" + mySourcePath + ")", commentAttributes);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.intellij.compiler.ant.taskdefs;
|
||||
|
||||
import com.intellij.compiler.ant.Tag;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
/**
|
||||
@@ -27,8 +26,7 @@ import org.jetbrains.annotations.NonNls;
|
||||
public class Include extends Tag {
|
||||
|
||||
public Include(@NonNls final String name) {
|
||||
//noinspection HardCodedStringLiteral
|
||||
super("include", new Pair[] {new Pair<String, String>("name", name)});
|
||||
super("include", pair("name", name));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.intellij.compiler.ant.taskdefs;
|
||||
|
||||
import com.intellij.compiler.ant.Tag;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
/**
|
||||
@@ -26,7 +25,6 @@ import org.jetbrains.annotations.NonNls;
|
||||
*/
|
||||
public class PatternSet extends Tag{
|
||||
public PatternSet(@NonNls final String id) {
|
||||
//noinspection HardCodedStringLiteral
|
||||
super("patternset", new Pair[] {new Pair<String, String>("id", id)});
|
||||
super("patternset", pair("id", id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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.compiler.ant.taskdefs;
|
||||
|
||||
import com.intellij.compiler.ant.Tag;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class Unzip extends Tag {
|
||||
public Unzip(String archivePath, String dest) {
|
||||
super("unzip", pair("src", archivePath), pair("dest", dest));
|
||||
}
|
||||
}
|
||||
@@ -17,9 +17,11 @@
|
||||
package com.intellij.compiler.ant.taskdefs;
|
||||
|
||||
import com.intellij.compiler.ant.Tag;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
@@ -31,12 +33,23 @@ import java.io.File;
|
||||
public class ZipFileSet extends Tag{
|
||||
public static final ZipFileSet[] EMPTY_ARRAY = new ZipFileSet[0];
|
||||
|
||||
private ZipFileSet(@NonNls String tagName, Pair... tagOptions) {
|
||||
super(tagName, tagOptions);
|
||||
}
|
||||
|
||||
public ZipFileSet(@NonNls String fileOrDir, @NonNls final String relativePath, boolean isDir) {
|
||||
super("zipfileset",
|
||||
pair(isDir ? "dir" : "file", fileOrDir),
|
||||
pair("prefix", prefix(isDir, relativePath)));
|
||||
}
|
||||
|
||||
public static ZipFileSet createUnpackedSet(@NonNls String zipFilePath, @NotNull String relativePath, final boolean isDir, String pattern) {
|
||||
return new ZipFileSet("zipfileset",
|
||||
pair("src", zipFilePath),
|
||||
pair("prefix", prefix(isDir, relativePath)),
|
||||
pair("includes", pattern));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String prefix(final boolean isDir, final String relativePath) {
|
||||
String path;
|
||||
|
||||
+6
-3
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package com.intellij.packaging.elements;
|
||||
|
||||
import com.intellij.compiler.ant.Tag;
|
||||
import com.intellij.compiler.ant.Generator;
|
||||
import com.intellij.compiler.ant.Tag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -32,8 +32,11 @@ public interface AntCopyInstructionCreator {
|
||||
Tag createFileCopyInstruction(@NotNull String filePath, String outputFileName);
|
||||
|
||||
@NotNull
|
||||
AntCopyInstructionCreator subFolder(String directoryName);
|
||||
AntCopyInstructionCreator subFolder(@NotNull String directoryName);
|
||||
|
||||
@Nullable
|
||||
Generator createSubFolderCommand(String directoryName);
|
||||
Generator createSubFolderCommand(@NotNull String directoryName);
|
||||
|
||||
@NotNull
|
||||
Generator createExtractedDirectoryInstruction(@NotNull String jarPath, @NotNull String pathInJar);
|
||||
}
|
||||
|
||||
@@ -67,6 +67,10 @@ public abstract class PackagingElementFactory {
|
||||
@NotNull
|
||||
public abstract PackagingElement<?> createDirectoryCopyWithParentDirectories(@NotNull String filePath, @NotNull String relativeOutputPath);
|
||||
|
||||
@NotNull
|
||||
public abstract PackagingElement<?> createExtractedDirectoryWithParentDirectories(@NotNull String jarPath, @NotNull String pathInJar,
|
||||
@NotNull String relativeOutputPath);
|
||||
|
||||
@NotNull
|
||||
public abstract PackagingElement<?> createFileCopyWithParentDirectories(@NotNull String filePath, @NotNull String relativeOutputPath,
|
||||
@Nullable String outputFileName);
|
||||
|
||||
@@ -22,6 +22,7 @@ public class PackagingElementWeights {
|
||||
public static final int ARTIFACT = 100;
|
||||
public static final int DIRECTORY = 50;
|
||||
public static final int DIRECTORY_COPY = 40;
|
||||
public static final int EXTRACTED_DIRECTORY = 39;
|
||||
public static final int LIBRARY = 30;
|
||||
public static final int MODULE = 20;
|
||||
public static final int FACET = 10;
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 727 B After Width: | Height: | Size: 588 B |
Binary file not shown.
|
After Width: | Height: | Size: 657 B |
@@ -510,7 +510,7 @@ public class FileUtil {
|
||||
return parentFile.exists() && parentFile.isDirectory() || parentFile.mkdirs();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean createIfDoesntExist(File file) {
|
||||
|
||||
Reference in New Issue
Block a user