Class PomModel

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

public final class PomModel extends Object
Read-only POM model backed by Maven 4's maven-api-model.

Parses a POM file using MavenStaxReader with location tracking enabled. Provides typed access to dependencies, properties, and parent — replacing regex-based extraction throughout the workspace plugin.

For writes, static utility methods delegate to PomRewriter, which uses OpenRewrite's XML Lossless Semantic Tree to update version elements in place — preserving whitespace, comments, and quote style. Regex/sed-style substitution on POMs is forbidden; see feedback_no_sed_on_poms.

  • Method Details

    • parse

      public static PomModel parse(Path pomFile) throws IOException
      Parse a POM file into a model with location tracking.
      Parameters:
      pomFile - path to pom.xml
      Returns:
      parsed model
      Throws:
      IOException - if the file cannot be read or parsed
    • model

      public org.apache.maven.api.model.Model model()
      The underlying Maven 4 model.
    • content

      public String content()
      Raw POM text for targeted editing.
    • allDependencies

      public List<org.apache.maven.api.model.Dependency> allDependencies()
      All dependencies from both <dependencies> and <dependencyManagement> sections.
    • allPlugins

      public List<org.apache.maven.api.model.Plugin> allPlugins()
      All plugins from both <build><plugins> and <build><pluginManagement><plugins> sections.
    • properties

      public Map<String,String> properties()
      Properties from <properties>.
    • parent

      public org.apache.maven.api.model.Parent parent()
      Parent info, or null if no parent block.
    • updateDependencyVersion

      public static String updateDependencyVersion(String pomContent, String groupId, String artifactId, String newVersion)
      Update the version of a specific dependency identified by groupId:artifactId. Uses OpenRewrite LST for element-order-tolerant matching within dependency blocks.
      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
    • updateProperty

      public static String updateProperty(String pomContent, String propertyName, String newValue)
      Update a version property value in the POM content. Uses OpenRewrite LST for precise property matching.
      Parameters:
      pomContent - the raw POM text
      propertyName - the property name (e.g., "tinkar-core.version")
      newValue - the new property value
      Returns:
      updated POM text
    • updateParentVersion

      public static String updateParentVersion(String pomContent, String parentGroupId, String parentArtifactId, String newVersion)
      Update the parent version in a POM's <parent> block. Uses OpenRewrite LST for element-order-tolerant matching.

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

      Parameters:
      pomContent - the raw POM text
      parentGroupId - the parent groupId to match
      parentArtifactId - the parent artifactId to match
      newVersion - the new version to set
      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. Uses OpenRewrite LST for element-order-tolerant matching within plugin blocks, including 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