Skip to content

Commit eb912d5

Browse files
committed
fix: make grpc deps common-protos and iam-v1 test-scoped
1 parent e46648f commit eb912d5

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

library_generation/owlbot/src/fix_poms.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ def _is_cloud_client(existing_modules: List[module.Module]) -> bool:
9292

9393

9494
def update_cloud_pom(
95-
filename: str, proto_modules: List[module.Module], grpc_modules: List[module.Module]
95+
filename: str,
96+
proto_modules: List[module.Module],
97+
grpc_modules: List[module.Module],
98+
repo_metadata: dict,
9699
):
97100
tree = etree.parse(filename)
98101
root = tree.getroot()
@@ -104,6 +107,39 @@ def update_cloud_pom(
104107
if m.find("{http://maven.apache.org/POM/4.0.0}artifactId") is not None
105108
]
106109

110+
# as of July 2024, we have two dependencies that should be declared as
111+
# test-scoped: grpc-google-common-protos and grpc-google-iam-v1. Only in
112+
# java-storage and java-spanner we keep them as they are
113+
TEST_SCOPED_DEPENDENCIES = ["grpc-google-common-protos", "grpc-google-iam-v1"]
114+
print(
115+
'converting old dependencies "grpc-google-common-protos" and "grpc-google-iam-v1" to test-scoped'
116+
)
117+
for d in dependencies:
118+
if repo_metadata["repo_short"] in ["java-spanner", "java-storage"]:
119+
print(
120+
f"skipping test-scoped-dependency fix for special case repo: {repo_metadata['repo_short']}"
121+
)
122+
continue
123+
artifact_query = "{http://maven.apache.org/POM/4.0.0}artifactId"
124+
scope_query = "{http://maven.apache.org/POM/4.0.0}scope"
125+
current_scope = d.find(scope_query)
126+
artifact_id_elem = d.find(artifact_query)
127+
if artifact_id_elem is None:
128+
continue
129+
artifact_id = artifact_id_elem.text
130+
is_test_scoped = (
131+
current_scope.text == "test" if current_scope is not None else False
132+
)
133+
if artifact_id in TEST_SCOPED_DEPENDENCIES and not is_test_scoped:
134+
new_scope = etree.Element(scope_query)
135+
new_scope.text = "test"
136+
if current_scope is not None:
137+
d.replace(current_scope, new_scope)
138+
else:
139+
d.append(new_scope)
140+
new_scope.tail = "\n "
141+
new_scope.getprevious().tail = "\n "
142+
107143
try:
108144
grpc_index = _find_dependency_index(
109145
dependencies, "com.google.api.grpc", "grpc-"
@@ -492,7 +528,9 @@ def main(versions_file, monorepo):
492528
if os.path.isfile(f"{artifact_id}/pom.xml"):
493529
print("updating modules in cloud pom.xml")
494530
if artifact_id not in excluded_poms_list:
495-
update_cloud_pom(f"{artifact_id}/pom.xml", proto_modules, grpc_modules)
531+
update_cloud_pom(
532+
f"{artifact_id}/pom.xml", proto_modules, grpc_modules, repo_metadata
533+
)
496534
elif artifact_id not in excluded_poms_list:
497535
print("creating missing cloud pom.xml")
498536
templates.render(

library_generation/owlbot/templates/poms/cloud_pom.xml.j2

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@
3939
<groupId>com.google.protobuf</groupId>
4040
<artifactId>protobuf-java</artifactId>
4141
</dependency>
42+
{%- if repo in ['java-storage', 'java-spanner'] %}
4243
<dependency>
4344
<groupId>com.google.api.grpc</groupId>
4445
<artifactId>proto-google-common-protos</artifactId>
4546
</dependency>
47+
{%- endif %}
4648
{% for module in proto_modules %}
4749
<dependency>
4850
<groupId>{{module.group_id}}</groupId>
@@ -72,16 +74,30 @@
7274
<groupId>com.google.api.grpc</groupId>
7375
<artifactId>proto-google-iam-v1</artifactId>
7476
</dependency>
77+
{%- if repo not in ['java-storage', 'java-spanner'] %}
7578
<dependency>
7679
<groupId>com.google.api.grpc</groupId>
7780
<artifactId>grpc-google-iam-v1</artifactId>
7881
</dependency>
82+
{%- endif %}
7983
<dependency>
8084
<groupId>org.threeten</groupId>
8185
<artifactId>threetenbp</artifactId>
8286
</dependency>
8387

8488
<!-- Test dependencies -->
89+
{%- if repo not in ['java-storage', 'java-spanner'] %}
90+
<dependency>
91+
<groupId>com.google.api.grpc</groupId>
92+
<artifactId>proto-google-common-protos</artifactId>
93+
<scope>test</scope>
94+
</dependency>
95+
<dependency>
96+
<groupId>com.google.api.grpc</groupId>
97+
<artifactId>grpc-google-iam-v1</artifactId>
98+
<scope>test</scope>
99+
</dependency>
100+
{%- endif %}
85101
<dependency>
86102
<groupId>junit</groupId>
87103
<artifactId>junit</artifactId>

0 commit comments

Comments
 (0)