|
|
@ -1,15 +1,11 @@ |
|
|
|
package dev.openrs2.util.io |
|
|
|
package dev.openrs2.util.io |
|
|
|
|
|
|
|
|
|
|
|
import com.google.common.jimfs.Configuration |
|
|
|
|
|
|
|
import com.google.common.jimfs.Jimfs |
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream |
|
|
|
import java.io.ByteArrayInputStream |
|
|
|
import java.io.ByteArrayOutputStream |
|
|
|
import java.io.ByteArrayOutputStream |
|
|
|
import java.nio.file.Files |
|
|
|
|
|
|
|
import java.nio.file.attribute.FileTime |
|
|
|
import java.nio.file.attribute.FileTime |
|
|
|
import java.util.jar.Attributes |
|
|
|
import java.util.jar.Attributes |
|
|
|
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.Manifest |
|
|
|
import java.util.jar.Manifest |
|
|
|
import kotlin.test.Test |
|
|
|
import kotlin.test.Test |
|
|
|
import kotlin.test.assertEquals |
|
|
|
import kotlin.test.assertEquals |
|
|
@ -27,7 +23,7 @@ object DeterministicJarOutputStreamTest { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun testPutNextEntry() { |
|
|
|
fun testPutNextEntry() { |
|
|
|
ByteArrayOutputStream().use { out -> |
|
|
|
ByteArrayOutputStream().use { out -> |
|
|
|
DeterministicJarOutputStream.create(out).use { jar -> |
|
|
|
DeterministicJarOutputStream(out).use { jar -> |
|
|
|
val entry = JarEntry("Hello.class") |
|
|
|
val entry = JarEntry("Hello.class") |
|
|
|
entry.creationTime = Y2K |
|
|
|
entry.creationTime = Y2K |
|
|
|
entry.lastAccessTime = Y2K |
|
|
|
entry.lastAccessTime = Y2K |
|
|
@ -55,7 +51,7 @@ object DeterministicJarOutputStreamTest { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun testManifest() { |
|
|
|
fun testManifest() { |
|
|
|
ByteArrayOutputStream().use { out -> |
|
|
|
ByteArrayOutputStream().use { out -> |
|
|
|
DeterministicJarOutputStream.create(out, manifest).use { jar -> |
|
|
|
DeterministicJarOutputStream(out, manifest).use { jar -> |
|
|
|
jar.putNextEntry(JarEntry("Hello.class")) |
|
|
|
jar.putNextEntry(JarEntry("Hello.class")) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -64,44 +60,4 @@ object DeterministicJarOutputStreamTest { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
fun testRepack() { |
|
|
|
|
|
|
|
Jimfs.newFileSystem(Configuration.unix()).use { fs -> |
|
|
|
|
|
|
|
val originalFile = Files.createTempFile(fs.getPath("/"), "original", ".jar") |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
JarOutputStream(Files.newOutputStream(originalFile)).use { jar -> |
|
|
|
|
|
|
|
val entry = JarEntry("Hello.class") |
|
|
|
|
|
|
|
entry.creationTime = Y2K |
|
|
|
|
|
|
|
entry.lastAccessTime = Y2K |
|
|
|
|
|
|
|
entry.lastModifiedTime = Y2K |
|
|
|
|
|
|
|
jar.putNextEntry(entry) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val repackedFile = Files.createTempFile(fs.getPath("/"), "repacked", ".jar") |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
DeterministicJarOutputStream.repack(originalFile, repackedFile) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JarInputStream(Files.newInputStream(repackedFile)).use { jar -> |
|
|
|
|
|
|
|
assertNull(jar.manifest) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val entry = jar.nextJarEntry |
|
|
|
|
|
|
|
assertNotNull(entry) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals("Hello.class", entry.name) |
|
|
|
|
|
|
|
assertEquals(0, entry.time) |
|
|
|
|
|
|
|
assertEquals(UNIX_EPOCH, entry.creationTime) |
|
|
|
|
|
|
|
assertEquals(UNIX_EPOCH, entry.lastAccessTime) |
|
|
|
|
|
|
|
assertEquals(UNIX_EPOCH, entry.lastModifiedTime) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertNull(jar.nextJarEntry) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
Files.deleteIfExists(repackedFile) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
Files.deleteIfExists(originalFile) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|