Class PomParentSupport

java.lang.Object
network.ike.plugin.ws.PomParentSupport

public final class PomParentSupport extends Object
Utilities for reading and updating <parent> blocks in POM files.

Reading uses the Maven 4 model API via PomModel. Writing uses the OpenRewrite LST via PomRewriter. Thread-safe — all methods are stateless.

  • Method Details

    • readParent

      public static PomParentSupport.ParentInfo readParent(Path pomFile) throws IOException
      Read the parent block from a POM file using the Maven 4 model API.
      Parameters:
      pomFile - path to pom.xml
      Returns:
      the parent info, or null if no parent block
      Throws:
      IOException - if the file cannot be read or parsed
    • updateParentVersion

      public static String updateParentVersion(String pomContent, String parentGroupId, String parentArtifactId, String newVersion)
      Update the parent version for a matching groupId:artifactId. Delegates to PomRewriter for AST-aware manipulation.

      Matching requires both groupId and artifactId to match — see issue #241.

      Parameters:
      pomContent - POM XML as a string
      parentGroupId - the groupId to match in the parent block
      parentArtifactId - the artifactId to match in the parent block
      newVersion - the new version to set
      Returns:
      updated POM content (unchanged if no match)
    • hasEmptyRelativePath

      public static boolean hasEmptyRelativePath(Path pomFile) throws IOException
      Check whether a POM's <parent> block declares an empty <relativePath/> (self-closing or empty content).

      An empty relativePath disables Maven's filesystem lookup for the parent — required to prevent the parent-cycle model-builder error when a subproject's <parent> GA matches the workspace aggregator's own parent GA (ike-issues#324).

      Detection is text-based rather than model-based: Maven 4's Parent model assigns a default value (typically "../pom.xml") to absent relativePath elements, so the parsed model cannot reliably distinguish "absent" from "default" from "explicit empty". The raw XML preserves that information.

      Parameters:
      pomFile - path to pom.xml
      Returns:
      true when the POM's <parent> block contains an empty <relativePath/>; false when absent, non-empty, or the parent block itself is missing
      Throws:
      IOException - if the file cannot be read
    • hasEmptyRelativePathInContent

      public static boolean hasEmptyRelativePathInContent(String pomContent)
      Same as hasEmptyRelativePath(Path) but operating on raw POM content. Used directly by tests and any caller that already has the content in memory.
      Parameters:
      pomContent - raw POM XML
      Returns:
      true when the <parent> block contains an empty <relativePath/>