Skip to content

Commit

Permalink
Make the default operation configurable
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hgschmie committed Aug 16, 2023
1 parent 30b2f72 commit bb2e123
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main/java/org/codehaus/mojo/flatten/FlattenDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
public class FlattenDescriptor {

private final Map<String, ElementHandling> name2handlingMap;
private ElementHandling defaultOperation = ElementHandling.flatten;

/**
* The constructor.
Expand All @@ -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}.
*
Expand All @@ -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;
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,14 @@ public class FlattenMojo extends AbstractFlattenMojo {
@Parameter(property = "flatten.dependency.keepComments", required = false, defaultValue = "false")
private boolean keepCommentsInPom;

/**
* The default operation to use when no element handling is given. Defaults to <code>flatten</code>.
*
* @since 1.5.1
*/
@Parameter(property = "flatten.dependency.defaultOperation", required = false, defaultValue = "flatten")
private ElementHandling defaultOperation;

@Inject
private DirectDependenciesInheritanceAssembler inheritanceAssembler;

Expand Down Expand Up @@ -767,10 +775,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;
}

Expand Down

0 comments on commit bb2e123

Please sign in to comment.