compiler: Remove enable_depreated option (#3541)

This commit is contained in:
ZHANG Dapeng 2017-10-05 14:14:57 -07:00 committed by GitHub
parent 5e36a8deb5
commit dba2323585
5 changed files with 17 additions and 120 deletions

View File

@ -133,9 +133,6 @@ subprojects {
task.inputs.file "${rootProject.projectDir}/build.gradle" task.inputs.file "${rootProject.projectDir}/build.gradle"
task.plugins { task.plugins {
grpc { grpc {
// To generate deprecated interfaces and static bindService method,
// turn the enable_deprecated option to true below:
option 'enable_deprecated=false'
option 'noversion' option 'noversion'
} }
} }

View File

@ -452,43 +452,11 @@ static void PrintBindServiceMethodBody(const ServiceDescriptor* service,
Printer* p, Printer* p,
bool generate_nano); bool generate_nano);
static void PrintDeprecatedDocComment(const ServiceDescriptor* service,
std::map<string, string>* vars,
Printer* p) {
p->Print(
*vars,
"/**\n"
" * This will be removed in the next release.\n"
" * If your code has been using gRPC-java v0.15.0 or higher already,\n"
" * the following changes to your code are suggested:\n"
" * <ul>\n"
" * <li> replace {@code extends/implements $service_name$}"
" with {@code extends $service_name$ImplBase} for server side;</li>\n"
" * <li> replace {@code $service_name$} with {@code $service_name$Stub} for client side;"
"</li>\n"
" * <li> replace usage of {@code $service_name$} with {@code $service_name$ImplBase};"
"</li>\n"
" * <li> replace usage of {@code Abstract$service_name$}"
" with {@link $service_name$ImplBase};</li>\n"
" * <li> replace"
" {@code serverBuilder.addService($service_class_name$.bindService(serviceImpl))}\n"
" * with {@code serverBuilder.addService(serviceImpl)};</li>\n"
" * <li> if you are mocking stubs using mockito, please do not mock them.\n"
" * See the documentation on testing with gRPC-java;</li>\n"
" * <li> replace {@code $service_name$BlockingClient}"
" with {@link $service_name$BlockingStub};</li>\n"
" * <li> replace {@code $service_name$FutureClient}"
" with {@link $service_name$FutureStub}.</li>\n"
" * </ul>\n"
" */\n");
}
// Prints a client interface or implementation class, or a server interface. // Prints a client interface or implementation class, or a server interface.
static void PrintStub( static void PrintStub(
const ServiceDescriptor* service, const ServiceDescriptor* service,
std::map<string, string>* vars, std::map<string, string>* vars,
Printer* p, StubType type, bool generate_nano, Printer* p, StubType type, bool generate_nano) {
bool enable_deprecated) {
const string service_name = service->name(); const string service_name = service->name();
(*vars)["service_name"] = service_name; (*vars)["service_name"] = service_name;
(*vars)["abstract_name"] = service_name + "ImplBase"; (*vars)["abstract_name"] = service_name + "ImplBase";
@ -537,35 +505,14 @@ static void PrintStub(
GrpcWriteServiceDocComment(p, service); GrpcWriteServiceDocComment(p, service);
} }
if (impl_base) { if (impl_base) {
if (enable_deprecated) {
p->Print(
*vars,
"public static abstract class $abstract_name$ implements $BindableService$, "
"$service_name$ {\n");
}
else {
p->Print( p->Print(
*vars, *vars,
"public static abstract class $abstract_name$ implements $BindableService$ {\n"); "public static abstract class $abstract_name$ implements $BindableService$ {\n");
}
} else {
if (enable_deprecated) {
if (interface) {
p->Print(
*vars,
"@$Deprecated$ public static interface $client_name$ {\n");
} else {
p->Print(
*vars,
"public static class $stub_name$ extends $AbstractStub$<$stub_name$>\n"
" implements $client_name$ {\n");
}
} else { } else {
p->Print( p->Print(
*vars, *vars,
"public static final class $stub_name$ extends $AbstractStub$<$stub_name$> {\n"); "public static final class $stub_name$ extends $AbstractStub$<$stub_name$> {\n");
} }
}
p->Indent(); p->Indent();
// Constructor and build() method // Constructor and build() method
@ -625,11 +572,6 @@ static void PrintStub(
// TODO(nmittler): Replace with WriteMethodDocComment once included by the protobuf distro. // TODO(nmittler): Replace with WriteMethodDocComment once included by the protobuf distro.
if (!interface) { if (!interface) {
GrpcWriteMethodDocComment(p, method); GrpcWriteMethodDocComment(p, method);
if (enable_deprecated) {
p->Print(
*vars,
"@$Override$\n");
}
} }
p->Print("public "); p->Print("public ");
switch (call_type) { switch (call_type) {
@ -784,8 +726,7 @@ static bool CompareMethodClientStreaming(const MethodDescriptor* method1,
static void PrintMethodHandlerClass(const ServiceDescriptor* service, static void PrintMethodHandlerClass(const ServiceDescriptor* service,
std::map<string, string>* vars, std::map<string, string>* vars,
Printer* p, Printer* p,
bool generate_nano, bool generate_nano) {
bool enable_deprecated) {
// Sort method ids based on client_streaming() so switch tables are compact. // Sort method ids based on client_streaming() so switch tables are compact.
std::vector<const MethodDescriptor*> sorted_methods(service->method_count()); std::vector<const MethodDescriptor*> sorted_methods(service->method_count());
for (int i = 0; i < service->method_count(); ++i) { for (int i = 0; i < service->method_count(); ++i) {
@ -802,11 +743,7 @@ static void PrintMethodHandlerClass(const ServiceDescriptor* service,
"private static final int $method_id_name$ = $method_id$;\n"); "private static final int $method_id_name$ = $method_id$;\n");
} }
p->Print("\n"); p->Print("\n");
if (enable_deprecated) {
(*vars)["service_name"] = service->name();
} else {
(*vars)["service_name"] = service->name() + "ImplBase"; (*vars)["service_name"] = service->name() + "ImplBase";
}
p->Print( p->Print(
*vars, *vars,
"private static final class MethodHandlers<Req, Resp> implements\n" "private static final class MethodHandlers<Req, Resp> implements\n"
@ -1059,7 +996,6 @@ static void PrintService(const ServiceDescriptor* service,
std::map<string, string>* vars, std::map<string, string>* vars,
Printer* p, Printer* p,
ProtoFlavor flavor, ProtoFlavor flavor,
bool enable_deprecated,
bool disable_version) { bool disable_version) {
(*vars)["service_name"] = service->name(); (*vars)["service_name"] = service->name();
(*vars)["file_name"] = service->file()->name(); (*vars)["file_name"] = service->file()->name();
@ -1131,38 +1067,12 @@ static void PrintService(const ServiceDescriptor* service,
p->Print("}\n\n"); p->Print("}\n\n");
bool generate_nano = flavor == ProtoFlavor::NANO; bool generate_nano = flavor == ProtoFlavor::NANO;
PrintStub(service, vars, p, ABSTRACT_CLASS, generate_nano, enable_deprecated); PrintStub(service, vars, p, ABSTRACT_CLASS, generate_nano);
PrintStub(service, vars, p, ASYNC_CLIENT_IMPL, generate_nano, enable_deprecated); PrintStub(service, vars, p, ASYNC_CLIENT_IMPL, generate_nano);
PrintStub(service, vars, p, BLOCKING_CLIENT_IMPL, generate_nano, enable_deprecated); PrintStub(service, vars, p, BLOCKING_CLIENT_IMPL, generate_nano);
PrintStub(service, vars, p, FUTURE_CLIENT_IMPL, generate_nano, enable_deprecated); PrintStub(service, vars, p, FUTURE_CLIENT_IMPL, generate_nano);
if (enable_deprecated) { PrintMethodHandlerClass(service, vars, p, generate_nano);
PrintDeprecatedDocComment(service, vars, p);
PrintStub(service, vars, p, ASYNC_INTERFACE, generate_nano, true);
PrintDeprecatedDocComment(service, vars, p);
PrintStub(service, vars, p, BLOCKING_CLIENT_INTERFACE, generate_nano, true);
PrintDeprecatedDocComment(service, vars, p);
PrintStub(service, vars, p, FUTURE_CLIENT_INTERFACE, generate_nano, true);
PrintDeprecatedDocComment(service, vars, p);
p->Print(
*vars,
"@$Deprecated$ public static abstract class Abstract$service_name$"
" extends $service_name$ImplBase {}\n\n");
// static bindService method
PrintDeprecatedDocComment(service, vars, p);
p->Print(
*vars,
"@$Deprecated$ public static $ServerServiceDefinition$ bindService("
"final $service_name$ serviceImpl) {\n");
(*vars)["instance"] = "serviceImpl";
PrintBindServiceMethodBody(service, vars, p, generate_nano);
p->Print(
*vars,
"}\n\n");
}
PrintMethodHandlerClass(service, vars, p, generate_nano, enable_deprecated);
PrintGetServiceDescriptorMethod(service, vars, p, flavor); PrintGetServiceDescriptorMethod(service, vars, p, flavor);
p->Outdent(); p->Outdent();
p->Print("}\n"); p->Print("}\n");
@ -1206,14 +1116,12 @@ void PrintImports(Printer* p, bool generate_nano) {
void GenerateService(const ServiceDescriptor* service, void GenerateService(const ServiceDescriptor* service,
google::protobuf::io::ZeroCopyOutputStream* out, google::protobuf::io::ZeroCopyOutputStream* out,
ProtoFlavor flavor, ProtoFlavor flavor,
bool enable_deprecated,
bool disable_version) { bool disable_version) {
// All non-generated classes must be referred by fully qualified names to // All non-generated classes must be referred by fully qualified names to
// avoid collision with generated classes. // avoid collision with generated classes.
std::map<string, string> vars; std::map<string, string> vars;
vars["String"] = "java.lang.String"; vars["String"] = "java.lang.String";
vars["Override"] = "java.lang.Override"; vars["Override"] = "java.lang.Override";
vars["Deprecated"] = "java.lang.Deprecated";
vars["Channel"] = "io.grpc.Channel"; vars["Channel"] = "io.grpc.Channel";
vars["CallOptions"] = "io.grpc.CallOptions"; vars["CallOptions"] = "io.grpc.CallOptions";
vars["MethodType"] = "io.grpc.MethodDescriptor.MethodType"; vars["MethodType"] = "io.grpc.MethodDescriptor.MethodType";
@ -1255,7 +1163,7 @@ void GenerateService(const ServiceDescriptor* service,
if (!vars["Package"].empty()) { if (!vars["Package"].empty()) {
vars["Package"].append("."); vars["Package"].append(".");
} }
PrintService(service, &vars, &printer, flavor, enable_deprecated, disable_version); PrintService(service, &vars, &printer, flavor, disable_version);
} }
string ServiceJavaPackage(const FileDescriptor* file, bool nano) { string ServiceJavaPackage(const FileDescriptor* file, bool nano) {

View File

@ -50,7 +50,6 @@ string ServiceClassName(const google::protobuf::ServiceDescriptor* service);
void GenerateService(const google::protobuf::ServiceDescriptor* service, void GenerateService(const google::protobuf::ServiceDescriptor* service,
google::protobuf::io::ZeroCopyOutputStream* out, google::protobuf::io::ZeroCopyOutputStream* out,
ProtoFlavor flavor, ProtoFlavor flavor,
bool enable_deprecated,
bool disable_version); bool disable_version);
} // namespace java_grpc_generator } // namespace java_grpc_generator

View File

@ -37,15 +37,12 @@ class JavaGrpcGenerator : public google::protobuf::compiler::CodeGenerator {
java_grpc_generator::ProtoFlavor flavor = java_grpc_generator::ProtoFlavor flavor =
java_grpc_generator::ProtoFlavor::NORMAL; java_grpc_generator::ProtoFlavor::NORMAL;
bool enable_deprecated = false;
bool disable_version = false; bool disable_version = false;
for (size_t i = 0; i < options.size(); i++) { for (size_t i = 0; i < options.size(); i++) {
if (options[i].first == "nano") { if (options[i].first == "nano") {
flavor = java_grpc_generator::ProtoFlavor::NANO; flavor = java_grpc_generator::ProtoFlavor::NANO;
} else if (options[i].first == "lite") { } else if (options[i].first == "lite") {
flavor = java_grpc_generator::ProtoFlavor::LITE; flavor = java_grpc_generator::ProtoFlavor::LITE;
} else if (options[i].first == "enable_deprecated") {
enable_deprecated = options[i].second == "true";
} else if (options[i].first == "noversion") { } else if (options[i].first == "noversion") {
disable_version = true; disable_version = true;
} }
@ -61,7 +58,7 @@ class JavaGrpcGenerator : public google::protobuf::compiler::CodeGenerator {
std::unique_ptr<google::protobuf::io::ZeroCopyOutputStream> output( std::unique_ptr<google::protobuf::io::ZeroCopyOutputStream> output(
context->Open(filename)); context->Open(filename));
java_grpc_generator::GenerateService( java_grpc_generator::GenerateService(
service, output.get(), flavor, enable_deprecated, disable_version); service, output.get(), flavor, disable_version);
} }
return true; return true;
} }

View File

@ -46,11 +46,7 @@ protobuf {
} }
generateProtoTasks { generateProtoTasks {
all()*.plugins { all()*.plugins {
grpc { grpc {}
// To generate deprecated interfaces and static bindService method,
// turn the enable_deprecated option to true below:
option 'enable_deprecated=false'
}
} }
} }
} }