Skip to content

Commit 8e87b2e

Browse files
authored
fix: only append .api.grpc suffix to group id if the artifact id starts with proto- or grpc- (#2731)
In this PR: - Only append `.api.grpc` suffix to group id if the corresponding artifact id starts with `proto-` or `grpc-`. We need to support `ad-manager`, which is the first artifact id doesn't start with `proto-`, `grpc-` and `google-`.
1 parent dbdcc91 commit 8e87b2e

File tree

13 files changed

+327
-9
lines changed

13 files changed

+327
-9
lines changed

library_generation/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ The transfer was not a verbatim copy, it rather had modifications:
300300
* `entrypoint.sh` was modified to have input arguments and slightly modified
301301
the way the helper scripts are called
302302
* Other helper scripts were modified to have input arguments.
303-
* `fix-poms.py` modified the way the monorepo is detected
303+
* `fix_poms.py` modified the way the monorepo is detected
304304

305305
All these modifications imply that whenever we want to reflect a change from the
306306
original owlbot in synthtool we may be better off modifying the affected source

library_generation/owlbot/bin/entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ echo "...done"
5757

5858
# write or restore pom.xml files
5959
echo "Generating missing pom.xml..."
60-
python3 "${scripts_root}/owlbot/src/fix-poms.py" "${versions_file}" "${is_monorepo}"
60+
python3 "${scripts_root}/owlbot/src/fix_poms.py" "${versions_file}" "${is_monorepo}"
6161
echo "...done"
6262

6363
# write or restore clirr-ignored-differences.xml

library_generation/owlbot/src/fix-poms.py renamed to library_generation/owlbot/src/fix_poms.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,12 @@
1414

1515
import sys
1616
import glob
17-
import inspect
18-
import itertools
1917
import json
2018
from lxml import etree
2119
import os
2220
import re
2321
from typing import List, Mapping
24-
from poms import module, templates
25-
from pathlib import Path
22+
from library_generation.owlbot.src.poms import module, templates
2623

2724

2825
def load_versions(filename: str, default_group_id: str) -> Mapping[str, module.Module]:
@@ -39,9 +36,17 @@ def load_versions(filename: str, default_group_id: str) -> Mapping[str, module.M
3936
if len(parts) == 3:
4037
artifact_id = parts[0]
4138
group_id = (
42-
default_group_id
43-
if artifact_id.startswith("google-")
44-
else __proto_group_id(default_group_id)
39+
# For artifact id starts with `proto-` or `grpc-`, we
40+
# need special treatments to append `.api.grpc` suffix
41+
# to its corresponding group id.
42+
# For other artifact id, keep the existing group id.
43+
# Other than the two aforementioned artifact id, do not
44+
# assume artifact id always starts with `google-`. Known
45+
# exception is ad-manager.
46+
__proto_group_id(default_group_id)
47+
if artifact_id.startswith("proto-")
48+
or artifact_id.startswith("grpc-")
49+
else default_group_id
4550
)
4651
modules[artifact_id] = module.Module(
4752
group_id=group_id,

library_generation/setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
"gapic-generator-java-wrapper",
2020
"requirements.*",
2121
"owlbot/bin/*.sh",
22+
"owlbot/src/*.py",
23+
"owlbot/src/poms/*.py",
2224
"owlbot/templates/clirr/*.j2",
2325
"owlbot/templates/poms/*.j2",
2426
"owlbot/templates/java_library/**/*",

library_generation/test/compare_poms.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ def compare_xml(expected, actual, print_trees):
102102
return False
103103

104104

105+
def compare_pom_in_subdir(base_dir: str, subdir: str) -> bool:
106+
golden = os.path.join(base_dir, subdir, "pom-golden.xml")
107+
pom = os.path.join(base_dir, subdir, "pom.xml")
108+
return compare_xml(
109+
golden,
110+
pom,
111+
False,
112+
)
113+
114+
105115
if __name__ == "__main__":
106116
if len(sys.argv) != 4:
107117
eprint(

library_generation/test/owlbot/__init__.py

Whitespace-only changes.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright 2024 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+
# https://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+
import os
15+
import shutil
16+
import unittest
17+
from library_generation.owlbot.src.fix_poms import main
18+
from library_generation.test.compare_poms import compare_pom_in_subdir
19+
20+
script_dir = os.path.dirname(os.path.realpath(__file__))
21+
resources_dir = os.path.join(script_dir, "..", "resources", "test-owlbot")
22+
23+
24+
class FixPomsTest(unittest.TestCase):
25+
def test_update_poms_group_id_does_not_start_with_google_correctly(self):
26+
ad_manager_resource = os.path.join(resources_dir, "java-admanager")
27+
versions_file = os.path.join(ad_manager_resource, "versions.txt")
28+
os.chdir(ad_manager_resource)
29+
sub_dirs = ["ad-manager", "ad-manager-bom", "proto-ad-manager-v1", "."]
30+
for sub_dir in sub_dirs:
31+
self.__copy__golden(ad_manager_resource, sub_dir)
32+
main(versions_file, "true")
33+
for sub_dir in sub_dirs:
34+
self.assertFalse(compare_pom_in_subdir(ad_manager_resource, sub_dir))
35+
for sub_dir in sub_dirs:
36+
self.__remove_file_in_subdir(ad_manager_resource, sub_dir)
37+
38+
@classmethod
39+
def __copy__golden(cls, base_dir: str, subdir: str):
40+
golden = os.path.join(base_dir, subdir, "pom-golden.xml")
41+
pom = os.path.join(base_dir, subdir, "pom.xml")
42+
shutil.copyfile(golden, pom)
43+
44+
@classmethod
45+
def __remove_file_in_subdir(cls, base_dir: str, subdir: str):
46+
pom = os.path.join(base_dir, subdir, "pom.xml")
47+
os.unlink(pom)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"api_shortname": "admanager",
3+
"name_pretty": "Google Ad Manager API",
4+
"product_documentation": "https://developers.google.com/ad-manager/api/beta",
5+
"api_description": "The Ad Manager API enables an app to integrate with Google Ad Manager. You can read Ad Manager data and run reports using the API.",
6+
"client_documentation": "https://cloud.google.com/java/docs/reference/ad-manager/latest/overview",
7+
"release_level": "preview",
8+
"transport": "http",
9+
"language": "java",
10+
"repo": "googleapis/google-cloud-java",
11+
"repo_short": "java-admanager",
12+
"distribution_name": "com.google.api-ads:ad-manager",
13+
"api_id": "admanager.googleapis.com",
14+
"library_type": "GAPIC_AUTO",
15+
"requires_billing": true
16+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
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.api-ads</groupId>
5+
<artifactId>ad-manager-bom</artifactId>
6+
<version>0.2.0-SNAPSHOT</version><!-- {x-version-update:ad-manager:current} -->
7+
<packaging>pom</packaging>
8+
<parent>
9+
<groupId>com.google.cloud</groupId>
10+
<artifactId>google-cloud-pom-parent</artifactId>
11+
<version>1.37.0-SNAPSHOT</version><!-- {x-version-update:google-cloud-java:current} -->
12+
<relativePath>../../google-cloud-pom-parent/pom.xml</relativePath>
13+
</parent>
14+
15+
<name>Google Google Ad Manager API BOM</name>
16+
<description>
17+
BOM for Google Ad Manager API
18+
</description>
19+
20+
<properties>
21+
<maven.antrun.skip>true</maven.antrun.skip>
22+
</properties>
23+
24+
<dependencyManagement>
25+
<dependencies>
26+
<dependency>
27+
<groupId>com.google.api-ads</groupId>
28+
<artifactId>ad-manager</artifactId>
29+
<version>0.2.0-SNAPSHOT</version><!-- {x-version-update:ad-manager:current} -->
30+
</dependency>
31+
<dependency>
32+
<groupId>com.google.api-ads.api.grpc</groupId>
33+
<artifactId>proto-ad-manager-v1</artifactId>
34+
<version>0.2.0-SNAPSHOT</version><!-- {x-version-update:proto-ad-manager-v1:current} -->
35+
</dependency>
36+
</dependencies>
37+
</dependencyManagement>
38+
</project>
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
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.api-ads</groupId>
5+
<artifactId>ad-manager</artifactId>
6+
<version>0.2.0-SNAPSHOT</version><!-- {x-version-update:ad-manager:current} -->
7+
<packaging>jar</packaging>
8+
<name>Google Google Ad Manager API</name>
9+
<description>Google Ad Manager API The Ad Manager API enables an app to integrate with Google Ad Manager. You can read Ad Manager data and run reports using the API.</description>
10+
<parent>
11+
<groupId>com.google.api-ads</groupId>
12+
<artifactId>ad-manager-parent</artifactId>
13+
<version>0.2.0-SNAPSHOT</version><!-- {x-version-update:ad-manager:current} -->
14+
</parent>
15+
<properties>
16+
<site.installationModule>ad-manager</site.installationModule>
17+
</properties>
18+
<dependencies>
19+
<dependency>
20+
<groupId>io.grpc</groupId>
21+
<artifactId>grpc-api</artifactId>
22+
</dependency>
23+
<dependency>
24+
<groupId>io.grpc</groupId>
25+
<artifactId>grpc-stub</artifactId>
26+
</dependency>
27+
<dependency>
28+
<groupId>io.grpc</groupId>
29+
<artifactId>grpc-protobuf</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>com.google.api</groupId>
33+
<artifactId>api-common</artifactId>
34+
</dependency>
35+
<dependency>
36+
<groupId>com.google.protobuf</groupId>
37+
<artifactId>protobuf-java</artifactId>
38+
</dependency>
39+
<dependency>
40+
<groupId>com.google.api.grpc</groupId>
41+
<artifactId>proto-google-common-protos</artifactId>
42+
</dependency>
43+
44+
<dependency>
45+
<groupId>com.google.api-ads.api.grpc</groupId>
46+
<artifactId>proto-ad-manager-v1</artifactId>
47+
</dependency>
48+
<dependency>
49+
<groupId>com.google.guava</groupId>
50+
<artifactId>guava</artifactId>
51+
</dependency>
52+
<dependency>
53+
<groupId>com.google.api</groupId>
54+
<artifactId>gax</artifactId>
55+
</dependency>
56+
<dependency>
57+
<groupId>com.google.api</groupId>
58+
<artifactId>gax-grpc</artifactId>
59+
</dependency>
60+
<dependency>
61+
<groupId>com.google.api</groupId>
62+
<artifactId>gax-httpjson</artifactId>
63+
</dependency>
64+
<dependency>
65+
<groupId>com.google.api.grpc</groupId>
66+
<artifactId>grpc-google-common-protos</artifactId>
67+
</dependency>
68+
<dependency>
69+
<groupId>com.google.api.grpc</groupId>
70+
<artifactId>proto-google-iam-v1</artifactId>
71+
</dependency>
72+
<dependency>
73+
<groupId>com.google.api.grpc</groupId>
74+
<artifactId>grpc-google-iam-v1</artifactId>
75+
</dependency>
76+
<dependency>
77+
<groupId>org.threeten</groupId>
78+
<artifactId>threetenbp</artifactId>
79+
</dependency>
80+
81+
<!-- Test dependencies -->
82+
<dependency>
83+
<groupId>junit</groupId>
84+
<artifactId>junit</artifactId>
85+
<scope>test</scope>
86+
</dependency>
87+
88+
<!-- Need testing utility classes for generated gRPC clients tests -->
89+
<dependency>
90+
<groupId>com.google.api</groupId>
91+
<artifactId>gax</artifactId>
92+
<classifier>testlib</classifier>
93+
<scope>test</scope>
94+
</dependency>
95+
<dependency>
96+
<groupId>com.google.api</groupId>
97+
<artifactId>gax-grpc</artifactId>
98+
<classifier>testlib</classifier>
99+
<scope>test</scope>
100+
</dependency>
101+
<dependency>
102+
<groupId>com.google.api</groupId>
103+
<artifactId>gax-httpjson</artifactId>
104+
<classifier>testlib</classifier>
105+
<scope>test</scope>
106+
</dependency>
107+
</dependencies>
108+
</project>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
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.api-ads</groupId>
5+
<artifactId>ad-manager-parent</artifactId>
6+
<packaging>pom</packaging>
7+
<version>0.2.0-SNAPSHOT</version><!-- {x-version-update:ad-manager:current} -->
8+
<name>Google Google Ad Manager API Parent</name>
9+
<description>
10+
Java idiomatic client for Google Cloud Platform services.
11+
</description>
12+
13+
<parent>
14+
<groupId>com.google.cloud</groupId>
15+
<artifactId>google-cloud-jar-parent</artifactId>
16+
<version>1.37.0-SNAPSHOT</version><!-- {x-version-update:google-cloud-java:current} -->
17+
<relativePath>../google-cloud-jar-parent/pom.xml</relativePath>
18+
</parent>
19+
20+
<properties>
21+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
23+
<github.global.server>github</github.global.server>
24+
<site.installationModule>ad-manager-parent</site.installationModule>
25+
</properties>
26+
27+
<dependencyManagement>
28+
<dependencies>
29+
<dependency>
30+
<groupId>com.google.api-ads</groupId>
31+
<artifactId>ad-manager</artifactId>
32+
<version>0.2.0-SNAPSHOT</version><!-- {x-version-update:ad-manager:current} -->
33+
</dependency>
34+
<dependency>
35+
<groupId>com.google.api-ads.api.grpc</groupId>
36+
<artifactId>proto-ad-manager-v1</artifactId>
37+
<version>0.2.0-SNAPSHOT</version><!-- {x-version-update:proto-ad-manager-v1:current} -->
38+
</dependency>
39+
40+
</dependencies>
41+
</dependencyManagement>
42+
43+
<modules>
44+
<module>ad-manager</module>
45+
<module>proto-ad-manager-v1</module>
46+
<module>ad-manager-bom</module>
47+
</modules>
48+
49+
</project>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>com.google.api-ads.api.grpc</groupId>
6+
<artifactId>proto-ad-manager-v1</artifactId>
7+
<version>0.2.0-SNAPSHOT</version><!-- {x-version-update:proto-ad-manager-v1:current} -->
8+
<name>proto-ad-manager-v1</name>
9+
<description>Proto library for ad-manager</description>
10+
<parent>
11+
<groupId>com.google.api-ads</groupId>
12+
<artifactId>ad-manager-parent</artifactId>
13+
<version>0.2.0-SNAPSHOT</version><!-- {x-version-update:ad-manager:current} -->
14+
</parent>
15+
<dependencies>
16+
<dependency>
17+
<groupId>com.google.protobuf</groupId>
18+
<artifactId>protobuf-java</artifactId>
19+
</dependency>
20+
<dependency>
21+
<groupId>com.google.api.grpc</groupId>
22+
<artifactId>proto-google-common-protos</artifactId>
23+
</dependency>
24+
<dependency>
25+
<groupId>com.google.api.grpc</groupId>
26+
<artifactId>proto-google-iam-v1</artifactId>
27+
</dependency>
28+
<dependency>
29+
<groupId>com.google.api</groupId>
30+
<artifactId>api-common</artifactId>
31+
</dependency>
32+
<dependency>
33+
<groupId>com.google.guava</groupId>
34+
<artifactId>guava</artifactId>
35+
</dependency>
36+
</dependencies>
37+
</project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Format:
2+
# module:released-version:current-version
3+
4+
google-cloud-java:1.36.0:1.37.0-SNAPSHOT
5+
ad-manager:0.1.0:0.2.0-SNAPSHOT
6+
proto-ad-manager-v1:0.1.0:0.2.0-SNAPSHOT

0 commit comments

Comments
 (0)