Skip to content

Remove Profile getSource / setSource - #12377

Merged
gnodet merged 3 commits into
apache:masterfrom
gnodet:fix-2569-remove-profile-getSource
Nov 18, 2026
Merged

gnodet merged 3 commits into
apache:masterfrom
gnodet:fix-2569-remove-profile-getSource

Conversation

@gnodet

@gnodet gnodet commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Removes Profile.getSource(), Profile.setSource(), Profile.SOURCE_POM, and Profile.SOURCE_SETTINGS starting at model version 4.2.0 (per Remove profile getSource / setSource #2569)
  • The 4.0.0 and 4.1.0 model versions retain these methods for backward compatibility (the 4.0.0 segment now uses its own field instead of delegating to the API model)
  • Replaces usages in the impl layer with InputLocation / InputSource checks: POM profiles are identified by having a non-null InputSource.getModelId()
  • The compat layer is unchanged — it still has getSource()/setSource() via its own model code segment

Files changed (3):

  • api/maven-api-model/src/main/mdo/maven.mdo — split 4.1.0+ segment into 4.1.0/4.1.99 (keeps source methods) and 4.2.0+ (removes them); fix 4.0.0/4.0.99 to use own field instead of delegating
  • impl/maven-impl/.../DefaultProfileSelector.java — replace Profile.SOURCE_POM.equals(profile.getSource()) with isFromPom() using InputSource.getModelId()
  • impl/maven-impl/.../SettingsUtilsV4.java — remove value.setSource("settings.xml")

Closes #2569

Test plan

  • Full build passes (all 38 modules, all tests green)
  • API Profile (4.2.0+) no longer has getSource/setSource
  • Compat Profile retains getSource/setSource via own field
  • No japicmp compatibility violations
  • CI build passes

🤖 Generated with Claude Code

@gnodet
gnodet force-pushed the fix-2569-remove-profile-getSource branch 2 times, most recently from 852c95f to 5e98283 Compare June 26, 2026 08:13
@gnodet
gnodet marked this pull request as ready for review June 26, 2026 14:20
@gnodet gnodet added this to the 4.1.0 milestone Jun 26, 2026
@gnodet
gnodet requested a review from Copilot July 7, 2026 08:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/setSource exist only for 4.0.x and 4.1.x, and are removed for 4.2.0+.
  • Update DefaultProfileSelector to classify “from POM” profiles based on a non-empty InputSource.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 gnodet left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 DefaultProfileSelectorTest is 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 gnodet left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):

  1. Compat behavior change (medium): The 4.0.0/4.0.99 code segment change from delegating getSource()/setSource() to using its own field means compat Profile objects created via SettingsUtils.convertFromSettingsProfile() will now return "pom" from getSource() instead of "settings.xml", because SettingsUtilsV4 no longer calls setSource("settings.xml") and the compat constructor initializes the field to SOURCE_POM. This affects the deprecated compat DefaultProfileSelector, which uses Profile.SOURCE_POM.equals(profile.getSource()). In the compat code path, a settings activeByDefault profile could be incorrectly suppressed. The impl layer is correct (uses isFromPom()), and the compat layer is deprecated, so likely acceptable — but third-party code using the Maven 3 compat API may observe changed behavior. Consider adding setSource("settings.xml") in the compat SettingsUtils wrapper to preserve old behavior.

  2. Edge case (low): The isFromPom() method defaults to true when no InputLocation is available. Correct default (matches previous SOURCE_POM initialization), 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 gnodet left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 empty modelId via SettingsUtilsV4.toLocation(), POM profiles get non-empty modelId during parsing
  • New DefaultProfileSelectorTest is 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 gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@gnodet
gnodet force-pushed the fix-2569-remove-profile-getSource branch from 22b753e to 8e625ed Compare November 6, 2026 01:48

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following up on my earlier reviews — both previously-raised issues are addressed:

  1. ✅ Compat regression fix (result.setSource(SOURCE_SETTINGS) in SettingsUtils) — confirmed in place
  2. ✅ isFromPom() duplication — extracted to ProfileSourceDetector, 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.
@gnodet
gnodet force-pushed the fix-2569-remove-profile-getSource branch from 8e625ed to dead59e Compare November 12, 2026 13:04

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. ✅ Compat regression fix (result.setSource(SOURCE_SETTINGS) in SettingsUtils) — in place
  2. ✅ isFromPom() duplication — extracted to ProfileSourceDetector
  3. ✅ private static consistency — now applied uniformly across all three classes

LGTM.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@gnodet
gnodet merged commit b0da053 into apache:master Nov 18, 2026
41 of 42 checks passed
@gnodet

gnodet commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Conflicts — manual resolution needed:

  • ❌ maven-4.0.x: Cherry-pick conflict in:

gnodet added a commit that referenced this pull request Nov 19, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove profile getSource / setSource

4 participants