Skip to content

Commit 31bda40

Browse files
committed
Very small (I promise) task refactor
This includes a small part of the canned task caching PR, which is the interface change to Task and making RenameTask, InjectTask, etc. use it. Also enforces dependencies be declared with Task#deps instead of just providing a List or Set.
1 parent 31a47ad commit 31bda40

File tree

14 files changed

+156
-103
lines changed

14 files changed

+156
-103
lines changed

src/main/java/net/minecraftforge/mcmaven/cli/MCPTask.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,12 @@ public static void run(String[] args) throws Exception {
171171
var predecomp = side.getTasks().getPreDecompile();
172172
if (ats != null) {
173173
var tmp = predecomp;
174-
predecomp = Task.named("modifyAccess", Set.of(tmp), () -> Patcher.modifyAccess(dir, tmp, ats, repo.getCache()));
174+
predecomp = Task.named("modifyAccess", Task.deps(tmp), () -> Patcher.modifyAccess(dir, tmp, ats, repo.getCache()));
175175
}
176176

177177
if (sas != null) {
178178
var tmp = predecomp;
179-
predecomp = Task.named("stripSides", Set.of(tmp), () -> Patcher.stripSides(dir, tmp, sas, repo.getCache()));
179+
predecomp = Task.named("stripSides", Task.deps(tmp), () -> Patcher.stripSides(dir, tmp, sas, repo.getCache()));
180180
}
181181

182182
var factory = side.getTasks().child(dir, predecomp);
@@ -205,7 +205,7 @@ public static void run(String[] args) throws Exception {
205205
? new ParchmentMappings(options.valueOf(parchmentO))
206206
: new Mappings("official", null).withMCVersion(MinecraftMaven.mcpToMcVersion(artifact.getVersion()));
207207

208-
var renameTask = new RenameTask(side.getBuildFolder(), pipeline, side, Task.existing("sources", sources), mappings).get();
208+
var renameTask = new RenameTask(side.getBuildFolder(), pipeline, side, sourcesTask, mappings);
209209
sources = renameTask.execute();
210210
} finally {
211211
Log.pop(indent);

src/main/java/net/minecraftforge/mcmaven/impl/MinecraftMaven.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ private void finalize(Artifact module, Mappings mappings, List<Repo.PendingArtif
151151
}
152152

153153
if (pending.getVariants() != null) {
154-
var source = pending.getVariants().get();
154+
var source = pending.getVariants().execute();
155155
var cache = HashStore.fromFile(target)
156156
.add("source", source);
157157

src/main/java/net/minecraftforge/mcmaven/impl/mappings/Mappings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public Task getCsvZip(MCPSide side) {
9393
var client = mc.versionFile("client_mappings", "txt");
9494
var server = mc.versionFile("server_mappings", "txt");
9595
ret = Task.named("srg2names[" + this + ']',
96-
Set.of(srg, client, server),
96+
Task.deps(srg, client, server),
9797
() -> getMappings(side, srg, client, server)
9898
);
9999
tasks.put(side, ret);

src/main/java/net/minecraftforge/mcmaven/impl/mappings/ParchmentMappings.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public Task getCsvZip(MCPSide side) {
7171
var data = downloadTask(side.getMCP());
7272

7373
ret = Task.named("srg2names[" + this + ']',
74-
Set.of(srg, client, server, data).stream().filter(e -> e != null).toList(),
74+
Task.deps(Set.of(srg, client, server, data).stream().filter(Objects::nonNull).toList()),
7575
() -> getMappings(side.getMCP(), srg, client, server, data)
7676
);
7777
tasks.put(side, ret);
@@ -82,7 +82,6 @@ public Task getCsvZip(MCPSide side) {
8282
private Task downloadTask(MCP mcp) {
8383
if (downloadTask == null) {
8484
downloadTask = Task.named("download[" + version() + "][parchment]",
85-
Set.of(),
8685
() -> download(mcp.getCache())
8786
);
8887
}

src/main/java/net/minecraftforge/mcmaven/impl/repo/Repo.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ protected Supplier<GradleModule.Variant[]> sourceVariant(Mappings mappings) {
7474
}
7575

7676
protected static Task variantTask(Task parent, Supplier<GradleModule.Variant[]> supplier) {
77-
return Task.named(parent.name() + "[variants]", List.of(parent), () -> {
77+
return Task.named(parent.name() + "[variants]", Task.deps(parent), () -> {
7878
var variants = supplier.get();
7979

80-
var variantFile = new File(parent.get().getAbsolutePath() + ".variants");
80+
var variantFile = new File(parent.execute().getAbsolutePath() + ".variants");
8181
try {
8282
FileUtils.ensureParent(variantFile);
8383
JsonData.toJson(variants, variantFile);
@@ -121,7 +121,7 @@ protected GradleModule.Variant[] classVariants(Mappings mappings, MCPSide side,
121121
}
122122

123123
var java = Util.replace(
124-
JsonData.minecraftVersion(side.getMCP().getMinecraftTasks().versionJson.get()),
124+
JsonData.minecraftVersion(side.getMCP().getMinecraftTasks().versionJson.execute()),
125125
v -> v.javaVersion != null ? v.javaVersion.majorVersion : null
126126
);
127127

@@ -196,7 +196,7 @@ private PendingArtifact(String message, Task task, Artifact artifact, @Nullable
196196
@Override
197197
public File get() {
198198
if (this.task.resolved())
199-
return this.task.get();
199+
return this.task.execute();
200200

201201
try {
202202
Log.info(this.message);

src/main/java/net/minecraftforge/mcmaven/impl/repo/forge/ForgeRepo.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,17 @@ private List<PendingArtifact> processV3(String version, Mappings mappings) {
135135
var patcher = new Patcher(build, this, userdev);
136136
var joined = patcher.getMCP().getSide(MCPSide.JOINED);
137137
var sourcesTask = new RenameTask(build, userdev, joined, patcher.get(), mappings);
138-
var recompile = new RecompileTask(build, name, patcher.getMCP(), patcher::getClasspath, sourcesTask.get(), mappings);
139-
var classesTask = new InjectTask(build, this.cache, name, patcher, recompile.get(), mappings);
138+
var recompile = new RecompileTask(build, name, patcher.getMCP(), patcher::getClasspath, sourcesTask, mappings);
139+
var classesTask = new InjectTask(build, this.cache, name, patcher, recompile, mappings);
140140

141141
var extraCoords = Artifact.from(Constants.MC_GROUP, Constants.MC_CLIENT + "-extra", patcher.getMCP().getName().getVersion());
142142
var mappingCoords = mappings.getArtifact(joined);
143143

144144
var mapzip = pending("Mappings Zip", mappings.getCsvZip(joined), mappingCoords);
145145
var mappom = pending("Mappings POM", simplePom(build, mappingCoords), mappingCoords.withExtension("pom"));
146146

147-
var sources = pending("Sources", sourcesTask.get(), name.withClassifier("sources"), sourceVariant(mappings));
148-
var classes = pending("Classes", classesTask.get(), name, () -> classVariants(mappings, patcher, extraCoords, mappingCoords));
147+
var sources = pending("Sources", sourcesTask, name.withClassifier("sources"), sourceVariant(mappings));
148+
var classes = pending("Classes", classesTask, name, () -> classVariants(mappings, patcher, extraCoords, mappingCoords));
149149
var metadata = pending("Metadata", metadata(build, patcher), name.withClassifier("metadata").withExtension("zip"));
150150

151151
PendingArtifact pom = null;
@@ -160,7 +160,7 @@ private List<PendingArtifact> processV3(String version, Mappings mappings) {
160160
}
161161

162162
private static Task metadata(File build, Patcher patcher) {
163-
return Task.named("metadata[forge]", Set.of(patcher.getMCP().getMinecraftTasks().versionJson), () -> {
163+
return Task.named("metadata[forge]", Task.deps(patcher.getMCP().getMinecraftTasks().versionJson), () -> {
164164
var output = new File(build, "metadata.zip");
165165

166166
// metadata
@@ -173,7 +173,7 @@ private static Task metadata(File build, Patcher patcher) {
173173

174174
// metadata/minecraft
175175
var minecraftDir = new File(metadataDir, "minecraft");
176-
var versionJson = patcher.getMCP().getMinecraftTasks().versionJson.get();
176+
var versionJson = patcher.getMCP().getMinecraftTasks().versionJson.execute();
177177

178178
var cache = HashStore
179179
.fromFile(output)

src/main/java/net/minecraftforge/mcmaven/impl/repo/forge/InjectTask.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
/**
2323
* Takes a jar containing compiled class files, and injects extra data/resources from a patcher into it.
2424
*/
25-
public final class InjectTask implements Supplier<Task> {
25+
public final class InjectTask implements Task {
2626
private final File build;
2727
private final Artifact name;
2828
private final Cache cache;
@@ -40,13 +40,23 @@ public final class InjectTask implements Supplier<Task> {
4040
}
4141

4242
@Override
43-
public Task get() {
44-
return this.task;
43+
public File execute() {
44+
return this.task.execute();
45+
}
46+
47+
@Override
48+
public boolean resolved() {
49+
return this.task.resolved();
50+
}
51+
52+
@Override
53+
public String name() {
54+
return this.task.name();
4555
}
4656

4757
private Task injectData(Task input) {
4858
return Task.named("injectData[" + this.name.getName() + "][" + mappings + ']',
49-
Set.of(input),
59+
Task.deps(input),
5060
() -> injectDataImpl(input, new File(this.build, "injected.jar"))
5161
);
5262
}

src/main/java/net/minecraftforge/mcmaven/impl/repo/forge/Patcher.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,12 @@ public class Patcher implements Supplier<Task> {
132132

133133
if (ats != null) {
134134
var tmp = predecomp;
135-
predecomp = Task.named("modifyAccess", Set.of(tmp), () -> modifyAccess(dir, tmp, ats, cache));
135+
predecomp = Task.named("modifyAccess", Task.deps(tmp), () -> modifyAccess(dir, tmp, ats, cache));
136136
}
137137

138138
if (sass != null) {
139139
var tmp = predecomp;
140-
predecomp = Task.named("stripSides", Set.of(tmp), () -> stripSides(dir, tmp, sass, cache));
140+
predecomp = Task.named("stripSides", Task.deps(tmp), () -> stripSides(dir, tmp, sass, cache));
141141
}
142142

143143
// If we changed the decompile input, rebuild decompile and subsequent tasks
@@ -494,7 +494,7 @@ private Task postProcess(Task input, File outputDir) {
494494
deps.add(extractSingle(entry.getKey(), entry.getValue()));
495495

496496
return Task.named("postProcess[" + this.name.getName() + ']',
497-
deps,
497+
Task.deps(deps),
498498
() -> postProcess(input, data, output, log)
499499
);
500500
}
@@ -553,7 +553,7 @@ private Task patch(Task input, File outputDir) {
553553
var output = new File(outputDir, "patched.jar");
554554
var rejects = new File(outputDir, "patched-rejects.jar");
555555
return Task.named("patch[" + this.name.getName() + ']',
556-
Set.of(input),
556+
Task.deps(input),
557557
() -> patch(input, output, rejects)
558558
);
559559
}
@@ -612,7 +612,7 @@ private Task injectSources(Task input, File outputDir) {
612612

613613
var output = new File(outputDir, "injected-sources.jar");
614614
return Task.named("injectSources[" + this.name.getName() + ']',
615-
Set.of(input, this.downloadSources),
615+
Task.deps(input, this.downloadSources),
616616
() -> injectSourcesImpl(input, output)
617617
);
618618
}

src/main/java/net/minecraftforge/mcmaven/impl/repo/mcpconfig/MCPConfigRepo.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ public List<PendingArtifact> process(Artifact artifact, Mappings mappings) {
107107
var pending = new ArrayList<PendingArtifact>();
108108

109109
var sourcesTask = new RenameTask(build, name, mcpSide, mcpSide.getSources(), mappings);
110-
var recompile = new RecompileTask(build, name, mcpSide.getMCP(), mcpSide::getClasspath, sourcesTask.get(), mappings);
111-
var classesTask = mergeExtra(build, side, recompile.get(), mcpSide.getTasks().getExtra(), mappings);
110+
var recompile = new RecompileTask(build, name, mcpSide.getMCP(), mcpSide::getClasspath, sourcesTask, mappings);
111+
var classesTask = mergeExtra(build, side, recompile, mcpSide.getTasks().getExtra(), mappings);
112112

113-
var sources = pending("Sources", sourcesTask.get(), name.withClassifier("sources"), sourceVariant(mappings));
113+
var sources = pending("Sources", sourcesTask, name.withClassifier("sources"), sourceVariant(mappings));
114114
var classes = pending("Classes", classesTask, name, () -> classVariants(mappings, mcpSide));
115115
var metadata = pending("Metadata", metadata(build, mcpSide), name.withClassifier("metadata").withExtension("zip"));
116116
pending.addAll(List.of(
@@ -150,10 +150,10 @@ public List<PendingArtifact> processExtra(String module, String version) {
150150

151151
// TODO [MCMavenizer][client-extra] Band-aid fix for merging for clean! Remove later.
152152
private static Task mergeExtra(File build, String side, Task recompiled, Task extra, Mappings mappings) {
153-
return Task.named("mergeExtra[" + side + "][" + mappings + ']', Set.of(extra, recompiled), () -> {
153+
return Task.named("mergeExtra[" + side + "][" + mappings + ']', Task.deps(extra, recompiled), () -> {
154154
var output = new File(mappings.getFolder(build), "recompiled-extra.jar");
155-
var recompiledF = recompiled.get();
156-
var extraF = extra.get();
155+
var recompiledF = recompiled.execute();
156+
var extraF = extra.execute();
157157
var cache = HashStore
158158
.fromFile(output)
159159
.add(recompiledF, extraF);
@@ -175,7 +175,7 @@ private static Task mergeExtra(File build, String side, Task recompiled, Task ex
175175

176176
private static Task metadata(File build, MCPSide side) {
177177
var minecraftTasks = side.getMCP().getMinecraftTasks();
178-
return Task.named("metadata[forge]", Set.of(minecraftTasks.versionJson), () -> {
178+
return Task.named("metadata[forge]", Task.deps(minecraftTasks.versionJson), () -> {
179179
var output = new File(build, "metadata.zip");
180180

181181
// metadata
@@ -184,7 +184,7 @@ private static Task metadata(File build, MCPSide side) {
184184

185185
// metadata/minecraft
186186
var minecraftDir = new File(metadataDir, "minecraft");
187-
var versionJson = minecraftTasks.versionJson.get();
187+
var versionJson = minecraftTasks.versionJson.execute();
188188

189189
var cache = HashStore
190190
.fromFile(output)

src/main/java/net/minecraftforge/mcmaven/impl/repo/mcpconfig/MCPTaskFactory.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ private Task strip(String name, Map<String, String> step) {
398398
var output = new File(this.build, name + ".jar").getAbsoluteFile();
399399
var input = findStep(step.get("input"));
400400
return Task.named(name,
401-
Task.collect(input, (Supplier<Task>) () -> this.mappings),
401+
Task.deps(() -> input, () -> this.mappings),
402402
() -> strip(input, whitelist, output)
403403
);
404404
}
@@ -452,7 +452,7 @@ private Task inject(String name, Map<String, String> step) {
452452
var packages = new File(this.build, name + "/packages.jar").getAbsoluteFile();
453453
var output = new File(this.build, name + "/output.jar").getAbsoluteFile();
454454
return Task.named(name,
455-
Set.of(input, inject),
455+
Task.deps(input, inject),
456456
() -> inject(input, inject, packages, output)
457457
);
458458
}
@@ -527,7 +527,7 @@ private Task patch(String name, Map<String, String> step) {
527527
var output = new File(this.build, name + "/output.jar");
528528
var rejects = new File(this.build, name + "/rejects.jar");
529529
return Task.named(name,
530-
Set.of(input, patches),
530+
Task.deps(input, patches),
531531
() -> patch(input, patches, output, rejects)
532532
);
533533
}
@@ -583,7 +583,7 @@ private Task listLibraries(String name, Map<String, String> step) {
583583
var output = new File(this.build, name + ".txt");
584584
var json = this.findStep("downloadJson");
585585
return Task.named(name,
586-
Set.of(json),
586+
Task.deps(json),
587587
() -> listLibraries(json, output)
588588
);
589589
}
@@ -670,7 +670,7 @@ private Task listLibrariesBundle(String name, Map<String, String> step) {
670670
var libraries = new File(this.build, name);
671671
var output = new File(this.build, name + "/libraries.txt");
672672
return Task.named(name,
673-
Set.of(bundle),
673+
Task.deps(bundle),
674674
() -> listLibrariesBundle(bundle, libraries, output)
675675
);
676676
}
@@ -758,7 +758,7 @@ public int compareTo(LibLine o) {
758758

759759
public Task getExtra() {
760760
return Task.named("extra[" + this.side.getName() + ']',
761-
Set.of(this.preStrip, this.mappings),
761+
Task.deps(this.preStrip, this.mappings),
762762
() -> getExtra(this.preStrip, mappings)
763763
);
764764
}
@@ -819,7 +819,7 @@ private Task execute(String name, Map<String, String> step, MCPConfig.Function f
819819
var jvmArgs = fillArgs(func.jvmargs, args, deps);
820820
var runArgs = fillArgs(func.args, args, deps);
821821

822-
return Task.named(name, deps,
822+
return Task.named(name, Task.deps(deps),
823823
() -> execute(jvmArgs, runArgs, func, log, output)
824824
);
825825
}

0 commit comments

Comments
 (0)