From 483b9da8b7b7850389dc259127bc226311dde1b2 Mon Sep 17 00:00:00 2001 From: Hanno Fellmann Date: Fri, 27 Oct 2023 12:13:08 +0200 Subject: [PATCH] add sha generation --- build.gradle.kts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 8c237a63..26de4f81 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,8 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import org.jetbrains.dokka.gradle.DokkaTask +import java.io.OutputStream +import java.security.DigestOutputStream +import java.security.MessageDigest plugins { id("org.jetbrains.kotlin.jvm") version "1.8.20" // Apply the Kotlin JVM plugin to add support for Kotlin. @@ -188,4 +191,19 @@ tasks { test { jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED") } -} \ No newline at end of file + shadowJar { + doLast { + println(calcSha1(File("$buildDir/libs/$executableName.jar"))) + } + } +} + +fun calcSha1(file: File): String { + val md = DigestOutputStream( + OutputStream.nullOutputStream(), MessageDigest.getInstance("SHA-1") + ) + file.inputStream().copyTo(md) + return md.messageDigest.digest().toHex() +} + +fun ByteArray.toHex() = joinToString(separator = "") { eachByte -> "%02x".format(eachByte) }