From c769feab3ea3a258bba2e5f4aa6d1bbcd45a52dc Mon Sep 17 00:00:00 2001 From: Graham Date: Tue, 14 Jan 2020 22:14:03 +0000 Subject: [PATCH] Add manifest support to writeJar --- .../main/java/dev/openrs2/asm/classpath/Library.kt | 11 +++++++---- .../common/io/DeterministicJarOutputStream.kt | 12 ++++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/asm/src/main/java/dev/openrs2/asm/classpath/Library.kt b/asm/src/main/java/dev/openrs2/asm/classpath/Library.kt index fab26bdded..88429dba1f 100644 --- a/asm/src/main/java/dev/openrs2/asm/classpath/Library.kt +++ b/asm/src/main/java/dev/openrs2/asm/classpath/Library.kt @@ -22,6 +22,7 @@ import java.util.TreeMap import java.util.jar.JarEntry import java.util.jar.JarInputStream import java.util.jar.JarOutputStream +import java.util.jar.Manifest import java.util.zip.GZIPInputStream import java.util.zip.GZIPOutputStream @@ -79,14 +80,16 @@ class Library constructor() : Iterable { } } - fun writeJar(path: Path) { + fun writeJar(path: Path, manifest: Manifest? = null) { logger.info { "Writing jar $path" } - Files.newOutputStream(path).use(::writeJar) + Files.newOutputStream(path).use { + writeJar(it, manifest) + } } - fun writeJar(out: OutputStream) { - DeterministicJarOutputStream(out).use { jar -> + fun writeJar(out: OutputStream, manifest: Manifest? = null) { + DeterministicJarOutputStream.create(out, manifest).use { jar -> for (clazz in classes.values) { val writer = ClassWriter(0) diff --git a/common/src/main/java/dev/openrs2/common/io/DeterministicJarOutputStream.kt b/common/src/main/java/dev/openrs2/common/io/DeterministicJarOutputStream.kt index 9a65fc1c64..fd19642d05 100644 --- a/common/src/main/java/dev/openrs2/common/io/DeterministicJarOutputStream.kt +++ b/common/src/main/java/dev/openrs2/common/io/DeterministicJarOutputStream.kt @@ -7,8 +7,8 @@ import java.util.jar.Manifest import java.util.zip.ZipEntry class DeterministicJarOutputStream : JarOutputStream { - constructor(out: OutputStream) : super(out) - constructor(out: OutputStream, man: Manifest) : super(out, man) + private constructor(out: OutputStream) : super(out) + private constructor(out: OutputStream, man: Manifest) : super(out, man) override fun putNextEntry(ze: ZipEntry) { ze.creationTime = UNIX_EPOCH @@ -19,5 +19,13 @@ class DeterministicJarOutputStream : JarOutputStream { companion object { private val UNIX_EPOCH = FileTime.fromMillis(0) + + fun create(out: OutputStream, manifest: Manifest? = null): JarOutputStream { + return if (manifest != null) { + DeterministicJarOutputStream(out, manifest) + } else { + DeterministicJarOutputStream(out) + } + } } }