|
1 | 1 | package gg.essential.loader.stage2.util; |
2 | 2 |
|
| 3 | +import com.google.gson.Gson; |
| 4 | +import com.google.gson.JsonArray; |
| 5 | +import com.google.gson.JsonObject; |
3 | 6 | import cpw.mods.jarhandling.JarMetadata; |
4 | 7 | import cpw.mods.jarhandling.SecureJar; |
5 | 8 | import gg.essential.loader.stage2.DescriptorRewritingJarMetadata; |
|
21 | 24 | import java.util.Set; |
22 | 25 | import java.util.regex.Matcher; |
23 | 26 | import java.util.regex.Pattern; |
| 27 | +import java.util.stream.Collectors; |
24 | 28 | import java.util.stream.Stream; |
| 29 | +import java.util.stream.StreamSupport; |
25 | 30 |
|
26 | 31 | /** |
27 | 32 | * We need to inject our bundled Kotlin library files into the existing KotlinForForge jar instead of injecting |
@@ -210,18 +215,17 @@ public String name() { |
210 | 215 |
|
211 | 216 | public static boolean isJarJarKff(SecureJar jar) { |
212 | 217 | try { |
213 | | - Path jarjarPath = jar.getRootPath().resolve("META-INF").resolve("jarjar"); |
| 218 | + Path jarjarPath = jar.getRootPath().resolve("META-INF").resolve("jarjar").resolve("metadata.json"); |
214 | 219 | 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"); |
225 | 229 | } catch (Throwable t) { |
226 | 230 | LOGGER.error("Failed to determine version of potential KFF jar at " + jar + ":", t); |
227 | 231 | return false; |
|
0 commit comments