|
27 | 27 | 1. preprocessing BeamModulePlugin.groovy to decide the dependencies need to sync |
28 | 28 | 2. generate an empty Maven project to fetch the exact target versions to change |
29 | 29 | 3. Write back to BeamModulePlugin.groovy |
30 | | -4. Update libraries-bom version on sdks/java/container/license_scripts/dep_urls_java.yaml |
| 30 | +4. Update libraries-bom and opentelemetry-bom entries on |
| 31 | + sdks/java/container/license_scripts/dep_urls_java.yaml |
31 | 32 |
|
32 | 33 | There are few reasons we need to declare the version numbers: |
33 | 34 | 1. Sync the dependency that not included in GCP-BOM with those included with BOM |
@@ -254,17 +255,51 @@ def write_back(self): |
254 | 255 | for line in self.target_lines: |
255 | 256 | fout.write(line) |
256 | 257 |
|
| 258 | + def _get_opentelemetry_version(self): |
| 259 | + for line in self.target_lines: |
| 260 | + match = self.VERSION_STRING.match(line) |
| 261 | + if match and match.group(1) == 'opentelemetry': |
| 262 | + return match.group(2) |
| 263 | + logging.warning('opentelemetry_version not found in BeamModulePlugin') |
| 264 | + return None |
| 265 | + |
257 | 266 | def write_license_script(self): |
258 | 267 | logging.info("-----Update dep_urls_java.yaml-----") |
259 | | - with open(os.path.join(self.project_root, self.LICENSE_SC_PATH), |
260 | | - 'r') as fin: |
| 268 | + license_path = os.path.join(self.project_root, self.LICENSE_SC_PATH) |
| 269 | + with open(license_path, 'r') as fin: |
261 | 270 | lines = fin.readlines() |
262 | | - with open(os.path.join(self.project_root, self.LICENSE_SC_PATH), |
263 | | - 'w') as fout: |
264 | | - for idx, line in enumerate(lines): |
265 | | - if line.strip() == 'libraries-bom:': |
266 | | - lines[idx + 1] = re.sub( |
267 | | - r'[\'"]\d[\.\d]+[\'"]', f"'{self.bom_version}'", lines[idx + 1]) |
| 271 | + |
| 272 | + otel_version = self._get_opentelemetry_version() |
| 273 | + otel_license_url = ( |
| 274 | + 'https://raw.githubusercontent.com/open-telemetry/' |
| 275 | + 'opentelemetry-java/v{}/LICENSE'.format(otel_version) |
| 276 | + if otel_version else None) |
| 277 | + otel_license_line = ' license: "{}"\n'.format(otel_license_url) |
| 278 | + |
| 279 | + for idx, line in enumerate(lines): |
| 280 | + stripped = line.strip() |
| 281 | + if stripped == 'libraries-bom:': |
| 282 | + lines[idx + 1] = re.sub( |
| 283 | + r'[\'"]\d[\d\.]+[\'"]', "'{}'".format(self.bom_version), |
| 284 | + lines[idx + 1]) |
| 285 | + continue |
| 286 | + if otel_version and stripped == 'opentelemetry-bom:': |
| 287 | + lines[idx + 1] = re.sub( |
| 288 | + r"'[\d\.]+'", "'{}'".format(otel_version), lines[idx + 1]) |
| 289 | + lines[idx + 2] = otel_license_line |
| 290 | + continue |
| 291 | + if otel_version and stripped == 'opentelemetry-bom-alpha:': |
| 292 | + lines[idx + 1] = re.sub( |
| 293 | + r"'[\d\.]+-alpha'", "'{}-alpha'".format(otel_version), |
| 294 | + lines[idx + 1]) |
| 295 | + lines[idx + 2] = otel_license_line |
| 296 | + |
| 297 | + if otel_version: |
| 298 | + logging.info( |
| 299 | + 'Updated opentelemetry-bom license entries to %s', otel_version) |
| 300 | + |
| 301 | + with open(license_path, 'w') as fout: |
| 302 | + for line in lines: |
268 | 303 | fout.write(line) |
269 | 304 |
|
270 | 305 | def run(self): |
|
0 commit comments