-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split initialize and configure into two separate sub-commands
- Loading branch information
1 parent
9f5fe34
commit 7d16e62
Showing
16 changed files
with
284 additions
and
314 deletions.
There are no files selected for viewing
4 changes: 1 addition & 3 deletions
4
ret-cli/src/main/kotlin/io/rabobank/ret/context/ExecutionContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
package io.rabobank.ret.context | ||
|
||
import io.rabobank.ret.configuration.version.VersionProperties | ||
import jakarta.enterprise.context.ApplicationScoped | ||
|
||
@ApplicationScoped | ||
class ExecutionContext(private val versionProperties: VersionProperties = VersionProperties()) { | ||
class ExecutionContext { | ||
|
||
private val gitContext = GitContext.create() | ||
|
||
fun repositoryName() = gitContext?.repositoryName() | ||
fun branchName() = gitContext?.branchName() | ||
fun version() = versionProperties.getAppVersion() | ||
} |
35 changes: 35 additions & 0 deletions
35
ret-cli/src/main/kotlin/io/rabobank/ret/plugins/PluginConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.rabobank.ret.plugins | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.module.kotlin.readValue | ||
import io.rabobank.ret.plugin.Plugin | ||
import io.rabobank.ret.plugin.PluginDefinition | ||
import io.rabobank.ret.util.OsUtils | ||
import jakarta.enterprise.context.ApplicationScoped | ||
import jakarta.enterprise.inject.Produces | ||
import java.nio.file.Path | ||
import kotlin.io.path.ExperimentalPathApi | ||
import kotlin.io.path.walk | ||
|
||
@ApplicationScoped | ||
class PluginConfiguration { | ||
|
||
companion object { | ||
const val PLUGIN_EXTENSION = "plugin" | ||
} | ||
|
||
@OptIn(ExperimentalPathApi::class) | ||
@Produces | ||
@ApplicationScoped | ||
fun plugins(osUtils: OsUtils, objectMapper: ObjectMapper): List<Plugin> = | ||
osUtils.getRetPluginsDirectory().let { pluginPath -> | ||
pluginPath.walk() | ||
.map(Path::toFile) | ||
.filter { it.extension == PLUGIN_EXTENSION } | ||
.map { objectMapper.readValue<PluginDefinition>(it.readText()) } | ||
.map { Plugin(it, pluginPath.resolve(it.dylibFile())) } | ||
.toList() | ||
} | ||
|
||
private fun PluginDefinition.dylibFile() = libName.takeIf { it.endsWith(".dylib") } ?: "$libName.dylib" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
ret-core/src/main/kotlin/io/rabobank/ret/configuration/ConfigurablePlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.rabobank.ret.configuration | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.module.kotlin.readValue | ||
import io.rabobank.ret.util.OsUtils | ||
import jakarta.enterprise.context.Dependent | ||
import jakarta.inject.Inject | ||
import org.eclipse.microprofile.config.inject.ConfigProperty | ||
|
||
/** | ||
* Extend from this base plugin class to help out with loading plugin specific configuration. | ||
* This class also implements [Configurable] with a default implementation of [properties] with an empty list. | ||
* | ||
* @see Configurable | ||
*/ | ||
@Dependent | ||
open class ConfigurablePlugin : Configurable { | ||
@ConfigProperty(name = "plugin.name", defaultValue = "ret") | ||
lateinit var pluginName: String | ||
|
||
@Inject | ||
lateinit var osUtils: OsUtils | ||
|
||
@Inject | ||
lateinit var objectMapper: ObjectMapper | ||
|
||
val config by lazy { | ||
runCatching { objectMapper.readValue<Map<String, String>>(osUtils.getPluginConfig(pluginName).toFile()) } | ||
.getOrDefault(emptyMap()) | ||
} | ||
|
||
override fun properties() = emptyList<ConfigurationProperty>() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
ret-plugin/src/main/kotlin/io/rabobank/ret/commands/ConfigureProjectCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package io.rabobank.ret.commands | ||
|
||
import io.quarkus.runtime.annotations.RegisterForReflection | ||
import io.rabobank.ret.RetContext | ||
import io.rabobank.ret.configuration.RetConfig | ||
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]) | ||
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<Project> | ||
projectsMap += Project(workingDir.name, workingDir.absolutePath) | ||
} | ||
|
||
retConfig.save() | ||
} | ||
} | ||
|
||
data class Project( | ||
val name: String, | ||
val path: String, | ||
) |
Oops, something went wrong.