From bb44ab9f38084c340145a2c9f8434dde230342c4 Mon Sep 17 00:00:00 2001 From: Andrea Selva Date: Mon, 30 Oct 2023 16:24:27 +0100 Subject: [PATCH] Download of JDK from the Elastic catalog instead of Adoptium (#15514) * Adapted the JDK's download URL creation to intereact with Elastic catalog to get metadata, and return the catalog download link instead of directly pointing to Adoptium API * Silenced the Download task of JDK to print the full url (cherry picked from commit 73daec05ed1c2419885b4e5d3421c5c83355e956) --- build.gradle | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 32d0cf30315..4edf7254829 100644 --- a/build.gradle +++ b/build.gradle @@ -707,8 +707,35 @@ class JDKDetails { } String createDownloadUrl() { + return createElasticCatalogDownloadUrl() + } + + private String createElasticCatalogDownloadUrl() { + // Ask details to catalog https://jvm-catalog.elastic.co/jdk and return the url to download the JDK + + // arch x86_64 never used, only aarch64 if macos + def url = "https://jvm-catalog.elastic.co/jdk/latest_adoptiumjdk_${major}_${osName}" + + // Append the cpu's arch only if Mac on aarch64, all the other OSes doesn't have CPU extension + if (arch == "aarch64") { + url += "_${arch}" + } + println "Retrieving JDK from catalog..." + def catalogMetadataUrl = new URL(url) + def catalogConnection = catalogMetadataUrl.openConnection() + catalogConnection.requestMethod = 'GET' + assert catalogConnection.responseCode == 200 + + def metadataRetrieved = catalogConnection.content.text + println "Retrieved!" + + def catalogMetadata = new JsonSlurper().parseText(metadataRetrieved) + return catalogMetadata.url + } + + private String createAdoptDownloadUrl() { String releaseName = major > 8 ? - "jdk-${revision}+${build}": + "jdk-${revision}+${build}" : "jdk${revision}u${build}" String vendorOsName = vendorOsName(osName) switch (vendor) { @@ -772,6 +799,7 @@ tasks.register("downloadJdk", Download) { src project.ext.jdkURL onlyIfNewer true overwrite false + quiet true inputs.file("${projectDir}/versions.yml") outputs.file(project.ext.jdkDownloadLocation) dest new File(project.ext.jdkDownloadLocation)