Skip to content

Commit

Permalink
Log java version on startup
Browse files Browse the repository at this point in the history
PR: #54
  • Loading branch information
EdwarDDay authored Jan 5, 2025
1 parent c1a97bb commit fd92c4d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
timeout-minutes: 1
run: |
version="$(cat gradle.properties | sed -n 's/version=//p')"
hostVersion=$(./scripting-host-release/bin/kss --version)
hostVersion=$(./scripting-host-release/bin/kss --version | grep "Version: ")
if [ "$hostVersion" != "Version: $version" ]; then
echo "host version ($hostVersion) doesn't match gradle properties version ($version)"
exit 1
Expand Down
13 changes: 9 additions & 4 deletions scripting-host/src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ private const val CONFIG_FILE_NAME = "kss.properties"
suspend fun main(args: Array<String>) = Main().main(args)

private class Main : SuspendingCliktCommand() {
val version by option("-v", "--version", help = "Print current version").flag()

private fun readPropertiesFromClasspath(fileName: String): Properties? {
return Thread.currentThread()
.getContextClassLoader()
Expand All @@ -41,6 +43,7 @@ private class Main : SuspendingCliktCommand() {
}
}
}

private fun loadProperties(): Properties {
// load default config
val defaultConfig = try {
Expand All @@ -65,14 +68,14 @@ private class Main : SuspendingCliktCommand() {
}
return commandLineConfig
}
val version by option("-v", "--version", help = "Print current version").flag()

override suspend fun run() {
val appVersion = kotlin.runCatching {
readPropertiesFromClasspath("version.properties")?.getProperty("version")
}.getOrElse { "<unknown>" }
if (version) {
val appVersion = kotlin.runCatching {
readPropertiesFromClasspath("version.properties")
}.getOrNull()?.getProperty("version") ?: "<unknown>"
echo("Version: $appVersion")
echo("Java version: ${Runtime.version()}")
return
}
val properties = loadProperties()
Expand All @@ -84,6 +87,8 @@ private class Main : SuspendingCliktCommand() {

val logger = KotlinLogging.logger {}

logger.info { "Version: $appVersion" }
logger.info { ("Java version: ${Runtime.version()}") }

val mavenDependenciesSettings = properties.getProperty("dependencies.maven.settingsFile").orEmpty()
val mavenDependenciesHome = properties.getProperty("dependencies.maven.homeDirectory").orEmpty()
Expand Down

0 comments on commit fd92c4d

Please sign in to comment.