diff --git a/.gitmodules b/.gitmodules index 94e8664d6..97a9d16eb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "config"] path = config url = https://github.com/SpineEventEngine/config +[submodule "docs/_examples"] + path = docs/_examples + url = https://github.com/spine-examples/hello-validation diff --git a/buildSrc/src/main/kotlin/io/spine/dependency/local/Compiler.kt b/buildSrc/src/main/kotlin/io/spine/dependency/local/Compiler.kt index ff1ad47ec..304cbf4a9 100644 --- a/buildSrc/src/main/kotlin/io/spine/dependency/local/Compiler.kt +++ b/buildSrc/src/main/kotlin/io/spine/dependency/local/Compiler.kt @@ -72,7 +72,7 @@ object Compiler : Dependency() { * The version of the Compiler dependencies. */ override val version: String - private const val fallbackVersion = "2.0.0-SNAPSHOT.038" + private const val fallbackVersion = "2.0.0-SNAPSHOT.039" /** * The distinct version of the Compiler used by other build tools. @@ -81,7 +81,7 @@ object Compiler : Dependency() { * transitive dependencies, this is the version used to build the project itself. */ val dogfoodingVersion: String - private const val fallbackDfVersion = "2.0.0-SNAPSHOT.038" + private const val fallbackDfVersion = "2.0.0-SNAPSHOT.039" /** * The artifact for the Compiler Gradle plugin. diff --git a/buildSrc/src/main/kotlin/io/spine/dependency/local/CoreJvmCompiler.kt b/buildSrc/src/main/kotlin/io/spine/dependency/local/CoreJvmCompiler.kt index 39d0336ca..0944be06e 100644 --- a/buildSrc/src/main/kotlin/io/spine/dependency/local/CoreJvmCompiler.kt +++ b/buildSrc/src/main/kotlin/io/spine/dependency/local/CoreJvmCompiler.kt @@ -46,12 +46,12 @@ object CoreJvmCompiler { /** * The version used to in the build classpath. */ - const val dogfoodingVersion = "2.0.0-SNAPSHOT.052" + const val dogfoodingVersion = "2.0.0-SNAPSHOT.053" /** * The version to be used for integration tests. */ - const val version = "2.0.0-SNAPSHOT.052" + const val version = "2.0.0-SNAPSHOT.053" /** * The ID of the Gradle plugin. diff --git a/buildSrc/src/main/kotlin/io/spine/dependency/local/ToolBase.kt b/buildSrc/src/main/kotlin/io/spine/dependency/local/ToolBase.kt index 1df8dd1f4..be8a3b7fa 100644 --- a/buildSrc/src/main/kotlin/io/spine/dependency/local/ToolBase.kt +++ b/buildSrc/src/main/kotlin/io/spine/dependency/local/ToolBase.kt @@ -34,8 +34,8 @@ package io.spine.dependency.local @Suppress("ConstPropertyName", "unused") object ToolBase { const val group = Spine.toolsGroup - const val version = "2.0.0-SNAPSHOT.371" - const val dogfoodingVersion = "2.0.0-SNAPSHOT.371" + const val version = "2.0.0-SNAPSHOT.372" + const val dogfoodingVersion = "2.0.0-SNAPSHOT.372" const val lib = "$group:tool-base:$version" const val classicCodegen = "$group:classic-codegen:$version" diff --git a/buildSrc/src/main/kotlin/io/spine/dependency/local/Validation.kt b/buildSrc/src/main/kotlin/io/spine/dependency/local/Validation.kt index 1cad8b740..a76093c13 100644 --- a/buildSrc/src/main/kotlin/io/spine/dependency/local/Validation.kt +++ b/buildSrc/src/main/kotlin/io/spine/dependency/local/Validation.kt @@ -36,7 +36,7 @@ object Validation { /** * The version of the Validation library artifacts. */ - const val version = "2.0.0-SNAPSHOT.393" + const val version = "2.0.0-SNAPSHOT.394" /** * The last version of Validation compatible with ProtoData. diff --git a/dependencies.md b/dependencies.md index ef9b16989..0da6c75ab 100644 --- a/dependencies.md +++ b/dependencies.md @@ -1,6 +1,6 @@ -# Dependencies of `io.spine.tools:validation-context:2.0.0-SNAPSHOT.394` +# Dependencies of `io.spine.tools:validation-context:2.0.0-SNAPSHOT.395` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.20.0. @@ -1139,14 +1139,14 @@ The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Fri Feb 13 15:18:11 WET 2026** using +This report was generated on **Mon Feb 23 16:36:39 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:validation-context-tests:2.0.0-SNAPSHOT.394` +# Dependencies of `io.spine.tools:validation-context-tests:2.0.0-SNAPSHOT.395` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.20.0. @@ -1731,28 +1731,28 @@ This report was generated on **Fri Feb 13 15:18:11 WET 2026** using The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Fri Feb 13 15:18:10 WET 2026** using +This report was generated on **Mon Feb 23 16:36:38 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:validation-docs:2.0.0-SNAPSHOT.394` +# Dependencies of `io.spine.tools:validation-docs:2.0.0-SNAPSHOT.395` ## Runtime ## Compile, tests, and tooling The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Feb 12 20:41:43 WET 2026** using +This report was generated on **Mon Feb 23 16:15:05 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:validation-gradle-plugin:2.0.0-SNAPSHOT.394` +# Dependencies of `io.spine.tools:validation-gradle-plugin:2.0.0-SNAPSHOT.395` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.20.0. @@ -2841,14 +2841,14 @@ This report was generated on **Thu Feb 12 20:41:43 WET 2026** using The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Fri Feb 13 15:18:11 WET 2026** using +This report was generated on **Mon Feb 23 16:36:38 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:validation-java:2.0.0-SNAPSHOT.394` +# Dependencies of `io.spine.tools:validation-java:2.0.0-SNAPSHOT.395` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.20.0. @@ -3935,14 +3935,14 @@ This report was generated on **Fri Feb 13 15:18:11 WET 2026** using The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Fri Feb 13 15:18:11 WET 2026** using +This report was generated on **Mon Feb 23 16:36:38 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:validation-java-bundle:2.0.0-SNAPSHOT.394` +# Dependencies of `io.spine.tools:validation-java-bundle:2.0.0-SNAPSHOT.395` ## Runtime 1. **Group** : com.google.auto.service. **Name** : auto-service-annotations. **Version** : 1.1.1. @@ -4005,14 +4005,14 @@ This report was generated on **Fri Feb 13 15:18:11 WET 2026** using The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Fri Feb 13 15:18:09 WET 2026** using +This report was generated on **Mon Feb 23 16:36:37 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine:validation-jvm-runtime:2.0.0-SNAPSHOT.394` +# Dependencies of `io.spine:validation-jvm-runtime:2.0.0-SNAPSHOT.395` ## Runtime 1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2. @@ -4845,14 +4845,14 @@ This report was generated on **Fri Feb 13 15:18:09 WET 2026** using The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Fri Feb 13 15:18:11 WET 2026** using +This report was generated on **Mon Feb 23 16:36:38 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:validation-ksp:2.0.0-SNAPSHOT.394` +# Dependencies of `io.spine.tools:validation-ksp:2.0.0-SNAPSHOT.395` ## Runtime 1. **Group** : com.google.auto.service. **Name** : auto-service-annotations. **Version** : 1.1.1. @@ -5781,14 +5781,14 @@ This report was generated on **Fri Feb 13 15:18:11 WET 2026** using The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Fri Feb 13 15:18:11 WET 2026** using +This report was generated on **Mon Feb 23 16:36:38 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:validation-consumer:2.0.0-SNAPSHOT.394` +# Dependencies of `io.spine.tools:validation-consumer:2.0.0-SNAPSHOT.395` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.20.0. @@ -6379,14 +6379,14 @@ This report was generated on **Fri Feb 13 15:18:11 WET 2026** using The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Fri Feb 13 15:18:10 WET 2026** using +This report was generated on **Mon Feb 23 16:36:38 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:validation-consumer-dependency:2.0.0-SNAPSHOT.394` +# Dependencies of `io.spine.tools:validation-consumer-dependency:2.0.0-SNAPSHOT.395` ## Runtime 1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2. @@ -6897,14 +6897,14 @@ This report was generated on **Fri Feb 13 15:18:10 WET 2026** using The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Fri Feb 13 15:18:10 WET 2026** using +This report was generated on **Mon Feb 23 16:36:38 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:validation-extensions:2.0.0-SNAPSHOT.394` +# Dependencies of `io.spine.tools:validation-extensions:2.0.0-SNAPSHOT.395` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.20.0. @@ -7588,14 +7588,14 @@ This report was generated on **Fri Feb 13 15:18:10 WET 2026** using The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Fri Feb 13 15:18:10 WET 2026** using +This report was generated on **Mon Feb 23 16:36:38 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:validation-runtime:2.0.0-SNAPSHOT.394` +# Dependencies of `io.spine.tools:validation-runtime:2.0.0-SNAPSHOT.395` ## Runtime 1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2. @@ -8217,14 +8217,14 @@ This report was generated on **Fri Feb 13 15:18:10 WET 2026** using The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Fri Feb 13 15:18:10 WET 2026** using +This report was generated on **Mon Feb 23 16:36:38 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:validation-validating:2.0.0-SNAPSHOT.394` +# Dependencies of `io.spine.tools:validation-validating:2.0.0-SNAPSHOT.395` ## Runtime 1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2. @@ -8889,14 +8889,14 @@ This report was generated on **Fri Feb 13 15:18:10 WET 2026** using The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Fri Feb 13 15:18:11 WET 2026** using +This report was generated on **Mon Feb 23 16:36:38 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:validation-validator:2.0.0-SNAPSHOT.394` +# Dependencies of `io.spine.tools:validation-validator:2.0.0-SNAPSHOT.395` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.20.0. @@ -9647,14 +9647,14 @@ This report was generated on **Fri Feb 13 15:18:11 WET 2026** using The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Fri Feb 13 15:18:10 WET 2026** using +This report was generated on **Mon Feb 23 16:36:38 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:validation-validator-dependency:2.0.0-SNAPSHOT.394` +# Dependencies of `io.spine.tools:validation-validator-dependency:2.0.0-SNAPSHOT.395` ## Runtime 1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2. @@ -9924,14 +9924,14 @@ This report was generated on **Fri Feb 13 15:18:10 WET 2026** using The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Fri Feb 13 15:18:10 WET 2026** using +This report was generated on **Mon Feb 23 16:36:38 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:validation-vanilla:2.0.0-SNAPSHOT.394` +# Dependencies of `io.spine.tools:validation-vanilla:2.0.0-SNAPSHOT.395` ## Runtime 1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2. @@ -10282,6 +10282,6 @@ This report was generated on **Fri Feb 13 15:18:10 WET 2026** using The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Fri Feb 13 15:18:10 WET 2026** using +This report was generated on **Mon Feb 23 16:36:38 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). \ No newline at end of file diff --git a/docs/_code/code-common.gradle.kts b/docs/_code/code-common.gradle.kts deleted file mode 100644 index 775040246..000000000 --- a/docs/_code/code-common.gradle.kts +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2026, 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 - * - * https://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. - */ - -group = "io.spine.validation.docs" - -// Take the version from the main code project. -// The path to the version script is relevant to a directory _under_ the `_code`, -// not to this script because it is applied from the example projects. -apply(from = "../../../version.gradle.kts") -version = extra["validationVersion"]!! diff --git a/docs/_code/first-model-with-framework/build.gradle.kts b/docs/_code/first-model-with-framework/build.gradle.kts deleted file mode 100644 index 2cbfdc62c..000000000 --- a/docs/_code/first-model-with-framework/build.gradle.kts +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2026, 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 - * - * https://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. - */ - -import java.net.URI - -plugins { - `java-library` - kotlin("jvm") version "2.2.21" - id("io.spine.core-jvm") version "2.0.0-SNAPSHOT.052" -} - -apply(from = "../code-common.gradle.kts") - -repositories { - mavenLocal() - mavenCentral() - maven { - url = URI("https://europe-maven.pkg.dev/spine-event-engine/snapshots") - } - maven { - url = URI("https://europe-maven.pkg.dev/spine-event-engine/releases") - } -} - -dependencies { - // Temporarily add the dependency on Validation JVM Runtime explicitly. - // We need this until CoreJvm Compiler migrates to the Validation version - // `2.0.0-SNAPSHOT.394` or later. This version exposes Spine Base as the `api` - // (rather than `implementation`) dependency of the runtime artifact. - // Before this version, this dependency comes as the `implementation` and as such - // is not visible for the Java compiler. - implementation("io.spine:spine-validation-jvm-runtime:2.0.0-SNAPSHOT.394") - testImplementation(kotlin("test")) -} - -kotlin { - jvmToolchain(17) -} - -tasks.test { - useJUnitPlatform() -} - -tasks.register("buildAll") { - dependsOn(tasks.clean) - dependsOn(tasks.build) -} - -tasks.named("build").configure { - mustRunAfter("clean") -} diff --git a/docs/_code/first-model-with-framework/gradle.properties b/docs/_code/first-model-with-framework/gradle.properties deleted file mode 120000 index 591a8b3f8..000000000 --- a/docs/_code/first-model-with-framework/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -../../../gradle.properties \ No newline at end of file diff --git a/docs/_code/first-model-with-framework/gradlew b/docs/_code/first-model-with-framework/gradlew deleted file mode 120000 index ab9334b00..000000000 --- a/docs/_code/first-model-with-framework/gradlew +++ /dev/null @@ -1 +0,0 @@ -../../../gradlew \ No newline at end of file diff --git a/docs/_code/first-model-with-framework/gradlew.bat b/docs/_code/first-model-with-framework/gradlew.bat deleted file mode 120000 index b284c3099..000000000 --- a/docs/_code/first-model-with-framework/gradlew.bat +++ /dev/null @@ -1 +0,0 @@ -../../../gradlew.bat \ No newline at end of file diff --git a/docs/_code/first-model-with-framework/settings.gradle.kts b/docs/_code/first-model-with-framework/settings.gradle.kts deleted file mode 100644 index 65f27dc6e..000000000 --- a/docs/_code/first-model-with-framework/settings.gradle.kts +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2026, 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 - * - * https://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. - */ - -rootProject.name = "first-model-with-framework" - -pluginManagement { - repositories { - mavenLocal() - gradlePluginPortal() - maven { - url = java.net.URI("https://europe-maven.pkg.dev/spine-event-engine/snapshots") - } - maven { - url = java.net.URI("https://europe-maven.pkg.dev/spine-event-engine/releases") - } - } -} diff --git a/docs/_code/first-model-with-framework/src b/docs/_code/first-model-with-framework/src deleted file mode 120000 index 89e7e6d43..000000000 --- a/docs/_code/first-model-with-framework/src +++ /dev/null @@ -1 +0,0 @@ -../first-model/src \ No newline at end of file diff --git a/docs/_code/first-model/build.gradle.kts b/docs/_code/first-model/build.gradle.kts deleted file mode 100644 index 1c1030bcc..000000000 --- a/docs/_code/first-model/build.gradle.kts +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2026, 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 - * - * https://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. - */ - -import java.net.URI - -plugins { - `java-library` - kotlin("jvm") version "2.2.21" - id("io.spine.validation") version "2.0.0-SNAPSHOT.394" -} - -apply(from = "../code-common.gradle.kts") - -repositories { - mavenLocal() - mavenCentral() - maven { - url = URI("https://europe-maven.pkg.dev/spine-event-engine/snapshots") - } - maven { - url = URI("https://europe-maven.pkg.dev/spine-event-engine/releases") - } -} - -dependencies { - testImplementation(kotlin("test")) -} - -kotlin { - jvmToolchain(17) -} - -tasks.test { - useJUnitPlatform() -} - -tasks.register("buildAll") { - dependsOn(tasks.clean) - dependsOn(tasks.build) -} - -tasks.named("build").configure { - mustRunAfter("clean") -} diff --git a/docs/_code/first-model/gradle.properties b/docs/_code/first-model/gradle.properties deleted file mode 120000 index 591a8b3f8..000000000 --- a/docs/_code/first-model/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -../../../gradle.properties \ No newline at end of file diff --git a/docs/_code/first-model/gradlew b/docs/_code/first-model/gradlew deleted file mode 120000 index ab9334b00..000000000 --- a/docs/_code/first-model/gradlew +++ /dev/null @@ -1 +0,0 @@ -../../../gradlew \ No newline at end of file diff --git a/docs/_code/first-model/gradlew.bat b/docs/_code/first-model/gradlew.bat deleted file mode 120000 index b284c3099..000000000 --- a/docs/_code/first-model/gradlew.bat +++ /dev/null @@ -1 +0,0 @@ -../../../gradlew.bat \ No newline at end of file diff --git a/docs/_code/first-model/settings.gradle.kts b/docs/_code/first-model/settings.gradle.kts deleted file mode 100644 index de70c06cd..000000000 --- a/docs/_code/first-model/settings.gradle.kts +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2026, 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 - * - * https://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. - */ - -rootProject.name = "first-model" - -pluginManagement { - repositories { - mavenLocal() - gradlePluginPortal() - maven { - url = java.net.URI("https://europe-maven.pkg.dev/spine-event-engine/snapshots") - } - maven { - url = java.net.URI("https://europe-maven.pkg.dev/spine-event-engine/releases") - } - } -} diff --git a/docs/_code/first-model/src/main/proto/spine/validation/docs/first_model/bank_card.proto b/docs/_code/first-model/src/main/proto/spine/validation/docs/first_model/bank_card.proto deleted file mode 100644 index fa1259b8e..000000000 --- a/docs/_code/first-model/src/main/proto/spine/validation/docs/first_model/bank_card.proto +++ /dev/null @@ -1,41 +0,0 @@ -syntax = "proto3"; - -package spine.validation.docs.first_model; - -import "spine/options.proto"; - -option (type_url_prefix) = "type.spine.io"; -option java_package = "io.spine.validation.docs.firstmodel"; -option java_multiple_files = true; - -// Provides bank card information with validation rules. -// -// The digits of the card are simplified for the sake of the example. -// -message BankCard { - - // The digits of the card number. - // - // Must be present and match a 16-digit card number formatted as four - // groups of four digits separated by spaces (for example, "1234 5678 1234 5678"). - // - string digits = 1 [ - (required) = true, - (pattern).regex = "^\\d{4}(?: \\d{4}){3}" - ]; - - // The name of the card owner. - // - // Must be present, contain at least 4 characters, start with a Latin letter, - // and have exactly one space between words. - // - string owner = 2 [ - (required) = true, - (pattern).regex = "^(?=.{4,})[A-Z][A-Za-z]*(?: [A-Za-z]+)+$" - ]; - - // All tags must be unique. Tags are optional. - repeated string tags = 3 [ - (distinct) = true - ]; -} diff --git a/docs/_code/first-model/src/test/java/io/spine/validation/docs/firstmodel/BankCardTest.java b/docs/_code/first-model/src/test/java/io/spine/validation/docs/firstmodel/BankCardTest.java deleted file mode 100644 index 5acc4dd01..000000000 --- a/docs/_code/first-model/src/test/java/io/spine/validation/docs/firstmodel/BankCardTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2026, 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 - * - * https://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.validation.docs.firstmodel; - -import io.spine.validation.ValidationException; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.junit.jupiter.api.Assertions.assertThrows; - -@DisplayName("`BankCard` should") -class BankCardTest { - - @Test - @DisplayName("throw `ValidationException` if digits are invalid") - void invalidDigits() { - assertThrows(ValidationException.class, () -> - BankCard.newBuilder() - .setDigits("invalid") - .setOwner("ALEX SMITH") - .build() - ); - } - - @Test - @DisplayName("throw `ValidationException` if owner is invalid") - void invalidOwner() { - assertThrows(ValidationException.class, () -> - BankCard.newBuilder() - .setDigits("1234 5678 1234 5678") - .setOwner("Al") - .build() - ); - } - - @Test - @DisplayName("throw `ValidationException` if tags are not distinct") - void duplicateTags() { - assertThrows(ValidationException.class, () -> - BankCard.newBuilder() - .setDigits("1234 5678 1234 5678") - .setOwner("ALEX SMITH") - .addTags("personal") - .addTags("personal") - .build() - ); - } - - @Test - @DisplayName("be built if all fields are valid") - void validCard() { - assertDoesNotThrow(() -> - BankCard.newBuilder() - .setDigits("1234 5678 1234 5678") - .setOwner("ALEX SMITH") - .addTags("personal") - .addTags("travel") - .build() - ); - } - - @Test - @DisplayName("allow multiple words in the owner name") - void multipleWordsOwner() { - assertDoesNotThrow(() -> - BankCard.newBuilder() - .setDigits("1234 5678 1234 5678") - .setOwner("John Jacob Jingleheimer Schmidt") - .build() - ); - } -} diff --git a/docs/_code/first-model/src/test/kotlin/io/spine/validation/docs/firstmodel/BankCardKtTest.kt b/docs/_code/first-model/src/test/kotlin/io/spine/validation/docs/firstmodel/BankCardKtTest.kt deleted file mode 100644 index 1b16ca130..000000000 --- a/docs/_code/first-model/src/test/kotlin/io/spine/validation/docs/firstmodel/BankCardKtTest.kt +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2026, 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 - * - * https://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.validation.docs.firstmodel - -import io.spine.validation.ValidationException -import org.junit.jupiter.api.DisplayName -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertThrows -import org.junit.jupiter.api.Assertions.assertDoesNotThrow - -@DisplayName("`BankCard` in Kotlin should") -class BankCardKtTest { - - @Test - @DisplayName("throw `ValidationException` if digits are invalid") - fun invalidDigits() { - assertThrows { - bankCard { - digits = "invalid" - owner = "ALEX SMITH" - } - } - } - - @Test - @DisplayName("throw `ValidationException` if owner is invalid") - fun invalidOwner() { - assertThrows { - bankCard { - digits = "1234 5678 1234 5678" - owner = "Al" - } - } - } - - @Test - @DisplayName("throw `ValidationException` if tags are not distinct") - fun duplicateTags() { - assertThrows { - bankCard { - digits = "1234 5678 1234 5678" - owner = "ALEX SMITH" - tags.add("personal") - tags.add("personal") - } - } - } - - @Test - @DisplayName("be built if all fields are valid") - fun validCard() { - assertDoesNotThrow { - bankCard { - digits = "1234 5678 1234 5678" - owner = "ALEX SMITH" - tags.add("personal") - tags.add("travel") - } - } - } - - @Test - @DisplayName("allow multiple words in the owner name") - fun multipleWordsOwner() { - assertDoesNotThrow { - bankCard { - digits = "1234 5678 1234 5678" - owner = "John Jacob Jingleheimer Schmidt" - } - } - } -} diff --git a/docs/_examples b/docs/_examples new file mode 160000 index 000000000..8c32da4ed --- /dev/null +++ b/docs/_examples @@ -0,0 +1 @@ +Subproject commit 8c32da4ed2c1ea4a04e391f3517ccb6625a51fa9 diff --git a/docs/_script/embed-code b/docs/_script/embed-code index 2667b966d..fdaf56a78 100755 --- a/docs/_script/embed-code +++ b/docs/_script/embed-code @@ -37,7 +37,7 @@ elif [ -f ${BASH_RC} ]; then . ${BASH_RC} fi -# Ensure `docs/_code` files are fetched. +# Ensure `docs/_examples` files are fetched. git submodule update --remote --merge --recursive # Navigate to the folder with embed-code binaries. diff --git a/docs/_settings/embed-code.yml b/docs/_settings/embed-code.yml index 3f442ea16..170b02456 100644 --- a/docs/_settings/embed-code.yml +++ b/docs/_settings/embed-code.yml @@ -1,5 +1,5 @@ -code-path: "../_code" +code-path: "../_examples" docs-path: "../content/docs/" embed-mappings: - - code-path: "../_code" + - code-path: "../_examples" docs-path: "../content/docs/" diff --git a/docs/build.gradle.kts b/docs/build.gradle.kts index dfa0e29c9..5d8c984a3 100644 --- a/docs/build.gradle.kts +++ b/docs/build.gradle.kts @@ -35,7 +35,7 @@ LicenseReporter.generateReportIn(project) val updateValidationPluginVersion = tasks.register("updateValidationPluginVersion") { - directory.set(file("$projectDir/_code/")) + directory.set(file("$projectDir/_examples/")) val validationVersion: String by rootProject.extra version.set(validationVersion) pluginId.set("io.spine.validation") @@ -43,7 +43,7 @@ val updateValidationPluginVersion = } val updateCoreJvmPluginVersion = tasks.register("updateCoreJvmPluginVersion") { - directory.set(file("$projectDir/_code/")) + directory.set(file("$projectDir/_examples/")) version.set(CoreJvmCompiler.version) pluginId.set("io.spine.core-jvm") kotlinVersion.set(Kotlin.version) @@ -100,26 +100,21 @@ val publishAllToMavenLocal by tasks.registering { ) } -val buildFirstModel by tasks.registering(RunGradle::class) { - directory = "$projectDir/_code/first-model" - task("buildAll") - dependsOn(publishAllToMavenLocal) - dependsOn(updateValidationPluginVersion) -} +// The root directory for the example projects. +val examplesDir = "$projectDir/_examples" -val buildFirstModelWithFramework by tasks.registering(RunGradle::class) { - directory = "$projectDir/_code/first-model-with-framework" - task("buildAll") - dependsOn(publishAllToMavenLocal) - dependsOn(updateValidationPluginVersion) -} +// The conventional name for the tasks that build "everything" for the documentation. +// E.g., the example projects these tasks do `clean build`. +val buildAll = "buildAll" -val buildExamples by tasks.registering { +val buildExamples by tasks.registering(RunGradle::class) { + directory = examplesDir + task(buildAll) + dependsOn(publishAllToMavenLocal) dependsOn(updatePluginVersions) - dependsOn(buildFirstModel, buildFirstModelWithFramework) } -tasks.register("buildAll") { +tasks.register(buildAll) { dependsOn(publishAllToMavenLocal) dependsOn(buildExamples) } diff --git a/docs/content/docs/validation/01-getting-started/_index.md b/docs/content/docs/validation/01-getting-started/_index.md index 8e9279f29..4d817a75d 100644 --- a/docs/content/docs/validation/01-getting-started/_index.md +++ b/docs/content/docs/validation/01-getting-started/_index.md @@ -47,5 +47,4 @@ the code produced by `protoc`. ## What’s next - [Adding Validation to your build](adding-to-build.md) -- [Your First Validated Model](first-model.md) -- [Validation Workflow](workflow.md) +- [Your first validated model](first-model.md) diff --git a/docs/content/docs/validation/01-getting-started/adding-to-build.md b/docs/content/docs/validation/01-getting-started/adding-to-build.md index 94618cb62..fa17d4d62 100644 --- a/docs/content/docs/validation/01-getting-started/adding-to-build.md +++ b/docs/content/docs/validation/01-getting-started/adding-to-build.md @@ -1,58 +1,70 @@ # Adding Validation to a Gradle build +## Adding Spine-specific Gradle plugin repositories + + +```kotlin +pluginManagement { + repositories { + mavenLocal() + gradlePluginPortal() + maven("https://europe-maven.pkg.dev/spine-event-engine/snapshots") + maven("https://europe-maven.pkg.dev/spine-event-engine/releases") + } +} +``` +The repositories at https://europe-maven.pkg.dev are needed for obtaining the versions of +Spine tools and libraries that are not yet published to the Gradle Plugin Portal or Maven Central. + +## Adding Gradle plugins to the build + Spine Validation can be added to a JVM project in two different ways. Choose the setup that matches your project: - Standalone use in any Protobuf-based project. -- As part of a Spine-based project that already uses the CoreJvm toolchain. +- As part of a Spine-based project that uses the CoreJvm toolchain. Both modes integrate the Validation compiler into the build and add the runtime library. - -## Mode 1: standalone via Validation Gradle plugin +### Mode 1: standalone via Validation Gradle plugin Use this mode if you want to run Validation without the rest of Spine. -1) Add the Validation plugin to the build. +Add the Validation plugin to the build. + ```kotlin plugins { - id("io.spine.validation") version "" + module + id("io.spine.validation") version "2.0.0-SNAPSHOT.395" } ``` -2) Make sure your repositories include Spine artifacts (the same repositories you use - for other Spine tools and libraries). - -3) Optional: control Validation generation explicitly. - -```kotlin -spine { - validation { - enabled.set(true) // `true` by default - } -} -``` +> ##### What is the `module` plugin? +> The plugin `module` in the snippet above refers to the name of the script plugin +> `buildSrc/src/kotlin/module.gradle.kts` which provides common configuration for +> the subprojects of the multi-module examples project. +> For more details on this, clone the [Validation examples repository][validation-examples]. The plugin wires Validation into Spine Compiler, adds the Validation Java codegen bundle, and brings in the JVM runtime dependency automatically. -## Mode 2: Spine-based project via CoreJvm Gradle plugin +### Mode 2: Spine-based project via CoreJvm Gradle plugin -If your project is base on the Spine CoreJvm library, apply the CoreJvm Gradle plugin instead of +If your project is based on the Spine CoreJvm library, apply the CoreJvm Gradle plugin instead of adding Validation directly. CoreJvm brings in the Validation Gradle plugin for you. + ```kotlin plugins { - id("io.spine.core-jvm") version "" + module + id("io.spine.core-jvm") version "2.0.0-SNAPSHOT.053" } ``` -Validation is available right away, and you can configure it using the same `validation` -extension if needed. - - ## Next step Continue with [Your first validated model](first-model.md). + +[validation-examples]: https://github.com/spine-examples/hello-validation diff --git a/docs/content/docs/validation/01-getting-started/first-model.md b/docs/content/docs/validation/01-getting-started/first-model.md index ac7230f2e..4a502c522 100644 --- a/docs/content/docs/validation/01-getting-started/first-model.md +++ b/docs/content/docs/validation/01-getting-started/first-model.md @@ -8,16 +8,8 @@ The validation options come from `spine/options.proto` and include constraints l ## 1) Configure the project -To use the Validation library, add the `io.spine.validation` plugin to your `build.gradle.kts` file: - - -```kotlin -plugins { - `java-library` - kotlin("jvm") version "2.2.21" - id("io.spine.validation") version "2.0.0-SNAPSHOT.394" -} -``` +First, make sure your project is configured to use the Validation library. +See [Adding Validation to a Gradle build](adding-to-build.md) for detailed instructions. ## 2) Define a validated message @@ -98,31 +90,59 @@ The code will be generated under the `generated` directory of your project. Validation runs on `build()` and can be triggered manually with `validate()`. + ```java -var card = BankCard.newBuilder() - .setDigits("invalid") - .setOwner("Al") - .build(); // Throws `ValidationException`. +assertThrows(ValidationException.class, () -> + BankCard.newBuilder() + .setDigits("invalid") + .setOwner("ALEX SMITH") + .build() +); ``` + ```kotlin -val card = bankCard { - digits = "invalid" - owner = "Al" -} // Throws `ValidationException`. +shouldThrow { + bankCard { + digits = "invalid" + owner = "ALEX SMITH" + } +} ``` To validate without throwing, use `validate()` on a built message: + ```java var card = BankCard.newBuilder() - .setDigits("invalid") - .buildPartial(); - + .setOwner("ALEX SMITH") + .setDigits("wrong number") + .buildPartial(); var error = card.validate(); -error.ifPresent(err -> System.out.println(err.getMessage())); +assertThat(error).isPresent(); + +var violation = error.get().getConstraintViolation(0); +var formatted = TemplateStrings.format(violation.getMessage()); + +assertThat(formatted).contains("digits"); +assertThat(formatted).contains("wrong number"); ``` - + + +```kotlin +val card = BankCard.newBuilder() + .setOwner("ALEX SMITH") + .setDigits("wrong number") + .buildPartial() // There is no Kotlin DSL for this. +val error = card.validate() +error.shouldBePresent() + +val violation = error.get().constraintViolationList[0] +val formatted = violation.message.format() + +formatted shouldContain "digits" +formatted shouldContain "wrong number" +``` ## What’s next diff --git a/gradle-plugin/src/main/kotlin/io/spine/tools/validation/gradle/ValidationGradlePlugin.kt b/gradle-plugin/src/main/kotlin/io/spine/tools/validation/gradle/ValidationGradlePlugin.kt index 4f35440b2..1ca4baca8 100644 --- a/gradle-plugin/src/main/kotlin/io/spine/tools/validation/gradle/ValidationGradlePlugin.kt +++ b/gradle-plugin/src/main/kotlin/io/spine/tools/validation/gradle/ValidationGradlePlugin.kt @@ -30,7 +30,6 @@ import com.google.protobuf.gradle.ProtobufPlugin import io.spine.tools.compiler.gradle.api.addUserClasspathDependency import io.spine.tools.compiler.gradle.api.compilerSettings import io.spine.tools.compiler.gradle.plugin.Extension -import io.spine.tools.compiler.gradle.plugin.Plugin as CompilerGradlePlugin import io.spine.tools.gradle.DslSpec import io.spine.tools.gradle.lib.LibraryPlugin import io.spine.tools.gradle.lib.spineExtension @@ -38,6 +37,7 @@ import io.spine.tools.meta.MavenArtifact import org.gradle.api.Project import org.gradle.api.artifacts.Dependency import org.gradle.kotlin.dsl.apply +import io.spine.tools.compiler.gradle.plugin.Plugin as CompilerGradlePlugin /** * Gradle plugin that configures the Spine Compiler to run the Validation Compiler. @@ -55,31 +55,33 @@ public class ValidationGradlePlugin : LibraryPlugin( // Apply the Compiler Gradle Plugin so that we can manipulate the compiler settings. // We do not want the user to add it manually either. project.apply() - val javaBundle = ValidationSdk.javaCodegenBundle - project.run { - addUserClasspathDependency(javaBundle) - afterEvaluate { - // Add the Validation Java Compiler only if `spine/validation/enabled` is true. - if (validationExtension.enabled.get()) { - (compilerSettings as Extension).run { - // Put the Validation Java Compiler first in the list of the plugins. - // Other plugins may rely on the validation code. - val ordered = listOf(ValidationSdk.javaCompilerPlugin) + plugins.get() - plugins.set(ordered) - } - } + project.configureValidation() + } +} + +private fun Project.configureValidation() { + val javaBundle = ValidationSdk.javaCodegenBundle + addUserClasspathDependency(javaBundle) + afterEvaluate { + // Add the Validation Java Compiler only if `spine/validation/enabled` is true. + if (validationExtension.enabled.get()) { + (compilerSettings as Extension).run { + // Put the Validation Java Compiler first in the list of the plugins. + // Other plugins may rely on the validation code. + val ordered = listOf(ValidationSdk.javaCompilerPlugin) + plugins.get() + plugins.set(ordered) } - // We add the dependency on runtime anyway for the following reasons: - // 1. We do not want users to change their Gradle build files when they turn on or off - // code generation for the validation code. - // - // 2. We have run-time validation rules that are going to be used in parallel with - // the generated code. This includes current and new implementation for validation - // rules for the already existing generated Protobuf code. - // - addDependency("implementation", ValidationSdk.jvmRuntime) } } + // We add the dependency on runtime anyway for the following reasons: + // 1. We do not want users to change their Gradle build files when they turn on or off + // code generation for the validation code. + // + // 2. We have run-time validation rules that are going to be used in parallel with + // the generated code. This includes current and new implementation for validation + // rules for the already existing generated Protobuf code. + // + addDependency("implementation", ValidationSdk.jvmRuntime) } /** diff --git a/pom.xml b/pom.xml index 7fcb99b69..2ae9cabf3 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ all modules and does not describe the project structure per-subproject. --> io.spine.tools validation -2.0.0-SNAPSHOT.394 +2.0.0-SNAPSHOT.395 2015 @@ -68,37 +68,37 @@ all modules and does not describe the project structure per-subproject. io.spine spine-validation-jvm-runtime - 2.0.0-SNAPSHOT.393 + 2.0.0-SNAPSHOT.394 compile io.spine.tools compiler-backend - 2.0.0-SNAPSHOT.038 + 2.0.0-SNAPSHOT.039 compile io.spine.tools compiler-gradle-api - 2.0.0-SNAPSHOT.038 + 2.0.0-SNAPSHOT.039 compile io.spine.tools compiler-gradle-plugin - 2.0.0-SNAPSHOT.038 + 2.0.0-SNAPSHOT.039 compile io.spine.tools compiler-jvm - 2.0.0-SNAPSHOT.038 + 2.0.0-SNAPSHOT.039 compile io.spine.tools jvm-tools - 2.0.0-SNAPSHOT.371 + 2.0.0-SNAPSHOT.372 compile @@ -176,13 +176,13 @@ all modules and does not describe the project structure per-subproject. io.spine.tools compiler-api - 2.0.0-SNAPSHOT.038 + 2.0.0-SNAPSHOT.039 test io.spine.tools compiler-testlib - 2.0.0-SNAPSHOT.038 + 2.0.0-SNAPSHOT.039 test @@ -277,22 +277,22 @@ all modules and does not describe the project structure per-subproject. io.spine.tools compiler-cli-all - 2.0.0-SNAPSHOT.038 + 2.0.0-SNAPSHOT.039 io.spine.tools compiler-protoc-plugin - 2.0.0-SNAPSHOT.038 + 2.0.0-SNAPSHOT.039 io.spine.tools core-jvm-gradle-plugins - 2.0.0-SNAPSHOT.052 + 2.0.0-SNAPSHOT.053 io.spine.tools core-jvm-routing - 2.0.0-SNAPSHOT.052 + 2.0.0-SNAPSHOT.053 io.spine.tools @@ -307,7 +307,7 @@ all modules and does not describe the project structure per-subproject. io.spine.tools validation-java-bundle - 2.0.0-SNAPSHOT.393 + 2.0.0-SNAPSHOT.394 net.sourceforge.pmd diff --git a/version.gradle.kts b/version.gradle.kts index bae585a6c..5254c065e 100644 --- a/version.gradle.kts +++ b/version.gradle.kts @@ -29,4 +29,4 @@ * * For Spine-based dependencies please see [io.spine.dependency.local.Spine]. */ -val validationVersion by extra("2.0.0-SNAPSHOT.394") +val validationVersion by extra("2.0.0-SNAPSHOT.395")