From 72f5b816d86b9c52f0f63564e92ba12fa64c1602 Mon Sep 17 00:00:00 2001 From: Sindre Stephansen Date: Wed, 28 Dec 2022 12:32:57 +0100 Subject: [PATCH] Handle missing artifactId and groupId in BOMs --- update-poms.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/update-poms.py b/update-poms.py index 0da99c1..5bde149 100755 --- a/update-poms.py +++ b/update-poms.py @@ -49,15 +49,27 @@ class PackagePOM: root_copy.extend(depman.findall('*')) root_copy.remove(depman) + tmpGroupId = f'tmp.{package.groupId}' + tmpArtifactId = f'placeholder.{package.artifactId}' + tmpVersion = package.version + if (groupId := root_copy.find('groupId', ns)) is not None: - groupId.text = f'tmp.{package.groupId}' + groupId.text = tmpGroupId + else: + logger.info(f"{package}: Inserting new groupId tag in pom") + ET.SubElement(root_copy, 'groupId').text = tmpGroupId + + if (artifactId := root_copy.find('artifactId', ns)) is not None: + artifactId.text = tmpArtifactId else: - logger.warning(f"{package}: No groupId tag in pom") + logger.info(f"{package}: Inserting new artifactId tag in pom") + ET.SubElement(root_copy, 'artifactId').text = tmpArtifactId - if (artifactId := root_copy.find('groupId', ns)) is not None: - artifactId.text = f'placeholder.{package.artifactId}' + if (version := root_copy.find('version', ns)) is not None: + version.text = tmpVersion else: - logger.warning(f"{package}: No artifactId tag in pom") + logger.info(f"{package}: Inserting new version tag in pom") + ET.SubElement(root_copy, 'version').text = tmpVersion # Add a dependency for the pom itself if (dependencies := root_copy.find('dependencies', ns)) is not None: