Skip to content

Commit

Permalink
Avoid parent's field direct access in Mojos
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgabut committed Feb 15, 2019
1 parent 79b5ba7 commit b9469e6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 20 deletions.
32 changes: 26 additions & 6 deletions pitest-maven/src/main/java/org/pitest/maven/AbstractPitMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,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 +47,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 +349,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 +366,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,14 +474,34 @@ 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;
}

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

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

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

public List<String> getExcludedMethods() {
return this.excludedMethods;
}
Expand Down
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

0 comments on commit b9469e6

Please sign in to comment.