Class AbstractUpgradeStrategy
java.lang.Object
org.apache.maven.cling.invoker.mvnup.goals.AbstractUpgradeStrategy
- All Implemented Interfaces:
UpgradeStrategy
- Direct Known Subclasses:
CompatibilityFixStrategy, InferenceStrategy, ModelUpgradeStrategy, PluginUpgradeStrategy
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal UpgradeResultapply(UpgradeContext context, Map<Path, eu.maveniverse.domtrip.Document> pomMap) Template method that handles common logging and error handling.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.protected abstract UpgradeResultdoApply(UpgradeContext context, Map<Path, eu.maveniverse.domtrip.Document> pomMap) Subclasses implement the actual upgrade logic here.static eu.maveniverse.domtrip.maven.CoordinatesextractArtifactCoordinatesWithParentResolution(UpgradeContext context, eu.maveniverse.domtrip.Document pomDocument) Extracts an Artifact from a POM document with parent resolution.protected final UpgradeOptionsgetOptions(UpgradeContext context) Gets the upgrade options from the context.protected voidlogSummary(UpgradeContext context, UpgradeResult result) Logs a summary of the upgrade results.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface UpgradeStrategy
getDescription, isApplicable, isOptionEnabled
-
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:
applyin interfaceUpgradeStrategy- Parameters:
context- the upgrade contextpomMap- 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 contextpomMap- map of all POM files in the project- Returns:
- the result of the upgrade operation
-
getOptions
Gets the upgrade options from the context.- Parameters:
context- the upgrade context- Returns:
- the upgrade options
-
logSummary
Logs a summary of the upgrade results.- Parameters:
context- the upgrade contextresult- 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 loggingpomDocument- 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 loggingpomMap- map of all POM files in the project- Returns:
- set of all Artifacts in the project
-