From 633be8f578cd8c0fa7d82c7e58c5d3581317ac45 Mon Sep 17 00:00:00 2001 From: Wagyourtail Date: Sat, 27 Jul 2024 19:27:47 -0500 Subject: [PATCH] more multi-release stuff --- .../xyz/wagyourtail/jvmdg/compile/PathDowngrader.java | 8 +++++++- src/shared/java/xyz/wagyourtail/jvmdg/util/Utils.java | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/xyz/wagyourtail/jvmdg/compile/PathDowngrader.java b/src/main/java/xyz/wagyourtail/jvmdg/compile/PathDowngrader.java index aacb7543..2ff3488f 100644 --- a/src/main/java/xyz/wagyourtail/jvmdg/compile/PathDowngrader.java +++ b/src/main/java/xyz/wagyourtail/jvmdg/compile/PathDowngrader.java @@ -79,7 +79,10 @@ public void accept(Path path) throws IOException { Path outFile = out.resolve(relativized.toString()); if (path.getFileName().toString().endsWith(".class")) { if (relativized.startsWith("META-INF/versions")) { - Files.copy(path, outFile, StandardCopyOption.REPLACE_EXISTING); + String version = relativized.getName(2).toString(); + if (downgrader.flags.multiReleaseOriginal || downgrader.flags.multiReleaseVersions.contains(Utils.majorVersionToClassVersion(Integer.parseInt(version)))) { + Files.copy(path, outFile, StandardCopyOption.REPLACE_EXISTING); + } } else { try { String relativizedName = relativized.toString(); @@ -133,6 +136,9 @@ public byte[] apply(String s) { if (Flags.jvmdgVersion != null) { attr.putValue("JvmDowngrader-Version", Flags.jvmdgVersion); } + if (downgrader.flags.multiReleaseOriginal || !downgrader.flags.multiReleaseVersions.isEmpty()) { + attr.putValue("Multi-Release", "true"); + } try (OutputStream os = Files.newOutputStream(outFile, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { manifest.write(os); diff --git a/src/shared/java/xyz/wagyourtail/jvmdg/util/Utils.java b/src/shared/java/xyz/wagyourtail/jvmdg/util/Utils.java index 538edd02..6b6a5107 100644 --- a/src/shared/java/xyz/wagyourtail/jvmdg/util/Utils.java +++ b/src/shared/java/xyz/wagyourtail/jvmdg/util/Utils.java @@ -85,6 +85,11 @@ public static int classVersionToMajorVersion(int version) { else return version - Opcodes.V1_2 + 2; } + public static int majorVersionToClassVersion(int version) { + if (version == 1) return Opcodes.V1_1; + else return version + Opcodes.V1_2 - 2; + } + public static void sneakyThrow(Throwable t) throws T { throw (T) t; }