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 fab26bdd..88429dba 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 9a65fc1c..fd19642d 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) + } + } } }