Class AbstractUpgradeStrategy
- All Implemented Interfaces:
UpgradeStrategy
- Direct Known Subclasses:
CompatibilityFixStrategy, DeduplicateDependenciesStrategy, DuplicateElementStrategy, EnforcerVersionRangeStrategy, InferenceStrategy, ModelUpgradeStrategy, ModuleNameFixStrategy, NashornCompatibilityStrategy, PluginUpgradeStrategy, RepositoryHttpsUpgradeStrategy, ResourceFilteringStrategy, SourceStrategy, ToolchainPluginStrategy
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
Effective model building
Each apply(UpgradeContext, Map) call pre-builds effective models for the whole reactor
in a single BUILD_PROJECT pass via prebuildReactorModels(UpgradeContext, Set).
This ensures that:
- Profile activation (file, property, condition) works correctly — not just OS/JDK/activeByDefault profiles;
- Maven 4 coordinate inference (
version/groupIdfrom reactor siblings) works becausemappedSourcesis populated for the whole reactor before any individual POM is resolved; - Remote parent resolution shares a single model-builder session, so artifacts fetched for one module are not re-fetched for siblings.
The resulting Map<Path, Model> cache is stored in
effectiveModelCache and consulted by buildEffectiveModel(UpgradeContext, Path).
For paths not in the cache (external parents reached during a parent-walk),
a fallback BUILD_EFFECTIVE call is made on the same
ModelBuilder.ModelBuilderSession, which still benefits from the
already-populated mappedSources.
Both the cache and the session are reset to null in the finally
block of apply(UpgradeContext, Map) so that singleton strategy instances do not leak state
across invocations or test runs.
-
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.protected ModelbuildEffectiveModel(UpgradeContext context, Path pomPath) Returns the effective model for the given POM path.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 PathfindCommonRoot(Set<Path> pomPaths) protected final UpgradeOptionsgetOptions(UpgradeContext context) Gets the upgrade options from the context.protected Sessionprotected voidlogSummary(UpgradeContext context, UpgradeResult result) Logs a summary of the upgrade results.protected static StringReturns the reason why remote resolution cannot honor the operator's configured repository posture, ornullif remote resolution may proceed.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().Before delegating to
doApply(UpgradeContext, Map), pre-builds effective models for every POM inpomMapvia a singleBUILD_PROJECTreactor pass so thatbuildEffectiveModel(UpgradeContext, Path)can serve from cache for the common case.- 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
-
getSession
-
remoteResolutionUnsupportedReason
Returns the reason why remote resolution cannot honor the operator's configured repository posture, ornullif remote resolution may proceed.The standalone resolver session used by mvnup does not apply mirrors, proxies or offline mode from the effective settings. Rather than silently resolving remote POMs while ignoring that configuration, strategies must call this method and skip the remote-model-dependent work whenever a posture is configured that the standalone session cannot honor.
Blocked mirrors (such as the default
external:http:*blocker shipped in the Maven installation settings) do not redirect traffic and therefore do not disable remote resolution by themselves.- Parameters:
context- the upgrade context- Returns:
- a human-readable reason to skip remote resolution, or
nullif allowed
-
findCommonRoot
-
buildEffectiveModel
Returns the effective model for the given POM path.Consults
effectiveModelCachefirst (populated by theBUILD_PROJECTreactor pass inprebuildReactorModels(UpgradeContext, Set)). If the path is not in the cache (e.g. an external parent that was not part of the reactor), falls back to aBUILD_EFFECTIVEcall onsharedModelBuilderSession, which still benefits from themappedSourcespopulated during the reactor build.- Parameters:
context- the upgrade context (used for debug logging)pomPath- the path to the POM file- Returns:
- the effective model, never
null
-