From 5eae93fe19bf272d755607b9bd68074e01383fdd Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Thu, 7 Sep 2023 13:14:06 +0300 Subject: [PATCH 01/30] Bump version 0.12.0 --- .../codegen/java/annotation/GeneratedTypeAnnotationSpec.kt | 1 - .../codegen/java/annotation/SuppressWarningsAnnotationSpec.kt | 1 - version.gradle.kts | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/codegen/java/src/test/kotlin/io/spine/protodata/codegen/java/annotation/GeneratedTypeAnnotationSpec.kt b/codegen/java/src/test/kotlin/io/spine/protodata/codegen/java/annotation/GeneratedTypeAnnotationSpec.kt index 4ee15b583..402152a81 100644 --- a/codegen/java/src/test/kotlin/io/spine/protodata/codegen/java/annotation/GeneratedTypeAnnotationSpec.kt +++ b/codegen/java/src/test/kotlin/io/spine/protodata/codegen/java/annotation/GeneratedTypeAnnotationSpec.kt @@ -35,7 +35,6 @@ import io.spine.protodata.backend.Pipeline import io.spine.protodata.codegen.java.JAVA_FILE import io.spine.protodata.codegen.java.WithSourceFileSet import io.spine.protodata.codegen.java.annotation.GeneratedTypeAnnotation.Companion.currentDateTime -import io.spine.protodata.codegen.java.file.PrintBeforePrimaryDeclaration import io.spine.protodata.renderer.SourceFile import io.spine.time.testing.FrozenMadHatterParty import io.spine.time.toTimestamp diff --git a/codegen/java/src/test/kotlin/io/spine/protodata/codegen/java/annotation/SuppressWarningsAnnotationSpec.kt b/codegen/java/src/test/kotlin/io/spine/protodata/codegen/java/annotation/SuppressWarningsAnnotationSpec.kt index 84c1d2790..f1de8d9f3 100644 --- a/codegen/java/src/test/kotlin/io/spine/protodata/codegen/java/annotation/SuppressWarningsAnnotationSpec.kt +++ b/codegen/java/src/test/kotlin/io/spine/protodata/codegen/java/annotation/SuppressWarningsAnnotationSpec.kt @@ -31,7 +31,6 @@ import com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest import io.spine.protodata.backend.Pipeline import io.spine.protodata.codegen.java.JAVA_FILE import io.spine.protodata.codegen.java.WithSourceFileSet -import io.spine.protodata.codegen.java.file.PrintBeforePrimaryDeclaration import io.spine.protodata.config.Configuration import io.spine.protodata.config.ConfigurationFormat.PROTO_JSON import kotlin.io.path.Path diff --git a/version.gradle.kts b/version.gradle.kts index 0afb03649..6d56fab7a 100644 --- a/version.gradle.kts +++ b/version.gradle.kts @@ -32,4 +32,4 @@ * * For dependencies on Spine SDK module please see [io.spine.internal.dependency.Spine]. */ -val protoDataVersion: String by extra("0.11.5") +val protoDataVersion: String by extra("0.12.0") From d140c06201511f9ad8b34f30b06df44c09c89e34 Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Thu, 7 Sep 2023 16:32:46 +0300 Subject: [PATCH 02/30] Introduce `SourceFileSetMarker` --- .../io/spine/protodata/renderer/Renderer.kt | 4 ++ .../spine/protodata/renderer/SourceFileSet.kt | 25 +++++----- .../protodata/renderer/SourceFileSetMarker.kt | 39 +++++++++++++++ .../protodata/renderer/SourceGenerator.kt | 41 +++++++++++++++ .../protodata/renderer/SourceFileSetSpec.kt | 3 +- .../kotlin/io/spine/protodata/cli/app/Main.kt | 4 +- .../io/spine/protodata/InsertionPointSpec.kt | 4 +- .../spine/protodata/backend/PipelineSpec.kt | 50 +++++++++---------- 8 files changed, 129 insertions(+), 41 deletions(-) create mode 100644 api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSetMarker.kt create mode 100644 api/src/main/kotlin/io/spine/protodata/renderer/SourceGenerator.kt diff --git a/api/src/main/kotlin/io/spine/protodata/renderer/Renderer.kt b/api/src/main/kotlin/io/spine/protodata/renderer/Renderer.kt index 95b675540..4ebc35177 100644 --- a/api/src/main/kotlin/io/spine/protodata/renderer/Renderer.kt +++ b/api/src/main/kotlin/io/spine/protodata/renderer/Renderer.kt @@ -34,6 +34,7 @@ import io.spine.protodata.type.TypeNameElement import io.spine.server.BoundedContext import io.spine.server.ContextAware import io.spine.server.query.QueryingClient +import io.spine.tools.code.AnyLanguage import io.spine.tools.code.Language /** @@ -61,6 +62,9 @@ protected constructor( sources.mergeBack(relevantFiles) } + public open fun supports(marker: SourceFileSetMarker): Boolean = + supportedLanguage == AnyLanguage || supportedLanguage == marker.language + /** * Makes changes to the given source set. * diff --git a/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSet.kt b/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSet.kt index 75550c17f..ca7336d89 100644 --- a/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSet.kt +++ b/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSet.kt @@ -29,6 +29,7 @@ package io.spine.protodata.renderer import com.google.common.collect.ImmutableSet.toImmutableSet import io.spine.annotation.Internal import io.spine.protodata.TypeName +import io.spine.protodata.renderer.SourceFileSet.Companion.create import io.spine.protodata.type.TypeConvention import io.spine.protodata.type.TypeNameElement import io.spine.server.query.Querying @@ -68,6 +69,8 @@ import kotlin.text.Charsets.UTF_8 @Suppress("TooManyFunctions") // All part of the public API. public class SourceFileSet internal constructor( + public val marker: SourceFileSetMarker, + files: Set, /** @@ -108,14 +111,6 @@ internal constructor( @Internal public companion object { - @Deprecated( - "Use `create(..)` instead.", - replaceWith = ReplaceWith("create"), - level = ERROR - ) - public fun from(inputRoot: Path, outputRoot: Path): SourceFileSet = - create(inputRoot, outputRoot) - /** * Collects a source set from the given [input][inputRoot], assigning * the [output][outputRoot]. @@ -128,7 +123,11 @@ internal constructor( * If different from the `sourceRoot`, the files in `sourceRoot` * will not be changed. */ - public fun create(inputRoot: Path, outputRoot: Path): SourceFileSet { + public fun create( + marker: SourceFileSetMarker, + inputRoot: Path, + outputRoot: Path + ): SourceFileSet { val source = inputRoot.canonical() val target = outputRoot.canonical() if (source != target) { @@ -138,17 +137,17 @@ internal constructor( .filter { it.isRegularFile() } .map { SourceFile.read(source.relativize(it), source) } .collect(toImmutableSet()) - return SourceFileSet(files, source, target) + return SourceFileSet(marker, files, source, target) } /** * Creates an empty source set which can be appended with new files and * written to the given target directory. */ - public fun empty(target: Path): SourceFileSet { + public fun empty(marker: SourceFileSetMarker, target: Path): SourceFileSet { checkTarget(target) val files = setOf() - return SourceFileSet(files, target, target) + return SourceFileSet(marker, files, target, target) } } @@ -301,7 +300,7 @@ internal constructor( * matching the given [predicate]. */ internal fun SourceFileSet.subsetWhere(predicate: (SourceFile) -> Boolean) = - SourceFileSet(this.filter(predicate).toSet(), inputRoot, outputRoot) + SourceFileSet(this.marker, this.filter(predicate).toSet(), inputRoot, outputRoot) /** * Obtains absolute [normalized][normalize] version of this path. diff --git a/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSetMarker.kt b/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSetMarker.kt new file mode 100644 index 000000000..2e333965c --- /dev/null +++ b/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSetMarker.kt @@ -0,0 +1,39 @@ +/* + * 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.protodata.renderer + +import io.spine.tools.code.Language + +public data class SourceFileSetMarker( + public val language: Language, + public val generator: SourceGenerator +) { + public constructor(language: Language) : this(language, Default) + + public constructor(language: Language, generatorName: String) + : this(language, Custom(generatorName)) +} diff --git a/api/src/main/kotlin/io/spine/protodata/renderer/SourceGenerator.kt b/api/src/main/kotlin/io/spine/protodata/renderer/SourceGenerator.kt new file mode 100644 index 000000000..646c741a1 --- /dev/null +++ b/api/src/main/kotlin/io/spine/protodata/renderer/SourceGenerator.kt @@ -0,0 +1,41 @@ +/* + * 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.protodata.renderer + +public sealed interface SourceGenerator { + + public val name: String + get() = javaClass.simpleName.lowercase() +} + +public object Default : SourceGenerator + +public class Custom( + override val name: String +) : SourceGenerator + +public object None : SourceGenerator diff --git a/api/src/test/kotlin/io/spine/protodata/renderer/SourceFileSetSpec.kt b/api/src/test/kotlin/io/spine/protodata/renderer/SourceFileSetSpec.kt index 4f75f4665..1bca95ab7 100644 --- a/api/src/test/kotlin/io/spine/protodata/renderer/SourceFileSetSpec.kt +++ b/api/src/test/kotlin/io/spine/protodata/renderer/SourceFileSetSpec.kt @@ -31,6 +31,7 @@ import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe import io.spine.protodata.renderer.given.PlainTextConvention import io.spine.protodata.typeName +import io.spine.tools.code.AnyLanguage import java.nio.file.Path import kotlin.io.path.Path import kotlin.io.path.div @@ -62,7 +63,7 @@ class SourceFileSetSpec { textFile.writeText("this is a non-empty file") } } - set = SourceFileSet.create(input, output) + set = SourceFileSet.create(SourceFileSetMarker(AnyLanguage), input, output) } @Test diff --git a/cli/src/main/kotlin/io/spine/protodata/cli/app/Main.kt b/cli/src/main/kotlin/io/spine/protodata/cli/app/Main.kt index 72d74ff26..2248ff2ad 100644 --- a/cli/src/main/kotlin/io/spine/protodata/cli/app/Main.kt +++ b/cli/src/main/kotlin/io/spine/protodata/cli/app/Main.kt @@ -63,9 +63,11 @@ import io.spine.protodata.cli.UserClasspathParam import io.spine.protodata.config.Configuration import io.spine.protodata.config.ConfigurationFormat import io.spine.protodata.renderer.SourceFileSet +import io.spine.protodata.renderer.SourceFileSetMarker import io.spine.string.Separator.Companion.nl import io.spine.string.pi import io.spine.string.ti +import io.spine.tools.code.AnyLanguage import io.spine.tools.code.manifest.Version import java.io.File import java.io.File.pathSeparator @@ -236,7 +238,7 @@ internal class Run(version: String) : CliktCommand( return sources ?.zip(targets) ?.filter { (s, _) -> s.exists() } - ?.map { (s, t) -> SourceFileSet.create(s, t) } + ?.map { (s, t) -> SourceFileSet.create(SourceFileSetMarker(AnyLanguage), s, t) } // TODO: real marker ?: targets.oneSetWithNoFiles() } diff --git a/compiler/src/test/kotlin/io/spine/protodata/InsertionPointSpec.kt b/compiler/src/test/kotlin/io/spine/protodata/InsertionPointSpec.kt index eb1e4f533..cf85b0202 100644 --- a/compiler/src/test/kotlin/io/spine/protodata/InsertionPointSpec.kt +++ b/compiler/src/test/kotlin/io/spine/protodata/InsertionPointSpec.kt @@ -34,6 +34,7 @@ import io.kotest.matchers.collections.shouldNotHaveSize import io.kotest.matchers.string.shouldContain import io.spine.protodata.backend.Pipeline import io.spine.protodata.renderer.SourceFileSet +import io.spine.protodata.renderer.SourceFileSetMarker import io.spine.protodata.renderer.codeLine import io.spine.protodata.test.CatOutOfTheBoxEmancipator import io.spine.protodata.test.CompanionFramer @@ -46,6 +47,7 @@ import io.spine.protodata.test.KotlinInsertionPoint.FILE_START import io.spine.protodata.test.KotlinInsertionPoint.LINE_FOUR_COL_THIRTY_THREE import io.spine.protodata.test.NonVoidMethodPrinter import io.spine.protodata.test.VariousKtInsertionPointsPrinter +import io.spine.tools.code.AnyLanguage import java.lang.System.lineSeparator import java.nio.file.Path import kotlin.io.path.createFile @@ -109,7 +111,7 @@ class InsertionPointsSpec { NonVoidMethodPrinter(), IgnoreValueAnnotator(), CompanionFramer(), CompanionLalalaRenderer() ), - sources = listOf(SourceFileSet.create(input, output)), + sources = listOf(SourceFileSet.create(SourceFileSetMarker(AnyLanguage), input, output)), request = PluginProtos.CodeGeneratorRequest.getDefaultInstance(), )() kotlinFile = output / inputKtFile.name diff --git a/compiler/src/test/kotlin/io/spine/protodata/backend/PipelineSpec.kt b/compiler/src/test/kotlin/io/spine/protodata/backend/PipelineSpec.kt index ddcd66f88..390f8179b 100644 --- a/compiler/src/test/kotlin/io/spine/protodata/backend/PipelineSpec.kt +++ b/compiler/src/test/kotlin/io/spine/protodata/backend/PipelineSpec.kt @@ -31,14 +31,13 @@ import com.google.common.truth.Truth.assertThat import com.google.errorprone.annotations.CanIgnoreReturnValue import com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest import com.google.protobuf.compiler.codeGeneratorRequest -import io.kotest.assertions.shouldFail -import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe import io.kotest.matchers.string.shouldContain import io.spine.protodata.ConfigurationError import io.spine.protodata.config.Configuration import io.spine.protodata.config.ConfigurationFormat import io.spine.protodata.renderer.SourceFileSet +import io.spine.protodata.renderer.SourceFileSetMarker import io.spine.protodata.renderer.codeLine import io.spine.protodata.test.AnnotationInsertionPointPrinter import io.spine.protodata.test.CatOutOfTheBoxEmancipator @@ -64,7 +63,7 @@ import io.spine.protodata.test.TestPlugin import io.spine.protodata.test.UnderscorePrefixRenderer import io.spine.testing.assertDoesNotExist import io.spine.testing.assertExists -import java.io.IOException +import io.spine.tools.code.AnyLanguage import java.nio.file.Path import kotlin.io.path.createFile import kotlin.io.path.div @@ -83,13 +82,14 @@ import org.junit.jupiter.api.io.TempDir @DisplayName("`Pipeline` should") class PipelineSpec { + private val marker = SourceFileSetMarker(AnyLanguage) private lateinit var srcRoot : Path private lateinit var targetRoot : Path private lateinit var codegenRequestFile: Path private lateinit var targetFile: Path private lateinit var request: CodeGeneratorRequest private lateinit var renderer: UnderscorePrefixRenderer - private lateinit var overwritingSourceSet: SourceFileSet + private lateinit var sourceFileSet: SourceFileSet @BeforeEach fun prepareSources(@TempDir sandbox: Path) { @@ -113,7 +113,7 @@ class PipelineSpec { codegenRequestFile.writeBytes(request.toByteArray()) renderer = UnderscorePrefixRenderer() - overwritingSourceSet = SourceFileSet.create(srcRoot, targetRoot) + sourceFileSet = SourceFileSet.create(marker, srcRoot, targetRoot) targetFile = targetRoot.resolve(sourceFileName) } @@ -129,7 +129,7 @@ class PipelineSpec { Pipeline( plugin = TestPlugin(), renderer = renderer, - sources = overwritingSourceSet, + sources = sourceFileSet, request )() assertTextIn(targetFile).isEqualTo("_Journey worth taking") @@ -140,7 +140,7 @@ class PipelineSpec { Pipeline( plugin = TestPlugin(), renderer = InternalAccessRenderer(), - sources = overwritingSourceSet, + sources = sourceFileSet, request )() val newClass = targetRoot.resolve("spine/protodata/test/JourneyInternal.java") @@ -155,7 +155,7 @@ class PipelineSpec { Pipeline( plugin = TestPlugin(), renderer = DeletingRenderer(), - sources = SourceFileSet.create(srcRoot, targetRoot), + sources = sourceFileSet, request )() assertDoesNotExist(targetRoot / path) @@ -173,7 +173,7 @@ class PipelineSpec { JavaGenericInsertionPointPrinter(), renderer ), - sources = SourceFileSet.create(srcRoot, targetRoot), + sources = sourceFileSet, request )() @@ -197,7 +197,7 @@ class PipelineSpec { renderers = listOf( renderer ), - sources = SourceFileSet.create(srcRoot, targetRoot), + sources = sourceFileSet, request )() textIn(targetRoot / path) shouldBe textIn(srcRoot / path) @@ -216,7 +216,7 @@ class PipelineSpec { Pipeline( plugins = listOf(), renderers = listOf(AnnotationInsertionPointPrinter(), NullableAnnotationRenderer()), - sources = listOf(SourceFileSet.create(srcRoot, targetRoot)), + sources = listOf(sourceFileSet), request = CodeGeneratorRequest.getDefaultInstance() )() assertTextIn(targetRoot / path) @@ -232,7 +232,7 @@ class PipelineSpec { Pipeline( plugin = TestPlugin(), renderers = listOf(renderer), - sources = SourceFileSet.create(srcRoot, targetRoot), + sources = sourceFileSet, request )() textIn(targetRoot / path) shouldBe textIn(srcRoot / path) @@ -250,7 +250,7 @@ class PipelineSpec { JsRenderer(), KtRenderer() ), - sources = SourceFileSet.create(srcRoot, targetRoot), + sources = sourceFileSet, request )() assertTextIn(targetRoot / jsPath).contains("Hello JavaScript") @@ -265,7 +265,7 @@ class PipelineSpec { JavaGenericInsertionPointPrinter(), CatOutOfTheBoxEmancipator() ), - sources = overwritingSourceSet, + sources = sourceFileSet, request )() assertTextIn(targetFile).run { @@ -283,7 +283,7 @@ class PipelineSpec { JavaGenericInsertionPointPrinter(), JsRenderer() ), - sources = overwritingSourceSet, + sources = sourceFileSet, request )() assertTextIn(targetFile).run { @@ -298,7 +298,7 @@ class PipelineSpec { Pipeline( plugin = TestPlugin(), renderer = InternalAccessRenderer(), - sources = SourceFileSet.create(srcRoot, destination), + sources = SourceFileSet.create(marker, srcRoot, destination), request )() @@ -317,7 +317,7 @@ class PipelineSpec { Pipeline( TestPlugin(), NoOpRenderer(), - SourceFileSet.create(srcRoot, targetRoot), + sourceFileSet, request )() assertExists(targetFile) @@ -341,8 +341,8 @@ class PipelineSpec { TestPlugin(), NoOpRenderer(), listOf( - SourceFileSet.create(srcRoot, destination1), - SourceFileSet.create(source2, destination2) + SourceFileSet.create(marker, srcRoot, destination1), + SourceFileSet.create(marker, source2, destination2) ), request )() @@ -370,8 +370,8 @@ class PipelineSpec { plugin = TestPlugin(), renderer = PlainStringRenderer(), listOf( - SourceFileSet.create(srcRoot, destination1), - SourceFileSet.create(source2, destination2) + SourceFileSet.create(marker, srcRoot, destination1), + SourceFileSet.create(marker, source2, destination2) ), request, Configuration.rawValue(expectedContent, ConfigurationFormat.PLAIN) @@ -403,8 +403,8 @@ class PipelineSpec { PrependingRenderer() ), sources = listOf( - SourceFileSet.create(srcRoot, destination1), - SourceFileSet.create(source2, destination2) + SourceFileSet.create(marker, srcRoot, destination1), + SourceFileSet.create(marker, source2, destination2) ), request )() @@ -426,7 +426,7 @@ class PipelineSpec { val pipeline = Pipeline( plugin = DocilePlugin(policies = setOf(policy)), renderer = renderer, - sources = overwritingSourceSet, + sources = sourceFileSet, request ) val error = assertThrows { pipeline() } @@ -444,7 +444,7 @@ class PipelineSpec { viewRepositories = setOf(DeletedTypeRepository()) ), renderer = renderer, - sources = overwritingSourceSet, + sources = sourceFileSet, request ) val error = assertThrows { pipeline() } From 91a084bee5258a161f3cabc105cd208ad91a63e4 Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Fri, 8 Sep 2023 17:00:40 +0300 Subject: [PATCH 03/30] Add stub markers --- cli/src/main/kotlin/io/spine/protodata/cli/app/Main.kt | 2 +- .../io/spine/protodata/codegen/java/WithSourceFileSet.kt | 5 ++++- .../test/kotlin/io/spine/protodata/backend/PipelineSpec.kt | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cli/src/main/kotlin/io/spine/protodata/cli/app/Main.kt b/cli/src/main/kotlin/io/spine/protodata/cli/app/Main.kt index 2248ff2ad..c676af811 100644 --- a/cli/src/main/kotlin/io/spine/protodata/cli/app/Main.kt +++ b/cli/src/main/kotlin/io/spine/protodata/cli/app/Main.kt @@ -333,7 +333,7 @@ internal class Run(version: String) : CliktCommand( * Creates a list that contain a single, empty source set. */ private fun List.oneSetWithNoFiles(): List = - listOf(SourceFileSet.empty(first())) + listOf(SourceFileSet.empty(SourceFileSetMarker(AnyLanguage), first())) /** * Throws an [UsageError] with the result of calling [lazyMessage] if the [condition] isn't met. diff --git a/codegen/java/src/test/kotlin/io/spine/protodata/codegen/java/WithSourceFileSet.kt b/codegen/java/src/test/kotlin/io/spine/protodata/codegen/java/WithSourceFileSet.kt index 7844ba9e4..27547ff6e 100644 --- a/codegen/java/src/test/kotlin/io/spine/protodata/codegen/java/WithSourceFileSet.kt +++ b/codegen/java/src/test/kotlin/io/spine/protodata/codegen/java/WithSourceFileSet.kt @@ -27,6 +27,8 @@ package io.spine.protodata.codegen.java import io.spine.protodata.renderer.SourceFileSet +import io.spine.protodata.renderer.SourceFileSetMarker +import io.spine.tools.code.AnyLanguage import java.nio.file.Path import java.nio.file.StandardOpenOption import kotlin.io.path.writeText @@ -51,6 +53,7 @@ open class WithSourceFileSet protected constructor() { val contents = javaClass.classLoader.getResource(JAVA_FILE)!!.readText() sourceFile.parent.toFile().mkdirs() sourceFile.writeText(contents, options = arrayOf(StandardOpenOption.CREATE_NEW)) - sources = listOf(SourceFileSet.create(sourceRoot, targetRoot)) + val marker = SourceFileSetMarker(AnyLanguage) + sources = listOf(SourceFileSet.create(marker, sourceRoot, targetRoot)) } } diff --git a/compiler/src/test/kotlin/io/spine/protodata/backend/PipelineSpec.kt b/compiler/src/test/kotlin/io/spine/protodata/backend/PipelineSpec.kt index 390f8179b..227c81078 100644 --- a/compiler/src/test/kotlin/io/spine/protodata/backend/PipelineSpec.kt +++ b/compiler/src/test/kotlin/io/spine/protodata/backend/PipelineSpec.kt @@ -64,6 +64,7 @@ import io.spine.protodata.test.UnderscorePrefixRenderer import io.spine.testing.assertDoesNotExist import io.spine.testing.assertExists import io.spine.tools.code.AnyLanguage +import io.spine.tools.code.Java import java.nio.file.Path import kotlin.io.path.createFile import kotlin.io.path.div @@ -82,7 +83,7 @@ import org.junit.jupiter.api.io.TempDir @DisplayName("`Pipeline` should") class PipelineSpec { - private val marker = SourceFileSetMarker(AnyLanguage) + private val marker = SourceFileSetMarker(Java) private lateinit var srcRoot : Path private lateinit var targetRoot : Path private lateinit var codegenRequestFile: Path From 368b73e4cf38735d16bd2535f3e71c8bb2e70789 Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Mon, 11 Sep 2023 11:58:16 +0300 Subject: [PATCH 04/30] Simplify a precondition check --- .../main/kotlin/io/spine/protodata/renderer/SourceFileSet.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSet.kt b/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSet.kt index ca7336d89..dc3fa5dbf 100644 --- a/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSet.kt +++ b/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSet.kt @@ -130,9 +130,7 @@ internal constructor( ): SourceFileSet { val source = inputRoot.canonical() val target = outputRoot.canonical() - if (source != target) { - checkTarget(target) - } + checkTarget(target) val files = walk(source) .filter { it.isRegularFile() } .map { SourceFile.read(source.relativize(it), source) } From 436df68de0c684271c1dd1ef29490013fd9a9bb2 Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Mon, 11 Sep 2023 11:58:30 +0300 Subject: [PATCH 05/30] Reduce repetition in tests --- .../spine/protodata/backend/PipelineSpec.kt | 40 +++++++++---------- license-report.md | 18 ++++----- pom.xml | 2 +- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/compiler/src/test/kotlin/io/spine/protodata/backend/PipelineSpec.kt b/compiler/src/test/kotlin/io/spine/protodata/backend/PipelineSpec.kt index 227c81078..955011d7d 100644 --- a/compiler/src/test/kotlin/io/spine/protodata/backend/PipelineSpec.kt +++ b/compiler/src/test/kotlin/io/spine/protodata/backend/PipelineSpec.kt @@ -90,15 +90,16 @@ class PipelineSpec { private lateinit var targetFile: Path private lateinit var request: CodeGeneratorRequest private lateinit var renderer: UnderscorePrefixRenderer - private lateinit var sourceFileSet: SourceFileSet + private val sourceFileSet: SourceFileSet + get() = SourceFileSet.create(marker, srcRoot, targetRoot) @BeforeEach fun prepareSources(@TempDir sandbox: Path) { - srcRoot = sandbox.resolve("src") + srcRoot = sandbox / "src" srcRoot.toFile().mkdirs() - targetRoot = sandbox.resolve("target") + targetRoot = sandbox / "target" targetRoot.toFile().mkdirs() - codegenRequestFile = sandbox.resolve("code-gen-request.bin") + codegenRequestFile = sandbox / "code-gen-request.bin" // Correctness of the Java source code is of no importance for this test suite. val sourceFileName = "SourceCode.java" @@ -114,13 +115,12 @@ class PipelineSpec { codegenRequestFile.writeBytes(request.toByteArray()) renderer = UnderscorePrefixRenderer() - sourceFileSet = SourceFileSet.create(marker, srcRoot, targetRoot) - targetFile = targetRoot.resolve(sourceFileName) + targetFile = targetRoot / sourceFileName } @CanIgnoreReturnValue private fun write(path: String, code: String) { - val file = srcRoot.resolve(path) + val file = srcRoot / path file.parent.toFile().mkdirs() file.writeText(code) } @@ -144,7 +144,7 @@ class PipelineSpec { sources = sourceFileSet, request )() - val newClass = targetRoot.resolve("spine/protodata/test/JourneyInternal.java") + val newClass = targetRoot / "spine/protodata/test/JourneyInternal.java" assertExists(newClass) assertTextIn(newClass).contains("class JourneyInternal") } @@ -204,7 +204,7 @@ class PipelineSpec { textIn(targetRoot / path) shouldBe textIn(srcRoot / path) } - @Test + @Test fun `write into inline insertion points`() { val path = "ClassWithMethod.java" write(path, """ @@ -304,12 +304,12 @@ class PipelineSpec { )() val path = "spine/protodata/test/JourneyInternal.java" - val newClass = destination.resolve(path) + val newClass = destination / path assertExists(newClass) assertTextIn(newClass).contains("class JourneyInternal") - val newClassInSourceRoot = srcRoot.resolve(path) + val newClassInSourceRoot = srcRoot / path assertDoesNotExist(newClassInSourceRoot) } @@ -348,14 +348,14 @@ class PipelineSpec { request )() - assertExists(destination1.resolve(targetFile.name)) - assertExists(destination2.resolve(secondSourceFile.name)) + assertExists(destination1 / targetFile.name) + assertExists(destination2 / secondSourceFile.name) - assertTextIn(destination2.resolve(secondSourceFile.name)) + assertTextIn(destination2 / secondSourceFile.name) .isEqualTo(secondSourceFile.readText()) - assertDoesNotExist(destination1.resolve(secondSourceFile.name)) - assertDoesNotExist(destination2.resolve(targetFile.name)) + assertDoesNotExist(destination1 / secondSourceFile.name) + assertDoesNotExist(destination2 / targetFile.name) } @Test @@ -378,8 +378,8 @@ class PipelineSpec { Configuration.rawValue(expectedContent, ConfigurationFormat.PLAIN) )() - val firstFile = destination1.resolve(ECHO_FILE) - val secondFile = destination2.resolve(ECHO_FILE) + val firstFile = destination1 / ECHO_FILE + val secondFile = destination2 / ECHO_FILE assertExists(firstFile) assertExists(secondFile) @@ -410,9 +410,9 @@ class PipelineSpec { request )() - assertDoesNotExist(destination2.resolve(existingFilePath)) + assertDoesNotExist(destination2 / existingFilePath) - val writtenFile = destination1.resolve(existingFilePath) + val writtenFile = destination1 / existingFilePath assertExists(writtenFile) assertTextIn(writtenFile).contains(expectedContent) } diff --git a/license-report.md b/license-report.md index c236b97f9..5f3a83274 100644 --- a/license-report.md +++ b/license-report.md @@ -925,7 +925,7 @@ The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Sep 05 16:30:03 EEST 2023** 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 **Wed Sep 06 14:14:25 EEST 2023** 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). @@ -1871,7 +1871,7 @@ This report was generated on **Tue Sep 05 16:30:03 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Sep 05 16:30:06 EEST 2023** 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 **Wed Sep 06 14:14:27 EEST 2023** 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). @@ -2789,7 +2789,7 @@ This report was generated on **Tue Sep 05 16:30:06 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Sep 05 16:30:07 EEST 2023** 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 **Wed Sep 06 14:14:30 EEST 2023** 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). @@ -3718,7 +3718,7 @@ This report was generated on **Tue Sep 05 16:30:07 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Sep 05 16:30:09 EEST 2023** 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 **Wed Sep 06 14:14:33 EEST 2023** 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). @@ -4647,7 +4647,7 @@ This report was generated on **Tue Sep 05 16:30:09 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Sep 05 16:30:11 EEST 2023** 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 **Wed Sep 06 14:14:35 EEST 2023** 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). @@ -5457,7 +5457,7 @@ This report was generated on **Tue Sep 05 16:30:11 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Sep 05 16:30:12 EEST 2023** 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 **Wed Sep 06 14:14:37 EEST 2023** 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). @@ -6550,7 +6550,7 @@ This report was generated on **Tue Sep 05 16:30:12 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Sep 05 16:30:14 EEST 2023** 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 **Wed Sep 06 14:14:39 EEST 2023** 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). @@ -7319,7 +7319,7 @@ This report was generated on **Tue Sep 05 16:30:14 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Sep 05 16:30:15 EEST 2023** 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 **Wed Sep 06 14:14:41 EEST 2023** 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). @@ -8255,4 +8255,4 @@ This report was generated on **Tue Sep 05 16:30:15 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Sep 05 16:30:17 EEST 2023** 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 **Wed Sep 06 14:14:43 EEST 2023** 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/pom.xml b/pom.xml index a5d6dba08..93bf1e09b 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ all modules and does not describe the project structure per-subproject. --> io.spine.protodata ProtoData -0.11.5 +0.12.0 2015 From e7bea699cf1177fc6a7eb971d8c40f3d45928497 Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Mon, 18 Sep 2023 10:59:45 +0300 Subject: [PATCH 06/30] Use `paths` in the Gradle plugin (WIP) --- .../protodata/renderer/SourceGenerator.kt | 2 - .../protodata/cli/CommandLineInterface.kt | 12 +++ .../spine/protodata/cli/app/KnownLanguages.kt | 79 +++++++++++++++++ .../kotlin/io/spine/protodata/cli/app/Main.kt | 77 ++++++++-------- .../io/spine/protodata/cli/app/CliTest.kt | 36 +++----- .../protodata/cli/app/LoggingLevelSpec.kt | 4 +- .../spine/protodata/gradle/CodegenSettings.kt | 6 -- .../protodata/gradle/plugin/Extension.kt | 87 +++++++++++++------ .../gradle/plugin/LaunchProtoData.kt | 60 +++++-------- .../spine/protodata/gradle/plugin/Plugin.kt | 34 ++------ .../protodata/gradle/plugin/SourcePaths.kt | 62 +++++++++++++ .../protodata/gradle/plugin/ExtensionSpec.kt | 28 ------ license-report.md | 36 ++++---- .../io/spine/protodata/test/PathParams.kt | 38 ++++++++ 14 files changed, 356 insertions(+), 205 deletions(-) create mode 100644 cli/src/main/kotlin/io/spine/protodata/cli/app/KnownLanguages.kt create mode 100644 gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/SourcePaths.kt create mode 100644 test-env/src/main/kotlin/io/spine/protodata/test/PathParams.kt diff --git a/api/src/main/kotlin/io/spine/protodata/renderer/SourceGenerator.kt b/api/src/main/kotlin/io/spine/protodata/renderer/SourceGenerator.kt index 646c741a1..24a1356b0 100644 --- a/api/src/main/kotlin/io/spine/protodata/renderer/SourceGenerator.kt +++ b/api/src/main/kotlin/io/spine/protodata/renderer/SourceGenerator.kt @@ -37,5 +37,3 @@ public object Default : SourceGenerator public class Custom( override val name: String ) : SourceGenerator - -public object None : SourceGenerator diff --git a/cli-api/src/main/kotlin/io/spine/protodata/cli/CommandLineInterface.kt b/cli-api/src/main/kotlin/io/spine/protodata/cli/CommandLineInterface.kt index 8c9c5d611..a9528d68b 100644 --- a/cli-api/src/main/kotlin/io/spine/protodata/cli/CommandLineInterface.kt +++ b/cli-api/src/main/kotlin/io/spine/protodata/cli/CommandLineInterface.kt @@ -117,6 +117,18 @@ public object TargetRootParam : Parameter( """ ) + +/** + * The source and target paths. + */ +public object PathsParam : Parameter( + name = "--paths", + shortName = "-P", + help = """ + + """ +) // TODO add help msg and doc. + /** * The command-line parameter for composing the user-defined classpath. */ diff --git a/cli/src/main/kotlin/io/spine/protodata/cli/app/KnownLanguages.kt b/cli/src/main/kotlin/io/spine/protodata/cli/app/KnownLanguages.kt new file mode 100644 index 000000000..e4e1b02c8 --- /dev/null +++ b/cli/src/main/kotlin/io/spine/protodata/cli/app/KnownLanguages.kt @@ -0,0 +1,79 @@ +/* + * 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.protodata.cli.app + +import io.spine.tools.code.AnyLanguage +import io.spine.tools.code.Java +import io.spine.tools.code.JavaScript +import io.spine.tools.code.Kotlin +import io.spine.tools.code.Language +import kotlin.reflect.KClass +import kotlin.reflect.full.isSubclassOf +import kotlin.reflect.jvm.isAccessible + +private val knownLanguages: Map = setOf( + Java, + Kotlin, + JavaScript, + AnyLanguage +).associateBy { it.name.lowercase() } + +internal fun String.toLanguage(): Language { + require(this.isNotBlank()) { "Expected a language name of class, but got `$this`." } + return toKnownLanguage() ?: loadLanguage() +} + +private fun String.toKnownLanguage(): Language? { + val key = lowercase() + return if (key in knownLanguages) { + knownLanguages.getValue(key) + } else { + null + } +} + +private fun String.loadLanguage(): Language { + val cls = languageClass() + return cls.objectInstance ?: cls.instantiate() + +} + +private fun String.languageClass(): KClass { + val javaClass = Class.forName(this) + val ktClass = javaClass.kotlin + require(ktClass.isSubclassOf(Language::class)) { "Expected a language class, but got `$this`." } + @Suppress("UNCHECKED_CAST") // Ensured by the precondition above. + return ktClass as KClass +} + +private fun KClass.instantiate(): Language { + val ctor = constructors.firstOrNull { it.parameters.isEmpty() } + require(ctor != null) { "Language class `$this` must have a zero-parameter constructor." } + ctor.isAccessible = true + val instance = ctor.call() + return instance +} diff --git a/cli/src/main/kotlin/io/spine/protodata/cli/app/Main.kt b/cli/src/main/kotlin/io/spine/protodata/cli/app/Main.kt index c676af811..42afd3f63 100644 --- a/cli/src/main/kotlin/io/spine/protodata/cli/app/Main.kt +++ b/cli/src/main/kotlin/io/spine/protodata/cli/app/Main.kt @@ -39,6 +39,7 @@ import com.github.ajalt.clikt.parameters.options.required import com.github.ajalt.clikt.parameters.options.split import com.github.ajalt.clikt.parameters.types.file import com.github.ajalt.clikt.parameters.types.path +import com.google.common.base.Splitter import com.google.protobuf.ExtensionRegistry import com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest import io.spine.code.proto.FileSet @@ -54,6 +55,7 @@ import io.spine.protodata.cli.ConfigValueParam import io.spine.protodata.cli.DebugLoggingParam import io.spine.protodata.cli.InfoLoggingParam import io.spine.protodata.cli.Parameter +import io.spine.protodata.cli.PathsParam import io.spine.protodata.cli.PluginParam import io.spine.protodata.cli.RendererParam import io.spine.protodata.cli.RequestParam @@ -62,6 +64,8 @@ import io.spine.protodata.cli.TargetRootParam import io.spine.protodata.cli.UserClasspathParam import io.spine.protodata.config.Configuration import io.spine.protodata.config.ConfigurationFormat +import io.spine.protodata.renderer.Custom +import io.spine.protodata.renderer.Default import io.spine.protodata.renderer.SourceFileSet import io.spine.protodata.renderer.SourceFileSetMarker import io.spine.string.Separator.Companion.nl @@ -72,6 +76,7 @@ import io.spine.tools.code.manifest.Version import java.io.File import java.io.File.pathSeparator import java.nio.file.Path +import kotlin.io.path.Path import kotlin.io.path.exists import kotlin.system.exitProcess @@ -113,6 +118,10 @@ internal class Run(version: String) : CliktCommand( epilog = "https://github.com/SpineEventEngine/ProtoData/", printHelpOnEmptyArgs = true ), WithLogging { + + private val pathSplitter = Splitter.on(pathSeparator) + private val labelRegex = Regex("([\\w.]+)(\\((\\w+)\\))?") + private fun Parameter.toOption(completionCandidates: CompletionCandidates? = null) = option( name, shortName, help = help, @@ -137,17 +146,9 @@ internal class Run(version: String) : CliktCommand( mustBeReadable = true ).required() - private val sourceRoots: List? - by SourceRootParam.toOption().path( - canBeFile = false, - canBeSymlink = false - ).splitPaths() - - private val targetRoots: List? - by TargetRootParam.toOption().path( - canBeFile = false, - canBeSymlink = false - ).splitPaths().required() + private val paths: List + by PathsParam.toOption() + .multiple(required = true) private val classpath: List? by UserClasspathParam.toOption().path( @@ -232,28 +233,38 @@ internal class Run(version: String) : CliktCommand( } private fun createSourceFileSets(): List { - checkPaths() - val sources = sourceRoots - val targets = (targetRoots ?: sources)!! - return sources - ?.zip(targets) - ?.filter { (s, _) -> s.exists() } - ?.map { (s, t) -> SourceFileSet.create(SourceFileSetMarker(AnyLanguage), s, t) } // TODO: real marker - ?: targets.oneSetWithNoFiles() + val pathPairs = paths.map { pathSplitter.splitToList(it) } + val existingPaths = pathPairs.filter { + val srcPath = it[1] + srcPath.isNotBlank() && Path(srcPath).exists() + }.toList() + if (existingPaths.isEmpty()) { + require(paths.size == 1) { "Expected exactly one target path, but was ${paths}." } + val (rawLabel, _, rawTarget) = pathPairs.first() + val label = loadLabel(rawLabel) + val targetPath = Path(rawTarget) + return listOf(SourceFileSet.empty(label, targetPath)) + } + return existingPaths.map { + val (rawLabel, rawSrc, rawTarget) = it + val sourceLabel = loadLabel(rawLabel) + val srcPath = Path(rawSrc) + val targetPath = Path(rawTarget) + SourceFileSet.create(sourceLabel, srcPath, targetPath) + } } - private fun checkPaths() { - if (sourceRoots == null) { - checkUsage(targetRoots!!.size == 1) { - "When not providing a source directory, only one target directory must be present." - } - } - if (sourceRoots != null && targetRoots != null) { - checkUsage(sourceRoots!!.size == targetRoots!!.size) { - "Mismatched amount of directories. Given ${sourceRoots!!.size} sources " + - "and ${targetRoots!!.size} targets." - } + private fun loadLabel(label: String): SourceFileSetMarker { + val match = labelRegex.matchEntire(label) + require(match != null) { "Could not load source label: `$label`." } + val language = match.groupValues[1].toLanguage() + val generator = if (match.groupValues.size > 2) { + Custom(match.groupValues[3]) + } else { + Default } + val sourceLabel = SourceFileSetMarker(language, generator) + return sourceLabel } private fun loadPlugins() = load(PluginBuilder(), plugins) @@ -329,12 +340,6 @@ internal class Run(version: String) : CliktCommand( private fun printError(message: String?) = echo(message, trailingNewline = true, err = true) } -/** - * Creates a list that contain a single, empty source set. - */ -private fun List.oneSetWithNoFiles(): List = - listOf(SourceFileSet.empty(SourceFileSetMarker(AnyLanguage), first())) - /** * Throws an [UsageError] with the result of calling [lazyMessage] if the [condition] isn't met. */ diff --git a/cli/src/test/kotlin/io/spine/protodata/cli/app/CliTest.kt b/cli/src/test/kotlin/io/spine/protodata/cli/app/CliTest.kt index 605ea2d29..6c574965c 100644 --- a/cli/src/test/kotlin/io/spine/protodata/cli/app/CliTest.kt +++ b/cli/src/test/kotlin/io/spine/protodata/cli/app/CliTest.kt @@ -49,10 +49,12 @@ import io.spine.protodata.test.ProtoEchoRenderer import io.spine.protodata.test.TestPlugin import io.spine.protodata.test.UnderscorePrefixRenderer import io.spine.protodata.test.echo +import io.spine.protodata.test.pathsForJava import io.spine.time.LocalDates import io.spine.time.Month.SEPTEMBER import io.spine.time.toInstant import io.spine.type.toCompactJson +import java.io.File import java.nio.file.Path import kotlin.io.path.createFile import kotlin.io.path.name @@ -114,8 +116,7 @@ class `Command line application should` { launchApp( "-p", TestPlugin::class.jvmName, "-r", UnderscorePrefixRenderer::class.jvmName, - "--src", srcRoot.toString(), - "--target", targetRoot.toString(), + "--paths", pathsForJava(srcRoot, targetRoot), "-t", codegenRequestFile.toString() ) targetFile.readText() shouldBe "_${Project::class.simpleName}.getUuid() " @@ -126,8 +127,7 @@ class `Command line application should` { launchApp( "-p", DefaultOptionsCounterPlugin::class.jvmName, "-r", DefaultOptionsCounterRenderer::class.jvmName, - "--src", srcRoot.toString(), - "--target", targetRoot.toString(), + "--paths", pathsForJava(srcRoot, targetRoot), "-t", codegenRequestFile.toString(), ) val generatedFile = targetRoot.resolve(DefaultOptionsCounterRenderer.FILE_NAME) @@ -148,8 +148,7 @@ class `Command line application should` { launchApp( "-r", EchoRenderer::class.jvmName, - "--src", srcRoot.toString(), - "--target", targetRoot.toString(), + "--paths", pathsForJava(srcRoot, targetRoot), "-t", codegenRequestFile.toString(), "-c", configFile.pathString ) @@ -161,8 +160,7 @@ class `Command line application should` { val name = "Mr. World" launchApp( "-r", EchoRenderer::class.jvmName, - "--src", srcRoot.toString(), - "--target", targetRoot.toString(), + "--paths", pathsForJava(srcRoot, targetRoot), "-t", codegenRequestFile.toString(), "--cv", """{ "value": "$name" }""", "--cf", "json" @@ -185,8 +183,7 @@ class `Command line application should` { launchApp( "-r", EchoRenderer::class.jvmName, - "--src", srcRoot.toString(), - "--target", targetRoot.toString(), + "--paths", pathsForJava(srcRoot, targetRoot), "-t", codegenRequestFile.toString(), "-c", configFile.pathString ) @@ -204,8 +201,7 @@ class `Command line application should` { }.toCompactJson() launchApp( "-r", ProtoEchoRenderer::class.jvmName, - "--src", srcRoot.toString(), - "--target", targetRoot.toString(), + "--paths", pathsForJava(srcRoot, targetRoot), "-t", codegenRequestFile.toString(), "--cv", json, "--cf", "proto_json" @@ -232,8 +228,7 @@ class `Command line application should` { launchApp( "-r", ProtoEchoRenderer::class.jvmName, - "--src", srcRoot.toString(), - "--target", targetRoot.toString(), + "--paths", pathsForJava(srcRoot, targetRoot), "-t", codegenRequestFile.toString(), "-c", configFile.pathString ) @@ -255,8 +250,7 @@ class `Command line application should` { """.trimIndent()) launchApp( "-r", EchoRenderer::class.jvmName, - "--src", srcRoot.toString(), - "--target", targetRoot.toString(), + "--paths", pathsForJava(srcRoot, targetRoot), "-t", codegenRequestFile.toString(), "-c", configFile.pathString ) @@ -268,8 +262,7 @@ class `Command line application should` { val plainString = "dont.mail.me:42@example.org" launchApp( "-r", PlainStringRenderer::class.jvmName, - "--src", srcRoot.toString(), - "--target", targetRoot.toString(), + "--paths", pathsForJava(srcRoot, targetRoot), "-t", codegenRequestFile.toString(), "--cv", plainString, "--cf", "plain" @@ -287,8 +280,7 @@ class `Command line application should` { assertMissingOption { launchApp( "-p", TestPlugin::class.jvmName, - "--src", srcRoot.toString(), - "--target", targetRoot.toString(), + "--paths", pathsForJava(srcRoot, targetRoot), "-t", codegenRequestFile.toString() ) } @@ -301,7 +293,7 @@ class `Command line application should` { "-p", TestPlugin::class.jvmName, "-r", UnderscorePrefixRenderer::class.jvmName, "-t", codegenRequestFile.toString(), - "--src", srcRoot.toString() + "-paths", pathsForJava(srcRoot, "") ) } } @@ -312,7 +304,7 @@ class `Command line application should` { launchApp( "-p", TestPlugin::class.jvmName, "-r", UnderscorePrefixRenderer::class.jvmName, - "--src", srcRoot.toString() + "--paths", pathsForJava(srcRoot, targetRoot) ) } } diff --git a/cli/src/test/kotlin/io/spine/protodata/cli/app/LoggingLevelSpec.kt b/cli/src/test/kotlin/io/spine/protodata/cli/app/LoggingLevelSpec.kt index fd8287d47..354d7a3be 100644 --- a/cli/src/test/kotlin/io/spine/protodata/cli/app/LoggingLevelSpec.kt +++ b/cli/src/test/kotlin/io/spine/protodata/cli/app/LoggingLevelSpec.kt @@ -39,6 +39,7 @@ import io.spine.protodata.renderer.Renderer import io.spine.protodata.renderer.SourceFileSet import io.spine.protodata.test.Project import io.spine.protodata.test.ProjectProto +import io.spine.protodata.test.pathsForJava import io.spine.tools.code.AnyLanguage import java.nio.file.Path import kotlin.io.path.writeBytes @@ -118,8 +119,7 @@ class `ProtoData CLI logging levels should` { private fun launchWithLoggingParams(vararg argv: String) { val params = mutableListOf( "-r", LoggingLevelAsserter::class.jvmName, - "--src", srcRoot.toString(), - "--target", targetRoot.toString(), + "--paths", pathsForJava(srcRoot, targetRoot), "-t", codegenRequestFile.toString(), "--cv", "testing-logging-levels", "--cf", "plain", diff --git a/gradle-api/src/main/kotlin/io/spine/protodata/gradle/CodegenSettings.kt b/gradle-api/src/main/kotlin/io/spine/protodata/gradle/CodegenSettings.kt index 9cfebeaa7..34f822609 100644 --- a/gradle-api/src/main/kotlin/io/spine/protodata/gradle/CodegenSettings.kt +++ b/gradle-api/src/main/kotlin/io/spine/protodata/gradle/CodegenSettings.kt @@ -37,12 +37,6 @@ public interface CodegenSettings { */ public fun plugins(vararg classNames: String) - /** - * Passes given names of Java classes to ProtoData as - * the `io.spine.protodata.renderer.Renderer` classes. - */ - public fun renderers(vararg classNames: String) - /** * Passes given names of Java classes to ProtoData as * the `io.spine.protodata.option.OptionsProvider` classes. diff --git a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt index 92e62898d..ce5717e96 100644 --- a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt +++ b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt @@ -29,8 +29,14 @@ package io.spine.protodata.gradle.plugin import io.spine.protodata.gradle.CodeGeneratorRequestFile import io.spine.protodata.gradle.CodeGeneratorRequestFile.DEFAULT_DIRECTORY import io.spine.protodata.gradle.CodegenSettings +import io.spine.protodata.renderer.Custom +import io.spine.protodata.renderer.Default +import io.spine.tools.code.Java import io.spine.tools.fs.DirectoryName.generated +import io.spine.tools.gradle.project.sourceSets import io.spine.tools.gradle.protobuf.generatedSourceProtoDir +import kotlin.io.path.name +import org.gradle.api.NamedDomainObjectContainer import org.gradle.api.Project import org.gradle.api.file.Directory import org.gradle.api.file.DirectoryProperty @@ -38,6 +44,7 @@ import org.gradle.api.file.RegularFile import org.gradle.api.provider.ListProperty import org.gradle.api.provider.Provider import org.gradle.api.tasks.SourceSet +import org.gradle.kotlin.dsl.domainObjectContainer import org.gradle.kotlin.dsl.listProperty /** @@ -53,11 +60,6 @@ public class Extension(internal val project: Project): CodegenSettings { internal val plugins: ListProperty = factory.listProperty(String::class.java).convention(listOf()) - @Suppress("DeprecatedCallableAddReplaceWith") // Not that simple ;) - @Deprecated("Supply Renderers via Plugins instead.") - public override fun renderers(vararg classNames: String): Unit = - renderers.addAll(classNames.toList()) - @Deprecated("Supply Renderers via Plugins instead.") internal val renderers: ListProperty = factory.listProperty().convention(listOf()) @@ -81,12 +83,56 @@ public class Extension(internal val project: Project): CodegenSettings { internal fun requestFile(forSourceSet: SourceSet): Provider = requestFilesDirProperty.file(CodeGeneratorRequestFile.name(forSourceSet)) + public val paths: NamedDomainObjectContainer = + project.objects.domainObjectContainer(SourcePaths::class) { + name -> SourcePaths(generatorName = name) + } + + internal fun pathsOrCompat(): Set { + if (paths.isNotEmpty()) { + return paths + } + return project.sourceSets.asSequence().flatMap { + val srcRoots = sourceDirs(it).get() + val targetRoots = targetDirs(it).get() + srcRoots.zip(targetRoots) + }.map { (src, target) -> + val pathSuffix = src.asFile.toPath().name + val generatorName = if (pathSuffix == "java") Default else Custom(pathSuffix) + SourcePaths( + src.asFile, + target.asFile, + Java, + generatorName + ) + }.toSet() + } + + public companion object { + + /** + * Default subdirectories expected by ProtoData under a generated source set. + * + * @see subDirs + */ + public val defaultSubdirectories: List = listOf( + "java", + "kotlin", + "grpc", + "js", + "dart", + "spine", + "protodata" + ) + } + /** * Synthetic property for providing the source directories for the given * source set under [Project.generatedSourceProtoDir]. * * @see sourceDirs */ + @Deprecated("Use `paths` instead.") private val srcBaseDirProperty: DirectoryProperty = with(project) { objects.directoryProperty().convention(provider { layout.projectDirectory.dir(generatedSourceProtoDir.toString()) @@ -98,21 +144,26 @@ public class Extension(internal val project: Project): CodegenSettings { * * Defaults to [defaultSubdirectories]. */ + @Deprecated("Use `paths` instead.") public override var subDirs: List get() = subDirProperty.get() set(value) { if (value.isNotEmpty()) { subDirProperty.set(value) } + } + @Deprecated("Use `paths` instead.") private val subDirProperty: ListProperty = factory.listProperty().convention(defaultSubdirectories) + @Deprecated("Use `paths` instead.") public override var targetBaseDir: Any get() = targetBaseDirProperty.get() set(value) = targetBaseDirProperty.set(project.file(value)) + @Deprecated("Use `paths` instead.") private val targetBaseDirProperty: DirectoryProperty = with(project) { objects.directoryProperty().convention( layout.projectDirectory.dir(generated.name) @@ -122,6 +173,7 @@ public class Extension(internal val project: Project): CodegenSettings { /** * Obtains the source directories for the given source set. */ + @Deprecated("Use `paths` instead.") internal fun sourceDirs(sourceSet: SourceSet): Provider> = compileDir(sourceSet, srcBaseDirProperty) @@ -130,34 +182,15 @@ public class Extension(internal val project: Project): CodegenSettings { * * @see targetBaseDir for the rules for the target dir construction */ + @Deprecated("Use `paths` instead.") internal fun targetDirs(sourceSet: SourceSet): Provider> = compileDir(sourceSet, targetBaseDirProperty) - private fun compileDir( - sourceSet: SourceSet, - base: DirectoryProperty - ): Provider> { + @Deprecated("Use `paths` instead.") + private fun compileDir(sourceSet: SourceSet, base: DirectoryProperty): Provider> { val sourceSetDir = base.dir(sourceSet.name) return sourceSetDir.map { root: Directory -> subDirs.map { root.dir(it) } } } - - public companion object { - - /** - * Default subdirectories expected by ProtoData under a generated source set. - * - * @see subDirs - */ - public val defaultSubdirectories: List = listOf( - "java", - "kotlin", - "grpc", - "js", - "dart", - "spine", - "protodata" - ) - } } diff --git a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/LaunchProtoData.kt b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/LaunchProtoData.kt index 6cc0bc56f..2bb24e55b 100644 --- a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/LaunchProtoData.kt +++ b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/LaunchProtoData.kt @@ -28,13 +28,13 @@ package io.spine.protodata.gradle.plugin import io.spine.protodata.CLI_APP_CLASS import io.spine.protodata.cli.ConfigFileParam +import io.spine.protodata.cli.PathsParam import io.spine.protodata.cli.PluginParam -import io.spine.protodata.cli.RendererParam import io.spine.protodata.cli.RequestParam -import io.spine.protodata.cli.SourceRootParam -import io.spine.protodata.cli.TargetRootParam import io.spine.protodata.cli.UserClasspathParam +import io.spine.protodata.renderer.Default import io.spine.tools.gradle.protobuf.containsProtoFiles +import java.io.File import java.io.File.pathSeparator import org.gradle.api.Action import org.gradle.api.Task @@ -48,8 +48,6 @@ import org.gradle.api.tasks.InputFile import org.gradle.api.tasks.InputFiles import org.gradle.api.tasks.Internal import org.gradle.api.tasks.JavaExec -import org.gradle.api.tasks.Optional -import org.gradle.api.tasks.OutputDirectories import org.gradle.api.tasks.SourceSet /** @@ -70,25 +68,14 @@ public abstract class LaunchProtoData : JavaExec() { @get:Internal public abstract val configurationFile: RegularFileProperty - @Deprecated("Supply Renderers via Plugins instead.") - @get:Input - internal lateinit var renderers: Provider> - @get:Input internal lateinit var plugins: Provider> @get:Input internal lateinit var optionProviders: Provider> - /** - * The paths to the directories with the generated source code. - * - * May not be available, if `protoc` built-ins were turned off, resulting in no source code - * being generated. In such a mode `protoc` worked only generating descriptor set files. - */ - @get:InputFiles - @get:Optional - internal lateinit var sources: Provider> + @get:Input + internal lateinit var paths: Set @get:InputFiles internal lateinit var userClasspathConfig: Configuration @@ -99,12 +86,6 @@ public abstract class LaunchProtoData : JavaExec() { @get:InputFiles internal lateinit var protoDataConfig: Configuration - /** - * The paths to the directories where the source code processed by ProtoData should go. - */ - @get:OutputDirectories - internal lateinit var targets: Provider> - /** * Configures the CLI command for this task. * @@ -116,21 +97,13 @@ public abstract class LaunchProtoData : JavaExec() { yield(PluginParam.name) yield(it) } - renderers.get().forEach { - yield(RendererParam.name) - yield(it) - } yield(RequestParam.name) yield(project.file(requestFile).absolutePath) - - if (sources.isPresent) { - yield(SourceRootParam.name) - yield(sources.absolutePaths()) + paths.forEach { + yield(PathsParam.name) + yield(it.toCliParam()) } - yield(TargetRootParam.name) - yield(targets.absolutePaths()) - val userCp = userClasspathConfig.asPath if (userCp.isNotEmpty()) { yield(UserClasspathParam.name) @@ -161,8 +134,8 @@ public abstract class LaunchProtoData : JavaExec() { private inner class CleanAction : Action { override fun execute(t: Task) { - val sourceDirs = sources.absoluteDirs() - val targetDirs = targets.absoluteDirs() + val sourceDirs = paths.map { File(it.source!!) } + val targetDirs = paths.map { File(it.target!!) } if (sourceDirs.isEmpty()) { return @@ -180,6 +153,19 @@ public abstract class LaunchProtoData : JavaExec() { } } +private fun SourcePaths.toCliParam(): String { +// checkAllSet() + val label = if (generatorName != Default.name) { + "$language($generatorName)" + } else { + language + } + val sourcePath = source ?: "" + val targetPath = target!! + val parts = listOf(label, sourcePath, targetPath) + return parts.joinToString(pathSeparator) +} + private fun Provider>.absoluteDirs() = takeIf { it.isPresent } ?.get() ?.map { it.asFile.absoluteFile } diff --git a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Plugin.kt b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Plugin.kt index afe266e21..271544a3b 100644 --- a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Plugin.kt +++ b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Plugin.kt @@ -166,16 +166,19 @@ private fun Project.createTasks(ext: Extension) { private fun Project.createLaunchTask(sourceSet: SourceSet, ext: Extension): LaunchProtoData { val taskName = LaunchTask.nameFor(sourceSet) val result = tasks.create(taskName) { - renderers = ext.renderers plugins = ext.plugins optionProviders = ext.optionProviders requestFile = ext.requestFile(sourceSet) protoDataConfig = protoDataRawArtifact userClasspathConfig = userClasspath project.afterEvaluate { - sources = ext.sourceDirs(sourceSet) - targets = ext.targetDirs(sourceSet) + paths = ext.pathsOrCompat() compileCommandLine() + + val java: SourceDirectorySet = sourceSet.java + paths.map { it.target!! }.forEach { targetPath -> + java.srcDir(targetPath) + } } setPreLaunchCleanup() onlyIf { @@ -189,6 +192,7 @@ private fun Project.createLaunchTask(sourceSet: SourceSet, ext: Extension): Laun javaCompileFor(sourceSet)?.dependsOn(launchTask) kotlinCompileFor(sourceSet)?.dependsOn(launchTask) } + return result } @@ -319,31 +323,8 @@ private fun GenerateProtoTask.excludeProtocOutput() { // Add the filtered directories back to the Java source set. java.srcDirs(newSourceDirectories) - - // Add copied files to the Java source set. - java.srcDir(generatedDir("java")) - java.srcDir(generatedDir("kotlin")) -} - -/** - * Obtains the `generated` directory for the source set of the task. - * - * If [language] is specified returns the subdirectory for this language. - */ -private fun GenerateProtoTask.generatedDir(language: String = ""): File { - val path = "${project.targetBaseDir}/${sourceSet.name}/$language" - return File(path) } -/** - * Obtains the name of the directory where ProtoData places generated files. - */ -private val Project.targetBaseDir: String - get() { - val ext = extensions.getByType(CodegenSettings::class.java) - return ext.targetBaseDir.toString() - } - /** * Makes a [LaunchProtoData], if it exists for the given [sourceSet], depend on * the given [GenerateProtoTask]. @@ -399,4 +380,3 @@ private fun Project.configureIdea() { */ private fun File.residesIn(directory: File): Boolean = canonicalFile.startsWith(directory.absolutePath) - diff --git a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/SourcePaths.kt b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/SourcePaths.kt new file mode 100644 index 000000000..8a449573f --- /dev/null +++ b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/SourcePaths.kt @@ -0,0 +1,62 @@ +/* + * 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.protodata.gradle.plugin + +import io.spine.protodata.renderer.Default +import io.spine.protodata.renderer.SourceGenerator +import io.spine.tools.code.Language +import java.io.File +import org.gradle.api.Named + +public data class SourcePaths( + public var source: String? = null, + public var target: String? = null, + public var language: String? = null, + public var generatorName: String = Default.name +) : Named { + + public constructor( + source: File, + target: File, + language: Language, + generator: SourceGenerator + ) : this( + source.absolutePath, + target.absolutePath, + language::class.qualifiedName, + generator.name + ) + + internal fun checkAllSet() { + require(target.isNullOrBlank()) { missingMessage("target path") } + require(language.isNullOrBlank()) { missingMessage("language") } + } + + override fun getName(): String = generatorName + + private fun missingMessage(propName: String) = "Source file set `$name` requires the $propName." +} diff --git a/gradle-plugin/src/test/kotlin/io/spine/protodata/gradle/plugin/ExtensionSpec.kt b/gradle-plugin/src/test/kotlin/io/spine/protodata/gradle/plugin/ExtensionSpec.kt index 3eac71300..d9ec891d2 100644 --- a/gradle-plugin/src/test/kotlin/io/spine/protodata/gradle/plugin/ExtensionSpec.kt +++ b/gradle-plugin/src/test/kotlin/io/spine/protodata/gradle/plugin/ExtensionSpec.kt @@ -74,16 +74,6 @@ class ExtensionSpec { .containsExactly(className) } - @Suppress("DEPRECATION") - @Test - fun `add 'Renderer' class names`() { - val className1 = "com.acme.MyRenderer1" - val className2 = "com.acme.MyRenderer2" - extension.renderers(className1, className2) - assertThat(extension.renderers.get()) - .containsExactly(className1, className2) - } - @Test fun `add 'OptionProvider' class names`() { val className = "com.acme.MyOptions" @@ -98,22 +88,4 @@ class ExtensionSpec { extension.requestFilesDir = path extension.requestFilesDirProperty.get().asFile shouldBe project.projectDir.resolve(path) } - - @Test - fun `produce target directory`() { - val basePath = "my/path" - val expected = listOf("foo", "bar") - - extension.targetBaseDir = basePath - extension.subDirs = expected - - val sourceSet = project.sourceSets.getByName(MAIN_SOURCE_SET_NAME) - val targetDirs = extension.targetDirs(sourceSet).get() - - val mainDir = project.projectDir.toPath() / basePath / MAIN_SOURCE_SET_NAME - targetDirs[0].toPath() shouldBe mainDir / expected[0] - targetDirs[1].toPath() shouldBe mainDir / expected[1] - } } - -private fun Directory.toPath() = asFile.toPath() diff --git a/license-report.md b/license-report.md index 5f3a83274..85aae5034 100644 --- a/license-report.md +++ b/license-report.md @@ -1,6 +1,6 @@ -# Dependencies of `io.spine.protodata:protodata-api:0.11.5` +# Dependencies of `io.spine.protodata:protodata-api:0.12.0` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.15.2.**No license information found** @@ -925,12 +925,12 @@ The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 06 14:14:25 EEST 2023** 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 **Mon Sep 11 12:26:46 EEST 2023** 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.protodata:protodata-cli:0.11.5` +# Dependencies of `io.spine.protodata:protodata-cli:0.12.0` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.15.2.**No license information found** @@ -1871,12 +1871,12 @@ This report was generated on **Wed Sep 06 14:14:25 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 06 14:14:27 EEST 2023** 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 **Mon Sep 11 12:26:49 EEST 2023** 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.protodata:protodata-cli-api:0.11.5` +# Dependencies of `io.spine.protodata:protodata-cli-api:0.12.0` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.15.2.**No license information found** @@ -2789,12 +2789,12 @@ This report was generated on **Wed Sep 06 14:14:27 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 06 14:14:30 EEST 2023** 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 **Mon Sep 11 12:26:52 EEST 2023** 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.protodata:protodata-codegen-java:0.11.5` +# Dependencies of `io.spine.protodata:protodata-codegen-java:0.12.0` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.15.2.**No license information found** @@ -3718,12 +3718,12 @@ This report was generated on **Wed Sep 06 14:14:30 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 06 14:14:33 EEST 2023** 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 **Mon Sep 11 12:26:55 EEST 2023** 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.protodata:protodata-compiler:0.11.5` +# Dependencies of `io.spine.protodata:protodata-compiler:0.12.0` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.15.2.**No license information found** @@ -4647,12 +4647,12 @@ This report was generated on **Wed Sep 06 14:14:33 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 06 14:14:35 EEST 2023** 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 **Mon Sep 11 12:26:57 EEST 2023** 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.protodata:protodata-gradle-api:0.11.5` +# Dependencies of `io.spine.protodata:protodata-gradle-api:0.12.0` ## Runtime 1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2. @@ -5457,12 +5457,12 @@ This report was generated on **Wed Sep 06 14:14:35 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 06 14:14:37 EEST 2023** 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 **Mon Sep 11 12:26:59 EEST 2023** 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.protodata:protodata-gradle-plugin:0.11.5` +# Dependencies of `io.spine.protodata:protodata-gradle-plugin:0.12.0` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.15.2.**No license information found** @@ -6550,12 +6550,12 @@ This report was generated on **Wed Sep 06 14:14:37 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 06 14:14:39 EEST 2023** 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 **Mon Sep 11 12:27:02 EEST 2023** 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.protodata:protodata-protoc:0.11.5` +# Dependencies of `io.spine.protodata:protodata-protoc:0.12.0` ## Runtime 1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2. @@ -7319,12 +7319,12 @@ This report was generated on **Wed Sep 06 14:14:39 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 06 14:14:41 EEST 2023** 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 **Mon Sep 11 12:27:04 EEST 2023** 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.protodata:protodata-test-env:0.11.5` +# Dependencies of `io.spine.protodata:protodata-test-env:0.12.0` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.15.2.**No license information found** @@ -8255,4 +8255,4 @@ This report was generated on **Wed Sep 06 14:14:41 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 06 14:14:43 EEST 2023** 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 **Mon Sep 11 12:27:06 EEST 2023** 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/test-env/src/main/kotlin/io/spine/protodata/test/PathParams.kt b/test-env/src/main/kotlin/io/spine/protodata/test/PathParams.kt new file mode 100644 index 000000000..e711885fc --- /dev/null +++ b/test-env/src/main/kotlin/io/spine/protodata/test/PathParams.kt @@ -0,0 +1,38 @@ +/* + * 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.protodata.test + +import java.io.File + + +public fun paths(label: String, src: Any, target: Any): String { + val ps = File.pathSeparator + return label + ps + src + ps + target +} + +public fun pathsForJava(src: Any, target: Any): String = + paths("java", src, target) From 162cc35b962b645469c6162c53e837ee7c6902d7 Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Mon, 18 Sep 2023 11:02:11 +0300 Subject: [PATCH 07/30] Fix CLI param syntax --- cli/src/test/kotlin/io/spine/protodata/cli/app/CliTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/test/kotlin/io/spine/protodata/cli/app/CliTest.kt b/cli/src/test/kotlin/io/spine/protodata/cli/app/CliTest.kt index 6c574965c..62a8a1f56 100644 --- a/cli/src/test/kotlin/io/spine/protodata/cli/app/CliTest.kt +++ b/cli/src/test/kotlin/io/spine/protodata/cli/app/CliTest.kt @@ -293,7 +293,7 @@ class `Command line application should` { "-p", TestPlugin::class.jvmName, "-r", UnderscorePrefixRenderer::class.jvmName, "-t", codegenRequestFile.toString(), - "-paths", pathsForJava(srcRoot, "") + "--paths", pathsForJava(srcRoot, "") ) } } From 068c93897dc5d4b7b34a1f50cd830b31ac492234 Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Mon, 18 Sep 2023 11:03:49 +0300 Subject: [PATCH 08/30] Fix alignment --- .../kotlin/io/spine/protodata/backend/PipelineSpec.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/src/test/kotlin/io/spine/protodata/backend/PipelineSpec.kt b/compiler/src/test/kotlin/io/spine/protodata/backend/PipelineSpec.kt index 955011d7d..9a72f6e7e 100644 --- a/compiler/src/test/kotlin/io/spine/protodata/backend/PipelineSpec.kt +++ b/compiler/src/test/kotlin/io/spine/protodata/backend/PipelineSpec.kt @@ -84,8 +84,8 @@ import org.junit.jupiter.api.io.TempDir class PipelineSpec { private val marker = SourceFileSetMarker(Java) - private lateinit var srcRoot : Path - private lateinit var targetRoot : Path + private lateinit var srcRoot: Path + private lateinit var targetRoot: Path private lateinit var codegenRequestFile: Path private lateinit var targetFile: Path private lateinit var request: CodeGeneratorRequest @@ -204,7 +204,7 @@ class PipelineSpec { textIn(targetRoot / path) shouldBe textIn(srcRoot / path) } - @Test + @Test fun `write into inline insertion points`() { val path = "ClassWithMethod.java" write(path, """ @@ -449,7 +449,7 @@ class PipelineSpec { request ) val error = assertThrows { pipeline() } - error.message shouldContain(viewClass.name) + error.message shouldContain viewClass.name } } } From 5204e0c5fbbf72a127bcfcc6074f2734ea23c8f1 Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Tue, 19 Sep 2023 15:30:33 +0300 Subject: [PATCH 09/30] Check if a renderer supports the given sources file set --- .../io/spine/protodata/plugin/Plugin.kt | 4 +- .../protodata/renderer/SourceFileSetMarker.kt | 4 +- .../io/spine/protodata/cli/app/CliTest.kt | 12 ----- .../protodata/codegen/java/JavaRenderer.kt | 5 ++ .../codegen/java/WithSourceFileSet.kt | 3 +- .../io/spine/protodata/InsertionPointSpec.kt | 29 ++++++++---- .../spine/protodata/backend/PipelineSpec.kt | 27 ++++++++--- .../protodata/gradle/plugin/Extension.kt | 46 ++++++++++--------- .../spine/protodata/gradle/plugin/Plugin.kt | 2 +- .../src/test/proto/protodata/test/task.proto | 2 +- .../protodata/test/uuid/UuidJavaRenderer.java | 12 ++--- 11 files changed, 82 insertions(+), 64 deletions(-) diff --git a/api/src/main/kotlin/io/spine/protodata/plugin/Plugin.kt b/api/src/main/kotlin/io/spine/protodata/plugin/Plugin.kt index 4a66434cd..195014c7d 100644 --- a/api/src/main/kotlin/io/spine/protodata/plugin/Plugin.kt +++ b/api/src/main/kotlin/io/spine/protodata/plugin/Plugin.kt @@ -155,7 +155,9 @@ public fun Plugin.render( renderers().forEach { r -> r.registerWith(codegenContext) r.withTypeConventions(conventionSet) - sources.forEach(r::renderSources) + sources.asSequence() + .filter { r.supports(it.marker) } + .forEach { r.renderSources(it) } } } diff --git a/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSetMarker.kt b/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSetMarker.kt index 2e333965c..92ae62c4d 100644 --- a/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSetMarker.kt +++ b/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSetMarker.kt @@ -30,10 +30,8 @@ import io.spine.tools.code.Language public data class SourceFileSetMarker( public val language: Language, - public val generator: SourceGenerator + public val generator: SourceGenerator = Default ) { - public constructor(language: Language) : this(language, Default) - public constructor(language: Language, generatorName: String) : this(language, Custom(generatorName)) } diff --git a/cli/src/test/kotlin/io/spine/protodata/cli/app/CliTest.kt b/cli/src/test/kotlin/io/spine/protodata/cli/app/CliTest.kt index 62a8a1f56..40272598d 100644 --- a/cli/src/test/kotlin/io/spine/protodata/cli/app/CliTest.kt +++ b/cli/src/test/kotlin/io/spine/protodata/cli/app/CliTest.kt @@ -286,18 +286,6 @@ class `Command line application should` { } } - @Test - fun `target dir is missing`() { - assertThrows { - launchApp( - "-p", TestPlugin::class.jvmName, - "-r", UnderscorePrefixRenderer::class.jvmName, - "-t", codegenRequestFile.toString(), - "--paths", pathsForJava(srcRoot, "") - ) - } - } - @Test fun `code generator request file is missing`() { assertMissingOption { diff --git a/codegen/java/src/main/kotlin/io/spine/protodata/codegen/java/JavaRenderer.kt b/codegen/java/src/main/kotlin/io/spine/protodata/codegen/java/JavaRenderer.kt index 9b349aab5..9b20555a3 100644 --- a/codegen/java/src/main/kotlin/io/spine/protodata/codegen/java/JavaRenderer.kt +++ b/codegen/java/src/main/kotlin/io/spine/protodata/codegen/java/JavaRenderer.kt @@ -30,7 +30,9 @@ import io.spine.protodata.File import io.spine.protodata.FilePath import io.spine.protodata.ProtobufSourceFile import io.spine.protodata.TypeName +import io.spine.protodata.renderer.Default import io.spine.protodata.renderer.Renderer +import io.spine.protodata.renderer.SourceFileSetMarker import io.spine.tools.code.Java import java.nio.file.Path @@ -47,6 +49,9 @@ public abstract class JavaRenderer : Renderer(Java) { return type.javaClassName(file) } + override fun supports(marker: SourceFileSetMarker): Boolean = + marker.language == Java && marker.generator == Default + /** * Obtains the path the `.java` file generated from the given type. * diff --git a/codegen/java/src/test/kotlin/io/spine/protodata/codegen/java/WithSourceFileSet.kt b/codegen/java/src/test/kotlin/io/spine/protodata/codegen/java/WithSourceFileSet.kt index 27547ff6e..53b75c9f4 100644 --- a/codegen/java/src/test/kotlin/io/spine/protodata/codegen/java/WithSourceFileSet.kt +++ b/codegen/java/src/test/kotlin/io/spine/protodata/codegen/java/WithSourceFileSet.kt @@ -29,6 +29,7 @@ package io.spine.protodata.codegen.java import io.spine.protodata.renderer.SourceFileSet import io.spine.protodata.renderer.SourceFileSetMarker import io.spine.tools.code.AnyLanguage +import io.spine.tools.code.Java import java.nio.file.Path import java.nio.file.StandardOpenOption import kotlin.io.path.writeText @@ -53,7 +54,7 @@ open class WithSourceFileSet protected constructor() { val contents = javaClass.classLoader.getResource(JAVA_FILE)!!.readText() sourceFile.parent.toFile().mkdirs() sourceFile.writeText(contents, options = arrayOf(StandardOpenOption.CREATE_NEW)) - val marker = SourceFileSetMarker(AnyLanguage) + val marker = SourceFileSetMarker(Java) sources = listOf(SourceFileSet.create(marker, sourceRoot, targetRoot)) } } diff --git a/compiler/src/test/kotlin/io/spine/protodata/InsertionPointSpec.kt b/compiler/src/test/kotlin/io/spine/protodata/InsertionPointSpec.kt index cf85b0202..fd78ba691 100644 --- a/compiler/src/test/kotlin/io/spine/protodata/InsertionPointSpec.kt +++ b/compiler/src/test/kotlin/io/spine/protodata/InsertionPointSpec.kt @@ -48,6 +48,8 @@ import io.spine.protodata.test.KotlinInsertionPoint.LINE_FOUR_COL_THIRTY_THREE import io.spine.protodata.test.NonVoidMethodPrinter import io.spine.protodata.test.VariousKtInsertionPointsPrinter import io.spine.tools.code.AnyLanguage +import io.spine.tools.code.Java +import io.spine.tools.code.Kotlin import java.lang.System.lineSeparator import java.nio.file.Path import kotlin.io.path.createFile @@ -70,12 +72,11 @@ class InsertionPointsSpec { @BeforeEach fun preparePipeline(@TempDir input: Path, @TempDir output: Path) { - val inputKtFile = input / "sources.kt" - val inputJavaFile = input / "Source.java" - - inputKtFile.createFile() - inputJavaFile.createFile() - inputKtFile.writeText(""" + val kt = "kt" + val java = "jj" + val inputKtFile = input / "$kt/sources.kt" + val inputJavaFile = input / "$java/Source.java" + inputKtFile.create(""" class LabMouse { companion object { const val I_AM_CONSTANT: String = "!!" @@ -87,7 +88,7 @@ class InsertionPointsSpec { } """.trimIndent() ) - inputJavaFile.writeText(""" + inputJavaFile.create(""" package com.example; public class Source { @@ -104,6 +105,8 @@ class InsertionPointsSpec { } """.trimIndent() ) + val javaSet = SourceFileSet.create(SourceFileSetMarker(Java), input / java, output / java) + val ktSet = SourceFileSet.create(SourceFileSetMarker(Kotlin), input / kt, output / kt) Pipeline( plugins = listOf(), renderers = listOf( @@ -111,11 +114,11 @@ class InsertionPointsSpec { NonVoidMethodPrinter(), IgnoreValueAnnotator(), CompanionFramer(), CompanionLalalaRenderer() ), - sources = listOf(SourceFileSet.create(SourceFileSetMarker(AnyLanguage), input, output)), + sources = listOf(javaSet, ktSet), request = PluginProtos.CodeGeneratorRequest.getDefaultInstance(), )() - kotlinFile = output / inputKtFile.name - javaFile = output / inputJavaFile.name + kotlinFile = output / kt / inputKtFile.name + javaFile = output / java / inputJavaFile.name } @Test @@ -157,3 +160,9 @@ class InsertionPointsSpec { lines[2] shouldContain Regex("$LALALA\\s+companion.+$LALALA\\s+object", DOT_MATCHES_ALL) } } + +private fun Path.create(content: String) { + parent.toFile().mkdirs() + createFile() + writeText(content) +} diff --git a/compiler/src/test/kotlin/io/spine/protodata/backend/PipelineSpec.kt b/compiler/src/test/kotlin/io/spine/protodata/backend/PipelineSpec.kt index 9a72f6e7e..0d44c7776 100644 --- a/compiler/src/test/kotlin/io/spine/protodata/backend/PipelineSpec.kt +++ b/compiler/src/test/kotlin/io/spine/protodata/backend/PipelineSpec.kt @@ -63,8 +63,9 @@ import io.spine.protodata.test.TestPlugin import io.spine.protodata.test.UnderscorePrefixRenderer import io.spine.testing.assertDoesNotExist import io.spine.testing.assertExists -import io.spine.tools.code.AnyLanguage import io.spine.tools.code.Java +import io.spine.tools.code.JavaScript +import io.spine.tools.code.Kotlin import java.nio.file.Path import kotlin.io.path.createFile import kotlin.io.path.div @@ -241,21 +242,33 @@ class PipelineSpec { @Test fun `use different renderers for different files`() { - val jsPath = "test/source.js" - val ktPath = "corp/acme/test/Source.kt" + val js = "js" + val kt = "kt" + val jsPath = "$js/test/source.js" + val ktPath = "$kt/corp/acme/test/Source.kt" write(jsPath, "alert('Hello')") write(ktPath, "println(\"Hello\")") + val jsSet = SourceFileSet.create( + SourceFileSetMarker(JavaScript), + srcRoot / js, + targetRoot / js + ) + val ktSet = SourceFileSet.create( + SourceFileSetMarker(Kotlin), + srcRoot / kt, + targetRoot / kt + ) Pipeline( - plugin = TestPlugin(), + plugins = listOf(TestPlugin()), renderers = listOf( JsRenderer(), KtRenderer() ), - sources = sourceFileSet, + sources = listOf(jsSet, ktSet), request )() - assertTextIn(targetRoot / jsPath).contains("Hello JavaScript") - assertTextIn(targetRoot / ktPath).contains("Hello Kotlin") + textIn(targetRoot / jsPath) shouldContain "Hello JavaScript" + textIn(targetRoot / ktPath) shouldContain "Hello Kotlin" } @Test diff --git a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt index ce5717e96..c82bfa904 100644 --- a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt +++ b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt @@ -26,12 +26,15 @@ package io.spine.protodata.gradle.plugin +import com.google.common.collect.HashMultimap +import com.google.common.collect.Multimap import io.spine.protodata.gradle.CodeGeneratorRequestFile import io.spine.protodata.gradle.CodeGeneratorRequestFile.DEFAULT_DIRECTORY import io.spine.protodata.gradle.CodegenSettings import io.spine.protodata.renderer.Custom import io.spine.protodata.renderer.Default import io.spine.tools.code.Java +import io.spine.tools.code.Kotlin import io.spine.tools.fs.DirectoryName.generated import io.spine.tools.gradle.project.sourceSets import io.spine.tools.gradle.protobuf.generatedSourceProtoDir @@ -83,29 +86,30 @@ public class Extension(internal val project: Project): CodegenSettings { internal fun requestFile(forSourceSet: SourceSet): Provider = requestFilesDirProperty.file(CodeGeneratorRequestFile.name(forSourceSet)) - public val paths: NamedDomainObjectContainer = - project.objects.domainObjectContainer(SourcePaths::class) { - name -> SourcePaths(generatorName = name) - } + public val paths: Multimap = HashMultimap.create() - internal fun pathsOrCompat(): Set { - if (paths.isNotEmpty()) { - return paths + internal fun pathsOrCompat(sourceSet: SourceSet): Set { + if (!paths.isEmpty) { + return paths[sourceSet.name].toSet() } - return project.sourceSets.asSequence().flatMap { - val srcRoots = sourceDirs(it).get() - val targetRoots = targetDirs(it).get() - srcRoots.zip(targetRoots) - }.map { (src, target) -> - val pathSuffix = src.asFile.toPath().name - val generatorName = if (pathSuffix == "java") Default else Custom(pathSuffix) - SourcePaths( - src.asFile, - target.asFile, - Java, - generatorName - ) - }.toSet() + val srcRoots = sourceDirs(sourceSet).get() + val targetRoots = targetDirs(sourceSet).get() + return srcRoots.zip(targetRoots) + .map { (src, target) -> + val pathSuffix = src.asFile.toPath().name + val lang = if (pathSuffix == "kotlin") Kotlin else Java + val generatorName = if (pathSuffix.equals(lang.name, ignoreCase = true)) { + Default + } else { + Custom(pathSuffix) + } + SourcePaths( + src.asFile, + target.asFile, + lang, + generatorName + ) + }.toSet() } public companion object { diff --git a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Plugin.kt b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Plugin.kt index 271544a3b..2cfc48bbf 100644 --- a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Plugin.kt +++ b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Plugin.kt @@ -172,7 +172,7 @@ private fun Project.createLaunchTask(sourceSet: SourceSet, ext: Extension): Laun protoDataConfig = protoDataRawArtifact userClasspathConfig = userClasspath project.afterEvaluate { - paths = ext.pathsOrCompat() + paths = ext.pathsOrCompat(sourceSet) compileCommandLine() val java: SourceDirectorySet = sourceSet.java diff --git a/tests/consumer/src/test/proto/protodata/test/task.proto b/tests/consumer/src/test/proto/protodata/test/task.proto index 2ddc12961..9f3c00634 100644 --- a/tests/consumer/src/test/proto/protodata/test/task.proto +++ b/tests/consumer/src/test/proto/protodata/test/task.proto @@ -3,7 +3,7 @@ syntax = "proto3"; package protodata.test; option java_package = "io.spine.protodata.test"; -option java_outer_classname = "TaskProto"; +option java_outer_classname = "TaskIdProto"; option java_multiple_files = true; message TaskId { diff --git a/tests/protodata-extension/src/main/java/io/spine/protodata/test/uuid/UuidJavaRenderer.java b/tests/protodata-extension/src/main/java/io/spine/protodata/test/uuid/UuidJavaRenderer.java index eb6ca9b46..fca4648ef 100644 --- a/tests/protodata-extension/src/main/java/io/spine/protodata/test/uuid/UuidJavaRenderer.java +++ b/tests/protodata-extension/src/main/java/io/spine/protodata/test/uuid/UuidJavaRenderer.java @@ -70,21 +70,19 @@ public final class UuidJavaRenderer extends JavaRenderer { */ @Override protected void render(SourceFileSet sources) { + System.err.println("000000000000000"); + System.err.println("UuidJavaRenderer"); + System.err.println("000000000000000"); Set uuidTypes = select(UuidType.class).all(); for (UuidType type : uuidTypes) { + System.err.println(type.getName().getSimpleName()); + System.err.println("--=----=-==-=-=-=-=-=-==-==-=-=-==-"); TypeName typeName = type.getName(); FilePath file = type.getDeclaredIn(); ClassName className = classNameOf(typeName, file); InsertionPoint classScope = new ClassScope(typeName); ImmutableList lines = METHOD_FORMAT.format(className, UUID.class.getName()); Path javaFilePath = javaFileOf(typeName, file); - - // If there are no Java files, we deal with another language. - // Have this workaround until we get access to the `sourceRoot` property. - if (sources.findFile(javaFilePath).isEmpty()) { - continue; - } - sources.file(javaFilePath) .at(classScope) .withExtraIndentation(INDENT_LEVEL) From 4bcdce0638525d7af0ab4b949bceb806dd0e50f6 Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Tue, 19 Sep 2023 18:20:10 +0300 Subject: [PATCH 10/30] Make regex parsing more resilient --- .../protodata/renderer/SourceFileSetMarker.kt | 3 +++ .../kotlin/io/spine/protodata/cli/app/Main.kt | 10 ++++++---- .../spine/protodata/gradle/plugin/Extension.kt | 5 ++++- .../protodata/gradle/plugin/LaunchProtoData.kt | 8 -------- license-report.md | 18 +++++++++--------- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSetMarker.kt b/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSetMarker.kt index 92ae62c4d..fa9b2726b 100644 --- a/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSetMarker.kt +++ b/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSetMarker.kt @@ -34,4 +34,7 @@ public data class SourceFileSetMarker( ) { public constructor(language: Language, generatorName: String) : this(language, Custom(generatorName)) + + override fun toString(): String = + "${language.name}(${generator.name})" } diff --git a/cli/src/main/kotlin/io/spine/protodata/cli/app/Main.kt b/cli/src/main/kotlin/io/spine/protodata/cli/app/Main.kt index 42afd3f63..5f7f5e4ec 100644 --- a/cli/src/main/kotlin/io/spine/protodata/cli/app/Main.kt +++ b/cli/src/main/kotlin/io/spine/protodata/cli/app/Main.kt @@ -120,7 +120,7 @@ internal class Run(version: String) : CliktCommand( ), WithLogging { private val pathSplitter = Splitter.on(pathSeparator) - private val labelRegex = Regex("([\\w.]+)(\\((\\w+)\\))?") + private val labelRegex = Regex("(?[\\w.]+)(\\((?\\w+)\\))?") private fun Parameter.toOption(completionCandidates: CompletionCandidates? = null) = option( name, shortName, @@ -257,9 +257,11 @@ internal class Run(version: String) : CliktCommand( private fun loadLabel(label: String): SourceFileSetMarker { val match = labelRegex.matchEntire(label) require(match != null) { "Could not load source label: `$label`." } - val language = match.groupValues[1].toLanguage() - val generator = if (match.groupValues.size > 2) { - Custom(match.groupValues[3]) + val language = match.groups["lang"]!!.value.toLanguage() + val generatorMatch = match.groups["generator"] + val generator = if (generatorMatch != null) { + val rawGeneratorName = generatorMatch.value + Custom(rawGeneratorName) } else { Default } diff --git a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt index c82bfa904..00fe9b851 100644 --- a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt +++ b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt @@ -191,7 +191,10 @@ public class Extension(internal val project: Project): CodegenSettings { compileDir(sourceSet, targetBaseDirProperty) @Deprecated("Use `paths` instead.") - private fun compileDir(sourceSet: SourceSet, base: DirectoryProperty): Provider> { + private fun compileDir( + sourceSet: SourceSet, + base: DirectoryProperty + ): Provider> { val sourceSetDir = base.dir(sourceSet.name) return sourceSetDir.map { root: Directory -> subDirs.map { root.dir(it) } diff --git a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/LaunchProtoData.kt b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/LaunchProtoData.kt index 2bb24e55b..eb7811300 100644 --- a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/LaunchProtoData.kt +++ b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/LaunchProtoData.kt @@ -166,14 +166,6 @@ private fun SourcePaths.toCliParam(): String { return parts.joinToString(pathSeparator) } -private fun Provider>.absoluteDirs() = takeIf { it.isPresent } - ?.get() - ?.map { it.asFile.absoluteFile } - ?: listOf() - -private fun Provider>.absolutePaths(): String = - absoluteDirs().joinToString(pathSeparator) - /** * Tells if the request file for this task exists. * diff --git a/license-report.md b/license-report.md index 85aae5034..8e0dbabbd 100644 --- a/license-report.md +++ b/license-report.md @@ -925,7 +925,7 @@ The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Mon Sep 11 12:26:46 EEST 2023** 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 Sep 19 17:46:48 EEST 2023** 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). @@ -1871,7 +1871,7 @@ This report was generated on **Mon Sep 11 12:26:46 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Mon Sep 11 12:26:49 EEST 2023** 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 Sep 19 17:46:50 EEST 2023** 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). @@ -2789,7 +2789,7 @@ This report was generated on **Mon Sep 11 12:26:49 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Mon Sep 11 12:26:52 EEST 2023** 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 Sep 19 17:46:51 EEST 2023** 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). @@ -3718,7 +3718,7 @@ This report was generated on **Mon Sep 11 12:26:52 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Mon Sep 11 12:26:55 EEST 2023** 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 Sep 19 17:46:53 EEST 2023** 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). @@ -4647,7 +4647,7 @@ This report was generated on **Mon Sep 11 12:26:55 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Mon Sep 11 12:26:57 EEST 2023** 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 Sep 19 17:46:54 EEST 2023** 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). @@ -5457,7 +5457,7 @@ This report was generated on **Mon Sep 11 12:26:57 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Mon Sep 11 12:26:59 EEST 2023** 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 Sep 19 17:46:56 EEST 2023** 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). @@ -6550,7 +6550,7 @@ This report was generated on **Mon Sep 11 12:26:59 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Mon Sep 11 12:27:02 EEST 2023** 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 Sep 19 17:46:57 EEST 2023** 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). @@ -7319,7 +7319,7 @@ This report was generated on **Mon Sep 11 12:27:02 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Mon Sep 11 12:27:04 EEST 2023** 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 Sep 19 17:46:58 EEST 2023** 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). @@ -8255,4 +8255,4 @@ This report was generated on **Mon Sep 11 12:27:04 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Mon Sep 11 12:27:06 EEST 2023** 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 Sep 19 17:46:59 EEST 2023** 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 From 1dd738517424f9aeac9317b9de8516184feeb999 Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Tue, 19 Sep 2023 19:16:39 +0300 Subject: [PATCH 11/30] Update Gradle plugin tests --- config | 2 +- .../android-library/build.gradle.kts | 3 +- .../resources/empty-test/build.gradle.kts | 3 +- .../java-kotlin-test/build.gradle.kts | 3 +- .../java-library-kotlin-jvm/build.gradle.kts | 3 +- .../resources/kotlin-test/build.gradle.kts | 3 +- .../resources/launch-test/build.gradle.kts | 3 +- .../with-functional-test/build.gradle.kts | 3 +- license-report.md | 36 +++++++++---------- pom.xml | 4 +-- .../io/spine/protodata/test/NoOpPlugin.kt | 33 +++++++++++++++++ .../protodata/test/UnderscorePrefixPlugin.kt | 33 +++++++++++++++++ 12 files changed, 94 insertions(+), 35 deletions(-) create mode 100644 test-env/src/main/kotlin/io/spine/protodata/test/NoOpPlugin.kt create mode 100644 test-env/src/main/kotlin/io/spine/protodata/test/UnderscorePrefixPlugin.kt diff --git a/config b/config index d4f232214..327bc212a 160000 --- a/config +++ b/config @@ -1 +1 @@ -Subproject commit d4f232214236e9bca746ab2984ce6e46c5d79600 +Subproject commit 327bc212a335bf4badd560394364def291c0282e 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 4e6565aa7..b58a5cf9d 100644 --- a/gradle-plugin/src/functionalTest/resources/android-library/build.gradle.kts +++ b/gradle-plugin/src/functionalTest/resources/android-library/build.gradle.kts @@ -43,8 +43,7 @@ repositories { } protoData { - renderers("io.spine.protodata.test.UnderscorePrefixRenderer") - plugins("io.spine.protodata.test.TestPlugin") + plugins("io.spine.protodata.test.TestPlugin", "io.spine.protodata.test.UnderscorePrefixPlugin") } dependencies { 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 4a2e3d07e..4a4599a13 100644 --- a/gradle-plugin/src/functionalTest/resources/empty-test/build.gradle.kts +++ b/gradle-plugin/src/functionalTest/resources/empty-test/build.gradle.kts @@ -53,6 +53,5 @@ protobuf { } protoData { - renderers("io.spine.protodata.test.UnderscorePrefixRenderer") - plugins("io.spine.protodata.test.TestPlugin") + plugins("io.spine.protodata.test.TestPlugin", "io.spine.protodata.test.UnderscorePrefixPlugin") } 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 94aee809d..587f81b52 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 @@ -44,8 +44,7 @@ repositories { } protoData { - renderers("io.spine.protodata.test.NoOpRenderer") - plugins("io.spine.protodata.test.TestPlugin") + plugins("io.spine.protodata.test.TestPlugin", "io.spine.protodata.test.NoOpPlugin") } 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 dec4bf6fa..087c59430 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 @@ -45,8 +45,7 @@ repositories { } protoData { - renderers("io.spine.protodata.test.NoOpRenderer") - plugins("io.spine.protodata.test.TestPlugin") + plugins("io.spine.protodata.test.TestPlugin", "io.spine.protodata.test.NoOpPlugin") } 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 47f6c671c..b731434a8 100644 --- a/gradle-plugin/src/functionalTest/resources/kotlin-test/build.gradle.kts +++ b/gradle-plugin/src/functionalTest/resources/kotlin-test/build.gradle.kts @@ -44,8 +44,7 @@ repositories { } protoData { - renderers("io.spine.protodata.test.NoOpRenderer") - plugins("io.spine.protodata.test.TestPlugin") + plugins("io.spine.protodata.test.TestPlugin", "io.spine.protodata.test.NoOpPlugin") } 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 4a2e3d07e..4a4599a13 100644 --- a/gradle-plugin/src/functionalTest/resources/launch-test/build.gradle.kts +++ b/gradle-plugin/src/functionalTest/resources/launch-test/build.gradle.kts @@ -53,6 +53,5 @@ protobuf { } protoData { - renderers("io.spine.protodata.test.UnderscorePrefixRenderer") - plugins("io.spine.protodata.test.TestPlugin") + plugins("io.spine.protodata.test.TestPlugin", "io.spine.protodata.test.UnderscorePrefixPlugin") } 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 834f13aa5..87e3cbb8c 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 @@ -45,8 +45,7 @@ repositories { } protoData { - renderers("io.spine.protodata.test.NoOpRenderer") - plugins("io.spine.protodata.test.TestPlugin") + plugins("io.spine.protodata.test.TestPlugin", "io.spine.protodata.test.NoOpPlugin") } dependencies { diff --git a/license-report.md b/license-report.md index 1c7844089..a9a93d223 100644 --- a/license-report.md +++ b/license-report.md @@ -1,6 +1,6 @@ -# Dependencies of `io.spine.protodata:protodata-api:0.11.6` +# Dependencies of `io.spine.protodata:protodata-api:0.12.0` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.15.2.**No license information found** @@ -925,12 +925,12 @@ The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 13 20:12:06 WEST 2023** 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 Sep 19 18:43:34 EEST 2023** 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.protodata:protodata-cli:0.11.6` +# Dependencies of `io.spine.protodata:protodata-cli:0.12.0` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.15.2.**No license information found** @@ -1871,12 +1871,12 @@ This report was generated on **Wed Sep 13 20:12:06 WEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 13 20:12:07 WEST 2023** 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 Sep 19 18:43:36 EEST 2023** 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.protodata:protodata-cli-api:0.11.6` +# Dependencies of `io.spine.protodata:protodata-cli-api:0.12.0` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.15.2.**No license information found** @@ -2789,12 +2789,12 @@ This report was generated on **Wed Sep 13 20:12:07 WEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 13 20:12:07 WEST 2023** 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 Sep 19 18:43:37 EEST 2023** 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.protodata:protodata-codegen-java:0.11.6` +# Dependencies of `io.spine.protodata:protodata-codegen-java:0.12.0` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.15.2.**No license information found** @@ -3718,12 +3718,12 @@ This report was generated on **Wed Sep 13 20:12:07 WEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 13 20:12:08 WEST 2023** 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 Sep 19 18:43:39 EEST 2023** 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.protodata:protodata-compiler:0.11.6` +# Dependencies of `io.spine.protodata:protodata-compiler:0.12.0` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.15.2.**No license information found** @@ -4647,12 +4647,12 @@ This report was generated on **Wed Sep 13 20:12:08 WEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 13 20:12:08 WEST 2023** 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 Sep 19 18:43:40 EEST 2023** 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.protodata:protodata-gradle-api:0.11.6` +# Dependencies of `io.spine.protodata:protodata-gradle-api:0.12.0` ## Runtime 1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2. @@ -5457,12 +5457,12 @@ This report was generated on **Wed Sep 13 20:12:08 WEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 13 20:12:08 WEST 2023** 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 Sep 19 18:43:41 EEST 2023** 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.protodata:protodata-gradle-plugin:0.11.6` +# Dependencies of `io.spine.protodata:protodata-gradle-plugin:0.12.0` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.15.2.**No license information found** @@ -6550,12 +6550,12 @@ This report was generated on **Wed Sep 13 20:12:08 WEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 13 20:12:09 WEST 2023** 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 Sep 19 18:43:43 EEST 2023** 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.protodata:protodata-protoc:0.11.6` +# Dependencies of `io.spine.protodata:protodata-protoc:0.12.0` ## Runtime 1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2. @@ -7319,12 +7319,12 @@ This report was generated on **Wed Sep 13 20:12:09 WEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 13 20:12:09 WEST 2023** 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 Sep 19 18:43:44 EEST 2023** 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.protodata:protodata-test-env:0.11.6` +# Dependencies of `io.spine.protodata:protodata-test-env:0.12.0` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.15.2.**No license information found** @@ -8255,4 +8255,4 @@ This report was generated on **Wed Sep 13 20:12:09 WEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 13 20:12:09 WEST 2023** 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 Sep 19 18:43:45 EEST 2023** 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/pom.xml b/pom.xml index 1707f7a69..93bf1e09b 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ all modules and does not describe the project structure per-subproject. --> io.spine.protodata ProtoData -0.11.6 +0.12.0 2015 @@ -170,7 +170,7 @@ all modules and does not describe the project structure per-subproject. io.spine.tools spine-testutil-server - 2.0.0-SNAPSHOT.156 + 2.0.0-SNAPSHOT.157 test diff --git a/test-env/src/main/kotlin/io/spine/protodata/test/NoOpPlugin.kt b/test-env/src/main/kotlin/io/spine/protodata/test/NoOpPlugin.kt new file mode 100644 index 000000000..6ba75f322 --- /dev/null +++ b/test-env/src/main/kotlin/io/spine/protodata/test/NoOpPlugin.kt @@ -0,0 +1,33 @@ +/* + * 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.protodata.test + +import io.spine.protodata.plugin.AbstractPlugin + +public class NoOpPlugin : AbstractPlugin( + renderers = listOf(NoOpRenderer()) +) diff --git a/test-env/src/main/kotlin/io/spine/protodata/test/UnderscorePrefixPlugin.kt b/test-env/src/main/kotlin/io/spine/protodata/test/UnderscorePrefixPlugin.kt new file mode 100644 index 000000000..53843237f --- /dev/null +++ b/test-env/src/main/kotlin/io/spine/protodata/test/UnderscorePrefixPlugin.kt @@ -0,0 +1,33 @@ +/* + * 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.protodata.test + +import io.spine.protodata.plugin.AbstractPlugin + +public class UnderscorePrefixPlugin : AbstractPlugin( + renderers = listOf(UnderscorePrefixRenderer()) +) From 186e1c2de77d9e63903f37d2a466c8d96be41e3d Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Wed, 20 Sep 2023 10:41:17 +0300 Subject: [PATCH 12/30] Set up incremental build --- .../gradle/plugin/LaunchProtoData.kt | 25 +++++++++++++++++-- .../protodata/gradle/plugin/SourcePaths.kt | 4 +-- license-report.md | 18 ++++++------- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/LaunchProtoData.kt b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/LaunchProtoData.kt index eb7811300..ae09e7fce 100644 --- a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/LaunchProtoData.kt +++ b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/LaunchProtoData.kt @@ -48,6 +48,8 @@ import org.gradle.api.tasks.InputFile import org.gradle.api.tasks.InputFiles import org.gradle.api.tasks.Internal import org.gradle.api.tasks.JavaExec +import org.gradle.api.tasks.Optional +import org.gradle.api.tasks.OutputDirectories import org.gradle.api.tasks.SourceSet /** @@ -74,7 +76,7 @@ public abstract class LaunchProtoData : JavaExec() { @get:Input internal lateinit var optionProviders: Provider> - @get:Input + @get:Internal internal lateinit var paths: Set @get:InputFiles @@ -86,6 +88,25 @@ public abstract class LaunchProtoData : JavaExec() { @get:InputFiles internal lateinit var protoDataConfig: Configuration + @Suppress("unused") // Used by Gradle for incremental compilation. + @get:InputFiles + @get:Optional + internal val sources: Set + get() = paths.asSequence() + .map { it.source } + .filter { it != null } + .map { project.layout.projectDirectory.dir(it!!) } + .toSet() + + @Suppress("unused") // Used by Gradle for incremental compilation. + @get:OutputDirectories + internal val targets: Set + get() = paths.asSequence() + .map { it.target } + .filter { it != null } + .map { project.layout.projectDirectory.dir(it!!) } + .toSet() + /** * Configures the CLI command for this task. * @@ -154,7 +175,7 @@ public abstract class LaunchProtoData : JavaExec() { } private fun SourcePaths.toCliParam(): String { -// checkAllSet() + checkAllSet() val label = if (generatorName != Default.name) { "$language($generatorName)" } else { diff --git a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/SourcePaths.kt b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/SourcePaths.kt index 8a449573f..58ac9c12f 100644 --- a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/SourcePaths.kt +++ b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/SourcePaths.kt @@ -52,8 +52,8 @@ public data class SourcePaths( ) internal fun checkAllSet() { - require(target.isNullOrBlank()) { missingMessage("target path") } - require(language.isNullOrBlank()) { missingMessage("language") } + require(!target.isNullOrBlank()) { missingMessage("target path") } + require(!language.isNullOrBlank()) { missingMessage("language") } } override fun getName(): String = generatorName diff --git a/license-report.md b/license-report.md index a9a93d223..2d07b2a1c 100644 --- a/license-report.md +++ b/license-report.md @@ -925,7 +925,7 @@ The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Sep 19 18:43:34 EEST 2023** 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 Sep 19 21:14:13 EEST 2023** 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). @@ -1871,7 +1871,7 @@ This report was generated on **Tue Sep 19 18:43:34 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Sep 19 18:43:36 EEST 2023** 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 Sep 19 21:14:16 EEST 2023** 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). @@ -2789,7 +2789,7 @@ This report was generated on **Tue Sep 19 18:43:36 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Sep 19 18:43:37 EEST 2023** 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 Sep 19 21:14:19 EEST 2023** 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). @@ -3718,7 +3718,7 @@ This report was generated on **Tue Sep 19 18:43:37 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Sep 19 18:43:39 EEST 2023** 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 Sep 19 21:14:22 EEST 2023** 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). @@ -4647,7 +4647,7 @@ This report was generated on **Tue Sep 19 18:43:39 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Sep 19 18:43:40 EEST 2023** 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 Sep 19 21:14:24 EEST 2023** 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). @@ -5457,7 +5457,7 @@ This report was generated on **Tue Sep 19 18:43:40 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Sep 19 18:43:41 EEST 2023** 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 Sep 19 21:14:27 EEST 2023** 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). @@ -6550,7 +6550,7 @@ This report was generated on **Tue Sep 19 18:43:41 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Sep 19 18:43:43 EEST 2023** 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 Sep 19 21:14:29 EEST 2023** 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). @@ -7319,7 +7319,7 @@ This report was generated on **Tue Sep 19 18:43:43 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Sep 19 18:43:44 EEST 2023** 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 Sep 19 21:14:31 EEST 2023** 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). @@ -8255,4 +8255,4 @@ This report was generated on **Tue Sep 19 18:43:44 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Sep 19 18:43:45 EEST 2023** 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 Sep 19 21:14:34 EEST 2023** 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 From 0fcecf9fe4c8ff2dadd59267da54a17c3f86bcaf Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Wed, 20 Sep 2023 11:12:33 +0300 Subject: [PATCH 13/30] Add some doc --- .../io/spine/protodata/renderer/Renderer.kt | 13 +++- .../protodata/renderer/SourceFileSetMarker.kt | 4 +- .../protodata/renderer/SourceGenerator.kt | 39 ----------- .../protodata/renderer/SourceGeneratorName.kt | 67 +++++++++++++++++++ .../kotlin/io/spine/protodata/cli/app/Main.kt | 11 ++- .../protodata/codegen/java/JavaRenderer.kt | 8 ++- .../protodata/gradle/plugin/Extension.kt | 11 ++- .../gradle/plugin/LaunchProtoData.kt | 4 +- .../protodata/gradle/plugin/SourcePaths.kt | 8 +-- 9 files changed, 100 insertions(+), 65 deletions(-) delete mode 100644 api/src/main/kotlin/io/spine/protodata/renderer/SourceGenerator.kt create mode 100644 api/src/main/kotlin/io/spine/protodata/renderer/SourceGeneratorName.kt diff --git a/api/src/main/kotlin/io/spine/protodata/renderer/Renderer.kt b/api/src/main/kotlin/io/spine/protodata/renderer/Renderer.kt index 4ebc35177..fb194d68a 100644 --- a/api/src/main/kotlin/io/spine/protodata/renderer/Renderer.kt +++ b/api/src/main/kotlin/io/spine/protodata/renderer/Renderer.kt @@ -62,14 +62,23 @@ protected constructor( sources.mergeBack(relevantFiles) } + /** + * Checks if this renderer supports a given source file set. + * + * By default, a renderer supports all source sets of the [supportedLanguage]. A renderer that + * supports [AnyLanguage] also supports any source file set. + * + * Note that, even if a source file set is supported, the renderer will still only receive + * a portion of it with the file that match the [language filter][Language.matches]. + */ public open fun supports(marker: SourceFileSetMarker): Boolean = supportedLanguage == AnyLanguage || supportedLanguage == marker.language /** * Makes changes to the given source set. * - * The source set is guaranteed to consist only of the files, containing the code in - * the [supportedLanguage]. + * The source set is guaranteed to be [supported][supports] and to consist only of the files + * containing the code in the [supportedLanguage]. * * This method may be called several times, if ProtoData is called with multiple source and * target directories. diff --git a/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSetMarker.kt b/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSetMarker.kt index fa9b2726b..2e3599327 100644 --- a/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSetMarker.kt +++ b/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSetMarker.kt @@ -30,10 +30,10 @@ import io.spine.tools.code.Language public data class SourceFileSetMarker( public val language: Language, - public val generator: SourceGenerator = Default + public val generator: SourceGeneratorName = DefaultGenerator ) { public constructor(language: Language, generatorName: String) - : this(language, Custom(generatorName)) + : this(language, CustomGenerator(generatorName)) override fun toString(): String = "${language.name}(${generator.name})" diff --git a/api/src/main/kotlin/io/spine/protodata/renderer/SourceGenerator.kt b/api/src/main/kotlin/io/spine/protodata/renderer/SourceGenerator.kt deleted file mode 100644 index 24a1356b0..000000000 --- a/api/src/main/kotlin/io/spine/protodata/renderer/SourceGenerator.kt +++ /dev/null @@ -1,39 +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.protodata.renderer - -public sealed interface SourceGenerator { - - public val name: String - get() = javaClass.simpleName.lowercase() -} - -public object Default : SourceGenerator - -public class Custom( - override val name: String -) : SourceGenerator diff --git a/api/src/main/kotlin/io/spine/protodata/renderer/SourceGeneratorName.kt b/api/src/main/kotlin/io/spine/protodata/renderer/SourceGeneratorName.kt new file mode 100644 index 000000000..e46bb1b58 --- /dev/null +++ b/api/src/main/kotlin/io/spine/protodata/renderer/SourceGeneratorName.kt @@ -0,0 +1,67 @@ +/* + * 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.protodata.renderer + +/** + * A name of a source code generator. + * + * This can be a `protoc` plugin or builtin, or a custom code generator tool. + */ +public sealed interface SourceGeneratorName { + + public val name: String + get() = javaClass.simpleName.lowercase() +} + +/** + * The default generator is the default way for the Protobuf compiler to generate source code for + * a given language. + * + * For example, in Java, the default generator, given a message `Foo`, would generate a message + * classes and auxiliary types, such as classes `Foo`, `Foo.Builder`, `Foo.Parser`, + * and the interface `FooOrBuilder`. + * + * Since the Protobuf compiler does not support all the existing programming languages, + * the `DefaultGenerator` is only defined for those languages that are supported, such as Java, JS, + * C++, etc. For other languages, as well as for other code generation scenarios, + * see [CustomGenerator]. + */ +public object DefaultGenerator : SourceGeneratorName + +/** + * A name of a custom source code generator. + * + * May represent a Protobuf compiler plugin, or any other code generator. + * + * Conventionally, the name of the generator should coincide with the name of the directory where + * the generated files are placed. Users should follow this convention where possible, yet diverge + * when necessary. For example, Java gRPC stubs should be labelled with the `grpc` name. However, + * files generated for Dart should be labelled with the name `dart`, not `lib`. + */ +public class CustomGenerator( + override val name: String +) : SourceGeneratorName diff --git a/cli/src/main/kotlin/io/spine/protodata/cli/app/Main.kt b/cli/src/main/kotlin/io/spine/protodata/cli/app/Main.kt index 5f7f5e4ec..12a5938fd 100644 --- a/cli/src/main/kotlin/io/spine/protodata/cli/app/Main.kt +++ b/cli/src/main/kotlin/io/spine/protodata/cli/app/Main.kt @@ -59,19 +59,16 @@ import io.spine.protodata.cli.PathsParam import io.spine.protodata.cli.PluginParam import io.spine.protodata.cli.RendererParam import io.spine.protodata.cli.RequestParam -import io.spine.protodata.cli.SourceRootParam -import io.spine.protodata.cli.TargetRootParam import io.spine.protodata.cli.UserClasspathParam import io.spine.protodata.config.Configuration import io.spine.protodata.config.ConfigurationFormat -import io.spine.protodata.renderer.Custom -import io.spine.protodata.renderer.Default +import io.spine.protodata.renderer.CustomGenerator +import io.spine.protodata.renderer.DefaultGenerator import io.spine.protodata.renderer.SourceFileSet import io.spine.protodata.renderer.SourceFileSetMarker import io.spine.string.Separator.Companion.nl import io.spine.string.pi import io.spine.string.ti -import io.spine.tools.code.AnyLanguage import io.spine.tools.code.manifest.Version import java.io.File import java.io.File.pathSeparator @@ -261,9 +258,9 @@ internal class Run(version: String) : CliktCommand( val generatorMatch = match.groups["generator"] val generator = if (generatorMatch != null) { val rawGeneratorName = generatorMatch.value - Custom(rawGeneratorName) + CustomGenerator(rawGeneratorName) } else { - Default + DefaultGenerator } val sourceLabel = SourceFileSetMarker(language, generator) return sourceLabel diff --git a/codegen/java/src/main/kotlin/io/spine/protodata/codegen/java/JavaRenderer.kt b/codegen/java/src/main/kotlin/io/spine/protodata/codegen/java/JavaRenderer.kt index 9b20555a3..a01567c0d 100644 --- a/codegen/java/src/main/kotlin/io/spine/protodata/codegen/java/JavaRenderer.kt +++ b/codegen/java/src/main/kotlin/io/spine/protodata/codegen/java/JavaRenderer.kt @@ -30,7 +30,7 @@ import io.spine.protodata.File import io.spine.protodata.FilePath import io.spine.protodata.ProtobufSourceFile import io.spine.protodata.TypeName -import io.spine.protodata.renderer.Default +import io.spine.protodata.renderer.DefaultGenerator import io.spine.protodata.renderer.Renderer import io.spine.protodata.renderer.SourceFileSetMarker import io.spine.tools.code.Java @@ -49,8 +49,12 @@ public abstract class JavaRenderer : Renderer(Java) { return type.javaClassName(file) } + /** + * A `JavaRenderer` supports only the default Java sources, i.e. the source files generated + * by the vanilla Protobuf compiler for the given Proto definitions. + */ override fun supports(marker: SourceFileSetMarker): Boolean = - marker.language == Java && marker.generator == Default + marker.language == Java && marker.generator == DefaultGenerator /** * Obtains the path the `.java` file generated from the given type. diff --git a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt index 00fe9b851..01a5bd921 100644 --- a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt +++ b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt @@ -31,15 +31,13 @@ import com.google.common.collect.Multimap import io.spine.protodata.gradle.CodeGeneratorRequestFile import io.spine.protodata.gradle.CodeGeneratorRequestFile.DEFAULT_DIRECTORY import io.spine.protodata.gradle.CodegenSettings -import io.spine.protodata.renderer.Custom -import io.spine.protodata.renderer.Default +import io.spine.protodata.renderer.CustomGenerator +import io.spine.protodata.renderer.DefaultGenerator import io.spine.tools.code.Java import io.spine.tools.code.Kotlin import io.spine.tools.fs.DirectoryName.generated -import io.spine.tools.gradle.project.sourceSets import io.spine.tools.gradle.protobuf.generatedSourceProtoDir import kotlin.io.path.name -import org.gradle.api.NamedDomainObjectContainer import org.gradle.api.Project import org.gradle.api.file.Directory import org.gradle.api.file.DirectoryProperty @@ -47,7 +45,6 @@ import org.gradle.api.file.RegularFile import org.gradle.api.provider.ListProperty import org.gradle.api.provider.Provider import org.gradle.api.tasks.SourceSet -import org.gradle.kotlin.dsl.domainObjectContainer import org.gradle.kotlin.dsl.listProperty /** @@ -99,9 +96,9 @@ public class Extension(internal val project: Project): CodegenSettings { val pathSuffix = src.asFile.toPath().name val lang = if (pathSuffix == "kotlin") Kotlin else Java val generatorName = if (pathSuffix.equals(lang.name, ignoreCase = true)) { - Default + DefaultGenerator } else { - Custom(pathSuffix) + CustomGenerator(pathSuffix) } SourcePaths( src.asFile, diff --git a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/LaunchProtoData.kt b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/LaunchProtoData.kt index ae09e7fce..f95722dd8 100644 --- a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/LaunchProtoData.kt +++ b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/LaunchProtoData.kt @@ -32,7 +32,7 @@ import io.spine.protodata.cli.PathsParam import io.spine.protodata.cli.PluginParam import io.spine.protodata.cli.RequestParam import io.spine.protodata.cli.UserClasspathParam -import io.spine.protodata.renderer.Default +import io.spine.protodata.renderer.DefaultGenerator import io.spine.tools.gradle.protobuf.containsProtoFiles import java.io.File import java.io.File.pathSeparator @@ -176,7 +176,7 @@ public abstract class LaunchProtoData : JavaExec() { private fun SourcePaths.toCliParam(): String { checkAllSet() - val label = if (generatorName != Default.name) { + val label = if (generatorName != DefaultGenerator.name) { "$language($generatorName)" } else { language diff --git a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/SourcePaths.kt b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/SourcePaths.kt index 58ac9c12f..795b02eb1 100644 --- a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/SourcePaths.kt +++ b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/SourcePaths.kt @@ -26,8 +26,8 @@ package io.spine.protodata.gradle.plugin -import io.spine.protodata.renderer.Default -import io.spine.protodata.renderer.SourceGenerator +import io.spine.protodata.renderer.DefaultGenerator +import io.spine.protodata.renderer.SourceGeneratorName import io.spine.tools.code.Language import java.io.File import org.gradle.api.Named @@ -36,14 +36,14 @@ public data class SourcePaths( public var source: String? = null, public var target: String? = null, public var language: String? = null, - public var generatorName: String = Default.name + public var generatorName: String = DefaultGenerator.name ) : Named { public constructor( source: File, target: File, language: Language, - generator: SourceGenerator + generator: SourceGeneratorName ) : this( source.absolutePath, target.absolutePath, From 368ae6e3b5673670a5b65f98c9c3ae450e657e82 Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Wed, 20 Sep 2023 11:34:38 +0300 Subject: [PATCH 14/30] More doc --- .../io/spine/protodata/plugin/Plugin.kt | 2 +- .../io/spine/protodata/renderer/Renderer.kt | 4 ++-- .../spine/protodata/renderer/SourceFileSet.kt | 13 +++++----- ...FileSetMarker.kt => SourceFileSetLabel.kt} | 12 +++++++++- .../protodata/renderer/SourceFileSetSpec.kt | 2 +- .../kotlin/io/spine/protodata/cli/app/Main.kt | 6 ++--- .../protodata/codegen/java/JavaRenderer.kt | 6 ++--- .../codegen/java/WithSourceFileSet.kt | 7 +++--- .../io/spine/protodata/InsertionPointSpec.kt | 7 +++--- .../spine/protodata/backend/PipelineSpec.kt | 24 +++++++++---------- 10 files changed, 45 insertions(+), 38 deletions(-) rename api/src/main/kotlin/io/spine/protodata/renderer/{SourceFileSetMarker.kt => SourceFileSetLabel.kt} (83%) diff --git a/api/src/main/kotlin/io/spine/protodata/plugin/Plugin.kt b/api/src/main/kotlin/io/spine/protodata/plugin/Plugin.kt index 39066edce..326723796 100644 --- a/api/src/main/kotlin/io/spine/protodata/plugin/Plugin.kt +++ b/api/src/main/kotlin/io/spine/protodata/plugin/Plugin.kt @@ -158,7 +158,7 @@ public fun Plugin.render( r.registerWith(codegenContext) r.withTypeConventions(conventionSet) sources.asSequence() - .filter { r.supports(it.marker) } + .filter { r.supports(it.label) } .forEach { r.renderSources(it) } } } diff --git a/api/src/main/kotlin/io/spine/protodata/renderer/Renderer.kt b/api/src/main/kotlin/io/spine/protodata/renderer/Renderer.kt index fb194d68a..f3994a5ca 100644 --- a/api/src/main/kotlin/io/spine/protodata/renderer/Renderer.kt +++ b/api/src/main/kotlin/io/spine/protodata/renderer/Renderer.kt @@ -71,8 +71,8 @@ protected constructor( * Note that, even if a source file set is supported, the renderer will still only receive * a portion of it with the file that match the [language filter][Language.matches]. */ - public open fun supports(marker: SourceFileSetMarker): Boolean = - supportedLanguage == AnyLanguage || supportedLanguage == marker.language + public open fun supports(label: SourceFileSetLabel): Boolean = + supportedLanguage == AnyLanguage || supportedLanguage == label.language /** * Makes changes to the given source set. diff --git a/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSet.kt b/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSet.kt index dc3fa5dbf..18cf4668b 100644 --- a/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSet.kt +++ b/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSet.kt @@ -40,7 +40,6 @@ import java.nio.charset.Charset import java.nio.file.Files.walk import java.nio.file.Path import java.util.* -import kotlin.DeprecationLevel.ERROR import kotlin.io.path.absolutePathString import kotlin.io.path.exists import kotlin.io.path.isRegularFile @@ -69,7 +68,7 @@ import kotlin.text.Charsets.UTF_8 @Suppress("TooManyFunctions") // All part of the public API. public class SourceFileSet internal constructor( - public val marker: SourceFileSetMarker, + public val label: SourceFileSetLabel, files: Set, @@ -124,7 +123,7 @@ internal constructor( * will not be changed. */ public fun create( - marker: SourceFileSetMarker, + label: SourceFileSetLabel, inputRoot: Path, outputRoot: Path ): SourceFileSet { @@ -135,17 +134,17 @@ internal constructor( .filter { it.isRegularFile() } .map { SourceFile.read(source.relativize(it), source) } .collect(toImmutableSet()) - return SourceFileSet(marker, files, source, target) + return SourceFileSet(label, files, source, target) } /** * Creates an empty source set which can be appended with new files and * written to the given target directory. */ - public fun empty(marker: SourceFileSetMarker, target: Path): SourceFileSet { + public fun empty(label: SourceFileSetLabel, target: Path): SourceFileSet { checkTarget(target) val files = setOf() - return SourceFileSet(marker, files, target, target) + return SourceFileSet(label, files, target, target) } } @@ -298,7 +297,7 @@ internal constructor( * matching the given [predicate]. */ internal fun SourceFileSet.subsetWhere(predicate: (SourceFile) -> Boolean) = - SourceFileSet(this.marker, this.filter(predicate).toSet(), inputRoot, outputRoot) + SourceFileSet(this.label, this.filter(predicate).toSet(), inputRoot, outputRoot) /** * Obtains absolute [normalized][normalize] version of this path. diff --git a/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSetMarker.kt b/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSetLabel.kt similarity index 83% rename from api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSetMarker.kt rename to api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSetLabel.kt index 2e3599327..e3ce1b487 100644 --- a/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSetMarker.kt +++ b/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSetLabel.kt @@ -28,10 +28,20 @@ package io.spine.protodata.renderer import io.spine.tools.code.Language -public data class SourceFileSetMarker( +/** + * A label for a source file set. + * + * The label marks the programming language that the files use and the name of the generator that + * created the files. + */ +public data class SourceFileSetLabel( public val language: Language, public val generator: SourceGeneratorName = DefaultGenerator ) { + + /** + * Creates a new `SourceFileSetLabel` with the given language and a custom generator name. + */ public constructor(language: Language, generatorName: String) : this(language, CustomGenerator(generatorName)) diff --git a/api/src/test/kotlin/io/spine/protodata/renderer/SourceFileSetSpec.kt b/api/src/test/kotlin/io/spine/protodata/renderer/SourceFileSetSpec.kt index 1bca95ab7..45e61227c 100644 --- a/api/src/test/kotlin/io/spine/protodata/renderer/SourceFileSetSpec.kt +++ b/api/src/test/kotlin/io/spine/protodata/renderer/SourceFileSetSpec.kt @@ -63,7 +63,7 @@ class SourceFileSetSpec { textFile.writeText("this is a non-empty file") } } - set = SourceFileSet.create(SourceFileSetMarker(AnyLanguage), input, output) + set = SourceFileSet.create(SourceFileSetLabel(AnyLanguage), input, output) } @Test diff --git a/cli/src/main/kotlin/io/spine/protodata/cli/app/Main.kt b/cli/src/main/kotlin/io/spine/protodata/cli/app/Main.kt index 12a5938fd..db4bcdc3b 100644 --- a/cli/src/main/kotlin/io/spine/protodata/cli/app/Main.kt +++ b/cli/src/main/kotlin/io/spine/protodata/cli/app/Main.kt @@ -65,7 +65,7 @@ import io.spine.protodata.config.ConfigurationFormat import io.spine.protodata.renderer.CustomGenerator import io.spine.protodata.renderer.DefaultGenerator import io.spine.protodata.renderer.SourceFileSet -import io.spine.protodata.renderer.SourceFileSetMarker +import io.spine.protodata.renderer.SourceFileSetLabel import io.spine.string.Separator.Companion.nl import io.spine.string.pi import io.spine.string.ti @@ -251,7 +251,7 @@ internal class Run(version: String) : CliktCommand( } } - private fun loadLabel(label: String): SourceFileSetMarker { + private fun loadLabel(label: String): SourceFileSetLabel { val match = labelRegex.matchEntire(label) require(match != null) { "Could not load source label: `$label`." } val language = match.groups["lang"]!!.value.toLanguage() @@ -262,7 +262,7 @@ internal class Run(version: String) : CliktCommand( } else { DefaultGenerator } - val sourceLabel = SourceFileSetMarker(language, generator) + val sourceLabel = SourceFileSetLabel(language, generator) return sourceLabel } diff --git a/codegen/java/src/main/kotlin/io/spine/protodata/codegen/java/JavaRenderer.kt b/codegen/java/src/main/kotlin/io/spine/protodata/codegen/java/JavaRenderer.kt index a01567c0d..4b4a7473f 100644 --- a/codegen/java/src/main/kotlin/io/spine/protodata/codegen/java/JavaRenderer.kt +++ b/codegen/java/src/main/kotlin/io/spine/protodata/codegen/java/JavaRenderer.kt @@ -32,7 +32,7 @@ import io.spine.protodata.ProtobufSourceFile import io.spine.protodata.TypeName import io.spine.protodata.renderer.DefaultGenerator import io.spine.protodata.renderer.Renderer -import io.spine.protodata.renderer.SourceFileSetMarker +import io.spine.protodata.renderer.SourceFileSetLabel import io.spine.tools.code.Java import java.nio.file.Path @@ -53,8 +53,8 @@ public abstract class JavaRenderer : Renderer(Java) { * A `JavaRenderer` supports only the default Java sources, i.e. the source files generated * by the vanilla Protobuf compiler for the given Proto definitions. */ - override fun supports(marker: SourceFileSetMarker): Boolean = - marker.language == Java && marker.generator == DefaultGenerator + override fun supports(label: SourceFileSetLabel): Boolean = + label.language == Java && label.generator == DefaultGenerator /** * Obtains the path the `.java` file generated from the given type. diff --git a/codegen/java/src/test/kotlin/io/spine/protodata/codegen/java/WithSourceFileSet.kt b/codegen/java/src/test/kotlin/io/spine/protodata/codegen/java/WithSourceFileSet.kt index 53b75c9f4..21416e4ef 100644 --- a/codegen/java/src/test/kotlin/io/spine/protodata/codegen/java/WithSourceFileSet.kt +++ b/codegen/java/src/test/kotlin/io/spine/protodata/codegen/java/WithSourceFileSet.kt @@ -27,8 +27,7 @@ package io.spine.protodata.codegen.java import io.spine.protodata.renderer.SourceFileSet -import io.spine.protodata.renderer.SourceFileSetMarker -import io.spine.tools.code.AnyLanguage +import io.spine.protodata.renderer.SourceFileSetLabel import io.spine.tools.code.Java import java.nio.file.Path import java.nio.file.StandardOpenOption @@ -54,7 +53,7 @@ open class WithSourceFileSet protected constructor() { val contents = javaClass.classLoader.getResource(JAVA_FILE)!!.readText() sourceFile.parent.toFile().mkdirs() sourceFile.writeText(contents, options = arrayOf(StandardOpenOption.CREATE_NEW)) - val marker = SourceFileSetMarker(Java) - sources = listOf(SourceFileSet.create(marker, sourceRoot, targetRoot)) + val label = SourceFileSetLabel(Java) + sources = listOf(SourceFileSet.create(label, sourceRoot, targetRoot)) } } diff --git a/compiler/src/test/kotlin/io/spine/protodata/InsertionPointSpec.kt b/compiler/src/test/kotlin/io/spine/protodata/InsertionPointSpec.kt index fd78ba691..9f554e8b2 100644 --- a/compiler/src/test/kotlin/io/spine/protodata/InsertionPointSpec.kt +++ b/compiler/src/test/kotlin/io/spine/protodata/InsertionPointSpec.kt @@ -34,7 +34,7 @@ import io.kotest.matchers.collections.shouldNotHaveSize import io.kotest.matchers.string.shouldContain import io.spine.protodata.backend.Pipeline import io.spine.protodata.renderer.SourceFileSet -import io.spine.protodata.renderer.SourceFileSetMarker +import io.spine.protodata.renderer.SourceFileSetLabel import io.spine.protodata.renderer.codeLine import io.spine.protodata.test.CatOutOfTheBoxEmancipator import io.spine.protodata.test.CompanionFramer @@ -47,7 +47,6 @@ import io.spine.protodata.test.KotlinInsertionPoint.FILE_START import io.spine.protodata.test.KotlinInsertionPoint.LINE_FOUR_COL_THIRTY_THREE import io.spine.protodata.test.NonVoidMethodPrinter import io.spine.protodata.test.VariousKtInsertionPointsPrinter -import io.spine.tools.code.AnyLanguage import io.spine.tools.code.Java import io.spine.tools.code.Kotlin import java.lang.System.lineSeparator @@ -105,8 +104,8 @@ class InsertionPointsSpec { } """.trimIndent() ) - val javaSet = SourceFileSet.create(SourceFileSetMarker(Java), input / java, output / java) - val ktSet = SourceFileSet.create(SourceFileSetMarker(Kotlin), input / kt, output / kt) + val javaSet = SourceFileSet.create(SourceFileSetLabel(Java), input / java, output / java) + val ktSet = SourceFileSet.create(SourceFileSetLabel(Kotlin), input / kt, output / kt) Pipeline( plugins = listOf(), renderers = listOf( diff --git a/compiler/src/test/kotlin/io/spine/protodata/backend/PipelineSpec.kt b/compiler/src/test/kotlin/io/spine/protodata/backend/PipelineSpec.kt index 0d44c7776..2a0ad05d1 100644 --- a/compiler/src/test/kotlin/io/spine/protodata/backend/PipelineSpec.kt +++ b/compiler/src/test/kotlin/io/spine/protodata/backend/PipelineSpec.kt @@ -37,7 +37,7 @@ import io.spine.protodata.ConfigurationError import io.spine.protodata.config.Configuration import io.spine.protodata.config.ConfigurationFormat import io.spine.protodata.renderer.SourceFileSet -import io.spine.protodata.renderer.SourceFileSetMarker +import io.spine.protodata.renderer.SourceFileSetLabel import io.spine.protodata.renderer.codeLine import io.spine.protodata.test.AnnotationInsertionPointPrinter import io.spine.protodata.test.CatOutOfTheBoxEmancipator @@ -84,7 +84,7 @@ import org.junit.jupiter.api.io.TempDir @DisplayName("`Pipeline` should") class PipelineSpec { - private val marker = SourceFileSetMarker(Java) + private val label = SourceFileSetLabel(Java) private lateinit var srcRoot: Path private lateinit var targetRoot: Path private lateinit var codegenRequestFile: Path @@ -92,7 +92,7 @@ class PipelineSpec { private lateinit var request: CodeGeneratorRequest private lateinit var renderer: UnderscorePrefixRenderer private val sourceFileSet: SourceFileSet - get() = SourceFileSet.create(marker, srcRoot, targetRoot) + get() = SourceFileSet.create(label, srcRoot, targetRoot) @BeforeEach fun prepareSources(@TempDir sandbox: Path) { @@ -249,12 +249,12 @@ class PipelineSpec { write(jsPath, "alert('Hello')") write(ktPath, "println(\"Hello\")") val jsSet = SourceFileSet.create( - SourceFileSetMarker(JavaScript), + SourceFileSetLabel(JavaScript), srcRoot / js, targetRoot / js ) val ktSet = SourceFileSet.create( - SourceFileSetMarker(Kotlin), + SourceFileSetLabel(Kotlin), srcRoot / kt, targetRoot / kt ) @@ -312,7 +312,7 @@ class PipelineSpec { Pipeline( plugin = TestPlugin(), renderer = InternalAccessRenderer(), - sources = SourceFileSet.create(marker, srcRoot, destination), + sources = SourceFileSet.create(label, srcRoot, destination), request )() @@ -355,8 +355,8 @@ class PipelineSpec { TestPlugin(), NoOpRenderer(), listOf( - SourceFileSet.create(marker, srcRoot, destination1), - SourceFileSet.create(marker, source2, destination2) + SourceFileSet.create(label, srcRoot, destination1), + SourceFileSet.create(label, source2, destination2) ), request )() @@ -384,8 +384,8 @@ class PipelineSpec { plugin = TestPlugin(), renderer = PlainStringRenderer(), listOf( - SourceFileSet.create(marker, srcRoot, destination1), - SourceFileSet.create(marker, source2, destination2) + SourceFileSet.create(label, srcRoot, destination1), + SourceFileSet.create(label, source2, destination2) ), request, Configuration.rawValue(expectedContent, ConfigurationFormat.PLAIN) @@ -417,8 +417,8 @@ class PipelineSpec { PrependingRenderer() ), sources = listOf( - SourceFileSet.create(marker, srcRoot, destination1), - SourceFileSet.create(marker, source2, destination2) + SourceFileSet.create(label, srcRoot, destination1), + SourceFileSet.create(label, source2, destination2) ), request )() From 1c32f458789061230b185f639a29ad7a1ac1aca9 Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Wed, 20 Sep 2023 13:27:49 +0300 Subject: [PATCH 15/30] More doc --- .../protodata/cli/CommandLineInterface.kt | 94 ++++++++++--------- .../io/spine/protodata/cli/KnownLanguages.kt | 45 +++++++++ .../app/{KnownLanguages.kt => Languages.kt} | 27 ++---- license-report.md | 18 ++-- 4 files changed, 112 insertions(+), 72 deletions(-) create mode 100644 cli-api/src/main/kotlin/io/spine/protodata/cli/KnownLanguages.kt rename cli/src/main/kotlin/io/spine/protodata/cli/app/{KnownLanguages.kt => Languages.kt} (84%) diff --git a/cli-api/src/main/kotlin/io/spine/protodata/cli/CommandLineInterface.kt b/cli-api/src/main/kotlin/io/spine/protodata/cli/CommandLineInterface.kt index a9528d68b..2ba4c9a29 100644 --- a/cli-api/src/main/kotlin/io/spine/protodata/cli/CommandLineInterface.kt +++ b/cli-api/src/main/kotlin/io/spine/protodata/cli/CommandLineInterface.kt @@ -35,6 +35,7 @@ import io.spine.protodata.config.ConfigurationFormat.PROTO_JSON import io.spine.protodata.config.ConfigurationFormat.YAML import io.spine.protodata.plugin.Plugin import io.spine.protodata.renderer.Renderer +import io.spine.tools.code.Language import java.io.File.pathSeparator /** @@ -77,57 +78,59 @@ public object RequestParam : Parameter( ) /** - * The command-line parameter for specifying the path to the directory with - * source files to be processed. - */ -public object SourceRootParam : Parameter( - name = "--source-root", - shortName = "--src", - help = """ - The path to a directory which contains the source files to be processed. - Skip this argument if there is no initial source to modify. - - Multiple directories can be listed separated by the system-dependent path separator (`$ps`). - In such a case, the number of directories must match the number of ${ddash.tr} - directories; source and target directories are paired up according to the order - they are provided in, so that the files from first source are written to - the first target and so on. - - When specifying multiple directories, some of them are allowed to be non-existent. - They will just be ignored along with their paired targets. But at least one directory - must exist. Otherwise, the process will end up with an error. - """ -) - -/** - * The command-line parameter for specifying the path to the directory where - * to put the processed files. - */ -public object TargetRootParam : Parameter( - name = "--target-root", - shortName = "--target", - help = """ - The path where the processed files should be placed. - May be the same as `${SourceRootParam.name}`. For editing files in-place, skip this option. - - Multiple directories can be listed separated by the system-dependent path separator (`$ps`). - In such a case, the number of directories must match the number of `${dash.src}` directories. - Source and target directories are paired up according to the order they are provided in, - so that the files from first source are written to the first target and so on. - """ -) - - -/** - * The source and target paths. + * The command-line parameter for specifying the source and target paths. */ public object PathsParam : Parameter( name = "--paths", shortName = "-P", help = """ + Paths specifying where the files for processing are located and where to put them after + processing. + + The value should consist of three parts, separated by the path separator character (`$ps`): + 1. The language that the files use and the name of the code generator that created + the files. The language should be a fully qualified name of + a `${Language::class.qualifiedName}` subclass that represents the language. + Alternatively, the language can be one of the preset values: + ${knownLanguages.keys.joinToString()}. + The code generator name is a plain string that identifies the name of the software + component, a `protoc` plugin or a separate program, that generated these code files. + The code generator name should go after the language in parentheses with no + white space. When using the default Protobuf code generation, the code generator name + may be omitted. + 2. The source path. Must be an absolute path where the code files are located. If there + are no code files, i.e. ProtoData should generate all the code from scratch, this part + may be left blank. + 2. The target path. Must be an absolute path where the code files should be placed after + processing. This path must either lead to an empty directory, or not lead to any + existing FS object. + + For specifying several source sets, supply this param multiple times. + Example 1. + `<...> ${ddash.path} java(grpc):/Users/me/foo/temp/generated/main/grpc:/Users/me/foo/gen/main/grpc` + This example provides a source set for Java gRPC stubs placed under + `./temp/generated/main/grpc`. After ProtoData finishes processing the files, it should + place them under `./gen/main/grpc`. + + Example 2. + `<...> ${ddash.path} org.example.Fortran(4gen):/a/b/c:a/b/d \ + ${ddash.path} org.example.Cobol(cobolmine):/x/y:/x/w` + In this example we supply two source sets with different languages to be processed in + the same run. + + Example 3. + `<...> ${ddash.path} kotlin;D:\Foo\Bar;D:\Foo\Baz` + In this example we supply the Kotlin source set generated by the default. Note the + absence of the code generator name after the language name. + + Example 4. + `<...> ${ddash.path} javascript(myself)::/a/b/c` + In this example we supply a JS source set that does not provide any existing files. + Here, it is expected that ProtoData will generate all the files into the target + directory `/a/b/c` from scratch. """ -) // TODO add help msg and doc. +) /** * The command-line parameter for composing the user-defined classpath. @@ -221,7 +224,6 @@ public object DebugLoggingParam : Parameter( private object dash { val p = lazy { PluginParam.shortName } val r = lazy { RendererParam.shortName } - val src = lazy { SourceRootParam.shortName } } /** @@ -229,10 +231,10 @@ private object dash { */ @Suppress("ClassName", "SpellCheckingInspection") // for better readability in `help` texts. private object ddash { - val tr = lazy { TargetRootParam.name } val confVal = lazy { ConfigValueParam.name } val confFmt = lazy { ConfigFormatParam.name } val renderer = lazy { RendererParam.name } + val path = lazy { PathsParam.name } } /** diff --git a/cli-api/src/main/kotlin/io/spine/protodata/cli/KnownLanguages.kt b/cli-api/src/main/kotlin/io/spine/protodata/cli/KnownLanguages.kt new file mode 100644 index 000000000..df2149250 --- /dev/null +++ b/cli-api/src/main/kotlin/io/spine/protodata/cli/KnownLanguages.kt @@ -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. + */ + +package io.spine.protodata.cli + +import io.spine.annotation.Internal +import io.spine.tools.code.AnyLanguage +import io.spine.tools.code.Java +import io.spine.tools.code.JavaScript +import io.spine.tools.code.Kotlin +import io.spine.tools.code.Language + +/** + * The well-known languages processed by ProtoData. + */ +@Internal +public val knownLanguages: Map = setOf( + Java, + Kotlin, + JavaScript, + AnyLanguage +).associateBy { it.name.lowercase() } diff --git a/cli/src/main/kotlin/io/spine/protodata/cli/app/KnownLanguages.kt b/cli/src/main/kotlin/io/spine/protodata/cli/app/Languages.kt similarity index 84% rename from cli/src/main/kotlin/io/spine/protodata/cli/app/KnownLanguages.kt rename to cli/src/main/kotlin/io/spine/protodata/cli/app/Languages.kt index e4e1b02c8..2326c7ce5 100644 --- a/cli/src/main/kotlin/io/spine/protodata/cli/app/KnownLanguages.kt +++ b/cli/src/main/kotlin/io/spine/protodata/cli/app/Languages.kt @@ -26,22 +26,20 @@ package io.spine.protodata.cli.app -import io.spine.tools.code.AnyLanguage -import io.spine.tools.code.Java -import io.spine.tools.code.JavaScript -import io.spine.tools.code.Kotlin +import io.spine.protodata.cli.knownLanguages import io.spine.tools.code.Language import kotlin.reflect.KClass import kotlin.reflect.full.isSubclassOf import kotlin.reflect.jvm.isAccessible -private val knownLanguages: Map = setOf( - Java, - Kotlin, - JavaScript, - AnyLanguage -).associateBy { it.name.lowercase() } - +/** + * Parses a [Language] from this string. + * + * If the string represents a [well-known language name][knownLanguages], uses that language. + * Otherwise, attempts to use this string as a class name and load an instance of that class. + * If the class represents a Kotlin `object`, loads the instance of the object. Otherwise, calls + * the no-argument constructor. + */ internal fun String.toLanguage(): Language { require(this.isNotBlank()) { "Expected a language name of class, but got `$this`." } return toKnownLanguage() ?: loadLanguage() @@ -49,17 +47,12 @@ internal fun String.toLanguage(): Language { private fun String.toKnownLanguage(): Language? { val key = lowercase() - return if (key in knownLanguages) { - knownLanguages.getValue(key) - } else { - null - } + return knownLanguages[key] } private fun String.loadLanguage(): Language { val cls = languageClass() return cls.objectInstance ?: cls.instantiate() - } private fun String.languageClass(): KClass { diff --git a/license-report.md b/license-report.md index 2d07b2a1c..84fa5d935 100644 --- a/license-report.md +++ b/license-report.md @@ -925,7 +925,7 @@ The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Sep 19 21:14:13 EEST 2023** 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 **Wed Sep 20 12:32:49 EEST 2023** 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). @@ -1871,7 +1871,7 @@ This report was generated on **Tue Sep 19 21:14:13 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Sep 19 21:14:16 EEST 2023** 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 **Wed Sep 20 12:32:53 EEST 2023** 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). @@ -2789,7 +2789,7 @@ This report was generated on **Tue Sep 19 21:14:16 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Sep 19 21:14:19 EEST 2023** 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 **Wed Sep 20 12:32:55 EEST 2023** 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). @@ -3718,7 +3718,7 @@ This report was generated on **Tue Sep 19 21:14:19 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Sep 19 21:14:22 EEST 2023** 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 **Wed Sep 20 12:32:58 EEST 2023** 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). @@ -4647,7 +4647,7 @@ This report was generated on **Tue Sep 19 21:14:22 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Sep 19 21:14:24 EEST 2023** 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 **Wed Sep 20 12:33:00 EEST 2023** 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). @@ -5457,7 +5457,7 @@ This report was generated on **Tue Sep 19 21:14:24 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Sep 19 21:14:27 EEST 2023** 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 **Wed Sep 20 12:33:02 EEST 2023** 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). @@ -6550,7 +6550,7 @@ This report was generated on **Tue Sep 19 21:14:27 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Sep 19 21:14:29 EEST 2023** 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 **Wed Sep 20 12:33:05 EEST 2023** 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). @@ -7319,7 +7319,7 @@ This report was generated on **Tue Sep 19 21:14:29 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Sep 19 21:14:31 EEST 2023** 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 **Wed Sep 20 12:33:07 EEST 2023** 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). @@ -8255,4 +8255,4 @@ This report was generated on **Tue Sep 19 21:14:31 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Sep 19 21:14:34 EEST 2023** 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 **Wed Sep 20 12:33:09 EEST 2023** 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 From 454ca484e9b52f7a413a9e757685ed0714e0191f Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Wed, 20 Sep 2023 13:42:12 +0300 Subject: [PATCH 16/30] More doc and stricter deprecation --- .../spine/protodata/gradle/plugin/Extension.kt | 16 +++++++++++++++- .../protodata/gradle/plugin/SourcePaths.kt | 18 ++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt index 01a5bd921..dc76f0145 100644 --- a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt +++ b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt @@ -37,6 +37,7 @@ import io.spine.tools.code.Java import io.spine.tools.code.Kotlin import io.spine.tools.fs.DirectoryName.generated import io.spine.tools.gradle.protobuf.generatedSourceProtoDir +import kotlin.DeprecationLevel.ERROR import kotlin.io.path.name import org.gradle.api.Project import org.gradle.api.file.Directory @@ -83,8 +84,21 @@ public class Extension(internal val project: Project): CodegenSettings { internal fun requestFile(forSourceSet: SourceSet): Provider = requestFilesDirProperty.file(CodeGeneratorRequestFile.name(forSourceSet)) + /** + * [SourcePaths] to run ProtoData on. + * + * The keys to the multimap are the scopes, i.e. Gradle's source set names, + * such as `main` and `test`. + */ public val paths: Multimap = HashMultimap.create() + /** + * Obtains the source configured paths. + * + * If the deprecated [subDirs] and [targetBaseDir] are used, constructs [SourcePaths] instances + * from the present data for backward compatibility. However, in this compatibility mode, + * only Java and Kotlin source file sets can be constructed. + */ internal fun pathsOrCompat(sourceSet: SourceSet): Set { if (!paths.isEmpty) { return paths[sourceSet.name].toSet() @@ -159,7 +173,7 @@ public class Extension(internal val project: Project): CodegenSettings { private val subDirProperty: ListProperty = factory.listProperty().convention(defaultSubdirectories) - @Deprecated("Use `paths` instead.") + @Deprecated("Use `paths` instead.", level = ERROR) public override var targetBaseDir: Any get() = targetBaseDirProperty.get() set(value) = targetBaseDirProperty.set(project.file(value)) diff --git a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/SourcePaths.kt b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/SourcePaths.kt index 795b02eb1..e044bdf50 100644 --- a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/SourcePaths.kt +++ b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/SourcePaths.kt @@ -32,13 +32,22 @@ import io.spine.tools.code.Language import java.io.File import org.gradle.api.Named +/** + * The paths to source and target dirs that constitute a single source file set. + * + * This is a part of the Gradle plugin's DSL for configuring ProtoData. Additional `SourcePaths` + * instances may be created for ProtoData to pick up. + */ public data class SourcePaths( public var source: String? = null, public var target: String? = null, public var language: String? = null, public var generatorName: String = DefaultGenerator.name -) : Named { +) { + /** + * Creates new `SourcePaths` from the given directories, language and generator name. + */ public constructor( source: File, target: File, @@ -51,12 +60,13 @@ public data class SourcePaths( generator.name ) + /** + * Ensures that all the necessary properties are present. + */ internal fun checkAllSet() { require(!target.isNullOrBlank()) { missingMessage("target path") } require(!language.isNullOrBlank()) { missingMessage("language") } } - override fun getName(): String = generatorName - - private fun missingMessage(propName: String) = "Source file set `$name` requires the $propName." + private fun missingMessage(propName: String) = "Source file set requires the $propName." } From 6d69dbc6b6fa888e5b63fd221c4ba9151f4565c7 Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Wed, 20 Sep 2023 13:45:18 +0300 Subject: [PATCH 17/30] Yet more doc --- test-env/src/main/kotlin/io/spine/protodata/test/NoOpPlugin.kt | 3 +++ .../kotlin/io/spine/protodata/test/UnderscorePrefixPlugin.kt | 3 +++ 2 files changed, 6 insertions(+) diff --git a/test-env/src/main/kotlin/io/spine/protodata/test/NoOpPlugin.kt b/test-env/src/main/kotlin/io/spine/protodata/test/NoOpPlugin.kt index 6ba75f322..6ae7dc306 100644 --- a/test-env/src/main/kotlin/io/spine/protodata/test/NoOpPlugin.kt +++ b/test-env/src/main/kotlin/io/spine/protodata/test/NoOpPlugin.kt @@ -28,6 +28,9 @@ package io.spine.protodata.test import io.spine.protodata.plugin.AbstractPlugin +/** + * A plugin with the [NoOpRenderer]. + */ public class NoOpPlugin : AbstractPlugin( renderers = listOf(NoOpRenderer()) ) diff --git a/test-env/src/main/kotlin/io/spine/protodata/test/UnderscorePrefixPlugin.kt b/test-env/src/main/kotlin/io/spine/protodata/test/UnderscorePrefixPlugin.kt index 53843237f..e757bd74c 100644 --- a/test-env/src/main/kotlin/io/spine/protodata/test/UnderscorePrefixPlugin.kt +++ b/test-env/src/main/kotlin/io/spine/protodata/test/UnderscorePrefixPlugin.kt @@ -28,6 +28,9 @@ package io.spine.protodata.test import io.spine.protodata.plugin.AbstractPlugin +/** + * A plugin with the [UnderscorePrefixRenderer]. + */ public class UnderscorePrefixPlugin : AbstractPlugin( renderers = listOf(UnderscorePrefixRenderer()) ) From 5ddd630a06e6e40d9f1844eb1303047c1974e9f4 Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Wed, 20 Sep 2023 13:49:02 +0300 Subject: [PATCH 18/30] More doc for test env --- .../main/kotlin/io/spine/protodata/test/PathParams.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test-env/src/main/kotlin/io/spine/protodata/test/PathParams.kt b/test-env/src/main/kotlin/io/spine/protodata/test/PathParams.kt index e711885fc..126c37704 100644 --- a/test-env/src/main/kotlin/io/spine/protodata/test/PathParams.kt +++ b/test-env/src/main/kotlin/io/spine/protodata/test/PathParams.kt @@ -28,11 +28,18 @@ package io.spine.protodata.test import java.io.File - +/** + * Constructs a `--path` CLI param with the given parts. + * + * See the CLI help message for the format details. + */ public fun paths(label: String, src: Any, target: Any): String { val ps = File.pathSeparator return label + ps + src + ps + target } +/** + * Constructs a `--path` CLI param with the Java language and the given source and target paths. + */ public fun pathsForJava(src: Any, target: Any): String = paths("java", src, target) From 2793061713480943f73615c5e4d9f82a8c219295 Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Wed, 20 Sep 2023 13:50:06 +0300 Subject: [PATCH 19/30] Remove debug output --- .../java/io/spine/protodata/test/uuid/UuidJavaRenderer.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/protodata-extension/src/main/java/io/spine/protodata/test/uuid/UuidJavaRenderer.java b/tests/protodata-extension/src/main/java/io/spine/protodata/test/uuid/UuidJavaRenderer.java index fca4648ef..f226c6571 100644 --- a/tests/protodata-extension/src/main/java/io/spine/protodata/test/uuid/UuidJavaRenderer.java +++ b/tests/protodata-extension/src/main/java/io/spine/protodata/test/uuid/UuidJavaRenderer.java @@ -70,13 +70,8 @@ public final class UuidJavaRenderer extends JavaRenderer { */ @Override protected void render(SourceFileSet sources) { - System.err.println("000000000000000"); - System.err.println("UuidJavaRenderer"); - System.err.println("000000000000000"); Set uuidTypes = select(UuidType.class).all(); for (UuidType type : uuidTypes) { - System.err.println(type.getName().getSimpleName()); - System.err.println("--=----=-==-=-=-=-=-=-==-==-=-=-==-"); TypeName typeName = type.getName(); FilePath file = type.getDeclaredIn(); ClassName className = classNameOf(typeName, file); From dffa31e80deadd2567a84757aedb62b99425c0d0 Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Wed, 20 Sep 2023 17:52:36 +0300 Subject: [PATCH 20/30] Remove redundant checks, add logging and another test --- .../io/spine/protodata/renderer/SourceFile.kt | 20 ++---- .../spine/protodata/renderer/SourceFileSet.kt | 12 ++-- .../kotlin/io/spine/protodata/cli/app/Main.kt | 12 +++- .../spine/protodata/gradle/CodegenSettings.kt | 22 ++++++ .../io/spine/protodata/gradle}/SourcePaths.kt | 15 ++-- .../protodata/gradle/plugin/PluginSpec.kt | 14 ++++ .../resources/custom-paths/build.gradle.kts | 69 +++++++++++++++++++ .../custom-paths/settings.gradle.kts | 31 +++++++++ .../custom-paths/src/main/proto/test.proto | 12 ++++ .../protodata/gradle/plugin/Extension.kt | 15 ++-- .../gradle/plugin/LaunchProtoData.kt | 3 +- license-report.md | 18 ++--- 12 files changed, 192 insertions(+), 51 deletions(-) rename {gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin => gradle-api/src/main/kotlin/io/spine/protodata/gradle}/SourcePaths.kt (87%) create mode 100644 gradle-plugin/src/functionalTest/resources/custom-paths/build.gradle.kts create mode 100644 gradle-plugin/src/functionalTest/resources/custom-paths/settings.gradle.kts create mode 100644 gradle-plugin/src/functionalTest/resources/custom-paths/src/main/proto/test.proto diff --git a/api/src/main/kotlin/io/spine/protodata/renderer/SourceFile.kt b/api/src/main/kotlin/io/spine/protodata/renderer/SourceFile.kt index fb006a32c..e9d86ee0a 100644 --- a/api/src/main/kotlin/io/spine/protodata/renderer/SourceFile.kt +++ b/api/src/main/kotlin/io/spine/protodata/renderer/SourceFile.kt @@ -69,9 +69,7 @@ private constructor( /** * The FS path to the file relative to the source root. */ - public val relativePath: Path, - - private var changed: Boolean = false + public val relativePath: Path ) { private lateinit var sources: SourceFileSet @@ -109,7 +107,7 @@ private constructor( * the source code. */ internal fun fromCode(relativePath: Path, code: String): SourceFile = - SourceFile(code, relativePath, changed = true) + SourceFile(code, relativePath) } /** @@ -178,7 +176,6 @@ private constructor( */ public fun overwrite(newCode: String) { this.code = newCode - this.changed = true } /** @@ -215,15 +212,12 @@ private constructor( internal fun write( baseDir: Path, charset: Charset = Charsets.UTF_8, - forceWrite: Boolean = false ) { - if (changed || forceWrite) { - val targetPath = baseDir / relativePath - targetPath.toFile() - .parentFile - .mkdirs() - targetPath.writeText(code, charset, WRITE, TRUNCATE_EXISTING, CREATE) - } + val targetPath = baseDir / relativePath + targetPath.toFile() + .parentFile + .mkdirs() + targetPath.writeText(code, charset, WRITE, TRUNCATE_EXISTING, CREATE) } /** diff --git a/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSet.kt b/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSet.kt index 18cf4668b..3e9b4a490 100644 --- a/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSet.kt +++ b/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSet.kt @@ -81,7 +81,7 @@ internal constructor( * @see outputRoot */ @get:JvmName("inputRoot") - public val inputRoot: Path, + public val inputRoot: Path?, /** * A directory where the source set should be placed after code generation. @@ -99,8 +99,9 @@ internal constructor( internal lateinit var querying: Querying init { - require(inputRoot.absolutePathString() != outputRoot.absolutePathString()) { - "Input and output roots cannot be the same, but was '${inputRoot.absolutePathString()}'" + require(inputRoot?.absolutePathString() != outputRoot.absolutePathString()) { + "Input and output roots cannot be the same, " + + "but was '${inputRoot!!.absolutePathString()}'" } val map = HashMap(files.size) this.files = files.associateByTo(map) { it.relativePath } @@ -144,7 +145,7 @@ internal constructor( public fun empty(label: SourceFileSetLabel, target: Path): SourceFileSet { checkTarget(target) val files = setOf() - return SourceFileSet(label, files, target, target) + return SourceFileSet(label, files, null, target) } } @@ -245,9 +246,8 @@ internal constructor( it.rm(rootDir = outputRoot) } outputRoot.toFile().mkdirs() - val forceWriteFiles = inputRoot != outputRoot files.values.forEach { - it.write(outputRoot, charset, forceWriteFiles) + it.write(outputRoot, charset) } } diff --git a/cli/src/main/kotlin/io/spine/protodata/cli/app/Main.kt b/cli/src/main/kotlin/io/spine/protodata/cli/app/Main.kt index db4bcdc3b..3c1e5b92e 100644 --- a/cli/src/main/kotlin/io/spine/protodata/cli/app/Main.kt +++ b/cli/src/main/kotlin/io/spine/protodata/cli/app/Main.kt @@ -230,20 +230,26 @@ internal class Run(version: String) : CliktCommand( } private fun createSourceFileSets(): List { - val pathPairs = paths.map { pathSplitter.splitToList(it) } - val existingPaths = pathPairs.filter { + val rawPaths = paths.map { pathSplitter.splitToList(it) } + val existingPaths = rawPaths.filter { val srcPath = it[1] srcPath.isNotBlank() && Path(srcPath).exists() }.toList() if (existingPaths.isEmpty()) { + logger.atInfo().log { + "No existing source paths supplied." + } require(paths.size == 1) { "Expected exactly one target path, but was ${paths}." } - val (rawLabel, _, rawTarget) = pathPairs.first() + val (rawLabel, _, rawTarget) = rawPaths.first() val label = loadLabel(rawLabel) val targetPath = Path(rawTarget) return listOf(SourceFileSet.empty(label, targetPath)) } return existingPaths.map { val (rawLabel, rawSrc, rawTarget) = it + logger.atInfo().log { + "Source file set: label: `$rawLabel`; source: `$rawSrc`; target: `$rawTarget`." + } val sourceLabel = loadLabel(rawLabel) val srcPath = Path(rawSrc) val targetPath = Path(rawTarget) diff --git a/gradle-api/src/main/kotlin/io/spine/protodata/gradle/CodegenSettings.kt b/gradle-api/src/main/kotlin/io/spine/protodata/gradle/CodegenSettings.kt index 34f822609..dafb319b8 100644 --- a/gradle-api/src/main/kotlin/io/spine/protodata/gradle/CodegenSettings.kt +++ b/gradle-api/src/main/kotlin/io/spine/protodata/gradle/CodegenSettings.kt @@ -26,6 +26,8 @@ package io.spine.protodata.gradle +import com.google.common.collect.Multimap + /** * Configures code generation process performed by ProtoData. */ @@ -68,4 +70,24 @@ public interface CodegenSettings { * By default, points at the `$projectDir/generated/` directory. */ public var targetBaseDir: Any + + /** + * `SourcePaths` to run ProtoData on. + * + * The keys to the multimap are the scopes, i.e. Gradle's source set names, + * such as `main` and `test`. + * + */ + public val paths: Multimap + + /** + * Creates a new [SourcePaths] for the given scope. + * + * @see paths + */ + public fun pathsFor(scope: String, configAction: SourcePaths.() -> Unit) { + val p = SourcePaths() + configAction(p) + paths.put(scope, p) + } } diff --git a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/SourcePaths.kt b/gradle-api/src/main/kotlin/io/spine/protodata/gradle/SourcePaths.kt similarity index 87% rename from gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/SourcePaths.kt rename to gradle-api/src/main/kotlin/io/spine/protodata/gradle/SourcePaths.kt index e044bdf50..5c721ea84 100644 --- a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/SourcePaths.kt +++ b/gradle-api/src/main/kotlin/io/spine/protodata/gradle/SourcePaths.kt @@ -24,13 +24,11 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package io.spine.protodata.gradle.plugin +package io.spine.protodata.gradle -import io.spine.protodata.renderer.DefaultGenerator -import io.spine.protodata.renderer.SourceGeneratorName +import io.spine.annotation.Internal import io.spine.tools.code.Language import java.io.File -import org.gradle.api.Named /** * The paths to source and target dirs that constitute a single source file set. @@ -42,7 +40,7 @@ public data class SourcePaths( public var source: String? = null, public var target: String? = null, public var language: String? = null, - public var generatorName: String = DefaultGenerator.name + public var generatorName: String = "" ) { /** @@ -52,18 +50,19 @@ public data class SourcePaths( source: File, target: File, language: Language, - generator: SourceGeneratorName + generator: String ) : this( source.absolutePath, target.absolutePath, language::class.qualifiedName, - generator.name + generator ) /** * Ensures that all the necessary properties are present. */ - internal fun checkAllSet() { + @Internal + public fun checkAllSet() { require(!target.isNullOrBlank()) { missingMessage("target path") } require(!language.isNullOrBlank()) { missingMessage("language") } } diff --git a/gradle-plugin/src/functionalTest/kotlin/io/spine/protodata/gradle/plugin/PluginSpec.kt b/gradle-plugin/src/functionalTest/kotlin/io/spine/protodata/gradle/plugin/PluginSpec.kt index ec5d8b872..44a5cd588 100644 --- a/gradle-plugin/src/functionalTest/kotlin/io/spine/protodata/gradle/plugin/PluginSpec.kt +++ b/gradle-plugin/src/functionalTest/kotlin/io/spine/protodata/gradle/plugin/PluginSpec.kt @@ -26,6 +26,7 @@ package io.spine.protodata.gradle.plugin +import io.kotest.assertions.withClue import io.kotest.matchers.shouldBe import io.spine.protodata.gradle.Names.GRADLE_PLUGIN_ID import io.spine.testing.SlowTest @@ -163,6 +164,19 @@ class PluginSpec { assertExists(generatedGrpcDir.resolve(serviceClass)) } + @Test + fun `launch with custom paths`() { + createProject("custom-paths") + launchAndExpectResult(SUCCESS) + + val files = projectDir.walk().filter { + !it.path.contains("buildSrc") && !it.path.contains(".gradle") + }.toList() + withClue(files) { + projectDir.resolve("build/foomain/io/spine/protodata/test/Test.java").exists() shouldBe true + } + } + private fun createEmptyProject() { createProject("empty-test") } diff --git a/gradle-plugin/src/functionalTest/resources/custom-paths/build.gradle.kts b/gradle-plugin/src/functionalTest/resources/custom-paths/build.gradle.kts new file mode 100644 index 000000000..77e60b1e0 --- /dev/null +++ b/gradle-plugin/src/functionalTest/resources/custom-paths/build.gradle.kts @@ -0,0 +1,69 @@ +/* + * Copyright 2022, TeamDev. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Redistribution and use in source and/or binary forms, with or without + * modification, must retain the above copyright notice and the following + * disclaimer. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import com.google.protobuf.gradle.protobuf +import io.spine.internal.gradle.standardToSpineSdk + +buildscript { + standardSpineSdkRepositories() +} + +plugins { + java + id("com.google.protobuf") + id("@PROTODATA_PLUGIN_ID@") version "@PROTODATA_VERSION@" +} + +repositories { + mavenLocal() // Must come first for `protodata-test-env`. + standardToSpineSdk() +} + +dependencies { + protoData("io.spine.protodata:protodata-test-env:+") +} + +protobuf { + protoc { + artifact = io.spine.internal.dependency.Protobuf.compiler + } +} + +protoData { + plugins("io.spine.protodata.test.TestPlugin", "io.spine.protodata.test.UnderscorePrefixPlugin") + + pathsFor("main") { + source = "$buildDir/generated/source/proto/main/java" + target = "$buildDir/foomain" + language = "java" + } + + pathsFor("test") { + source = "$buildDir/generated-proto/test/kotlin" + target = "$buildDir/footest" + language = "java" + } +} diff --git a/gradle-plugin/src/functionalTest/resources/custom-paths/settings.gradle.kts b/gradle-plugin/src/functionalTest/resources/custom-paths/settings.gradle.kts new file mode 100644 index 000000000..f5ecc1b72 --- /dev/null +++ b/gradle-plugin/src/functionalTest/resources/custom-paths/settings.gradle.kts @@ -0,0 +1,31 @@ +/* + * Copyright 2022, TeamDev. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Redistribution and use in source and/or binary forms, with or without + * modification, must retain the above copyright notice and the following + * disclaimer. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +pluginManagement { + repositories { + mavenLocal() + } +} diff --git a/gradle-plugin/src/functionalTest/resources/custom-paths/src/main/proto/test.proto b/gradle-plugin/src/functionalTest/resources/custom-paths/src/main/proto/test.proto new file mode 100644 index 000000000..6a60feb41 --- /dev/null +++ b/gradle-plugin/src/functionalTest/resources/custom-paths/src/main/proto/test.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; + +package spine.protodata.test; + +option java_package = "io.spine.protodata.test"; +option java_outer_classname = "TestProto"; +option java_multiple_files = true; + +// We need there to be at least some definitions. We don't care which ones for this test. + +message Test { +} diff --git a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt index dc76f0145..4cc4587b3 100644 --- a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt +++ b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt @@ -31,8 +31,7 @@ import com.google.common.collect.Multimap import io.spine.protodata.gradle.CodeGeneratorRequestFile import io.spine.protodata.gradle.CodeGeneratorRequestFile.DEFAULT_DIRECTORY import io.spine.protodata.gradle.CodegenSettings -import io.spine.protodata.renderer.CustomGenerator -import io.spine.protodata.renderer.DefaultGenerator +import io.spine.protodata.gradle.SourcePaths import io.spine.tools.code.Java import io.spine.tools.code.Kotlin import io.spine.tools.fs.DirectoryName.generated @@ -84,13 +83,7 @@ public class Extension(internal val project: Project): CodegenSettings { internal fun requestFile(forSourceSet: SourceSet): Provider = requestFilesDirProperty.file(CodeGeneratorRequestFile.name(forSourceSet)) - /** - * [SourcePaths] to run ProtoData on. - * - * The keys to the multimap are the scopes, i.e. Gradle's source set names, - * such as `main` and `test`. - */ - public val paths: Multimap = HashMultimap.create() + override val paths: Multimap = HashMultimap.create() /** * Obtains the source configured paths. @@ -110,9 +103,9 @@ public class Extension(internal val project: Project): CodegenSettings { val pathSuffix = src.asFile.toPath().name val lang = if (pathSuffix == "kotlin") Kotlin else Java val generatorName = if (pathSuffix.equals(lang.name, ignoreCase = true)) { - DefaultGenerator + "" } else { - CustomGenerator(pathSuffix) + pathSuffix } SourcePaths( src.asFile, diff --git a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/LaunchProtoData.kt b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/LaunchProtoData.kt index f95722dd8..622fa27d7 100644 --- a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/LaunchProtoData.kt +++ b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/LaunchProtoData.kt @@ -32,6 +32,7 @@ import io.spine.protodata.cli.PathsParam import io.spine.protodata.cli.PluginParam import io.spine.protodata.cli.RequestParam import io.spine.protodata.cli.UserClasspathParam +import io.spine.protodata.gradle.SourcePaths import io.spine.protodata.renderer.DefaultGenerator import io.spine.tools.gradle.protobuf.containsProtoFiles import java.io.File @@ -176,7 +177,7 @@ public abstract class LaunchProtoData : JavaExec() { private fun SourcePaths.toCliParam(): String { checkAllSet() - val label = if (generatorName != DefaultGenerator.name) { + val label = if (generatorName != DefaultGenerator.name && generatorName.isNotBlank()) { "$language($generatorName)" } else { language diff --git a/license-report.md b/license-report.md index 84fa5d935..6fca4def5 100644 --- a/license-report.md +++ b/license-report.md @@ -925,7 +925,7 @@ The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 20 12:32:49 EEST 2023** 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 **Wed Sep 20 16:27:33 EEST 2023** 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). @@ -1871,7 +1871,7 @@ This report was generated on **Wed Sep 20 12:32:49 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 20 12:32:53 EEST 2023** 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 **Wed Sep 20 16:27:35 EEST 2023** 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). @@ -2789,7 +2789,7 @@ This report was generated on **Wed Sep 20 12:32:53 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 20 12:32:55 EEST 2023** 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 **Wed Sep 20 16:27:37 EEST 2023** 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). @@ -3718,7 +3718,7 @@ This report was generated on **Wed Sep 20 12:32:55 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 20 12:32:58 EEST 2023** 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 **Wed Sep 20 16:27:39 EEST 2023** 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). @@ -4647,7 +4647,7 @@ This report was generated on **Wed Sep 20 12:32:58 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 20 12:33:00 EEST 2023** 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 **Wed Sep 20 16:27:40 EEST 2023** 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). @@ -5457,7 +5457,7 @@ This report was generated on **Wed Sep 20 12:33:00 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 20 12:33:02 EEST 2023** 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 **Wed Sep 20 16:27:42 EEST 2023** 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). @@ -6550,7 +6550,7 @@ This report was generated on **Wed Sep 20 12:33:02 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 20 12:33:05 EEST 2023** 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 **Wed Sep 20 16:27:43 EEST 2023** 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). @@ -7319,7 +7319,7 @@ This report was generated on **Wed Sep 20 12:33:05 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 20 12:33:07 EEST 2023** 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 **Wed Sep 20 16:27:44 EEST 2023** 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). @@ -8255,4 +8255,4 @@ This report was generated on **Wed Sep 20 12:33:07 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 20 12:33:09 EEST 2023** 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 **Wed Sep 20 16:27:46 EEST 2023** 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 From 8cf7162430f647a2d6926c7598c2ed64779372b7 Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Thu, 21 Sep 2023 17:10:57 +0300 Subject: [PATCH 21/30] Remove unwanted generated subdirs --- .../spine/protodata/gradle/plugin/Extension.kt | 4 +--- license-report.md | 18 +++++++++--------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt index 4cc4587b3..da7f89428 100644 --- a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt +++ b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt @@ -128,9 +128,7 @@ public class Extension(internal val project: Project): CodegenSettings { "kotlin", "grpc", "js", - "dart", - "spine", - "protodata" + "dart" ) } diff --git a/license-report.md b/license-report.md index 6fca4def5..693070c6b 100644 --- a/license-report.md +++ b/license-report.md @@ -925,7 +925,7 @@ The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 20 16:27:33 EEST 2023** 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 **Wed Sep 20 21:05:07 EEST 2023** 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). @@ -1871,7 +1871,7 @@ This report was generated on **Wed Sep 20 16:27:33 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 20 16:27:35 EEST 2023** 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 **Wed Sep 20 21:05:09 EEST 2023** 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). @@ -2789,7 +2789,7 @@ This report was generated on **Wed Sep 20 16:27:35 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 20 16:27:37 EEST 2023** 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 **Wed Sep 20 21:05:11 EEST 2023** 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). @@ -3718,7 +3718,7 @@ This report was generated on **Wed Sep 20 16:27:37 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 20 16:27:39 EEST 2023** 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 **Wed Sep 20 21:05:12 EEST 2023** 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). @@ -4647,7 +4647,7 @@ This report was generated on **Wed Sep 20 16:27:39 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 20 16:27:40 EEST 2023** 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 **Wed Sep 20 21:05:14 EEST 2023** 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). @@ -5457,7 +5457,7 @@ This report was generated on **Wed Sep 20 16:27:40 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 20 16:27:42 EEST 2023** 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 **Wed Sep 20 21:05:15 EEST 2023** 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). @@ -6550,7 +6550,7 @@ This report was generated on **Wed Sep 20 16:27:42 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 20 16:27:43 EEST 2023** 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 **Wed Sep 20 21:05:16 EEST 2023** 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). @@ -7319,7 +7319,7 @@ This report was generated on **Wed Sep 20 16:27:43 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 20 16:27:44 EEST 2023** 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 **Wed Sep 20 21:05:18 EEST 2023** 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). @@ -8255,4 +8255,4 @@ This report was generated on **Wed Sep 20 16:27:44 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 20 16:27:46 EEST 2023** 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 **Wed Sep 20 21:05:19 EEST 2023** 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 From 0742a7e71b4a34542865cf5c1d429b44ae9f4a4e Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Thu, 21 Sep 2023 17:11:26 +0300 Subject: [PATCH 22/30] Fix numbering --- .../main/kotlin/io/spine/protodata/cli/CommandLineInterface.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli-api/src/main/kotlin/io/spine/protodata/cli/CommandLineInterface.kt b/cli-api/src/main/kotlin/io/spine/protodata/cli/CommandLineInterface.kt index 2ba4c9a29..2b1a05c03 100644 --- a/cli-api/src/main/kotlin/io/spine/protodata/cli/CommandLineInterface.kt +++ b/cli-api/src/main/kotlin/io/spine/protodata/cli/CommandLineInterface.kt @@ -101,7 +101,7 @@ public object PathsParam : Parameter( 2. The source path. Must be an absolute path where the code files are located. If there are no code files, i.e. ProtoData should generate all the code from scratch, this part may be left blank. - 2. The target path. Must be an absolute path where the code files should be placed after + 3. The target path. Must be an absolute path where the code files should be placed after processing. This path must either lead to an empty directory, or not lead to any existing FS object. From 2370ae38dfbf8544523eb20c3c19f26186219924 Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Thu, 21 Sep 2023 17:26:08 +0300 Subject: [PATCH 23/30] Better doc --- .../io/spine/protodata/renderer/SourceFileSetLabel.kt | 8 ++++++-- .../io/spine/protodata/renderer/SourceGeneratorName.kt | 4 ++-- .../kotlin/io/spine/protodata/gradle/CodegenSettings.kt | 4 +--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSetLabel.kt b/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSetLabel.kt index e3ce1b487..b037849d4 100644 --- a/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSetLabel.kt +++ b/api/src/main/kotlin/io/spine/protodata/renderer/SourceFileSetLabel.kt @@ -31,8 +31,12 @@ import io.spine.tools.code.Language /** * A label for a source file set. * - * The label marks the programming language that the files use and the name of the generator that - * created the files. + * The label consists of the programming language that the files use and the name of the code + * generator that created the files. + * + * A label signifies the type of code structures found in the source files. This helps renderers + * that process those sources to know what to expect from the source file set before ever checking + * the contents of the files themselves. */ public data class SourceFileSetLabel( public val language: Language, diff --git a/api/src/main/kotlin/io/spine/protodata/renderer/SourceGeneratorName.kt b/api/src/main/kotlin/io/spine/protodata/renderer/SourceGeneratorName.kt index e46bb1b58..c7100b782 100644 --- a/api/src/main/kotlin/io/spine/protodata/renderer/SourceGeneratorName.kt +++ b/api/src/main/kotlin/io/spine/protodata/renderer/SourceGeneratorName.kt @@ -59,8 +59,8 @@ public object DefaultGenerator : SourceGeneratorName * * Conventionally, the name of the generator should coincide with the name of the directory where * the generated files are placed. Users should follow this convention where possible, yet diverge - * when necessary. For example, Java gRPC stubs should be labelled with the `grpc` name. However, - * files generated for Dart should be labelled with the name `dart`, not `lib`. + * when necessary. For example, Java gRPC stubs should be marked with the `grpc` name. However, + * files generated for Dart should be marked with the name `dart`, not `lib`. */ public class CustomGenerator( override val name: String diff --git a/gradle-api/src/main/kotlin/io/spine/protodata/gradle/CodegenSettings.kt b/gradle-api/src/main/kotlin/io/spine/protodata/gradle/CodegenSettings.kt index dafb319b8..b44050c43 100644 --- a/gradle-api/src/main/kotlin/io/spine/protodata/gradle/CodegenSettings.kt +++ b/gradle-api/src/main/kotlin/io/spine/protodata/gradle/CodegenSettings.kt @@ -74,9 +74,7 @@ public interface CodegenSettings { /** * `SourcePaths` to run ProtoData on. * - * The keys to the multimap are the scopes, i.e. Gradle's source set names, - * such as `main` and `test`. - * + * The keys to the multimap are the Gradle's source set names, such as `main` and `test`. */ public val paths: Multimap From 484e0d349cecef40501a14795e5ead1bff616867 Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Thu, 21 Sep 2023 17:42:42 +0300 Subject: [PATCH 24/30] More doc --- .../kotlin/io/spine/protodata/renderer/SourceGeneratorName.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/src/main/kotlin/io/spine/protodata/renderer/SourceGeneratorName.kt b/api/src/main/kotlin/io/spine/protodata/renderer/SourceGeneratorName.kt index c7100b782..06fab20ff 100644 --- a/api/src/main/kotlin/io/spine/protodata/renderer/SourceGeneratorName.kt +++ b/api/src/main/kotlin/io/spine/protodata/renderer/SourceGeneratorName.kt @@ -45,6 +45,8 @@ public sealed interface SourceGeneratorName { * classes and auxiliary types, such as classes `Foo`, `Foo.Builder`, `Foo.Parser`, * and the interface `FooOrBuilder`. * + * Most ProtoData plugins will likely work with code generated by the default generator. + * * Since the Protobuf compiler does not support all the existing programming languages, * the `DefaultGenerator` is only defined for those languages that are supported, such as Java, JS, * C++, etc. For other languages, as well as for other code generation scenarios, From 8747165b9f44f3862562ca4afeabe0467df00fe7 Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Thu, 21 Sep 2023 17:44:23 +0300 Subject: [PATCH 25/30] Better error message --- .../src/main/kotlin/io/spine/protodata/gradle/SourcePaths.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle-api/src/main/kotlin/io/spine/protodata/gradle/SourcePaths.kt b/gradle-api/src/main/kotlin/io/spine/protodata/gradle/SourcePaths.kt index 5c721ea84..909f9987b 100644 --- a/gradle-api/src/main/kotlin/io/spine/protodata/gradle/SourcePaths.kt +++ b/gradle-api/src/main/kotlin/io/spine/protodata/gradle/SourcePaths.kt @@ -63,9 +63,9 @@ public data class SourcePaths( */ @Internal public fun checkAllSet() { - require(!target.isNullOrBlank()) { missingMessage("target path") } + require(!target.isNullOrBlank()) { missingMessage("target") } require(!language.isNullOrBlank()) { missingMessage("language") } } - private fun missingMessage(propName: String) = "Source file set requires the $propName." + private fun missingMessage(propName: String) = "Source file set requires the `$propName`." } From 09ccc193579aa8e509b39dabf8be9df66e0e3bc4 Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Thu, 21 Sep 2023 17:46:36 +0300 Subject: [PATCH 26/30] Remove a duplicate string literal --- .../main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt index da7f89428..c264658aa 100644 --- a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt +++ b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt @@ -101,7 +101,7 @@ public class Extension(internal val project: Project): CodegenSettings { return srcRoots.zip(targetRoots) .map { (src, target) -> val pathSuffix = src.asFile.toPath().name - val lang = if (pathSuffix == "kotlin") Kotlin else Java + val lang = if (pathSuffix.equals(Kotlin.name, ignoreCase = true)) Kotlin else Java val generatorName = if (pathSuffix.equals(lang.name, ignoreCase = true)) { "" } else { From b006441dbdd2afbc8f4977ebf3e3795186dccb5e Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Thu, 21 Sep 2023 17:49:40 +0300 Subject: [PATCH 27/30] More doc --- .../main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt index c264658aa..94eccd055 100644 --- a/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt +++ b/gradle-plugin/src/main/kotlin/io/spine/protodata/gradle/plugin/Extension.kt @@ -91,6 +91,9 @@ public class Extension(internal val project: Project): CodegenSettings { * If the deprecated [subDirs] and [targetBaseDir] are used, constructs [SourcePaths] instances * from the present data for backward compatibility. However, in this compatibility mode, * only Java and Kotlin source file sets can be constructed. + * + * This method exists for backward compatibility reasons only. Once the old way of providing + * source set paths is no longer available, we remove it and simply query [paths] instead. */ internal fun pathsOrCompat(sourceSet: SourceSet): Set { if (!paths.isEmpty) { From 44c297d2a810234ac5cb150608afd1d6ba736d5f Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Thu, 21 Sep 2023 18:30:13 +0300 Subject: [PATCH 28/30] Make language reference for `AnyLanguage` simpler --- .../io/spine/protodata/cli/KnownLanguages.kt | 12 ++++++------ license-report.md | 18 +++++++++--------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/cli-api/src/main/kotlin/io/spine/protodata/cli/KnownLanguages.kt b/cli-api/src/main/kotlin/io/spine/protodata/cli/KnownLanguages.kt index df2149250..27ca05c00 100644 --- a/cli-api/src/main/kotlin/io/spine/protodata/cli/KnownLanguages.kt +++ b/cli-api/src/main/kotlin/io/spine/protodata/cli/KnownLanguages.kt @@ -37,9 +37,9 @@ import io.spine.tools.code.Language * The well-known languages processed by ProtoData. */ @Internal -public val knownLanguages: Map = setOf( - Java, - Kotlin, - JavaScript, - AnyLanguage -).associateBy { it.name.lowercase() } +public val knownLanguages: Map = mapOf( + Java.name.lowercase() to Java, + Kotlin.name.lowercase() to Kotlin, + JavaScript.name.lowercase() to JavaScript, + "any" to AnyLanguage +) diff --git a/license-report.md b/license-report.md index 693070c6b..52a8a24a8 100644 --- a/license-report.md +++ b/license-report.md @@ -925,7 +925,7 @@ The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 20 21:05:07 EEST 2023** 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 **Thu Sep 21 18:10:21 EEST 2023** 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). @@ -1871,7 +1871,7 @@ This report was generated on **Wed Sep 20 21:05:07 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 20 21:05:09 EEST 2023** 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 **Thu Sep 21 18:10:24 EEST 2023** 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). @@ -2789,7 +2789,7 @@ This report was generated on **Wed Sep 20 21:05:09 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 20 21:05:11 EEST 2023** 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 **Thu Sep 21 18:10:27 EEST 2023** 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). @@ -3718,7 +3718,7 @@ This report was generated on **Wed Sep 20 21:05:11 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 20 21:05:12 EEST 2023** 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 **Thu Sep 21 18:10:30 EEST 2023** 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). @@ -4647,7 +4647,7 @@ This report was generated on **Wed Sep 20 21:05:12 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 20 21:05:14 EEST 2023** 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 **Thu Sep 21 18:10:32 EEST 2023** 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). @@ -5457,7 +5457,7 @@ This report was generated on **Wed Sep 20 21:05:14 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 20 21:05:15 EEST 2023** 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 **Thu Sep 21 18:10:34 EEST 2023** 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). @@ -6550,7 +6550,7 @@ This report was generated on **Wed Sep 20 21:05:15 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 20 21:05:16 EEST 2023** 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 **Thu Sep 21 18:10:37 EEST 2023** 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). @@ -7319,7 +7319,7 @@ This report was generated on **Wed Sep 20 21:05:16 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 20 21:05:18 EEST 2023** 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 **Thu Sep 21 18:10:39 EEST 2023** 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). @@ -8255,4 +8255,4 @@ This report was generated on **Wed Sep 20 21:05:18 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Wed Sep 20 21:05:19 EEST 2023** 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 **Thu Sep 21 18:10:42 EEST 2023** 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 From 54bcd5a9db50a8b2db17b0f4530ea67901c8629b Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Fri, 22 Sep 2023 17:54:14 +0300 Subject: [PATCH 29/30] Rename new DSL components --- .../spine/protodata/gradle/CodegenSettings.kt | 22 +++++--- .../io/spine/protodata/gradle/Launch.kt | 51 +++++++++++++++++++ .../resources/custom-paths/build.gradle.kts | 20 +++++--- license-report.md | 18 +++---- 4 files changed, 88 insertions(+), 23 deletions(-) create mode 100644 gradle-api/src/main/kotlin/io/spine/protodata/gradle/Launch.kt diff --git a/gradle-api/src/main/kotlin/io/spine/protodata/gradle/CodegenSettings.kt b/gradle-api/src/main/kotlin/io/spine/protodata/gradle/CodegenSettings.kt index b44050c43..4f85e02b1 100644 --- a/gradle-api/src/main/kotlin/io/spine/protodata/gradle/CodegenSettings.kt +++ b/gradle-api/src/main/kotlin/io/spine/protodata/gradle/CodegenSettings.kt @@ -27,6 +27,7 @@ package io.spine.protodata.gradle import com.google.common.collect.Multimap +import org.gradle.api.tasks.SourceSet /** * Configures code generation process performed by ProtoData. @@ -79,13 +80,22 @@ public interface CodegenSettings { public val paths: Multimap /** - * Creates a new [SourcePaths] for the given scope. + * Configures a particular launch of ProtoData for the given source set. * - * @see paths + * @param sourceSet the source set for which ProtoData is launched. + * @param configure the block configuring the launch. */ - public fun pathsFor(scope: String, configAction: SourcePaths.() -> Unit) { - val p = SourcePaths() - configAction(p) - paths.put(scope, p) + public fun launchFor(sourceSet: SourceSet, configure: Launch.() -> Unit): Unit = + launchFor(sourceSet.name, configure) + + /** + * Configures a particular launch of ProtoData for the source set with the given name. + * + * @param sourceSetName the name of the source set for which ProtoData is launched. + * @param configure the block configuring the launch. + */ + public fun launchFor(sourceSetName: String, configure: Launch.() -> Unit) { + val l = Launch(sourceSetName, this) + configure(l) } } diff --git a/gradle-api/src/main/kotlin/io/spine/protodata/gradle/Launch.kt b/gradle-api/src/main/kotlin/io/spine/protodata/gradle/Launch.kt new file mode 100644 index 000000000..51c91393a --- /dev/null +++ b/gradle-api/src/main/kotlin/io/spine/protodata/gradle/Launch.kt @@ -0,0 +1,51 @@ +/* + * 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.protodata.gradle + +/** + * A DSL component configuring a particular ProtoData launch. + * + * ProtoData is launched separately for each Gradle source set. This part of the DSL configures + * the source paths that are used by ProtoData in the given launch. + */ +public class Launch +internal constructor( + private val sourceSetName: String, + private val settings: CodegenSettings +) { + + /** + * Adds the configured [SourcePaths] to the launch. + * + * @param configure the code block configuring the paths. + */ + public fun sourceFileSet(configure: SourcePaths.() -> Unit) { + val paths = SourcePaths() + configure(paths) + settings.paths.put(sourceSetName, paths) + } +} diff --git a/gradle-plugin/src/functionalTest/resources/custom-paths/build.gradle.kts b/gradle-plugin/src/functionalTest/resources/custom-paths/build.gradle.kts index 77e60b1e0..bd7774f61 100644 --- a/gradle-plugin/src/functionalTest/resources/custom-paths/build.gradle.kts +++ b/gradle-plugin/src/functionalTest/resources/custom-paths/build.gradle.kts @@ -55,15 +55,19 @@ protobuf { protoData { plugins("io.spine.protodata.test.TestPlugin", "io.spine.protodata.test.UnderscorePrefixPlugin") - pathsFor("main") { - source = "$buildDir/generated/source/proto/main/java" - target = "$buildDir/foomain" - language = "java" + launchFor("main") { + sourceFileSet { + source = "$buildDir/generated/source/proto/main/java" + target = "$buildDir/foomain" + language = "java" + } } - pathsFor("test") { - source = "$buildDir/generated-proto/test/kotlin" - target = "$buildDir/footest" - language = "java" + launchFor(sourceSets.test.get()) { + sourceFileSet { + source = "$buildDir/generated-proto/test/kotlin" + target = "$buildDir/footest" + language = "java" + } } } diff --git a/license-report.md b/license-report.md index 52a8a24a8..bc57552fd 100644 --- a/license-report.md +++ b/license-report.md @@ -925,7 +925,7 @@ The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Sep 21 18:10:21 EEST 2023** 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 **Fri Sep 22 16:47:12 EEST 2023** 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). @@ -1871,7 +1871,7 @@ This report was generated on **Thu Sep 21 18:10:21 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Sep 21 18:10:24 EEST 2023** 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 **Fri Sep 22 16:47:14 EEST 2023** 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). @@ -2789,7 +2789,7 @@ This report was generated on **Thu Sep 21 18:10:24 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Sep 21 18:10:27 EEST 2023** 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 **Fri Sep 22 16:47:15 EEST 2023** 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). @@ -3718,7 +3718,7 @@ This report was generated on **Thu Sep 21 18:10:27 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Sep 21 18:10:30 EEST 2023** 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 **Fri Sep 22 16:47:17 EEST 2023** 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). @@ -4647,7 +4647,7 @@ This report was generated on **Thu Sep 21 18:10:30 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Sep 21 18:10:32 EEST 2023** 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 **Fri Sep 22 16:47:18 EEST 2023** 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). @@ -5457,7 +5457,7 @@ This report was generated on **Thu Sep 21 18:10:32 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Sep 21 18:10:34 EEST 2023** 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 **Fri Sep 22 16:47:19 EEST 2023** 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). @@ -6550,7 +6550,7 @@ This report was generated on **Thu Sep 21 18:10:34 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Sep 21 18:10:37 EEST 2023** 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 **Fri Sep 22 16:47:20 EEST 2023** 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). @@ -7319,7 +7319,7 @@ This report was generated on **Thu Sep 21 18:10:37 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Sep 21 18:10:39 EEST 2023** 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 **Fri Sep 22 16:47:21 EEST 2023** 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). @@ -8255,4 +8255,4 @@ This report was generated on **Thu Sep 21 18:10:39 EEST 2023** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Sep 21 18:10:42 EEST 2023** 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 **Fri Sep 22 16:47:22 EEST 2023** 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 From 9a3158edbb8b16370748df01cfca1a8c23906b20 Mon Sep 17 00:00:00 2001 From: Dmytro Dashenkov Date: Fri, 22 Sep 2023 17:59:16 +0300 Subject: [PATCH 30/30] Add a shortcut for Gradle's providers --- .../io/spine/protodata/gradle/CodegenSettings.kt | 10 ++++++++++ .../resources/custom-paths/build.gradle.kts | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/gradle-api/src/main/kotlin/io/spine/protodata/gradle/CodegenSettings.kt b/gradle-api/src/main/kotlin/io/spine/protodata/gradle/CodegenSettings.kt index 4f85e02b1..886ee0c24 100644 --- a/gradle-api/src/main/kotlin/io/spine/protodata/gradle/CodegenSettings.kt +++ b/gradle-api/src/main/kotlin/io/spine/protodata/gradle/CodegenSettings.kt @@ -27,6 +27,7 @@ package io.spine.protodata.gradle import com.google.common.collect.Multimap +import org.gradle.api.provider.Provider import org.gradle.api.tasks.SourceSet /** @@ -79,6 +80,15 @@ public interface CodegenSettings { */ public val paths: Multimap + /** + * Configures a particular launch of ProtoData for the given source set. + * + * @param sourceSet the source set for which ProtoData is launched. + * @param configure the block configuring the launch. + */ + public fun launchFor(sourceSet: Provider, configure: Launch.() -> Unit): Unit = + launchFor(sourceSet.get().name, configure) + /** * Configures a particular launch of ProtoData for the given source set. * diff --git a/gradle-plugin/src/functionalTest/resources/custom-paths/build.gradle.kts b/gradle-plugin/src/functionalTest/resources/custom-paths/build.gradle.kts index bd7774f61..a98a6fa20 100644 --- a/gradle-plugin/src/functionalTest/resources/custom-paths/build.gradle.kts +++ b/gradle-plugin/src/functionalTest/resources/custom-paths/build.gradle.kts @@ -63,7 +63,7 @@ protoData { } } - launchFor(sourceSets.test.get()) { + launchFor(sourceSets.test) { sourceFileSet { source = "$buildDir/generated-proto/test/kotlin" target = "$buildDir/footest"