Skip to content

Commit 4dd4922

Browse files
committed
updated Maven wrapper
1 parent f44e94a commit 4dd4922

File tree

6 files changed

+197
-79
lines changed

6 files changed

+197
-79
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
target/
22
generated/
33
gen/
4-
/.mvn/wrapper/maven-wrapper.jar
54

65
### IntelliJ IDEA ###
76
.idea
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright 2007-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import java.net.*;
17+
import java.io.*;
18+
import java.nio.channels.*;
19+
import java.util.Properties;
20+
21+
public class MavenWrapperDownloader {
22+
23+
private static final String WRAPPER_VERSION = "0.5.6";
24+
/**
25+
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
26+
*/
27+
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
28+
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
29+
30+
/**
31+
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
32+
* use instead of the default one.
33+
*/
34+
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
35+
".mvn/wrapper/maven-wrapper.properties";
36+
37+
/**
38+
* Path where the maven-wrapper.jar will be saved to.
39+
*/
40+
private static final String MAVEN_WRAPPER_JAR_PATH =
41+
".mvn/wrapper/maven-wrapper.jar";
42+
43+
/**
44+
* Name of the property which should be used to override the default download url for the wrapper.
45+
*/
46+
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
47+
48+
public static void main(String args[]) {
49+
System.out.println("- Downloader started");
50+
File baseDirectory = new File(args[0]);
51+
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
52+
53+
// If the maven-wrapper.properties exists, read it and check if it contains a custom
54+
// wrapperUrl parameter.
55+
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
56+
String url = DEFAULT_DOWNLOAD_URL;
57+
if(mavenWrapperPropertyFile.exists()) {
58+
FileInputStream mavenWrapperPropertyFileInputStream = null;
59+
try {
60+
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
61+
Properties mavenWrapperProperties = new Properties();
62+
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
63+
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
64+
} catch (IOException e) {
65+
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
66+
} finally {
67+
try {
68+
if(mavenWrapperPropertyFileInputStream != null) {
69+
mavenWrapperPropertyFileInputStream.close();
70+
}
71+
} catch (IOException e) {
72+
// Ignore ...
73+
}
74+
}
75+
}
76+
System.out.println("- Downloading from: " + url);
77+
78+
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
79+
if(!outputFile.getParentFile().exists()) {
80+
if(!outputFile.getParentFile().mkdirs()) {
81+
System.out.println(
82+
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
83+
}
84+
}
85+
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
86+
try {
87+
downloadFileFromURL(url, outputFile);
88+
System.out.println("Done");
89+
System.exit(0);
90+
} catch (Throwable e) {
91+
System.out.println("- Error downloading");
92+
e.printStackTrace();
93+
System.exit(1);
94+
}
95+
}
96+
97+
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
98+
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
99+
String username = System.getenv("MVNW_USERNAME");
100+
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
101+
Authenticator.setDefault(new Authenticator() {
102+
@Override
103+
protected PasswordAuthentication getPasswordAuthentication() {
104+
return new PasswordAuthentication(username, password);
105+
}
106+
});
107+
}
108+
URL website = new URL(urlString);
109+
ReadableByteChannel rbc;
110+
rbc = Channels.newChannel(website.openStream());
111+
FileOutputStream fos = new FileOutputStream(destination);
112+
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
113+
fos.close();
114+
rbc.close();
115+
}
116+
117+
}

.mvn/wrapper/maven-wrapper.jar

49.5 KB
Binary file not shown.
Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,2 @@
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-
# https://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.8.4/apache-maven-3.8.4-bin.zip
18-
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
2+
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar

mvnw

Lines changed: 61 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919
# ----------------------------------------------------------------------------
2020

2121
# ----------------------------------------------------------------------------
22-
# Apache Maven Wrapper startup batch script, version 3.1.1
22+
# Maven Start Up Batch script
2323
#
2424
# Required ENV vars:
2525
# ------------------
2626
# JAVA_HOME - location of a JDK home dir
2727
#
2828
# Optional ENV vars
2929
# -----------------
30+
# M2_HOME - location of maven2's installed home dir
3031
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
3132
# e.g. to debug Maven itself, use
3233
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@@ -35,10 +36,6 @@
3536

3637
if [ -z "$MAVEN_SKIP_RC" ] ; then
3738

38-
if [ -f /usr/local/etc/mavenrc ] ; then
39-
. /usr/local/etc/mavenrc
40-
fi
41-
4239
if [ -f /etc/mavenrc ] ; then
4340
. /etc/mavenrc
4441
fi
@@ -61,9 +58,9 @@ case "`uname`" in
6158
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
6259
if [ -z "$JAVA_HOME" ]; then
6360
if [ -x "/usr/libexec/java_home" ]; then
64-
JAVA_HOME="`/usr/libexec/java_home`"; export JAVA_HOME
61+
export JAVA_HOME="`/usr/libexec/java_home`"
6562
else
66-
JAVA_HOME="/Library/Java/Home"; export JAVA_HOME
63+
export JAVA_HOME="/Library/Java/Home"
6764
fi
6865
fi
6966
;;
@@ -75,8 +72,36 @@ if [ -z "$JAVA_HOME" ] ; then
7572
fi
7673
fi
7774

75+
if [ -z "$M2_HOME" ] ; then
76+
## resolve links - $0 may be a link to maven's home
77+
PRG="$0"
78+
79+
# need this for relative symlinks
80+
while [ -h "$PRG" ] ; do
81+
ls=`ls -ld "$PRG"`
82+
link=`expr "$ls" : '.*-> \(.*\)$'`
83+
if expr "$link" : '/.*' > /dev/null; then
84+
PRG="$link"
85+
else
86+
PRG="`dirname "$PRG"`/$link"
87+
fi
88+
done
89+
90+
saveddir=`pwd`
91+
92+
M2_HOME=`dirname "$PRG"`/..
93+
94+
# make it fully qualified
95+
M2_HOME=`cd "$M2_HOME" && pwd`
96+
97+
cd "$saveddir"
98+
# echo Using m2 at $M2_HOME
99+
fi
100+
78101
# For Cygwin, ensure paths are in UNIX format before anything is touched
79102
if $cygwin ; then
103+
[ -n "$M2_HOME" ] &&
104+
M2_HOME=`cygpath --unix "$M2_HOME"`
80105
[ -n "$JAVA_HOME" ] &&
81106
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
82107
[ -n "$CLASSPATH" ] &&
@@ -85,6 +110,8 @@ fi
85110

86111
# For Mingw, ensure paths are in UNIX format before anything is touched
87112
if $mingw ; then
113+
[ -n "$M2_HOME" ] &&
114+
M2_HOME="`(cd "$M2_HOME"; pwd)`"
88115
[ -n "$JAVA_HOME" ] &&
89116
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
90117
fi
@@ -118,7 +145,7 @@ if [ -z "$JAVACMD" ] ; then
118145
JAVACMD="$JAVA_HOME/bin/java"
119146
fi
120147
else
121-
JAVACMD="`\\unset -f command; \\command -v java`"
148+
JAVACMD="`which java`"
122149
fi
123150
fi
124151

@@ -132,9 +159,12 @@ if [ -z "$JAVA_HOME" ] ; then
132159
echo "Warning: JAVA_HOME environment variable is not set."
133160
fi
134161

162+
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
163+
135164
# traverses directory structure from process work directory to filesystem root
136165
# first directory with .mvn subdirectory is considered project base directory
137166
find_maven_basedir() {
167+
138168
if [ -z "$1" ]
139169
then
140170
echo "Path not specified to find_maven_basedir"
@@ -154,7 +184,7 @@ find_maven_basedir() {
154184
fi
155185
# end of workaround
156186
done
157-
printf '%s' "$(cd "$basedir"; pwd)"
187+
echo "${basedir}"
158188
}
159189

160190
# concatenates all lines of a file
@@ -164,16 +194,11 @@ concat_lines() {
164194
fi
165195
}
166196

167-
BASE_DIR=$(find_maven_basedir "$(dirname $0)")
197+
BASE_DIR=`find_maven_basedir "$(pwd)"`
168198
if [ -z "$BASE_DIR" ]; then
169199
exit 1;
170200
fi
171201

172-
MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR
173-
if [ "$MVNW_VERBOSE" = true ]; then
174-
echo $MAVEN_PROJECTBASEDIR
175-
fi
176-
177202
##########################################################################################
178203
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
179204
# This allows using the maven wrapper in projects that prohibit checking in binary data.
@@ -187,66 +212,59 @@ else
187212
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
188213
fi
189214
if [ -n "$MVNW_REPOURL" ]; then
190-
wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar"
215+
jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
191216
else
192-
wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar"
217+
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
193218
fi
194219
while IFS="=" read key value; do
195-
case "$key" in (wrapperUrl) wrapperUrl="$value"; break ;;
220+
case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
196221
esac
197222
done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
198223
if [ "$MVNW_VERBOSE" = true ]; then
199-
echo "Downloading from: $wrapperUrl"
224+
echo "Downloading from: $jarUrl"
200225
fi
201226
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
202227
if $cygwin; then
203228
wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
204229
fi
205230

206231
if command -v wget > /dev/null; then
207-
QUIET="--quiet"
208232
if [ "$MVNW_VERBOSE" = true ]; then
209233
echo "Found wget ... using wget"
210-
QUIET=""
211234
fi
212235
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
213-
wget $QUIET "$wrapperUrl" -O "$wrapperJarPath"
236+
wget "$jarUrl" -O "$wrapperJarPath"
214237
else
215-
wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath"
238+
wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath"
216239
fi
217-
[ $? -eq 0 ] || rm -f "$wrapperJarPath"
218240
elif command -v curl > /dev/null; then
219-
QUIET="--silent"
220241
if [ "$MVNW_VERBOSE" = true ]; then
221242
echo "Found curl ... using curl"
222-
QUIET=""
223243
fi
224244
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
225-
curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L
245+
curl -o "$wrapperJarPath" "$jarUrl" -f
226246
else
227-
curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L
247+
curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
228248
fi
229-
[ $? -eq 0 ] || rm -f "$wrapperJarPath"
249+
230250
else
231251
if [ "$MVNW_VERBOSE" = true ]; then
232252
echo "Falling back to using Java to download"
233253
fi
234-
javaSource="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
235-
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class"
254+
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
236255
# For Cygwin, switch paths to Windows format before running javac
237256
if $cygwin; then
238-
javaSource=`cygpath --path --windows "$javaSource"`
239257
javaClass=`cygpath --path --windows "$javaClass"`
240258
fi
241-
if [ -e "$javaSource" ]; then
242-
if [ ! -e "$javaClass" ]; then
259+
if [ -e "$javaClass" ]; then
260+
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
243261
if [ "$MVNW_VERBOSE" = true ]; then
244262
echo " - Compiling MavenWrapperDownloader.java ..."
245263
fi
246264
# Compiling the Java class
247-
("$JAVA_HOME/bin/javac" "$javaSource")
265+
("$JAVA_HOME/bin/javac" "$javaClass")
248266
fi
249-
if [ -e "$javaClass" ]; then
267+
if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
250268
# Running the downloader
251269
if [ "$MVNW_VERBOSE" = true ]; then
252270
echo " - Running MavenWrapperDownloader.java ..."
@@ -260,10 +278,16 @@ fi
260278
# End of extension
261279
##########################################################################################
262280

281+
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
282+
if [ "$MVNW_VERBOSE" = true ]; then
283+
echo $MAVEN_PROJECTBASEDIR
284+
fi
263285
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
264286

265287
# For Cygwin, switch paths to Windows format before running java
266288
if $cygwin; then
289+
[ -n "$M2_HOME" ] &&
290+
M2_HOME=`cygpath --path --windows "$M2_HOME"`
267291
[ -n "$JAVA_HOME" ] &&
268292
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
269293
[ -n "$CLASSPATH" ] &&
@@ -281,7 +305,6 @@ WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
281305

282306
exec "$JAVACMD" \
283307
$MAVEN_OPTS \
284-
$MAVEN_DEBUG_OPTS \
285308
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
286-
"-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
309+
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
287310
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"

0 commit comments

Comments
 (0)