Skip to content

Commit

Permalink
JENKINS-16790: Add link from coverage column to coverage report for l…
Browse files Browse the repository at this point in the history
…ast completed build
  • Loading branch information
centic9 committed Nov 4, 2013
1 parent b910d88 commit f8a4f6d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
Expand Up @@ -26,13 +26,22 @@ public class JaCoCoColumn extends ListViewColumn {
public JaCoCoColumn() {
}

public boolean hasCoverage(final Job<?, ?> job) {
final Run<?, ?> lastSuccessfulBuild = job.getLastSuccessfulBuild();
if (lastSuccessfulBuild == null) {
return false;
} else if (lastSuccessfulBuild.getAction(JacocoBuildAction.class) == null){
return false;
}

return true;
}

public String getPercent(final Job<?, ?> job) {
final Run<?, ?> lastSuccessfulBuild = job.getLastSuccessfulBuild();
final StringBuilder stringBuilder = new StringBuilder();

if (lastSuccessfulBuild == null) {
stringBuilder.append("N/A");
} else if (lastSuccessfulBuild.getAction(JacocoBuildAction.class) == null){
if (!hasCoverage(job)) {
stringBuilder.append("N/A");
} else {
final Double percent = getLinePercent(lastSuccessfulBuild);
Expand Down
Expand Up @@ -13,7 +13,18 @@

<j:choose>
<j:when test="${coverageAmount != null}">
<td style="color:#${color}; background-color:#${backgroundColor};" data="${coverageAmount}" align="center">${coveragePercent}%</td>
<td style="color:#${color}; background-color:#${backgroundColor};" data="${coverageAmount}" align="center">
<j:choose>
<j:when test="${it.hasCoverage(job)}">
<a href="${job.url}lastCompletedBuild/jacoco/">
${coveragePercent}%
</a>
</j:when>
<j:otherwise>
N/A
</j:otherwise>
</j:choose>
</td>
</j:when>
<j:otherwise>
<td data="-" align="center"></td>
Expand Down
Expand Up @@ -46,9 +46,10 @@ public void testGetPercentWithNoLastSuccessfulBuild() {
protected void reload() {
}
};
assertFalse(jacocoColumn.hasCoverage(mockJob));
assertEquals("N/A", jacocoColumn.getPercent(mockJob));
assertEquals(new BigDecimal("0.0"), jacocoColumn.getLineCoverage(mockJob));

EasyMock.verify(context);
}

Expand All @@ -59,6 +60,7 @@ public void testGetPercentWithLastSuccessfulBuild() {
EasyMock.replay(context);

final Job<?, ?> mockJob = new ExternalJobExtension("externaljob");
assertFalse(jacocoColumn.hasCoverage(mockJob));
assertEquals("N/A", jacocoColumn.getPercent(mockJob));
assertEquals(new BigDecimal("0.0"), jacocoColumn.getLineCoverage(mockJob));

Expand Down Expand Up @@ -129,6 +131,7 @@ public void finished(Result result) {
protected synchronized void saveNextBuildNumber() throws IOException {
}
};
assertTrue(jacocoColumn.hasCoverage(mockJob));
assertEquals("0.0", jacocoColumn.getPercent(mockJob));
assertEquals(new BigDecimal("0.0"), jacocoColumn.getLineCoverage(mockJob));

Expand Down

0 comments on commit f8a4f6d

Please sign in to comment.