@@ -57,7 +57,10 @@ class BeamModulePluginProcessor:
57
57
# dependencies managed by GCP-BOM that used the dependencies in KNOWN_DEPS
58
58
# So we need to add it to the example project to get the version to sync
59
59
OTHER_CONSTRANTS = [
60
- "com.google.cloud:google-cloud-bigquery" # uses arrow
60
+ "com.google.cloud:google-cloud-bigquery" , # for arrow
61
+ 'com.google.cloud:google-cloud-nio' , # for google-api-services-storage
62
+ 'com.google.cloud:google-cloud-resourcemanager' , # for google-api-services-cloudresourcemanager
63
+ 'com.google.cloud:google-cloud-datastore' , # for google-cloud-dataflow-java-proto-library-all
61
64
]
62
65
63
66
# TODO: the logic can be generalized to support multiple BOM
@@ -66,6 +69,9 @@ class BeamModulePluginProcessor:
66
69
)
67
70
# e.g. def grpc_version = "1.61.0"
68
71
VERSION_STRING = re .compile (r'^\s*def (\w+)_version\s*=\s*[\'"](\S+)[\'"]' )
72
+ SINGLE_VERSION_STRING = re .compile (
73
+ r'.+:\s*[\'"]([\w\-.]+:[\w\-.]+):(.+)[\'"],\s*//\s*\[bomupgrader\] sets version'
74
+ )
69
75
BOM_VERSION_STRING = re .compile (
70
76
r'\s*google_cloud_platform_libraries_bom\s*:\s*[\'"]com\.google\.cloud:libraries-bom:([0-9\.]+)[\'"],?'
71
77
)
@@ -92,7 +98,24 @@ def __init__(self, bom_version, project_root='.', runnable=None):
92
98
# e.g. {"io.grpc:grpc-netty", "1.61.0"}
93
99
self .dep_versions = {}
94
100
self .dep_versions_current = {}
95
- self .known_deps = {}
101
+ # dependencies managed by bomupgrader. They are declared inline in BeamModulePlugin,
102
+ # different from KNOWN_DEPS which first define a version
103
+ self .set_deps = {}
104
+ self .set_deps_current = {}
105
+
106
+ @staticmethod
107
+ def resolve_actual_dep (line , id ):
108
+ """Resolve actual dependency from dependencyTree line"""
109
+ idx = line .find (id + ':' )
110
+ if idx == - 1 : return "" # not found
111
+ dep_and_other = line [idx + len (id ) + 1 :].split ()
112
+ try :
113
+ jdx = dep_and_other .index ('->' )
114
+ ver = dep_and_other [jdx + 1 ]
115
+ except ValueError :
116
+ # there might be multiple ':', e.g. come.group.id:some-package:test:1.2.3
117
+ ver = dep_and_other [0 ].split (':' )[- 1 ]
118
+ return ver
96
119
97
120
def check_dependencies (self ):
98
121
"""Check dependencies in KNOWN_DEPS are found in BeamModulePlugin, and vice versa."""
@@ -107,6 +130,11 @@ def check_dependencies(self):
107
130
"Version definition not found after anchor comment. Try standardize it."
108
131
)
109
132
found_deps [n .group (1 )] = n .group (2 )
133
+ continue
134
+ m = self .SINGLE_VERSION_STRING .match (line )
135
+ if m :
136
+ self .set_deps_current [m .group (1 )] = m .group (2 )
137
+
110
138
assert sorted (self .KNOWN_DEPS .keys ()) == sorted (found_deps .keys ()), f"expect { self .KNOWN_DEPS .keys ()} == { found_deps .keys ()} "
111
139
self .dep_versions_current = {
112
140
self .KNOWN_DEPS [k ]: v
@@ -122,7 +150,8 @@ def prepare_gradle(self, bom_version):
122
150
raise
123
151
124
152
deps = []
125
- for dep in list (self .KNOWN_DEPS .values ()) + self .OTHER_CONSTRANTS :
153
+ for dep in list (self .KNOWN_DEPS .values ()) + self .OTHER_CONSTRANTS + list (
154
+ self .set_deps_current .keys ()):
126
155
deps .append (f"implementation '{ dep } '" )
127
156
gradle_file = self .GRADLE_TEMPLATE % (bom_version , "\n " .join (deps ))
128
157
with open (os .path .join (self .BUILD_DIR , 'build.gradle' ), 'w' ) as fout :
@@ -145,26 +174,34 @@ def resolve(self):
145
174
result = subp .stdout .decode ('utf-8' )
146
175
# example line: | +--- com.google.guava:guava:32.1.3-android -> 32.1.3-jre (*)
147
176
logging .debug (result )
177
+ get_dep_line = re .compile ('\s+([\w\-.]+:[\w\-.]+):(.+)' )
178
+
148
179
for line in result .splitlines ():
180
+ # search self.set_deps version
181
+ m = get_dep_line .search (line )
182
+ if m and m .group (1 ) in self .set_deps_current :
183
+ ver = self .resolve_actual_dep (line , m .group (1 ))
184
+ self .set_deps [m .group (1 )] = ver
185
+ continue
186
+
187
+ # search KNOWN_DEPS version
149
188
for id in self .KNOWN_DEPS .values ():
150
- idx = line .find (id + ':' )
151
- if idx == - 1 :
152
- continue
153
- dep_and_other = line [idx + len (id ) + 1 :].split ()
154
- try :
155
- jdx = dep_and_other .index ('->' )
156
- ver = dep_and_other [jdx + 1 ]
157
- except ValueError :
158
- # there might be multiple ':', e.g. come.group.id:some-package:test:1.2.3
159
- ver = dep_and_other [0 ].split (':' )[- 1 ]
160
- self .dep_versions [id ] = ver
161
- break
189
+ if id in self .dep_versions : continue
190
+ ver = self .resolve_actual_dep (line , id )
191
+ if ver :
192
+ self .dep_versions [id ] = ver
193
+ break
162
194
163
195
if len (self .dep_versions ) < len (self .KNOWN_DEPS ):
164
196
logging .warning (
165
197
"Warning: not all dependencies are resolved: %s" , self .dep_versions )
166
198
logging .info (result )
167
199
200
+ if len (self .set_deps ) < len (self .set_deps_current ):
201
+ logging .warning (
202
+ "Warning: not all dependencies are resolved: %s" , self .set_deps )
203
+ logging .info (result )
204
+
168
205
def write_back (self ):
169
206
logging .info ("-----Update BeamModulePlugin-----" )
170
207
# make a shallow copy
@@ -188,13 +225,26 @@ def write_back(self):
188
225
logging .info ('Changed %s: %s -> %s' , id , old_v , new_v )
189
226
else :
190
227
logging .info ('Unchanged: %s:%s' , id , new_v )
191
- else :
192
- # replace GCP BOM version
193
- n = self .BOM_VERSION_STRING .match (line )
194
- if n :
228
+ continue
229
+
230
+ # single_ver replace
231
+ m = self .SINGLE_VERSION_STRING .match (line )
232
+ if m :
233
+ id = m .group (1 )
234
+ old_v = m .group (2 )
235
+ new_v = self .set_deps [id ]
236
+ if new_v != old_v :
195
237
self .target_lines [idx ] = self .original_lines [idx ].replace (
196
- n .group (1 ), self .bom_version )
197
- found_bom = True
238
+ old_v , new_v )
239
+ logging .info ('Changed %s: %s -> %s' , id , old_v , new_v )
240
+ else :
241
+ logging .info ('Unchanged: %s:%s' , id , new_v )
242
+ # replace GCP BOM version
243
+ n = self .BOM_VERSION_STRING .match (line )
244
+ if n :
245
+ self .target_lines [idx ] = self .original_lines [idx ].replace (
246
+ n .group (1 ), self .bom_version )
247
+ found_bom = True
198
248
199
249
if not found_bom :
200
250
logging .warning (
@@ -224,6 +274,7 @@ def run(self):
224
274
self .write_back ()
225
275
self .write_license_script ()
226
276
277
+
227
278
if __name__ == '__main__' :
228
279
logging .getLogger ().setLevel (logging .INFO )
229
280
if len (sys .argv ) < 2 :
0 commit comments