From 37a674ea03bdd554e128bd4df79d6b287b0bcef1 Mon Sep 17 00:00:00 2001 From: "Henning P. Schmiedehausen" Date: Tue, 15 Aug 2023 22:36:52 -0700 Subject: [PATCH] Make the default operation configurable Make it possible to replace the default operation ("flatten") with another value. This is useful to e.g. strip a pom completely and then only add a few elements back. --- .../org/codehaus/mojo/flatten/FlattenDescriptor.java | 11 ++++++++++- .../java/org/codehaus/mojo/flatten/FlattenMojo.java | 10 ++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/codehaus/mojo/flatten/FlattenDescriptor.java b/src/main/java/org/codehaus/mojo/flatten/FlattenDescriptor.java index 6be67dd6..af715d41 100644 --- a/src/main/java/org/codehaus/mojo/flatten/FlattenDescriptor.java +++ b/src/main/java/org/codehaus/mojo/flatten/FlattenDescriptor.java @@ -35,6 +35,7 @@ public class FlattenDescriptor { private final Map name2handlingMap; + private ElementHandling defaultOperation = ElementHandling.flatten; /** * The constructor. @@ -59,6 +60,14 @@ public FlattenDescriptor(Xpp3Dom descriptor) { } } + public ElementHandling getDefaultOperation() { + return defaultOperation; + } + + public void setDefaultOperation(ElementHandling defaultOperation) { + this.defaultOperation = defaultOperation; + } + /** * Generic method to get a {@link ElementHandling}. * @@ -68,7 +77,7 @@ public FlattenDescriptor(Xpp3Dom descriptor) { public ElementHandling getHandling(PomProperty property) { ElementHandling handling = this.name2handlingMap.get(property.getName()); if (handling == null) { - handling = ElementHandling.flatten; + handling = defaultOperation; } return handling; } diff --git a/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java b/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java index 55fbe797..20342048 100644 --- a/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java +++ b/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java @@ -372,6 +372,14 @@ public class FlattenMojo extends AbstractFlattenMojo { @Parameter(property = "flatten.flatten.skip", defaultValue = "false") private boolean skipFlatten; + /** + * The default operation to use when no element handling is given. Defaults to flatten. + * + * @since 1.6.0 + */ + @Parameter(property = "flatten.dependency.defaultOperation", required = false, defaultValue = "flatten") + private ElementHandling defaultOperation; + @Inject private DirectDependenciesInheritanceAssembler inheritanceAssembler; @@ -791,10 +799,12 @@ private FlattenDescriptor getFlattenDescriptor() throws MojoFailureException { Xpp3Dom rawDescriptor = this.mojoExecution.getConfiguration().getChild("pomElements"); descriptor = new FlattenDescriptor(rawDescriptor); } + if (this.flattenMode != null) { descriptor = descriptor.merge(this.flattenMode.getDescriptor()); } } + descriptor.setDefaultOperation(defaultOperation); return descriptor; }