Skip to content

Commit

Permalink
Download of JDK from the Elastic catalog instead of Adoptium (#15514)
Browse files Browse the repository at this point in the history
* 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 73daec0)
  • Loading branch information
andsel authored and logstashmachine committed Oct 30, 2023
1 parent 6e0bd72 commit bb44ab9
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bb44ab9

Please sign in to comment.