Skip to content

Commit

Permalink
[MWRAPPER-139] Remove trailing whitespace from fields in maven-wrappe…
Browse files Browse the repository at this point in the history
…r.properties (#139)

This prevents issues due to confusion between CRLF and LF when
running in more exotic locations such as MINGW on Windows but
using ./mvnw rather than ./mvnw.cmd. A prime example of where
this is an issue would be on windows-latest GitHub Actions
runners.

Fixes MWRAPPER-139, MWRAPPER-137.

---

https://issues.apache.org/jira/browse/MWRAPPER-139
https://issues.apache.org/jira/browse/MWRAPPER-137
https://issues.apache.org/jira/browse/MWRAPPER-136
  • Loading branch information
ascopes authored May 21, 2024
1 parent 038d300 commit 1149c75
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions maven-wrapper-distribution/src/resources/only-mvnw
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,19 @@ die() {
exit 1
}

trim() {
# MWRAPPER-139:
# Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds.
# Needed for removing poorly interpreted newline sequences when running in more
# exotic environments such as mingw bash on Windows.
printf "%s" "${1}" | tr -d '[:space:]'
}

# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties
while IFS="=" read -r key value; do
case "${key-}" in
distributionUrl) distributionUrl="${value-}" ;;
distributionSha256Sum) distributionSha256Sum="${value-}" ;;
distributionUrl) distributionUrl=$(trim "${value-}") ;;
distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;;
esac
done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties"
[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties"
Expand Down

0 comments on commit 1149c75

Please sign in to comment.