Skip to content

Commit

Permalink
chore: generate non-cloud client library (#1770)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
JoeWang1127 authored Feb 24, 2023
1 parent 4c15ec0 commit 269a915
Show file tree
Hide file tree
Showing 20 changed files with 771 additions and 11 deletions.
8 changes: 8 additions & 0 deletions docker/owlbot/java/cloudbuild_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ steps:
args: ["diff", "-rw", "input", "golden"]
dir: docker/owlbot/java/tests/new-client
waitFor: ["new-client-run"]
- name: "gcr.io/$PROJECT_ID/owlbot-java:$SHORT_SHA"
dir: docker/owlbot/java/tests/new-client-maps/input
id: "new-client-maps-run"
waitFor: [ "build" ]
- name: "bash"
args: [ "diff", "-rw", "input", "golden" ]
dir: docker/owlbot/java/tests/new-client-maps
waitFor: [ "new-client-maps-run" ]
- name: "gcr.io/$PROJECT_ID/owlbot-java:$SHORT_SHA"
dir: docker/owlbot/java/tests/new-version/input
id: "new-version-run"
Expand Down
33 changes: 23 additions & 10 deletions docker/owlbot/java/src/fix-poms.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def load_versions(filename: str, default_group_id: str) -> Mapping[str, module.M
group_id = (
default_group_id
if artifact_id.startswith("google-")
else "com.google.api.grpc"
else _proto_group_id(default_group_id)
)
modules[artifact_id] = module.Module(
group_id=group_id,
Expand Down Expand Up @@ -274,6 +274,18 @@ def update_bom_pom(filename: str, modules: List[module.Module]):

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


# When generating non-cloud client library, the group id of proto/grpc artifacts
# is prefixed with `{main_artifact_group_id}.api.grpc`, rather than
# `com.google.api.grpc`.
# https://github.com/googleapis/google-cloud-java/issues/9125
def _proto_group_id(main_artifact_group_id: str) -> str:
prefix = "com.google" \
if main_artifact_group_id == "com.google.cloud" \
else main_artifact_group_id
return f"{prefix}.api.grpc"


def main():
print(f"working directory: {os.getcwd()}")
with open(".repo-metadata.json", "r") as fp:
Expand Down Expand Up @@ -353,15 +365,15 @@ def main():
for path in glob.glob("proto-google-*"):
if not path in existing_modules:
existing_modules[path] = module.Module(
group_id="com.google.api.grpc",
group_id=_proto_group_id(group_id),
artifact_id=path,
version=main_module.version,
release_version=main_module.release_version,
)
if path not in excluded_dependencies_list \
and path not in main_module.artifact_id:
required_dependencies[path] = module.Module(
group_id="com.google.api.grpc",
group_id=_proto_group_id(group_id),
artifact_id=path,
version=main_module.version,
release_version=main_module.release_version,
Expand All @@ -378,29 +390,29 @@ def main():
if path not in excluded_dependencies_list \
and path not in main_module.artifact_id:
required_dependencies[path] = module.Module(
group_id="com.google.api.grpc",
group_id=_proto_group_id(group_id),
artifact_id=path,
version=main_module.version,
release_version=main_module.release_version,
)

for path in glob.glob("grpc-google-*"):
if not path in existing_modules:
existing_modules[path] = module.Module(
group_id="com.google.api.grpc",
group_id=_proto_group_id(group_id),
artifact_id=path,
version=main_module.version,
release_version=main_module.release_version,
)
if path not in excluded_dependencies_list \
and path not in main_module.artifact_id:
required_dependencies[path] = module.Module(
group_id="com.google.api.grpc",
group_id=_proto_group_id(group_id),
artifact_id=path,
version=main_module.version,
release_version=main_module.release_version,
)

if not os.path.isfile(f"{path}/pom.xml"):
proto_artifact_id = path.replace("grpc-", "proto-")
print(f"creating missing grpc pom: {path}")
Expand All @@ -415,7 +427,7 @@ def main():
if path not in excluded_dependencies_list \
and path not in main_module.artifact_id:
required_dependencies[path] = module.Module(
group_id="com.google.api.grpc",
group_id=_proto_group_id(group_id),
artifact_id=path,
version=main_module.version,
release_version=main_module.release_version,
Expand Down Expand Up @@ -498,7 +510,7 @@ def main():
for dependency_module in extra_managed_modules:
if dependency_module not in existing_modules:
existing_modules[dependency_module] = module.Module(
group_id="com.google.api.grpc",
group_id=_proto_group_id(group_id),
artifact_id=dependency_module,
version=main_module.version,
release_version=main_module.release_version,
Expand All @@ -507,5 +519,6 @@ def main():
template_name="versions.txt.j2", output_name=versions_txt_file, modules=existing_modules.values(),
)


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion docker/owlbot/java/templates/poms/cloud_pom.xml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</dependency>
{% for module in proto_modules %}
<dependency>
<groupId>com.google.api.grpc</groupId>
<groupId>{{module.group_id}}</groupId>
<artifactId>{{module.artifact_id}}</artifactId>
</dependency>{% endfor %}
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "maps",
"name_pretty": "Example API",
"product_documentation": "https://maps.google.com/foo/",
"api_description": "is an example API",
"client_documentation": "https://googleapis.dev/java/google-maps-foo/latest/index.html",
"release_level": "beta",
"transport": "grpc",
"language": "java",
"repo": "googleapis/java-maps",
"repo_short": "java-maps",
"distribution_name": "com.google.maps:google-maps-foo",
"api_id": "maps.googleapis.com",
"requires_billing": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?xml version="1.0"?>
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.maps</groupId>
<artifactId>google-maps-foo-bom</artifactId>
<version>0.0.1-SNAPSHOT</version><!-- {x-version-update:google-maps-foo:current} -->
<packaging>pom</packaging>
<parent>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-shared-config</artifactId>
<version>1.5.3</version>
</parent>

<name>Google Example API BOM</name>
<url>https://github.com/googleapis/java-maps</url>
<description>
BOM for Example API
</description>

<organization>
<name>Google LLC</name>
</organization>

<developers>
<developer>
<id>chingor13</id>
<name>Jeff Ching</name>
<email>chingor@google.com</email>
<organization>Google LLC</organization>
<roles>
<role>Developer</role>
</roles>
</developer>
<developer>
<id>neenushaji</id>
<name>Neenu Shaji</name>
<email>neenushaji@google.com</email>
<organization>Google LLC</organization>
<roles>
<role>Developer</role>
</roles>
</developer>
</developers>

<scm>
<connection>scm:git:https://github.com/googleapis/java-maps.git</connection>
<developerConnection>scm:git:git@github.com:googleapis/java-maps.git</developerConnection>
<url>https://github.com/googleapis/java-maps</url>
</scm>

<properties>
<maven.antrun.skip>true</maven.antrun.skip>
</properties>

<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.maps</groupId>
<artifactId>google-maps-foo</artifactId>
<version>0.0.1-SNAPSHOT</version><!-- {x-version-update:google-maps-foo:current} -->
</dependency>
<dependency>
<groupId>com.google.maps.api.grpc</groupId>
<artifactId>grpc-google-maps-foo-v1</artifactId>
<version>0.0.1-SNAPSHOT</version><!-- {x-version-update:grpc-google-maps-foo-v1:current} -->
</dependency>
<dependency>
<groupId>com.google.maps.api.grpc</groupId>
<artifactId>proto-google-maps-foo-v1</artifactId>
<version>0.0.1-SNAPSHOT</version><!-- {x-version-update:proto-google-maps-foo-v1:current} -->
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<?xml version="1.0"?>
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.maps</groupId>
<artifactId>google-maps-foo</artifactId>
<version>0.0.1-SNAPSHOT</version><!-- {x-version-update:google-maps-foo:current} -->
<packaging>jar</packaging>
<name>Google Example API</name>
<url>https://github.com/googleapis/java-maps</url>
<description>Example API is an example API</description>
<parent>
<groupId>com.google.maps</groupId>
<artifactId>google-maps-foo-parent</artifactId>
<version>0.0.1-SNAPSHOT</version><!-- {x-version-update:google-maps-foo:current} -->
</parent>
<properties>
<site.installationModule>google-maps-foo</site.installationModule>
</properties>
<dependencies>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-api</artifactId>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
</dependency>
<dependency>
<groupId>com.google.api</groupId>
<artifactId>api-common</artifactId>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-common-protos</artifactId>
</dependency>

<dependency>
<groupId>com.google.maps.api.grpc</groupId>
<artifactId>proto-google-maps-foo-v1</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>com.google.api</groupId>
<artifactId>gax</artifactId>
</dependency>
<dependency>
<groupId>com.google.api</groupId>
<artifactId>gax-grpc</artifactId>
</dependency>
<dependency>
<groupId>com.google.api</groupId>
<artifactId>gax-httpjson</artifactId>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-google-common-protos</artifactId>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-iam-v1</artifactId>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-google-iam-v1</artifactId>
</dependency>
<dependency>
<groupId>org.threeten</groupId>
<artifactId>threetenbp</artifactId>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
<version>4.13.2</version>
</dependency>

<dependency>
<groupId>com.google.maps.api.grpc</groupId>
<artifactId>grpc-google-maps-foo-v1</artifactId>
<scope>test</scope>
</dependency>
<!-- Need testing utility classes for generated gRPC clients tests -->
<dependency>
<groupId>com.google.api</groupId>
<artifactId>gax</artifactId>
<classifier>testlib</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.api</groupId>
<artifactId>gax-grpc</artifactId>
<classifier>testlib</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.api</groupId>
<artifactId>gax-httpjson</artifactId>
<classifier>testlib</classifier>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
<profile>
<id>java9</id>
<activation>
<jdk>[9,)</jdk>
</activation>
<dependencies>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Loading

0 comments on commit 269a915

Please sign in to comment.