saner version and git hash config
This commit is contained in:
parent
88d9ecaecc
commit
b314a5217f
4 changed files with 19 additions and 30 deletions
|
@ -1,7 +1,7 @@
|
|||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
|
||||
plugins {
|
||||
kotlin("jvm") version "2.0.0"
|
||||
|
@ -28,29 +28,17 @@ dependencies {
|
|||
}
|
||||
|
||||
fun getGitCommitHash(): String {
|
||||
val outputStream = ByteArrayOutputStream()
|
||||
val result = project.exec {
|
||||
commandLine("git", "rev-parse", "HEAD")
|
||||
standardOutput = outputStream
|
||||
return try {
|
||||
val ref = Files.readAllLines(Paths.get(".git/HEAD"))[0].split(": ")[1]
|
||||
Files.readAllLines(Paths.get(".git/$ref"))[0].trim()
|
||||
} catch (e: Exception) {
|
||||
"unknown"
|
||||
}
|
||||
return if (result.exitValue == 0)
|
||||
outputStream.toString("UTF-8").trim()
|
||||
else
|
||||
"0000000000000000000000000000000000000000"
|
||||
}
|
||||
|
||||
val commitHash = getGitCommitHash()
|
||||
|
||||
val generateBuildConfigFile by tasks.registering(Task::class) {
|
||||
// surely there has to be a better way to do this
|
||||
doLast {
|
||||
val targetFile = file("src/main/kotlin/BuildConfig.kt")
|
||||
targetFile.writeText("""
|
||||
package burp
|
||||
|
||||
const val COMMIT_HASH = "$commitHash"
|
||||
const val VERSION = "$version"
|
||||
""".trimIndent())
|
||||
tasks.processResources {
|
||||
filesMatching("version.properties") {
|
||||
expand(mapOf("commitHash" to getGitCommitHash(), "version" to version))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,9 +46,6 @@ kotlin {
|
|||
compilerOptions.jvmTarget.set(JvmTarget.JVM_21)
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile> {
|
||||
dependsOn(generateBuildConfigFile)
|
||||
}
|
||||
|
||||
tasks.withType<ShadowJar> {
|
||||
exclude("**/*.kotlin_metadata")
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
package burp
|
||||
|
||||
const val COMMIT_HASH = "faa960a56eb8ecb74e6b021d97e6fbde5d623e68"
|
||||
const val VERSION = "0.3.0"
|
|
@ -4,9 +4,11 @@ import burp.api.montoya.BurpExtension
|
|||
import burp.api.montoya.MontoyaApi
|
||||
import burp.api.montoya.http.handler.*
|
||||
import burp.api.montoya.http.message.requests.HttpRequest
|
||||
import java.util.*
|
||||
|
||||
const val EXTENSION_NAME = "Value Autoupdater"
|
||||
|
||||
@Suppress("unused")
|
||||
class BurpExtender : BurpExtension {
|
||||
private lateinit var ui: UI
|
||||
private lateinit var items: ItemStore
|
||||
|
@ -21,6 +23,10 @@ class BurpExtender : BurpExtension {
|
|||
System.setOut(api.logging().output())
|
||||
System.setErr(api.logging().error())
|
||||
|
||||
val properties = Properties().apply {
|
||||
object {}.javaClass.classLoader.getResourceAsStream("version.properties").use { load(it) }
|
||||
}
|
||||
|
||||
this.api = api
|
||||
|
||||
api.extension().setName(EXTENSION_NAME)
|
||||
|
@ -31,7 +37,7 @@ class BurpExtender : BurpExtension {
|
|||
|
||||
api.http().registerHttpHandler(ExtHttpHandler())
|
||||
|
||||
log.info("Initialized $EXTENSION_NAME $VERSION (${COMMIT_HASH.take(8)})")
|
||||
log.info("Initialized $EXTENSION_NAME ${properties.getProperty("version")} (${properties.getProperty("commitHash").take(8)})")
|
||||
}
|
||||
|
||||
inner class ExtHttpHandler : HttpHandler {
|
||||
|
|
2
src/main/resources/version.properties
Normal file
2
src/main/resources/version.properties
Normal file
|
@ -0,0 +1,2 @@
|
|||
commitHash=${commitHash}
|
||||
version=${version}
|
Loading…
Reference in a new issue