-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
[JENKINS-47517] Revert the change to the default behavior of Queue.Task.getCauseOfBlockage #3099
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1814,18 +1814,22 @@ public interface Task extends ModelObject, SubTask { | |
| /** | ||
| * Returns true if the execution should be blocked | ||
| * for temporary reasons. | ||
| * | ||
| * <p> | ||
| * Short-hand for {@code getCauseOfBlockageForItem()!=null}. | ||
| * @deprecated Use {@link #getCauseOfBlockage} != null | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As of 2.85 was already not being called by core, so why keep it?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it be also restricted? |
||
| */ | ||
| 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() { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some other methods in this interface could benefit from default implementations but I will leave that to another day. |
||
| CauseOfBlockage cause = getCauseOfBlockage(); | ||
| return cause != null ? cause.getShortDescription() : null; | ||
| } | ||
|
|
||
| /** | ||
| * If the execution of this task should be blocked for temporary reasons, | ||
|
|
@@ -1841,9 +1845,6 @@ public interface Task extends ModelObject, SubTask { | |
| */ | ||
| @CheckForNull | ||
| default CauseOfBlockage getCauseOfBlockage() { | ||
| if (isBuildBlocked()) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fix. |
||
| return CauseOfBlockage.fromMessage(Messages._Queue_Unknown()); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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()); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With |
||
| assertNull(t.getWhyBlocked()); | ||
| assertNull(t.getCauseOfBlockage()); | ||
| } | ||
| static class LegacyTask extends AbstractQueueTask { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same essential structure as current |
||
| @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(); | ||
| } | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -547,8 +547,7 @@ static class TestTask implements Queue.Task { | |
| @Override public int hashCode() { | ||
| return cnt.hashCode(); | ||
| } | ||
| @Override public boolean isBuildBlocked() {return isBlocked;} | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was only a test task. A real one would already have needed to implement |
||
| @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() {} | ||
|
|
@@ -988,20 +987,6 @@ public String getShortDescription() { | |
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testDefaultImplementationOfGetCauseOfBlockageForBlocked() throws Exception { | ||
| Queue queue = r.getInstance().getQueue(); | ||
| queue.schedule2(new TestTask(new AtomicInteger(0), true), 0); | ||
|
|
||
| queue.maintain(); | ||
|
|
||
| assertEquals(1, r.jenkins.getQueue().getBlockedItems().size()); | ||
| CauseOfBlockage actual = r.jenkins.getQueue().getBlockedItems().get(0).getCauseOfBlockage(); | ||
| CauseOfBlockage expected = CauseOfBlockage.fromMessage(Messages._Queue_Unknown()); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Testing something which is no longer wanted. |
||
|
|
||
| assertEquals(expected.getShortDescription(), actual.getShortDescription()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetCauseOfBlockageForNonConcurrentFreestyle() throws Exception { | ||
| Queue queue = r.getInstance().getQueue(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now no-op overrides.