mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
external build for artifacts: added API to filter contents of directory extracted from jar file
This commit is contained in:
+15
-1
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.jps.incremental.artifacts.instructions;
|
||||
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -31,9 +32,22 @@ public interface ArtifactCompilerInstructionCreator {
|
||||
|
||||
void addDirectoryCopyInstructions(@NotNull File directory, @Nullable SourceFileFilter filter);
|
||||
|
||||
/**
|
||||
* Add instruction to extract directory from a jar file into the current place in the artifact layout.
|
||||
*
|
||||
* @param jarFile jar file to extract
|
||||
* @param pathInJar relative path to directory inside {@code jarFile} which need to be extracted. Use "/" to extract the whole jar contents
|
||||
*/
|
||||
void addExtractDirectoryInstruction(@NotNull File jarFile, @NotNull String pathInJar);
|
||||
|
||||
void addExtractDirectoryInstruction(@NotNull File jarFile, @NotNull String pathInJar, @Nullable SourceFileFilter sourceFileFilter);
|
||||
/**
|
||||
* Add instruction to extract directory from a jar file into the current place in the artifact layout.
|
||||
* @param jarFile jar file to extract
|
||||
* @param pathInJar relative path to directory inside {@code jarFile} which need to be extracted. Use "/" to extract the whole jar contents
|
||||
* @param pathInJarFilter a filter instance specifying which entries should be extracted. It should accept paths inside the jar file
|
||||
* relative to {@code pathInJar} root and return {@code true} if the entry should be extracted and {@code false} otherwise
|
||||
*/
|
||||
void addExtractDirectoryInstruction(@NotNull File jarFile, @NotNull String pathInJar, @NotNull Condition<String> pathInJarFilter);
|
||||
|
||||
ArtifactCompilerInstructionCreator subFolder(@NotNull String directoryName);
|
||||
|
||||
|
||||
+10
-6
@@ -15,14 +15,16 @@
|
||||
*/
|
||||
package org.jetbrains.jps.incremental.artifacts.instructions;
|
||||
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Conditions;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.PathUtilRt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.cmdline.ProjectDescriptor;
|
||||
import org.jetbrains.jps.incremental.artifacts.JarPathUtil;
|
||||
import org.jetbrains.jps.indices.IgnoredFileIndex;
|
||||
import org.jetbrains.jps.indices.ModuleExcludeIndex;
|
||||
import org.jetbrains.jps.incremental.artifacts.JarPathUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -56,20 +58,22 @@ public abstract class ArtifactCompilerInstructionCreatorBase implements Artifact
|
||||
|
||||
@Override
|
||||
public void addExtractDirectoryInstruction(@NotNull File jarFile, @NotNull String pathInJar) {
|
||||
addExtractDirectoryInstruction(jarFile, pathInJar, null);
|
||||
addExtractDirectoryInstruction(jarFile, pathInJar, Conditions.<String>alwaysTrue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtractDirectoryInstruction(@NotNull File jarFile, @NotNull String pathInJar, @Nullable SourceFileFilter sourceFileFilter) {
|
||||
public void addExtractDirectoryInstruction(@NotNull File jarFile,
|
||||
@NotNull String pathInJar,
|
||||
@NotNull Condition<String> pathInJarFilter) {
|
||||
//an entry of a jar file is excluded if and only if the jar file itself is excluded. In that case we should unpack entries to the artifact
|
||||
// because the jar itself is explicitly added to the artifact layout.
|
||||
//because the jar itself is explicitly added to the artifact layout.
|
||||
boolean includeExcluded = true;
|
||||
|
||||
final SourceFileFilterImpl filter = new SourceFileFilterImpl(sourceFileFilter, myInstructionsBuilder.getRootsIndex(),
|
||||
final SourceFileFilterImpl filter = new SourceFileFilterImpl(null, myInstructionsBuilder.getRootsIndex(),
|
||||
myInstructionsBuilder.getIgnoredFileIndex(), includeExcluded);
|
||||
DestinationInfo destination = createDirectoryDestination();
|
||||
if (destination != null) {
|
||||
ArtifactRootDescriptor descriptor = myInstructionsBuilder.createJarBasedRoot(jarFile, pathInJar, filter, destination);
|
||||
ArtifactRootDescriptor descriptor = myInstructionsBuilder.createJarBasedRoot(jarFile, pathInJar, filter, destination, pathInJarFilter);
|
||||
if (myInstructionsBuilder.addDestination(descriptor)) {
|
||||
onAdded(descriptor);
|
||||
}
|
||||
|
||||
+5
-2
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.jps.incremental.artifacts.instructions;
|
||||
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.incremental.artifacts.ArtifactBuildTarget;
|
||||
import org.jetbrains.jps.indices.IgnoredFileIndex;
|
||||
@@ -79,7 +80,9 @@ public class ArtifactInstructionsBuilderImpl implements ArtifactInstructionsBuil
|
||||
|
||||
public JarBasedArtifactRootDescriptor createJarBasedRoot(@NotNull File jarFile,
|
||||
@NotNull String pathInJar,
|
||||
@NotNull SourceFileFilter filter, final DestinationInfo destinationInfo) {
|
||||
return new JarBasedArtifactRootDescriptor(jarFile, pathInJar, filter, myRootIndex++, myBuildTarget, destinationInfo);
|
||||
@NotNull SourceFileFilter filter,
|
||||
@NotNull DestinationInfo destinationInfo,
|
||||
@NotNull Condition<String> pathInJarFilter) {
|
||||
return new JarBasedArtifactRootDescriptor(jarFile, pathInJar, filter, myRootIndex++, myBuildTarget, destinationInfo, pathInJarFilter);
|
||||
}
|
||||
}
|
||||
|
||||
+9
-2
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.jps.incremental.artifacts.instructions;
|
||||
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -39,14 +40,18 @@ import java.util.zip.ZipFile;
|
||||
*/
|
||||
public class JarBasedArtifactRootDescriptor extends ArtifactRootDescriptor {
|
||||
private final String myPathInJar;
|
||||
private final Condition<String> myPathInJarFilter;
|
||||
|
||||
public JarBasedArtifactRootDescriptor(@NotNull File jarFile,
|
||||
@NotNull String pathInJar,
|
||||
@NotNull SourceFileFilter filter,
|
||||
int index,
|
||||
ArtifactBuildTarget target, DestinationInfo destinationInfo) {
|
||||
@NotNull ArtifactBuildTarget target,
|
||||
@NotNull DestinationInfo destinationInfo,
|
||||
@NotNull Condition<String> pathInJarFilter) {
|
||||
super(jarFile, filter, index, target, destinationInfo);
|
||||
myPathInJar = pathInJar;
|
||||
myPathInJarFilter = pathInJarFilter;
|
||||
}
|
||||
|
||||
public void processEntries(EntryProcessor processor) throws IOException {
|
||||
@@ -68,7 +73,9 @@ public class JarBasedArtifactRootDescriptor extends ArtifactRootDescriptor {
|
||||
final String name = entry.getName();
|
||||
if (name.startsWith(prefix)) {
|
||||
String relativePath = name.substring(prefix.length());
|
||||
processor.process(entry.isDirectory() ? null : zipFile.getInputStream(entry), relativePath, entry);
|
||||
if (myPathInJarFilter.value(relativePath)) {
|
||||
processor.process(entry.isDirectory() ? null : zipFile.getInputStream(entry), relativePath, entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user