Skip to content

Commit

Permalink
Merge pull request #61 from felipebn/master
Browse files Browse the repository at this point in the history
Add coverage summary on build status/result page
  • Loading branch information
centic9 committed Nov 17, 2015
2 parents f55ced3 + 72529df commit 5ecbb3d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/main/java/hudson/plugins/jacoco/JacocoBuildAction.java
Expand Up @@ -240,6 +240,37 @@ public JacocoBuildAction getPreviousResult() {
return getPreviousResult(owner);
}

/**
* @return Map<CoverageRatio,Failed?> to represents coverage objects and its status to show on build status page (summary.jelly).
*/
public Map<Coverage,Boolean> getCoverageRatios(){
CoverageReport result = getResult();
Map<Coverage,Boolean> ratios = new LinkedHashMap<Coverage,Boolean>();
if( result != null ) {
Coverage instructionCoverage = result.getInstructionCoverage();
Coverage classCoverage = result.getClassCoverage();
Coverage complexityScore = result.getComplexityScore();
Coverage branchCoverage = result.getBranchCoverage();
Coverage lineCoverage = result.getLineCoverage();
Coverage methodCoverage = result.getMethodCoverage();

instructionCoverage.setType(CoverageElement.Type.INSTRUCTION);
classCoverage.setType(CoverageElement.Type.CLASS);
complexityScore.setType(CoverageElement.Type.COMPLEXITY);
branchCoverage.setType(CoverageElement.Type.BRANCH);
lineCoverage.setType(CoverageElement.Type.LINE);
methodCoverage.setType(CoverageElement.Type.METHOD);

ratios.put(instructionCoverage,JacocoHealthReportThresholds.RESULT.BELLOWMINIMUM == thresholds.getResultByTypeAndRatio(instructionCoverage));
ratios.put(branchCoverage,JacocoHealthReportThresholds.RESULT.BELLOWMINIMUM == thresholds.getResultByTypeAndRatio(branchCoverage));
ratios.put(complexityScore,JacocoHealthReportThresholds.RESULT.BELLOWMINIMUM == thresholds.getResultByTypeAndRatio(complexityScore));
ratios.put(lineCoverage,JacocoHealthReportThresholds.RESULT.BELLOWMINIMUM == thresholds.getResultByTypeAndRatio(lineCoverage));
ratios.put(methodCoverage,JacocoHealthReportThresholds.RESULT.BELLOWMINIMUM == thresholds.getResultByTypeAndRatio(methodCoverage));
ratios.put(classCoverage,JacocoHealthReportThresholds.RESULT.BELLOWMINIMUM == thresholds.getResultByTypeAndRatio(classCoverage));
}
return ratios;
}

/**
* Gets the previous {@link JacocoBuildAction} of the given build.
*/
Expand Down
@@ -0,0 +1,17 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler"
xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson"
xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<link rel="stylesheet" href="${rootURL}/plugin/jacoco/css/style.css"/>
<t:summary icon="/plugin/jacoco/icons/jacoco-48x48.png">
<b>Jacoco - ${%Overall Coverage Summary}</b>
<table class="pane" border="1" style="width: 95%;margin-left: 5%;">
<j:forEach var="coverageRatio" items="${it.coverageRatios}">
<tr>
<th style="background-color:#e0e0e0;width:30%">${coverageRatio.key.type}</th>
<td style="width:15%;text-align:center" class="${coverageRatio.value ? 'red':''}">${coverageRatio.key.percentage}%</td>
<td><div class="percentgraph"><div style="width:${100 - coverageRatio.key.percentage}%" class="redbar"></div></div></td>
</tr>
</j:forEach>
</table>
</t:summary>
</j:jelly>
Binary file added src/main/webapp/icons/jacoco-48x48.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5ecbb3d

Please sign in to comment.