Skip to content

Commit 34d65ff

Browse files
authoredApr 22, 2024··
Upgrade maven wrapper (#972)
1 parent 0028516 commit 34d65ff

File tree

5 files changed

+334
-396
lines changed

5 files changed

+334
-396
lines changed
 

‎.mvn/wrapper/maven-wrapper.properties

+17-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1-
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip

‎README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ All the jars and releases are available from Maven Central, so you'll find every
140140

141141
## Requirements
142142

143-
* Maven 3.5.4+
143+
* Maven 3.9.6+
144144
* Java 8+ at runtime
145-
* Java 21+ at build time
145+
* Java 22+ at build time
146146
* Graal 23.1+ (native-image)
147147

148148
Check out and build:

‎mvnw

+193-256
Original file line numberDiff line numberDiff line change
@@ -19,295 +19,232 @@
1919
# ----------------------------------------------------------------------------
2020

2121
# ----------------------------------------------------------------------------
22-
# Maven2 Start Up Batch script
23-
#
24-
# Required ENV vars:
25-
# ------------------
26-
# JAVA_HOME - location of a JDK home dir
22+
# Apache Maven Wrapper startup batch script, version 3.3.0
2723
#
2824
# Optional ENV vars
2925
# -----------------
30-
# M2_HOME - location of maven2's installed home dir
31-
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
32-
# e.g. to debug Maven itself, use
33-
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34-
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
26+
# JAVA_HOME - location of a JDK home dir, required when download maven via java source
27+
# MVNW_REPOURL - repo url base for downloading maven distribution
28+
# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
29+
# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output
3530
# ----------------------------------------------------------------------------
3631

37-
if [ -z "$MAVEN_SKIP_RC" ] ; then
38-
39-
if [ -f /etc/mavenrc ] ; then
40-
. /etc/mavenrc
41-
fi
42-
43-
if [ -f "$HOME/.mavenrc" ] ; then
44-
. "$HOME/.mavenrc"
45-
fi
32+
set -euf
33+
[ "${MVNW_VERBOSE-}" != debug ] || set -x
4634

47-
fi
48-
49-
# OS specific support. $var _must_ be set to either true or false.
50-
cygwin=false;
51-
darwin=false;
52-
mingw=false
53-
case "`uname`" in
54-
CYGWIN*) cygwin=true ;;
55-
MINGW*) mingw=true;;
56-
Darwin*) darwin=true
57-
#
58-
# Look for the Apple JDKs first to preserve the existing behaviour, and then look
59-
# for the new JDKs provided by Oracle.
60-
#
61-
if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then
62-
#
63-
# Apple JDKs
64-
#
65-
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
66-
fi
67-
68-
if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then
69-
#
70-
# Apple JDKs
71-
#
72-
export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
73-
fi
74-
75-
if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then
76-
#
77-
# Oracle JDKs
78-
#
79-
export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
80-
fi
81-
82-
if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then
83-
#
84-
# Apple JDKs
85-
#
86-
export JAVA_HOME=`/usr/libexec/java_home`
87-
fi
88-
;;
35+
# OS specific support.
36+
native_path() { printf %s\\n "$1"; }
37+
case "$(uname)" in
38+
CYGWIN* | MINGW*)
39+
[ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")"
40+
native_path() { cygpath --path --windows "$1"; }
41+
;;
8942
esac
9043

91-
if [ -z "$JAVA_HOME" ] ; then
92-
if [ -r /etc/gentoo-release ] ; then
93-
JAVA_HOME=`java-config --jre-home`
94-
fi
95-
fi
96-
97-
if [ -z "$M2_HOME" ] ; then
98-
## resolve links - $0 may be a link to maven's home
99-
PRG="$0"
100-
101-
# need this for relative symlinks
102-
while [ -h "$PRG" ] ; do
103-
ls=`ls -ld "$PRG"`
104-
link=`expr "$ls" : '.*-> \(.*\)$'`
105-
if expr "$link" : '/.*' > /dev/null; then
106-
PRG="$link"
44+
# set JAVACMD and JAVACCMD
45+
set_java_home() {
46+
# For Cygwin and MinGW, ensure paths are in Unix format before anything is touched
47+
if [ -n "${JAVA_HOME-}" ]; then
48+
if [ -x "$JAVA_HOME/jre/sh/java" ]; then
49+
# IBM's JDK on AIX uses strange locations for the executables
50+
JAVACMD="$JAVA_HOME/jre/sh/java"
51+
JAVACCMD="$JAVA_HOME/jre/sh/javac"
10752
else
108-
PRG="`dirname "$PRG"`/$link"
53+
JAVACMD="$JAVA_HOME/bin/java"
54+
JAVACCMD="$JAVA_HOME/bin/javac"
55+
56+
if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then
57+
echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2
58+
echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2
59+
return 1
60+
fi
10961
fi
62+
else
63+
JAVACMD="$(
64+
'set' +e
65+
'unset' -f command 2>/dev/null
66+
'command' -v java
67+
)" || :
68+
JAVACCMD="$(
69+
'set' +e
70+
'unset' -f command 2>/dev/null
71+
'command' -v javac
72+
)" || :
73+
74+
if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then
75+
echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2
76+
return 1
77+
fi
78+
fi
79+
}
80+
81+
# hash string like Java String::hashCode
82+
hash_string() {
83+
str="${1:-}" h=0
84+
while [ -n "$str" ]; do
85+
char="${str%"${str#?}"}"
86+
h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296))
87+
str="${str#?}"
11088
done
89+
printf %x\\n $h
90+
}
11191

112-
saveddir=`pwd`
92+
verbose() { :; }
93+
[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; }
11394

114-
M2_HOME=`dirname "$PRG"`/..
95+
die() {
96+
printf %s\\n "$1" >&2
97+
exit 1
98+
}
11599

116-
# make it fully qualified
117-
M2_HOME=`cd "$M2_HOME" && pwd`
100+
# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties
101+
while IFS="=" read -r key value; do
102+
case "${key-}" in
103+
distributionUrl) distributionUrl="${value-}" ;;
104+
distributionSha256Sum) distributionSha256Sum="${value-}" ;;
105+
esac
106+
done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties"
107+
[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties"
108+
109+
case "${distributionUrl##*/}" in
110+
maven-mvnd-*bin.*)
111+
MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/
112+
case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in
113+
*AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;;
114+
:Darwin*x86_64) distributionPlatform=darwin-amd64 ;;
115+
:Darwin*arm64) distributionPlatform=darwin-aarch64 ;;
116+
:Linux*x86_64*) distributionPlatform=linux-amd64 ;;
117+
*)
118+
echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2
119+
distributionPlatform=linux-amd64
120+
;;
121+
esac
122+
distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip"
123+
;;
124+
maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;;
125+
*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;;
126+
esac
118127

119-
cd "$saveddir"
120-
# echo Using m2 at $M2_HOME
121-
fi
128+
# apply MVNW_REPOURL and calculate MAVEN_HOME
129+
# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-<version>,maven-mvnd-<version>-<platform>}/<hash>
130+
[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}"
131+
distributionUrlName="${distributionUrl##*/}"
132+
distributionUrlNameMain="${distributionUrlName%.*}"
133+
distributionUrlNameMain="${distributionUrlNameMain%-bin}"
134+
MAVEN_HOME="$HOME/.m2/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")"
135+
136+
exec_maven() {
137+
unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || :
138+
exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD"
139+
}
122140

123-
# For Cygwin, ensure paths are in UNIX format before anything is touched
124-
if $cygwin ; then
125-
[ -n "$M2_HOME" ] &&
126-
M2_HOME=`cygpath --unix "$M2_HOME"`
127-
[ -n "$JAVA_HOME" ] &&
128-
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
129-
[ -n "$CLASSPATH" ] &&
130-
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
141+
if [ -d "$MAVEN_HOME" ]; then
142+
verbose "found existing MAVEN_HOME at $MAVEN_HOME"
143+
exec_maven "$@"
131144
fi
132145

133-
# For Migwn, ensure paths are in UNIX format before anything is touched
134-
if $mingw ; then
135-
[ -n "$M2_HOME" ] &&
136-
M2_HOME="`(cd "$M2_HOME"; pwd)`"
137-
[ -n "$JAVA_HOME" ] &&
138-
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
139-
fi
146+
case "${distributionUrl-}" in
147+
*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;;
148+
*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;;
149+
esac
140150

141-
if [ -z "$JAVA_HOME" ]; then
142-
javaExecutable="`which javac`"
143-
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
144-
# readlink(1) is not available as standard on Solaris 10.
145-
readLink=`which readlink`
146-
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
147-
if $darwin ; then
148-
javaHome="`dirname \"$javaExecutable\"`"
149-
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
150-
else
151-
javaExecutable="`readlink -f \"$javaExecutable\"`"
152-
fi
153-
javaHome="`dirname \"$javaExecutable\"`"
154-
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
155-
JAVA_HOME="$javaHome"
156-
export JAVA_HOME
157-
fi
158-
fi
151+
# prepare tmp dir
152+
if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then
153+
clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; }
154+
trap clean HUP INT TERM EXIT
155+
else
156+
die "cannot create temp dir"
159157
fi
160158

161-
if [ -z "$JAVACMD" ] ; then
162-
if [ -n "$JAVA_HOME" ] ; then
163-
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
164-
# IBM's JDK on AIX uses strange locations for the executables
165-
JAVACMD="$JAVA_HOME/jre/sh/java"
166-
else
167-
JAVACMD="$JAVA_HOME/bin/java"
168-
fi
169-
else
170-
JAVACMD="`which java`"
171-
fi
172-
fi
159+
mkdir -p -- "${MAVEN_HOME%/*}"
173160

174-
if [ ! -x "$JAVACMD" ] ; then
175-
echo "Error: JAVA_HOME is not defined correctly." >&2
176-
echo " We cannot execute $JAVACMD" >&2
177-
exit 1
178-
fi
161+
# Download and Install Apache Maven
162+
verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
163+
verbose "Downloading from: $distributionUrl"
164+
verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
179165

180-
if [ -z "$JAVA_HOME" ] ; then
181-
echo "Warning: JAVA_HOME environment variable is not set."
166+
# select .zip or .tar.gz
167+
if ! command -v unzip >/dev/null; then
168+
distributionUrl="${distributionUrl%.zip}.tar.gz"
169+
distributionUrlName="${distributionUrl##*/}"
182170
fi
183171

184-
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
172+
# verbose opt
173+
__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR=''
174+
[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v
185175

186-
# traverses directory structure from process work directory to filesystem root
187-
# first directory with .mvn subdirectory is considered project base directory
188-
find_maven_basedir() {
176+
# normalize http auth
177+
case "${MVNW_PASSWORD:+has-password}" in
178+
'') MVNW_USERNAME='' MVNW_PASSWORD='' ;;
179+
has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;;
180+
esac
189181

190-
if [ -z "$1" ]
191-
then
192-
echo "Path not specified to find_maven_basedir"
193-
return 1
194-
fi
182+
if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then
183+
verbose "Found wget ... using wget"
184+
wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl"
185+
elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then
186+
verbose "Found curl ... using curl"
187+
curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl"
188+
elif set_java_home; then
189+
verbose "Falling back to use Java to download"
190+
javaSource="$TMP_DOWNLOAD_DIR/Downloader.java"
191+
targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName"
192+
cat >"$javaSource" <<-END
193+
public class Downloader extends java.net.Authenticator
194+
{
195+
protected java.net.PasswordAuthentication getPasswordAuthentication()
196+
{
197+
return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() );
198+
}
199+
public static void main( String[] args ) throws Exception
200+
{
201+
setDefault( new Downloader() );
202+
java.nio.file.Files.copy( new java.net.URL( args[0] ).openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() );
203+
}
204+
}
205+
END
206+
# For Cygwin/MinGW, switch paths to Windows format before running javac and java
207+
verbose " - Compiling Downloader.java ..."
208+
"$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java"
209+
verbose " - Running Downloader.java ..."
210+
"$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")"
211+
fi
195212

196-
basedir="$1"
197-
wdir="$1"
198-
while [ "$wdir" != '/' ] ; do
199-
if [ -d "$wdir"/.mvn ] ; then
200-
basedir=$wdir
201-
break
213+
# If specified, validate the SHA-256 sum of the Maven distribution zip file
214+
if [ -n "${distributionSha256Sum-}" ]; then
215+
distributionSha256Result=false
216+
if [ "$MVN_CMD" = mvnd.sh ]; then
217+
echo "Checksum validation is not supported for maven-mvnd." >&2
218+
echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
219+
exit 1
220+
elif command -v sha256sum >/dev/null; then
221+
if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then
222+
distributionSha256Result=true
202223
fi
203-
# workaround for JBEAP-8937 (on Solaris 10/Sparc)
204-
if [ -d "${wdir}" ]; then
205-
wdir=`cd "$wdir/.."; pwd`
224+
elif command -v shasum >/dev/null; then
225+
if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then
226+
distributionSha256Result=true
206227
fi
207-
# end of workaround
208-
done
209-
echo "${basedir}"
210-
}
211-
212-
# concatenates all lines of a file
213-
concat_lines() {
214-
if [ -f "$1" ]; then
215-
echo "$(tr -s '\n' ' ' < "$1")"
228+
else
229+
echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2
230+
echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
231+
exit 1
232+
fi
233+
if [ $distributionSha256Result = false ]; then
234+
echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2
235+
echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2
236+
exit 1
216237
fi
217-
}
218-
219-
BASE_DIR=`find_maven_basedir "$(pwd)"`
220-
if [ -z "$BASE_DIR" ]; then
221-
exit 1;
222238
fi
223239

224-
##########################################################################################
225-
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
226-
# This allows using the maven wrapper in projects that prohibit checking in binary data.
227-
##########################################################################################
228-
if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
229-
if [ "$MVNW_VERBOSE" = true ]; then
230-
echo "Found .mvn/wrapper/maven-wrapper.jar"
231-
fi
240+
# unzip and move
241+
if command -v unzip >/dev/null; then
242+
unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip"
232243
else
233-
if [ "$MVNW_VERBOSE" = true ]; then
234-
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
235-
fi
236-
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
237-
while IFS="=" read key value; do
238-
case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
239-
esac
240-
done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
241-
if [ "$MVNW_VERBOSE" = true ]; then
242-
echo "Downloading from: $jarUrl"
243-
fi
244-
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
245-
246-
if command -v wget > /dev/null; then
247-
if [ "$MVNW_VERBOSE" = true ]; then
248-
echo "Found wget ... using wget"
249-
fi
250-
wget "$jarUrl" -O "$wrapperJarPath"
251-
elif command -v curl > /dev/null; then
252-
if [ "$MVNW_VERBOSE" = true ]; then
253-
echo "Found curl ... using curl"
254-
fi
255-
curl -o "$wrapperJarPath" "$jarUrl"
256-
else
257-
if [ "$MVNW_VERBOSE" = true ]; then
258-
echo "Falling back to using Java to download"
259-
fi
260-
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
261-
if [ -e "$javaClass" ]; then
262-
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
263-
if [ "$MVNW_VERBOSE" = true ]; then
264-
echo " - Compiling MavenWrapperDownloader.java ..."
265-
fi
266-
# Compiling the Java class
267-
("$JAVA_HOME/bin/javac" "$javaClass")
268-
fi
269-
if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
270-
# Running the downloader
271-
if [ "$MVNW_VERBOSE" = true ]; then
272-
echo " - Running MavenWrapperDownloader.java ..."
273-
fi
274-
("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
275-
fi
276-
fi
277-
fi
278-
fi
279-
##########################################################################################
280-
# End of extension
281-
##########################################################################################
282-
283-
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
284-
if [ "$MVNW_VERBOSE" = true ]; then
285-
echo $MAVEN_PROJECTBASEDIR
286-
fi
287-
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
288-
289-
# For Cygwin, switch paths to Windows format before running java
290-
if $cygwin; then
291-
[ -n "$M2_HOME" ] &&
292-
M2_HOME=`cygpath --path --windows "$M2_HOME"`
293-
[ -n "$JAVA_HOME" ] &&
294-
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
295-
[ -n "$CLASSPATH" ] &&
296-
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
297-
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
298-
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
244+
tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar"
299245
fi
246+
printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url"
247+
mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME"
300248

301-
# Provide a "standardized" way to retrieve the CLI args that will
302-
# work with both Windows and non-Windows executions.
303-
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
304-
export MAVEN_CMD_LINE_ARGS
305-
306-
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
307-
308-
exec "$JAVACMD" \
309-
$MAVEN_OPTS \
310-
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
311-
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
312-
${WRAPPER_LAUNCHER} $MAVEN_CMD_LINE_ARGS
313-
249+
clean || :
250+
exec_maven "$@"

‎mvnw.cmd

+121-136
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<# : batch portion
12
@REM ----------------------------------------------------------------------------
23
@REM Licensed to the Apache Software Foundation (ASF) under one
34
@REM or more contributor license agreements. See the NOTICE file
@@ -18,144 +19,128 @@
1819
@REM ----------------------------------------------------------------------------
1920

2021
@REM ----------------------------------------------------------------------------
21-
@REM Maven2 Start Up Batch script
22-
@REM
23-
@REM Required ENV vars:
24-
@REM JAVA_HOME - location of a JDK home dir
22+
@REM Apache Maven Wrapper startup batch script, version 3.3.0
2523
@REM
2624
@REM Optional ENV vars
27-
@REM M2_HOME - location of maven2's installed home dir
28-
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29-
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
30-
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31-
@REM e.g. to debug Maven itself, use
32-
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33-
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
25+
@REM MVNW_REPOURL - repo url base for downloading maven distribution
26+
@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
27+
@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output
3428
@REM ----------------------------------------------------------------------------
3529

36-
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37-
@echo off
38-
@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
39-
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
40-
41-
@REM set %HOME% to equivalent of $HOME
42-
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
43-
44-
@REM Execute a user defined script before this one
45-
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
46-
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
47-
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
48-
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
49-
:skipRcPre
50-
51-
@setlocal
52-
53-
set ERROR_CODE=0
54-
55-
@REM To isolate internal variables from possible post scripts, we use another setlocal
56-
@setlocal
57-
58-
@REM ==== START VALIDATION ====
59-
if not "%JAVA_HOME%" == "" goto OkJHome
60-
61-
echo.
62-
echo Error: JAVA_HOME not found in your environment. >&2
63-
echo Please set the JAVA_HOME variable in your environment to match the >&2
64-
echo location of your Java installation. >&2
65-
echo.
66-
goto error
67-
68-
:OkJHome
69-
if exist "%JAVA_HOME%\bin\java.exe" goto init
70-
71-
echo.
72-
echo Error: JAVA_HOME is set to an invalid directory. >&2
73-
echo JAVA_HOME = "%JAVA_HOME%" >&2
74-
echo Please set the JAVA_HOME variable in your environment to match the >&2
75-
echo location of your Java installation. >&2
76-
echo.
77-
goto error
78-
79-
@REM ==== END VALIDATION ====
80-
81-
:init
82-
83-
set MAVEN_CMD_LINE_ARGS=%MAVEN_CONFIG% %*
84-
85-
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
86-
@REM Fallback to current working directory if not found.
87-
88-
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
89-
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
90-
91-
set EXEC_DIR=%CD%
92-
set WDIR=%EXEC_DIR%
93-
:findBaseDir
94-
IF EXIST "%WDIR%"\.mvn goto baseDirFound
95-
cd ..
96-
IF "%WDIR%"=="%CD%" goto baseDirNotFound
97-
set WDIR=%CD%
98-
goto findBaseDir
99-
100-
:baseDirFound
101-
set MAVEN_PROJECTBASEDIR=%WDIR%
102-
cd "%EXEC_DIR%"
103-
goto endDetectBaseDir
104-
105-
:baseDirNotFound
106-
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
107-
cd "%EXEC_DIR%"
108-
109-
:endDetectBaseDir
110-
111-
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
112-
113-
@setlocal EnableExtensions EnableDelayedExpansion
114-
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
115-
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
116-
117-
:endReadAdditionalConfig
118-
119-
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
120-
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
121-
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
122-
123-
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
124-
FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO (
125-
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
126-
)
127-
128-
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
129-
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
130-
if exist %WRAPPER_JAR% (
131-
echo Found %WRAPPER_JAR%
132-
) else (
133-
echo Couldn't find %WRAPPER_JAR%, downloading it ...
134-
echo Downloading from: %DOWNLOAD_URL%
135-
powershell -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"
136-
echo Finished downloading %WRAPPER_JAR%
30+
@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0)
31+
@SET __MVNW_CMD__=
32+
@SET __MVNW_ERROR__=
33+
@SET __MVNW_PSMODULEP_SAVE=%PSModulePath%
34+
@SET PSModulePath=
35+
@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @(
36+
IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B)
13737
)
138-
@REM End of extension
139-
140-
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CMD_LINE_ARGS%
141-
if ERRORLEVEL 1 goto error
142-
goto end
143-
144-
:error
145-
set ERROR_CODE=1
146-
147-
:end
148-
@endlocal & set ERROR_CODE=%ERROR_CODE%
149-
150-
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
151-
@REM check for post script, once with legacy .bat ending and once with .cmd ending
152-
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
153-
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
154-
:skipRcPost
155-
156-
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
157-
if "%MAVEN_BATCH_PAUSE%" == "on" pause
158-
159-
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
160-
161-
exit /B %ERROR_CODE%
38+
@SET PSModulePath=%__MVNW_PSMODULEP_SAVE%
39+
@SET __MVNW_PSMODULEP_SAVE=
40+
@SET __MVNW_ARG0_NAME__=
41+
@SET MVNW_USERNAME=
42+
@SET MVNW_PASSWORD=
43+
@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*)
44+
@echo Cannot start maven from wrapper >&2 && exit /b 1
45+
@GOTO :EOF
46+
: end batch / begin powershell #>
47+
48+
$ErrorActionPreference = "Stop"
49+
if ($env:MVNW_VERBOSE -eq "true") {
50+
$VerbosePreference = "Continue"
51+
}
52+
53+
# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties
54+
$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl
55+
if (!$distributionUrl) {
56+
Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties"
57+
}
58+
59+
switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) {
60+
"maven-mvnd-*" {
61+
$USE_MVND = $true
62+
$distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip"
63+
$MVN_CMD = "mvnd.cmd"
64+
break
65+
}
66+
default {
67+
$USE_MVND = $false
68+
$MVN_CMD = $script -replace '^mvnw','mvn'
69+
break
70+
}
71+
}
72+
73+
# apply MVNW_REPOURL and calculate MAVEN_HOME
74+
# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-<version>,maven-mvnd-<version>-<platform>}/<hash>
75+
if ($env:MVNW_REPOURL) {
76+
$MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" }
77+
$distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')"
78+
}
79+
$distributionUrlName = $distributionUrl -replace '^.*/',''
80+
$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$',''
81+
$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain"
82+
$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join ''
83+
$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME"
84+
85+
if (Test-Path -Path "$MAVEN_HOME" -PathType Container) {
86+
Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME"
87+
Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
88+
exit $?
89+
}
90+
91+
if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) {
92+
Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl"
93+
}
94+
95+
# prepare tmp dir
96+
$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile
97+
$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir"
98+
$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null
99+
trap {
100+
if ($TMP_DOWNLOAD_DIR.Exists) {
101+
try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
102+
catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
103+
}
104+
}
105+
106+
New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null
107+
108+
# Download and Install Apache Maven
109+
Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
110+
Write-Verbose "Downloading from: $distributionUrl"
111+
Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
112+
113+
$webclient = New-Object System.Net.WebClient
114+
if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) {
115+
$webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD)
116+
}
117+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
118+
$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null
119+
120+
# If specified, validate the SHA-256 sum of the Maven distribution zip file
121+
$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum
122+
if ($distributionSha256Sum) {
123+
if ($USE_MVND) {
124+
Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties."
125+
}
126+
Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash
127+
if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) {
128+
Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property."
129+
}
130+
}
131+
132+
# unzip and move
133+
Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null
134+
Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null
135+
try {
136+
Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null
137+
} catch {
138+
if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) {
139+
Write-Error "fail to move MAVEN_HOME"
140+
}
141+
} finally {
142+
try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
143+
catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
144+
}
145+
146+
Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"

‎pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@
552552
<plugin>
553553
<groupId>org.apache.maven.plugins</groupId>
554554
<artifactId>maven-wrapper-plugin</artifactId>
555-
<version>3.2.0</version>
555+
<version>3.3.0</version>
556556
</plugin>
557557

558558
<plugin>

0 commit comments

Comments
 (0)
Please sign in to comment.