Skip to content

Commit

Permalink
Prevent the error when explicitly specifying default buf gen template…
Browse files Browse the repository at this point in the history
… file path
  • Loading branch information
un1024 committed Jun 2, 2024
1 parent f9c45dc commit 23987fb
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/kotlin/build/buf/gradle/GenerateTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ abstract class GenerateTask : DefaultTask() {
check(specifiedTemplateFile != null) {
"Specified templateFileLocation does not exist."
}
check(defaultTemplateFile == null) {
"Buf gen template file specified in the project directory as well as with templateFileLocation; pick one."
if (specifiedTemplateFile != defaultTemplateFile) {
check(defaultTemplateFile == null) {
"Buf gen template file specified in the project directory as well as with templateFileLocation; pick one."
}
}
specifiedTemplateFile
} else {
Expand Down
5 changes: 5 additions & 0 deletions src/test/kotlin/build/buf/gradle/AbstractGenerateTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ abstract class AbstractGenerateTest : AbstractBufIntegrationTest() {
gradleRunner().withArguments(BUILD_TASK_NAME).build()
}

@Test
fun `buf generate with default template file path explicitly specifying`() {
gradleRunner().withArguments(BUILD_TASK_NAME).build()
}

@Test
fun `buf generate fails with a nonexistent specified template file`() {
val result = gradleRunner().withArguments(BUF_GENERATE_TASK_NAME).buildAndFail()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: v1
plugins:
- plugin: buf.build/protocolbuffers/java:v23.4
out: java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2023 Buf Technologies, Inc.
//
// 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 buf.test.v1;

option java_package = "buf.test.v1";

message BasicMessage {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
plugins {
id 'java'
id 'build.buf'
}

repositories {
mavenCentral()
}

buf {
generate {
templateFileLocation = project.file("./buf.gen.yaml")
}
}

compileJava.dependsOn 'bufGenerate'

sourceSets.main.java {
srcDir 'build/bufbuild/generated/java'
}

dependencies {
implementation "com.google.protobuf:protobuf-java:$protobufVersion"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2023 Buf Technologies, Inc.
//
// 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 buf.test.v1;

public class Foo {
public static void test() {
Test.BasicMessage.newBuilder().build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: v1
plugins:
- plugin: buf.build/protocolbuffers/java:v23.4
out: java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version: v1
directories:
- workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
plugins {
id 'java'
id 'build.buf'
}

repositories {
mavenCentral()
}

buf {
generate {
templateFileLocation = project.file("./buf.gen.yaml")
}
}

compileJava.dependsOn 'bufGenerate'

sourceSets.main.java {
srcDir 'build/bufbuild/generated/java'
}

dependencies {
implementation "com.google.protobuf:protobuf-java:$protobufVersion"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2023 Buf Technologies, Inc.
//
// 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 buf.test.v1;

public class Foo {
public static void test() {
Test.BasicMessage.newBuilder().build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2023 Buf Technologies, Inc.
//
// 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 buf.test.v1;

option java_package = "buf.test.v1";

message BasicMessage {}

0 comments on commit 23987fb

Please sign in to comment.