Repository navigation
Remove Profile getSource / setSource - #12377
Conversation
852c95f to
5e98283
Compare
There was a problem hiding this comment.
Pull request overview
Removes legacy Profile source tracking (getSource/setSource and related constants) from the API model starting with model version 4.2.0, and updates the impl layer to distinguish POM vs settings profiles via InputLocation/InputSource (per #2569).
Changes:
- Split API model code generation segments so
Profile.getSource/setSourceexist only for 4.0.x and 4.1.x, and are removed for 4.2.0+. - Update
DefaultProfileSelectorto classify “from POM” profiles based on a non-emptyInputSource.getModelId(). - Remove impl-layer writes to
Profile.setSource("settings.xml")and add tests covering the updated activation behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultProfileSelectorTest.java | Adds coverage for POM vs settings profile handling using InputSource model id, including edge cases. |
| impl/maven-impl/src/main/java/org/apache/maven/impl/SettingsUtilsV4.java | Stops setting Profile source explicitly; relies on InputLocation/InputSource instead. |
| impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultProfileSelector.java | Replaces Profile.getSource() checks with InputSource.getModelId()-based origin detection. |
| api/maven-api-model/src/main/mdo/maven.mdo | Adjusts generated API model versions: retains source API for 4.0.x/4.1.x and removes it for 4.2.0+. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
gnodet
left a comment
There was a problem hiding this comment.
LGTM — Clean removal of the legacy Profile.getSource()/setSource() methods from the 4.2.0+ API model, correctly replacing usages in the impl layer with InputSource.getModelId() checks. The compat layer retains backward compatibility for 4.0.x/4.1.x consumers.
Highlights:
- The version segmentation strategy (4.0.0/4.0.99, 4.1.0/4.1.99, 4.2.0+) is well-structured and ensures backward compatibility at each layer
- The replacement mechanism using
InputSource.getModelId()is sound: POM profiles get a modelId during parsing while settings profiles get an empty string, naturally distinguishing profile sources without a separate mutable field - The new
DefaultProfileSelectorTestis thorough: covers POM-only, settings-only, mixed, null-modelId, no-location, and exception cases - japicmp passes, confirming no binary compatibility violations
- CI is fully green across all platforms
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of Guillaume Nodet
gnodet
left a comment
There was a problem hiding this comment.
Well-structured API evolution that correctly removes Profile.getSource()/setSource() from the 4.2.0+ model and replaces the profile-origin check with InputSource.getModelId()-based detection. The new isFromPom() logic is sound, the MDO version segmentation is correct, and the test coverage is thorough.
Two observations (informational, not blocking — self-authored PR, cannot self-approve):
-
Compat behavior change (medium): The 4.0.0/4.0.99 code segment change from delegating
getSource()/setSource()to using its own field means compatProfileobjects created viaSettingsUtils.convertFromSettingsProfile()will now return"pom"fromgetSource()instead of"settings.xml", becauseSettingsUtilsV4no longer callssetSource("settings.xml")and the compat constructor initializes the field toSOURCE_POM. This affects the deprecated compatDefaultProfileSelector, which usesProfile.SOURCE_POM.equals(profile.getSource()). In the compat code path, a settingsactiveByDefaultprofile could be incorrectly suppressed. The impl layer is correct (usesisFromPom()), and the compat layer is deprecated, so likely acceptable — but third-party code using the Maven 3 compat API may observe changed behavior. Consider addingsetSource("settings.xml")in the compatSettingsUtilswrapper to preserve old behavior. -
Edge case (low): The
isFromPom()method defaults totruewhen noInputLocationis available. Correct default (matches previousSOURCE_POMinitialization), but if a settings profile is created without location tracking, it would be treated as a POM profile.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of gnodet
gnodet
left a comment
There was a problem hiding this comment.
Well-structured API evolution that correctly removes Profile.getSource()/setSource() from the 4.2.0+ model, replaces the profile-origin check in the impl layer with InputSource.getModelId()-based detection, and adds thorough test coverage. CI is fully green (22/22 checks).
Observations
Compat behavioral change (medium): SettingsUtils.convertFromSettingsProfile() in the compat layer wraps the API Profile returned by SettingsUtilsV4. Since the PR changes the 4.0.0/4.0.99 segment to use its own field (initialized to SOURCE_POM) and removes the setSource("settings.xml") call from SettingsUtilsV4, compat Profile objects for settings profiles will now return "pom" from getSource() instead of "settings.xml". This could affect code using the deprecated compat DefaultProfileSelector (which checks Profile.SOURCE_POM.equals(profile.getSource())), potentially causing settings activeByDefault profiles to be incorrectly suppressed. The impl path is unaffected since it uses isFromPom() via InputSource.getModelId(). Could be fixed by adding result.setSource(Profile.SOURCE_SETTINGS) in the compat wrapper if needed.
isFromPom() default (low): The method defaults to true when no InputLocation is available — matching the previous SOURCE_POM field default. If a settings profile is programmatically constructed without location tracking, it would be incorrectly treated as a POM profile. In practice, settings.xml is always parsed with location info, so this is unlikely to occur.
✅ Strengths
- Version segmentation (4.0.0/4.0.99, 4.1.0/4.1.99, 4.2.0+) is well-structured and preserves backward compat at each layer
isFromPom()logic is sound: settings profiles get emptymodelIdviaSettingsUtilsV4.toLocation(), POM profiles get non-emptymodelIdduring parsing- New
DefaultProfileSelectorTestis thorough: covers POM-only, settings-only, mixed, null-modelId, no-location, and exception cases
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of Guillaume Nodet
gnodet-bot
left a comment
There was a problem hiding this comment.
Compat layer regression: settings profiles' activeByDefault behavior is broken.
SettingsUtils.convertFromSettingsProfile() (in impl/maven-core) wraps the API Profile returned by SettingsUtilsV4.convertFromSettingsProfile(). The compat Profile.getSource() delegates directly to getDelegate().getSource() on the wrapped API model object.
The API model Profile (4.1.0 segment) defaults source to SOURCE_POM ("pom"). Before this PR, SettingsUtilsV4.convertFromSettingsProfile() called value.setSource("settings.xml") to override that default. After this PR removes that call, the API Profile retains its default "pom" source — so the compat Profile.getSource() returns "pom" for settings profiles too.
compat/maven-model-builder/.../DefaultProfileSelector.java (still @Named @Singleton, used by Maven 3 embedders) checks Profile.SOURCE_POM.equals(profile.getSource()) at lines 73 and 77. After this PR, settings profiles match that check. The activeByDefault deactivation logic — which should only apply to POM profiles — now incorrectly applies to settings profiles: a settings activeByDefault profile will be suppressed when any POM profile is explicitly activated.
This is a behaviour change in the compat layer with no corresponding Maven 3.x port.
The fix is minimal — in SettingsUtils.convertFromSettingsProfile():
public static org.apache.maven.model.Profile convertFromSettingsProfile(Profile settingsProfile) {
org.apache.maven.model.Profile result = new org.apache.maven.model.Profile(
SettingsUtilsV4.convertFromSettingsProfile(settingsProfile.getDelegate()));
result.setSource(org.apache.maven.model.Profile.SOURCE_SETTINGS);
return result;
}
Note: the compat Profile.setSource() delegates to the API model's setSource(), which IS still present in the 4.1.0 segment — this works without touching the compat layer's own code.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
e225956 to
22b753e
Compare
gnodet-bot
left a comment
There was a problem hiding this comment.
The compat regression fix (result.setSource(SOURCE_SETTINGS) in SettingsUtils) is properly addressed, and the isFromPom() logic is correct with the right default-true fallback when location/source is null.
One observation: isFromPom() is duplicated verbatim across three classes — DefaultProfileSelector, ConditionProfileActivator, and PropertyProfileActivator. Consider extracting it to a shared utility (e.g. a static method on Profile or a ProfileUtils helper) to avoid future divergence.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
22b753e to
8e625ed
Compare
gnodet-bot
left a comment
There was a problem hiding this comment.
Following up on my earlier reviews — both previously-raised issues are addressed:
- ✅ Compat regression fix (
result.setSource(SOURCE_SETTINGS)inSettingsUtils) — confirmed in place - ✅
isFromPom()duplication — extracted toProfileSourceDetector, all three classes delegate to it
The ProfileSourceDetector.isFromPom() logic is correct. SettingsUtilsV4.toLocation() creates InputSource.of("", source.getLocation()) (empty modelId) for settings-sourced profiles, so isFromPom() reliably returns false for them. The default-to-true fallback for null-location profiles is safe — POM profiles always have location tracking; settings profiles without a location would be an edge case not reachable via the standard SettingsStaxReader.
One low-severity nit: ConditionProfileActivator declares its isFromPom() wrapper as private static (line 203), while the equivalent wrappers in DefaultProfileSelector and PropertyProfileActivator are private (non-static). All three delegate to a static method and use no instance state — they should be consistent. Prefer private static across all three, or drop the wrappers entirely and call ProfileSourceDetector.isFromPom(profile) directly.
LGTM otherwise — the new test coverage is solid, covering empty vs null modelId, mixed POM+settings activeByDefault suppression, and the no-location fallback.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
Remove getSource()/setSource() and SOURCE_POM/SOURCE_SETTINGS constants from the Profile class starting at model version 4.2.0. The 4.0.0 and 4.1.0 model versions retain these methods for backward compatibility. Replace usages in the impl layer (DefaultProfileSelector, SettingsUtilsV4, ConditionProfileActivator, PropertyProfileActivator) with InputLocation/InputSource checks. POM-originating profiles are now identified by having a non-null, non-empty InputSource.getModelId(). Fix compat-layer regression: SettingsUtils.convertFromSettingsProfile() now explicitly sets SOURCE_SETTINGS so that the compat DefaultProfileSelector still correctly identifies settings-originating profiles. Add tests for POM vs settings profile detection in DefaultProfileSelector.
8e625ed to
dead59e
Compare
gnodet-bot
left a comment
There was a problem hiding this comment.
Following up on my previous three reviews — the nit from Reviews 2 and 3 (private static consistency for isFromPom() wrappers) remains unaddressed.
All functional changes are correct: the .mdo version range split (4.0.0/4.0.99 → own field, 4.1.0/4.1.99 → retains methods, 4.2.0+ → removes source) is properly structured, the compat regression fix is in place, ProfileSourceDetector.isFromPom() logic is sound, and the new test coverage is thorough — covering POM activeByDefault suppression, settings activeByDefault non-suppression, null/empty modelId edge cases, no-location fallback, and the throwing-activator exception path.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
…ctor and PropertyProfileActivator
gnodet-bot
left a comment
There was a problem hiding this comment.
Following up on my previous four reviews — the last remaining nit (private static consistency for isFromPom() wrappers) is now addressed in both DefaultProfileSelector and PropertyProfileActivator.
All findings from my earlier reviews are resolved:
- ✅ Compat regression fix (
result.setSource(SOURCE_SETTINGS)inSettingsUtils) — in place - ✅
isFromPom()duplication — extracted toProfileSourceDetector - ✅
private staticconsistency — now applied uniformly across all three classes
LGTM.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
|
Conflicts — manual resolution needed:
|
…14069) * [Backport maven-4.0.x] #12377: Remove Profile getSource / setSource Backport of #12377 to maven-4.0.x. - Replace Profile.SOURCE_POM.equals(profile.getSource()) with isFromPom() using InputLocation/InputSource detection in DefaultProfileSelector, ConditionProfileActivator, and PropertyProfileActivator - Add ProfileSourceDetector utility class - Fix 4.0.0/4.0.99 compat segment to use own field instead of delegate - Note: cascading profile activation (from #1774) not backported; cascading-specific tests disabled with @disabled Cherry-picked from b0da053 * Address review: remove dead isFromPom() wrappers, fix @SInCE tag * fix: remove trailing blank lines (Spotless) * fix: schema codeSegment blocks - 4.0.0/4.0.99 keeps getSource/setSource, 4.1.0+ has clean toString only --------- Co-authored-by: Guillaume Nodet <[email protected]>
Summary
Profile.getSource(),Profile.setSource(),Profile.SOURCE_POM, andProfile.SOURCE_SETTINGSstarting at model version 4.2.0 (per Remove profile getSource / setSource #2569)InputLocation/InputSourcechecks: POM profiles are identified by having a non-nullInputSource.getModelId()getSource()/setSource()via its own model code segmentFiles changed (3):
api/maven-api-model/src/main/mdo/maven.mdo— split4.1.0+segment into4.1.0/4.1.99(keeps source methods) and4.2.0+(removes them); fix4.0.0/4.0.99to use own field instead of delegatingimpl/maven-impl/.../DefaultProfileSelector.java— replaceProfile.SOURCE_POM.equals(profile.getSource())withisFromPom()usingInputSource.getModelId()impl/maven-impl/.../SettingsUtilsV4.java— removevalue.setSource("settings.xml")Closes #2569
Test plan
getSource/setSourcegetSource/setSourcevia own field🤖 Generated with Claude Code