+import groovy.json.JsonBuilder
+import groovy.json.JsonSlurper
import org.apache.tools.ant.filters.ReplaceTokens
import org.sonar.build.LicenseReader
dependencyConfiguration = 'appLicenses'
}
+tasks.register('downloadJres') {
+ doLast {
+ def jresMetadata = new JsonSlurper().parse(file(layout.projectDirectory.dir('src/main/resources/jres-metadata.json').asFile))
+ jresMetadata.each { jre ->
+ downloadJreFromAdoptium(jre.os, jre.arch, jre.filename, jre.sha256)
+ }
+ }
+}
+
task zip(type: Zip, dependsOn: [configurations.compileClasspath]) {
duplicatesStrategy DuplicatesStrategy.EXCLUDE
def archiveDir = "sonarqube-$project.version"
+ dependsOn tasks.downloadJres
+ into("${archiveDir}/jres") {
+ from(layout.buildDirectory.dir('jres'))
+ }
+
if(release) {
dependsOn tasks.downloadLicenses
into("${archiveDir}/") {
// Check the size of the archive
zip.doLast {
def minLength = 340000000
- def maxLength = 476000000
+ def maxLength = 727000000
def length = archiveFile.get().asFile.length()
if (length < minLength)
}
}
}
+
+String.metaClass.urlEncode = { -> URLEncoder.encode(delegate as String, 'UTF-8') }
+ext {
+ WINDOWS = 'windows'
+ MAC = 'mac'
+ ALPINE_ADOPTIUM = 'alpine-linux'
+ ALPINE = 'alpine'
+}
+
+/**
+ * Run this task only when you want to update embedded JREs metadata. Please double check the generated file jres-metadata.json before committing.
+ */
+tasks.register('updateJresMetadata') {
+ doLast {
+ // download JSON file from Adoptium API
+ URL apiUrl = new URL("https://api.adoptium.net/v3/assets/release_name/eclipse/${jre_release_name.urlEncode()}?heap_size=normal&image_type=jre&project=jdk")
+ def response = new JsonSlurper().parse(apiUrl)
+
+ def metadataContent = []
+
+ def supportedOsAndArch = [[os:'linux', arch:'x64'], [os:'linux', arch:'aarch64'], [os:ext.ALPINE_ADOPTIUM, arch:'x64'], [os: ext.WINDOWS, arch:'x64'], [os:ext.MAC, arch:'x64'], [os:'mac', arch:'aarch64']]
+
+ for (jreFlavor in supportedOsAndArch) {
+ var candidates = response.binaries.findAll {
+ it.os == jreFlavor.os && it.architecture == jreFlavor.arch
+ }
+ assert candidates.size() == 1, "Expected one JRE package for ${jreFlavor.os} ${jreFlavor.arch} but got ${candidates.size()}"
+ var jre = candidates[0]
+ metadataContent << [
+ 'id': UUID.randomUUID(),
+ 'filename': jre.package.name,
+ 'sha256': jre.package.checksum,
+ 'javaPath': "${jre_release_name}-jre" + (jreFlavor.os == ext.MAC ? '/Contents/Home' : '') + '/bin/java' + (jreFlavor.os == ext.WINDOWS ? '.exe' : ''),
+ 'os': jreFlavor.os.replace(ext.ALPINE_ADOPTIUM, ext.ALPINE),
+ 'arch': jreFlavor.arch
+ ]
+ }
+
+ def jresMetadata = file(layout.projectDirectory.dir('src/main/resources/jres-metadata.json').asFile)
+ jresMetadata.text = new JsonBuilder(metadataContent).toPrettyString()
+ }
+}
+
+def downloadJreFromAdoptium(os, arch, filename, sha256) {
+ def jreFile = layout.buildDirectory.file("jres/${filename}")
+ download.run {
+ src "https://api.adoptium.net/v3/binary/version/${jre_release_name.urlEncode()}/${os.replace(ext.ALPINE, ext.ALPINE_ADOPTIUM).urlEncode()}/${arch.urlEncode()}/jre/hotspot/normal/eclipse?project=jdk"
+ dest jreFile
+ overwrite false
+ }
+ verifyChecksum.run {
+ src jreFile
+ algorithm 'SHA-256'
+ checksum sha256
+ }
+}
\ No newline at end of file
--- /dev/null
+[
+ {
+ "id": "9fe68398-f6a1-4c70-993f-72253d2704b0",
+ "filename": "OpenJDK17U-jre_x64_linux_hotspot_17.0.11_9.tar.gz",
+ "sha256": "bcb1b7b8ad68c93093f09b591b7cb17161d39891f7d29d33a586f5a328603707",
+ "javaPath": "jdk-17.0.11+9-jre/bin/java",
+ "os": "linux",
+ "arch": "x64"
+ },
+ {
+ "id": "a9b05fc0-56eb-4a8e-917a-535cf885e34e",
+ "filename": "OpenJDK17U-jre_aarch64_linux_hotspot_17.0.11_9.tar.gz",
+ "sha256": "ccfa23c25790475c84df983cc5f729b94c04d9ea9863912deb15c6266782cf16",
+ "javaPath": "jdk-17.0.11+9-jre/bin/java",
+ "os": "linux",
+ "arch": "aarch64"
+ },
+ {
+ "id": "9e1c89a4-fa86-453c-8fa4-716c1be6ceae",
+ "filename": "OpenJDK17U-jre_x64_alpine-linux_hotspot_17.0.11_9.tar.gz",
+ "sha256": "b5dffd0be08c464d9c3903e2947508c1a5c21804ea1cff5556991a2a47d617d8",
+ "javaPath": "jdk-17.0.11+9-jre/bin/java",
+ "os": "alpine",
+ "arch": "x64"
+ },
+ {
+ "id": "29a1a704-026c-4c58-9b81-ae9bc0ab2961",
+ "filename": "OpenJDK17U-jre_x64_windows_hotspot_17.0.11_9.zip",
+ "sha256": "4bafe2e94439c8193fc8c68247cb0dbaf4e80265b903288f63f128304f129bbe",
+ "javaPath": "jdk-17.0.11+9-jre/bin/java.exe",
+ "os": "windows",
+ "arch": "x64"
+ },
+ {
+ "id": "8efcd6d9-3552-45a1-84aa-8ccf00057ae6",
+ "filename": "OpenJDK17U-jre_x64_mac_hotspot_17.0.11_9.tar.gz",
+ "sha256": "232c40bebd6ddbb673862e86e7e6e09bcfe399e5a53c8a6b77bf1ceab8edefd0",
+ "javaPath": "jdk-17.0.11+9-jre/Contents/Home/bin/java",
+ "os": "mac",
+ "arch": "x64"
+ },
+ {
+ "id": "54f81f6e-212c-4cb5-a9cf-7c146a593351",
+ "filename": "OpenJDK17U-jre_aarch64_mac_hotspot_17.0.11_9.tar.gz",
+ "sha256": "003d3e0a65a2f0633b8bfed42be133724b490acb323c174c708d3a446d5fc660",
+ "javaPath": "jdk-17.0.11+9-jre/Contents/Home/bin/java",
+ "os": "mac",
+ "arch": "aarch64"
+ }
+]
\ No newline at end of file