Skip to content

Commit

Permalink
Merge pull request #19 from vdupain/master
Browse files Browse the repository at this point in the history
JENKINS-18880 Build statistics does not display
  • Loading branch information
mambu committed Jul 23, 2013
2 parents 1d693fc + 25ef4f2 commit 93b1982
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
33 changes: 16 additions & 17 deletions src/main/java/hudson/plugins/view/dashboard/stats/StatBuilds.java
Expand Up @@ -34,7 +34,6 @@ public StatBuilds(String name) {
}

public Map<BallColor, Integer> getBuildStat(List<TopLevelItem> jobs) {
int nBuilds = 0;
SortedMap<BallColor, Integer> colStatBuilds = new TreeMap<BallColor, Integer>();
for (BallColor color : BallColor.values()) {
colStatBuilds.put(color.noAnime(), 0);
Expand All @@ -45,22 +44,22 @@ public Map<BallColor, Integer> getBuildStat(List<TopLevelItem> jobs) {
// Build statistics
// With a 1.507+ dep and a fix of JENKINS-18065 could use simply: job.getBuilds().limit(MAX_BUILDS)
SortedMap<Integer,Run> buildMap = ((Job) job).getBuildsAsMap();
Collection<Run> builds = buildMap.headMap(buildMap.firstKey() - MAX_BUILDS).values();
if (builds.isEmpty()) {
colStatBuilds.put(BallColor.GREY.noAnime(), colStatBuilds
.get(BallColor.GREY) + 1);
nBuilds++;
} else {
//loop over builds
for (Run build : builds) {
BallColor bColor = build.getIconColor();
if(bColor != null && bColor.noAnime() != null && colStatBuilds.get(bColor) != null){
colStatBuilds.put(bColor.noAnime(), colStatBuilds
.get(bColor) + 1);
nBuilds++;
}
}
}
if (!buildMap.isEmpty()) {
Collection<Run> builds = buildMap.headMap(buildMap.firstKey() - MAX_BUILDS).values();
if (builds.isEmpty()) {
colStatBuilds.put(BallColor.GREY.noAnime(), colStatBuilds
.get(BallColor.GREY) + 1);
} else {
//loop over builds
for (Run build : builds) {
BallColor bColor = build.getIconColor();
if(bColor != null && bColor.noAnime() != null && colStatBuilds.get(bColor) != null){
colStatBuilds.put(bColor.noAnime(), colStatBuilds
.get(bColor) + 1);
}
}
}
}
}
}
return colStatBuilds;
Expand Down
Expand Up @@ -5,9 +5,11 @@
import hudson.model.TopLevelItem;
import hudson.plugins.view.dashboard.RunLoadCounter;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.Callable;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;

import org.junit.Rule;
import org.jvnet.hudson.test.JenkinsRule;

Expand All @@ -29,4 +31,14 @@ public Integer call() throws Exception {
}).intValue());
}

@Test public void testGettingBuildStatsWithZeroBuild() throws Exception {
final FreeStyleProject project = j.createFreeStyleProject();
RunLoadCounter.prepare(project);
final StatBuilds stats = new StatBuilds("-");
final Map<BallColor,Integer> buildStats = stats.getBuildStat(Collections.<TopLevelItem>singletonList(project));
for (BallColor color : BallColor.values()) {
assertEquals((Integer)0, buildStats.get(color.noAnime()));
}
}

}

0 comments on commit 93b1982

Please sign in to comment.