Skip to content

Commit 5708273

Browse files
authored
[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
1 parent 40fe1dc commit 5708273

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/ProfileActivationFilePathInterpolator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public Object getValue(String expression) {
8181
interpolator.addValueSource(new AbstractValueSource(false) {
8282
@Override
8383
public Object getValue(String expression) {
84-
if ("rootDirectory".equals(expression)) {
84+
if ("project.rootDirectory".equals(expression)) {
8585
Path root = rootLocator.findMandatoryRoot(basedir);
8686
return root.toFile().getAbsolutePath();
8787
}

maven-model-builder/src/main/java/org/apache/maven/model/path/ProfileActivationFilePathInterpolator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public Object getValue(String expression) {
8282
interpolator.addValueSource(new AbstractValueSource(false) {
8383
@Override
8484
public Object getValue(String expression) {
85-
if ("rootDirectory".equals(expression)) {
85+
if ("project.rootDirectory".equals(expression)) {
8686
Path base = basedir != null ? basedir.toPath() : null;
8787
Path root = rootLocator.findMandatoryRoot(base);
8888
return root.toFile().getAbsolutePath();

maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/FileProfileActivatorTest.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,22 @@ void testRootDirectoryWithNull() {
6767

6868
IllegalStateException e = assertThrows(
6969
IllegalStateException.class,
70-
() -> assertActivation(false, newExistsProfile("${rootDirectory}"), context));
70+
() -> assertActivation(false, newExistsProfile("${project.rootDirectory}"), context));
7171
assertEquals(RootLocator.UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE, e.getMessage());
7272
}
7373

7474
@Test
7575
void testRootDirectory() {
76-
assertActivation(false, newExistsProfile("${rootDirectory}/someFile.txt"), context);
77-
assertActivation(true, newMissingProfile("${rootDirectory}/someFile.txt"), context);
78-
assertActivation(true, newExistsProfile("${rootDirectory}"), context);
79-
assertActivation(true, newExistsProfile("${rootDirectory}/" + "file.txt"), context);
80-
assertActivation(false, newMissingProfile("${rootDirectory}"), context);
81-
assertActivation(false, newMissingProfile("${rootDirectory}/" + "file.txt"), context);
76+
assertActivation(false, newExistsProfile("${project.rootDirectory}/someFile.txt"), context);
77+
assertActivation(true, newMissingProfile("${project.rootDirectory}/someFile.txt"), context);
78+
assertActivation(true, newExistsProfile("${project.rootDirectory}"), context);
79+
assertActivation(true, newExistsProfile("${project.rootDirectory}/" + "file.txt"), context);
80+
assertActivation(false, newMissingProfile("${project.rootDirectory}"), context);
81+
assertActivation(false, newMissingProfile("${project.rootDirectory}/" + "file.txt"), context);
8282
}
8383

8484
@Test
85-
void testIsActiveNoFile() {
85+
void testIsActiveNoFileWithShortBasedir() {
8686
assertActivation(false, newExistsProfile(null), context);
8787
assertActivation(false, newExistsProfile("someFile.txt"), context);
8888
assertActivation(false, newExistsProfile("${basedir}/someFile.txt"), context);
@@ -92,15 +92,26 @@ void testIsActiveNoFile() {
9292
assertActivation(true, newMissingProfile("${basedir}/someFile.txt"), context);
9393
}
9494

95+
@Test
96+
void testIsActiveNoFile() {
97+
assertActivation(false, newExistsProfile(null), context);
98+
assertActivation(false, newExistsProfile("someFile.txt"), context);
99+
assertActivation(false, newExistsProfile("${project.basedir}/someFile.txt"), context);
100+
101+
assertActivation(false, newMissingProfile(null), context);
102+
assertActivation(true, newMissingProfile("someFile.txt"), context);
103+
assertActivation(true, newMissingProfile("${project.basedir}/someFile.txt"), context);
104+
}
105+
95106
@Test
96107
void testIsActiveExistsFileExists() {
97108
assertActivation(true, newExistsProfile("file.txt"), context);
98-
assertActivation(true, newExistsProfile("${basedir}"), context);
99-
assertActivation(true, newExistsProfile("${basedir}/" + "file.txt"), context);
109+
assertActivation(true, newExistsProfile("${project.basedir}"), context);
110+
assertActivation(true, newExistsProfile("${project.basedir}/" + "file.txt"), context);
100111

101112
assertActivation(false, newMissingProfile("file.txt"), context);
102-
assertActivation(false, newMissingProfile("${basedir}"), context);
103-
assertActivation(false, newMissingProfile("${basedir}/" + "file.txt"), context);
113+
assertActivation(false, newMissingProfile("${project.basedir}"), context);
114+
assertActivation(false, newMissingProfile("${project.basedir}/" + "file.txt"), context);
104115
}
105116

106117
@Test

0 commit comments

Comments
 (0)