Skip to content
Permalink
Browse files
[FIXED JENKINS-8922] skip disabled projects when calculating worst bu…
…ild result in a view
  • Loading branch information
alanharder committed Jul 28, 2011
1 parent 837bed8 commit 57a8fa192b96e05b737d6c51b4b92701c93dec89
Showing with 28 additions and 2 deletions.
  1. +5 −2 src/main/java/hudson/plugins/nested_view/NestedView.java
  2. +23 −0 src/test/java/hudson/plugins/nested_view/NestedViewTest.java
@@ -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;
@@ -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;
}
}
@@ -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;

/**
@@ -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);

0 comments on commit 57a8fa1

Please sign in to comment.