From 5c07639baab435e461ea295f8d7d78e1a1d88dd6 Mon Sep 17 00:00:00 2001 From: "James Z.M. Gao" Date: Sun, 16 Oct 2022 19:18:21 +0800 Subject: [PATCH 1/9] Add script mvnd-auto to auto select native or pure java mvnd --- dist/src/main/distro/bin/mvnd-auto | 67 ++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 dist/src/main/distro/bin/mvnd-auto diff --git a/dist/src/main/distro/bin/mvnd-auto b/dist/src/main/distro/bin/mvnd-auto new file mode 100755 index 000000000..e759c52d0 --- /dev/null +++ b/dist/src/main/distro/bin/mvnd-auto @@ -0,0 +1,67 @@ +#!/bin/sh + +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. + +set -euf + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +# For Cygwin and MinGW, ensure paths are in Unix format before anything is touched +(CYGWIN*|MINGW*) [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } ;; +esac + +is_jdk_11() { + if [ -n "${JAVA_HOME-}" ] ; then + "$(native_path "$JAVA_HOME/bin/java")" --enable-preview -version >/dev/null 2>/dev/null + else + java --enable-preview -version >/dev/null 2>/dev/null + fi +} + +## resolve links - $0 may be a link to Maven's home +PRG="$0" + +# need this for relative symlinks +while [ -h "$PRG" ] ; do + ls=$(ls -ld "$PRG") + link=$(expr "$ls" : '.*-> \(.*\)$') + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="$(dirname "$PRG")/$link" + fi +done + +# make it fully qualified +MVND_HOME=$(cd -- "$(dirname -- "$PRG")/.." && pwd) + +if "$MVND_HOME"/bin/mvnd --status >/dev/null 2>/dev/null; then + # try native mvnd + exec "$MVND_HOME"/bin/mvnd "$@" +elif is_jdk_11; then + # try java version mvnd + exec "$MVND_HOME"/bin/mvnd.sh "$@" +else + # fall back to embedded maven + exec "$MVND_HOME"/mvn/bin/mvn "$@" +fi + +echo "failed to exec mvnd" >&2 +exit 1 From 29ecd01c87b8fc05d3b03f0bc839e8c40e65bc24 Mon Sep 17 00:00:00 2001 From: "James Z.M. Gao" Date: Fri, 21 Oct 2022 00:51:47 +0800 Subject: [PATCH 2/9] Move fallback logic into main entry script 1. rename native binary to 'mvnd-native--' 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 --- client/pom.xml | 2 +- dist/src/main/distro/bin/{mvnd.sh => mvnd} | 35 +++++++++++ dist/src/main/distro/bin/mvnd-auto | 67 ---------------------- dist/src/main/distro/bin/mvnd.cmd | 16 ++++++ dist/src/main/provisio/maven-distro.xml | 4 +- 5 files changed, 54 insertions(+), 70 deletions(-) rename dist/src/main/distro/bin/{mvnd.sh => mvnd} (83%) delete mode 100755 dist/src/main/distro/bin/mvnd-auto diff --git a/client/pom.xml b/client/pom.xml index f9808d067..e25b44f46 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -209,7 +209,7 @@ false org.mvndaemon.mvnd.client.DefaultClient - mvnd + mvnd-native-${os.detected.name}-${os.detected.arch} --no-server --no-fallback --allow-incomplete-classpath diff --git a/dist/src/main/distro/bin/mvnd.sh b/dist/src/main/distro/bin/mvnd similarity index 83% rename from dist/src/main/distro/bin/mvnd.sh rename to dist/src/main/distro/bin/mvnd index df821112e..41b36957b 100755 --- a/dist/src/main/distro/bin/mvnd.sh +++ b/dist/src/main/distro/bin/mvnd @@ -25,6 +25,9 @@ # 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_ENTRY_FALLBACK (Optional) Flag to disable fallback to pure java mvnd, +# default 'true' enable the fallback, +# set to 'false' to force execute the native mvnd. # ----------------------------------------------------------------------------- if [ -z "$MAVEN_SKIP_RC" ] ; then @@ -89,6 +92,38 @@ if $mingw ; then # TODO classpath? fi +# force execute native image +if [ "${MVND_ENTRY_FALLBACK:-true}" = false ]; then + MVND_CMD=$(echo "$MVND_HOME"/bin/mvnd-native-*) + [ ! -x "$MVND_CMD" ] || exec "$MVND_CMD" "$@" + echo "Cannot run native mvnd '${MVND_CMD-}'!" >&2 + exit 1 +fi + +case "$(uname -a)" in +(CYGWIN*|MINGW*) os=windows arch=$(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-}" != arm64 ] || arch=aarch64 + +# try native image +MVND_CMD="$MVND_HOME/bin/mvnd-native-$os-$arch" +if [ -x "$MVND_CMD" ]; then + is_native=true + if [ "$os" = linux ]; then + case "$(ldd "$MVND_CMD")" in + (''|*"not found"*) is_native=false ;; + esac + fi + ! $is_native || exec "$MVND_CMD" "$@" +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/distro/bin/mvnd-auto b/dist/src/main/distro/bin/mvnd-auto deleted file mode 100755 index e759c52d0..000000000 --- a/dist/src/main/distro/bin/mvnd-auto +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/sh - -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. - -set -euf - -# OS specific support. -native_path() { printf %s\\n "$1"; } -case "$(uname)" in -# For Cygwin and MinGW, ensure paths are in Unix format before anything is touched -(CYGWIN*|MINGW*) [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" - native_path() { cygpath --path --windows "$1"; } ;; -esac - -is_jdk_11() { - if [ -n "${JAVA_HOME-}" ] ; then - "$(native_path "$JAVA_HOME/bin/java")" --enable-preview -version >/dev/null 2>/dev/null - else - java --enable-preview -version >/dev/null 2>/dev/null - fi -} - -## resolve links - $0 may be a link to Maven's home -PRG="$0" - -# need this for relative symlinks -while [ -h "$PRG" ] ; do - ls=$(ls -ld "$PRG") - link=$(expr "$ls" : '.*-> \(.*\)$') - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="$(dirname "$PRG")/$link" - fi -done - -# make it fully qualified -MVND_HOME=$(cd -- "$(dirname -- "$PRG")/.." && pwd) - -if "$MVND_HOME"/bin/mvnd --status >/dev/null 2>/dev/null; then - # try native mvnd - exec "$MVND_HOME"/bin/mvnd "$@" -elif is_jdk_11; then - # try java version mvnd - exec "$MVND_HOME"/bin/mvnd.sh "$@" -else - # fall back to embedded maven - exec "$MVND_HOME"/mvn/bin/mvn "$@" -fi - -echo "failed to exec mvnd" >&2 -exit 1 diff --git a/dist/src/main/distro/bin/mvnd.cmd b/dist/src/main/distro/bin/mvnd.cmd index 62d29d490..b3c949425 100644 --- a/dist/src/main/distro/bin/mvnd.cmd +++ b/dist/src/main/distro/bin/mvnd.cmd @@ -25,6 +25,9 @@ @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_ENTRY_FALLBACK (Optional) Flag to disable fallback to pure java mvnd, +@REM default 'true' enable the fallback, +@REM set to 'false' to force execute the native mvnd. @REM ----------------------------------------------------------------------------- @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' @@ -43,6 +46,19 @@ if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* set ERROR_CODE=0 +@REM try execute native image +set "MVND_CMD=%~dp0\mvnd-native-windows-%PROCESSOR_ARCHITECTURE:x64=amd64%.exe" +if not exist "%MVND_CMD%" goto noNativeImage +"%MVND_CMD%" %* +if ERRORLEVEL 1 goto error +goto end +:noNativeImage +if not "%MVND_ENTRY_FALLBACK%"=="false" goto fallback +echo Cannot run native mvnd %MVND_CMD%! >&2 +goto error +:fallback +@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/provisio/maven-distro.xml b/dist/src/main/provisio/maven-distro.xml index 145e2f883..7f4907f3d 100644 --- a/dist/src/main/provisio/maven-distro.xml +++ b/dist/src/main/provisio/maven-distro.xml @@ -94,8 +94,8 @@ - mvnd - mvnd.exe + mvnd-native-${os.detected.name}-${os.detected.arch} + mvnd-native-${os.detected.name}-${os.detected.arch}.exe From 9e24715e9931d0e1c4852d5a9aaf9cb34e77e7ff Mon Sep 17 00:00:00 2001 From: "James Z.M. Gao" Date: Fri, 21 Oct 2022 08:01:19 +0800 Subject: [PATCH 3/9] change entry name on windows --- .../test/java/org/mvndaemon/mvnd/junit/MvndTestExtension.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-tests/src/test/java/org/mvndaemon/mvnd/junit/MvndTestExtension.java b/integration-tests/src/test/java/org/mvndaemon/mvnd/junit/MvndTestExtension.java index 4aa6a7b02..9523d5b20 100644 --- a/integration-tests/src/test/java/org/mvndaemon/mvnd/junit/MvndTestExtension.java +++ b/integration-tests/src/test/java/org/mvndaemon/mvnd/junit/MvndTestExtension.java @@ -130,7 +130,7 @@ Client newClient(boolean isNative, DaemonParameters parameters, long timeoutMs) System.getProperty("os.name") .toLowerCase(Locale.ROOT) .startsWith("windows") - ? "bin/mvnd.exe" + ? "bin/mvnd.cmd" : "bin/mvnd") .toAbsolutePath() .normalize(); From ceff591740726aac40c67af11676929c7a4db3bb Mon Sep 17 00:00:00 2001 From: "James Z.M. Gao" Date: Mon, 24 Oct 2022 01:10:11 +0800 Subject: [PATCH 4/9] Add script mvnd-persist-native for moving the native image to the default entry path --- dist/src/main/distro/bin/mvnd-persist-native | 62 ++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 dist/src/main/distro/bin/mvnd-persist-native diff --git a/dist/src/main/distro/bin/mvnd-persist-native b/dist/src/main/distro/bin/mvnd-persist-native new file mode 100755 index 000000000..80ad40c2b --- /dev/null +++ b/dist/src/main/distro/bin/mvnd-persist-native @@ -0,0 +1,62 @@ +#!/bin/sh + +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. + +set -eu + +# full qualified mvnd bin dir +MVND_BIN=$(cd -- "${0%/*}" && pwd) + +__MVND_ALREADY_OPTIMIZED=true +find "$MVND_BIN" -name 'mvnd-generic*' | grep -q mvnd- || __MVND_ALREADY_OPTIMIZED=false + +__MVND_FORCE_NATIVE_OK=true +MVND_ENTRY_FALLBACK=false "$MVND_BIN/mvnd" --status >/dev/null 2>/dev/null || __MVND_FORCE_NATIVE_OK=false + +case "$__MVND_ALREADY_OPTIMIZED:$__MVND_FORCE_NATIVE_OK" in +(true:true) exit 0 ;; +(true:false) + echo "Native image does not work, but should work!" >&2 + exit 1 + ;; +(false:true) ;; # should move native image as 'mvnd' +(false:false) + echo "Keep using the generic entry script." + exit 0 + ;; +esac + +MVND_NATIVE=$(echo "$MVND_BIN"/mvnd-native-*) + +if [ ! -x "$MVND_NATIVE" ]; then + echo "Cannot find native image at '$MVND_NATIVE'" >&2 + exit 1 +fi + +mv -f -- "$MVND_BIN/mvnd" "$MVND_BIN/mvnd-generic" +if [ -f "$MVND_BIN/mvnd.cmd" ]; then + mv -f -- "$MVND_BIN/mvnd.cmd" "$MVND_BIN/mvnd-generic.cmd" +fi + +mv -f -- "$MVND_NATIVE" "$MVND_BIN/mvnd" +cat >"$MVND_NATIVE" <<-END + #!/bin/sh + exec "$MVND_BIN/mvnd" "\$@" + END + +chmod +x "$MVND_NATIVE" From 6e4cad7ba0ccb70f82a4c412753959ab200a4022 Mon Sep 17 00:00:00 2001 From: "James Z.M. Gao" Date: Tue, 10 Jan 2023 17:51:18 +0800 Subject: [PATCH 5/9] improve platform detect --- dist/src/main/distro/bin/mvnd | 13 ++++++------- dist/src/main/distro/bin/mvnd.cmd | 6 +++++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/dist/src/main/distro/bin/mvnd b/dist/src/main/distro/bin/mvnd index 41b36957b..ffe719dfb 100755 --- a/dist/src/main/distro/bin/mvnd +++ b/dist/src/main/distro/bin/mvnd @@ -94,32 +94,31 @@ fi # force execute native image if [ "${MVND_ENTRY_FALLBACK:-true}" = false ]; then - MVND_CMD=$(echo "$MVND_HOME"/bin/mvnd-native-*) - [ ! -x "$MVND_CMD" ] || exec "$MVND_CMD" "$@" - echo "Cannot run native mvnd '${MVND_CMD-}'!" >&2 - exit 1 + exec -- "$(echo "$MVND_HOME"/bin/mvnd-native-*)" "$@" fi case "$(uname -a)" in -(CYGWIN*|MINGW*) os=windows arch=$(uname -m) ;; +(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 # try native image MVND_CMD="$MVND_HOME/bin/mvnd-native-$os-$arch" +[ "${os-}" != windows ] || MVND_CMD="$MVND_CMD.exe" if [ -x "$MVND_CMD" ]; then is_native=true if [ "$os" = linux ]; then - case "$(ldd "$MVND_CMD")" in + case "$(ldd "$MVND_CMD" 2>&1)" in (''|*"not found"*) is_native=false ;; esac fi - ! $is_native || exec "$MVND_CMD" "$@" + ! $is_native || exec -- "$MVND_CMD" "$@" fi # fallback to pure java version diff --git a/dist/src/main/distro/bin/mvnd.cmd b/dist/src/main/distro/bin/mvnd.cmd index b3c949425..ec443b899 100644 --- a/dist/src/main/distro/bin/mvnd.cmd +++ b/dist/src/main/distro/bin/mvnd.cmd @@ -47,7 +47,11 @@ if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* set ERROR_CODE=0 @REM try execute native image -set "MVND_CMD=%~dp0\mvnd-native-windows-%PROCESSOR_ARCHITECTURE:x64=amd64%.exe" +if not "%PROCESSOR_ARCHITEW6432%"=="" ( + set "MVND_CMD=%~dp0\mvnd-native-windows-%PROCESSOR_ARCHITEW6432:x64=amd64%.exe" +) else ( + set "MVND_CMD=%~dp0\mvnd-native-windows-%PROCESSOR_ARCHITECTURE:x64=amd64%.exe" +) if not exist "%MVND_CMD%" goto noNativeImage "%MVND_CMD%" %* if ERRORLEVEL 1 goto error From b8094bd2d6adeaae505fb1c90170a6e9bfb2fc04 Mon Sep 17 00:00:00 2001 From: "James Z.M. Gao" Date: Tue, 10 Jan 2023 21:56:12 +0800 Subject: [PATCH 6/9] fix error on dash --- dist/src/main/distro/bin/mvnd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/src/main/distro/bin/mvnd b/dist/src/main/distro/bin/mvnd index ffe719dfb..a6ec7241d 100755 --- a/dist/src/main/distro/bin/mvnd +++ b/dist/src/main/distro/bin/mvnd @@ -94,7 +94,7 @@ fi # force execute native image if [ "${MVND_ENTRY_FALLBACK:-true}" = false ]; then - exec -- "$(echo "$MVND_HOME"/bin/mvnd-native-*)" "$@" + exec "$(echo "$MVND_HOME"/bin/mvnd-native-*)" "$@" fi case "$(uname -a)" in @@ -118,7 +118,7 @@ if [ -x "$MVND_CMD" ]; then (''|*"not found"*) is_native=false ;; esac fi - ! $is_native || exec -- "$MVND_CMD" "$@" + ! $is_native || exec "$MVND_CMD" "$@" fi # fallback to pure java version From 1c3d4fa787ee5c657dff88d057e71a1b67e37104 Mon Sep 17 00:00:00 2001 From: "James Z.M. Gao" Date: Wed, 11 Jan 2023 14:16:52 +0800 Subject: [PATCH 7/9] rollback default entry to the native image --- client/pom.xml | 4 +- dist/src/main/distro/bin/mvnd-persist-native | 62 ------------------- dist/src/main/distro/bin/mvnd.cmd | 7 ++- dist/src/main/distro/bin/{mvnd => mvnd.sh} | 11 ++-- dist/src/main/provisio/maven-distro.xml | 5 +- .../mvnd/junit/MvndTestExtension.java | 2 +- 6 files changed, 15 insertions(+), 76 deletions(-) delete mode 100755 dist/src/main/distro/bin/mvnd-persist-native rename dist/src/main/distro/bin/{mvnd => mvnd.sh} (96%) diff --git a/client/pom.xml b/client/pom.xml index e25b44f46..8fb167f92 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -209,7 +209,7 @@ false org.mvndaemon.mvnd.client.DefaultClient - mvnd-native-${os.detected.name}-${os.detected.arch} + mvnd --no-server --no-fallback --allow-incomplete-classpath @@ -225,7 +225,7 @@ - build + compile-no-fork package diff --git a/dist/src/main/distro/bin/mvnd-persist-native b/dist/src/main/distro/bin/mvnd-persist-native deleted file mode 100755 index 80ad40c2b..000000000 --- a/dist/src/main/distro/bin/mvnd-persist-native +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/sh - -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. - -set -eu - -# full qualified mvnd bin dir -MVND_BIN=$(cd -- "${0%/*}" && pwd) - -__MVND_ALREADY_OPTIMIZED=true -find "$MVND_BIN" -name 'mvnd-generic*' | grep -q mvnd- || __MVND_ALREADY_OPTIMIZED=false - -__MVND_FORCE_NATIVE_OK=true -MVND_ENTRY_FALLBACK=false "$MVND_BIN/mvnd" --status >/dev/null 2>/dev/null || __MVND_FORCE_NATIVE_OK=false - -case "$__MVND_ALREADY_OPTIMIZED:$__MVND_FORCE_NATIVE_OK" in -(true:true) exit 0 ;; -(true:false) - echo "Native image does not work, but should work!" >&2 - exit 1 - ;; -(false:true) ;; # should move native image as 'mvnd' -(false:false) - echo "Keep using the generic entry script." - exit 0 - ;; -esac - -MVND_NATIVE=$(echo "$MVND_BIN"/mvnd-native-*) - -if [ ! -x "$MVND_NATIVE" ]; then - echo "Cannot find native image at '$MVND_NATIVE'" >&2 - exit 1 -fi - -mv -f -- "$MVND_BIN/mvnd" "$MVND_BIN/mvnd-generic" -if [ -f "$MVND_BIN/mvnd.cmd" ]; then - mv -f -- "$MVND_BIN/mvnd.cmd" "$MVND_BIN/mvnd-generic.cmd" -fi - -mv -f -- "$MVND_NATIVE" "$MVND_BIN/mvnd" -cat >"$MVND_NATIVE" <<-END - #!/bin/sh - exec "$MVND_BIN/mvnd" "\$@" - END - -chmod +x "$MVND_NATIVE" diff --git a/dist/src/main/distro/bin/mvnd.cmd b/dist/src/main/distro/bin/mvnd.cmd index ec443b899..a11794e4f 100644 --- a/dist/src/main/distro/bin/mvnd.cmd +++ b/dist/src/main/distro/bin/mvnd.cmd @@ -47,11 +47,12 @@ if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* set ERROR_CODE=0 @REM try execute native image -if not "%PROCESSOR_ARCHITEW6432%"=="" ( - set "MVND_CMD=%~dp0\mvnd-native-windows-%PROCESSOR_ARCHITEW6432:x64=amd64%.exe" +if "%PROCESSOR_ARCHITEW6432%"=="" ( + if not exist "%~dp0\platform-windows-%PROCESSOR_ARCHITECTURE%" goto noNativeImage ) else ( - set "MVND_CMD=%~dp0\mvnd-native-windows-%PROCESSOR_ARCHITECTURE:x64=amd64%.exe" + if not exist "%~dp0\platform-windows-%PROCESSOR_ARCHITEW6432%" goto noNativeImage ) +set "MVND_CMD=%~dp0\mvnd.exe" if not exist "%MVND_CMD%" goto noNativeImage "%MVND_CMD%" %* if ERRORLEVEL 1 goto error diff --git a/dist/src/main/distro/bin/mvnd b/dist/src/main/distro/bin/mvnd.sh similarity index 96% rename from dist/src/main/distro/bin/mvnd rename to dist/src/main/distro/bin/mvnd.sh index a6ec7241d..2016cefdc 100755 --- a/dist/src/main/distro/bin/mvnd +++ b/dist/src/main/distro/bin/mvnd.sh @@ -46,8 +46,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 @@ -94,7 +94,7 @@ fi # force execute native image if [ "${MVND_ENTRY_FALLBACK:-true}" = false ]; then - exec "$(echo "$MVND_HOME"/bin/mvnd-native-*)" "$@" + exec "$MVND_HOME/bin/mvnd${native_ext:-}" "$@" fi case "$(uname -a)" in @@ -109,9 +109,8 @@ esac [ "${arch-}" != arm64 ] || arch=aarch64 # try native image -MVND_CMD="$MVND_HOME/bin/mvnd-native-$os-$arch" -[ "${os-}" != windows ] || MVND_CMD="$MVND_CMD.exe" -if [ -x "$MVND_CMD" ]; then +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 diff --git a/dist/src/main/provisio/maven-distro.xml b/dist/src/main/provisio/maven-distro.xml index 7f4907f3d..536f348a6 100644 --- a/dist/src/main/provisio/maven-distro.xml +++ b/dist/src/main/provisio/maven-distro.xml @@ -94,9 +94,10 @@ - mvnd-native-${os.detected.name}-${os.detected.arch} - mvnd-native-${os.detected.name}-${os.detected.arch}.exe + mvnd + mvnd.exe + Date: Thu, 12 Jan 2023 00:57:33 +0800 Subject: [PATCH 8/9] use MVND_CLIENT switch to control the selection of mvnd client --- dist/src/main/distro/bin/mvnd.cmd | 30 ++++++++++------- dist/src/main/distro/bin/mvnd.sh | 56 ++++++++++++++++--------------- 2 files changed, 47 insertions(+), 39 deletions(-) diff --git a/dist/src/main/distro/bin/mvnd.cmd b/dist/src/main/distro/bin/mvnd.cmd index a11794e4f..0cb492e91 100644 --- a/dist/src/main/distro/bin/mvnd.cmd +++ b/dist/src/main/distro/bin/mvnd.cmd @@ -25,9 +25,11 @@ @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_ENTRY_FALLBACK (Optional) Flag to disable fallback to pure java mvnd, -@REM default 'true' enable the fallback, -@REM set to 'false' to force execute the native mvnd. +@REM MVND_CLIENT (Optional) Control how to select mvnd client to communicate with the daemon: +@REM 'auto' (default) - prefer the native client mvnd if it works; otherwise use +@REM the pure 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' @@ -46,22 +48,26 @@ 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 noNativeImage + if not exist "%~dp0\platform-windows-%PROCESSOR_ARCHITECTURE%" goto runJvm ) else ( - if not exist "%~dp0\platform-windows-%PROCESSOR_ARCHITEW6432%" goto noNativeImage + if not exist "%~dp0\platform-windows-%PROCESSOR_ARCHITEW6432%" goto runJvm ) -set "MVND_CMD=%~dp0\mvnd.exe" -if not exist "%MVND_CMD%" goto noNativeImage +if not exist "%MVND_CMD%" goto runJvm + +:runNative "%MVND_CMD%" %* if ERRORLEVEL 1 goto error goto end -:noNativeImage -if not "%MVND_ENTRY_FALLBACK%"=="false" goto fallback -echo Cannot run native mvnd %MVND_CMD%! >&2 -goto error -:fallback + +:runJvm @REM fallback to pure java version @REM ==== START VALIDATION ==== diff --git a/dist/src/main/distro/bin/mvnd.sh b/dist/src/main/distro/bin/mvnd.sh index 2016cefdc..edec8b274 100755 --- a/dist/src/main/distro/bin/mvnd.sh +++ b/dist/src/main/distro/bin/mvnd.sh @@ -25,9 +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_ENTRY_FALLBACK (Optional) Flag to disable fallback to pure java mvnd, -# default 'true' enable the fallback, -# set to 'false' to force execute the native mvnd. +# MVND_CLIENT (Optional) Control how to select mvnd client to communicate with the daemon: +# 'auto' (default) - prefer the native client mvnd if it works; otherwise use +# the pure Java client. +# 'native' - use the native client mvnd.exe +# 'jvm' - use the pure Java client # ----------------------------------------------------------------------------- if [ -z "$MAVEN_SKIP_RC" ] ; then @@ -92,32 +94,32 @@ if $mingw ; then # TODO classpath? fi -# force execute native image -if [ "${MVND_ENTRY_FALLBACK:-true}" = false ]; then +if [ "${MVND_CLIENT:=auto}" = native ]; then + # force execute native image exec "$MVND_HOME/bin/mvnd${native_ext:-}" "$@" -fi - -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 - -# try native image -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 +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 - ! $is_native || exec "$MVND_CMD" "$@" fi # fallback to pure java version From b6a5e8c078565c459291b7e54cf02a095d186fa0 Mon Sep 17 00:00:00 2001 From: "James Z.M. Gao" Date: Thu, 12 Jan 2023 22:56:35 +0800 Subject: [PATCH 9/9] improve comment docs as suggestion --- dist/src/main/distro/bin/mvnd.cmd | 5 +++-- dist/src/main/distro/bin/mvnd.sh | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/dist/src/main/distro/bin/mvnd.cmd b/dist/src/main/distro/bin/mvnd.cmd index 0cb492e91..4d1125367 100644 --- a/dist/src/main/distro/bin/mvnd.cmd +++ b/dist/src/main/distro/bin/mvnd.cmd @@ -26,8 +26,9 @@ @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 if it works; otherwise use -@REM the pure Java client. +@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 ----------------------------------------------------------------------------- diff --git a/dist/src/main/distro/bin/mvnd.sh b/dist/src/main/distro/bin/mvnd.sh index edec8b274..5ac4533a0 100755 --- a/dist/src/main/distro/bin/mvnd.sh +++ b/dist/src/main/distro/bin/mvnd.sh @@ -26,9 +26,9 @@ # 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 works; otherwise use -# the pure Java client. -# 'native' - use the native client mvnd.exe +# '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 # -----------------------------------------------------------------------------