From 57082737d81a7cb8f31fb6639e749daf172bd58b Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 29 Aug 2024 17:33:49 +0200 Subject: [PATCH] [MNG-7897] Support ${project.rootDirectory} in file profile activation (#1687) * [MNG-7897] Support ${project.rootDirectory} in file profile activation * Add a test with the short ${basedir} expression --- ...ProfileActivationFilePathInterpolator.java | 2 +- ...ProfileActivationFilePathInterpolator.java | 2 +- .../activation/FileProfileActivatorTest.java | 35 ++++++++++++------- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/ProfileActivationFilePathInterpolator.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/ProfileActivationFilePathInterpolator.java index 572b626d9a..d8af860b04 100644 --- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/ProfileActivationFilePathInterpolator.java +++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/ProfileActivationFilePathInterpolator.java @@ -81,7 +81,7 @@ public class ProfileActivationFilePathInterpolator { interpolator.addValueSource(new AbstractValueSource(false) { @Override public Object getValue(String expression) { - if ("rootDirectory".equals(expression)) { + if ("project.rootDirectory".equals(expression)) { Path root = rootLocator.findMandatoryRoot(basedir); return root.toFile().getAbsolutePath(); } diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/path/ProfileActivationFilePathInterpolator.java b/maven-model-builder/src/main/java/org/apache/maven/model/path/ProfileActivationFilePathInterpolator.java index 1ab4e4734c..17e6fd6c48 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/path/ProfileActivationFilePathInterpolator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/path/ProfileActivationFilePathInterpolator.java @@ -82,7 +82,7 @@ public class ProfileActivationFilePathInterpolator { interpolator.addValueSource(new AbstractValueSource(false) { @Override public Object getValue(String expression) { - if ("rootDirectory".equals(expression)) { + if ("project.rootDirectory".equals(expression)) { Path base = basedir != null ? basedir.toPath() : null; Path root = rootLocator.findMandatoryRoot(base); return root.toFile().getAbsolutePath(); diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/FileProfileActivatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/FileProfileActivatorTest.java index 56447be9d4..810dea6a65 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/FileProfileActivatorTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/FileProfileActivatorTest.java @@ -67,22 +67,22 @@ class FileProfileActivatorTest extends AbstractProfileActivatorTest assertActivation(false, newExistsProfile("${rootDirectory}"), context)); + () -> assertActivation(false, newExistsProfile("${project.rootDirectory}"), context)); assertEquals(RootLocator.UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE, e.getMessage()); } @Test void testRootDirectory() { - assertActivation(false, newExistsProfile("${rootDirectory}/someFile.txt"), context); - assertActivation(true, newMissingProfile("${rootDirectory}/someFile.txt"), context); - assertActivation(true, newExistsProfile("${rootDirectory}"), context); - assertActivation(true, newExistsProfile("${rootDirectory}/" + "file.txt"), context); - assertActivation(false, newMissingProfile("${rootDirectory}"), context); - assertActivation(false, newMissingProfile("${rootDirectory}/" + "file.txt"), context); + assertActivation(false, newExistsProfile("${project.rootDirectory}/someFile.txt"), context); + assertActivation(true, newMissingProfile("${project.rootDirectory}/someFile.txt"), context); + assertActivation(true, newExistsProfile("${project.rootDirectory}"), context); + assertActivation(true, newExistsProfile("${project.rootDirectory}/" + "file.txt"), context); + assertActivation(false, newMissingProfile("${project.rootDirectory}"), context); + assertActivation(false, newMissingProfile("${project.rootDirectory}/" + "file.txt"), context); } @Test - void testIsActiveNoFile() { + void testIsActiveNoFileWithShortBasedir() { assertActivation(false, newExistsProfile(null), context); assertActivation(false, newExistsProfile("someFile.txt"), context); assertActivation(false, newExistsProfile("${basedir}/someFile.txt"), context); @@ -92,15 +92,26 @@ class FileProfileActivatorTest extends AbstractProfileActivatorTest