Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions stage2/modlauncher9/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ dependencies {
// provided by fmlloader (both forge and neoforge ones)
compileOnly("org.apache.logging.log4j:log4j-api:2.8.1")
compileOnly("org.apache.maven:maven-artifact:3.8.1")
compileOnly("com.google.code.gson:gson:2.8.0")
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package gg.essential.loader.stage2.util;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import cpw.mods.jarhandling.JarMetadata;
import cpw.mods.jarhandling.SecureJar;
import gg.essential.loader.stage2.DescriptorRewritingJarMetadata;
Expand All @@ -21,7 +24,9 @@
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

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

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