Class ModelVersionUtils

java.lang.Object
org.apache.maven.cling.invoker.mvnup.goals.ModelVersionUtils

public final class ModelVersionUtils extends Object
Utility class for handling Maven model version operations during upgrades.

This class uses domtrip internally for superior formatting preservation and simplified API while maintaining the same external interface.

  • Method Details

    • detectModelVersion

      public static String detectModelVersion(eu.maveniverse.domtrip.Document pomDocument)
      Detects the model version from a POM document. Uses both the modelVersion element and namespace URI for detection.
      Parameters:
      pomDocument - the POM document (domtrip Document)
      Returns:
      the detected model version
    • isValidModelVersion

      public static boolean isValidModelVersion(String modelVersion)
      Checks if a model version is valid for upgrade operations. Currently supports 4.0.0, 4.1.0, and 4.2.0.
      Parameters:
      modelVersion - the model version to validate
      Returns:
      true if the model version is valid
    • canUpgrade

      public static boolean canUpgrade(String fromVersion, String toVersion)
      Checks if an upgrade from one version to another is possible.
      Parameters:
      fromVersion - the source version
      toVersion - the target version
      Returns:
      true if the upgrade is possible
    • isEligibleForInference

      public static boolean isEligibleForInference(String modelVersion)
      Checks if a model version is eligible for inference optimizations. Models 4.0.0+ are eligible (4.0.0 has limited inference, 4.1.0+ has full inference).
      Parameters:
      modelVersion - the model version to check
      Returns:
      true if eligible for inference
    • isNewerThan410

      public static boolean isNewerThan410(String modelVersion)
      Checks if a model version is newer than 4.1.0.
      Parameters:
      modelVersion - the model version to check
      Returns:
      true if newer than 4.1.0
    • isVersionGreaterOrEqual

      public static boolean isVersionGreaterOrEqual(String modelVersion, String targetVersion)
      Checks if a model version is greater than or equal to a target version.
      Parameters:
      modelVersion - the model version to check
      targetVersion - the target version to compare against
      Returns:
      true if modelVersion >= targetVersion
    • updateModelVersion

      public static void updateModelVersion(eu.maveniverse.domtrip.Document pomDocument, String newVersion)
      Updates the model version element in a POM document.
      Parameters:
      pomDocument - the POM document (domtrip Document)
      newVersion - the new model version
    • removeModelVersion

      public static boolean removeModelVersion(eu.maveniverse.domtrip.Document document)
      Removes the model version element from a POM editor. This is used during inference when the model version can be inferred.
      Parameters:
      document - the XML document
      Returns:
      true if the element was removed, false if it didn't exist
    • getSchemaLocationForModelVersion

      public static String getSchemaLocationForModelVersion(String modelVersion)
      Gets the schema location for a model version.
      Parameters:
      modelVersion - the model version
      Returns:
      the schema location