Skip to content

Commit

Permalink
Fixing:
Browse files Browse the repository at this point in the history
JENKINS-14928: Sourcefile highlighting loses the indentation
JENKINS-15182: improve formatting of coverage reports
  • Loading branch information
ognjenb committed Oct 8, 2012
1 parent 8f3b673 commit a697060
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/main/java/hudson/plugins/jacoco/report/MethodReport.java
Expand Up @@ -5,6 +5,7 @@
import hudson.plugins.jacoco.model.CoverageObject;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
Expand All @@ -18,6 +19,8 @@
import org.jacoco.core.analysis.ICounter;
import org.jacoco.core.analysis.IMethodCoverage;

import com.google.common.io.Files;

/**
* @author Kohsuke Kawaguchi
* @author David Carver
Expand Down Expand Up @@ -68,7 +71,7 @@ public void readFile(String filePath) throws java.io.FileNotFoundException,
br = new BufferedReader(new FileReader(filePath));
String line = null;
while ((line = br.readLine()) != null) {
aList.add(line.replaceAll("\\t"," ").replaceAll("<", "&lt"));
aList.add(line.replaceAll("\\t","&nbsp&nbsp&nbsp&nbsp").replaceAll("<", "&lt").replaceAll(">", "&gt"));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
Expand Down Expand Up @@ -128,16 +131,18 @@ public String printHighlightedSrcFile() {
try {

readFile(sourceFilePath);
buf.append(sourceFilePath+" lineSize: "+this.sourceLines.size()).append("<br>");
//buf.append(sourceFilePath+" number of lines: "+this.sourceLines.size()).append("<br>");
buf.append("<code>");
for (int i=1;i<=this.sourceLines.size(); ++i) {
if ((methodCov.getLine(i).getInstructionCounter().getStatus() == ICounter.FULLY_COVERED) || (methodCov.getLine(i).getInstructionCounter().getStatus() == ICounter.PARTLY_COVERED)) {
buf.append(i + ": ").append("<SPAN style=\"BACKGROUND-COLOR: #ffff00\">"+ sourceLines.get(i-1)).append("</SPAN>").append("<br>");
buf.append(i + ": ").append("<SPAN style=\"BACKGROUND-COLOR: #32cd32\">"+ sourceLines.get(i-1)).append("</SPAN>").append("<br>");
} else {
buf.append(i + ": ").append(sourceLines.get(i-1)).append("<br>");
}

}
buf.append("</code>");

//logger.log(Level.INFO, "lines: " + buf);
} catch (FileNotFoundException e) {
buf.append("ERROR: Sourcefile does not exist!");
} catch (IOException e) {
Expand Down

0 comments on commit a697060

Please sign in to comment.