Skip to content

Commit

Permalink
[FIXED JENKINS-15539]
Browse files Browse the repository at this point in the history
/jacoco.exec now serves the (possibly combined) jacoco.exec file.
  • Loading branch information
kohsuke committed Feb 22, 2013
1 parent 8aa01a9 commit 45e4e6e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
40 changes: 40 additions & 0 deletions src/main/java/hudson/plugins/jacoco/report/CoverageReport.java
Expand Up @@ -6,16 +6,27 @@
import hudson.plugins.jacoco.JacocoHealthReportThresholds;
import hudson.plugins.jacoco.model.Coverage;

import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import hudson.util.HttpResponses;
import org.jacoco.core.analysis.IClassCoverage;
import org.jacoco.core.analysis.IMethodCoverage;
import org.jacoco.core.analysis.IPackageCoverage;
import org.jacoco.core.data.ExecFileLoader;
import org.jacoco.core.data.ExecutionDataWriter;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.WebMethod;

import javax.servlet.ServletException;

/**
* Root object of the coverage report.
Expand Down Expand Up @@ -149,6 +160,35 @@ public AbstractBuild<?,?> getBuild() {
return action.owner;
}

/**
* Serves a single jacoco.exec file that merges all that have been recorded.
*/
@WebMethod(name="jacoco.exec")
public HttpResponse doJacocoExec() throws IOException {
final List<File> files = action.getJacocoReport().getExecFiles();

switch (files.size()) {
case 0:
return HttpResponses.error(404, "No jacoco.exec file recorded");
case 1:
return HttpResponses.staticResource(files.get(0));
default:
// TODO: perhaps we want to cache the merged result?
return new HttpResponse() {
public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException {
ExecFileLoader loader = new ExecFileLoader();
for (File exec : files) {
loader.load(exec);
}
rsp.setContentType("application/octet-stream");
final ExecutionDataWriter dataWriter = new ExecutionDataWriter(rsp.getOutputStream());
loader.getSessionInfoStore().accept(dataWriter);
loader.getExecutionDataStore().accept(dataWriter);
}
};
}
}


public void setThresholds(JacocoHealthReportThresholds healthReports) {
this.healthReports = healthReports;
Expand Down
Expand Up @@ -3,7 +3,11 @@
<st:include it="${it.build}" page="sidepanel.jelly" />
<l:main-panel>
<h2>${%JaCoCo Coverage Report}</h2>

<div>
<img src="${imagesURL}/24x24/save.png" />

<a href="jacoco.exec">Download <tt>jacoco.exec</tt> binary coverage file</a>
</div>

<e:floatingTrendGraph/>

Expand Down

0 comments on commit 45e4e6e

Please sign in to comment.