Skip to content

Commit 6c0db12

Browse files
authored
Automate OpenTelemetry license entries in bomupgrader (#38815)
* Automate OpenTelemetry license entries in bomupgrader * Simplify OpenTelemetry license updates in bomupgrader
1 parent e353462 commit 6c0db12

2 files changed

Lines changed: 44 additions & 15 deletions

File tree

scripts/tools/bomupgrader.py

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
1. preprocessing BeamModulePlugin.groovy to decide the dependencies need to sync
2828
2. generate an empty Maven project to fetch the exact target versions to change
2929
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
3132
3233
There are few reasons we need to declare the version numbers:
3334
1. Sync the dependency that not included in GCP-BOM with those included with BOM
@@ -254,17 +255,51 @@ def write_back(self):
254255
for line in self.target_lines:
255256
fout.write(line)
256257

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+
257266
def write_license_script(self):
258267
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:
261270
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:
268303
fout.write(line)
269304

270305
def run(self):

sdks/java/container/license_scripts/dep_urls_java.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,10 @@ org.eclipse.jgit:
6666
license: "https://www.eclipse.org/org/documents/edl-v10.html"
6767
type: "Eclipse Distribution License - v1.0"
6868
opentelemetry-bom:
69-
'1.56.0':
70-
license: "https://raw.githubusercontent.com/open-telemetry/opentelemetry-java/v1.56.0/LICENSE"
71-
type: "Apache License 2.0"
7269
'1.57.0':
7370
license: "https://raw.githubusercontent.com/open-telemetry/opentelemetry-java/v1.57.0/LICENSE"
7471
type: "Apache License 2.0"
7572
opentelemetry-bom-alpha:
76-
'1.56.0-alpha':
77-
license: "https://raw.githubusercontent.com/open-telemetry/opentelemetry-java/v1.56.0/LICENSE"
78-
type: "Apache License 2.0"
7973
'1.57.0-alpha':
8074
license: "https://raw.githubusercontent.com/open-telemetry/opentelemetry-java/v1.57.0/LICENSE"
8175
type: "Apache License 2.0"

0 commit comments

Comments
 (0)