Skip to content

Commit

Permalink
Merge pull request hcoles#555 from maxgabut/nulls-plugin-list-elements
Browse files Browse the repository at this point in the history
Ignore empty element from plugin configuration
  • Loading branch information
hcoles authored Feb 23, 2019
2 parents 79b5ba7 + df50c0c commit abcce5f
Show file tree
Hide file tree
Showing 5 changed files with 299 additions and 38 deletions.
77 changes: 55 additions & 22 deletions pitest-maven/src/main/java/org/pitest/maven/AbstractPitMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.logging.Logger;

import org.apache.maven.artifact.Artifact;
Expand All @@ -17,6 +18,8 @@
import org.pitest.coverage.CoverageSummary;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import org.pitest.mutationtest.config.PluginServices;
import org.pitest.mutationtest.config.ReportOptions;
import org.pitest.mutationtest.statistics.MutationStatistics;
Expand All @@ -31,9 +34,9 @@ public class AbstractPitMojo extends AbstractMojo {

private final Predicate<MavenProject> notEmptyProject;

protected final Predicate<Artifact> filter;
private final Predicate<Artifact> filter;

protected final PluginServices plugins;
private final PluginServices plugins;

// Concrete List types declared for all fields to work around maven 2 bug

Expand All @@ -47,13 +50,13 @@ public class AbstractPitMojo extends AbstractMojo {
* Classes to include in mutation test
*/
@Parameter(property = "targetClasses")
protected ArrayList<String> targetClasses;
private ArrayList<String> targetClasses;

/**
* Tests to run
*/
@Parameter(property = "targetTests")
protected ArrayList<String> targetTests;
private ArrayList<String> targetTests;

/**
* Methods not to mutate
Expand Down Expand Up @@ -349,7 +352,7 @@ public class AbstractPitMojo extends AbstractMojo {
*
*/
@Parameter(property = "project", readonly = true, required = true)
protected MavenProject project;
private MavenProject project;

/**
* <i>Internal</i>: Map of plugin artifacts.
Expand All @@ -366,7 +369,7 @@ public class AbstractPitMojo extends AbstractMojo {
@Parameter(property = "useClasspathJar", defaultValue = "false")
private boolean useClasspathJar;

protected final GoalStrategy goalStrategy;
private final GoalStrategy goalStrategy;

public AbstractPitMojo() {
this(new RunPitStrategy(), new DependencyFilter(new PluginServices(
Expand Down Expand Up @@ -474,24 +477,44 @@ protected File detectBaseDir() {
return executionProject.getBasedir();
}

protected Predicate<Artifact> getFilter() {
return filter;
}

protected GoalStrategy getGoalStrategy() {
return goalStrategy;
}

protected PluginServices getPlugins() {
return plugins;
}

public List<String> getTargetClasses() {
return this.targetClasses;
return withoutNulls(this.targetClasses);
}

public void setTargetClasses(ArrayList<String> targetClasses) {
this.targetClasses = targetClasses;
}

public List<String> getTargetTests() {
return this.targetTests;
return withoutNulls(this.targetTests);
}

public void setTargetTests(ArrayList<String> targetTests) {
this.targetTests = targetTests;
}

public List<String> getExcludedMethods() {
return this.excludedMethods;
return withoutNulls(this.excludedMethods);
}

public List<String> getExcludedClasses() {
return this.excludedClasses;
return withoutNulls(this.excludedClasses);
}

public List<String> getAvoidCallsTo() {
return this.avoidCallsTo;
return withoutNulls(this.avoidCallsTo);
}

public File getReportsDirectory() {
Expand All @@ -511,7 +534,7 @@ public boolean isMutateStaticInitializers() {
}

public List<String> getMutators() {
return this.mutators;
return withoutNulls(this.mutators);
}

public float getTimeoutFactor() {
Expand All @@ -523,19 +546,19 @@ public long getTimeoutConstant() {
}

public ArrayList<String> getExcludedTestClasses() {
return excludedTestClasses;
return withoutNulls(excludedTestClasses);
}

public int getMaxMutationsPerClass() {
return this.maxMutationsPerClass;
}

public List<String> getJvmArgs() {
return this.jvmArgs;
return withoutNulls(this.jvmArgs);
}

public List<String> getOutputFormats() {
return this.outputFormats;
return withoutNulls(this.outputFormats);
}

public boolean isVerbose() {
Expand All @@ -555,15 +578,15 @@ public boolean isFailWhenNoMutations() {
}

public List<String> getExcludedGroups() {
return this.excludedGroups;
return withoutNulls(this.excludedGroups);
}

public List<String> getIncludedGroups() {
return this.includedGroups;
return withoutNulls(this.includedGroups);
}

public List<String> getIncludedTestMethods() {
return this.includedTestMethods;
return withoutNulls(this.includedTestMethods);
}

public boolean isFullMutationMatrix() {
Expand Down Expand Up @@ -637,11 +660,11 @@ public void setJavaExecutable(final String javaExecutable) {
}

public List<String> getAdditionalClasspathElements() {
return this.additionalClasspathElements;
return withoutNulls(this.additionalClasspathElements);
}

public List<String> getClasspathDependencyExcludes() {
return this.classpathDependencyExcludes;
return withoutNulls(this.classpathDependencyExcludes);
}

public boolean isParseSurefireConfig() {
Expand All @@ -665,11 +688,11 @@ public boolean useHistory() {
}

public ArrayList<String> getExcludedRunners() {
return excludedRunners;
return withoutNulls(excludedRunners);
}

public ArrayList<String> getFeatures() {
return features;
return withoutNulls(features);
}

public String getTestPlugin() {
Expand All @@ -696,4 +719,14 @@ public List<String> getReasons() {
}
}

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

return originalList.stream()
.filter(Objects::nonNull)
.collect(Collectors.toCollection(ArrayList::new));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private void determineHistory(final ReportOptions data) {

private void useHistoryFileInTempDir(final ReportOptions data) {
String tempDir = System.getProperty("java.io.tmpdir");
MavenProject project = this.mojo.project;
MavenProject project = this.mojo.getProject();
String name = project.getGroupId() + "."
+ project.getArtifactId() + "."
+ project.getVersion() + "_pitest_history.bin";
Expand Down
26 changes: 13 additions & 13 deletions pitest-maven/src/main/java/org/pitest/maven/ScmMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ protected Optional<CombinedStatistics> analyse() throws MojoExecutionException {
this.scmRootDir = findScmRootDir();
}

this.targetClasses = makeConcreteList(findModifiedClassNames());
setTargetClasses(makeConcreteList(findModifiedClassNames()));

if (this.targetClasses.isEmpty()) {
if (this.getTargetClasses().isEmpty()) {
this.getLog().info(
"No modified files found - nothing to mutation test, analyseLastCommit=" + this.analyseLastCommit);
return Optional.empty();
Expand All @@ -126,32 +126,32 @@ protected Optional<CombinedStatistics> analyse() throws MojoExecutionException {
logClassNames();
defaultTargetTestsIfNoValueSet();
final ReportOptions data = new MojoToReportOptionsConverter(this,
new SurefireConfigConverter(), filter).convert();
new SurefireConfigConverter(), getFilter()).convert();
data.setFailWhenNoMutations(false);

return Optional.ofNullable(this.goalStrategy.execute(detectBaseDir(), data,
plugins, new HashMap<String, String>()));
return Optional.ofNullable(this.getGoalStrategy().execute(detectBaseDir(), data,
getPlugins(), new HashMap<String, String>()));

}

private void defaultTargetTestsIfNoValueSet() {
if (this.getTargetTests() == null || this.getTargetTests().isEmpty()) {
File tests = new File(this.getProject().getBuild()
.getTestOutputDirectory());
this.targetTests = new ArrayList<>(MojoToReportOptionsConverter
.findOccupiedPackagesIn(tests));
setTargetTests(new ArrayList<>(MojoToReportOptionsConverter
.findOccupiedPackagesIn(tests)));
}
}

private void logClassNames() {
for (final String each : this.targetClasses) {
for (final String each : this.getTargetClasses()) {
this.getLog().info("Will mutate changed class " + each);
}
}

private List<String> findModifiedClassNames() throws MojoExecutionException {

final File sourceRoot = new File(this.project.getBuild()
final File sourceRoot = new File(this.getProject().getBuild()
.getSourceDirectory());

final List<String> modifiedPaths = FCollection.map(findModifiedPaths(), pathByScmDir());
Expand All @@ -165,7 +165,7 @@ private Function<String, String> pathByScmDir() {
}

private File findScmRootDir() {
MavenProject rootProject = this.project;
MavenProject rootProject = this.getProject();
while (rootProject.hasParent() && rootProject.getParent().getBasedir() != null) {
rootProject = rootProject.getParent();
}
Expand Down Expand Up @@ -268,17 +268,17 @@ private File scmRoot() {

private String getSCMConnection() throws MojoExecutionException {

if (this.project.getScm() == null) {
if (this.getProject().getScm() == null) {
throw new MojoExecutionException("No SCM Connection configured.");
}

final String scmConnection = this.project.getScm().getConnection();
final String scmConnection = this.getProject().getScm().getConnection();
if ("connection".equalsIgnoreCase(this.connectionType)
&& StringUtils.isNotEmpty(scmConnection)) {
return scmConnection;
}

final String scmDeveloper = this.project.getScm().getDeveloperConnection();
final String scmDeveloper = this.getProject().getScm().getDeveloperConnection();
if ("developerconnection".equalsIgnoreCase(this.connectionType)
&& StringUtils.isNotEmpty(scmDeveloper)) {
return scmDeveloper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ protected void configurePitMojo(final AbstractPitMojo pitMojo, final String conf

setVariableValueToObject(pitMojo, "project", this.project);

ArrayList<String> elements = new ArrayList<>();
setVariableValueToObject(pitMojo, "additionalClasspathElements", elements);
if (pitMojo.getAdditionalClasspathElements() == null) {
ArrayList<String> elements = new ArrayList<>();
setVariableValueToObject(pitMojo, "additionalClasspathElements", elements);
}

}

Expand Down
Loading

0 comments on commit abcce5f

Please sign in to comment.