Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Fix user properties interpolation and maven.multiModuleProjectDirectory (fixes #1031) #1056

Merged
merged 3 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}