Skip to content

Commit 4bc9ff2

Browse files
committed
Add --ignore-cache, which forces all tasks to be re-run. Fixes #14
Move RecompileSources to temp directory. Fixes #2
1 parent cb87441 commit 4bc9ff2

17 files changed

Lines changed: 211 additions & 202 deletions

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.io.File;
88
import java.io.IOException;
99
import joptsimple.OptionParser;
10+
import net.minecraftforge.mcmaven.impl.Mavenizer;
1011
import net.minecraftforge.mcmaven.impl.MinecraftMaven;
1112
import net.minecraftforge.mcmaven.impl.cache.Cache;
1213
import net.minecraftforge.mcmaven.impl.data.MCPSetupFiles;
@@ -165,7 +166,7 @@ static OptionParser run(String[] args, boolean getParser) throws Exception {
165166
LOGGER.pop(indent);
166167
}
167168

168-
if (!output.exists() || !cache.isSame()) {
169+
if (!Mavenizer.checkCache(output, cache)) {
169170
try {
170171
org.apache.commons.io.FileUtils.copyFile(raw, output);
171172
if (outputFiles != null)
@@ -231,7 +232,7 @@ static OptionParser run(String[] args, boolean getParser) throws Exception {
231232
cache.add("renamed", sources);
232233
}
233234

234-
if (!output.exists() || !cache.isSame()) {
235+
if (!Mavenizer.checkCache(output, cache)) {
235236
try {
236237
org.apache.commons.io.FileUtils.copyFile(sources, output);
237238
if (outputFiles != null)

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ static OptionParser run(String[] args, boolean getParser) throws Exception {
7272
var cacheOnlyO = parser.accepts("cache-only",
7373
"Only use caches, fail if any downloads need to occur or if a task needs to do work");
7474

75+
// ignore caches, currently only invalidates HashStore entries
76+
var ignoreCacheO = parser.accepts("ignore-cache",
77+
"Forces all cache checks to fail, which results in all tasks re-running")
78+
.availableUnless(cacheOnlyO);
79+
cacheOnlyO.availableUnless(ignoreCacheO);
80+
7581
var mappingsO = parser.accepts("mappings",
7682
"Mappings to use for this artifact. Formatted as channel:version")
7783
.withRequiredArg().ofType(String.class).defaultsTo("official");
@@ -101,8 +107,8 @@ static OptionParser run(String[] args, boolean getParser) throws Exception {
101107
stubO.availableUnless(accessTransformerO);
102108

103109
var outputJsonO = parser.accepts("output-json",
104-
"File to write extended output data to. Not compatible with bulk operations.")
105-
.withRequiredArg().ofType(File.class);
110+
"File to write extended output data to. Not compatible with bulk operations.")
111+
.withRequiredArg().ofType(File.class);
106112

107113
var shorthandOptions = new HashMap<String, OptionSpecBuilder>();
108114
var artifacts = Map.of(
@@ -146,6 +152,8 @@ static OptionParser run(String[] args, boolean getParser) throws Exception {
146152
Mavenizer.setOffline();
147153
if (options.has(cacheOnlyO))
148154
Mavenizer.setCacheOnly();
155+
if (options.has(ignoreCacheO))
156+
Mavenizer.setIgnoreCache();
149157

150158
var output = options.valueOf(outputO);
151159
var cache = options.valueOf(cacheO);
@@ -178,18 +186,18 @@ static OptionParser run(String[] args, boolean getParser) throws Exception {
178186
}
179187

180188
var mcmaven = new MinecraftMaven(
181-
output,
182-
options.has(dependenciesOnlyO),
183-
cache,
184-
jdkCache,
185-
mappings,
189+
output,
190+
options.has(dependenciesOnlyO),
191+
cache,
192+
jdkCache,
193+
mappings,
186194
foreignRepositories,
187195
options.has(globalAuxiliaryVariantsO),
188196
options.has(disableGradleO),
189197
options.has(stubO),
190198
options.valuesOf(accessTransformerO),
191199
options.valueOf(outputJsonO)
192-
);
200+
);
193201
mcmaven.run(artifact);
194202

195203
return parser;

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@
44
*/
55
package net.minecraftforge.mcmaven.impl;
66

7+
import java.io.File;
8+
9+
import net.minecraftforge.util.hash.HashStore;
710
import net.minecraftforge.util.logging.Logger;
811

912
public final class Mavenizer {
13+
private Mavenizer() { }
14+
1015
public static final Logger LOGGER = Logger.create();
1116

1217
private static boolean offline = false;
1318

1419
private static boolean cacheOnly = false;
1520
private static boolean cacheMiss = false;
21+
private static boolean ignoreCache = false;
1622

1723
public static boolean isOffline() {
1824
return offline || cacheOnly;
@@ -30,6 +36,14 @@ public static void setCacheOnly() {
3036
cacheOnly = true;
3137
}
3238

39+
public static void setIgnoreCache() {
40+
ignoreCache = true;
41+
}
42+
43+
public static boolean ignoreCache() {
44+
return ignoreCache;
45+
}
46+
3347
public static void assertOnline() {
3448
if (offline)
3549
throw new IllegalArgumentException("Offline mode is enabled! Please run without --offline");
@@ -39,11 +53,16 @@ public static void assertNotCacheOnly() {
3953
if (cacheOnly) {
4054
throw new IllegalArgumentException("Cache is out of date! Please run without --cache-only");
4155
} else if (!cacheMiss) {
42-
LOGGER.debug("Cache miss!", new Exception("Cache miss!"));
56+
LOGGER.debug("Cache miss!", new Exception("Cache miss! Stacktrace for Information Only"));
4357
cacheMiss = true;
4458
LOGGER.release();
4559
}
4660
}
4761

48-
private Mavenizer() { }
62+
public static boolean checkCache(File output, HashStore cache) {
63+
if (!ignoreCache && output.exists() && cache.isSame())
64+
return true;
65+
Mavenizer.assertNotCacheOnly();
66+
return false;
67+
}
4968
}

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

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public MinecraftMaven(File output, boolean dependenciesOnly, File cacheRoot, Fil
9393
LOGGER.info(" JDK Cache: " + cache.jdks().root().getAbsolutePath());
9494
LOGGER.info(" Offline: " + Mavenizer.isOffline());
9595
LOGGER.info(" Cache Only: " + Mavenizer.isCacheOnly());
96+
LOGGER.info(" Ignore Cache: " + Mavenizer.ignoreCache());
9697
LOGGER.info(" Mappings: " + mappings);
9798
if (!foreignRepositories.isEmpty())
9899
LOGGER.info(" Foreign Repos: [" + String.join(", ", foreignRepositories.values()) + ']');
@@ -119,8 +120,8 @@ public void run(Artifact artifact) {
119120
LOGGER.info("Processing Minecraft dependency: %s:%s".formatted(module, version));
120121
Map<String, Supplier<String>> outputJson = null;
121122
if (outputJsonFile != null) {
122-
outputJson = new HashMap<>();
123-
outputJson.put("spec", () -> "1");
123+
outputJson = new HashMap<>();
124+
outputJson.put("spec", () -> "1");
124125
}
125126

126127
var mcprepo = new MCPConfigRepo(this.cache, dependenciesOnly);
@@ -134,19 +135,19 @@ public void run(Artifact artifact) {
134135
}
135136

136137
if (outputJson != null) {
137-
var finalized = new TreeMap<String, String>();
138-
for (var entry : outputJson.entrySet())
139-
finalized.put(entry.getKey(), entry.getValue().get());
138+
var finalized = new TreeMap<String, String>();
139+
for (var entry : outputJson.entrySet())
140+
finalized.put(entry.getKey(), entry.getValue().get());
140141

141-
var parent = outputJsonFile.getParentFile();
142-
if (parent != null && !parent.exists())
143-
parent.mkdirs();
142+
var parent = outputJsonFile.getParentFile();
143+
if (parent != null && !parent.exists())
144+
parent.mkdirs();
144145

145146
try (var writer = new FileWriter(outputJsonFile)) {
146147
Util.GSON.toJson(finalized, writer);
147148
} catch (IOException e) {
148-
LOGGER.error("Failed to write output json file: " + outputJsonFile.getAbsolutePath(), e);
149-
Util.sneak(e);
149+
LOGGER.error("Failed to write output json file: " + outputJsonFile.getAbsolutePath(), e);
150+
Util.sneak(e);
150151
}
151152
}
152153
}
@@ -160,8 +161,8 @@ protected void createForge(Artifact artifact, MCPConfigRepo mcprepo, ForgeRepo r
160161
throw new IllegalArgumentException("No version specified for Forge");
161162

162163
if ("all".equals(version)) {
163-
if (outputJson != null)
164-
throw new IllegalArgumentException("Output Json does not support bulk operations");
164+
if (outputJson != null)
165+
throw new IllegalArgumentException("Output Json does not support bulk operations");
165166

166167
var versions = this.cache.maven().getVersions(artifact);
167168
var mappingCache = new HashMap<String, Mappings>();
@@ -195,8 +196,8 @@ protected void createMinecraft(Artifact artifact, MCPConfigRepo mcprepo, Map<Str
195196
throw new IllegalArgumentException("No version specified for Forge");
196197

197198
if ("all".equals(version)) {
198-
if (outputJson != null)
199-
throw new IllegalArgumentException("Output Json does not support bulk operations");
199+
if (outputJson != null)
200+
throw new IllegalArgumentException("Output Json does not support bulk operations");
200201

201202
var manifestFile = mcprepo.getLauncherManifestTask().execute();
202203
var manifest = JsonData.launcherManifest(manifestFile);
@@ -322,7 +323,7 @@ protected void finalize(Artifact module, Mappings mappings, List<Repo.PendingArt
322323
var cache = HashStore.fromFile(varTarget)
323324
.add("source", source);
324325

325-
if (!varTarget.exists() || !cache.isSame()) {
326+
if (!Mavenizer.checkCache(varTarget, cache)) {
326327
variants.add(Artifact.from(artifact.getGroup(), artifact.getName(), artifact.getVersion()));
327328
try {
328329
GradleModule.Variant[] data = JsonData.fromJson(source, GradleModule.Variant[].class);
@@ -377,6 +378,8 @@ private void updateFile(File target, File source, Artifact artifact) {
377378
} else {
378379
write = !target.exists() || !cache.isSame();
379380
}
381+
if (Mavenizer.ignoreCache())
382+
write = true;
380383

381384
if (write) {
382385
try {
@@ -399,7 +402,7 @@ private void writeStub(File target, File source, Artifact artifact) {
399402
.add("tool", tool)
400403
.add("source", source);
401404

402-
if (target.exists() && cache.isSame())
405+
if (Mavenizer.checkCache(target, cache))
403406
return;
404407

405408
File jdk;
@@ -431,7 +434,7 @@ private void writeAccessTransformed(File target, File source, Artifact artifact)
431434
.add(accessTransformer)
432435
.add("source", source);
433436

434-
if (target.exists() && cache.isSame())
437+
if (Mavenizer.checkCache(target, cache))
435438
return;
436439

437440
File jdk;
@@ -483,7 +486,7 @@ private void updateVariants(Artifact artifact) {
483486
cache.add(input);
484487
}
485488

486-
if (target.exists() && cache.isSame())
489+
if (Mavenizer.checkCache(target, cache))
487490
return;
488491

489492
var module = GradleModule.of(artifact);

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ public static Mappings of(String mappingsNotation) {
6161

6262
switch (channel) {
6363
case "parchment":
64-
return new ParchmentMappings(version);
64+
return new ParchmentMappings(version);
6565
case "official":
66-
return new Mappings(channel, version);
66+
return new Mappings(channel, version);
6767
case "snapshot":
6868
case "snapshot_nodoc":
6969
case "stable":
7070
case "stable_nodoc":
71-
return new MCPMappings(channel, version);
71+
return new MCPMappings(channel, version);
7272
}
7373
throw new IllegalArgumentException("Unsupported Mappings: " + mappingsNotation);
7474
}
@@ -129,8 +129,8 @@ public boolean isPrimary() {
129129
}
130130

131131
public Mappings withMCVersion(String version) {
132-
if (Objects.equals(this.version, version))
133-
return this;
132+
if (Objects.equals(this.version, version))
133+
return this;
134134
return new Mappings(channel(), version);
135135
}
136136

@@ -205,11 +205,9 @@ private File getMappings(MCPSide side, Task srgMappings, Task clientTask, Task s
205205
cache.add("client", client);
206206
cache.add("server", server);
207207

208-
if (output.exists() && cache.isSame())
208+
if (Mavenizer.checkCache(output, cache))
209209
return output;
210210

211-
Mavenizer.assertNotCacheOnly();
212-
213211
var args = List.of(
214212
"--task",
215213
"MAPPINGS_CSV",
@@ -249,7 +247,7 @@ private File makeTsrg(MCPSide side, Task srgTask, Task csvTask, boolean toObf) {
249247
.add("srg", srg)
250248
.add("csv", csv);
251249

252-
if (output.exists() && cache.isSame())
250+
if (Mavenizer.checkCache(output, cache))
253251
return output;
254252

255253
try {

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import de.siegmar.fastcsv.writer.CsvWriter;
2323
import de.siegmar.fastcsv.writer.LineDelimiter;
24+
import net.minecraftforge.mcmaven.impl.Mavenizer;
2425
import net.minecraftforge.mcmaven.impl.cache.Cache;
2526
import net.minecraftforge.mcmaven.impl.cache.MavenCache;
2627
import net.minecraftforge.mcmaven.impl.repo.mcpconfig.MCP;
@@ -34,11 +35,11 @@
3435
import net.minecraftforge.util.hash.HashStore;
3536

3637
public class ParchmentMappings extends Mappings {
37-
private final ParchmentVersion parsedVersion;
38+
private final ParchmentVersion parsedVersion;
3839
private Task downloadTask;
3940

4041
public ParchmentMappings(String version) {
41-
this(ParchmentVersion.parse(version));
42+
this(ParchmentVersion.parse(version));
4243
}
4344
private ParchmentMappings(ParchmentVersion version) {
4445
super("parchment", version.toFriendly());
@@ -53,18 +54,18 @@ public boolean isPrimary() {
5354
// Maybe download the maven-metadata.xml for the MC version and pick the latest one?
5455
@Override
5556
public Mappings withMCVersion(String mcVer) {
56-
if (mcVer == null)
57-
throw new IllegalArgumentException("Minecraft Version can not be null");
57+
if (mcVer == null)
58+
throw new IllegalArgumentException("Minecraft Version can not be null");
5859

59-
if (mcVer.equals(this.parsedVersion.mcVersion()))
60-
return this;
60+
if (mcVer.equals(this.parsedVersion.mcVersion()))
61+
return this;
6162

62-
return new ParchmentMappings(this.parsedVersion.withMinecraft(mcVer));
63+
return new ParchmentMappings(this.parsedVersion.withMinecraft(mcVer));
6364
}
6465

6566
@Override
6667
public Artifact getArtifact(MCPSide side) {
67-
return this.parsedVersion.getMappingArtifact(side.getMCP().getName().getVersion());
68+
return this.parsedVersion.getMappingArtifact(side.getMCP().getName().getVersion());
6869
}
6970

7071
@Override
@@ -120,7 +121,7 @@ private File getMappings(MCP mcp, Task srgTask, Task clientTask, Task serverTask
120121
.add("codever", "1"); // 1 - Fixed class names being in internals names, instead of FG6's pseudo source names (pkg.Outer$Inner)
121122

122123

123-
if (output.exists() && cache.isSame())
124+
if (Mavenizer.checkCache(output, cache))
124125
return output;
125126

126127
ParchmentData json = null;

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,9 @@ protected static Task simplePom(File build, Artifact artifact) {
193193
return Task.named("pom[" + artifact.getName() + ']', () -> {
194194
var output = new File(build, artifact.getName() + '-' + artifact.getVersion() + ".pom");
195195
var cache = HashStore.fromFile(output);
196-
if (output.exists() && cache.isSame())
196+
if (Mavenizer.checkCache(output, cache))
197197
return output;
198198

199-
Mavenizer.assertNotCacheOnly();
200-
201199
var builder = new POMBuilder(artifact.getGroup(), artifact.getName(), artifact.getVersion());
202200

203201
FileUtils.ensureParent(output);
@@ -259,14 +257,14 @@ protected List<PendingArtifact> mappingArtifacts(File cache, Mappings mappings,
259257
var m2o = pending("Mappings map2obf", mappings.getMapped2Obf(side), coords.withClassifier("map2obf").withExtension("tsrg.gz"), false);
260258
var m2s = pending("Mappings map2srg", mappings.getMapped2Srg(side), coords.withClassifier("map2srg").withExtension("tsrg.gz"), false);
261259
if (outputJson != null) {
262-
outputJson.put("mappings.channel", mappings::channel);
263-
outputJson.put("mappings.version", mappings::version);
264-
outputJson.put("mappings.csv.artifact", csvs.artifact()::toString);
265-
outputJson.put("mappings.csv.file", csvs.task().filePathSupplier());
266-
outputJson.put("mappings.obf.artifact", m2o.artifact()::toString);
267-
outputJson.put("mappings.obf.file", m2o.task().filePathSupplier());
268-
outputJson.put("mappings.srg.artifact", m2s.artifact()::toString);
269-
outputJson.put("mappings.srg.file", m2s.task().filePathSupplier());
260+
outputJson.put("mappings.channel", mappings::channel);
261+
outputJson.put("mappings.version", mappings::version);
262+
outputJson.put("mappings.csv.artifact", csvs.artifact()::toString);
263+
outputJson.put("mappings.csv.file", csvs.task().filePathSupplier());
264+
outputJson.put("mappings.obf.artifact", m2o.artifact()::toString);
265+
outputJson.put("mappings.obf.file", m2o.task().filePathSupplier());
266+
outputJson.put("mappings.srg.artifact", m2s.artifact()::toString);
267+
outputJson.put("mappings.srg.file", m2s.task().filePathSupplier());
270268
}
271269
return List.of(csvs, pom, m2o, m2s);
272270
}

0 commit comments

Comments
 (0)