mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
external build for Maven projects: apply web roots filtering to web roots only (ZD-37637)
This commit is contained in:
+12
-9
@@ -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
|
||||
|
||||
+6
@@ -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();
|
||||
}
|
||||
|
||||
+16
-2
@@ -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();
|
||||
|
||||
|
||||
+8
-1
@@ -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<ArtifactRootDescriptor> getDescriptors();
|
||||
|
||||
@NotNull
|
||||
FileCopyingHandler createCopyingHandler(@NotNull File file, @NotNull JpsPackagingElement contextElement);
|
||||
}
|
||||
|
||||
+7
-4
@@ -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<ArtifactRootDescriptor> 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;
|
||||
}
|
||||
|
||||
+17
-2
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -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;
|
||||
|
||||
+8
-1
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user