Skip to content

Commit

Permalink
expand BuildVerifierFactory args
Browse files Browse the repository at this point in the history
  • Loading branch information
hcoles committed Apr 5, 2024
1 parent 887a350 commit b10626d
Show file tree
Hide file tree
Showing 24 changed files with 122 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.pitest.coverage.ReportCoverage;
import org.pitest.mutationtest.config.ReportOptions;
import org.pitest.mutationtest.engine.MutationEngine;
import org.pitest.mutationtest.verify.BuildIssue;
import org.pitest.mutationtest.verify.BuildMessage;
import org.pitest.plugin.FeatureSetting;
import org.pitest.util.ResultOutputStrategy;

Expand All @@ -26,7 +26,7 @@ public class ListenerArguments {
private final boolean fullMutationMatrix;
private final ReportOptions data;
private final FeatureSetting setting;
private final List<BuildIssue> issues;
private final List<BuildMessage> issues;

public ListenerArguments(ResultOutputStrategy outputStrategy,
ReportCoverage coverage,
Expand All @@ -35,7 +35,7 @@ public ListenerArguments(ResultOutputStrategy outputStrategy,
long startTime,
boolean fullMutationMatrix,
ReportOptions data,
List<BuildIssue> issues) {
List<BuildMessage> issues) {
this(outputStrategy, coverage, locator, engine, startTime, fullMutationMatrix, data, null, issues);
}

Expand All @@ -47,7 +47,7 @@ public ListenerArguments(ResultOutputStrategy outputStrategy,
boolean fullMutationMatrix,
ReportOptions data,
FeatureSetting setting,
List<BuildIssue> issues) {
List<BuildMessage> issues) {
this.outputStrategy = outputStrategy;
this.coverage = coverage;
this.locator = locator;
Expand Down Expand Up @@ -94,7 +94,7 @@ public Optional<FeatureSetting> settings() {
return Optional.ofNullable(setting);
}

public List<BuildIssue> issues() {
public List<BuildMessage> issues() {
return Collections.unmodifiableList(issues);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.pitest.coverage.CoverageSummary;
import org.pitest.mutationtest.statistics.MutationStatistics;
import org.pitest.mutationtest.verify.BuildIssue;
import org.pitest.mutationtest.verify.BuildMessage;

import java.util.List;

Expand All @@ -11,11 +11,11 @@ public class CombinedStatistics {
private final MutationStatistics mutationStatistics;
private final CoverageSummary coverageSummary;

private final List<BuildIssue> issues;
private final List<BuildMessage> issues;

public CombinedStatistics(MutationStatistics mutationStatistics,
CoverageSummary coverageSummary,
List<BuildIssue> issues) {
List<BuildMessage> issues) {
this.mutationStatistics = mutationStatistics;
this.coverageSummary = coverageSummary;
this.issues = issues;
Expand All @@ -29,7 +29,7 @@ public CoverageSummary getCoverageSummary() {
return this.coverageSummary;
}

public List<BuildIssue> getIssues() {
public List<BuildMessage> getIssues() {
return issues;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.pitest.mutationtest.incremental.NullHistory;
import org.pitest.mutationtest.incremental.NullWriterFactory;
import org.pitest.mutationtest.incremental.WriterFactory;
import org.pitest.mutationtest.verify.BuildVerifierArguments;
import org.pitest.plugin.Feature;
import org.pitest.plugin.FeatureParameter;
import org.pitest.plugin.FeatureParser;
Expand Down Expand Up @@ -127,7 +128,7 @@ public AnalysisResult execute(File baseDir, ReportOptions data,
final MutationStrategies strategies = new MutationStrategies(
settings.createEngine(), history, coverageDatabase, reportFactory, settings.getResultInterceptor().add(new HistoryResultInterceptor(history)),
settings.createCoverageTransformer(code),
reportOutput, settings.createVerifier().create(code));
reportOutput, settings.createVerifier().create(new BuildVerifierArguments(code, data)));

final MutationCoverage report = new MutationCoverage(strategies, baseDir,
code, data, settings, timings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import org.pitest.mutationtest.statistics.MutationStatistics;
import org.pitest.mutationtest.statistics.MutationStatisticsListener;
import org.pitest.mutationtest.statistics.Score;
import org.pitest.mutationtest.verify.BuildIssue;
import org.pitest.mutationtest.verify.BuildMessage;
import org.pitest.util.Log;
import org.pitest.util.StringUtil;
import org.pitest.util.Timings;
Expand Down Expand Up @@ -114,7 +114,7 @@ public CombinedStatistics runReport() throws IOException {

final long t0 = System.nanoTime();

List<BuildIssue> issues = verifyBuildSuitableForMutationTesting();
List<BuildMessage> issues = verifyBuildSuitableForMutationTesting();

checkExcludedRunners();

Expand Down Expand Up @@ -143,7 +143,7 @@ private CombinedStatistics emptyStatistics() {
return new CombinedStatistics(mutationStatistics, new CoverageSummary(0,0), Collections.emptyList());
}

private CombinedStatistics runAnalysis(Runtime runtime, long t0, EngineArguments args, MutationEngine engine, List<BuildIssue> issues) {
private CombinedStatistics runAnalysis(Runtime runtime, long t0, EngineArguments args, MutationEngine engine, List<BuildMessage> issues) {
History history = this.strategies.history();
history.initialize();

Expand Down Expand Up @@ -255,7 +255,7 @@ private List<MutationResultListener> createConfig(long t0,
ReportCoverage coverageData,
History history,
MutationStatisticsListener stats,
MutationEngine engine, List<BuildIssue> issues) {
MutationEngine engine, List<BuildMessage> issues) {
final List<MutationResultListener> ls = new ArrayList<>();

ls.add(stats);
Expand All @@ -280,7 +280,7 @@ private MutationResultInterceptor resultInterceptor() {
return this.strategies.resultInterceptor();
}

private List<BuildIssue> verifyBuildSuitableForMutationTesting() {
private List<BuildMessage> verifyBuildSuitableForMutationTesting() {
return this.strategies.buildVerifier().verifyBuild();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

import java.util.Objects;

public final class BuildIssue implements Comparable<BuildIssue> {
public final class BuildMessage implements Comparable<BuildMessage> {
private final String text;
private final String url;
private final int priority;

public BuildIssue(String text, String url, int priority) {
public BuildMessage(String text, String url, int priority) {
this.text = text;
this.url = url;
this.priority = priority;
}

public static BuildIssue issue(String text) {
return new BuildIssue(text, null, 5);
public static BuildMessage buildMessage(String text) {
return new BuildMessage(text, null, 5);
}

public String text() {
Expand Down Expand Up @@ -42,7 +42,7 @@ public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
BuildIssue that = (BuildIssue) o;
BuildMessage that = (BuildMessage) o;
return priority == that.priority && Objects.equals(text, that.text) && Objects.equals(url, that.url);
}

Expand All @@ -52,7 +52,7 @@ public int hashCode() {
}

@Override
public int compareTo(BuildIssue o) {
public int compareTo(BuildMessage o) {
return Integer.compare(this.priority, o.priority);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ default List<String> verify() {
return Collections.emptyList();
}

default List<BuildIssue> verifyBuild() {
default List<BuildMessage> verifyBuild() {
return verify().stream()
.map(BuildIssue::issue)
.map(BuildMessage::buildMessage)
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.pitest.mutationtest.verify;

import org.pitest.classpath.CodeSource;
import org.pitest.mutationtest.config.ReportOptions;

public class BuildVerifierArguments {

private final CodeSource code;
private final ReportOptions data;

public BuildVerifierArguments(CodeSource code, ReportOptions data) {
this.code = code;
this.data = data;
}

public ReportOptions data() {
return data;
}

public CodeSource code() {
return code;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,12 @@

public interface BuildVerifierFactory extends ToolClasspathPlugin {

BuildVerifier create(CodeSource code);
default BuildVerifier create(BuildVerifierArguments args) {
return create(args.code());
}

@Deprecated
default BuildVerifier create(CodeSource code) {
throw new IllegalStateException();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.pitest.mutationtest.verify;

import org.pitest.classpath.CodeSource;

import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -14,15 +12,15 @@ public CompoundBuildVerifierFactory(List<BuildVerifierFactory> verifiers) {
}

@Override
public BuildVerifier create(CodeSource code) {
List<BuildIssue> issues = verifiers.stream()
.map(f -> f.create(code))
public BuildVerifier create(BuildVerifierArguments args) {
List<BuildMessage> issues = verifiers.stream()
.map(f -> f.create(args))
.flatMap(v -> v.verifyBuild().stream())
.collect(Collectors.toList());

return new BuildVerifier() {
@Override
public List<BuildIssue> verifyBuild() {
public List<BuildMessage> verifyBuild() {
return issues;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public DefaultBuildVerifier(CodeSource code) {
}

@Override
public List<BuildIssue> verifyBuild() {
public List<BuildMessage> verifyBuild() {

// check we have at least one class that is not an interface
// otherwise our checks will fire on an empty project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class KotlinVerifier implements BuildVerifier {
}

@Override
public List<BuildIssue> verifyBuild() {
public List<BuildMessage> verifyBuild() {
if (kotlinIsOnClassPath() && !kotlinPluginIsPresent() && kotlinClassesToBeMutated()) {
return asList(new BuildIssue("Project uses kotlin, but the Arcmutate kotlin plugin is not present.", "https://docs.arcmutate.com/docs/kotlin.html", 4));
return asList(new BuildMessage("Project uses kotlin, but the Arcmutate kotlin plugin is not present.", "https://docs.arcmutate.com/docs/kotlin.html", 4));
}

return Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ class MissingJUnit5PluginVerifier implements BuildVerifier {
}

@Override
public List<BuildIssue> verifyBuild() {
public List<BuildMessage> verifyBuild() {
if (!junit5PluginIsPresent() && junitJupiterPresent()) {
// log as well as return in case the run is aborted before messages are displayed at the end
String msg = "JUnit 5 is on the classpath but the pitest junit 5 plugin is not installed.";
Log.getLogger().warning(msg);
return asList(new BuildIssue(msg, "https://github.com/pitest/pitest-junit5-plugin", 5));
return asList(new BuildMessage(msg, "https://github.com/pitest/pitest-junit5-plugin", 5));
}

return Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ class MissingTestNGPluginVerifier implements BuildVerifier {
}

@Override
public List<BuildIssue> verifyBuild() {
public List<BuildMessage> verifyBuild() {
if (!testNGPluginIsPresent() && testNGisPresent()) {
// log as well as return in case the run is aborted before messages are displayed at the end
String msg = "TestNG is on the classpath but the pitest TestNG plugin is not installed.";
Log.getLogger().warning(msg);
return asList(new BuildIssue(msg, "https://github.com/pitest/pitest-testng-plugin", 5));
return asList(new BuildMessage(msg, "https://github.com/pitest/pitest-testng-plugin", 5));
}

return Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class SpringVerifier implements BuildVerifier {
}

@Override
public List<BuildIssue> verifyBuild() {
public List<BuildMessage> verifyBuild() {
if (springIsOnClassPath() && !springPluginIsPresent()) {
return asList(new BuildIssue("Project uses Spring, but the Arcmutate Spring plugin is not present.", "https://docs.arcmutate.com/docs/spring.html", 4));
return asList(new BuildMessage("Project uses Spring, but the Arcmutate Spring plugin is not present.", "https://docs.arcmutate.com/docs/spring.html", 4));
}

return Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.pitest.mutationtest;

import org.junit.Test;
import org.pitest.mutationtest.verify.BuildIssue;
import org.pitest.mutationtest.verify.BuildMessage;

import java.util.List;

Expand All @@ -12,17 +12,17 @@ public class ListenerArgumentsTest {

@Test
public void removesDuplicateBuildIssues() {
List<BuildIssue> issues = asList(BuildIssue.issue("foo"), BuildIssue.issue("foo"));
List<BuildMessage> issues = asList(BuildMessage.buildMessage("foo"), BuildMessage.buildMessage("foo"));
ListenerArguments underTest = new ListenerArguments(null, null, null, null, 0, false, null, issues);
assertThat(underTest.issues()).containsExactly(BuildIssue.issue("foo"));
assertThat(underTest.issues()).containsExactly(BuildMessage.buildMessage("foo"));
}

@Test
public void ordersBuildIssuesByPriority() {
BuildIssue a = new BuildIssue("foo", null, 5);
BuildIssue b = new BuildIssue("important", null, 0);
BuildIssue c = new BuildIssue("bar", null, 4);
List<BuildIssue> issues = asList(a,b,c);
BuildMessage a = new BuildMessage("foo", null, 5);
BuildMessage b = new BuildMessage("important", null, 0);
BuildMessage c = new BuildMessage("bar", null, 4);
List<BuildMessage> issues = asList(a,b,c);
ListenerArguments underTest = new ListenerArguments(null, null, null, null, 0, false, null, issues);
assertThat(underTest.issues()).containsExactly(b, c, a);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
import static org.assertj.core.api.Assertions.assertThat;


public class BuildIssueTest {
public class BuildMessageTest {
@Test
public void obeysHashcodeEqualsContract() {
EqualsVerifier.forClass(BuildIssue.class)
EqualsVerifier.forClass(BuildMessage.class)
.verify();
}

@Test
public void sortsZeroPriorityFirst() {
BuildIssue a = new BuildIssue("a","",10);
BuildIssue b = new BuildIssue("b","",0);
BuildIssue c = new BuildIssue("c","",5);
BuildMessage a = new BuildMessage("a","",10);
BuildMessage b = new BuildMessage("b","",0);
BuildMessage c = new BuildMessage("c","",5);

List<BuildIssue> l = asList(a,b,c);
List<BuildMessage> l = asList(a,b,c);
Collections.sort(l);
assertThat(l).containsExactly(b,c,a);
}
Expand Down
Loading

0 comments on commit b10626d

Please sign in to comment.