diff --git a/client/src/main/java-mvnd/org/mvndaemon/mvnd/client/DefaultClient.java b/client/src/main/java-mvnd/org/mvndaemon/mvnd/client/DefaultClient.java index 61c8aea7d..df54b59cc 100644 --- a/client/src/main/java-mvnd/org/mvndaemon/mvnd/client/DefaultClient.java +++ b/client/src/main/java-mvnd/org/mvndaemon/mvnd/client/DefaultClient.java @@ -132,9 +132,11 @@ public static void main(String[] argv) throws Exception { } else { dir = parameters.userDir(); } + Path multiModuleProjectDirectory = parameters.multiModuleProjectDirectory(dir); System.setProperty( - Environment.MAVEN_MULTIMODULE_PROJECT_DIRECTORY.getProperty(), - parameters.multiModuleProjectDirectory(dir).toString()); + Environment.MAVEN_MULTIMODULE_PROJECT_DIRECTORY.getProperty(), multiModuleProjectDirectory.toString()); + Environment.MAVEN_MULTIMODULE_PROJECT_DIRECTORY.addCommandLineOption( + args, multiModuleProjectDirectory.toString()); // .mvn/jvm.config if (Files.isRegularFile(parameters.jvmConfigPath())) { diff --git a/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCli.java b/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCli.java index 3d14afaf2..c70abb989 100644 --- a/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCli.java +++ b/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCli.java @@ -1443,7 +1443,6 @@ static File resolveFile(File file, String workingDirectory) { static void populateProperties(CliRequest cliRequest, Properties systemProperties, Properties userProperties) throws InterpolationException { - addEnvVars(systemProperties); // ---------------------------------------------------------------------- // Options that are set on the command line become system properties @@ -1462,6 +1461,7 @@ static void populateProperties(CliRequest cliRequest, Properties systemPropertie } } + addEnvVars(systemProperties); SystemProperties.addSystemProperties(systemProperties); StringSearchInterpolator interpolator = createInterpolator(cliRequest, cliProperties, systemProperties); @@ -1471,6 +1471,14 @@ static void populateProperties(CliRequest cliRequest, Properties systemPropertie userProperties.setProperty(name, value); } + systemProperties.putAll(userProperties); + + // ---------------------------------------------------------------------- + // I'm leaving the setting of system properties here as not to break + // the SystemPropertyProfileActivator. This won't harm embedding. jvz. + // ---------------------------------------------------------------------- + userProperties.forEach((k, v) -> System.setProperty((String) k, (String) v)); + // ---------------------------------------------------------------------- // Properties containing info about the currently running version of Maven // These override any corresponding properties set on the command line diff --git a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/MavenConfNativeIT.java b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/MavenConfNativeIT.java index 75c84bde0..aa0f1b0d4 100644 --- a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/MavenConfNativeIT.java +++ b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/MavenConfNativeIT.java @@ -56,4 +56,38 @@ void version() throws IOException, InterruptedException { assertTrue( o.getMessages().stream().anyMatch(m -> m.toString().contains(conf)), "Output should contain " + conf); } + + @Test + void interpolation() throws IOException, InterruptedException { + final TestClientOutput o = new TestClientOutput(); + client.execute( + o, + "org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate", + "-D", + "expression=something", + "-q", + "-DforceStdout", + "--raw-streams") + .assertSuccess(); + String conf = parameters.multiModuleProjectDirectory().toString(); + assertTrue( + o.getMessages().stream().anyMatch(m -> m.toString().contains(conf)), "Output should contain " + conf); + } + + @Test + void multiModuleProjectDirectory() throws IOException, InterruptedException { + final TestClientOutput o = new TestClientOutput(); + client.execute( + o, + "org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate", + "-D", + "expression=maven.multiModuleProjectDirectory", + "-q", + "-DforceStdout", + "--raw-streams") + .assertSuccess(); + String conf = parameters.multiModuleProjectDirectory().toString(); + assertTrue( + o.getMessages().stream().anyMatch(m -> m.toString().contains(conf)), "Output should contain " + conf); + } } diff --git a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/MavenConfTest.java b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/MavenConfTest.java index eb9326850..2fe077c2f 100644 --- a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/MavenConfTest.java +++ b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/MavenConfTest.java @@ -18,7 +18,18 @@ */ package org.mvndaemon.mvnd.it; +import java.io.IOException; + +import org.junit.jupiter.api.Test; import org.mvndaemon.mvnd.junit.MvndTest; @MvndTest(projectDir = "src/test/projects/maven-conf") -class MavenConfTest extends MavenConfNativeIT {} +class MavenConfTest extends MavenConfNativeIT { + + @Test + @Override + void multiModuleProjectDirectory() throws IOException, InterruptedException { + // empty test as multiModuleProjectDirectory is set by the client + // and can not be really tested + } +}