Skip to content

Commit 38b8d64

Browse files
committed
Maven Wrapper Upgrade
Signed-off-by: Ben Hale <[email protected]>
1 parent e362974 commit 38b8d64

File tree

5 files changed

+91
-38
lines changed

5 files changed

+91
-38
lines changed

.mvn/wrapper/MavenWrapperDownloader.java

100755100644
+29-22
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
11
/*
2-
Licensed to the Apache Software Foundation (ASF) under one
3-
or more contributor license agreements. See the NOTICE file
4-
distributed with this work for additional information
5-
regarding copyright ownership. The ASF licenses this file
6-
to you under the Apache License, Version 2.0 (the
7-
"License"); you may not use this file except in compliance
8-
with the License. You may obtain a copy of the License at
9-
10-
https://www.apache.org/licenses/LICENSE-2.0
11-
12-
Unless required by applicable law or agreed to in writing,
13-
software distributed under the License is distributed on an
14-
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15-
KIND, either express or implied. See the License for the
16-
specific language governing permissions and limitations
17-
under the License.
18-
*/
19-
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+
*/
2016
import java.net.*;
2117
import java.io.*;
2218
import java.nio.channels.*;
2319
import java.util.Properties;
2420

2521
public class MavenWrapperDownloader {
2622

23+
private static final String WRAPPER_VERSION = "0.5.5";
2724
/**
2825
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
2926
*/
30-
private static final String DEFAULT_DOWNLOAD_URL =
31-
"https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar";
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";
3229

3330
/**
3431
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
@@ -76,13 +73,13 @@ public static void main(String args[]) {
7673
}
7774
}
7875
}
79-
System.out.println("- Downloading from: : " + url);
76+
System.out.println("- Downloading from: " + url);
8077

8178
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
8279
if(!outputFile.getParentFile().exists()) {
8380
if(!outputFile.getParentFile().mkdirs()) {
8481
System.out.println(
85-
"- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'");
82+
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
8683
}
8784
}
8885
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
@@ -98,6 +95,16 @@ public static void main(String args[]) {
9895
}
9996

10097
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+
}
101108
URL website = new URL(urlString);
102109
ReadableByteChannel rbc;
103110
rbc = Channels.newChannel(website.openStream());

.mvn/wrapper/maven-wrapper.jar

100755100644
2.32 KB
Binary file not shown.

.mvn/wrapper/maven-wrapper.properties

100755100644
+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.1/apache-maven-3.6.1-bin.zip
2+
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar

mvnw

+29-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# "License"); you may not use this file except in compliance
99
# with the License. You may obtain a copy of the License at
1010
#
11-
# https://www.apache.org/licenses/LICENSE-2.0
11+
# http://www.apache.org/licenses/LICENSE-2.0
1212
#
1313
# Unless required by applicable law or agreed to in writing,
1414
# software distributed under the License is distributed on an
@@ -114,7 +114,6 @@ if $mingw ; then
114114
M2_HOME="`(cd "$M2_HOME"; pwd)`"
115115
[ -n "$JAVA_HOME" ] &&
116116
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
117-
# TODO classpath?
118117
fi
119118

120119
if [ -z "$JAVA_HOME" ]; then
@@ -212,7 +211,11 @@ else
212211
if [ "$MVNW_VERBOSE" = true ]; then
213212
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
214213
fi
215-
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
214+
if [ -n "$MVNW_REPOURL" ]; then
215+
jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
216+
else
217+
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
218+
fi
216219
while IFS="=" read key value; do
217220
case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
218221
esac
@@ -221,22 +224,38 @@ else
221224
echo "Downloading from: $jarUrl"
222225
fi
223226
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
227+
if $cygwin; then
228+
wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
229+
fi
224230

225231
if command -v wget > /dev/null; then
226232
if [ "$MVNW_VERBOSE" = true ]; then
227233
echo "Found wget ... using wget"
228234
fi
229-
wget "$jarUrl" -O "$wrapperJarPath"
235+
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
236+
wget "$jarUrl" -O "$wrapperJarPath"
237+
else
238+
wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath"
239+
fi
230240
elif command -v curl > /dev/null; then
231241
if [ "$MVNW_VERBOSE" = true ]; then
232242
echo "Found curl ... using curl"
233243
fi
234-
curl -o "$wrapperJarPath" "$jarUrl"
244+
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
245+
curl -o "$wrapperJarPath" "$jarUrl" -f
246+
else
247+
curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
248+
fi
249+
235250
else
236251
if [ "$MVNW_VERBOSE" = true ]; then
237252
echo "Falling back to using Java to download"
238253
fi
239254
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
255+
# For Cygwin, switch paths to Windows format before running javac
256+
if $cygwin; then
257+
javaClass=`cygpath --path --windows "$javaClass"`
258+
fi
240259
if [ -e "$javaClass" ]; then
241260
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
242261
if [ "$MVNW_VERBOSE" = true ]; then
@@ -277,6 +296,11 @@ if $cygwin; then
277296
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
278297
fi
279298

299+
# Provide a "standardized" way to retrieve the CLI args that will
300+
# work with both Windows and non-Windows executions.
301+
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
302+
export MAVEN_CMD_LINE_ARGS
303+
280304
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
281305

282306
exec "$JAVACMD" \

mvnw.cmd

100755100644
+31-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@REM "License"); you may not use this file except in compliance
88
@REM with the License. You may obtain a copy of the License at
99
@REM
10-
@REM https://www.apache.org/licenses/LICENSE-2.0
10+
@REM http://www.apache.org/licenses/LICENSE-2.0
1111
@REM
1212
@REM Unless required by applicable law or agreed to in writing,
1313
@REM software distributed under the License is distributed on an
@@ -37,7 +37,7 @@
3737
@echo off
3838
@REM set title of command window
3939
title %0
40-
@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
40+
@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
4141
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
4242

4343
@REM set %HOME% to equivalent of $HOME
@@ -120,23 +120,44 @@ SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
120120
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
121121
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
122122

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
123+
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
124+
125+
FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
126+
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
126127
)
127128

128129
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
129130
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
130131
if exist %WRAPPER_JAR% (
131-
echo Found %WRAPPER_JAR%
132+
if "%MVNW_VERBOSE%" == "true" (
133+
echo Found %WRAPPER_JAR%
134+
)
132135
) else (
133-
echo Couldn't find %WRAPPER_JAR%, downloading it ...
134-
echo Downloading from: %DOWNLOAD_URL%
135-
powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"
136-
echo Finished downloading %WRAPPER_JAR%
136+
if not "%MVNW_REPOURL%" == "" (
137+
SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
138+
)
139+
if "%MVNW_VERBOSE%" == "true" (
140+
echo Couldn't find %WRAPPER_JAR%, downloading it ...
141+
echo Downloading from: %DOWNLOAD_URL%
142+
)
143+
144+
powershell -Command "&{"^
145+
"$webclient = new-object System.Net.WebClient;"^
146+
"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
147+
"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
148+
"}"^
149+
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
150+
"}"
151+
if "%MVNW_VERBOSE%" == "true" (
152+
echo Finished downloading %WRAPPER_JAR%
153+
)
137154
)
138155
@REM End of extension
139156

157+
@REM Provide a "standardized" way to retrieve the CLI args that will
158+
@REM work with both Windows and non-Windows executions.
159+
set MAVEN_CMD_LINE_ARGS=%*
160+
140161
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
141162
if ERRORLEVEL 1 goto error
142163
goto end

0 commit comments

Comments
 (0)