Repository navigation
Fix #13084: sandbox profile activation context for external model builds - #13112
Conversation
…el builds Replace the type-based profile pre-filter with a sandboxed ProfileActivationContext for repository-resolved (external) models — dependency POMs, parent POMs, imported BOMs. ## Problem The original fix (f599020) blocked file- and property-activated profiles in external model builds by pre-filtering the profile list. This correctly stopped consumer -D flags from activating dependency profiles, but had two flaws: 1. It also blocked profiles conditioned on the POM's own <properties> section, which are part of the artifact's published identity (not the consumer's environment). 2. apache#13095 worked around flaw (1) for the negated-property case (!foo) only, but missed the positive case where a publisher declares <properties><foo>bar</foo></properties> and conditions a profile on <property><name>foo</name></property>. ## Solution Instead of filtering profiles by activation type, pass all profiles to the selector but evaluate them against a sandboxed ProfileActivationContext that: - **Preserves system properties** (java.version, os.name, …) so JDK/OS activation works. - **Preserves model properties** (the POM's own <properties>) because they are part of the artifact's published identity, not the consumer's environment. - **Empties user properties** so consumer -D flags cannot activate dependency profiles. - **Disables file existence checks** (new stack: exists() returns false; legacy: file profiles are pre-filtered as before) because publisher paths don't exist in the consumer's environment. This is applied consistently in both the legacy compat stack (DefaultModelBuilder in maven-model-builder) and the new Maven 4 stack (DefaultModelBuilder in maven-impl). ## PropertyProfileActivator Both stacks' PropertyProfileActivator now consult model/project properties as a third fallback (after user → system), making POM-declared-property activation work correctly in all contexts including external model builds. ## Documentation Javadoc updated on ProfileActivationContext.getUserProperties() / getUserProperty() and getProjectProperties() / getModelProperty() to explain the external-model contract. ## Tests ExternalModelProfileActivationTest rewritten with 8 targeted cases covering: - File activation suppressed - User-property (-D) activation suppressed - System-property activation preserved - POM-declared-property activation preserved (the key new case) - Negated-property default-on activation preserved - JDK activation preserved - Profile repositories always stripped Supersedes apache#13095. Fixes apache#13084.
gnodet-bot
left a comment
There was a problem hiding this comment.
Solid approach. The sandbox pattern is a clear improvement over the type-based pre-filter — it correctly activates POM-declared property profiles while still suppressing consumer -D injection. Two findings below.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
some.gating.property and some.condition.property simulate -D flags in tests. With the sandbox approach, system properties survive the external-model context (they are platform facts like java.version), so these must be in userProperties to be correctly suppressed in external model builds.
gnodet-bot
left a comment
There was a problem hiding this comment.
Re-review after c639b4f (fix tests: move simulated -D flags from system to user properties).
The new commit correctly moves some.gating.property and some.condition.property from system to user properties in DefaultModelBuilderTest, so the external-model sandbox actually exercises its suppression logic. The test was previously passing for the wrong reason (gating props in system properties survived the sandbox). Good catch.
Two findings from the previous review remain unaddressed — re-raising below.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
- Fix compat PropertyProfileActivator comment referencing getExternalActivationContext() → externalActivationContext() - Pre-filter file-activated profiles in impl stack for external models, matching compat stack behavior: returning false from exists() alone would incorrectly activate <missing> profiles - Update Javadoc in DefaultProfileActivationContext to document the pre-filtering requirement
gnodet-bot
left a comment
There was a problem hiding this comment.
Re-review after 8ff7ca6e23 — both previous findings addressed.
- Javadoc method name (
getExternalActivationContext()→externalActivationContext()): fixed in the compatPropertyProfileActivatorcomment. <file><missing>behavioral asymmetry: the impl stack now pre-filters file-activated profiles before evaluation, matching the compat stack'swithoutFileActivation()approach. Both stacks are now consistent.
The sandbox approach is solid. Condition-activated profiles (impl stack) are no longer blanket-filtered but evaluated against the sandboxed context — this is strictly more correct since the sandbox naturally suppresses user-property references without losing condition expressions that depend only on system/model properties.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
The PropertyProfileActivator was unconditionally checking model/project properties (getModelProperty/getProjectProperties) for ALL profile evaluations, including the build's own project. This caused unintended profile activation when a POM declares a property that matches a profile's activation condition — e.g. the IT proxy profile activating because <proxy.host>localhost</proxy.host> was declared in <properties>. Fix: revert the model property fallback in PropertyProfileActivator and instead merge model properties into the system properties map within the sandboxed context used for external (dependency/parent/BOM) model builds. This ensures POM-declared properties drive profile activation only in external builds (where they represent the artifact's published identity), not in the build's own project (where they could conflict with activation conditions). Also use fully-qualified plugin coordinate in MNG-8736 IT to avoid NoPluginFoundForPrefixException in the restricted IT environment.
gnodet-bot
left a comment
There was a problem hiding this comment.
Re-review after f2bf110b0a — model property lookup moved from activator to sandbox context.
Good refactor. The previous approach (adding getProjectProperties() / getModelProperty() as a third fallback in PropertyProfileActivator) had the side effect of making POM-declared-property profiles fire in ALL builds, including the build's own project. This commit fixes that by merging model properties into the system properties map inside the sandbox only — so the activator's lookup chain stays unchanged for non-external models, and POM-declared properties only drive activation in external (dependency/parent/BOM) builds where they belong.
Both stacks are consistent:
- Compat sandbox:
getSystemProperties()merges project props into a newHashMap(system wins viaputAllordering) - Impl sandbox:
getSystemProperty(key)falls back togetModelProperty(key)per-key
Test updated correctly — assertNull for POM-declared-property profile in project builds, assertEquals("activated") in external builds.
The IT change (help:active-profiles → fully qualified maven-help-plugin:3.5.1:active-profiles) is a valid stability fix.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
…el builds Backport of apache#13112 to `maven-3.10.x`. Cherry-picked and manually adapted from the master commits: - e58a96a Fix apache#13084: sandbox profile activation context for external model builds - 8ff7ca6 Address review: fix Javadoc method ref and file-activation asymmetry - f2bf110 fix: move model property lookup from activator to sandbox context The second commit (c639b4f) was empty on this branch (it only touched impl/maven-impl/ which doesn't exist on maven-3.10.x; the equivalent adjustment was already included in the first commit's ResolvedDependencyProfileActivationTest). Conflicts resolved by adapting to the flat module layout of maven-3.10.x: - Changes to compat/maven-model-builder/ cherry-picked cleanly as maven-model-builder/ - Changes to impl/maven-impl/ have no direct equivalent (not removed — confirmed n/a) - Changes to its/core-it-suite/ removed (ITs are in a separate repo on this branch)
…efault-on profile Port test coverage gap flagged in gnodet-bot re-review: - Add testExternalModelSystemPropertySuppressesDefaultOnProfile: verifies that a consumer setting skip.defaults as a *system* property suppresses the dependency's default-on (!skip.defaults) profile in external builds. System properties pass through the sandbox unchanged; this is intentional behavior but was unprotected by a test.
gnodet-bot
left a comment
There was a problem hiding this comment.
Re-review after b1506fc1 — prior findings addressed; one new gap.
The new commit correctly reconciles with #13114: the !skip.defaults negated-property profile is wired into the impl fixture and tests, and the system-property-suppresses-default-on case is now covered in DefaultModelBuilderTest. One parallel-path asymmetry: the equivalent system-property-suppression test is missing from the compat stack.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
…proach Conflicts resolved: - impl/maven-impl/.../DefaultModelBuilder.java: keep sandbox activation (withoutUserPropertiesAndFilesystem) but drop repo stripping per apache#13100. Repositories from legitimately-active external profiles (JDK/OS/activeByDefault and POM-property-gated) are now honored, fixing the dep1→dep2 repo pattern. - compat/.../ExternalModelProfileActivationTest.java: keep comprehensive sandbox tests (file, user-prop, sys-prop, POM-declared, negated, JDK), update repo assertion from noneMatch→anyMatch, add testActiveByDefaultProfileRepositoryHonored from apache#13100.
…efault-on profile Port test coverage gap from the apache#13114 review: - Add negated-property-default-on profile to the XML fixture - Assert it fires in project builds (skip.defaults absent from system props) - Add testExternalModelSystemPropertySuppressesDefaultOnProfile: verifies that a consumer setting skip.defaults as a *system* property suppresses the dependency's default-on profile (system props pass through the sandbox)
b1506fc to
48bdea0
Compare
|
Conflict resolved with The two PRs are complementary — not contradictory. Merged approach:
All 50 tests pass (40 impl + 9 compat ExternalModelProfileActivationTest + 1 compat DefaultModelBuilderTest). |
Add testExternalModelSystemPropertySuppressesDefaultOnProfile to ExternalModelProfileActivationTest to mirror the equivalent test in DefaultModelBuilderTest (impl stack). Verifies that a system property named 'skip.defaults' suppresses the default-on negated-property profile (!skip.defaults) in external builds — system properties are platform facts that pass through the sandbox unchanged.
gnodet-bot
left a comment
There was a problem hiding this comment.
Re-review after 48bdea09 — previous finding partially addressed; compat test gap remains.
The new commit correctly adds testExternalModelSystemPropertySuppressesDefaultOnProfile to the impl stack (DefaultModelBuilderTest) and wires up the negated-property-default-on profile in the XML fixture. One gap carries over.
Previous finding (NOT addressed): compat stack missing system-property-suppresses-default-on test
The impl stack now asserts that setting skip.defaults as a system property suppresses the default-on !skip.defaults profile even in external builds (testExternalModelSystemPropertySuppressesDefaultOnProfile). The equivalent test is absent from ExternalModelProfileActivationTest (compat stack).
The compat externalActivationContext() merges model properties into system properties and suppresses user properties — the same sandbox logic as the impl stack. Without this test, a regression in externalActivationContext() that accidentally lets system properties through (or accidentally clears them) would go undetected on the compat path.
Missing test to add to compat/maven-model-builder/src/test/java/org/apache/maven/model/building/ExternalModelProfileActivationTest.java:
@Test
void testExternalModelSystemPropertySuppressesDefaultOnProfile() throws Exception {
// A system property named skip.defaults suppresses the default-on negated-property
// profile (!skip.defaults) even in external model builds: system properties are
// platform facts that pass through the sandbox unchanged.
Properties sp = systemPropertiesWithTestValues();
sp.setProperty("skip.defaults", "true"); // system-level opt-out
Model model = build(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL, sp, new Properties());
assertNull(
model.getProperties().get("profile.negated.property"),
"negated-property (default-on) profile must be suppressed when system property 'skip.defaults' is set");
}New (low): getSystemProperties() allocates a new HashMap on every call in the compat sandbox
In externalActivationContext() (compat DefaultModelBuilder), getSystemProperties() creates a fresh HashMap each time it is called. PropertyProfileActivator.isActive() calls it once per profile being evaluated — for a POM with many property-activated profiles this adds unnecessary allocations. The impl stack avoids this via scalar getSystemProperty(key) with a direct fallback to getModelProperty(key) (no map copy needed).
Consider caching the merged map in the anonymous class (computed once on first access via a field initialized lazily in the constructor or via Suppliers.memoize), or — better — following the impl's pattern of using the scalar getSystemProperty(String) method with a fallback, which the compat ProfileActivationContext interface also exposes.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
…model builds (#13114) Backport of #13112 to `maven-3.10.x`. Cherry-picked and manually adapted from the master commits: - e58a96a Fix #13084: sandbox profile activation context for external model builds - 8ff7ca6 Address review: fix Javadoc method ref and file-activation asymmetry - f2bf110 fix: move model property lookup from activator to sandbox context Conflicts resolved by adapting to the flat module layout of maven-3.10.x: - `compat/maven-model-builder/` → `maven-model-builder/` (flat layout) - `impl/maven-impl/` changes have no equivalent on 3.10.x (not present) - `its/core-it-suite/` changes dropped (ITs are in a separate repo on this branch) See #13112 for the full rationale and design.
…ndbox Avoid creating a new HashMap on every getSystemProperties() call in the anonymous ProfileActivationContext returned by externalActivationContext(). The merged map is now computed once on first access and cached in a field. This matches the intent of the impl stack which uses a scalar per-key lookup (getSystemProperty → getModelProperty) without any map copy. Addresses low-priority finding from code review.
|
Addressed the low-priority finding from the last review: caching the merged system+project properties map in |
gnodet-bot
left a comment
There was a problem hiding this comment.
Re-review after 95fefaf7e7 + 3639a89689 — both outstanding findings addressed.
-
Compat stack system-property suppression test (
testExternalModelSystemPropertySuppressesDefaultOnProfileinExternalModelProfileActivationTest): added, mirrors the impl stack test exactly. ✅ -
getSystemProperties()allocation per call (low, compat sandbox): fixed by adding amergedSystemPropertiescache field to the anonymousProfileActivationContext. The cache is correctly scoped per anonymous instance — a new instance is created per loop iteration (model in parent chain), andsetProjectProperties()mutates the delegate between iterations so each iteration needs its own merged map. No stale-cache risk. ✅
Both stacks are now consistent in behaviour and test coverage. The sandbox approach is solid.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
…el builds Backport of apache#13112 (master) and apache#13114 (maven-3.10.x) to maven-4.0.x. Instead of blanket-filtering file and property profiles in external model builds (dependency POMs, parent POMs, imported BOMs), evaluate them against a sandboxed ProfileActivationContext that: - Merges model properties into system property lookups (so POM-declared <properties> drive property-activated profiles in dependency builds). - Suppresses user properties (consumer -D flags must not activate dependency profiles — they were not set for that artifact). - Pre-filters file-activated profiles (returning false from exists() would incorrectly activate <missing> profiles). - Strips repository contributions from all active external profiles. Both compat and impl stacks are updated identically. The key insight is that model properties are merged into system properties inside the sandbox rather than changing PropertyProfileActivator's lookup chain, to avoid unintended activation when a project POM declares a property that coincidentally matches a profile's activation condition. Tests: ExternalModelProfileActivationTest (compat) and DefaultModelBuilderTest (impl) cover file suppression, user-property suppression, system-property preservation, POM-declared-property activation, negated-property default-on preservation, and system-property opt-out of the default-on pattern.
…lds (#13158) * Fix #13084: sandbox profile activation context for external model builds Backport of #13112 (master) and #13114 (maven-3.10.x) to maven-4.0.x. Instead of blanket-filtering file and property profiles in external model builds (dependency POMs, parent POMs, imported BOMs), evaluate them against a sandboxed ProfileActivationContext that: - Merges model properties into system property lookups (so POM-declared <properties> drive property-activated profiles in dependency builds). - Suppresses user properties (consumer -D flags must not activate dependency profiles — they were not set for that artifact). - Pre-filters file-activated profiles (returning false from exists() would incorrectly activate <missing> profiles). - Strips repository contributions from all active external profiles. Both compat and impl stacks are updated identically. The key insight is that model properties are merged into system properties inside the sandbox rather than changing PropertyProfileActivator's lookup chain, to avoid unintended activation when a project POM declares a property that coincidentally matches a profile's activation condition. Tests: ExternalModelProfileActivationTest (compat) and DefaultModelBuilderTest (impl) cover file suppression, user-property suppression, system-property preservation, POM-declared-property activation, negated-property default-on preservation, and system-property opt-out of the default-on pattern. * Address review: fix mutable map leak in compat sandbox context, pre-filter missing()-condition profiles in CONSUMER_DEPENDENCY builds
Problem
The fix in f599020 blocked file- and property-activated profiles in external (repository-resolved) model builds by pre-filtering the profile list before activation. This correctly stopped consumer
-Dflags from activating dependency profiles, but had a correctness gap:<properties>section — which are part of the artifact's published identity, not the consumer's build environment.#13095partially addressed this by allowing negated-property profiles (!foo), but missed the symmetric case: a publisher who declares<properties><foo>bar</foo></properties>and conditions a profile on<property><name>foo</name></property>would still be broken.Solution
Replace the type-based profile pre-filter with a sandboxed
ProfileActivationContextfor external model builds. All profiles are passed to the selector; the sandbox restricts what inputs they see:java.version,os.name, …)<properties>-Dflags)This gives correct results in all cases:
<property><name>foo</name></property>wherefoo=barin<properties>→ fires ✅<property><name>!foo</name></property>(absent from sandbox) → fires ✅ (default-on preserved)<property><name>flag</name></property>whereflagis only in consumer-D→ suppressed ✅<jdk>,<os>,activeByDefault→ always fire ✅Changes
Both stacks (compat
maven-model-builderand newimpl/maven-impl):DefaultModelBuilder: replace pre-filter with sandboxed context for theexternalOrigin/VALIDATION_LEVEL_MINIMALbranchPropertyProfileActivator: add model/project<properties>as third fallback in lookup chain (user → system → model)DefaultProfileActivationContext(new stack): addwithoutUserPropertiesAndFilesystem()returning a sandboxed context viewProfileActivationContextinterfaces: updated Javadoc ongetUserProperties()/getUserProperty()andgetProjectProperties()/getModelProperty()to document the external-model contractTests:
ExternalModelProfileActivationTestrewritten with 8 focused cases covering each activation type separately.Supersedes
Supersedes #13095 (which is a narrower workaround for the negated-property case only). Fixes #13084.