Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 8 additions & 18 deletions core/src/main/java/hudson/model/AbstractProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -1015,24 +1015,6 @@ public Object getSameNodeConstraint() {
return this; // in this way, any member that wants to run with the main guy can nominate the project itself
}

/**
* {@inheritDoc}
*
* <p>
* 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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now no-op overrides.

public boolean isBuildBlocked() {
return getCauseOfBlockage()!=null;
}

public String getWhyBlocked() {
CauseOfBlockage cb = getCauseOfBlockage();
return cb!=null ? cb.getShortDescription() : null;
}

/**
* @deprecated use {@link BlockedBecauseOfBuildInProgress} instead.
*/
Expand Down Expand Up @@ -1075,6 +1057,14 @@ public String getShortDescription() {
}
}

/**
* {@inheritDoc}
*
* <p>
* 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
Expand Down
17 changes: 9 additions & 8 deletions core/src/main/java/hudson/model/Queue.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The 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?

Copy link
Member

Choose a reason for hiding this comment

The 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() {
Copy link
Member Author

Choose a reason for hiding this comment

The 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,
Expand All @@ -1841,9 +1845,6 @@ public interface Task extends ModelObject, SubTask {
*/
@CheckForNull
default CauseOfBlockage getCauseOfBlockage() {
if (isBuildBlocked()) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix.

return CauseOfBlockage.fromMessage(Messages._Queue_Unknown());
}
return null;
}

Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/hudson/model/queue/QueueTaskFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ public Node getLastBuiltOn() {
return base.getLastBuiltOn();
}

@Deprecated
public boolean isBuildBlocked() {
return base.isBuildBlocked();
}

@Deprecated
public String getWhyBlocked() {
return base.getWhyBlocked();
}
Expand Down
83 changes: 83 additions & 0 deletions core/src/test/java/hudson/model/queue/AbstractQueueTaskTest.java
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());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With Queue.java reverted to master version, reproduces the StackOverflowError.

assertNull(t.getWhyBlocked());
assertNull(t.getCauseOfBlockage());
}
static class LegacyTask extends AbstractQueueTask {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same essential structure as current org.jenkinsci.plugins.workflow.job.AfterRestartTask.

@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();
}
}

}
17 changes: 1 addition & 16 deletions test/src/test/java/hudson/model/QueueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,7 @@ static class TestTask implements Queue.Task {
@Override public int hashCode() {
return cnt.hashCode();
}
@Override public boolean isBuildBlocked() {return isBlocked;}
Copy link
Member Author

Choose a reason for hiding this comment

The 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 getCauseOfBlockage to provide a message to the user. (It was abstract prior to #2879 in 2.62 so it is unlikely that new code was written against 2.62–2.85 that assumed that only implementing isBuildBlocked was OK.)

@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() {}
Expand Down Expand Up @@ -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());
Copy link
Member Author

Choose a reason for hiding this comment

The 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();
Expand Down