[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
This commit is contained in:
Guillaume Nodet 2024-08-29 17:33:49 +02:00 committed by GitHub
parent 40fe1dc167
commit 57082737d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 14 deletions

View File

@ -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();
}

View File

@ -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();

View File

@ -67,22 +67,22 @@ class FileProfileActivatorTest extends AbstractProfileActivatorTest<FileProfileA
IllegalStateException e = assertThrows(
IllegalStateException.class,
() -> 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<FileProfileA
assertActivation(true, newMissingProfile("${basedir}/someFile.txt"), context);
}
@Test
void testIsActiveNoFile() {
assertActivation(false, newExistsProfile(null), context);
assertActivation(false, newExistsProfile("someFile.txt"), context);
assertActivation(false, newExistsProfile("${project.basedir}/someFile.txt"), context);
assertActivation(false, newMissingProfile(null), context);
assertActivation(true, newMissingProfile("someFile.txt"), context);
assertActivation(true, newMissingProfile("${project.basedir}/someFile.txt"), context);
}
@Test
void testIsActiveExistsFileExists() {
assertActivation(true, newExistsProfile("file.txt"), context);
assertActivation(true, newExistsProfile("${basedir}"), context);
assertActivation(true, newExistsProfile("${basedir}/" + "file.txt"), context);
assertActivation(true, newExistsProfile("${project.basedir}"), context);
assertActivation(true, newExistsProfile("${project.basedir}/" + "file.txt"), context);
assertActivation(false, newMissingProfile("file.txt"), context);
assertActivation(false, newMissingProfile("${basedir}"), context);
assertActivation(false, newMissingProfile("${basedir}/" + "file.txt"), context);
assertActivation(false, newMissingProfile("${project.basedir}"), context);
assertActivation(false, newMissingProfile("${project.basedir}/" + "file.txt"), context);
}
@Test