gnodet-bot commented on code in PR #1774:
URL: https://github.com/apache/maven/pull/1774#discussion_r4292724182


##########
impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultProfileActivationContext.java:
##########
@@ -484,7 +524,7 @@ private String interpolate(String path) throws 
InterpolatorException {
             if ("project.rootDirectory".equals(s)) {
                 return getModelRootDirectory();
             }
-            String r = getModelProperty(s);
+            String r = getModelPropertyForActivation(s);

Review Comment:
   ⚠️ **Path interpolation lookup order is backwards — `interpolate()` shadows 
user `-D` flags with cascaded/model properties.**
   
   `getModelPropertyForActivation(s)` (cascaded + model properties) is checked 
**first**, before `getUserProperty(s)` and `getSystemProperty(s)`. This 
contradicts the documented Maven precedence and is inconsistent with 
`ConditionProfileActivator.doGetProperty()` in this same PR (user → system → 
cascaded → model) and with `PropertyProfileActivator.isActive()` (same order).
   
   Concrete failure: user runs `mvn -Dmy.dir=/opt/custom ...`. Profile A has 
`<properties><my.dir>/default/path</my.dir></properties>`. Profile B has 
`<exists>${my.dir}/marker</exists>`. With the current code, A's model property 
wins over the user's `-D` flag — B activates or not based on 
`/default/path/marker` instead of `/opt/custom/marker`. The same `-D` **would** 
win in `PropertyProfileActivator` (correct precedence there). This divergence 
is a bug.
   
   Fix the order to match `ConditionProfileActivator.doGetProperty()`:
   ```java
   String r = getUserProperty(s);
   if (r == null) {
       r = getSystemProperty(s);
   }
   if (r == null) {
       r = getModelPropertyForActivation(s);
   }
   ```



##########
impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultProfileSelectorTest.java:
##########
@@ -0,0 +1,410 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.impl.model;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.api.model.Activation;
+import org.apache.maven.api.model.ActivationProperty;
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.model.Profile;
+import org.apache.maven.impl.DefaultModelVersionParser;
+import org.apache.maven.impl.model.profile.PropertyProfileActivator;
+import org.apache.maven.impl.model.profile.SimpleProblemCollector;
+import org.apache.maven.impl.model.rootlocator.DefaultRootLocator;
+import org.eclipse.aether.util.version.GenericVersionScheme;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Tests {@link DefaultProfileSelector} with focus on cascading activation 
behavior.
+ */
+public class DefaultProfileSelectorTest {

Review Comment:
   ⚠️ **No test for file-existence cascade behavior.**
   
   The SPI Javadoc on `interpolatePath` now explicitly states: *"file-existence 
conditions (`<exists>`, `<missing>`) can depend on properties set by earlier 
profiles in the activation cascade."* But `DefaultProfileSelectorTest` only 
tests `PropertyProfileActivator` cascading. A test with a file-existence 
activator triggered by a cascaded property is needed — it would also have 
caught the lookup-order bug above (the test would fail with the current 
ordering).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to