Skip to content

Commit

Permalink
Remove html escaping of old html reporter and correct file names so t…
Browse files Browse the repository at this point in the history
…he stryker parser creates proper folders
  • Loading branch information
Wmaarts committed Apr 8, 2019
1 parent e180251 commit dfc02e8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<MutationResult> mutations;
private final CoverageDatabase statistics;
private final Collection<ClassInfo> classesInFile;
private final Collection<MutationResult> mutations;
private final CoverageDatabase statistics;
private final Collection<ClassInfo> classesInFile;

public AnnotatedLineFactory(
final Collection<MutationResult> mutations,
public AnnotatedLineFactory(final Collection<MutationResult> mutations,
final CoverageDatabase statistics, final Collection<ClassInfo> classes) {
this.mutations = mutations;
this.statistics = statistics;
Expand All @@ -58,9 +56,8 @@ private Function<String, Line> 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;
}
Expand All @@ -69,8 +66,7 @@ public Line apply(final String a) {
}

private List<MutationResult> getMutationsForLine(final int lineNumber) {
return this.mutations.stream()
.filter(isAtLineNumber(lineNumber))
return this.mutations.stream().filter(isAtLineNumber(lineNumber))
.collect(Collectors.toList());
}

Expand All @@ -96,8 +92,9 @@ private boolean isCodeLine(final int line) {
}

private boolean isLineCovered(final int line) {
final Predicate<ClassInfo> predicate = a -> !AnnotatedLineFactory.this.statistics.getTestsForClassLine(
new ClassLine(a.getName().asInternalName(), line)).isEmpty();
final Predicate<ClassInfo> predicate = a -> !AnnotatedLineFactory.this.statistics
.getTestsForClassLine(new ClassLine(a.getName().asInternalName(), line))
.isEmpty();
return FCollection.contains(this.classesInFile, predicate);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -34,11 +35,11 @@ public StrykerJsonParser(final Collection<SourceLocator> sourceRoots,
private final Map<String, StrykerFile> collectedStrykerFiles = new HashMap<>();
private final Set<MutationIdentifier> 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\": {"
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit dfc02e8

Please sign in to comment.