diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts index f33a59b00..7cd720902 100644 --- a/buildSrc/settings.gradle.kts +++ b/buildSrc/settings.gradle.kts @@ -43,18 +43,20 @@ dependencyResolutionManagement { /* The code, we have put on a classpath, exposes a class `SpineVersionCatalog`, - which can execute code upon `VersionCatalogBuilder`. + which can execute actions upon `VersionCatalogBuilder`. It is so because we want to preserve a possibility of overwrite. Currently, Gradle does not provide a clear way to perform overwrite for - already created catalogs. When a library is added to a catalog, it can - not be overwritten. The subsequent attempts to add the same library lead - to a silent nothing. + already created catalogs. Thus, it is a responsibility of end-users + to create catalogs. `SpineVersionCatalog` just operates upon the given builder. - Thus, to overwrite a library or version you should declare it first. - All subsequent declaration of that library or version will just be ignored. - And this is the reason, why we don't have a plugin at all. We just - don't need it. + In order to override a version, shipped by the catalog, one should + declare it BEFORE applying the catalog to the builder. Versions, + declared first, always win. + + In contrast, to override a library, plugin or bundle, one should + declare it AFTER applying the catalog to the builder. Those items, + declared last, always win. See the issue: https://github.com/gradle/gradle/issues/20836 */ diff --git a/version-catalog/README.md b/version-catalog/README.md index c539e3531..2b78b62c7 100644 --- a/version-catalog/README.md +++ b/version-catalog/README.md @@ -46,83 +46,141 @@ In order to add a new dependency to this catalog, perform the following steps: 2. Open `io.spine.internal.catalog.entry` package. 3. Create a new file there, which contains an object declaration, named after a dependency, that is being added. - 4. Make an object inherit from one of the following entries, depending on what -a dependency represents: - 1. `VersionEntry` for a bare version. - 2. `LibraryEntry` for a single library. - 3. `PluginEntry` for a single Gradle plugin. - 4. `DependnecyEntry` for complex dependencies, which may contain several modules, - plugins or bundles. - 5. Publish a new version of the catalog. - -Take a look on an example, which showcases usage of all entries in a single place. -Pay attention to how entries are nested one into another. And how it reflects in -their resulting accessors. + 4. Make an object inherit from `CatalogEntry`. + 5. Perform all necessary declarations within this object. + 6. Publish a new version of the catalog. + +Take a look on an example, which showcases usage of `CatalogEntry` API. Pay attention +to how entries are nested one into another. And how it reflects in their resulting accessors. Source code of `Dummy` dependency: ```kotlin -internal object Dummy : DependencyEntry() { - - private const val group = "org.dummy.company" - override val module = "$group:dummy-lib" // libs.dummy - override val version = "1.0.0" // libs.versions.dummy - - val core by lib("$group:dummy-core") // libs.dummy.core - val runner by lib("$group:dummy-runner") // libs.dummy.runner - val api by lib("$group:dummy-api") // libs.dummy.api - - // In bundles, you can reference already declared libs, - // or create them in-place. - - override val bundle = setOf( // libs.bundles.dummy - core, runner, api, - lib("params", "$group:dummy-params"), // libs.dummy.params - lib("types", "$group:dummy-types"), // libs.dummy.types - ) - - // "GradlePlugin" - is a special entry name for `PluginEntry`. - // For plugin entries with this name, the facade will not put "gradlePlugin" - // suffix for a plugin's ID. Note, that we have this suffix for the version - // and module, and does not have for ID. - - object GradlePlugin : PluginEntry() { - override val version = "0.0.8" // libs.versions.dummy.gradlePlugin - override val module = "$group:my-dummy-plugin" // libs.dummy.gradlePlugin - override val id = "my-dummy-plugin" // libs.plugins.dummy - } +internal object Dummy : CatalogEntry() { + + private const val group = "org.dummy.company" + override val module = "$group:dummy-lib" // libs.dummy + override val version = "1.0.0" // libs.versions.dummy + + val core by lib("$group:dummy-core") // libs.dummy.core + val runner by lib("$group:dummy-runner") // libs.dummy.runner + val api by lib("$group:dummy-api") // libs.dummy.api + + // In bundles, you can reference entries (which declare module), extra + // libraries or declare them in-place. + + override val bundle = setOf( // libs.bundles.dummy + this, + core, runner, api, + lib("params", "$group:dummy-params"), // libs.dummy.params + lib("types", "$group:dummy-types"), // libs.dummy.types + ) + + // "GradlePlugin" - is a special entry name. "gradlePlugin" suffix will not + // be put for a final plugin alias. Note, that in an example below, we have + // this suffix for the version and module, and does not have for ID. + + object GradlePlugin : CatalogEntry() { + override val version = "0.0.8" // libs.versions.dummy.gradlePlugin + override val module = "$group:my-dummy-plugin" // libs.dummy.gradlePlugin + override val id = "my-dummy-plugin" // libs.plugins.dummy + } + + object Runtime : CatalogEntry() { + + // When an entry does not override the version, it will try to fetch it + // from the closest parental entry, which has one. For example, in this case, + // all libraries within "Runtime" entry will have version = "1.0.0". + + val win by lib("$group:runtime-win") // libs.dummy.runtime.win + val mac by lib("$group:runtime-mac") // libs.dummy.runtime.mac + val linux by lib("$group:runtime-linux") // libs.dummy.runtime.linux + + object Bom : CatalogEntry() { + override val version = "2.0.0" // libs.versions.dummy.runtime.bom + override val module = "$group:dummy-bom" // libs.dummy.runtime.bom + } + } + + // It's also possible to declare an extra bundle by a property delegate. + // Just like with extra modules. + + val runtime by bundle( // libs.bundles.dummy.runtime + Runtime.Bom, + Runtime.win, + Runtime.mac, + Runtime.linux, + ) +} +``` + + +## Overriding of items shipped by `SpineVersionCatalog` + +Sometimes, it happens that a projects needs to override items, shipped by the catalog. +In most cases, it is needed to override one or more versions. - object Runtime : DependencyEntry() { +Currently, Gradle does not [provide](https://github.com/gradle/gradle/issues/20836) +a clear way to perform overwrite for already created catalogs. Thus, we use approach +with creating a catalog directly in settings files. It preserves a possibility +of a local override. - // When an entry does not override the version, it is taken from - // the outer entry. For example, in this case, all libs within "Runtime" - // entry will have "1.0.0". +Below are examples on how to override the items of `Dummy` dependency. Instead of +applying `SpineVersionCatalog`, `DummyVersionCatalog` is used, as we are going to +override `Dummy`'s items. - val win by lib("$group:runtime-win") // libs.dummy.runtime.win - val mac by lib("$group:runtime-mac") // libs.dummy.runtime.mac - val linux by lib("$group:runtime-linux") // libs.dummy.runtime.linux +### Overriding of versions - object BOM : LibraryEntry() { - override val version = "2.0.0" // libs.versions.dummy.runtime.bom - override val module = "$group:dummy-bom" // libs.dummy.runtime.bom +In order to override a version you should declare it *before* applying the catalog. +A version, declared first always wins. All subsequent declarations of the same version +will be ignored by the builder. + +In total, `Dummy` declares three versions. + +Let's override them all: + +```kotlin +dependencyResolutionManagement { + versionCatalogs { + create("libs") { + + version("dummy", "2.0.0") // Dummy.version + version("dummy-gradlePlugin", "0.0.9") // Dummy.GradlePlugin.version + version("dummy-runtime-bom", "3.0.0") // Dummy.Runtime.Bom.version + + DummyVersionCatalog.useIn(this) } } +} +``` - // A library that is declared as `object SomeLib : LibraryEntry()` can be - // referenced as well as the one declared by `lib()` delegate. +### Overriding of libraries, plugins and bundles - val runtime by bundle( // libs.bundles.dummy.runtime - Runtime.BOM, - Runtime.win, - Runtime.mac, - Runtime.linux, - ) +In order to override a library, plugin or bundle, one should declare it *after* +applying the catalog. This is the opposite of what is done with versions. - // It is also possible to declare just a bare version. +When overriding libraries and plugins, a version should be specified in-place. - object Tools : VersionEntry() { - override val version = "3.0.0" // libs.versions.dummy.tools - } +For example: + +```kotlin +dependencyResolutionManagement { + versionCatalogs { + create("libs") { + + DummyVersionCatalog.useIn(this) + + library("dummy", "org.dummy.company:dummy-lib-patched:3.41-patched") // Dummy.module + version + library("dummy-gradlePlugin", "org.dummy.company:another-plugin:3.41-patched") // Dummy.GradlePlugin.module + version + library("dummy-runtime-mac", "org.dummy.company:runtime-linux:3.41-patched") // Dummy.Runtime.mac + version + + plugin("dummy", "my-dummy-plugin-patched").version("1.0.0-patched") // Dummy.GradlePlugin.id + version + + // In bundles, the passed list contains aliases of libraries. + bundle("dummy", listOf("dummy-runtime-bom", "dummy-runtime-win")) // Dummy.bundle + bundle("dummy-runtime", listOf("dummy", "dummy-core")) // Dummy.runtime + } + } } ``` @@ -133,20 +191,17 @@ Within this PR, `spine-version-catalog` is a resident of `time` repository, but it is a standalone project. Meaning, it has its own Gradle's `settings` file, and doesn't relate anyhow to `time`. -`spine-version-catalog` consists of several modules: - -1. `api` – represents a facade upon Gradle's provided `VersionCatalogBuilder`. -This module hides an imperative nature of the builder, and, instead, provides -a declarative API to declare dependencies using Kotlin objects. +`spine-version-catalog` consists of two modules: -2. `catalog` – contains all dependencies, declared using the declarative `api`. -The module publishes `SpineVersionCatalog`. +1. `catalog` – provides a facade upon Gradle's provided `VersionCatalogBuilder` +and assembles `SpineVersionCatalog`, using that facade. -3. `func-test` – performs testing of `api` with a real `VersionCatalogBuilder`. +2. `func-test` – performs testing of the facade with a real instance of `VersionCatalogBuilder`. To do that, the module does the following: 1. Assembles a `dummy-catalog` with a single `Dummy` dependency and publishes - it to Maven local. + it to Maven local. In order to declare `Dummy`, the module depends on `:catalog`, + which exposes the declarative facade. 2. Makes `dummy-project` use `dummy-catalog` from Maven local. 3. Builds `dummy-project`. It has assertions in its build file. Those assertions verify the generated type-safe accessors to `Dummy` dependency. When any of assertions @@ -155,20 +210,6 @@ To do that, the module does the following: ## Details about Functional Testing -`func-test` module sets the next dependencies for `test` task: - -```kotlin -test { - dependsOn( - ":api:publishToMavenLocal", - ":func-test:dummy-catalog:publishToMavenLocal" - ) -} -``` - -It is so, because `dummy-project` (which the test builds), fetches `dummy-catalog` -from Maven local. Which, in turn, depends on `api` module. Thus, we need them both in Maven local. - We have to do a true functional testing here, because Gradle does not provide a test fixture for `Settings`, as it does for `Project`. For this reason, we test it on a real Gradle project, with assertions right in a build file. diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/SpineVersionCatalog.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/SpineVersionCatalog.kt index ab0f4fd5e..c88d3c9e6 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/SpineVersionCatalog.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/SpineVersionCatalog.kt @@ -32,11 +32,11 @@ import org.reflections.Reflections import org.reflections.util.ConfigurationBuilder /** - * This catalog contains dependencies, which are used in Spine-related projects. + * Contains dependencies, which are used in Spine-related projects. * * In order to use this catalog, one should perform the following: * - * 1. Obtain this class on a classpath of settings file. + * 1. Obtain this class on a classpath of `settings.gradle.kts` file. * 2. Create a version catalog. `libs` is a conventional name to go with. * 3. Call [useIn] on a newly created catalog. * @@ -66,8 +66,9 @@ import org.reflections.util.ConfigurationBuilder * ``` * * In order to add a new dependency to this catalog, create an object declaration - * in [io.spine.internal.catalog.entry] package. Take a look on a special `Dummy` - * dependency in README file to quickly grasp API of a dependency declaration. + * that inherits from [CatalogEntry] in [io.spine.internal.catalog.entry] package. + * Take a look on a special `Dummy` dependency in README file to quickly grasp API + * of a dependency declaration. */ @Suppress("unused") class SpineVersionCatalog { @@ -95,8 +96,7 @@ class SpineVersionCatalog { * the following criteria: * * 1. Be an object declaration. Only objects can serve as concrete entries. - * 2. Be a top-level declared. Only root entries should be asked for records. - * Then, they will ask their nested entries accordingly. + * 2. Be top-level declared. Only root entries can be asked for records. */ private fun findEntries(): Set { val builder = ConfigurationBuilder().forPackage(pkg) diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/AnimalSniffer.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/AnimalSniffer.kt index 9df178f79..200060b91 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/AnimalSniffer.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/AnimalSniffer.kt @@ -26,13 +26,13 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.LibraryEntry +import io.spine.internal.catalog.model.CatalogEntry /** * [AnimalSniffer](https://www.mojohaus.org/animal-sniffer/animal-sniffer-maven-plugin/) */ @Suppress("unused") -internal object AnimalSniffer : LibraryEntry() { +internal object AnimalSniffer : CatalogEntry() { override val version = "1.21" override val module = "org.codehaus.mojo:animal-sniffer-annotations" } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/ApacheCommons.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/ApacheCommons.kt index ea3d676c0..42a0f29ba 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/ApacheCommons.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/ApacheCommons.kt @@ -27,7 +27,6 @@ package io.spine.internal.catalog.entry import io.spine.internal.catalog.model.CatalogEntry -import io.spine.internal.catalog.model.LibraryEntry @Suppress("unused") internal object ApacheCommons : CatalogEntry() { @@ -35,7 +34,7 @@ internal object ApacheCommons : CatalogEntry() { /** * [CommonsCli](https://commons.apache.org/proper/commons-cli/) */ - object Cli : LibraryEntry() { + object Cli : CatalogEntry() { override val version = "1.5.0" override val module = "commons-cli:commons-cli" } @@ -43,7 +42,7 @@ internal object ApacheCommons : CatalogEntry() { /** * [CommonsCodec](https://commons.apache.org/proper/commons-codec/changes-report.html) */ - object Codec : LibraryEntry() { + object Codec : CatalogEntry() { override val version = "1.15" override val module = "commons-codec:commons-codec" } @@ -51,7 +50,7 @@ internal object ApacheCommons : CatalogEntry() { /** * [CommonsLogging](https://commons.apache.org/proper/commons-logging/) */ - object Logging : LibraryEntry() { + object Logging : CatalogEntry() { override val version = "1.2" override val module = "commons-logging:commons-logging" } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/ApacheHttp.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/ApacheHttp.kt index 4e418532b..3ee992808 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/ApacheHttp.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/ApacheHttp.kt @@ -26,13 +26,13 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.DependencyEntry +import io.spine.internal.catalog.model.CatalogEntry /** * [ApacheHttp](https://hc.apache.org/downloads.cgi) */ @Suppress("unused") -internal object ApacheHttp : DependencyEntry() { +internal object ApacheHttp : CatalogEntry() { override val version = "4.4.14" val core by lib("org.apache.httpcomponents:httpcore") } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/AppEngine.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/AppEngine.kt index 0d441438f..c9d116a5f 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/AppEngine.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/AppEngine.kt @@ -26,19 +26,18 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.DependencyEntry -import io.spine.internal.catalog.model.LibraryEntry +import io.spine.internal.catalog.model.CatalogEntry /** * [AppEngine](https://cloud.google.com/java/docs/reference) */ @Suppress("unused") -internal object AppEngine : DependencyEntry() { +internal object AppEngine : CatalogEntry() { override val version = "1.9.82" val sdk by lib("com.google.appengine:appengine-api-1.0-sdk") - object GradlePlugin : LibraryEntry() { + object GradlePlugin : CatalogEntry() { override val version = "2.2.0" override val module = "com.google.cloud.tools:appengine-gradle-plugin" } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/AssertK.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/AssertK.kt index cac09ddeb..a1522d279 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/AssertK.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/AssertK.kt @@ -26,13 +26,13 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.DependencyEntry +import io.spine.internal.catalog.model.CatalogEntry /** * [AssertK](https://github.com/willowtreeapps/assertk) */ @Suppress("unused") -internal object AssertK : DependencyEntry() { +internal object AssertK : CatalogEntry() { override val version = "0.25" val jvm by lib("com.willowtreeapps.assertk:assertk-jvm") } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/BouncyCastle.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/BouncyCastle.kt index debee1563..fe05363c3 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/BouncyCastle.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/BouncyCastle.kt @@ -26,13 +26,13 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.DependencyEntry +import io.spine.internal.catalog.model.CatalogEntry /** * [BouncyCastle](https://www.bouncycastle.org/java.html) */ @Suppress("unused") -internal object BouncyCastle : DependencyEntry() { +internal object BouncyCastle : CatalogEntry() { override val version = "1.68" val libPkcsJdk15 by lib("org.bouncycastle:bcpkix-jdk15on") } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/CheckStyle.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/CheckStyle.kt index 8c4f4d808..7932ae6d8 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/CheckStyle.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/CheckStyle.kt @@ -26,12 +26,12 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.VersionEntry +import io.spine.internal.catalog.model.CatalogEntry /** * [CheckStyle](https://checkstyle.sourceforge.io/) */ @Suppress("unused") -internal object CheckStyle : VersionEntry() { +internal object CheckStyle : CatalogEntry() { override val version = "10.1" } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/CheckerFramework.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/CheckerFramework.kt index 0a96eef13..da54f48c8 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/CheckerFramework.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/CheckerFramework.kt @@ -26,20 +26,19 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.DependencyEntry -import io.spine.internal.catalog.model.LibraryEntry +import io.spine.internal.catalog.model.CatalogEntry /** * [CheckerFramework](https://checkerframework.org/) */ @Suppress("unused") -internal object CheckerFramework : DependencyEntry() { +internal object CheckerFramework : CatalogEntry() { /** * This is a discontinued artifact, which we do not use directly. * It is a transitive dependency which we use for forcing the version. */ - object CompatQual : LibraryEntry() { + object CompatQual : CatalogEntry() { override val version = "2.5.5" override val module = "org.checkerframework:checker-compat-qual" } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Dokka.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Dokka.kt index 057220bb7..4677f433d 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Dokka.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Dokka.kt @@ -26,15 +26,13 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.DependencyEntry -import io.spine.internal.catalog.model.LibraryEntry -import io.spine.internal.catalog.model.PluginEntry +import io.spine.internal.catalog.model.CatalogEntry /** * [Dokka](https://github.com/Kotlin/dokka) */ @Suppress("unused") -internal object Dokka : DependencyEntry() { +internal object Dokka : CatalogEntry() { private const val group = "org.jetbrains.dokka" override val version = "1.6.20" @@ -45,8 +43,8 @@ internal object Dokka : DependencyEntry() { * @see * Dokka output formats */ - val kotlinAsJavaPlugin by lib("${io.spine.internal.catalog.entry.Dokka.group}:kotlin-as-java-plugin") - val basePlugin by lib("${io.spine.internal.catalog.entry.Dokka.group}:dokka-base") + val kotlinAsJavaPlugin by lib("$group:kotlin-as-java-plugin") + val basePlugin by lib("$group:dokka-base") /** * Custom Dokka plugins developed for Spine-specific needs like excluding @@ -55,13 +53,13 @@ internal object Dokka : DependencyEntry() { * @see * Custom Dokka Plugins */ - object SpineExtensions : LibraryEntry() { + object SpineExtensions : CatalogEntry() { override val version = "2.0.0-SNAPSHOT.3" override val module = "io.spine.tools:spine-dokka-extensions" } - object GradlePlugin : PluginEntry() { - override val module = "${io.spine.internal.catalog.entry.Dokka.group}:dokka-gradle-plugin" + object GradlePlugin : CatalogEntry() { + override val module = "$group:dokka-gradle-plugin" override val id = "org.jetbrains.dokka" } } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/ErrorProne.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/ErrorProne.kt index 6c59cd901..582e34535 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/ErrorProne.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/ErrorProne.kt @@ -26,15 +26,13 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.DependencyEntry -import io.spine.internal.catalog.model.LibraryEntry -import io.spine.internal.catalog.model.PluginEntry +import io.spine.internal.catalog.model.CatalogEntry /** * [ErrorProne](https://github.com/google/error-prone) */ @Suppress("unused") -internal object ErrorProne : DependencyEntry() { +internal object ErrorProne : CatalogEntry() { override val version = "2.13.1" @@ -50,7 +48,7 @@ internal object ErrorProne : DependencyEntry() { /** * [JavacPlugin](https://github.com/tbroyer/gradle-errorprone-plugin/blob/v0.8/build.gradle.kts) */ - object JavacPlugin : LibraryEntry() { + object JavacPlugin : CatalogEntry() { override val version = "9+181-r4173-1" override val module = "com.google.errorprone:javac" } @@ -58,7 +56,7 @@ internal object ErrorProne : DependencyEntry() { /** * [GradlePlugin](https://github.com/tbroyer/gradle-errorprone-plugin/releases) */ - object GradlePlugin : PluginEntry() { + object GradlePlugin : CatalogEntry() { override val version = "2.0.2" override val module = "net.ltgt.gradle:gradle-errorprone-plugin" override val id = "net.ltgt.errorprone" diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/FindBugs.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/FindBugs.kt index 0ef675f24..a48cde24b 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/FindBugs.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/FindBugs.kt @@ -26,7 +26,7 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.DependencyEntry +import io.spine.internal.catalog.model.CatalogEntry /** * The FindBugs project is dead since 2017. It has a successor called SpotBugs, @@ -38,7 +38,7 @@ import io.spine.internal.catalog.model.DependencyEntry * See [this issue](https://github.com/SpineEventEngine/base/issues/108) for more details. */ @Suppress("unused") -internal object FindBugs : DependencyEntry() { +internal object FindBugs : CatalogEntry() { override val version = "3.0.2" val annotations by lib("com.google.code.findbugs:jsr305") } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Firebase.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Firebase.kt index ed3adc86c..10a673d2d 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Firebase.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Firebase.kt @@ -27,7 +27,6 @@ package io.spine.internal.catalog.entry import io.spine.internal.catalog.model.CatalogEntry -import io.spine.internal.catalog.model.LibraryEntry @Suppress("unused") internal object Firebase : CatalogEntry() { @@ -35,7 +34,7 @@ internal object Firebase : CatalogEntry() { /** * [Firebase Admin](https://firebase.google.com/docs/admin/setup#java) */ - object Admin : LibraryEntry() { + object Admin : CatalogEntry() { override val version = "8.1.0" override val module = "com.google.firebase:firebase-admin" } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Flogger.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Flogger.kt index 8f603e740..071b6aece 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Flogger.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Flogger.kt @@ -26,20 +26,19 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.DependencyEntry -import io.spine.internal.catalog.model.LibraryEntry +import io.spine.internal.catalog.model.CatalogEntry /** * [Flogger](https://github.com/google/flogger) */ @Suppress("unused") -internal object Flogger : LibraryEntry() { +internal object Flogger : CatalogEntry() { private const val group = "com.google.flogger" override val version = "0.7.4" override val module = "$group:flogger" - object Runtime : DependencyEntry() { + object Runtime : CatalogEntry() { val systemBackend by lib("$group:flogger-system-backend") val log4J by lib("$group:flogger-log4j") val slf4J by lib("$group:slf4j-backend-factory") diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/GoogleApis.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/GoogleApis.kt index 6b6858b07..d6322a84a 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/GoogleApis.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/GoogleApis.kt @@ -27,8 +27,6 @@ package io.spine.internal.catalog.entry import io.spine.internal.catalog.model.CatalogEntry -import io.spine.internal.catalog.model.DependencyEntry -import io.spine.internal.catalog.model.LibraryEntry /** * [GoogleApis](https://github.com/googleapis/) @@ -39,7 +37,7 @@ internal object GoogleApis : CatalogEntry() { /** * [Client](https://github.com/googleapis/google-api-java-client) */ - object Client : LibraryEntry() { + object Client : CatalogEntry() { override val version = "1.32.2" override val module = "com.google.api-client:google-api-client" } @@ -47,7 +45,7 @@ internal object GoogleApis : CatalogEntry() { /** * [Common](https://github.com/googleapis/api-common-java) */ - object Common : LibraryEntry() { + object Common : CatalogEntry() { override val version = "2.1.1" override val module = "com.google.api:api-common" } @@ -55,7 +53,7 @@ internal object GoogleApis : CatalogEntry() { /** * [CommonProtos](https://github.com/googleapis/java-common-protos) */ - object CommonProtos : LibraryEntry() { + object CommonProtos : CatalogEntry() { override val version = "2.7.0" override val module = "com.google.api.grpc:proto-google-common-protos" } @@ -63,7 +61,7 @@ internal object GoogleApis : CatalogEntry() { /** * [GAX](https://github.com/googleapis/gax-java) */ - object Gax : LibraryEntry() { + object Gax : CatalogEntry() { override val version = "2.7.1" override val module = "com.google.api:gax" } @@ -71,7 +69,7 @@ internal object GoogleApis : CatalogEntry() { /** * [ProtoAim](https://github.com/googleapis/java-iam) */ - object ProtoAim : LibraryEntry() { + object ProtoAim : CatalogEntry() { override val version = "1.2.0" override val module = "com.google.api.grpc:proto-google-iam-v1" } @@ -79,7 +77,7 @@ internal object GoogleApis : CatalogEntry() { /** * [OAuthClient](https://github.com/googleapis/google-oauth-java-client) */ - object OAuthClient : LibraryEntry() { + object OAuthClient : CatalogEntry() { override val version = "1.32.1" override val module = "com.google.oauth-client:google-oauth-client" } @@ -87,7 +85,7 @@ internal object GoogleApis : CatalogEntry() { /** * [AuthLibrary](https://github.com/googleapis/google-auth-library-java) */ - object AuthLibrary : DependencyEntry() { + object AuthLibrary : CatalogEntry() { override val version = "1.3.0" val credentials by lib("com.google.auth:google-auth-library-credentials") val oAuth2Http by lib("com.google.auth:google-auth-library-oauth2-http") diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/GoogleAuto.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/GoogleAuto.kt index 1a5577f93..0ff12c825 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/GoogleAuto.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/GoogleAuto.kt @@ -27,8 +27,6 @@ package io.spine.internal.catalog.entry import io.spine.internal.catalog.model.CatalogEntry -import io.spine.internal.catalog.model.DependencyEntry -import io.spine.internal.catalog.model.LibraryEntry /** * [GoogleAuto](https://github.com/google/auto) @@ -36,18 +34,18 @@ import io.spine.internal.catalog.model.LibraryEntry @Suppress("unused") internal object GoogleAuto : CatalogEntry() { - object Common : LibraryEntry() { + object Common : CatalogEntry() { override val version = "1.2.1" override val module = "com.google.auto:auto-common" } - object Service : DependencyEntry() { + object Service : CatalogEntry() { override val version = "1.0.1" val annotations by lib("com.google.auto.service:auto-service-annotations") val processor by lib("com.google.auto.service:auto-service") } - object Value : DependencyEntry() { + object Value : CatalogEntry() { override val version = "1.9" val annotations by lib("com.google.auto.value:auto-value-annotations") } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/GoogleCloud.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/GoogleCloud.kt index 3b0507a76..d20d27bcb 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/GoogleCloud.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/GoogleCloud.kt @@ -27,8 +27,6 @@ package io.spine.internal.catalog.entry import io.spine.internal.catalog.model.CatalogEntry -import io.spine.internal.catalog.model.DependencyEntry -import io.spine.internal.catalog.model.LibraryEntry @Suppress("unused") internal object GoogleCloud : CatalogEntry() { @@ -36,7 +34,7 @@ internal object GoogleCloud : CatalogEntry() { /** * [Core](https://github.com/googleapis/java-core) */ - object Core : LibraryEntry() { + object Core : CatalogEntry() { override val version = "2.3.3" override val module = "com.google.cloud:google-cloud-core" } @@ -44,7 +42,7 @@ internal object GoogleCloud : CatalogEntry() { /** * [PubSubGrcpApi](https://github.com/googleapis/java-pubsub/tree/main/proto-google-cloud-pubsub-v1) */ - object PubSubGrpcApi : LibraryEntry() { + object PubSubGrpcApi : CatalogEntry() { override val version = "1.97.0" override val module = "com.google.api.grpc:proto-google-cloud-pubsub-v1" } @@ -52,7 +50,7 @@ internal object GoogleCloud : CatalogEntry() { /** * [Trace](https://github.com/googleapis/java-trace) */ - object Trace : LibraryEntry() { + object Trace : CatalogEntry() { override val version = "2.1.0" override val module = "com.google.cloud:google-cloud-trace" } @@ -60,12 +58,12 @@ internal object GoogleCloud : CatalogEntry() { /** * [Datastore](https://github.com/googleapis/java-datastore) */ - object Datastore : LibraryEntry() { + object Datastore : CatalogEntry() { override val version = "2.2.1" override val module = "com.google.cloud:google-cloud-datastore" } - object ArtifactRegistry : DependencyEntry() { + object ArtifactRegistry : CatalogEntry() { override val version = "2.1.2" val authCommon by lib("com.google.cloud.artifactregistry:artifactregistry-auth-common") } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/GrGit.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/GrGit.kt index 0d3257317..f7a035ae4 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/GrGit.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/GrGit.kt @@ -26,10 +26,10 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.DependencyEntry +import io.spine.internal.catalog.model.CatalogEntry @Suppress("unused") -internal object GrGit : DependencyEntry() { +internal object GrGit : CatalogEntry() { override val version = "3.1.1" val core by lib("org.ajoberstar.grgit:grgit-core") } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Grpc.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Grpc.kt index af271e4e8..5fb8c2ce7 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Grpc.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Grpc.kt @@ -26,13 +26,13 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.DependencyEntry +import io.spine.internal.catalog.model.CatalogEntry /** * [Grpc Java](https://github.com/grpc/grpc-java) */ @Suppress("unused") -internal object Grpc : DependencyEntry() { +internal object Grpc : CatalogEntry() { override val version = "1.45.1" val api by lib("io.grpc:grpc-api") val auth by lib("io.grpc:grpc-auth") diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Gson.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Gson.kt index e7d37922f..efd3ce62e 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Gson.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Gson.kt @@ -26,7 +26,7 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.LibraryEntry +import io.spine.internal.catalog.model.CatalogEntry /** * Gson is a transitive dependency which we don't use directly. @@ -36,7 +36,7 @@ import io.spine.internal.catalog.model.LibraryEntry * [Gson](https://github.com/google/gson) */ @Suppress("unused") -internal object Gson : LibraryEntry() { +internal object Gson : CatalogEntry() { override val version = "2.9.0" override val module = "com.google.code.gson:gson" } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Guava.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Guava.kt index 0e6da693c..7d222e107 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Guava.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Guava.kt @@ -26,7 +26,7 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.DependencyEntry +import io.spine.internal.catalog.model.CatalogEntry /** * The dependencies for Guava. @@ -38,7 +38,7 @@ import io.spine.internal.catalog.model.DependencyEntry * [Guava](https://github.com/google/guava) */ @Suppress("unused") -internal object Guava : DependencyEntry() { +internal object Guava : CatalogEntry() { override val version = "31.1-jre" override val module = "com.google.guava:guava" val testLib by lib("com.google.guava:guava-testlib") diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/HttpClient.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/HttpClient.kt index 7de4f429c..b3e485e07 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/HttpClient.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/HttpClient.kt @@ -26,14 +26,13 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.DependencyEntry -import io.spine.internal.catalog.model.LibraryEntry +import io.spine.internal.catalog.model.CatalogEntry /** * [Google HTTP client](https://github.com/googleapis/google-http-java-client) */ @Suppress("unused") -internal object HttpClient : DependencyEntry() { +internal object HttpClient : CatalogEntry() { /** * [Releases](https://github.com/googleapis/google-http-java-client) @@ -45,7 +44,7 @@ internal object HttpClient : DependencyEntry() { val gson by lib("com.google.http-client:google-http-client-gson") val apache2 by lib("com.google.http-client:google-http-client-apache-v2") - object Apache : LibraryEntry() { + object Apache : CatalogEntry() { override val version = "2.1.2" override val module = "com.google.http-client:google-http-client-apache" } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/J2ObjC.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/J2ObjC.kt index 54c994d6f..37e270809 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/J2ObjC.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/J2ObjC.kt @@ -26,14 +26,14 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.DependencyEntry +import io.spine.internal.catalog.model.CatalogEntry /** * [J2ObjC](https://developers.google.com/j2objc) is a transitive dependency * which we don't use directly. This object is used for forcing the version. */ @Suppress("unused") -internal object J2ObjC : DependencyEntry() { +internal object J2ObjC : CatalogEntry() { /** * [Releases](https://github.com/google/j2objc/releases) diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/JUnit.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/JUnit.kt index cbf38d084..d3ccb7fa6 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/JUnit.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/JUnit.kt @@ -26,14 +26,13 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.DependencyEntry -import io.spine.internal.catalog.model.LibraryEntry +import io.spine.internal.catalog.model.CatalogEntry /** * [JUnit5](https://junit.org/junit5/) */ @Suppress("unused") -internal object JUnit : DependencyEntry() { +internal object JUnit : CatalogEntry() { override val version = "5.8.2" val bom by lib("org.junit:junit-bom") @@ -42,18 +41,18 @@ internal object JUnit : DependencyEntry() { /** * [ApiGuardian](https://github.com/apiguardian-team/apiguardian) */ - object ApiGuardian : LibraryEntry() { + object ApiGuardian : CatalogEntry() { override val version = "1.1.2" override val module = "org.apiguardian:apiguardian-api" } - object Platform : DependencyEntry() { + object Platform : CatalogEntry() { override val version = "1.8.2" val commons by lib("org.junit.platform:junit-platform-commons") val launcher by lib("org.junit.platform:junit-platform-launcher") } - object Legacy : LibraryEntry() { + object Legacy : CatalogEntry() { override val version = "4.13.1" override val module = "junit:junit" } @@ -61,7 +60,7 @@ internal object JUnit : DependencyEntry() { /** * [Junit-Pioneer](https://github.com/junit-pioneer/junit-pioneer) */ - object Pioneer : LibraryEntry() { + object Pioneer : CatalogEntry() { override val version = "1.5.0" override val module = "org.junit-pioneer:junit-pioneer" } @@ -69,6 +68,6 @@ internal object JUnit : DependencyEntry() { override val bundle = setOf( lib("api", "org.junit.jupiter:junit-jupiter-api"), lib("params", "org.junit.jupiter:junit-jupiter-params"), - io.spine.internal.catalog.entry.JUnit.ApiGuardian + ApiGuardian ) } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Jackson.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Jackson.kt index 5068ae5b5..98f523bec 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Jackson.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Jackson.kt @@ -26,11 +26,10 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.DependencyEntry -import io.spine.internal.catalog.model.LibraryEntry +import io.spine.internal.catalog.model.CatalogEntry @Suppress("unused") -internal object Jackson : DependencyEntry() { +internal object Jackson : CatalogEntry() { override val version = "2.13.2" @@ -57,7 +56,7 @@ internal object Jackson : DependencyEntry() { /** * [Databind](https://github.com/FasterXML/jackson-databind) */ - object Databind : LibraryEntry() { + object Databind : CatalogEntry() { override val version = "2.13.2.2" override val module = "com.fasterxml.jackson.core:jackson-databind" } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/JavaJwt.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/JavaJwt.kt index 948b7b69f..20a1faafa 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/JavaJwt.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/JavaJwt.kt @@ -26,7 +26,7 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.LibraryEntry +import io.spine.internal.catalog.model.CatalogEntry /** * A Java implementation of JSON Web Token (JWT) - RFC 7519. @@ -34,7 +34,7 @@ import io.spine.internal.catalog.model.LibraryEntry * [Java JWT](https://github.com/auth0/java-jwt) */ @Suppress("unused") -internal object JavaJwt : LibraryEntry() { +internal object JavaJwt : CatalogEntry() { override val version = "3.19.1" override val module = "com.auth0:java-jwt" } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/JavaPoet.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/JavaPoet.kt index 4223e90ff..50fbd02da 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/JavaPoet.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/JavaPoet.kt @@ -26,13 +26,13 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.LibraryEntry +import io.spine.internal.catalog.model.CatalogEntry /** * [JavaPoet](https://github.com/square/javapoet) */ @Suppress("unused") -internal object JavaPoet : LibraryEntry() { +internal object JavaPoet : CatalogEntry() { override val version = "1.13.0" override val module = "com.squareup:javapoet" } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/JavaX.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/JavaX.kt index 91f9557f1..a0a19e248 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/JavaX.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/JavaX.kt @@ -27,7 +27,6 @@ package io.spine.internal.catalog.entry import io.spine.internal.catalog.model.CatalogEntry -import io.spine.internal.catalog.model.LibraryEntry @Suppress("unused") internal object JavaX : CatalogEntry() { @@ -37,12 +36,12 @@ internal object JavaX : CatalogEntry() { * * [Annotations](https://github.com/eclipse-ee4j/common-annotations-api) */ - object Annotations : LibraryEntry() { + object Annotations : CatalogEntry() { override val version = "1.3.2" override val module = "javax.annotation:javax.annotation-api" } - object ServletApi : LibraryEntry() { + object ServletApi : CatalogEntry() { override val version = "3.1.0" override val module = "javax.servlet:javax.servlet-api" } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Klaxon.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Klaxon.kt index 464737058..a856a4c49 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Klaxon.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Klaxon.kt @@ -26,7 +26,7 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.LibraryEntry +import io.spine.internal.catalog.model.CatalogEntry /** * A JSON parser in Kotlin. @@ -34,7 +34,7 @@ import io.spine.internal.catalog.model.LibraryEntry * [Klaxon](https://github.com/cbeust/klaxon) */ @Suppress("unused") -internal object Klaxon : LibraryEntry() { +internal object Klaxon : CatalogEntry() { override val version = "5.6" override val module = "com.beust:klaxon" } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Kotlin.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Kotlin.kt index 27eec648f..1814134df 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Kotlin.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Kotlin.kt @@ -26,13 +26,13 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.DependencyEntry +import io.spine.internal.catalog.model.CatalogEntry /** * [Kotlin](https://github.com/JetBrains/kotlin) */ @Suppress("unused") -internal object Kotlin : DependencyEntry() { +internal object Kotlin : CatalogEntry() { private const val group = "org.jetbrains.kotlin" override val version = "1.6.21" @@ -40,7 +40,7 @@ internal object Kotlin : DependencyEntry() { val gradlePlugin by lib("$group:kotlin-gradle-plugin") val reflect by lib("$group:kotlin-reflect") - object StdLib : DependencyEntry() { + object StdLib : CatalogEntry() { override val module = "$group:kotlin-stdlib" val common by lib("$group:kotlin-stdlib-common") val jdk8 by lib("$group:kotlin-stdlib-jdk8") diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/KotlinSemver.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/KotlinSemver.kt index c56f0a84c..1110e8cc4 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/KotlinSemver.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/KotlinSemver.kt @@ -26,13 +26,13 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.LibraryEntry +import io.spine.internal.catalog.model.CatalogEntry /** * [KotlinSemver](https://github.com/z4kn4fein/kotlin-semver) */ @Suppress("unused") -internal object KotlinSemver : LibraryEntry() { +internal object KotlinSemver : CatalogEntry() { override val version = "1.2.1" override val module = "io.github.z4kn4fein:semver" } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/KotlinX.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/KotlinX.kt index 5ac0d17e6..9e808dbf2 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/KotlinX.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/KotlinX.kt @@ -27,20 +27,18 @@ package io.spine.internal.catalog.entry import io.spine.internal.catalog.model.CatalogEntry -import io.spine.internal.catalog.model.DependencyEntry -import io.spine.internal.catalog.model.VersionEntry @Suppress("unused") internal object KotlinX : CatalogEntry() { - object Coroutines : VersionEntry() { + object Coroutines : CatalogEntry() { /** * [KotlinX.Coroutines](https://github.com/Kotlin/kotlinx.coroutines) */ override val version = "1.6.1" - object Core : DependencyEntry() { + object Core : CatalogEntry() { override val module = "org.jetbrains.kotlinx:kotlinx-coroutines-core" val jvm by lib("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm") } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/LicenseReport.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/LicenseReport.kt index d1edf4728..f9d5124ce 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/LicenseReport.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/LicenseReport.kt @@ -26,19 +26,18 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.LibraryEntry -import io.spine.internal.catalog.model.PluginEntry +import io.spine.internal.catalog.model.CatalogEntry /** * [LicenseReport](https://github.com/jk1/Gradle-License-Report) */ @Suppress("unused") -internal object LicenseReport : LibraryEntry() { +internal object LicenseReport : CatalogEntry() { override val version = "1.16" override val module = "com.github.jk1:gradle-license-report" - object GradlePlugin : PluginEntry() { + object GradlePlugin : CatalogEntry() { override val module = "com.github.jk1:gradle-license-report" override val id = "com.github.jk1.dependency-license-report" } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Netty.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Netty.kt index 1eb65f786..31cd00ff6 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Netty.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Netty.kt @@ -26,10 +26,10 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.DependencyEntry +import io.spine.internal.catalog.model.CatalogEntry @Suppress("unused") -internal object Netty : DependencyEntry() { +internal object Netty : CatalogEntry() { /** * [Releases](https://github.com/netty/netty/releases) diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Okio.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Okio.kt index c1b1888ec..a35b6c676 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Okio.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Okio.kt @@ -26,14 +26,14 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.LibraryEntry +import io.spine.internal.catalog.model.CatalogEntry /** * Okio is a transitive dependency which we don't use directly. * This object is used to force the version. */ @Suppress("unused") -internal object Okio : LibraryEntry() { +internal object Okio : CatalogEntry() { // This is the last version before next major. override val version = "1.17.5" override val module = "com.squareup.okio:okio" diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/OsDetector.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/OsDetector.kt index 98bcf4107..c88864472 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/OsDetector.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/OsDetector.kt @@ -26,13 +26,13 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.PluginEntry +import io.spine.internal.catalog.model.CatalogEntry /** * [OsDetector](https://github.com/google/osdetector-gradle-plugin) */ @Suppress("unused") -internal object OsDetector : PluginEntry() { +internal object OsDetector : CatalogEntry() { override val version = "1.7.0" override val module = "com.google.gradle:osdetector-gradle-plugin" override val id = "com.google.osdetector" diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Plexus.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Plexus.kt index 28b7756c6..6a8deccf3 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Plexus.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Plexus.kt @@ -26,7 +26,7 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.DependencyEntry +import io.spine.internal.catalog.model.CatalogEntry /** * Plexus Utils is a transitive dependency which we don't use directly. @@ -35,7 +35,7 @@ import io.spine.internal.catalog.model.DependencyEntry * [Plexus Utils](https://codehaus-plexus.github.io/plexus-utils/) */ @Suppress("unused") -internal object Plexus : DependencyEntry() { +internal object Plexus : CatalogEntry() { override val version = "3.4.0" val utils by lib("org.codehaus.plexus:plexus-utils") } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Pmd.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Pmd.kt index 6b38ac630..98584b5b9 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Pmd.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Pmd.kt @@ -26,12 +26,12 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.VersionEntry +import io.spine.internal.catalog.model.CatalogEntry /** * [Pmd](https://pmd.github.io/) */ @Suppress("unused") -internal object Pmd : VersionEntry() { +internal object Pmd : CatalogEntry() { override val version = "6.44.0" } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Protobuf.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Protobuf.kt index 8416226ca..cae64e348 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Protobuf.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Protobuf.kt @@ -26,14 +26,13 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.DependencyEntry -import io.spine.internal.catalog.model.PluginEntry +import io.spine.internal.catalog.model.CatalogEntry /** * [Protobuf](https://github.com/protocolbuffers/protobuf) */ @Suppress("unused") -internal object Protobuf : DependencyEntry() { +internal object Protobuf : CatalogEntry() { private const val group = "com.google.protobuf" override val version = "3.20.1" @@ -48,7 +47,7 @@ internal object Protobuf : DependencyEntry() { /** * [GradlePlugin](https://github.com/google/protobuf-gradle-plugin/releases) */ - object GradlePlugin : PluginEntry() { + object GradlePlugin : CatalogEntry() { override val version = "0.8.18" override val module = "$group:protobuf-gradle-plugin" override val id = "com.google.protobuf" diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Roaster.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Roaster.kt index f203536c4..ae9d3528e 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Roaster.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Roaster.kt @@ -26,13 +26,13 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.DependencyEntry +import io.spine.internal.catalog.model.CatalogEntry /** * [Roaster](https://github.com/forge/roaster) */ @Suppress("unused") -internal object Roaster : DependencyEntry() { +internal object Roaster : CatalogEntry() { /** * Do not advance this version further because it would break compatibility with Java 8 diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Slf4J.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Slf4J.kt index dc5505b15..fa40aafaf 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Slf4J.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Slf4J.kt @@ -26,7 +26,7 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.DependencyEntry +import io.spine.internal.catalog.model.CatalogEntry /** * Spine used to log with SLF4J. Now we use Flogger. Whenever a choice comes up, @@ -37,7 +37,7 @@ import io.spine.internal.catalog.model.DependencyEntry */ @Suppress("unused") @Deprecated("Use Flogger over SLF4J.", replaceWith = ReplaceWith("Flogger")) -internal object Slf4J : DependencyEntry() { +internal object Slf4J : CatalogEntry() { private const val group = "org.slf4j" override val version = "1.7.30" diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/TestKitTruth.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/TestKitTruth.kt index 505870b09..cd9e6fd39 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/TestKitTruth.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/TestKitTruth.kt @@ -26,7 +26,7 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.LibraryEntry +import io.spine.internal.catalog.model.CatalogEntry /** * Gradle TestKit extension for Google Truth. @@ -35,7 +35,7 @@ import io.spine.internal.catalog.model.LibraryEntry * [Usage description](https://dev.to/autonomousapps/gradle-all-the-way-down-testing-your-gradle-plugin-with-gradle-testkit-2hmc) */ @Suppress("unused") -internal object TestKitTruth : LibraryEntry() { +internal object TestKitTruth : CatalogEntry() { override val version = "1.1" override val module = "com.autonomousapps:testkit-truth" } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Truth.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Truth.kt index 987d8ddf1..18b5e85b1 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Truth.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/entry/Truth.kt @@ -26,16 +26,17 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.DependencyEntry +import io.spine.internal.catalog.model.CatalogEntry /** * [Truth](https://github.com/google/truth) */ @Suppress("unused") -internal object Truth : DependencyEntry() { +internal object Truth : CatalogEntry() { override val version = "1.1.3" + override val module = "com.google.truth:truth" override val bundle = setOf( - lib("truth", "com.google.truth:truth"), + this, lib("java8Extension", "com.google.truth.extensions:truth-java8-extension"), lib("protoExtension", "com.google.truth.extensions:truth-proto-extension"), ) diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/Alias.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/Alias.kt index 9915514e8..02ea2cffb 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/Alias.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/Alias.kt @@ -29,7 +29,11 @@ package io.spine.internal.catalog.model /** * A name, by which an item is known in a version catalog. * - * Each item within the catalog has its unique alias. + * It consists of one or more camel cased words separated by a hyphen. + * + * For example: `kotlinX-coroutines-gradlePlugin`. + * + * ### Role of aliases in the catalog * * Aliases perform two functions: * @@ -37,14 +41,77 @@ package io.spine.internal.catalog.model * 2. Referencing. One item in a version catalog can use another item, and this * linkage is done via aliases. * - * Please, consider an example of how aliases are mapped to the generated - * type-safe accessors of the catalog. + * A version catalog itself consists of four sections: versions, libraries, plugins + * and bundles (sets of libraries). Thus, an alias can point to a version, library, + * plugin or bundle. Within each section, an alias should be unique. + * + * ### Mapping to the generated accessors + * + * Below is an example of how aliases are mapped to the generated type-safe + * accessors of the catalog. + * + * Let's suppose, a catalog is named `libs` and each alias denotes a library: * * ``` - * "kotlinx-coroutines" => libs.kotlin.coroutines - * "kotlinx-coroutines-gradlePlugin" => libs.kotlin.coroutines.gradlePlugin - * "kotlinx-coroutines-runtime-jvm" => libs.kotlin.runtime.jvm - * "kotlinx-coroutines-runtime-clr" => libs.kotlin.runtime.clr + * "kotlinX-coroutines" => libs.kotlinX.coroutines + * "kotlinX-coroutines-gradlePlugin" => libs.kotlinX.coroutines.gradlePlugin + * "kotlinX-runtime-jvm" => libs.kotlinX.runtime.jvm + * "kotlinX-runtime-clr" => libs.kotlinX.runtime.clr * ``` + * + * Depending on which type of item an alias points to, the resulting accessor + * may have additional prefixes. + * + * Below are accessor patterns for different types of items: + * + * 1. Library: `{catalog name}.{alias}`. + * 2. Version: `{catalog name}.versions.{alias}`. + * 3. Plugin : `{catalog name}.plugins.{alias}`. + * 4. Bundle : `{catalog name}.bundles.{alias}`. */ -internal typealias Alias = String +@JvmInline +value class Alias private constructor(val value: String) { + + companion object { + + /** + * Gradle's recommended separator for sub-aliases. + */ + private const val SEPARATOR = "-" + + /** + * Composes an alias for the given entry. + * + * For a top-level entry it's just a camel-cased entry's name. + * + * For a nested entry, it's a parent alias plus camel-cased entry's name. + */ + fun forEntry(entry: CatalogEntry): Alias { + val className = entry.javaClass.simpleName.replaceFirstChar { it.lowercaseChar() } + val outerEntry = entry.outerEntry + val result = if (outerEntry != null) outerEntry.alias + className else Alias(className) + return result + } + } + + /** + * Returns a copy of this [Alias] with the given suffix appended. + */ + operator fun plus(suffix: String): Alias { + val newValue = value + SEPARATOR + suffix + val result = Alias(newValue) + return result + } + + /** + * If this [Alias] ends with the given [suffix], returns a copy of this alias + * with the suffix removed. + * + * Otherwise, returns this alias. + */ + operator fun minus(suffix: String): Alias { + val newValue = value.removeSuffix(SEPARATOR + suffix) + val result = if (newValue == value) this else Alias(newValue) + return result + } +} diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/CatalogEntry.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/CatalogEntry.kt index a9d6ac772..a31492245 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/CatalogEntry.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/CatalogEntry.kt @@ -27,83 +27,417 @@ package io.spine.internal.catalog.model /** - * A base catalog entry. + * Declaration of a dependency, which is going to become a part of a version catalog. * - * The main idea behind the concept of entries is to provide a declarative way to - * define catalog items. Entries expose a declarative API, leaving behind the scene - * all imperative code. Entries resemble a bridge between notations (a language, - * used to declare items) and records (the way, items are stored in the catalog). + * The main idea behind the concept of entries is to provide a declarative way + * to define catalog items: versions, libraries, plugins and bundles. Entries expose + * a declarative API, leaving behind the scene all imperative code. * - * Only object declarations are meant to serve as concrete entries. + * Out of declarations, which are done within an entry, it [produces][allRecords] + * a set of [CatalogRecord]s. Once produced, the records can be directly [written][CatalogRecord.writeTo] + * into a version catalog. The relationship between an entry and records it produces + * is "one to many". It means that a single entry can produce zero, one or more records. * - * As a base entry, this class takes a responsibility for the following: + * # Usage * - * 1. Support of nesting. An entry can nest one or more other entries. - * 2. Automatic aliasing for entries. An alias is picked up from the object's name, - * taking into account its nesting. + * Please note, only object declarations are meant to inherit from this class + * and serve as concrete entries. * - * The primary goal achieved by the `CatalogEntry` objects is to [produce][allRecords] - * a set of [CatalogRecord]s. It combines all the declarations within this entry and - * its nested entries. Once produced, the records can be directly [written][CatalogRecord.writeTo] - * into a version catalog. + * For example: * - * It is worth to mention, that the relationship between an entry and records it - * produces is "one to many". It means that a single entry can produce zero, one - * or more records. + * ``` + * internal object MyLib : CatalogEntry() { + * // ... + * } + * ``` + * + * ## Nesting + * + * One entry can be put into another one. When an entry is [asked][allRecords] + * for records, it will propagate the request down to its nested entries. + * Thus, only root entries should be used to produce records. + * + * ## Aliasing + * + * Each item in a version catalog should have [Alias]. An entry sets aliases on + * its own for items, declared within it. Automatic aliasing takes into account + * entry's nesting. + * + * One can declare an entry, which only hosts other entries. Thus, providing + * a named scope for other declarations. + * + * Consider the following example: + * + * ``` + * internal object Runtime : CatalogEntry() { // alias = "runtime" + * object Linux : CatalogEntry() // alias = "runtime-linux" + * object Mac : CatalogEntry() // alias = "runtime-mac" + * object Win : CatalogEntry() // alias = "runtime-win" + * } + * ``` + * + * See documentation to [Alias] to see how a type-safe accessor is generated + * from an alias. + * + * ## Declaring versions + * + * An entry which declares only a bare version is a quite rare case. Such entries + * can be used to declare a version of used tools. + * + * An example of how to declare a bare version: + * + * ``` + * internal object MyTool : CatalogEntry() { + * override val version = "1.0.0" + * } + * ``` + * + * ## Declaring libraries + * + * The most common case is a declaring a library. Most entries just declare a + * single library. + * + * An example of how to declare a library: + * + * ``` + * internal object MyLib : CatalogEntry() { + * override val version = "1.0.0" + * override val module = "com.company:my-lib" + * } + * ``` + * + * Sometimes, a dependency consists of several libraries. Or even of a group + * of libraries. A group can be extracted into a nested entry, and extra libraries + * can be declared by a [delegated property][lib]. + * + * For example: + * + * ``` + * internal object MyLib : CatalogEntry() { + * private const val group = "com.company" + * override val version = "1.9.0" + * override val module = "$group:my-lib" + * + * val runner by lib("$group:my-runner") + * val linter by lib("$group:my-linter") + * + * object Adapters : CatalogEntry() { + * val html4 by lib("$group:html4-adapter") + * val html5 by lib("$group:html5-adapter") + * } + * } + * ``` * - * A base entry doesn't produce any records. It can only be used as an outer entry - * for introducing a common alias. Such entries don't declare anything, they just - * serve as a named scope for nested declarations. + * Please note, that nested `Adapters` entry doesn't declare a version. In cases, + * when a version is not declared, an entry will try to fetch it from the closest + * parental entry, which has one. If the version is needed, but isn't found, + * an entry will throw an exception. * - * Below is an example of `Runtime` entry: + * ## Declaring plugins * + * The minimum, required to declare a plugin is a [version] and [id]. + * + * For example: + * + * ``` + * internal object MyPlugin : CatalogEntry() { + * override val version = "1.0.0" + * override val id = "com.company.plugin" + * } + * ``` + * + * A standalone plugin is also a quite rare case. Usually, they are declared + * within more complex entries, which represent frameworks or big libraries. + * A plugin can also be supplemented with a library, that makes possible applying + * it from `buildSrc`. + * + * For example: + * + * ``` + * internal object MyLib : CatalogEntry() { + * private const val group = "com.company" + * // ... + * + * object GradlePlugin : CatalogEntry() { + * override val version = "1.2.3" // libs.versions.myLib.gradlePlugin + * override val module = "$group:my-plugin" // libs.myLib.gradlePlugin + * override val id = "$group.plugin" // libs.plugins.myLib (without `gradlePlugin`!) + * } + * } * ``` - * internal object Runtime : CatalogEntry() { // alias = runtime - * object Linux : SomeEntry() // alias = runtime.linux - * object Mac : SomeEntry() // alias = runtime.mac - * object Win : SomeEntry() // alias = runtime.win + * + * In the example above, comments show the resulted generated accessors. Please note, + * that `GradlePlugin` is a special name for entries. Such an entry will not append + * `gradlePlugin` suffix for [id] item. It is done in order not to repeat yourself + * in naming. Otherwise, we would come up with this: `libs.plugins.myLib.gradlePlugin`. + * + * ## Declaring bundles + * + * A bundle is a named set of libraries. One can compose a bundle out of already + * declared extra libraries, in-place library declarations or entries, which + * declare a library. + * + * For example: + * + * ``` + * internal object MyLib : CatalogEntry() { + * private const val group = "com.company" + * override val version = "1.9.0" + * override val module = "$group:my-lib" + * + * object Adapters : CatalogEntry() { + * val html4 by lib("$group:html4-adapter") + * val html5 by lib("$group:html5-adapter") + * } + * + * object Runner : CatalogEntry() { + * override val version = "18.51.0" + * override val module = "$group:runner" + * } + * + * override val bundle = setOf( + * + * // Entries, which declare `module`. + * this, Runner, + * + * // Extra libraries, declared by `lib` delegate. + * Adapters.html4, + * Adapters.html5, + * + * // In-place declarations. + * lib("linter", "$group:linter"), + * lib("core", "$group:core"), + * ) * } * ``` * - * In the example above, `Linux`, `Mac` and `Win` are concrete entries, which may - * produce concrete records (such as a library, version, etc.). Meanwhile, `Runtime` - * does not produce anything. It's just hosting other entries, affecting their final alias. + * There's also a possibility to declare extra bundles on top of the current entry. + * Just like with extra libraries, using a [property delegate][bundle]. + * + * For example: + * + * ``` + * internal object MyLib : CatalogEntry() { + * private const val group = "com.company" + * override val version = "1.9.0" + * override val module = "$group:my-lib" + * + * object Adapters : CatalogEntry() { + * val html4 by lib("$group:html4-adapter") + * val html5 by lib("$group:html5-adapter") + * } * - * See also: [CatalogNotation], [CatalogRecord]. + * val adapters by bundle( + * Adapters.html4, + * Adapters.html5, + * ) + * } + * ``` */ -open class CatalogEntry : CatalogNotation { +abstract class CatalogEntry { + + private val extraLibs = mutableSetOf() + private val extraBundles = mutableSetOf() + private val versionRecord: VersionRecord by lazy { versionRecord() } + + /** + * A direct parent of this entry, if any. + */ + internal val outerEntry: CatalogEntry? = outerEntry() + + /** + * An alias of this entry. + * + * All items, declared within this entry, will receive this alias. + * + * [Extra libraries][lib] and [bundles][bundle], declared on top of this + * entry, will also use this alias as a base for their own aliases. + */ + @Suppress("LeakingThis") // `Alias.forEntry()` uses only final properties. + internal val alias: Alias = Alias.forEntry(this) + + /** + * Optionally, this entry can declare a version. + * + * In order to do that, override this property, specifying a string + * representation of a version. + * + * For example: `2.0.0-SNAPSHOT.21`. + * + * A declared version will inherit entry's [alias]. + */ + open val version: String? = null + + /** + * Optionally, this entry can declare a library. + * + * In order to do that, override this property, specifying a group and + * artifact of a library, seperated by a colon. + * + * For example: `io.spine:spine-core`. + * + * A declared library will inherit entry's [alias]. + * + * When declaring [module], make sure that this entry or any parental one + * declares [version]. A library can't be declared without version. + */ + open val module: String? = null + + /** + * Optionally, this entry can declare a plugin. + * + * In order to do that, override this property, specifying a plugin id. + * + * For example: `org.jetbrains.kotlin.jvm`. + * + * A declared plugin will inherit entry's [alias]. + * + * When declaring [id], make sure that this entry or any parental one + * declares [version]. A plugin can't be declared without version. + */ + open val id: String? = null + + /** + * Optionally, this entry can declare a bundle (named set of libraries). + * + * In order to do that, override this property, specifying a set of libraries. + * + * The following declarations are acceptable to be passed into this set: + * + * 1. [CatalogEntry]s which declare [module]. + * 2. Extra libraries, declared by a [delegated property][lib]. + * 3. Extra libraries, declared by a [method][lib] right in this set. + * + * An example snippet is present in `Declaring bundles` section of + * documentation to [CatalogEntry]. + * + * A declared bundle will inherit entry's [alias]. + */ + open val bundle: Set? = null /** - * A parent entry, within which this entry resides, if present. + * Declares an extra library on top of this entry, using property delegation. + * + * An example usage: + * + * ``` + * val core by lib("my.company:core-lib") + * ``` + * + * The resulting alias fot this library is entry's [alias] followed by + * a property name. */ - protected val outerEntry: CatalogEntry? = outerEntry() + fun lib(module: String): MemoizingDelegate = + delegate { property -> lib(property.name, module) } /** - * Object's name with respect to entity's nesting. + * Declares an extra library on top of this entry. + * + * This method allows declaring libraries right in bundle declarations: * - * We say "object" here because all concrete entries are meant to be - * object declarations. + * ``` + * val bundle = setOf( + * lib("core", "my.company:core-lib"), + * lib("types", "my.company:types-lib"), + * lib("lang", "my.company:lang-lib") + * ) + * ``` + * + * The resulting alias fot this library is entry's [alias] followed by + * the given name. */ - final override val alias: Alias = alias() + fun lib(name: String, module: String): CatalogRecord { + val libAlias = alias + name + val record = LibraryRecord(libAlias, module, versionRecord) + return record.also { extraLibs.add(it) } + } /** - * A base entry produce no records. + * Declares an extra bundle on top of this entry, using property delegation. + * + * The following declarations are acceptable to be passed into this set: + * + * 1. [CatalogEntry]s which declare [module]. + * 2. Extra libraries, declared by a [delegated property][lib]. + * 3. Extra libraries, declared by a [method][lib] right in this set. + * + * An example snippet is present in `Declaring bundles` section of + * documentation to [CatalogEntry]. + * + * The resulting alias fot this library is entry's [alias] followed by + * a property name. */ - protected open fun records(): Set = emptySet() + fun bundle(vararg libs: Any): MemoizingDelegate = + delegate { property -> + val bundleAlias = alias + property.name + val libRecords = libs.asIterable().toLibraryRecords() + val record = BundleRecord(bundleAlias, libRecords) + record.also { extraBundles.add(it) } + } /** - * Obtains all catalog records, produced by this entry and its nested entries. + * Produces [CatalogRecord]s out of declarations, performed within this + * entry and its nested entries. + * + * When an entry is asked for records, it will propagate the request down + * to its nested entries. For this reason, this method should be called only + * on top-level (root) entries. + * + * Calling of this method on a nested entry leads to an exception. */ fun allRecords(): Set { + + if (outerEntry != null) { + throw IllegalStateException("Only root entries can produce records!") + } + + val allRecords = records() + return allRecords + } + + private fun records(): Set { + val fromThisEntry = recordsFromThisEntry() + val fromNested = recordsFromNested() + val result = fromThisEntry + fromNested + return result + } + + private fun recordsFromThisEntry(): Set { val result = mutableSetOf() - val fromThisEntry = records() - result.addAll(fromThisEntry) + if (version != null) { + val record = VersionRecord(alias, version!!) + result.add(record) + } + + if (module != null) { + val record = LibraryRecord(alias, module!!, versionRecord) + result.add(record) + } + + if (id != null) { + val pluginAlias = alias - "gradlePlugin" + val record = PluginRecord(pluginAlias, id!!, versionRecord) + result.add(record) + } + + if (bundle != null) { + val libs = bundle!!.toLibraryRecords() + val record = BundleRecord(alias, libs) + result.add(record) + } + + extraLibs.forEach { result.add(it) } + extraBundles.forEach { result.add(it) } + return result + } + + private fun recordsFromNested(): Set { + val result = mutableSetOf() val nestedEntries = nestedEntries() - val fromNested = nestedEntries.flatMap { it.allRecords() } + val fromNested = nestedEntries.flatMap { it.records() } result.addAll(fromNested) - return result } @@ -125,11 +459,28 @@ open class CatalogEntry : CatalogNotation { return enclosingInstance } - private fun alias(): String { - val className = this::class.java.simpleName.toCamelCase() - val alias = if (outerEntry != null) "${outerEntry.alias}-$className" else className - return alias + private fun versionRecord(): VersionRecord = when { + version != null -> VersionRecord(alias, version!!) + outerEntry != null -> outerEntry.versionRecord + else -> throw IllegalStateException("Specify version in this entry or any parental one!") } - private fun String.toCamelCase() = replaceFirstChar { it.lowercaseChar() } + private fun Iterable.toLibraryRecords(): Set { + val result = map { it.toLibraryRecord() }.toSet() + return result + } + + private fun Any.toLibraryRecord(): LibraryRecord { + if (this is LibraryRecord) { + return this + } + + if (this is CatalogEntry) { + val entry = this + val record = LibraryRecord(entry.alias, entry.module!!, entry.versionRecord) + return record + } + + throw IllegalArgumentException("Unknown object has been passed: $this!") + } } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/CatalogNotations.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/CatalogNotations.kt deleted file mode 100644 index 6f307bf22..000000000 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/CatalogNotations.kt +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2022, TeamDev. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and/or binary forms, with or without - * modification, must retain the above copyright notice and the following - * disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package io.spine.internal.catalog.model - -/** - * Defines what information is necessary to create one or another version - * catalog-compatible item. - * - * Notations are citizens of a declaration site. They form DSL and say what is - * needed from the point of view of who provides this information. In other words, - * they define what input is required from a user. - * - * They are used for the following purposes: - * - * 1. To set a language, which is then implemented by entries (link below). - * 2. To hold data. Sometimes, one item needs to reference another item. - * This communication can be done via notations. For example, property - * delegates in `DependencyEntry` return notations, which can be consumed - * by other delegates or methods. - * - * This interface, in particular, doesn't describe any concrete catalog item. - * It just serves as a common foundation for other notations. - * - * Direct implementation: [CatalogEntry][io.spine.internal.catalog.entry.CatalogEntry]. - */ -interface CatalogNotation { - - /** - * A name, by which this item will be known in the catalog. - * - * For example: `kotlin.stdLib.common.jvm`. - */ - val alias: Alias -} - -/** - * Information, required to create a version item. - * - * Direct implementation: [VersionEntry][io.spine.internal.catalog.entry.VersionEntry]. - */ -interface VersionNotation : CatalogNotation { - - /** - * A string value, which denotes a version. - * - * For example: `2.0.0-SNAPSHOT.21`. - */ - val version: String -} - -/** - * Information, required to create a library item. - * - * Direct implementation: [LibraryEntry][io.spine.internal.catalog.entry.LibraryEntry]. - */ -interface LibraryNotation : VersionNotation { - - /** - * Group and artifact of a library, seperated by a colon. - * - * For example: `io.spine:spine-core`. - */ - val module: String -} - -/** - * Information, required to create a plugin item. - * - * Direct implementation: [PluginEntry][io.spine.internal.catalog.entry.PluginEntry]. - */ -interface PluginNotation : LibraryNotation { - - /** - * A unique name, by which a plugin is represented in both Gradle Plugin Portal - * and in the project. - * - * For example: `org.jetbrains.kotlin.jvm`. - */ - val id: String -} - -/** - * Information, required to create a bundle item. - * - * Direct implementation: [DependencyEntry][io.spine.internal.catalog.entry.DependencyEntry]. - */ -interface BundleNotation : CatalogNotation { - - /** - * Set of libraries, to be referenced as a whole. - */ - val bundle: Set -} diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/CatalogRecords.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/CatalogRecords.kt index cb7ce6c26..9c16793a5 100644 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/CatalogRecords.kt +++ b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/CatalogRecords.kt @@ -29,42 +29,26 @@ package io.spine.internal.catalog.model import org.gradle.api.initialization.dsl.VersionCatalogBuilder /** - * A single, atomic unit, which can be written into a version catalog. + * An atomic unit, which can be written into a version catalog. * - * Records say what information is necessary to write one or another item into - * a version catalog. Theirs properties strictly reflect the way, an item is - * stored in the catalog. + * Records strictly reflect the way, the information is stored in the catalog. + * Due to this fact, they don't need any preparations to be written there. * - * Similarly to [notations][CatalogNotation], records define what information is - * needed to create one or another catalog-compatible item. But in contrast to - * notations, records are citizens of an implementation site. They sas what is needed - * from the point of view of how this information is actually stored in the catalog. + * This interface, doesn't represent a concrete catalog item. It serves as a common + * foundation for other records. * - * Consider the following example: - * - * ``` - * // A user defines a plugin, using the corresponding notation. - * - * val plugin = object : PluginNotation { - * override val id: String = "kotlin-jvm" - * override val module: String = "org.jetbrains:kotlin-jvm" - * override val version: String = "1.6.21" - * override val alias: Alias = "kotlin.jvm" - * } - * ``` - * - * In order to represent this notation in [VersionCatalogBuilder], three records - * should be written there: [VersionRecord], [LibraryRecord], [PluginRecord]. - * - * This interface, in particular, doesn't describe any concrete catalog item. - * It just serves as a common foundation for other records. + * All concrete records are internal by design. They are assembled by [CatalogEntry] + * under the hood and not meant to be exposed to end-users. All a user might need + * to do with a record is to write it into the catalog, which can be done with + * this public interface. */ interface CatalogRecord { /** * A name, by which this record will be known in the catalog. * - * For example: `kotlin.stdLib.common.jvm`. + * See documentation to [Alias] to see how a type-safe accessor is generated + * from an alias. */ val alias: Alias @@ -75,7 +59,7 @@ interface CatalogRecord { } /** - * Represents a version item, which can be directly written into a version catalog. + * A version, which can be directly written into a version catalog. * * [value] is a string representation of a version. * @@ -87,67 +71,62 @@ internal data class VersionRecord( ) : CatalogRecord { override fun writeTo(catalog: VersionCatalogBuilder) { - catalog.version(alias, value) + catalog.version(alias.value, value) } } /** - * Represents a library item, which can be directly written into a version catalog. + * A library, which can be directly written into a version catalog. * * [module] is a group and artifact of a library, seperated by a colon. * * For example: `io.spine:spine-core`. * - * Version for the library is obtained by the reference. Thus, the given [versionRef] - * should point to a [VersionRecord]. + * A version of the library is referenced by the given [version record][version]. */ internal data class LibraryRecord( override val alias: Alias, val module: String, - val versionRef: Alias + val version: VersionRecord ) : CatalogRecord { override fun writeTo(catalog: VersionCatalogBuilder) { val group = module.substringBefore(':') val artifact = module.substringAfter(':') - catalog.library(alias, group, artifact).versionRef(versionRef) + catalog.library(alias.value, group, artifact).versionRef(version.alias.value) } } /** - * Represents a plugin item, which can be directly written into a version catalog. + * A plugin, which can be directly written into a version catalog. * * [id] is a unique name, by which a plugin is represented in both Gradle Plugin Portal * and in the project. * * For example: `org.jetbrains.kotlin.jvm`. * - * Version of the plugin is obtained by the reference. Thus, the given [versionRef] - * should point to a [VersionRecord]. + * A version of the plugin is referenced by the given [version record][version]. */ internal data class PluginRecord( override val alias: Alias, val id: String, - val versionRef: Alias + val version: VersionRecord ) : CatalogRecord { override fun writeTo(catalog: VersionCatalogBuilder) { - catalog.plugin(alias, id).versionRef(versionRef) + catalog.plugin(alias.value, id).versionRef(version.alias.value) } } /** - * Represents a named set of libraries, which can be directly written into - * a version catalog - * - * It is expected, that each alias in [libs] points to a [LibraryRecord]. + * A named set of libraries, which can be directly written into a version catalog */ internal data class BundleRecord( override val alias: Alias, - val libs: Set + val libs: Set ) : CatalogRecord { override fun writeTo(catalog: VersionCatalogBuilder) { - catalog.bundle(alias, libs.toList()) + catalog.bundle(alias.value, libs.map { it.alias.value }) } } diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/DependencyEntry.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/DependencyEntry.kt deleted file mode 100644 index 7b54fa510..000000000 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/DependencyEntry.kt +++ /dev/null @@ -1,278 +0,0 @@ -/* - * Copyright 2022, TeamDev. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and/or binary forms, with or without - * modification, must retain the above copyright notice and the following - * disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package io.spine.internal.catalog.model - -/** - * A compound catalog entry, which is used to declare complex dependencies. - * - * Although, many dependencies can be represented by a single [LibraryEntry], - * some are a way more complex. They may consist of several modules, versions - * and bundles. For example, frameworks. - * - * This entry can declare a library and version. But, in case it is all you need, - * it is better to use a simpler entries: [VersionEntry] and [LibraryEntry]. - * - * An example of a version and module declaration: - * - * ``` - * internal object MyLib : DependencyEntry() { - * override val version = "1.9.0" // libs.versions.myLib - * override val module = "ua.company:my-lib" // libs.myLib - * } - * ``` - * - * The main feature of this entry is a possibility to declare extra [libraries][lib] - * and [bundles][bundle] on top of this entry, using property delegation. - * - * An example of declaring several extra libraries and an extra bundle: - * - * ``` - * internal object MyLib : DependencyEntry() { - * - * override val version = "1.9.0" // libs.versions.myLib - * override val module = "ua.company:my-lib" // libs.myLib - * - * object Adapters : DependencyEntry() { - * val html4 by lib("ua.company:html4-adapter") // libs.myLib.adapters.html4 - * val html5 by lib("ua.company:html5-adapter") // libs.myLib.adapters.html5 - * } - * - * val adapters by bundle( // libs.bundles.myLib.adapters - * Adapters.html4, - * Adapters.html5 - * ) - * } - * ``` - * - * Even more, a code snippet above can be re-written even simpler, using in-place - * bundle declaration and method calls to declare extra libraries. - * - * Below is the same example as above, but re-written with in-place API: - * - * ``` - * internal object MyLib : DependencyEntry() { - * - * override val version = "1.9.0" // libs.versions.myLib - * override val module = "ua.company:my-lib" // libs.myLib - * - * object Adapters : DependencyEntry() { - * override val bundle = setOf( - * lib("html4", "ua.company:html4-adapter"), - * lib("html5", "ua.company:html5-adapter") - * ) - * } - * } - * ``` - * - * Bundles can't include entries, within which they are declared. A [DependencyEntry] - * can't guarantee that a library is declared within it. Library declaration is - * optional for such entries. - * - * Something like this is NOT possible: - * - * ``` - * internal object MyLib : DependencyEntry() { - * - * override val version = "1.9.0" // libs.versions.myLib - * override val module = "ua.company:my-lib" // libs.myLib - * - * val types by lib("ua.company:my-types") // libs.myLib.types - * val data by lib("ua.company:my-data") // libs.myLib.data - * - * // Referencing to [this] is not supported. - * override val bundle = setOf(this, types, data) // libs.bundles.myLib - * } - * ``` - * - * When one needs a bundle and library named after the enclosing entry itself, - * (or even more, that bundle should include that library) one can declare an - * extra library, named after the entry in which it is declared. It is a special - * case for extra libraries. In this case, the entry will not concat its name - * with library's one. - * - * Let's re-write a snippet above with that knowledge: - * - * ``` - * internal object MyLib : DependencyEntry() { - * - * override val version = "1.9.0" // libs.versions.myLib - * - * val myLib by lib("ua.company:my-lib") // libs.myLib (not libs.myLib.myLib!) - * val types by lib("ua.company:my-types") // libs.myLib.types - * val data by lib("ua.company:my-data") // libs.myLib.data - * - * override val bundle = setOf(myLib, types, data) // libs.bundles.myLib - * } - * ``` - * - * The desired goal has been achieved. We came up with a library and bundle, both - * named after the enclosing entry: `libs.myLib` and `libs.bundles.myLib`. - * And the bundle includes the library. - */ -open class DependencyEntry : VersionInheritingEntry() { - - private val standaloneLibs = mutableSetOf() - private val standaloneBundles = mutableSetOf() - - /** - * Optionally, this entry can declare a module. - * - * When declaring a module, make sure the entry has a version to compose a [LibraryRecord]. - * The version can be declared right in this entry or inherited from the outer one. - */ - open val module: String? = null - - /** - * Optionally, this entry can declare a bundle. - * - * The bundle elements can be: [LibraryEntry]s and extra libraries. - * - * An example usage is provided in documentation to this class. - */ - open val bundle: Set? = null - - /** - * This entry is very flexible in how many records it can produce. - * - * It may produce zero, one or more: [LibraryRecord]s and [BundleRecord]s. - * - * And also, it may produce zero or one [io.spine.internal.catalog.VersionRecord]. - */ - override fun records(): Set { - val result = mutableSetOf() - - val optionalVersion = super.records() - result.addAll(optionalVersion) - - if (module != null) { - val library = LibraryRecord(alias, module!!, versionAlias) - result.add(library) - } - - if (bundle != null) { - val aliases = bundle!!.map { it.alias }.toSet() - val bundle = BundleRecord(alias, aliases) - result.add(bundle) - } - - val extraBundles = standaloneBundles.map { record(it) } - result.addAll(extraBundles) - - val extraLibraries = standaloneLibs.map { record(it) } - result.addAll(extraLibraries) - - return result - } - - private fun record(notation: BundleNotation): BundleRecord { - val aliases = notation.bundle.map { it.alias }.toSet() - val record = BundleRecord(notation.alias, aliases) - return record - } - - private fun record(notation: LibraryNotation): LibraryRecord { - val record = LibraryRecord(notation.alias, notation.module, versionAlias) - return record - } - - /** - * Declares a library on the top of this entry. - * - * This method is useful to declare libraries right in a bundle declaration: - * - * ``` - * val bundle = setOf( - * lib("core", "my.company:core-lib"), - * lib("types", "my.company:types-lib"), - * lib("lang", "my.company:lang-lib") - * ) - * ``` - * - * When a property and entry have the same name, it is not duplicated in - * the resulting alias of the library. - */ - fun lib(name: String, module: String): LibraryNotation { - val thisEntryAlias = this.alias - val libAlias = if (thisEntryAlias.endsWith(name)) thisEntryAlias - else "$thisEntryAlias-$name" - - val notation = object : LibraryNotation { - override val alias: String = libAlias - override val version: String = "" // will be taken from this entry - override val module: String = module - } - - standaloneLibs.add(notation) - return notation - } - - /** - * Declares a library on the top of this entry, using property delegation. - * - * The name of library will be the same as a property name. - * - * An example usage: - * - * ``` - * val core by lib("my.company:core-lib") - * ``` - * - * When a property and entry have the same name, it is not duplicated in - * the resulting alias of the library. - */ - fun lib(module: String): MemoizingDelegate = - delegate { property -> lib(property.name, module) } - - /** - * Declares a bundle on top of this entry, using property delegation. - * - * The name of a bundle will be the same as a property name. - * - * An example usage: - * - * ``` - * val runtime by bundle( - * lib("mac", "my.company:mac-lib"), - * lib("linux", "my.company:linux-lib"), - * lib("win", "my.company:win-lib") - * ) - * ``` - */ - fun bundle(vararg libs: LibraryNotation): MemoizingDelegate = - delegate { property -> - val thisEntryAlias = this.alias - val bundleAlias = "$thisEntryAlias-${property.name}" - - val notation = object : BundleNotation { - override val alias: String = bundleAlias - override val bundle: Set = libs.toSet() - } - - standaloneBundles.add(notation) - notation - } -} diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/LibraryEntry.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/LibraryEntry.kt deleted file mode 100644 index 3531efa11..000000000 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/LibraryEntry.kt +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2022, TeamDev. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and/or binary forms, with or without - * modification, must retain the above copyright notice and the following - * disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package io.spine.internal.catalog.model - -/** - * A catalog entry, which is used to declare a library. - * - * Only object declarations are meant to inherit from this class. - * - * Below is an example of how to declare a library using this entry: - * - * ``` - * internal object MyLib : LibraryEntry() { - * override val version = "1.0.0" - * override val module = "org.my.company:my-lib" - * } - * ``` - */ -abstract class LibraryEntry : CatalogEntry(), LibraryNotation { - - /** - * Produces [VersionRecord] and [LibraryRecord]. - */ - override fun records(): Set { - val version = VersionRecord(alias, version) - val library = LibraryRecord(alias, module, alias) - return setOf(version, library) - } -} diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/PluginEntry.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/PluginEntry.kt deleted file mode 100644 index 7fd99dbc5..000000000 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/PluginEntry.kt +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright 2022, TeamDev. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and/or binary forms, with or without - * modification, must retain the above copyright notice and the following - * disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package io.spine.internal.catalog.model - -/** - * A catalog entry, which is used to declare a Gradle plugin. - * - * Only object declarations are meant to inherit from this class. - * - * Below is an example of how to declare a plugin using this entry: - * - * ``` - * internal object MyPlugin : PluginEntry() { - * override val version = "1.0.0" - * override val module = "org.my.company:my-gradle-plugin" - * override val id = "org.my.company.plugin" - * } - * ``` - * - * Specifying of [version] is optional, when it can be inherited from - * the outer entry. - * - * An example with an inherited version: - * - * ``` - * internal object MyLib : VersionEntry() { - * override val version = "1.2.3" - * - * object GradlePlugin : PluginEntry() { - * override val module = "org.my.company:my-gradle-plugin" - * override val id = "org.my.company.plugin" - * } - * } - * ``` - * - * Also, there's a special treatment for plugin entries named "GradlePlugin". - * For them, "gradlePlugin" suffix will not be appended to a final plugin's alias. - * - * Consider the following example: - * - * ``` - * internal object MyLib : CatalogEntry() { - * object GradlePlugin : PluginEntry() { - * override val version = "1.2.3" // libs.versions.myLib.gradlePlugin - * override val module = "my.company:my-plugin" // libs.myLib.gradlePlugin - * override val id = "org.my.company.plugin" // libs.plugins.myLib - * } - * } - * ``` - * - * In the example above, the side comments demonstrate the generated accessors. - * The version and module have `gradlePlugin` suffix, while the plugin doesn't. - * It is done so in order not to repeat yourself in naming. Otherwise, we would - * come up with this: `libs.plugins.myLib.gradlePlugin`. - */ -abstract class PluginEntry : VersionInheritingEntry(), PluginNotation { - - private val pluginAlias: Alias by lazy { pluginAlias() } - - /** - * Always produces [PluginRecord] and [LibraryRecord]. - * - * Optionally, it can produce [VersionRecord] if the entry declares it - * on its own. - */ - override fun records(): Set { - val result = mutableSetOf() - - val optionalVersion = super.records() - result.addAll(optionalVersion) - - val library = LibraryRecord(alias, module, versionAlias) - result.add(library) - - val record = PluginRecord(pluginAlias, id, versionAlias) - result.add(record) - - return result - } - - private fun pluginAlias(): Alias = - if (alias.endsWith("gradlePlugin")) alias.substringBeforeLast('-') else alias -} diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/VersionEntry.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/VersionEntry.kt deleted file mode 100644 index 8d5ae6b1e..000000000 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/VersionEntry.kt +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2022, TeamDev. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and/or binary forms, with or without - * modification, must retain the above copyright notice and the following - * disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package io.spine.internal.catalog.model - -/** - * A catalog entry, which is used to declare a bare version. - * - * Only object declarations are meant to inherit from this class. - * - * Below is an example of how to declare a version using this entry: - * - * ``` - * internal object PMD : VersionEntry() { - * override val version = "1.0.0" - * } - * ``` - */ -abstract class VersionEntry : CatalogEntry(), VersionNotation { - - /** - * Produces a single [VersionRecord]. - */ - override fun records(): Set { - val record = VersionRecord(alias, version) - return setOf(record) - } -} diff --git a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/VersionInheritingEntry.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/VersionInheritingEntry.kt deleted file mode 100644 index 068deb2f5..000000000 --- a/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/VersionInheritingEntry.kt +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright 2022, TeamDev. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and/or binary forms, with or without - * modification, must retain the above copyright notice and the following - * disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package io.spine.internal.catalog.model - -/** - * A version entry, which can take the version from the outer entry. - * - * From the outside it looks like the entry just "inherits" the version from - * its parent. - * - * This entry is not meant to be used directly, rather server as a foundation - * for other entries. - * - * In order to understand why it's needed, consider the following snippet: - * - * ``` - * internal object Kotlin : LibraryEntry() { - * override val version = "1.6.21" // libs.versions.kotlin - * override val module = "jetbrains:kotlin" // libs.kotlin - * - * object Runtime : LibraryEntry() { - * override val version = Kotlin.version // libs.versions.kotlin.runtime - * override val module = "jetbrains:kotlin-runtime" // libs.kotlin.runtime - * } - * } - * ``` - * - * Both `Kotlin` and `Kotlin.Runtime` libraries will receive the same version, - * declared in a single place. But for each library, an independent version - * record will be created: - * - * 1. `libs.versions.kotlin`. - * 2. `libs.versions.kotlin.runtime`. - * - * Thus, a local overriding (in settings file) of `libs.versions.kotlin` will - * not affect the version of `Kotlin.Runtime` library. But, intuitively should. - * - * In contrast, when using this entry, there's no need in manual declaration of - * the version in the nested entry. A version inheriting entry can take the version - * from the outer entry on its own. - * - * Consider the same snippet, but with an entry which extends this class: - * - * ``` - * internal object Kotlin : LibraryEntry() { - * override val version = "1.6.21" // libs.versions.kotlin - * override val module = "org.jetbrains:kotlin" // libs.kotlin - * - * object Runtime : SomeVersionInheritingEntry() { - * override val module = "org.jetbrains:kotlin-runtime" // libs.kotlin.runtime - * } - * } - * ``` - * - * Going this way, only `libs.versions.kotlin` will be generated and available - * for a local override. Both `Kotlin` and `Kotlin.Runtime` libraries will - * reference `libs.versions.kotlin` version. When this version is overridden, - * both libraries will be affected as well. - * - * Although, such entries are not bound to use only an inherited version. - * It is still possible to declare the version within this entry. But in case, - * when neither this entry nor its outer one declares a version, an exception - * will be thrown. - * - * See direct implementations: [PluginEntry], [DependencyEntry]. - */ -open class VersionInheritingEntry : CatalogEntry(), VersionNotation { - - private companion object { - const val FROM_PARENT = "" - } - - /** - * A version of this entry. - * - * When unspecified, the entry will try to use the version, declared in - * the outer entry. - * - * Please note, a presence of the version is mandatory. And if neither this - * entry nor its outer one declares a version, an exception will be thrown. - */ - override val version: String = FROM_PARENT - - /** - * When inheritors of this class need a version, they should use this reference. - * - * It is lazy by design. Otherwise, if this property is computed during class - * initialization, we will never be able to handle a version, declared by - * this entry on its own. - * - * In other words, making this property non-lazy eliminates a possibility - * of a version declaration for this entry. It will be able only to inherit - * the version from the outer entry. - */ - protected val versionAlias: Alias by lazy { versionAlias() } - - override fun records(): Set { - - if (version == FROM_PARENT) { - return emptySet() - } - - val version = VersionRecord(alias, version) - return setOf(version) - } - - private fun versionAlias(): Alias = when { - version != FROM_PARENT -> alias - outerEntry is VersionInheritingEntry -> outerEntry.versionAlias - outerEntry is VersionNotation -> outerEntry.alias - else -> throw IllegalStateException("Specify version in this entry or the outer entry!") - } -} diff --git a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/CatalogEntryTest.kt b/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/CatalogEntryTest.kt index dba71710b..8c940103d 100644 --- a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/CatalogEntryTest.kt +++ b/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/CatalogEntryTest.kt @@ -27,8 +27,24 @@ package io.spine.internal.catalog.model import com.google.common.truth.Truth.assertThat -import io.spine.internal.catalog.model.given.OuterDummy -import io.spine.internal.catalog.model.given.StandaloneDummy +import io.spine.internal.catalog.model.given.BundleEntry +import io.spine.internal.catalog.model.given.CatalogEntryTestEnv.Companion.bundleRecord +import io.spine.internal.catalog.model.given.CatalogEntryTestEnv.Companion.libraryRecord +import io.spine.internal.catalog.model.given.CatalogEntryTestEnv.Companion.pluginRecord +import io.spine.internal.catalog.model.given.CatalogEntryTestEnv.Companion.versionRecord +import io.spine.internal.catalog.model.given.DirectInheritingEntry +import io.spine.internal.catalog.model.given.EmptyRootEntry +import io.spine.internal.catalog.model.given.ErroneousLibraryEntry +import io.spine.internal.catalog.model.given.ErroneousPluginEntry +import io.spine.internal.catalog.model.given.ExtraBundleEntry +import io.spine.internal.catalog.model.given.ExtraLibraryEntry +import io.spine.internal.catalog.model.given.IndirectInheritingEntry +import io.spine.internal.catalog.model.given.LibraryEntry +import io.spine.internal.catalog.model.given.OuterEntry +import io.spine.internal.catalog.model.given.WithPluginEntry +import io.spine.internal.catalog.model.given.PluginEntry +import io.spine.internal.catalog.model.given.RootEntry +import io.spine.internal.catalog.model.given.VersionEntry import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test @@ -38,65 +54,200 @@ import org.junit.jupiter.api.assertThrows internal class CatalogEntryTest { @Nested - inner class `when standalone` { + inner class `when is root` { - private val standaloneEntry = StandaloneDummy + @Nested + inner class `optionally declare` { - @Test - fun `use object's name as alias`() { - assertThat(standaloneEntry.alias).isEqualTo("standaloneDummy") + @Test + fun `a version`() { + val entry = VersionEntry + val records = entry.allRecords() + assertThat(records).hasSize(1) + + val record = versionRecord(records) + assertThat(record.alias.value).isEqualTo("versionEntry") + assertThat(record.value).isEqualTo("v0.0.1") + } + + @Test + fun `a library`() { + val entry = LibraryEntry + val records = entry.allRecords() + assertThat(records).hasSize(2) + + val library = libraryRecord(records) + assertThat(library.alias.value).isEqualTo("libraryEntry") + assertThat(library.module).isEqualTo("com.company:lib") + + val version = versionRecord(records) + assertThat(library.version).isEqualTo(version) + } + + @Test + fun `an extra library`() { + val entry = ExtraLibraryEntry + val records = entry.allRecords() + assertThat(records).hasSize(2) + + val library = libraryRecord(records) + assertThat(library.alias.value).isEqualTo("extraLibraryEntry-core") + assertThat(library.module).isEqualTo("com.company:core-lib") + + val version = versionRecord(records) + assertThat(library.version).isEqualTo(version) + } + + @Test + fun `a plugin`() { + val entry = PluginEntry + val records = entry.allRecords() + assertThat(records).hasSize(2) + + val plugin = pluginRecord(records) + assertThat(plugin.alias.value).isEqualTo("pluginEntry") + assertThat(plugin.id).isEqualTo("com.company.plugin") + + val version = versionRecord(records) + assertThat(plugin.version).isEqualTo(version) + } + + @Test + fun `a bundle`() { + val entry = BundleEntry + val records = entry.allRecords() + assertThat(records).hasSize(5) + + val bundle = bundleRecord(records) + assertThat(bundle.alias.value).isEqualTo("bundleEntry") + + val expected = records.filterIsInstance().toSet() + assertThat(expected).hasSize(3) + assertThat(bundle.libs).isEqualTo(expected) + } + + @Test + fun `an extra bundle`() { + val entry = ExtraBundleEntry + val records = entry.allRecords() + assertThat(records).hasSize(5) + + val bundle = bundleRecord(records) + assertThat(bundle.alias.value).isEqualTo("extraBundleEntry-full") + + val expected = records.filterIsInstance().toSet() + assertThat(expected).hasSize(3) + assertThat(bundle.libs).isEqualTo(expected) + } } @Test - fun `produce no records`() { - assertThat(standaloneEntry.allRecords()).isEmpty() + fun `produce no records if empty`() { + val entry = EmptyRootEntry + val records = entry.allRecords() + assertThat(records).isEmpty() } - } - - @Nested - inner class `when nested` { @Test - fun `regard parent entries in alias`() { - val nested = OuterDummy.Runtime.Mac - assertThat(nested.alias).isEqualTo("outerDummy-runtime-mac") + fun `ask nested entries for records`() { + val entry = RootEntry + val records = entry.allRecords() + assertThat(records).hasSize(5) } @Test - fun `throw an exception when being nested in a plain object`() { - val exception = assertThrows { - // Let's trigger object initializing. - OuterDummy.NotEntry.Api.Params - } - - val cause = exception.cause - assertThat(cause).isInstanceOf(IllegalStateException::class.java) - assertThat(cause).hasMessageThat().isEqualTo("Plain objects can't nest entries!") + fun `use object's name for alias`() { + val entry = RootEntry + val record = entry.allRecords().first() + assertThat(record.alias.value).isEqualTo("rootEntry") } } @Nested - inner class `when outer` { + inner class `when is nested` { - @Test - fun `ask nested entries for records`() { + @Nested + inner class `inherit the version from` { - val nested = listOf( - OuterDummy.Runtime, - OuterDummy.Runtime.Mac, - OuterDummy.Runtime.Win, - OuterDummy.Runtime.Linux, - ) + @Test + fun `direct parent`() { + val entry = DirectInheritingEntry + val records = entry.allRecords() + assertThat(records).hasSize(2) - nested.forEach { - assertThat(it.wasAsked).isFalse() + val library = libraryRecord(records) + assertThat(library.alias.value).isEqualTo("directInheritingEntry-inheritor") + assertThat(library.module).isEqualTo("com.company:lib") + + val version = versionRecord(records) + assertThat(library.version).isEqualTo(version) + } + + @Test + fun `indirect parent`() { + val entry = IndirectInheritingEntry + val records = entry.allRecords() + assertThat(records).hasSize(2) + + val library = libraryRecord(records) + assertThat(library.alias.value).isEqualTo("indirectInheritingEntry-separator-inheritor") + assertThat(library.module).isEqualTo("com.company:lib") + + val version = versionRecord(records) + assertThat(library.version).isEqualTo(version) } + } - assertThat(OuterDummy.allRecords()).isEmpty() + @Nested + inner class `throw an exception if the version is needed, but not declared for` { - nested.forEach { - assertThat(it.wasAsked).isTrue() + @Test + fun `a library`() { + val entry = ErroneousLibraryEntry + assertThrows { entry.allRecords() } } + + @Test + fun `a plugin`() { + val entry = ErroneousPluginEntry + assertThrows { entry.allRecords() } + } + } + + @Test + fun `not append 'GradlePlugin' suffix for plugins`() { + val entry = WithPluginEntry + val records = entry.allRecords() + assertThat(records).hasSize(2) + + val plugin = pluginRecord(records) + assertThat(plugin.alias.value).isEqualTo("withPluginEntry") + assertThat(plugin.id).isEqualTo("my.plugin") + + val version = versionRecord(records) + assertThat(plugin.version).isEqualTo(version) + assertThat(version.alias.value).isEqualTo("withPluginEntry-gradlePlugin") + } + + @Test + fun `reflect nesting in alias`() { + val entry = RootEntry + val records = entry.allRecords() + val aliases = records.map { it.alias.value } + val expected = listOf( + "rootEntry", + "rootEntry-firstChild", + "rootEntry-secondChild", + "rootEntry-thirdChild", + "rootEntry-thirdChild-grandChild", + ) + assertThat(aliases).isEqualTo(expected) + } + + @Test + fun `throw an exception on request to produce records`() { + val entry = OuterEntry.Nested + assertThrows { entry.allRecords() } } } } diff --git a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/DependencyEntryTest.kt b/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/DependencyEntryTest.kt deleted file mode 100644 index db794d651..000000000 --- a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/DependencyEntryTest.kt +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright 2022, TeamDev. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and/or binary forms, with or without - * modification, must retain the above copyright notice and the following - * disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package io.spine.internal.catalog.model - -import com.google.common.truth.Truth.assertThat -import io.spine.internal.catalog.model.given.DependencyEntryTestEnv.Companion.assert -import io.spine.internal.catalog.model.given.StandaloneDummyVersionDependency -import io.spine.internal.catalog.model.given.DependencyEntryTestEnv.Companion.bundleRecord -import io.spine.internal.catalog.model.given.DependencyEntryTestEnv.Companion.libraryRecord -import io.spine.internal.catalog.model.given.DependencyEntryTestEnv.Companion.versionRecord -import io.spine.internal.catalog.model.given.ErroneousOuterDummyDependency -import io.spine.internal.catalog.model.given.LibraryEntryTestEnv.Companion.assert -import io.spine.internal.catalog.model.given.OuterDummyDependency -import io.spine.internal.catalog.model.given.SimpleDependency -import io.spine.internal.catalog.model.given.StandaloneDummyBundleDependency -import io.spine.internal.catalog.model.given.StandaloneDummyLibraryDependency -import io.spine.internal.catalog.model.given.StandaloneDummyPropertyDependency -import io.spine.internal.catalog.model.given.VersionEntryTestEnv.Companion.assert -import org.junit.jupiter.api.DisplayName -import org.junit.jupiter.api.Nested -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertThrows - -@DisplayName("`DependencyEntry` should") -internal class DependencyEntryTest { - - @Nested - inner class `when standalone` { - - @Test - fun `assemble a version record, if version is specified`() { - val version = versionRecord(StandaloneDummyVersionDependency) - version.assert( - alias = "standaloneDummyVersionDependency", - version = "sdvd-0.0.1" - ) - } - - @Test - fun `assemble a library record, if module is specified`() { - val library = libraryRecord(StandaloneDummyLibraryDependency) - library.assert( - alias = "standaloneDummyLibraryDependency", - module = "org.dummy", - versionRef = "standaloneDummyLibraryDependency" - ) - } - - @Test - fun `assemble a bundle record, if bundle is specified`() { - val bundle = bundleRecord(StandaloneDummyBundleDependency) - bundle.assert( - alias = "standaloneDummyBundleDependency", - libs = setOf( - "standaloneDummyBundleDependency-subLib1", - "standaloneDummyBundleDependency-subLib2", - "standaloneDummyBundleDependency-subLib3" - ) - ) - } - - @Test - fun `add an extra library by property delegation`() { - val library = libraryRecord(StandaloneDummyPropertyDependency) - library.assert( - alias = "standaloneDummyPropertyDependency-subLib", - module = "org.dummy:subLib", - versionRef = "standaloneDummyPropertyDependency" - ) - } - - @Test - fun `don't append extra-lib's name to alias, when it named after the entry`() { - val library = libraryRecord(SimpleDependency) - library.assert( - alias = "simpleDependency", - module = "org.simple", - versionRef = "simpleDependency" - ) - } - } - - @Nested - inner class `when nested` { - - @Test - fun `be able to inherit the version from the outer entry`() { - val library = libraryRecord(OuterDummyDependency.Nested) - library.assert( - alias = "outerDummyDependency-nested", - module = "org.nested", - versionRef = "outerDummyDependency" - ) - } - - @Test - fun `throw an exception when the version is neither declared nor inherited`() { - val exception = assertThrows { - val entry = ErroneousOuterDummyDependency.Nested - entry.allRecords() - } - assertThat(exception.message).isEqualTo( - "Specify version in this entry or the outer entry!" - ) - } - } -} diff --git a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/LibraryEntryTest.kt b/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/LibraryEntryTest.kt deleted file mode 100644 index f8844c903..000000000 --- a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/LibraryEntryTest.kt +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2022, TeamDev. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and/or binary forms, with or without - * modification, must retain the above copyright notice and the following - * disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package io.spine.internal.catalog.model - -import com.google.common.truth.Truth.assertThat -import io.spine.internal.catalog.model.given.LibraryEntryTestEnv.Companion.assert -import io.spine.internal.catalog.model.given.LibraryEntryTestEnv.Companion.libraryRecord -import io.spine.internal.catalog.model.given.LibraryEntryTestEnv.Companion.versionRecord -import io.spine.internal.catalog.model.given.StandaloneDummyLibrary -import io.spine.internal.catalog.model.given.VersionEntryTestEnv.Companion.assert -import org.junit.jupiter.api.DisplayName -import org.junit.jupiter.api.Nested -import org.junit.jupiter.api.Test - -@DisplayName("`LibraryEntry` should") -internal class LibraryEntryTest { - - @Nested - inner class `when standalone` { - - @Test - fun `assemble version and library records`() { - val entry = StandaloneDummyLibrary - assertThat(entry.allRecords()).hasSize(2) - - val version = versionRecord(entry) - version.assert( - alias = "standaloneDummyLibrary", - version = "sdl-0.0.1" - ) - - val library = libraryRecord(entry) - library.assert( - alias = "standaloneDummyLibrary", - module = "org.dummy:dummy-lib", - versionRef = "standaloneDummyLibrary" - ) - } - } -} diff --git a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/PluginEntryTest.kt b/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/PluginEntryTest.kt deleted file mode 100644 index 0a201db6e..000000000 --- a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/PluginEntryTest.kt +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright 2022, TeamDev. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and/or binary forms, with or without - * modification, must retain the above copyright notice and the following - * disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package io.spine.internal.catalog.model - -import com.google.common.truth.Truth.assertThat -import io.spine.internal.catalog.model.given.ErroneousStandaloneDummyPlugin -import io.spine.internal.catalog.model.given.LibraryEntryTestEnv.Companion.assert -import io.spine.internal.catalog.model.given.OuterDummyPlugin -import io.spine.internal.catalog.model.given.OuterDummyVersion -import io.spine.internal.catalog.model.given.PluginEntryTestEnv.Companion.assert -import io.spine.internal.catalog.model.given.PluginEntryTestEnv.Companion.libraryRecord -import io.spine.internal.catalog.model.given.PluginEntryTestEnv.Companion.pluginRecord -import io.spine.internal.catalog.model.given.PluginEntryTestEnv.Companion.versionRecord -import io.spine.internal.catalog.model.given.StandaloneDummyPlugin -import io.spine.internal.catalog.model.given.VersionEntryTestEnv.Companion.assert -import org.junit.jupiter.api.DisplayName -import org.junit.jupiter.api.Nested -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertThrows - -@DisplayName("`PluginEntry` should") -internal class PluginEntryTest { - - @Nested - inner class `when standalone` { - - @Test - fun `assemble plugin, library and version records`() { - val entry = StandaloneDummyPlugin - assertThat(entry.allRecords()).hasSize(3) - - val version = versionRecord(entry) - version.assert( - alias = "standaloneDummyPlugin", - version = "sdp-0.0.1" - ) - - val library = libraryRecord(entry) - library.assert( - alias = "standaloneDummyPlugin", - module = "org.dummy", - versionRef = "standaloneDummyPlugin" - ) - - val plugin = pluginRecord(entry) - plugin.assert( - alias = "standaloneDummyPlugin", - id = "dummy-plugin", - versionRef = "standaloneDummyPlugin" - ) - } - - @Test - fun `throw an exception when the version is not specified`() { - val exception = assertThrows { - val entry = ErroneousStandaloneDummyPlugin - entry.allRecords() - } - assertThat(exception.message).isEqualTo( - "Specify version in this entry or the outer entry!" - ) - } - } - - @Nested - inner class `when nested` { - - @Test - fun `not prepend a 'GradlePlugin' prefix for the plugin alias `() { - val plugin = pluginRecord(OuterDummyPlugin.GradlePlugin) - plugin.assert( - alias = "outerDummyPlugin", - id = "dummy-gradle-plugin", - versionRef = "outerDummyPlugin-gradlePlugin" - ) - } - - @Test - fun `be able to inherit the version from the outer entry`() { - val plugin = pluginRecord(OuterDummyVersion.GradlePlugin) - plugin.assert( - alias = "outerDummyVersion", - id = "dummy-gradle-plugin", - versionRef = "outerDummyVersion" - ) - } - - @Test - fun `throw an exception when the version is neither declared nor inherited`() { - val exception = assertThrows { - val entry = OuterDummyPlugin.ErroneousGradlePlugin - entry.allRecords() - } - assertThat(exception.message).isEqualTo( - "Specify version in this entry or the outer entry!" - ) - } - } -} diff --git a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/VersionEntryTest.kt b/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/VersionEntryTest.kt deleted file mode 100644 index 8a1f5a35d..000000000 --- a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/VersionEntryTest.kt +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2022, TeamDev. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and/or binary forms, with or without - * modification, must retain the above copyright notice and the following - * disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package io.spine.internal.catalog.model - -import com.google.common.truth.Truth.assertThat -import io.spine.internal.catalog.model.given.StandaloneDummyVersion -import io.spine.internal.catalog.model.given.VersionEntryTestEnv.Companion.assert -import io.spine.internal.catalog.model.given.VersionEntryTestEnv.Companion.versionRecord -import org.junit.jupiter.api.DisplayName -import org.junit.jupiter.api.Nested -import org.junit.jupiter.api.Test - -@DisplayName("`VersionEntry` should") -internal class VersionEntryTest { - - @Nested - inner class `when standalone` { - - @Test - fun `assemble a version record`() { - val entry = StandaloneDummyVersion - assertThat(entry.allRecords()).hasSize(1) - - val record = versionRecord(StandaloneDummyVersion) - record.assert(alias = "standaloneDummyVersion", version = "sdv-0.0.1") - } - } -} diff --git a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/CatalogEntries.kt b/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/CatalogEntries.kt index b1a4d14b5..d42b97063 100644 --- a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/CatalogEntries.kt +++ b/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/CatalogEntries.kt @@ -26,32 +26,125 @@ package io.spine.internal.catalog.model.given -import io.spine.internal.catalog.model.CatalogRecord import io.spine.internal.catalog.model.CatalogEntry -internal object StandaloneDummy : CatalogEntry() +internal object VersionEntry : CatalogEntry() { + override val version = "v0.0.1" +} + +internal object LibraryEntry : CatalogEntry() { + override val version = "l0.0.1" + override val module = "com.company:lib" +} + +internal object ExtraLibraryEntry : CatalogEntry() { + override val version = "el0.0.1" + + @Suppress("unused") + val core by lib("com.company:core-lib") +} + +internal object PluginEntry : CatalogEntry() { + override val version = "p0.0.1" + override val id = "com.company.plugin" +} + +@Suppress("MemberVisibilityCanBePrivate") +internal object BundleEntry : CatalogEntry() { + override val version = "b0.0.1" + override val module = "com.company:lib" + val core by lib("com.company:core-lib") + override val bundle = setOf( + this, + core, + lib("runner", "com.company:runner-lib") + ) +} + +@Suppress("MemberVisibilityCanBePrivate") +internal object ExtraBundleEntry : CatalogEntry() { + override val version = "b0.0.1" + override val module = "com.company:lib" + + val core by lib("com.company:core-lib") + + @Suppress("unused") + val full by bundle( + this, + core, + lib("runner", "com.company:runner-lib") + ) +} -internal open class MemoizingCatalogEntry : CatalogEntry() { +internal object EmptyRootEntry : CatalogEntry() - var wasAsked: Boolean = false +internal object RootEntry : CatalogEntry() { - override fun records(): Set { - wasAsked = true - return emptySet() + override val version = "re0.0.0" + + @Suppress("unused") + object FirstChild : CatalogEntry() { + override val version = "fc0.0.0" + } + + @Suppress("unused") + object SecondChild : CatalogEntry() { + override val version = "sc0.0.0" + } + + @Suppress("unused") + object ThirdChild : CatalogEntry() { + + override val version = "tc0.0.0" + + object GrandChild : CatalogEntry() { + override val version = "gc0.0.0" + } } } -internal object OuterDummy : CatalogEntry() { +internal object DirectInheritingEntry : CatalogEntry() { + override val version = "dvi0.0.1" - object Runtime : MemoizingCatalogEntry() { - object Mac : MemoizingCatalogEntry() - object Win : MemoizingCatalogEntry() - object Linux : MemoizingCatalogEntry() + @Suppress("unused") + object Inheritor : CatalogEntry() { + override val module = "com.company:lib" } +} - object NotEntry { - object Api : CatalogEntry() { - object Params : CatalogEntry() +internal object IndirectInheritingEntry : CatalogEntry() { + override val version = "ivi0.0.1" + + @Suppress("unused") + object Separator : CatalogEntry() { + object Inheritor : CatalogEntry() { + override val module = "com.company:lib" } } } + +internal object ErroneousLibraryEntry : CatalogEntry() { + @Suppress("unused") + object Nested : CatalogEntry() { + override val module = "com.company:lib" + } +} + +internal object ErroneousPluginEntry : CatalogEntry() { + @Suppress("unused") + object Nested : CatalogEntry() { + override val id = "com.company:lib" + } +} + +internal object WithPluginEntry : CatalogEntry() { + @Suppress("unused") + internal object GradlePlugin : CatalogEntry() { + override val version = "gp0.0.2" + override val id = "my.plugin" + } +} + +internal object OuterEntry : CatalogEntry() { + object Nested : CatalogEntry() +} diff --git a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/DependencyEntryTestEnv.kt b/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/CatalogEntryTestEnv.kt similarity index 66% rename from version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/DependencyEntryTestEnv.kt rename to version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/CatalogEntryTestEnv.kt index 06713d702..f48b940a4 100644 --- a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/DependencyEntryTestEnv.kt +++ b/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/CatalogEntryTestEnv.kt @@ -26,28 +26,24 @@ package io.spine.internal.catalog.model.given -import io.spine.internal.catalog.model.DependencyEntry -import io.spine.internal.catalog.model.Alias import io.spine.internal.catalog.model.BundleRecord +import io.spine.internal.catalog.model.CatalogRecord import io.spine.internal.catalog.model.LibraryRecord +import io.spine.internal.catalog.model.PluginRecord import io.spine.internal.catalog.model.VersionRecord -import org.junit.jupiter.api.Assertions.assertEquals -internal class DependencyEntryTestEnv { +internal class CatalogEntryTestEnv { companion object { - fun versionRecord(entry: DependencyEntry) = - entry.allRecords().first { it is VersionRecord } as VersionRecord + fun versionRecord(records: Iterable): VersionRecord = typedRecord(records) - fun libraryRecord(entry: DependencyEntry) = - entry.allRecords().first { it is LibraryRecord } as LibraryRecord + fun libraryRecord(records: Iterable): LibraryRecord = typedRecord(records) - fun bundleRecord(entry: DependencyEntry) = - entry.allRecords().first { it is BundleRecord } as BundleRecord + fun pluginRecord(records: Iterable): PluginRecord = typedRecord(records) - fun BundleRecord.assert(alias: Alias, libs: Set) { - assertEquals(alias, this.alias) - assertEquals(libs, this.libs) - } + fun bundleRecord(records: Iterable): BundleRecord = typedRecord(records) + + private inline fun typedRecord(records: Iterable): T = + records.first { it is T } as T } } diff --git a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/DependencyEntries.kt b/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/DependencyEntries.kt deleted file mode 100644 index 79e544aa2..000000000 --- a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/DependencyEntries.kt +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2022, TeamDev. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and/or binary forms, with or without - * modification, must retain the above copyright notice and the following - * disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package io.spine.internal.catalog.model.given - -import io.spine.internal.catalog.model.DependencyEntry - -internal object StandaloneDummyVersionDependency : DependencyEntry() { - override val version = "sdvd-0.0.1" -} - -internal object StandaloneDummyLibraryDependency : DependencyEntry() { - override val version = "sdld-0.0.1" - override val module = "org.dummy" -} - -internal object StandaloneDummyBundleDependency : DependencyEntry() { - override val version = "sdbd-0.0.1" - override val bundle = setOf( - lib("subLib1", "org.dummy:subLib1"), - lib("subLib2", "org.dummy:subLib2"), - lib("subLib3", "org.dummy:subLib3"), - ) -} - -@Suppress("unused") -internal object StandaloneDummyPropertyDependency : DependencyEntry() { - override val version = "sdpd-0.0.1" - val subLib by lib("org.dummy:subLib") -} - -@Suppress("unused") -internal object SimpleDependency : DependencyEntry() { - override val version = "sdpnd-0.0.1" - val simpleDependency by lib("org.simple") -} - -internal object OuterDummyDependency : DependencyEntry() { - override val version = "odp-0.0.1" - - object Nested : DependencyEntry() { - override val module = "org.nested" - } -} - -internal object ErroneousOuterDummyDependency : DependencyEntry() { - object Nested : DependencyEntry() { - override val module = "org.dummy" - } -} diff --git a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/LibraryEntries.kt b/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/LibraryEntries.kt deleted file mode 100644 index f853e5f93..000000000 --- a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/LibraryEntries.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2022, TeamDev. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and/or binary forms, with or without - * modification, must retain the above copyright notice and the following - * disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package io.spine.internal.catalog.model.given - -import io.spine.internal.catalog.model.LibraryEntry - -internal object StandaloneDummyLibrary : LibraryEntry() { - override val version = "sdl-0.0.1" - override val module = "org.dummy:dummy-lib" -} diff --git a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/LibraryEntryTestEnv.kt b/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/LibraryEntryTestEnv.kt deleted file mode 100644 index 30d1da914..000000000 --- a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/LibraryEntryTestEnv.kt +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2022, TeamDev. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and/or binary forms, with or without - * modification, must retain the above copyright notice and the following - * disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package io.spine.internal.catalog.model.given - -import io.spine.internal.catalog.model.LibraryEntry -import io.spine.internal.catalog.model.LibraryRecord -import io.spine.internal.catalog.model.VersionRecord -import org.junit.jupiter.api.Assertions.assertEquals - -internal class LibraryEntryTestEnv { - companion object { - - fun versionRecord(entry: LibraryEntry) = - entry.allRecords().first { it is VersionRecord } as VersionRecord - - fun libraryRecord(entry: LibraryEntry) = - entry.allRecords().first { it is LibraryRecord } as LibraryRecord - - fun LibraryRecord.assert(alias: String, module: String, versionRef: String) { - assertEquals(alias, this.alias) - assertEquals(module, this.module) - assertEquals(versionRef, this.versionRef) - } - } -} diff --git a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/PluginEntries.kt b/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/PluginEntries.kt deleted file mode 100644 index f6a0896df..000000000 --- a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/PluginEntries.kt +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2022, TeamDev. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and/or binary forms, with or without - * modification, must retain the above copyright notice and the following - * disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package io.spine.internal.catalog.model.given - -import io.spine.internal.catalog.model.CatalogEntry -import io.spine.internal.catalog.model.PluginEntry -import io.spine.internal.catalog.model.VersionEntry - -internal object StandaloneDummyPlugin : PluginEntry() { - override val version = "sdp-0.0.1" - override val module = "org.dummy" - override val id = "dummy-plugin" -} - -internal object ErroneousStandaloneDummyPlugin : PluginEntry() { - override val module = "org.dummy" - override val id = "dummy-plugin" -} - -internal object OuterDummyPlugin : CatalogEntry() { - - object GradlePlugin : PluginEntry() { - override val version = "gp-0.0.1" - override val module = "org.dummy" - override val id = "dummy-gradle-plugin" - } - - object ErroneousGradlePlugin : PluginEntry() { - override val module = "org.dummy" - override val id = "dummy-gradle-plugin" - } -} - -internal object OuterDummyVersion : VersionEntry() { - override val version = "pe-0.0.1" - - object GradlePlugin : PluginEntry() { - override val module = "org.dummy" - override val id = "dummy-gradle-plugin" - } -} diff --git a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/PluginEntryTestEnv.kt b/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/PluginEntryTestEnv.kt deleted file mode 100644 index e0fa96ac5..000000000 --- a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/PluginEntryTestEnv.kt +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2022, TeamDev. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and/or binary forms, with or without - * modification, must retain the above copyright notice and the following - * disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package io.spine.internal.catalog.model.given - -import io.spine.internal.catalog.model.Alias -import io.spine.internal.catalog.model.LibraryRecord -import io.spine.internal.catalog.model.PluginEntry -import io.spine.internal.catalog.model.PluginRecord -import io.spine.internal.catalog.model.VersionRecord -import org.junit.jupiter.api.Assertions - -internal class PluginEntryTestEnv { - companion object { - - fun versionRecord(entry: PluginEntry) = - entry.allRecords().first { it is VersionRecord } as VersionRecord - - fun libraryRecord(entry: PluginEntry) = - entry.allRecords().first { it is LibraryRecord } as LibraryRecord - - fun pluginRecord(entry: PluginEntry) = - entry.allRecords().first { it is PluginRecord } as PluginRecord - - fun PluginRecord.assert(alias: String, id: String, versionRef: Alias) { - Assertions.assertEquals(alias, this.alias) - Assertions.assertEquals(id, this.id) - Assertions.assertEquals(versionRef, this.versionRef) - } - } -} diff --git a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/VersionEntries.kt b/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/VersionEntries.kt deleted file mode 100644 index 76c902be6..000000000 --- a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/VersionEntries.kt +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2022, TeamDev. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and/or binary forms, with or without - * modification, must retain the above copyright notice and the following - * disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package io.spine.internal.catalog.model.given - -import io.spine.internal.catalog.model.VersionEntry - -internal object StandaloneDummyVersion : VersionEntry() { - override val version = "sdv-0.0.1" -} diff --git a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/VersionEntryTestEnv.kt b/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/VersionEntryTestEnv.kt deleted file mode 100644 index fa801fb93..000000000 --- a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/VersionEntryTestEnv.kt +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2022, TeamDev. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and/or binary forms, with or without - * modification, must retain the above copyright notice and the following - * disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package io.spine.internal.catalog.model.given - -import io.spine.internal.catalog.model.VersionEntry -import io.spine.internal.catalog.model.VersionRecord -import org.junit.jupiter.api.Assertions.assertEquals - -internal class VersionEntryTestEnv { - companion object { - - fun versionRecord(entry: VersionEntry) = - entry.allRecords().first() as VersionRecord - - fun VersionRecord.assert(alias: String, version: String) { - assertEquals(alias, this.alias) - assertEquals(version, this.value) - } - } -} diff --git a/version-catalog/func-test/build.gradle.kts b/version-catalog/func-test/build.gradle.kts index a161ae40f..82ec59af9 100644 --- a/version-catalog/func-test/build.gradle.kts +++ b/version-catalog/func-test/build.gradle.kts @@ -31,7 +31,7 @@ dependencies { tasks { test { dependsOn( - ":catalog:test", + ":catalog:test", // Let's force unit tests run first. ":func-test:dummy-catalog:publishToMavenLocal" ) } diff --git a/version-catalog/func-test/dummy-catalog/build.gradle.kts b/version-catalog/func-test/dummy-catalog/build.gradle.kts index 29e06e18c..8125e26f5 100644 --- a/version-catalog/func-test/dummy-catalog/build.gradle.kts +++ b/version-catalog/func-test/dummy-catalog/build.gradle.kts @@ -29,6 +29,8 @@ plugins { } dependencies { + // Provides declarative API for dependencies. + // It is a facade upon Gradle's provided `VersionCatalogBuilder`. implementation(project(":catalog")) } @@ -44,6 +46,8 @@ publishing { } tasks { + // It will be impossible to use this module from Maven local without `:catalog`. + // As this module depends on it. named("publishToMavenLocal") { dependsOn(":catalog:publishToMavenLocal") } diff --git a/version-catalog/func-test/dummy-catalog/src/main/kotlin/io/spine/internal/catalog/entry/Dummy.kt b/version-catalog/func-test/dummy-catalog/src/main/kotlin/io/spine/internal/catalog/entry/Dummy.kt index 6e9c8b51d..7dad4b10e 100644 --- a/version-catalog/func-test/dummy-catalog/src/main/kotlin/io/spine/internal/catalog/entry/Dummy.kt +++ b/version-catalog/func-test/dummy-catalog/src/main/kotlin/io/spine/internal/catalog/entry/Dummy.kt @@ -26,26 +26,23 @@ package io.spine.internal.catalog.entry -import io.spine.internal.catalog.model.DependencyEntry -import io.spine.internal.catalog.model.LibraryEntry -import io.spine.internal.catalog.model.PluginEntry -import io.spine.internal.catalog.model.VersionEntry +import io.spine.internal.catalog.model.CatalogEntry /** - * This dependency describes an imaginary library. + * An imaginary dependency. * * It is used to showcase API for dependency declaration and perform true * functional testing. * * Side comments to certain statements demonstrate how those lines will - * be represented in the generated type-safe accessors. + * be represented in the generated type-safe accessors. `libs` is a conventional + * name for version catalogs. * - * Source code of this dependency is shown in README file to the module. - * As for now, an automatic rendering of this file is NOT configured. + * Source code of this dependency is shown in README file of the module. * Thus, when modifying this dependency, put the updated code to `README.md`. */ @Suppress("unused", "MemberVisibilityCanBePrivate") -internal object Dummy : DependencyEntry() { +internal object Dummy : CatalogEntry() { private const val group = "org.dummy.company" override val module = "$group:dummy-lib" // libs.dummy @@ -55,55 +52,49 @@ internal object Dummy : DependencyEntry() { val runner by lib("$group:dummy-runner") // libs.dummy.runner val api by lib("$group:dummy-api") // libs.dummy.api - // In bundles, you can reference already declared libs, - // or create them in-place. + // In bundles, you can reference entries (which declare module), extra + // libraries or declare them in-place. override val bundle = setOf( // libs.bundles.dummy + this, core, runner, api, lib("params", "$group:dummy-params"), // libs.dummy.params lib("types", "$group:dummy-types"), // libs.dummy.types ) - // "GradlePlugin" - is a special entry name for `PluginEntry`. - // For plugin entries with this name, the facade will not put "gradlePlugin" - // suffix for a plugin's ID. Note, that we have this suffix for the version - // and module, and does not have for ID. + // "GradlePlugin" - is a special entry name. "gradlePlugin" suffix will not + // be put for a final plugin alias. Note, that in an example below, we have + // this suffix for the version and module, and does not have for ID. - object GradlePlugin : PluginEntry() { + object GradlePlugin : CatalogEntry() { override val version = "0.0.8" // libs.versions.dummy.gradlePlugin override val module = "$group:my-dummy-plugin" // libs.dummy.gradlePlugin override val id = "my-dummy-plugin" // libs.plugins.dummy } - object Runtime : DependencyEntry() { + object Runtime : CatalogEntry() { - // When an entry does not override the version, it is taken from - // the outer entry. For example, in this case, all libs within "Runtime" - // entry will have "1.0.0". + // When an entry does not override the version, it will try to fetch it + // from the closest parental entry, which has one. For example, in this case, + // all libraries within "Runtime" entry will have version = "1.0.0". val win by lib("$group:runtime-win") // libs.dummy.runtime.win val mac by lib("$group:runtime-mac") // libs.dummy.runtime.mac val linux by lib("$group:runtime-linux") // libs.dummy.runtime.linux - object BOM : LibraryEntry() { + object Bom : CatalogEntry() { override val version = "2.0.0" // libs.versions.dummy.runtime.bom override val module = "$group:dummy-bom" // libs.dummy.runtime.bom } } - // A library that is declared as `object SomeLib : LibraryEntry()` can be - // referenced as well as the one declared by `lib()` delegate. + // It's also possible to declare an extra bundle by a property delegate. + // Just like with extra modules. val runtime by bundle( // libs.bundles.dummy.runtime - Runtime.BOM, + Runtime.Bom, Runtime.win, Runtime.mac, Runtime.linux, ) - - // It is also possible to declare just a bare version. - - object Tools : VersionEntry() { - override val version = "3.0.0" // libs.versions.dummy.tools - } } diff --git a/version-catalog/func-test/dummy-project/build.gradle.kts b/version-catalog/func-test/dummy-project/build.gradle.kts index c5c3a16be..0c21e7554 100644 --- a/version-catalog/func-test/dummy-project/build.gradle.kts +++ b/version-catalog/func-test/dummy-project/build.gradle.kts @@ -62,11 +62,12 @@ with(libs.dummy) { assert( libs.bundles.dummy, "[" + - "org.dummy.company:dummy-core:1.0.0, " + - "org.dummy.company:dummy-runner:1.0.0, " + - "org.dummy.company:dummy-api:1.0.0, " + - "org.dummy.company:dummy-params:1.0.0, " + - "org.dummy.company:dummy-types:1.0.0" + + "$group:dummy-lib:1.0.0, " + + "$group:dummy-core:1.0.0, " + + "$group:dummy-runner:1.0.0, " + + "$group:dummy-api:1.0.0, " + + "$group:dummy-params:1.0.0, " + + "$group:dummy-types:1.0.0" + "]" ) @@ -85,11 +86,9 @@ with(libs.dummy.runtime) { assert( libs.bundles.dummy.runtime, "[" + - "org.dummy.company:dummy-bom:2.0.0, " + - "org.dummy.company:runtime-win:1.0.0, " + - "org.dummy.company:runtime-mac:1.0.0, " + - "org.dummy.company:runtime-linux:1.0.0" + + "$group:dummy-bom:2.0.0, " + + "$group:runtime-win:1.0.0, " + + "$group:runtime-mac:1.0.0, " + + "$group:runtime-linux:1.0.0" + "]" ) - -assert(libs.versions.dummy.tools, "3.0.0") diff --git a/version-catalog/func-test/src/test/kotlin/io/spine/internal/catalog/DummyVersionCatalogTest.kt b/version-catalog/func-test/src/test/kotlin/io/spine/internal/catalog/DummyVersionCatalogTest.kt index bdda7b83f..462179d1b 100644 --- a/version-catalog/func-test/src/test/kotlin/io/spine/internal/catalog/DummyVersionCatalogTest.kt +++ b/version-catalog/func-test/src/test/kotlin/io/spine/internal/catalog/DummyVersionCatalogTest.kt @@ -35,7 +35,7 @@ import org.junit.jupiter.api.assertDoesNotThrow /** * Verifies the generated type-safe accessors for `Dummy` dependency. * - * `Dummy` dependency is an imaginary library, which exists for two reasons: + * `Dummy` is an imaginary dependency, which exists for two reasons: * * 1. Showcasing API for dependency declarations. * 2. Functional testing in conditions, which are very close to real life.