artifact building API: pass target directory to ArtifactRootCopyingHandlerProvider

This is needed to properly filter files when building Maven projects (IDEA-CR-23524).
This commit is contained in:
nik
2017-08-09 12:28:53 +03:00
parent ecc047a08a
commit 69f67b9a31
10 changed files with 75 additions and 5 deletions
@@ -127,7 +127,7 @@ public class LayoutElementBuildersRegistry {
@NotNull JpsPackagingElement contextElement) {
if (outputUrl != null) {
File directory = JpsPathUtil.urlToFile(outputUrl);
creator.addDirectoryCopyInstructions(directory, null, creator.getInstructionsBuilder().createCopyingHandler(directory, contextElement));
creator.addDirectoryCopyInstructions(directory, null, creator.getInstructionsBuilder().createCopyingHandler(directory, contextElement, creator));
}
}
@@ -178,7 +178,7 @@ public class LayoutElementBuildersRegistry {
final String dirPath = element.getDirectoryPath();
if (dirPath != null) {
final File directory = new File(dirPath);
instructionCreator.addDirectoryCopyInstructions(directory, null, instructionCreator.getInstructionsBuilder().createCopyingHandler(directory, element));
instructionCreator.addDirectoryCopyInstructions(directory, null, instructionCreator.getInstructionsBuilder().createCopyingHandler(directory, element, instructionCreator));
}
}
@@ -207,7 +207,7 @@ public class LayoutElementBuildersRegistry {
final String fileName = element.getRenamedOutputFileName();
String outputFileName = fileName != null ? fileName : file.getName();
instructionCreator.addFileCopyInstruction(file, outputFileName,
instructionCreator.getInstructionsBuilder().createCopyingHandler(file, element));
instructionCreator.getInstructionsBuilder().createCopyingHandler(file, element, instructionCreator));
}
}
@@ -60,4 +60,11 @@ public interface ArtifactCompilerInstructionCreator {
ArtifactCompilerInstructionCreator subFolderByRelativePath(@NotNull String relativeDirectoryPath);
ArtifactInstructionsBuilder getInstructionsBuilder();
/**
* @return target directory for instructions created by this instance or {@code null} if there is no such directory (e.g. because it corresponds
* to an entry in a JAR file)
*/
@Nullable
File getTargetDirectory();
}
@@ -28,6 +28,12 @@ public interface ArtifactInstructionsBuilder {
@NotNull
List<ArtifactRootDescriptor> getDescriptors();
/**
* @deprecated use {@link #createCopyingHandler(File, JpsPackagingElement, ArtifactCompilerInstructionCreator)} instead
*/
@NotNull
FileCopyingHandler createCopyingHandler(@NotNull File file, @NotNull JpsPackagingElement contextElement);
@NotNull
FileCopyingHandler createCopyingHandler(@NotNull File file, @NotNull JpsPackagingElement contextElement, @NotNull ArtifactCompilerInstructionCreator instructionCreator);
}
@@ -104,6 +104,23 @@ public class ArtifactInstructionsBuilderImpl implements ArtifactInstructionsBuil
return FileCopyingHandler.DEFAULT;
}
@NotNull
@Override
public FileCopyingHandler createCopyingHandler(@NotNull File file,
@NotNull JpsPackagingElement contextElement,
@NotNull ArtifactCompilerInstructionCreator instructionCreator) {
File targetDirectory = instructionCreator.getTargetDirectory();
if (targetDirectory == null) return FileCopyingHandler.DEFAULT;
for (ArtifactRootCopyingHandlerProvider provider : myCopyingHandlerProviders) {
FileCopyingHandler handler = provider.createCustomHandler(myBuildTarget.getArtifact(), file, targetDirectory, contextElement, myModel, myBuildDataPaths);
if (handler != null) {
return handler;
}
}
return FileCopyingHandler.DEFAULT;
}
public JarBasedArtifactRootDescriptor createJarBasedRoot(@NotNull File jarFile,
@NotNull String pathInJar,
@NotNull SourceFileFilter filter,
@@ -39,11 +39,25 @@ public abstract class ArtifactRootCopyingHandlerProvider {
/**
* Override this method to customize how files from {@code root} are copied to the {@code artifact output}.
* @param root file or directory which is configured in {@code artifact} to be copied to its output
* @param targetDirectory target directory under the artifact output to which {@code root} will be copied.
* @param contextElement element in the artifact layout to which {@code root} corresponds; it may be for example
* {@link JpsDirectoryCopyPackagingElement} (in that case {@code root} will be its {@link JpsDirectoryCopyPackagingElement#getDirectoryPath() directory})
* or {@link JpsModuleOutputPackagingElement} (in that case {@code root} will be the module output directory)
*/
@Nullable
public FileCopyingHandler createCustomHandler(@NotNull JpsArtifact artifact,
@NotNull File root,
@NotNull File targetDirectory,
@NotNull JpsPackagingElement contextElement,
@NotNull JpsModel model,
@NotNull BuildDataPaths buildDataPaths) {
return createCustomHandler(artifact, root, model, buildDataPaths);
}
/**
* @deprecated override {@link #createCustomHandler(JpsArtifact, File, File, JpsPackagingElement, JpsModel, BuildDataPaths)} instead
*/
@Nullable
public FileCopyingHandler createCustomHandler(@NotNull JpsArtifact artifact,
@NotNull File root,
@NotNull JpsPackagingElement contextElement,
@@ -53,7 +67,7 @@ public abstract class ArtifactRootCopyingHandlerProvider {
}
/**
* @deprecated override {@link #createCustomHandler(JpsArtifact, File, JpsPackagingElement, JpsModel, BuildDataPaths)} instead
* @deprecated override {@link #createCustomHandler(JpsArtifact, File, File, JpsPackagingElement, JpsModel, BuildDataPaths)} instead
*/
@Nullable
public FileCopyingHandler createCustomHandler(@NotNull JpsArtifact artifact, @NotNull File root, @NotNull JpsModel model,
@@ -16,6 +16,9 @@
package org.jetbrains.jps.incremental.artifacts.instructions;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
/**
* @author nik
@@ -54,4 +57,10 @@ public class CopyToDirectoryInstructionCreator extends ArtifactCompilerInstructi
}
return new PackIntoArchiveInstructionCreator(myInstructionsBuilder, jarInfo, "", destination);
}
@Nullable
@Override
public File getTargetDirectory() {
return new File(myOutputPath);
}
}
@@ -19,6 +19,8 @@ import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
/**
* @author nik
*/
@@ -68,4 +70,10 @@ public class PackIntoArchiveInstructionCreator extends ArtifactCompilerInstructi
myJarInfo.addJar(destination.getPathInJar(), jarInfo);
return new PackIntoArchiveInstructionCreator(myInstructionsBuilder, jarInfo, "", destination);
}
@Nullable
@Override
public File getTargetDirectory() {
return null;
}
}
@@ -17,6 +17,8 @@ package org.jetbrains.jps.incremental.artifacts.instructions;
import org.jetbrains.annotations.NotNull;
import java.io.File;
/**
* @author nik
*/
@@ -46,4 +48,9 @@ public class SkipAllInstructionCreator extends ArtifactCompilerInstructionCreato
public SkipAllInstructionCreator archive(@NotNull String archiveFileName) {
return this;
}
@Override
public File getTargetDirectory() {
return null;
}
}
@@ -37,11 +37,11 @@ import java.io.File;
* @author nik
*/
public class MavenEjbArtifactRootCopyingHandlerProvider extends ArtifactRootCopyingHandlerProvider {
@Nullable
@Override
public FileCopyingHandler createCustomHandler(@NotNull JpsArtifact artifact,
@NotNull File root,
@NotNull File targetDirectory,
@NotNull JpsPackagingElement contextElement,
@NotNull JpsModel model,
@NotNull BuildDataPaths buildDataPaths) {
@@ -45,10 +45,12 @@ import static com.intellij.openapi.util.io.FileUtil.toSystemDependentName;
*/
public class MavenWebArtifactRootCopyingHandlerProvider extends ArtifactRootCopyingHandlerProvider {
private static final Logger LOG = Logger.getInstance(MavenWebArtifactRootCopyingHandlerProvider.class);
@Nullable
@Override
public FileCopyingHandler createCustomHandler(@NotNull JpsArtifact artifact,
@NotNull File root,
@NotNull File targetDirectory,
@NotNull JpsPackagingElement contextElement,
@NotNull JpsModel model,
@NotNull BuildDataPaths buildDataPaths) {