From b6476d39d6281e799fac3ebad18adde45c436c76 Mon Sep 17 00:00:00 2001 From: "oleg.melnik" Date: Thu, 11 Jul 2024 14:03:31 +0300 Subject: [PATCH 01/13] Migrate to the latest version of ProtoData. --- .../io/spine/internal/dependency/ProtoData.kt | 2 +- .../BuilderBeforeReturnInsertionPoint.kt | 20 +++++++++++++------ .../plugin/BuilderBeforeReturnRenderer.kt | 11 +++++++--- .../hello/plugin/BuilderExtensionGenerator.kt | 6 ++++-- .../plugin/ValidateSizeOptionRenderer.kt | 2 +- version.gradle.kts | 2 +- 6 files changed, 29 insertions(+), 14 deletions(-) diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/ProtoData.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/ProtoData.kt index 442f3ca..fe0f970 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/ProtoData.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/ProtoData.kt @@ -62,7 +62,7 @@ object ProtoData { /** * The version of ProtoData dependencies. */ - const val version: String = "0.20.7" + const val version: String = "0.50.0" const val pluginLib: String = "$group:gradle-plugin:$version" diff --git a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderBeforeReturnInsertionPoint.kt b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderBeforeReturnInsertionPoint.kt index c884a3b..bae9472 100644 --- a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderBeforeReturnInsertionPoint.kt +++ b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderBeforeReturnInsertionPoint.kt @@ -56,13 +56,13 @@ public class BuilderBeforeReturnInsertionPoint : InsertionPoint { * taking into account the following: * * - The builder class is the nested within class of some `Message`. - * - The class of `Message` is the only top-level class in the passed + * - The class of `Message` is the only top-level class in the given * [text]. * * This implementation assumes that Proto file has its `java_multiple_files` * option set to `true`. */ - public override fun locate(text: Text): Set { + override fun locate(text: String): Set { val messageClass = parseMessageClass(text) val builderClass = loadBuilderClass(messageClass) val builderMethod = builderClass.getMethod("build") @@ -70,15 +70,23 @@ public class BuilderBeforeReturnInsertionPoint : InsertionPoint { return setOf(lineBeforeReturn) } + @Deprecated( + message = "Use `locate(String)` instead.", + replaceWith = ReplaceWith("locate(text.value)") + ) + override fun locate(text: Text): Set { + return locate(text.value) + } + /** * Returns the [TextCoordinates] that points to the line before * the `return` statement of the `build` method. */ private fun lineBeforeReturn( method: MethodSource<*>, - sourceCode: Text + sourceCode: String ): TextCoordinates { - val methodCode = sourceCode.value.substring( + val methodCode = sourceCode.substring( method.startPosition, method.endPosition ) val returnIndex = findReturnLine(methodCode) @@ -102,8 +110,8 @@ public class BuilderBeforeReturnInsertionPoint : InsertionPoint { /** * Parses a message class from the text provided. */ - private fun parseMessageClass(code: Text): JavaClassSource { - val result = Roaster.parse(JavaSource::class.java, code.value) + private fun parseMessageClass(code: String): JavaClassSource { + val result = Roaster.parse(JavaSource::class.java, code) check(result.isClass) { "No message class found." } return result as JavaClassSource } diff --git a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderBeforeReturnRenderer.kt b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderBeforeReturnRenderer.kt index fe9f7f1..11fee9a 100644 --- a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderBeforeReturnRenderer.kt +++ b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderBeforeReturnRenderer.kt @@ -47,20 +47,25 @@ public class BuilderBeforeReturnRenderer( if (!sources.outputRoot.endsWith("java")) { return } + sources.filter { builderValidationMethods.hasMethods(it.relativePath) - }.forEach(::insertValidationMethodsInvocation) + }.forEach { + insertValidationMethodsInvocation(it) + } } /** * Inserts validation method calls into the `build` method * of the message builder class. */ - private fun insertValidationMethodsInvocation(sourceFile: SourceFile) { + private fun insertValidationMethodsInvocation(sourceFile: SourceFile<*>) { val builder = sourceFile.at(BuilderBeforeReturnInsertionPoint()) .withExtraIndentation(2) builderValidationMethods.methods(sourceFile.relativePath) - .forEach(builder::add) + .forEach { + builder.add(it) + } } } diff --git a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderExtensionGenerator.kt b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderExtensionGenerator.kt index d6cbeea..d863c81 100644 --- a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderExtensionGenerator.kt +++ b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderExtensionGenerator.kt @@ -169,7 +169,9 @@ private fun ProtobufSourceFile.javaPackage(): String { } private fun ProtobufSourceFile.type(typeName: TypeName): MessageType { - val type = typeMap.values.find { it.name == typeName } + val type = typeMap.values.find { + it.name.simpleName == typeName.simpleName + } checkNotNull(type) { "Cannot find type '$typeName' in $file." } @@ -177,7 +179,7 @@ private fun ProtobufSourceFile.type(typeName: TypeName): MessageType { } private fun MessageType.field(fieldName: FieldName): Field { - val field = fieldList.find { it.name == fieldName } + val field = fieldList.find { it.name.value == fieldName.value } checkNotNull(field) { "Cannot find field '${fieldName.value}' in type '${typeName.value}'." } diff --git a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/ValidateSizeOptionRenderer.kt b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/ValidateSizeOptionRenderer.kt index d2fea8a..ff164a9 100644 --- a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/ValidateSizeOptionRenderer.kt +++ b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/ValidateSizeOptionRenderer.kt @@ -80,7 +80,7 @@ public class ValidateSizeOptionRenderer( * Returns the [ProtobufSourceFile] by the [File] provided. */ private fun findSourceFile(file: File): ProtobufSourceFile { - val sourceFile = select().all().find { + val sourceFile = select(ProtobufSourceFile::class.java).all().find { it.file.path == file.path } checkNotNull(sourceFile) { diff --git a/version.gradle.kts b/version.gradle.kts index b2fb41a..87a8883 100644 --- a/version.gradle.kts +++ b/version.gradle.kts @@ -30,4 +30,4 @@ * This version also used by integration tests, so if you chage the version, * please also update it in the [io.spine.internal.dependency.HelloProtoData]. */ -val helloProtoDataVersion: String by extra("0.20.7") +val helloProtoDataVersion: String by extra("0.50.0") From 0a93a70b9e65771b95934f6887847ff104475cbf Mon Sep 17 00:00:00 2001 From: "oleg.melnik" Date: Thu, 11 Jul 2024 19:22:45 +0300 Subject: [PATCH 02/13] Add debug logging in integration tests. --- gradle.properties | 2 +- .../protodata/hello/test/ApplySizeOptionPluginTest.kt | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 73c47a6..4ec318e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ # JVM memory settings for the Gradle build. -org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+UseParallelGC +#org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+UseParallelGC diff --git a/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/ApplySizeOptionPluginTest.kt b/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/ApplySizeOptionPluginTest.kt index caf4702..fb6ba12 100644 --- a/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/ApplySizeOptionPluginTest.kt +++ b/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/ApplySizeOptionPluginTest.kt @@ -157,8 +157,15 @@ class `ApplySizeOptionPlugin should` { } catch (_: UnexpectedBuildFailure) { } + val sdterrContent = stderr.toString() + val errorFound = sdterrContent.contains(expectedExceptionMessage) + + if (!errorFound) { + println(sdterrContent) + } + assertTrue( - stderr.toString().contains(expectedExceptionMessage), + errorFound, "The expected exception was not thrown." ) } From 123f580b33488fd6ed6c131094df8efd2f438362 Mon Sep 17 00:00:00 2001 From: "oleg.melnik" Date: Thu, 11 Jul 2024 19:33:12 +0300 Subject: [PATCH 03/13] Adjust build memory settings. --- gradle.properties | 2 +- .../examples/protodata/hello/test/ApplySizeOptionPluginTest.kt | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 4ec318e..85abfc4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ # JVM memory settings for the Gradle build. -#org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+UseParallelGC +org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=1024m -XX:+UseParallelGC diff --git a/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/ApplySizeOptionPluginTest.kt b/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/ApplySizeOptionPluginTest.kt index fb6ba12..1f205a3 100644 --- a/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/ApplySizeOptionPluginTest.kt +++ b/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/ApplySizeOptionPluginTest.kt @@ -161,7 +161,9 @@ class `ApplySizeOptionPlugin should` { val errorFound = sdterrContent.contains(expectedExceptionMessage) if (!errorFound) { + println("=========== StdErr of the separate Gradle build ============================") println(sdterrContent) + println("============================================================================") } assertTrue( From 07b9416603e4609a97bc4b0e147dc72f8826139a Mon Sep 17 00:00:00 2001 From: "oleg.melnik" Date: Thu, 11 Jul 2024 20:07:13 +0300 Subject: [PATCH 04/13] Adjust logging in integration tests. --- .../hello/test/ApplySizeOptionPluginTest.kt | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/ApplySizeOptionPluginTest.kt b/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/ApplySizeOptionPluginTest.kt index 1f205a3..d4c5459 100644 --- a/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/ApplySizeOptionPluginTest.kt +++ b/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/ApplySizeOptionPluginTest.kt @@ -30,7 +30,7 @@ import io.spine.tools.gradle.testing.GradleProject import io.spine.tools.mc.java.gradle.McJavaTaskName import org.gradle.testkit.runner.UnexpectedBuildFailure import org.gradle.testkit.runner.internal.DefaultGradleRunner -import org.junit.jupiter.api.Assertions.assertTrue +//import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Assertions.fail import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test @@ -158,17 +158,15 @@ class `ApplySizeOptionPlugin should` { } val sdterrContent = stderr.toString() - val errorFound = sdterrContent.contains(expectedExceptionMessage) + val errorFound = sdterrContent.contains("###$expectedExceptionMessage") if (!errorFound) { - println("=========== StdErr of the separate Gradle build ============================") - println(sdterrContent) - println("============================================================================") + fail(sdterrContent) } - assertTrue( +/* assertTrue( errorFound, "The expected exception was not thrown." - ) + )*/ } } From 0a87c9f1912fac4b1f566f605f32c9cad18794d9 Mon Sep 17 00:00:00 2001 From: "oleg.melnik" Date: Mon, 29 Jul 2024 16:42:50 +0300 Subject: [PATCH 05/13] Update build scripts and dependencies. --- build.gradle.kts | 4 +- buildSrc/src/main/kotlin/BuildExtensions.kt | 27 +- .../src/main/kotlin/DependencyResolution.kt | 5 + .../main/kotlin/build-proto-model.gradle.kts | 45 ++ .../main/kotlin/compile-protobuf.gradle.kts | 2 +- .../internal/dependency/HelloProtoData.kt | 2 +- .../io/spine/internal/dependency/KotlinX.kt | 42 ++ .../io/spine/internal/dependency/Ksp.kt | 40 ++ .../io/spine/internal/dependency/ProtoData.kt | 3 + .../io/spine/internal/dependency/ProtoTap.kt | 46 ++ .../io/spine/internal/dependency/Spine.kt | 12 +- .../internal/gradle/ProjectExtensions.kt | 28 ++ .../io/spine/internal/gradle/Repositories.kt | 235 +++++++++ .../gradle/protobuf/ProtoTaskExtensions.kt | 52 +- .../gradle/publish/CheckVersionIncrement.kt | 129 +++++ .../gradle/publish/CloudArtifactRegistry.kt | 78 +++ .../internal/gradle/publish/CloudRepo.kt | 68 +++ .../internal/gradle/publish/GitHubPackages.kt | 105 ++++ .../internal/gradle/publish/IncrementGuard.kt | 109 +++++ .../spine/internal/gradle/publish/JarDsl.kt | 167 +++++++ .../internal/gradle/publish/ProtoExts.kt | 89 ++++ .../internal/gradle/publish/Publications.kt | 234 +++++++++ .../internal/gradle/publish/PublishingExts.kt | 276 +++++++++++ .../gradle/publish/PublishingRepos.kt | 42 ++ .../gradle/publish/SpinePublishing.kt | 452 ++++++++++++++++++ .../hello/plugin/ApplySizeOptionPlugin.kt | 6 + .../protodata/hello/plugin/SizeOptionView.kt | 7 +- .../hello/plugin/SizeOptionViewRepository.kt | 1 + .../plugin/ValidateSizeOptionRenderer.kt | 12 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../hello/test/ApplySizeOptionPluginTest.kt | 14 +- .../resources/test-project/build.gradle.kts | 2 +- model/build.gradle.kts | 41 +- proto-extension/build.gradle.kts | 3 +- 34 files changed, 2341 insertions(+), 39 deletions(-) create mode 100644 buildSrc/src/main/kotlin/build-proto-model.gradle.kts create mode 100644 buildSrc/src/main/kotlin/io/spine/internal/dependency/KotlinX.kt create mode 100644 buildSrc/src/main/kotlin/io/spine/internal/dependency/Ksp.kt create mode 100644 buildSrc/src/main/kotlin/io/spine/internal/dependency/ProtoTap.kt create mode 100644 buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/CheckVersionIncrement.kt create mode 100644 buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/CloudArtifactRegistry.kt create mode 100644 buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/CloudRepo.kt create mode 100644 buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/GitHubPackages.kt create mode 100644 buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/IncrementGuard.kt create mode 100644 buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/JarDsl.kt create mode 100644 buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/ProtoExts.kt create mode 100644 buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/Publications.kt create mode 100644 buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/PublishingExts.kt create mode 100644 buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/PublishingRepos.kt create mode 100644 buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/SpinePublishing.kt diff --git a/build.gradle.kts b/build.gradle.kts index 74257f5..f9d9fec 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -46,6 +46,8 @@ buildscript { dependencies { classpath(io.spine.internal.dependency.Spine.McJava.pluginLib) + classpath(io.spine.internal.dependency.Protobuf.GradlePlugin.lib) + classpath(io.spine.internal.dependency.Kotlin.gradlePluginLib) } } @@ -54,7 +56,7 @@ plugins { id("net.ltgt.errorprone") id("detekt-code-analysis") id("com.google.protobuf") - id("io.spine.protodata") version "0.20.7" + id("io.spine.protodata") version "0.50.0" idea } diff --git a/buildSrc/src/main/kotlin/BuildExtensions.kt b/buildSrc/src/main/kotlin/BuildExtensions.kt index 57228a9..7ce2194 100644 --- a/buildSrc/src/main/kotlin/BuildExtensions.kt +++ b/buildSrc/src/main/kotlin/BuildExtensions.kt @@ -5,7 +5,7 @@ * 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 + * 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 @@ -30,7 +30,9 @@ import io.spine.internal.dependency.ErrorProne import io.spine.internal.dependency.GradleDoctor import io.spine.internal.dependency.Kotest import io.spine.internal.dependency.Kover +import io.spine.internal.dependency.Ksp import io.spine.internal.dependency.ProtoData +import io.spine.internal.dependency.ProtoTap import io.spine.internal.dependency.Protobuf import io.spine.internal.dependency.Spine import io.spine.internal.gradle.standardToSpineSdk @@ -63,9 +65,9 @@ fun ScriptHandlerScope.standardSpineSdkRepositories() { * * But for some plugins, it's impossible to apply them directly to a project. * For example, when a plugin is not published to Gradle Portal, it can only be - * applied with buildscript's classpath. Thus, it's needed to leave some freedom + * applied with the buildscript's classpath. Thus, it's needed to leave some freedom * upon how to apply them. In such cases, just a shortcut to a dependency object - * can be declared, without applying of the plugin in-place. + * can be declared without applying the plugin in-place. */ private const val ABOUT_DEPENDENCY_EXTENSIONS = "" @@ -81,8 +83,9 @@ val PluginDependenciesSpec.mcJava: Spine.McJava /** * Shortcut to [ProtoData] dependency object. * - * This plugin is in Gradle Portal. But when used in pair with [mcJava], it cannot be applied - * directly to a project. It is so, because [mcJava] uses [protoData] as its dependency. + * This plugin is published at Gradle Portal. But when used in a pair with [mcJava], + * it cannot be applied directly to a project. + * It is so, because [mcJava] uses [protoData] as its dependency. * And buildscript's classpath ends up with both of them. */ val PluginDependenciesSpec.protoData: ProtoData @@ -95,8 +98,8 @@ val PluginDependenciesSpec.protoData: ProtoData * declared in auto-generated `org.gradle.kotlin.dsl.PluginAccessors.kt` file. * It conflicts with our own declarations. * - * Declaring of top-level shortcuts eliminates need in applying plugins - * using fully-qualified name of dependency objects. + * Declaring of top-level shortcuts eliminates the need in applying plugins + * using fully qualified name of dependency objects. * * It is still possible to apply a plugin with a custom version, if needed. * Just declare a version again on the returned [PluginDependencySpec]. @@ -117,6 +120,9 @@ val PluginDependenciesSpec.errorprone: PluginDependencySpec val PluginDependenciesSpec.protobuf: PluginDependencySpec get() = id(Protobuf.GradlePlugin.id) +val PluginDependenciesSpec.prototap: PluginDependencySpec + get() = id(ProtoTap.gradlePluginId).version(ProtoTap.version) + val PluginDependenciesSpec.`gradle-doctor`: PluginDependencySpec get() = id(GradleDoctor.pluginId).version(GradleDoctor.version) @@ -128,13 +134,16 @@ val PluginDependenciesSpec.kotest: PluginDependencySpec val PluginDependenciesSpec.kover: PluginDependencySpec get() = id(Kover.id).version(Kover.version) +val PluginDependenciesSpec.ksp: PluginDependencySpec + get() = id(Ksp.id).version(Ksp.version) + /** * Configures the dependencies between third-party Gradle tasks * and those defined via ProtoData and Spine Model Compiler. * - * It is required in order to avoid warnings in build logs, detecting the undeclared + * It is required to avoid warnings in build logs, detecting the undeclared * usage of Spine-specific task output by other tasks, - * e.g. the output of `launchProtoData` is used by `compileKotlin`. + * e.g., the output of `launchProtoData` is used by `compileKotlin`. */ @Suppress("unused") fun Project.configureTaskDependencies() { diff --git a/buildSrc/src/main/kotlin/DependencyResolution.kt b/buildSrc/src/main/kotlin/DependencyResolution.kt index 0875661..70551a8 100644 --- a/buildSrc/src/main/kotlin/DependencyResolution.kt +++ b/buildSrc/src/main/kotlin/DependencyResolution.kt @@ -43,6 +43,7 @@ import io.spine.internal.dependency.Jackson import io.spine.internal.dependency.JavaDiffUtils import io.spine.internal.dependency.Kotest import io.spine.internal.dependency.Kotlin +import io.spine.internal.dependency.KotlinX import io.spine.internal.dependency.OpenTest4J import io.spine.internal.dependency.Protobuf import io.spine.internal.dependency.Slf4J @@ -78,6 +79,7 @@ fun doForceVersions(configurations: ConfigurationContainer) { spine.toolBase, spine.server, protoData.pluginLib, + protoData.lib, logging.lib, validation.runtime ) @@ -117,6 +119,9 @@ private fun ResolutionStrategy.forceProductionDependencies() { Kotlin.stdLibCommon, Kotlin.stdLibJdk7, Kotlin.stdLibJdk8, + KotlinX.Coroutines.core, + KotlinX.Coroutines.jvm, + KotlinX.Coroutines.jdk8, Protobuf.GradlePlugin.lib, Protobuf.libs, Slf4J.lib diff --git a/buildSrc/src/main/kotlin/build-proto-model.gradle.kts b/buildSrc/src/main/kotlin/build-proto-model.gradle.kts new file mode 100644 index 0000000..2215e25 --- /dev/null +++ b/buildSrc/src/main/kotlin/build-proto-model.gradle.kts @@ -0,0 +1,45 @@ +/* + * Copyright 2023, 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. + */ + +@file:Suppress("RemoveRedundantQualifierName") + +import io.spine.internal.dependency.Protobuf +import io.spine.internal.dependency.Spine.McJava + +/** + * The dependency onto Spine Validation causes the circular dependency in this Gradle project. + * Therefore, we disable the validation altogether. + */ +System.setProperty("spine.internal.validation.disabled", "true") + +apply { + plugin(Protobuf.GradlePlugin.id) + plugin(McJava.pluginId) +} + +dependencies { + Protobuf.libs.forEach { "api"(it) } +} diff --git a/buildSrc/src/main/kotlin/compile-protobuf.gradle.kts b/buildSrc/src/main/kotlin/compile-protobuf.gradle.kts index ba3e579..c5be445 100644 --- a/buildSrc/src/main/kotlin/compile-protobuf.gradle.kts +++ b/buildSrc/src/main/kotlin/compile-protobuf.gradle.kts @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/HelloProtoData.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/HelloProtoData.kt index 96fed2d..78c8aed 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/HelloProtoData.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/HelloProtoData.kt @@ -39,7 +39,7 @@ object HelloProtoData { const val group = "io.spine.examples" - private const val version = "0.20.7" + private const val version = "0.50.0" private const val prefix = "hello-protodata-" object ProtoExtension { diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/KotlinX.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/KotlinX.kt new file mode 100644 index 0000000..435befd --- /dev/null +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/KotlinX.kt @@ -0,0 +1,42 @@ +/* + * Copyright 2023, 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.dependency + +@Suppress("unused", "ConstPropertyName") +object KotlinX { + + const val group = "org.jetbrains.kotlinx" + + object Coroutines { + + // https://github.com/Kotlin/kotlinx.coroutines + const val version = "1.7.3" + const val core = "$group:kotlinx-coroutines-core:$version" + const val jvm = "$group:kotlinx-coroutines-core-jvm:$version" + const val jdk8 = "$group:kotlinx-coroutines-jdk8:$version" + } +} diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Ksp.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Ksp.kt new file mode 100644 index 0000000..ae44a40 --- /dev/null +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Ksp.kt @@ -0,0 +1,40 @@ +/* + * Copyright 2024, 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.internal.dependency + +/** + * Kotlin Symbol Processing API. + * + * @see KSP GitHub repository + */ +object Ksp { + /** + * The latest version compatible with Kotlin v1.8.22, which is bundled with Gradle 7.6.4. + */ + const val version = "1.8.22-1.0.11" + const val id = "com.google.devtools.ksp" +} diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/ProtoData.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/ProtoData.kt index fe0f970..8992b0a 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/ProtoData.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/ProtoData.kt @@ -64,6 +64,9 @@ object ProtoData { */ const val version: String = "0.50.0" + const val lib: String = + "io.spine:protodata:0.50.0" + const val pluginLib: String = "$group:gradle-plugin:$version" diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/ProtoTap.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/ProtoTap.kt new file mode 100644 index 0000000..470f550 --- /dev/null +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/ProtoTap.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2024, 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.internal.dependency + +/** + * Dependencies on ProtoTap plugins. + * + * See [`SpineEventEngine/ProtoTap`](https://github.com/SpineEventEngine/ProtoTap/). + */ +@Suppress( + "unused" /* Some subprojects do not use ProtoData directly. */, + "ConstPropertyName" /* We use custom convention for artifact properties. */, + "MemberVisibilityCanBePrivate" /* The properties are used directly by other subprojects. */, +) +object ProtoTap { + const val group = "io.spine.tools" + const val version = "0.8.7" + const val gradlePluginId = "io.spine.prototap" + const val api = "$group:prototap-api:$version" + const val gradlePlugin = "$group:prototap-gradle-plugin:$version" + const val protocPlugin = "$group:prototap-protoc-plugin:$version" +} diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Spine.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Spine.kt index cc7f2fe..33ebaff 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Spine.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Spine.kt @@ -5,7 +5,7 @@ * 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 + * 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 @@ -29,7 +29,7 @@ package io.spine.internal.dependency /** * Dependencies on Spine modules. */ -@Suppress("unused") +@Suppress("unused", "ConstPropertyName") object Spine { const val group = "io.spine" @@ -45,14 +45,14 @@ object Spine { * * @see spine-base */ - const val base = "2.0.0-SNAPSHOT.199" + const val base = "2.0.0-SNAPSHOT.203" /** * The version of [Spine.reflect]. * * @see spine-reflect */ - const val reflect = "2.0.0-SNAPSHOT.183" + const val reflect = "2.0.0-SNAPSHOT.187" /** * The version of [Spine.Logging]. @@ -89,7 +89,7 @@ object Spine { * * @see spine-mc-java */ - const val mcJava = "2.0.0-SNAPSHOT.205" + const val mcJava = "2.0.0-SNAPSHOT.206" /** * The version of [Spine.baseTypes]. @@ -124,7 +124,7 @@ object Spine { * * @see spine-tool-base */ - const val toolBase = "2.0.0-SNAPSHOT.212" + const val toolBase = "2.0.0-SNAPSHOT.217" /** * The version of [Spine.javadocTools]. diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/ProjectExtensions.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/ProjectExtensions.kt index 62ef8c4..18a1efc 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/ProjectExtensions.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/ProjectExtensions.kt @@ -26,11 +26,14 @@ package io.spine.internal.gradle +import io.spine.internal.gradle.publish.SpinePublishing +import java.io.File import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.Task import org.gradle.api.plugins.JavaPluginExtension import org.gradle.api.tasks.SourceSetContainer +import org.gradle.kotlin.dsl.findByType import org.gradle.kotlin.dsl.getByType /** @@ -70,3 +73,28 @@ fun Project.findTask(name: String): T { ?: error("Unable to find a task named `$name` in the project `${this.name}`.") return task as T } + +/** + * Obtains Maven artifact ID of this [Project]. + * + * The method checks if [SpinePublishing] extension is configured upon this project. If yes, + * returns [SpinePublishing.artifactId] for the project. Otherwise, a project's name is returned. + */ +val Project.artifactId: String + get() { + + // Publishing of a project can be configured either from the project itself or + // from its root project. This is why it is required to check both places. + + val spinePublishing = extensions.findByType() + ?: rootProject.extensions.findByType() + + val artifactId = spinePublishing?.artifactId(this) + return artifactId ?: name + } + +/** + * Returns project's build directory as [File]. + */ +val Project.buildDirectory: File + get() = layout.buildDirectory.get().asFile diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/Repositories.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/Repositories.kt index f059f76..4a88035 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/Repositories.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/Repositories.kt @@ -28,9 +28,145 @@ package io.spine.internal.gradle +import io.spine.internal.gradle.publish.CloudRepo +import io.spine.internal.gradle.publish.PublishingRepos +import io.spine.internal.gradle.publish.PublishingRepos.gitHub +import java.io.File import java.net.URI +import java.util.* +import org.gradle.api.Project import org.gradle.api.artifacts.dsl.RepositoryHandler import org.gradle.api.artifacts.repositories.MavenArtifactRepository +import org.gradle.kotlin.dsl.ScriptHandlerScope +import org.gradle.kotlin.dsl.maven + +/** + * Applies [standard][doApplyStandard] repositories to this [ScriptHandlerScope] + * optionally adding [gitHub] repositories for Spine-only components, if + * names of such repositories are given. + * + * @param buildscript + * a [ScriptHandlerScope] to work with. Pass `this` under `buildscript { }`. + * @param rootProject + * a root project where the `buildscript` is declared. + * @param gitHubRepo + * a list of short repository names, or empty list if only + * [standard repositories][doApplyStandard] are required. + */ +@Suppress("unused") +@Deprecated( + message = "Please use `standardSpineSdkRepositories()`.", + replaceWith = ReplaceWith("standardSpineSdkRepositories()") +) +fun applyWithStandard( + buildscript: ScriptHandlerScope, + rootProject: Project, + vararg gitHubRepo: String +) { + val repositories = buildscript.repositories + gitHubRepo.iterator().forEachRemaining { repo -> + repositories.applyGitHubPackages(repo, rootProject) + } + repositories.standardToSpineSdk() +} + +/** + * Registers the selected GitHub Packages repos as Maven repositories. + * + * To be used in `buildscript` clauses when a fully-qualified call must be made. + * + * @param repositories + * the handler to accept registration of the GitHub Packages repository + * @param shortRepositoryName + * the short name of the GitHub repository (e.g. "core-java") + * @param project + * the project which is going to consume artifacts from the repository + * @see applyGitHubPackages + */ +@Suppress("unused") +@Deprecated( + message = "Please use `standardSpineSdkRepositories()`.", + replaceWith = ReplaceWith("standardSpineSdkRepositories()") +) +fun doApplyGitHubPackages( + repositories: RepositoryHandler, + shortRepositoryName: String, + project: Project +) = repositories.applyGitHubPackages(shortRepositoryName, project) + +/** + * Registers the standard set of Maven repositories. + * + * To be used in `buildscript` clauses when a fully-qualified call must be made. + */ +@Suppress("unused") +@Deprecated( + message = "Please use `standardSpineSdkRepositories()`.", + replaceWith = ReplaceWith("standardSpineSdkRepositories()") +) +fun doApplyStandard(repositories: RepositoryHandler) = repositories.standardToSpineSdk() + +/** + * Applies the repository hosted at GitHub Packages, to which Spine artifacts were published. + * + * This method should be used by those wishing to have Spine artifacts published + * to GitHub Packages as dependencies. + * + * @param shortRepositoryName + * short names of the GitHub repository (e.g. "base", "core-java", "model-tools") + * @param project + * the project which is going to consume artifacts from repositories + */ +fun RepositoryHandler.applyGitHubPackages(shortRepositoryName: String, project: Project) { + val repository = gitHub(shortRepositoryName) + val credentials = repository.credentials(project) + + credentials?.let { + spineMavenRepo(it, repository.releases) + spineMavenRepo(it, repository.snapshots) + } +} + +/** + * Applies the repositories hosted at GitHub Packages, to which Spine artifacts were published. + * + * This method should be used by those wishing to have Spine artifacts published + * to GitHub Packages as dependencies. + * + * @param shortRepositoryName + * the short name of the GitHub repository (e.g. "core-java") + * @param project + * the project which is going to consume or publish artifacts from + * the registered repository + */ +fun RepositoryHandler.applyGitHubPackages(project: Project, vararg shortRepositoryName: String) { + for (name in shortRepositoryName) { + applyGitHubPackages(name, project) + } +} + +/** + * Applies [standard][applyStandard] repositories to this [RepositoryHandler] + * optionally adding [applyGitHubPackages] repositories for Spine-only components, if + * names of such repositories are given. + * + * @param project + * a project to which we add dependencies + * @param gitHubRepo + * a list of short repository names, or empty list if only + * [standard repositories][applyStandard] are required. + */ +@Suppress("unused") +@Deprecated( + message = "Please use `standardToSpineSdk()`.", + replaceWith = ReplaceWith("standardToSpineSdk()") +) +fun RepositoryHandler.applyStandardWithGitHub(project: Project, vararg gitHubRepo: String) { + gitHubRepo.iterator().forEachRemaining { repo -> + applyGitHubPackages(repo, project) + } + standardToSpineSdk() +} /** * A scrambled version of PAT generated with the only "read:packages" scope. @@ -79,12 +215,37 @@ fun RepositoryHandler.spineArtifacts(): MavenArtifactRepository = maven { } } +val RepositoryHandler.intellijReleases: MavenArtifactRepository + get() = maven("https://www.jetbrains.com/intellij-repository/releases") + +val RepositoryHandler.jetBrainsCacheRedirector: MavenArtifactRepository + get() = maven("https://cache-redirector.jetbrains.com/intellij-dependencies") + /** * Applies repositories commonly used by Spine Event Engine projects. */ fun RepositoryHandler.standardToSpineSdk() { spineArtifacts() + val spineRepos = listOf( + Repos.spine, + Repos.spineSnapshots, + Repos.artifactRegistry, + Repos.artifactRegistrySnapshots + ) + + spineRepos + .map { URI(it) } + .forEach { + maven { + url = it + includeSpineOnly() + } + } + + intellijReleases + jetBrainsCacheRedirector + maven { url = URI(Repos.sonatypeSnapshots) } @@ -100,6 +261,57 @@ fun RepositoryHandler.standardToSpineSdk() { ) fun RepositoryHandler.applyStandard() = this.standardToSpineSdk() +/** + * A Maven repository. + */ +data class Repository( + val releases: String, + val snapshots: String, + private val credentialsFile: String? = null, + private val credentialValues: ((Project) -> Credentials?)? = null, + val name: String = "Maven repository `$releases`" +) { + + /** + * Obtains the publishing password credentials to this repository. + * + * If the credentials are represented by a `.properties` file, reads the file and parses + * the credentials. The file must have properties `user.name` and `user.password`, which store + * the username and the password for the Maven repository auth. + */ + fun credentials(project: Project): Credentials? = when { + credentialValues != null -> credentialValues.invoke(project) + credentialsFile != null -> credsFromFile(credentialsFile, project) + else -> throw IllegalArgumentException( + "Credentials file or a supplier function should be passed." + ) + } + + private fun credsFromFile(fileName: String, project: Project): Credentials? { + val file = project.rootProject.file(fileName) + if (file.exists().not()) { + return null + } + + val log = project.logger + log.info("Using credentials from `$fileName`.") + val creds = file.parseCredentials() + log.info("Publishing build as `${creds.username}`.") + return creds + } + + private fun File.parseCredentials(): Credentials { + val properties = Properties().apply { load(inputStream()) } + val username = properties.getProperty("user.name") + val password = properties.getProperty("user.password") + return Credentials(username, password) + } + + override fun toString(): String { + return name + } +} + /** * Password credentials for a Maven repository. */ @@ -114,6 +326,10 @@ data class Credentials( * @see [applyStandard] */ private object Repos { + val spine = CloudRepo.published.releases + val spineSnapshots = CloudRepo.published.snapshots + val artifactRegistry = PublishingRepos.cloudArtifactRegistry.releases + val artifactRegistrySnapshots = PublishingRepos.cloudArtifactRegistry.snapshots @Suppress("unused") @Deprecated( @@ -125,6 +341,25 @@ private object Repos { const val sonatypeSnapshots = "https://oss.sonatype.org/content/repositories/snapshots" } +/** + * Registers the Maven repository with the passed [repoCredentials] for authorization. + * + * Only includes the Spine-related artifact groups. + */ +private fun RepositoryHandler.spineMavenRepo( + repoCredentials: Credentials, + repoUrl: String +) { + maven { + url = URI(repoUrl) + includeSpineOnly() + credentials { + username = repoCredentials.username + password = repoCredentials.password + } + } +} + /** * Narrows down the search for this repository to Spine-related artifact groups. */ diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/protobuf/ProtoTaskExtensions.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/protobuf/ProtoTaskExtensions.kt index 5a94e6b..de78a5e 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/protobuf/ProtoTaskExtensions.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/protobuf/ProtoTaskExtensions.kt @@ -29,6 +29,8 @@ package io.spine.internal.gradle.protobuf import com.google.protobuf.gradle.GenerateProtoTask import io.spine.internal.gradle.sourceSets import java.io.File +import java.nio.file.Files +import java.nio.file.StandardOpenOption.TRUNCATE_EXISTING import org.gradle.api.Project import org.gradle.api.file.SourceDirectorySet import org.gradle.api.tasks.SourceSet @@ -112,23 +114,69 @@ fun GenerateProtoTask.setup() { /** * Tell `protoc` to generate descriptor set files under the project build dir. + * + * The name of the descriptor set file to be generated + * is made to be unique per project's Maven coordinates. + * + * As the last step of this task, writes a `desc.ref` file + * for the contextual source set, pointing to the generated descriptor set file. + * This is needed in order to allow other Spine libraries + * to locate and load the generated descriptor set files properly. + * + * Such a job is usually performed by Spine McJava plugin, + * however, it is not possible to use this plugin (or its code) + * in this repository due to cyclic dependencies. */ +@Suppress( + "TooGenericExceptionCaught" /* Handling all file-writing failures in the same way.*/) private fun GenerateProtoTask.setupDescriptorSetFileCreation() { // Tell `protoc` generate descriptor set file. + // The name of the generated file reflects project's Maven coordinates. val ssn = sourceSet.name generateDescriptorSet = true - val descriptorsDir = "${project.buildDir}/descriptors/${ssn}" + val buildDir = project.layout.buildDirectory.asFile.get().path + val descriptorsDir = "$buildDir/descriptors/${ssn}" + val descriptorName = project.descriptorSetName(sourceSet) with(descriptorSetOptions) { - path = "$descriptorsDir/known_types_${ssn}.desc" + path = "$descriptorsDir/$descriptorName" includeImports = true includeSourceInfo = true } + // Make the descriptor set file included into the resources. project.sourceSets.named(ssn) { resources.srcDirs(descriptorsDir) } + + // Create a `desc.ref` in the same resource folder, + // with the name of the descriptor set file created above. + this.doLast { + val descRefFile = File(descriptorsDir, "desc.ref") + descRefFile.createNewFile() + try { + Files.write(descRefFile.toPath(), setOf(descriptorName), TRUNCATE_EXISTING) + } catch (e: Exception) { + project.logger.error("Error writing `${descRefFile.absolutePath}`.", e) + throw e + } + } } +/** + * Returns a name of the descriptor file for the given [sourceSet], + * reflecting the Maven coordinates of Gradle artifact, and the source set + * for which the descriptor set name is to be generated. + * + * The returned value is just a file name, and does not contain a file path. + */ +private fun Project.descriptorSetName(sourceSet: SourceSet) = + arrayOf( + group.toString(), + name, + sourceSet.name, + version.toString() + ).joinToString(separator = "_", postfix = ".desc") + /** * Copies files from the [outputBaseDir][GenerateProtoTask.outputBaseDir] into * a subdirectory of [generatedDir][Project.generatedDir] for diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/CheckVersionIncrement.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/CheckVersionIncrement.kt new file mode 100644 index 0000000..a81cbdc --- /dev/null +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/CheckVersionIncrement.kt @@ -0,0 +1,129 @@ +/* + * Copyright 2023, 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.gradle.publish + +import com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES +import com.fasterxml.jackson.dataformat.xml.XmlMapper +import io.spine.internal.gradle.Repository +import java.io.FileNotFoundException +import java.net.URL +import org.gradle.api.DefaultTask +import org.gradle.api.GradleException +import org.gradle.api.Project +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.TaskAction + +/** + * A task which verifies that the current version of the library has not been published to the given + * Maven repository yet. + */ +open class CheckVersionIncrement : DefaultTask() { + + /** + * The Maven repository in which to look for published artifacts. + * + * We check both the `releases` and `snapshots` repositories. Artifacts in either of these repos + * may not be overwritten. + */ + @Input + lateinit var repository: Repository + + @Input + val version: String = project.version as String + + @TaskAction + fun fetchAndCheck() { + val artifact = "${project.artifactPath()}/${MavenMetadata.FILE_NAME}" + checkInRepo(repository.snapshots, artifact) + + if (repository.releases != repository.snapshots) { + checkInRepo(repository.releases, artifact) + } + } + + private fun checkInRepo(repoUrl: String, artifact: String) { + val metadata = fetch(repoUrl, artifact) + val versions = metadata?.versioning?.versions + val versionExists = versions?.contains(version) ?: false + if (versionExists) { + throw GradleException(""" + Version `$version` is already published to maven repository `$repoUrl`. + Try incrementing the library version. + All available versions are: ${versions?.joinToString(separator = ", ")}. + + To disable this check, run Gradle with `-x $name`. + """.trimIndent() + ) + } + } + + private fun fetch(repository: String, artifact: String): MavenMetadata? { + val url = URL("$repository/$artifact") + return MavenMetadata.fetchAndParse(url) + } + + private fun Project.artifactPath(): String { + val group = this.group as String + val name = "spine-${this.name}" + + val pathElements = ArrayList(group.split('.')) + pathElements.add(name) + val path = pathElements.joinToString(separator = "/") + return path + } +} + +private data class MavenMetadata(var versioning: Versioning = Versioning()) { + + companion object { + + const val FILE_NAME = "maven-metadata.xml" + + private val mapper = XmlMapper() + + init { + mapper.configure(FAIL_ON_UNKNOWN_PROPERTIES, false) + } + + /** + * Fetches the metadata for the repository and parses the document. + * + *

If the document could not be found, assumes that the module was never + * released and thus has no metadata. + */ + fun fetchAndParse(url: URL): MavenMetadata? { + return try { + val metadata = mapper.readValue(url, MavenMetadata::class.java) + metadata + } catch (ignored: FileNotFoundException) { + null + } + } + } +} + +private data class Versioning(var versions: List = listOf()) diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/CloudArtifactRegistry.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/CloudArtifactRegistry.kt new file mode 100644 index 0000000..4751d56 --- /dev/null +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/CloudArtifactRegistry.kt @@ -0,0 +1,78 @@ +/* + * Copyright 2023, 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.gradle.publish + +import com.google.auth.oauth2.GoogleCredentials +import com.google.cloud.artifactregistry.auth.DefaultCredentialProvider +import io.spine.internal.gradle.Credentials +import io.spine.internal.gradle.Repository +import java.io.IOException +import org.gradle.api.Project + +/** + * The experimental Google Cloud Artifact Registry repository. + * + * In order to successfully publish into this repository, a service account key is needed. + * The published must create a service account, grant it the permission to write into + * Artifact Registry, and generate a JSON key. + * Then, the key must be placed somewhere on the file system and the environment variable + * `GOOGLE_APPLICATION_CREDENTIALS` must be set to point at the key file. + * Once these preconditions are met, publishing becomes possible. + * + * Google provides a Gradle plugin for configuring the publishing repository credentials + * automatically. We achieve the same goal by assembling the credentials manually. We do so + * in order to fit the Google Cloud Artifact Registry repository into the standard frame of + * the Maven [Repository]-s. Applying the plugin would take a substantial effort due to the fact + * that both our publishing scripts and the Google's plugin use `afterEvaluate { }` hooks. + * Ordering said hooks is a non-trivial operation and the result is usually quite fragile. + * Thus, we choose to do this small piece of configuration manually. + */ +internal object CloudArtifactRegistry { + + private const val spineRepoLocation = "https://europe-maven.pkg.dev/spine-event-engine" + + val repository = Repository( + releases = "${spineRepoLocation}/releases", + snapshots = "${spineRepoLocation}/snapshots", + credentialValues = this::fetchGoogleCredentials + ) + + private fun fetchGoogleCredentials(p: Project): Credentials? { + return try { + val googleCreds = DefaultCredentialProvider() + val creds = googleCreds.credential as GoogleCredentials + creds.refreshIfExpired() + Credentials("oauth2accesstoken", creds.accessToken.tokenValue) + } catch (e: IOException) { + p.logger.info("Unable to fetch credentials for Google Cloud Artifact Registry." + + " Reason: '${e.message}'." + + " The debug output may contain more details.") + null + } + } +} + diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/CloudRepo.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/CloudRepo.kt new file mode 100644 index 0000000..148ebce --- /dev/null +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/CloudRepo.kt @@ -0,0 +1,68 @@ +/* + * Copyright 2023, 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.gradle.publish + +import io.spine.internal.gradle.Repository + +/** + * CloudRepo Maven repository. + * + * There is a special treatment for this repository. Usually, fetching and publishing of artifacts + * is performed via the same URL. But it is not true for CloudRepo. Fetching is performed via + * public repository, and publishing via private one. Their URLs differ in `/public` infix. + */ +internal object CloudRepo { + + private const val name = "CloudRepo" + private const val credentialsFile = "cloudrepo.properties" + private const val publicUrl = "https://spine.mycloudrepo.io/public/repositories" + private val privateUrl = publicUrl.replace("/public", "") + + /** + * CloudRepo repository for fetching of artifacts. + * + * Use this instance to depend on artifacts from this repository. + */ + val published = Repository( + name = name, + releases = "$publicUrl/releases", + snapshots = "$publicUrl/snapshots", + credentialsFile = credentialsFile + ) + + /** + * CloudRepo repository for publishing of artifacts. + * + * Use this instance to push new artifacts to this repository. + */ + val destination = Repository( + name = name, + releases = "$privateUrl/releases", + snapshots = "$privateUrl/snapshots", + credentialsFile = credentialsFile + ) +} diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/GitHubPackages.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/GitHubPackages.kt new file mode 100644 index 0000000..68b68a2 --- /dev/null +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/GitHubPackages.kt @@ -0,0 +1,105 @@ +/* + * Copyright 2023, 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.gradle.publish + +import io.spine.internal.gradle.Credentials +import io.spine.internal.gradle.Repository +import io.spine.internal.gradle.buildDirectory +import net.lingala.zip4j.ZipFile +import org.gradle.api.Project + +/** + * Maven repositories of Spine Event Engine projects hosted at GitHub Packages. + */ +internal object GitHubPackages { + + /** + * Obtains an instance of the GitHub Packages repository with the given name. + */ + fun repository(repoName: String): Repository { + val githubActor: String = actor() + return Repository( + name = "GitHub Packages", + releases = "https://maven.pkg.github.com/SpineEventEngine/$repoName", + snapshots = "https://maven.pkg.github.com/SpineEventEngine/$repoName", + credentialValues = { project -> project.credentialsWithToken(githubActor) } + ) + } + + private fun actor(): String { + var githubActor: String? = System.getenv("GITHUB_ACTOR") + githubActor = if (githubActor.isNullOrEmpty()) { + "developers@spine.io" + } else { + githubActor + } + return githubActor + } +} + +/** + * This is a trick. Gradle only supports password or AWS credentials. + * Thus, we pass the GitHub token as a "password". + * + * See https://docs.github.com/en/actions/guides/publishing-java-packages-with-gradle#publishing-packages-to-github-packages + */ +private fun Project.credentialsWithToken(githubActor: String) = Credentials( + username = githubActor, + password = readGitHubToken() +) + +private fun Project.readGitHubToken(): String { + val githubToken: String? = System.getenv("GITHUB_TOKEN") + return if (githubToken.isNullOrEmpty()) { + readTokenFromArchive() + } else { + githubToken + } +} + +/** + * Read the personal access token for the `developers@spine.io` account which + * has only the permission to read public GitHub packages. + * + * The token is extracted from the archive called `aus.weis` stored under `buildSrc`. + * The archive has such an unusual name to avoid scanning for tokens placed in repositories + * which is performed by GitHub. Since we do not violate any security, it is OK to + * use such a workaround. + */ +private fun Project.readTokenFromArchive(): String { + val targetDir = "$buildDirectory/token" + file(targetDir).mkdirs() + val fileToUnzip = "${rootDir}/buildSrc/aus.weis" + + logger.info( + "GitHub Packages: reading token by unzipping `$fileToUnzip` into `$targetDir`." + ) + ZipFile(fileToUnzip, "123".toCharArray()).extractAll(targetDir) + val file = file("$targetDir/token.txt") + val result = file.readText() + return result +} diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/IncrementGuard.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/IncrementGuard.kt new file mode 100644 index 0000000..4dfb641 --- /dev/null +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/IncrementGuard.kt @@ -0,0 +1,109 @@ +/* + * Copyright 2024, 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. + */ + +@file:Suppress("unused") + +package io.spine.internal.gradle.publish + +import org.gradle.api.Plugin +import org.gradle.api.Project + +/** + * Gradle plugin which adds a [CheckVersionIncrement] task. + * + * The task is called `checkVersionIncrement` inserted before the `check` task. + */ +class IncrementGuard : Plugin { + + companion object { + const val taskName = "checkVersionIncrement" + } + + /** + * Adds the [CheckVersionIncrement] task to the project. + * + * The task is created anyway, but it is enabled only if: + * 1. The project is built on GitHub CI, and + * 2. The job is a pull request. + * + * The task only runs on non-master branches on GitHub Actions. + * This is done to prevent unexpected CI fails when re-building `master` multiple times, + * creating git tags, and in other cases that go outside the "usual" development cycle. + */ + override fun apply(target: Project) { + val tasks = target.tasks + tasks.register(taskName, CheckVersionIncrement::class.java) { + repository = CloudArtifactRegistry.repository + tasks.getByName("check").dependsOn(this) + + if (!shouldCheckVersion()) { + logger.info( + "The build does not represent a GitHub Actions feature branch job, " + + "the `checkVersionIncrement` task is disabled." + ) + this.enabled = false + } + } + } + + /** + * Returns `true` if the current build is a GitHub Actions build which represents a push + * to a feature branch. + * + * Returns `false` if the associated reference is not a branch (e.g., a tag) or if it has + * the name which ends with `master` or `main`. + * + * For example, on the following branches the method would return `false`: + * + * 1. `master`. + * 2. `main`. + * 3. `2.x-jdk8-master`. + * 4. `2.x-jdk8-main`. + * + * @see + * List of default environment variables provided for GitHub Actions builds + */ + private fun shouldCheckVersion(): Boolean { + val event = System.getenv("GITHUB_EVENT_NAME") + val reference = System.getenv("GITHUB_REF") + if (event != "push" || reference == null) { + return false + } + val branch = branchName(reference) + return when { + branch == null -> false + branch.endsWith("master") -> false + branch.endsWith("main") -> false + else -> true + } + } + + private fun branchName(gitHubRef: String): String? { + val matches = Regex("refs/heads/(.+)").matchEntire(gitHubRef) + val branch = matches?.let { it.groupValues[1] } + return branch + } +} diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/JarDsl.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/JarDsl.kt new file mode 100644 index 0000000..2bc2870 --- /dev/null +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/JarDsl.kt @@ -0,0 +1,167 @@ +/* + * Copyright 2023, 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.gradle.publish + +/** + * A DSL element of [SpinePublishing] extension which configures publishing of + * [dokkaKotlinJar] artifact. + * + * This artifact contains Dokka-generated documentation. By default, it is not published. + * + * Take a look at the [SpinePublishing.dokkaJar] for a usage example. + * + * @see [artifacts] + */ +class DokkaJar { + /** + * Enables publishing `JAR`s with Dokka-generated documentation for all published modules. + */ + @Suppress("unused") + @Deprecated("Please use `kotlin` and `java` flags instead.") + var enabled = false + + /** + * Controls whether [dokkaKotlinJar] artifact should be published. + * The default value is `true`. + */ + var kotlin = true + + /** + * Controls whether [dokkaJavaJar] artifact should be published. + * The default value is `false`. + */ + var java = false +} + +/** + * A DSL element of [SpinePublishing] extension which allows enabling publishing + * of [testJar] artifact. + * + * This artifact contains compilation output of `test` source set. By default, it is not published. + * + * Take a look on [SpinePublishing.testJar] for a usage example. + + * @see [artifacts] + */ +class TestJar { + + /** + * Set of modules, for which a test JAR will be published. + */ + var inclusions: Set = emptySet() + + /** + * Enables test JAR publishing for all published modules. + */ + var enabled = false +} + +/** + * A DSL element of [SpinePublishing] extension which allows disabling publishing + * of [protoJar] artifact. + * + * This artifact contains all the `.proto` definitions from `sourceSets.main.proto`. By default, + * it is published. + * + * Take a look on [SpinePublishing.protoJar] for a usage example. + * + * @see [artifacts] + */ +class ProtoJar { + + /** + * Set of modules, for which a proto JAR will not be published. + */ + var exclusions: Set = emptySet() + + /** + * Disables proto JAR publishing for all published modules. + */ + var disabled = false +} + +/** + * Flags for turning optional JAR artifacts in a project. + */ +internal data class JarFlags( + + /** + * Tells whether [sourcesJar] artifact should be published. + * + * Default value is `true`. + */ + val sourcesJar: Boolean = true, + + /** + * Tells whether [javadocJar] artifact should be published. + * + * Default value is `true`. + */ + val javadocJar: Boolean = true, + + /** + * Tells whether [protoJar] artifact should be published. + */ + val publishProtoJar: Boolean, + + /** + * Tells whether [testJar] artifact should be published. + */ + val publishTestJar: Boolean, + + /** + * Tells whether [dokkaKotlinJar] artifact should be published. + */ + val publishDokkaKotlinJar: Boolean, + + /** + * Tells whether [dokkaJavaJar] artifact should be published. + */ + val publishDokkaJavaJar: Boolean +) { + internal companion object { + /** + * Creates an instance of [JarFlags] for the project with the given name, + * taking the setup parameters from JAR DSL elements. + */ + fun create( + projectName: String, + protoJar: ProtoJar, + testJar: TestJar, + dokkaJar: DokkaJar + ): JarFlags { + val addProtoJar = (protoJar.exclusions.contains(projectName) || protoJar.disabled).not() + val addTestJar = testJar.inclusions.contains(projectName) || testJar.enabled + return JarFlags( + sourcesJar = true, + javadocJar = true, + addProtoJar, addTestJar, + dokkaJar.kotlin, dokkaJar.java + ) + } + } +} diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/ProtoExts.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/ProtoExts.kt new file mode 100644 index 0000000..97e3319 --- /dev/null +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/ProtoExts.kt @@ -0,0 +1,89 @@ +/* + * Copyright 2023, 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.gradle.publish + +import io.spine.internal.gradle.sourceSets +import java.io.File +import org.gradle.api.Project +import org.gradle.api.Task +import org.gradle.api.file.FileTreeElement +import org.gradle.api.file.SourceDirectorySet +import org.gradle.api.tasks.bundling.Jar + +/** + * Tells whether there are any Proto sources in "main" source set. + */ +internal fun Project.hasProto(): Boolean { + val protoSources = protoSources() + val result = protoSources.any { it.exists() } + return result +} + +/** + * Locates directories with proto sources under the "main" source sets. + * + * Special treatment for Proto sources is needed, because they are not Java-related, and, + * thus, not included in `sourceSets["main"].allSource`. + */ +internal fun Project.protoSources(): Set { + val mainSourceSets = sourceSets.filter { + ss -> ss.name.endsWith("main", ignoreCase = true) + } + + val protoExtensions = mainSourceSets.mapNotNull { + it.extensions.findByName("proto") as SourceDirectorySet? + } + + val protoDirs = mutableSetOf() + protoExtensions.forEach { + protoDirs.addAll(it.srcDirs) + } + + return protoDirs +} + +/** + * Checks if the given file belongs to the Google `.proto` sources. + */ +internal fun FileTreeElement.isGoogleProtoSource(): Boolean { + val pathSegments = relativePath.segments + return pathSegments.isNotEmpty() && pathSegments[0].equals("google") +} + +/** + * The reference to the `generateProto` task of a `main` source set. + */ +internal fun Project.generateProto(): Task? = tasks.findByName("generateProto") + +/** + * Makes this [Jar] task depend on the [generateProto] task, if it exists in the same project. + */ +internal fun Jar.dependOnGenerateProto() { + project.generateProto()?.let { + this.dependsOn(it) + } +} diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/Publications.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/Publications.kt new file mode 100644 index 0000000..0b4d24b --- /dev/null +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/Publications.kt @@ -0,0 +1,234 @@ +/* + * Copyright 2024, 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.gradle.publish + +import io.spine.internal.gradle.Repository +import io.spine.internal.gradle.isSnapshot +import org.gradle.api.Project +import org.gradle.api.artifacts.dsl.RepositoryHandler +import org.gradle.api.publish.maven.MavenPublication +import org.gradle.api.tasks.TaskProvider +import org.gradle.api.tasks.bundling.Jar +import org.gradle.kotlin.dsl.apply +import org.gradle.kotlin.dsl.create + +/** + * The name of the Maven Publishing Gradle plugin. + */ +private const val MAVEN_PUBLISH = "maven-publish" + +/** + * Abstract base for handlers of publications in a project + * with [spinePublishing] settings declared. + */ +internal sealed class PublicationHandler( + protected val project: Project, + private val destinations: Set +) { + + fun apply() = with(project) { + if (!hasCustomPublishing) { + apply(plugin = MAVEN_PUBLISH) + } + + pluginManager.withPlugin(MAVEN_PUBLISH) { + handlePublications() + registerDestinations() + configurePublishTask(destinations) + } + } + + /** + * Either handles publications already declared in the given project, + * or creates new ones. + */ + abstract fun handlePublications() + + /** + * Goes through the [destinations] and registers each as a repository for publishing + * in the given Gradle project. + */ + private fun registerDestinations() { + val repositories = project.publishingExtension.repositories + destinations.forEach { destination -> + repositories.register(project, destination) + } + } + + /** + * Copies the attributes of Gradle [Project] to this [MavenPublication]. + * + * The following project attributes are copied: + * * [group][Project.getGroup]; + * * [version][Project.getVersion]; + * * [description][Project.getDescription]. + * + * Also, this function adds the [artifactPrefix][SpinePublishing.artifactPrefix] to + * the [artifactId][MavenPublication.setArtifactId] of this publication, + * if the prefix is not added yet. + * + * Finally, the Apache Software License 2.0 is set as the only license + * under which the published artifact is distributed. + */ + protected fun MavenPublication.copyProjectAttributes() { + groupId = project.group.toString() + val prefix = project.spinePublishing.artifactPrefix + if (!artifactId.startsWith(prefix)) { + artifactId = prefix + artifactId + } + version = project.version.toString() + pom.description.set(project.description) + + pom.licenses { + license { + name.set("The Apache Software License, Version 2.0") + url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") + } + } + } +} + +/** + * Adds a Maven repository to the project specifying credentials, if they are + * [available][Repository.credentials] from the root project. + */ +private fun RepositoryHandler.register(project: Project, repository: Repository) { + val isSnapshot = project.version.toString().isSnapshot() + val target = if (isSnapshot) repository.snapshots else repository.releases + val credentials = repository.credentials(project.rootProject) + maven { + url = project.uri(target) + credentials { + username = credentials?.username + password = credentials?.password + } + } +} + +/** + * A publication for a typical Java project. + * + * In Gradle, to publish something, one should create a publication. + * A publication has a name and consists of one or more artifacts plus information about + * those artifacts – the metadata. + * + * An instance of this class represents [MavenPublication] named "mavenJava". It is generally + * accepted that a publication with this name contains a Java project published to one or + * more Maven repositories. + * + * By default, only a jar with the compilation output of `main` source set and its + * metadata files are published. Other artifacts are specified through the + * [constructor parameter][jarFlags]. Please, take a look on [specifyArtifacts] for additional info. + * + * @param jarFlags + * flags for additional JARs published along with the compilation output. + * @param destinations + * Maven repositories to which the produced artifacts will be sent. + * @see + * Maven Publish Plugin | Publications + */ +internal class StandardJavaPublicationHandler( + project: Project, + private val jarFlags: JarFlags, + destinations: Set, +) : PublicationHandler(project, destinations) { + + /** + * Creates a new "mavenJava" [MavenPublication] in the given project. + */ + override fun handlePublications() { + val jars = project.artifacts(jarFlags) + val publications = project.publications + publications.create("mavenJava") { + copyProjectAttributes() + specifyArtifacts(jars) + } + } + + /** + * Specifies which artifacts this [MavenPublication] will contain. + * + * A typical Maven publication contains: + * + * 1. Jar archives. For example: compilation output, sources, javadoc, etc. + * 2. Maven metadata file that has ".pom" extension. + * 3. Gradle's metadata file that has ".module" extension. + * + * Metadata files contain information about a publication itself, its artifacts and their + * dependencies. Presence of ".pom" file is mandatory for publication to be consumed by + * `mvn` build tool itself or other build tools that understand Maven notation (Gradle, Ivy). + * Presence of ".module" is optional, but useful when a publication is consumed by Gradle. + * + * @see Maven – POM Reference + * @see + * Understanding Gradle Module Metadata + */ + private fun MavenPublication.specifyArtifacts(jars: Set>) { + + /* "java" component provides a jar with compilation output of "main" source set. + It is NOT defined as another `Jar` task intentionally. Doing that will leave the + publication without correct ".pom" and ".module" metadata files generated. + */ + val javaComponent = project.components.findByName("java") + javaComponent?.let { + from(it) + } + + /* Other artifacts are represented by `Jar` tasks. Those artifacts don't bring any other + metadata in comparison with `Component` (such as dependencies notation). + */ + jars.forEach { + artifact(it) + } + } +} + +/** + * A handler for custom publications, which are declared under the [publications] + * section of a module. + * + * Such publications should be treated differently than [StandardJavaPublicationHandler], + * which is created for a module. Instead, since the publications are already declared, + * this class only [assigns maven coordinates][copyProjectAttributes]. + * + * A module which declares custom publications must be specified in + * the [SpinePublishing.modulesWithCustomPublishing] property. + * + * If a module with [publications] declared locally is not specified as one with custom publishing, + * it may cause a name clash between an artifact produced by the [standard][MavenPublication] + * publication, and custom ones. To have both standard and custom publications, + * please specify custom artifact IDs or classifiers for each custom publication. + */ +internal class CustomPublicationHandler(project: Project, destinations: Set) : + PublicationHandler(project, destinations) { + + override fun handlePublications() { + project.publications.forEach { + (it as MavenPublication).copyProjectAttributes() + } + } +} diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/PublishingExts.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/PublishingExts.kt new file mode 100644 index 0000000..b4c15c3 --- /dev/null +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/PublishingExts.kt @@ -0,0 +1,276 @@ +/* + * Copyright 2023, 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.gradle.publish + +import io.spine.internal.gradle.Repository +import io.spine.internal.gradle.sourceSets +import java.util.* +import org.gradle.api.InvalidUserDataException +import org.gradle.api.Project +import org.gradle.api.Task +import org.gradle.api.publish.PublicationContainer +import org.gradle.api.publish.PublishingExtension +import org.gradle.api.tasks.TaskContainer +import org.gradle.api.tasks.TaskProvider +import org.gradle.api.tasks.bundling.Jar +import org.gradle.kotlin.dsl.findByType +import org.gradle.kotlin.dsl.get +import org.gradle.kotlin.dsl.getByType +import org.gradle.kotlin.dsl.named +import org.gradle.kotlin.dsl.register +import org.gradle.kotlin.dsl.withType + +/** + * Obtains [PublishingExtension] of this project. + */ +internal val Project.publishingExtension: PublishingExtension + get() = extensions.getByType() + +/** + * Obtains [PublicationContainer] of this project. + */ +internal val Project.publications: PublicationContainer + get() = publishingExtension.publications + +/** + * Obtains [SpinePublishing] extension from this [Project]. + * + * If this [Project] doesn't have one, it returns [SpinePublishing] + * declared in the root project. + */ +internal val Project.spinePublishing: SpinePublishing + get() { + val local = this.extensions.findByType() + if (local != null) { + return local + } + val fromRoot = this.rootProject.extensions.findByType() + if (fromRoot != null) { + return fromRoot + } + error("`SpinePublishing` is not found in `${project.name}`.") + } + +/** + * Tells if this project has custom publishing. + */ +internal val Project.hasCustomPublishing: Boolean + get() = spinePublishing.modulesWithCustomPublishing.contains(name) + +private const val PUBLISH_TASK = "publish" + +/** + * Locates `publish` task in this [TaskContainer]. + * + * This task publishes all defined publications to all defined repositories. To achieve that, + * the task depends on all `publish`*PubName*`PublicationTo`*RepoName*`Repository` tasks. + * + * Please note, task execution would not copy publications to the local Maven cache. + * + * @see + * Tasks | Maven Publish Plugin + */ +internal val TaskContainer.publish: TaskProvider + get() = named(PUBLISH_TASK) + +/** + * Sets dependencies for `publish` task in this [Project]. + * + * This method performs the following: + * + * 1. When this [Project] is not a root, makes `publish` task in a root project + * depend on a local `publish`. + * 2. Makes local `publish` task verify that credentials are present for each + * of destination repositories. + */ +internal fun Project.configurePublishTask(destinations: Set) { + attachCredentialsVerification(destinations) + bindToRootPublish() +} + +private fun Project.attachCredentialsVerification(destinations: Set) { + val checkCredentials = tasks.registerCheckCredentialsTask(destinations) + val localPublish = tasks.publish + localPublish.configure { dependsOn(checkCredentials) } +} + +private fun Project.bindToRootPublish() { + if (project == rootProject) { + return + } + + val localPublish = tasks.publish + val rootPublish = rootProject.tasks.getOrCreatePublishTask() + rootPublish.configure { dependsOn(localPublish) } +} + +/** + * Use this task accessor when it is not guaranteed that the task is present + * in this [TaskContainer]. + */ +private fun TaskContainer.getOrCreatePublishTask(): TaskProvider = + if (names.contains(PUBLISH_TASK)) { + named(PUBLISH_TASK) + } else { + register(PUBLISH_TASK) + } + +private fun TaskContainer.registerCheckCredentialsTask( + destinations: Set +): TaskProvider = + register("checkCredentials") { + doLast { + destinations.forEach { it.ensureCredentials(project) } + } + } + +private fun Repository.ensureCredentials(project: Project) { + val credentials = credentials(project) + if (Objects.isNull(credentials)) { + throw InvalidUserDataException( + "No valid credentials for repository `${this}`. Please make sure " + + "to pass username/password or a valid `.properties` file." + ) + } +} + +/** + * Excludes Google `.proto` sources from all artifacts. + * + * Goes through all registered `Jar` tasks and filters out Google's files. + */ +@Suppress("unused") +fun TaskContainer.excludeGoogleProtoFromArtifacts() { + withType().configureEach { + exclude { it.isGoogleProtoSource() } + } +} + +/** + * Locates or creates `sourcesJar` task in this [Project]. + * + * The output of this task is a `jar` archive. The archive contains sources from `main` source set. + * The task makes sure that sources from the directories below will be included into + * a resulted archive: + * + * - Kotlin + * - Java + * - Proto + * + * Java and Kotlin sources are default to `main` source set since it is created by `java` plugin. + * For Proto sources to be included – [special treatment][protoSources] is needed. + */ +internal fun Project.sourcesJar(): TaskProvider = tasks.getOrCreate("sourcesJar") { + dependOnGenerateProto() + archiveClassifier.set("sources") + from(sourceSets["main"].allSource) // Puts Java and Kotlin sources. + from(protoSources()) // Puts Proto sources. + exclude("desc.ref", "*.desc") // Exclude descriptor files and the descriptor reference. +} + +/** + * Locates or creates `protoJar` task in this [Project]. + * + * The output of this task is a `jar` archive. The archive contains only + * [Proto sources][protoSources] from `main` source set. + */ +internal fun Project.protoJar(): TaskProvider = tasks.getOrCreate("protoJar") { + dependOnGenerateProto() + archiveClassifier.set("proto") + from(protoSources()) +} + +/** + * Locates or creates `testJar` task in this [Project]. + * + * The output of this task is a `jar` archive. The archive contains compilation output + * of `test` source set. + */ +internal fun Project.testJar(): TaskProvider = tasks.getOrCreate("testJar") { + archiveClassifier.set("test") + from(sourceSets["test"].output) +} + +/** + * Locates or creates `javadocJar` task in this [Project]. + * + * The output of this task is a `jar` archive. The archive contains Javadoc, + * generated upon Java sources from `main` source set. If javadoc for Kotlin is also needed, + * apply Dokka plugin. It tunes `javadoc` task to generate docs upon Kotlin sources as well. + */ +fun Project.javadocJar(): TaskProvider = tasks.getOrCreate("javadocJar") { + archiveClassifier.set("javadoc") + val javadocFiles = layout.buildDirectory.files("/docs/javadoc") + from(javadocFiles) + dependsOn("javadoc") +} + +internal fun TaskContainer.getOrCreate(name: String, init: Jar.() -> Unit): TaskProvider = + if (names.contains(name)) { + named(name) + } else { + register(name) { + init() + } + } + +/** + * Obtains as a set of [Jar] tasks, output of which is used as Maven artifacts. + * + * By default, only a jar with Java compilation output is included into publication. This method + * registers tasks which produce additional artifacts according to the values of [jarFlags]. + * + * @return the list of the registered tasks. + */ +internal fun Project.artifacts(jarFlags: JarFlags): Set> { + val tasks = mutableSetOf>() + + if (jarFlags.sourcesJar) { + tasks.add(sourcesJar()) + } + + if (jarFlags.javadocJar) { + tasks.add(javadocJar()) + } + + // We don't want to have an empty "proto.jar" when a project doesn't have any Proto files. + if (hasProto() && jarFlags.publishProtoJar) { + tasks.add(protoJar()) + } + + // Here, we don't have the corresponding `hasTests()` check, since this artifact is disabled + // by default. And turning it on means "We have tests and need them to be published." + if (jarFlags.publishTestJar) { + tasks.add(testJar()) + } + +/* if (jarFlags.publishDokkaKotlinJar) { + tasks.add(dokkaKotlinJar()) + }*/ + + return tasks +} diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/PublishingRepos.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/PublishingRepos.kt new file mode 100644 index 0000000..0de3080 --- /dev/null +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/PublishingRepos.kt @@ -0,0 +1,42 @@ +/* + * Copyright 2024, 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.internal.gradle.publish + +import io.spine.internal.gradle.Repository + +/** + * Repositories to which we may publish. + */ +object PublishingRepos { + + val cloudArtifactRegistry = CloudArtifactRegistry.repository + + /** + * Obtains a GitHub repository by the given name. + */ + fun gitHub(repoName: String): Repository = GitHubPackages.repository(repoName) +} diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/SpinePublishing.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/SpinePublishing.kt new file mode 100644 index 0000000..74ed0a3 --- /dev/null +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/SpinePublishing.kt @@ -0,0 +1,452 @@ +/* + * Copyright 2024, 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. + */ + +@file:Suppress("TooManyFunctions") + +package io.spine.internal.gradle.publish + +import io.spine.internal.gradle.Repository +import org.gradle.api.Project +import org.gradle.api.publish.maven.plugins.MavenPublishPlugin +import org.gradle.kotlin.dsl.apply +import org.gradle.kotlin.dsl.create +import org.gradle.kotlin.dsl.findByType + +/** + * Configures [SpinePublishing] extension. + * + * This extension sets up publishing of artifacts to Maven repositories. + * + * The extension can be configured for single- and multi-module projects. + * + * When used with a multi-module project, the extension should be opened in a root project's + * build file. The published modules are specified explicitly by their names: + * + * ``` + * spinePublishing { + * modules = setOf( + * "subprojectA", + * "subprojectB", + * ) + * destinations = setOf( + * PublishingRepos.cloudRepo, + * PublishingRepos.cloudArtifactRegistry, + * ) + * } + * ``` + * + * When used with a single-module project, the extension should be opened in a project's build file. + * Only destinations should be specified: + * + * ``` + * spinePublishing { + * destinations = setOf( + * PublishingRepos.cloudRepo, + * PublishingRepos.cloudArtifactRegistry, + * ) + * } + * ``` + * + * It is worth to mention, that publishing of a module can be configured only from a single place. + * For example, declaring `subprojectA` as published in a root project and opening + * `spinePublishing` extension within `subprojectA` itself would lead to an exception. + * + * In Gradle, in order to publish something somewhere one should create a publication. In each + * of published modules, the extension will create a [publication][StandardJavaPublicationHandler] + * named "mavenJava". All artifacts, published by this extension belong to this publication. + * + * By default, along with the compilation output of "main" source set, the extension publishes + * the following artifacts: + * + * 1. [sourcesJar] – sources from "main" source set. Includes "hand-made" Java, + * Kotlin and Proto files. In order to include the generated code into this artifact, a module + * should specify those files as a part of "main" source set. + * + * Here's an example of how to do that: + * + * ``` + * sourceSets { + * val generatedDir by extra("$projectDir/generated") + * val generatedSpineDir by extra("$generatedDir/main/java") + * main { + * java.srcDir(generatedSpineDir) + * } + * } + * ``` + * 2. [protoJar] – only Proto sources from "main" source set. It's published only if + * Proto files are actually present in the source set. Publication of this artifact is optional + * and can be disabled via [SpinePublishing.protoJar]. + * 3. [javadocJar] - javadoc, generated upon Java sources from "main" source set. + * If javadoc for Kotlin is also needed, apply Dokka plugin. It tunes `javadoc` task to generate + * docs upon Kotlin sources as well. + * 4. [dokkaKotlinJar] - documentation generated by Dokka for Kotlin and Java sources + * using the Kotlin API mode. + * 5. [dokkaJavaJar] - documentation generated by Dokka for Kotlin and Java sources + * * using the Java API mode. + * + * Additionally, [testJar] artifact can be published. This artifact contains compilation output + * of "test" source set. Use [SpinePublishing.testJar] to enable its publishing. + * + * @see [artifacts] + */ +fun Project.spinePublishing(block: SpinePublishing.() -> Unit) { + apply() + val name = SpinePublishing::class.java.simpleName + val extension = with(extensions) { + findByType() ?: create(name, project) + } + extension.run { + block() + configured() + } +} + +/** + * A Gradle extension for setting up publishing of spine modules using `maven-publish` plugin. + * + * @param project + * a project in which the extension is opened. By default, this project will be + * published as long as a [set][modules] of modules to publish is not specified explicitly. + * + * @see spinePublishing + */ +open class SpinePublishing(private val project: Project) { + + private val protoJar = ProtoJar() + private val testJar = TestJar() + private val dokkaJar = DokkaJar() + + /** + * Set of modules to be published. + * + * Both the module's name or path can be used. + * + * Use this property if the extension is configured from a root project's build file. + * + * If left empty, the [project], in which the extension is opened, will be published. + * + * Empty by default. + */ + var modules: Set = emptySet() + + /** + * Controls whether the published module needs standard publications. + * + * If `true`, the module should configure publications on its own. + * Otherwise, the extension will configure standard [ones][StandardJavaPublicationHandler]. + * + * This property is analogue of [modulesWithCustomPublishing] for projects, + * for which [spinePublishing] is configured individually. + * + * Setting of this property and having a non-empty [modules] will lead + * to an exception. + * + * Default value is `false`. + */ + var customPublishing = false + + /** + * Set of modules that have custom publications and do not need standard ones. + * + * Empty by default. + */ + var modulesWithCustomPublishing: Set = emptySet() + + /** + * Set of repositories, to which the resulting artifacts will be sent. + * + * Usually, Spine-related projects are published to one or more repositories, + * declared in [PublishingRepos]: + * + * ``` + * destinations = setOf( + * PublishingRepos.cloudRepo, + * PublishingRepos.cloudArtifactRegistry, + * PublishingRepos.gitHub("base"), + * ) + * ``` + * + * Empty by default. + */ + var destinations: Set = emptySet() + + /** + * A prefix to be added before the name of each artifact. + * + * The default value is "spine-". + */ + var artifactPrefix: String = "spine-" + + /** + * Allows disabling publishing of [protoJar] artifact, containing all Proto sources + * from `sourceSets.main.proto`. + * + * Here's an example of how to disable it for some of the published modules: + * + * ``` + * spinePublishing { + * modules = setOf( + * "subprojectA", + * "subprojectB", + * ) + * protoJar { + * exclusions = setOf( + * "subprojectB", + * ) + * } + * } + * ``` + * + * For all modules, or when the extension is configured within a published module itself: + * + * ``` + * spinePublishing { + * protoJar { + * disabled = true + * } + * } + * ``` + * + * The resulting artifact is available under "proto" classifier. + * For example, in Gradle 7+, one could depend on it like this: + * + * ``` + * implementation("io.spine:spine-client:$version@proto") + * ``` + */ + fun protoJar(block: ProtoJar.() -> Unit) = protoJar.run(block) + + /** + * Allows enabling publishing of [testJar] artifact, containing compilation output + * of "test" source set. + * + * Here's an example of how to enable it for some of the published modules: + * + * ``` + * spinePublishing { + * modules = setOf( + * "subprojectA", + * "subprojectB", + * ) + * testJar { + * inclusions = setOf( + * "subprojectB", + * ) + * } + * } + * ``` + * + * For all modules, or when the extension is configured within a published module itself: + * + * ``` + * spinePublishing { + * testJar { + * enabled = true + * } + * } + * ``` + * + * The resulting artifact is available under "test" classifier. For example, + * in Gradle 7+, one could depend on it like this: + * + * ``` + * implementation("io.spine:spine-client:$version@test") + * ``` + */ + fun testJar(block: TestJar.() -> Unit) = testJar.run(block) + + /** + * Configures publishing of [dokkaKotlinJar] and [dokkaJavaJar] artifacts, + * containing Dokka-generated documentation. + * + * By default, publishing of the [dokkaKotlinJar] artifact is enabled, and [dokkaJavaJar] + * is disabled. + * + * Remember that the Dokka Gradle plugin should be applied to publish this artifact as it is + * produced by the `dokkaHtml` task. It can be done by using the + * [io.spine.internal.dependency.Dokka] dependency object or by applying the + * `buildSrc/src/main/kotlin/dokka-for-kotlin` or + * `buildSrc/src/main/kotlin/dokka-for-java` script plugins. + * + * Here's an example of how to use this option: + * + * ``` + * spinePublishing { + * dokkaJar { + * kotlin = false + * java = true + * } + * } + * ``` + * + * The resulting artifact is available under "dokka" classifier. + */ + fun dokkaJar(block: DokkaJar.() -> Unit) = dokkaJar.run(block) + + /** + * Called to notify the extension that its configuration is completed. + * + * On this stage the extension will validate the received configuration and set up + * `maven-publish` plugin for each published module. + */ + internal fun configured() { + ensureProtoJarExclusionsArePublished() + ensureTestJarInclusionsArePublished() + ensureModulesNotDuplicated() + ensureCustomPublishingNotMisused() + + val projectsToPublish = projectsToPublish() + projectsToPublish.forEach { project -> + val jarFlags = JarFlags.create(project.name, protoJar, testJar, dokkaJar) + project.setUpPublishing(jarFlags) + } + } + + /** + * Maps the names of published modules to [Project] instances. + * + * The method considers two options: + * + * 1. The [set][modules] of subprojects to publish is not empty. It means that the extension + * is opened from a root project. + * 2. The [set][modules] is empty. Then, the [project] in which the extension is opened + * will be published. + * + * @see modules + */ + private fun projectsToPublish(): Collection { + if (project.subprojects.isEmpty()) { + return setOf(project) + } + return modules.union(modulesWithCustomPublishing) + .map { name -> project.project(name) } + .ifEmpty { setOf(project) } + } + + /** + * Sets up `maven-publish` plugin for the given project. + * + * Firstly, an instance of [PublicationHandler] is created for the project depending + * on the nature of the publication process configured. + * Then, this the handler is scheduled to apply on [Project.afterEvaluate]. + * + * General rule of thumb is to avoid using [Project.afterEvaluate] of this closure, + * as it configures a project when its configuration is considered completed. + * Which is quite counter-intuitive. + * + * We selected to use [Project.afterEvaluate] so that we can configure publishing of multiple + * modules from a root project. When we do this, we configure publishing for a module, + * build file of which has not been even evaluated yet. + * + * The simplest example here is specifying of `version` and `group` for Maven coordinates. + * Let's suppose, they are declared in a module's build file. It is a common practice. + * But publishing of the module is configured from a root project's build file. By the time, + * when we need to specify them, we just don't know them. As a result, we have to use + * [Project.afterEvaluate] in order to guarantee that a module will be configured by the time + * we configure publishing for it. + */ + private fun Project.setUpPublishing(jarFlags: JarFlags) { + val customPublishing = modulesWithCustomPublishing.contains(name) || customPublishing + val handler = if (customPublishing) { + CustomPublicationHandler(project, destinations) + } else { + StandardJavaPublicationHandler(project, jarFlags, destinations) + } + afterEvaluate { + handler.apply() + } + } + + /** + * Obtains an artifact ID for the given project. + * + * It consists of a project's name and [prefix][artifactPrefix]: + * ``. + */ + fun artifactId(project: Project): String = "$artifactPrefix${project.name}" + + /** + * Ensures that all modules, marked as excluded from [protoJar] publishing, + * are actually published. + * + * It makes no sense to tell a module don't publish [protoJar] artifact, if the module is not + * published at all. + */ + private fun ensureProtoJarExclusionsArePublished() { + val nonPublishedExclusions = protoJar.exclusions.minus(modules) + if (nonPublishedExclusions.isNotEmpty()) { + throw IllegalStateException("One or more modules are marked as `excluded from proto " + + "JAR publication`, but they are not even published: $nonPublishedExclusions") + } + } + + /** + * Ensures that all modules, marked as included into [testJar] publishing, + * are actually published. + * + * It makes no sense to tell a module publish [testJar] artifact, if the module is not + * published at all. + */ + private fun ensureTestJarInclusionsArePublished() { + val nonPublishedInclusions = testJar.inclusions.minus(modules) + if (nonPublishedInclusions.isNotEmpty()) { + error( + "One or more modules are marked as `included into test JAR publication`," + + " but they are not even published: $nonPublishedInclusions." + ) + } + } + + /** + * Ensures that publishing of a module is configured only from a single place. + * + * We allow configuration of publishing from two places - a root project and module itself. + * Here we verify that publishing of a module is not configured in both places simultaneously. + */ + private fun ensureModulesNotDuplicated() { + val rootProject = project.rootProject + if (rootProject == project) { + return + } + + val rootExtension = with(rootProject.extensions) { findByType() } + rootExtension?.let { rootPublishing -> + val thisProject = setOf(project.name, project.path) + if (thisProject.minus(rootPublishing.modules).size != 2) { + error( + "Publishing of `$thisProject` module is already configured in a root project!" + ) + } + } + } + + private fun ensureCustomPublishingNotMisused() { + if (modules.isNotEmpty() && customPublishing) { + error("`customPublishing` property can be set only if `spinePublishing` extension " + + "is open in an individual module, so `modules` property should be empty.") + } + } +} diff --git a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/ApplySizeOptionPlugin.kt b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/ApplySizeOptionPlugin.kt index a64df49..2acbf8d 100644 --- a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/ApplySizeOptionPlugin.kt +++ b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/ApplySizeOptionPlugin.kt @@ -51,6 +51,9 @@ import io.spine.protodata.renderer.Renderer public class ApplySizeOptionPlugin : Plugin { override fun renderers(): List> { + + println("============================== Plugin renderers()") + // A container for collecting generated validation methods, which should // later be added to the `build` method of the message builder class. val builderValidationMethods = BuilderValidationMethods() @@ -62,6 +65,9 @@ public class ApplySizeOptionPlugin : Plugin { } override fun viewRepositories(): Set> { + + println("============================== Plugin viewRepositories()") + return setOf(SizeOptionViewRepository()) } } diff --git a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/SizeOptionView.kt b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/SizeOptionView.kt index 3f2daec..5e21ce5 100644 --- a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/SizeOptionView.kt +++ b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/SizeOptionView.kt @@ -50,13 +50,16 @@ internal class SizeOptionView : View() { + override fun setupEventRouting(routing: EventRouting) { super.setupEventRouting(routing) routing.route(FieldOptionDiscovered::class.java) diff --git a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/ValidateSizeOptionRenderer.kt b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/ValidateSizeOptionRenderer.kt index ff164a9..c989383 100644 --- a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/ValidateSizeOptionRenderer.kt +++ b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/ValidateSizeOptionRenderer.kt @@ -55,7 +55,15 @@ public class ValidateSizeOptionRenderer( return } - select(SizeOption::class.java).all() + println("============================== Execute ValidateSizeOptionRenderer") + + val sizeOptions = select(SizeOption::class.java).all() + + sizeOptions.forEach { + println("============================== SizeOption: $it") + } + + sizeOptions // Separate all size options by pair File+Type, so we can // generate one builder extension for options within one Type. .groupBy { sizeOption -> @@ -69,6 +77,8 @@ public class ValidateSizeOptionRenderer( builderValidationMethods ) + println("============================== Generator Created") + sources.createFile( generator.filePath(), generator.fileContent() diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b1624c4..c7d437b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.4-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/ApplySizeOptionPluginTest.kt b/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/ApplySizeOptionPluginTest.kt index d4c5459..d578672 100644 --- a/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/ApplySizeOptionPluginTest.kt +++ b/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/ApplySizeOptionPluginTest.kt @@ -30,7 +30,7 @@ import io.spine.tools.gradle.testing.GradleProject import io.spine.tools.mc.java.gradle.McJavaTaskName import org.gradle.testkit.runner.UnexpectedBuildFailure import org.gradle.testkit.runner.internal.DefaultGradleRunner -//import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Assertions.fail import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test @@ -158,15 +158,15 @@ class `ApplySizeOptionPlugin should` { } val sdterrContent = stderr.toString() - val errorFound = sdterrContent.contains("###$expectedExceptionMessage") + val errorFound = sdterrContent.contains(expectedExceptionMessage) - if (!errorFound) { - fail(sdterrContent) - } + System.err.println(sdterrContent) + + //check(errorFound) { sdterrContent } -/* assertTrue( + assertTrue( errorFound, "The expected exception was not thrown." - )*/ + ) } } diff --git a/integration-tests/src/test/resources/test-project/build.gradle.kts b/integration-tests/src/test/resources/test-project/build.gradle.kts index 725e0c5..8064db3 100644 --- a/integration-tests/src/test/resources/test-project/build.gradle.kts +++ b/integration-tests/src/test/resources/test-project/build.gradle.kts @@ -50,7 +50,7 @@ buildscript { plugins { kotlin("jvm") id("com.google.protobuf") - id("io.spine.protodata") version "0.20.7" + id("io.spine.protodata") version "0.50.0" } object BuildSettings { diff --git a/model/build.gradle.kts b/model/build.gradle.kts index 5bc0668..436776e 100644 --- a/model/build.gradle.kts +++ b/model/build.gradle.kts @@ -25,13 +25,38 @@ import io.spine.internal.dependency.JUnit import io.spine.internal.dependency.Validation +import io.spine.protodata.gradle.CodegenSettings + +//buildscript { + //standardSpineSdkRepositories() + //apply(from = "$rootDir/../version.gradle.kts") + //val protoDataVersion: String by extra +// dependencies { +// classpath("io.spine.protodata:io.spine.protodata.gradle.plugin:0.50.0") +// } +//} + +buildscript { + standardSpineSdkRepositories() + dependencies { + classpath(io.spine.internal.dependency.Spine.McJava.pluginLib) + } +} dependencies { // Enable field options extension. - api(project(":proto-extension")) + //api(project(":proto-extension")) // Add module with code generation plugin to ProtoData classpath. - protoData(project(":codegen-plugin")) + //protoData(project(":codegen-plugin")) + + val extensionSubproject = project(":proto-extension") + "protoData"(extensionSubproject) + implementation(extensionSubproject) + + val pluginsSubproject = project(":codegen-plugin") + "protoData"(pluginsSubproject) + implementation(pluginsSubproject) // To allow access to `ValidatingBuilder` from the generated Kotlin code. implementation(Validation.runtime) @@ -39,15 +64,19 @@ dependencies { testImplementation(JUnit.runner) } -apply { - plugin("io.spine.protodata") -} +apply(plugin = "io.spine.protodata") -protoData { +/*protoData { // Run ProtoData with the `size` option plugin enabled. plugins( "io.spine.examples.protodata.hello.plugin.ApplySizeOptionPlugin" ) +}*/ + +extensions.getByType().apply { + plugins( + "io.spine.examples.protodata.hello.plugin.ApplySizeOptionPlugin" + ) } modelCompiler { diff --git a/proto-extension/build.gradle.kts b/proto-extension/build.gradle.kts index ec93717..f4b8d46 100644 --- a/proto-extension/build.gradle.kts +++ b/proto-extension/build.gradle.kts @@ -33,7 +33,8 @@ plugins { dependencies { // To use @AutoService in options provider - implementation(AutoService.annotations) + annotationProcessor(AutoService.processor) + compileOnly(AutoService.annotations) // To allow access to `ValidatingBuilder` from the generated Kotlin code. implementation(Validation.runtime) From c52a9f51dd8d1c96ae430179df452b7be33d7260 Mon Sep 17 00:00:00 2001 From: Alex Tymchenko Date: Mon, 29 Jul 2024 16:00:20 +0100 Subject: [PATCH 06/13] Use KSP annotation processor. Bring back `@External` annotation. --- .../io/spine/internal/dependency/Auto.kt | 12 ++++++ .../protodata/hello/plugin/SizeOptionView.kt | 2 +- model/build.gradle.kts | 41 ++++--------------- proto-extension/build.gradle.kts | 3 ++ 4 files changed, 25 insertions(+), 33 deletions(-) diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Auto.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Auto.kt index 1a6aa0b..f09315d 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Auto.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Auto.kt @@ -47,3 +47,15 @@ object AutoValue { private const val version = "1.10.2" const val annotations = "com.google.auto.value:auto-value-annotations:${version}" } + + +// https://github.com/ZacSweers/auto-service-ksp +object AutoServiceKsp { + /** + * The latest version compatible with Kotlin 1.8.22. + * + * @see Ksp.version + */ + private const val version = "1.1.0" + const val processor = "dev.zacsweers.autoservice:auto-service-ksp:$version" +} diff --git a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/SizeOptionView.kt b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/SizeOptionView.kt index 5e21ce5..d23320f 100644 --- a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/SizeOptionView.kt +++ b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/SizeOptionView.kt @@ -49,7 +49,7 @@ internal class SizeOptionView : View().apply { - plugins( - "io.spine.examples.protodata.hello.plugin.ApplySizeOptionPlugin" - ) } +//extensions.getByType().apply { +// plugins( +// "io.spine.examples.protodata.hello.plugin.ApplySizeOptionPlugin" +// ) +//} + modelCompiler { java { codegen { diff --git a/proto-extension/build.gradle.kts b/proto-extension/build.gradle.kts index f4b8d46..9d3947a 100644 --- a/proto-extension/build.gradle.kts +++ b/proto-extension/build.gradle.kts @@ -24,17 +24,20 @@ */ import io.spine.internal.dependency.AutoService +import io.spine.internal.dependency.AutoServiceKsp import io.spine.internal.dependency.HelloProtoData import io.spine.internal.dependency.Validation plugins { `maven-publish` + ksp } dependencies { // To use @AutoService in options provider annotationProcessor(AutoService.processor) compileOnly(AutoService.annotations) + ksp(AutoServiceKsp.processor) // To allow access to `ValidatingBuilder` from the generated Kotlin code. implementation(Validation.runtime) From a01c07fba65260bf4a0fe1335f7de6c1ec86cbed Mon Sep 17 00:00:00 2001 From: "oleg.melnik" Date: Tue, 30 Jul 2024 14:53:32 +0300 Subject: [PATCH 07/13] Update integration tests build script. Cleanup code. --- build.gradle.kts | 2 -- .../hello/plugin/ApplySizeOptionPlugin.kt | 6 ------ .../hello/plugin/BuilderBeforeReturnRenderer.kt | 2 +- .../hello/plugin/BuilderValidationMethods.kt | 13 +------------ .../protodata/hello/plugin/SizeOptionView.kt | 10 ++++------ .../hello/plugin/ValidateSizeOptionRenderer.kt | 15 ++------------- .../test/resources/test-project/build.gradle.kts | 2 -- model/build.gradle.kts | 12 +++--------- proto-extension/build.gradle.kts | 3 +-- 9 files changed, 12 insertions(+), 53 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index f9d9fec..dd0e486 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -46,8 +46,6 @@ buildscript { dependencies { classpath(io.spine.internal.dependency.Spine.McJava.pluginLib) - classpath(io.spine.internal.dependency.Protobuf.GradlePlugin.lib) - classpath(io.spine.internal.dependency.Kotlin.gradlePluginLib) } } diff --git a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/ApplySizeOptionPlugin.kt b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/ApplySizeOptionPlugin.kt index 2acbf8d..a64df49 100644 --- a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/ApplySizeOptionPlugin.kt +++ b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/ApplySizeOptionPlugin.kt @@ -51,9 +51,6 @@ import io.spine.protodata.renderer.Renderer public class ApplySizeOptionPlugin : Plugin { override fun renderers(): List> { - - println("============================== Plugin renderers()") - // A container for collecting generated validation methods, which should // later be added to the `build` method of the message builder class. val builderValidationMethods = BuilderValidationMethods() @@ -65,9 +62,6 @@ public class ApplySizeOptionPlugin : Plugin { } override fun viewRepositories(): Set> { - - println("============================== Plugin viewRepositories()") - return setOf(SizeOptionViewRepository()) } } diff --git a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderBeforeReturnRenderer.kt b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderBeforeReturnRenderer.kt index 11fee9a..3537758 100644 --- a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderBeforeReturnRenderer.kt +++ b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderBeforeReturnRenderer.kt @@ -49,7 +49,7 @@ public class BuilderBeforeReturnRenderer( } sources.filter { - builderValidationMethods.hasMethods(it.relativePath) + builderValidationMethods.methods(it.relativePath).isNotEmpty() }.forEach { insertValidationMethodsInvocation(it) } diff --git a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderValidationMethods.kt b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderValidationMethods.kt index fee1582..89825a8 100644 --- a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderValidationMethods.kt +++ b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderValidationMethods.kt @@ -48,17 +48,6 @@ public class BuilderValidationMethods { methodMap.put(javaSourceFilePath, validationMethod) } - /** - * Checks that some builder validation methods are associated - * with the given Java source file. - * - * @param javaSourceFilePath - * a [Path] to the generated java file. - */ - public fun hasMethods(javaSourceFilePath: Path): Boolean { - return methodMap.containsKey(javaSourceFilePath) - } - /** * Returns the list of validation methods that are associated * with the given Java source file. @@ -66,7 +55,7 @@ public class BuilderValidationMethods { * @param javaSourceFilePath * a [Path] to the generated java file. */ - public fun methods(javaSourceFilePath: Path): Iterable { + public fun methods(javaSourceFilePath: Path): Collection { return methodMap.get(javaSourceFilePath) } } diff --git a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/SizeOptionView.kt b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/SizeOptionView.kt index d23320f..3857046 100644 --- a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/SizeOptionView.kt +++ b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/SizeOptionView.kt @@ -49,17 +49,15 @@ internal class SizeOptionView : View @@ -76,9 +68,6 @@ public class ValidateSizeOptionRenderer( mapEntry.value, builderValidationMethods ) - - println("============================== Generator Created") - sources.createFile( generator.filePath(), generator.fileContent() @@ -94,7 +83,7 @@ public class ValidateSizeOptionRenderer( it.file.path == file.path } checkNotNull(sourceFile) { - "Cannot find 'ProtobufSourceFile' for ${file.path}." + "Cannot find `ProtobufSourceFile` for ${file.path}." } return sourceFile } diff --git a/integration-tests/src/test/resources/test-project/build.gradle.kts b/integration-tests/src/test/resources/test-project/build.gradle.kts index 8064db3..5e25186 100644 --- a/integration-tests/src/test/resources/test-project/build.gradle.kts +++ b/integration-tests/src/test/resources/test-project/build.gradle.kts @@ -59,9 +59,7 @@ object BuildSettings { val javaVersion: JavaLanguageVersion = JavaLanguageVersion.of(JAVA_VERSION) } - allprojects { - // Define the repositories universally for all modules, including the root. repositories.standardToSpineSdk() diff --git a/model/build.gradle.kts b/model/build.gradle.kts index e6cecea..5bc0668 100644 --- a/model/build.gradle.kts +++ b/model/build.gradle.kts @@ -25,8 +25,6 @@ import io.spine.internal.dependency.JUnit import io.spine.internal.dependency.Validation -import io.spine.protodata.gradle.CodegenSettings - dependencies { // Enable field options extension. @@ -41,7 +39,9 @@ dependencies { testImplementation(JUnit.runner) } -apply(plugin = "io.spine.protodata") +apply { + plugin("io.spine.protodata") +} protoData { // Run ProtoData with the `size` option plugin enabled. @@ -50,12 +50,6 @@ protoData { ) } -//extensions.getByType().apply { -// plugins( -// "io.spine.examples.protodata.hello.plugin.ApplySizeOptionPlugin" -// ) -//} - modelCompiler { java { codegen { diff --git a/proto-extension/build.gradle.kts b/proto-extension/build.gradle.kts index 9d3947a..c1b40b1 100644 --- a/proto-extension/build.gradle.kts +++ b/proto-extension/build.gradle.kts @@ -34,8 +34,7 @@ plugins { } dependencies { - // To use @AutoService in options provider - annotationProcessor(AutoService.processor) + // To use @AutoService in options provider. compileOnly(AutoService.annotations) ksp(AutoServiceKsp.processor) From 8d5c76e986e7f8150755a43d958ecd5d074e5e7b Mon Sep 17 00:00:00 2001 From: "oleg.melnik" Date: Tue, 30 Jul 2024 15:24:05 +0300 Subject: [PATCH 08/13] Update license header. --- LICENSE | 2 +- README.md | 2 +- build.gradle.kts | 2 +- buildSrc/build.gradle.kts | 2 +- buildSrc/src/main/kotlin/BuildSettings.kt | 2 +- .../src/main/kotlin/DependencyResolution.kt | 2 +- .../main/kotlin/build-proto-model.gradle.kts | 2 +- .../src/main/kotlin/config-tester.gradle.kts | 2 +- .../kotlin/detekt-code-analysis.gradle.kts | 2 +- .../io/spine/internal/dependency/Asm.kt | 2 +- .../io/spine/internal/dependency/Auto.kt | 2 +- .../spine/internal/dependency/CheckStyle.kt | 2 +- .../internal/dependency/CheckerFramework.kt | 2 +- .../spine/internal/dependency/CommonsCli.kt | 2 +- .../spine/internal/dependency/CommonsCodec.kt | 2 +- .../internal/dependency/CommonsLogging.kt | 2 +- .../spine/internal/dependency/ErrorProne.kt | 2 +- .../io/spine/internal/dependency/FindBugs.kt | 2 +- .../io/spine/internal/dependency/Flogger.kt | 2 +- .../spine/internal/dependency/GoogleApis.kt | 2 +- .../spine/internal/dependency/GradleDoctor.kt | 2 +- .../io/spine/internal/dependency/Grpc.kt | 2 +- .../io/spine/internal/dependency/Gson.kt | 2 +- .../io/spine/internal/dependency/Guava.kt | 2 +- .../io/spine/internal/dependency/Hamcrest.kt | 2 +- .../internal/dependency/HelloProtoData.kt | 2 +- .../io/spine/internal/dependency/J2ObjC.kt | 2 +- .../io/spine/internal/dependency/JUnit.kt | 2 +- .../io/spine/internal/dependency/Jackson.kt | 2 +- .../internal/dependency/JavaDiffUtils.kt | 2 +- .../io/spine/internal/dependency/JavaPoet.kt | 2 +- .../io/spine/internal/dependency/JavaX.kt | 2 +- .../io/spine/internal/dependency/Klaxon.kt | 2 +- .../io/spine/internal/dependency/Kotest.kt | 2 +- .../io/spine/internal/dependency/Kotlin.kt | 2 +- .../spine/internal/dependency/KotlinPoet.kt | 2 +- .../spine/internal/dependency/KotlinSemver.kt | 2 +- .../io/spine/internal/dependency/KotlinX.kt | 2 +- .../io/spine/internal/dependency/Kover.kt | 2 +- .../spine/internal/dependency/OpenTest4J.kt | 2 +- .../io/spine/internal/dependency/ProtoData.kt | 2 +- .../io/spine/internal/dependency/Protobuf.kt | 2 +- .../io/spine/internal/dependency/Roaster.kt | 2 +- .../io/spine/internal/dependency/Slf4J.kt | 2 +- .../spine/internal/dependency/TestKitTruth.kt | 2 +- .../io/spine/internal/dependency/Truth.kt | 2 +- .../spine/internal/dependency/Validation.kt | 2 +- .../kotlin/io/spine/internal/gradle/Build.kt | 2 +- .../kotlin/io/spine/internal/gradle/Clean.kt | 2 +- .../io/spine/internal/gradle/ConfigTester.kt | 2 +- .../internal/gradle/ProjectExtensions.kt | 22 +- .../io/spine/internal/gradle/Repositories.kt | 2 +- .../io/spine/internal/gradle/RunBuild.kt | 2 +- .../io/spine/internal/gradle/RunGradle.kt | 2 +- .../io/spine/internal/gradle/Runtime.kt | 2 +- .../spine/internal/gradle/StringExtensions.kt | 2 +- .../io/spine/internal/gradle/TaskName.kt | 2 +- .../io/spine/internal/gradle/base/Tasks.kt | 2 +- .../gradle/checkstyle/CheckStyleConfig.kt | 2 +- .../spine/internal/gradle/fs/LazyTempPath.kt | 2 +- .../io/spine/internal/gradle/java/Tasks.kt | 2 +- .../spine/internal/gradle/javac/ErrorProne.kt | 2 +- .../io/spine/internal/gradle/javac/Javac.kt | 2 +- .../internal/gradle/kotlin/KotlinConfig.kt | 2 +- .../gradle/protobuf/ProtoTaskExtensions.kt | 2 +- .../gradle/publish/CheckVersionIncrement.kt | 129 ----- .../gradle/publish/CloudArtifactRegistry.kt | 3 +- .../internal/gradle/publish/CloudRepo.kt | 2 +- .../internal/gradle/publish/GitHubPackages.kt | 2 +- .../internal/gradle/publish/IncrementGuard.kt | 109 ----- .../spine/internal/gradle/publish/JarDsl.kt | 167 ------- .../internal/gradle/publish/ProtoExts.kt | 89 ---- .../internal/gradle/publish/Publications.kt | 234 --------- .../internal/gradle/publish/PublishingExts.kt | 276 ----------- .../gradle/publish/SpinePublishing.kt | 452 ------------------ .../spine/internal/gradle/testing/Logging.kt | 2 +- .../io/spine/internal/gradle/testing/Tasks.kt | 2 +- codegen-plugin/build.gradle.kts | 2 +- .../hello/plugin/ApplySizeOptionPlugin.kt | 2 +- .../BuilderBeforeReturnInsertionPoint.kt | 2 +- .../plugin/BuilderBeforeReturnRenderer.kt | 2 +- .../hello/plugin/BuilderExtensionGenerator.kt | 2 +- .../hello/plugin/BuilderValidationMethods.kt | 2 +- .../protodata/hello/plugin/SizeOptionView.kt | 2 +- .../hello/plugin/SizeOptionViewRepository.kt | 2 +- .../plugin/ValidateSizeOptionRenderer.kt | 2 +- .../protodata/hello/plugin/package-info.java | 2 +- .../protodata/hello/plugin/size_option.proto | 2 +- config | 2 +- gradle.properties | 2 +- integration-tests/build.gradle.kts | 2 +- .../hello/test/ApplySizeOptionPluginTest.kt | 2 +- .../examples/protodata/hello/test/TestEnv.kt | 2 +- .../protodata/hello/test/package-info.java | 2 +- .../protodata/hello/test/contact.proto | 2 +- .../empty_expression_value.proto | 2 +- .../negative-cases/non_repeated_field.proto | 2 +- .../resources/test-project/build.gradle.kts | 2 +- .../test-project/model/build.gradle.kts | 2 +- .../test-project/settings.gradle.kts | 2 +- model/build.gradle.kts | 2 +- .../protodata/hello/model/tictactoe.proto | 2 +- .../hello/model/test/SizeOptionPluginTest.kt | 2 +- .../hello/model/test/package-info.java | 2 +- proto-extension/build.gradle.kts | 2 +- .../hello/ArrayOfSizeOptionProvider.kt | 2 +- .../protodata/hello/package-info.java | 2 +- .../examples/protodata/hello/options.proto | 2 +- settings.gradle.kts | 2 +- version.gradle.kts | 2 +- 110 files changed, 103 insertions(+), 1580 deletions(-) delete mode 100644 buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/CheckVersionIncrement.kt delete mode 100644 buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/IncrementGuard.kt delete mode 100644 buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/JarDsl.kt delete mode 100644 buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/ProtoExts.kt delete mode 100644 buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/Publications.kt delete mode 100644 buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/PublishingExts.kt delete mode 100644 buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/SpinePublishing.kt diff --git a/LICENSE b/LICENSE index 261eeb9..b447376 100644 --- a/LICENSE +++ b/LICENSE @@ -192,7 +192,7 @@ 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 + https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/README.md b/README.md index cf95ddd..046fe9f 100644 --- a/README.md +++ b/README.md @@ -205,7 +205,7 @@ git clone git@github.com:spine-examples/Hello-ProtoData.git [ubuntu-build-badge]: https://github.com/spine-examples/Hello-ProtoData/actions/workflows/build-on-ubuntu.yml/badge.svg [windows-build-badge]: https://github.com/spine-examples/Hello-ProtoData/actions/workflows/build-on-windows.yml/badge.svg [license-badge]: https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat -[apache-license]: http://www.apache.org/licenses/LICENSE-2.0 +[apache-license]: https://www.apache.org/licenses/LICENSE-2.0 [proto3-options]: https://protobuf.dev/programming-guides/proto3/#options [descriptor-proto]: https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto diff --git a/build.gradle.kts b/build.gradle.kts index dd0e486..67a5afb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 4d4be39..961c0c7 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/BuildSettings.kt b/buildSrc/src/main/kotlin/BuildSettings.kt index c59242c..f342979 100644 --- a/buildSrc/src/main/kotlin/BuildSettings.kt +++ b/buildSrc/src/main/kotlin/BuildSettings.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/DependencyResolution.kt b/buildSrc/src/main/kotlin/DependencyResolution.kt index 70551a8..50e1e6a 100644 --- a/buildSrc/src/main/kotlin/DependencyResolution.kt +++ b/buildSrc/src/main/kotlin/DependencyResolution.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/build-proto-model.gradle.kts b/buildSrc/src/main/kotlin/build-proto-model.gradle.kts index 2215e25..5721ed3 100644 --- a/buildSrc/src/main/kotlin/build-proto-model.gradle.kts +++ b/buildSrc/src/main/kotlin/build-proto-model.gradle.kts @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/config-tester.gradle.kts b/buildSrc/src/main/kotlin/config-tester.gradle.kts index e993fe6..faf3113 100644 --- a/buildSrc/src/main/kotlin/config-tester.gradle.kts +++ b/buildSrc/src/main/kotlin/config-tester.gradle.kts @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/detekt-code-analysis.gradle.kts b/buildSrc/src/main/kotlin/detekt-code-analysis.gradle.kts index 15310b8..503114d 100644 --- a/buildSrc/src/main/kotlin/detekt-code-analysis.gradle.kts +++ b/buildSrc/src/main/kotlin/detekt-code-analysis.gradle.kts @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Asm.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Asm.kt index a5f2b4b..2236c51 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Asm.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Asm.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Auto.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Auto.kt index f09315d..53deb5f 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Auto.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Auto.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/CheckStyle.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/CheckStyle.kt index af9e631..aa68719 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/CheckStyle.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/CheckStyle.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/CheckerFramework.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/CheckerFramework.kt index 4f1ee56..eb7cdef 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/CheckerFramework.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/CheckerFramework.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/CommonsCli.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/CommonsCli.kt index 2ab034e..c47d11c 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/CommonsCli.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/CommonsCli.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/CommonsCodec.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/CommonsCodec.kt index 255b8bb..e7d30bc 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/CommonsCodec.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/CommonsCodec.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/CommonsLogging.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/CommonsLogging.kt index 1850fa3..6e36c12 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/CommonsLogging.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/CommonsLogging.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/ErrorProne.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/ErrorProne.kt index 3b3cc5b..e434272 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/ErrorProne.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/ErrorProne.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/FindBugs.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/FindBugs.kt index 14ec016..3658429 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/FindBugs.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/FindBugs.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Flogger.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Flogger.kt index e2ad74f..a48812f 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Flogger.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Flogger.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/GoogleApis.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/GoogleApis.kt index 79a1991..6273a4c 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/GoogleApis.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/GoogleApis.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/GradleDoctor.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/GradleDoctor.kt index ae24fbd..6e70adf 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/GradleDoctor.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/GradleDoctor.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Grpc.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Grpc.kt index 04b31df..0280cb4 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Grpc.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Grpc.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Gson.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Gson.kt index b6814f3..e9b60fb 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Gson.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Gson.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Guava.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Guava.kt index c0f7892..7fa8eaf 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Guava.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Guava.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Hamcrest.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Hamcrest.kt index effc3fe..f8f8a17 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Hamcrest.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Hamcrest.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/HelloProtoData.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/HelloProtoData.kt index 78c8aed..0d4eebe 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/HelloProtoData.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/HelloProtoData.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/J2ObjC.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/J2ObjC.kt index bf04e03..0e5ed49 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/J2ObjC.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/J2ObjC.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/JUnit.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/JUnit.kt index f25a63a..82196fe 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/JUnit.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/JUnit.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Jackson.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Jackson.kt index 6425fb5..445d13f 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Jackson.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Jackson.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/JavaDiffUtils.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/JavaDiffUtils.kt index fb21638..b69b8d0 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/JavaDiffUtils.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/JavaDiffUtils.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/JavaPoet.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/JavaPoet.kt index ca1079c..00194a4 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/JavaPoet.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/JavaPoet.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/JavaX.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/JavaX.kt index bf74fa0..e0e7c1e 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/JavaX.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/JavaX.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Klaxon.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Klaxon.kt index d673152..3188599 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Klaxon.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Klaxon.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Kotest.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Kotest.kt index 81b18a7..ac1dee3 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Kotest.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Kotest.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Kotlin.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Kotlin.kt index 86ca664..a6ce58a 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Kotlin.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Kotlin.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/KotlinPoet.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/KotlinPoet.kt index 7d205d8..f5e9095 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/KotlinPoet.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/KotlinPoet.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/KotlinSemver.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/KotlinSemver.kt index 21d4d6c..1c3b783 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/KotlinSemver.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/KotlinSemver.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/KotlinX.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/KotlinX.kt index 435befd..b67dc5e 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/KotlinX.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/KotlinX.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Kover.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Kover.kt index c994c15..5af9494 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Kover.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Kover.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/OpenTest4J.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/OpenTest4J.kt index f631863..3fc79f5 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/OpenTest4J.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/OpenTest4J.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/ProtoData.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/ProtoData.kt index 8992b0a..c5a8ae0 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/ProtoData.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/ProtoData.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Protobuf.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Protobuf.kt index fdb8277..b2a22ba 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Protobuf.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Protobuf.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Roaster.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Roaster.kt index a35bea1..e747eb6 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Roaster.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Roaster.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Slf4J.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Slf4J.kt index 1a2e4a9..9eaa748 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Slf4J.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Slf4J.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/TestKitTruth.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/TestKitTruth.kt index 0f34030..f5f5ee5 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/TestKitTruth.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/TestKitTruth.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Truth.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Truth.kt index ec75dfb..fb6f345 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Truth.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Truth.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Validation.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Validation.kt index 5b973cf..8d65ce0 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/Validation.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/Validation.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/Build.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/Build.kt index ee42a1a..3038f1d 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/Build.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/Build.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/Clean.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/Clean.kt index 9732fdf..f60e59f 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/Clean.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/Clean.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/ConfigTester.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/ConfigTester.kt index 0fb5c93..d49572d 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/ConfigTester.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/ConfigTester.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/ProjectExtensions.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/ProjectExtensions.kt index 18a1efc..ee79218 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/ProjectExtensions.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/ProjectExtensions.kt @@ -5,7 +5,7 @@ * 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 + * 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 @@ -26,7 +26,6 @@ package io.spine.internal.gradle -import io.spine.internal.gradle.publish.SpinePublishing import java.io.File import org.gradle.api.Plugin import org.gradle.api.Project @@ -74,25 +73,6 @@ fun Project.findTask(name: String): T { return task as T } -/** - * Obtains Maven artifact ID of this [Project]. - * - * The method checks if [SpinePublishing] extension is configured upon this project. If yes, - * returns [SpinePublishing.artifactId] for the project. Otherwise, a project's name is returned. - */ -val Project.artifactId: String - get() { - - // Publishing of a project can be configured either from the project itself or - // from its root project. This is why it is required to check both places. - - val spinePublishing = extensions.findByType() - ?: rootProject.extensions.findByType() - - val artifactId = spinePublishing?.artifactId(this) - return artifactId ?: name - } - /** * Returns project's build directory as [File]. */ diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/Repositories.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/Repositories.kt index 4a88035..5b87a36 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/Repositories.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/Repositories.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/RunBuild.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/RunBuild.kt index 50733a9..bc90fe4 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/RunBuild.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/RunBuild.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/RunGradle.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/RunGradle.kt index 8c22526..7bfc62e 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/RunGradle.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/RunGradle.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/Runtime.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/Runtime.kt index aa3712b..156593f 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/Runtime.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/Runtime.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/StringExtensions.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/StringExtensions.kt index 4bf97d7..2c2c519 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/StringExtensions.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/StringExtensions.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/TaskName.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/TaskName.kt index 3547a61..555ec78 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/TaskName.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/TaskName.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/base/Tasks.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/base/Tasks.kt index 9176cd5..438a383 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/base/Tasks.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/base/Tasks.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/checkstyle/CheckStyleConfig.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/checkstyle/CheckStyleConfig.kt index b4d8bfa..8b8d5a1 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/checkstyle/CheckStyleConfig.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/checkstyle/CheckStyleConfig.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/fs/LazyTempPath.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/fs/LazyTempPath.kt index 796f90f..a922e70 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/fs/LazyTempPath.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/fs/LazyTempPath.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/java/Tasks.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/java/Tasks.kt index 87b56a3..46122e1 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/java/Tasks.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/java/Tasks.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/javac/ErrorProne.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/javac/ErrorProne.kt index da48ecd..e0f5c6f 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/javac/ErrorProne.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/javac/ErrorProne.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/javac/Javac.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/javac/Javac.kt index ba50301..98f2c0f 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/javac/Javac.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/javac/Javac.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/kotlin/KotlinConfig.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/kotlin/KotlinConfig.kt index 5728938..2613d8c 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/kotlin/KotlinConfig.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/kotlin/KotlinConfig.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/protobuf/ProtoTaskExtensions.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/protobuf/ProtoTaskExtensions.kt index de78a5e..e4fb948 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/protobuf/ProtoTaskExtensions.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/protobuf/ProtoTaskExtensions.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/CheckVersionIncrement.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/CheckVersionIncrement.kt deleted file mode 100644 index a81cbdc..0000000 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/CheckVersionIncrement.kt +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright 2023, 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.gradle.publish - -import com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES -import com.fasterxml.jackson.dataformat.xml.XmlMapper -import io.spine.internal.gradle.Repository -import java.io.FileNotFoundException -import java.net.URL -import org.gradle.api.DefaultTask -import org.gradle.api.GradleException -import org.gradle.api.Project -import org.gradle.api.tasks.Input -import org.gradle.api.tasks.TaskAction - -/** - * A task which verifies that the current version of the library has not been published to the given - * Maven repository yet. - */ -open class CheckVersionIncrement : DefaultTask() { - - /** - * The Maven repository in which to look for published artifacts. - * - * We check both the `releases` and `snapshots` repositories. Artifacts in either of these repos - * may not be overwritten. - */ - @Input - lateinit var repository: Repository - - @Input - val version: String = project.version as String - - @TaskAction - fun fetchAndCheck() { - val artifact = "${project.artifactPath()}/${MavenMetadata.FILE_NAME}" - checkInRepo(repository.snapshots, artifact) - - if (repository.releases != repository.snapshots) { - checkInRepo(repository.releases, artifact) - } - } - - private fun checkInRepo(repoUrl: String, artifact: String) { - val metadata = fetch(repoUrl, artifact) - val versions = metadata?.versioning?.versions - val versionExists = versions?.contains(version) ?: false - if (versionExists) { - throw GradleException(""" - Version `$version` is already published to maven repository `$repoUrl`. - Try incrementing the library version. - All available versions are: ${versions?.joinToString(separator = ", ")}. - - To disable this check, run Gradle with `-x $name`. - """.trimIndent() - ) - } - } - - private fun fetch(repository: String, artifact: String): MavenMetadata? { - val url = URL("$repository/$artifact") - return MavenMetadata.fetchAndParse(url) - } - - private fun Project.artifactPath(): String { - val group = this.group as String - val name = "spine-${this.name}" - - val pathElements = ArrayList(group.split('.')) - pathElements.add(name) - val path = pathElements.joinToString(separator = "/") - return path - } -} - -private data class MavenMetadata(var versioning: Versioning = Versioning()) { - - companion object { - - const val FILE_NAME = "maven-metadata.xml" - - private val mapper = XmlMapper() - - init { - mapper.configure(FAIL_ON_UNKNOWN_PROPERTIES, false) - } - - /** - * Fetches the metadata for the repository and parses the document. - * - *

If the document could not be found, assumes that the module was never - * released and thus has no metadata. - */ - fun fetchAndParse(url: URL): MavenMetadata? { - return try { - val metadata = mapper.readValue(url, MavenMetadata::class.java) - metadata - } catch (ignored: FileNotFoundException) { - null - } - } - } -} - -private data class Versioning(var versions: List = listOf()) diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/CloudArtifactRegistry.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/CloudArtifactRegistry.kt index 4751d56..cc94c49 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/CloudArtifactRegistry.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/CloudArtifactRegistry.kt @@ -5,7 +5,7 @@ * 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 + * 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 @@ -75,4 +75,3 @@ internal object CloudArtifactRegistry { } } } - diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/CloudRepo.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/CloudRepo.kt index 148ebce..7067552 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/CloudRepo.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/CloudRepo.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/GitHubPackages.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/GitHubPackages.kt index 68b68a2..728cedf 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/GitHubPackages.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/GitHubPackages.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/IncrementGuard.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/IncrementGuard.kt deleted file mode 100644 index 4dfb641..0000000 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/IncrementGuard.kt +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright 2024, 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. - */ - -@file:Suppress("unused") - -package io.spine.internal.gradle.publish - -import org.gradle.api.Plugin -import org.gradle.api.Project - -/** - * Gradle plugin which adds a [CheckVersionIncrement] task. - * - * The task is called `checkVersionIncrement` inserted before the `check` task. - */ -class IncrementGuard : Plugin { - - companion object { - const val taskName = "checkVersionIncrement" - } - - /** - * Adds the [CheckVersionIncrement] task to the project. - * - * The task is created anyway, but it is enabled only if: - * 1. The project is built on GitHub CI, and - * 2. The job is a pull request. - * - * The task only runs on non-master branches on GitHub Actions. - * This is done to prevent unexpected CI fails when re-building `master` multiple times, - * creating git tags, and in other cases that go outside the "usual" development cycle. - */ - override fun apply(target: Project) { - val tasks = target.tasks - tasks.register(taskName, CheckVersionIncrement::class.java) { - repository = CloudArtifactRegistry.repository - tasks.getByName("check").dependsOn(this) - - if (!shouldCheckVersion()) { - logger.info( - "The build does not represent a GitHub Actions feature branch job, " + - "the `checkVersionIncrement` task is disabled." - ) - this.enabled = false - } - } - } - - /** - * Returns `true` if the current build is a GitHub Actions build which represents a push - * to a feature branch. - * - * Returns `false` if the associated reference is not a branch (e.g., a tag) or if it has - * the name which ends with `master` or `main`. - * - * For example, on the following branches the method would return `false`: - * - * 1. `master`. - * 2. `main`. - * 3. `2.x-jdk8-master`. - * 4. `2.x-jdk8-main`. - * - * @see - * List of default environment variables provided for GitHub Actions builds - */ - private fun shouldCheckVersion(): Boolean { - val event = System.getenv("GITHUB_EVENT_NAME") - val reference = System.getenv("GITHUB_REF") - if (event != "push" || reference == null) { - return false - } - val branch = branchName(reference) - return when { - branch == null -> false - branch.endsWith("master") -> false - branch.endsWith("main") -> false - else -> true - } - } - - private fun branchName(gitHubRef: String): String? { - val matches = Regex("refs/heads/(.+)").matchEntire(gitHubRef) - val branch = matches?.let { it.groupValues[1] } - return branch - } -} diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/JarDsl.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/JarDsl.kt deleted file mode 100644 index 2bc2870..0000000 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/JarDsl.kt +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright 2023, 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.gradle.publish - -/** - * A DSL element of [SpinePublishing] extension which configures publishing of - * [dokkaKotlinJar] artifact. - * - * This artifact contains Dokka-generated documentation. By default, it is not published. - * - * Take a look at the [SpinePublishing.dokkaJar] for a usage example. - * - * @see [artifacts] - */ -class DokkaJar { - /** - * Enables publishing `JAR`s with Dokka-generated documentation for all published modules. - */ - @Suppress("unused") - @Deprecated("Please use `kotlin` and `java` flags instead.") - var enabled = false - - /** - * Controls whether [dokkaKotlinJar] artifact should be published. - * The default value is `true`. - */ - var kotlin = true - - /** - * Controls whether [dokkaJavaJar] artifact should be published. - * The default value is `false`. - */ - var java = false -} - -/** - * A DSL element of [SpinePublishing] extension which allows enabling publishing - * of [testJar] artifact. - * - * This artifact contains compilation output of `test` source set. By default, it is not published. - * - * Take a look on [SpinePublishing.testJar] for a usage example. - - * @see [artifacts] - */ -class TestJar { - - /** - * Set of modules, for which a test JAR will be published. - */ - var inclusions: Set = emptySet() - - /** - * Enables test JAR publishing for all published modules. - */ - var enabled = false -} - -/** - * A DSL element of [SpinePublishing] extension which allows disabling publishing - * of [protoJar] artifact. - * - * This artifact contains all the `.proto` definitions from `sourceSets.main.proto`. By default, - * it is published. - * - * Take a look on [SpinePublishing.protoJar] for a usage example. - * - * @see [artifacts] - */ -class ProtoJar { - - /** - * Set of modules, for which a proto JAR will not be published. - */ - var exclusions: Set = emptySet() - - /** - * Disables proto JAR publishing for all published modules. - */ - var disabled = false -} - -/** - * Flags for turning optional JAR artifacts in a project. - */ -internal data class JarFlags( - - /** - * Tells whether [sourcesJar] artifact should be published. - * - * Default value is `true`. - */ - val sourcesJar: Boolean = true, - - /** - * Tells whether [javadocJar] artifact should be published. - * - * Default value is `true`. - */ - val javadocJar: Boolean = true, - - /** - * Tells whether [protoJar] artifact should be published. - */ - val publishProtoJar: Boolean, - - /** - * Tells whether [testJar] artifact should be published. - */ - val publishTestJar: Boolean, - - /** - * Tells whether [dokkaKotlinJar] artifact should be published. - */ - val publishDokkaKotlinJar: Boolean, - - /** - * Tells whether [dokkaJavaJar] artifact should be published. - */ - val publishDokkaJavaJar: Boolean -) { - internal companion object { - /** - * Creates an instance of [JarFlags] for the project with the given name, - * taking the setup parameters from JAR DSL elements. - */ - fun create( - projectName: String, - protoJar: ProtoJar, - testJar: TestJar, - dokkaJar: DokkaJar - ): JarFlags { - val addProtoJar = (protoJar.exclusions.contains(projectName) || protoJar.disabled).not() - val addTestJar = testJar.inclusions.contains(projectName) || testJar.enabled - return JarFlags( - sourcesJar = true, - javadocJar = true, - addProtoJar, addTestJar, - dokkaJar.kotlin, dokkaJar.java - ) - } - } -} diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/ProtoExts.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/ProtoExts.kt deleted file mode 100644 index 97e3319..0000000 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/ProtoExts.kt +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2023, 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.gradle.publish - -import io.spine.internal.gradle.sourceSets -import java.io.File -import org.gradle.api.Project -import org.gradle.api.Task -import org.gradle.api.file.FileTreeElement -import org.gradle.api.file.SourceDirectorySet -import org.gradle.api.tasks.bundling.Jar - -/** - * Tells whether there are any Proto sources in "main" source set. - */ -internal fun Project.hasProto(): Boolean { - val protoSources = protoSources() - val result = protoSources.any { it.exists() } - return result -} - -/** - * Locates directories with proto sources under the "main" source sets. - * - * Special treatment for Proto sources is needed, because they are not Java-related, and, - * thus, not included in `sourceSets["main"].allSource`. - */ -internal fun Project.protoSources(): Set { - val mainSourceSets = sourceSets.filter { - ss -> ss.name.endsWith("main", ignoreCase = true) - } - - val protoExtensions = mainSourceSets.mapNotNull { - it.extensions.findByName("proto") as SourceDirectorySet? - } - - val protoDirs = mutableSetOf() - protoExtensions.forEach { - protoDirs.addAll(it.srcDirs) - } - - return protoDirs -} - -/** - * Checks if the given file belongs to the Google `.proto` sources. - */ -internal fun FileTreeElement.isGoogleProtoSource(): Boolean { - val pathSegments = relativePath.segments - return pathSegments.isNotEmpty() && pathSegments[0].equals("google") -} - -/** - * The reference to the `generateProto` task of a `main` source set. - */ -internal fun Project.generateProto(): Task? = tasks.findByName("generateProto") - -/** - * Makes this [Jar] task depend on the [generateProto] task, if it exists in the same project. - */ -internal fun Jar.dependOnGenerateProto() { - project.generateProto()?.let { - this.dependsOn(it) - } -} diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/Publications.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/Publications.kt deleted file mode 100644 index 0b4d24b..0000000 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/Publications.kt +++ /dev/null @@ -1,234 +0,0 @@ -/* - * Copyright 2024, 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.gradle.publish - -import io.spine.internal.gradle.Repository -import io.spine.internal.gradle.isSnapshot -import org.gradle.api.Project -import org.gradle.api.artifacts.dsl.RepositoryHandler -import org.gradle.api.publish.maven.MavenPublication -import org.gradle.api.tasks.TaskProvider -import org.gradle.api.tasks.bundling.Jar -import org.gradle.kotlin.dsl.apply -import org.gradle.kotlin.dsl.create - -/** - * The name of the Maven Publishing Gradle plugin. - */ -private const val MAVEN_PUBLISH = "maven-publish" - -/** - * Abstract base for handlers of publications in a project - * with [spinePublishing] settings declared. - */ -internal sealed class PublicationHandler( - protected val project: Project, - private val destinations: Set -) { - - fun apply() = with(project) { - if (!hasCustomPublishing) { - apply(plugin = MAVEN_PUBLISH) - } - - pluginManager.withPlugin(MAVEN_PUBLISH) { - handlePublications() - registerDestinations() - configurePublishTask(destinations) - } - } - - /** - * Either handles publications already declared in the given project, - * or creates new ones. - */ - abstract fun handlePublications() - - /** - * Goes through the [destinations] and registers each as a repository for publishing - * in the given Gradle project. - */ - private fun registerDestinations() { - val repositories = project.publishingExtension.repositories - destinations.forEach { destination -> - repositories.register(project, destination) - } - } - - /** - * Copies the attributes of Gradle [Project] to this [MavenPublication]. - * - * The following project attributes are copied: - * * [group][Project.getGroup]; - * * [version][Project.getVersion]; - * * [description][Project.getDescription]. - * - * Also, this function adds the [artifactPrefix][SpinePublishing.artifactPrefix] to - * the [artifactId][MavenPublication.setArtifactId] of this publication, - * if the prefix is not added yet. - * - * Finally, the Apache Software License 2.0 is set as the only license - * under which the published artifact is distributed. - */ - protected fun MavenPublication.copyProjectAttributes() { - groupId = project.group.toString() - val prefix = project.spinePublishing.artifactPrefix - if (!artifactId.startsWith(prefix)) { - artifactId = prefix + artifactId - } - version = project.version.toString() - pom.description.set(project.description) - - pom.licenses { - license { - name.set("The Apache Software License, Version 2.0") - url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") - } - } - } -} - -/** - * Adds a Maven repository to the project specifying credentials, if they are - * [available][Repository.credentials] from the root project. - */ -private fun RepositoryHandler.register(project: Project, repository: Repository) { - val isSnapshot = project.version.toString().isSnapshot() - val target = if (isSnapshot) repository.snapshots else repository.releases - val credentials = repository.credentials(project.rootProject) - maven { - url = project.uri(target) - credentials { - username = credentials?.username - password = credentials?.password - } - } -} - -/** - * A publication for a typical Java project. - * - * In Gradle, to publish something, one should create a publication. - * A publication has a name and consists of one or more artifacts plus information about - * those artifacts – the metadata. - * - * An instance of this class represents [MavenPublication] named "mavenJava". It is generally - * accepted that a publication with this name contains a Java project published to one or - * more Maven repositories. - * - * By default, only a jar with the compilation output of `main` source set and its - * metadata files are published. Other artifacts are specified through the - * [constructor parameter][jarFlags]. Please, take a look on [specifyArtifacts] for additional info. - * - * @param jarFlags - * flags for additional JARs published along with the compilation output. - * @param destinations - * Maven repositories to which the produced artifacts will be sent. - * @see - * Maven Publish Plugin | Publications - */ -internal class StandardJavaPublicationHandler( - project: Project, - private val jarFlags: JarFlags, - destinations: Set, -) : PublicationHandler(project, destinations) { - - /** - * Creates a new "mavenJava" [MavenPublication] in the given project. - */ - override fun handlePublications() { - val jars = project.artifacts(jarFlags) - val publications = project.publications - publications.create("mavenJava") { - copyProjectAttributes() - specifyArtifacts(jars) - } - } - - /** - * Specifies which artifacts this [MavenPublication] will contain. - * - * A typical Maven publication contains: - * - * 1. Jar archives. For example: compilation output, sources, javadoc, etc. - * 2. Maven metadata file that has ".pom" extension. - * 3. Gradle's metadata file that has ".module" extension. - * - * Metadata files contain information about a publication itself, its artifacts and their - * dependencies. Presence of ".pom" file is mandatory for publication to be consumed by - * `mvn` build tool itself or other build tools that understand Maven notation (Gradle, Ivy). - * Presence of ".module" is optional, but useful when a publication is consumed by Gradle. - * - * @see Maven – POM Reference - * @see - * Understanding Gradle Module Metadata - */ - private fun MavenPublication.specifyArtifacts(jars: Set>) { - - /* "java" component provides a jar with compilation output of "main" source set. - It is NOT defined as another `Jar` task intentionally. Doing that will leave the - publication without correct ".pom" and ".module" metadata files generated. - */ - val javaComponent = project.components.findByName("java") - javaComponent?.let { - from(it) - } - - /* Other artifacts are represented by `Jar` tasks. Those artifacts don't bring any other - metadata in comparison with `Component` (such as dependencies notation). - */ - jars.forEach { - artifact(it) - } - } -} - -/** - * A handler for custom publications, which are declared under the [publications] - * section of a module. - * - * Such publications should be treated differently than [StandardJavaPublicationHandler], - * which is created for a module. Instead, since the publications are already declared, - * this class only [assigns maven coordinates][copyProjectAttributes]. - * - * A module which declares custom publications must be specified in - * the [SpinePublishing.modulesWithCustomPublishing] property. - * - * If a module with [publications] declared locally is not specified as one with custom publishing, - * it may cause a name clash between an artifact produced by the [standard][MavenPublication] - * publication, and custom ones. To have both standard and custom publications, - * please specify custom artifact IDs or classifiers for each custom publication. - */ -internal class CustomPublicationHandler(project: Project, destinations: Set) : - PublicationHandler(project, destinations) { - - override fun handlePublications() { - project.publications.forEach { - (it as MavenPublication).copyProjectAttributes() - } - } -} diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/PublishingExts.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/PublishingExts.kt deleted file mode 100644 index b4c15c3..0000000 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/PublishingExts.kt +++ /dev/null @@ -1,276 +0,0 @@ -/* - * Copyright 2023, 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.gradle.publish - -import io.spine.internal.gradle.Repository -import io.spine.internal.gradle.sourceSets -import java.util.* -import org.gradle.api.InvalidUserDataException -import org.gradle.api.Project -import org.gradle.api.Task -import org.gradle.api.publish.PublicationContainer -import org.gradle.api.publish.PublishingExtension -import org.gradle.api.tasks.TaskContainer -import org.gradle.api.tasks.TaskProvider -import org.gradle.api.tasks.bundling.Jar -import org.gradle.kotlin.dsl.findByType -import org.gradle.kotlin.dsl.get -import org.gradle.kotlin.dsl.getByType -import org.gradle.kotlin.dsl.named -import org.gradle.kotlin.dsl.register -import org.gradle.kotlin.dsl.withType - -/** - * Obtains [PublishingExtension] of this project. - */ -internal val Project.publishingExtension: PublishingExtension - get() = extensions.getByType() - -/** - * Obtains [PublicationContainer] of this project. - */ -internal val Project.publications: PublicationContainer - get() = publishingExtension.publications - -/** - * Obtains [SpinePublishing] extension from this [Project]. - * - * If this [Project] doesn't have one, it returns [SpinePublishing] - * declared in the root project. - */ -internal val Project.spinePublishing: SpinePublishing - get() { - val local = this.extensions.findByType() - if (local != null) { - return local - } - val fromRoot = this.rootProject.extensions.findByType() - if (fromRoot != null) { - return fromRoot - } - error("`SpinePublishing` is not found in `${project.name}`.") - } - -/** - * Tells if this project has custom publishing. - */ -internal val Project.hasCustomPublishing: Boolean - get() = spinePublishing.modulesWithCustomPublishing.contains(name) - -private const val PUBLISH_TASK = "publish" - -/** - * Locates `publish` task in this [TaskContainer]. - * - * This task publishes all defined publications to all defined repositories. To achieve that, - * the task depends on all `publish`*PubName*`PublicationTo`*RepoName*`Repository` tasks. - * - * Please note, task execution would not copy publications to the local Maven cache. - * - * @see - * Tasks | Maven Publish Plugin - */ -internal val TaskContainer.publish: TaskProvider - get() = named(PUBLISH_TASK) - -/** - * Sets dependencies for `publish` task in this [Project]. - * - * This method performs the following: - * - * 1. When this [Project] is not a root, makes `publish` task in a root project - * depend on a local `publish`. - * 2. Makes local `publish` task verify that credentials are present for each - * of destination repositories. - */ -internal fun Project.configurePublishTask(destinations: Set) { - attachCredentialsVerification(destinations) - bindToRootPublish() -} - -private fun Project.attachCredentialsVerification(destinations: Set) { - val checkCredentials = tasks.registerCheckCredentialsTask(destinations) - val localPublish = tasks.publish - localPublish.configure { dependsOn(checkCredentials) } -} - -private fun Project.bindToRootPublish() { - if (project == rootProject) { - return - } - - val localPublish = tasks.publish - val rootPublish = rootProject.tasks.getOrCreatePublishTask() - rootPublish.configure { dependsOn(localPublish) } -} - -/** - * Use this task accessor when it is not guaranteed that the task is present - * in this [TaskContainer]. - */ -private fun TaskContainer.getOrCreatePublishTask(): TaskProvider = - if (names.contains(PUBLISH_TASK)) { - named(PUBLISH_TASK) - } else { - register(PUBLISH_TASK) - } - -private fun TaskContainer.registerCheckCredentialsTask( - destinations: Set -): TaskProvider = - register("checkCredentials") { - doLast { - destinations.forEach { it.ensureCredentials(project) } - } - } - -private fun Repository.ensureCredentials(project: Project) { - val credentials = credentials(project) - if (Objects.isNull(credentials)) { - throw InvalidUserDataException( - "No valid credentials for repository `${this}`. Please make sure " + - "to pass username/password or a valid `.properties` file." - ) - } -} - -/** - * Excludes Google `.proto` sources from all artifacts. - * - * Goes through all registered `Jar` tasks and filters out Google's files. - */ -@Suppress("unused") -fun TaskContainer.excludeGoogleProtoFromArtifacts() { - withType().configureEach { - exclude { it.isGoogleProtoSource() } - } -} - -/** - * Locates or creates `sourcesJar` task in this [Project]. - * - * The output of this task is a `jar` archive. The archive contains sources from `main` source set. - * The task makes sure that sources from the directories below will be included into - * a resulted archive: - * - * - Kotlin - * - Java - * - Proto - * - * Java and Kotlin sources are default to `main` source set since it is created by `java` plugin. - * For Proto sources to be included – [special treatment][protoSources] is needed. - */ -internal fun Project.sourcesJar(): TaskProvider = tasks.getOrCreate("sourcesJar") { - dependOnGenerateProto() - archiveClassifier.set("sources") - from(sourceSets["main"].allSource) // Puts Java and Kotlin sources. - from(protoSources()) // Puts Proto sources. - exclude("desc.ref", "*.desc") // Exclude descriptor files and the descriptor reference. -} - -/** - * Locates or creates `protoJar` task in this [Project]. - * - * The output of this task is a `jar` archive. The archive contains only - * [Proto sources][protoSources] from `main` source set. - */ -internal fun Project.protoJar(): TaskProvider = tasks.getOrCreate("protoJar") { - dependOnGenerateProto() - archiveClassifier.set("proto") - from(protoSources()) -} - -/** - * Locates or creates `testJar` task in this [Project]. - * - * The output of this task is a `jar` archive. The archive contains compilation output - * of `test` source set. - */ -internal fun Project.testJar(): TaskProvider = tasks.getOrCreate("testJar") { - archiveClassifier.set("test") - from(sourceSets["test"].output) -} - -/** - * Locates or creates `javadocJar` task in this [Project]. - * - * The output of this task is a `jar` archive. The archive contains Javadoc, - * generated upon Java sources from `main` source set. If javadoc for Kotlin is also needed, - * apply Dokka plugin. It tunes `javadoc` task to generate docs upon Kotlin sources as well. - */ -fun Project.javadocJar(): TaskProvider = tasks.getOrCreate("javadocJar") { - archiveClassifier.set("javadoc") - val javadocFiles = layout.buildDirectory.files("/docs/javadoc") - from(javadocFiles) - dependsOn("javadoc") -} - -internal fun TaskContainer.getOrCreate(name: String, init: Jar.() -> Unit): TaskProvider = - if (names.contains(name)) { - named(name) - } else { - register(name) { - init() - } - } - -/** - * Obtains as a set of [Jar] tasks, output of which is used as Maven artifacts. - * - * By default, only a jar with Java compilation output is included into publication. This method - * registers tasks which produce additional artifacts according to the values of [jarFlags]. - * - * @return the list of the registered tasks. - */ -internal fun Project.artifacts(jarFlags: JarFlags): Set> { - val tasks = mutableSetOf>() - - if (jarFlags.sourcesJar) { - tasks.add(sourcesJar()) - } - - if (jarFlags.javadocJar) { - tasks.add(javadocJar()) - } - - // We don't want to have an empty "proto.jar" when a project doesn't have any Proto files. - if (hasProto() && jarFlags.publishProtoJar) { - tasks.add(protoJar()) - } - - // Here, we don't have the corresponding `hasTests()` check, since this artifact is disabled - // by default. And turning it on means "We have tests and need them to be published." - if (jarFlags.publishTestJar) { - tasks.add(testJar()) - } - -/* if (jarFlags.publishDokkaKotlinJar) { - tasks.add(dokkaKotlinJar()) - }*/ - - return tasks -} diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/SpinePublishing.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/SpinePublishing.kt deleted file mode 100644 index 74ed0a3..0000000 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/publish/SpinePublishing.kt +++ /dev/null @@ -1,452 +0,0 @@ -/* - * Copyright 2024, 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. - */ - -@file:Suppress("TooManyFunctions") - -package io.spine.internal.gradle.publish - -import io.spine.internal.gradle.Repository -import org.gradle.api.Project -import org.gradle.api.publish.maven.plugins.MavenPublishPlugin -import org.gradle.kotlin.dsl.apply -import org.gradle.kotlin.dsl.create -import org.gradle.kotlin.dsl.findByType - -/** - * Configures [SpinePublishing] extension. - * - * This extension sets up publishing of artifacts to Maven repositories. - * - * The extension can be configured for single- and multi-module projects. - * - * When used with a multi-module project, the extension should be opened in a root project's - * build file. The published modules are specified explicitly by their names: - * - * ``` - * spinePublishing { - * modules = setOf( - * "subprojectA", - * "subprojectB", - * ) - * destinations = setOf( - * PublishingRepos.cloudRepo, - * PublishingRepos.cloudArtifactRegistry, - * ) - * } - * ``` - * - * When used with a single-module project, the extension should be opened in a project's build file. - * Only destinations should be specified: - * - * ``` - * spinePublishing { - * destinations = setOf( - * PublishingRepos.cloudRepo, - * PublishingRepos.cloudArtifactRegistry, - * ) - * } - * ``` - * - * It is worth to mention, that publishing of a module can be configured only from a single place. - * For example, declaring `subprojectA` as published in a root project and opening - * `spinePublishing` extension within `subprojectA` itself would lead to an exception. - * - * In Gradle, in order to publish something somewhere one should create a publication. In each - * of published modules, the extension will create a [publication][StandardJavaPublicationHandler] - * named "mavenJava". All artifacts, published by this extension belong to this publication. - * - * By default, along with the compilation output of "main" source set, the extension publishes - * the following artifacts: - * - * 1. [sourcesJar] – sources from "main" source set. Includes "hand-made" Java, - * Kotlin and Proto files. In order to include the generated code into this artifact, a module - * should specify those files as a part of "main" source set. - * - * Here's an example of how to do that: - * - * ``` - * sourceSets { - * val generatedDir by extra("$projectDir/generated") - * val generatedSpineDir by extra("$generatedDir/main/java") - * main { - * java.srcDir(generatedSpineDir) - * } - * } - * ``` - * 2. [protoJar] – only Proto sources from "main" source set. It's published only if - * Proto files are actually present in the source set. Publication of this artifact is optional - * and can be disabled via [SpinePublishing.protoJar]. - * 3. [javadocJar] - javadoc, generated upon Java sources from "main" source set. - * If javadoc for Kotlin is also needed, apply Dokka plugin. It tunes `javadoc` task to generate - * docs upon Kotlin sources as well. - * 4. [dokkaKotlinJar] - documentation generated by Dokka for Kotlin and Java sources - * using the Kotlin API mode. - * 5. [dokkaJavaJar] - documentation generated by Dokka for Kotlin and Java sources - * * using the Java API mode. - * - * Additionally, [testJar] artifact can be published. This artifact contains compilation output - * of "test" source set. Use [SpinePublishing.testJar] to enable its publishing. - * - * @see [artifacts] - */ -fun Project.spinePublishing(block: SpinePublishing.() -> Unit) { - apply() - val name = SpinePublishing::class.java.simpleName - val extension = with(extensions) { - findByType() ?: create(name, project) - } - extension.run { - block() - configured() - } -} - -/** - * A Gradle extension for setting up publishing of spine modules using `maven-publish` plugin. - * - * @param project - * a project in which the extension is opened. By default, this project will be - * published as long as a [set][modules] of modules to publish is not specified explicitly. - * - * @see spinePublishing - */ -open class SpinePublishing(private val project: Project) { - - private val protoJar = ProtoJar() - private val testJar = TestJar() - private val dokkaJar = DokkaJar() - - /** - * Set of modules to be published. - * - * Both the module's name or path can be used. - * - * Use this property if the extension is configured from a root project's build file. - * - * If left empty, the [project], in which the extension is opened, will be published. - * - * Empty by default. - */ - var modules: Set = emptySet() - - /** - * Controls whether the published module needs standard publications. - * - * If `true`, the module should configure publications on its own. - * Otherwise, the extension will configure standard [ones][StandardJavaPublicationHandler]. - * - * This property is analogue of [modulesWithCustomPublishing] for projects, - * for which [spinePublishing] is configured individually. - * - * Setting of this property and having a non-empty [modules] will lead - * to an exception. - * - * Default value is `false`. - */ - var customPublishing = false - - /** - * Set of modules that have custom publications and do not need standard ones. - * - * Empty by default. - */ - var modulesWithCustomPublishing: Set = emptySet() - - /** - * Set of repositories, to which the resulting artifacts will be sent. - * - * Usually, Spine-related projects are published to one or more repositories, - * declared in [PublishingRepos]: - * - * ``` - * destinations = setOf( - * PublishingRepos.cloudRepo, - * PublishingRepos.cloudArtifactRegistry, - * PublishingRepos.gitHub("base"), - * ) - * ``` - * - * Empty by default. - */ - var destinations: Set = emptySet() - - /** - * A prefix to be added before the name of each artifact. - * - * The default value is "spine-". - */ - var artifactPrefix: String = "spine-" - - /** - * Allows disabling publishing of [protoJar] artifact, containing all Proto sources - * from `sourceSets.main.proto`. - * - * Here's an example of how to disable it for some of the published modules: - * - * ``` - * spinePublishing { - * modules = setOf( - * "subprojectA", - * "subprojectB", - * ) - * protoJar { - * exclusions = setOf( - * "subprojectB", - * ) - * } - * } - * ``` - * - * For all modules, or when the extension is configured within a published module itself: - * - * ``` - * spinePublishing { - * protoJar { - * disabled = true - * } - * } - * ``` - * - * The resulting artifact is available under "proto" classifier. - * For example, in Gradle 7+, one could depend on it like this: - * - * ``` - * implementation("io.spine:spine-client:$version@proto") - * ``` - */ - fun protoJar(block: ProtoJar.() -> Unit) = protoJar.run(block) - - /** - * Allows enabling publishing of [testJar] artifact, containing compilation output - * of "test" source set. - * - * Here's an example of how to enable it for some of the published modules: - * - * ``` - * spinePublishing { - * modules = setOf( - * "subprojectA", - * "subprojectB", - * ) - * testJar { - * inclusions = setOf( - * "subprojectB", - * ) - * } - * } - * ``` - * - * For all modules, or when the extension is configured within a published module itself: - * - * ``` - * spinePublishing { - * testJar { - * enabled = true - * } - * } - * ``` - * - * The resulting artifact is available under "test" classifier. For example, - * in Gradle 7+, one could depend on it like this: - * - * ``` - * implementation("io.spine:spine-client:$version@test") - * ``` - */ - fun testJar(block: TestJar.() -> Unit) = testJar.run(block) - - /** - * Configures publishing of [dokkaKotlinJar] and [dokkaJavaJar] artifacts, - * containing Dokka-generated documentation. - * - * By default, publishing of the [dokkaKotlinJar] artifact is enabled, and [dokkaJavaJar] - * is disabled. - * - * Remember that the Dokka Gradle plugin should be applied to publish this artifact as it is - * produced by the `dokkaHtml` task. It can be done by using the - * [io.spine.internal.dependency.Dokka] dependency object or by applying the - * `buildSrc/src/main/kotlin/dokka-for-kotlin` or - * `buildSrc/src/main/kotlin/dokka-for-java` script plugins. - * - * Here's an example of how to use this option: - * - * ``` - * spinePublishing { - * dokkaJar { - * kotlin = false - * java = true - * } - * } - * ``` - * - * The resulting artifact is available under "dokka" classifier. - */ - fun dokkaJar(block: DokkaJar.() -> Unit) = dokkaJar.run(block) - - /** - * Called to notify the extension that its configuration is completed. - * - * On this stage the extension will validate the received configuration and set up - * `maven-publish` plugin for each published module. - */ - internal fun configured() { - ensureProtoJarExclusionsArePublished() - ensureTestJarInclusionsArePublished() - ensureModulesNotDuplicated() - ensureCustomPublishingNotMisused() - - val projectsToPublish = projectsToPublish() - projectsToPublish.forEach { project -> - val jarFlags = JarFlags.create(project.name, protoJar, testJar, dokkaJar) - project.setUpPublishing(jarFlags) - } - } - - /** - * Maps the names of published modules to [Project] instances. - * - * The method considers two options: - * - * 1. The [set][modules] of subprojects to publish is not empty. It means that the extension - * is opened from a root project. - * 2. The [set][modules] is empty. Then, the [project] in which the extension is opened - * will be published. - * - * @see modules - */ - private fun projectsToPublish(): Collection { - if (project.subprojects.isEmpty()) { - return setOf(project) - } - return modules.union(modulesWithCustomPublishing) - .map { name -> project.project(name) } - .ifEmpty { setOf(project) } - } - - /** - * Sets up `maven-publish` plugin for the given project. - * - * Firstly, an instance of [PublicationHandler] is created for the project depending - * on the nature of the publication process configured. - * Then, this the handler is scheduled to apply on [Project.afterEvaluate]. - * - * General rule of thumb is to avoid using [Project.afterEvaluate] of this closure, - * as it configures a project when its configuration is considered completed. - * Which is quite counter-intuitive. - * - * We selected to use [Project.afterEvaluate] so that we can configure publishing of multiple - * modules from a root project. When we do this, we configure publishing for a module, - * build file of which has not been even evaluated yet. - * - * The simplest example here is specifying of `version` and `group` for Maven coordinates. - * Let's suppose, they are declared in a module's build file. It is a common practice. - * But publishing of the module is configured from a root project's build file. By the time, - * when we need to specify them, we just don't know them. As a result, we have to use - * [Project.afterEvaluate] in order to guarantee that a module will be configured by the time - * we configure publishing for it. - */ - private fun Project.setUpPublishing(jarFlags: JarFlags) { - val customPublishing = modulesWithCustomPublishing.contains(name) || customPublishing - val handler = if (customPublishing) { - CustomPublicationHandler(project, destinations) - } else { - StandardJavaPublicationHandler(project, jarFlags, destinations) - } - afterEvaluate { - handler.apply() - } - } - - /** - * Obtains an artifact ID for the given project. - * - * It consists of a project's name and [prefix][artifactPrefix]: - * ``. - */ - fun artifactId(project: Project): String = "$artifactPrefix${project.name}" - - /** - * Ensures that all modules, marked as excluded from [protoJar] publishing, - * are actually published. - * - * It makes no sense to tell a module don't publish [protoJar] artifact, if the module is not - * published at all. - */ - private fun ensureProtoJarExclusionsArePublished() { - val nonPublishedExclusions = protoJar.exclusions.minus(modules) - if (nonPublishedExclusions.isNotEmpty()) { - throw IllegalStateException("One or more modules are marked as `excluded from proto " + - "JAR publication`, but they are not even published: $nonPublishedExclusions") - } - } - - /** - * Ensures that all modules, marked as included into [testJar] publishing, - * are actually published. - * - * It makes no sense to tell a module publish [testJar] artifact, if the module is not - * published at all. - */ - private fun ensureTestJarInclusionsArePublished() { - val nonPublishedInclusions = testJar.inclusions.minus(modules) - if (nonPublishedInclusions.isNotEmpty()) { - error( - "One or more modules are marked as `included into test JAR publication`," + - " but they are not even published: $nonPublishedInclusions." - ) - } - } - - /** - * Ensures that publishing of a module is configured only from a single place. - * - * We allow configuration of publishing from two places - a root project and module itself. - * Here we verify that publishing of a module is not configured in both places simultaneously. - */ - private fun ensureModulesNotDuplicated() { - val rootProject = project.rootProject - if (rootProject == project) { - return - } - - val rootExtension = with(rootProject.extensions) { findByType() } - rootExtension?.let { rootPublishing -> - val thisProject = setOf(project.name, project.path) - if (thisProject.minus(rootPublishing.modules).size != 2) { - error( - "Publishing of `$thisProject` module is already configured in a root project!" - ) - } - } - } - - private fun ensureCustomPublishingNotMisused() { - if (modules.isNotEmpty() && customPublishing) { - error("`customPublishing` property can be set only if `spinePublishing` extension " + - "is open in an individual module, so `modules` property should be empty.") - } - } -} diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/testing/Logging.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/testing/Logging.kt index 1ca4dcc..8d9d585 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/testing/Logging.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/testing/Logging.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/buildSrc/src/main/kotlin/io/spine/internal/gradle/testing/Tasks.kt b/buildSrc/src/main/kotlin/io/spine/internal/gradle/testing/Tasks.kt index ef559f2..6ca71c8 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/gradle/testing/Tasks.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/gradle/testing/Tasks.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/codegen-plugin/build.gradle.kts b/codegen-plugin/build.gradle.kts index 510602c..6499dc0 100644 --- a/codegen-plugin/build.gradle.kts +++ b/codegen-plugin/build.gradle.kts @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/ApplySizeOptionPlugin.kt b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/ApplySizeOptionPlugin.kt index a64df49..8777eb4 100644 --- a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/ApplySizeOptionPlugin.kt +++ b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/ApplySizeOptionPlugin.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderBeforeReturnInsertionPoint.kt b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderBeforeReturnInsertionPoint.kt index bae9472..092591a 100644 --- a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderBeforeReturnInsertionPoint.kt +++ b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderBeforeReturnInsertionPoint.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderBeforeReturnRenderer.kt b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderBeforeReturnRenderer.kt index 3537758..41a1193 100644 --- a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderBeforeReturnRenderer.kt +++ b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderBeforeReturnRenderer.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderExtensionGenerator.kt b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderExtensionGenerator.kt index d863c81..afcad4d 100644 --- a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderExtensionGenerator.kt +++ b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderExtensionGenerator.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderValidationMethods.kt b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderValidationMethods.kt index 89825a8..fc828d4 100644 --- a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderValidationMethods.kt +++ b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/BuilderValidationMethods.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/SizeOptionView.kt b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/SizeOptionView.kt index 3857046..b7da4a1 100644 --- a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/SizeOptionView.kt +++ b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/SizeOptionView.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/SizeOptionViewRepository.kt b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/SizeOptionViewRepository.kt index 90413aa..18e549d 100644 --- a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/SizeOptionViewRepository.kt +++ b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/SizeOptionViewRepository.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/ValidateSizeOptionRenderer.kt b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/ValidateSizeOptionRenderer.kt index 83efce8..b57cda6 100644 --- a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/ValidateSizeOptionRenderer.kt +++ b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/ValidateSizeOptionRenderer.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/package-info.java b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/package-info.java index 8448547..ac288aa 100644 --- a/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/package-info.java +++ b/codegen-plugin/src/main/kotlin/io/spine/examples/protodata/hello/plugin/package-info.java @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/codegen-plugin/src/main/proto/spine/examples/protodata/hello/plugin/size_option.proto b/codegen-plugin/src/main/proto/spine/examples/protodata/hello/plugin/size_option.proto index 2ec47b7..ced0fe5 100644 --- a/codegen-plugin/src/main/proto/spine/examples/protodata/hello/plugin/size_option.proto +++ b/codegen-plugin/src/main/proto/spine/examples/protodata/hello/plugin/size_option.proto @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/config b/config index 5793185..3478c12 160000 --- a/config +++ b/config @@ -1 +1 @@ -Subproject commit 5793185d866be1fb22fe1af9147b7a23775d6fe6 +Subproject commit 3478c12027df47eab3d195cca0c2ff38bc7163f4 diff --git a/gradle.properties b/gradle.properties index 85abfc4..73c47a6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ # JVM memory settings for the Gradle build. -org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=1024m -XX:+UseParallelGC +org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+UseParallelGC diff --git a/integration-tests/build.gradle.kts b/integration-tests/build.gradle.kts index fe08ebf..aa52700 100644 --- a/integration-tests/build.gradle.kts +++ b/integration-tests/build.gradle.kts @@ -4,7 +4,7 @@ * 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 + * 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 diff --git a/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/ApplySizeOptionPluginTest.kt b/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/ApplySizeOptionPluginTest.kt index d578672..d1aff84 100644 --- a/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/ApplySizeOptionPluginTest.kt +++ b/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/ApplySizeOptionPluginTest.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/TestEnv.kt b/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/TestEnv.kt index 4d17417..9545768 100644 --- a/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/TestEnv.kt +++ b/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/TestEnv.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/package-info.java b/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/package-info.java index f9beb5b..c345fd2 100644 --- a/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/package-info.java +++ b/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/package-info.java @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/integration-tests/src/test/proto/spine/examples/protodata/hello/test/contact.proto b/integration-tests/src/test/proto/spine/examples/protodata/hello/test/contact.proto index c4a6b7f..a84efd7 100644 --- a/integration-tests/src/test/proto/spine/examples/protodata/hello/test/contact.proto +++ b/integration-tests/src/test/proto/spine/examples/protodata/hello/test/contact.proto @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/integration-tests/src/test/resources/negative-cases/empty_expression_value.proto b/integration-tests/src/test/resources/negative-cases/empty_expression_value.proto index 6b7db5f..efd7423 100644 --- a/integration-tests/src/test/resources/negative-cases/empty_expression_value.proto +++ b/integration-tests/src/test/resources/negative-cases/empty_expression_value.proto @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/integration-tests/src/test/resources/negative-cases/non_repeated_field.proto b/integration-tests/src/test/resources/negative-cases/non_repeated_field.proto index 838186d..e9b5f8c 100644 --- a/integration-tests/src/test/resources/negative-cases/non_repeated_field.proto +++ b/integration-tests/src/test/resources/negative-cases/non_repeated_field.proto @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/integration-tests/src/test/resources/test-project/build.gradle.kts b/integration-tests/src/test/resources/test-project/build.gradle.kts index 5e25186..34b211d 100644 --- a/integration-tests/src/test/resources/test-project/build.gradle.kts +++ b/integration-tests/src/test/resources/test-project/build.gradle.kts @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/integration-tests/src/test/resources/test-project/model/build.gradle.kts b/integration-tests/src/test/resources/test-project/model/build.gradle.kts index 39a653f..28375f3 100644 --- a/integration-tests/src/test/resources/test-project/model/build.gradle.kts +++ b/integration-tests/src/test/resources/test-project/model/build.gradle.kts @@ -4,7 +4,7 @@ * 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 + * 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 diff --git a/integration-tests/src/test/resources/test-project/settings.gradle.kts b/integration-tests/src/test/resources/test-project/settings.gradle.kts index 42347ce..78b79b3 100644 --- a/integration-tests/src/test/resources/test-project/settings.gradle.kts +++ b/integration-tests/src/test/resources/test-project/settings.gradle.kts @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/model/build.gradle.kts b/model/build.gradle.kts index 5bc0668..fc9f481 100644 --- a/model/build.gradle.kts +++ b/model/build.gradle.kts @@ -4,7 +4,7 @@ * 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 + * 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 diff --git a/model/src/main/proto/spine/examples/protodata/hello/model/tictactoe.proto b/model/src/main/proto/spine/examples/protodata/hello/model/tictactoe.proto index 7f58338..dc90a78 100644 --- a/model/src/main/proto/spine/examples/protodata/hello/model/tictactoe.proto +++ b/model/src/main/proto/spine/examples/protodata/hello/model/tictactoe.proto @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/model/src/test/kotlin/io/spine/examples/protodata/hello/model/test/SizeOptionPluginTest.kt b/model/src/test/kotlin/io/spine/examples/protodata/hello/model/test/SizeOptionPluginTest.kt index 96aba4f..fee1bc5 100644 --- a/model/src/test/kotlin/io/spine/examples/protodata/hello/model/test/SizeOptionPluginTest.kt +++ b/model/src/test/kotlin/io/spine/examples/protodata/hello/model/test/SizeOptionPluginTest.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/model/src/test/kotlin/io/spine/examples/protodata/hello/model/test/package-info.java b/model/src/test/kotlin/io/spine/examples/protodata/hello/model/test/package-info.java index 1cb08af..b46b4dd 100644 --- a/model/src/test/kotlin/io/spine/examples/protodata/hello/model/test/package-info.java +++ b/model/src/test/kotlin/io/spine/examples/protodata/hello/model/test/package-info.java @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/proto-extension/build.gradle.kts b/proto-extension/build.gradle.kts index c1b40b1..53e6dd7 100644 --- a/proto-extension/build.gradle.kts +++ b/proto-extension/build.gradle.kts @@ -4,7 +4,7 @@ * 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 + * 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 diff --git a/proto-extension/src/main/kotlin/io/spine/examples/protodata/hello/ArrayOfSizeOptionProvider.kt b/proto-extension/src/main/kotlin/io/spine/examples/protodata/hello/ArrayOfSizeOptionProvider.kt index dd571eb..282aa53 100644 --- a/proto-extension/src/main/kotlin/io/spine/examples/protodata/hello/ArrayOfSizeOptionProvider.kt +++ b/proto-extension/src/main/kotlin/io/spine/examples/protodata/hello/ArrayOfSizeOptionProvider.kt @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/proto-extension/src/main/kotlin/io/spine/examples/protodata/hello/package-info.java b/proto-extension/src/main/kotlin/io/spine/examples/protodata/hello/package-info.java index 25492bb..43a6331 100644 --- a/proto-extension/src/main/kotlin/io/spine/examples/protodata/hello/package-info.java +++ b/proto-extension/src/main/kotlin/io/spine/examples/protodata/hello/package-info.java @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/proto-extension/src/main/proto/spine/examples/protodata/hello/options.proto b/proto-extension/src/main/proto/spine/examples/protodata/hello/options.proto index 4370fb9..746b40f 100644 --- a/proto-extension/src/main/proto/spine/examples/protodata/hello/options.proto +++ b/proto-extension/src/main/proto/spine/examples/protodata/hello/options.proto @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/settings.gradle.kts b/settings.gradle.kts index 3ed82cb..ecc5524 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -5,7 +5,7 @@ * 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 + * 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 diff --git a/version.gradle.kts b/version.gradle.kts index 87a8883..cb81492 100644 --- a/version.gradle.kts +++ b/version.gradle.kts @@ -5,7 +5,7 @@ * 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 + * 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 From 0364c4c0371e8273610de6f4a1a115920be362d9 Mon Sep 17 00:00:00 2001 From: "oleg.melnik" Date: Tue, 30 Jul 2024 16:01:43 +0300 Subject: [PATCH 09/13] Fix git config. --- .gitmodules | 3 --- config | 1 - 2 files changed, 4 deletions(-) delete mode 160000 config diff --git a/.gitmodules b/.gitmodules index 94e8664..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "config"] - path = config - url = https://github.com/SpineEventEngine/config diff --git a/config b/config deleted file mode 160000 index 3478c12..0000000 --- a/config +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3478c12027df47eab3d195cca0c2ff38bc7163f4 From 1b40f30f0208251670fa58f5eddaae86072bb859 Mon Sep 17 00:00:00 2001 From: "oleg.melnik" Date: Tue, 30 Jul 2024 16:12:27 +0300 Subject: [PATCH 10/13] Add detekt config. --- config/quality/detekt-config.yml | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 config/quality/detekt-config.yml diff --git a/config/quality/detekt-config.yml b/config/quality/detekt-config.yml new file mode 100644 index 0000000..36b61a9 --- /dev/null +++ b/config/quality/detekt-config.yml @@ -0,0 +1,36 @@ + +naming: + ClassNaming: + excludes: &testFiles # Allows ticks-named nested test and spec suites. + - "**/*Test.kt" + - "**/*Spec.kt" + MatchingDeclarationName: + excludes: *testFiles # Allows ticks-named top-level test and spec suites. + +style: + UnusedPrivateMember: + allowedNames: '(_|ignored|expected|serialVersionUID|about|ABOUT)' + MagicNumber: + ignoreNumbers: + - '-1' + - '0' + - '1' + - '2' + - '3' + MaxLineLength: + maxLineLength: 100 + excludeCommentStatements: true + ForbiddenComment: + allowedPatterns: 'TODO:' + +complexity: + TooManyFunctions: + excludes: + - '**/*Exts.kt' + - '**/*Extensions.kt' + - '**/*View.kt' + - '**/*Projection.kt' + - '**/*Test.kt' + - '**/*Spec.kt' + LongMethod: + excludes: *testFiles # Allows long names for test and spec methods. From 274af234ab1d0254741ad8bb80f778b10762b251 Mon Sep 17 00:00:00 2001 From: "oleg.melnik" Date: Tue, 30 Jul 2024 16:41:38 +0300 Subject: [PATCH 11/13] Get rid of build warnings. --- proto-extension/build.gradle.kts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/proto-extension/build.gradle.kts b/proto-extension/build.gradle.kts index 53e6dd7..2a6b39b 100644 --- a/proto-extension/build.gradle.kts +++ b/proto-extension/build.gradle.kts @@ -58,3 +58,12 @@ publishing { } } } + +// To avoid warning on implicit tasks dependency. +// See https://discuss.gradle.org/t/implicit-dependency-among-tasks-but-the-tasks-do-not-exist/46127 +// for details. +tasks.configureEach { + if (name == "kspKotlin") { + mustRunAfter(tasks.named("launchProtoData")) + } +} From 45c4ad4593b6601fc38513bcee5c83ae4764b1ab Mon Sep 17 00:00:00 2001 From: "oleg.melnik" Date: Tue, 30 Jul 2024 16:54:30 +0300 Subject: [PATCH 12/13] Remove usage of hardcoded ProtoData version. --- .../src/main/kotlin/io/spine/internal/dependency/ProtoData.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/main/kotlin/io/spine/internal/dependency/ProtoData.kt b/buildSrc/src/main/kotlin/io/spine/internal/dependency/ProtoData.kt index c5a8ae0..2a64566 100644 --- a/buildSrc/src/main/kotlin/io/spine/internal/dependency/ProtoData.kt +++ b/buildSrc/src/main/kotlin/io/spine/internal/dependency/ProtoData.kt @@ -65,7 +65,7 @@ object ProtoData { const val version: String = "0.50.0" const val lib: String = - "io.spine:protodata:0.50.0" + "io.spine:protodata:$version" const val pluginLib: String = "$group:gradle-plugin:$version" From 86509114fa4276224c20703133828edb36e6c55c Mon Sep 17 00:00:00 2001 From: "oleg.melnik" Date: Wed, 31 Jul 2024 15:05:52 +0300 Subject: [PATCH 13/13] Do not apply `ModelCompiler` to "proto-extension" module. Remove some unnecessary build scripts. Remove usage of `System.out`. --- build.gradle.kts | 8 ++- .../main/kotlin/build-proto-model.gradle.kts | 45 --------------- .../main/kotlin/compile-protobuf.gradle.kts | 45 --------------- .../src/main/kotlin/config-tester.gradle.kts | 57 ------------------- .../hello/test/ApplySizeOptionPluginTest.kt | 9 +-- proto-extension/build.gradle.kts | 23 +------- 6 files changed, 9 insertions(+), 178 deletions(-) delete mode 100644 buildSrc/src/main/kotlin/build-proto-model.gradle.kts delete mode 100644 buildSrc/src/main/kotlin/compile-protobuf.gradle.kts delete mode 100644 buildSrc/src/main/kotlin/config-tester.gradle.kts diff --git a/build.gradle.kts b/build.gradle.kts index 67a5afb..01a440c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -85,7 +85,13 @@ subprojects { plugin("detekt-code-analysis") plugin("com.google.protobuf") plugin("idea") - plugin("io.spine.mc-java") + } + + // Apply ModelCompiler to every subproject except "proto-extension". + if (!name.contains("proto-extension")) { + apply { + plugin("io.spine.mc-java") + } } dependencies { diff --git a/buildSrc/src/main/kotlin/build-proto-model.gradle.kts b/buildSrc/src/main/kotlin/build-proto-model.gradle.kts deleted file mode 100644 index 5721ed3..0000000 --- a/buildSrc/src/main/kotlin/build-proto-model.gradle.kts +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2023, 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. - */ - -@file:Suppress("RemoveRedundantQualifierName") - -import io.spine.internal.dependency.Protobuf -import io.spine.internal.dependency.Spine.McJava - -/** - * The dependency onto Spine Validation causes the circular dependency in this Gradle project. - * Therefore, we disable the validation altogether. - */ -System.setProperty("spine.internal.validation.disabled", "true") - -apply { - plugin(Protobuf.GradlePlugin.id) - plugin(McJava.pluginId) -} - -dependencies { - Protobuf.libs.forEach { "api"(it) } -} diff --git a/buildSrc/src/main/kotlin/compile-protobuf.gradle.kts b/buildSrc/src/main/kotlin/compile-protobuf.gradle.kts deleted file mode 100644 index c5be445..0000000 --- a/buildSrc/src/main/kotlin/compile-protobuf.gradle.kts +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2024, 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 io.spine.internal.dependency.Protobuf -import io.spine.internal.gradle.protobuf.setup - -plugins { - id("java-library") - id("com.google.protobuf") -} - - -// For generating test fixtures. See `src/test/proto`. -protobuf { - configurations.excludeProtobufLite() - protoc { - artifact = Protobuf.compiler - } - generateProtoTasks.all().configureEach { - setup() - } -} diff --git a/buildSrc/src/main/kotlin/config-tester.gradle.kts b/buildSrc/src/main/kotlin/config-tester.gradle.kts deleted file mode 100644 index faf3113..0000000 --- a/buildSrc/src/main/kotlin/config-tester.gradle.kts +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2024, 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 io.spine.internal.gradle.ConfigTester -import io.spine.internal.gradle.SpineRepos -import io.spine.internal.gradle.cleanFolder -import java.nio.file.Path -import java.nio.file.Paths - -// A reference to `config` to use along with the `ConfigTester`. -val config: Path = Paths.get("./") - -// A temp folder to use to check out the sources of other repositories with the `ConfigTester`. -val tempFolder = File("./tmp") - -// Creates a Gradle task which checks out and builds the selected Spine repositories -// with the local version of `config` and `config/buildSrc`. -ConfigTester(config, tasks, tempFolder) - .addRepo(SpineRepos.baseTypes) // Builds `base-types` at `master`. - .addRepo(SpineRepos.base) // Builds `base` at `master`. - .addRepo(SpineRepos.coreJava) // Builds `core-java` at `master`. - - // This is how one builds a specific branch of some repository: - // .addRepo(SpineRepos.coreJava, Branch("grpc-concurrency-fixes")) - - // Register the produced task under the selected name to invoke manually upon need. - .registerUnder("buildDependants") - -// Cleans the temp folder used to check out the sources from Git. -tasks.register("clean") { - doLast { - cleanFolder(tempFolder) - } -} diff --git a/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/ApplySizeOptionPluginTest.kt b/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/ApplySizeOptionPluginTest.kt index d1aff84..8fe2445 100644 --- a/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/ApplySizeOptionPluginTest.kt +++ b/integration-tests/src/test/kotlin/io/spine/examples/protodata/hello/test/ApplySizeOptionPluginTest.kt @@ -157,15 +157,8 @@ class `ApplySizeOptionPlugin should` { } catch (_: UnexpectedBuildFailure) { } - val sdterrContent = stderr.toString() - val errorFound = sdterrContent.contains(expectedExceptionMessage) - - System.err.println(sdterrContent) - - //check(errorFound) { sdterrContent } - assertTrue( - errorFound, + stderr.toString().contains(expectedExceptionMessage), "The expected exception was not thrown." ) } diff --git a/proto-extension/build.gradle.kts b/proto-extension/build.gradle.kts index 2a6b39b..db41222 100644 --- a/proto-extension/build.gradle.kts +++ b/proto-extension/build.gradle.kts @@ -26,7 +26,6 @@ import io.spine.internal.dependency.AutoService import io.spine.internal.dependency.AutoServiceKsp import io.spine.internal.dependency.HelloProtoData -import io.spine.internal.dependency.Validation plugins { `maven-publish` @@ -35,19 +34,8 @@ plugins { dependencies { // To use @AutoService in options provider. - compileOnly(AutoService.annotations) + api(AutoService.annotations) ksp(AutoServiceKsp.processor) - - // To allow access to `ValidatingBuilder` from the generated Kotlin code. - implementation(Validation.runtime) -} - -modelCompiler { - java { - codegen { - validation().enabled.set(false) - } - } } publishing { @@ -58,12 +46,3 @@ publishing { } } } - -// To avoid warning on implicit tasks dependency. -// See https://discuss.gradle.org/t/implicit-dependency-among-tasks-but-the-tasks-do-not-exist/46127 -// for details. -tasks.configureEach { - if (name == "kspKotlin") { - mustRunAfter(tasks.named("launchProtoData")) - } -}