diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/builders/LayoutElementBuildersRegistry.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/builders/LayoutElementBuildersRegistry.java index 5cef20f4dfb4..2278f317f55b 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/builders/LayoutElementBuildersRegistry.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/builders/LayoutElementBuildersRegistry.java @@ -24,9 +24,7 @@ import org.jetbrains.jps.builders.BuildTarget; import org.jetbrains.jps.builders.TargetOutputIndex; import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType; import org.jetbrains.jps.incremental.ModuleBuildTarget; -import org.jetbrains.jps.incremental.artifacts.instructions.ArtifactCompilerInstructionCreator; -import org.jetbrains.jps.incremental.artifacts.instructions.ArtifactInstructionsBuilderContext; -import org.jetbrains.jps.incremental.artifacts.instructions.CopyToDirectoryInstructionCreator; +import org.jetbrains.jps.incremental.artifacts.instructions.*; import org.jetbrains.jps.model.artifact.JpsArtifact; import org.jetbrains.jps.model.artifact.elements.*; import org.jetbrains.jps.model.java.JpsProductionModuleOutputPackagingElement; @@ -124,9 +122,12 @@ public class LayoutElementBuildersRegistry { } } - private static void generateModuleOutputInstructions(@Nullable String outputUrl, ArtifactCompilerInstructionCreator creator) { + private static void generateModuleOutputInstructions(@Nullable String outputUrl, + @NotNull ArtifactCompilerInstructionCreator creator, + @NotNull JpsPackagingElement contextElement) { if (outputUrl != null) { - creator.addDirectoryCopyInstructions(JpsPathUtil.urlToFile(outputUrl)); + File directory = JpsPathUtil.urlToFile(outputUrl); + creator.addDirectoryCopyInstructions(directory, null, creator.getInstructionsBuilder().createCopyingHandler(directory, contextElement)); } } @@ -177,7 +178,7 @@ public class LayoutElementBuildersRegistry { final String dirPath = element.getDirectoryPath(); if (dirPath != null) { final File directory = new File(dirPath); - instructionCreator.addDirectoryCopyInstructions(directory); + instructionCreator.addDirectoryCopyInstructions(directory, null, instructionCreator.getInstructionsBuilder().createCopyingHandler(directory, element)); } } @@ -204,7 +205,9 @@ public class LayoutElementBuildersRegistry { if (filePath != null) { final File file = new File(filePath); final String fileName = element.getRenamedOutputFileName(); - instructionCreator.addFileCopyInstruction(file, fileName != null ? fileName : file.getName()); + String outputFileName = fileName != null ? fileName : file.getName(); + instructionCreator.addFileCopyInstruction(file, outputFileName, + instructionCreator.getInstructionsBuilder().createCopyingHandler(file, element)); } } @@ -243,7 +246,7 @@ public class LayoutElementBuildersRegistry { public void generateInstructions(JpsProductionModuleOutputPackagingElement element, ArtifactCompilerInstructionCreator instructionCreator, ArtifactInstructionsBuilderContext builderContext) { - generateModuleOutputInstructions(element.getOutputUrl(), instructionCreator); + generateModuleOutputInstructions(element.getOutputUrl(), instructionCreator, element); } @Override @@ -266,7 +269,7 @@ public class LayoutElementBuildersRegistry { public void generateInstructions(JpsTestModuleOutputPackagingElement element, ArtifactCompilerInstructionCreator instructionCreator, ArtifactInstructionsBuilderContext builderContext) { - generateModuleOutputInstructions(element.getOutputUrl(), instructionCreator); + generateModuleOutputInstructions(element.getOutputUrl(), instructionCreator, element); } @Override diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactCompilerInstructionCreator.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactCompilerInstructionCreator.java index 5648eb96f16a..f64f8c8ead8d 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactCompilerInstructionCreator.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactCompilerInstructionCreator.java @@ -28,10 +28,14 @@ public interface ArtifactCompilerInstructionCreator { void addFileCopyInstruction(@NotNull File file, @NotNull String outputFileName); + void addFileCopyInstruction(@NotNull File file, @NotNull String outputFileName, @NotNull FileCopyingHandler copyingHandler); + void addDirectoryCopyInstructions(@NotNull File directory); void addDirectoryCopyInstructions(@NotNull File directory, @Nullable SourceFileFilter filter); + void addDirectoryCopyInstructions(@NotNull File directory, @Nullable SourceFileFilter filter, @NotNull FileCopyingHandler copyingHandler); + /** * Add instruction to extract directory from a jar file into the current place in the artifact layout. * @@ -54,4 +58,6 @@ public interface ArtifactCompilerInstructionCreator { ArtifactCompilerInstructionCreator archive(@NotNull String archiveFileName); ArtifactCompilerInstructionCreator subFolderByRelativePath(@NotNull String relativeDirectoryPath); + + ArtifactInstructionsBuilder getInstructionsBuilder(); } diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactCompilerInstructionCreatorBase.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactCompilerInstructionCreatorBase.java index 2e5aa50ad45b..7c27ab0e4c98 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactCompilerInstructionCreatorBase.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactCompilerInstructionCreatorBase.java @@ -45,11 +45,15 @@ public abstract class ArtifactCompilerInstructionCreatorBase implements Artifact } public void addDirectoryCopyInstructions(@NotNull File directory, @Nullable SourceFileFilter filter) { + addDirectoryCopyInstructions(directory, filter, FileCopyingHandler.DEFAULT); + } + + public void addDirectoryCopyInstructions(@NotNull File directory, @Nullable SourceFileFilter filter, @NotNull FileCopyingHandler copyingHandler) { final boolean copyExcluded = myInstructionsBuilder.getRootsIndex().isExcluded(directory); SourceFileFilter fileFilter = new SourceFileFilterImpl(filter, myInstructionsBuilder.getRootsIndex(), myInstructionsBuilder.getIgnoredFileIndex(), copyExcluded); DestinationInfo destination = createDirectoryDestination(); if (destination != null) { - ArtifactRootDescriptor descriptor = myInstructionsBuilder.createFileBasedRoot(directory, fileFilter, destination); + ArtifactRootDescriptor descriptor = myInstructionsBuilder.createFileBasedRoot(directory, fileFilter, destination, copyingHandler); if (myInstructionsBuilder.addDestination(descriptor)) { onAdded(descriptor); } @@ -95,15 +99,25 @@ public abstract class ArtifactCompilerInstructionCreatorBase implements Artifact @Override public void addFileCopyInstruction(@NotNull File file, @NotNull String outputFileName) { + addFileCopyInstruction(file, outputFileName, FileCopyingHandler.DEFAULT); + } + + @Override + public void addFileCopyInstruction(@NotNull File file, @NotNull String outputFileName, @NotNull FileCopyingHandler copyingHandler) { DestinationInfo destination = createFileDestination(outputFileName); if (destination != null) { - FileBasedArtifactRootDescriptor root = myInstructionsBuilder.createFileBasedRoot(file, SourceFileFilter.ALL, destination); + FileBasedArtifactRootDescriptor root = myInstructionsBuilder.createFileBasedRoot(file, SourceFileFilter.ALL, destination, copyingHandler); if (myInstructionsBuilder.addDestination(root)) { onAdded(root); } } } + @Override + public ArtifactInstructionsBuilder getInstructionsBuilder() { + return myInstructionsBuilder; + } + @Nullable protected abstract DestinationInfo createDirectoryDestination(); diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactInstructionsBuilder.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactInstructionsBuilder.java index 298ccb105ed9..8387d97780f7 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactInstructionsBuilder.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactInstructionsBuilder.java @@ -15,12 +15,19 @@ */ package org.jetbrains.jps.incremental.artifacts.instructions; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jps.model.artifact.elements.JpsPackagingElement; + +import java.io.File; import java.util.List; /** * @author nik */ public interface ArtifactInstructionsBuilder { - + @NotNull List getDescriptors(); + + @NotNull + FileCopyingHandler createCopyingHandler(@NotNull File file, @NotNull JpsPackagingElement contextElement); } diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactInstructionsBuilderImpl.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactInstructionsBuilderImpl.java index c6b15a793e77..a64425366482 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactInstructionsBuilderImpl.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactInstructionsBuilderImpl.java @@ -22,6 +22,7 @@ import org.jetbrains.jps.incremental.artifacts.ArtifactBuildTarget; import org.jetbrains.jps.indices.IgnoredFileIndex; import org.jetbrains.jps.indices.ModuleExcludeIndex; import org.jetbrains.jps.model.JpsModel; +import org.jetbrains.jps.model.artifact.elements.JpsPackagingElement; import org.jetbrains.jps.service.JpsServiceManager; import java.io.File; @@ -79,6 +80,7 @@ public class ArtifactInstructionsBuilderImpl implements ArtifactInstructionsBuil return true; } + @NotNull @Override public List getDescriptors() { return myDescriptors; @@ -86,14 +88,15 @@ public class ArtifactInstructionsBuilderImpl implements ArtifactInstructionsBuil public FileBasedArtifactRootDescriptor createFileBasedRoot(@NotNull File file, @NotNull SourceFileFilter filter, - final @NotNull DestinationInfo destinationInfo) { - FileCopyingHandler handler = createCopyingHandler(file); + final @NotNull DestinationInfo destinationInfo, FileCopyingHandler handler) { return new FileBasedArtifactRootDescriptor(file, filter, myRootIndex++, myBuildTarget, destinationInfo, handler); } - private FileCopyingHandler createCopyingHandler(File file) { + @NotNull + @Override + public FileCopyingHandler createCopyingHandler(@NotNull File file, @NotNull JpsPackagingElement contextElement) { for (ArtifactRootCopyingHandlerProvider provider : myCopyingHandlerProviders) { - FileCopyingHandler handler = provider.createCustomHandler(myBuildTarget.getArtifact(), file, myModel, myBuildDataPaths); + FileCopyingHandler handler = provider.createCustomHandler(myBuildTarget.getArtifact(), file, contextElement, myModel, myBuildDataPaths); if (handler != null) { return handler; } diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactRootCopyingHandlerProvider.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactRootCopyingHandlerProvider.java index fecaa167ffc2..558608883084 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactRootCopyingHandlerProvider.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactRootCopyingHandlerProvider.java @@ -20,6 +20,7 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.builders.storage.BuildDataPaths; import org.jetbrains.jps.model.JpsModel; import org.jetbrains.jps.model.artifact.JpsArtifact; +import org.jetbrains.jps.model.artifact.elements.JpsPackagingElement; import java.io.File; @@ -28,6 +29,20 @@ import java.io.File; */ public abstract class ArtifactRootCopyingHandlerProvider { @Nullable - public abstract FileCopyingHandler createCustomHandler(@NotNull JpsArtifact artifact, @NotNull File root, @NotNull JpsModel model, - @NotNull BuildDataPaths buildDataPaths); + public FileCopyingHandler createCustomHandler(@NotNull JpsArtifact artifact, + @NotNull File root, + @NotNull JpsPackagingElement contextElement, + @NotNull JpsModel model, + @NotNull BuildDataPaths buildDataPaths) { + return createCustomHandler(artifact, root, model, buildDataPaths); + } + + /** + * @deprecated override {@link #createCustomHandler(JpsArtifact, File, JpsPackagingElement, JpsModel, BuildDataPaths)} instead + */ + @Nullable + public FileCopyingHandler createCustomHandler(@NotNull JpsArtifact artifact, @NotNull File root, @NotNull JpsModel model, + @NotNull BuildDataPaths buildDataPaths) { + throw new UnsupportedOperationException(); + } } diff --git a/plugins/maven/jps-plugin/src/org/jetbrains/jps/maven/compiler/MavenEjbArtifactRootCopyingHandlerProvider.java b/plugins/maven/jps-plugin/src/org/jetbrains/jps/maven/compiler/MavenEjbArtifactRootCopyingHandlerProvider.java index c39385ccee90..39c2d44784fa 100644 --- a/plugins/maven/jps-plugin/src/org/jetbrains/jps/maven/compiler/MavenEjbArtifactRootCopyingHandlerProvider.java +++ b/plugins/maven/jps-plugin/src/org/jetbrains/jps/maven/compiler/MavenEjbArtifactRootCopyingHandlerProvider.java @@ -27,6 +27,7 @@ import org.jetbrains.jps.maven.model.impl.MavenProjectConfiguration; import org.jetbrains.jps.maven.model.impl.MavenResourceFileFilter; import org.jetbrains.jps.model.JpsModel; import org.jetbrains.jps.model.artifact.JpsArtifact; +import org.jetbrains.jps.model.artifact.elements.JpsPackagingElement; import java.io.File; @@ -37,7 +38,10 @@ public class MavenEjbArtifactRootCopyingHandlerProvider extends ArtifactRootCopy @Nullable @Override - public FileCopyingHandler createCustomHandler(@NotNull JpsArtifact artifact, @NotNull File root, @NotNull JpsModel model, + public FileCopyingHandler createCustomHandler(@NotNull JpsArtifact artifact, + @NotNull File root, + @NotNull JpsPackagingElement contextElement, + @NotNull JpsModel model, @NotNull BuildDataPaths buildDataPaths) { JpsMavenExtensionService mavenExtensionService = JpsMavenExtensionService.getInstance(); if (!mavenExtensionService.hasMavenProjectConfiguration(buildDataPaths)) return null; diff --git a/plugins/maven/jps-plugin/src/org/jetbrains/jps/maven/compiler/MavenWebArtifactRootCopyingHandlerProvider.java b/plugins/maven/jps-plugin/src/org/jetbrains/jps/maven/compiler/MavenWebArtifactRootCopyingHandlerProvider.java index b7015992d3e1..3658e829ef62 100644 --- a/plugins/maven/jps-plugin/src/org/jetbrains/jps/maven/compiler/MavenWebArtifactRootCopyingHandlerProvider.java +++ b/plugins/maven/jps-plugin/src/org/jetbrains/jps/maven/compiler/MavenWebArtifactRootCopyingHandlerProvider.java @@ -29,6 +29,8 @@ import org.jetbrains.jps.maven.model.JpsMavenExtensionService; import org.jetbrains.jps.maven.model.impl.*; import org.jetbrains.jps.model.JpsModel; import org.jetbrains.jps.model.artifact.JpsArtifact; +import org.jetbrains.jps.model.artifact.elements.JpsModuleOutputPackagingElement; +import org.jetbrains.jps.model.artifact.elements.JpsPackagingElement; import java.io.File; import java.io.FileFilter; @@ -42,8 +44,13 @@ public class MavenWebArtifactRootCopyingHandlerProvider extends ArtifactRootCopy private static final Logger LOG = Logger.getInstance(MavenWebArtifactRootCopyingHandlerProvider.class); @Nullable @Override - public FileCopyingHandler createCustomHandler(@NotNull JpsArtifact artifact, @NotNull File root, @NotNull JpsModel model, + public FileCopyingHandler createCustomHandler(@NotNull JpsArtifact artifact, + @NotNull File root, + @NotNull JpsPackagingElement contextElement, + @NotNull JpsModel model, @NotNull BuildDataPaths buildDataPaths) { + if (contextElement instanceof JpsModuleOutputPackagingElement) return null; + JpsMavenExtensionService mavenExtensionService = JpsMavenExtensionService.getInstance(); if (!mavenExtensionService.hasMavenProjectConfiguration(buildDataPaths)) return null;