Add manifest support to writeJar

master
Graham 5 years ago
parent c6cf9a4d94
commit c769feab3e
  1. 11
      asm/src/main/java/dev/openrs2/asm/classpath/Library.kt
  2. 12
      common/src/main/java/dev/openrs2/common/io/DeterministicJarOutputStream.kt

@ -22,6 +22,7 @@ import java.util.TreeMap
import java.util.jar.JarEntry import java.util.jar.JarEntry
import java.util.jar.JarInputStream import java.util.jar.JarInputStream
import java.util.jar.JarOutputStream import java.util.jar.JarOutputStream
import java.util.jar.Manifest
import java.util.zip.GZIPInputStream import java.util.zip.GZIPInputStream
import java.util.zip.GZIPOutputStream import java.util.zip.GZIPOutputStream
@ -79,14 +80,16 @@ class Library constructor() : Iterable<ClassNode> {
} }
} }
fun writeJar(path: Path) { fun writeJar(path: Path, manifest: Manifest? = null) {
logger.info { "Writing jar $path" } logger.info { "Writing jar $path" }
Files.newOutputStream(path).use(::writeJar) Files.newOutputStream(path).use {
writeJar(it, manifest)
}
} }
fun writeJar(out: OutputStream) { fun writeJar(out: OutputStream, manifest: Manifest? = null) {
DeterministicJarOutputStream(out).use { jar -> DeterministicJarOutputStream.create(out, manifest).use { jar ->
for (clazz in classes.values) { for (clazz in classes.values) {
val writer = ClassWriter(0) val writer = ClassWriter(0)

@ -7,8 +7,8 @@ import java.util.jar.Manifest
import java.util.zip.ZipEntry import java.util.zip.ZipEntry
class DeterministicJarOutputStream : JarOutputStream { class DeterministicJarOutputStream : JarOutputStream {
constructor(out: OutputStream) : super(out) private constructor(out: OutputStream) : super(out)
constructor(out: OutputStream, man: Manifest) : super(out, man) private constructor(out: OutputStream, man: Manifest) : super(out, man)
override fun putNextEntry(ze: ZipEntry) { override fun putNextEntry(ze: ZipEntry) {
ze.creationTime = UNIX_EPOCH ze.creationTime = UNIX_EPOCH
@ -19,5 +19,13 @@ class DeterministicJarOutputStream : JarOutputStream {
companion object { companion object {
private val UNIX_EPOCH = FileTime.fromMillis(0) 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)
}
}
} }
} }

Loading…
Cancel
Save