Skip to content

Commit

Permalink
Store ret-core version in ret.json
Browse files Browse the repository at this point in the history
  • Loading branch information
martinvisser committed Sep 11, 2023
1 parent 9080720 commit a684d31
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 59 deletions.
16 changes: 13 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<kotlin.code.style>official</kotlin.code.style>
<kotlin.version>1.9.10</kotlin.version>
<maven.compiler.release>17</maven.compiler.release>
Expand All @@ -51,20 +52,21 @@
<jreleaser-maven-plugin.version>1.8.0</jreleaser-maven-plugin.version>
<ktlint-maven-plugin.version>2.0.0</ktlint-maven-plugin.version>
<maven-assembly-plugin.version>3.6.0</maven-assembly-plugin.version>
<maven-deploy-plugin.version>3.1.1</maven-deploy-plugin.version>
<maven-release-plugin.version>3.0.1</maven-release-plugin.version>
<maven-resources-plugin.version>3.3.1</maven-resources-plugin.version>
<maven-source-plugin.version>3.3.0</maven-source-plugin.version>
<os-maven-plugin.version>1.7.1</os-maven-plugin.version>
<quarkus.platform.version>3.3.1</quarkus.platform.version>
<quarkus.platform.version>3.3.2</quarkus.platform.version>
<surefire-plugin.version>3.1.2</surefire-plugin.version>
<versions-maven-plugin.version>2.16.0</versions-maven-plugin.version>

<assertj-core.version>3.24.2</assertj-core.version>
<commons-lang3.version>3.13.0</commons-lang3.version>
<detekt.version>1.23.1</detekt.version>
<maven-deploy-plugin.version>3.1.1</maven-deploy-plugin.version>
<maven-surefire-junit5-tree-reporter.version>1.2.1</maven-surefire-junit5-tree-reporter.version>
<mockito-kotlin.version>5.1.0</mockito-kotlin.version>
<quarkus-jgit.version>3.0.2</quarkus-jgit.version>
<quarkus-jgit.version>3.0.3</quarkus-jgit.version>
<quarkus-junit5-mockk.version>2.1.0</quarkus-junit5-mockk.version>
<sshd-core.version>2.10.0</sshd-core.version>
</properties>
Expand Down Expand Up @@ -475,6 +477,14 @@
<rulesUri>file:///${session.executionRootDirectory}/dependency-update-rules.xml</rulesUri>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven-resources-plugin.version}</version>
<configuration>
<propertiesEncoding>${project.build.sourceEncoding}</propertiesEncoding>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class PluginLoader(
environment.name,
executionContext.repositoryName(),
executionContext.branchName(),
executionContext.version(),
)

private companion object {
Expand Down
7 changes: 7 additions & 0 deletions ret-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@
<build>
<sourceDirectory>src/main/kotlin</sourceDirectory>
<testSourceDirectory>src/test/kotlin</testSourceDirectory>

<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.jboss.jandex</groupId>
Expand Down
2 changes: 2 additions & 0 deletions ret-core/src/main/kotlin/io/rabobank/ret/RetContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ 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(
val command: List<String> = emptyList(),
val environment: String? = null,
val gitRepository: String? = null,
val gitBranch: String? = null,
val version: String? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class RetConfig(
private val retConsole: RetConsole,
private val objectMapper: ObjectMapper,
private val configurables: Instance<Configurable>,
@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()
Expand Down
1 change: 1 addition & 0 deletions ret-core/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ret.version=@project.version@
quarkus.log.level=WARN
quarkus.log.category."io.rabobank".level=INFO
quarkus.log.file.enable=true
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -52,24 +51,25 @@ 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()) {
retConsole.out("Please fill in an answer")
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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
}
Expand All @@ -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",
),
)
}
Expand All @@ -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",
),
)
}
Expand All @@ -94,6 +97,7 @@ class PluginConfigureCommandTest {
val demoConfig = mapOf(
"project" to "oldProject",
"organisation" to "oldOrganisation",
"plugin_version" to "unknown",
)
storeConfig(demoConfig)

Expand All @@ -103,7 +107,7 @@ class PluginConfigureCommandTest {
command.run()

val pluginConfig = readConfig()
assertThat(pluginConfig).isEqualTo(demoConfig)
assertThat(pluginConfig).containsExactlyInAnyOrderEntriesOf(demoConfig)
}

private fun storeConfig(demoConfig: Map<String, String>) {
Expand Down

0 comments on commit a684d31

Please sign in to comment.