From cb6d342c2cfdd01cce5206749064c82a86f14bb4 Mon Sep 17 00:00:00 2001 From: andsel Date: Mon, 30 Oct 2023 12:25:02 +0100 Subject: [PATCH 1/3] 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 --- build.gradle | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 32d0cf30315..8c9fd2841f2 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/latest_adoptiumjdk_17_windows + // 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 (osName == "darwin" && arch == "aarch64") { + url += "_${arch}" + } + 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) { @@ -762,6 +789,8 @@ tasks.register("downloadJdk", Download) { // find url of build artifact String artifactApiUrl = jdkDetails.createDownloadUrl() + println "DNADBG>> artifactApiUrl $artifactApiUrl}" + project.ext.set("jdkURL", System.getenv("JDK_URL") ?: artifactApiUrl) project.ext.set("jdkDownloadLocation", "${projectDir}/build/${jdkDetails.localPackageName}") project.ext.set("jdkDirectory", "${projectDir}/build/${jdkDetails.unpackedJdkName}") From b96888828b684c3f31d95893d671a188bae3553a Mon Sep 17 00:00:00 2001 From: andsel Date: Mon, 30 Oct 2023 13:56:45 +0100 Subject: [PATCH 2/3] Adds CPU specification to the catalog URL only for ARM --- build.gradle | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 8c9fd2841f2..e0883c04025 100644 --- a/build.gradle +++ b/build.gradle @@ -711,14 +711,13 @@ class JDKDetails { } private String createElasticCatalogDownloadUrl() { - // Ask details to catalog https://jvm-catalog.elastic.co/jdk/latest_adoptiumjdk_17_windows - // and return the url to download the JDK + // 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 (osName == "darwin" && arch == "aarch64") { + if (arch == "aarch64") { url += "_${arch}" } def catalogMetadataUrl = new URL(url) @@ -789,8 +788,6 @@ tasks.register("downloadJdk", Download) { // find url of build artifact String artifactApiUrl = jdkDetails.createDownloadUrl() - println "DNADBG>> artifactApiUrl $artifactApiUrl}" - project.ext.set("jdkURL", System.getenv("JDK_URL") ?: artifactApiUrl) project.ext.set("jdkDownloadLocation", "${projectDir}/build/${jdkDetails.localPackageName}") project.ext.set("jdkDirectory", "${projectDir}/build/${jdkDetails.unpackedJdkName}") From 375503847180708c3772ed8c6cc8ca022021a626 Mon Sep 17 00:00:00 2001 From: andsel Date: Mon, 30 Oct 2023 15:53:40 +0100 Subject: [PATCH 3/3] Silencend the Download task of JDK to print the full url --- build.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.gradle b/build.gradle index e0883c04025..4edf7254829 100644 --- a/build.gradle +++ b/build.gradle @@ -720,6 +720,7 @@ class JDKDetails { if (arch == "aarch64") { url += "_${arch}" } + println "Retrieving JDK from catalog..." def catalogMetadataUrl = new URL(url) def catalogConnection = catalogMetadataUrl.openConnection() catalogConnection.requestMethod = 'GET' @@ -798,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)