Skip to content

Commit

Permalink
extra features param for maven
Browse files Browse the repository at this point in the history
Additional parameter extraFeatures allowed features to be added from the
commandline without overwriting/needing to respecify features set within
the pom.xml
  • Loading branch information
hcoles committed Sep 19, 2023
1 parent 3638a83 commit a171784
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
22 changes: 20 additions & 2 deletions pitest-maven/src/main/java/org/pitest/maven/AbstractPitMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,19 @@ public class AbstractPitMojo extends AbstractMojo {
private ArrayList<String> mutators;

/**
* Mutation operators to apply
* Features to activate/deactivate
*/
@Parameter(property = "features")
private ArrayList<String> features;

/**
* Additional features activate/deactivate, use to
* avoid overwriting features set in the build script when
* specifying features from the command line
*/
@Parameter(property = "extraFeatures")
private ArrayList<String> extraFeatures;


/**
* Weighting to allow for timeouts
Expand Down Expand Up @@ -739,7 +747,9 @@ public ArrayList<String> getExcludedRunners() {
}

public ArrayList<String> getFeatures() {
return withoutNulls(features);
ArrayList<String> consolidated = emptyWithoutNulls(features);
consolidated.addAll(emptyWithoutNulls(extraFeatures));
return consolidated;
}

public boolean isUseClasspathJar() {
Expand Down Expand Up @@ -778,6 +788,14 @@ public List<String> getReasons() {
}
}

private <X> ArrayList<X> emptyWithoutNulls(List<X> originalList) {
if (originalList == null) {
return new ArrayList<>();
}

return withoutNulls(originalList);
}

private <X> ArrayList<X> withoutNulls(List<X> originalList) {
if (originalList == null) {
return null;
Expand Down
17 changes: 17 additions & 0 deletions pitest-maven/src/test/java/org/pitest/maven/PitMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,23 @@ public void testEmptyFeatureIsIgnored() throws Exception {
mojo.getFeatures());
}

public void testCombinesFeaturesAndExtraFeatures() throws Exception {

AbstractPitMojo mojo = createPITMojo(createPomWithConfiguration("\n"
+ " <features>\n"
+ " <feature>FEATURE</feature>\n"
+ " </features>\n"
+ " <extraFeatures>\n"
+ " <feature>ALSO_A_FEATURE</feature>\n"
+ " <feature>MORE</feature>\n"
+ " </extraFeatures>\n"
));

assertEquals(
asList("FEATURE", "ALSO_A_FEATURE", "MORE"),
mojo.getFeatures());
}

private void setupCoverage(long mutationScore, int lines, int linesCovered)
throws MojoExecutionException {
Iterable<Score> scores = Collections.<Score>emptyList();
Expand Down

0 comments on commit a171784

Please sign in to comment.