Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding coverage summary on build status/result page. #61

Merged
merged 1 commit into from Nov 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.