From 44484c75398ce18e33ba7ca16e2dcdee52316720 Mon Sep 17 00:00:00 2001 From: Filipe Roque Date: Mon, 1 Apr 2024 16:52:46 +0100 Subject: [PATCH] Merge JDK release binaries if it shares a release name api.adoptium.net may respond with a duplicate release name if a new build was required [1]. In this case, adopt_build_number should be present and incremented. > Note that they have different adopt_build_number, in effect openjdk_version to Adoptium releases are not 1:1 within the API, and therefore will be grouped into different release lists. As in this case we might re-spin a release, this would modify the adopt_build_number but would map to the same openjdk_version since they are built from the same tag of the OpenJDK repo, and would map to the same version in the upstream project. [1] https://github.com/adoptium/api.adoptium.net/issues/829 Should fix JENKINS-72319 Unable to install JDK 21.0. --- adoptopenjdk.groovy | 77 +++++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 31 deletions(-) diff --git a/adoptopenjdk.groovy b/adoptopenjdk.groovy index 3f257dc..51eaf17 100755 --- a/adoptopenjdk.groovy +++ b/adoptopenjdk.groovy @@ -41,41 +41,56 @@ class ListAdoptOpenJDK { private JSONArray getReleases(JSONArray available_releases, String jvm_impl) { JSONArray result = new JSONArray() - String openjdk_impl = jvm_impl.toLowerCase() available_releases.each { feature_version -> - JSONObject r = new JSONObject() - r.put("name", "OpenJDK " + feature_version + " - " + jvm_impl) - JSONArray releases = new JSONArray() - int page = 0 - boolean keepGoing = true - while (keepGoing) { - Page a = wc.getPage(API_URL + "/assets/feature_releases/" + feature_version + "/ga?vendor=eclipse&project=jdk&image_type=jdk&sort_method=DEFAULT&sort_order=DESC&page_size=20&page=" + (page++) + "&jvm_impl=" + openjdk_impl) - WebResponse ar = a.getWebResponse() - if (ar.getStatusCode() == 200) { - JSONArray assets = JSONArray.fromObject(ar.getContentAsString()) - releases.addAll(assets.collect { - [ - release_name: it.release_name, - openjdk_impl: openjdk_impl, - binaries : it.binaries.collect { - [ - architecture: it.architecture, - os : it.os, - openjdk_impl: it.jvm_impl, - binary_link : it.package.link - ] - } - ] - }) - } else { - keepGoing = false - } - } - r.put("releases", releases) + JSONObject r = getRelease(feature_version as String, jvm_impl) result.add(r) } return result } + + private JSONObject getRelease(String feature_version, String jvm_impl){ + String openjdk_impl = jvm_impl.toLowerCase() + JSONObject r = new JSONObject() + r.put("name", "OpenJDK " + feature_version + " - " + jvm_impl) + Map releasesMap = new LinkedHashMap<>(); + int page = 0 + boolean keepGoing = true + while (keepGoing) { + Page a = wc.getPage(API_URL + "/assets/feature_releases/" + feature_version + "/ga?vendor=eclipse&project=jdk&image_type=jdk&sort_method=DEFAULT&sort_order=DESC&page_size=20&page=" + (page++) + "&jvm_impl=" + openjdk_impl) + WebResponse ar = a.getWebResponse() + if (ar.getStatusCode() == 200) { + JSONArray assets = JSONArray.fromObject(ar.getContentAsString()) + assets.forEach { JSONObject asset -> releasesMap.merge(asset.release_name as String, asset, { v1, v2 -> + if (v1.version_data?.adopt_build_number > v1.version_data?.adopt_build_number){ + v1.binaries.addAll(v2.binaries); + return v1; + } else { + v2.binaries.addAll(v1.binaries); + return v2; + } + })} + } else { + keepGoing = false + } + } + + def releases = releasesMap.values().collect { + [ + release_name: it.release_name, + openjdk_impl: openjdk_impl, + binaries : it.binaries.collect { + [ + architecture: it.architecture, + os : it.os, + openjdk_impl: it.jvm_impl, + binary_link : it.package.link + ] + } + ] + } + r.put("releases", releases) + return r + } } -new ListAdoptOpenJDK().main(); \ No newline at end of file +new ListAdoptOpenJDK().main();