Skip to content

Commit

Permalink
[JENKINS-22575] fix NumberFormatException when numBuilds is not const…
Browse files Browse the repository at this point in the history
…rained
  • Loading branch information
olivergondza committed Sep 10, 2014
1 parent 78af008 commit 01d566e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
10 changes: 9 additions & 1 deletion src/main/java/hudson/plugins/plot/Plot.java
Expand Up @@ -773,7 +773,15 @@ private void savePlotData() {
* @return true if the build should be part of the graph.
*/
/*package*/ boolean reportBuild(int buildNumber) {
int numBuilds = Integer.parseInt(this.numBuilds);
int numBuilds;
try {

numBuilds = Integer.parseInt(this.numBuilds);
} catch (NumberFormatException ex) {
// Report all builds
numBuilds = Integer.MAX_VALUE;
}

if (buildNumber < project.getNextBuildNumber() - numBuilds) return false;
return keepRecords || project.getBuildByNumber(buildNumber) != null;
}
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/hudson/plugins/plot/PlotTest.java
Expand Up @@ -44,7 +44,7 @@ public class PlotTest {
public void discardPlotSamplesForOldBuilds() throws Exception {
FreeStyleProject p = jobArchivingBuilds(1);

plotBuilds(p, 2, false);
plotBuilds(p, "2", false);

j.buildAndAssertSuccess(p);
assertSampleCount(p, 1);
Expand All @@ -60,7 +60,7 @@ public void discardPlotSamplesForOldBuilds() throws Exception {
public void discardPlotSamplesForDeletedBuilds() throws Exception {
FreeStyleProject p = jobArchivingBuilds(10);

plotBuilds(p, 10, false);
plotBuilds(p, "", false);

j.buildAndAssertSuccess(p);
assertSampleCount(p, 1);
Expand All @@ -79,7 +79,7 @@ public void discardPlotSamplesForDeletedBuilds() throws Exception {
public void keepPlotSamplesForOldBuilds() throws Exception {
FreeStyleProject p = jobArchivingBuilds(1);

plotBuilds(p, 2, true);
plotBuilds(p, "2", true);

j.buildAndAssertSuccess(p);
assertSampleCount(p, 1);
Expand All @@ -98,7 +98,7 @@ public void keepPlotSamplesForOldBuilds() throws Exception {
public void keepPlotSamplesForDeletedBuilds() throws Exception {
FreeStyleProject p = jobArchivingBuilds(10);

plotBuilds(p, 10, true);
plotBuilds(p, "", true);

j.buildAndAssertSuccess(p);
assertSampleCount(p, 1);
Expand All @@ -121,9 +121,9 @@ private FreeStyleProject jobArchivingBuilds(int count) throws Exception {
return p;
}

private void plotBuilds(FreeStyleProject p, int count, boolean keepRecords) {
private void plotBuilds(FreeStyleProject p, String count, boolean keepRecords) {
final PlotPublisher publisher = new PlotPublisher();
final Plot plot = new Plot("Title", "Number", "default", String.valueOf(count), null, "line", false, keepRecords);
final Plot plot = new Plot("Title", "Number", "default", count, null, "line", false, keepRecords);
p.getPublishersList().add(publisher);
publisher.addPlot(plot);
plot.series = Arrays.<Series>asList(new PropertiesSeries("src.properties", null));
Expand Down

0 comments on commit 01d566e

Please sign in to comment.