Class PomModel
java.lang.Object
network.ike.plugin.ws.PomModel
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 Summary
Modifier and TypeMethodDescriptionList<org.apache.maven.api.model.Dependency> All dependencies from both<dependencies>and<dependencyManagement>sections.List<org.apache.maven.api.model.Plugin> All plugins from both<build><plugins>and<build><pluginManagement><plugins>sections.content()Raw POM text for targeted editing.org.apache.maven.api.model.Modelmodel()The underlying Maven 4 model.org.apache.maven.api.model.Parentparent()Parent info, or null if no parent block.static PomModelParse a POM file into a model with location tracking.Properties from<properties>.static StringupdateDependencyVersion(String pomContent, String groupId, String artifactId, String newVersion) Update the version of a specific dependency identified bygroupId:artifactId.static StringupdateParentVersion(String pomContent, String parentGroupId, String parentArtifactId, String newVersion) Update the parent version in a POM's<parent>block.static StringupdatePluginVersion(String pomContent, String groupId, String artifactId, String newVersion) Update the version of a specific plugin identified bygroupId:artifactId.static StringupdateProperty(String pomContent, String propertyName, String newValue) Update a version property value in the POM content.
-
Method Details
-
parse
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
Raw POM text for targeted editing. -
allDependencies
All dependencies from both<dependencies>and<dependencyManagement>sections. -
allPlugins
All plugins from both<build><plugins>and<build><pluginManagement><plugins>sections. -
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 bygroupId:artifactId. Uses OpenRewrite LST for element-order-tolerant matching within dependency blocks.- 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
-
updateProperty
Update a version property value in the POM content. Uses OpenRewrite LST for precise property matching.- Parameters:
pomContent- the raw POM textpropertyName- 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 textparentGroupId- the parent groupId to matchparentArtifactId- the parent artifactId to matchnewVersion- 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 bygroupId:artifactId. Uses OpenRewrite LST for element-order-tolerant matching within plugin blocks, including 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
-