Permalink
Browse files

getting the Build's as generic as possible.

Switching it to Run where applicable. There few places that required it to be AbstractBuild we just do an InstanceOf check.
This should help prevent any future job types from not showing up on the view.
  • Loading branch information...
1 parent 591f11a commit e5daebd3c3b4d63e0e0e09d35d1259d490e5841a @JoelJ committed May 31, 2012
Showing with 20 additions and 15 deletions.
  1. +20 −15 src/main/java/com/attask/jenkins/dashboard/PipelineDashboard.java
View
35 src/main/java/com/attask/jenkins/dashboard/PipelineDashboard.java
@@ -101,7 +101,7 @@ public Table getDisplayRows() {
// LOGGER.info("getDisplayRows starting");
Jenkins jenkins = Jenkins.getInstance();
- Map<String, Build[]> map = findMatchingBuilds(jenkins, jobs, descriptionRegex, descriptionRegexGroup);
+ Map<String, Run[]> map = findMatchingBuilds(jenkins, jobs, descriptionRegex, descriptionRegexGroup);
// LOGGER.info("map size: " + map.size());
Table result = generateRowData(jenkins.getRootUrl(), User.current(), map, this.showBuildName, this.showFailureCount);
@@ -110,18 +110,18 @@ public Table getDisplayRows() {
return result;
}
- protected Map<String, Build[]> findMatchingBuilds(ItemGroup<TopLevelItem> jenkins, List<String> jobs, String descriptionRegex, int descriptionRegexGroup) {
+ protected Map<String, Run[]> findMatchingBuilds(ItemGroup<TopLevelItem> jenkins, List<String> jobs, String descriptionRegex, int descriptionRegexGroup) {
if(jenkins == null || jobs == null || descriptionRegex == null) return Collections.emptyMap();
- Map<String, Build[]> map = new HashMap<String, Build[]>();
+ Map<String, Run[]> map = new HashMap<String, Run[]>();
for (String jobName : jobs) {
try {
Job job = (Job) jenkins.getItem(jobName);
if(job == null) continue;
RunList builds = job.getBuilds();
if(builds == null) continue;
for (Object buildObj : builds) {
- Build build = (Build)buildObj;
+ Run build = (Run)buildObj;
String buildDescription = build.getDescription();
if(buildDescription == null || buildDescription.trim().isEmpty()) {
continue;
@@ -131,7 +131,7 @@ public Table getDisplayRows() {
if(buildDescription.matches(descriptionRegex)) {
String key = buildDescription.replaceFirst(descriptionRegex, "$" + descriptionRegexGroup);
if(!map.containsKey(key)) {
- map.put(key, new Build[jobs.size()]);
+ map.put(key, new Run[jobs.size()]);
}
map.get(key)[jobs.indexOf(jobName)] = build;
}
@@ -146,7 +146,7 @@ public Table getDisplayRows() {
return map;
}
- protected Table generateRowData(String rootUrl, User currentUser, Map<String, Build[]> map, boolean showBuildName, boolean showFailureCount) {
+ protected Table generateRowData(String rootUrl, User currentUser, Map<String, Run[]> map, boolean showBuildName, boolean showFailureCount) {
if(rootUrl == null) rootUrl = "";
if(map == null) return Table.EMPTY_TABLE;
@@ -162,19 +162,22 @@ public int compare(Row row1, Row row2) {
for (String rowName : map.keySet()) {
try {
// LOGGER.info("Row " + rowName);
- Build[] builds = map.get(rowName);
+ Run[] builds = map.get(rowName);
List<Column> columns = new LinkedList<Column>();
Date date = null;
String displayName = rowName;
boolean isCulprit = false;
boolean hasMultiple = false;
- for (Build build : builds) {
+ for (Run build : builds) {
if(build != null) {
// LOGGER.info("\t" + build.getDisplayName() + " " + build.getDescription());
if(date == null) {
date = build.getTime();
- hasMultiple = !build.getChangeSet().isEmptySet() && build.getChangeSet().getItems().length > 1;
+ if(build instanceof AbstractBuild) {
+ AbstractBuild abstractBuild = (AbstractBuild) build;
+ hasMultiple = !abstractBuild.getChangeSet().isEmptySet() && abstractBuild.getChangeSet().getItems().length > 1;
+ }
}
String rowDisplayName = "";
@@ -238,7 +241,7 @@ public int compare(Row row1, Row row2) {
return new Table(result, lastSuccessfulRow);
}
- private boolean getUserIsCommitter(User currentUser, Build build) {
+ private boolean getUserIsCommitter(User currentUser, Run build) {
if(currentUser == null || build == null) return false;
String description = build.getDescription();
@@ -247,11 +250,13 @@ private boolean getUserIsCommitter(User currentUser, Build build) {
}
//noinspection unchecked
- for (Object changeO : build.getChangeSet()) {
- ChangeLogSet.Entry change = (ChangeLogSet.Entry)changeO;
- User culprit = change.getAuthor();
- if((culprit.getId() != null && culprit.getId().equals(currentUser.getId())) || (culprit.getFullName() != null && culprit.getFullName().equals(currentUser.getFullName()))) {
- return true;
+ if(build instanceof AbstractBuild) {
+ for (Object changeObj : ((AbstractBuild)build).getChangeSet()) {
+ ChangeLogSet.Entry change = (ChangeLogSet.Entry)changeObj;
+ User culprit = change.getAuthor();
+ if((culprit.getId() != null && culprit.getId().equals(currentUser.getId())) || (culprit.getFullName() != null && culprit.getFullName().equals(currentUser.getFullName()))) {
+ return true;
+ }
}
}

0 comments on commit e5daebd

Please sign in to comment.