From dfc02e8d24709b9464a312ca72b1e1dbc5bbb00e Mon Sep 17 00:00:00 2001 From: Wouter Aarts Date: Mon, 8 Apr 2019 16:08:36 +0200 Subject: [PATCH] Remove html escaping of old html reporter and correct file names so the stryker parser creates proper folders --- .../report/html/AnnotatedLineFactory.java | 35 +++++++++---------- .../pitest/mutationtest/report/html/Line.java | 6 ++-- .../html/stryker/StrykerJsonParser.java | 14 +++++--- 3 files changed, 28 insertions(+), 27 deletions(-) diff --git a/pitest-html-report/src/main/java/org/pitest/mutationtest/report/html/AnnotatedLineFactory.java b/pitest-html-report/src/main/java/org/pitest/mutationtest/report/html/AnnotatedLineFactory.java index 1d352e331..2e0217b0e 100644 --- a/pitest-html-report/src/main/java/org/pitest/mutationtest/report/html/AnnotatedLineFactory.java +++ b/pitest-html-report/src/main/java/org/pitest/mutationtest/report/html/AnnotatedLineFactory.java @@ -14,6 +14,12 @@ */ package org.pitest.mutationtest.report.html; +import org.pitest.classinfo.ClassInfo; +import org.pitest.coverage.ClassLine; +import org.pitest.coverage.CoverageDatabase; +import org.pitest.functional.FCollection; +import org.pitest.mutationtest.MutationResult; + import java.io.IOException; import java.io.Reader; import java.util.Collection; @@ -22,21 +28,13 @@ import java.util.function.Predicate; import java.util.stream.Collectors; -import org.pitest.classinfo.ClassInfo; -import org.pitest.coverage.ClassLine; -import org.pitest.coverage.CoverageDatabase; -import org.pitest.functional.FCollection; -import org.pitest.mutationtest.MutationResult; -import org.pitest.util.StringUtil; - public class AnnotatedLineFactory { - private final Collection mutations; - private final CoverageDatabase statistics; - private final Collection classesInFile; + private final Collection mutations; + private final CoverageDatabase statistics; + private final Collection classesInFile; - public AnnotatedLineFactory( - final Collection mutations, + public AnnotatedLineFactory(final Collection mutations, final CoverageDatabase statistics, final Collection classes) { this.mutations = mutations; this.statistics = statistics; @@ -58,9 +56,8 @@ private Function stringToAnnotatedLine() { @Override public Line apply(final String a) { - final Line l = new Line(this.lineNumber, - StringUtil.escapeBasicHtmlChars(a), lineCovered(this.lineNumber), - getMutationsForLine(this.lineNumber)); + final Line l = new Line(this.lineNumber, a, + lineCovered(this.lineNumber), getMutationsForLine(this.lineNumber)); this.lineNumber++; return l; } @@ -69,8 +66,7 @@ public Line apply(final String a) { } private List getMutationsForLine(final int lineNumber) { - return this.mutations.stream() - .filter(isAtLineNumber(lineNumber)) + return this.mutations.stream().filter(isAtLineNumber(lineNumber)) .collect(Collectors.toList()); } @@ -96,8 +92,9 @@ private boolean isCodeLine(final int line) { } private boolean isLineCovered(final int line) { - final Predicate predicate = a -> !AnnotatedLineFactory.this.statistics.getTestsForClassLine( - new ClassLine(a.getName().asInternalName(), line)).isEmpty(); + final Predicate predicate = a -> !AnnotatedLineFactory.this.statistics + .getTestsForClassLine(new ClassLine(a.getName().asInternalName(), line)) + .isEmpty(); return FCollection.contains(this.classesInFile, predicate); } diff --git a/pitest-html-report/src/main/java/org/pitest/mutationtest/report/html/Line.java b/pitest-html-report/src/main/java/org/pitest/mutationtest/report/html/Line.java index d40474201..4cdd2fba4 100644 --- a/pitest-html-report/src/main/java/org/pitest/mutationtest/report/html/Line.java +++ b/pitest-html-report/src/main/java/org/pitest/mutationtest/report/html/Line.java @@ -14,12 +14,12 @@ */ package org.pitest.mutationtest.report.html; +import org.pitest.mutationtest.DetectionStatus; +import org.pitest.mutationtest.MutationResult; + import java.util.Collections; import java.util.List; - import java.util.Optional; -import org.pitest.mutationtest.DetectionStatus; -import org.pitest.mutationtest.MutationResult; public class Line { private final long number; diff --git a/pitest-html-report/src/main/java/org/pitest/mutationtest/report/html/stryker/StrykerJsonParser.java b/pitest-html-report/src/main/java/org/pitest/mutationtest/report/html/stryker/StrykerJsonParser.java index c4a168a73..49617a6aa 100644 --- a/pitest-html-report/src/main/java/org/pitest/mutationtest/report/html/stryker/StrykerJsonParser.java +++ b/pitest-html-report/src/main/java/org/pitest/mutationtest/report/html/stryker/StrykerJsonParser.java @@ -1,6 +1,7 @@ package org.pitest.mutationtest.report.html.stryker; import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import org.pitest.classinfo.ClassInfo; import org.pitest.coverage.CoverageDatabase; import org.pitest.functional.FCollection; @@ -34,11 +35,11 @@ public StrykerJsonParser(final Collection sourceRoots, private final Map collectedStrykerFiles = new HashMap<>(); private final Set parsedMutations = new HashSet<>(); - private final Gson gson = new Gson(); + private final Gson gson = new GsonBuilder().disableHtmlEscaping().create(); public String getJson() throws IOException { StrykerReport report = new StrykerReport(collectedStrykerFiles); - return gson.toJson(report); + return gson.toJson(report, StrykerReport.class); // final String beginJson = // "{" + "\"schemaVersion\": \"1\"," + "\"thresholds\": {" @@ -84,10 +85,13 @@ private void addToStrykerFiles(PackageSummaryData packageSummaryData) final String source = this.parseLinesToString(lines); if (!source.isEmpty()) { // Step 3: Add mutations to file - if (this.collectedStrykerFiles.get(data.getFileName()) == null) { - this.collectedStrykerFiles.put(data.getFileName(), new StrykerFile()); + final String fullPath = + data.getPackageName().replaceAll("\\.", "/") + "/" + data + .getFileName(); + if (this.collectedStrykerFiles.get(fullPath) == null) { + this.collectedStrykerFiles.put(fullPath, new StrykerFile()); } - StrykerFile file = this.collectedStrykerFiles.get(data.getFileName()); + StrykerFile file = this.collectedStrykerFiles.get(fullPath); file.addMutants(strykerMutants); file.addSource(source); }