Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add DIREGAPIC-specific pagination #767

Merged
merged 10 commits into from
Jun 17, 2021
28 changes: 28 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,34 @@ java_binary(
],
)

java_binary(
vam-google marked this conversation as resolved.
Show resolved Hide resolved
name = "protoc-gen-code_generator_request_dumper",
main_class = "com.google.api.generator.debug.CodeGeneratorRequestDumper",
runtime_deps = [
"//src/main/java/com/google/api/generator",
"//src/main/java/com/google/api/generator/debug",
"//src/main/java/com/google/api/generator/gapic",
"@com_google_googleapis//google/api:api_java_proto",
"@com_google_googleapis//google/longrunning:longrunning_java_proto",
"@com_google_guava_guava",
"@com_google_protobuf//:protobuf_java",
],
)

java_binary(
name = "protoc-gen-java_gapic_from_file",
main_class = "com.google.api.generator.debug.MainFromFile",
runtime_deps = [
"//src/main/java/com/google/api/generator",
"//src/main/java/com/google/api/generator/debug",
"//src/main/java/com/google/api/generator/gapic",
"@com_google_googleapis//google/api:api_java_proto",
"@com_google_googleapis//google/longrunning:longrunning_java_proto",
"@com_google_guava_guava",
"@com_google_protobuf//:protobuf_java",
],
)

# google-java-format
java_binary(
name = "google_java_format_binary",
Expand Down
67 changes: 54 additions & 13 deletions rules_java_gapic/java_gapic.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,18 @@ def _append_dep_without_duplicates(dest_deps, new_deps):
dest_deps.append(new_deps[i])
return dest_deps

def java_gapic_library(
def _java_gapic_srcjar(
name,
srcs,
grpc_service_config = None,
gapic_yaml = None,
service_yaml = None,
deps = [],
test_deps = [],
grpc_service_config,
gapic_yaml,
service_yaml,
# possible values are: "grpc", "rest", "grpc+rest"
transport = None,
transport,
# Can be used to provide a java_library with a customized generator,
# like the one which dumps descriptor to a file for future debugging.
_java_generator_name = "java_gapic",
java_generator_name = "java_gapic",
output_suffix = ".srcjar",
**kwargs):
file_args_dict = {}

Expand Down Expand Up @@ -159,8 +158,6 @@ def java_gapic_library(
else:
fail("Service.yaml is no longer supported in the Java microgenerator")

srcjar_name = name + "_srcjar"
raw_srcjar_name = srcjar_name + "_raw"
output_suffix = ".srcjar"
opt_args = []

Expand All @@ -172,18 +169,43 @@ def java_gapic_library(
plugin_args = ["metadata"]

proto_custom_library(
name = raw_srcjar_name,
name = name,
deps = srcs,
plugin = Label("@gapic_generator_java//:protoc-gen-%s" % _java_generator_name),
plugin = Label("@gapic_generator_java//:protoc-gen-%s" % java_generator_name),
plugin_args = plugin_args,
plugin_file_args = {},
opt_file_args = file_args_dict,
output_type = _java_generator_name,
output_type = java_generator_name,
output_suffix = output_suffix,
opt_args = opt_args,
**kwargs
)

def java_gapic_library(
name,
srcs,
grpc_service_config = None,
gapic_yaml = None,
service_yaml = None,
deps = [],
test_deps = [],
# possible values are: "grpc", "rest", "grpc+rest"
transport = None,
**kwargs):
srcjar_name = name + "_srcjar"
raw_srcjar_name = srcjar_name + "_raw"

_java_gapic_srcjar(
name = raw_srcjar_name,
srcs = srcs,
grpc_service_config = grpc_service_config,
gapic_yaml = gapic_yaml,
service_yaml = service_yaml,
transport = transport,
java_generator_name = "java_gapic",
**kwargs
)

_java_gapic_postprocess_srcjar(
name = srcjar_name,
gapic_srcjar = "%s.srcjar" % raw_srcjar_name,
Expand Down Expand Up @@ -282,3 +304,22 @@ def java_gapic_test(name, runtime_deps, test_classes, **kwargs):
tests = test_classes,
**kwargs
)

def java_generator_request_dump(
name,
srcs,
grpc_service_config = None,
gapic_yaml = None,
service_yaml = None,
transport = None,
**kwargs):
_java_gapic_srcjar(
name = name,
srcs = srcs,
grpc_service_config = grpc_service_config,
gapic_yaml = gapic_yaml,
service_yaml = service_yaml,
transport = transport,
java_generator_name = "code_generator_request_dumper",
**kwargs
)
6 changes: 2 additions & 4 deletions src/main/java/com/google/api/generator/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
import com.google.api.ResourceProto;
import com.google.api.generator.gapic.Generator;
import com.google.longrunning.OperationsProto;
import com.google.protobuf.Descriptors.DescriptorValidationException;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest;
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse;
import java.io.IOException;

public class Main {
public static void main(String[] args)
throws IOException, InterruptedException, DescriptorValidationException {
public static void main(String[] args) throws IOException {
ExtensionRegistry registry = ExtensionRegistry.newInstance();
registerAllExtensions(registry);
CodeGeneratorRequest request = CodeGeneratorRequest.parseFrom(System.in, registry);
Expand All @@ -37,7 +35,7 @@ public static void main(String[] args)
}

/** Register all extensions needed to process API protofiles. */
private static void registerAllExtensions(ExtensionRegistry extensionRegistry) {
public static void registerAllExtensions(ExtensionRegistry extensionRegistry) {
vam-google marked this conversation as resolved.
Show resolved Hide resolved
OperationsProto.registerAllExtensions(extensionRegistry);
AnnotationsProto.registerAllExtensions(extensionRegistry);
ClientProto.registerAllExtensions(extensionRegistry);
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/com/google/api/generator/debug/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
load("@rules_java//java:defs.bzl", "java_library", "java_plugin")

package(default_visibility = ["//visibility:public"])

filegroup(
name = "debug_files",
srcs = glob(["*.java"]),
)

java_library(
name = "debug",
srcs = [
":debug_files",
],
deps = [
"//src/main/java/com/google/api/generator",
"//src/main/java/com/google/api/generator/engine",
"//src/main/java/com/google/api/generator/engine/ast",
"//src/main/java/com/google/api/generator/gapic",
"//src/main/java/com/google/api/generator/gapic/model",
"//src/main/java/com/google/api/generator/util",
"@com_google_googleapis//google/api:api_java_proto",
"@com_google_googleapis//google/longrunning:longrunning_java_proto",
"@com_google_guava_guava//jar",
"@com_google_protobuf//:protobuf_java",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.api.generator.debug;

import com.google.api.generator.Main;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest;
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse;
import java.io.IOException;

public class CodeGeneratorRequestDumper {
vam-google marked this conversation as resolved.
Show resolved Hide resolved
public static void main(String[] args) throws IOException {
ExtensionRegistry registry = ExtensionRegistry.newInstance();
Main.registerAllExtensions(registry);
CodeGeneratorRequest request = CodeGeneratorRequest.parseFrom(System.in, registry);

CodeGeneratorResponse.Builder response = CodeGeneratorResponse.newBuilder();
response
.setSupportedFeatures(CodeGeneratorResponse.Feature.FEATURE_PROTO3_OPTIONAL_VALUE)
vam-google marked this conversation as resolved.
Show resolved Hide resolved
.addFileBuilder()
.setName("desc-dump.bin")
.setContentBytes(request.toByteString());
response.build().writeTo(System.out);
}
}
43 changes: 43 additions & 0 deletions src/main/java/com/google/api/generator/debug/MainFromFile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.api.generator.debug;

import com.google.api.generator.Main;
import com.google.api.generator.gapic.Generator;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest;
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class MainFromFile {
vam-google marked this conversation as resolved.
Show resolved Hide resolved
public static void main(String[] args) throws IOException {
ExtensionRegistry registry = ExtensionRegistry.newInstance();
Main.registerAllExtensions(registry);

String inputFile = args[0];
String outputFile = args[1];

try (InputStream inputStream = new FileInputStream(inputFile);
OutputStream outputStream = new FileOutputStream(outputFile)) {
CodeGeneratorRequest request = CodeGeneratorRequest.parseFrom(inputStream, registry);
CodeGeneratorResponse response = Generator.generateGapic(request);
response.writeTo(outputStream);
}
}
}
Loading