From cb79384dd405693bfb8caa72739533cbd095b9bd Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Mon, 23 Jan 2023 15:20:49 -0500 Subject: [PATCH 1/2] Introduce `SubTask.getOwnerExecutable` --- core/src/main/java/hudson/model/Queue.java | 8 ++++-- .../main/java/hudson/model/queue/SubTask.java | 28 +++++++++++++------ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/hudson/model/Queue.java b/core/src/main/java/hudson/model/Queue.java index 3914fd0d12f7..7a4c7c7a93dd 100644 --- a/core/src/main/java/hudson/model/Queue.java +++ b/core/src/main/java/hudson/model/Queue.java @@ -2077,10 +2077,14 @@ public interface Executable extends Runnable { /** * An umbrella executable (such as a {@link Run}) of which this is one part. - * If {@link #getParent} has a distinct {@link SubTask#getOwnerTask}, - * then it should be the case that {@code getParentExecutable().getParent() == getParent().getOwnerTask()}. + * Some invariants: + * * @return a distinct executable (never {@code this}, unlike the default of {@link SubTask#getOwnerTask}!); or null if this executable was already at top level * @since 2.313, but implementations can already implement this with a lower core dependency. + * @see SubTask#getOwnerExecutable */ default @CheckForNull Executable getParentExecutable() { return null; diff --git a/core/src/main/java/hudson/model/queue/SubTask.java b/core/src/main/java/hudson/model/queue/SubTask.java index 98c9e0bacbaf..5109b969cb6c 100644 --- a/core/src/main/java/hudson/model/queue/SubTask.java +++ b/core/src/main/java/hudson/model/queue/SubTask.java @@ -30,8 +30,7 @@ import hudson.model.Executor; import hudson.model.Label; import hudson.model.Node; -import hudson.model.Queue.Executable; -import hudson.model.Queue.Task; +import hudson.model.Queue; import hudson.model.ResourceActivity; import java.io.IOException; @@ -79,19 +78,30 @@ default long getEstimatedDuration() { } /** - * Creates {@link Executable}, which performs the actual execution of the task. - * @return {@link Executable} to be launched or null if the executable cannot be + * Creates an object which performs the actual execution of the task. + * @return executable to be launched or null if the executable cannot be * created (e.g. {@link AbstractProject} is disabled) - * @exception IOException {@link Executable} cannot be created + * @exception IOException executable cannot be created */ - @CheckForNull Executable createExecutable() throws IOException; + @CheckForNull Queue.Executable createExecutable() throws IOException; /** - * Gets the {@link Task} that this subtask belongs to. + * Gets the task that this subtask belongs to. * @return by default, {@code this} + * @see #getOwnerExecutable */ - default @NonNull Task getOwnerTask() { - return (Task) this; + default @NonNull Queue.Task getOwnerTask() { + return (Queue.Task) this; + } + + /** + * If this task is associated with an executable of {@link #getOwnerTask}, finds that. + * @return by default, {@code null} + * @see hudson.model.Queue.Executable#getParentExecutable + * @since TODO + */ + default @CheckForNull Queue.Executable getOwnerExecutable() { + return null; } /** From 343e0f4b22979cac4adbd40e274ada5a520b7cd3 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Mon, 23 Jan 2023 16:15:00 -0500 Subject: [PATCH 2/2] Javadoc --- core/src/main/java/hudson/model/queue/SubTask.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/hudson/model/queue/SubTask.java b/core/src/main/java/hudson/model/queue/SubTask.java index 5109b969cb6c..f6dd5ca834a3 100644 --- a/core/src/main/java/hudson/model/queue/SubTask.java +++ b/core/src/main/java/hudson/model/queue/SubTask.java @@ -35,9 +35,9 @@ import java.io.IOException; /** - * A component of {@link Task} that represents a computation carried out by a single {@link Executor}. + * A component of {@link Queue.Task} that represents a computation carried out by a single {@link Executor}. * - * A {@link Task} consists of a number of {@link SubTask}. + * A {@link Queue.Task} consists of a number of {@link SubTask}. * *

* Plugins are encouraged to extend from {@link AbstractSubTask} @@ -105,7 +105,7 @@ default long getEstimatedDuration() { } /** - * If a subset of {@link SubTask}s of a {@link Task} needs to be collocated with other {@link SubTask}s, + * If a subset of {@link SubTask}s of a {@link Queue.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 * colocation constraint. * @return by default, null