From e52d86c2898b854e03eb926140ab0f5328a45109 Mon Sep 17 00:00:00 2001 From: Henry Coles Date: Mon, 8 Apr 2024 10:51:10 +0100 Subject: [PATCH] hide arcmutate link when installed --- .../java/org/pitest/aggregate/ReportAggregator.java | 1 + .../pitest/mutationtest/config/ReportOptions.java | 12 +++++++++++- .../mutationtest/tooling/MutationCoverage.java | 4 ++-- .../org/pitest/mutationtest/verify/BuildMessage.java | 4 +++- .../pitest/mutationtest/verify/BuildMessageTest.java | 12 ++++++++++++ .../mutationtest/report/html/HtmlReportFactory.java | 2 +- .../report/html/MutationHtmlReportListener.java | 5 +++++ .../templates/mutation/mutation_package_index.st | 7 +++++-- .../report/html/MutationHtmlReportListenerTest.java | 2 +- 9 files changed, 41 insertions(+), 8 deletions(-) diff --git a/pitest-aggregator/src/main/java/org/pitest/aggregate/ReportAggregator.java b/pitest-aggregator/src/main/java/org/pitest/aggregate/ReportAggregator.java index 3a43f8393..4a684e351 100644 --- a/pitest-aggregator/src/main/java/org/pitest/aggregate/ReportAggregator.java +++ b/pitest-aggregator/src/main/java/org/pitest/aggregate/ReportAggregator.java @@ -123,6 +123,7 @@ private MutationResultListener createResultListener(SourceLocator sourceLocator, mutatorNames, partialCoverage, Collections.emptyList(), + true, sourceLocator); } diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/config/ReportOptions.java b/pitest-entry/src/main/java/org/pitest/mutationtest/config/ReportOptions.java index c35927a3b..723eaf20d 100644 --- a/pitest-entry/src/main/java/org/pitest/mutationtest/config/ReportOptions.java +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/config/ReportOptions.java @@ -151,6 +151,8 @@ public class ReportOptions { private Charset inputEncoding; private Charset outputEncoding; + private boolean arcmutateMissing = true; + // currently used only via maven private Map environmentVariables = new HashMap<>(); @@ -666,6 +668,14 @@ public Map getEnvironmentVariables() { return environmentVariables; } + public boolean isArcmutateMissing() { + return arcmutateMissing; + } + + public void setArcmutateMissing(boolean arcmutateMissing) { + this.arcmutateMissing = arcmutateMissing; + } + @Override public String toString() { return new StringJoiner(", ", ReportOptions.class.getSimpleName() + "[", "]") @@ -714,8 +724,8 @@ public String toString() { .add("inputEncoding=" + inputEncoding) .add("outputEncoding=" + outputEncoding) .add("reportCoverage=" + reportCoverage) + .add("arcmutateMissing=" + arcmutateMissing) .toString(); } - } diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/tooling/MutationCoverage.java b/pitest-entry/src/main/java/org/pitest/mutationtest/tooling/MutationCoverage.java index 7547e0105..2529233d0 100644 --- a/pitest-entry/src/main/java/org/pitest/mutationtest/tooling/MutationCoverage.java +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/tooling/MutationCoverage.java @@ -315,8 +315,8 @@ private void printStats(CombinedStatistics combinedStatistics) { if (!combinedStatistics.getIssues().isEmpty()) { ps.println(); - ps.println("!! The following issues were detected during the run !!"); - combinedStatistics.getIssues().forEach(ps::println); + ps.println("Build messages:- "); + combinedStatistics.getIssues().forEach(m -> ps.println("* " + m)); } } diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/verify/BuildMessage.java b/pitest-entry/src/main/java/org/pitest/mutationtest/verify/BuildMessage.java index 60189e7aa..c6370c532 100644 --- a/pitest-entry/src/main/java/org/pitest/mutationtest/verify/BuildMessage.java +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/verify/BuildMessage.java @@ -1,6 +1,7 @@ package org.pitest.mutationtest.verify; import java.util.Objects; +import java.util.Optional; public final class BuildMessage implements Comparable { private final String text; @@ -31,7 +32,8 @@ public int priority() { @Override public String toString() { - return text + " (" + url + ")"; + return text + Optional.ofNullable(url) + .map( u -> " (" + u + ")").orElse(""); } @Override diff --git a/pitest-entry/src/test/java/org/pitest/mutationtest/verify/BuildMessageTest.java b/pitest-entry/src/test/java/org/pitest/mutationtest/verify/BuildMessageTest.java index f97387359..c12657e8a 100644 --- a/pitest-entry/src/test/java/org/pitest/mutationtest/verify/BuildMessageTest.java +++ b/pitest-entry/src/test/java/org/pitest/mutationtest/verify/BuildMessageTest.java @@ -27,4 +27,16 @@ public void sortsZeroPriorityFirst() { Collections.sort(l); assertThat(l).containsExactly(b,c,a); } + + @Test + public void includesURLInToStringWhenPresent() { + BuildMessage underTest = new BuildMessage("text", "https://pitest.org", 0); + assertThat(underTest.toString()).isEqualTo("text (https://pitest.org)"); + } + + @Test + public void doesNotIncludeURLInToStringWhenNull() { + BuildMessage underTest = new BuildMessage("text", null, 0); + assertThat(underTest.toString()).isEqualTo("text"); + } } \ No newline at end of file diff --git a/pitest-html-report/src/main/java/org/pitest/mutationtest/report/html/HtmlReportFactory.java b/pitest-html-report/src/main/java/org/pitest/mutationtest/report/html/HtmlReportFactory.java index 3745f7c66..0802fe0ed 100644 --- a/pitest-html-report/src/main/java/org/pitest/mutationtest/report/html/HtmlReportFactory.java +++ b/pitest-html-report/src/main/java/org/pitest/mutationtest/report/html/HtmlReportFactory.java @@ -28,7 +28,7 @@ public MutationResultListener getListener(Properties props, ListenerArguments args) { return new MutationHtmlReportListener(args.data().getOutputEncoding(), args.getCoverage(), args.getOutputStrategy(), args.getEngine().getMutatorNames(), args.data().shouldReportCoverage(), - args.issues(), args.getLocator()); + args.issues(), args.data().isArcmutateMissing(), args.getLocator()); } @Override diff --git a/pitest-html-report/src/main/java/org/pitest/mutationtest/report/html/MutationHtmlReportListener.java b/pitest-html-report/src/main/java/org/pitest/mutationtest/report/html/MutationHtmlReportListener.java index f7b57a804..f76b2dcad 100644 --- a/pitest-html-report/src/main/java/org/pitest/mutationtest/report/html/MutationHtmlReportListener.java +++ b/pitest-html-report/src/main/java/org/pitest/mutationtest/report/html/MutationHtmlReportListener.java @@ -61,12 +61,15 @@ public class MutationHtmlReportListener implements MutationResultListener { private final List messages; + private final boolean arcmutateMissing; + public MutationHtmlReportListener(Charset outputCharset, ReportCoverage coverage, ResultOutputStrategy outputStrategy, Collection mutatorNames, boolean reportCoverage, List messages, + boolean arcmutateMissing, SourceLocator... locators) { this.outputCharset = outputCharset; this.coverage = coverage; @@ -76,6 +79,7 @@ public MutationHtmlReportListener(Charset outputCharset, this.css = loadCss(); this.reportCoverage = reportCoverage; this.messages = messages; + this.arcmutateMissing = arcmutateMissing; } private String loadCss() { @@ -227,6 +231,7 @@ private void createIndexPages() { st.setAttribute("outputCharset", this.outputCharset); st.setAttribute("showCoverage", this.reportCoverage); st.setAttribute("messages", wrap(this.messages)); + st.setAttribute("arcmutateMissing", arcmutateMissing); try { writer.write(st.toString()); writer.close(); diff --git a/pitest-html-report/src/main/resources/templates/mutation/mutation_package_index.st b/pitest-html-report/src/main/resources/templates/mutation/mutation_package_index.st index d6dadfbcb..efacb9020 100644 --- a/pitest-html-report/src/main/resources/templates/mutation/mutation_package_index.st +++ b/pitest-html-report/src/main/resources/templates/mutation/mutation_package_index.st @@ -71,7 +71,9 @@ $errors : { error | @@ -80,7 +82,8 @@ Report generated by PIT ${project.version}

-Enhanced functionality available at arcmutate.com +$if(arcmutateMissing)$ Enhanced functionality available at arcmutate.com +$endif$ \ No newline at end of file diff --git a/pitest-html-report/src/test/java/org/pitest/mutationtest/report/html/MutationHtmlReportListenerTest.java b/pitest-html-report/src/test/java/org/pitest/mutationtest/report/html/MutationHtmlReportListenerTest.java index 335fdc190..47e6998b9 100644 --- a/pitest-html-report/src/test/java/org/pitest/mutationtest/report/html/MutationHtmlReportListenerTest.java +++ b/pitest-html-report/src/test/java/org/pitest/mutationtest/report/html/MutationHtmlReportListenerTest.java @@ -69,7 +69,7 @@ public void setUp() { this.classInfo); this.testee = new MutationHtmlReportListener(StandardCharsets.UTF_8, this.coverageDb, - this.outputStrategy, Collections.emptyList(), true, Collections.emptyList(), this.sourceLocator); + this.outputStrategy, Collections.emptyList(), true, Collections.emptyList(), true, this.sourceLocator); } @Test