From a684d312d73dcdae307a8a566cb331fede4a158b Mon Sep 17 00:00:00 2001 From: Martin Visser Date: Wed, 6 Sep 2023 15:36:24 +0200 Subject: [PATCH] Store ret-core version in ret.json --- pom.xml | 16 +++++-- .../rabobank/ret/context/ExecutionContext.kt | 4 +- .../io/rabobank/ret/plugins/PluginLoader.kt | 1 + ret-core/pom.xml | 7 ++++ .../main/kotlin/io/rabobank/ret/RetContext.kt | 2 + .../rabobank/ret/configuration/RetConfig.kt | 2 +- .../src/main/resources/application.properties | 1 + .../ret/commands/ConfigureProjectCommand.kt | 42 ------------------- .../ret/commands/PluginConfigureCommand.kt | 16 +++---- .../commands/PluginConfigureCommandTest.kt | 12 ++++-- 10 files changed, 44 insertions(+), 59 deletions(-) delete mode 100644 ret-plugin/src/main/kotlin/io/rabobank/ret/commands/ConfigureProjectCommand.kt diff --git a/pom.xml b/pom.xml index f100039..22753bb 100644 --- a/pom.xml +++ b/pom.xml @@ -40,6 +40,7 @@ UTF-8 + UTF-8 official 1.9.10 17 @@ -51,20 +52,21 @@ 1.8.0 2.0.0 3.6.0 + 3.1.1 3.0.1 + 3.3.1 3.3.0 1.7.1 - 3.3.1 + 3.3.2 3.1.2 2.16.0 3.24.2 3.13.0 1.23.1 - 3.1.1 1.2.1 5.1.0 - 3.0.2 + 3.0.3 2.1.0 2.10.0 @@ -475,6 +477,14 @@ file:///${session.executionRootDirectory}/dependency-update-rules.xml + + org.apache.maven.plugins + maven-resources-plugin + ${maven-resources-plugin.version} + + ${project.build.sourceEncoding} + + diff --git a/ret-cli/src/main/kotlin/io/rabobank/ret/context/ExecutionContext.kt b/ret-cli/src/main/kotlin/io/rabobank/ret/context/ExecutionContext.kt index 181daf5..b3789ce 100644 --- a/ret-cli/src/main/kotlin/io/rabobank/ret/context/ExecutionContext.kt +++ b/ret-cli/src/main/kotlin/io/rabobank/ret/context/ExecutionContext.kt @@ -1,12 +1,14 @@ package io.rabobank.ret.context +import io.rabobank.ret.configuration.version.VersionProperties import jakarta.enterprise.context.ApplicationScoped @ApplicationScoped -class ExecutionContext { +class ExecutionContext(private val versionProperties: VersionProperties = VersionProperties()) { private val gitContext = GitContext.create() fun repositoryName() = gitContext?.repositoryName() fun branchName() = gitContext?.branchName() + fun version() = versionProperties.getAppVersion() } diff --git a/ret-cli/src/main/kotlin/io/rabobank/ret/plugins/PluginLoader.kt b/ret-cli/src/main/kotlin/io/rabobank/ret/plugins/PluginLoader.kt index b5711fe..7f136ef 100644 --- a/ret-cli/src/main/kotlin/io/rabobank/ret/plugins/PluginLoader.kt +++ b/ret-cli/src/main/kotlin/io/rabobank/ret/plugins/PluginLoader.kt @@ -81,6 +81,7 @@ class PluginLoader( environment.name, executionContext.repositoryName(), executionContext.branchName(), + executionContext.version(), ) private companion object { diff --git a/ret-core/pom.xml b/ret-core/pom.xml index ddf708e..71ec8cd 100644 --- a/ret-core/pom.xml +++ b/ret-core/pom.xml @@ -59,6 +59,13 @@ src/main/kotlin src/test/kotlin + + + + src/main/resources + true + + org.jboss.jandex diff --git a/ret-core/src/main/kotlin/io/rabobank/ret/RetContext.kt b/ret-core/src/main/kotlin/io/rabobank/ret/RetContext.kt index 200f6b2..0805020 100644 --- a/ret-core/src/main/kotlin/io/rabobank/ret/RetContext.kt +++ b/ret-core/src/main/kotlin/io/rabobank/ret/RetContext.kt @@ -13,6 +13,7 @@ import io.quarkus.runtime.annotations.RegisterForReflection * This is a custom environment variable, set by the caller. By default, it is "CLI". * @property gitRepository the Git repository, if RET was called from a Git directory. * @property gitBranch the current Git branch, if RET was called from a Git repository. + * @property version the current version of RET. */ @RegisterForReflection data class RetContext( @@ -20,4 +21,5 @@ data class RetContext( val environment: String? = null, val gitRepository: String? = null, val gitBranch: String? = null, + val version: String? = null, ) diff --git a/ret-core/src/main/kotlin/io/rabobank/ret/configuration/RetConfig.kt b/ret-core/src/main/kotlin/io/rabobank/ret/configuration/RetConfig.kt index 11febcd..238958d 100644 --- a/ret-core/src/main/kotlin/io/rabobank/ret/configuration/RetConfig.kt +++ b/ret-core/src/main/kotlin/io/rabobank/ret/configuration/RetConfig.kt @@ -24,7 +24,7 @@ class RetConfig( private val retConsole: RetConsole, private val objectMapper: ObjectMapper, private val configurables: Instance, - @ConfigProperty(name = "quarkus.application.version") private val retVersion: String, + @ConfigProperty(name = "ret.version") private val retVersion: String, ) : Config { private val oldConfigFile = osUtils.getRetHomeDirectory().resolve("ret.config").toFile() private val oldConfigFileBackup = osUtils.getRetHomeDirectory().resolve("ret.config.bak").toFile() diff --git a/ret-core/src/main/resources/application.properties b/ret-core/src/main/resources/application.properties index 012afee..01a49a7 100644 --- a/ret-core/src/main/resources/application.properties +++ b/ret-core/src/main/resources/application.properties @@ -1,3 +1,4 @@ +ret.version=@project.version@ quarkus.log.level=WARN quarkus.log.category."io.rabobank".level=INFO quarkus.log.file.enable=true diff --git a/ret-plugin/src/main/kotlin/io/rabobank/ret/commands/ConfigureProjectCommand.kt b/ret-plugin/src/main/kotlin/io/rabobank/ret/commands/ConfigureProjectCommand.kt deleted file mode 100644 index 927c12a..0000000 --- a/ret-plugin/src/main/kotlin/io/rabobank/ret/commands/ConfigureProjectCommand.kt +++ /dev/null @@ -1,42 +0,0 @@ -package io.rabobank.ret.commands - -import io.quarkus.runtime.annotations.RegisterForReflection -import io.rabobank.ret.RetContext -import io.rabobank.ret.configuration.RetConfig -import io.rabobank.ret.util.Logged -import picocli.CommandLine.Command -import picocli.CommandLine.Model.CommandSpec -import picocli.CommandLine.Spec -import java.io.File - -@Command( - name = "project", - hidden = true, -) -@RegisterForReflection(targets = [RetContext::class]) -@Logged -class ConfigureProjectCommand( - private val retConfig: RetConfig, -) : Runnable { - @Spec - lateinit var commandSpec: CommandSpec - - override fun run() { - val workingDir = File("").absoluteFile - - if (retConfig["projects"] == null) { - retConfig["projects"] = listOf(Project(workingDir.name, workingDir.absolutePath)) - } else { - @Suppress("UNCHECKED_CAST") - val projectsMap = retConfig["projects"] as MutableList - projectsMap += Project(workingDir.name, workingDir.absolutePath) - } - - retConfig.save() - } -} - -data class Project( - val name: String, - val path: String, -) diff --git a/ret-plugin/src/main/kotlin/io/rabobank/ret/commands/PluginConfigureCommand.kt b/ret-plugin/src/main/kotlin/io/rabobank/ret/commands/PluginConfigureCommand.kt index 96c4733..8b2526f 100644 --- a/ret-plugin/src/main/kotlin/io/rabobank/ret/commands/PluginConfigureCommand.kt +++ b/ret-plugin/src/main/kotlin/io/rabobank/ret/commands/PluginConfigureCommand.kt @@ -5,6 +5,7 @@ import io.quarkus.logging.Log import io.rabobank.ret.RetConsole import io.rabobank.ret.configuration.Config import io.rabobank.ret.configuration.ConfigurationProperty +import io.rabobank.ret.configuration.version.VersionProperties import io.rabobank.ret.util.Logged import picocli.CommandLine.Command import picocli.CommandLine.Model.CommandSpec @@ -21,15 +22,13 @@ import picocli.CommandLine.Spec @Command( name = "configure", hidden = true, - subcommands = [ - ConfigureProjectCommand::class, - ], ) @Logged class PluginConfigureCommand( private val config: Config, private val retConsole: RetConsole, private val objectMapper: ObjectMapper, + private val versionProperties: VersionProperties, ) : Runnable { @Spec lateinit var commandSpec: CommandSpec @@ -52,12 +51,13 @@ class PluginConfigureCommand( var hasPluginSpecificConfig = false val pluginConfigFile = config.pluginConfigDirectory().resolve("$pluginName.json").toFile() val pluginConfig = config.load() - val answers = pluginConfig.config + val config = pluginConfig.config + config["plugin_version"] = versionProperties.getAppVersion() - config.configure { + this.config.configure { hasPluginSpecificConfig = true val message = it.toMessage() - val currentValue = (answers[it.key] as String?).orEmpty() + val currentValue = (config[it.key] as String?).orEmpty() var input = retConsole.prompt(message, currentValue) while (it.required && input.ifEmpty { currentValue }.isEmpty()) { @@ -65,11 +65,11 @@ class PluginConfigureCommand( input = retConsole.prompt(message, currentValue) } - answers[it.key] = input.ifEmpty { currentValue } + config[it.key] = input.ifEmpty { currentValue } } if (hasPluginSpecificConfig) { - objectMapper.writerWithDefaultPrettyPrinter().writeValue(pluginConfigFile, answers) + objectMapper.writerWithDefaultPrettyPrinter().writeValue(pluginConfigFile, config) retConsole.out("Wrote configuration to $pluginConfigFile") } diff --git a/ret-plugin/src/test/kotlin/io/rabobank/ret/commands/PluginConfigureCommandTest.kt b/ret-plugin/src/test/kotlin/io/rabobank/ret/commands/PluginConfigureCommandTest.kt index 564d7b9..d95472e 100644 --- a/ret-plugin/src/test/kotlin/io/rabobank/ret/commands/PluginConfigureCommandTest.kt +++ b/ret-plugin/src/test/kotlin/io/rabobank/ret/commands/PluginConfigureCommandTest.kt @@ -5,6 +5,7 @@ import com.fasterxml.jackson.module.kotlin.readValue import io.mockk.every import io.mockk.mockk import io.rabobank.ret.RetConsole +import io.rabobank.ret.configuration.version.VersionProperties import org.apache.commons.io.FileUtils import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.AfterEach @@ -39,7 +40,7 @@ class PluginConfigureCommandTest { @BeforeEach fun before() { - command = PluginConfigureCommand(config, retConsole, jacksonObjectMapper()) + command = PluginConfigureCommand(config, retConsole, jacksonObjectMapper(), VersionProperties()) command.commandSpec = CommandSpec.create() .parent(CommandSpec.create().name(pluginName)) } @@ -57,10 +58,11 @@ class PluginConfigureCommandTest { command.run() val pluginConfig = readConfig() - assertThat(pluginConfig).isEqualTo( + assertThat(pluginConfig).containsExactlyInAnyOrderEntriesOf( mapOf( "project" to "myProject", "organisation" to "myOrganisation", + "plugin_version" to "unknown", ), ) } @@ -81,10 +83,11 @@ class PluginConfigureCommandTest { command.run() val pluginConfig = readConfig() - assertThat(pluginConfig).isEqualTo( + assertThat(pluginConfig).containsExactlyInAnyOrderEntriesOf( mapOf( "project" to "newProject", "organisation" to "newOrganisation", + "plugin_version" to "unknown", ), ) } @@ -94,6 +97,7 @@ class PluginConfigureCommandTest { val demoConfig = mapOf( "project" to "oldProject", "organisation" to "oldOrganisation", + "plugin_version" to "unknown", ) storeConfig(demoConfig) @@ -103,7 +107,7 @@ class PluginConfigureCommandTest { command.run() val pluginConfig = readConfig() - assertThat(pluginConfig).isEqualTo(demoConfig) + assertThat(pluginConfig).containsExactlyInAnyOrderEntriesOf(demoConfig) } private fun storeConfig(demoConfig: Map) {