Skip to content

Commit c593508

Browse files
committed
feat: use Oracle Java Releases API for latest Oracle JDK
https://blogs.oracle.com/java/post/oracle-java-releases-public-apis Closes #50
1 parent 390dcda commit c593508

File tree

1 file changed

+62
-36
lines changed

1 file changed

+62
-36
lines changed

bin/oracle.bash

Lines changed: 62 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,48 +24,15 @@ ensure_directory "${CHECKSUM_DIR}"
2424
# shellcheck disable=SC2016
2525
REGEX='s/^jdk-([0-9+.]{2,})_(linux|macos|windows)-(x64|aarch64)_bin\.(tar\.gz|zip|msi|dmg|exe|deb|rpm)$/VERSION="$1" OS="$2" ARCH="$3" ARCHIVE="$4"/g'
2626

27-
function current_releases {
28-
local version="$1"
29-
30-
# https://www.oracle.com/java/technologies/jdk-script-friendly-urls/
31-
local -a params=(
32-
'linux,aarch64,rpm:tar.gz'
33-
'linux,x64,deb:rpm:tar.gz'
34-
'macos,aarch64,dmg:tar.gz'
35-
'macos,x64,dmg:tar.gz'
36-
'windows,x64,exe:msi:zip'
37-
)
38-
for param in "${params[@]}"
39-
do
40-
local os
41-
os=$(cut -f1 -d, <<<"$param")
42-
local arch
43-
arch=$(cut -f2 -d, <<<"$param")
44-
local ext_list
45-
ext_list=$(cut -f3 -d, <<<"$param")
46-
47-
for ext in ${ext_list//:/ }
48-
do
49-
echo "jdk-${version}_${os}-${arch}_bin.${ext}"
50-
done
51-
done
52-
}
53-
5427
function download_and_parse {
5528
MAJOR_VERSION="${1}"
5629
INDEX_FILE="${TEMP_DIR}/index${MAJOR_VERSION}.html"
5730

5831
download_file "https://www.oracle.com/java/technologies/javase/jdk${MAJOR_VERSION}-archive-downloads.html" "${INDEX_FILE}"
5932

6033
JDK_FILES=$(grep -o -E '<a href="https://download\.oracle\.com/java/.+/archive/(jdk-.+_(linux|macos|windows)-(x64|aarch64)_bin\.(tar\.gz|zip|msi|dmg|exe|deb|rpm))">' "${INDEX_FILE}" | perl -pe 's#<a href="https://download\.oracle\.com/java/.+/archive/(.+)">#$1#g' | sort -V)
61-
CURRENT_RELEASE=$(curl -sSf https://www.oracle.com/java/technologies/downloads/ | (grep "<h3 id=\"java${MAJOR_VERSION}\"" || true) | perl -pe 's#<h3 id="java[0-9]{2}">JDK Development Kit (.+) downloads</h3>#$1#g')
62-
JDK_FILES_CURRENT=""
63-
if [[ -n "${CURRENT_RELEASE}" ]]
64-
then
65-
JDK_FILES_CURRENT=$(current_releases "${CURRENT_RELEASE}")
66-
fi
67-
68-
for JDK_FILE in ${JDK_FILES} ${JDK_FILES_CURRENT}
34+
35+
for JDK_FILE in ${JDK_FILES}
6936
do
7037
if [[ -z "${JDK_FILE}" ]]
7138
then
@@ -131,4 +98,63 @@ do
13198
download_and_parse "$version"
13299
done
133100

134-
jq -s -S . "${METADATA_DIR}"/jdk-*.json > "${METADATA_DIR}/all.json"
101+
# Latest
102+
download_file "https://java.oraclecloud.com/javaVersions" "${TEMP_DIR}/latest-versions.json"
103+
for version in $(jq -r '.items[].latestReleaseVersion' "${TEMP_DIR}/latest-versions.json")
104+
do
105+
download_file "https://java.oraclecloud.com/javaReleases/${version}" "${TEMP_DIR}/release-${version}.json"
106+
for JDK_URL in $(jq -r '.artifacts[].downloadUrl' "${TEMP_DIR}/release-${version}.json")
107+
do
108+
JDK_FILE=$(basename "${JDK_URL}")
109+
JDK_ARCHIVE="${TEMP_DIR}/${JDK_FILE}"
110+
METADATA_FILE="${METADATA_DIR}/${JDK_FILE}.json"
111+
if [[ -f "${METADATA_FILE}" ]]
112+
then
113+
echo "Skipping ${JDK_FILE}"
114+
else
115+
if ! download_file "${JDK_URL}" "${JDK_ARCHIVE}";
116+
then
117+
echo "Failed to download ${JDK_FILE}, skipping"
118+
continue
119+
fi
120+
VERSION=""
121+
OS=""
122+
ARCH=""
123+
ARCHIVE=""
124+
125+
# Parse meta-data from file name
126+
PARSED_NAME=$(perl -pe "${REGEX}" <<< "${JDK_FILE}")
127+
if [[ "${PARSED_NAME}" = "${JDK_FILE}" ]]
128+
then
129+
echo "Regular expression didn't match ${JDK_FILE}"
130+
continue
131+
else
132+
eval "${PARSED_NAME}"
133+
fi
134+
135+
METADATA_JSON="$(metadata_json \
136+
"${VENDOR}" \
137+
"${JDK_FILE}" \
138+
"ga" \
139+
"${VERSION}" \
140+
"${VERSION}" \
141+
'hotspot' \
142+
"$(normalize_os "${OS}")" \
143+
"$(normalize_arch "${ARCH}")" \
144+
"${ARCHIVE}" \
145+
"jdk" \
146+
"" \
147+
"${JDK_URL}" \
148+
"$(hash_file 'md5' "${JDK_ARCHIVE}" "${CHECKSUM_DIR}")" \
149+
"$(hash_file 'sha1' "${JDK_ARCHIVE}" "${CHECKSUM_DIR}")" \
150+
"$(hash_file 'sha256' "${JDK_ARCHIVE}" "${CHECKSUM_DIR}")" \
151+
"$(hash_file 'sha512' "${JDK_ARCHIVE}" "${CHECKSUM_DIR}")" \
152+
"$(file_size "${JDK_ARCHIVE}")" \
153+
"${JDK_FILE}"
154+
)"
155+
156+
echo "${METADATA_JSON}" > "${METADATA_FILE}"
157+
rm -f "${JDK_ARCHIVE}"
158+
fi
159+
done
160+
done

0 commit comments

Comments
 (0)