mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-15 23:06:07 -04:00
Refactor build.gradle
This commit is contained in:
parent
3c2f232acb
commit
ace830bced
@ -1,5 +1,4 @@
|
|||||||
import java.nio.file.FileSystems
|
import java.nio.file.FileSystems
|
||||||
import java.nio.file.StandardOpenOption
|
|
||||||
import java.security.KeyFactory
|
import java.security.KeyFactory
|
||||||
import java.security.MessageDigest
|
import java.security.MessageDigest
|
||||||
import java.security.Signature
|
import java.security.Signature
|
||||||
@ -43,17 +42,27 @@ def attachSignature(File jar) {
|
|||||||
.sorted(Comparator.comparing { it.name })
|
.sorted(Comparator.comparing { it.name })
|
||||||
.filter { it.name != "META-INF/hmcl_signature" }
|
.filter { it.name != "META-INF/hmcl_signature" }
|
||||||
.forEach {
|
.forEach {
|
||||||
signer.update(digest("SHA-512", it.name.getBytes("UTF-8")))
|
signer.update(digest("SHA-512", it.name.getBytes("UTF-8")))
|
||||||
signer.update(digest("SHA-512", zip.getInputStream(it).bytes))
|
signer.update(digest("SHA-512", zip.getInputStream(it).bytes))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
def signature = signer.sign()
|
def signature = signer.sign()
|
||||||
|
|
||||||
FileSystems.newFileSystem(URI.create("jar:" + jar.toURI()), [:]).withCloseable { zipfs ->
|
FileSystems.newFileSystem(URI.create("jar:" + jar.toURI()), [:]).withCloseable { zipfs ->
|
||||||
Files.newOutputStream(zipfs.getPath("META-INF/hmcl_signature"), StandardOpenOption.CREATE, StandardOpenOption.WRITE).bytes = signature
|
Files.newOutputStream(zipfs.getPath("META-INF/hmcl_signature")).withCloseable { it.bytes = signature }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ext.packer = Pack200.newPacker()
|
||||||
|
packer.properties()["pack.effort"] = "9"
|
||||||
|
ext.unpacker = Pack200.newUnpacker()
|
||||||
|
|
||||||
|
def repack(File file) {
|
||||||
|
def packed = new ByteArrayOutputStream()
|
||||||
|
new JarFile(file).withCloseable { packer.pack(it, packed) }
|
||||||
|
new JarOutputStream(file.newOutputStream()).withCloseable { unpacker.unpack(new ByteArrayInputStream(packed.toByteArray()), it) }
|
||||||
|
}
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
|
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
|
||||||
|
|
||||||
@ -65,6 +74,7 @@ jar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
doLast {
|
doLast {
|
||||||
|
repack(archivePath)
|
||||||
attachSignature(archivePath)
|
attachSignature(archivePath)
|
||||||
createChecksum(archivePath)
|
createChecksum(archivePath)
|
||||||
}
|
}
|
||||||
@ -78,22 +88,12 @@ def createExecutable(String suffix, String header) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
task makePackGz(dependsOn: jar) doLast {
|
task makePackGz(dependsOn: jar) doLast {
|
||||||
def tmp = new File(project.buildDir, "tmp")
|
def outputPath = new File(jar.archivePath.parentFile, jar.archivePath.name[0..-4] + "pack.gz")
|
||||||
def unpackedJar = new File(tmp, jar.archivePath.name)
|
new GZIPOutputStream(outputPath.newOutputStream()).withCloseable { out ->
|
||||||
def packGz = new File(jar.archivePath.parentFile, jar.archivePath.name[0..-4] + "pack.gz")
|
new JarFile(jar.archivePath).withCloseable { jarFile -> packer.pack(jarFile, out) }
|
||||||
|
|
||||||
def originalStream = new ByteArrayOutputStream()
|
|
||||||
def unpackedJarStream = new JarOutputStream(new FileOutputStream(unpackedJar))
|
|
||||||
Pack200.newPacker().pack(new JarFile(jar.archivePath), originalStream)
|
|
||||||
Pack200.newUnpacker().unpack(new ByteArrayInputStream(originalStream.toByteArray()), unpackedJarStream)
|
|
||||||
unpackedJarStream.close()
|
|
||||||
attachSignature(unpackedJar)
|
|
||||||
|
|
||||||
new GZIPOutputStream(new FileOutputStream(packGz)).withCloseable { stream ->
|
|
||||||
Pack200.newPacker().pack(new JarFile(unpackedJar), stream)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
createChecksum(packGz)
|
createChecksum(outputPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user