From fce31a4f1d261fd984275f2efe15e7d21e188091 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 5 Sep 2023 03:30:13 +0800 Subject: [PATCH] Delete forge mods' jarjar metadata (#159) * Delete forge mods' jarjar metadata * Update ZipUtils.java * Update src/main/java/net/fabricmc/loom/util/ZipUtils.java Co-authored-by: Juuz <6596629+Juuxel@users.noreply.github.com> --------- Co-authored-by: Juuz <6596629+Juuxel@users.noreply.github.com> --- .../net/fabricmc/loom/configuration/mods/ModProcessor.java | 6 ++++++ src/main/java/net/fabricmc/loom/util/ZipUtils.java | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/main/java/net/fabricmc/loom/configuration/mods/ModProcessor.java b/src/main/java/net/fabricmc/loom/configuration/mods/ModProcessor.java index 54402cace..5efb674d1 100644 --- a/src/main/java/net/fabricmc/loom/configuration/mods/ModProcessor.java +++ b/src/main/java/net/fabricmc/loom/configuration/mods/ModProcessor.java @@ -121,6 +121,12 @@ private String describeConfiguration(Configuration configuration) { } private void stripNestedJars(Path path) { + try { + ZipUtils.deleteIfExists(path, "META-INF/jarjar/metadata.json"); + } catch (IOException e) { + throw new UncheckedIOException("Failed to strip nested jars from %s".formatted(path), e); + } + if (!ZipUtils.contains(path, "fabric.mod.json")) { if (ZipUtils.contains(path, "quilt.mod.json")) { // Strip out all contained jar info as we dont want loader to try and load the jars contained in dev. diff --git a/src/main/java/net/fabricmc/loom/util/ZipUtils.java b/src/main/java/net/fabricmc/loom/util/ZipUtils.java index 2d1be1e68..14c5cce57 100644 --- a/src/main/java/net/fabricmc/loom/util/ZipUtils.java +++ b/src/main/java/net/fabricmc/loom/util/ZipUtils.java @@ -184,6 +184,12 @@ public static void replace(Path zip, String path, byte[] bytes) throws IOExcepti } } + public static void deleteIfExists(Path zip, String path) throws IOException { + try (FileSystemUtil.Delegate fs = FileSystemUtil.getJarFileSystem(zip, false)) { + Files.deleteIfExists(fs.getPath(path)); + } + } + public static int transformString(Path zip, Collection>> transforms) throws IOException { return transformString(zip, transforms.stream()); }