You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2022/01/11 07:12:25 UTC

[maven-mvnd] branch master updated: Make sure the maven.home and maven.conf properties are correctly set when the JVM is started, fixes #553

This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-mvnd.git


The following commit(s) were added to refs/heads/master by this push:
     new 4c99b52  Make sure the maven.home and maven.conf properties are correctly set when the JVM is started, fixes #553
4c99b52 is described below

commit 4c99b52e03311242b042dacbf929f21c595a1be2
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Tue Jan 11 08:12:18 2022 +0100

    Make sure the maven.home and maven.conf properties are correctly set when the JVM is started, fixes #553
---
 .../org/mvndaemon/mvnd/client/DaemonConnector.java |  3 ++
 .../org/mvndaemon/mvnd/client/DefaultClient.java   |  2 +
 .../org/mvndaemon/mvnd/common/Environment.java     |  2 +-
 .../java/org/apache/maven/cli/DaemonMavenCli.java  | 11 -----
 .../org/mvndaemon/mvnd/it/MavenConfNativeIT.java   | 47 ++++++++++++++++++++
 .../java/org/mvndaemon/mvnd/it/MavenConfTest.java  | 51 ++++++++++++++++++++++
 .../src/test/projects/maven-conf/pom.xml           | 27 ++++++++++++
 7 files changed, 131 insertions(+), 12 deletions(-)

diff --git a/client/src/main/java/org/mvndaemon/mvnd/client/DaemonConnector.java b/client/src/main/java/org/mvndaemon/mvnd/client/DaemonConnector.java
index 38986dd..5660eee 100644
--- a/client/src/main/java/org/mvndaemon/mvnd/client/DaemonConnector.java
+++ b/client/src/main/java/org/mvndaemon/mvnd/client/DaemonConnector.java
@@ -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());
diff --git a/client/src/main/java/org/mvndaemon/mvnd/client/DefaultClient.java b/client/src/main/java/org/mvndaemon/mvnd/client/DefaultClient.java
index 9f33215..72fba87 100644
--- a/client/src/main/java/org/mvndaemon/mvnd/client/DefaultClient.java
+++ b/client/src/main/java/org/mvndaemon/mvnd/client/DefaultClient.java
@@ -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)) {
diff --git a/common/src/main/java/org/mvndaemon/mvnd/common/Environment.java b/common/src/main/java/org/mvndaemon/mvnd/common/Environment.java
index 20547e6..a2d3b00 100644
--- a/common/src/main/java/org/mvndaemon/mvnd/common/Environment.java
+++ b/common/src/main/java/org/mvndaemon/mvnd/common/Environment.java
@@ -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 */
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 b55ecc5..746f1df 100644
--- a/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCli.java
+++ b/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCli.java
@@ -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)
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
new file mode 100644
index 0000000..8a694c6
--- /dev/null
+++ b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/MavenConfNativeIT.java
@@ -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);
+    }
+
+}
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
new file mode 100644
index 0000000..768ace5
--- /dev/null
+++ b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/MavenConfTest.java
@@ -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);
+    }
+
+}
diff --git a/integration-tests/src/test/projects/maven-conf/pom.xml b/integration-tests/src/test/projects/maven-conf/pom.xml
new file mode 100644
index 0000000..2aa36cd
--- /dev/null
+++ b/integration-tests/src/test/projects/maven-conf/pom.xml
@@ -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>
\ No newline at end of file