diff --git a/core/src/main/java/hudson/model/CauseAction.java b/core/src/main/java/hudson/model/CauseAction.java index 356d7d7ee6..2835aa1d9e 100644 --- a/core/src/main/java/hudson/model/CauseAction.java +++ b/core/src/main/java/hudson/model/CauseAction.java @@ -24,13 +24,13 @@ package hudson.model; import hudson.model.Queue.Task; +import hudson.model.queue.FoldableAction; +import org.kohsuke.stapler.export.Exported; +import org.kohsuke.stapler.export.ExportedBean; import java.util.ArrayList; import java.util.List; -import org.kohsuke.stapler.export.Exported; -import org.kohsuke.stapler.export.ExportedBean; - @ExportedBean public class CauseAction implements FoldableAction { /** @@ -77,15 +77,14 @@ public class CauseAction implements FoldableAction { return causes.get(0).getShortDescription(); } - public void foldIntoExisting(Task t, List actions) { - for(Action action : actions) { - if(action instanceof CauseAction) { - this.causes.addAll(((CauseAction)action).causes); - return; - } + public void foldIntoExisting(hudson.model.Queue.Item item, Task owner, List otherActions) { + CauseAction existing = item.getAction(CauseAction.class); + if (existing!=null) { + existing.causes.addAll(this.causes); + return; } // no CauseAction found, so add a copy of this one - actions.add(new CauseAction(this)); + item.getActions().add(new CauseAction(this)); } private Object readResolve() { diff --git a/core/src/main/java/hudson/model/Queue.java b/core/src/main/java/hudson/model/Queue.java index e03e77abc9..b784edc961 100644 --- a/core/src/main/java/hudson/model/Queue.java +++ b/core/src/main/java/hudson/model/Queue.java @@ -380,7 +380,7 @@ public class Queue extends ResourceController implements Saveable { return scheduleInternal(p, quietPeriod, actions); } - + /** * Schedules an execution of a task. * @@ -426,7 +426,7 @@ public class Queue extends ResourceController implements Saveable { // but let the actions affect the existing stuff. for(Item item : duplicatesInQueue) { for(FoldableAction a : Util.filter(actions,FoldableAction.class)) { - a.foldIntoExisting(item.task, item.getActions()); + a.foldIntoExisting(item, p, actions); } } @@ -1207,6 +1207,8 @@ public class Queue extends ResourceController implements Saveable { /** * An optional interface for actions on Queue.Item. * Lets the action cooperate in queue management. + * + * @since 1.300-ish. */ public interface QueueAction extends Action { /** diff --git a/core/src/main/java/hudson/model/FoldableAction.java b/core/src/main/java/hudson/model/queue/FoldableAction.java similarity index 56% rename from core/src/main/java/hudson/model/FoldableAction.java rename to core/src/main/java/hudson/model/queue/FoldableAction.java index 6e822fab97..f8f6e7bc08 100644 --- a/core/src/main/java/hudson/model/FoldableAction.java +++ b/core/src/main/java/hudson/model/queue/FoldableAction.java @@ -21,18 +21,39 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package hudson.model; +package hudson.model.queue; import hudson.model.Queue.Task; +import hudson.model.Action; +import hudson.model.Queue; import java.util.List; /** - * @author mdonohue * An action interface that allows action data to be folded together. - * This is useful for combining any distinct values from a build determined to - * be a duplicate of a build already in the build queue. + * + *

+ * {@link Action} can implement this optional marker interface to be notified when + * the {@link Task} that it's added to the queue with is determined to be "already in the queue". + * + *

+ * This is useful for passing on parameters to the task that's already in the queue. + * + * @author mdonohue + * @since 1.300-ish. */ public interface FoldableAction extends Action { - public void foldIntoExisting(Task t, List actions); + /** + * Notifies that the {@link Task} that "owns" this action (that is, the task for which this action is submitted) + * is considered as a duplicate. + * + * @param item + * The existing {@link Queue.Item} in the queue against which we are judged as a duplicate. Never null. + * @param owner + * The {@link Task} with which this action was submitted to the queue. Never null. + * @param otherActions + * Other {@link Action}s that are submitted with the task. (One of them is this {@link FoldableAction}.) + * Never null. + */ + void foldIntoExisting(Queue.Item item, Task owner, List otherActions); }