diff --git a/compiler/src/java_plugin/cpp/java_generator.cpp b/compiler/src/java_plugin/cpp/java_generator.cpp index cf844503567..00855df3d04 100644 --- a/compiler/src/java_plugin/cpp/java_generator.cpp +++ b/compiler/src/java_plugin/cpp/java_generator.cpp @@ -1128,12 +1128,26 @@ static void PrintService(const ServiceDescriptor* service, #endif // TODO(nmittler): Replace with WriteServiceDocComment once included by protobuf distro. GrpcWriteServiceDocComment(p, service, NONE); - p->Print( - *vars, - "@$Generated$(\n" - " value = \"by gRPC proto compiler$grpc_version$\",\n" - " comments = \"Source: $file_name$\")\n" - "@$GrpcGenerated$\n"); + + if ((*vars)["JakartaMode"] == "javax") { + p->Print( + *vars, + "@javax.annotation.Generated(\n" + " value = \"by gRPC proto compiler$grpc_version$\",\n" + " comments = \"Source: $file_name$\")\n" + "@$GrpcGenerated$\n"); + } else if ((*vars)["JakartaMode"] == "omit") { + p->Print( + *vars, + "@$GrpcGenerated$\n"); + } else { + p->Print( + *vars, + "@javax.annotation.Generated(\n" + " value = \"by gRPC proto compiler$grpc_version$\",\n" + " comments = \"Source: $file_name$\")\n" + "@$GrpcGenerated$\n"); + } if (service->options().deprecated()) { p->Print(*vars, "@$Deprecated$\n"); @@ -1217,7 +1231,8 @@ void PrintImports(Printer* p) { void GenerateService(const ServiceDescriptor* service, protobuf::io::ZeroCopyOutputStream* out, ProtoFlavor flavor, - bool disable_version) { + bool disable_version, + std::string jakarta_mode) { // All non-generated classes must be referred by fully qualified names to // avoid collision with generated classes. std::map vars; @@ -1249,7 +1264,7 @@ void GenerateService(const ServiceDescriptor* service, vars["MethodDescriptor"] = "io.grpc.MethodDescriptor"; vars["StreamObserver"] = "io.grpc.stub.StreamObserver"; vars["Iterator"] = "java.util.Iterator"; - vars["Generated"] = "javax.annotation.Generated"; + vars["JakartaMode"] = jakarta_mode; vars["GrpcGenerated"] = "io.grpc.stub.annotations.GrpcGenerated"; vars["ListenableFuture"] = "com.google.common.util.concurrent.ListenableFuture"; diff --git a/compiler/src/java_plugin/cpp/java_generator.h b/compiler/src/java_plugin/cpp/java_generator.h index f3ec49f8e27..d30179d334e 100644 --- a/compiler/src/java_plugin/cpp/java_generator.h +++ b/compiler/src/java_plugin/cpp/java_generator.h @@ -68,7 +68,8 @@ std::string ServiceClassName(const impl::protobuf::ServiceDescriptor* service); void GenerateService(const impl::protobuf::ServiceDescriptor* service, impl::protobuf::io::ZeroCopyOutputStream* out, ProtoFlavor flavor, - bool disable_version); + bool disable_version, + std::string jakarta_mode); } // namespace java_grpc_generator diff --git a/compiler/src/java_plugin/cpp/java_plugin.cpp b/compiler/src/java_plugin/cpp/java_plugin.cpp index 2eed9d260d1..36f22893f63 100644 --- a/compiler/src/java_plugin/cpp/java_plugin.cpp +++ b/compiler/src/java_plugin/cpp/java_plugin.cpp @@ -59,12 +59,23 @@ class JavaGrpcGenerator : public protobuf::compiler::CodeGenerator { java_grpc_generator::ProtoFlavor flavor = java_grpc_generator::ProtoFlavor::NORMAL; + /* + jakarta_mode has these values: + javax, the original behavior - add @javax.annotation.Generated + omit, "less controversial" = just add @io.grpc.stub.annotations.GrpcGenerated + and maybe others in the future + */ + std::string jakarta_mode; bool disable_version = false; for (size_t i = 0; i < options.size(); i++) { if (options[i].first == "lite") { flavor = java_grpc_generator::ProtoFlavor::LITE; } else if (options[i].first == "noversion") { disable_version = true; + } else if (options[i].first == "jakarta_javax") { + jakarta_mode = "javax"; + } else if (options[i].first == "jakarta_omit") { + jakarta_mode = "omit"; } } @@ -77,7 +88,7 @@ class JavaGrpcGenerator : public protobuf::compiler::CodeGenerator { std::unique_ptr output( context->Open(filename)); java_grpc_generator::GenerateService( - service, output.get(), flavor, disable_version); + service, output.get(), flavor, disable_version, jakarta_mode); } return true; }