Skip to content

Commit

Permalink
JENKINS-22412 Update values in portlet to show N/A instead of 0 when …
Browse files Browse the repository at this point in the history
…no data is present.
  • Loading branch information
Tamini committed Mar 28, 2014
1 parent d7e0f5c commit aa6deca
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
22 changes: 14 additions & 8 deletions src/main/java/hudson/plugins/cobertura/targets/CoverageResult.java
Expand Up @@ -329,16 +329,22 @@ public CoverageResult getChild(String name) {
}

public Ratio getCoverage(CoverageMetric metric) {
// CoverageMetric myMetric = CoverageMetric.METHOD;
// if (metric.getName().equals(myMetric.getName()))
// {
// aggregateResults.put(metric, Ratio.create(1, 1));
// }
//
// fixEmptyMetric(metric);

return aggregateResults.get(metric);
}

public Ratio getCoverageWithEmpty(CoverageMetric metric) {
if (aggregateResults.containsKey(metric))
return aggregateResults.get(metric);
Map<CoverageMetric, Ratio> currMetricSet = new EnumMap<CoverageMetric, Ratio>(CoverageMetric.class);
currMetricSet.putAll(aggregateResults);
if (!currMetricSet.containsKey(metric))
{
return null;
}
return currMetricSet.get(metric);
}

/**
* Getter for property 'metrics'.
*
Expand Down Expand Up @@ -371,7 +377,7 @@ private List<CoverageMetric> findEmptyMetrics(Map<CoverageMetric, Ratio> currMet
private void fixEmptyMetrics(List<CoverageMetric> missingMetrics, Map<CoverageMetric, Ratio> currMetricSet) {
for (CoverageMetric missing : missingMetrics)
{
currMetricSet.put(missing, Ratio.create(0, 1));
currMetricSet.put(missing, Ratio.create(1, 1));
}
}

Expand Down
Expand Up @@ -54,7 +54,14 @@ THE SOFTWARE.
</j:when>
<j:otherwise>
<j:forEach var="metric" items="${metrics}">
<td class="pane" style="text-align: right;" data="${result.getCoverage(metric)}"> ${result.getCoverage(metric).percentage}%</td>
<j:choose>
<j:when test="${empty(result.getCoverageWithEmpty(metric).percentage)}">
<td class="pane" style="text-align: right;" data="${result.getCoverageWithEmpty(metric)}">${%N/A}</td>
</j:when>
<j:otherwise>
<td class="pane" style="text-align: right;" data="${result.getCoverageWithEmpty(metric)}"> ${result.getCoverageWithEmpty(metric).percentage}%</td>
</j:otherwise>
</j:choose>
</j:forEach>
</j:otherwise>
</j:choose>
Expand All @@ -63,7 +70,7 @@ THE SOFTWARE.
<tr class="sortbottom">
<j:set var="result" value="${it.getCoverageResult(coverageRuns[0])}"/>
<j:set var="metrics" value="${result.metricsWithEmpty}"/>
<td class="pane-header"><b>${%Total}:</b></td>
<td class="pane-header"><b>${%Total}:222222</b></td>
<j:forEach var="metric" items="${metrics}">
<td class="pane-header" style="text-align: right;"> ${it.getTotalCoverageRatio().get(metric).percentage}%</td>
</j:forEach>
Expand Down

0 comments on commit aa6deca

Please sign in to comment.