Class PomRewriter

java.lang.Object
network.ike.plugin.PomRewriter

public final class PomRewriter extends Object
AST-aware POM manipulation using OpenRewrite's XML LST.

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 Details

    • updateDependencyVersion

      public static String updateDependencyVersion(String pomContent, String groupId, String artifactId, String newVersion)
      Update the version of a specific dependency identified by groupId:artifactId anywhere in the POM (both <dependencies> and <dependencyManagement>).
      Parameters:
      pomContent - the raw POM text
      groupId - dependency groupId to match
      artifactId - dependency artifactId to match
      newVersion - 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 match parentGroupId: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 text
      parentGroupId - 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 matching groupId:artifactId in 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-parent vs. network.ike.pipeline:ike-parent) — see issue #241.

      Parameters:
      pomContent - the raw POM text
      parentGroupId - 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

      public static String updateProperty(String pomContent, String propertyName, String newValue)
      Update a version property value in the POM's <properties> block.
      Parameters:
      pomContent - the raw POM text
      propertyName - 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 by groupId:artifactId anywhere in the POM (both <plugins> and <pluginManagement>).
      Parameters:
      pomContent - the raw POM text
      groupId - plugin groupId to match
      artifactId - plugin artifactId to match
      newVersion - the version to set
      Returns:
      updated POM text, or unchanged if no match
    • removeDependencyVersion

      public static String removeDependencyVersion(String pomContent, String groupId, String artifactId)
      Remove the <version> child from a dependency matched by groupId:artifactId. Used to eliminate intra-reactor version pins where the reactor resolves the version automatically.
      Parameters:
      pomContent - the raw POM text
      groupId - dependency groupId to match
      artifactId - dependency artifactId to match
      Returns:
      updated POM text with version tag removed, or unchanged if no match
    • addProperty

      public static String addProperty(String pomContent, String propertyName, String propertyValue)
      Add a property to the POM's <properties> block. No-op if the property is already declared (use updateProperty(String, String, String) to change an existing value). No-op if the POM has no <properties> block.

      Introduced for the __ALIAS indirection bake step (IKE-Network/ike-issues#527): release-publish reads __ALIAS declarations and materializes the corresponding <short>${canonical}</short> indirections into the release-tagged source pom.

      Parameters:
      pomContent - the raw POM text
      propertyName - the property name to add
      propertyValue - the property value
      Returns:
      updated POM text, or unchanged if the property is already declared or no <properties> block exists
    • removeProperty

      public static String removeProperty(String pomContent, String propertyName)
      Remove a property from the POM's <properties> block. No-op if the property is not declared.

      Introduced for the __ALIAS indirection 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 text
      propertyName - the property name to remove
      Returns:
      updated POM text, or unchanged if no match
    • listProperties

      public static Map<String,String> listProperties(String pomContent)
      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 __ALIAS declarations.

      Parameters:
      pomContent - the raw POM text
      Returns:
      name → value map of declared properties; empty if no <properties> block exists