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 authored and slawekjaranowski committed Jan 9, 2024
1 parent 9065dba commit c6f8e45
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 @@ -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 <code>flatten</code>.
*
* @since 1.6.0
*/
@Parameter(property = "flatten.dependency.defaultOperation", required = false, defaultValue = "flatten")
private ElementHandling defaultOperation;

@Inject
private DirectDependenciesInheritanceAssembler inheritanceAssembler;

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit c6f8e45

Please sign in to comment.