gnodet-bot commented on code in PR #13239:
URL: https://github.com/apache/maven/pull/13239#discussion_r4069176830


##########
apache-maven/src/assembly/maven/bin/mvn:
##########
@@ -462,6 +462,38 @@ 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,
+# -st/--toolchains and -gt/--global-toolchains 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
+  _cygwin_convert_paths() {
+    _out=; _np=false
+    for _a do
+      if $_np; then
+        case "$_a" in
+          /*) _a=$(cygpath --windows "$_a") ;;
+        esac
+        _np=false
+      else
+        case "$_a" in
+          
-f|--file|-s|--settings|-gs|--global-settings|-st|--toolchains|-gt|--global-toolchains)
+            _np=true ;;
+        esac
+      fi
+      # Accumulate single-quoted tokens, escaping any embedded single-quotes
+      _out="${_out}'$(printf '%s' "$_a" | sed "s/'/'\\\\''/g")' "
+    done
+    printf '%s' "$_out"
+  }
+  eval set -- "$(_cygwin_convert_paths "$@")"
+  unset -f _cygwin_convert_paths

Review Comment:
   ⚠️ **No tests for the new conversion logic.**
   
   `apache-maven/src/test/scripts/test-mvn-path-conversion.sh` already has 
exactly the infrastructure needed: `run_mvn()` with a stubbed `cygpath` that 
maps `/cygdrive/c/...` to `C:\...`, and `assert_contains`/`assert_not_contains` 
helpers. The existing `CYGWIN_NT-10.0` loop only checks `MAVEN_HOME`, 
`multiModuleProjectDirectory`, and `jvm.config` — it does not exercise 
`-f`/`-s` user-supplied paths at all.
   
   This PR must add assertions like:
   
   ```sh
   # 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"
   
   # 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"
   ```
   
   The test file would need a `run_mvn_with_args` helper (like `run_mvn` but 
forwarding extra args) and the existing `cygpath` stub would need to handle 
`/cygdrive/c/` → `C:\` translation. Without tests, a future refactor of this 
block would break Cygwin silently.



##########
apache-maven/src/assembly/maven/bin/mvn:
##########
@@ -462,6 +462,38 @@ 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,
+# -st/--toolchains and -gt/--global-toolchains 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
+  _cygwin_convert_paths() {
+    _out=; _np=false
+    for _a do
+      if $_np; then
+        case "$_a" in
+          /*) _a=$(cygpath --windows "$_a") ;;
+        esac
+        _np=false
+      else
+        case "$_a" in

Review Comment:
   ⚠️ **Bug: `--file=<path>` (equals form) is not converted.**
   
   Commons CLI accepts both `--file /cygdrive/c/pom.xml` (space-separated) and 
`--file=/cygdrive/c/pom.xml` (equals-form). The current function only handles 
the two-token form — when the user writes `--file=/cygdrive/c/...` the flag and 
path arrive as a single token, the `case` matches `--file=...` against none of 
the patterns, `_np` stays `false`, and the path reaches the JVM unconverted.
   
   Fix: add a second branch in the `else` block that detects and rewrites the 
equals-form in one shot:
   
   ```suggestion
             
-f|--file|-s|--settings|-gs|--global-settings|-st|--toolchains|-gt|--global-toolchains)
               _np=true ;;
             
--file=/*|--settings=/*|--global-settings=/*|--toolchains=/*|--global-toolchains=/*)
               _flag="${_a%%=*}"
               _path="${_a#*=}"
               _a="${_flag}=$(cygpath --windows "${_path}")"
               ;;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to