mirror of https://github.com/apache/maven.git
Download maven wrapper with authentication if availble
This commit is contained in:
parent
42ca0a344f
commit
b9e6795b6c
|
@ -98,6 +98,16 @@ public class MavenWrapperDownloader {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
|
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
|
||||||
|
if (System.getenv("MVNW_WRAPPER_AUTH_USERNAME") != null && System.getenv("MVNW_WRAPPER_AUTH_PASSWORD") != null) {
|
||||||
|
String username = System.getenv("MVNW_WRAPPER_AUTH_USERNAME");
|
||||||
|
char[] password = System.getenv("MVNW_WRAPPER_AUTH_PASSWORD").toCharArray();
|
||||||
|
Authenticator.setDefault(new Authenticator() {
|
||||||
|
@Override
|
||||||
|
protected PasswordAuthentication getPasswordAuthentication() {
|
||||||
|
return new PasswordAuthentication(username, password);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
URL website = new URL(urlString);
|
URL website = new URL(urlString);
|
||||||
ReadableByteChannel rbc;
|
ReadableByteChannel rbc;
|
||||||
rbc = Channels.newChannel(website.openStream());
|
rbc = Channels.newChannel(website.openStream());
|
||||||
|
|
|
@ -225,12 +225,21 @@ else
|
||||||
if [ "$MVNW_VERBOSE" = true ]; then
|
if [ "$MVNW_VERBOSE" = true ]; then
|
||||||
echo "Found wget ... using wget"
|
echo "Found wget ... using wget"
|
||||||
fi
|
fi
|
||||||
|
if [ -z "$MVNW_WRAPPER_AUTH_USERNAME" ] || [ -z "$MVNW_WRAPPER_AUTH_PASSWORD" ]; then
|
||||||
wget "$jarUrl" -O "$wrapperJarPath"
|
wget "$jarUrl" -O "$wrapperJarPath"
|
||||||
|
else
|
||||||
|
wget --http-user=$MVNW_WRAPPER_AUTH_USERNAME --http-password=$MVNW_WRAPPER_AUTH_PASSWORD "$jarUrl" -O "$wrapperJarPath"
|
||||||
|
fi
|
||||||
elif command -v curl > /dev/null; then
|
elif command -v curl > /dev/null; then
|
||||||
if [ "$MVNW_VERBOSE" = true ]; then
|
if [ "$MVNW_VERBOSE" = true ]; then
|
||||||
echo "Found curl ... using curl"
|
echo "Found curl ... using curl"
|
||||||
fi
|
fi
|
||||||
curl -o "$wrapperJarPath" "$jarUrl"
|
if [ -z "$MVNW_WRAPPER_AUTH_USERNAME" ] || [ -z "$MVNW_WRAPPER_AUTH_PASSWORD" ]; then
|
||||||
|
curl -o "$wrapperJarPath" "$jarUrl" -f
|
||||||
|
else
|
||||||
|
curl --user $MVNW_WRAPPER_AUTH_USERNAME:$MVNW_WRAPPER_AUTH_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
|
||||||
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
if [ "$MVNW_VERBOSE" = true ]; then
|
if [ "$MVNW_VERBOSE" = true ]; then
|
||||||
echo "Falling back to using Java to download"
|
echo "Falling back to using Java to download"
|
||||||
|
|
|
@ -132,7 +132,14 @@ if exist %WRAPPER_JAR% (
|
||||||
) else (
|
) else (
|
||||||
echo Couldn't find %WRAPPER_JAR%, downloading it ...
|
echo Couldn't find %WRAPPER_JAR%, downloading it ...
|
||||||
echo Downloading from: %DOWNLOAD_URL%
|
echo Downloading from: %DOWNLOAD_URL%
|
||||||
powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"
|
|
||||||
|
powershell -Command "&{"^
|
||||||
|
"$webclient = new-object System.Net.WebClient;"^
|
||||||
|
"if (-not ([string]::IsNullOrEmpty('%MVNW_WRAPPER_AUTH_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_WRAPPER_AUTH_PASSWORD%'))) {"^
|
||||||
|
"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_WRAPPER_AUTH_USERNAME%', '%MVNW_WRAPPER_AUTH_PASSWORD%');"^
|
||||||
|
"}"^
|
||||||
|
"$webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
|
||||||
|
"}"
|
||||||
echo Finished downloading %WRAPPER_JAR%
|
echo Finished downloading %WRAPPER_JAR%
|
||||||
)
|
)
|
||||||
@REM End of extension
|
@REM End of extension
|
||||||
|
|
Loading…
Reference in New Issue