Skip to content
Permalink
Browse files
Merge pull request #11 from yoichi/JENKINS-17040
[FIXED JENKINS-17040] give weight to completed build results in nested view status
  • Loading branch information
ctapobep committed Oct 29, 2013
2 parents cc853be + 8301be7 commit 8ba32de909430969250edfb51e61a63730c15f39
Showing with 26 additions and 9 deletions.
  1. +1 −1 pom.xml
  2. +25 −8 src/main/java/hudson/plugins/nested_view/NestedView.java
@@ -3,7 +3,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.450</version>
<version>1.526</version>
</parent>
<properties>
<maven-release-plugin.version>2.4</maven-release-plugin.version>
@@ -51,7 +51,7 @@
* @author Romain Seguy
*/
public class NestedView extends View implements ViewGroup, StaplerProxy {
private final static Result WORST_RESULT = Result.ABORTED;
private final static Result WORST_RESULT = Result.FAILURE;

/**
* Nested views.
@@ -282,27 +282,44 @@ public Result getWorstResult() {
return found ? result : null;
}

/**
* Returns the worse result from two.
*/
private static Result getWorse(Result r1, Result r2) {
// completed build wins
if (!r1.isCompleteBuild() && r2.isCompleteBuild()) {
return r2;
}
if (r1.isCompleteBuild() && !r2.isCompleteBuild()) {
return r1;
}

// return worse one
return r1.isWorseThan(r2) ? r1 : r2;
}

/**
* Returns the worst result for a normal view, by browsing all the jobs it
* contains; As soon as {@link #WORST_RESULT} is found, the browsing stops.
* Returns null if no build occurred yet
*/
private static Result getWorstResultForNormalView(View v) {
boolean found = false;
Result result = Result.SUCCESS, check;
Result result = Result.NOT_BUILT, check;
for (TopLevelItem item : v.getItems()) {
if (item instanceof Job && !( // Skip disabled projects
item instanceof AbstractProject && ((AbstractProject) item).isDisabled())) {
final Run lastCompletedBuild = ((Job) item).getLastCompletedBuild();
if (lastCompletedBuild != null) {
found = true;
if ((check = lastCompletedBuild.getResult()).isWorseThan(result)) {
result = check;
if (result.isWorseOrEqualTo(WORST_RESULT)) {
// cut the search if we find the worst possible case
return result;
}
check = lastCompletedBuild.getResult();
if (check.isCompleteBuild() == WORST_RESULT.isCompleteBuild() &&
check.isWorseOrEqualTo(WORST_RESULT)) {
// cut the search if we find the worst possible case
return check;
}

result = getWorse(check, result);
}
}
}

0 comments on commit 8ba32de

Please sign in to comment.