arturobernalg opened a new pull request, #13478:
URL: https://github.com/apache/maven/pull/13478
Fixes #13413
### What and why
`bin/mvn` passed `MAVEN_ARGS` to the JVM unquoted, so the shell split it on
every space and the quote characters reached Maven as part of the arguments.
`MAVEN_ARGS='"-Dmaven.repo.local=/path with space/repo"' mvn validate`
therefore failed with "No goals have been specified for this build". The
Jenkins Pipeline Maven plugin passes `--settings` and `-Dmaven.repo.local` this
way, so builds in a workspace with a space in its path fail.
### How
The script now splits the value itself, with built-ins only:
- white space separates the words, and single or double quotes group a word
containing white space;
- adjacent quoted and unquoted parts form one word, and `""` is an empty
word;
- nothing else is interpreted, so backslashes and `${...}` placeholders
reach Maven as written, which is what the existing comment on this code asks
for (#12348);
- the words go in front of the user arguments, which are kept untouched, and
`MAVEN_ARGS` is still skipped for `--up`, `--enc`, `--shell` and `--val`
(#12465);
- an unterminated quote prints a warning and takes the end of the value as
is.
One side effect: a pattern like `*` in `MAVEN_ARGS` is no longer expanded by
the shell. The debug log now prints the words one by one instead of the raw
variable.
### Tests
`apache-maven/src/test/scripts/test-mvn-args.sh` is new and runs in the
`shell-script-tests` profile like the other launcher tests, with the same
stubbed `java`. It covers the case of the issue, single and double quotes,
mixed and empty words, tabs and new lines, ordering against the user arguments,
no globbing, backslashes, placeholders and `$(...)`, the unterminated quote,
the sub-commands and the debug log. 12 of its 24 assertions fail on the
previous script.
I also ran it with `bash --posix` and `zsh` in `sh` and `ksh` mode, and
checked with a built distribution that Maven uses `-Dmaven.repo.local` and
`--settings` paths containing a space. `test-mvn-path-conversion.sh` and
`test-mvn-fast-version.sh` still pass. I did not run it with dash.
`mvn.cmd` is not touched and I could not run it on Windows. The issue also
reports 3.9.16 and 3.10.0, this PR targets master only. A backport to
maven-4.0.x is welcome, and I can open one for the 3.x branches after agreement.
---
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:
- [ ] 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)
- [ ] I hereby declare that I have filed an [Apache Individual Contributor
License Agreement](https://www.apache.org/licenses/icla.pdf).
--
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]