15
15
import sys
16
16
import glob
17
17
import json
18
+ from xml .etree .ElementTree import ElementTree
19
+
18
20
from lxml import etree
19
21
import os
20
22
import re
@@ -95,7 +97,7 @@ def update_cloud_pom(
95
97
filename : str ,
96
98
proto_modules : List [module .Module ],
97
99
grpc_modules : List [module .Module ],
98
- repo_metadata : dict ,
100
+ is_monorepo : bool ,
99
101
):
100
102
tree = etree .parse (filename )
101
103
root = tree .getroot ()
@@ -107,42 +109,8 @@ def update_cloud_pom(
107
109
if m .find ("{http://maven.apache.org/POM/4.0.0}artifactId" ) is not None
108
110
]
109
111
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, java-spanner and java-dataproc 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 [
119
- "java-spanner" ,
120
- "java-storage" ,
121
- "java-dataproc" ,
122
- ]:
123
- print (
124
- f"skipping test-scoped-dependency fix for special case repo: { repo_metadata ['repo_short' ]} "
125
- )
126
- continue
127
- artifact_query = "{http://maven.apache.org/POM/4.0.0}artifactId"
128
- scope_query = "{http://maven.apache.org/POM/4.0.0}scope"
129
- current_scope = d .find (scope_query )
130
- artifact_id_elem = d .find (artifact_query )
131
- if artifact_id_elem is None :
132
- continue
133
- artifact_id = artifact_id_elem .text
134
- is_test_scoped = (
135
- current_scope .text == "test" if current_scope is not None else False
136
- )
137
- if artifact_id in TEST_SCOPED_DEPENDENCIES and not is_test_scoped :
138
- new_scope = etree .Element (scope_query )
139
- new_scope .text = "test"
140
- if current_scope is not None :
141
- d .replace (current_scope , new_scope )
142
- else :
143
- d .append (new_scope )
144
- new_scope .tail = "\n "
145
- new_scope .getprevious ().tail = "\n "
112
+ if is_monorepo :
113
+ _set_test_scoped_deps (dependencies )
146
114
147
115
try :
148
116
grpc_index = _find_dependency_index (
@@ -209,6 +177,39 @@ def update_cloud_pom(
209
177
tree .write (filename , pretty_print = True , xml_declaration = True , encoding = "utf-8" )
210
178
211
179
180
+ def _set_test_scoped_deps (dependencies : list [ElementTree ]) -> None :
181
+ """
182
+ As of July 2024, we have two dependencies that should be declared as
183
+ test-scoped in a monorepo: grpc-google-common-protos and grpc-google-iam-v1.
184
+ HW libraries are treated as usual
185
+ :param dependencies: List of XML Objects representing a <dependency/>
186
+ """
187
+ TEST_SCOPED_DEPENDENCIES = ["grpc-google-common-protos" , "grpc-google-iam-v1" ]
188
+ print (
189
+ 'converting dependencies "grpc-google-common-protos" and "grpc-google-iam-v1" to test-scoped'
190
+ )
191
+ for d in dependencies :
192
+ artifact_query = "{http://maven.apache.org/POM/4.0.0}artifactId"
193
+ scope_query = "{http://maven.apache.org/POM/4.0.0}scope"
194
+ current_scope = d .find (scope_query )
195
+ artifact_id_elem = d .find (artifact_query )
196
+ if artifact_id_elem is None :
197
+ continue
198
+ artifact_id = artifact_id_elem .text
199
+ is_test_scoped = (
200
+ current_scope .text == "test" if current_scope is not None else False
201
+ )
202
+ if artifact_id in TEST_SCOPED_DEPENDENCIES and not is_test_scoped :
203
+ new_scope = etree .Element (scope_query )
204
+ new_scope .text = "test"
205
+ if current_scope is not None :
206
+ d .replace (current_scope , new_scope )
207
+ else :
208
+ d .append (new_scope )
209
+ new_scope .tail = "\n "
210
+ new_scope .getprevious ().tail = "\n "
211
+
212
+
212
213
def update_parent_pom (filename : str , modules : List [module .Module ]):
213
214
tree = etree .parse (filename )
214
215
root = tree .getroot ()
@@ -533,7 +534,7 @@ def main(versions_file, monorepo):
533
534
print ("updating modules in cloud pom.xml" )
534
535
if artifact_id not in excluded_poms_list :
535
536
update_cloud_pom (
536
- f"{ artifact_id } /pom.xml" , proto_modules , grpc_modules , repo_metadata
537
+ f"{ artifact_id } /pom.xml" , proto_modules , grpc_modules , monorepo
537
538
)
538
539
elif artifact_id not in excluded_poms_list :
539
540
print ("creating missing cloud pom.xml" )
0 commit comments