diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b92b8195..f7495e76 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,16 +24,16 @@ jobs: - uses: actions/checkout@v2 with: fetch-depth: 0 - - - name: Set up JDK 11 + + - name: Set up JDK 17 uses: actions/setup-java@v2 with: distribution: adopt - java-version: 11 + java-version: 17 - name: Build run: ./gradlew build --info - + - name: Publish unit test results uses: EnricoMi/publish-unit-test-result-action@v1 if: always() diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 00b692ea..c4e18273 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -2,9 +2,9 @@ name: Publish on: push: - tags: + tags: - "[0-9]+.[0-9]+.[0-9]+" - + workflow_dispatch: jobs: @@ -25,11 +25,11 @@ jobs: - uses: actions/checkout@v2 with: fetch-depth: 0 - - - name: Set up JDK 11 + + - name: Set up JDK 17 uses: actions/setup-java@v1 with: - java-version: 11 + java-version: 17 - name: Publish run: ./gradlew publishToRemote closeAndReleaseRepository publishPlugins -Dorg.gradle.internal.http.socketTimeout=120000 -Dorg.gradle.internal.network.retry.max.attempts=1 -Dorg.gradle.internal.publish.checksums.insecure=true diff --git a/README.md b/README.md index 6b17e033..37721040 100644 --- a/README.md +++ b/README.md @@ -5,13 +5,13 @@ Linting and breakage-check integration for [Buf](https://github.com/bufbuild/buf) with Gradle. Supports integration purely between Buf and Gradle or additionally with the [protobuf-gradle-plugin](https://github.com/google/protobuf-gradle-plugin). -This plugin supports straightforward usage of `buf lint` and a self-contained integration between `buf build` and `buf breaking`. It does not (yet) integrate with `buf generate`. +This plugin supports straightforward usage of `buf lint` and `buf generate` and a self-contained integration between `buf build` and `buf breaking`. ## Usage By default this plugin assumes that Buf is configured for the project root (with or without a workspace `buf.work.yaml`). It will scan all top-level directories for protobuf sources. -If the project includes the `protobuf-gradle-plugin`, then this plugin will use an implicit Buf workspace that includes all specified protobuf source set directories, the `include` dependencies that the protobuf-gradle-plugin extracts into `"${project.buildDir}/extracted-include-protos"`, and the dependencies that the protobuf-gradle-plugin has been told to generate that are extracted into `"${project.buildDir}/extracted-protos"`. +If the project includes the `protobuf-gradle-plugin`, then this plugin will use an implicit Buf workspace that includes all specified protobuf source set directories, the `include` dependencies that the protobuf-gradle-plugin extracts into `"$buildDir/extracted-include-protos"`, and the dependencies that the protobuf-gradle-plugin has been told to generate that are extracted into `"$buildDir/extracted-protos"`. This plugin does not support usage of both a Buf workspace and the `protobuf-gradle-plugin`; determining ownership of dependency resolution in that case would be complicated and error-prone. @@ -35,9 +35,10 @@ buildscript { apply(plugin = "com.parmet.buf") ``` -When applied the plugin creates two useful tasks: +When applied the plugin creates several tasks: - `bufLint` lints protobuf code - `bufBreaking` checks protobuf against a previous version for backwards-incompatible changes +- `bufGenerate` generates protobuf code ## Configuration @@ -170,6 +171,45 @@ buf { } ``` +### `bufGenerate` + +`bufGenerate` is configured as described in the Buf docs. Create a `buf.gen.yaml` in the project root and `bufGenerate` will generate code in the project's build directory at `"$buildDir/bufbuild/generated/"`. + +An example for Java code generation using the remote plugin: + +``` yaml +version: v1 +plugins: + - remote: buf.build/protocolbuffers/plugins/java: + out: java +``` + +If you want to use generated code in your build you must add the generated code as a source directory and configure a task dependency to ensure code is generated before compilation: + +``` kotlin +// build.gradle.kts + +import com.parmet.buf.gradle.BUF_GENERATED_DIR + +plugins { + `java` + id("com.parmet.buf") version "" +} + +// Add a task dependency for compilation +tasks.named("compileJava").configure { dependsOn("bufGenerate") } + +// Add the generated code to the main source set +sourceSets["main"].java { srcDir("$buildDir/$BUF_GENERATED_DIR/java") } + +// Configure dependencies for protobuf-java: +repositories { mavenCentral() } + +dependencies { + implementation("com.google.protobuf:protobuf-java:") +} +``` + ## Additional Configuration The version of Buf used can be configured using the `toolVersion` property on the extension: diff --git a/build.gradle.kts b/build.gradle.kts index 9fd79a7d..b5151b6a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -95,7 +95,7 @@ tasks { dependencies { signature(libs.java8Signature) { artifact { type = "signature" } } - testImplementation(libs.junit) + testImplementation(libs.junit) { version { branch = "main" } } testImplementation(libs.truth) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a12cedbe..87d3d7cf 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -21,7 +21,6 @@ spotless = "6.3.0" java8Signature = "1.0" # test -junit = "5.8.2" truth = "1.1.3" [plugins] @@ -34,5 +33,5 @@ spotless = { id = "com.diffplug.spotless", version.ref = "spotless" } java8Signature = { module = "org.codehaus.mojo.signature:java18", version.ref = "java8Signature" } # test -junit = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" } +junit = { module = "org.junit.jupiter:junit-jupiter" } truth = { module = "com.google.truth:truth", version.ref = "truth" } diff --git a/settings.gradle.kts b/settings.gradle.kts index d825acbf..c054346b 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -13,6 +13,8 @@ * limitations under the License. */ +import java.net.URI + buildscript { repositories { gradlePluginPortal() @@ -25,3 +27,9 @@ buildscript { apply(plugin = "net.vivin.gradle-semantic-build-versioning") rootProject.name = "buf-gradle-plugin" + +sourceControl { + gitRepository(URI.create("https://github.com/andrewparmet/junit5.git")) { + producesModule("org.junit.jupiter:junit-jupiter") + } +} diff --git a/src/main/kotlin/com/parmet/buf/gradle/Breaking.kt b/src/main/kotlin/com/parmet/buf/gradle/Breaking.kt index b1108e5d..0c3ca92b 100644 --- a/src/main/kotlin/com/parmet/buf/gradle/Breaking.kt +++ b/src/main/kotlin/com/parmet/buf/gradle/Breaking.kt @@ -94,7 +94,7 @@ private fun Project.configureBreakingTask(ext: BufExtension, bufBreakingFile: La buf( ext, "breaking", - qualifyFile(BUF_BUILD_PUBLICATION_FILENAME), + qualifyFile(BUF_BUILD_PUBLICATION_FILE_NAME), "--against", qualifyFile { "$BREAKING_DIR/${bufBreakingFile.fileName}" } ) diff --git a/src/main/kotlin/com/parmet/buf/gradle/BufPlugin.kt b/src/main/kotlin/com/parmet/buf/gradle/BufPlugin.kt index 6b6ca6dc..21855ff3 100644 --- a/src/main/kotlin/com/parmet/buf/gradle/BufPlugin.kt +++ b/src/main/kotlin/com/parmet/buf/gradle/BufPlugin.kt @@ -42,7 +42,7 @@ class BufPlugin : Plugin { If you have multiple protobuf source directories and you would like to use the protobuf-gradle-plugin, configure the protobuf-gradle-plugin to use those directories as source directories in the appropriate source set. If you - would like to use Buf workspaces, you must configure dependency resolution and + would like to use a Buf workspace, you must configure dependency resolution and code generation using Buf. There is no (easy) way to reconcile the two configurations for linting, breakage, and code generation steps. """.trimIndent().replace('\n', ' ') @@ -59,6 +59,7 @@ class BufPlugin : Plugin { private fun Project.configureBuf(ext: BufExtension) { configureLint(ext) configureBuild(ext) + configureGenerate(ext) afterEvaluate { getArtifactDetails(ext)?.let { diff --git a/src/main/kotlin/com/parmet/buf/gradle/Build.kt b/src/main/kotlin/com/parmet/buf/gradle/Build.kt index 0f3e47f7..6ac67756 100644 --- a/src/main/kotlin/com/parmet/buf/gradle/Build.kt +++ b/src/main/kotlin/com/parmet/buf/gradle/Build.kt @@ -24,7 +24,7 @@ import org.gradle.kotlin.dsl.register import org.gradle.kotlin.dsl.the const val BUF_BUILD_TASK_NAME = "bufBuild" -const val BUF_BUILD_PUBLICATION_FILENAME = "image.json" +const val BUF_BUILD_PUBLICATION_FILE_NAME = "image.json" const val BUF_IMAGE_PUBLICATION_NAME = "bufImagePublication" internal fun Project.configureBuild(ext: BufExtension) { @@ -36,7 +36,7 @@ internal fun Project.configureBuild(ext: BufExtension) { createsOutput() } - buf(ext, "build", "--output", qualifyFile(BUF_BUILD_PUBLICATION_FILENAME)) + buf(ext, "build", "--output", qualifyFile(BUF_BUILD_PUBLICATION_FILE_NAME)) } } @@ -49,7 +49,7 @@ internal fun Project.configureImagePublication(artifactDetails: ArtifactDetails) artifactId = artifactDetails.artifactId version = artifactDetails.version - artifact(file("$bufbuildDir/$BUF_BUILD_PUBLICATION_FILENAME")) { + artifact(file("$bufbuildDir/$BUF_BUILD_PUBLICATION_FILE_NAME")) { builtBy(tasks.named(BUF_BUILD_TASK_NAME)) } } diff --git a/src/main/kotlin/com/parmet/buf/gradle/Generate.kt b/src/main/kotlin/com/parmet/buf/gradle/Generate.kt new file mode 100644 index 00000000..82b1d630 --- /dev/null +++ b/src/main/kotlin/com/parmet/buf/gradle/Generate.kt @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022 Andrew Parmet + * + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.parmet.buf.gradle + +import org.gradle.api.Project +import org.gradle.api.tasks.Exec +import org.gradle.kotlin.dsl.register + +const val BUF_GENERATE_TASK_NAME = "bufGenerate" + +private const val GENERATED_DIR = "generated" +const val BUF_GENERATED_DIR = "$BUF_BUILD_DIR/$GENERATED_DIR" + +internal fun Project.configureGenerate(ext: BufExtension) { + if (hasGenerate()) { + tasks.register(BUF_GENERATE_TASK_NAME) { + createsOutput() + buf(ext, "generate", "--output", qualifyFile(GENERATED_DIR)) + } + } +} + +private fun Project.hasGenerate() = + file("buf.gen.yaml").let { it.exists() && it.isFile } diff --git a/src/test/kotlin/com/parmet/buf/gradle/AbstractBufIntegrationTest.kt b/src/test/kotlin/com/parmet/buf/gradle/AbstractBufIntegrationTest.kt index 322d2469..5c87ebcd 100644 --- a/src/test/kotlin/com/parmet/buf/gradle/AbstractBufIntegrationTest.kt +++ b/src/test/kotlin/com/parmet/buf/gradle/AbstractBufIntegrationTest.kt @@ -19,24 +19,26 @@ import com.google.common.truth.Truth.assertWithMessage import org.gradle.testkit.runner.GradleRunner import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.TestInfo +import org.junit.jupiter.api.io.CleanupMode.NEVER import org.junit.jupiter.api.io.TempDir import java.io.File import java.nio.file.Paths abstract class AbstractBufIntegrationTest : IntegrationTest { - @TempDir + @TempDir(cleanup = NEVER) lateinit var projectDir: File - private lateinit var settingsFile: File - lateinit var buildFile: File - lateinit var protoDir: File + private val settingsFile + get() = File(projectDir, "settings.gradle") + + val buildFile + get() = File(projectDir, "build.gradle").takeIf { it.exists() } ?: File(projectDir, "build.gradle.kts") + + val protoDir + get() = Paths.get(projectDir.path, "src", "main", "proto").toFile() @BeforeEach fun setup(testInfo: TestInfo) { - settingsFile = File(projectDir, "settings.gradle") - buildFile = File(projectDir, "build.gradle") - protoDir = Paths.get(projectDir.path, "src", "main", "proto").toFile() - settingsFile.writeText("rootProject.name = 'testing'") val fixture = File("src/test/resources/${testInfo.testClass.get().simpleName}/${testInfo.testMethod.get().name}") diff --git a/src/test/kotlin/com/parmet/buf/gradle/AbstractGenerateTest.kt b/src/test/kotlin/com/parmet/buf/gradle/AbstractGenerateTest.kt new file mode 100644 index 00000000..4ede5231 --- /dev/null +++ b/src/test/kotlin/com/parmet/buf/gradle/AbstractGenerateTest.kt @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2022 Andrew Parmet + * + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.parmet.buf.gradle + +import org.junit.jupiter.api.Test + +abstract class AbstractGenerateTest : AbstractBufIntegrationTest() { + @Test + fun `generate java`() { + gradleRunner().withArguments("build").build() + } + + @Test + fun `generate java with kotlin dsl`() { + gradleRunner().withArguments("build").build() + } +} diff --git a/src/test/kotlin/com/parmet/buf/gradle/GenerateTest.kt b/src/test/kotlin/com/parmet/buf/gradle/GenerateTest.kt new file mode 100644 index 00000000..5b66bdc0 --- /dev/null +++ b/src/test/kotlin/com/parmet/buf/gradle/GenerateTest.kt @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2022 Andrew Parmet + * + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.parmet.buf.gradle + +class GenerateTest : AbstractGenerateTest() diff --git a/src/test/kotlin/com/parmet/buf/gradle/GenerateWithWorkspaceTest.kt b/src/test/kotlin/com/parmet/buf/gradle/GenerateWithWorkspaceTest.kt new file mode 100644 index 00000000..f46a16b0 --- /dev/null +++ b/src/test/kotlin/com/parmet/buf/gradle/GenerateWithWorkspaceTest.kt @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2022 Andrew Parmet + * + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.parmet.buf.gradle + +class GenerateWithWorkspaceTest : AbstractGenerateTest() diff --git a/src/test/resources/GenerateTest/generate java with kotlin dsl/buf.gen.yaml b/src/test/resources/GenerateTest/generate java with kotlin dsl/buf.gen.yaml new file mode 100644 index 00000000..ad242492 --- /dev/null +++ b/src/test/resources/GenerateTest/generate java with kotlin dsl/buf.gen.yaml @@ -0,0 +1,17 @@ +# Copyright (c) 2022 Andrew Parmet +# +# 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 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +version: v1 +plugins: + - remote: buf.build/protocolbuffers/plugins/java:v3.20.0-1 + out: java diff --git a/src/test/resources/GenerateTest/generate java with kotlin dsl/build.gradle.kts b/src/test/resources/GenerateTest/generate java with kotlin dsl/build.gradle.kts new file mode 100644 index 00000000..91111269 --- /dev/null +++ b/src/test/resources/GenerateTest/generate java with kotlin dsl/build.gradle.kts @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2022 Andrew Parmet + * + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import com.parmet.buf.gradle.BUF_GENERATED_DIR + +plugins { + `java` + id("com.parmet.buf") +} + +repositories { mavenCentral() } + +tasks.named("compileJava").configure { dependsOn("bufGenerate") } + +sourceSets["main"].java { + srcDir("$buildDir/$BUF_GENERATED_DIR/java") +} + +val protobufVersion: String by project + +dependencies { + implementation("com.google.protobuf:protobuf-java:$protobufVersion") +} diff --git a/src/test/resources/GenerateTest/generate java with kotlin dsl/parmet/buf/test/v1/test.proto b/src/test/resources/GenerateTest/generate java with kotlin dsl/parmet/buf/test/v1/test.proto new file mode 100644 index 00000000..cef39e8f --- /dev/null +++ b/src/test/resources/GenerateTest/generate java with kotlin dsl/parmet/buf/test/v1/test.proto @@ -0,0 +1,20 @@ +// Copyright (c) 2022 Andrew Parmet +// +// 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 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package parmet.buf.test.v1; + +option java_package = "com.parmet.buf.test.v1"; + +message BasicMessage {} diff --git a/src/test/resources/GenerateTest/generate java with kotlin dsl/src/main/java/com/parmet/buf/test/v1/Foo.java b/src/test/resources/GenerateTest/generate java with kotlin dsl/src/main/java/com/parmet/buf/test/v1/Foo.java new file mode 100644 index 00000000..d45c3726 --- /dev/null +++ b/src/test/resources/GenerateTest/generate java with kotlin dsl/src/main/java/com/parmet/buf/test/v1/Foo.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 Andrew Parmet + * + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.parmet.buf.test.v1; + +public class Foo { + public static void test() { + Test.BasicMessage.newBuilder().build(); + } +} diff --git a/src/test/resources/GenerateTest/generate java/buf.gen.yaml b/src/test/resources/GenerateTest/generate java/buf.gen.yaml new file mode 100644 index 00000000..ad242492 --- /dev/null +++ b/src/test/resources/GenerateTest/generate java/buf.gen.yaml @@ -0,0 +1,17 @@ +# Copyright (c) 2022 Andrew Parmet +# +# 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 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +version: v1 +plugins: + - remote: buf.build/protocolbuffers/plugins/java:v3.20.0-1 + out: java diff --git a/src/test/resources/GenerateTest/generate java/build.gradle b/src/test/resources/GenerateTest/generate java/build.gradle new file mode 100644 index 00000000..a0fb47a9 --- /dev/null +++ b/src/test/resources/GenerateTest/generate java/build.gradle @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2022 Andrew Parmet + * + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +plugins { + id 'java' + id 'com.parmet.buf' +} + +repositories { mavenCentral() } + +compileJava.dependsOn 'bufGenerate' + +sourceSets.main.java { + srcDir 'build/bufbuild/generated/java' +} + +dependencies { + implementation "com.google.protobuf:protobuf-java:$protobufVersion" +} diff --git a/src/test/resources/GenerateTest/generate java/parmet/buf/test/v1/test.proto b/src/test/resources/GenerateTest/generate java/parmet/buf/test/v1/test.proto new file mode 100644 index 00000000..cef39e8f --- /dev/null +++ b/src/test/resources/GenerateTest/generate java/parmet/buf/test/v1/test.proto @@ -0,0 +1,20 @@ +// Copyright (c) 2022 Andrew Parmet +// +// 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 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package parmet.buf.test.v1; + +option java_package = "com.parmet.buf.test.v1"; + +message BasicMessage {} diff --git a/src/test/resources/GenerateTest/generate java/src/main/java/com/parmet/buf/test/v1/Foo.java b/src/test/resources/GenerateTest/generate java/src/main/java/com/parmet/buf/test/v1/Foo.java new file mode 100644 index 00000000..d45c3726 --- /dev/null +++ b/src/test/resources/GenerateTest/generate java/src/main/java/com/parmet/buf/test/v1/Foo.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 Andrew Parmet + * + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.parmet.buf.test.v1; + +public class Foo { + public static void test() { + Test.BasicMessage.newBuilder().build(); + } +} diff --git a/src/test/resources/GenerateWithWorkspaceTest/generate java with kotlin dsl/buf.gen.yaml b/src/test/resources/GenerateWithWorkspaceTest/generate java with kotlin dsl/buf.gen.yaml new file mode 100644 index 00000000..ad242492 --- /dev/null +++ b/src/test/resources/GenerateWithWorkspaceTest/generate java with kotlin dsl/buf.gen.yaml @@ -0,0 +1,17 @@ +# Copyright (c) 2022 Andrew Parmet +# +# 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 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +version: v1 +plugins: + - remote: buf.build/protocolbuffers/plugins/java:v3.20.0-1 + out: java diff --git a/src/test/resources/GenerateWithWorkspaceTest/generate java with kotlin dsl/buf.work.yaml b/src/test/resources/GenerateWithWorkspaceTest/generate java with kotlin dsl/buf.work.yaml new file mode 100644 index 00000000..898453cb --- /dev/null +++ b/src/test/resources/GenerateWithWorkspaceTest/generate java with kotlin dsl/buf.work.yaml @@ -0,0 +1,16 @@ +# Copyright (c) 2022 Andrew Parmet +# +# 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 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +version: v1 +directories: + - workspace diff --git a/src/test/resources/GenerateWithWorkspaceTest/generate java with kotlin dsl/build.gradle.kts b/src/test/resources/GenerateWithWorkspaceTest/generate java with kotlin dsl/build.gradle.kts new file mode 100644 index 00000000..91111269 --- /dev/null +++ b/src/test/resources/GenerateWithWorkspaceTest/generate java with kotlin dsl/build.gradle.kts @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2022 Andrew Parmet + * + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import com.parmet.buf.gradle.BUF_GENERATED_DIR + +plugins { + `java` + id("com.parmet.buf") +} + +repositories { mavenCentral() } + +tasks.named("compileJava").configure { dependsOn("bufGenerate") } + +sourceSets["main"].java { + srcDir("$buildDir/$BUF_GENERATED_DIR/java") +} + +val protobufVersion: String by project + +dependencies { + implementation("com.google.protobuf:protobuf-java:$protobufVersion") +} diff --git a/src/test/resources/GenerateWithWorkspaceTest/generate java with kotlin dsl/src/main/java/com/parmet/buf/test/v1/Foo.java b/src/test/resources/GenerateWithWorkspaceTest/generate java with kotlin dsl/src/main/java/com/parmet/buf/test/v1/Foo.java new file mode 100644 index 00000000..d45c3726 --- /dev/null +++ b/src/test/resources/GenerateWithWorkspaceTest/generate java with kotlin dsl/src/main/java/com/parmet/buf/test/v1/Foo.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 Andrew Parmet + * + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.parmet.buf.test.v1; + +public class Foo { + public static void test() { + Test.BasicMessage.newBuilder().build(); + } +} diff --git a/src/test/resources/GenerateWithWorkspaceTest/generate java with kotlin dsl/workspace/parmet/buf/test/v1/test.proto b/src/test/resources/GenerateWithWorkspaceTest/generate java with kotlin dsl/workspace/parmet/buf/test/v1/test.proto new file mode 100644 index 00000000..cef39e8f --- /dev/null +++ b/src/test/resources/GenerateWithWorkspaceTest/generate java with kotlin dsl/workspace/parmet/buf/test/v1/test.proto @@ -0,0 +1,20 @@ +// Copyright (c) 2022 Andrew Parmet +// +// 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 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package parmet.buf.test.v1; + +option java_package = "com.parmet.buf.test.v1"; + +message BasicMessage {} diff --git a/src/test/resources/GenerateWithWorkspaceTest/generate java/buf.gen.yaml b/src/test/resources/GenerateWithWorkspaceTest/generate java/buf.gen.yaml new file mode 100644 index 00000000..ad242492 --- /dev/null +++ b/src/test/resources/GenerateWithWorkspaceTest/generate java/buf.gen.yaml @@ -0,0 +1,17 @@ +# Copyright (c) 2022 Andrew Parmet +# +# 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 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +version: v1 +plugins: + - remote: buf.build/protocolbuffers/plugins/java:v3.20.0-1 + out: java diff --git a/src/test/resources/GenerateWithWorkspaceTest/generate java/buf.work.yaml b/src/test/resources/GenerateWithWorkspaceTest/generate java/buf.work.yaml new file mode 100644 index 00000000..898453cb --- /dev/null +++ b/src/test/resources/GenerateWithWorkspaceTest/generate java/buf.work.yaml @@ -0,0 +1,16 @@ +# Copyright (c) 2022 Andrew Parmet +# +# 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 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +version: v1 +directories: + - workspace diff --git a/src/test/resources/GenerateWithWorkspaceTest/generate java/build.gradle b/src/test/resources/GenerateWithWorkspaceTest/generate java/build.gradle new file mode 100644 index 00000000..a0fb47a9 --- /dev/null +++ b/src/test/resources/GenerateWithWorkspaceTest/generate java/build.gradle @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2022 Andrew Parmet + * + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +plugins { + id 'java' + id 'com.parmet.buf' +} + +repositories { mavenCentral() } + +compileJava.dependsOn 'bufGenerate' + +sourceSets.main.java { + srcDir 'build/bufbuild/generated/java' +} + +dependencies { + implementation "com.google.protobuf:protobuf-java:$protobufVersion" +} diff --git a/src/test/resources/GenerateWithWorkspaceTest/generate java/src/main/java/com/parmet/buf/test/v1/Foo.java b/src/test/resources/GenerateWithWorkspaceTest/generate java/src/main/java/com/parmet/buf/test/v1/Foo.java new file mode 100644 index 00000000..d45c3726 --- /dev/null +++ b/src/test/resources/GenerateWithWorkspaceTest/generate java/src/main/java/com/parmet/buf/test/v1/Foo.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 Andrew Parmet + * + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.parmet.buf.test.v1; + +public class Foo { + public static void test() { + Test.BasicMessage.newBuilder().build(); + } +} diff --git a/src/test/resources/GenerateWithWorkspaceTest/generate java/workspace/parmet/buf/test/v1/test.proto b/src/test/resources/GenerateWithWorkspaceTest/generate java/workspace/parmet/buf/test/v1/test.proto new file mode 100644 index 00000000..cef39e8f --- /dev/null +++ b/src/test/resources/GenerateWithWorkspaceTest/generate java/workspace/parmet/buf/test/v1/test.proto @@ -0,0 +1,20 @@ +// Copyright (c) 2022 Andrew Parmet +// +// 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 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package parmet.buf.test.v1; + +option java_package = "com.parmet.buf.test.v1"; + +message BasicMessage {}