Skip to content
Permalink
Browse files

[JENKINS-22575] fix NumberFormatException when numBuilds is not const…

…rained
  • Loading branch information...
olivergondza committed Sep 10, 2014
1 parent 78af008 commit 01d566e9ccc5809fa1b0bc984d50c8835b5ffe8f
Showing with 15 additions and 7 deletions.
  1. +9 −1 src/main/java/hudson/plugins/plot/Plot.java
  2. +6 −6 src/test/java/hudson/plugins/plot/PlotTest.java
@@ -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;
}
@@ -44,7 +44,7 @@
public void discardPlotSamplesForOldBuilds() throws Exception {
FreeStyleProject p = jobArchivingBuilds(1);

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

j.buildAndAssertSuccess(p);
assertSampleCount(p, 1);
@@ -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);
@@ -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);
@@ -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);
@@ -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));

0 comments on commit 01d566e

Please sign in to comment.
You can’t perform that action at this time.