From 3ca8a3526d0332b2e9641395c8f5c489e0a34c06 Mon Sep 17 00:00:00 2001 From: "yevhenii.nadtochii" Date: Wed, 8 Jun 2022 18:03:36 +0300 Subject: [PATCH 01/11] Leave only a single `CatalogEntry` --- .../internal/catalog/entry/AnimalSniffer.kt | 4 +- .../internal/catalog/entry/ApacheCommons.kt | 7 +- .../internal/catalog/entry/ApacheHttp.kt | 4 +- .../spine/internal/catalog/entry/AppEngine.kt | 7 +- .../spine/internal/catalog/entry/AssertK.kt | 4 +- .../internal/catalog/entry/BouncyCastle.kt | 4 +- .../internal/catalog/entry/CheckStyle.kt | 4 +- .../catalog/entry/CheckerFramework.kt | 7 +- .../io/spine/internal/catalog/entry/Dokka.kt | 16 +- .../internal/catalog/entry/ErrorProne.kt | 10 +- .../spine/internal/catalog/entry/FindBugs.kt | 4 +- .../spine/internal/catalog/entry/Firebase.kt | 3 +- .../spine/internal/catalog/entry/Flogger.kt | 7 +- .../internal/catalog/entry/GoogleApis.kt | 16 +- .../internal/catalog/entry/GoogleAuto.kt | 8 +- .../internal/catalog/entry/GoogleCloud.kt | 12 +- .../io/spine/internal/catalog/entry/GrGit.kt | 4 +- .../io/spine/internal/catalog/entry/Grpc.kt | 4 +- .../io/spine/internal/catalog/entry/Gson.kt | 4 +- .../io/spine/internal/catalog/entry/Guava.kt | 4 +- .../internal/catalog/entry/HttpClient.kt | 7 +- .../io/spine/internal/catalog/entry/J2ObjC.kt | 4 +- .../io/spine/internal/catalog/entry/JUnit.kt | 15 +- .../spine/internal/catalog/entry/Jackson.kt | 7 +- .../spine/internal/catalog/entry/JavaJwt.kt | 4 +- .../spine/internal/catalog/entry/JavaPoet.kt | 4 +- .../io/spine/internal/catalog/entry/JavaX.kt | 5 +- .../io/spine/internal/catalog/entry/Klaxon.kt | 4 +- .../io/spine/internal/catalog/entry/Kotlin.kt | 6 +- .../internal/catalog/entry/KotlinSemver.kt | 4 +- .../spine/internal/catalog/entry/KotlinX.kt | 6 +- .../internal/catalog/entry/LicenseReport.kt | 7 +- .../io/spine/internal/catalog/entry/Netty.kt | 4 +- .../io/spine/internal/catalog/entry/Okio.kt | 4 +- .../internal/catalog/entry/OsDetector.kt | 4 +- .../io/spine/internal/catalog/entry/Plexus.kt | 4 +- .../io/spine/internal/catalog/entry/Pmd.kt | 4 +- .../spine/internal/catalog/entry/Protobuf.kt | 7 +- .../spine/internal/catalog/entry/Roaster.kt | 4 +- .../io/spine/internal/catalog/entry/Slf4J.kt | 4 +- .../internal/catalog/entry/TestKitTruth.kt | 4 +- .../io/spine/internal/catalog/entry/Truth.kt | 4 +- .../internal/catalog/model/CatalogEntry.kt | 162 +++++----- .../catalog/model/CatalogNotations.kt | 117 -------- .../internal/catalog/model/CatalogRecords.kt | 26 +- .../internal/catalog/model/DependencyEntry.kt | 278 ------------------ .../internal/catalog/model/LibraryEntry.kt | 53 ---- .../internal/catalog/model/PluginEntry.kt | 107 ------- .../internal/catalog/model/VersionEntry.kt | 51 ---- .../catalog/model/VersionInheritingEntry.kt | 137 --------- .../catalog/model/CatalogEntryTest.kt | 204 ++++++------- .../catalog/model/DependencyEntryTest.kt | 261 ++++++++-------- .../catalog/model/LibraryEntryTest.kt | 64 ---- .../internal/catalog/model/PluginEntryTest.kt | 245 ++++++++------- .../catalog/model/VersionEntryTest.kt | 52 ---- .../catalog/model/given/CatalogEntries.kt | 114 +++---- .../catalog/model/given/DependencyEntries.kt | 20 +- .../model/given/DependencyEntryTestEnv.kt | 13 +- .../catalog/model/given/LibraryEntries.kt | 9 - .../model/given/LibraryEntryTestEnv.kt | 98 +++--- .../catalog/model/given/PluginEntries.kt | 129 ++++---- .../catalog/model/given/PluginEntryTestEnv.kt | 108 +++---- .../catalog/model/given/VersionEntries.kt | 33 --- .../model/given/VersionEntryTestEnv.kt | 44 --- .../io/spine/internal/catalog/entry/Dummy.kt | 15 +- 65 files changed, 819 insertions(+), 1770 deletions(-) delete mode 100644 version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/CatalogNotations.kt delete mode 100644 version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/DependencyEntry.kt delete mode 100644 version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/LibraryEntry.kt delete mode 100644 version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/PluginEntry.kt delete mode 100644 version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/VersionEntry.kt delete mode 100644 version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/VersionInheritingEntry.kt delete mode 100644 version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/LibraryEntryTest.kt delete mode 100644 version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/VersionEntryTest.kt delete mode 100644 version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/VersionEntries.kt delete mode 100644 version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/VersionEntryTestEnv.kt 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..81026ae45 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,13 +26,13 @@ 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 bundle = setOf( lib("truth", "com.google.truth:truth"), 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..f2db23ce8 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 @@ -26,74 +26,57 @@ package io.spine.internal.catalog.model -/** - * A base catalog entry. - * - * 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). - * - * Only object declarations are meant to serve as concrete entries. - * - * As a base entry, this class takes a responsibility for the following: - * - * 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. - * - * 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. - * - * 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. - * - * 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. - * - * Below is an example of `Runtime` entry: - * - * ``` - * 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, `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. - * - * See also: [CatalogNotation], [CatalogRecord]. - */ -open class CatalogEntry : CatalogNotation { - - /** - * A parent entry, within which this entry resides, if present. - */ - protected val outerEntry: CatalogEntry? = outerEntry() - - /** - * Object's name with respect to entity's nesting. - * - * We say "object" here because all concrete entries are meant to be - * object declarations. - */ - final override val alias: Alias = alias() - - /** - * A base entry produce no records. - */ - protected open fun records(): Set = emptySet() - - /** - * Obtains all catalog records, produced by this entry and its nested entries. - */ +open class CatalogEntry { + + private val outerEntry: CatalogEntry? = outerEntry() + + private val alias: Alias = alias() + + private val standaloneLibs = mutableSetOf() + + private val standaloneBundles = mutableSetOf() + + private val versionRecord: VersionRecord by lazy { versionRecord() } + + open val version: String? = null + + open val module: String? = null + + open val id: String? = null + + open val bundle: Set? = null + + private fun records(): Set { + val result = mutableSetOf() + + 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 = pluginAlias() + val record = PluginRecord(pluginAlias, id!!, versionRecord) + result.add(record) + } + + if (bundle != null) { + val libs = toLibraryRecords(bundle!!) + val record = BundleRecord(alias, libs) + result.add(record) + } + + standaloneLibs.forEach { result.add(it) } + standaloneBundles.forEach { result.add(it) } + + return result + } + fun allRecords(): Set { val result = mutableSetOf() @@ -107,6 +90,32 @@ open class CatalogEntry : CatalogNotation { return result } + fun lib(name: String, module: String): LibraryRecord { + val thisEntryAlias = this.alias + val libAlias = if (thisEntryAlias.endsWith(name)) thisEntryAlias + else "$thisEntryAlias-$name" + + val record = LibraryRecord(libAlias, module, versionRecord) + standaloneLibs.add(record) + + return record + } + + fun lib(module: String): MemoizingDelegate = + delegate { property -> lib(property.name, module) } + + fun bundle(vararg libs: Any): MemoizingDelegate = + delegate { property -> + val thisEntryAlias = this.alias + val bundleAlias = "$thisEntryAlias-${property.name}" + + val libRecords = toLibraryRecords(libs.asIterable()) + val record = BundleRecord(bundleAlias, libRecords) + standaloneBundles.add(record) + + record + } + private fun nestedEntries(): Set { val nestedClasses = this::class.nestedClasses val nestedObjects = nestedClasses.mapNotNull { it.objectInstance } @@ -132,4 +141,21 @@ open class CatalogEntry : CatalogNotation { } private fun String.toCamelCase() = replaceFirstChar { it.lowercaseChar() } + + private fun toLibraryRecords(obj: Iterable): Set = + obj.map { toLibraryRecord(it) }.toSet() + + private fun toLibraryRecord(obj: Any): LibraryRecord = when (obj) { + is LibraryRecord -> obj + is CatalogEntry -> LibraryRecord(obj.alias, obj.module!!, obj.versionRecord) + else -> throw IllegalArgumentException("Unknown object has been passed: $obj!") + } + + private fun versionRecord(): VersionRecord = when { + version != null -> VersionRecord(alias, version!!) + outerEntry != null -> outerEntry.versionRecord + else -> throw IllegalStateException("Specify version in this entry or any parent one!") + } + + private fun pluginAlias(): Alias = alias.removeSuffix("-gradlePlugin") } 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..7773f1941 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 @@ -81,7 +81,7 @@ interface CatalogRecord { * * For example: `2.0.0-SNAPSHOT.21`. */ -internal data class VersionRecord( +data class VersionRecord( override val alias: Alias, val value: String ) : CatalogRecord { @@ -97,20 +97,17 @@ internal data class VersionRecord( * [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]. */ -internal data class LibraryRecord( +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, group, artifact).versionRef(version.alias) } } @@ -121,33 +118,28 @@ internal data class LibraryRecord( * 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]. */ 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, id).versionRef(version.alias) } } /** * 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]. */ -internal data class BundleRecord( +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, libs.map { it.alias }) } } 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..04b907218 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 @@ -1,102 +1,102 @@ -/* - * 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.OuterDummy -import io.spine.internal.catalog.model.given.StandaloneDummy -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("`CatalogEntry` should") -internal class CatalogEntryTest { - - @Nested - inner class `when standalone` { - - private val standaloneEntry = StandaloneDummy - - @Test - fun `use object's name as alias`() { - assertThat(standaloneEntry.alias).isEqualTo("standaloneDummy") - } - - @Test - fun `produce no records`() { - assertThat(standaloneEntry.allRecords()).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") - } - - @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!") - } - } - - @Nested - inner class `when outer` { - - @Test - fun `ask nested entries for records`() { - - val nested = listOf( - OuterDummy.Runtime, - OuterDummy.Runtime.Mac, - OuterDummy.Runtime.Win, - OuterDummy.Runtime.Linux, - ) - - nested.forEach { - assertThat(it.wasAsked).isFalse() - } - - assertThat(OuterDummy.allRecords()).isEmpty() - - nested.forEach { - assertThat(it.wasAsked).isTrue() - } - } - } -} +///* +// * 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.OuterDummy +//import io.spine.internal.catalog.model.given.StandaloneDummy +//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("`CatalogEntry` should") +//internal class CatalogEntryTest { +// +// @Nested +// inner class `when standalone` { +// +// private val standaloneEntry = StandaloneDummy +// +// @Test +// fun `use object's name as alias`() { +//// assertThat(standaloneEntry.alias).isEqualTo("standaloneDummy") +// } +// +// @Test +// fun `produce no records`() { +// assertThat(standaloneEntry.allRecords()).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") +// } +// +// @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!") +// } +// } +// +// @Nested +// inner class `when outer` { +// +// @Test +// fun `ask nested entries for records`() { +// +// val nested = listOf( +// OuterDummy.Runtime, +// OuterDummy.Runtime.Mac, +// OuterDummy.Runtime.Win, +// OuterDummy.Runtime.Linux, +// ) +// +// nested.forEach { +// assertThat(it.wasAsked).isFalse() +// } +// +// assertThat(OuterDummy.allRecords()).isEmpty() +// +// nested.forEach { +// assertThat(it.wasAsked).isTrue() +// } +// } +// } +//} 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 index db794d651..1850a1898 100644 --- 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 @@ -1,131 +1,130 @@ -/* - * 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!" - ) - } - } -} +///* +// * 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 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 index 0a201db6e..2600e8402 100644 --- 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 @@ -1,123 +1,122 @@ -/* - * 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!" - ) - } - } -} +///* +// * 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 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..ec9ada042 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 @@ -1,57 +1,57 @@ -/* - * 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.CatalogRecord -import io.spine.internal.catalog.model.CatalogEntry - -internal object StandaloneDummy : CatalogEntry() - -internal open class MemoizingCatalogEntry : CatalogEntry() { - - var wasAsked: Boolean = false - - override fun records(): Set { - wasAsked = true - return emptySet() - } -} - -internal object OuterDummy : CatalogEntry() { - - object Runtime : MemoizingCatalogEntry() { - object Mac : MemoizingCatalogEntry() - object Win : MemoizingCatalogEntry() - object Linux : MemoizingCatalogEntry() - } - - object NotEntry { - object Api : CatalogEntry() { - object Params : CatalogEntry() - } - } -} +///* +// * 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.CatalogRecord +//import io.spine.internal.catalog.model.CatalogEntry +// +//internal object StandaloneDummy : CatalogEntry() +// +//internal open class MemoizingCatalogEntry : CatalogEntry() { +// +// var wasAsked: Boolean = false +// +// override fun records(): Set { +// wasAsked = true +// return emptySet() +// } +//} +// +//internal object OuterDummy : CatalogEntry() { +// +// object Runtime : MemoizingCatalogEntry() { +// object Mac : MemoizingCatalogEntry() +// object Win : MemoizingCatalogEntry() +// object Linux : MemoizingCatalogEntry() +// } +// +// object NotEntry { +// object Api : CatalogEntry() { +// object Params : CatalogEntry() +// } +// } +//} 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 index 79e544aa2..d7a574dca 100644 --- 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 @@ -26,18 +26,18 @@ package io.spine.internal.catalog.model.given -import io.spine.internal.catalog.model.DependencyEntry +import io.spine.internal.catalog.model.CatalogEntry -internal object StandaloneDummyVersionDependency : DependencyEntry() { +internal object StandaloneDummyVersionDependency : CatalogEntry() { override val version = "sdvd-0.0.1" } -internal object StandaloneDummyLibraryDependency : DependencyEntry() { +internal object StandaloneDummyLibraryDependency : CatalogEntry() { override val version = "sdld-0.0.1" override val module = "org.dummy" } -internal object StandaloneDummyBundleDependency : DependencyEntry() { +internal object StandaloneDummyBundleDependency : CatalogEntry() { override val version = "sdbd-0.0.1" override val bundle = setOf( lib("subLib1", "org.dummy:subLib1"), @@ -47,27 +47,27 @@ internal object StandaloneDummyBundleDependency : DependencyEntry() { } @Suppress("unused") -internal object StandaloneDummyPropertyDependency : DependencyEntry() { +internal object StandaloneDummyPropertyDependency : CatalogEntry() { override val version = "sdpd-0.0.1" val subLib by lib("org.dummy:subLib") } @Suppress("unused") -internal object SimpleDependency : DependencyEntry() { +internal object SimpleDependency : CatalogEntry() { override val version = "sdpnd-0.0.1" val simpleDependency by lib("org.simple") } -internal object OuterDummyDependency : DependencyEntry() { +internal object OuterDummyDependency : CatalogEntry() { override val version = "odp-0.0.1" - object Nested : DependencyEntry() { + object Nested : CatalogEntry() { override val module = "org.nested" } } -internal object ErroneousOuterDummyDependency : DependencyEntry() { - object Nested : DependencyEntry() { +internal object ErroneousOuterDummyDependency : CatalogEntry() { + object Nested : CatalogEntry() { override val module = "org.dummy" } } 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/DependencyEntryTestEnv.kt index 06713d702..d8a6cac43 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/DependencyEntryTestEnv.kt @@ -26,7 +26,7 @@ package io.spine.internal.catalog.model.given -import io.spine.internal.catalog.model.DependencyEntry +import io.spine.internal.catalog.model.CatalogEntry import io.spine.internal.catalog.model.Alias import io.spine.internal.catalog.model.BundleRecord import io.spine.internal.catalog.model.LibraryRecord @@ -36,13 +36,18 @@ import org.junit.jupiter.api.Assertions.assertEquals internal class DependencyEntryTestEnv { companion object { - fun versionRecord(entry: DependencyEntry) = + fun versionRecord(entry: CatalogEntry) = entry.allRecords().first { it is VersionRecord } as VersionRecord - fun libraryRecord(entry: DependencyEntry) = + fun VersionRecord.assert(alias: String, version: String) { + assertEquals(alias, this.alias) + assertEquals(version, this.value) + } + + fun libraryRecord(entry: CatalogEntry) = entry.allRecords().first { it is LibraryRecord } as LibraryRecord - fun bundleRecord(entry: DependencyEntry) = + fun bundleRecord(entry: CatalogEntry) = entry.allRecords().first { it is BundleRecord } as BundleRecord fun BundleRecord.assert(alias: Alias, libs: Set) { 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 index f853e5f93..a204bb69c 100644 --- 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 @@ -23,12 +23,3 @@ * (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 index 30d1da914..15a864983 100644 --- 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 @@ -1,49 +1,49 @@ -/* - * 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) - } - } -} +///* +// * 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 index f6a0896df..a6ade7032 100644 --- 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 @@ -1,65 +1,64 @@ -/* - * 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" - } -} +///* +// * 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 +// +//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 : CatalogEntry() { +// 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 index e0fa96ac5..8cfa0dfab 100644 --- 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 @@ -1,54 +1,54 @@ -/* - * 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) - } - } -} +///* +// * 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/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..ebb7fb7b3 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,10 +26,7 @@ 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. @@ -45,7 +42,7 @@ import io.spine.internal.catalog.model.VersionEntry * 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 @@ -69,13 +66,13 @@ internal object Dummy : DependencyEntry() { // 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() { + 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" @@ -85,7 +82,7 @@ internal object Dummy : DependencyEntry() { 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 } @@ -103,7 +100,7 @@ internal object Dummy : DependencyEntry() { // It is also possible to declare just a bare version. - object Tools : VersionEntry() { + object Tools : CatalogEntry() { override val version = "3.0.0" // libs.versions.dummy.tools } } From c9601de5704e3d346db08b48148d42e49d511bfe Mon Sep 17 00:00:00 2001 From: "yevhenii.nadtochii" Date: Thu, 9 Jun 2022 11:52:07 +0300 Subject: [PATCH 02/11] Don't expose concrete records --- .../kotlin/io/spine/internal/catalog/model/CatalogEntry.kt | 6 +++--- .../io/spine/internal/catalog/model/CatalogRecords.kt | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) 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 f2db23ce8..3022f5cd9 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 @@ -90,7 +90,7 @@ open class CatalogEntry { return result } - fun lib(name: String, module: String): LibraryRecord { + fun lib(name: String, module: String): CatalogRecord { val thisEntryAlias = this.alias val libAlias = if (thisEntryAlias.endsWith(name)) thisEntryAlias else "$thisEntryAlias-$name" @@ -101,10 +101,10 @@ open class CatalogEntry { return record } - fun lib(module: String): MemoizingDelegate = + fun lib(module: String): MemoizingDelegate = delegate { property -> lib(property.name, module) } - fun bundle(vararg libs: Any): MemoizingDelegate = + fun bundle(vararg libs: Any): MemoizingDelegate = delegate { property -> val thisEntryAlias = this.alias val bundleAlias = "$thisEntryAlias-${property.name}" 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 7773f1941..13c643ba0 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 @@ -81,7 +81,7 @@ interface CatalogRecord { * * For example: `2.0.0-SNAPSHOT.21`. */ -data class VersionRecord( +internal data class VersionRecord( override val alias: Alias, val value: String ) : CatalogRecord { @@ -98,7 +98,7 @@ data class VersionRecord( * * For example: `io.spine:spine-core`. */ -data class LibraryRecord( +internal data class LibraryRecord( override val alias: Alias, val module: String, val version: VersionRecord @@ -134,7 +134,7 @@ internal data class PluginRecord( * Represents a named set of libraries, which can be directly written into * a version catalog */ -data class BundleRecord( +internal data class BundleRecord( override val alias: Alias, val libs: Set ) : CatalogRecord { From 4619471a067cc4831416ef17fb27b88eb04a8381 Mon Sep 17 00:00:00 2001 From: "yevhenii.nadtochii" Date: Thu, 9 Jun 2022 12:48:53 +0300 Subject: [PATCH 03/11] Update documentation to `Alias` and `CatalogRecords` --- .../io/spine/internal/catalog/model/Alias.kt | 36 ++++++++++++--- .../internal/catalog/model/CatalogRecords.kt | 46 ++++++++----------- 2 files changed, 47 insertions(+), 35 deletions(-) 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..26f2bdf28 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,15 @@ 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 + * + * A version catalog itself consists of four sections: versions, libraries, plugins + * and bundles (sets of libraries). Thus, an alias can denote four types of items. + * Within each section, an alias should be unique. * * Aliases perform two functions: * @@ -37,14 +45,28 @@ 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. + * ### 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`: * * ``` - * "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, the resulting accessor + * may have additional prefixes. + * + * Below are an accessor patterns for different 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 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 13c643ba0..57baa66c5 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 @@ -31,33 +31,16 @@ import org.gradle.api.initialization.dsl.VersionCatalogBuilder /** * A single, 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 used 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 { @@ -65,6 +48,9 @@ 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 +61,7 @@ interface CatalogRecord { } /** - * Represents a version item, which can be directly written into a version catalog. + * Represents a version, which can be directly written into a version catalog. * * [value] is a string representation of a version. * @@ -92,11 +78,13 @@ internal data class VersionRecord( } /** - * Represents a library item, which can be directly written into a version catalog. + * Represents 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`. + * + * A version of the library is obtained by referencing to the given [version record][version]. */ internal data class LibraryRecord( override val alias: Alias, @@ -112,12 +100,14 @@ internal data class LibraryRecord( } /** - * Represents a plugin item, which can be directly written into a version catalog. + * Represents 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`. + * + * A version of the plugin is obtained by referencing to the given [version record][version]. */ internal data class PluginRecord( override val alias: Alias, From 5b1698d8c066ea9e08f1e28ca180bdedc30b0887 Mon Sep 17 00:00:00 2001 From: "yevhenii.nadtochii" Date: Thu, 9 Jun 2022 16:48:48 +0300 Subject: [PATCH 04/11] Write top-level docs for `CatalogEntry` --- .../internal/catalog/model/CatalogEntry.kt | 337 ++++++++++++++---- 1 file changed, 277 insertions(+), 60 deletions(-) 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 3022f5cd9..1564ee6de 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 @@ -26,17 +26,227 @@ package io.spine.internal.catalog.model -open class CatalogEntry { - - private val outerEntry: CatalogEntry? = outerEntry() - - private val alias: Alias = alias() +/** + * A dependency, which is going to be added into a version 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. 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. + * + * 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. + * + * # Usage + * + * Please note, only object declarations are meant to inherit from this class + * and serve as concrete entries. + * + * ``` + * internal object SomeLibrary : CatalogEntry() { + * // ... + * } + * ``` + * + * ## Nesting + * + * Entries support nesting. One entry can be put into another one. This way they + * can form a hierarchy. + * + * Also, each item in a version catalog should have [Alias]. An entry sets aliases + * on its own for items, declared within it. To do this, it takes object's name + * with respect to its 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. + * + * ## Versions + * + * An entry which declares only a 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" + * } + * ``` + * + * ## 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 library can consist of several modules. Or even of a group + * of modules. A group can be declared using a nested entry, and extra modules + * 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") + * } + * } + * ``` + * + * 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 parent. + * + * Also, when a module is named after the entry in which it is declared, + * the resulting suffix will not contain a duplicated suffix. Consider an example + * below, in which comments represent the generated type-safe accessors to + * corresponding items. + * + * + * An example with a module named after the entry: + * + * ``` + * internal object MyLib : CatalogEntry() { + * private const val group = "com.company" + * override val version = "1.9.0" // libs.versions.myLib + * + * val myLib by lib("$group:my-lib") // libs.myLib (not libs.myLib.myLib!) + * val types by lib("$group:my-types") // libs.myLib.types + * val data by lib("$group:my-data") // libs.myLib.data + * } + * ``` + * + * ## 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 that + * consists of several modules. Additionally, plugins can be supplemented with + * a library, that makes possible applying a plugin from `buildSrc`. + * + * Please note, that `GradlePlugin` is a special name for entries. Such entry + * will not append `gradlePlugin` suffix for [id] item. + * + * For example: + * + * ``` + * internal object MyBigLib : VersionEntry() { + * private const val group = "com.company" + * // ... + * + * object GradlePlugin : PluginEntry() { + * override val version = "1.2.3" // libs.versions.myBigLib.gradlePlugin + * override val module = "$group:my-plugin" // libs.myBigLib.gradlePlugin + * override val id = "$group.plugin" // libs.plugins.myBigLib (without `gradlePlugin`!) + * } + * } + * ``` + * + * ## Bundles + * + * A bundle is a named set of libraries. One can compose a bundle out of + * extra modules, in-place module declarations or entries (which declare module). + * + * 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( + * Runner, + * Adapters.html4, + * Adapters.html5, + * lib("linter", "$group:linter"), + * lib("core", "$group:core") + * ) + * } + * ``` + * + * There's also a possibility to declare extra bundles on top of a current entry. + * Just like with extra modules, using a [property delegation][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") + * } + * + * val adapters by bundle( + * Adapters.html4, + * Adapters.html5, + * ) + * } + * ``` + */ +abstract class CatalogEntry { private val standaloneLibs = mutableSetOf() - private val standaloneBundles = mutableSetOf() - private val versionRecord: VersionRecord by lazy { versionRecord() } + private val outerEntry: CatalogEntry? = outerEntry() + private val alias: Alias = alias() open val version: String? = null @@ -46,6 +256,45 @@ open class CatalogEntry { open val bundle: Set? = null + fun lib(module: String): MemoizingDelegate = + delegate { property -> lib(property.name, module) } + + fun lib(name: String, module: String): CatalogRecord { + val thisEntryAlias = this.alias + val libAlias = if (thisEntryAlias.endsWith(name)) thisEntryAlias + else "$thisEntryAlias-$name" + + val record = LibraryRecord(libAlias, module, versionRecord) + standaloneLibs.add(record) + + return record + } + + fun bundle(vararg libs: Any): MemoizingDelegate = + delegate { property -> + val thisEntryAlias = this.alias + val bundleAlias = "$thisEntryAlias-${property.name}" + + val libRecords = libs.asIterable().toLibraryRecords() + val record = BundleRecord(bundleAlias, libRecords) + standaloneBundles.add(record) + + record + } + + fun allRecords(): Set { + val result = mutableSetOf() + + val fromThisEntry = records() + result.addAll(fromThisEntry) + + val nestedEntries = nestedEntries() + val fromNested = nestedEntries.flatMap { it.allRecords() } + result.addAll(fromNested) + + return result + } + private fun records(): Set { val result = mutableSetOf() @@ -60,13 +309,13 @@ open class CatalogEntry { } if (id != null) { - val pluginAlias = pluginAlias() + val pluginAlias = alias.removeSuffix("-gradlePlugin") val record = PluginRecord(pluginAlias, id!!, versionRecord) result.add(record) } if (bundle != null) { - val libs = toLibraryRecords(bundle!!) + val libs = bundle!!.toLibraryRecords() val record = BundleRecord(alias, libs) result.add(record) } @@ -77,45 +326,6 @@ open class CatalogEntry { return result } - fun allRecords(): Set { - val result = mutableSetOf() - - val fromThisEntry = records() - result.addAll(fromThisEntry) - - val nestedEntries = nestedEntries() - val fromNested = nestedEntries.flatMap { it.allRecords() } - result.addAll(fromNested) - - return result - } - - fun lib(name: String, module: String): CatalogRecord { - val thisEntryAlias = this.alias - val libAlias = if (thisEntryAlias.endsWith(name)) thisEntryAlias - else "$thisEntryAlias-$name" - - val record = LibraryRecord(libAlias, module, versionRecord) - standaloneLibs.add(record) - - return record - } - - fun lib(module: String): MemoizingDelegate = - delegate { property -> lib(property.name, module) } - - fun bundle(vararg libs: Any): MemoizingDelegate = - delegate { property -> - val thisEntryAlias = this.alias - val bundleAlias = "$thisEntryAlias-${property.name}" - - val libRecords = toLibraryRecords(libs.asIterable()) - val record = BundleRecord(bundleAlias, libRecords) - standaloneBundles.add(record) - - record - } - private fun nestedEntries(): Set { val nestedClasses = this::class.nestedClasses val nestedObjects = nestedClasses.mapNotNull { it.objectInstance } @@ -135,27 +345,34 @@ open class CatalogEntry { } private fun alias(): String { + fun String.toCamelCase() = replaceFirstChar { it.lowercaseChar() } val className = this::class.java.simpleName.toCamelCase() val alias = if (outerEntry != null) "${outerEntry.alias}-$className" else className return alias } - private fun String.toCamelCase() = replaceFirstChar { it.lowercaseChar() } - - private fun toLibraryRecords(obj: Iterable): Set = - obj.map { toLibraryRecord(it) }.toSet() - - private fun toLibraryRecord(obj: Any): LibraryRecord = when (obj) { - is LibraryRecord -> obj - is CatalogEntry -> LibraryRecord(obj.alias, obj.module!!, obj.versionRecord) - else -> throw IllegalArgumentException("Unknown object has been passed: $obj!") - } - private fun versionRecord(): VersionRecord = when { version != null -> VersionRecord(alias, version!!) outerEntry != null -> outerEntry.versionRecord else -> throw IllegalStateException("Specify version in this entry or any parent one!") } - private fun pluginAlias(): Alias = alias.removeSuffix("-gradlePlugin") + 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!") + } } From 54c1d3fd7ff2c4b37d160ce9d5a0a2475101ddf4 Mon Sep 17 00:00:00 2001 From: "yevhenii.nadtochii" Date: Thu, 9 Jun 2022 17:40:02 +0300 Subject: [PATCH 05/11] Drop a special treatment for extra libs named after the entry --- .../io/spine/internal/catalog/entry/Truth.kt | 3 +- .../internal/catalog/model/CatalogEntry.kt | 101 +++++++----------- .../io/spine/internal/catalog/entry/Dummy.kt | 1 + .../func-test/dummy-project/build.gradle.kts | 19 ++-- 4 files changed, 51 insertions(+), 73 deletions(-) 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 81026ae45..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 @@ -34,8 +34,9 @@ import io.spine.internal.catalog.model.CatalogEntry @Suppress("unused") 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/CatalogEntry.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/CatalogEntry.kt index 1564ee6de..507b105b8 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,18 +27,16 @@ package io.spine.internal.catalog.model /** - * A dependency, which is going to be added into a version catalog. + * 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: versions, libraries, plugins and bundles. Entries expose - * a declarative API, leaving behind the scene all imperative code. 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. + * a declarative API, leaving behind the scene all imperative code. * - * 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. + * 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. * * # Usage * @@ -46,15 +44,16 @@ package io.spine.internal.catalog.model * and serve as concrete entries. * * ``` - * internal object SomeLibrary : CatalogEntry() { + * internal object MyLib : CatalogEntry() { * // ... * } * ``` * * ## Nesting * - * Entries support nesting. One entry can be put into another one. This way they - * can form a hierarchy. + * One entry can be put into another one. This way entries can form a hierarchy. + * When an entry is [asked][allRecords] for records, it will propagate the + * request down the hierarchy. Thus, only root entries should be asked for records. * * Also, each item in a version catalog should have [Alias]. An entry sets aliases * on its own for items, declared within it. To do this, it takes object's name @@ -103,15 +102,13 @@ package io.spine.internal.catalog.model * } * ``` * - * Sometimes, a library can consist of several modules. Or even of a group - * of modules. A group can be declared using a nested entry, and extra modules - * by a [delegated property][lib]. + * Sometimes, a library consists of several modules. Or even of a group of modules. + * A group can be declared by a nested entry, and extra modules 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" @@ -129,25 +126,6 @@ package io.spine.internal.catalog.model * 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 parent. * - * Also, when a module is named after the entry in which it is declared, - * the resulting suffix will not contain a duplicated suffix. Consider an example - * below, in which comments represent the generated type-safe accessors to - * corresponding items. - * - * - * An example with a module named after the entry: - * - * ``` - * internal object MyLib : CatalogEntry() { - * private const val group = "com.company" - * override val version = "1.9.0" // libs.versions.myLib - * - * val myLib by lib("$group:my-lib") // libs.myLib (not libs.myLib.myLib!) - * val types by lib("$group:my-types") // libs.myLib.types - * val data by lib("$group:my-data") // libs.myLib.data - * } - * ``` - * * ## Plugins * * The minimum, required to declare a plugin is a [version] and [id]. @@ -161,29 +139,29 @@ package io.spine.internal.catalog.model * } * ``` * - * A standalone plugin is also a quite rare case. Usually, they are declared - * within more complex entries, which represent frameworks or big libraries that - * consists of several modules. Additionally, plugins can be supplemented with - * a library, that makes possible applying a plugin from `buildSrc`. - * - * Please note, that `GradlePlugin` is a special name for entries. Such entry - * will not append `gradlePlugin` suffix for [id] item. + * A standalone plugin is a quite rare case. Usually, they are declared within + * more complex entries, which represent frameworks or big libraries that + * consists of several modules. A plugin can also be supplemented with a library, + * that makes possible applying it from `buildSrc`. * * For example: * * ``` - * internal object MyBigLib : VersionEntry() { + * internal object MyLib : VersionEntry() { * private const val group = "com.company" * // ... * * object GradlePlugin : PluginEntry() { - * override val version = "1.2.3" // libs.versions.myBigLib.gradlePlugin - * override val module = "$group:my-plugin" // libs.myBigLib.gradlePlugin - * override val id = "$group.plugin" // libs.plugins.myBigLib (without `gradlePlugin`!) + * 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`!) * } * } * ``` * + * Please note, that `GradlePlugin` is a special name for entries. Such an entry + * will not append `gradlePlugin` suffix for [id] item. + * * ## Bundles * * A bundle is a named set of libraries. One can compose a bundle out of @@ -208,21 +186,27 @@ package io.spine.internal.catalog.model * } * * override val bundle = setOf( - * Runner, + * + * // entries, which declare `module` + * this, Runner, + * + * // extra modules * Adapters.html4, * Adapters.html5, + * + * // in-place declarations * lib("linter", "$group:linter"), - * lib("core", "$group:core") + * lib("core", "$group:core"), * ) * } * ``` * - * There's also a possibility to declare extra bundles on top of a current entry. - * Just like with extra modules, using a [property delegation][bundle]. + * There's also a possibility to declare extra bundles on top of the current entry. + * Just like with extra modules, using a [property delegate][bundle]. * * For example: * - * * ``` + * ``` * internal object MyLib : CatalogEntry() { * private const val group = "com.company" * override val version = "1.9.0" @@ -260,26 +244,17 @@ abstract class CatalogEntry { delegate { property -> lib(property.name, module) } fun lib(name: String, module: String): CatalogRecord { - val thisEntryAlias = this.alias - val libAlias = if (thisEntryAlias.endsWith(name)) thisEntryAlias - else "$thisEntryAlias-$name" - + val libAlias = "$alias-$name" val record = LibraryRecord(libAlias, module, versionRecord) - standaloneLibs.add(record) - - return record + return record.also { standaloneLibs.add(it) } } fun bundle(vararg libs: Any): MemoizingDelegate = delegate { property -> - val thisEntryAlias = this.alias - val bundleAlias = "$thisEntryAlias-${property.name}" - + val bundleAlias = "$alias-${property.name}" val libRecords = libs.asIterable().toLibraryRecords() val record = BundleRecord(bundleAlias, libRecords) - standaloneBundles.add(record) - - record + record.also { standaloneBundles.add(it) } } fun allRecords(): Set { 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 ebb7fb7b3..ff62df2f8 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 @@ -92,6 +92,7 @@ internal object Dummy : CatalogEntry() { // referenced as well as the one declared by `lib()` delegate. val runtime by bundle( // libs.bundles.dummy.runtime + this, Runtime.BOM, Runtime.win, Runtime.mac, diff --git a/version-catalog/func-test/dummy-project/build.gradle.kts b/version-catalog/func-test/dummy-project/build.gradle.kts index c5c3a16be..1745012fb 100644 --- a/version-catalog/func-test/dummy-project/build.gradle.kts +++ b/version-catalog/func-test/dummy-project/build.gradle.kts @@ -62,11 +62,11 @@ 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-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,10 +85,11 @@ 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-lib: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" + "]" ) From 66608d5a444d0bec63d4c8233adefe7e289fbbca Mon Sep 17 00:00:00 2001 From: "yevhenii.nadtochii" Date: Fri, 10 Jun 2022 15:22:53 +0300 Subject: [PATCH 06/11] Adjust tests to a single `CatalogEntry` --- .../internal/catalog/model/CatalogEntry.kt | 56 ++- .../catalog/model/CatalogEntryTest.kt | 343 ++++++++++++------ .../catalog/model/DependencyEntryTest.kt | 130 ------- .../internal/catalog/model/PluginEntryTest.kt | 122 ------- .../catalog/model/given/CatalogEntries.kt | 195 +++++++--- ...EntryTestEnv.kt => CatalogEntryTestEnv.kt} | 27 +- .../catalog/model/given/DependencyEntries.kt | 73 ---- .../catalog/model/given/LibraryEntries.kt | 25 -- .../model/given/LibraryEntryTestEnv.kt | 49 --- .../catalog/model/given/PluginEntries.kt | 64 ---- .../catalog/model/given/PluginEntryTestEnv.kt | 54 --- .../io/spine/internal/catalog/entry/Dummy.kt | 31 +- .../func-test/dummy-project/build.gradle.kts | 4 +- 13 files changed, 437 insertions(+), 736 deletions(-) delete mode 100644 version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/DependencyEntryTest.kt delete mode 100644 version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/PluginEntryTest.kt rename version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/{DependencyEntryTestEnv.kt => CatalogEntryTestEnv.kt} (62%) delete mode 100644 version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/DependencyEntries.kt delete mode 100644 version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/LibraryEntries.kt delete mode 100644 version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/LibraryEntryTestEnv.kt delete mode 100644 version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/PluginEntries.kt delete mode 100644 version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/PluginEntryTestEnv.kt 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 507b105b8..c11a31829 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 @@ -51,13 +51,15 @@ package io.spine.internal.catalog.model * * ## Nesting * - * One entry can be put into another one. This way entries can form a hierarchy. - * When an entry is [asked][allRecords] for records, it will propagate the - * request down the hierarchy. Thus, only root entries should be asked for records. + * 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 for obtaining records. * - * Also, each item in a version catalog should have [Alias]. An entry sets aliases - * on its own for items, declared within it. To do this, it takes object's name - * with respect to its nesting. + * ## Aliasing + * + * Each item in a version catalog should have [Alias]. An entry sets aliases on + * its own for items, declared within it. To do this, it takes object's name with + * respect to its nesting. * * One can declare an entry, which only hosts other entries. Thus, providing * a named scope for other declarations. @@ -75,9 +77,9 @@ package io.spine.internal.catalog.model * See documentation to [Alias] to see how a type-safe accessor is generated * from an alias. * - * ## Versions + * ## Declaring versions * - * An entry which declares only a version is a quite rare case. Such entries + * 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: @@ -88,7 +90,7 @@ package io.spine.internal.catalog.model * } * ``` * - * ## Libraries + * ## Declaring libraries * * The most common case is a declaring a library. Most entries just declare a * single library. @@ -125,8 +127,10 @@ package io.spine.internal.catalog.model * * 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 parent. + * Entry will go up to the root, searching for a version. If the version is needed, + * but can't be found, an entry will throw an exception. * - * ## Plugins + * ## Declaring plugins * * The minimum, required to declare a plugin is a [version] and [id]. * @@ -162,10 +166,10 @@ package io.spine.internal.catalog.model * Please note, that `GradlePlugin` is a special name for entries. Such an entry * will not append `gradlePlugin` suffix for [id] item. * - * ## Bundles + * ## Declaring bundles * - * A bundle is a named set of libraries. One can compose a bundle out of - * extra modules, in-place module declarations or entries (which declare module). + * A bundle is a named set of libraries. One can compose a bundle out of already + * declared extra modules, in-place module declarations or entries (which declare module). * * For example: * @@ -258,19 +262,23 @@ abstract class CatalogEntry { } fun allRecords(): Set { - val result = mutableSetOf() - val fromThisEntry = records() - result.addAll(fromThisEntry) + if (outerEntry != null) { + throw IllegalStateException("Only root entries can produce records!") + } - val nestedEntries = nestedEntries() - val fromNested = nestedEntries.flatMap { it.allRecords() } - result.addAll(fromNested) + val allRecords = records() + return allRecords + } + private fun records(): Set { + val fromThisEntry = recordsFromThisEntry() + val fromNested = recordsFromNested() + val result = fromThisEntry + fromNested return result } - private fun records(): Set { + private fun recordsFromThisEntry(): Set { val result = mutableSetOf() if (version != null) { @@ -301,6 +309,14 @@ abstract class CatalogEntry { return result } + private fun recordsFromNested(): Set { + val result = mutableSetOf() + val nestedEntries = nestedEntries() + val fromNested = nestedEntries.flatMap { it.records() } + result.addAll(fromNested) + return result + } + private fun nestedEntries(): Set { val nestedClasses = this::class.nestedClasses val nestedObjects = nestedClasses.mapNotNull { it.objectInstance } 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 04b907218..cb9d6dbd2 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 @@ -1,102 +1,241 @@ -///* -// * 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.OuterDummy -//import io.spine.internal.catalog.model.given.StandaloneDummy -//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("`CatalogEntry` should") -//internal class CatalogEntryTest { -// -// @Nested -// inner class `when standalone` { -// -// private val standaloneEntry = StandaloneDummy -// -// @Test -// fun `use object's name as alias`() { -//// assertThat(standaloneEntry.alias).isEqualTo("standaloneDummy") -// } -// -// @Test -// fun `produce no records`() { -// assertThat(standaloneEntry.allRecords()).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") -// } -// -// @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!") -// } -// } -// -// @Nested -// inner class `when outer` { -// -// @Test -// fun `ask nested entries for records`() { -// -// val nested = listOf( -// OuterDummy.Runtime, -// OuterDummy.Runtime.Mac, -// OuterDummy.Runtime.Win, -// OuterDummy.Runtime.Linux, -// ) -// -// nested.forEach { -// assertThat(it.wasAsked).isFalse() -// } -// -// assertThat(OuterDummy.allRecords()).isEmpty() -// -// nested.forEach { -// assertThat(it.wasAsked).isTrue() -// } -// } -// } -//} +/* + * 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.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.ErroneousEntry +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 +import org.junit.jupiter.api.assertThrows + +@DisplayName("`CatalogEntry` should") +internal class CatalogEntryTest { + + @Nested + inner class `when is root` { + + @Nested + inner class `optionally declare` { + + @Test + fun `a version`() { + val entry = VersionEntry + val records = entry.allRecords() + assertThat(records).hasSize(1) + + val record = versionRecord(records) + assertThat(record.alias).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).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).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).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).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).isEqualTo("extraBundleEntry-full") + + val expected = records.filterIsInstance().toSet() + assertThat(expected).hasSize(3) + assertThat(bundle.libs).isEqualTo(expected) + } + } + + @Test + fun `produce no records if empty`() { + val entry = EmptyRootEntry + val records = entry.allRecords() + assertThat(records).isEmpty() + } + + @Test + fun `ask nested entries for records`() { + val entry = RootEntry + val records = entry.allRecords() + assertThat(records).hasSize(5) + } + + @Test + fun `use object's name for alias`() { + val entry = RootEntry + val record = entry.allRecords().first() + assertThat(record.alias).isEqualTo("rootEntry") + } + } + + @Nested + inner class `when is nested` { + + @Nested + inner class `inherit the version from` { + + @Test + fun `direct parent`() { + val entry = DirectInheritingEntry + val records = entry.allRecords() + assertThat(records).hasSize(2) + + val library = libraryRecord(records) + assertThat(library.alias).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).isEqualTo("indirectInheritingEntry-separator-inheritor") + assertThat(library.module).isEqualTo("com.company:lib") + + val version = versionRecord(records) + assertThat(library.version).isEqualTo(version) + } + } + + @Test + fun `throw if the version is needed, but not declared`() { + val entry = ErroneousEntry + 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).isEqualTo("withPluginEntry") + assertThat(plugin.id).isEqualTo("my.plugin") + + val version = versionRecord(records) + assertThat(plugin.version).isEqualTo(version) + assertThat(version.alias).isEqualTo("withPluginEntry-gradlePlugin") + } + + @Test + fun `reflect nesting in alias`() { + val entry = RootEntry + val records = entry.allRecords() + val expected = setOf( + VersionRecord("rootEntry", "re0.0.0"), + VersionRecord("rootEntry-firstChild", "fc0.0.0"), + VersionRecord("rootEntry-secondChild", "sc0.0.0"), + VersionRecord("rootEntry-thirdChild", "tc0.0.0"), + VersionRecord("rootEntry-thirdChild-grandChild", "gc0.0.0"), + ) + assertThat(records).isEqualTo(expected) + } + + @Test + fun `throw 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 1850a1898..000000000 --- a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/DependencyEntryTest.kt +++ /dev/null @@ -1,130 +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 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/PluginEntryTest.kt b/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/PluginEntryTest.kt deleted file mode 100644 index 2600e8402..000000000 --- a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/PluginEntryTest.kt +++ /dev/null @@ -1,122 +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 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/given/CatalogEntries.kt b/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/CatalogEntries.kt index ec9ada042..63fae4b07 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 @@ -1,57 +1,138 @@ -///* -// * 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.CatalogRecord -//import io.spine.internal.catalog.model.CatalogEntry -// -//internal object StandaloneDummy : CatalogEntry() -// -//internal open class MemoizingCatalogEntry : CatalogEntry() { -// -// var wasAsked: Boolean = false -// -// override fun records(): Set { -// wasAsked = true -// return emptySet() -// } -//} -// -//internal object OuterDummy : CatalogEntry() { -// -// object Runtime : MemoizingCatalogEntry() { -// object Mac : MemoizingCatalogEntry() -// object Win : MemoizingCatalogEntry() -// object Linux : MemoizingCatalogEntry() -// } -// -// object NotEntry { -// object Api : CatalogEntry() { -// object Params : CatalogEntry() -// } -// } -//} +/* + * 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 + +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" +} + +@Suppress("unused") +internal object ExtraLibraryEntry : CatalogEntry() { + override val version = "el0.0.1" + 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("unused", "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") + val full by bundle( + this, + core, + lib("runner", "com.company:runner-lib") + ) +} + +internal object EmptyRootEntry : CatalogEntry() + +@Suppress("unused") +internal object RootEntry : CatalogEntry() { + + override val version = "re0.0.0" + + object FirstChild : CatalogEntry() { + override val version = "fc0.0.0" + } + + object SecondChild : CatalogEntry() { + override val version = "sc0.0.0" + } + + object ThirdChild : CatalogEntry() { + + override val version = "tc0.0.0" + + object GrandChild : CatalogEntry() { + override val version = "gc0.0.0" + } + } +} + +@Suppress("unused") +internal object DirectInheritingEntry : CatalogEntry() { + override val version = "dvi0.0.1" + + object Inheritor : CatalogEntry() { + override val module = "com.company:lib" + } +} + +@Suppress("unused") +internal object IndirectInheritingEntry : CatalogEntry() { + override val version = "ivi0.0.1" + + object Separator : CatalogEntry() { + + object Inheritor : CatalogEntry() { + override val module = "com.company:lib" + } + } +} + +@Suppress("unused") +internal object ErroneousEntry : CatalogEntry() { + object Nested : CatalogEntry() { + override val module = "com.company:lib" + } +} + +@Suppress("unused") +internal object WithPluginEntry : CatalogEntry() { + 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 62% 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 d8a6cac43..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,33 +26,24 @@ package io.spine.internal.catalog.model.given -import io.spine.internal.catalog.model.CatalogEntry -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: CatalogEntry) = - entry.allRecords().first { it is VersionRecord } as VersionRecord + fun versionRecord(records: Iterable): VersionRecord = typedRecord(records) - fun VersionRecord.assert(alias: String, version: String) { - assertEquals(alias, this.alias) - assertEquals(version, this.value) - } + fun libraryRecord(records: Iterable): LibraryRecord = typedRecord(records) - fun libraryRecord(entry: CatalogEntry) = - entry.allRecords().first { it is LibraryRecord } as LibraryRecord + fun pluginRecord(records: Iterable): PluginRecord = typedRecord(records) - fun bundleRecord(entry: CatalogEntry) = - entry.allRecords().first { it is BundleRecord } as BundleRecord + fun bundleRecord(records: Iterable): BundleRecord = typedRecord(records) - fun BundleRecord.assert(alias: Alias, libs: Set) { - assertEquals(alias, this.alias) - assertEquals(libs, this.libs) - } + 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 d7a574dca..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.CatalogEntry - -internal object StandaloneDummyVersionDependency : CatalogEntry() { - override val version = "sdvd-0.0.1" -} - -internal object StandaloneDummyLibraryDependency : CatalogEntry() { - override val version = "sdld-0.0.1" - override val module = "org.dummy" -} - -internal object StandaloneDummyBundleDependency : CatalogEntry() { - 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 : CatalogEntry() { - override val version = "sdpd-0.0.1" - val subLib by lib("org.dummy:subLib") -} - -@Suppress("unused") -internal object SimpleDependency : CatalogEntry() { - override val version = "sdpnd-0.0.1" - val simpleDependency by lib("org.simple") -} - -internal object OuterDummyDependency : CatalogEntry() { - override val version = "odp-0.0.1" - - object Nested : CatalogEntry() { - override val module = "org.nested" - } -} - -internal object ErroneousOuterDummyDependency : CatalogEntry() { - object Nested : CatalogEntry() { - 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 a204bb69c..000000000 --- a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/LibraryEntries.kt +++ /dev/null @@ -1,25 +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. - */ 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 15a864983..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 a6ade7032..000000000 --- a/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/PluginEntries.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.given -// -//import io.spine.internal.catalog.model.CatalogEntry -//import io.spine.internal.catalog.model.PluginEntry -// -//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 : CatalogEntry() { -// 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 8cfa0dfab..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/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 ff62df2f8..0c30f0570 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 @@ -35,10 +35,10 @@ import io.spine.internal.catalog.model.CatalogEntry * 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") @@ -52,19 +52,19 @@ internal object Dummy : CatalogEntry() { 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 : CatalogEntry() { override val version = "0.0.8" // libs.versions.dummy.gradlePlugin @@ -75,7 +75,7 @@ internal object Dummy : CatalogEntry() { 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" + // the parent entry. For example, in this case, all libs within "Runtime" // entry will have "1.0.0". val win by lib("$group:runtime-win") // libs.dummy.runtime.win @@ -88,20 +88,13 @@ internal object Dummy : CatalogEntry() { } } - // 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 - this, Runtime.BOM, Runtime.win, Runtime.mac, Runtime.linux, ) - - // It is also possible to declare just a bare version. - - object Tools : CatalogEntry() { - 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 1745012fb..0c21e7554 100644 --- a/version-catalog/func-test/dummy-project/build.gradle.kts +++ b/version-catalog/func-test/dummy-project/build.gradle.kts @@ -62,6 +62,7 @@ with(libs.dummy) { assert( libs.bundles.dummy, "[" + + "$group:dummy-lib:1.0.0, " + "$group:dummy-core:1.0.0, " + "$group:dummy-runner:1.0.0, " + "$group:dummy-api:1.0.0, " + @@ -85,12 +86,9 @@ with(libs.dummy.runtime) { assert( libs.bundles.dummy.runtime, "[" + - "$group:dummy-lib: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") From e2c6cbc35f983c02bc576116d75846bcefd6ed75 Mon Sep 17 00:00:00 2001 From: "yevhenii.nadtochii" Date: Fri, 10 Jun 2022 16:36:38 +0300 Subject: [PATCH 07/11] Extract Alias-related code to `Alias` class --- .../io/spine/internal/catalog/model/Alias.kt | 36 +++++++++++++++--- .../internal/catalog/model/CatalogEntry.kt | 18 +++------ .../internal/catalog/model/CatalogRecords.kt | 25 ++++++------- .../catalog/model/CatalogEntryTest.kt | 37 ++++++++++--------- 4 files changed, 68 insertions(+), 48 deletions(-) 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 26f2bdf28..b94abc9ab 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 @@ -36,8 +36,8 @@ package io.spine.internal.catalog.model * ### Role of aliases in the catalog * * A version catalog itself consists of four sections: versions, libraries, plugins - * and bundles (sets of libraries). Thus, an alias can denote four types of items. - * Within each section, an alias should be unique. + * 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. * * Aliases perform two functions: * @@ -50,7 +50,7 @@ package io.spine.internal.catalog.model * 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`: + * Let's suppose, a catalog is named `libs` and each alias denotes a library: * * ``` * "kotlinX-coroutines" => libs.kotlinX.coroutines @@ -62,11 +62,37 @@ package io.spine.internal.catalog.model * Depending on which type of item an alias points, the resulting accessor * may have additional prefixes. * - * Below are an accessor patterns for different items: + * Below are accessor patterns for different 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 { + + private const val SEPARATOR = "-" + + 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 + } + } + + operator fun plus(value: String): Alias { + val newValue = this.value + SEPARATOR + value + val result = Alias(newValue) + return result + } + + fun withoutSuffix(value: String): Alias { + val newValue = this.value.removeSuffix(SEPARATOR + value) + val result = 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 c11a31829..363b6de04 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 @@ -228,13 +228,14 @@ package io.spine.internal.catalog.model * } * ``` */ +@Suppress("LeakingThis") // `Alias.forEntry()` uses only final properties. abstract class CatalogEntry { private val standaloneLibs = mutableSetOf() private val standaloneBundles = mutableSetOf() private val versionRecord: VersionRecord by lazy { versionRecord() } - private val outerEntry: CatalogEntry? = outerEntry() - private val alias: Alias = alias() + internal val outerEntry: CatalogEntry? = outerEntry() + internal val alias: Alias = Alias.forEntry(this) open val version: String? = null @@ -248,14 +249,14 @@ abstract class CatalogEntry { delegate { property -> lib(property.name, module) } fun lib(name: String, module: String): CatalogRecord { - val libAlias = "$alias-$name" + val libAlias = alias + name val record = LibraryRecord(libAlias, module, versionRecord) return record.also { standaloneLibs.add(it) } } fun bundle(vararg libs: Any): MemoizingDelegate = delegate { property -> - val bundleAlias = "$alias-${property.name}" + val bundleAlias = alias + property.name val libRecords = libs.asIterable().toLibraryRecords() val record = BundleRecord(bundleAlias, libRecords) record.also { standaloneBundles.add(it) } @@ -292,7 +293,7 @@ abstract class CatalogEntry { } if (id != null) { - val pluginAlias = alias.removeSuffix("-gradlePlugin") + val pluginAlias = alias.withoutSuffix("gradlePlugin") val record = PluginRecord(pluginAlias, id!!, versionRecord) result.add(record) } @@ -335,13 +336,6 @@ abstract class CatalogEntry { return enclosingInstance } - private fun alias(): String { - fun String.toCamelCase() = replaceFirstChar { it.lowercaseChar() } - 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 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 57baa66c5..d4f9e7581 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,7 +29,7 @@ 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 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. @@ -37,7 +37,7 @@ import org.gradle.api.initialization.dsl.VersionCatalogBuilder * This interface, doesn't represent a concrete catalog item. It serves as a common * foundation for other records. * - * All concrete records are internal by design. They are used by [CatalogEntry] + * 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. @@ -61,7 +61,7 @@ interface CatalogRecord { } /** - * Represents a version, 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. * @@ -73,18 +73,18 @@ internal data class VersionRecord( ) : CatalogRecord { override fun writeTo(catalog: VersionCatalogBuilder) { - catalog.version(alias, value) + catalog.version(alias.value, value) } } /** - * Represents a library, 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`. * - * A version of the library is obtained by referencing to the given [version record][version]. + * A version of the library is referenced by the given [version record][version]. */ internal data class LibraryRecord( override val alias: Alias, @@ -95,19 +95,19 @@ internal data class LibraryRecord( override fun writeTo(catalog: VersionCatalogBuilder) { val group = module.substringBefore(':') val artifact = module.substringAfter(':') - catalog.library(alias, group, artifact).versionRef(version.alias) + catalog.library(alias.value, group, artifact).versionRef(version.alias.value) } } /** - * Represents a plugin, 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`. * - * A version of the plugin is obtained by referencing to the given [version record][version]. + * A version of the plugin is referenced by the given [version record][version]. */ internal data class PluginRecord( override val alias: Alias, @@ -116,13 +116,12 @@ internal data class PluginRecord( ) : CatalogRecord { override fun writeTo(catalog: VersionCatalogBuilder) { - catalog.plugin(alias, id).versionRef(version.alias) + catalog.plugin(alias.value, id).versionRef(version.alias.value) } } /** - * Represents a named set of libraries, which can be directly written into - * a version catalog + * A named set of libraries, which can be directly written into a version catalog */ internal data class BundleRecord( override val alias: Alias, @@ -130,6 +129,6 @@ internal data class BundleRecord( ) : CatalogRecord { override fun writeTo(catalog: VersionCatalogBuilder) { - catalog.bundle(alias, libs.map { it.alias }) + catalog.bundle(alias.value, libs.map { it.alias.value }) } } 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 cb9d6dbd2..80d0d88e7 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 @@ -65,7 +65,7 @@ internal class CatalogEntryTest { assertThat(records).hasSize(1) val record = versionRecord(records) - assertThat(record.alias).isEqualTo("versionEntry") + assertThat(record.alias.value).isEqualTo("versionEntry") assertThat(record.value).isEqualTo("v0.0.1") } @@ -76,7 +76,7 @@ internal class CatalogEntryTest { assertThat(records).hasSize(2) val library = libraryRecord(records) - assertThat(library.alias).isEqualTo("libraryEntry") + assertThat(library.alias.value).isEqualTo("libraryEntry") assertThat(library.module).isEqualTo("com.company:lib") val version = versionRecord(records) @@ -90,7 +90,7 @@ internal class CatalogEntryTest { assertThat(records).hasSize(2) val library = libraryRecord(records) - assertThat(library.alias).isEqualTo("extraLibraryEntry-core") + assertThat(library.alias.value).isEqualTo("extraLibraryEntry-core") assertThat(library.module).isEqualTo("com.company:core-lib") val version = versionRecord(records) @@ -104,7 +104,7 @@ internal class CatalogEntryTest { assertThat(records).hasSize(2) val plugin = pluginRecord(records) - assertThat(plugin.alias).isEqualTo("pluginEntry") + assertThat(plugin.alias.value).isEqualTo("pluginEntry") assertThat(plugin.id).isEqualTo("com.company.plugin") val version = versionRecord(records) @@ -118,7 +118,7 @@ internal class CatalogEntryTest { assertThat(records).hasSize(5) val bundle = bundleRecord(records) - assertThat(bundle.alias).isEqualTo("bundleEntry") + assertThat(bundle.alias.value).isEqualTo("bundleEntry") val expected = records.filterIsInstance().toSet() assertThat(expected).hasSize(3) @@ -132,7 +132,7 @@ internal class CatalogEntryTest { assertThat(records).hasSize(5) val bundle = bundleRecord(records) - assertThat(bundle.alias).isEqualTo("extraBundleEntry-full") + assertThat(bundle.alias.value).isEqualTo("extraBundleEntry-full") val expected = records.filterIsInstance().toSet() assertThat(expected).hasSize(3) @@ -158,7 +158,7 @@ internal class CatalogEntryTest { fun `use object's name for alias`() { val entry = RootEntry val record = entry.allRecords().first() - assertThat(record.alias).isEqualTo("rootEntry") + assertThat(record.alias.value).isEqualTo("rootEntry") } } @@ -175,7 +175,7 @@ internal class CatalogEntryTest { assertThat(records).hasSize(2) val library = libraryRecord(records) - assertThat(library.alias).isEqualTo("directInheritingEntry-inheritor") + assertThat(library.alias.value).isEqualTo("directInheritingEntry-inheritor") assertThat(library.module).isEqualTo("com.company:lib") val version = versionRecord(records) @@ -189,7 +189,7 @@ internal class CatalogEntryTest { assertThat(records).hasSize(2) val library = libraryRecord(records) - assertThat(library.alias).isEqualTo("indirectInheritingEntry-separator-inheritor") + assertThat(library.alias.value).isEqualTo("indirectInheritingEntry-separator-inheritor") assertThat(library.module).isEqualTo("com.company:lib") val version = versionRecord(records) @@ -210,26 +210,27 @@ internal class CatalogEntryTest { assertThat(records).hasSize(2) val plugin = pluginRecord(records) - assertThat(plugin.alias).isEqualTo("withPluginEntry") + assertThat(plugin.alias.value).isEqualTo("withPluginEntry") assertThat(plugin.id).isEqualTo("my.plugin") val version = versionRecord(records) assertThat(plugin.version).isEqualTo(version) - assertThat(version.alias).isEqualTo("withPluginEntry-gradlePlugin") + assertThat(version.alias.value).isEqualTo("withPluginEntry-gradlePlugin") } @Test fun `reflect nesting in alias`() { val entry = RootEntry val records = entry.allRecords() - val expected = setOf( - VersionRecord("rootEntry", "re0.0.0"), - VersionRecord("rootEntry-firstChild", "fc0.0.0"), - VersionRecord("rootEntry-secondChild", "sc0.0.0"), - VersionRecord("rootEntry-thirdChild", "tc0.0.0"), - VersionRecord("rootEntry-thirdChild-grandChild", "gc0.0.0"), + val aliases = records.map { it.alias.value } + val expected = listOf( + "rootEntry", + "rootEntry-firstChild", + "rootEntry-secondChild", + "rootEntry-thirdChild", + "rootEntry-thirdChild-grandChild", ) - assertThat(records).isEqualTo(expected) + assertThat(aliases).isEqualTo(expected) } @Test From e21c29b575c74df89d99e677df238c8445c2e021 Mon Sep 17 00:00:00 2001 From: "yevhenii.nadtochii" Date: Fri, 10 Jun 2022 18:33:47 +0300 Subject: [PATCH 08/11] Document public properties and methods of `CatalogEntry` --- .../io/spine/internal/catalog/model/Alias.kt | 42 +++- .../internal/catalog/model/CatalogEntry.kt | 182 +++++++++++++++--- .../catalog/model/CatalogEntryTest.kt | 21 +- .../catalog/model/given/CatalogEntries.kt | 9 +- 4 files changed, 208 insertions(+), 46 deletions(-) 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 b94abc9ab..8c15ffd08 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 @@ -35,16 +35,16 @@ package io.spine.internal.catalog.model * * ### Role of aliases in 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. - * * Aliases perform two functions: * * 1. Navigation. By an alias, one can locate and access an item in the catalog. * 2. Referencing. One item in a version catalog can use another item, and this * linkage is done via aliases. * + * 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 @@ -62,7 +62,7 @@ package io.spine.internal.catalog.model * Depending on which type of item an alias points, the resulting accessor * may have additional prefixes. * - * Below are accessor patterns for different items: + * Below are accessor patterns for different types of item: * * 1. Library: `{catalog name}.{alias}`. * 2. Version: `{catalog name}.versions.{alias}`. @@ -74,8 +74,21 @@ value class Alias private constructor(val value: String) { companion object { + /** + * Gradle's recommended separator for aliases. + * + * It can also be a dot (.) or an underscore (_). + */ 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 with camel-cased entry's + * name appended. + */ fun forEntry(entry: CatalogEntry): Alias { val className = entry.javaClass.simpleName.replaceFirstChar { it.lowercaseChar() } val outerEntry = entry.outerEntry @@ -84,15 +97,24 @@ value class Alias private constructor(val value: String) { } } - operator fun plus(value: String): Alias { - val newValue = this.value + SEPARATOR + value + /** + * 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 } - fun withoutSuffix(value: String): Alias { - val newValue = this.value.removeSuffix(SEPARATOR + value) - val result = Alias(newValue) + /** + * 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 363b6de04..c22ed68ac 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 @@ -43,6 +43,8 @@ package io.spine.internal.catalog.model * Please note, only object declarations are meant to inherit from this class * and serve as concrete entries. * + * For example: + * * ``` * internal object MyLib : CatalogEntry() { * // ... @@ -53,13 +55,13 @@ package io.spine.internal.catalog.model * * 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 for obtaining records. + * 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. To do this, it takes object's name with - * respect to its nesting. + * 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. @@ -67,10 +69,10 @@ package io.spine.internal.catalog.model * 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 + * internal object Runtime : CatalogEntry() { // alias = "runtime" + * object Linux : CatalogEntry() // alias = "runtime-linux" + * object Mac : CatalogEntry() // alias = "runtime-mac" + * object Win : CatalogEntry() // alias = "runtime-win" * } * ``` * @@ -104,8 +106,9 @@ package io.spine.internal.catalog.model * } * ``` * - * Sometimes, a library consists of several modules. Or even of a group of modules. - * A group can be declared by a nested entry, and extra modules by a [delegated property][lib]. + * Sometimes, a dependency consists of several libraries. Or even of a group + * of libraries. A group can be declared by a nested entry, and extra libraries + * by a [delegated property][lib]. * * For example: * @@ -126,9 +129,9 @@ package io.spine.internal.catalog.model * ``` * * 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 parent. - * Entry will go up to the root, searching for a version. If the version is needed, - * but can't be found, an entry will throw an exception. + * when a version is not declared, an entry will try to fetch it from any + * parental entry. Entry will go up to the root entry, searching for a version. + * If the version is needed, but isn't found, an entry will throw an exception. * * ## Declaring plugins * @@ -143,19 +146,19 @@ package io.spine.internal.catalog.model * } * ``` * - * A standalone plugin is a quite rare case. Usually, they are declared within - * more complex entries, which represent frameworks or big libraries that - * consists of several modules. A plugin can also be supplemented with a library, - * that makes possible applying it from `buildSrc`. + * 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 : VersionEntry() { + * internal object MyLib : CatalogEntry() { * private const val group = "com.company" * // ... * - * object GradlePlugin : PluginEntry() { + * 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`!) @@ -163,13 +166,16 @@ package io.spine.internal.catalog.model * } * ``` * - * Please note, that `GradlePlugin` is a special name for entries. Such an entry - * will not append `gradlePlugin` suffix for [id] item. + * In the example above, comments show the resulting 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 modules, in-place module declarations or entries (which declare module). + * declared extra libraries, in-place library declarations or entries, which + * declare a library. * * For example: * @@ -206,7 +212,7 @@ package io.spine.internal.catalog.model * ``` * * There's also a possibility to declare extra bundles on top of the current entry. - * Just like with extra modules, using a [property delegate][bundle]. + * Just like with extra libraries, using a [property delegate][bundle]. * * For example: * @@ -228,40 +234,156 @@ package io.spine.internal.catalog.model * } * ``` */ -@Suppress("LeakingThis") // `Alias.forEntry()` uses only final properties. abstract class CatalogEntry { - private val standaloneLibs = mutableSetOf() - private val standaloneBundles = mutableSetOf() + 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. + * + * 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 pass into this set: + * + * 1. [CatalogEntry]s which declare [module]. + * 2. Extra libraries, created 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 + /** + * Declares an extra library on the 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 based on entry's [alias] and + * a property name. + */ fun lib(module: String): MemoizingDelegate = delegate { property -> lib(property.name, module) } + /** + * Declares an extra library on the top of this entry. + * + * This method exists to declare libraries right in bundle 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 based on entry's [alias] and + * a property name. + */ fun lib(name: String, module: String): CatalogRecord { val libAlias = alias + name val record = LibraryRecord(libAlias, module, versionRecord) - return record.also { standaloneLibs.add(it) } + return record.also { extraLibs.add(it) } } + /** + * Declares an extra bundle on top of this entry, using property delegation. + * + * 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") + * ) + * ``` + * + * The resulting alias fot this bundle is based on entry's [alias] and + * a property name. + */ 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 { standaloneBundles.add(it) } + record.also { extraBundles.add(it) } } + /** + * 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) { @@ -293,7 +415,7 @@ abstract class CatalogEntry { } if (id != null) { - val pluginAlias = alias.withoutSuffix("gradlePlugin") + val pluginAlias = alias - "gradlePlugin" val record = PluginRecord(pluginAlias, id!!, versionRecord) result.add(record) } @@ -304,8 +426,8 @@ abstract class CatalogEntry { result.add(record) } - standaloneLibs.forEach { result.add(it) } - standaloneBundles.forEach { result.add(it) } + extraLibs.forEach { result.add(it) } + extraBundles.forEach { result.add(it) } return result } 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 80d0d88e7..4b3bc865a 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 @@ -34,7 +34,8 @@ import io.spine.internal.catalog.model.given.CatalogEntryTestEnv.Companion.plugi 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.ErroneousEntry +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 @@ -197,10 +198,20 @@ internal class CatalogEntryTest { } } - @Test - fun `throw if the version is needed, but not declared`() { - val entry = ErroneousEntry - assertThrows { entry.allRecords() } + @Nested + inner class `throw an exception if the version is needed, but not declared for` { + + @Test + fun `a library`() { + val entry = ErroneousLibraryEntry + assertThrows { entry.allRecords() } + } + + @Test + fun `a plugin`() { + val entry = ErroneousPluginEntry + assertThrows { entry.allRecords() } + } } @Test 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 63fae4b07..be4526116 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 @@ -119,12 +119,19 @@ internal object IndirectInheritingEntry : CatalogEntry() { } @Suppress("unused") -internal object ErroneousEntry : CatalogEntry() { +internal object ErroneousLibraryEntry : CatalogEntry() { object Nested : CatalogEntry() { override val module = "com.company:lib" } } +@Suppress("unused") +internal object ErroneousPluginEntry : CatalogEntry() { + object Nested : CatalogEntry() { + override val id = "com.company:lib" + } +} + @Suppress("unused") internal object WithPluginEntry : CatalogEntry() { internal object GradlePlugin : CatalogEntry() { From 778604960c30fe6d84f643c7878d964701a7f1f2 Mon Sep 17 00:00:00 2001 From: "yevhenii.nadtochii" Date: Mon, 13 Jun 2022 12:25:17 +0300 Subject: [PATCH 09/11] Polish code and docs --- .../internal/catalog/SpineVersionCatalog.kt | 12 ++-- .../io/spine/internal/catalog/model/Alias.kt | 11 ++-- .../internal/catalog/model/CatalogEntry.kt | 59 ++++++++++--------- .../internal/catalog/model/CatalogRecords.kt | 2 - .../catalog/model/CatalogEntryTest.kt | 2 +- .../catalog/model/given/CatalogEntries.kt | 23 +++++--- version-catalog/func-test/build.gradle.kts | 2 +- .../func-test/dummy-catalog/build.gradle.kts | 2 + .../io/spine/internal/catalog/entry/Dummy.kt | 14 ++--- .../catalog/DummyVersionCatalogTest.kt | 2 +- 10 files changed, 66 insertions(+), 63 deletions(-) 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/model/Alias.kt b/version-catalog/catalog/src/main/kotlin/io/spine/internal/catalog/model/Alias.kt index 8c15ffd08..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 @@ -59,10 +59,10 @@ package io.spine.internal.catalog.model * "kotlinX-runtime-clr" => libs.kotlinX.runtime.clr * ``` * - * Depending on which type of item an alias points, the resulting accessor + * 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 item: + * Below are accessor patterns for different types of items: * * 1. Library: `{catalog name}.{alias}`. * 2. Version: `{catalog name}.versions.{alias}`. @@ -75,9 +75,7 @@ value class Alias private constructor(val value: String) { companion object { /** - * Gradle's recommended separator for aliases. - * - * It can also be a dot (.) or an underscore (_). + * Gradle's recommended separator for sub-aliases. */ private const val SEPARATOR = "-" @@ -86,8 +84,7 @@ value class Alias private constructor(val value: String) { * * For a top-level entry it's just a camel-cased entry's name. * - * For a nested entry, it's a parent alias with camel-cased entry's - * name appended. + * 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() } 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 c22ed68ac..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 @@ -107,8 +107,8 @@ package io.spine.internal.catalog.model * ``` * * Sometimes, a dependency consists of several libraries. Or even of a group - * of libraries. A group can be declared by a nested entry, and extra libraries - * by a [delegated property][lib]. + * of libraries. A group can be extracted into a nested entry, and extra libraries + * can be declared by a [delegated property][lib]. * * For example: * @@ -129,9 +129,9 @@ package io.spine.internal.catalog.model * ``` * * 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 any - * parental entry. Entry will go up to the root entry, searching for a version. - * If the version is needed, but isn't found, an entry will throw an exception. + * 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. * * ## Declaring plugins * @@ -166,7 +166,7 @@ package io.spine.internal.catalog.model * } * ``` * - * In the example above, comments show the resulting generated accessors. Please note, + * 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`. @@ -197,14 +197,14 @@ package io.spine.internal.catalog.model * * override val bundle = setOf( * - * // entries, which declare `module` + * // Entries, which declare `module`. * this, Runner, * - * // extra modules + * // Extra libraries, declared by `lib` delegate. * Adapters.html4, * Adapters.html5, * - * // in-place declarations + * // In-place declarations. * lib("linter", "$group:linter"), * lib("core", "$group:core"), * ) @@ -271,8 +271,8 @@ abstract class CatalogEntry { /** * 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. + * 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`. * @@ -288,6 +288,8 @@ abstract class CatalogEntry { * * 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 @@ -300,10 +302,10 @@ abstract class CatalogEntry { * * In order to do that, override this property, specifying a set of libraries. * - * The following declarations are acceptable to pass into this set: + * The following declarations are acceptable to be passed into this set: * * 1. [CatalogEntry]s which declare [module]. - * 2. Extra libraries, created by a [delegated property][lib]. + * 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 @@ -314,7 +316,7 @@ abstract class CatalogEntry { open val bundle: Set? = null /** - * Declares an extra library on the top of this entry, using property delegation. + * Declares an extra library on top of this entry, using property delegation. * * An example usage: * @@ -322,16 +324,16 @@ abstract class CatalogEntry { * val core by lib("my.company:core-lib") * ``` * - * The resulting alias fot this library is based on entry's [alias] and + * The resulting alias fot this library is entry's [alias] followed by * a property name. */ fun lib(module: String): MemoizingDelegate = delegate { property -> lib(property.name, module) } /** - * Declares an extra library on the top of this entry. + * Declares an extra library on top of this entry. * - * This method exists to declare libraries right in bundle declarations: + * This method allows declaring libraries right in bundle declarations: * * ``` * val bundle = setOf( @@ -341,8 +343,8 @@ abstract class CatalogEntry { * ) * ``` * - * The resulting alias fot this library is based on entry's [alias] and - * a property name. + * The resulting alias fot this library is entry's [alias] followed by + * the given name. */ fun lib(name: String, module: String): CatalogRecord { val libAlias = alias + name @@ -353,17 +355,16 @@ abstract class CatalogEntry { /** * Declares an extra bundle on top of this entry, using property delegation. * - * An example usage: + * The following declarations are acceptable to be passed into this set: * - * ``` - * val runtime by bundle( - * lib("mac", "my.company:mac-lib"), - * lib("linux", "my.company:linux-lib"), - * lib("win", "my.company:win-lib") - * ) - * ``` + * 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 bundle is based on entry's [alias] and + * The resulting alias fot this library is entry's [alias] followed by * a property name. */ fun bundle(vararg libs: Any): MemoizingDelegate = @@ -461,7 +462,7 @@ abstract class CatalogEntry { private fun versionRecord(): VersionRecord = when { version != null -> VersionRecord(alias, version!!) outerEntry != null -> outerEntry.versionRecord - else -> throw IllegalStateException("Specify version in this entry or any parent one!") + else -> throw IllegalStateException("Specify version in this entry or any parental one!") } private fun Iterable.toLibraryRecords(): 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 d4f9e7581..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 @@ -47,8 +47,6 @@ 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. */ 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 4b3bc865a..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 @@ -245,7 +245,7 @@ internal class CatalogEntryTest { } @Test - fun `throw on request to produce records`() { + 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/given/CatalogEntries.kt b/version-catalog/catalog/src/test/kotlin/io/spine/internal/catalog/model/given/CatalogEntries.kt index be4526116..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 @@ -37,9 +37,10 @@ internal object LibraryEntry : CatalogEntry() { override val module = "com.company:lib" } -@Suppress("unused") internal object ExtraLibraryEntry : CatalogEntry() { override val version = "el0.0.1" + + @Suppress("unused") val core by lib("com.company:core-lib") } @@ -60,11 +61,14 @@ internal object BundleEntry : CatalogEntry() { ) } -@Suppress("unused", "MemberVisibilityCanBePrivate") +@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, @@ -74,19 +78,21 @@ internal object ExtraBundleEntry : CatalogEntry() { internal object EmptyRootEntry : CatalogEntry() -@Suppress("unused") internal object RootEntry : CatalogEntry() { 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" @@ -97,43 +103,42 @@ internal object RootEntry : CatalogEntry() { } } -@Suppress("unused") internal object DirectInheritingEntry : CatalogEntry() { override val version = "dvi0.0.1" + @Suppress("unused") object Inheritor : CatalogEntry() { override val module = "com.company:lib" } } -@Suppress("unused") internal object IndirectInheritingEntry : CatalogEntry() { override val version = "ivi0.0.1" + @Suppress("unused") object Separator : CatalogEntry() { - object Inheritor : CatalogEntry() { override val module = "com.company:lib" } } } -@Suppress("unused") internal object ErroneousLibraryEntry : CatalogEntry() { + @Suppress("unused") object Nested : CatalogEntry() { override val module = "com.company:lib" } } -@Suppress("unused") internal object ErroneousPluginEntry : CatalogEntry() { + @Suppress("unused") object Nested : CatalogEntry() { override val id = "com.company:lib" } } -@Suppress("unused") internal object WithPluginEntry : CatalogEntry() { + @Suppress("unused") internal object GradlePlugin : CatalogEntry() { override val version = "gp0.0.2" override val id = "my.plugin" 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..4d1a19724 100644 --- a/version-catalog/func-test/dummy-catalog/build.gradle.kts +++ b/version-catalog/func-test/dummy-catalog/build.gradle.kts @@ -29,6 +29,7 @@ plugins { } dependencies { + // Defines declarative API for dependencies. implementation(project(":catalog")) } @@ -45,6 +46,7 @@ publishing { tasks { named("publishToMavenLocal") { + // We can't use this module from Maven local without `:catalog`. 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 0c30f0570..d7400b6cd 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 @@ -29,7 +29,7 @@ package io.spine.internal.catalog.entry 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. @@ -62,9 +62,9 @@ internal object Dummy : CatalogEntry() { 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. + // "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 @@ -74,9 +74,9 @@ internal object Dummy : CatalogEntry() { object Runtime : CatalogEntry() { - // When an entry does not override the version, it is taken from - // the parent 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 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. From 391abf9daf6db653636941c0d9bbd55838f79402 Mon Sep 17 00:00:00 2001 From: "yevhenii.nadtochii" Date: Mon, 13 Jun 2022 16:07:17 +0300 Subject: [PATCH 10/11] Add examples of override to README --- buildSrc/settings.gradle.kts | 18 +- version-catalog/README.md | 172 ++++++++++++------ .../io/spine/internal/catalog/entry/Dummy.kt | 4 +- 3 files changed, 127 insertions(+), 67 deletions(-) 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..a40afb23e 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() { +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, + ) +} +``` - 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 +## Overriding of items shipped by `SpineVersionCatalog` - // In bundles, you can reference already declared libs, - // or create them in-place. +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. - 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 - ) +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. - // "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. +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. - 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 - } +### Overriding of versions - object Runtime : DependencyEntry() { +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. - // 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". +In total, `Dummy` declares three versions. - 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 +Let's override them all: - object BOM : LibraryEntry() { - override val version = "2.0.0" // libs.versions.dummy.runtime.bom - override val module = "$group:dummy-bom" // libs.dummy.runtime.bom +```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 + } + } } ``` 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 d7400b6cd..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 @@ -82,7 +82,7 @@ internal object Dummy : CatalogEntry() { 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() { + object Bom : CatalogEntry() { override val version = "2.0.0" // libs.versions.dummy.runtime.bom override val module = "$group:dummy-bom" // libs.dummy.runtime.bom } @@ -92,7 +92,7 @@ internal object Dummy : CatalogEntry() { // Just like with extra modules. val runtime by bundle( // libs.bundles.dummy.runtime - Runtime.BOM, + Runtime.Bom, Runtime.win, Runtime.mac, Runtime.linux, From 77c85853ea2ed6c8e04e1b5476d5ff76c1435916 Mon Sep 17 00:00:00 2001 From: "yevhenii.nadtochii" Date: Mon, 13 Jun 2022 16:19:32 +0300 Subject: [PATCH 11/11] Update modules structure in README --- version-catalog/README.md | 29 ++++--------------- .../func-test/dummy-catalog/build.gradle.kts | 6 ++-- 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/version-catalog/README.md b/version-catalog/README.md index a40afb23e..2b78b62c7 100644 --- a/version-catalog/README.md +++ b/version-catalog/README.md @@ -191,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: +`spine-version-catalog` consists of two 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. +1. `catalog` – provides a facade upon Gradle's provided `VersionCatalogBuilder` +and assembles `SpineVersionCatalog`, using that facade. -2. `catalog` – contains all dependencies, declared using the declarative `api`. -The module publishes `SpineVersionCatalog`. - -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 @@ -213,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/func-test/dummy-catalog/build.gradle.kts b/version-catalog/func-test/dummy-catalog/build.gradle.kts index 4d1a19724..8125e26f5 100644 --- a/version-catalog/func-test/dummy-catalog/build.gradle.kts +++ b/version-catalog/func-test/dummy-catalog/build.gradle.kts @@ -29,7 +29,8 @@ plugins { } dependencies { - // Defines declarative API for dependencies. + // Provides declarative API for dependencies. + // It is a facade upon Gradle's provided `VersionCatalogBuilder`. implementation(project(":catalog")) } @@ -45,8 +46,9 @@ publishing { } tasks { + // It will be impossible to use this module from Maven local without `:catalog`. + // As this module depends on it. named("publishToMavenLocal") { - // We can't use this module from Maven local without `:catalog`. dependsOn(":catalog:publishToMavenLocal") } }