This is an automated email from the ASF dual-hosted git repository.

slawekjaranowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git


The following commit(s) were added to refs/heads/master by this push:
     new 3b2d445b10 Issue #13883: Add tests for custom rootDirectory property 
and fix rootDirectory docs
3b2d445b10 is described below

commit 3b2d445b10ace42c48c10ecc34fe68bc2c258d14
Author: Slawomir Jaranowski <[email protected]>
AuthorDate: Sat Nov 7 20:59:06 2026 +0100

    Issue #13883: Add tests for custom rootDirectory property and fix 
rootDirectory docs
    
    Maven 3.10.0 resolves an unprefixed ${rootDirectory} to the project root
    directory, shadowing a custom rootDirectory property defined in the POM.
    Maven 4 is not affected: only ${project.rootDirectory} is supported and
    model properties take precedence.
    
    Add regression tests for model interpolation (impl) and file-based profile
    activation (impl and compat) to make sure a custom ${rootDirectory} property
    resolves to its own value, while ${project.rootDirectory} still points to 
the
    root directory, and that an unprefixed ${rootDirectory} is not interpolated
    as an alias.
    
    Fix the maven-model-builder documentation, which referred to
    ${rootDirectory} instead of ${project.rootDirectory}, and note that the
    property is available since Maven 3.10.0 (.mvn directory) and Maven 4
    (also root="true" attribute).
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../maven-model-builder/src/site/markdown/index.md |  6 +--
 .../activation/FileProfileActivatorTest.java       | 43 ++++++++++++++++
 .../impl/model/DefaultModelInterpolatorTest.java   | 59 ++++++++++++++++++++++
 .../model/profile/FileProfileActivatorTest.java    | 42 +++++++++++++++
 4 files changed, 147 insertions(+), 3 deletions(-)

diff --git a/compat/maven-model-builder/src/site/markdown/index.md 
b/compat/maven-model-builder/src/site/markdown/index.md
index d364507aee..acb1cbf174 100644
--- a/compat/maven-model-builder/src/site/markdown/index.md
+++ b/compat/maven-model-builder/src/site/markdown/index.md
@@ -33,7 +33,7 @@ The main component is `ModelBuilder` 
([javadoc](./apidocs/org/apache/maven/model
 The sequence is divided into 2 phases:
 
 - phase 1
-    - profile activation: see [available 
activators](./apidocs/org/apache/maven/model/profile/activation/package-summary.html).
 Notice that model interpolation hasn't happened yet, then interpolation for 
file-based activation is limited to `${basedir}` (since Maven 3), 
`${rootDirectory}` (since Maven 4), system properties and user properties
+    - profile activation: see [available 
activators](./apidocs/org/apache/maven/model/profile/activation/package-summary.html).
 Notice that model interpolation hasn't happened yet, then interpolation for 
file-based activation is limited to `${basedir}` (since Maven 3), 
`${project.rootDirectory}` (since Maven 3.10.0 and Maven 4), system properties 
and user properties
     - file model validation: `ModelValidator` 
([javadoc](./apidocs/org/apache/maven/model/validation/ModelValidator.html)), 
with its `DefaultModelValidator` implementation 
([source](./xref/org/apache/maven/model/validation/DefaultModelValidator.html))
 - phase 2, with optional plugin processing
     - Build up a raw model by re-reading the file and enriching it based on 
information available in the reactor. Some features:
@@ -73,7 +73,7 @@ Notice that the 5 URLs from the model (`project.url`, 
`project.scm.connection`,
 
 Model Interpolation consists in replacing `${...}` with calculated value. It 
is done in `StringVisitorModelInterpolator` 
([javadoc](./apidocs/org/apache/maven/model/interpolation/StringVisitorModelInterpolator.html),
 
[source](./xref/org/apache/maven/model/interpolation/StringVisitorModelInterpolator.html)).
 
-Notice that model interpolation happens _after_ profile activation, and that 
profile activation doesn't benefit from every values: interpolation for 
file-based activation is limited to `${basedir}` (which was introduced in Maven 
3 and is not deprecated in this context) and `${rootDirectory}` (introduced in 
Maven 4), system properties and user properties.
+Notice that model interpolation happens _after_ profile activation, and that 
profile activation doesn't benefit from every values: interpolation for 
file-based activation is limited to `${basedir}` (which was introduced in Maven 
3 and is not deprecated in this context) and `${project.rootDirectory}` 
(introduced in Maven 3.10.0 and Maven 4), system properties and user properties.
 
 Values are evaluated in sequence from different syntaxes:
 
@@ -82,7 +82,7 @@ Values are evaluated in sequence from different syntaxes:
 |`project.*` <br />`pom.*` (_deprecated_) <br />`*` (_deprecated_)|POM content 
(see [POM reference](../maven-model/maven.html))|`${project.version}` <br 
/>`${project.build.finalName}` <br />`${project.artifactId}` <br 
/>`${project.build.directory}`|
 |`project.basedir` <br />`pom.basedir` (_deprecated_) <br />`basedir` 
(_deprecated_)|the directory containing the `pom.xml` file|`${project.basedir}`|
 |`project.baseUri` <br />`pom.baseUri` (_deprecated_)|the directory containing 
the `pom.xml` file as URI|`${project.baseUri}`|
-|`project.rootDirectory`|the project's root directory (containing a `.mvn` 
directory or with the `root="true"` xml attribute)|`${project.rootDirectory}`|
+|`project.rootDirectory`|the project's root directory (containing a `.mvn` 
directory _(since Maven 3.10.0 and Maven 4)_, or with the `root="true"` xml 
attribute _(since Maven 4)_)|`${project.rootDirectory}`|
 |`build.timestamp` <br />`maven.build.timestamp`|the UTC timestamp of build 
start, in `yyyy-MM-dd'T'HH:mm:ss'Z'` default format, which can be overridden 
with `maven.build.timestamp.format` POM property|`${maven.build.timestamp}`|
 |`*`|user properties, set from CLI with `-Dproperty=value`|`${skipTests}`|
 |`*`|model properties, such as project properties set in the pom|`${any.key}`|
diff --git 
a/compat/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/FileProfileActivatorTest.java
 
b/compat/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/FileProfileActivatorTest.java
index 35440a15cf..5216ddf1d8 100644
--- 
a/compat/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/FileProfileActivatorTest.java
+++ 
b/compat/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/FileProfileActivatorTest.java
@@ -20,7 +20,9 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.file.Files;
 import java.nio.file.Path;
+import java.util.Properties;
 
 import org.apache.maven.api.model.Activation;
 import org.apache.maven.api.model.ActivationFile;
@@ -90,6 +92,47 @@ void testRootDirectory() {
         assertActivation(false, newMissingProfile("${project.rootDirectory}/" 
+ "file.txt"), context);
     }
 
+    @Test
+    void testCustomRootDirectoryPropertyIsNotShadowed() throws Exception {
+        // GH-13883: a custom ${rootDirectory} property must not be shadowed 
by ${project.rootDirectory}
+        Properties modelProperties = new Properties();
+        modelProperties.setProperty("rootDirectory", "${project.basedir}");
+        DefaultProfileActivationContext moduleContext = 
newModuleContext(modelProperties);
+
+        assertActivation(true, 
newExistsProfile("${rootDirectory}/module-file.txt"), moduleContext);
+        assertActivation(false, newExistsProfile("${rootDirectory}/file.txt"), 
moduleContext);
+        assertActivation(true, 
newExistsProfile("${project.rootDirectory}/file.txt"), moduleContext);
+        assertActivation(false, 
newExistsProfile("${project.rootDirectory}/module-file.txt"), moduleContext);
+    }
+
+    @Test
+    void testUnprefixedRootDirectoryIsNotInterpolated() throws Exception {
+        // GH-13883: only ${project.rootDirectory} is supported, 
${rootDirectory} is not an alias
+        DefaultProfileActivationContext moduleContext = newModuleContext(new 
Properties());
+
+        assertActivation(false, newExistsProfile("${rootDirectory}/file.txt"), 
moduleContext);
+        assertActivation(true, newMissingProfile("${rootDirectory}/file.txt"), 
moduleContext);
+    }
+
+    private DefaultProfileActivationContext newModuleContext(Properties 
modelProperties) throws IOException {
+        Path moduleDir = Files.createDirectories(tempDir.resolve("module"));
+        Files.createFile(moduleDir.resolve("module-file.txt"));
+
+        activator = new FileProfileActivator()
+                .setProfileActivationFilePathInterpolator(new 
ProfileActivationFilePathInterpolator()
+                        .setPathTranslator(new DefaultPathTranslator())
+                        .setRootLocator(new DefaultRootLocator() {
+                            @Override
+                            public Path findRoot(Path basedir) {
+                                return tempDir;
+                            }
+                        }));
+
+        return new DefaultProfileActivationContext()
+                .setProjectDirectory(moduleDir.toFile())
+                .setProjectProperties(modelProperties);
+    }
+
     @Test
     void testIsActiveNoFileWithShortBasedir() {
         assertActivation(false, newExistsProfile(null), context);
diff --git 
a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelInterpolatorTest.java
 
b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelInterpolatorTest.java
index c1c35ffd0f..4702493dc5 100644
--- 
a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelInterpolatorTest.java
+++ 
b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelInterpolatorTest.java
@@ -428,6 +428,65 @@ void testRootDirectoryWithNull() throws Exception {
         assertEquals(RootLocator.UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE, 
e.getMessage());
     }
 
+    @Test
+    void testCustomRootDirectoryPropertyIsNotShadowed() throws Exception {
+        // GH-13883: a custom ${rootDirectory} property must not be shadowed 
by ${project.rootDirectory}
+        Path rootDirectory = Paths.get("myRootDirectory");
+        Path projectDirectory = rootDirectory.resolve("module");
+        this.rootDirectory = new AtomicReference<>(rootDirectory);
+
+        Map<String, String> modelProperties = new HashMap<>();
+        modelProperties.put("rootDirectory", "${project.basedir}");
+
+        Model model = Model.newBuilder()
+                .version("3.8.1")
+                .artifactId("foo")
+                .properties(modelProperties)
+                .repositories(List.of(
+                        Repository.newBuilder()
+                                .id("custom")
+                                .url("${rootDirectory}/temp-repo")
+                                .build(),
+                        Repository.newBuilder()
+                                .id("project")
+                                .url("${project.rootDirectory}/temp-repo")
+                                .build()))
+                .build();
+
+        final SimpleProblemCollector collector = new SimpleProblemCollector();
+        Model out = interpolator.interpolateModel(
+                model, projectDirectory, 
createModelBuildingRequest(context).build(), collector);
+        assertProblemFree(collector);
+
+        assertEquals(
+                projectDirectory.toAbsolutePath() + "/temp-repo",
+                out.getRepositories().get(0).getUrl());
+        assertEquals(rootDirectory + "/temp-repo", 
out.getRepositories().get(1).getUrl());
+    }
+
+    @Test
+    void testUnprefixedRootDirectoryIsNotInterpolated() throws Exception {
+        // GH-13883: only ${project.rootDirectory} is supported, 
${rootDirectory} is not an alias
+        Path rootDirectory = Paths.get("myRootDirectory");
+        Path projectDirectory = rootDirectory.resolve("module");
+        this.rootDirectory = new AtomicReference<>(rootDirectory);
+
+        Model model = Model.newBuilder()
+                .version("3.8.1")
+                .artifactId("foo")
+                .repositories(List.of(Repository.newBuilder()
+                        .url("${rootDirectory}/temp-repo")
+                        .build()))
+                .build();
+
+        final SimpleProblemCollector collector = new SimpleProblemCollector();
+        Model out = interpolator.interpolateModel(
+                model, projectDirectory, 
createModelBuildingRequest(context).build(), collector);
+        assertProblemFree(collector);
+
+        assertEquals("${rootDirectory}/temp-repo", 
out.getRepositories().get(0).getUrl());
+    }
+
     @Test
     public void testEnvars() throws Exception {
         context.put("env.HOME", "/path/to/home");
diff --git 
a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/FileProfileActivatorTest.java
 
b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/FileProfileActivatorTest.java
index c7312beb66..6a835cc631 100644
--- 
a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/FileProfileActivatorTest.java
+++ 
b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/FileProfileActivatorTest.java
@@ -20,14 +20,19 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.file.Files;
 import java.nio.file.Path;
+import java.util.Map;
 
 import org.apache.maven.api.model.Activation;
 import org.apache.maven.api.model.ActivationFile;
 import org.apache.maven.api.model.Model;
 import org.apache.maven.api.model.Profile;
+import org.apache.maven.api.services.model.ProfileActivationContext;
 import org.apache.maven.api.services.model.RootLocator;
+import org.apache.maven.impl.model.DefaultInterpolator;
 import org.apache.maven.impl.model.DefaultProfileActivationContext;
+import org.apache.maven.impl.model.rootlocator.DefaultRootLocator;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.io.TempDir;
@@ -79,6 +84,43 @@ void testRootDirectory() {
         assertActivation(false, newMissingProfile("${project.rootDirectory}/" 
+ "file.txt"), context);
     }
 
+    @Test
+    void testCustomRootDirectoryPropertyIsNotShadowed() throws Exception {
+        // GH-13883: a custom ${rootDirectory} property must not be shadowed 
by ${project.rootDirectory}
+        ProfileActivationContext moduleContext = 
newModuleContext(Map.of("rootDirectory", "${project.basedir}"));
+
+        assertActivation(true, 
newExistsProfile("${rootDirectory}/module-file.txt"), moduleContext);
+        assertActivation(false, newExistsProfile("${rootDirectory}/file.txt"), 
moduleContext);
+        assertActivation(true, 
newExistsProfile("${project.rootDirectory}/file.txt"), moduleContext);
+        assertActivation(false, 
newExistsProfile("${project.rootDirectory}/module-file.txt"), moduleContext);
+    }
+
+    @Test
+    void testUnprefixedRootDirectoryIsNotInterpolated() throws Exception {
+        // GH-13883: only ${project.rootDirectory} is supported, 
${rootDirectory} is not an alias
+        ProfileActivationContext moduleContext = newModuleContext(Map.of());
+
+        assertActivation(false, newExistsProfile("${rootDirectory}/file.txt"), 
moduleContext);
+        assertActivation(true, newMissingProfile("${rootDirectory}/file.txt"), 
moduleContext);
+    }
+
+    private ProfileActivationContext newModuleContext(Map<String, String> 
modelProperties) throws IOException {
+        Path moduleDir = Files.createDirectories(tempDir.resolve("module"));
+        Files.createFile(moduleDir.resolve("module-file.txt"));
+
+        RootLocator rootLocator = new DefaultRootLocator() {
+            @Override
+            protected boolean isRootDirectory(Path dir) {
+                return tempDir.equals(dir);
+            }
+        };
+        return new DefaultProfileActivationContext(rootLocator, new 
DefaultInterpolator())
+                .setModel(Model.newBuilder()
+                        .pomFile(moduleDir.resolve("pom.xml"))
+                        .properties(modelProperties)
+                        .build());
+    }
+
     @Test
     void testIsActiveNoFileWithShortBasedir() {
         assertActivation(false, newExistsProfile(null), context);

Reply via email to