consistent usage of MVNW_USERNAME and MVWN_PASSWORD

This commit is contained in:
Manfred Moser 2019-02-18 11:56:54 -08:00 committed by rfscholte
parent 0e55dc7366
commit bca8bfd583
6 changed files with 21 additions and 20 deletions

View File

@ -98,9 +98,9 @@ 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) { if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
String username = System.getenv("MVNW_WRAPPER_AUTH_USERNAME"); String username = System.getenv("MVNW_USERNAME");
char[] password = System.getenv("MVNW_WRAPPER_AUTH_PASSWORD").toCharArray(); char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
Authenticator.setDefault(new Authenticator() { Authenticator.setDefault(new Authenticator() {
@Override @Override
protected PasswordAuthentication getPasswordAuthentication() { protected PasswordAuthentication getPasswordAuthentication() {

View File

@ -83,9 +83,9 @@ download the file from the URL specified in
download is attempted via curl, wget and, as last resort, by compiling the download is attempted via curl, wget and, as last resort, by compiling the
`./mvn/wrapper/MavenWrapperDownloader.java` file and executing the resulting class. `./mvn/wrapper/MavenWrapperDownloader.java` file and executing the resulting class.
If your maven repository is password protected you can specify your username via the If your Maven repository is password protected you can specify your username via the
environment variable `MVNW_WRAPPER_AUTH_USERNAME` and the password via the environment environment variable `MVNW_USERNAME` and the password via the environment
variable `MVNW_WRAPPER_AUTH_PASSWORD`. variable `MVNW_PASSWORD`.
## Using a Different Version of Maven ## Using a Different Version of Maven
@ -106,7 +106,7 @@ distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-mav
To download Maven from a location that requires Basic Authentication you have 2 options: To download Maven from a location that requires Basic Authentication you have 2 options:
1. Set the environment variables MVNW_USER and MVNW_PASSWORD 1. Set the environment variables MVNW_USERNAME and MVNW_PASSWORD
or or
@ -137,10 +137,11 @@ To test Maven wrapper usage:
- use on test project with maven plugin version - use on test project with maven plugin version
For release For release
- make sure version in mvnw files and config files and pom files is new upcoming - make sure version in mvnw files, MavenWrapperDownloader.java and config files
release and pom files is new upcoming release
- cut maven release with usual release plugin usage - cut maven release with usual release plugin usage
- update maven plugin to release version - update maven plugin to release version
- release it as well - release it as well

8
maven-wrapper/mvnw vendored
View File

@ -228,19 +228,19 @@ 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 if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
wget "$jarUrl" -O "$wrapperJarPath" wget "$jarUrl" -O "$wrapperJarPath"
else else
wget --http-user=$MVNW_WRAPPER_AUTH_USERNAME --http-password=$MVNW_WRAPPER_AUTH_PASSWORD "$jarUrl" -O "$wrapperJarPath" wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath"
fi 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
if [ -z "$MVNW_WRAPPER_AUTH_USERNAME" ] || [ -z "$MVNW_WRAPPER_AUTH_PASSWORD" ]; then if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
curl -o "$wrapperJarPath" "$jarUrl" -f curl -o "$wrapperJarPath" "$jarUrl" -f
else else
curl --user $MVNW_WRAPPER_AUTH_USERNAME:$MVNW_WRAPPER_AUTH_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
fi fi
else else

View File

@ -135,8 +135,8 @@ if exist %WRAPPER_JAR% (
powershell -Command "&{"^ powershell -Command "&{"^
"$webclient = new-object System.Net.WebClient;"^ "$webclient = new-object System.Net.WebClient;"^
"if (-not ([string]::IsNullOrEmpty('%MVNW_WRAPPER_AUTH_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_WRAPPER_AUTH_PASSWORD%'))) {"^ "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_WRAPPER_AUTH_USERNAME%', '%MVNW_WRAPPER_AUTH_PASSWORD%');"^ "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
"}"^ "}"^
"$webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ "$webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
"}" "}"

View File

@ -17,7 +17,7 @@
package org.apache.maven.wrapper; package org.apache.maven.wrapper;
import static org.apache.maven.wrapper.MavenWrapperMain.MVNW_PASSWORD; import static org.apache.maven.wrapper.MavenWrapperMain.MVNW_PASSWORD;
import static org.apache.maven.wrapper.MavenWrapperMain.MVNW_USER; import static org.apache.maven.wrapper.MavenWrapperMain.MVNW_USERNAME;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.File; import java.io.File;
@ -58,10 +58,10 @@ public class DefaultDownloader implements Downloader {
} }
private void configureAuthentication() { private void configureAuthentication() {
if (System.getProperty("MVNW_WRAPPER_AUTH_USERNAME") != null && System.getProperty("MVNW_WRAPPER_AUTH_PASSWORD") != null && System.getProperty("http.proxyUser") == null) { if (System.getProperty("MVNW_USERNAME") != null && System.getProperty("MVNW_PASSWORD") != null && System.getProperty("http.proxyUser") == null) {
Authenticator.setDefault(new Authenticator() { Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() { protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(System.getProperty("MVNW_WRAPPER_AUTH_USERNAME"), System.getProperty("MVNW_WRAPPER_AUTH_PASSWORD").toCharArray()); return new PasswordAuthentication(System.getProperty("MVNW_USERNAME"), System.getProperty("MVNW_PASSWORD").toCharArray());
} }
}); });
} }
@ -150,7 +150,7 @@ public class DefaultDownloader implements Downloader {
} }
private String calculateUserInfo(URI uri) { private String calculateUserInfo(URI uri) {
String username = System.getenv(MVNW_USER); String username = System.getenv(MVNW_USERNAME);
String password = System.getenv(MVNW_PASSWORD); String password = System.getenv(MVNW_PASSWORD);
if (username != null && password != null) { if (username != null && password != null) {
return username + ':' + password; return username + ':' + password;

View File

@ -37,7 +37,7 @@ public class MavenWrapperMain {
public static final String MAVEN_USER_HOME_ENV_KEY = "MAVEN_USER_HOME"; public static final String MAVEN_USER_HOME_ENV_KEY = "MAVEN_USER_HOME";
public static final String MVNW_VERBOSE = "MVNW_VERBOSE"; public static final String MVNW_VERBOSE = "MVNW_VERBOSE";
public static final String MVNW_USER = "MVNW_USER"; public static final String MVNW_USERNAME = "MVNW_USERNAME";
public static final String MVNW_PASSWORD = "MVNW_PASSWORD"; public static final String MVNW_PASSWORD = "MVNW_PASSWORD";
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {