Skip to content

Commit

Permalink
JENKINS-16580: ignore empty coverage value
Browse files Browse the repository at this point in the history
  • Loading branch information
mheinzerling committed May 30, 2016
1 parent af467da commit 0b8c9e3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
Binary file added resources/test/skipzero.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions src/main/java/hudson/plugins/jacoco/model/CoverageGraphLayout.java
Expand Up @@ -157,6 +157,12 @@ public Number getValue(Coverage c)
static class Axis
{
private String label = null;
private boolean skipZero = false;

public boolean isSkipZero()
{
return skipZero;
}

public String getLabel()
{
Expand Down Expand Up @@ -226,6 +232,13 @@ public CoverageGraphLayout label(String label)
return this;
}

public CoverageGraphLayout skipZero()
{
assureAxis();
axes.peek().skipZero = true;
return this;
}

public CoverageGraphLayout plot()
{
assureAxis();
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/hudson/plugins/jacoco/model/CoverageObject.java
Expand Up @@ -395,13 +395,23 @@ protected Map<Axis, DataSetBuilder<String, NumberOnlyBuildLabel>> createDataSetB
builders.put(axis, new DataSetBuilder<String, NumberOnlyBuildLabel>());
}

Map<Plot, Number> last = new HashMap<Plot, Number>();
for (CoverageObject<SELF> a = obj; a != null; a = a.getPreviousResult())
{
NumberOnlyBuildLabel label = new NumberOnlyBuildLabel(a.getBuild());
for (Plot plot : layout.getPlots())
{
Number value = plot.getValue(a);
Axis axis = plot.getAxis();
if (axis.isSkipZero() && (value == null || value.floatValue() == 0f)) value = null;
if (value != null)
{
last.put(plot, value);
}
else
{
value = last.get(plot);
}
builders.get(axis).add(value, plot.getMessage(), label);
}
}
Expand Down
Expand Up @@ -105,6 +105,17 @@ public void multipleAccessAndDifferentCoverageType() throws IOException
assertGraph(chart, "multiple.png");
}

@Test
public void skipZero() throws IOException
{
CoverageGraphLayout layout = new CoverageGraphLayout()
.skipZero()
.plot().type(CoverageType.BRANCH).value(CoverageValue.PERCENTAGE).color(Color.RED);

JFreeChart chart = createTestCoverage().createGraph(new GregorianCalendar(), WIDTH, HEIGHT, layout).getGraph();
assertGraph(chart, "skipzero.png");
}

private TestCoverageObject createTestCoverage()
{
TestCoverageObject t5 = new TestCoverageObject().branch(6, 30).line(5000, 19000);
Expand Down

0 comments on commit 0b8c9e3

Please sign in to comment.