You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by cs...@apache.org on 2026/10/20 15:14:08 UTC

(maven) branch maven-3.10.x updated: [MNG-8056] Fix -f/-s parameters failing with absolute Cygwin paths (fix #10810) (#13593)

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

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


The following commit(s) were added to refs/heads/maven-3.10.x by this push:
     new d1b5c61019 [MNG-8056] Fix -f/-s parameters failing with absolute Cygwin paths (fix #10810) (#13593)
d1b5c61019 is described below

commit d1b5c610191465ff4b7e925db5f22665c779b60a
Author: Arturo Bernal <ab...@apache.org>
AuthorDate: Tue Oct 20 17:14:01 2026 +0200

    [MNG-8056] Fix -f/-s parameters failing with absolute Cygwin paths (fix #10810) (#13593)
    
    Backport of #13239 to maven-3.10.x. It is already on master and on maven-4.0.x (#13248).
    
    Under Cygwin the JVM is a native Windows process and cannot resolve POSIX paths such as `/cygdrive/c/temp/pom.xml`, so `mvn -f /cygdrive/c/temp/pom.xml validate` and `mvn -s /cygdrive/c/.../settings.xml` fail (#10810, reported against 3.9.6). `bin/mvn` already converts its own paths with `cygpath`, but not the ones given as arguments. It now converts the absolute POSIX path of `-f/--file`, `-s/--settings`, `-gs/--global-settings`, `-t/--toolchains`, `-gt/--global-toolchains`, `-ps/--p [...]
    
    The patch did not apply as it was, because the launcher differs on this branch (the `MAVEN_ARGS` handling is different, and `-af` does not exist in 3.x), so the block was placed after the `MAVEN_ARGS` processing and the `-af/--at-file` flag was left out. The test script `test-mvn-path-conversion.sh` has the same cases as on master: `-f`, `-s` and `--file=` with a `/cygdrive` path, a relative path, and MinGW. It passes, and the three Cygwin cases fail without the change. I could not ru [...]
    
    ---
    
    To make clear that you license your contribution under
    the [Apache License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0)
    check one of the following:
    
    - [x] I hereby declare this contribution to be licensed under the [Apache License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0)
    - [x] I hereby declare that I have filed an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
---
 apache-maven/src/bin/mvn                           | 36 +++++++++++++++++
 .../src/test/scripts/test-mvn-path-conversion.sh   | 45 ++++++++++++++++++++--
 2 files changed, 78 insertions(+), 3 deletions(-)

diff --git a/apache-maven/src/bin/mvn b/apache-maven/src/bin/mvn
index 80d236376b..a7c6f69e9b 100755
--- a/apache-maven/src/bin/mvn
+++ b/apache-maven/src/bin/mvn
@@ -309,6 +309,42 @@ if [ -n "$MAVEN_ARGS" ]; then
   done
 fi
 
+# MNG-8056: Under Cygwin, the JVM is a native Windows process and cannot resolve
+# Cygwin-style POSIX paths (e.g. /cygdrive/c/...) directly.  The internal paths
+# (MAVEN_HOME, CLASSWORLDS_CONF, JAVA_HOME, ...) are already converted above, but
+# user-supplied paths passed via -f/--file, -s/--settings, -gs/--global-settings,
+# -t/--toolchains, -gt/--global-toolchains and -l/--log-file reach the JVM
+# unconverted.
+# The loop below rewrites only those argument values that begin with '/' (absolute
+# POSIX paths); relative paths and already-Windows paths are left unchanged.
+# MinGW/MSYS2 perform automatic path mangling, so the fix is Cygwin-only.
+if $cygwin ; then
+  _np=false
+  _count=$#
+  while [ $_count -gt 0 ]; do
+    _a="$1"
+    shift
+    if $_np; then
+      case "$_a" in
+        /*) _a=`cygpath --windows "$_a"` ;;
+      esac
+      _np=false
+    else
+      case "$_a" in
+        -f|--file|-s|--settings|-gs|--global-settings|-t|--toolchains|-gt|--global-toolchains|-l|--log-file)
+          _np=true ;;
+        --file=/*|--settings=/*|--global-settings=/*|--toolchains=/*|--global-toolchains=/*|--log-file=/*)
+          _flag="${_a%%=*}"
+          _path="${_a#*=}"
+          _a="${_flag}=`cygpath --windows "${_path}"`"
+          ;;
+      esac
+    fi
+    set -- "$@" "$_a"
+    _count=$(( _count - 1 ))
+  done
+fi
+
 if [ -n "$MAVEN_DEBUG_SCRIPT" ]; then
   echo "[DEBUG] Launching JVM with arguments:" >&2
   printf ' "%s"' "$@" >&2; echo >&2
diff --git a/apache-maven/src/test/scripts/test-mvn-path-conversion.sh b/apache-maven/src/test/scripts/test-mvn-path-conversion.sh
index 8a48d17db0..66a86251d8 100644
--- a/apache-maven/src/test/scripts/test-mvn-path-conversion.sh
+++ b/apache-maven/src/test/scripts/test-mvn-path-conversion.sh
@@ -118,7 +118,17 @@ replace() {
 }
 
 case " $* " in
-  *" --windows "*) printf 'C:%s\n' "`replace "$path" '/' '\'`" ;;
+  *" --windows "*)
+    case "$path" in
+      /cygdrive/c/*)
+        path="`replace "$path" '/cygdrive/c/' ''`"
+        printf 'C:\%s\n' "`replace "$path" '/' '\'`"
+        ;;
+      *)
+        printf 'C:%s\n' "`replace "$path" '/' '\'`"
+        ;;
+    esac
+    ;;
   *" --unix "*) printf '%s\n' "`replace "${path#C:}" '\' '/'`" ;;
   *" --path "*)
     # --path with --windows
@@ -208,9 +218,18 @@ failures=0
 
 # run_mvn <uname-output> <stub-dir>
 run_mvn() {
+  run_mvn_with_args "$1" "$2" verify
+}
+
+# run_mvn_with_args <uname-output> <stub-dir> [args...]
+run_mvn_with_args() {
+  uname_out="$1"
+  shift
+  stub_dir_arg="$1"
+  shift
   ( cd "$project_dir/module" &&
-    FAKE_UNAME="$1" PATH="$2" JAVA_HOME= MAVEN_SKIP_RC=1 \
-      "$sh_bin" "$maven_home/bin/mvn" verify 2>/dev/null )
+    FAKE_UNAME="$uname_out" PATH="$stub_dir_arg" JAVA_HOME= MAVEN_SKIP_RC=1 \
+      "$sh_bin" "$maven_home/bin/mvn" "$@" 2>/dev/null )
 }
 
 # to_windows <posix-path>
@@ -292,6 +311,26 @@ for os in CYGWIN_NT-10.0 MINGW32_NT-6.2 MINGW64_NT-10.0 MSYS_NT-10.0; do
   assert_not_contains "$os: no path mixes both separators" "$output" "\\/"
 done
 
+# Cygwin: -f with an absolute POSIX path is converted
+output=`run_mvn_with_args CYGWIN_NT-10.0 "$stub_dir" -f /cygdrive/c/temp/pom.xml validate`
+assert_contains "cygwin: -f /cygdrive path converted" "$output" "[-f][C:\\temp\\pom.xml]"
+
+# Cygwin: -s with an absolute POSIX path is converted
+output=`run_mvn_with_args CYGWIN_NT-10.0 "$stub_dir" -s /cygdrive/c/settings.xml validate`
+assert_contains "cygwin: -s /cygdrive path converted" "$output" "[-s][C:\\settings.xml]"
+
+# Cygwin: --file= with an absolute POSIX path is converted
+output=`run_mvn_with_args CYGWIN_NT-10.0 "$stub_dir" --file=/cygdrive/c/temp/pom.xml validate`
+assert_contains "cygwin: --file= /cygdrive path converted" "$output" "[--file=C:\\temp\\pom.xml]"
+
+# Cygwin: a relative path is left unchanged
+output=`run_mvn_with_args CYGWIN_NT-10.0 "$stub_dir" -f ./relative/pom.xml validate`
+assert_contains "cygwin: relative -f path unchanged" "$output" "[-f][./relative/pom.xml]"
+
+# MinGW/MSYS2: the conversion does not run
+output=`run_mvn_with_args MINGW64_NT-10.0 "$stub_dir" -f /cygdrive/c/temp/pom.xml validate`
+assert_contains "mingw: -f path not converted" "$output" "[-f][/cygdrive/c/temp/pom.xml]"
+
 # Without cygpath the launcher must still work, using unconverted paths, rather
 # than passing empty paths to the JVM.
 output=`run_mvn MINGW64_NT-10.0 "$nocygpath_dir"`