mirror of
https://github.com/apache/maven-mvnd.git
synced 2025-09-11 05:30:08 +00:00
Make sure the maven.home and maven.conf properties are correctly set when the JVM is started, fixes #553
This commit is contained in:
@@ -372,6 +372,9 @@ public class DaemonConnector {
|
||||
}
|
||||
|
||||
Environment.MVND_HOME.addCommandLineOption(args, mvndHome.toString());
|
||||
args.add("-Dmaven.home=" + mvndHome.resolve("mvn"));
|
||||
args.add("-Dmaven.conf=" + mvndHome.resolve("mvn/conf"));
|
||||
|
||||
Environment.MVND_JAVA_HOME.addCommandLineOption(args, parameters.javaHome().toString());
|
||||
Environment.LOGBACK_CONFIGURATION_FILE
|
||||
.addCommandLineOption(args, parameters.logbackConfigurationPath().toString());
|
||||
|
@@ -112,6 +112,8 @@ public class DefaultClient implements Client {
|
||||
System.setProperty(Environment.MVND_NO_BUFERING.getProperty(), Boolean.toString(true));
|
||||
}
|
||||
|
||||
System.setProperty(Environment.MVND_HOME.getProperty(), parameters.mvndHome().toString());
|
||||
|
||||
int exitCode = 0;
|
||||
boolean noBuffering = batchMode || parameters.noBuffering();
|
||||
try (TerminalOutput output = new TerminalOutput(noBuffering, parameters.rollingWindowSize(), logFile)) {
|
||||
|
@@ -79,7 +79,7 @@ public enum Environment {
|
||||
* The daemon installation directory. The client normally sets this according to where its <code>mvnd</code>
|
||||
* executable is located
|
||||
*/
|
||||
MVND_HOME("mvnd.home", "MVND_HOME", null, OptionType.PATH, Flags.NONE),
|
||||
MVND_HOME("mvnd.home", "MVND_HOME", null, OptionType.PATH, Flags.DISCRIMINATING),
|
||||
/** The user home directory */
|
||||
USER_HOME("user.home", null, null, OptionType.PATH, Flags.NONE),
|
||||
/** The current working directory */
|
||||
|
@@ -260,17 +260,6 @@ public class DaemonMavenCli {
|
||||
throw new ExitException(1);
|
||||
}
|
||||
System.setProperty("maven.multiModuleProjectDirectory", cliRequest.multiModuleProjectDirectory.toString());
|
||||
|
||||
//
|
||||
// Make sure the Maven home directory is an absolute path to save us from confusion with say drive-relative
|
||||
// Windows paths.
|
||||
//
|
||||
String mvndHome = System.getProperty("mvnd.home");
|
||||
|
||||
if (mvndHome != null) {
|
||||
System.setProperty("mvnd.home", new File(mvndHome).getAbsolutePath());
|
||||
System.setProperty("maven.home", new File(mvndHome + "/mvn").getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
void cli(CliRequest cliRequest)
|
||||
|
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2019-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.mvndaemon.mvnd.it;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.inject.Inject;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mvndaemon.mvnd.assertj.TestClientOutput;
|
||||
import org.mvndaemon.mvnd.client.Client;
|
||||
import org.mvndaemon.mvnd.client.DaemonParameters;
|
||||
import org.mvndaemon.mvnd.junit.MvndNativeTest;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@MvndNativeTest(projectDir = "src/test/projects/maven-conf")
|
||||
public class MavenConfNativeIT {
|
||||
|
||||
@Inject
|
||||
Client client;
|
||||
|
||||
@Inject
|
||||
DaemonParameters parameters;
|
||||
|
||||
@Test
|
||||
void version() throws IOException, InterruptedException {
|
||||
final TestClientOutput o = new TestClientOutput();
|
||||
client.execute(o, "org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate",
|
||||
"-Dexpression=maven.conf", "-q", "-DforceStdout", "--raw-streams").assertSuccess();
|
||||
String conf = parameters.mvndHome().resolve("mvn/conf").toString();
|
||||
assertTrue(o.getMessages().stream()
|
||||
.anyMatch(m -> m.toString().contains(conf)), "Output should contain " + conf);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2019-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.mvndaemon.mvnd.it;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.inject.Inject;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mvndaemon.mvnd.assertj.TestClientOutput;
|
||||
import org.mvndaemon.mvnd.client.Client;
|
||||
import org.mvndaemon.mvnd.client.DaemonParameters;
|
||||
import org.mvndaemon.mvnd.junit.MvndTest;
|
||||
import org.mvndaemon.mvnd.junit.TestRegistry;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@MvndTest(projectDir = "src/test/projects/maven-conf")
|
||||
public class MavenConfTest extends MavenConfNativeIT {
|
||||
|
||||
@Inject
|
||||
Client client;
|
||||
|
||||
@Inject
|
||||
DaemonParameters parameters;
|
||||
|
||||
@Inject
|
||||
TestRegistry registry;
|
||||
|
||||
@Test
|
||||
void version() throws IOException, InterruptedException {
|
||||
final TestClientOutput o = new TestClientOutput();
|
||||
client.execute(o, "org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate",
|
||||
"-Dexpression=maven.conf", "-q", "-DforceStdout", "--raw-streams").assertSuccess();
|
||||
String conf = parameters.mvndHome().resolve("mvn/conf").toString();
|
||||
assertTrue(o.getMessages().stream()
|
||||
.anyMatch(m -> m.toString().contains(conf)), "Output should contain " + conf);
|
||||
}
|
||||
|
||||
}
|
27
integration-tests/src/test/projects/maven-conf/pom.xml
Normal file
27
integration-tests/src/test/projects/maven-conf/pom.xml
Normal file
@@ -0,0 +1,27 @@
|
||||
<!--
|
||||
|
||||
Copyright 2019-2022 the original author or authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
-->
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.mvndaemon.mvnd.test.maven-conf</groupId>
|
||||
<artifactId>maven-conf</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
</project>
|
Reference in New Issue
Block a user