From 19714f201809cf1bb4e278e53bc58eafef23d36f Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Thu, 19 Oct 2017 13:06:35 -0400 Subject: [PATCH] Deprecate isBuildBlocked & getWhyBlocked in favor of getCauseOfBlockage, which you needed to implement anyway. --- .../java/hudson/model/AbstractProject.java | 26 ++---- core/src/main/java/hudson/model/Queue.java | 14 ++-- .../hudson/model/queue/QueueTaskFilter.java | 2 + .../model/queue/AbstractQueueTaskTest.java | 83 +++++++++++++++++++ .../src/test/java/hudson/model/QueueTest.java | 3 +- 5 files changed, 103 insertions(+), 25 deletions(-) create mode 100644 core/src/test/java/hudson/model/queue/AbstractQueueTaskTest.java diff --git a/core/src/main/java/hudson/model/AbstractProject.java b/core/src/main/java/hudson/model/AbstractProject.java index 954011f650..ffee6413d8 100644 --- a/core/src/main/java/hudson/model/AbstractProject.java +++ b/core/src/main/java/hudson/model/AbstractProject.java @@ -1015,24 +1015,6 @@ public abstract class AbstractProject

,R extends A return this; // in this way, any member that wants to run with the main guy can nominate the project itself } - /** - * {@inheritDoc} - * - *

- * A project must be blocked if its own previous build is in progress, - * or if the blockBuildWhenUpstreamBuilding option is true and an upstream - * project is building, but derived classes can also check other conditions. - */ - @Override - public boolean isBuildBlocked() { - return getCauseOfBlockage()!=null; - } - - public String getWhyBlocked() { - CauseOfBlockage cb = getCauseOfBlockage(); - return cb!=null ? cb.getShortDescription() : null; - } - /** * @deprecated use {@link BlockedBecauseOfBuildInProgress} instead. */ @@ -1075,6 +1057,14 @@ public abstract class AbstractProject

,R extends A } } + /** + * {@inheritDoc} + * + *

+ * A project must be blocked if its own previous build is in progress, + * or if the blockBuildWhenUpstreamBuilding option is true and an upstream + * project is building, but derived classes can also check other conditions. + */ @Override public CauseOfBlockage getCauseOfBlockage() { // Block builds until they are done with post-production diff --git a/core/src/main/java/hudson/model/Queue.java b/core/src/main/java/hudson/model/Queue.java index 214213c488..ece3da76cf 100644 --- a/core/src/main/java/hudson/model/Queue.java +++ b/core/src/main/java/hudson/model/Queue.java @@ -1814,18 +1814,22 @@ public class Queue extends ResourceController implements Saveable { /** * Returns true if the execution should be blocked * for temporary reasons. - * - *

- * Short-hand for {@code getCauseOfBlockageForItem()!=null}. + * @deprecated Use {@link #getCauseOfBlockage} != null */ - boolean isBuildBlocked(); + @Deprecated + default boolean isBuildBlocked() { + return getCauseOfBlockage() != null; + } /** * @deprecated as of 1.330 * Use {@link CauseOfBlockage#getShortDescription()} instead. */ @Deprecated - String getWhyBlocked(); + default String getWhyBlocked() { + CauseOfBlockage cause = getCauseOfBlockage(); + return cause != null ? cause.getShortDescription() : null; + } /** * If the execution of this task should be blocked for temporary reasons, diff --git a/core/src/main/java/hudson/model/queue/QueueTaskFilter.java b/core/src/main/java/hudson/model/queue/QueueTaskFilter.java index 4688551b8e..9bf4887247 100644 --- a/core/src/main/java/hudson/model/queue/QueueTaskFilter.java +++ b/core/src/main/java/hudson/model/queue/QueueTaskFilter.java @@ -56,10 +56,12 @@ public abstract class QueueTaskFilter implements Queue.Task { return base.getLastBuiltOn(); } + @Deprecated public boolean isBuildBlocked() { return base.isBuildBlocked(); } + @Deprecated public String getWhyBlocked() { return base.getWhyBlocked(); } diff --git a/core/src/test/java/hudson/model/queue/AbstractQueueTaskTest.java b/core/src/test/java/hudson/model/queue/AbstractQueueTaskTest.java new file mode 100644 index 0000000000..9a31d139c3 --- /dev/null +++ b/core/src/test/java/hudson/model/queue/AbstractQueueTaskTest.java @@ -0,0 +1,83 @@ +/* + * The MIT License + * + * Copyright 2017 CloudBees, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package hudson.model.queue; + +import hudson.model.Queue; +import java.io.IOException; +import org.junit.Test; +import static org.junit.Assert.*; +import org.jvnet.hudson.test.Issue; + +@SuppressWarnings("deprecation") +public class AbstractQueueTaskTest { + + @Issue("JENKINS-47517") + @Test + public void causeOfBlockageOverrides() { + Queue.Task t = new LegacyTask(); + assertFalse(t.isBuildBlocked()); + assertNull(t.getWhyBlocked()); + assertNull(t.getCauseOfBlockage()); + } + static class LegacyTask extends AbstractQueueTask { + @Override + public boolean isBuildBlocked() { + return getCauseOfBlockage() != null; + } + @Override + public String getWhyBlocked() { + CauseOfBlockage causeOfBlockage = getCauseOfBlockage(); + return causeOfBlockage != null ? causeOfBlockage.getShortDescription() : null; + } + @Override + public String getName() { + return null; + } + @Override + public String getFullDisplayName() { + return null; + } + @Override + public void checkAbortPermission() { + } + @Override + public boolean hasAbortPermission() { + return false; + } + @Override + public String getUrl() { + return null; + } + @Override + public String getDisplayName() { + return null; + } + @Override + public Queue.Executable createExecutable() throws IOException { + throw new IOException(); + } + } + +} diff --git a/test/src/test/java/hudson/model/QueueTest.java b/test/src/test/java/hudson/model/QueueTest.java index 1518b404ab..ca506b3a95 100644 --- a/test/src/test/java/hudson/model/QueueTest.java +++ b/test/src/test/java/hudson/model/QueueTest.java @@ -547,8 +547,7 @@ public class QueueTest { @Override public int hashCode() { return cnt.hashCode(); } - @Override public boolean isBuildBlocked() {return isBlocked;} - @Override public String getWhyBlocked() {return null;} + @Override public CauseOfBlockage getCauseOfBlockage() {return isBlocked ? CauseOfBlockage.fromMessage(Messages._Queue_Unknown()) : null;} @Override public String getName() {return "test";} @Override public String getFullDisplayName() {return "Test";} @Override public void checkAbortPermission() {}