Skip to content

Commit

Permalink
Include Java's @deprecated annotation on RPC services or methods with…
Browse files Browse the repository at this point in the history
… `option deprecated = true;`
  • Loading branch information
elandau committed Aug 14, 2018
1 parent 6735208 commit 587732e
Show file tree
Hide file tree
Showing 7 changed files with 944 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
TestService.java.txt binary
TestServiceLite.java.txt binary
TestServiceNano.java.txt binary
TestDeprecatedService.java.txt binary
TestDeprecatedServiceLite.java.txt binary
TestDeprecatedServiceNano.java.txt binary
18 changes: 12 additions & 6 deletions compiler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ artifacts {
}
}

def configureTestTask(Task task, String dep, String extraPackage) {
def configureTestTask(Task task, String dep, String extraPackage, String serviceName) {
test.dependsOn task
task.dependsOn "generateTest${dep}Proto"
if (osdetector.os != 'windows') {
Expand All @@ -312,13 +312,19 @@ def configureTestTask(Task task, String dep, String extraPackage) {
}
// File isn't found on Windows if last slash is forward-slash
def slash = System.getProperty("file.separator")
task.args "$buildDir/generated/source/proto/test${dep}/grpc/io/grpc/testing/compiler${extraPackage}${slash}TestServiceGrpc.java",
"$projectDir/src/test${dep}/golden/TestService.java.txt"
task.args "$buildDir/generated/source/proto/test${dep}/grpc/io/grpc/testing/compiler${extraPackage}${slash}${serviceName}Grpc.java",
"$projectDir/src/test${dep}/golden/${serviceName}.java.txt"
}

task testGolden(type: Exec)
task testLiteGolden(type: Exec)
task testNanoGolden(type: Exec)
configureTestTask(testGolden, '', '')
configureTestTask(testLiteGolden, 'Lite', '')
configureTestTask(testNanoGolden, 'Nano', '/nano')
task testDeprecatedGolden(type: Exec)
task testDeprecatedLiteGolden(type: Exec)
task testDeprecatedNanoGolden(type: Exec)
configureTestTask(testGolden, '', '', 'TestService')
configureTestTask(testLiteGolden, 'Lite', '', 'TestService')
configureTestTask(testNanoGolden, 'Nano', '/nano', 'TestService')
configureTestTask(testDeprecatedGolden, '', '', 'TestDeprecatedService')
configureTestTask(testDeprecatedLiteGolden, 'Lite', '', 'TestDeprecatedService')
configureTestTask(testDeprecatedNanoGolden, 'Nano', '/nano', 'TestDeprecatedService')
20 changes: 19 additions & 1 deletion compiler/src/java_plugin/cpp/java_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <vector>
#include <google/protobuf/compiler/java/java_names.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream.h>

Expand Down Expand Up @@ -644,6 +645,11 @@ static void PrintStub(
if (!interface) {
GrpcWriteServiceDocComment(p, service);
}

if (service->options().deprecated()) {
p->Print(*vars, "@$Deprecated$\n");
}

if (impl_base) {
p->Print(
*vars,
Expand Down Expand Up @@ -713,6 +719,11 @@ static void PrintStub(
if (!interface) {
GrpcWriteMethodDocComment(p, method);
}

if (method->options().deprecated()) {
p->Print(*vars, "@$Deprecated$\n");
}

p->Print("public ");
switch (call_type) {
case BLOCKING_CALL:
Expand Down Expand Up @@ -1152,7 +1163,14 @@ static void PrintService(const ServiceDescriptor* service,
*vars,
"@$Generated$(\n"
" value = \"by gRPC proto compiler$grpc_version$\",\n"
" comments = \"Source: $file_name$\")\n"
" comments = \"Source: $file_name$\")\n");

if (service->options().deprecated()) {
p->Print(*vars, "@$Deprecated$\n");
}

p->Print(
*vars,
"public final class $service_class_name$ {\n\n");
p->Indent();
p->Print(
Expand Down

0 comments on commit 587732e

Please sign in to comment.