@@ -70,17 +70,29 @@ for (packageDir in file("src/main/files/packages").listFiles()!!) {
7070 into(destinationDir)
7171 val shasumFile = destinationDir.map { it.file(" ${packageDir.name} .json.sha256" ) }
7272 outputs.file(shasumFile)
73+ val hexDigits =
74+ charArrayOf(' 0' , ' 1' , ' 2' , ' 3' , ' 4' , ' 5' , ' 6' , ' 7' , ' 8' , ' 9' , ' a' , ' b' , ' c' , ' d' , ' e' , ' f' )
75+ val computeChecksum: (File ) -> String = { file ->
76+ val hash = MessageDigest .getInstance(" SHA-256" ).digest(file.readBytes())
77+ buildString(hash.size * 2 ) {
78+ for (b in hash) {
79+ append(hexDigits[b.toInt() shr 4 and 0xF ])
80+ append(hexDigits[b.toInt() and 0xF ])
81+ }
82+ }
83+ }
7384 filter { line ->
74- line.replaceFirst(" \$ computedChecksum" , archiveFile.get().asFile.computeChecksum( ))
85+ line.replaceFirst(" \$ computedChecksum" , computeChecksum( archiveFile.get().asFile))
7586 }
87+ val isWindows = buildInfo.os.isWindows
7688 doLast {
7789 val outputFile = destinationDir.get().asFile.resolve(" ${packageDir.name} .json" )
78- if (buildInfo.os. isWindows) {
90+ if (isWindows) {
7991 val contents = outputFile.readText()
8092 // workaround for https://github.com/gradle/gradle/issues/1151
8193 outputFile.writeText(contents.replace(" \r\n " , " \n " ))
8294 }
83- shasumFile.get().asFile.writeText(outputFile. computeChecksum())
95+ shasumFile.get().asFile.writeText(computeChecksum(outputFile ))
8496 }
8597 }
8698
@@ -111,6 +123,9 @@ val generateKeys by
111123 " CN=localhost" ,
112124 )
113125 workingDir(keystoreDir)
126+ // capture keystoreFile inside closure so we don't reference `this$0`; which breaks Gradle
127+ // configuration cache
128+ val keystoreFile = keystoreFile
114129 doFirst {
115130 workingDir.mkdirs()
116131 keystoreFile.get().asFile.delete()
@@ -143,20 +158,3 @@ val exportCerts by
143158 outputFile.get().asFile.delete()
144159 }
145160 }
146-
147- fun toHex (hash : ByteArray ): String {
148- val hexDigitTable =
149- charArrayOf(' 0' , ' 1' , ' 2' , ' 3' , ' 4' , ' 5' , ' 6' , ' 7' , ' 8' , ' 9' , ' a' , ' b' , ' c' , ' d' , ' e' , ' f' )
150- return buildString(hash.size * 2 ) {
151- for (b in hash) {
152- append(hexDigitTable[b.toInt() shr 4 and 0xF ])
153- append(hexDigitTable[b.toInt() and 0xF ])
154- }
155- }
156- }
157-
158- fun File.computeChecksum (): String {
159- val md = MessageDigest .getInstance(" SHA-256" )
160- val hash = md.digest(readBytes())
161- return toHex(hash)
162- }
0 commit comments