strip archives

reproducible
Zlatin Balevsky 2021-05-13 19:38:19 +01:00
parent f5783bbd86
commit 2831cfd43d
No known key found for this signature in database
GPG Key ID: A72832072D525E41
1 changed files with 23 additions and 0 deletions

View File

@ -34,5 +34,28 @@ subprojects {
tasks.withType(AbstractArchiveTask) {
preserveFileTimestamps = false
reproducibleFileOrder = true
doLast {
stripJar(it.archivePath)
}
}
}
import java.util.jar.*
void stripJar(File file) {
if (file.getName().endsWith('.tar'))
return
println "stripping $file"
File newFile = new File(file.parent, 'tmp-' + file.name)
newFile.withOutputStream { fout ->
JarOutputStream out = new JarOutputStream(fout)
JarFile jf = new JarFile(file)
jf.entries().unique {it.name}.sort {it.name}.each {
def copy = new JarEntry(it.name)
copy.time = 1001
out.putNextEntry(copy)
out << jf.getInputStream(it)
}
out.finish()
}
newFile.renameTo file
}