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 2023/01/24 16:54:27 UTC

[maven-mvnd] branch mvnd-0.9.x updated (34004ebc -> 78416160)

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

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


    from 34004ebc Upgrade to sisu 0.9.0.M1 and surefire 3.0.0-M8
     new b8028d2e Make connection timeouts configurable, fixes #772 (#778)
     new 33422a36 Fix system out / err streams when redirecting to file (#779)
     new 8d2ae6da Attempt at moving mvn as first class citizen in mvnd distribution, #392 (#769)
     new f9954a52 Try native image then fallback to pure java version (#717)
     new 78416160 Fix executable bit on the mvnd-bash-completion script (#756)

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 client/pom.xml                                     |  2 +-
 .../org/mvndaemon/mvnd/client/DaemonConnector.java | 45 ++++++++----
 .../mvndaemon/mvnd/client/DaemonParameters.java    |  7 +-
 .../org/mvndaemon/mvnd/common/Environment.java     | 12 ++++
 .../org/mvndaemon/mvnd/common/MavenDaemon.java     |  4 +-
 .../mvnd/common/logging/TerminalOutput.java        | 16 +++--
 dist/src/main/distro/{mvn => }/bin/mvn             |  2 +-
 dist/src/main/distro/{mvn => }/bin/mvn.cmd         |  2 +-
 .../main/distro/{mvn/bin/m2.conf => bin/mvn.conf}  |  0
 dist/src/main/distro/{mvn => }/bin/mvnDebug        |  0
 dist/src/main/distro/{mvn => }/bin/mvnDebug.cmd    |  0
 dist/src/main/distro/bin/mvnd-bash-completion.bash |  0
 dist/src/main/distro/bin/mvnd.cmd                  | 32 ++++++++-
 dist/src/main/distro/bin/{m2.conf => mvnd.conf}    |  5 +-
 dist/src/main/distro/bin/mvnd.sh                   | 43 +++++++++--
 .../distro/conf/{ => logging}/logback-client.xml   |  0
 .../conf/{logback.xml => logging/logback-mvnd.xml} |  0
 .../main/distro/{mvn => }/conf/logging/logback.xml |  0
 dist/src/main/provisio/maven-distro.xml            | 83 ++++++++++------------
 .../test/java/org/mvndaemon/mvnd/it/DistroIT.java  | 56 +++++++--------
 .../org/mvndaemon/mvnd/it/MavenConfNativeIT.java   |  2 +-
 pom.xml                                            |  5 ++
 22 files changed, 203 insertions(+), 113 deletions(-)
 rename dist/src/main/distro/{mvn => }/bin/mvn (99%)
 rename dist/src/main/distro/{mvn => }/bin/mvn.cmd (95%)
 rename dist/src/main/distro/{mvn/bin/m2.conf => bin/mvn.conf} (100%)
 rename dist/src/main/distro/{mvn => }/bin/mvnDebug (100%)
 rename dist/src/main/distro/{mvn => }/bin/mvnDebug.cmd (100%)
 mode change 100644 => 100755 dist/src/main/distro/bin/mvnd-bash-completion.bash
 rename dist/src/main/distro/bin/{m2.conf => mvnd.conf} (88%)
 rename dist/src/main/distro/conf/{ => logging}/logback-client.xml (100%)
 rename dist/src/main/distro/conf/{logback.xml => logging/logback-mvnd.xml} (100%)
 rename dist/src/main/distro/{mvn => }/conf/logging/logback.xml (100%)


[maven-mvnd] 01/05: Make connection timeouts configurable, fixes #772 (#778)

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit b8028d2e10df28cfe655f33aef0bfbb8414cbf0d
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Mon Jan 23 19:56:49 2023 +0100

    Make connection timeouts configurable, fixes #772 (#778)
---
 .../org/mvndaemon/mvnd/client/DaemonConnector.java | 35 +++++++++++++++-------
 .../org/mvndaemon/mvnd/common/Environment.java     | 12 ++++++++
 2 files changed, 37 insertions(+), 10 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 cd5f416d..b9dfb7e1 100644
--- a/client/src/main/java/org/mvndaemon/mvnd/client/DaemonConnector.java
+++ b/client/src/main/java/org/mvndaemon/mvnd/client/DaemonConnector.java
@@ -69,10 +69,6 @@ import static org.mvndaemon.mvnd.common.DaemonState.Canceled;
  */
 public class DaemonConnector {
 
-    public static final int DEFAULT_CONNECT_TIMEOUT = 30000;
-    public static final int CANCELED_WAIT_TIMEOUT = 3000;
-    private static final int CONNECT_TIMEOUT = 10000;
-
     private static final Logger LOGGER = LoggerFactory.getLogger(DaemonConnector.class);
 
     private final DaemonRegistry registry;
@@ -164,6 +160,11 @@ public class DaemonConnector {
         });
         serverThread.start();
         long start = System.currentTimeMillis();
+        long stop = start
+                + parameters
+                        .property(Environment.MVND_CONNECT_TIMEOUT)
+                        .asDuration()
+                        .toMillis();
         do {
             DaemonClientConnection daemonConnection = connectToDaemonWithId(daemon, true);
             if (daemonConnection != null) {
@@ -174,7 +175,7 @@ public class DaemonConnector {
             } catch (InterruptedException e) {
                 throw new DaemonException.InterruptedException(e);
             }
-        } while (serverThread.isAlive() && System.currentTimeMillis() - start < DEFAULT_CONNECT_TIMEOUT);
+        } while (serverThread.isAlive() && System.currentTimeMillis() < stop);
         throw new RuntimeException("Unable to connect to internal daemon", throwable.get());
     }
 
@@ -261,7 +262,12 @@ public class DaemonConnector {
         if (!compatibleCanceledDaemons.isEmpty()) {
             LOGGER.debug("Waiting for daemons with canceled builds to become available");
             long start = System.currentTimeMillis();
-            while (connection == null && System.currentTimeMillis() - start < CANCELED_WAIT_TIMEOUT) {
+            long stop = start
+                    + parameters
+                            .property(Environment.MVND_CANCEL_CONNECT_TIMEOUT)
+                            .asDuration()
+                            .toMillis();
+            while (connection == null && System.currentTimeMillis() < stop) {
                 try {
                     sleep(200);
                     connection = connectToIdleDaemon(registry.getIdle(), constraint);
@@ -304,6 +310,11 @@ public class DaemonConnector {
         final Process process = startDaemonProcess(daemonId, output);
         LOGGER.debug("Started Maven daemon {}", daemonId);
         long start = System.currentTimeMillis();
+        long stop = start
+                + parameters
+                        .property(Environment.MVND_CONNECT_TIMEOUT)
+                        .asDuration()
+                        .toMillis();
         do {
             DaemonClientConnection daemonConnection = connectToDaemonWithId(daemonId, true);
             if (daemonConnection != null) {
@@ -314,7 +325,7 @@ public class DaemonConnector {
             } catch (InterruptedException e) {
                 throw new DaemonException.InterruptedException(e);
             }
-        } while (process.isAlive() && System.currentTimeMillis() - start < DEFAULT_CONNECT_TIMEOUT);
+        } while (process.isAlive() && System.currentTimeMillis() < stop);
         DaemonDiagnostics diag = new DaemonDiagnostics(daemonId, parameters);
         throw new DaemonException.ConnectException(
                 "Timeout waiting to connect to the Maven daemon.\n" + diag.describe());
@@ -546,13 +557,17 @@ public class DaemonConnector {
             socketChannel.configureBlocking(false);
             boolean connected = socketChannel.connect(address);
             if (!connected) {
-                long t0 = System.nanoTime();
-                long t1 = t0 + TimeUnit.MICROSECONDS.toNanos(CONNECT_TIMEOUT);
+                long t0 = System.currentTimeMillis();
+                long t1 = t0
+                        + parameters
+                                .property(Environment.MVND_SOCKET_CONNECT_TIMEOUT)
+                                .asDuration()
+                                .toMillis();
                 while (!connected && t0 < t1) {
                     Thread.sleep(10);
                     connected = socketChannel.finishConnect();
                     if (!connected) {
-                        t0 = System.nanoTime();
+                        t0 = System.currentTimeMillis();
                     }
                 }
                 if (!connected) {
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 5ac6185a..65dcddcc 100644
--- a/common/src/main/java/org/mvndaemon/mvnd/common/Environment.java
+++ b/common/src/main/java/org/mvndaemon/mvnd/common/Environment.java
@@ -290,6 +290,18 @@ public enum Environment {
      * Whether or not decorate output and error streams
      **/
     MVND_RAW_STREAMS("mvnd.rawStreams", null, Boolean.FALSE, OptionType.VOID, Flags.OPTIONAL, "mvnd:--raw-streams"),
+    /**
+     * Overall timeout to connect to a daemon.
+     */
+    MVND_CONNECT_TIMEOUT("mvnd.connectTimeout", null, "10 seconds", OptionType.DURATION, Flags.NONE),
+    /**
+     * Timeout to establish the socket connection.
+     */
+    MVND_SOCKET_CONNECT_TIMEOUT("mvnd.socketConnectTimeout", null, "1 seconds", OptionType.DURATION, Flags.NONE),
+    /**
+     * Timeout to connect to a cancelled daemon.
+     */
+    MVND_CANCEL_CONNECT_TIMEOUT("mvnd.cancelConnectTimeout", null, "3 seconds", OptionType.DURATION, Flags.NONE),
     ;
 
     static Properties properties;


[maven-mvnd] 05/05: Fix executable bit on the mvnd-bash-completion script (#756)

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 7841616075a67f130d6cc5aa57ff5bab02d71537
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Tue Jan 24 11:55:36 2023 +0100

    Fix executable bit on the mvnd-bash-completion script (#756)
---
 dist/src/main/distro/bin/mvnd-bash-completion.bash | 0
 1 file changed, 0 insertions(+), 0 deletions(-)

diff --git a/dist/src/main/distro/bin/mvnd-bash-completion.bash b/dist/src/main/distro/bin/mvnd-bash-completion.bash
old mode 100644
new mode 100755


[maven-mvnd] 03/05: Attempt at moving mvn as first class citizen in mvnd distribution, #392 (#769)

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 8d2ae6da4dcd62f9c2e614caff5c8e592310dc75
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Tue Jan 24 10:50:40 2023 +0100

    Attempt at moving mvn as first class citizen in mvnd distribution, #392 (#769)
    
    # Conflicts:
    #       dist/src/main/provisio/maven-distro.xml
---
 .../org/mvndaemon/mvnd/client/DaemonConnector.java | 10 +--
 .../mvndaemon/mvnd/client/DaemonParameters.java    |  7 +-
 .../org/mvndaemon/mvnd/common/MavenDaemon.java     |  4 +-
 dist/src/main/distro/{mvn => }/bin/mvn             |  2 +-
 dist/src/main/distro/{mvn => }/bin/mvn.cmd         |  2 +-
 .../main/distro/{mvn/bin/m2.conf => bin/mvn.conf}  |  0
 dist/src/main/distro/{mvn => }/bin/mvnDebug        |  0
 dist/src/main/distro/{mvn => }/bin/mvnDebug.cmd    |  0
 dist/src/main/distro/bin/mvnd.cmd                  |  4 +-
 dist/src/main/distro/bin/{m2.conf => mvnd.conf}    |  5 +-
 dist/src/main/distro/bin/mvnd.sh                   |  4 +-
 .../distro/conf/{ => logging}/logback-client.xml   |  0
 .../conf/{logback.xml => logging/logback-mvnd.xml} |  0
 .../main/distro/{mvn => }/conf/logging/logback.xml |  0
 dist/src/main/provisio/maven-distro.xml            | 82 +++++++++-------------
 .../test/java/org/mvndaemon/mvnd/it/DistroIT.java  | 56 +++++++--------
 .../org/mvndaemon/mvnd/it/MavenConfNativeIT.java   |  2 +-
 pom.xml                                            |  5 ++
 18 files changed, 87 insertions(+), 96 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 b9dfb7e1..53cbacc4 100644
--- a/client/src/main/java/org/mvndaemon/mvnd/client/DaemonConnector.java
+++ b/client/src/main/java/org/mvndaemon/mvnd/client/DaemonConnector.java
@@ -339,7 +339,7 @@ public class DaemonConnector {
         final Path mvndHome = parameters.mvndHome();
         final Path workingDir = parameters.userDir();
         String command = "";
-        try (DirectoryStream<Path> jarPaths = Files.newDirectoryStream(mvndHome.resolve("mvn/lib/ext"))) {
+        try (DirectoryStream<Path> jarPaths = Files.newDirectoryStream(mvndHome.resolve("lib"))) {
             List<String> args = new ArrayList<>();
             // executable
             final String java = Os.current().isUnixLike() ? "bin/java" : "bin\\java.exe";
@@ -358,10 +358,10 @@ public class DaemonConnector {
                 }
             }
             if (mvndCommonPath == null) {
-                throw new IllegalStateException("Could not find mvnd-common jar in mvn/lib/ext/");
+                throw new IllegalStateException("Could not find mvnd-common jar in lib/");
             }
             if (mvndAgentPath == null) {
-                throw new IllegalStateException("Could not find mvnd-agent jar in mvn/lib/ext/");
+                throw new IllegalStateException("Could not find mvnd-agent jar in lib/");
             }
             args.add("-classpath");
             args.add(mvndCommonPath + File.pathSeparator + mvndAgentPath);
@@ -419,8 +419,8 @@ public class DaemonConnector {
             }
 
             Environment.MVND_HOME.addSystemProperty(args, mvndHome.toString());
-            args.add("-Dmaven.home=" + mvndHome.resolve("mvn"));
-            args.add("-Dmaven.conf=" + mvndHome.resolve("mvn/conf"));
+            args.add("-Dmaven.home=" + mvndHome);
+            args.add("-Dmaven.conf=" + mvndHome.resolve("conf"));
 
             Environment.MVND_JAVA_HOME.addSystemProperty(
                     args, parameters.javaHome().toString());
diff --git a/client/src/main/java/org/mvndaemon/mvnd/client/DaemonParameters.java b/client/src/main/java/org/mvndaemon/mvnd/client/DaemonParameters.java
index e6c6a4ec..7dfa00be 100644
--- a/client/src/main/java/org/mvndaemon/mvnd/client/DaemonParameters.java
+++ b/client/src/main/java/org/mvndaemon/mvnd/client/DaemonParameters.java
@@ -122,8 +122,8 @@ public class DaemonParameters {
         if (Environment.isNative() && cmd.isPresent()) {
             final Path mvndH = Paths.get(cmd.get()).getParent().getParent();
             if (mvndH != null) {
-                final Path mvndDaemonLib = mvndH.resolve("mvn/lib/ext/mvnd-daemon-"
-                        + BuildProperties.getInstance().getVersion() + ".jar");
+                final Path mvndDaemonLib = mvndH.resolve(
+                        "lib/mvnd-daemon-" + BuildProperties.getInstance().getVersion() + ".jar");
                 if (Files.exists(mvndDaemonLib)) {
                     return mvndH.toString();
                 }
@@ -238,7 +238,8 @@ public class DaemonParameters {
 
     public Path logbackConfigurationPath() {
         return property(Environment.MVND_LOGBACK)
-                .orDefault(() -> mvndHome().resolve("conf/logback.xml").toString())
+                .orDefault(() ->
+                        mvndHome().resolve("conf/logging/logback-mvnd.xml").toString())
                 .orFail()
                 .asPath();
     }
diff --git a/common/src/main/java/org/mvndaemon/mvnd/common/MavenDaemon.java b/common/src/main/java/org/mvndaemon/mvnd/common/MavenDaemon.java
index cf4bb133..0ebbfee5 100644
--- a/common/src/main/java/org/mvndaemon/mvnd/common/MavenDaemon.java
+++ b/common/src/main/java/org/mvndaemon/mvnd/common/MavenDaemon.java
@@ -31,7 +31,7 @@ public class MavenDaemon {
         final Path mvndHome = Environment.MVND_HOME.asPath();
         URL[] classpath = Stream.concat(
                         /* jars */
-                        Stream.of("mvn/lib/ext", "mvn/lib", "mvn/boot")
+                        Stream.of("lib/ext", "lib", "boot")
                                 .map(mvndHome::resolve)
                                 .flatMap((Path p) -> {
                                     try {
@@ -46,7 +46,7 @@ public class MavenDaemon {
                                 })
                                 .filter(Files::isRegularFile),
                         /* resources */
-                        Stream.of(mvndHome.resolve("mvn/conf"), mvndHome.resolve("mvn/conf/logging")))
+                        Stream.of(mvndHome.resolve("conf"), mvndHome.resolve("conf/logging")))
                 .map(Path::normalize)
                 .map(Path::toUri)
                 .map(uri -> {
diff --git a/dist/src/main/distro/mvn/bin/mvn b/dist/src/main/distro/bin/mvn
similarity index 99%
rename from dist/src/main/distro/mvn/bin/mvn
rename to dist/src/main/distro/bin/mvn
index 97363a1e..50395f00 100755
--- a/dist/src/main/distro/mvn/bin/mvn
+++ b/dist/src/main/distro/bin/mvn
@@ -192,7 +192,7 @@ exec "$JAVACMD" \
   $MAVEN_DEBUG_OPTS \
   -classpath "${CLASSWORLDS_JAR}" \
   "-Dlogback.configurationFile=${MAVEN_HOME}/conf/logging/logback.xml" \
-  "-Dclassworlds.conf=${MAVEN_HOME}/bin/m2.conf" \
+  "-Dclassworlds.conf=${MAVEN_HOME}/bin/mvn.conf" \
   "-Dmaven.home=${MAVEN_HOME}" \
   "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
   ${CLASSWORLDS_LAUNCHER} "$@"
diff --git a/dist/src/main/distro/mvn/bin/mvn.cmd b/dist/src/main/distro/bin/mvn.cmd
similarity index 95%
rename from dist/src/main/distro/mvn/bin/mvn.cmd
rename to dist/src/main/distro/bin/mvn.cmd
index 17cb1cb7..1a75f297 100644
--- a/dist/src/main/distro/mvn/bin/mvn.cmd
+++ b/dist/src/main/distro/bin/mvn.cmd
@@ -173,7 +173,7 @@ set CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
   %MAVEN_DEBUG_OPTS% ^
   -classpath %CLASSWORLDS_JAR% ^
   "-Dlogback.configurationFile=%MAVEN_HOME%\conf\logging\logback.xml" ^
-  "-Dclassworlds.conf=%MAVEN_HOME%\bin\m2.conf" ^
+  "-Dclassworlds.conf=%MAVEN_HOME%\bin\mvn.conf" ^
   "-Dmaven.home=%MAVEN_HOME%" ^
   "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
   %CLASSWORLDS_LAUNCHER% %MAVEN_CMD_LINE_ARGS%
diff --git a/dist/src/main/distro/mvn/bin/m2.conf b/dist/src/main/distro/bin/mvn.conf
similarity index 100%
rename from dist/src/main/distro/mvn/bin/m2.conf
rename to dist/src/main/distro/bin/mvn.conf
diff --git a/dist/src/main/distro/mvn/bin/mvnDebug b/dist/src/main/distro/bin/mvnDebug
similarity index 100%
rename from dist/src/main/distro/mvn/bin/mvnDebug
rename to dist/src/main/distro/bin/mvnDebug
diff --git a/dist/src/main/distro/mvn/bin/mvnDebug.cmd b/dist/src/main/distro/bin/mvnDebug.cmd
similarity index 100%
rename from dist/src/main/distro/mvn/bin/mvnDebug.cmd
rename to dist/src/main/distro/bin/mvnDebug.cmd
diff --git a/dist/src/main/distro/bin/mvnd.cmd b/dist/src/main/distro/bin/mvnd.cmd
index 62d29d49..a14caedf 100644
--- a/dist/src/main/distro/bin/mvnd.cmd
+++ b/dist/src/main/distro/bin/mvnd.cmd
@@ -161,7 +161,7 @@ for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do s
 
 :endReadAdditionalConfig
 
-for %%i in ("%MVND_HOME%"\mvn\boot\plexus-classworlds-*) do set CLASSWORLDS_JAR="%%i"
+for %%i in ("%MVND_HOME%"\boot\plexus-classworlds-*) do set CLASSWORLDS_JAR="%%i"
 set CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
 
 "%JAVACMD%" ^
@@ -169,7 +169,7 @@ set CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
   %MAVEN_OPTS% ^
   %MAVEN_DEBUG_OPTS% ^
   -classpath %CLASSWORLDS_JAR% ^
-  "-Dclassworlds.conf=%MVND_HOME%\bin\m2.conf"
+  "-Dclassworlds.conf=%MVND_HOME%\bin\mvnd.conf"
   "-Dmvnd.home=%MVND_HOME%" ^
   "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
   %CLASSWORLDS_LAUNCHER% %MAVEN_CMD_LINE_ARGS%
diff --git a/dist/src/main/distro/bin/m2.conf b/dist/src/main/distro/bin/mvnd.conf
similarity index 88%
rename from dist/src/main/distro/bin/m2.conf
rename to dist/src/main/distro/bin/mvnd.conf
index 1f7aa818..3df58b2b 100644
--- a/dist/src/main/distro/bin/m2.conf
+++ b/dist/src/main/distro/bin/mvnd.conf
@@ -16,9 +16,10 @@
 # under the License.
 main is org.mvndaemon.mvnd.client.DefaultClient from plexus.core
 
-set maven.home default ${mvnd.home}/mvn
+set maven.home default ${mvnd.home}
 set maven.conf default ${maven.home}/conf
-set logback.configurationFile default ${mvnd.home}/conf/logback-client.xml
+
+set logback.configurationFile default ${maven.conf}/logging/logback-client.xml
 set logback.configurationFile.fallback default ${maven.conf}/logging/logback.xml
 
 [plexus.core]
diff --git a/dist/src/main/distro/bin/mvnd.sh b/dist/src/main/distro/bin/mvnd.sh
index df821112..029ac1a5 100755
--- a/dist/src/main/distro/bin/mvnd.sh
+++ b/dist/src/main/distro/bin/mvnd.sh
@@ -101,7 +101,7 @@ if [ ! -x "$JAVACMD" ] ; then
   exit 1
 fi
 
-CLASSWORLDS_JAR=`echo "${MVND_HOME}"/mvn/boot/plexus-classworlds-*.jar`
+CLASSWORLDS_JAR=`echo "${MVND_HOME}"/boot/plexus-classworlds-*.jar`
 CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
 
 # For Cygwin, switch paths to Windows format before running java
@@ -184,7 +184,7 @@ exec "$JAVACMD" \
   $MAVEN_OPTS \
   $MAVEN_DEBUG_OPTS \
   -classpath "${CLASSWORLDS_JAR}" \
-  "-Dclassworlds.conf=${MVND_HOME}/bin/m2.conf" \
+  "-Dclassworlds.conf=${MVND_HOME}/bin/mvnd.conf" \
   "-Dmvnd.home=${MVND_HOME}" \
   "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
   ${CLASSWORLDS_LAUNCHER} "$@"
diff --git a/dist/src/main/distro/conf/logback-client.xml b/dist/src/main/distro/conf/logging/logback-client.xml
similarity index 100%
rename from dist/src/main/distro/conf/logback-client.xml
rename to dist/src/main/distro/conf/logging/logback-client.xml
diff --git a/dist/src/main/distro/conf/logback.xml b/dist/src/main/distro/conf/logging/logback-mvnd.xml
similarity index 100%
rename from dist/src/main/distro/conf/logback.xml
rename to dist/src/main/distro/conf/logging/logback-mvnd.xml
diff --git a/dist/src/main/distro/mvn/conf/logging/logback.xml b/dist/src/main/distro/conf/logging/logback.xml
similarity index 100%
rename from dist/src/main/distro/mvn/conf/logging/logback.xml
rename to dist/src/main/distro/conf/logging/logback.xml
diff --git a/dist/src/main/provisio/maven-distro.xml b/dist/src/main/provisio/maven-distro.xml
index 56c8b68d..e39e9d61 100644
--- a/dist/src/main/provisio/maven-distro.xml
+++ b/dist/src/main/provisio/maven-distro.xml
@@ -17,65 +17,53 @@
 -->
 <assembly>
 
-    <artifactSet to="/mvn">
+    <artifactSet to="/">
         <artifact id="org.apache.maven:apache-maven:tar.gz:bin">
             <unpack useRoot="false"
-                    excludes="lib/*slf4j*,conf/logging/*,lib/maven-slf4j-provider*,bin/mvn*,lib/jansi-*.jar,lib/jansi-native/*,lib/maven-resolver-api-*,lib/maven-resolver-impl-*,lib/maven-resolver-spi-*,lib/maven-resolver-util-*,lib/maven-resolver-connector-*,lib/maven-resolver-transport-*,lib/plexus-utils-*,lib/wagon-provider-api-*"/>
+                    excludes="conf/logging/*,lib/maven-slf4j-provider*" />
         </artifact>
     </artifactSet>
 
-    <artifactSet to="/mvn/lib">
-        <exclusion id="javax.annotation:javax.annotation-api"/>
-        <artifact id="org.apache.maven.resolver:maven-resolver-api"/>
-        <artifact id="org.apache.maven.resolver:maven-resolver-impl"/>
-        <artifact id="org.apache.maven.resolver:maven-resolver-spi"/>
-        <artifact id="org.apache.maven.resolver:maven-resolver-util"/>
-        <artifact id="org.apache.maven.resolver:maven-resolver-connector-basic"/>
-        <artifact id="org.apache.maven.resolver:maven-resolver-transport-wagon"/>
+    <artifactSet to="/lib">
+        <artifact id="ch.qos.logback:logback-classic">
+            <exclusion id="*:*"/>
+        </artifact>
+        <artifact id="ch.qos.logback:logback-core">
+            <exclusion id="*:*"/>
+        </artifact>
     </artifactSet>
 
-    <artifactSet to="/mvn/lib/ext">
-        <exclusion id="org.slf4j:slf4j-api"/>
+    <artifactSet to="/lib">
         <artifact id="org.apache.maven.daemon:mvnd-daemon:${project.version}">
-            <exclusion id="org.codehaus.plexus:plexus-classworlds"/>
-            <exclusion id="*:cdi-api"/>
-            <exclusion id="*:commons-cli"/>
-            <exclusion id="*:commons-io"/>
-            <exclusion id="*:commons-lang3"/>
-            <exclusion id="*:guava"/>
-            <exclusion id="*:guice"/>
-            <exclusion id="*:javax.inject"/>
-            <exclusion id="*:jsr250-api"/>
-            <exclusion id="*:maven-artifact"/>
-            <exclusion id="*:maven-builder-support"/>
-            <exclusion id="*:maven-core"/>
-            <exclusion id="*:maven-embedder"/>
-            <exclusion id="*:maven-model"/>
-            <exclusion id="*:maven-model-builder"/>
-            <exclusion id="*:maven-plugin-api"/>
-            <exclusion id="*:maven-repository-metadata"/>
-            <exclusion id="*:maven-resolver-api"/>
-            <exclusion id="*:maven-resolver-impl"/>
-            <exclusion id="*:maven-resolver-provider"/>
-            <exclusion id="*:maven-resolver-spi"/>
-            <exclusion id="*:maven-resolver-util"/>
-            <exclusion id="*:maven-settings"/>
-            <exclusion id="*:maven-settings-builder"/>
-            <exclusion id="*:maven-shared-utils"/>
-            <exclusion id="*:org.eclipse.sisu.inject"/>
-            <exclusion id="*:org.eclipse.sisu.plexus"/>
-            <exclusion id="*:plexus-cipher"/>
-            <exclusion id="*:plexus-component-annotations"/>
-            <exclusion id="*:plexus-interpolation"/>
-            <exclusion id="*:plexus-sec-dispatcher"/>
-            <exclusion id="*:plexus-utils"/>
-            <exclusion id="*:plexus-container-default"/>
+            <exclusion id="*:*"/>
         </artifact>
         <artifact id="org.apache.maven.daemon:mvnd-client:${project.version}">
             <exclusion id="*:*"/>
         </artifact>
-        <artifact id="org.apache.maven.daemon:mvnd-agent:${project.version}"/>
-        <artifact id="org.apache.maven.daemon:mvnd-helper-agent:${project.version}"/>
+        <artifact id="org.apache.maven.daemon:mvnd-common:${project.version}">
+            <exclusion id="*:*"/>
+        </artifact>
+        <artifact id="org.apache.maven.daemon:mvnd-agent:${project.version}">
+            <exclusion id="*:*"/>
+        </artifact>
+        <artifact id="org.apache.maven.daemon:mvnd-helper-agent:${project.version}">
+            <exclusion id="*:*"/>
+        </artifact>
+        <artifact id="org.apache.maven.daemon:mvnd-native:${project.version}">
+            <exclusion id="*:*"/>
+        </artifact>
+        <artifact id="ch.qos.logback:logback-classic">
+            <exclusion id="*:*"/>
+        </artifact>
+        <artifact id="org.codehaus.plexus:plexus-interactivity-api">
+            <exclusion id="*:*"/>
+        </artifact>
+        <artifact id="org.jline:jline-terminal">
+            <exclusion id="*:*"/>
+        </artifact>
+        <artifact id="org.jline:jline-terminal-jansi">
+            <exclusion id="*:*"/>
+        </artifact>
     </artifactSet>
 
     <fileSet to="/">
diff --git a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/DistroIT.java b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/DistroIT.java
index 1044673d..5691c848 100644
--- a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/DistroIT.java
+++ b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/DistroIT.java
@@ -21,10 +21,8 @@ package org.mvndaemon.mvnd.it;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
-import java.util.ArrayList;
 import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
+import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
@@ -33,6 +31,8 @@ import java.util.stream.Stream;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
 public class DistroIT {
 
     /**
@@ -40,20 +40,16 @@ public class DistroIT {
      */
     @Test
     void noDuplicateJars() {
-        final Path mavenHome = Paths.get(System.getProperty("mvnd.home"));
-        Set<Avc> mavenLibs =
-                streamJars(mavenHome, "mvn/lib", "mvn/boot").collect(Collectors.toCollection(TreeSet::new));
-        Assertions.assertFalse(mavenLibs.isEmpty());
-        final List<Avc> mvndJars = streamJars(mavenHome, "mvn/lib/ext").collect(Collectors.toList());
-        Assertions.assertFalse(mvndJars.isEmpty());
-
-        final List<Avc> dups = mvndJars.stream()
-                .filter(avc -> mavenLibs.stream().anyMatch(mvnAvc -> mvnAvc.sameArtifactId(avc)))
+        String property = System.getProperty("mvnd.home");
+        assertNotNull(property, "mvnd.home must be defined");
+        final Path mavenHome = Paths.get(property);
+        List<Avc> avcs = listJars(mavenHome);
+        Map<String, List<Avc>> avcsByArtifactId = avcs.stream().collect(Collectors.groupingBy(Avc::getArtifactId));
+        List<List<Avc>> duplicateJars = avcsByArtifactId.values().stream()
+                .filter(list -> list.size() > 1)
                 .collect(Collectors.toList());
 
-        final String msg = mavenHome.resolve("mvn/lib/ext") + " contains duplicates available in "
-                + mavenHome.resolve("mvn/lib") + " or " + mavenHome.resolve("mvn/boot");
-        Assertions.assertEquals(new ArrayList<Avc>(), dups, msg);
+        Assertions.assertTrue(duplicateJars.isEmpty(), mavenHome + " contains duplicates jars" + duplicateJars);
     }
 
     @Test
@@ -69,21 +65,17 @@ public class DistroIT {
         Assertions.assertEquals(classifier, avc.classifier, "classifier in " + jarName);
     }
 
-    private static Stream<Avc> streamJars(Path mavenHome, String... dirs) {
-        return Stream.of(dirs)
-                .map(mavenHome::resolve)
-                .flatMap((Path p) -> {
-                    try {
-                        return Files.list(p);
-                    } catch (java.io.IOException e) {
-                        throw new RuntimeException("Could not list " + p, e);
-                    }
-                })
-                .filter(p -> p.getFileName().toString().endsWith(".jar"))
-                .filter(Files::isRegularFile)
-                .map(Path::getFileName)
-                .map(Path::toString)
-                .map(Avc::of);
+    private static List<Avc> listJars(Path mavenHome) {
+        try (Stream<Path> stream = Files.walk(mavenHome)) {
+            return stream.filter(p -> p.getFileName().toString().endsWith(".jar"))
+                    .filter(Files::isRegularFile)
+                    .map(Path::getFileName)
+                    .map(Path::toString)
+                    .map(Avc::of)
+                    .collect(Collectors.toList());
+        } catch (java.io.IOException e) {
+            throw new RuntimeException("Could not list " + mavenHome, e);
+        }
     }
 
     static class Avc implements Comparable<Avc> {
@@ -113,6 +105,10 @@ public class DistroIT {
             this.jarName = jarName;
         }
 
+        public String getArtifactId() {
+            return artifactId;
+        }
+
         @Override
         public String toString() {
             return jarName;
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 f562b233..9e291e60 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
@@ -52,7 +52,7 @@ public class MavenConfNativeIT {
                         "-DforceStdout",
                         "--raw-streams")
                 .assertSuccess();
-        String conf = parameters.mvndHome().resolve("mvn/conf").toString();
+        String conf = parameters.mvndHome().resolve("conf").toString();
         assertTrue(
                 o.getMessages().stream().anyMatch(m -> m.toString().contains(conf)), "Output should contain " + conf);
     }
diff --git a/pom.xml b/pom.xml
index b23a5f76..1db39f99 100644
--- a/pom.xml
+++ b/pom.xml
@@ -120,6 +120,11 @@
         <artifactId>logback-classic</artifactId>
         <version>${logback.version}</version>
       </dependency>
+      <dependency>
+        <groupId>ch.qos.logback</groupId>
+        <artifactId>logback-core</artifactId>
+        <version>${logback.version}</version>
+      </dependency>
       <dependency>
         <groupId>org.slf4j</groupId>
         <artifactId>slf4j-api</artifactId>


[maven-mvnd] 02/05: Fix system out / err streams when redirecting to file (#779)

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 33422a36fcb076e029097643edb23450dbdbc4b1
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Tue Jan 24 08:19:05 2023 +0100

    Fix system out / err streams when redirecting to file (#779)
---
 .../mvndaemon/mvnd/common/logging/TerminalOutput.java    | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/common/src/main/java/org/mvndaemon/mvnd/common/logging/TerminalOutput.java b/common/src/main/java/org/mvndaemon/mvnd/common/logging/TerminalOutput.java
index 85ad87d2..56f89b56 100644
--- a/common/src/main/java/org/mvndaemon/mvnd/common/logging/TerminalOutput.java
+++ b/common/src/main/java/org/mvndaemon/mvnd/common/logging/TerminalOutput.java
@@ -323,14 +323,22 @@ public class TerminalOutput implements ClientOutput {
             }
             case Message.PRINT_OUT: {
                 Message.StringMessage d = (Message.StringMessage) entry;
-                clearDisplay();
-                System.out.printf("%s%n", d.getMessage());
+                if (log instanceof FileLog) {
+                    log.accept(d.getMessage());
+                } else {
+                    clearDisplay();
+                    System.out.printf("%s%n", d.getMessage());
+                }
                 break;
             }
             case Message.PRINT_ERR: {
                 Message.StringMessage d = (Message.StringMessage) entry;
-                clearDisplay();
-                System.err.printf("%s%n", d.getMessage());
+                if (log instanceof FileLog) {
+                    log.accept(d.getMessage());
+                } else {
+                    clearDisplay();
+                    System.err.printf("%s%n", d.getMessage());
+                }
                 break;
             }
             case Message.PROMPT: {


[maven-mvnd] 04/05: Try native image then fallback to pure java version (#717)

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit f9954a526f608abe512764ed3985cf3547e92b3c
Author: James Z.M. Gao <ga...@gmail.com>
AuthorDate: Tue Jan 24 17:51:56 2023 +0800

    Try native image then fallback to pure java version (#717)
    
    * Add script mvnd-auto to auto select native or pure java mvnd
    
    * Move fallback logic into main entry script
    
    1. rename native binary to 'mvnd-native-<os>-<arch>'
    2. add environment switch MVND_ENTRY_FALLBACK, default 'true' enables
       the fallback logic, set to 'false' to force execute the native mvnd.
    3. rename mvnd.sh to mvnd
    
    * change entry name on windows
    
    * Add script mvnd-persist-native for moving the native image to the default entry path
    
    * improve platform detect
    
    * fix error on dash
    
    * rollback default entry to the native image
    
    * use MVND_CLIENT switch to control the selection of mvnd client
    
    * improve comment docs as suggestion
---
 client/pom.xml                          |  2 +-
 dist/src/main/distro/bin/mvnd.cmd       | 28 +++++++++++++++++++++++
 dist/src/main/distro/bin/mvnd.sh        | 39 +++++++++++++++++++++++++++++++--
 dist/src/main/provisio/maven-distro.xml |  1 +
 4 files changed, 67 insertions(+), 3 deletions(-)

diff --git a/client/pom.xml b/client/pom.xml
index b34f3f2f..322ae765 100644
--- a/client/pom.xml
+++ b/client/pom.xml
@@ -225,7 +225,7 @@
             <executions>
               <execution>
                 <goals>
-                  <goal>build</goal>
+                  <goal>compile-no-fork</goal>
                 </goals>
                 <phase>package</phase>
               </execution>
diff --git a/dist/src/main/distro/bin/mvnd.cmd b/dist/src/main/distro/bin/mvnd.cmd
index a14caedf..50fbeea1 100644
--- a/dist/src/main/distro/bin/mvnd.cmd
+++ b/dist/src/main/distro/bin/mvnd.cmd
@@ -25,6 +25,12 @@
 @REM   MAVEN_BATCH_PAUSE (Optional) set to 'on' to wait for a key stroke before ending.
 @REM   MAVEN_OPTS        (Optional) Java runtime options used when Maven is executed.
 @REM   MAVEN_SKIP_RC     (Optional) Flag to disable loading of mavenrc files.
+@REM   MVND_CLIENT       (Optional) Control how to select mvnd client to communicate with the daemon:
+@REM                        'auto' (default) - prefer the native client mvnd.exe if it suits the current
+@REM                                           OS and processor architecture; otherwise use the pure
+@REM                                           Java client.
+@REM                        'native' - use the native client mvnd.exe
+@REM                        'jvm' - use the pure Java client
 @REM -----------------------------------------------------------------------------
 
 @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@@ -43,6 +49,28 @@ if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %*
 
 set ERROR_CODE=0
 
+set "MVND_CMD=%~dp0\mvnd.exe"
+if "%MVND_CLIENT%"=="native" goto runNative
+if "%MVND_CLIENT%"=="" goto checkNative
+if not "%MVND_CLIENT%"=="auto" goto runJvm
+
+:checkNative
+@REM try execute native image
+if "%PROCESSOR_ARCHITEW6432%"=="" (
+  if not exist "%~dp0\platform-windows-%PROCESSOR_ARCHITECTURE%" goto runJvm
+) else (
+  if not exist "%~dp0\platform-windows-%PROCESSOR_ARCHITEW6432%" goto runJvm
+)
+if not exist "%MVND_CMD%" goto runJvm
+
+:runNative
+"%MVND_CMD%" %*
+if ERRORLEVEL 1 goto error
+goto end
+
+:runJvm
+@REM fallback to pure java version
+
 @REM ==== START VALIDATION ====
 if not "%JAVA_HOME%"=="" goto OkJHome
 for %%i in (java.exe) do set "JAVACMD=%%~$PATH:i"
diff --git a/dist/src/main/distro/bin/mvnd.sh b/dist/src/main/distro/bin/mvnd.sh
index 029ac1a5..72eafe54 100755
--- a/dist/src/main/distro/bin/mvnd.sh
+++ b/dist/src/main/distro/bin/mvnd.sh
@@ -25,6 +25,11 @@
 #   JAVA_HOME       Must point at your Java Development Kit installation.
 #   MAVEN_OPTS      (Optional) Java runtime options used when Maven is executed.
 #   MAVEN_SKIP_RC   (Optional) Flag to disable loading of mavenrc files.
+#   MVND_CLIENT     (Optional) Control how to select mvnd client to communicate with the daemon:
+#                      'auto' (default) - prefer the native client mvnd if it suits the current OS and
+#                                         processor architecture; otherwise use the pure Java client.
+#                      'native' - use the native client mvnd
+#                      'jvm' - use the pure Java client
 # -----------------------------------------------------------------------------
 
 if [ -z "$MAVEN_SKIP_RC" ] ; then
@@ -43,8 +48,8 @@ fi
 cygwin=false;
 mingw=false;
 case "`uname`" in
-  CYGWIN*) cygwin=true;;
-  MINGW*) mingw=true;;
+  CYGWIN*) cygwin=true native_ext=.exe ;;
+  MINGW*) mingw=true native_ext=.exe ;;
 esac
 
 ## resolve links - $0 may be a link to Maven's home
@@ -89,6 +94,36 @@ if $mingw ; then
   # TODO classpath?
 fi
 
+if [ "${MVND_CLIENT:=auto}" = native ]; then
+  # force execute native image
+  exec "$MVND_HOME/bin/mvnd${native_ext:-}" "$@"
+elif [ "$MVND_CLIENT" = auto ]; then
+  # try native image
+  case "$(uname -a)" in
+  (CYGWIN*|MINGW*) os=windows arch="${PROCESSOR_ARCHITEW6432:-"${PROCESSOR_ARCHITECTURE:-"$(uname -m)"}"}" ;;
+  (Darwin*x86_64) os=darwin arch=amd64 ;;
+  (Darwin*arm64) os=darwin arch=aarch64 ;;
+  (Linux*) os=linux arch=$(uname -m) ;;
+  (*) os=$(uname) arch=$(uname -m) ;;
+  esac
+  [ "${arch-}" != x86_64 ] || arch=amd64
+  [ "${arch-}" != AMD64 ] || arch=amd64
+  [ "${arch-}" != arm64 ] || arch=aarch64
+
+  MVND_CMD="$MVND_HOME/bin/mvnd${native_ext:-}"
+  if [ -e "$MVND_HOME/bin/platform-$os-$arch" ] && [ -x "$MVND_CMD" ]; then
+    is_native=true
+    if [ "$os" = linux ]; then
+      case "$(ldd "$MVND_CMD" 2>&1)" in
+      (''|*"not found"*) is_native=false ;;
+      esac
+    fi
+    ! $is_native || exec "$MVND_CMD" "$@"
+  fi
+fi
+
+# fallback to pure java version
+
 if [ -z "$JAVA_HOME" ] ; then
   JAVACMD="`\\unset -f command; \\command -v java`"
 else
diff --git a/dist/src/main/provisio/maven-distro.xml b/dist/src/main/provisio/maven-distro.xml
index e39e9d61..29afeade 100644
--- a/dist/src/main/provisio/maven-distro.xml
+++ b/dist/src/main/provisio/maven-distro.xml
@@ -79,6 +79,7 @@
             <include>mvnd</include>
             <include>mvnd.exe</include>
         </directory>
+        <file touch="platform-${os.detected.name}-${os.detected.arch}"/>
     </fileSet>
 
     <archive name="maven-mvnd-${project.version}-${os.detected.name}-${os.detected.arch}.zip"