Skip to content

Commit

Permalink
more multi-release stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Jul 28, 2024
1 parent e995ce6 commit 633be8f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/shared/java/xyz/wagyourtail/jvmdg/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T extends Throwable> void sneakyThrow(Throwable t) throws T {
throw (T) t;
}
Expand Down

0 comments on commit 633be8f

Please sign in to comment.