Fix ToolchainPluginStrategy to detect inherited source levels from parent POMs - #12973
Fix ToolchainPluginStrategy to detect inherited source levels from parent POMs#12973gnodet wants to merge 2 commits into
Conversation
…rent POMs When a project inherits --source/--release from a remote parent POM (e.g. org.apache.sling:sling-parent setting --source 6), mvnup's ToolchainPluginStrategy failed to detect it because detectSourceLevel() only inspected the local POM XML DOM. This caused mvnup to skip adding the toolchains plugin, leading to Maven 4 build failures. Changes: - Share the Maven 4 API Session across all strategy instances (DCL singleton) so the Session's RequestCache deduplicates effective model builds across PluginUpgradeStrategy, ToolchainPluginStrategy, and CompatibilityFixStrategy - Route buildEffectiveModel() through InternalSession.request() to leverage the RequestCache - Add effective model fallback in ToolchainPluginStrategy: when local POM has no source level, resolve the effective model to pick up inherited compiler configuration from parent POMs - Add 8 new tests for effective model source level detection Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
3a3c891 to
aaca753
Compare
Move the Maven 4 API Session creation from AbstractUpgradeStrategy into a dedicated MvnupSessionHolder class that uses @provides @singleton to produce the Session as a DI-managed bean. The DI container calls createSession() once and injects the singleton Session into all strategy instances via @Inject @nAmed("mvnup") field injection on the abstract base class. This replaces the manual DCL singleton pattern with proper DI lifecycle management. A static fallback in getSession() preserves backward compatibility for unit tests that instantiate strategies directly (without DI). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
9d704c2 to
a3c0591
Compare
gnodet
left a comment
There was a problem hiding this comment.
Well-structured refactoring that correctly extracts session management into a DI-managed singleton, adds a proper DCL fallback for tests, and implements sound effective model source-level detection with good test coverage.
Observations (non-blocking):
-
[low]
detectFromEffectivePlugins()matches only onartifactId(ToolchainPluginStrategy.java~line 346) — Unlike the XML-baseddetectFromPluginSection()which also validatesgroupId, the effective model path checks onlyartifactId. Safe in practice since Maven defaults the groupId toorg.apache.maven.plugins, but it's an inconsistency between the two code paths. -
[low] Documentation accuracy (
MvnupSessionHolder.java~line 50) — The Javadoc states the shared session enables cache sharing acrossPluginUpgradeStrategy,ToolchainPluginStrategy, andCompatibilityFixStrategy. In practice,PluginUpgradeStrategybuilds effective models from temporary POM paths whileToolchainPluginStrategyuses real POM paths, so cross-strategy deduplication won't actually occur between those two.
What looks good:
- DCL pattern is textbook correct:
volatilefield, outer null check,synchronizedblock, inner null check @Inject @Named("mvnup")/@Provides @Singleton @Named("mvnup")pairing avoids DI conflictsRequestCacheintegration is sound —ModelBuilderRequesthas properequals()/hashCode()for cache key deduplication- Exception handling in
detectSourceLevelFromEffectiveModel()correctly catches all exceptions and falls back to -1 - 8 new tests cover property and plugin detection paths well, including precedence rules
This review was generated by an AI agent (Claude Code) and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of Guillaume Nodet
Summary
RequestCacheto deduplicate effective model builds acrossPluginUpgradeStrategy,ToolchainPluginStrategy, andCompatibilityFixStrategybuildEffectiveModel()throughInternalSession.request()to leverage theRequestCache— identicalModelBuilderRequestobjects (same POM path) return cached resultsToolchainPluginStrategy: when the local POM XML has no--source/--releaseconfig, resolve the fully-inherited effective model to detect compiler settings from parent POMs (e.g.org.apache.sling:sling-parentsetting--source 6)Problem
When a project inherits
--source 6from a remote parent POM,mvnup'sToolchainPluginStrategysaid "No source level configured" and skipped adding the toolchains plugin. This caused Maven 4 build failures because:detectSourceLevel()only inspected the local POM XML DOMTest plan
ToolchainPluginStrategyTesttests passPluginUpgradeCliTest)🤖 Generated with Claude Code