Skip to content

Commit

Permalink
CLI: add version flag to show version information of the app and the …
Browse files Browse the repository at this point in the history
…connector plugin
  • Loading branch information
ryru committed Sep 15, 2024
1 parent f51fd47 commit d0d1aac
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 2 deletions.
20 changes: 20 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import org.apache.tools.ant.filters.ReplaceTokens

plugins {
id("dga.application-conventions")
}

description = "CLI application project"

group = "ch.addere.dga.app"
version = property("cliVersion").toString()

dependencies {
implementation(project(":core"))
implementation(project(":importer"))
Expand All @@ -26,3 +31,18 @@ distributions {
tasks.withType<CreateStartScripts> {
applicationName = "dga"
}

val cliVersion = property("cliVersion").toString()
val connectorPluginVersion = property("connectorPluginVersion").toString()

tasks.withType<Jar> {
filesMatching("versions.txt") {
filter(
ReplaceTokens::class,
"tokens" to mapOf(
"cliVersion" to cliVersion,
"pluginVersion" to connectorPluginVersion
)
)
}
}
14 changes: 13 additions & 1 deletion app/src/main/kotlin/ch/addere/dga/app/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ch.addere.dga.app.infrastructure.factory.coreModule
import ch.addere.dga.app.infrastructure.factory.dgaModule
import ch.addere.dga.app.infrastructure.factory.importerModule
import ch.addere.dga.app.infrastructure.factory.userInputModule
import ch.addere.dga.app.infrastructure.service.AppVersionService
import ch.addere.dga.core.domain.model.Configuration
import ch.addere.dga.core.domain.model.Module
import com.github.ajalt.clikt.core.CliktCommand
Expand All @@ -26,6 +27,7 @@ import com.github.ajalt.clikt.parameters.options.flag
import com.github.ajalt.clikt.parameters.options.help
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.options.split
import com.github.ajalt.clikt.parameters.options.versionOption
import com.github.ajalt.clikt.parameters.types.file
import org.koin.core.component.KoinComponent
import org.koin.core.component.get
Expand All @@ -37,6 +39,17 @@ import kotlin.system.exitProcess
private class Dga : CliktCommand(help = "Analyse the module dependency graph of a Gradle project."),
KoinComponent {

private val appVersionService = AppVersionService()

init {
val appVersion = appVersionService.readVersions()
val versionOutput = """
${appVersion.cli}
dga connector plugin version ${appVersion.plugin}
""".trimIndent()
versionOption(versionOutput, names = setOf("--version", "-v"))
}

private val gradleProject: File by argument()
.file()
.help("Path of the Gradle project directory")
Expand Down Expand Up @@ -64,7 +77,6 @@ private class Dga : CliktCommand(help = "Analyse the module dependency graph of
name = "Display Options",
).single().default(OutputOptions.OutputOptionOverviewOnly)


override fun run() {
val filterConfig = FilterConfig(
optionsFilter.modules,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package ch.addere.dga.app.domain.model

data class AppVersion(val cli: String, val plugin: String)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ch.addere.dga.app.infrastructure.service

import ch.addere.dga.app.domain.model.AppVersion

class AppVersionService {

fun readVersions(): AppVersion {
val a = javaClass.getResource("/versions.txt")!!.readText().split("\n")
.filter { it.isNotEmpty() }
val b = a.associate {
val (component, version) = it.split("=")
component.trim() to version.trim()
}.toMap()
return AppVersion(b["cli"]!!, b["plugin"]!!)
}
}
2 changes: 2 additions & 0 deletions app/src/main/resources/versions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cli=@cliVersion@
plugin=@pluginVersion@
3 changes: 3 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ plugins {
}

description = "Core logic for analysing dependency graphs"

group = "ch.addere.dga.core"
version = property("cliVersion").toString()
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
# https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties
org.gradle.parallel=true
org.gradle.caching=true
cliVersion=0.1.2-SNAPSHOT
connectorPluginVersion=0.1.5
2 changes: 1 addition & 1 deletion importer/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = "ch.addere.dga.importer"
version = "0.1.0"
version = property("cliVersion").toString()

description = "Imports project information of to be analysed Gradle project"

Expand Down

0 comments on commit d0d1aac

Please sign in to comment.