diff options
author | shedaniel <daniel@shedaniel.me> | 2021-12-05 18:55:51 +0800 |
---|---|---|
committer | shedaniel <daniel@shedaniel.me> | 2021-12-05 18:56:31 +0800 |
commit | 3c8e1f8b31ab96322887c77dd1ed2a138727dee6 (patch) | |
tree | 5a498c3187622ba64efbaa591d0d548bd0e23556 /src/main/java | |
parent | ae383b8d4bc44962f2648099f01f2fc74838c036 (diff) | |
download | architectury-loom-3c8e1f8b31ab96322887c77dd1ed2a138727dee6.tar.gz architectury-loom-3c8e1f8b31ab96322887c77dd1ed2a138727dee6.tar.bz2 architectury-loom-3c8e1f8b31ab96322887c77dd1ed2a138727dee6.zip |
Allow transitive access wideners to be declared through architectury.common.json
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/net/fabricmc/loom/configuration/accesswidener/AccessWidenerFile.java | 38 | ||||
-rw-r--r-- | src/main/java/net/fabricmc/loom/task/RemapJarTask.java | 2 |
2 files changed, 39 insertions, 1 deletions
diff --git a/src/main/java/net/fabricmc/loom/configuration/accesswidener/AccessWidenerFile.java b/src/main/java/net/fabricmc/loom/configuration/accesswidener/AccessWidenerFile.java index 893a1611..5bc892e9 100644 --- a/src/main/java/net/fabricmc/loom/configuration/accesswidener/AccessWidenerFile.java +++ b/src/main/java/net/fabricmc/loom/configuration/accesswidener/AccessWidenerFile.java @@ -45,6 +45,44 @@ public record AccessWidenerFile( * Reads the access-widener contained in a mod jar, or returns null if there is none. */ public static AccessWidenerFile fromModJar(Path modJarPath) { + if (ZipUtils.contains(modJarPath, "architectury.common.json")) { + String awPath = null; + byte[] commonJsonBytes; + + try { + commonJsonBytes = ZipUtils.unpackNullable(modJarPath, "architectury.common.json"); + } catch (IOException e) { + throw new UncheckedIOException("Failed to read access-widener file from: " + modJarPath.toAbsolutePath(), e); + } + + if (commonJsonBytes != null) { + JsonObject jsonObject = new Gson().fromJson(new String(commonJsonBytes, StandardCharsets.UTF_8), JsonObject.class); + + if (jsonObject.has("accessWidener")) { + awPath = jsonObject.get("accessWidener").getAsString(); + } else { + throw new IllegalArgumentException("The architectury.common.json file does not contain an accessWidener field."); + } + } else { + // ??????????? + throw new IllegalArgumentException("The architectury.common.json file does not exist."); + } + + byte[] content; + + try { + content = ZipUtils.unpack(modJarPath, awPath); + } catch (IOException e) { + throw new UncheckedIOException("Could not find access widener file (%s) defined in the architectury.common.json file of %s".formatted(awPath, modJarPath.toAbsolutePath()), e); + } + + return new AccessWidenerFile( + awPath, + modJarPath.getFileName().toString(), + content + ); + } + byte[] modJsonBytes; try { diff --git a/src/main/java/net/fabricmc/loom/task/RemapJarTask.java b/src/main/java/net/fabricmc/loom/task/RemapJarTask.java index 27dd39e6..1ced8299 100644 --- a/src/main/java/net/fabricmc/loom/task/RemapJarTask.java +++ b/src/main/java/net/fabricmc/loom/task/RemapJarTask.java @@ -198,7 +198,7 @@ public class RemapJarTask extends Jar { } AccessWidenerFile awFile = AccessWidenerFile.fromModJar(remapData.input); - Preconditions.checkNotNull(awFile, "Failed to find accessWidener in fabric.mod.json: " + remapData.input); + Preconditions.checkNotNull(awFile, "Failed to find accessWidener in fabric.mod.json / architectury.common.json: " + remapData.input); return Pair.of(awFile.name(), data); } |