Skip to content

Commit 47fe90a

Browse files
committed
Add busybox wget support as fallback in only-mvnw script
- Enhanced only-mvnw script to try busybox wget when neither wget nor curl is available - Added busybox wget detection in all HTTP request functions: * resolve_jdk_url() for JDK URL resolution API calls * redirect URL resolution logic * get_latest_version_from_disco() for version API calls * install_jdk() for JDK file downloads * main Maven distribution download section - Updated error messages to include busybox wget as supported option - Updated integration tests to handle busybox wget error messages - Improves compatibility with minimal Linux environments like Alpine containers
1 parent f926a20 commit 47fe90a

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

maven-wrapper-distribution/src/resources/only-mvnw

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,10 @@ resolve_jdk_url() {
196196
_resolve_api_response="$(curl -s -f "$_resolve_disco_api_url" 2>/dev/null)"
197197
elif command -v wget >/dev/null; then
198198
_resolve_api_response="$(wget -q -O - "$_resolve_disco_api_url" 2>/dev/null)"
199+
elif command -v busybox >/dev/null && busybox wget --help >/dev/null 2>&1; then
200+
_resolve_api_response="$(busybox wget -q -O - "$_resolve_disco_api_url" 2>/dev/null)"
199201
else
200-
die "Cannot resolve JDK URL: curl or wget required"
202+
die "Cannot resolve JDK URL: curl, wget, or busybox wget required"
201203
fi
202204

203205
if [ -z "$_resolve_api_response" ]; then
@@ -216,6 +218,8 @@ resolve_jdk_url() {
216218
_resolve_download_url="$(curl -s -I "$_resolve_redirect_url" 2>/dev/null | grep -i '^location:' | cut -d' ' -f2- | tr -d '\r\n')"
217219
elif command -v wget >/dev/null; then
218220
_resolve_download_url="$(wget -q -S -O /dev/null "$_resolve_redirect_url" 2>&1 | grep -i '^ location:' | cut -d' ' -f4- | tr -d '\r\n')"
221+
elif command -v busybox >/dev/null && busybox wget --help >/dev/null 2>&1; then
222+
_resolve_download_url="$(busybox wget -q -S -O /dev/null "$_resolve_redirect_url" 2>&1 | grep -i '^ location:' | cut -d' ' -f4- | tr -d '\r\n')"
219223
else
220224
# Fallback to using the redirect URL directly
221225
_resolve_download_url="$_resolve_redirect_url"
@@ -334,8 +338,10 @@ get_latest_version_from_disco() {
334338
api_response="$(curl -s -f "$disco_api_url" 2>/dev/null)"
335339
elif command -v wget >/dev/null; then
336340
api_response="$(wget -q -O - "$disco_api_url" 2>/dev/null)"
341+
elif command -v busybox >/dev/null && busybox wget --help >/dev/null 2>&1; then
342+
api_response="$(busybox wget -q -O - "$disco_api_url" 2>/dev/null)"
337343
else
338-
verbose "No HTTP client (curl/wget) available for Disco API"
344+
verbose "No HTTP client (curl/wget/busybox wget) available for Disco API"
339345
return 1 # No HTTP client available
340346
fi
341347

@@ -508,8 +514,10 @@ install_jdk() {
508514
wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$url" -O "$jdk_file" || die "wget: Failed to fetch JDK from $url"
509515
elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then
510516
curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$jdk_file" "$url" || die "curl: Failed to fetch JDK from $url"
517+
elif [ -z "${MVNW_USERNAME-}" ] && command -v busybox >/dev/null && busybox wget --help >/dev/null 2>&1; then
518+
busybox wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$url" -O "$jdk_file" || die "busybox wget: Failed to fetch JDK from $url"
511519
else
512-
die "Cannot download JDK: wget or curl required"
520+
die "Cannot download JDK: wget, curl, or busybox wget required"
513521
fi
514522

515523
# Verify checksum if provided
@@ -670,6 +678,9 @@ if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then
670678
elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then
671679
verbose "Found curl ... using curl"
672680
curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl"
681+
elif [ -z "${MVNW_USERNAME-}" ] && command -v busybox >/dev/null && busybox wget --help >/dev/null 2>&1; then
682+
verbose "Found busybox wget ... using busybox wget"
683+
busybox wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "busybox wget: Failed to fetch $distributionUrl"
673684
elif set_java_home; then
674685
verbose "Falling back to use Java to download"
675686
javaSource="$TMP_DOWNLOAD_DIR/Downloader.java"

maven-wrapper-plugin/src/it/projects/jdk_checksum_verification/verify.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ assert log.contains('[INFO] Unpacked only-script type wrapper distribution')
4444
// 2. Network issues preventing download
4545
// 3. System JDK usage (if JDK download is skipped)
4646
boolean checksumFailure = log.contains("checksum") || log.contains("SHA-256") || log.contains("verification")
47-
boolean networkIssue = log.contains("Failed to fetch") || log.contains("curl:") || log.contains("wget:")
47+
boolean networkIssue = log.contains("Failed to fetch") || log.contains("curl:") || log.contains("wget:") || log.contains("busybox wget:")
4848

4949
// The test should either fail checksum verification or use system JDK
5050
assert checksumFailure || networkIssue || systemJdkUsed, "Either checksum verification should occur, network issue encountered, or system JDK should be used"

maven-wrapper-plugin/src/it/projects/type_only-script-fail/verify.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ if (isWindows) {
2727
} else {
2828
// on non-Windows: verify clear messages as well
2929
// cover all methods: point is, there is no Maven version 0.0.0
30-
assert log.contains('wget: Failed to fetch') || log.contains('curl: Failed to fetch') || log.contains('- Error downloading:')
30+
assert log.contains('wget: Failed to fetch') || log.contains('curl: Failed to fetch') || log.contains('busybox wget: Failed to fetch') || log.contains('- Error downloading:')
3131
}

0 commit comments

Comments
 (0)