Skip to content

Commit 8983e23

Browse files
committed
feat: implement DIREGAPIC
1 parent 8f6f40e commit 8983e23

63 files changed

Lines changed: 7458 additions & 123 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

BUILD.bazel

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,32 @@ java_binary(
4545
],
4646
)
4747

48+
java_binary(
49+
name = "protoc-gen-java_dumper",
50+
main_class = "com.google.api.generator.MainDumper",
51+
runtime_deps = [
52+
"//src/main/java/com/google/api/generator",
53+
"//src/main/java/com/google/api/generator/gapic",
54+
"@com_google_googleapis//google/api:api_java_proto",
55+
"@com_google_googleapis//google/longrunning:longrunning_java_proto",
56+
"@com_google_guava_guava",
57+
"@com_google_protobuf//:protobuf_java",
58+
],
59+
)
60+
61+
java_binary(
62+
name = "protoc-gen-java_gapicfromfile",
63+
main_class = "com.google.api.generator.MainFromFile",
64+
runtime_deps = [
65+
"//src/main/java/com/google/api/generator",
66+
"//src/main/java/com/google/api/generator/gapic",
67+
"@com_google_googleapis//google/api:api_java_proto",
68+
"@com_google_googleapis//google/longrunning:longrunning_java_proto",
69+
"@com_google_guava_guava",
70+
"@com_google_protobuf//:protobuf_java",
71+
],
72+
)
73+
4874
# google-java-format
4975
java_binary(
5076
name = "google_java_format_binary",

WORKSPACE

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
workspace(name = "gapic_generator_java")
22

33
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4+
load("@bazel_tools//tools/build_defs/repo:jvm.bzl", "jvm_maven_import_external")
45

56
# DO NOT REMOVE.
67
# This is needed to clobber any transitively-pulled in versions of bazel_skylib so that packages
@@ -14,6 +15,32 @@ http_archive(
1415
],
1516
)
1617

18+
jvm_maven_import_external(
19+
name = "google_java_format_all_deps",
20+
artifact = "com.google.googlejavaformat:google-java-format:jar:all-deps:1.7",
21+
server_urls = ["https://repo.maven.apache.org/maven2/", "http://repo1.maven.org/maven2/"],
22+
licenses = ["notice", "reciprocal"]
23+
)
24+
25+
_gax_java_version = "1.64.0"
26+
27+
http_archive(
28+
name = "com_google_api_gax_java",
29+
strip_prefix = "gax-java-%s" % _gax_java_version,
30+
urls = ["https://github.com/googleapis/gax-java/archive/v%s.zip" % _gax_java_version],
31+
)
32+
33+
load("@com_google_api_gax_java//:repository_rules.bzl", "com_google_api_gax_java_properties")
34+
35+
com_google_api_gax_java_properties(
36+
name = "com_google_api_gax_java_properties",
37+
file = "@com_google_api_gax_java//:dependencies.properties",
38+
)
39+
40+
load("@com_google_api_gax_java//:repositories.bzl", "com_google_api_gax_java_repositories")
41+
42+
com_google_api_gax_java_repositories()
43+
1744
load("//:repository_rules.bzl", "gapic_generator_java_properties")
1845

1946
gapic_generator_java_properties(
@@ -35,8 +62,8 @@ protobuf_deps()
3562
# Import the monolith so we can transitively use its gapic rules for googleapis.
3663
http_archive(
3764
name = "com_google_api_codegen",
38-
strip_prefix = "gapic-generator-2.4.6",
39-
urls = ["https://github.com/googleapis/gapic-generator/archive/v2.4.6.zip"],
65+
strip_prefix = "gapic-generator-2.11.1",
66+
urls = ["https://github.com/googleapis/gapic-generator/archive/v2.11.1.zip"],
4067
)
4168

4269
load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language")
@@ -48,25 +75,12 @@ switched_rules_by_language(
4875
java = True,
4976
)
5077

51-
_gax_java_version = PROPERTIES["version.com_google_gax_java"]
52-
53-
http_archive(
54-
name = "com_google_api_gax_java",
55-
strip_prefix = "gax-java-%s" % _gax_java_version,
56-
urls = ["https://github.com/googleapis/gax-java/archive/v%s.zip" % _gax_java_version],
57-
)
58-
59-
load("@com_google_api_gax_java//:repository_rules.bzl", "com_google_api_gax_java_properties")
60-
61-
com_google_api_gax_java_properties(
62-
name = "com_google_api_gax_java_properties",
63-
file = "@com_google_api_gax_java//:dependencies.properties",
64-
)
65-
66-
load("@com_google_api_gax_java//:repositories.bzl", "com_google_api_gax_java_repositories")
67-
68-
com_google_api_gax_java_repositories()
69-
7078
load("@io_grpc_grpc_java//:repositories.bzl", "grpc_java_repositories")
7179

7280
grpc_java_repositories()
81+
82+
http_archive(
83+
name = "com_google_disco_to_proto3_converter",
84+
strip_prefix = "disco-to-proto3-converter-1839f6aca5e968e59b7acc03e7018b0fda8c480b",
85+
urls = ["https://github.com/googleapis/disco-to-proto3-converter/archive/1839f6aca5e968e59b7acc03e7018b0fda8c480b.zip"],
86+
)

dependencies.properties

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
# Target workspace name: com_google_api_codegen
88

99
# Versions only, for dependencies which actual artifacts differ between Bazel and Gradle
10-
version.com_google_protobuf=3.13.0
10+
version.com_google_protobuf=3.15.2
1111
# Version of google-java-format is downgraded from 1.8 to 1.7, because 1.8 supports java 11 minimum, while our JRE is java 8.
1212
version.google_java_format=1.7
1313
version.com_google_api_common_java=1.9.3
14-
version.com_google_gax_java=1.62.0
1514
version.io_grpc_java=1.30.2
1615

1716
# Common deps.
@@ -20,7 +19,7 @@ maven.com_google_code_findbugs_jsr305=com.google.code.findbugs:jsr305:3.0.0
2019
maven.com_google_auto_value_auto_value=com.google.auto.value:auto-value:1.7.2
2120
maven.com_google_auto_value_auto_value_annotations=com.google.auto.value:auto-value-annotations:1.7.2
2221
maven.com_google_code_gson=com.google.code.gson:gson:2.8.6
23-
maven.com_google_protobuf_protobuf_java=com.google.protobuf:protobuf-java:3.12.2
22+
maven.com_google_protobuf_protobuf_java=com.google.protobuf:protobuf-java:3.15.8
2423
maven.io_github_java_diff_utils=io.github.java-diff-utils:java-diff-utils:4.0
2524
maven.javax_annotation_javax_annotation_api=javax.annotation:javax.annotation-api:1.3.2
2625
maven.javax_validation_javax_validation_api=javax.validation:validation-api:2.0.1.Final

repositories.bzl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,18 @@ def gapic_generator_java_repositories():
5959
_maybe(
6060
http_archive,
6161
name = "com_google_googleapis",
62-
strip_prefix = "googleapis-2bea43cdc7a4443876380732980d83cd8d560582",
62+
strip_prefix = "googleapis-0b26f05c9f469dc710e13a94f10d46dae4fa0b3c",
6363
urls = [
64-
"https://github.com/googleapis/googleapis/archive/2bea43cdc7a4443876380732980d83cd8d560582.zip",
64+
"https://github.com/googleapis/googleapis/archive/0b26f05c9f469dc710e13a94f10d46dae4fa0b3c.zip",
6565
],
6666
)
6767

68+
_maybe(
69+
native.local_repository,
70+
name = "com_google_googleapis_discovery",
71+
path = "/usr/local/google/home/vam/_/projects/_/googleapis-discovery"
72+
)
73+
6874
_maybe(
6975
native.bind,
7076
name = "guava",

rules_java_gapic/java_gapic.bzl

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,14 @@ def java_gapic_library(
127127
service_yaml = None,
128128
deps = [],
129129
test_deps = [],
130+
transport = None,
131+
java_generator_name = "java_gapic",
130132
**kwargs):
131133
file_args_dict = {}
132134

133135
if grpc_service_config:
134136
file_args_dict[grpc_service_config] = "grpc-service-config"
135-
else:
137+
elif transport != "rest":
136138
for keyword in NO_GRPC_CONFIG_ALLOWLIST:
137139
if keyword not in name:
138140
fail("Missing a gRPC service config file")
@@ -157,21 +159,25 @@ def java_gapic_library(
157159
srcjar_name = name + "_srcjar"
158160
raw_srcjar_name = srcjar_name + "_raw"
159161
output_suffix = ".srcjar"
162+
opt_args = []
163+
164+
if transport:
165+
opt_args.append("transport=%s" % transport)
160166

161167
# Produces the GAPIC metadata file if this flag is set. to any value.
162168
# Protoc invocation: --java_gapic_opt=metadata
163169
plugin_args = ["metadata"]
164170

165-
_java_generator_name = "java_gapic"
166171
proto_custom_library(
167172
name = raw_srcjar_name,
168173
deps = srcs,
169-
plugin = Label("@gapic_generator_java//:protoc-gen-%s" % _java_generator_name),
174+
plugin = Label("@gapic_generator_java//:protoc-gen-%s" % java_generator_name),
170175
plugin_args = plugin_args,
171176
plugin_file_args = {},
172177
opt_file_args = file_args_dict,
173-
output_type = _java_generator_name,
178+
output_type = java_generator_name,
174179
output_suffix = output_suffix,
180+
opt_args = opt_args,
175181
**kwargs
176182
)
177183

@@ -201,10 +207,7 @@ def java_gapic_library(
201207
"@com_google_protobuf//:protobuf_java",
202208
"@com_google_api_api_common//jar",
203209
"@com_google_api_gax_java//gax:gax",
204-
"@com_google_api_gax_java//gax-grpc:gax_grpc",
205210
"@com_google_guava_guava//jar",
206-
"@io_grpc_grpc_java//core:core",
207-
"@io_grpc_grpc_java//protobuf:protobuf",
208211
"@com_google_code_findbugs_jsr305//jar",
209212
"@org_threeten_threetenbp//jar",
210213
"@io_opencensus_opencensus_api//jar",
@@ -214,6 +217,17 @@ def java_gapic_library(
214217
"@javax_annotation_javax_annotation_api//jar",
215218
]
216219

220+
if transport == "rest":
221+
actual_deps += [
222+
"@com_google_api_gax_java//gax-httpjson:gax_httpjson",
223+
]
224+
else:
225+
actual_deps += [
226+
"@com_google_api_gax_java//gax-grpc:gax_grpc",
227+
"@io_grpc_grpc_java//core:core",
228+
"@io_grpc_grpc_java//protobuf:protobuf",
229+
]
230+
217231
native.java_library(
218232
name = name,
219233
srcs = ["%s.srcjar" % srcjar_name],
@@ -224,15 +238,24 @@ def java_gapic_library(
224238
# Test deps.
225239
actual_test_deps = [
226240
"@com_google_googleapis//google/type:type_java_proto", # Commonly used.
227-
"@com_google_api_gax_java//gax-grpc:gax_grpc_testlib",
228241
"@com_google_api_gax_java//gax:gax_testlib",
229242
"@com_google_code_gson_gson//jar",
230-
"@io_grpc_grpc_java//auth:auth",
231-
"@io_grpc_grpc_netty_shaded//jar",
232-
"@io_grpc_grpc_java//stub:stub",
233-
"@io_opencensus_opencensus_contrib_grpc_metrics//jar",
234243
"@junit_junit//jar",
235244
]
245+
246+
if transport == "rest":
247+
actual_test_deps += [
248+
"@com_google_api_gax_java//gax-httpjson:gax_httpjson_testlib",
249+
]
250+
else:
251+
actual_test_deps += [
252+
"@com_google_api_gax_java//gax-grpc:gax_grpc_testlib",
253+
"@io_grpc_grpc_java//auth:auth",
254+
"@io_grpc_grpc_netty_shaded//jar",
255+
"@io_grpc_grpc_java//stub:stub",
256+
"@io_opencensus_opencensus_contrib_grpc_metrics//jar",
257+
]
258+
236259
_append_dep_without_duplicates(actual_test_deps, test_deps)
237260
_append_dep_without_duplicates(actual_test_deps, actual_deps)
238261

rules_java_gapic/java_gapic_pkg.bzl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ def java_gapic_assembly_gradle_pkg(
301301
name,
302302
deps,
303303
assembly_name = None,
304+
transport = None,
304305
**kwargs):
305306
package_dir = name
306307
if assembly_name:
@@ -350,9 +351,14 @@ def java_gapic_assembly_gradle_pkg(
350351
grpc_target_dep = ["%s" % grpc_target]
351352

352353
if client_deps:
354+
if transport == "rest":
355+
template_label = Label("//rules_java_gapic:resources/gradle/client_rest.gradle.tmpl")
356+
else:
357+
template_label = Label("//rules_java_gapic:resources/gradle/client_grpc.gradle.tmpl")
358+
353359
_java_gapic_gradle_pkg(
354360
name = client_target,
355-
template_label = Label("//rules_java_gapic:resources/gradle/client.gradle.tmpl"),
361+
template_label = template_label,
356362
deps = proto_target_dep + client_deps,
357363
test_deps = grpc_target_dep + client_test_deps,
358364
**kwargs

rules_java_gapic/resources/gradle/client.gradle.tmpl renamed to rules_java_gapic/resources/gradle/client_grpc.gradle.tmpl

File renamed without changes.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
buildscript {
2+
repositories {
3+
mavenCentral()
4+
}
5+
}
6+
7+
apply plugin: 'java'
8+
9+
description = 'GAPIC library for {{name}}'
10+
group = 'com.google.cloud'
11+
version = (findProperty('version') == 'unspecified') ? '0.0.0-SNAPSHOT' : version
12+
sourceCompatibility = 1.7
13+
targetCompatibility = 1.7
14+
15+
repositories {
16+
mavenCentral()
17+
mavenLocal()
18+
}
19+
20+
compileJava.options.encoding = 'UTF-8'
21+
javadoc.options.encoding = 'UTF-8'
22+
23+
dependencies {
24+
compile 'com.google.api:gax:{{version.gax}}'
25+
testCompile 'com.google.api:gax:{{version.gax}}:testlib'
26+
compile 'com.google.api:gax-httpjson:{{version.gax_httpjson}}'
27+
testCompile 'com.google.api:gax-httpjson:{{version.gax_httpjson}}:testlib'
28+
testCompile '{{maven.junit_junit}}'
29+
{{extra_deps}}
30+
}
31+
32+
task smokeTest(type: Test) {
33+
filter {
34+
includeTestsMatching "*SmokeTest"
35+
setFailOnNoMatchingTests false
36+
}
37+
}
38+
39+
test {
40+
exclude "**/*SmokeTest*"
41+
}
42+
43+
sourceSets {
44+
main {
45+
java {
46+
srcDir 'src/main/java'
47+
}
48+
}
49+
}
50+
51+
clean {
52+
delete 'all-jars'
53+
}
54+
55+
task allJars(type: Copy) {
56+
dependsOn test, jar
57+
into 'all-jars'
58+
// Replace with `from configurations.testRuntime, jar` to include test dependencies
59+
from configurations.runtime, jar
60+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2021 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.api.generator;
16+
17+
import com.google.api.AnnotationsProto;
18+
import com.google.api.ClientProto;
19+
import com.google.api.FieldBehaviorProto;
20+
import com.google.api.ResourceProto;
21+
import com.google.longrunning.OperationsProto;
22+
import com.google.protobuf.ExtensionRegistry;
23+
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest;
24+
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse;
25+
import java.io.IOException;
26+
27+
public class MainDumper {
28+
public static void main(String[] args) throws IOException {
29+
ExtensionRegistry registry = ExtensionRegistry.newInstance();
30+
registerAllExtensions(registry);
31+
CodeGeneratorRequest request = CodeGeneratorRequest.parseFrom(System.in, registry);
32+
33+
CodeGeneratorResponse.Builder response = CodeGeneratorResponse.newBuilder();
34+
response
35+
.setSupportedFeatures(CodeGeneratorResponse.Feature.FEATURE_PROTO3_OPTIONAL_VALUE)
36+
.addFileBuilder()
37+
.setName("desc-dump.bin")
38+
.setContentBytes(request.toByteString());
39+
response.build().writeTo(System.out);
40+
}
41+
42+
/** Register all extensions needed to process API protofiles. */
43+
private static void registerAllExtensions(ExtensionRegistry extensionRegistry) {
44+
OperationsProto.registerAllExtensions(extensionRegistry);
45+
AnnotationsProto.registerAllExtensions(extensionRegistry);
46+
ClientProto.registerAllExtensions(extensionRegistry);
47+
ResourceProto.registerAllExtensions(extensionRegistry);
48+
FieldBehaviorProto.registerAllExtensions(extensionRegistry);
49+
}
50+
}

0 commit comments

Comments
 (0)