Skip to content

[MNG-8056] Fix -f/-s parameters failing with absolute Cygwin paths - #13239

Merged
gnodet merged 1 commit into
apache:masterfrom
Tarun4201:fix/MNG-8056-cygwin-absolute-paths
Sep 23, 2026
Merged

gnodet merged 1 commit into
apache:masterfrom
Tarun4201:fix/MNG-8056-cygwin-absolute-paths

Conversation

@Tarun4201

Copy link
Copy Markdown
Contributor

Summary

Fixes MNG-8056 / closes #10810.

When Maven is invoked from Cygwin on Windows with an absolute POSIX path:

mvn -f /cygdrive/c/temp/parametertest/pom.xml validate
mvn -s /cygdrive/c/temp/parametertest/.m2/settings.xml validate

the JVM (a native Windows process) receives the Cygwin path verbatim. Because it does not understand the Cygwin virtual filesystem, it prepends C:\ to the path, producing C:\cygdrive\c\temp\... which does not exist — causing the build to fail with:

[FATAL] Non-readable POM C:\cygdrive\c\temp\parametertest\pom.xml
[ERROR] The specified user settings file does not exist: C:\cygdrive\c\temp\...

Root Cause

The bin/mvn shell script already converts internal paths (MAVEN_HOME, JAVA_HOME, CLASSWORLDS_CONF, etc.) for Cygwin/MinGW using cygpath, but user-supplied path arguments ($@) passed via -f/--file, -s/--settings, -gs/--global-settings, -st/--toolchains, and -gt/--global-toolchains were passed through to the JVM unconverted.

Fix

Added a Cygwin-only post-processing step in apache-maven/src/assembly/maven/bin/mvn that:

  1. Defines a helper function _cygwin_convert_paths() which iterates over positional parameters.
  2. When it detects a path-accepting flag, it converts the next argument to Windows form via cygpath --windows — but only if it starts with / (i.e., it is an absolute POSIX path).
  3. Relative paths (./relative/pom.xml) and already-native Windows paths are left unchanged.
  4. MinGW/MSYS2 are excluded because their POSIX emulation layer already mangles paths automatically.

Verification

Tested scenarios (on Cygwin 3.5.x, Maven 3.9.6, Windows 10/11):

Command Before After
mvn -f /cygdrive/c/temp/pom.xml validate ❌ FATAL: Non-readable POM ✅ BUILD SUCCESS
mvn -s /cygdrive/c/temp/.m2/settings.xml validate ❌ settings file does not exist ✅ BUILD SUCCESS
mvn -f ./relative/pom.xml validate ✅ works ✅ still works
mvn -f pom.xml validate (no flag) ✅ works ✅ still works

Related

  • MNG-5812 — Project base dir not fully working in Cygwin
  • MNG-7621 — Parameter -f causes ignoring any maven.config (only on Windows)

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two issues before this can merge: missing tests (the existing test harness in test-mvn-path-conversion.sh is a perfect fit), and the --file=<path> equals-form is not handled and will still fail on Cygwin.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Comment thread apache-maven/src/assembly/maven/bin/mvn Outdated
Comment thread apache-maven/src/assembly/maven/bin/mvn Outdated

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review after the latest commits. Both previously-requested changes are now addressed:

  • ✅ --file=<path> (equals form) is handled — the --file=/* branch correctly extracts the flag and path, converts the path, and reassembles the argument.
  • ✅ Tests added — five new assertions in test-mvn-path-conversion.sh covering -f, -s, --file=, relative paths (unchanged), and MinGW non-conversion.

Two remaining issues worth addressing before merge.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Comment thread apache-maven/src/assembly/maven/bin/mvn Outdated
Comment thread apache-maven/src/test/scripts/test-mvn-path-conversion.sh Outdated
Comment thread apache-maven/src/assembly/maven/bin/mvn Outdated
@Tarun4201

Copy link
Copy Markdown
Contributor Author

Thanks for the review and for catching those edge cases! I've just pushed a new commit to address the tokenization issue and the equals-form argument handling.

Here are the key changes made in the latest commit:

  1. Robust Argument Tokenization:
    I replaced the eval set -- and sed escaping logic with a clean, POSIX-compliant while loop that iterates over the arguments using shift and set -- "$@" "$_a". This safely modifies the arguments in-place without breaking any quotes, spaces, or native token boundaries. This inherently fixes the issue where arguments were getting mangled or lost in restricted test environments.

  2. Equals-form Argument Support (--file=):
    The script now explicitly intercepts and converts paths passed in the equals-form format (e.g. --file=/cygdrive/c/path, --settings=, --global-settings=, --toolchains=, --global-toolchains=). It splits the flag from the path, converts the path using cygpath, and dynamically reassembles them before passing to the JVM.

  3. Added Comprehensive Testing:
    I expanded test-mvn-path-conversion.sh to include assertions specifically validating -s, -f, and --file= formats, ensuring that the argument array preserves spaces correctly and that native environments (like MinGW) are bypassed accurately as expected.

All path conversion tests now pass successfully. Let me know if everything looks good or if there are any other scenarios you'd like me to cover!

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review after latest commits. Both previously-requested changes are addressed:

  • ✅ Tests added — 5 cases covering -f, -s, --file=, relative path passthrough, and MinGW non-conversion (all pass locally).
  • ✅ --file=<path> equals-form now handled via the dedicated case branch.

Two remaining nits before merge:

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Comment thread apache-maven/src/assembly/maven/bin/mvn Outdated
Comment thread apache-maven/src/test/scripts/test-mvn-path-conversion.sh Outdated
@Tarun4201

Copy link
Copy Markdown
Contributor Author

Both nitpicks have been addressed in the latest commit:

  1. Spurious blank line: Removed the extra blank line before handle_args() in bin/mvn to match the file's style conventions.
  2. Test output noise: Re-added 2>/dev/null to run_mvn_with_args in test-mvn-path-conversion.sh to properly suppress the intentional missing POM warnings during tests.

Let me know if there's anything else needed!

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review after the latest commits. Previously-raised nits are addressed:

  • ✅ Spurious blank line between MNG-8056 fi and handle_args() — now one blank line, matches surrounding style.
  • ✅ 2>/dev/null restored in run_mvn_with_args — stderr suppressed as intended.

Three issues remain.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Comment thread apache-maven/src/assembly/maven/bin/mvn Outdated
Comment thread apache-maven/src/assembly/maven/bin/mvn Outdated
Comment thread apache-maven/src/assembly/maven/bin/mvn Outdated
@Tarun4201

Copy link
Copy Markdown
Contributor Author

Thank you for catching those missing flags!

I have pushed a new commit to resolve the missing flags:

  1. Fixed the incorrect -st flag by changing it to -t (--toolchains) in the space-separated arguments list.
  2. Added the remaining path-accepting flags: -ps (--project-settings), -is (--install-settings), -it (--install-toolchains), and -l (--log-file) to both the space-separated check and the equals-form check (--project-settings=/*, etc.).
  3. Removed the trailing # End of file comment to match the project's styling.

All paths should now be converted correctly for Cygwin users across all of these flags. Let me know if everything looks good!

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review after the latest commit. All three previously-raised issues are addressed:

  • ✅ -st → -t corrected (toolchains).
  • ✅ Equals-form branch complete: --project-settings=/*, --install-settings=/*, --install-toolchains=/*, --log-file=/* added.
  • ✅ # End of file comment removed.

One remaining gap before this can merge.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Comment thread apache-maven/src/assembly/maven/bin/mvn Outdated
Comment thread apache-maven/src/assembly/maven/bin/mvn Outdated
@Tarun4201

Copy link
Copy Markdown
Contributor Author

Good catch on the -af/--at-file flag!

I have just pushed another commit to address this oversight:

  • Added -af|--at-file to the space-separated match case.
  • Added --at-file=/* to the equals-form match case.

The path conversion now safely covers the --at-file flag as well. Thanks again!

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review after the latest commit. The previously-raised gap is addressed:

  • ✅ -af/--at-file added to both the space-separated branch and the equals-form branch.

One remaining nit before merge.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Comment thread apache-maven/src/assembly/maven/bin/mvn Outdated
@Tarun4201

Copy link
Copy Markdown
Contributor Author

Good point about the stale comment! I've updated the comment in bin/mvn so that it accurately documents the full set of flags that we are now converting for Cygwin users. Thanks for the review!

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review after the latest commit. The previously-raised nit is addressed:

  • ✅ Stale comment updated — lines 468-470 in bin/mvn now accurately document all 10 flags handled by the MNG-8056 block: -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.

The implementation is correct and complete. The argument rewriting loop is POSIX-compliant, handles both space-separated and equals-form arguments, correctly skips relative paths and non-Cygwin environments, and is backed by 5 targeted test cases. Ready to merge.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@gnodet gnodet added bug Something isn't working backport-to-4.0.x labels Sep 22, 2026
@gnodet gnodet added this to the 4.1.0 milestone Sep 22, 2026
- 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
@gnodet
gnodet force-pushed the fix/MNG-8056-cygwin-absolute-paths branch from e25e0ba to ebf0397 Compare September 23, 2026 05:53
@gnodet
gnodet merged commit acd29da into apache:master Sep 23, 2026
@Tarun4201
Tarun4201 deleted the fix/MNG-8056-cygwin-absolute-paths branch September 23, 2026 05:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-to-4.0.x bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants