diff --git a/gradle-plugin/src/test/kotlin/io/spine/tools/prototap/gradle/PluginSpec.kt b/gradle-plugin/src/test/kotlin/io/spine/tools/prototap/gradle/PluginSpec.kt index 6b43228..391ada7 100644 --- a/gradle-plugin/src/test/kotlin/io/spine/tools/prototap/gradle/PluginSpec.kt +++ b/gradle-plugin/src/test/kotlin/io/spine/tools/prototap/gradle/PluginSpec.kt @@ -82,6 +82,14 @@ internal class PluginSpec { assertDescriptorSetFileExits() } + @Test + fun `work as a 'classpath' dependency of 'buildscript'`() { + createProject("via-classpath") + runBuild() + assertJavaCodeGenerated() + assertRequestFileExits() + } + private fun assertJavaCodeGenerated() { val javaDir = resultDir.resolve("java") javaDir.countFiles() shouldNotBe 0 diff --git a/gradle-plugin/src/test/resources/via-classpath/build.gradle.kts b/gradle-plugin/src/test/resources/via-classpath/build.gradle.kts new file mode 100644 index 0000000..e6b9afc --- /dev/null +++ b/gradle-plugin/src/test/resources/via-classpath/build.gradle.kts @@ -0,0 +1,62 @@ +/* + * Copyright 2024, TeamDev. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Redistribution and use in source and/or binary forms, with or without + * modification, must retain the above copyright notice and the following + * disclaimer. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import com.google.protobuf.gradle.protobuf +import io.spine.internal.dependency.Protobuf +import io.spine.internal.dependency.GoogleApis +import io.spine.internal.gradle.standardToSpineSdk + +buildscript { + standardSpineSdkRepositories() + dependencies { + classpath("io.spine.tools:prototap-gradle-plugin:@PROTOTAP_VERSION@") + } +} + +plugins { + java + `java-test-fixtures` + id("com.google.protobuf") +} + +apply(plugin = "@PROTOTAP_PLUGIN_ID@") + +repositories { + mavenLocal() + standardToSpineSdk() +} + +protobuf { + protoc { + artifact = io.spine.internal.dependency.Protobuf.compiler + } +} + +dependencies { + testFixturesImplementation(Protobuf.javaLib) + // For `google/type/` proto types used in stub domains. + testFixturesImplementation(GoogleApis.commonProtos) +} diff --git a/gradle-plugin/src/test/resources/via-classpath/settings.gradle.kts b/gradle-plugin/src/test/resources/via-classpath/settings.gradle.kts new file mode 100644 index 0000000..4aadfdd --- /dev/null +++ b/gradle-plugin/src/test/resources/via-classpath/settings.gradle.kts @@ -0,0 +1,31 @@ +/* + * Copyright 2024, TeamDev. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Redistribution and use in source and/or binary forms, with or without + * modification, must retain the above copyright notice and the following + * disclaimer. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +pluginManagement { + repositories { + mavenLocal() + } +} diff --git a/gradle-plugin/src/test/resources/via-classpath/src/testFixtures/proto/given/domain/gas_transportation.proto b/gradle-plugin/src/test/resources/via-classpath/src/testFixtures/proto/given/domain/gas_transportation.proto new file mode 100644 index 0000000..a796651 --- /dev/null +++ b/gradle-plugin/src/test/resources/via-classpath/src/testFixtures/proto/given/domain/gas_transportation.proto @@ -0,0 +1,65 @@ +/* +* Copyright 2024, TeamDev. All rights reserved. +* +* 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. +*/ +syntax = "proto3"; + +package given.domain; + +// +// This is a "vanilla" Protobuf file, which does not use Spine-specific features like +// custom options such as `type_url_prefix` or validation constraints. +// We also use "pure" Protobuf Java `protoc` plugin to process these files so that +// we recreate conditions we have before ProtoData gets into play after `protoc` +// finishes its work. +// + +option java_package = "io.spine.given.domain.gas"; +option java_outer_classname = "GasTransportationProto"; +option java_multiple_files = true; + +import "google/type/latlng.proto"; + +message OilAndGasWell { + google.type.LatLng location = 1; +} + +message Pipe { + google.type.LatLng from = 1; + google.type.LatLng to = 2; +} + +message GasProcessingPlant { + string name = 1; + google.type.LatLng location = 2; + repeated Pipe inbound = 3; + repeated Pipe outbound = 4; +} + +message CompressorStation { + google.type.LatLng location = 1; + repeated Pipe inbound = 2; + repeated Pipe outbound = 3; +} + +message LngStorage { + string name = 1; + google.type.LatLng location = 2; + Pipe inbound = 3; + Pipe outbound = 4; +} diff --git a/gradle-plugin/src/test/resources/via-classpath/src/testFixtures/proto/given/domain/oil_refinery.proto b/gradle-plugin/src/test/resources/via-classpath/src/testFixtures/proto/given/domain/oil_refinery.proto new file mode 100644 index 0000000..c85fa31 --- /dev/null +++ b/gradle-plugin/src/test/resources/via-classpath/src/testFixtures/proto/given/domain/oil_refinery.proto @@ -0,0 +1,56 @@ +/* +* Copyright 2024, TeamDev. All rights reserved. +* +* 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. +*/ +syntax = "proto3"; + +package given.domain; + +// +// This is a "vanilla" Protobuf file, which does not use Spine-specific features like +// custom options such as `type_url_prefix` or validation constraints. +// We also use "pure" Protobuf Java `protoc` plugin to process these files so that +// we recreate conditions we have before ProtoData gets into play after `protoc` +// finishes its work. +// + +option java_package = "io.spine.given.domain.oil"; +option java_outer_classname = "OilRefineryProto"; +option java_multiple_files = true; + +enum ProductType { + PT_UNKNOWN = 0; + PETROL = 1; + KEROSENE = 2; + DIESEL = 3; + FUEL_OIL = 4; + LUBRICATING_OIL = 5; + PARAFFIN_WAX = 6; + ASPHALT_BASE = 7; +} + +message Product { + ProductType type = 1; + float volume = 2; +} + +message Refinery { + string name = 1; + float input = 2; + repeated Product output = 3; +}