Skip to content
This repository has been archived by the owner on Dec 18, 2021. It is now read-only.

Commit

Permalink
Download maven wrapper with authentication if availble
Browse files Browse the repository at this point in the history
  • Loading branch information
vdotjansen committed Aug 17, 2018
1 parent fe0fa45 commit 9119943
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
10 changes: 10 additions & 0 deletions .mvn/wrapper/MavenWrapperDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ public static void main(String args[]) {
}

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);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
Expand Down
13 changes: 11 additions & 2 deletions mvnw
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,21 @@ else
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found wget ... using wget"
fi
wget "$jarUrl" -O "$wrapperJarPath"
if [ -z "$MVNW_WRAPPER_AUTH_USERNAME" ] || [ -z "$MVNW_WRAPPER_AUTH_PASSWORD" ]; then
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
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found curl ... using curl"
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
if [ "$MVNW_VERBOSE" = true ]; then
echo "Falling back to using Java to download"
Expand Down
9 changes: 8 additions & 1 deletion mvnw.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,14 @@ if exist %WRAPPER_JAR% (
) else (
echo Couldn't find %WRAPPER_JAR%, downloading it ...
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%
)
@REM End of extension
Expand Down

0 comments on commit 9119943

Please sign in to comment.