Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions apache-maven/src/assembly/maven/bin/mvn
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,26 @@ if $cygwin || $mingw ; then
fi
fi

# A cygpath(1) from an unrelated POSIX emulation layer (e.g. the one shipped in
# an Anaconda installation) can be found on the PATH first. It re-roots every
# POSIX path under its own installation prefix, so all converted values point to
# non-existing directories and the JVM dies with a bare ClassNotFoundException.
# cygpath can convert relative paths too, but the current directory is the only
# path that is known to exist at this point: verify that its Windows form can be
# found on disk before trusting any of the later conversions.
if $cygwin || $mingw ; then
_cygpath_bin=`( \unset -f command; \command -v cygpath )` || _cygpath_bin=
_probe_win=`cygpath --windows "$PWD"` || _probe_win=
Comment thread
gnodet marked this conversation as resolved.
Resolved
if [ -z "$_probe_win" ] || [ ! -d "$_probe_win" ] ; then
printf '%s\n' "Warning: the cygpath found on the PATH (\"$_cygpath_bin\") does not convert paths to" >&2
printf '%s\n' "usable Windows paths (\"$PWD\" converts to \"$_probe_win\", which does not exist)," >&2
printf '%s\n' "so Apache Maven cannot convert paths to the Windows format." >&2
printf '%s\n' "Some plugins may misbehave when they receive POSIX paths." >&2
cygwin=false
mingw=false
fi
fi

## resolve links - $0 may be a link to Maven's home
PRG="$0"

Expand Down
78 changes: 78 additions & 0 deletions apache-maven/src/test/scripts/test-mvn-path-conversion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,53 @@ for stub in uname dirname java; do
chmod +x "$nocygpath_dir/$stub"
done

# A third stub set whose cygpath re-roots every POSIX path under its own
# installation prefix, like the cygpath shipped inside an Anaconda installation
# does (issue #13414). The launcher must detect that the Windows form does not
# exist on disk, warn, and fall back to unconverted POSIX paths.
lying_dir="$work_dir/stubs-lying-cygpath"
mkdir -p "$lying_dir"
for stub in uname dirname java; do
cp "$stub_dir/$stub" "$lying_dir/$stub"
chmod +x "$lying_dir/$stub"
done

cat > "$lying_dir/cygpath" <<'LYING'
#!/bin/sh
# cygpath(1) stub re-rooting every POSIX path under its own prefix, like the
# Anaconda-shipped cygpath that caused issue #13414.
for arg in "$@"; do
case "$arg" in
--*) ;;
*) path="$arg" ;;
esac
done

replace() {
text="$1"; needle="$2"; value="$3"; out=""
while :; do
case "$text" in
*"$needle"*)
out="$out${text%%"$needle"*}$value"
text="${text#*"$needle"}"
;;
*) break ;;
esac
done
printf '%s' "$out$text"
}

case " $* " in
*" --windows "*)
printf 'C:\Anaconda\Library\%s\n' "`replace "$path" '/' '\'`"
;;
*)
printf '%s\n' "$path"
;;
esac
LYING
chmod +x "$lying_dir/cygpath"

# A jvm.config referencing the project base directory, to assert that the value
# handed over to the JVM configuration is converted as well.
echo '-Xmx512m -Dtest.basedir=${MAVEN_PROJECTBASEDIR}' > "$project_dir/.mvn/jvm.config"
Expand Down Expand Up @@ -223,6 +270,16 @@ to_windows() {
printf 'C:%s' "$out$text"
}

# bin/mvn verifies that the Windows form of the current directory exists on
# disk before trusting the cygpath output. The stubbed cygpath produces
# C:-prefixed paths, which exist on Windows only. POSIX filesystems accept
# them literally (backslashes and colons are ordinary characters), so create
# the directory here to let the verification pass with the stub as well. On
# Windows creating it fails because the real directory exists: fine.
# mkdir -p: on Windows the argument is a real multi-component path whose
# parents may not exist yet; on POSIX it is a single oddly-named directory.
( cd "$project_dir/module" && mkdir -p "`to_windows "$project_dir/module"`" 2>/dev/null || true )

# contains <haystack> <needle>
# Plain substring check. A case/glob comparison cannot be used, the haystack
# holds Windows paths and backslashes are escape characters in glob patterns.
Expand Down Expand Up @@ -311,6 +368,27 @@ assert_contains "missing cygpath: maven.home falls back to a POSIX path" "$outpu
assert_not_contains "missing cygpath: no empty maven.home is passed" "$output" \
"[-Dmaven.home=]"

# A cygpath from a foreign emulation layer must be detected: the conversion is
# skipped, the paths stay in their POSIX form, and warnings explain why.
output=`run_mvn MINGW64_NT-10.0 "$lying_dir"`
assert_contains "foreign cygpath: multiModuleProjectDirectory falls back to a POSIX path" "$output" \
"[-Dmaven.multiModuleProjectDirectory=$project_dir]"
assert_contains "foreign cygpath: maven.home falls back to a POSIX path" "$output" \
"[-Dmaven.home=$maven_home]"
assert_not_contains "foreign cygpath: no empty maven.home is passed" "$output" \
"[-Dmaven.home=]"

# ... and the warnings name the offending cygpath and the bogus conversion.
warn_output=`( cd "$project_dir/module" &&
FAKE_UNAME="MINGW64_NT-10.0" PATH="$lying_dir" JAVA_HOME= MAVEN_SKIP_RC=1 \
"$sh_bin" "$maven_home/bin/mvn" verify 2>&1 )`
assert_contains "foreign cygpath: warning names the offending cygpath" "$warn_output" \
"does not convert paths to"
assert_contains "foreign cygpath: warning shows the bogus Windows form" "$warn_output" \
"which does not exist"
assert_contains "foreign cygpath: warning names the discovered cygpath" "$warn_output" \
"stubs-lying-cygpath/cygpath"

# The debug log must reproduce the Windows paths verbatim. echo expands
# backslash escapes in dash and friends, turning C:\tmp into C:<tab>mp.
debug_output=`run_mvn_debug MSYS_NT-10.0 "$stub_dir"`
Expand Down
Loading