Skip to content

Commit

Permalink
[FIXED JENKINS-8922] skip disabled projects when calculating worst bu…
Browse files Browse the repository at this point in the history
…ild result in a view
  • Loading branch information
alanharder committed Jul 28, 2011
1 parent 837bed8 commit 57a8fa1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/java/hudson/plugins/nested_view/NestedView.java
Expand Up @@ -27,6 +27,7 @@
import hudson.model.Descriptor.FormException;
import hudson.Extension;
import hudson.Util;
import hudson.model.AbstractProject;
import hudson.model.HealthReport;
import hudson.model.Hudson;
import hudson.model.Item;
Expand Down Expand Up @@ -175,9 +176,11 @@ public static Result getWorstResult(View view) {
}
} else {
for (TopLevelItem item : view.getItems()) {
if (item instanceof Job) {
if (item instanceof Job && !( // Skip disabled projects
item instanceof AbstractProject && ((AbstractProject)item).isDisabled())) {
final Run lastCompletedBuild = ((Job)item).getLastCompletedBuild();
if (lastCompletedBuild != null && (check = lastCompletedBuild.getResult()).isWorseThan(result))
if (lastCompletedBuild != null
&& (check = lastCompletedBuild.getResult()).isWorseThan(result))
result = check;
}
}
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/hudson/plugins/nested_view/NestedViewTest.java
Expand Up @@ -26,10 +26,15 @@
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlOption;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import hudson.model.AllView;
import hudson.model.Cause.UserCause;
import hudson.model.FreeStyleProject;
import hudson.model.ListView;
import static hudson.model.Result.*;
import hudson.util.FormValidation;
import static hudson.util.FormValidation.Kind.*;
import java.util.List;
import org.jvnet.hudson.test.FailureBuilder;
import org.jvnet.hudson.test.HudsonTestCase;

/**
Expand Down Expand Up @@ -87,6 +92,24 @@ public void test() throws Exception {
assertNotNull(page.getAnchorByHref("newView"));
}

public void testGetWorstResult() throws Exception {
NestedView view = new NestedView("test");
assertSame(SUCCESS, NestedView.getWorstResult(view)); // Empty
view.addView(new AllView("foo", view));
assertSame(SUCCESS, NestedView.getWorstResult(view)); // Empty
FreeStyleProject p = createFreeStyleProject();
assertSame(SUCCESS, NestedView.getWorstResult(view)); // Job not yet run
assertBuildStatusSuccess(p.scheduleBuild2(0, new UserCause()).get());
assertSame(SUCCESS, NestedView.getWorstResult(view)); // Job ran ok
FreeStyleProject bad = createFreeStyleProject();
bad.getBuildersList().add(new FailureBuilder());
assertSame(SUCCESS, NestedView.getWorstResult(view)); // New job not yet run
assertBuildStatus(FAILURE, bad.scheduleBuild2(0, new UserCause()).get());
assertSame(FAILURE, NestedView.getWorstResult(view)); // Job failed
bad.disable();
assertSame(SUCCESS, NestedView.getWorstResult(view)); // Ignore disabled job
}

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

0 comments on commit 57a8fa1

Please sign in to comment.