diff --git a/maven-wrapper-distribution/src/resources/mvnw.cmd b/maven-wrapper-distribution/src/resources/mvnw.cmd index 97fff177..0f605bf7 100644 --- a/maven-wrapper-distribution/src/resources/mvnw.cmd +++ b/maven-wrapper-distribution/src/resources/mvnw.cmd @@ -121,6 +121,20 @@ set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/@@project.version@@/maven-wrapper-@@project.version@@.jar" +REM --- BEGIN: Parse userinfo from WRAPPER_URL (for basic auth) --- +set WRAPPER_URL_STR=%WRAPPER_URL% +for /f "tokens=1,2 delims=@" %%U in ("%WRAPPER_URL_STR:@= @%") do set WRAPPER_URL_USERINFO=%%U& set WRAPPER_URL_NOUSER=%%V +REM If userinfo is present, it will be in WRAPPER_URL_USERINFO as protocol://username:password +set MVNW_USERNAME= +set MVNW_PASSWORD= +set WRAPPER_URL_CLEAN=%WRAPPER_URL% +for /f "tokens=1,2 delims=//" %%A in ("%WRAPPER_URL_USERINFO%") do set WRAPPER_URL_PROTO=%%A& set WRAPPER_URL_AUTH=%%B +REM WRAPPER_URL_AUTH will be username:password if present +for /f "tokens=1,2 delims=:" %%A in ("%WRAPPER_URL_AUTH%") do set MVNW_USERNAME=%%A& set MVNW_PASSWORD=%%B +REM If both username and password are set, reconstruct WRAPPER_URL without userinfo +if not "%MVNW_USERNAME%"=="" if not "%MVNW_PASSWORD%"=="" set WRAPPER_URL=%WRAPPER_URL_PROTO://%%WRAPPER_URL_NOUSER% +REM --- END: Parse userinfo --- + FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B ) @@ -147,6 +161,7 @@ if exist %WRAPPER_JAR% ( "}"^ "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ "}" + ping 127.0.0.1 -n 2 > nul if "%MVNW_VERBOSE%" == "true" ( echo Finished downloading %WRAPPER_JAR% ) diff --git a/maven-wrapper-distribution/src/resources/only-mvnw b/maven-wrapper-distribution/src/resources/only-mvnw index 6d8e3f8d..a14420b7 100755 --- a/maven-wrapper-distribution/src/resources/only-mvnw +++ b/maven-wrapper-distribution/src/resources/only-mvnw @@ -145,9 +145,15 @@ distributionUrlNameMain="${distributionUrlNameMain%-bin}" MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +# Only unset sensitive env vars when running the actual Maven binary, not before running the wrapper plugin exec_maven() { - unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : - exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" + if [ "$1" = "org.apache.maven.plugins:maven-wrapper-plugin:"* ]; then + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" + else + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" + fi } if [ -d "$MAVEN_HOME" ]; then