Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version: v2
clean: true
plugins:
- remote: buf.build/protocolbuffers/java:v31.1
- remote: buf.build/protocolbuffers/java:$protocJavaPluginVersion
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ tree build/buf-gen-templates
build/buf-gen-templates
├── buf.gen.yaml
└── src
    └── test
        └── resources
            └── proto
                ├── buf.gen.cel.testtypes.yaml
                ├── buf.gen.cel.yaml
                ├── buf.gen.imports.yaml
                └── buf.gen.noimports.yaml
$ cat build/buf-gen-templates/buf.gen.yaml 
version: v2
clean: true
plugins:
  - remote: buf.build/protocolbuffers/java:v31.1
    out: build/generated/sources/bufgen

out: build/generated/sources/bufgen
34 changes: 24 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -72,32 +72,46 @@ tasks.register<Exec>("licenseHeader") {
)
}

tasks.register<Copy>("filterBufGenYaml") {
from(".")
include("buf.gen.yaml", "src/**/buf*gen*.yaml")
includeEmptyDirs = false
into(layout.buildDirectory.dir("buf-gen-templates"))
expand("protocJavaPluginVersion" to "v${libs.versions.protobuf.get().substringAfter('.')}")
filteringCharset = "UTF-8"
}

tasks.register<Exec>("generateTestSourcesImports") {
dependsOn("exportProtovalidateModule")
dependsOn("exportProtovalidateModule", "filterBufGenYaml")
description = "Generates code with buf generate --include-imports for unit tests."
commandLine(
buf.asPath,
"generate",
"--template",
"src/test/resources/proto/buf.gen.imports.yaml",
"${layout.buildDirectory.get()}/buf-gen-templates/src/test/resources/proto/buf.gen.imports.yaml",
"--include-imports",
)
}

tasks.register<Exec>("generateTestSourcesNoImports") {
dependsOn("exportProtovalidateModule")
dependsOn("exportProtovalidateModule", "filterBufGenYaml")
description = "Generates code with buf generate --include-imports for unit tests."
commandLine(buf.asPath, "generate", "--template", "src/test/resources/proto/buf.gen.noimports.yaml")
commandLine(
buf.asPath,
"generate",
"--template",
"${layout.buildDirectory.get()}/buf-gen-templates/src/test/resources/proto/buf.gen.noimports.yaml",
)
}

tasks.register<Exec>("generateCelConformance") {
dependsOn("generateCelConformanceTestTypes")
dependsOn("generateCelConformanceTestTypes", "filterBufGenYaml")
description = "Generates CEL conformance code with buf generate for unit tests."
commandLine(
buf.asPath,
"generate",
"--template",
"src/test/resources/proto/buf.gen.cel.yaml",
"${layout.buildDirectory.get()}/buf-gen-templates/src/test/resources/proto/buf.gen.cel.yaml",
"buf.build/google/cel-spec:${project.findProperty("cel.spec.version")}",
"--exclude-path",
"cel/expr/conformance/proto2",
Expand All @@ -112,13 +126,13 @@ tasks.register<Exec>("generateCelConformance") {
// specified in these proto files is "dev.cel.expr.conformance.proto3". So, to get around this,
// we're generating these separately and specifying a java_package override of the package we need.
tasks.register<Exec>("generateCelConformanceTestTypes") {
dependsOn("exportProtovalidateModule")
dependsOn("exportProtovalidateModule", "filterBufGenYaml")
description = "Generates CEL conformance test types with buf generate for unit tests using a Java package override."
commandLine(
buf.asPath,
"generate",
"--template",
"src/test/resources/proto/buf.gen.cel.testtypes.yaml",
"${layout.buildDirectory.get()}/buf-gen-templates/src/test/resources/proto/buf.gen.cel.testtypes.yaml",
"buf.build/google/cel-spec:${project.findProperty("cel.spec.version")}",
"--path",
"cel/expr/conformance/proto3",
Expand Down Expand Up @@ -166,9 +180,9 @@ tasks.register<Exec>("exportProtovalidateModule") {
}

tasks.register<Exec>("generateSources") {
dependsOn("exportProtovalidateModule")
dependsOn("exportProtovalidateModule", "filterBufGenYaml")
description = "Generates sources for the bufbuild/protovalidate module sources to build/generated/sources/bufgen."
commandLine(buf.asPath, "generate", "--template", "buf.gen.yaml", "src/main/resources")
commandLine(buf.asPath, "generate", "--template", "${layout.buildDirectory.get()}/buf-gen-templates/buf.gen.yaml", "src/main/resources")
}

tasks.register("generate") {
Expand Down
2 changes: 1 addition & 1 deletion conformance/buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ managed:
- file_option: java_package_prefix
value: build
plugins:
- remote: buf.build/protocolbuffers/java:v31.1
- remote: buf.build/protocolbuffers/java:$protocJavaPluginVersion
out: build/generated/sources/bufgen
13 changes: 11 additions & 2 deletions conformance/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,23 @@ tasks.register<Exec>("conformance") {
commandLine(*(listOf(conformanceCLIPath) + conformanceArgs + listOf(conformanceAppScript)).toTypedArray())
}

tasks.register<Copy>("filterBufGenYaml") {
from(".")
include("buf.gen.yaml")
includeEmptyDirs = false
into(layout.buildDirectory.dir("buf-gen-templates"))
expand("protocJavaPluginVersion" to "v${libs.versions.protobuf.get().substringAfter('.')}")
filteringCharset = "UTF-8"
}

tasks.register<Exec>("generateConformance") {
dependsOn("configureBuf")
dependsOn("configureBuf", "filterBufGenYaml")
description = "Generates sources for the bufbuild/protovalidate-testing module to build/generated/sources/bufgen."
commandLine(
buf.asPath,
"generate",
"--template",
"buf.gen.yaml",
"${layout.buildDirectory.get()}/buf-gen-templates/buf.gen.yaml",
"buf.build/bufbuild/protovalidate-testing:${project.findProperty("protovalidate.version")}",
)
}
Expand Down
5 changes: 0 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ cel = "0.5.3"
error-prone = "2.38.0"
junit = "5.13.0"
maven-publish = "0.32.0"
# When updating, make sure to update versions in the following files to match and regenerate code with 'make generate'.
# - buf.gen.yaml
# - conformance/buf.gen.yaml
# - src/test/resources/proto/buf.gen.imports.yaml
# - src/test/resources/proto/buf.gen.noimports.yaml
protobuf = "4.31.1"

[libraries]
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/proto/buf.gen.cel.testtypes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ managed:
- file_option: java_package
value: cel.expr.conformance.proto3
plugins:
- remote: buf.build/protocolbuffers/java:v31.1
- remote: buf.build/protocolbuffers/java:$protocJavaPluginVersion
out: build/generated/test-sources/bufgen
2 changes: 1 addition & 1 deletion src/test/resources/proto/buf.gen.cel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ version: v2
managed:
enabled: true
plugins:
- remote: buf.build/protocolbuffers/java:v31.1
- remote: buf.build/protocolbuffers/java:$protocJavaPluginVersion
out: build/generated/test-sources/bufgen
2 changes: 1 addition & 1 deletion src/test/resources/proto/buf.gen.imports.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ managed:
- file_option: java_package_prefix
value: com.example.imports
plugins:
- remote: buf.build/protocolbuffers/java:v31.1
- remote: buf.build/protocolbuffers/java:$protocJavaPluginVersion
out: build/generated/test-sources/bufgen
inputs:
- directory: src/test/resources/proto
2 changes: 1 addition & 1 deletion src/test/resources/proto/buf.gen.noimports.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ managed:
- file_option: java_package_prefix
value: com.example.noimports
plugins:
- remote: buf.build/protocolbuffers/java:v31.1
- remote: buf.build/protocolbuffers/java:$protocJavaPluginVersion
out: build/generated/test-sources/bufgen
inputs:
- directory: src/main/resources
Expand Down