-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
TaskExecutionGraph.java
170 lines (154 loc) · 6.65 KB
/
TaskExecutionGraph.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
* Copyright 2007-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.api.execution;
import groovy.lang.Closure;
import org.gradle.api.Action;
import org.gradle.api.Task;
import java.util.List;
import java.util.Set;
/**
* <p>A <code>TaskExecutionGraph</code> is responsible for managing the execution of the {@link Task} instances which
* are part of the build. The <code>TaskExecutionGraph</code> maintains an execution plan of tasks to be executed (or
* which have been executed), and you can query this plan from your build file.</p>
*
* <p>You can access the {@code TaskExecutionGraph} by calling {@link org.gradle.api.invocation.Gradle#getTaskGraph()}.
* In your build file you can use {@code gradle.taskGraph} to access it.</p>
*
* <p>The <code>TaskExecutionGraph</code> is populated only after all the projects in the build have been evaluated. It
* is empty before then. You can receive a notification when the graph is populated, using {@link
* #whenReady(groovy.lang.Closure)} or {@link #addTaskExecutionGraphListener(TaskExecutionGraphListener)}.</p>
*/
public interface TaskExecutionGraph {
/**
* <p>Adds a listener to this graph, to be notified when this graph is ready.</p>
*
* @param listener The listener to add. Does nothing if this listener has already been added.
*/
void addTaskExecutionGraphListener(TaskExecutionGraphListener listener);
/**
* <p>Remove a listener from this graph.</p>
*
* @param listener The listener to remove. Does nothing if this listener was never added to this graph.
*/
void removeTaskExecutionGraphListener(TaskExecutionGraphListener listener);
/**
* <p>Adds a listener to this graph, to be notified as tasks are executed.</p>
*
* @param listener The listener to add. Does nothing if this listener has already been added.
* @deprecated This method is not supported when configuration caching is enabled.
*/
@Deprecated
void addTaskExecutionListener(TaskExecutionListener listener);
/**
* <p>Remove a listener from this graph.</p>
*
* @param listener The listener to remove. Does nothing if this listener was never added to this graph.
* @deprecated This method is not supported when configuration caching is enabled.
*/
@Deprecated
void removeTaskExecutionListener(TaskExecutionListener listener);
/**
* <p>Adds a closure to be called when this graph has been populated. This graph is passed to the closure as a
* parameter.</p>
*
* @param closure The closure to execute when this graph has been populated.
*/
void whenReady(Closure closure);
/**
* <p>Adds an action to be called when this graph has been populated. This graph is passed to the action as a
* parameter.</p>
*
* @param action The action to execute when this graph has been populated.
*
* @since 3.1
*/
void whenReady(Action<TaskExecutionGraph> action);
/**
* <p>Adds a closure to be called immediately before a task is executed. The task is passed to the closure as a
* parameter.</p>
*
* @param closure The closure to execute when a task is about to be executed.
* @deprecated This method is not supported when configuration caching is enabled.
*/
@Deprecated
void beforeTask(Closure closure);
/**
* <p>Adds an action to be called immediately before a task is executed. The task is passed to the action as a
* parameter.</p>
*
* @param action The action to execute when a task is about to be executed.
* @deprecated This method is not supported when configuration caching is enabled.
*
* @since 3.1
*/
@Deprecated
void beforeTask(Action<Task> action);
/**
* <p>Adds a closure to be called immediately after a task has executed. The task is passed to the closure as the
* first parameter. A {@link org.gradle.api.tasks.TaskState} is passed as the second parameter. Both parameters are
* optional.</p>
*
* @param closure The closure to execute when a task has been executed
* @deprecated This method is not supported when configuration caching is enabled.
*/
@Deprecated
void afterTask(Closure closure);
/**
* <p>Adds an action to be called immediately after a task has executed. The task is passed to the action as the
* first parameter.</p>
*
* @param action The action to execute when a task has been executed
* @deprecated This method is not supported when configuration caching is enabled.
*
* @since 3.1
*/
@Deprecated
void afterTask(Action<Task> action);
/**
* <p>Determines whether the given task is included in the execution plan.</p>
*
* @param path the <em>absolute</em> path of the task.
* @return true if a task with the given path is included in the execution plan.
* @throws IllegalStateException When this graph has not been populated.
*/
boolean hasTask(String path);
/**
* <p>Determines whether the given task is included in the execution plan.</p>
*
* @param task the task
* @return true if the given task is included in the execution plan.
* @throws IllegalStateException When this graph has not been populated.
*/
boolean hasTask(Task task);
/**
* <p>Returns the tasks which are included in the execution plan.
* The order of the tasks in the result is compatible with the constraints (dependsOn/mustRunAfter/etc) set in the build configuration.
* However, Gradle may execute tasks in a slightly different order to speed up the overall execution while still respecting the constraints.
* </p>
*
* @return The tasks. Returns an empty list if no tasks are to be executed.
*/
List<Task> getAllTasks();
/**
* <p>Returns the dependencies of a task which are part of the execution graph.</p>
*
* @return The tasks. Returns an empty set if there are no dependent tasks.
* @throws IllegalStateException When this graph has not been populated or the task is not part of it.
*
* @since 4.6
*/
Set<Task> getDependencies(Task task);
}