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 2026/09/23 05:53:43 UTC

(maven) branch master updated: [MNG-8056] Fix -f/-s parameters failing with absolute Cygwin paths

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.git


The following commit(s) were added to refs/heads/master by this push:
     new acd29dabd7 [MNG-8056] Fix -f/-s parameters failing with absolute Cygwin paths
acd29dabd7 is described below

commit acd29dabd7e16fb8db27803dec227b6754d0fb0f
Author: -TARUN N <tn...@gmail.com>
AuthorDate: Wed Sep 23 11:23:37 2026 +0530

    [MNG-8056] Fix -f/-s parameters failing with absolute Cygwin paths
    
    - Added _cygwin_convert_paths() helper in bin/mvn that converts absolute POSIX paths to Windows form via cygpath --windows for -f/--file, -s/--settings, -gs/--global-settings, -t/--toolchains, -gt/--global-toolchains, -st/--install-toolchains, -ps/--project-settings, -is/--install-settings, -it/--install-toolchains, -l/--log-file, and -af/--at-file flags (both space-separated and equals forms)
    - MinGW/MSYS2 excluded (their POSIX emulation layer already handles path translation)
    - Relative paths and already-native Windows paths are left unchanged
    - Added test coverage in test-mvn-path-conversion.sh for all converted flags
    
    Fixes MNG-8056
---
 apache-maven/src/assembly/maven/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/assembly/maven/bin/mvn b/apache-maven/src/assembly/maven/bin/mvn
index 96046c701e..fe04dacb0b 100755
--- a/apache-maven/src/assembly/maven/bin/mvn
+++ b/apache-maven/src/assembly/maven/bin/mvn
@@ -462,6 +462,42 @@ if $cygwin || $mingw ; then
 fi
 MAVEN_PROJECTBASEDIR="$MAVEN_PROJECTBASEDIR_NATIVE"
 
+# 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,
+# -ps/--project-settings, -is/--install-settings, -it/--install-toolchains,
+# -l/--log-file, and -af/--at-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|-ps|--project-settings|-is|--install-settings|-it|--install-toolchains|-l|--log-file|-af|--at-file)
+          _np=true ;;
+        --file=/*|--settings=/*|--global-settings=/*|--toolchains=/*|--global-toolchains=/*|--project-settings=/*|--install-settings=/*|--install-toolchains=/*|--log-file=/*|--at-file=/*)
+          _flag="${_a%%=*}"
+          _path="${_a#*=}"
+          _a="${_flag}=$(cygpath --windows "${_path}")"
+          ;;
+      esac
+    fi
+    set -- "$@" "$_a"
+    _count=$(( _count - 1 ))
+  done
+fi
+
 handle_args() {
   while [ $# -gt 0 ]; do
     case $1 in
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 51d520cc90..35ffdf252f 100644
--- a/apache-maven/src/test/scripts/test-mvn-path-conversion.sh
+++ b/apache-maven/src/test/scripts/test-mvn-path-conversion.sh
@@ -107,7 +107,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:}" '\' '/'`" ;;
   *) printf '%s\n' "$path" ;;
 esac
@@ -176,9 +186,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="$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" JAVA_HOME= MAVEN_SKIP_RC=1 \
+      "$sh_bin" "$maven_home/bin/mvn" "$@" 2>/dev/null )
 }
 
 # run_mvn_debug <uname-output> <stub-dir>
@@ -262,6 +281,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 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 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 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: 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: conversion does NOT run (cygwin=false)
+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"`