Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@
<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>2.2.0</kotlin.version>
<kotlin.version>2.2.10</kotlin.version>
<maven.compiler.release>21</maven.compiler.release>

<compiler-plugin.version>3.14.0</compiler-plugin.version>
<dokka-maven-plugin.version>2.0.0</dokka-maven-plugin.version>
<git-commit-id.version>9.0.2</git-commit-id.version>
<jandex-maven-plugin.version>1.2.3</jandex-maven-plugin.version>
<jreleaser-maven-plugin.version>1.19.0</jreleaser-maven-plugin.version>
<jreleaser-maven-plugin.version>1.20.0</jreleaser-maven-plugin.version>
<ktlint-maven-plugin.version>3.5.0</ktlint-maven-plugin.version>
<maven-assembly-plugin.version>3.7.1</maven-assembly-plugin.version>
<maven-deploy-plugin.version>3.1.4</maven-deploy-plugin.version>
Expand All @@ -57,18 +57,18 @@
<maven-resources-plugin.version>3.3.1</maven-resources-plugin.version>
<maven-source-plugin.version>3.3.1</maven-source-plugin.version>
<os-maven-plugin.version>1.7.1</os-maven-plugin.version>
<quarkus.platform.version>3.25.0</quarkus.platform.version>
<quarkus.platform.version>3.26.2</quarkus.platform.version>
<surefire-plugin.version>3.5.3</surefire-plugin.version>
<versions-maven-plugin.version>2.18.0</versions-maven-plugin.version>
<versions-maven-plugin.version>2.19.0</versions-maven-plugin.version>

<assertj-core.version>3.27.3</assertj-core.version>
<assertj-core.version>3.27.4</assertj-core.version>
<commons-lang3.version>3.18.0</commons-lang3.version>
<detekt.version>1.23.8</detekt.version>
<maven-surefire-junit5-tree-reporter.version>1.4.0</maven-surefire-junit5-tree-reporter.version>
<mockito-kotlin.version>5.1.0</mockito-kotlin.version>
<quarkus-jgit.version>3.3.3</quarkus-jgit.version>
<quarkus-jgit.version>3.6.0</quarkus-jgit.version>
<quarkus-junit5-mockk.version>3.1.0</quarkus-junit5-mockk.version>
<sshd-core.version>2.15.0</sshd-core.version>
<sshd-core.version>2.16.0</sshd-core.version>
</properties>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import picocli.CommandLine.Model.CommandSpec
private const val SHEBANG = "#!/bin/zsh"

@ApplicationScoped
class ZshAutocompletionGenerator(private val template: ZshAutocompletionTemplate) {
class ZshAutocompletionGenerator(
private val template: ZshAutocompletionTemplate,
) {
/**
* This function generates the full ZSH autocompletion script for the command that's provided and all subcommands
*/
Expand All @@ -23,8 +25,10 @@ class ZshAutocompletionGenerator(private val template: ZshAutocompletionTemplate
}

private fun loadLinesForResource() =
ZshAutocompletionGenerator::class.java.getResourceAsStream("/autocompletion/zsh/footer.sh")
?.bufferedReader()?.lines()
ZshAutocompletionGenerator::class.java
.getResourceAsStream("/autocompletion/zsh/footer.sh")
?.bufferedReader()
?.lines()
?: error("Cannot find footer.sh for the autocompletion script")

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ function $functionName() {
): List<ArgumentSpecActionPair> {
val overviewValues =
subcommands.joinToString(" ") {
val description = it.commandSpec.usageMessage().description().firstOrNull() ?: ""
val description =
it.commandSpec
.usageMessage()
.description()
.firstOrNull() ?: ""
"'${it.commandName}[$description]'"
}

Expand Down Expand Up @@ -110,7 +114,11 @@ function $functionName() {

private fun generatePositionalParameterSpecActionPairs(positionalParameters: List<PositionalParamSpec>) =
positionalParameters.withIndex().mapNotNull {
val description = it.value.description().joinToString("").ifEmpty { " " }
val description =
it.value
.description()
.joinToString("")
.ifEmpty { " " }
val index = it.index + 1

when (val action = generateAutocompleteAction(it.value.completionCandidates())) {
Expand Down Expand Up @@ -153,12 +161,20 @@ function $functionName() {
* This data class holds the spec which will be added to ZSH's _arguments method,
* and the action describes what's done when a certain argument spec is matched.
*/
data class ArgumentSpecActionPair(val spec: String, val action: String? = null)
data class ArgumentSpecActionPair(
val spec: String,
val action: String? = null,
)

sealed interface AutoCompleteAction

data object NoAction : AutoCompleteAction

data class FunctionCallAction(val functionName: String) : AutoCompleteAction
data class FunctionCallAction(
val functionName: String,
) : AutoCompleteAction

data class StaticValuesAction(val staticValues: String) : AutoCompleteAction
data class StaticValuesAction(
val staticValues: String,
) : AutoCompleteAction
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ import picocli.CommandLine.Help.Ansi.AUTO
import picocli.CommandLine.Help.ColorScheme

@ApplicationScoped
class CommandLineConfiguration(private val pluginLoader: PluginLoader) {
class CommandLineConfiguration(
private val pluginLoader: PluginLoader,
) {
@Produces
fun customCommandLine(
factory: PicocliCommandLineFactory,
retConsole: RetConsole,
): CommandLine {
val commandLine =
factory.create()
factory
.create()
.setExecutionExceptionHandler(ExceptionMessageHandler(retConsole))
.setExecutionStrategy { CommandLine.RunLast().execute(it) }
.setColorScheme(ColorScheme.Builder().ansi(AUTO).build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ class EnvironmentManager {
runCatching {
Log.debug("ret.env value is $retEnvironment")
valueOf(retEnvironment)
}
.getOrDefault(CLI)
}.getOrDefault(CLI)
}

enum class Environment(val recordMetrics: Boolean) {
enum class Environment(
val recordMetrics: Boolean,
) {
CLI(true),
ZSH_AUTOCOMPLETE(false),
ALFRED(true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import picocli.CommandLine
import picocli.CommandLine.IExecutionExceptionHandler
import picocli.CommandLine.ParseResult

class ExceptionMessageHandler(private val retConsole: RetConsole) : IExecutionExceptionHandler {
class ExceptionMessageHandler(
private val retConsole: RetConsole,
) : IExecutionExceptionHandler {
override fun handleExecutionException(
ex: Exception,
commandLine: CommandLine,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import io.rabobank.ret.configuration.version.VersionProperties
import jakarta.enterprise.context.ApplicationScoped

@ApplicationScoped
class ExecutionContext(private val versionProperties: VersionProperties = VersionProperties()) {
class ExecutionContext(
private val versionProperties: VersionProperties = VersionProperties(),
) {
private val gitContext = GitContext.create()

fun repositoryName() = gitContext?.repositoryName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package io.rabobank.ret.context
import org.eclipse.jgit.lib.Repository
import org.eclipse.jgit.storage.file.FileRepositoryBuilder

internal class GitContext internal constructor(private val repository: Repository) {
internal class GitContext internal constructor(
private val repository: Repository,
) {
fun repositoryName(): String? {
val remoteOriginURL: String? = repository.config.getString("remote", "origin", "url")
return remoteOriginURL?.substringAfterLast("/")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ package io.rabobank.ret.plugins

import picocli.CommandLine.Model.CommandSpec

data class PluginCommandEntry(val name: String, val commandSpec: CommandSpec)
data class PluginCommandEntry(
val name: String,
val commandSpec: CommandSpec,
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class PluginExtensionLoader {
objectMapper: ObjectMapper,
): List<Plugin> =
osUtils.getRetPluginsDirectory().let { pluginPath ->
pluginPath.walk()
pluginPath
.walk()
.map(Path::toFile)
.filter { it.extension == PLUGIN_EXTENSION }
.map { objectMapper.readValue<PluginDefinition>(it.readText()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class PluginLoader(

command.arguments.forEach {
commandSpec.addPositional(
PositionalParamSpec.builder()
PositionalParamSpec
.builder()
.paramLabel(it.name)
.index(it.position)
.arity(it.arity)
Expand All @@ -61,7 +62,8 @@ class PluginLoader(

command.options.forEach {
commandSpec.addOption(
OptionSpec.builder(it.names.toTypedArray())
OptionSpec
.builder(it.names.toTypedArray())
.type(asType(it.type))
.completionCandidates(it.completionCandidates)
.build(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class PluginLoaderTest {

private fun loadPlugin(file: String): Plugin {
val definition =
this.javaClass.classLoader.getResourceAsStream("testdata/$file")!!
this.javaClass.classLoader
.getResourceAsStream("testdata/$file")!!
.bufferedReader()
.readText()

Expand Down
13 changes: 10 additions & 3 deletions ret-core/src/main/kotlin/io/rabobank/ret/IntelliSearch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ package io.rabobank.ret
import io.quarkus.logging.Log
import jakarta.enterprise.context.ApplicationScoped

data class SearchHit(val filterRound: FilterRound, val candidateIndex: Int)

data class FilterRound(val filter: String, val startIndex: Int, val endIndex: Int) {
data class SearchHit(
val filterRound: FilterRound,
val candidateIndex: Int,
)

data class FilterRound(
val filter: String,
val startIndex: Int,
val endIndex: Int,
) {
val value = filter.substring(startIndex..endIndex)

override fun toString() = "filter: $filter part: $startIndex..$endIndex value: $value"
Expand Down
8 changes: 6 additions & 2 deletions ret-core/src/main/kotlin/io/rabobank/ret/RetConsole.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ import picocli.CommandLine.ParseResult
* This class is used to interact with the user by outputting messages, errors and prompting for responses.
*/
@ApplicationScoped
class RetConsole(parseResult: ParseResult) {
class RetConsole(
parseResult: ParseResult,
) {
private val commandLine =
parseResult.commandSpec().commandLine()
parseResult
.commandSpec()
.commandLine()
.setColorScheme(ColorScheme.Builder().ansi(CommandLine.Help.Ansi.AUTO).build())

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ open class Configurable {
inline fun <reified T> convertTo() = objectMapper.convertValue<T>(pluginConfig.config)
}

class PluginConfig(val config: MutableMap<String, Any?>) {
class PluginConfig(
val config: MutableMap<String, Any?>,
) {
inline operator fun <reified T> get(key: String): T? {
val value = config[key]
return if (value is T?) {
Expand All @@ -115,7 +117,11 @@ class PluginConfig(val config: MutableMap<String, Any?>) {
}
}

class PluginConfigLoader(pluginName: String, private val objectMapper: ObjectMapper, osUtils: OsUtils) {
class PluginConfigLoader(
pluginName: String,
private val objectMapper: ObjectMapper,
osUtils: OsUtils,
) {
private val pluginFile = osUtils.getPluginConfig(pluginName).toFile()

fun load() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ package io.rabobank.ret.configuration
* @property prompt the message to the user, specifying what should be provided for this config property.
* @property required tells the user this is a mandatory field which cannot be skipped.
*/
data class ConfigurationProperty(val key: String, val prompt: String, val required: Boolean = false)
data class ConfigurationProperty(
val key: String,
val prompt: String,
val required: Boolean = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import org.jboss.logging.MDC
* This is done automatically, so you don't need to use this class in your plugin.
*/
@ApplicationScoped
class MdcConfig(private val versionProperties: VersionProperties) {
class MdcConfig(
private val versionProperties: VersionProperties,
) {
@Suppress("unused")
fun onStart(
@Observes ev: StartupEvent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import picocli.CommandLine
*/
@Unremovable
@ApplicationScoped
class RetVersionProvider(private val versionProperties: VersionProperties = VersionProperties()) :
CommandLine.IVersionProvider {
class RetVersionProvider(
private val versionProperties: VersionProperties = VersionProperties(),
) : CommandLine.IVersionProvider {
override fun getVersion() =
arrayOf(
"RET Version: ${versionProperties.getAppVersion()}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class VersionProperties {
}

private fun loadGitProperties() {
VersionProperties::class.java.classLoader.getResourceAsStream(GIT_PROPERTIES)
VersionProperties::class.java.classLoader
.getResourceAsStream(GIT_PROPERTIES)
?.run { properties.load(this) }
?: Log.debug("No Git information available: cannot load git.properties file.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ object IntrospectionUtil {
)

private fun loadCustomZshAutocompletion(): String? =
javaClass.getResourceAsStream("/autocompletion/zsh/completions.zsh")
javaClass
.getResourceAsStream("/autocompletion/zsh/completions.zsh")
?.bufferedReader()
?.readText()

Expand All @@ -34,7 +35,8 @@ object IntrospectionUtil {
)
}
val options =
commandSpec.options()
commandSpec
.options()
.map {
Option(
it.names().toList(),
Expand All @@ -44,7 +46,9 @@ object IntrospectionUtil {
}

val subcommands =
commandSpec.subcommands().values
commandSpec
.subcommands()
.values
.map {
generateCommand(it.commandSpec)
}
Expand Down