Skip to content

Commit ce26b9c

Browse files
committed
stage2/ml9: Support KotlinForForge 5.8
KFF 5.8 switched to using a different JarJar gradle plugin which assigns a different file name to the nested `kffmod` jar, resulting in our `isJarJarKff` failing to identify it. This commit fixes the issue by properly parsing the JarJar `metadata.json` file instead of matching file names.
1 parent 2b35cce commit ce26b9c

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

stage2/modlauncher9/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ dependencies {
2222
// provided by fmlloader (both forge and neoforge ones)
2323
compileOnly("org.apache.logging.log4j:log4j-api:2.8.1")
2424
compileOnly("org.apache.maven:maven-artifact:3.8.1")
25+
compileOnly("com.google.code.gson:gson:2.8.0")
2526
}

stage2/modlauncher9/src/main/java/gg/essential/loader/stage2/util/KFFMerger.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package gg.essential.loader.stage2.util;
22

3+
import com.google.gson.Gson;
4+
import com.google.gson.JsonArray;
5+
import com.google.gson.JsonObject;
36
import cpw.mods.jarhandling.JarMetadata;
47
import cpw.mods.jarhandling.SecureJar;
58
import gg.essential.loader.stage2.DescriptorRewritingJarMetadata;
@@ -21,7 +24,9 @@
2124
import java.util.Set;
2225
import java.util.regex.Matcher;
2326
import java.util.regex.Pattern;
27+
import java.util.stream.Collectors;
2428
import java.util.stream.Stream;
29+
import java.util.stream.StreamSupport;
2530

2631
/**
2732
* We need to inject our bundled Kotlin library files into the existing KotlinForForge jar instead of injecting
@@ -210,18 +215,17 @@ public String name() {
210215

211216
public static boolean isJarJarKff(SecureJar jar) {
212217
try {
213-
Path jarjarPath = jar.getRootPath().resolve("META-INF").resolve("jarjar");
218+
Path jarjarPath = jar.getRootPath().resolve("META-INF").resolve("jarjar").resolve("metadata.json");
214219
if (!Files.exists(jarjarPath)) return false;
215-
try (Stream<Path> stream = Files.list(jarjarPath)) {
216-
List<String> files = stream
217-
.map(it -> it.getFileName().toString())
218-
.filter(it -> it.endsWith(".jar"))
219-
.toList();
220-
// A JarJar-using KotlinForForge jar can be recognized by the fact that it bundles both the KFF mod as
221-
// well as the Kotlin Standard Library
222-
return files.stream().anyMatch(it -> it.startsWith("kffmod-"))
223-
&& files.stream().anyMatch(it -> it.startsWith("kotlin-stdlib-"));
224-
}
220+
JsonObject root = new Gson().fromJson(Files.readString(jarjarPath), JsonObject.class);
221+
JsonArray jars = root.getAsJsonArray("jars");
222+
Set<String> artifactIds = StreamSupport.stream(jars.spliterator(), false)
223+
.map(it -> it.getAsJsonObject().getAsJsonObject("identifier"))
224+
.map(it -> it.getAsJsonPrimitive("group").getAsString() + ":" + it.getAsJsonPrimitive("artifact").getAsString())
225+
.collect(Collectors.toSet());
226+
// A JarJar-using KotlinForForge jar can be recognized by the fact that it bundles both the KFF mod as
227+
// well as the Kotlin Standard Library
228+
return artifactIds.contains("thedarkcolour:kffmod") && artifactIds.contains("org.jetbrains.kotlin:kotlin-stdlib");
225229
} catch (Throwable t) {
226230
LOGGER.error("Failed to determine version of potential KFF jar at " + jar + ":", t);
227231
return false;

0 commit comments

Comments
 (0)