diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 0bcb833..f13bffb 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -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")) @@ -26,3 +31,18 @@ distributions { tasks.withType { applicationName = "dga" } + +val cliVersion = property("cliVersion").toString() +val connectorPluginVersion = property("connectorPluginVersion").toString() + +tasks.withType { + filesMatching("versions.txt") { + filter( + ReplaceTokens::class, + "tokens" to mapOf( + "cliVersion" to cliVersion, + "pluginVersion" to connectorPluginVersion + ) + ) + } +} diff --git a/app/src/main/kotlin/ch/addere/dga/app/App.kt b/app/src/main/kotlin/ch/addere/dga/app/App.kt index a91a847..6542f13 100644 --- a/app/src/main/kotlin/ch/addere/dga/app/App.kt +++ b/app/src/main/kotlin/ch/addere/dga/app/App.kt @@ -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 @@ -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 @@ -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") @@ -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, diff --git a/app/src/main/kotlin/ch/addere/dga/app/domain/model/AppVersion.kt b/app/src/main/kotlin/ch/addere/dga/app/domain/model/AppVersion.kt new file mode 100644 index 0000000..69f279b --- /dev/null +++ b/app/src/main/kotlin/ch/addere/dga/app/domain/model/AppVersion.kt @@ -0,0 +1,3 @@ +package ch.addere.dga.app.domain.model + +data class AppVersion(val cli: String, val plugin: String) diff --git a/app/src/main/kotlin/ch/addere/dga/app/infrastructure/service/AppVersionService.kt b/app/src/main/kotlin/ch/addere/dga/app/infrastructure/service/AppVersionService.kt new file mode 100644 index 0000000..6c0075f --- /dev/null +++ b/app/src/main/kotlin/ch/addere/dga/app/infrastructure/service/AppVersionService.kt @@ -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"]!!) + } +} diff --git a/app/src/main/resources/versions.txt b/app/src/main/resources/versions.txt new file mode 100644 index 0000000..b0d1f51 --- /dev/null +++ b/app/src/main/resources/versions.txt @@ -0,0 +1,2 @@ +cli=@cliVersion@ +plugin=@pluginVersion@ diff --git a/core/build.gradle.kts b/core/build.gradle.kts index fd22b5d..b225e24 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -3,3 +3,6 @@ plugins { } description = "Core logic for analysing dependency graphs" + +group = "ch.addere.dga.core" +version = property("cliVersion").toString() diff --git a/gradle.properties b/gradle.properties index e57141e..c4d58dd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/importer/build.gradle.kts b/importer/build.gradle.kts index dce1b90..56ea91f 100644 --- a/importer/build.gradle.kts +++ b/importer/build.gradle.kts @@ -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"