summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zarna2013-08-14 12:29:08 (EDT)
committerSteffen Pingel2013-08-18 17:18:35 (EDT)
commit71d9fcc54ee39ed077bd50971892b59ea7401e1b (patch)
treee21d4cfd45b884437da4d65c35e396feca32d639
parent234dbd986cb3ce52927d3ccbe5db9ff2811a1beb (diff)
downloadorg.eclipse.mylyn.builds-71d9fcc54ee39ed077bd50971892b59ea7401e1b.zip
org.eclipse.mylyn.builds-71d9fcc54ee39ed077bd50971892b59ea7401e1b.tar.gz
org.eclipse.mylyn.builds-71d9fcc54ee39ed077bd50971892b59ea7401e1b.tar.bz2
412294: NullPointerException on disabled builds / new buildsv1.1.1R_3_9_1
Bug: 412294 Change-Id: I8782d4d9707f2d30eec5d41368cbd7d24fc35350 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=412294 Signed-off-by: Tomasz Zarna <tomasz.zarna@tasktop.com>
-rw-r--r--org.eclipse.mylyn.hudson.core/src/org/eclipse/mylyn/internal/hudson/core/HudsonServerBehaviour.java96
-rw-r--r--org.eclipse.mylyn.hudson.tests/src/org/eclipse/mylyn/hudson/tests/core/HudsonServerBehaviourTest.java62
2 files changed, 120 insertions, 38 deletions
diff --git a/org.eclipse.mylyn.hudson.core/src/org/eclipse/mylyn/internal/hudson/core/HudsonServerBehaviour.java b/org.eclipse.mylyn.hudson.core/src/org/eclipse/mylyn/internal/hudson/core/HudsonServerBehaviour.java
index 23c8339..69c8601 100644
--- a/org.eclipse.mylyn.hudson.core/src/org/eclipse/mylyn/internal/hudson/core/HudsonServerBehaviour.java
+++ b/org.eclipse.mylyn.hudson.core/src/org/eclipse/mylyn/internal/hudson/core/HudsonServerBehaviour.java
@@ -841,46 +841,66 @@ public class HudsonServerBehaviour extends BuildServerBehaviour {
}
protected void updateStateAndStatus(HudsonModelJob job, IBuildPlan plan) {
- if (job.getColor().equals(HudsonModelBallColor.BLUE) || job.getColor().equals(HudsonModelBallColor.GREEN)) {
- plan.setStatus(BuildStatus.SUCCESS);
- plan.setState(BuildState.STOPPED);
- } else if (job.getColor().equals(HudsonModelBallColor.BLUE_ANIME)
- || job.getColor().equals(HudsonModelBallColor.GREEN_ANIME)) {
- plan.setStatus(BuildStatus.SUCCESS);
- plan.setState(BuildState.RUNNING);
- } else if (job.getColor().equals(HudsonModelBallColor.RED)) {
- plan.setStatus(BuildStatus.FAILED);
- plan.setState(BuildState.STOPPED);
- } else if (job.getColor().equals(HudsonModelBallColor.RED_ANIME)) {
- plan.setStatus(BuildStatus.FAILED);
- plan.setState(BuildState.RUNNING);
- } else if (job.getColor().equals(HudsonModelBallColor.YELLOW)) {
- plan.setStatus(BuildStatus.UNSTABLE);
- plan.setState(BuildState.STOPPED);
- } else if (job.getColor().equals(HudsonModelBallColor.YELLOW_ANIME)) {
- plan.setStatus(BuildStatus.UNSTABLE);
- plan.setState(BuildState.RUNNING);
- } else if (job.getColor().equals(HudsonModelBallColor.GREY)) {
- plan.setStatus(BuildStatus.DISABLED);
- plan.setState(BuildState.STOPPED);
- } else if (job.getColor().equals(HudsonModelBallColor.GREY_ANIME)) {
- plan.setStatus(BuildStatus.DISABLED);
- plan.setState(BuildState.RUNNING);
- } else if (job.getColor().equals(HudsonModelBallColor.DISABLED)) {
- plan.setStatus(BuildStatus.DISABLED);
- plan.setState(BuildState.STOPPED);
- } else if (job.getColor().equals(HudsonModelBallColor.DISABLED_ANIME)) {
- plan.setStatus(BuildStatus.DISABLED);
- plan.setState(BuildState.RUNNING);
- } else if (job.getColor().equals(HudsonModelBallColor.ABORTED)) {
- plan.setStatus(BuildStatus.ABORTED);
- plan.setState(BuildState.STOPPED);
- } else if (job.getColor().equals(HudsonModelBallColor.ABORTED_ANIME)) {
- plan.setStatus(BuildStatus.ABORTED);
- plan.setState(BuildState.RUNNING);
- } else {
+ HudsonModelBallColor color = job.getColor();
+ if (color == null) {
plan.setStatus(null);
plan.setState(null);
+ } else {
+ switch (color) {
+ case BLUE:
+ case GREEN:
+ plan.setStatus(BuildStatus.SUCCESS);
+ plan.setState(BuildState.STOPPED);
+ break;
+ case BLUE_ANIME:
+ case GREEN_ANIME:
+ plan.setStatus(BuildStatus.SUCCESS);
+ plan.setState(BuildState.RUNNING);
+ break;
+ case RED:
+ plan.setStatus(BuildStatus.FAILED);
+ plan.setState(BuildState.STOPPED);
+ break;
+ case RED_ANIME:
+ plan.setStatus(BuildStatus.FAILED);
+ plan.setState(BuildState.RUNNING);
+ break;
+ case YELLOW:
+ plan.setStatus(BuildStatus.UNSTABLE);
+ plan.setState(BuildState.STOPPED);
+ break;
+ case YELLOW_ANIME:
+ plan.setStatus(BuildStatus.UNSTABLE);
+ plan.setState(BuildState.RUNNING);
+ break;
+ case GREY:
+ plan.setStatus(BuildStatus.DISABLED);
+ plan.setState(BuildState.STOPPED);
+ break;
+ case GREY_ANIME:
+ plan.setStatus(BuildStatus.DISABLED);
+ plan.setState(BuildState.RUNNING);
+ break;
+ case DISABLED:
+ plan.setStatus(BuildStatus.DISABLED);
+ plan.setState(BuildState.STOPPED);
+ break;
+ case DISABLED_ANIME:
+ plan.setStatus(BuildStatus.DISABLED);
+ plan.setState(BuildState.RUNNING);
+ break;
+ case ABORTED:
+ plan.setStatus(BuildStatus.ABORTED);
+ plan.setState(BuildState.STOPPED);
+ break;
+ case ABORTED_ANIME:
+ plan.setStatus(BuildStatus.ABORTED);
+ plan.setState(BuildState.RUNNING);
+ break;
+ default:
+ plan.setStatus(null);
+ plan.setState(null);
+ }
}
EnumSet<BuildState> flags = EnumSet.noneOf(BuildState.class);
diff --git a/org.eclipse.mylyn.hudson.tests/src/org/eclipse/mylyn/hudson/tests/core/HudsonServerBehaviourTest.java b/org.eclipse.mylyn.hudson.tests/src/org/eclipse/mylyn/hudson/tests/core/HudsonServerBehaviourTest.java
index c5e6a78..6f29fd5 100644
--- a/org.eclipse.mylyn.hudson.tests/src/org/eclipse/mylyn/hudson/tests/core/HudsonServerBehaviourTest.java
+++ b/org.eclipse.mylyn.hudson.tests/src/org/eclipse/mylyn/hudson/tests/core/HudsonServerBehaviourTest.java
@@ -11,8 +11,13 @@
package org.eclipse.mylyn.hudson.tests.core;
+import java.util.HashSet;
+import java.util.Set;
+
import junit.framework.TestCase;
+import org.eclipse.mylyn.builds.core.BuildState;
+import org.eclipse.mylyn.builds.core.IBuildPlan;
import org.eclipse.mylyn.commons.repositories.core.RepositoryLocation;
import org.eclipse.mylyn.internal.hudson.core.HudsonServerBehaviour;
import org.eclipse.mylyn.internal.hudson.core.client.HudsonConfigurationCache;
@@ -44,4 +49,61 @@ public class HudsonServerBehaviourTest extends TestCase {
assertEquals(80, behaviour.parseJob(job).getHealth());
}
+ public void testParseJobNoColor() throws Exception {
+ HudsonServerBehaviour behaviour = new HudsonServerBehaviour(new RepositoryLocation(),
+ new HudsonConfigurationCache());
+ HudsonModelJob job = new HudsonModelJob();
+
+ IBuildPlan buildPlan = behaviour.parseJob(job);
+
+ assertNull(buildPlan.getState());
+ assertNull(buildPlan.getStatus());
+ }
+
+ public void testParseJobRunningColor() throws Exception {
+ HudsonServerBehaviour behaviour = new HudsonServerBehaviour(new RepositoryLocation(),
+ new HudsonConfigurationCache());
+ HudsonModelJob job = new HudsonModelJob();
+
+ for (HudsonModelBallColor color : getRunningColors()) {
+ job.setColor(color);
+ IBuildPlan buildPlan = behaviour.parseJob(job);
+
+ assertEquals(BuildState.RUNNING, buildPlan.getState());
+ }
+ }
+
+ public void testParseJobStoppedColor() throws Exception {
+ HudsonServerBehaviour behaviour = new HudsonServerBehaviour(new RepositoryLocation(),
+ new HudsonConfigurationCache());
+ HudsonModelJob job = new HudsonModelJob();
+
+ for (HudsonModelBallColor color : getStoppedColors()) {
+ job.setColor(color);
+ IBuildPlan buildPlan = behaviour.parseJob(job);
+
+ assertEquals(BuildState.STOPPED, buildPlan.getState());
+ }
+ }
+
+ private Set<HudsonModelBallColor> getRunningColors() {
+ Set<HudsonModelBallColor> result = new HashSet<HudsonModelBallColor>();
+ for (HudsonModelBallColor color : HudsonModelBallColor.values()) {
+ if (color.value().endsWith("_anime")) {
+ result.add(color);
+ }
+ }
+ return result;
+ }
+
+ private Set<HudsonModelBallColor> getStoppedColors() {
+ Set<HudsonModelBallColor> result = new HashSet<HudsonModelBallColor>();
+ for (HudsonModelBallColor color : HudsonModelBallColor.values()) {
+ if (!color.value().endsWith("_anime")) {
+ result.add(color);
+ }
+ }
+ return result;
+ }
+
}