diff --git a/buildSrc/src/main/kotlin/io/spine/dependency/local/ToolBase.kt b/buildSrc/src/main/kotlin/io/spine/dependency/local/ToolBase.kt index eaf5c44776..643c107796 100644 --- a/buildSrc/src/main/kotlin/io/spine/dependency/local/ToolBase.kt +++ b/buildSrc/src/main/kotlin/io/spine/dependency/local/ToolBase.kt @@ -34,10 +34,12 @@ package io.spine.dependency.local @Suppress("ConstPropertyName", "unused") object ToolBase { const val group = Spine.toolsGroup - const val version = "2.0.0-SNAPSHOT.333" + const val version = "2.0.0-SNAPSHOT.335" const val lib = "$group:spine-tool-base:$version" const val pluginBase = "$group:spine-plugin-base:$version" + const val gradleRootPlugin = "$group:spine-gradle-root-plugin:$version" + const val gradlePluginApi = "$group:spine-gradle-plugin-api:$version" const val pluginTestlib = "$group:spine-plugin-testlib:$version" const val intellijPlatformJava = "$group:intellij-platform-java:$version" diff --git a/dependencies.md b/dependencies.md index 0d2de0d950..c49cd675bf 100644 --- a/dependencies.md +++ b/dependencies.md @@ -1,6 +1,6 @@ -# Dependencies of `io.spine.compiler:api:2.0.0-SNAPSHOT.007` +# Dependencies of `io.spine.compiler:api:2.0.0-SNAPSHOT.008` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.18.3. @@ -1046,12 +1046,12 @@ The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue May 27 20:07:11 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). +This report was generated on **Tue Jun 03 18:11:05 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.compiler:api-tests:2.0.0-SNAPSHOT.007` +# Dependencies of `io.spine.compiler:api-tests:2.0.0-SNAPSHOT.008` ## Runtime 1. **Group** : org.jetbrains. **Name** : annotations. **Version** : 13.0. @@ -1836,12 +1836,12 @@ This report was generated on **Tue May 27 20:07:11 WEST 2025** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue May 27 20:07:11 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). +This report was generated on **Tue Jun 03 18:11:05 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.compiler:backend:2.0.0-SNAPSHOT.007` +# Dependencies of `io.spine.compiler:backend:2.0.0-SNAPSHOT.008` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.18.3. @@ -2887,12 +2887,12 @@ This report was generated on **Tue May 27 20:07:11 WEST 2025** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue May 27 20:07:11 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). +This report was generated on **Tue Jun 03 18:11:05 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.compiler:cli:2.0.0-SNAPSHOT.007` +# Dependencies of `io.spine.compiler:cli:2.0.0-SNAPSHOT.008` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.18.3. @@ -3962,12 +3962,12 @@ This report was generated on **Tue May 27 20:07:11 WEST 2025** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue May 27 20:07:11 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). +This report was generated on **Tue Jun 03 18:11:05 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.compiler:gradle-api:2.0.0-SNAPSHOT.007` +# Dependencies of `io.spine.compiler:gradle-api:2.0.0-SNAPSHOT.008` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.18.3. @@ -4948,12 +4948,12 @@ This report was generated on **Tue May 27 20:07:11 WEST 2025** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue May 27 20:07:11 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). +This report was generated on **Tue Jun 03 18:11:05 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.compiler:gradle-plugin:2.0.0-SNAPSHOT.007` +# Dependencies of `io.spine.compiler:gradle-plugin:2.0.0-SNAPSHOT.008` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.18.3. @@ -5982,12 +5982,12 @@ This report was generated on **Tue May 27 20:07:11 WEST 2025** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue May 27 20:07:11 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). +This report was generated on **Tue Jun 03 18:11:05 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.compiler:jvm:2.0.0-SNAPSHOT.007` +# Dependencies of `io.spine.compiler:jvm:2.0.0-SNAPSHOT.008` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.18.3. @@ -7033,12 +7033,12 @@ This report was generated on **Tue May 27 20:07:11 WEST 2025** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue May 27 20:07:11 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). +This report was generated on **Tue Jun 03 18:11:05 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.compiler:params:2.0.0-SNAPSHOT.007` +# Dependencies of `io.spine.compiler:params:2.0.0-SNAPSHOT.008` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.18.3. @@ -8076,12 +8076,12 @@ This report was generated on **Tue May 27 20:07:11 WEST 2025** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue May 27 20:07:11 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). +This report was generated on **Tue Jun 03 18:11:05 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.compiler:protoc-plugin:2.0.0-SNAPSHOT.007` +# Dependencies of `io.spine.compiler:protoc-plugin:2.0.0-SNAPSHOT.008` ## Runtime 1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2. @@ -8884,12 +8884,12 @@ This report was generated on **Tue May 27 20:07:11 WEST 2025** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue May 27 20:07:11 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). +This report was generated on **Tue Jun 03 18:11:05 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.compiler:test-env:2.0.0-SNAPSHOT.007` +# Dependencies of `io.spine.compiler:test-env:2.0.0-SNAPSHOT.008` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.18.3. @@ -9931,12 +9931,12 @@ This report was generated on **Tue May 27 20:07:11 WEST 2025** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue May 27 20:07:11 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). +This report was generated on **Tue Jun 03 18:11:05 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.compiler:testlib:2.0.0-SNAPSHOT.007` +# Dependencies of `io.spine.compiler:testlib:2.0.0-SNAPSHOT.008` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.18.3. @@ -11080,4 +11080,4 @@ This report was generated on **Tue May 27 20:07:11 WEST 2025** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue May 27 20:07:11 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). \ No newline at end of file +This report was generated on **Tue Jun 03 18:11:05 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). \ No newline at end of file diff --git a/gradle-api/build.gradle.kts b/gradle-api/build.gradle.kts index d0689f8403..7ffc5045d0 100644 --- a/gradle-api/build.gradle.kts +++ b/gradle-api/build.gradle.kts @@ -34,6 +34,7 @@ dependencies { compileOnly(gradleApi()) implementation(ToolBase.pluginBase) + implementation(ToolBase.gradlePluginApi) implementation(project(":api")) implementation(project(":params")) diff --git a/gradle-api/src/main/kotlin/io/spine/compiler/gradle/api/CodegenSettings.kt b/gradle-api/src/main/kotlin/io/spine/compiler/gradle/api/CompilerSettings.kt similarity index 90% rename from gradle-api/src/main/kotlin/io/spine/compiler/gradle/api/CodegenSettings.kt rename to gradle-api/src/main/kotlin/io/spine/compiler/gradle/api/CompilerSettings.kt index 0c247a42e9..5feb001484 100644 --- a/gradle-api/src/main/kotlin/io/spine/compiler/gradle/api/CodegenSettings.kt +++ b/gradle-api/src/main/kotlin/io/spine/compiler/gradle/api/CompilerSettings.kt @@ -29,13 +29,13 @@ package io.spine.compiler.gradle.api import org.gradle.api.file.DirectoryProperty /** - * Configures the code generation process performed by ProtoData. + * Configures the code generation process performed by the Compiler. */ -public interface CodegenSettings { +public interface CompilerSettings { /** - * Passes given names of Java classes to ProtoData as - * the `io.spine.compiler.plugin.Plugin` classes. + * Passes given names of Java classes to the Compiler as classes + * extending the `io.spine.compiler.plugin.Plugin` class. */ public fun plugins(vararg classNames: String) diff --git a/gradle-api/src/main/kotlin/io/spine/compiler/gradle/api/Names.kt b/gradle-api/src/main/kotlin/io/spine/compiler/gradle/api/Names.kt index 0eaa4e454d..51a8e12d56 100644 --- a/gradle-api/src/main/kotlin/io/spine/compiler/gradle/api/Names.kt +++ b/gradle-api/src/main/kotlin/io/spine/compiler/gradle/api/Names.kt @@ -27,7 +27,7 @@ package io.spine.compiler.gradle.api /** - * The name of various objects in ProtoData Gradle API. + * The name of various objects in Spine Compiler Gradle API. */ public object Names { diff --git a/gradle-api/src/main/kotlin/io/spine/compiler/gradle/api/ProjectExts.kt b/gradle-api/src/main/kotlin/io/spine/compiler/gradle/api/ProjectExts.kt index e66ac829be..253693a265 100644 --- a/gradle-api/src/main/kotlin/io/spine/compiler/gradle/api/ProjectExts.kt +++ b/gradle-api/src/main/kotlin/io/spine/compiler/gradle/api/ProjectExts.kt @@ -26,10 +26,12 @@ package io.spine.compiler.gradle.api -import org.gradle.api.Project -import io.spine.compiler.params.Directories.PROTODATA_WORKING_DIR +import io.spine.compiler.params.Directories.COMPILER_WORKING_DIR +import io.spine.tools.gradle.lib.spineExtension +import io.spine.tools.gradle.root.rootWorkingDir import java.io.File import java.nio.file.Path +import org.gradle.api.Project import org.gradle.api.file.Directory import org.gradle.api.tasks.SourceSet @@ -37,20 +39,20 @@ import org.gradle.api.tasks.SourceSet * Obtains the directory where ProtoData stores its temporary files. */ public val Project.compilerWorkingDir: Directory - get() = layout.buildDirectory.dir(PROTODATA_WORKING_DIR).get() + get() = rootWorkingDir.dir(COMPILER_WORKING_DIR) /** - * Obtains the instance of [CodegenSettings] extension of this project. + * Obtains the instance of [CompilerSettings] extension of this project. */ -public val Project.codegenSettings: CodegenSettings - get() = extensions.findByType(CodegenSettings::class.java)!! +public val Project.compilerSettings: CompilerSettings + get() = spineExtension() /** * Obtains the path of the directory with the generated code as configured by - * the [CodegenSettings.outputBaseDir] property of the ProtoData extension of this Gradle project. + * the [CompilerSettings.outputBaseDir] property of the ProtoData extension of this Gradle project. */ public val Project.generatedDir: Path - get() = codegenSettings.outputBaseDir.get().asFile.toPath() + get() = compilerSettings.outputBaseDir.get().asFile.toPath() /** * Obtains the `generated` directory for the given [sourceSet] and a language. diff --git a/gradle-plugin/build.gradle.kts b/gradle-plugin/build.gradle.kts index 281f10b21b..d662dee63b 100644 --- a/gradle-plugin/build.gradle.kts +++ b/gradle-plugin/build.gradle.kts @@ -72,13 +72,14 @@ testing { } dependencies { - api(project(":gradle-api")) - compileOnly(gradleApi()) compileOnly(gradleKotlinDsl()) compileOnly(Protobuf.GradlePlugin.lib) compileOnly(Kotlin.GradlePlugin.api) + api(project(":gradle-api")) + api(ToolBase.gradlePluginApi) + implementation(project(":api")) implementation(project(":params")) implementation(ToolBase.lib) @@ -89,6 +90,7 @@ dependencies { * Make functional tests depend on publishing all the submodules to Maven Local so that * the Gradle plugin can get all the dependencies when it's applied to the test projects. */ +@Suppress("unused") val functionalTest: Task by tasks.getting { val task = this productionModules.forEach { subproject -> @@ -108,6 +110,7 @@ val publishPlugins: Task by tasks.getting { enabled = !isSnapshot } +@Suppress("unused") val publish: Task by tasks.getting { if (!isSnapshot) { dependsOn(publishPlugins) diff --git a/gradle-plugin/src/functionalTest/kotlin/io/spine/compiler/gradle/plugin/PluginSpec.kt b/gradle-plugin/src/functionalTest/kotlin/io/spine/compiler/gradle/plugin/PluginSpec.kt index 64a14c89c7..9ee5cb2f82 100644 --- a/gradle-plugin/src/functionalTest/kotlin/io/spine/compiler/gradle/plugin/PluginSpec.kt +++ b/gradle-plugin/src/functionalTest/kotlin/io/spine/compiler/gradle/plugin/PluginSpec.kt @@ -76,6 +76,49 @@ class PluginSpec { generatedKotlinDir = generatedMainDir.resolve("kotlin") } + private fun createProject(resourceDir: String) { + val version = Plugin.readVersion() + val builder = GradleProject.setupAt(projectDir) + .fromResources(resourceDir) + .withSharedTestKitDirectory() + .replace("@COMPILER_PLUGIN_ID@", GRADLE_PLUGIN_ID) + .replace("@COMPILER_VERSION@", version) + .withLoggingLevel(LogLevel.INFO) + /* Uncomment the following if you need to debug the build process. + Please note that: + 1) Test will run much slower. + 2) Under Windows it may cause this issue to occur: + https://github.com/gradle/native-platform/issues/274 + After finishing the debug, please comment out this call again. */ + //.enableRunnerDebug() + .copyBuildSrc() + project = builder.create() + (project.runner as DefaultGradleRunner).withJvmArguments( + "-Xmx8g", + "-XX:MaxMetaspaceSize=1512m", + "-XX:+UseParallelGC", + "-XX:+HeapDumpOnOutOfMemoryError" + ) + } + + private fun createEmptyProject() { + createProject("empty-test") + } + + private fun createLaunchTestProject() { + createProject("launch-test") + } + + private fun launchAndExpectResult(expected: TaskOutcome) { + val result = launch() + + val outcome = result[launchSpineCompiler] + outcome shouldBe expected + } + + private fun launch(): BuildResult = + project.executeTask(launchSpineCompiler) + /** * Since there are no `proto` files in this project, the request file is * not created, resulting in the [SKIPPED] status of the [launchSpineCompiler] task. @@ -87,7 +130,7 @@ class PluginSpec { } @Test - fun `launch ProtoData`() { + fun `launch the compiler task`() { createLaunchTestProject() launchAndExpectResult(SUCCESS) } @@ -168,49 +211,6 @@ class PluginSpec { assertExists(generatedGrpcDir) assertExists(generatedGrpcDir.resolve(serviceClass)) } - - private fun createEmptyProject() { - createProject("empty-test") - } - - private fun createLaunchTestProject() { - createProject("launch-test") - } - - private fun launchAndExpectResult(expected: TaskOutcome) { - val result = launch() - - val outcome = result[launchSpineCompiler] - outcome shouldBe expected - } - - private fun launch(): BuildResult = - project.executeTask(launchSpineCompiler) - - private fun createProject(resourceDir: String) { - val version = Plugin.readVersion() - val builder = GradleProject.setupAt(projectDir) - .fromResources(resourceDir) - .withSharedTestKitDirectory() - .replace("@PROTODATA_PLUGIN_ID@", GRADLE_PLUGIN_ID) - .replace("@PROTODATA_VERSION@", version) - .withLoggingLevel(LogLevel.INFO) - /* Uncomment the following if you need to debug the build process. - Please note that: - 1) Test will run much slower. - 2) Under Windows it may cause this issue to occur: - https://github.com/gradle/native-platform/issues/274 - After finishing the debug, please comment out this call again. */ - //.enableRunnerDebug() - .copyBuildSrc() - project = builder.create() - (project.runner as DefaultGradleRunner).withJvmArguments( - "-Xmx8g", - "-XX:MaxMetaspaceSize=1512m", - "-XX:+UseParallelGC", - "-XX:+HeapDumpOnOutOfMemoryError" - ) - } } /** diff --git a/gradle-plugin/src/functionalTest/resources/android-library/build.gradle.kts b/gradle-plugin/src/functionalTest/resources/android-library/build.gradle.kts index df54a9a70a..5bbbed6a1a 100644 --- a/gradle-plugin/src/functionalTest/resources/android-library/build.gradle.kts +++ b/gradle-plugin/src/functionalTest/resources/android-library/build.gradle.kts @@ -34,7 +34,7 @@ buildscript { plugins { id("com.android.library") version "7.3.0" // Protobuf needs it to run. id("com.google.protobuf") - id("@PROTODATA_PLUGIN_ID@") version "@PROTODATA_VERSION@" + id("@COMPILER_PLUGIN_ID@") version "@COMPILER_VERSION@" } repositories { @@ -42,11 +42,13 @@ repositories { standardToSpineSdk() } -compiler { - plugins( - "io.spine.compiler.test.UnderscorePrefixRendererPlugin", - "io.spine.compiler.test.TestPlugin" - ) +spine { + compiler { + plugins( + "io.spine.compiler.test.UnderscorePrefixRendererPlugin", + "io.spine.compiler.test.TestPlugin" + ) + } } dependencies { diff --git a/gradle-plugin/src/functionalTest/resources/copy-grpc/build.gradle.kts b/gradle-plugin/src/functionalTest/resources/copy-grpc/build.gradle.kts index b64e0c05d7..0d9396b66f 100644 --- a/gradle-plugin/src/functionalTest/resources/copy-grpc/build.gradle.kts +++ b/gradle-plugin/src/functionalTest/resources/copy-grpc/build.gradle.kts @@ -37,7 +37,7 @@ plugins { java kotlin("jvm") id("com.google.protobuf") - id("@PROTODATA_PLUGIN_ID@") version "@PROTODATA_VERSION@" + id("@COMPILER_PLUGIN_ID@") version "@COMPILER_VERSION@" } repositories { diff --git a/gradle-plugin/src/functionalTest/resources/empty-test/build.gradle.kts b/gradle-plugin/src/functionalTest/resources/empty-test/build.gradle.kts index ebfdfc1fd7..51c0da3211 100644 --- a/gradle-plugin/src/functionalTest/resources/empty-test/build.gradle.kts +++ b/gradle-plugin/src/functionalTest/resources/empty-test/build.gradle.kts @@ -35,7 +35,7 @@ plugins { java kotlin("jvm") id("com.google.protobuf") - id("@PROTODATA_PLUGIN_ID@") version "@PROTODATA_VERSION@" + id("@COMPILER_PLUGIN_ID@") version "@COMPILER_VERSION@" } repositories { @@ -53,9 +53,11 @@ protobuf { } } -compiler { - plugins( - "io.spine.compiler.test.UnderscorePrefixRendererPlugin", - "io.spine.compiler.test.TestPlugin" - ) +spine { + compiler { + plugins( + "io.spine.compiler.test.UnderscorePrefixRendererPlugin", + "io.spine.compiler.test.TestPlugin" + ) + } } diff --git a/gradle-plugin/src/functionalTest/resources/java-kotlin-test/build.gradle.kts b/gradle-plugin/src/functionalTest/resources/java-kotlin-test/build.gradle.kts index a28adcaef1..8e18d16943 100644 --- a/gradle-plugin/src/functionalTest/resources/java-kotlin-test/build.gradle.kts +++ b/gradle-plugin/src/functionalTest/resources/java-kotlin-test/build.gradle.kts @@ -36,7 +36,7 @@ plugins { java kotlin("jvm") id("com.google.protobuf") - id("@PROTODATA_PLUGIN_ID@") version "@PROTODATA_VERSION@" + id("@COMPILER_PLUGIN_ID@") version "@COMPILER_VERSION@" } repositories { @@ -44,11 +44,13 @@ repositories { standardToSpineSdk() } -compiler { - plugins( - "io.spine.compiler.test.NoOpRendererPlugin", - "io.spine.compiler.test.TestPlugin" - ) +spine { + compiler { + plugins( + "io.spine.compiler.test.NoOpRendererPlugin", + "io.spine.compiler.test.TestPlugin" + ) + } } dependencies { diff --git a/gradle-plugin/src/functionalTest/resources/java-library-kotlin-jvm/build.gradle.kts b/gradle-plugin/src/functionalTest/resources/java-library-kotlin-jvm/build.gradle.kts index 2113888d92..f73bddc7a1 100644 --- a/gradle-plugin/src/functionalTest/resources/java-library-kotlin-jvm/build.gradle.kts +++ b/gradle-plugin/src/functionalTest/resources/java-library-kotlin-jvm/build.gradle.kts @@ -36,7 +36,7 @@ plugins { `java-library` kotlin("jvm") id("com.google.protobuf") - id("@PROTODATA_PLUGIN_ID@") version "@PROTODATA_VERSION@" + id("@COMPILER_PLUGIN_ID@") version "@COMPILER_VERSION@" } repositories { @@ -44,11 +44,13 @@ repositories { standardToSpineSdk() } -compiler { - plugins( - "io.spine.compiler.test.NoOpRendererPlugin", - "io.spine.compiler.test.TestPlugin" - ) +spine { + compiler { + plugins( + "io.spine.compiler.test.NoOpRendererPlugin", + "io.spine.compiler.test.TestPlugin" + ) + } } dependencies { diff --git a/gradle-plugin/src/functionalTest/resources/kotlin-test/build.gradle.kts b/gradle-plugin/src/functionalTest/resources/kotlin-test/build.gradle.kts index ee665034b0..f540ed0af3 100644 --- a/gradle-plugin/src/functionalTest/resources/kotlin-test/build.gradle.kts +++ b/gradle-plugin/src/functionalTest/resources/kotlin-test/build.gradle.kts @@ -35,7 +35,7 @@ buildscript { plugins { kotlin("jvm") id("com.google.protobuf") - id("@PROTODATA_PLUGIN_ID@") version "@PROTODATA_VERSION@" + id("@COMPILER_PLUGIN_ID@") version "@COMPILER_VERSION@" } repositories { @@ -43,11 +43,13 @@ repositories { standardToSpineSdk() } -compiler { - plugins( - "io.spine.compiler.test.NoOpRendererPlugin", - "io.spine.compiler.test.TestPlugin" - ) +spine { + compiler { + plugins( + "io.spine.compiler.test.NoOpRendererPlugin", + "io.spine.compiler.test.TestPlugin" + ) + } } dependencies { diff --git a/gradle-plugin/src/functionalTest/resources/launch-test/build.gradle.kts b/gradle-plugin/src/functionalTest/resources/launch-test/build.gradle.kts index ebfdfc1fd7..51c0da3211 100644 --- a/gradle-plugin/src/functionalTest/resources/launch-test/build.gradle.kts +++ b/gradle-plugin/src/functionalTest/resources/launch-test/build.gradle.kts @@ -35,7 +35,7 @@ plugins { java kotlin("jvm") id("com.google.protobuf") - id("@PROTODATA_PLUGIN_ID@") version "@PROTODATA_VERSION@" + id("@COMPILER_PLUGIN_ID@") version "@COMPILER_VERSION@" } repositories { @@ -53,9 +53,11 @@ protobuf { } } -compiler { - plugins( - "io.spine.compiler.test.UnderscorePrefixRendererPlugin", - "io.spine.compiler.test.TestPlugin" - ) +spine { + compiler { + plugins( + "io.spine.compiler.test.UnderscorePrefixRendererPlugin", + "io.spine.compiler.test.TestPlugin" + ) + } } diff --git a/gradle-plugin/src/functionalTest/resources/with-functional-test/build.gradle.kts b/gradle-plugin/src/functionalTest/resources/with-functional-test/build.gradle.kts index c62988e31c..51d556f495 100644 --- a/gradle-plugin/src/functionalTest/resources/with-functional-test/build.gradle.kts +++ b/gradle-plugin/src/functionalTest/resources/with-functional-test/build.gradle.kts @@ -37,7 +37,7 @@ plugins { java kotlin("jvm") id("com.google.protobuf") - id("@PROTODATA_PLUGIN_ID@") version "@PROTODATA_VERSION@" + id("@COMPILER_PLUGIN_ID@") version "@COMPILER_VERSION@" } repositories { @@ -45,11 +45,13 @@ repositories { standardToSpineSdk() } -compiler { - plugins( - "io.spine.compiler.test.NoOpRendererPlugin", - "io.spine.compiler.test.TestPlugin" - ) +spine { + compiler { + plugins( + "io.spine.compiler.test.NoOpRendererPlugin", + "io.spine.compiler.test.TestPlugin" + ) + } } dependencies { diff --git a/gradle-plugin/src/main/kotlin/io/spine/compiler/gradle/plugin/Extension.kt b/gradle-plugin/src/main/kotlin/io/spine/compiler/gradle/plugin/Extension.kt index 66334a24d1..a6e18d47e2 100644 --- a/gradle-plugin/src/main/kotlin/io/spine/compiler/gradle/plugin/Extension.kt +++ b/gradle-plugin/src/main/kotlin/io/spine/compiler/gradle/plugin/Extension.kt @@ -27,12 +27,15 @@ package io.spine.compiler.gradle.plugin import com.google.common.annotations.VisibleForTesting -import io.spine.compiler.gradle.api.CodegenSettings +import io.spine.compiler.gradle.api.CompilerSettings +import io.spine.compiler.gradle.api.Names.EXTENSION_NAME import io.spine.tools.fs.DirectoryName.generated +import io.spine.tools.gradle.DslSpec import io.spine.tools.gradle.protobuf.generatedSourceProtoDir import org.gradle.api.Project import org.gradle.api.file.Directory import org.gradle.api.file.DirectoryProperty +import org.gradle.api.plugins.ExtensionContainer import org.gradle.api.provider.ListProperty import org.gradle.api.provider.Provider import org.gradle.api.tasks.SourceSet @@ -41,7 +44,7 @@ import org.gradle.kotlin.dsl.listProperty /** * The `compiler { }` Gradle project extension. */ -public class Extension(private val project: Project): CodegenSettings { +public class Extension(private val project: Project): CompilerSettings { private val factory = project.objects @@ -145,3 +148,23 @@ public class Extension(private val project: Project): CodegenSettings { ) } } + +/** + * Overrides [DslSpec] for customizing creation of the [Extension]. + */ +internal class CompilerDslSpec : + DslSpec(EXTENSION_NAME, CompilerSettings::class) { + + /** + * The function for obtaining a project to which the [Plugin] is applied. + * + * This property is injected at the [Plugin] constructor. + */ + internal lateinit var project: () -> Project + + override fun createIn(container: ExtensionContainer): CompilerSettings { + val extension = Extension(project()) + container.add(extensionClass.java, name, extension) + return extension + } +} diff --git a/gradle-plugin/src/main/kotlin/io/spine/compiler/gradle/plugin/LaunchSpineCompiler.kt b/gradle-plugin/src/main/kotlin/io/spine/compiler/gradle/plugin/LaunchSpineCompiler.kt index 6431386dbf..86c803a3ff 100644 --- a/gradle-plugin/src/main/kotlin/io/spine/compiler/gradle/plugin/LaunchSpineCompiler.kt +++ b/gradle-plugin/src/main/kotlin/io/spine/compiler/gradle/plugin/LaunchSpineCompiler.kt @@ -172,7 +172,7 @@ public abstract class LaunchSpineCompiler : JavaExec() { internal fun LaunchSpineCompiler.applyDefaults(sourceSet: SourceSet) { sourceSetName.set(sourceSet.name) val project = project - val ext = project.extension + val ext = project.compilerSettings plugins = ext.plugins compilerConfiguration = project.compilerRawArtifact userClasspathConfiguration = project.userClasspath diff --git a/gradle-plugin/src/main/kotlin/io/spine/compiler/gradle/plugin/Plugin.kt b/gradle-plugin/src/main/kotlin/io/spine/compiler/gradle/plugin/Plugin.kt index c62f5f0b0b..e74a83068f 100644 --- a/gradle-plugin/src/main/kotlin/io/spine/compiler/gradle/plugin/Plugin.kt +++ b/gradle-plugin/src/main/kotlin/io/spine/compiler/gradle/plugin/Plugin.kt @@ -35,15 +35,14 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue import com.google.protobuf.gradle.GenerateProtoTask import io.spine.code.proto.DescriptorReference import io.spine.compiler.gradle.api.Artifacts -import io.spine.compiler.gradle.api.SpineCompilerCleanTask -import io.spine.compiler.gradle.api.CodegenSettings +import io.spine.compiler.gradle.api.CompilerSettings import io.spine.compiler.gradle.api.CompilerTask import io.spine.compiler.gradle.api.Names.COMPILER_RAW_ARTIFACT -import io.spine.compiler.gradle.api.Names.EXTENSION_NAME import io.spine.compiler.gradle.api.Names.PROTOBUF_GRADLE_PLUGIN_ID import io.spine.compiler.gradle.api.Names.SPINE_COMPILER_PROTOC_PLUGIN import io.spine.compiler.gradle.api.Names.USER_CLASSPATH_CONFIGURATION import io.spine.compiler.gradle.api.ProtocPluginArtifact +import io.spine.compiler.gradle.api.SpineCompilerCleanTask import io.spine.compiler.gradle.api.compilerWorkingDir import io.spine.compiler.gradle.api.generatedDir import io.spine.compiler.gradle.plugin.GeneratedSubdir.GRPC @@ -53,6 +52,8 @@ import io.spine.compiler.params.WorkingDirectory import io.spine.string.toBase64Encoded import io.spine.tools.code.SourceSetName import io.spine.tools.code.manifest.Version +import io.spine.tools.gradle.lib.LibraryPlugin +import io.spine.tools.gradle.lib.spineExtension import io.spine.tools.gradle.project.hasJava import io.spine.tools.gradle.project.hasJavaOrKotlin import io.spine.tools.gradle.project.hasKotlin @@ -70,43 +71,54 @@ import org.gradle.api.tasks.Delete import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.TaskProvider import org.gradle.kotlin.dsl.exclude -import org.gradle.kotlin.dsl.findByType import org.gradle.kotlin.dsl.register -import org.gradle.api.Plugin as GradlePlugin /** - * The ProtoData Gradle plugin. + * The Gradle plugin of the Spine Compiler. * - * Adds the `launchProtoData` task which runs the executable with the arguments assembled from - * the configuration of this plugin. + * Adds the `launchSpineCompiler` tasks which runs the executable with the arguments + * assembled from settings of this plugin. * * The users can submit configuration parameters, such as renderer and plugin class names, etc. via - * the `protoData { }` extension. + * the `compiler { }` extension. * - * The users can submit the user classpath to the ProtoData by declaring dependencies using - * the `protoData` configuration. + * The users can submit the user classpath to the Compiler by declaring dependencies using + * the `spineCompiler` configuration. * * Example: * ``` - * protoData { - * renderers("com.acme.MyRenderer") - * plugins("com.acme.MyPlugin") + * spine { + * compiler { + * plugins("com.acme.MyPlugin") + * } * } * * dependencies { - * protoData(project(":my-plugin")) + * spineCompiler(project(":my-plugin")) * } * ``` */ -public class Plugin : GradlePlugin { +public class Plugin : LibraryPlugin( + CompilerDslSpec() +) { + + init { + // Inject the access to the project so that `CompilerDslSpec` can + // create an instance of `Extension`. + (dslSpec as CompilerDslSpec).project = { this.project } + } + /** + * The version of the plugin. + */ private val version: String by lazy { readVersion() } override fun apply(project: Project) { + super.apply(project) + createExtension() with(project) { - createExtension() createConfigurations(this@Plugin.version) createTasks() configureWithProtobufPlugin(this@Plugin.version) @@ -133,21 +145,8 @@ public class Plugin : GradlePlugin { * * Or, if the extension is not yet added, creates it and returns. */ -internal val Project.extension: Extension - get() = extensions.findByType(CodegenSettings::class)?.run { this as Extension } - ?: createExtension() - -/** - * Creates [Extension] associated with [Plugin] in this project. - * - * The extension is exposed by the type of [CodegenSettings] it implements to hide - * the implementation details from the end-user projects. - */ -private fun Project.createExtension(): Extension { - val extension = Extension(this) - extensions.add(CodegenSettings::class.java, EXTENSION_NAME, extension) - return extension -} +internal val Project.compilerSettings: Extension + get() = spineExtension() as Extension /** * Creates configurations for `protoDataRawArtifact` and user-defined classpath, @@ -205,7 +204,7 @@ private fun Project.createCleanTask(sourceSet: SourceSet) { val project = this val cleanSourceSet = SpineCompilerCleanTask.nameFor(sourceSet) tasks.register(cleanSourceSet) { - delete(extension.outputDirs(sourceSet)) + delete(compilerSettings.outputDirs(sourceSet)) val spineCompilerCleanTask = this tasks.getByName("clean").dependsOn(spineCompilerCleanTask) diff --git a/gradle-plugin/src/test/kotlin/io/spine/compiler/gradle/plugin/ExtensionSpec.kt b/gradle-plugin/src/test/kotlin/io/spine/compiler/gradle/plugin/ExtensionSpec.kt index 06b0d44bf8..b70f9dc110 100644 --- a/gradle-plugin/src/test/kotlin/io/spine/compiler/gradle/plugin/ExtensionSpec.kt +++ b/gradle-plugin/src/test/kotlin/io/spine/compiler/gradle/plugin/ExtensionSpec.kt @@ -29,7 +29,6 @@ package io.spine.compiler.gradle.plugin import com.google.common.truth.Truth.assertThat import com.google.protobuf.gradle.ProtobufPlugin import io.kotest.matchers.shouldBe -import io.spine.compiler.gradle.api.CodegenSettings import io.spine.tools.gradle.project.sourceSets import java.io.File import kotlin.io.path.div @@ -37,7 +36,6 @@ import org.gradle.api.Project import org.gradle.api.file.Directory import org.gradle.api.tasks.SourceSet.MAIN_SOURCE_SET_NAME import org.gradle.kotlin.dsl.apply -import org.gradle.kotlin.dsl.getByType import org.gradle.testfixtures.ProjectBuilder import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.DisplayName @@ -62,7 +60,7 @@ class ExtensionSpec { apply() apply() - this@ExtensionSpec.extension = extensions.getByType() as Extension + this@ExtensionSpec.extension = project.compilerSettings } } diff --git a/gradle-plugin/src/test/kotlin/io/spine/compiler/gradle/plugin/ProjectConfigSpec.kt b/gradle-plugin/src/test/kotlin/io/spine/compiler/gradle/plugin/ProjectConfigSpec.kt index f5dba99835..3ff12d1c5f 100644 --- a/gradle-plugin/src/test/kotlin/io/spine/compiler/gradle/plugin/ProjectConfigSpec.kt +++ b/gradle-plugin/src/test/kotlin/io/spine/compiler/gradle/plugin/ProjectConfigSpec.kt @@ -29,8 +29,9 @@ package io.spine.compiler.gradle.plugin import com.google.common.truth.Correspondence import com.google.common.truth.Truth.assertThat import com.google.protobuf.gradle.ProtobufPlugin +import io.kotest.matchers.shouldNotBe import io.spine.compiler.gradle.api.CompilerTaskName -import io.spine.compiler.gradle.api.Names.EXTENSION_NAME +import io.spine.compiler.gradle.api.compilerSettings import io.spine.tools.code.SourceSetName import io.spine.tools.gradle.project.sourceSets import java.io.File @@ -43,12 +44,12 @@ import org.gradle.testfixtures.ProjectBuilder import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertDoesNotThrow import org.junit.jupiter.api.io.TempDir @DisplayName("Plugin configuration should") class ProjectConfigSpec { - @Suppress("HasPlatformType") companion object { val mainCompilerTask = CompilerTaskName(SourceSetName.main).value() @@ -89,15 +90,14 @@ class ProjectConfigSpec { @Test fun `add extension`() { - val assertExtension = assertThat(project.extensions.getByName(EXTENSION_NAME)) - assertExtension - .isNotNull() - assertExtension - .isInstanceOf(Extension::class.java) + assertDoesNotThrow { + project.compilerSettings + } + project.compilerSettings shouldNotBe null } @Test - fun `bind 'launchProtoData' to Java compilation`() { + fun `bind 'launchSpineCompiler' to Java compilation`() { val task = project.tasks.getByName("compileJava") assertThat(task.dependsOn) .comparingElementsUsing(taskNames) diff --git a/params/src/main/kotlin/io/spine/compiler/params/CodeGeneratorRequestFile.kt b/params/src/main/kotlin/io/spine/compiler/params/CodeGeneratorRequestFile.kt index 26dbf32311..8efd63d6cc 100644 --- a/params/src/main/kotlin/io/spine/compiler/params/CodeGeneratorRequestFile.kt +++ b/params/src/main/kotlin/io/spine/compiler/params/CodeGeneratorRequestFile.kt @@ -26,7 +26,7 @@ package io.spine.compiler.params -import io.spine.compiler.params.Directories.PROTODATA_WORKING_DIR +import io.spine.compiler.params.Directories.COMPILER_WORKING_DIR import io.spine.compiler.params.Directories.REQUESTS_SUBDIR import io.spine.tools.code.SourceSetName @@ -40,7 +40,7 @@ public object CodeGeneratorRequestFile { * request files are placed. */ @Suppress("ConstPropertyName") // https://bit.ly/kotlin-prop-names - public const val defaultDirectory: String = "$PROTODATA_WORKING_DIR/$REQUESTS_SUBDIR" + public const val defaultDirectory: String = "$COMPILER_WORKING_DIR/$REQUESTS_SUBDIR" /** * Obtains the name of the file with the code generation request for the given source set. diff --git a/params/src/main/kotlin/io/spine/compiler/params/Directories.kt b/params/src/main/kotlin/io/spine/compiler/params/Directories.kt index 9456eca436..e136e4e380 100644 --- a/params/src/main/kotlin/io/spine/compiler/params/Directories.kt +++ b/params/src/main/kotlin/io/spine/compiler/params/Directories.kt @@ -32,25 +32,25 @@ package io.spine.compiler.params public object Directories { /** - * The name of the ProtoData working directory which is conventionally - * placed under the `build` directory. + * The name of the Compiler working directory which is conventionally + * placed under the `build/spine` directory. */ - public const val PROTODATA_WORKING_DIR: String = "protodata" + public const val COMPILER_WORKING_DIR: String = "compiler" /** - * The name of the subdirectory under [PROTODATA_WORKING_DIR] for storing + * The name of the subdirectory under [COMPILER_WORKING_DIR] for storing * files passed as parameters to pipelines. */ public const val PARAMETERS_SUBDIR: String = "parameters" /** - * The name of the subdirectory under [PROTODATA_WORKING_DIR] where + * The name of the subdirectory under [COMPILER_WORKING_DIR] where * the ProtoData settings files are stored. */ public const val SETTINGS_SUBDIR: String = "settings" /** - * The name of the subdirectory under [PROTODATA_WORKING_DIR] where + * The name of the subdirectory under [COMPILER_WORKING_DIR] where * [code generation requests files][CodeGeneratorRequestFile] are stored. */ public const val REQUESTS_SUBDIR: String = "requests" diff --git a/pom.xml b/pom.xml index 8922ba4bb7..e31e07fa88 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ all modules and does not describe the project structure per-subproject. --> io.spine.compiler spine-compiler -2.0.0-SNAPSHOT.007 +2.0.0-SNAPSHOT.008 2015 @@ -131,22 +131,28 @@ all modules and does not describe the project structure per-subproject. 0.10.0 compile + + io.spine.tools + spine-gradle-plugin-api + 2.0.0-SNAPSHOT.335 + compile + io.spine.tools spine-plugin-base - 2.0.0-SNAPSHOT.333 + 2.0.0-SNAPSHOT.335 compile io.spine.tools spine-psi-java - 2.0.0-SNAPSHOT.333 + 2.0.0-SNAPSHOT.335 compile io.spine.tools spine-tool-base - 2.0.0-SNAPSHOT.333 + 2.0.0-SNAPSHOT.335 compile @@ -218,7 +224,7 @@ all modules and does not describe the project structure per-subproject. io.spine.tools spine-plugin-testlib - 2.0.0-SNAPSHOT.333 + 2.0.0-SNAPSHOT.335 test diff --git a/tests/consumer/build.gradle.kts b/tests/consumer/build.gradle.kts index 3994114232..2937066ff5 100644 --- a/tests/consumer/build.gradle.kts +++ b/tests/consumer/build.gradle.kts @@ -29,7 +29,8 @@ import io.spine.dependency.lib.JavaX import io.spine.dependency.local.Base import io.spine.dependency.local.Spine -import io.spine.compiler.gradle.api.CodegenSettings +import io.spine.compiler.gradle.api.CompilerSettings +import io.spine.tools.gradle.root.rootExtension buildscript { standardSpineSdkRepositories() @@ -50,7 +51,7 @@ dependencies { testImplementation(Base.lib)?.because("tests use packing and unpacking extension functions.") } -extensions.getByType().apply { +rootExtension.extensions.getByType().apply { plugins( "io.spine.compiler.test.uuid.UuidPlugin", "io.spine.compiler.test.annotation.AnnotationPlugin" diff --git a/tests/in-place-consumer/build.gradle.kts b/tests/in-place-consumer/build.gradle.kts index 1f4c2090c1..c3406defca 100644 --- a/tests/in-place-consumer/build.gradle.kts +++ b/tests/in-place-consumer/build.gradle.kts @@ -46,9 +46,11 @@ dependencies { val protobufDir = "$projectDir/proto-gen/" -compiler { - plugins( - "io.spine.compiler.test.uuid.UuidPlugin" - ) - outputBaseDir.set(project.layout.projectDirectory.dir(protobufDir)) +spine { + compiler { + plugins( + "io.spine.compiler.test.uuid.UuidPlugin" + ) + outputBaseDir.set(project.layout.projectDirectory.dir(protobufDir)) + } } diff --git a/version.gradle.kts b/version.gradle.kts index b24e0f5b35..d644292e38 100644 --- a/version.gradle.kts +++ b/version.gradle.kts @@ -32,4 +32,4 @@ * * For dependencies on Spine SDK module please see [io.spine.dependency.local.Spine]. */ -val compilerVersion: String by extra("2.0.0-SNAPSHOT.007") +val compilerVersion: String by extra("2.0.0-SNAPSHOT.008")