Bounded HTTP client

Use https://nativify.javavirtualenvironment.com/api/v1 and the /builds routes. The submit POST /builds is non-idempotent and may consume NCU; do not place it in an automatic retry wrapper. Persist the returned task ID once, then poll GET /builds/{id} until a total deadline.

Retry only polling GET failures with status 429, 502, 503, or 504. Honor Retry-After when it is an integer number of seconds or an HTTP-date; otherwise use a bounded fallback backoff. Treat SUCCESS as the only downloadable success, FAILED and CANCELLED as terminal failures, and any undocumented status as an immediate failure. Never poll an unknown state indefinitely.

Download only after SUCCESS, within the same total deadline. Write the response to a temporary file in the destination directory, validate the command result, then atomically rename it to the final output. Remove the temporary file on failure so a partial JAR is never mistaken for a release artifact.

bash
remaining=$((deadline - SECONDS))
((remaining > 0)) || { echo "deadline exceeded before download" >&2; exit 1; }
temp_output="${OUTPUT_JAR}.part.$"
trap 'rm -f "$temp_output"' EXIT
curl --fail-with-body --silent --show-error --max-time "$remaining" \
  --output "$temp_output" "$download_url"
mv -f "$temp_output" "$OUTPUT_JAR"
trap - EXIT