Class AbstractUpgradeStrategy

java.lang.Object
org.apache.maven.cling.invoker.mvnup.goals.AbstractUpgradeStrategy
All Implemented Interfaces:
UpgradeStrategy
Direct Known Subclasses:
CompatibilityFixStrategy, InferenceStrategy, ModelUpgradeStrategy, PluginUpgradeStrategy

public abstract class AbstractUpgradeStrategy extends Object implements UpgradeStrategy
Abstract base class for upgrade strategies that provides common functionality and reduces code duplication across strategy implementations.

Strategies work with domtrip Documents for perfect formatting preservation. Subclasses can create domtrip Editors from Documents as needed:

Editor editor = new Editor(document);
// ... perform domtrip operations ...
// Document is automatically updated
  • Constructor Details

    • AbstractUpgradeStrategy

      public AbstractUpgradeStrategy()
  • Method Details

    • apply

      public final UpgradeResult apply(UpgradeContext context, Map<Path, eu.maveniverse.domtrip.Document> pomMap)
      Template method that handles common logging and error handling. Subclasses implement the actual upgrade logic in doApply().
      Specified by:
      apply in interface UpgradeStrategy
      Parameters:
      context - the upgrade context
      pomMap - map of all POM files in the project (domtrip Documents)
      Returns:
      the result of the upgrade operation
    • doApply

      protected abstract UpgradeResult doApply(UpgradeContext context, Map<Path, eu.maveniverse.domtrip.Document> pomMap)
      Subclasses implement the actual upgrade logic here.
      Parameters:
      context - the upgrade context
      pomMap - map of all POM files in the project
      Returns:
      the result of the upgrade operation
    • getOptions

      protected final UpgradeOptions getOptions(UpgradeContext context)
      Gets the upgrade options from the context.
      Parameters:
      context - the upgrade context
      Returns:
      the upgrade options
    • logSummary

      protected void logSummary(UpgradeContext context, UpgradeResult result)
      Logs a summary of the upgrade results.
      Parameters:
      context - the upgrade context
      result - the upgrade result
    • extractArtifactCoordinatesWithParentResolution

      public static eu.maveniverse.domtrip.maven.Coordinates extractArtifactCoordinatesWithParentResolution(UpgradeContext context, eu.maveniverse.domtrip.Document pomDocument)
      Extracts an Artifact from a POM document with parent resolution. If groupId or version are missing, attempts to resolve from parent.

      This method handles Maven's inheritance mechanism where groupId and version can be inherited from the parent POM.

      Parameters:
      context - the upgrade context for logging
      pomDocument - the POM document
      Returns:
      the Artifact or null if it cannot be determined
    • computeAllArtifactCoordinates

      public static Set<eu.maveniverse.domtrip.maven.Coordinates> computeAllArtifactCoordinates(UpgradeContext context, Map<Path, eu.maveniverse.domtrip.Document> pomMap)
      Computes all artifacts from all POMs in a multi-module project. This includes resolving parent inheritance.
      Parameters:
      context - the upgrade context for logging
      pomMap - map of all POM files in the project
      Returns:
      set of all Artifacts in the project