@@ -21,6 +21,29 @@ CHECKSUM_DIR="${2}/${VENDOR}"
2121ensure_directory " ${METADATA_DIR} "
2222ensure_directory " ${CHECKSUM_DIR} "
2323
24+ # Parse an asset file name and echo "JAVA_VERSION|OS|ARCH|EXT".
25+ # Exits non-zero when the name does not match, so the caller can skip the asset
26+ # instead of silently producing metadata with empty fields.
27+ #
28+ # Handles both naming schemes seen so far:
29+ # graalvm-community-jdk-17.0.7_linux-x64_bin.tar.gz -> 17.0.7
30+ # graalvm-community-jdk-21.0.2_macos-aarch64_bin.tar.gz -> 21.0.2
31+ # graalvm-community-jdk-25i3-25.0.4.1_windows-x64_bin.zip -> 25.0.4.1
32+ #
33+ # The middle part between "jdk-" and "_<os>-<arch>" is treated as an opaque
34+ # blob; the Java version is the trailing dotted-numeric run inside it. That way
35+ # extra stream labels (25i3, and whatever comes next) do not break parsing, and
36+ # version numbers with any number of components are accepted.
37+ function parse_asset_name {
38+ perl -e '
39+ my $name = $ARGV[0];
40+ exit 1 unless $name =~ /^graalvm-community-jdk-(.+)_(linux|macos|windows)-(aarch64|x64)_bin\.(zip|tar\.gz)$/;
41+ my ($blob, $os, $arch, $ext) = ($1, $2, $3, $4);
42+ exit 1 unless $blob =~ /(\d+(?:\.\d+)*)$/;
43+ print join("|", $1, $os, $arch, $ext);
44+ ' " ${1} "
45+ }
46+
2447function download {
2548 local tag_name=" ${1} "
2649 local asset_name=" ${2} "
@@ -33,52 +56,68 @@ function download {
3356 if [[ -f " ${metadata_file} " ]]
3457 then
3558 echo " Skipping ${filename} "
36- else
37- # Starting from graalvm 23 : graalvm-community-jdk-17.0.7_macos-aarch64_bin.tar.gz
38- # graalvm-community-jdk-17.0.7_linux-x64_bin.tar.gz
39- # shellcheck disable=SC2016
40- local regex=' s/^graalvm-community-jdk-([0-9]{1,2}\.[0-9]{1}\.[0-9]{1,3})_(linux|macos|windows)-(aarch64|x64)_bin\.(zip|tar\.gz)$/JAVA_VERSION="$1" OS="$2" ARCH="$3" EXT="$4"/g'
41-
42- local JAVA_VERSION=" "
43- local OS=" "
44- local ARCH=" "
45- local EXT=" "
46-
47- # Parse meta-data from file name
48- eval " $( echo " ${asset_name} " | perl -pe " ${regex} " ) "
49-
50- download_file " ${url} " " ${archive} " || return 1
51-
52- local json
53- json=" $( metadata_json \
54- " ${VENDOR} " \
55- " ${filename} " \
56- ' ga' \
57- " ${JAVA_VERSION} " \
58- " ${JAVA_VERSION} " \
59- ' graalvm' \
60- " $( normalize_os " ${OS} " ) " \
61- " $( normalize_arch " ${ARCH} " ) " \
62- " ${EXT} " \
63- ' jdk' \
64- ' ' \
65- " ${url} " \
66- " $( hash_file ' md5' " ${archive} " " ${CHECKSUM_DIR} " ) " \
67- " $( hash_file ' sha1' " ${archive} " " ${CHECKSUM_DIR} " ) " \
68- " $( hash_file ' sha256' " ${archive} " " ${CHECKSUM_DIR} " ) " \
69- " $( hash_file ' sha512' " ${archive} " " ${CHECKSUM_DIR} " ) " \
70- " $( file_size " ${archive} " ) " \
71- " ${filename} "
72- ) "
73-
74- echo " ${json} " > " ${metadata_file} "
75- rm -f " ${archive} "
59+ return 0
60+ fi
61+
62+ # Parse meta-data from file name
63+ local parsed
64+ if ! parsed=" $( parse_asset_name " ${asset_name} " ) "
65+ then
66+ echo " Cannot parse asset name ${asset_name} "
67+ return 1
7668 fi
69+
70+ local JAVA_VERSION OS ARCH EXT
71+ IFS=' |' read -r JAVA_VERSION OS ARCH EXT <<< " ${parsed}"
72+
73+ if [[ -z " ${JAVA_VERSION} " || -z " ${OS} " || -z " ${ARCH} " || -z " ${EXT} " ]]
74+ then
75+ echo " Incomplete meta-data parsed from ${asset_name} "
76+ return 1
77+ fi
78+
79+ download_file " ${url} " " ${archive} " || return 1
80+
81+ local json
82+ json=" $( metadata_json \
83+ " ${VENDOR} " \
84+ " ${filename} " \
85+ ' ga' \
86+ " ${JAVA_VERSION} " \
87+ " ${JAVA_VERSION} " \
88+ ' graalvm' \
89+ " $( normalize_os " ${OS} " ) " \
90+ " $( normalize_arch " ${ARCH} " ) " \
91+ " ${EXT} " \
92+ ' jdk' \
93+ ' ' \
94+ " ${url} " \
95+ " $( hash_file ' md5' " ${archive} " " ${CHECKSUM_DIR} " ) " \
96+ " $( hash_file ' sha1' " ${archive} " " ${CHECKSUM_DIR} " ) " \
97+ " $( hash_file ' sha256' " ${archive} " " ${CHECKSUM_DIR} " ) " \
98+ " $( hash_file ' sha512' " ${archive} " " ${CHECKSUM_DIR} " ) " \
99+ " $( file_size " ${archive} " ) " \
100+ " ${filename} "
101+ ) "
102+
103+ echo " ${json} " > " ${metadata_file} "
104+ rm -f " ${archive} "
77105}
78106
79107download_github_releases ' graalvm' ' graalvm-ce-builds' " ${TEMP_DIR} /releases-graalvm-community.json"
80108
81- versions=$( jq -r ' .[].tag_name' " ${TEMP_DIR} /releases-graalvm-community.json" | sort -V | grep " ^jdk" )
109+ # Release tags changed prefix: older releases use "jdk-21.0.2", newer ones use
110+ # "graal-25.3.4.1". The real guard is the asset-name filter below, which only
111+ # accepts assets starting with "graalvm-community" - so this grep only needs to
112+ # be loose enough not to drop valid releases.
113+ versions=$( jq -r ' .[].tag_name' " ${TEMP_DIR} /releases-graalvm-community.json" | sort -V | grep -E ' ^(jdk|graal)-' || true)
114+
115+ if [[ -z " ${versions} " ]]
116+ then
117+ echo " No matching release tags found - has the tag naming changed again?"
118+ exit 1
119+ fi
120+
82121for version in ${versions}
83122do
84123 assets=$( jq -r " .[] | select(.tag_name == \" ${version} \" ) | .assets[].name | select(startswith(\" graalvm-community\" )) | select(endswith(\" tar.gz\" ) or endswith(\" zip\" ))" " ${TEMP_DIR} /releases-graalvm-community.json" )
0 commit comments