|
23 | 23 | import java.util.Map; |
24 | 24 | import java.util.Objects; |
25 | 25 | import java.util.concurrent.Callable; |
| 26 | +import java.util.function.Supplier; |
26 | 27 |
|
27 | 28 | /** Internal utilities. Documented for maintainability, NOT for public consumption. */ |
28 | 29 | final class Util { |
@@ -111,49 +112,29 @@ static <T> T tryElse(Callable<? extends T> value, T orElse) { |
111 | 112 | /// @param project The project |
112 | 113 | /// @param task The task to run first |
113 | 114 | static void runFirst(Project project, TaskProvider<?> task) { |
114 | | - // we need this local class so that the execution request is serialized properly |
115 | | - record SimpleTaskExecutionRequest(List<String> getArgs) implements TaskExecutionRequest, Serializable { |
116 | | - @Override |
117 | | - public @Nullable String getProjectPath() { |
118 | | - return null; |
119 | | - } |
120 | | - |
121 | | - @Override |
122 | | - public @Nullable File getRootDir() { |
123 | | - return null; |
124 | | - } |
| 115 | + // copy the requests because the backed list isn't concurrent |
| 116 | + var requests = new ArrayList<>(project.getGradle().getStartParameter().getTaskRequests()); |
125 | 117 |
|
| 118 | + // add the task to the front of the list |
| 119 | + requests.add(0, new TaskExecutionRequest() { |
126 | 120 | @Override |
127 | | - public String toString() { |
128 | | - return "SimpleTaskExecutionRequest{args=[%s]}".formatted(String.join(", ", this.getArgs)); |
| 121 | + public List<String> getArgs() { |
| 122 | + return List.of(task.get().getPath()); |
129 | 123 | } |
130 | 124 |
|
131 | 125 | @Override |
132 | | - public boolean equals(Object o) { |
133 | | - return this == o || o instanceof SimpleTaskExecutionRequest that && Objects.equals(this.getArgs, that.getArgs); |
| 126 | + public @Nullable String getProjectPath() { |
| 127 | + return null; |
134 | 128 | } |
135 | 129 |
|
136 | 130 | @Override |
137 | | - public int hashCode() { |
138 | | - return Objects.hashCode(getArgs); |
| 131 | + public @Nullable File getRootDir() { |
| 132 | + return null; |
139 | 133 | } |
140 | | - } |
141 | | - |
142 | | - // copy the requests because the backed list isn't concurrent |
143 | | - var requests = new ArrayList<>(project.getGradle().getStartParameter().getTaskRequests()); |
144 | | - |
145 | | - // remove any existing requests for this task |
146 | | - requests.removeIf(request -> { |
147 | | - var args = request.getArgs(); |
148 | | - if (args.size() != 1) return false; |
149 | | - |
150 | | - return Objects.equals(args.get(0), task.getName()); |
151 | 134 | }); |
152 | 135 |
|
153 | | - // add the task to the front of the list |
154 | | - requests.add(0, new SimpleTaskExecutionRequest(List.of(task.getName()))); |
155 | | - |
156 | 136 | // set the new requests |
| 137 | + project.getLogger().info("Adding task to beginning of task graph! Project: {}, Task: {}", project.getName(), task.getName()); |
157 | 138 | project.getGradle().getStartParameter().setTaskRequests(requests); |
158 | 139 | } |
159 | 140 | } |
0 commit comments