Skip to content

Commit

Permalink
Merge pull request #12 from yoichi/JENKINS-17040-19716
Browse files Browse the repository at this point in the history
[FIXED JENKINS-17040][FIXED JENKINS-19716] fix status handling for nested NestedView
  • Loading branch information
ctapobep committed Nov 5, 2013
2 parents 7137761 + 59c1fc2 commit 8e1ca88
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/main/java/hudson/plugins/nested_view/NestedView.java
Expand Up @@ -230,7 +230,7 @@ void setOwner(ViewGroup owner) {
* mentionned previously.</p>
*/
public Result getWorstResult() {
Result result = Result.SUCCESS, check;
Result result = Result.NOT_BUILT, check;
boolean found = false;

List<View> normalViews = new ArrayList<View>();
Expand All @@ -251,13 +251,11 @@ public Result getWorstResult() {
check = getWorstResultForNormalView(v);
if (check != null) {
found = true;
if (check.isWorseThan(result)) {
result = check;
if (result.isWorseOrEqualTo(WORST_RESULT)) {
// cut the search if we find the worst possible case
return result;
}
if (isWorst(check)) {
// cut the search if we find the worst possible case
return check;
}
result = getWorse(check, result);
}
}

Expand All @@ -268,21 +266,27 @@ public Result getWorstResult() {
// has the worst result possible, in which case the algorithm ends)
// TODO: derecursify the algorithm to improve performance on complex views
check = v.getWorstResult();
found = true;
if (check != null) {
if (check.isWorseThan(result)) {
result = check;
if (result.isWorseOrEqualTo(WORST_RESULT)) {
// as before, cut the search if we find the worst possible case
return result;
}
found = true;
if (isWorst(check)) {
// as before, cut the search if we find the worst possible case
return check;
}
result = getWorse(check, result);
}
}

return found ? result : null;
}

/**
* Returns true if r is worst.
*/
private static boolean isWorst(Result r) {
return (r.isCompleteBuild() == WORST_RESULT.isCompleteBuild() &&
r.isWorseOrEqualTo(WORST_RESULT));
}

/**
* Returns the worse result from two.
*/
Expand Down Expand Up @@ -314,8 +318,7 @@ private static Result getWorstResultForNormalView(View v) {
if (lastCompletedBuild != null) {
found = true;
check = lastCompletedBuild.getResult();
if (check.isCompleteBuild() == WORST_RESULT.isCompleteBuild() &&
check.isWorseOrEqualTo(WORST_RESULT)) {
if (isWorst(check)) {
// cut the search if we find the worst possible case
return check;
}
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/hudson/plugins/nested_view/NestedViewTest.java
Expand Up @@ -113,6 +113,15 @@ public void testGetWorstResult() throws Exception {
assertSame(SUCCESS, NestedView.getWorstResult(view)); // Ignore disabled job
}

public void testStatusOfEmptyNest() throws Exception {
NestedView parent = new NestedView("parent");
parent.setOwner(hudson);
NestedView child = new NestedView("child");
parent.addView(child);
assertSame(null, NestedView.getWorstResult(child)); // Empty
assertSame(null, NestedView.getWorstResult(parent)); // contains Empty child only
}

public void testDoViewExistsCheck() {
NestedView view = new NestedView("test");
view.setOwner(hudson);
Expand Down

0 comments on commit 8e1ca88

Please sign in to comment.