Class PomRewriter
Replaces regex-based POM editing with lossless semantic tree (LST) transformations that preserve formatting, comments, and whitespace. Each method parses the POM, applies a targeted change, and serializes back to text.
Relocated from ike-workspace-maven-plugin (ike-platform)
to this module (ike-tooling) in IKE-Network/ike-issues#348
so the scaffold goals in ike-maven-plugin can apply
foundation drift without depending on a downstream artifact. The
earlier package-private visibility was widened to public
for the same reason.
Usage:
String updated = PomRewriter.updateDependencyVersion(
pomContent, "network.ike", "ike-bom", "84");
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringaddProperty(String pomContent, String propertyName, String propertyValue) Add a property to the POM's<properties>block.listProperties(String pomContent) List the properties declared in the POM's<properties>block.readParentVersion(String pomContent, String parentGroupId, String parentArtifactId) Read the version of the POM's<parent>block when its coordinates matchparentGroupId:parentArtifactId.static StringremoveDependencyVersion(String pomContent, String groupId, String artifactId) Remove the<version>child from a dependency matched bygroupId:artifactId.static StringremoveProperty(String pomContent, String propertyName) Remove a property from the POM's<properties>block.static StringupdateDependencyVersion(String pomContent, String groupId, String artifactId, String newVersion) Update the version of a specific dependency identified bygroupId:artifactIdanywhere in the POM (both<dependencies>and<dependencyManagement>).static StringupdateParentVersion(String pomContent, String parentGroupId, String parentArtifactId, String newVersion) Update the parent version for a matchinggroupId:artifactIdin the POM's<parent>block.static StringupdatePluginVersion(String pomContent, String groupId, String artifactId, String newVersion) Update the version of a specific plugin identified bygroupId:artifactIdanywhere in the POM (both<plugins>and<pluginManagement>).static StringupdateProperty(String pomContent, String propertyName, String newValue) Update a version property value in the POM's<properties>block.
-
Method Details
-
updateDependencyVersion
public static String updateDependencyVersion(String pomContent, String groupId, String artifactId, String newVersion) Update the version of a specific dependency identified bygroupId:artifactIdanywhere in the POM (both<dependencies>and<dependencyManagement>).- Parameters:
pomContent- the raw POM textgroupId- dependency groupId to matchartifactId- dependency artifactId to matchnewVersion- the version to set- Returns:
- updated POM text, or unchanged if no match
-
readParentVersion
public static Optional<String> readParentVersion(String pomContent, String parentGroupId, String parentArtifactId) Read the version of the POM's<parent>block when its coordinates matchparentGroupId:parentArtifactId.Companion read to
updateParentVersion(String, String, String, String): the cascade alignment path uses this to inspect the current parent version before deciding whether (and to what) to bump it. Returns the version text exactly as it appears in the POM — a literal, an unresolved${...}reference, whatever is declared.- Parameters:
pomContent- the raw POM textparentGroupId- the parent groupId to match (required)parentArtifactId- the parent artifactId to match (required)- Returns:
- the parent's declared version, or empty when the POM
has no
<parent>block matching those coordinates
-
updateParentVersion
public static String updateParentVersion(String pomContent, String parentGroupId, String parentArtifactId, String newVersion) Update the parent version for a matchinggroupId:artifactIdin the POM's<parent>block.Matching requires both groupId and artifactId to match. This prevents cross-coordinate mutation when the same artifactId lives under multiple groupIds (e.g.
network.ike.platform:ike-parentvs.network.ike.pipeline:ike-parent) — see issue #241.- Parameters:
pomContent- the raw POM textparentGroupId- the parent groupId to match (required)parentArtifactId- the parent artifactId to match (required)newVersion- the new version to set- Returns:
- updated POM text, or unchanged if no match
-
updateProperty
Update a version property value in the POM's<properties>block.- Parameters:
pomContent- the raw POM textpropertyName- the property name (e.g., "tinkar-core.version")newValue- the new property value- Returns:
- updated POM text, or unchanged if no match
-
updatePluginVersion
public static String updatePluginVersion(String pomContent, String groupId, String artifactId, String newVersion) Update the version of a specific plugin identified bygroupId:artifactIdanywhere in the POM (both<plugins>and<pluginManagement>).- Parameters:
pomContent- the raw POM textgroupId- plugin groupId to matchartifactId- plugin artifactId to matchnewVersion- the version to set- Returns:
- updated POM text, or unchanged if no match
-
removeDependencyVersion
Remove the<version>child from a dependency matched bygroupId:artifactId. Used to eliminate intra-reactor version pins where the reactor resolves the version automatically.- Parameters:
pomContent- the raw POM textgroupId- dependency groupId to matchartifactId- dependency artifactId to match- Returns:
- updated POM text with version tag removed, or unchanged if no match
-
addProperty
Add a property to the POM's<properties>block. No-op if the property is already declared (useupdateProperty(String, String, String)to change an existing value). No-op if the POM has no<properties>block.Introduced for the
__ALIASindirection bake step (IKE-Network/ike-issues#527): release-publish reads__ALIASdeclarations and materializes the corresponding<short>${canonical}</short>indirections into the release-tagged source pom.- Parameters:
pomContent- the raw POM textpropertyName- the property name to addpropertyValue- the property value- Returns:
- updated POM text, or unchanged if the property is
already declared or no
<properties>block exists
-
removeProperty
Remove a property from the POM's<properties>block. No-op if the property is not declared.Introduced for the
__ALIASindirection unbake step (IKE-Network/ike-issues#527): release-publish removes the materialized indirections after the release tag, before the merge back to main.- Parameters:
pomContent- the raw POM textpropertyName- the property name to remove- Returns:
- updated POM text, or unchanged if no match
-
listProperties
List the properties declared in the POM's<properties>block. Returns name → value pairs in declaration order. Whitespace, comments, and non-tag content are skipped.Used by the indirection bake/unbake steps (IKE-Network/ike-issues#527) to scan for
__ALIASdeclarations.- Parameters:
pomContent- the raw POM text- Returns:
- name → value map of declared properties; empty if no
<properties>block exists
-