Commit 4e5f2e31 authored by Torsten Grote's avatar Torsten Grote

Merge branch 'deterministic-briar-headless-jar' into 'master'

Make briar-headless.jar deterministic

See merge request !1282
parents 7ef2fb5f 518c0370
Pipeline #4816 passed with stage
in 9 minutes and 43 seconds
import java.util.jar.JarEntry
import java.util.jar.JarFile
import java.util.jar.JarOutputStream
import static java.util.Collections.list
plugins {
id 'java'
id 'idea'
......@@ -47,6 +53,34 @@ jar {
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
doLast() {
// Rename the original jar
File jar = project.jar.archivePath
String srcPath = jar.toString().replaceFirst('\\.jar$', '.unsorted.jar')
File srcFile = new File(srcPath)
jar.renameTo(srcFile)
JarFile srcJarFile = new JarFile(srcFile)
OutputStream destStream = new JarOutputStream(new FileOutputStream(jar))
// Read and sort the entries
Map<String, JarEntry> entries = new TreeMap<String, JarEntry>()
for (JarEntry e : list(srcJarFile.entries())) entries.put(e.getName(), e)
// Write the sorted entries
for (JarEntry srcEntry : entries.values()) {
JarEntry destEntry = new JarEntry(srcEntry.getName())
destEntry.setTime(0)
destStream.putNextEntry(destEntry)
InputStream srcStream = srcJarFile.getInputStream(srcEntry)
int read
byte[] buf = new byte[4096]
while ((read = srcStream.read(buf, 0, buf.length)) != -1) {
destStream.write(buf, 0, read)
}
destStream.closeEntry()
srcStream.close()
}
destStream.close()
srcJarFile.close()
}
}
// At the moment for non-Android projects we need to explicitly mark the code generated by kapt
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment