add version info output

This commit is contained in:
ansgarz 2024-12-11 22:02:11 +01:00
parent 0af6f8ebc2
commit 8d9de5517a
6 changed files with 49 additions and 13 deletions

View file

@ -234,3 +234,20 @@ publishing {
} }
} }
} }
// create version file to allow Kotlin code to print own version - see https://stackoverflow.com/questions/33020069/how-to-get-version-attribute-from-a-gradle-build-to-be-included-in-runtime-swing
tasks.register('createVersion') {
dependsOn processResources
doLast {
def version = project.version.toString() + " (" + Instant.now().toString().split("\\.")[0] + ")"
def fileName = "src/main/resources/version.txt"
def file = new File(fileName)
file.write(version)
println "Created file: " + fileName
}
}
classes {
dependsOn createVersion
}

View file

@ -6,6 +6,7 @@ import org.domaindrivenarchitecture.provs.desktop.domain.DesktopConfig
import org.domaindrivenarchitecture.provs.desktop.domain.provisionDesktopCommand import org.domaindrivenarchitecture.provs.desktop.domain.provisionDesktopCommand
import org.domaindrivenarchitecture.provs.desktop.infrastructure.getConfig import org.domaindrivenarchitecture.provs.desktop.infrastructure.getConfig
import org.domaindrivenarchitecture.provs.framework.core.cli.createProvInstance import org.domaindrivenarchitecture.provs.framework.core.cli.createProvInstance
import org.domaindrivenarchitecture.provs.framework.core.cli.printProvsVersion
import org.domaindrivenarchitecture.provs.framework.core.cli.quit import org.domaindrivenarchitecture.provs.framework.core.cli.quit
import java.io.FileNotFoundException import java.io.FileNotFoundException
import java.nio.file.Files import java.nio.file.Files
@ -17,6 +18,8 @@ import kotlin.system.exitProcess
*/ */
fun main(args: Array<String>) { fun main(args: Array<String>) {
printProvsVersion()
val cmd = CliArgumentsParser("provs-desktop.jar subcommand target").parseCommand(args) val cmd = CliArgumentsParser("provs-desktop.jar subcommand target").parseCommand(args)
if (!cmd.isValid()) { if (!cmd.isValid()) {
println("Arguments are not valid, pls try option -h for help.") println("Arguments are not valid, pls try option -h for help.")
@ -31,12 +34,12 @@ fun main(args: Array<String>) {
val configFileName = cmd.configFile?.fileName ?: defaultConfigFileName val configFileName = cmd.configFile?.fileName ?: defaultConfigFileName
try { try {
getConfig(configFileName) getConfig(configFileName)
} catch (e: SerializationException) { } catch (_: SerializationException) {
println( println(
"Error: File \"${configFileName}\" has an invalid format and or invalid data." "Error: File \"${configFileName}\" has an invalid format and or invalid data."
) )
null null
} catch (e: FileNotFoundException) { } catch (_: FileNotFoundException) {
println( println(
"Error: File\u001b[31m $configFileName \u001b[0m was not found.\n" + "Error: File\u001b[31m $configFileName \u001b[0m was not found.\n" +
"Pls copy file \u001B[31m desktop-config-example.yaml \u001B[0m to file \u001B[31m $configFileName \u001B[0m " + "Pls copy file \u001B[31m desktop-config-example.yaml \u001B[0m to file \u001B[31m $configFileName \u001B[0m " +

View file

@ -35,6 +35,20 @@ fun createProvInstance(targetCommand: TargetCliCommand): Prov {
} }
/**
* Wrapper for exitProcess, which allows e.g. mocking for test purposes
*/
fun quit(status: Int): Nothing {
exitProcess(status)
}
fun printProvsVersion() {
val version = object {}.javaClass.getResource("/version.txt")?.readText()?.trim()
println("Provs version: $version")
}
internal fun createRemoteProvInstance( internal fun createRemoteProvInstance(
target: TargetCliCommand.RemoteTarget?, target: TargetCliCommand.RemoteTarget?,
password: Secret? = null password: Secret? = null
@ -52,11 +66,3 @@ internal fun createRemoteProvInstance(
internal fun getPasswordToConfigureSudoWithoutPassword(): Secret { internal fun getPasswordToConfigureSudoWithoutPassword(): Secret {
return PromptSecretSource("password to configure sudo without password.").secret() return PromptSecretSource("password to configure sudo without password.").secret()
} }
/**
* Wrapper for exitProcess, which allows e.g. mocking for test purposes
*/
fun quit(status: Int): Nothing {
exitProcess(status)
}

View file

@ -2,6 +2,7 @@ package org.domaindrivenarchitecture.provs.server.application
import org.domaindrivenarchitecture.provs.configuration.application.ensureSudoWithoutPassword import org.domaindrivenarchitecture.provs.configuration.application.ensureSudoWithoutPassword
import org.domaindrivenarchitecture.provs.framework.core.cli.createProvInstance import org.domaindrivenarchitecture.provs.framework.core.cli.createProvInstance
import org.domaindrivenarchitecture.provs.framework.core.cli.printProvsVersion
import org.domaindrivenarchitecture.provs.framework.core.cli.quit import org.domaindrivenarchitecture.provs.framework.core.cli.quit
import org.domaindrivenarchitecture.provs.server.domain.ServerType import org.domaindrivenarchitecture.provs.server.domain.ServerType
import org.domaindrivenarchitecture.provs.server.domain.k3s.K3sCliCommand import org.domaindrivenarchitecture.provs.server.domain.k3s.K3sCliCommand
@ -17,6 +18,8 @@ import kotlin.system.exitProcess
*/ */
fun main(args: Array<String>) { fun main(args: Array<String>) {
printProvsVersion()
val checkedArgs = if (args.isEmpty()) arrayOf("-h") else args val checkedArgs = if (args.isEmpty()) arrayOf("-h") else args
// validate subcommand // validate subcommand

View file

@ -0,0 +1 @@
0.39.3-SNAPSHOT (2024-12-11T20:58:26)

View file

@ -15,7 +15,7 @@ import org.domaindrivenarchitecture.provs.framework.core.cli.quit
import org.domaindrivenarchitecture.provs.framework.core.processors.DummyProcessor import org.domaindrivenarchitecture.provs.framework.core.processors.DummyProcessor
import org.domaindrivenarchitecture.provs.test.setRootLoggingLevel import org.domaindrivenarchitecture.provs.test.setRootLoggingLevel
import org.junit.jupiter.api.AfterAll import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows import org.junit.jupiter.api.assertThrows
@ -116,7 +116,10 @@ internal class ApplicationKtTest {
val expectedOutput = val expectedOutput =
"Error: File\u001B[31m idontexist.yaml \u001B[0m was not found.Pls copy file \u001B[31m desktop-config-example.yaml \u001B[0m to file \u001B[31m idontexist.yaml \u001B[0m and change the content according to your needs.No suitable config found." "Error: File\u001B[31m idontexist.yaml \u001B[0m was not found.Pls copy file \u001B[31m desktop-config-example.yaml \u001B[0m to file \u001B[31m idontexist.yaml \u001B[0m and change the content according to your needs.No suitable config found."
assertEquals(expectedOutput, outContent.toString().replace("\r", "").replace("\n", "")) assertTrue(
outContent.toString().replace("\r", "").replace("\n", "").contains(expectedOutput),
"$expectedOutput\nnot found in:\n$outContent"
)
verify(exactly = 0) { any<Prov>().provisionDesktop(any(), any(), any(), any(), any()) } verify(exactly = 0) { any<Prov>().provisionDesktop(any(), any(), any(), any(), any()) }
@ -150,7 +153,10 @@ internal class ApplicationKtTest {
val expectedOutput = val expectedOutput =
"Error: File \"src/test/resources/invalid-desktop-config.yaml\" has an invalid format and or invalid data.No suitable config found." "Error: File \"src/test/resources/invalid-desktop-config.yaml\" has an invalid format and or invalid data.No suitable config found."
assertEquals(expectedOutput, outContent.toString().replace("\r", "").replace("\n", "")) assertTrue(
outContent.toString().replace("\r", "").replace("\n", "").contains(expectedOutput),
"$expectedOutput\nnot found in:\n$outContent"
)
verify(exactly = 0) { any<Prov>().provisionDesktop(any(), any(), any(), any(), any()) } verify(exactly = 0) { any<Prov>().provisionDesktop(any(), any(), any(), any(), any()) }