Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 8ba32de
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -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>
Expand Down
33 changes: 25 additions & 8 deletions src/main/java/hudson/plugins/nested_view/NestedView.java
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit 8ba32de

Please sign in to comment.