Skip to content

Commit 269a915

Browse files
authored
chore: generate non-cloud client library (#1770)
* chore: add proto group prefix * add test case for generating google maps * run new tests in ci * parameterize group id for proto artifacts * use helper to compute group id of proto artifacts * verify non cloud library generation * change artifact name in golden * restore new client test * change description * change description * add comments to _proto_group_id
1 parent 4c15ec0 commit 269a915

File tree

20 files changed

+771
-11
lines changed

20 files changed

+771
-11
lines changed

docker/owlbot/java/cloudbuild_test.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ steps:
3939
args: ["diff", "-rw", "input", "golden"]
4040
dir: docker/owlbot/java/tests/new-client
4141
waitFor: ["new-client-run"]
42+
- name: "gcr.io/$PROJECT_ID/owlbot-java:$SHORT_SHA"
43+
dir: docker/owlbot/java/tests/new-client-maps/input
44+
id: "new-client-maps-run"
45+
waitFor: [ "build" ]
46+
- name: "bash"
47+
args: [ "diff", "-rw", "input", "golden" ]
48+
dir: docker/owlbot/java/tests/new-client-maps
49+
waitFor: [ "new-client-maps-run" ]
4250
- name: "gcr.io/$PROJECT_ID/owlbot-java:$SHORT_SHA"
4351
dir: docker/owlbot/java/tests/new-version/input
4452
id: "new-version-run"

docker/owlbot/java/src/fix-poms.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def load_versions(filename: str, default_group_id: str) -> Mapping[str, module.M
3939
group_id = (
4040
default_group_id
4141
if artifact_id.startswith("google-")
42-
else "com.google.api.grpc"
42+
else _proto_group_id(default_group_id)
4343
)
4444
modules[artifact_id] = module.Module(
4545
group_id=group_id,
@@ -274,6 +274,18 @@ def update_bom_pom(filename: str, modules: List[module.Module]):
274274

275275
tree.write(filename, pretty_print=True, xml_declaration=True, encoding="utf-8")
276276

277+
278+
# When generating non-cloud client library, the group id of proto/grpc artifacts
279+
# is prefixed with `{main_artifact_group_id}.api.grpc`, rather than
280+
# `com.google.api.grpc`.
281+
# https://github.com/googleapis/google-cloud-java/issues/9125
282+
def _proto_group_id(main_artifact_group_id: str) -> str:
283+
prefix = "com.google" \
284+
if main_artifact_group_id == "com.google.cloud" \
285+
else main_artifact_group_id
286+
return f"{prefix}.api.grpc"
287+
288+
277289
def main():
278290
print(f"working directory: {os.getcwd()}")
279291
with open(".repo-metadata.json", "r") as fp:
@@ -353,15 +365,15 @@ def main():
353365
for path in glob.glob("proto-google-*"):
354366
if not path in existing_modules:
355367
existing_modules[path] = module.Module(
356-
group_id="com.google.api.grpc",
368+
group_id=_proto_group_id(group_id),
357369
artifact_id=path,
358370
version=main_module.version,
359371
release_version=main_module.release_version,
360372
)
361373
if path not in excluded_dependencies_list \
362374
and path not in main_module.artifact_id:
363375
required_dependencies[path] = module.Module(
364-
group_id="com.google.api.grpc",
376+
group_id=_proto_group_id(group_id),
365377
artifact_id=path,
366378
version=main_module.version,
367379
release_version=main_module.release_version,
@@ -378,29 +390,29 @@ def main():
378390
if path not in excluded_dependencies_list \
379391
and path not in main_module.artifact_id:
380392
required_dependencies[path] = module.Module(
381-
group_id="com.google.api.grpc",
393+
group_id=_proto_group_id(group_id),
382394
artifact_id=path,
383395
version=main_module.version,
384396
release_version=main_module.release_version,
385397
)
386-
398+
387399
for path in glob.glob("grpc-google-*"):
388400
if not path in existing_modules:
389401
existing_modules[path] = module.Module(
390-
group_id="com.google.api.grpc",
402+
group_id=_proto_group_id(group_id),
391403
artifact_id=path,
392404
version=main_module.version,
393405
release_version=main_module.release_version,
394406
)
395407
if path not in excluded_dependencies_list \
396408
and path not in main_module.artifact_id:
397409
required_dependencies[path] = module.Module(
398-
group_id="com.google.api.grpc",
410+
group_id=_proto_group_id(group_id),
399411
artifact_id=path,
400412
version=main_module.version,
401413
release_version=main_module.release_version,
402414
)
403-
415+
404416
if not os.path.isfile(f"{path}/pom.xml"):
405417
proto_artifact_id = path.replace("grpc-", "proto-")
406418
print(f"creating missing grpc pom: {path}")
@@ -415,7 +427,7 @@ def main():
415427
if path not in excluded_dependencies_list \
416428
and path not in main_module.artifact_id:
417429
required_dependencies[path] = module.Module(
418-
group_id="com.google.api.grpc",
430+
group_id=_proto_group_id(group_id),
419431
artifact_id=path,
420432
version=main_module.version,
421433
release_version=main_module.release_version,
@@ -498,7 +510,7 @@ def main():
498510
for dependency_module in extra_managed_modules:
499511
if dependency_module not in existing_modules:
500512
existing_modules[dependency_module] = module.Module(
501-
group_id="com.google.api.grpc",
513+
group_id=_proto_group_id(group_id),
502514
artifact_id=dependency_module,
503515
version=main_module.version,
504516
release_version=main_module.release_version,
@@ -507,5 +519,6 @@ def main():
507519
template_name="versions.txt.j2", output_name=versions_txt_file, modules=existing_modules.values(),
508520
)
509521

522+
510523
if __name__ == "__main__":
511524
main()

docker/owlbot/java/templates/poms/cloud_pom.xml.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
</dependency>
4444
{% for module in proto_modules %}
4545
<dependency>
46-
<groupId>com.google.api.grpc</groupId>
46+
<groupId>{{module.group_id}}</groupId>
4747
<artifactId>{{module.artifact_id}}</artifactId>
4848
</dependency>{% endfor %}
4949
<dependency>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "maps",
3+
"name_pretty": "Example API",
4+
"product_documentation": "https://maps.google.com/foo/",
5+
"api_description": "is an example API",
6+
"client_documentation": "https://googleapis.dev/java/google-maps-foo/latest/index.html",
7+
"release_level": "beta",
8+
"transport": "grpc",
9+
"language": "java",
10+
"repo": "googleapis/java-maps",
11+
"repo_short": "java-maps",
12+
"distribution_name": "com.google.maps:google-maps-foo",
13+
"api_id": "maps.googleapis.com",
14+
"requires_billing": true
15+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?xml version="1.0"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.google.maps</groupId>
5+
<artifactId>google-maps-foo-bom</artifactId>
6+
<version>0.0.1-SNAPSHOT</version><!-- {x-version-update:google-maps-foo:current} -->
7+
<packaging>pom</packaging>
8+
<parent>
9+
<groupId>com.google.cloud</groupId>
10+
<artifactId>google-cloud-shared-config</artifactId>
11+
<version>1.5.3</version>
12+
</parent>
13+
14+
<name>Google Example API BOM</name>
15+
<url>https://github.com/googleapis/java-maps</url>
16+
<description>
17+
BOM for Example API
18+
</description>
19+
20+
<organization>
21+
<name>Google LLC</name>
22+
</organization>
23+
24+
<developers>
25+
<developer>
26+
<id>chingor13</id>
27+
<name>Jeff Ching</name>
28+
<email>[email protected]</email>
29+
<organization>Google LLC</organization>
30+
<roles>
31+
<role>Developer</role>
32+
</roles>
33+
</developer>
34+
<developer>
35+
<id>neenushaji</id>
36+
<name>Neenu Shaji</name>
37+
<email>[email protected]</email>
38+
<organization>Google LLC</organization>
39+
<roles>
40+
<role>Developer</role>
41+
</roles>
42+
</developer>
43+
</developers>
44+
45+
<scm>
46+
<connection>scm:git:https://github.com/googleapis/java-maps.git</connection>
47+
<developerConnection>scm:git:[email protected]:googleapis/java-maps.git</developerConnection>
48+
<url>https://github.com/googleapis/java-maps</url>
49+
</scm>
50+
51+
<properties>
52+
<maven.antrun.skip>true</maven.antrun.skip>
53+
</properties>
54+
55+
<licenses>
56+
<license>
57+
<name>The Apache Software License, Version 2.0</name>
58+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
59+
<distribution>repo</distribution>
60+
</license>
61+
</licenses>
62+
63+
<dependencyManagement>
64+
<dependencies>
65+
<dependency>
66+
<groupId>com.google.maps</groupId>
67+
<artifactId>google-maps-foo</artifactId>
68+
<version>0.0.1-SNAPSHOT</version><!-- {x-version-update:google-maps-foo:current} -->
69+
</dependency>
70+
<dependency>
71+
<groupId>com.google.maps.api.grpc</groupId>
72+
<artifactId>grpc-google-maps-foo-v1</artifactId>
73+
<version>0.0.1-SNAPSHOT</version><!-- {x-version-update:grpc-google-maps-foo-v1:current} -->
74+
</dependency>
75+
<dependency>
76+
<groupId>com.google.maps.api.grpc</groupId>
77+
<artifactId>proto-google-maps-foo-v1</artifactId>
78+
<version>0.0.1-SNAPSHOT</version><!-- {x-version-update:proto-google-maps-foo-v1:current} -->
79+
</dependency>
80+
</dependencies>
81+
</dependencyManagement>
82+
83+
<build>
84+
<plugins>
85+
<plugin>
86+
<groupId>org.apache.maven.plugins</groupId>
87+
<artifactId>maven-checkstyle-plugin</artifactId>
88+
<configuration>
89+
<skip>true</skip>
90+
</configuration>
91+
</plugin>
92+
</plugins>
93+
</build>
94+
</project>
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<?xml version="1.0"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.google.maps</groupId>
5+
<artifactId>google-maps-foo</artifactId>
6+
<version>0.0.1-SNAPSHOT</version><!-- {x-version-update:google-maps-foo:current} -->
7+
<packaging>jar</packaging>
8+
<name>Google Example API</name>
9+
<url>https://github.com/googleapis/java-maps</url>
10+
<description>Example API is an example API</description>
11+
<parent>
12+
<groupId>com.google.maps</groupId>
13+
<artifactId>google-maps-foo-parent</artifactId>
14+
<version>0.0.1-SNAPSHOT</version><!-- {x-version-update:google-maps-foo:current} -->
15+
</parent>
16+
<properties>
17+
<site.installationModule>google-maps-foo</site.installationModule>
18+
</properties>
19+
<dependencies>
20+
<dependency>
21+
<groupId>io.grpc</groupId>
22+
<artifactId>grpc-api</artifactId>
23+
</dependency>
24+
<dependency>
25+
<groupId>io.grpc</groupId>
26+
<artifactId>grpc-stub</artifactId>
27+
</dependency>
28+
<dependency>
29+
<groupId>io.grpc</groupId>
30+
<artifactId>grpc-protobuf</artifactId>
31+
</dependency>
32+
<dependency>
33+
<groupId>com.google.api</groupId>
34+
<artifactId>api-common</artifactId>
35+
</dependency>
36+
<dependency>
37+
<groupId>com.google.protobuf</groupId>
38+
<artifactId>protobuf-java</artifactId>
39+
</dependency>
40+
<dependency>
41+
<groupId>com.google.api.grpc</groupId>
42+
<artifactId>proto-google-common-protos</artifactId>
43+
</dependency>
44+
45+
<dependency>
46+
<groupId>com.google.maps.api.grpc</groupId>
47+
<artifactId>proto-google-maps-foo-v1</artifactId>
48+
</dependency>
49+
<dependency>
50+
<groupId>com.google.guava</groupId>
51+
<artifactId>guava</artifactId>
52+
</dependency>
53+
<dependency>
54+
<groupId>com.google.api</groupId>
55+
<artifactId>gax</artifactId>
56+
</dependency>
57+
<dependency>
58+
<groupId>com.google.api</groupId>
59+
<artifactId>gax-grpc</artifactId>
60+
</dependency>
61+
<dependency>
62+
<groupId>com.google.api</groupId>
63+
<artifactId>gax-httpjson</artifactId>
64+
</dependency>
65+
<dependency>
66+
<groupId>com.google.api.grpc</groupId>
67+
<artifactId>grpc-google-common-protos</artifactId>
68+
</dependency>
69+
<dependency>
70+
<groupId>com.google.api.grpc</groupId>
71+
<artifactId>proto-google-iam-v1</artifactId>
72+
</dependency>
73+
<dependency>
74+
<groupId>com.google.api.grpc</groupId>
75+
<artifactId>grpc-google-iam-v1</artifactId>
76+
</dependency>
77+
<dependency>
78+
<groupId>org.threeten</groupId>
79+
<artifactId>threetenbp</artifactId>
80+
</dependency>
81+
82+
<!-- Test dependencies -->
83+
<dependency>
84+
<groupId>junit</groupId>
85+
<artifactId>junit</artifactId>
86+
<scope>test</scope>
87+
<version>4.13.2</version>
88+
</dependency>
89+
90+
<dependency>
91+
<groupId>com.google.maps.api.grpc</groupId>
92+
<artifactId>grpc-google-maps-foo-v1</artifactId>
93+
<scope>test</scope>
94+
</dependency>
95+
<!-- Need testing utility classes for generated gRPC clients tests -->
96+
<dependency>
97+
<groupId>com.google.api</groupId>
98+
<artifactId>gax</artifactId>
99+
<classifier>testlib</classifier>
100+
<scope>test</scope>
101+
</dependency>
102+
<dependency>
103+
<groupId>com.google.api</groupId>
104+
<artifactId>gax-grpc</artifactId>
105+
<classifier>testlib</classifier>
106+
<scope>test</scope>
107+
</dependency>
108+
<dependency>
109+
<groupId>com.google.api</groupId>
110+
<artifactId>gax-httpjson</artifactId>
111+
<classifier>testlib</classifier>
112+
<scope>test</scope>
113+
</dependency>
114+
</dependencies>
115+
116+
<profiles>
117+
<profile>
118+
<id>java9</id>
119+
<activation>
120+
<jdk>[9,)</jdk>
121+
</activation>
122+
<dependencies>
123+
<dependency>
124+
<groupId>javax.annotation</groupId>
125+
<artifactId>javax.annotation-api</artifactId>
126+
</dependency>
127+
</dependencies>
128+
</profile>
129+
</profiles>
130+
131+
<build>
132+
<plugins>
133+
<plugin>
134+
<groupId>org.codehaus.mojo</groupId>
135+
<artifactId>flatten-maven-plugin</artifactId>
136+
</plugin>
137+
</plugins>
138+
</build>
139+
</project>

0 commit comments

Comments
 (0)