From 0cee4ef199cd33b3e07b67cd998cd4786087232c Mon Sep 17 00:00:00 2001 From: kohsuke Date: Thu, 9 Sep 2010 22:26:49 +0000 Subject: [PATCH] SubTask -> Task traversal and additional bug fix git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@34613 71c3de6d-444a-0410-be80-ed276b4c234a --- core/src/main/java/hudson/model/AbstractProject.java | 5 +++++ core/src/main/java/hudson/model/Executor.java | 4 ++-- .../main/java/hudson/model/queue/AbstractQueueTask.java | 5 +++++ .../src/main/java/hudson/model/queue/QueueTaskFilter.java | 8 ++++++++ core/src/main/java/hudson/model/queue/SubTask.java | 5 +++++ 5 files changed, 25 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/hudson/model/AbstractProject.java b/core/src/main/java/hudson/model/AbstractProject.java index 69e51f19cc..11ec84d6ed 100644 --- a/core/src/main/java/hudson/model/AbstractProject.java +++ b/core/src/main/java/hudson/model/AbstractProject.java @@ -41,6 +41,7 @@ import hudson.model.Cause.UserCause; import hudson.model.Descriptor.FormException; import hudson.model.Fingerprint.RangeSet; import hudson.model.Queue.Executable; +import hudson.model.Queue.Task; import hudson.model.queue.SubTask; import hudson.model.Queue.WaitingItem; import hudson.model.RunMap.Constructor; @@ -920,6 +921,10 @@ 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 } + public final Task getOwnerTask() { + return this; + } + /** * {@inheritDoc} * diff --git a/core/src/main/java/hudson/model/Executor.java b/core/src/main/java/hudson/model/Executor.java index a00856bf60..e3abf437fe 100644 --- a/core/src/main/java/hudson/model/Executor.java +++ b/core/src/main/java/hudson/model/Executor.java @@ -344,7 +344,7 @@ public class Executor extends Thread implements ModelObject { public void doStop( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException { Queue.Executable e = executable; if(e!=null) { - e.getParent().checkAbortPermission(); + e.getParent().getOwnerTask().checkAbortPermission(); interrupt(); } rsp.forwardToPreviousPage(req); @@ -355,7 +355,7 @@ public class Executor extends Thread implements ModelObject { */ public boolean hasStopPermission() { Queue.Executable e = executable; - return e!=null && e.getParent().hasAbortPermission(); + return e!=null && e.getParent().getOwnerTask().hasAbortPermission(); } public Computer getOwner() { diff --git a/core/src/main/java/hudson/model/queue/AbstractQueueTask.java b/core/src/main/java/hudson/model/queue/AbstractQueueTask.java index ddb3c53d43..3bdb1ffaa7 100644 --- a/core/src/main/java/hudson/model/queue/AbstractQueueTask.java +++ b/core/src/main/java/hudson/model/queue/AbstractQueueTask.java @@ -25,6 +25,7 @@ package hudson.model.queue; import hudson.model.Queue; +import hudson.model.Queue.Task; import java.util.Collection; import java.util.Collections; @@ -40,4 +41,8 @@ public abstract class AbstractQueueTask implements Queue.Task { public Collection getSubTasks() { return Collections.emptyList(); } + + public final Task getOwnerTask() { + return this; + } } diff --git a/core/src/main/java/hudson/model/queue/QueueTaskFilter.java b/core/src/main/java/hudson/model/queue/QueueTaskFilter.java index 640dc48be8..b8b6e240c8 100644 --- a/core/src/main/java/hudson/model/queue/QueueTaskFilter.java +++ b/core/src/main/java/hudson/model/queue/QueueTaskFilter.java @@ -110,4 +110,12 @@ public abstract class QueueTaskFilter implements Queue.Task { public Collection getSubTasks() { return base.getSubTasks(); } + + public final Task getOwnerTask() { + return this; + } + + public Object getSameNodeConstraint() { + return base.getSameNodeConstraint(); + } } diff --git a/core/src/main/java/hudson/model/queue/SubTask.java b/core/src/main/java/hudson/model/queue/SubTask.java index 99d4be5829..c7000426ec 100644 --- a/core/src/main/java/hudson/model/queue/SubTask.java +++ b/core/src/main/java/hudson/model/queue/SubTask.java @@ -72,6 +72,11 @@ public interface SubTask extends ResourceActivity { */ Executable createExecutable() throws IOException; + /** + * Gets the {@link Task} that this subtask belongs to. + */ + Task getOwnerTask(); + /** * If a subset of {@link SubTask}s of a {@link Task} needs to be collocated with other {@link SubTask}s, * those {@link SubTask}s should return the equal object here. If null, the execution unit isn't under a