diff --git a/gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/task/DowngradeJar.kt b/gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/task/DowngradeJar.kt index de0c02ee..d2affdb7 100644 --- a/gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/task/DowngradeJar.kt +++ b/gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/task/DowngradeJar.kt @@ -56,7 +56,7 @@ abstract class DowngradeJar : Jar(), DowngradeFlags { ) } - inputFile.asFile.get().toPath().readZipInputStreamFor("META-INF/MANIFEST.MF", false) { inp -> + tempOutput.toPath().readZipInputStreamFor("META-INF/MANIFEST.MF", false) { inp -> // write to temp file val inpTmp = temporaryDir.toPath().resolve("input-manifest.MF") inpTmp.outputStream(StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING).use { out -> diff --git a/src/main/java/xyz/wagyourtail/jvmdg/cli/Flags.java b/src/main/java/xyz/wagyourtail/jvmdg/cli/Flags.java index 3206ea32..62c1a275 100644 --- a/src/main/java/xyz/wagyourtail/jvmdg/cli/Flags.java +++ b/src/main/java/xyz/wagyourtail/jvmdg/cli/Flags.java @@ -18,6 +18,8 @@ import java.util.Set; public class Flags { + public static final String jvmdgVersion = Flags.class.getPackage().getImplementationVersion(); + public int classVersion = Opcodes.V1_8; public File api = null; public boolean quiet = Boolean.getBoolean(Constants.QUIET); diff --git a/src/main/java/xyz/wagyourtail/jvmdg/compile/PathDowngrader.java b/src/main/java/xyz/wagyourtail/jvmdg/compile/PathDowngrader.java index bf7a58af..0b139e6a 100644 --- a/src/main/java/xyz/wagyourtail/jvmdg/compile/PathDowngrader.java +++ b/src/main/java/xyz/wagyourtail/jvmdg/compile/PathDowngrader.java @@ -1,11 +1,13 @@ package xyz.wagyourtail.jvmdg.compile; import xyz.wagyourtail.jvmdg.ClassDowngrader; +import xyz.wagyourtail.jvmdg.cli.Flags; import xyz.wagyourtail.jvmdg.util.*; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.lang.instrument.IllegalClassFormatException; import java.net.URL; import java.net.URLClassLoader; @@ -16,6 +18,8 @@ import java.util.*; import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicReference; +import java.util.jar.Attributes; +import java.util.jar.Manifest; public class PathDowngrader { @@ -118,6 +122,17 @@ public byte[] apply(String s) { throw new IOException("Failed to downgrade " + path, e); } } + } else if (path.toString().equals("META-INF/MANIFEST.MF")) { + // add version number to manifest + try(InputStream is = Files.newInputStream(path)) { + Manifest manifest = new Manifest(is); + Attributes attr = manifest.getMainAttributes(); + attr.put("JvmDowngrader-Version", Flags.jvmdgVersion); + + try (OutputStream os = Files.newOutputStream(outFile, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { + manifest.write(os); + } + } } else { // strip signatures since downgraded classes will not have the same signatures if (path.toString().startsWith("META-INF/") && (path.toString().endsWith(".SF") || path.toString().endsWith(".DSA") || path.toString().endsWith(".RSA"))) {