Skip to content

Commit

Permalink
[1.x] Fix user properties interpolation and maven.multiModuleProjectD…
Browse files Browse the repository at this point in the history
…irectory (fixes #1031) (#1056)
  • Loading branch information
gnodet authored Jul 16, 2024
1 parent a5a5eb5 commit df5a179
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand Down
10 changes: 9 additions & 1 deletion daemon/src/main/java/org/apache/maven/cli/DaemonMavenCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -1462,6 +1461,7 @@ static void populateProperties(CliRequest cliRequest, Properties systemPropertie
}
}

addEnvVars(systemProperties);
SystemProperties.addSystemProperties(systemProperties);

StringSearchInterpolator interpolator = createInterpolator(cliRequest, cliProperties, systemProperties);
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit df5a179

Please sign in to comment.