Skip to content

Commit bbb4477

Browse files
committed
Fixed task requests not respecting project path
Fixes attempting to sync the Minecraft Mavenizer with other projects
1 parent 14bf6a6 commit bbb4477

File tree

2 files changed

+20
-35
lines changed

2 files changed

+20
-35
lines changed

src/main/groovy/net/minecraftforge/gradle/SlimeLauncherOptions.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import java.io.File;
2828
import java.util.Arrays;
2929
import java.util.Map;
30-
import java.util.function.Consumer;
31-
import java.util.function.Predicate;
3230

3331
/// The configuration options for Slime Launcher tasks.
3432
///
@@ -592,15 +590,21 @@ private SlimeLauncherOptions(String name) {
592590
this.workingDir = this.getObjects().directoryProperty().convention(this.getLayout().getProjectDirectory().dir("run").dir(name));
593591
}
594592

595-
protected abstract @Inject ObjectFactory getObjects();
593+
abstract ObjectFactory getObjects();
596594

597-
protected abstract @Inject ProjectLayout getLayout();
595+
abstract ProjectLayout getLayout();
598596

599597
abstract non-sealed static class Impl extends SlimeLauncherOptions {
600598
@Inject
601599
public Impl(String name) {
602600
super(name);
603601
}
602+
603+
@Override
604+
protected abstract @Inject ObjectFactory getObjects();
605+
606+
@Override
607+
protected abstract @Inject ProjectLayout getLayout();
604608
}
605609

606610
/// Creates a Slime Launcher options named domain object container.

src/main/groovy/net/minecraftforge/gradle/Util.java

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Map;
2424
import java.util.Objects;
2525
import java.util.concurrent.Callable;
26+
import java.util.function.Supplier;
2627

2728
/** Internal utilities. Documented for maintainability, NOT for public consumption. */
2829
final class Util {
@@ -111,49 +112,29 @@ static <T> T tryElse(Callable<? extends T> value, T orElse) {
111112
/// @param project The project
112113
/// @param task The task to run first
113114
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());
125117

118+
// add the task to the front of the list
119+
requests.add(0, new TaskExecutionRequest() {
126120
@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());
129123
}
130124

131125
@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;
134128
}
135129

136130
@Override
137-
public int hashCode() {
138-
return Objects.hashCode(getArgs);
131+
public @Nullable File getRootDir() {
132+
return null;
139133
}
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());
151134
});
152135

153-
// add the task to the front of the list
154-
requests.add(0, new SimpleTaskExecutionRequest(List.of(task.getName())));
155-
156136
// set the new requests
137+
project.getLogger().info("Adding task to beginning of task graph! Project: {}, Task: {}", project.getName(), task.getName());
157138
project.getGradle().getStartParameter().setTaskRequests(requests);
158139
}
159140
}

0 commit comments

Comments
 (0)