From 0b53cb043fbf15db1a66f8be5f902e4e0e994f1d Mon Sep 17 00:00:00 2001 From: Harrison Cole Date: Thu, 16 May 2024 09:59:46 +1000 Subject: [PATCH 1/2] - compiler: add option @generated=jakarta --- compiler/src/java_plugin/cpp/java_generator.cpp | 11 +++++++---- compiler/src/java_plugin/cpp/java_generator.h | 2 +- compiler/src/java_plugin/cpp/java_plugin.cpp | 2 ++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/compiler/src/java_plugin/cpp/java_generator.cpp b/compiler/src/java_plugin/cpp/java_generator.cpp index 8693fad1b66..c5e85cd6d39 100644 --- a/compiler/src/java_plugin/cpp/java_generator.cpp +++ b/compiler/src/java_plugin/cpp/java_generator.cpp @@ -1135,13 +1135,16 @@ static void PrintService(const ServiceDescriptor* service, *vars, "@javax.annotation.Generated(\n" " value = \"by gRPC proto compiler$grpc_version$\",\n" - " comments = \"Source: $file_name$\")\n" - "@$GrpcGenerated$\n"); - } else { // GeneratedAnnotation::OMIT + " comments = \"Source: $file_name$\")\n"); + } else if generated_annotation == GeneratedAnnotation::JAKARTA) { p->Print( *vars, - "@$GrpcGenerated$\n"); + "@jakarta.annotation.Generated(\n" + " value = \"by gRPC proto compiler$grpc_version$\",\n" + " comments = \"Source: $file_name$\")\n"); } + // Always include @GrpcGenerated + p->Print(*vars, "@$GrpcGenerated$\n"); if (service->options().deprecated()) { p->Print(*vars, "@$Deprecated$\n"); diff --git a/compiler/src/java_plugin/cpp/java_generator.h b/compiler/src/java_plugin/cpp/java_generator.h index 857fcab31d0..abd28983302 100644 --- a/compiler/src/java_plugin/cpp/java_generator.h +++ b/compiler/src/java_plugin/cpp/java_generator.h @@ -58,7 +58,7 @@ enum ProtoFlavor { }; enum GeneratedAnnotation { - OMIT, JAVAX + OMIT, JAVAX, JAKARTA }; // Returns the package name of the gRPC services defined in the given file. diff --git a/compiler/src/java_plugin/cpp/java_plugin.cpp b/compiler/src/java_plugin/cpp/java_plugin.cpp index b1f407e2a3d..8b98ecf7494 100644 --- a/compiler/src/java_plugin/cpp/java_plugin.cpp +++ b/compiler/src/java_plugin/cpp/java_plugin.cpp @@ -72,6 +72,8 @@ class JavaGrpcGenerator : public protobuf::compiler::CodeGenerator { generated_annotation = java_grpc_generator::GeneratedAnnotation::OMIT; } else if (options[i].second == "javax") { generated_annotation = java_grpc_generator::GeneratedAnnotation::JAVAX; + } else if (options[i].second == "jakarta") { + generated_annotation = java_grpc_generator::GeneratedAnnotation::JAKARTA; } } } From 4383915347d2519bd4c57df88696ab4ffa1a9d00 Mon Sep 17 00:00:00 2001 From: Harrison Cole Date: Thu, 16 May 2024 10:10:23 +1000 Subject: [PATCH 2/2] - add missing parentheses. --- compiler/src/java_plugin/cpp/java_generator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/java_plugin/cpp/java_generator.cpp b/compiler/src/java_plugin/cpp/java_generator.cpp index c5e85cd6d39..dca7f51bf71 100644 --- a/compiler/src/java_plugin/cpp/java_generator.cpp +++ b/compiler/src/java_plugin/cpp/java_generator.cpp @@ -1136,7 +1136,7 @@ static void PrintService(const ServiceDescriptor* service, "@javax.annotation.Generated(\n" " value = \"by gRPC proto compiler$grpc_version$\",\n" " comments = \"Source: $file_name$\")\n"); - } else if generated_annotation == GeneratedAnnotation::JAKARTA) { + } else if (generated_annotation == GeneratedAnnotation::JAKARTA) { p->Print( *vars, "@jakarta.annotation.Generated(\n"