Skip to content

Commit

Permalink
[Gradle] Support runtime.java 24 and 25 (elastic#119387)
Browse files Browse the repository at this point in the history
We add explicit support for running build with -Druntime.java=24 and
-Druntime.java=24) By default it takes the build that was available at
implementation time (b29 for 24 and b3 for 25)

You can pass the build number also dynamically by running your build
e.g. with

```
-Druntime.java=24 -Druntime.java.build=29
```

which will resolve java ea24 build 29

fixes elastic#118329
  • Loading branch information
breskeby authored Dec 31, 2024
1 parent 34ec706 commit f028340
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ public String url(String os, String arch, String extension) {
}
}

record EarlyAccessJdkBuild(JavaLanguageVersion languageVersion, String version, String buildNumber) implements JdkBuild {

record EarlyAccessJdkBuild(JavaLanguageVersion languageVersion) implements JdkBuild {
@Override
public String url(String os, String arch, String extension) {
String buildNumber = resolveBuildNumber(languageVersion.asInt());
return "https://download.java.net/java/early_access/jdk"
+ version
+ languageVersion.asInt()
+ "/"
+ version
+ buildNumber
+ "/GPL/openjdk-"
+ version
+ languageVersion.asInt()
+ "-ea+"
+ buildNumber
+ "_"
Expand All @@ -73,6 +73,29 @@ public String url(String os, String arch, String extension) {
+ "_bin."
+ extension;
}

private static String resolveBuildNumber(int version) {
String buildNumber = System.getProperty("runtime.java." + version + ".build");
if (buildNumber != null) {
System.out.println("buildNumber = " + buildNumber);
return buildNumber;
}
buildNumber = System.getProperty("runtime.java.build");
if (buildNumber != null) {
System.out.println("buildNumber2 = " + buildNumber);
return buildNumber;
}

switch (version) {
case 24:
// latest explicitly found build number for 24
return "29";
case 25:
return "3";
default:
throw new IllegalArgumentException("Unsupported version " + version);
}
}
}

private static final Pattern VERSION_PATTERN = Pattern.compile(
Expand All @@ -88,8 +111,8 @@ public String url(String os, String arch, String extension) {
// package private so it can be replaced by tests
List<JdkBuild> builds = List.of(
getBundledJdkBuild(),
// 23 early access
new EarlyAccessJdkBuild(JavaLanguageVersion.of(23), "23", "24")
new EarlyAccessJdkBuild(JavaLanguageVersion.of(24)),
new EarlyAccessJdkBuild(JavaLanguageVersion.of(25))
);

private JdkBuild getBundledJdkBuild() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

package org.elasticsearch.gradle.internal.toolchain

import spock.lang.Unroll

import org.gradle.api.provider.Property
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.jvm.toolchain.JavaToolchainDownload
Expand All @@ -26,6 +28,7 @@ import static org.gradle.platform.OperatingSystem.MAC_OS

abstract class AbstractToolchainResolverSpec extends Specification {

@Unroll
def "resolves #os #arch #vendor jdk #langVersion"() {
given:
def resolver = resolverImplementation()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,34 @@

package org.elasticsearch.gradle.internal.toolchain

import spock.util.environment.RestoreSystemProperties

import org.gradle.api.services.BuildServiceParameters
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.jvm.toolchain.JavaToolchainDownload

import static org.gradle.jvm.toolchain.JvmVendorSpec.ORACLE
import static org.gradle.platform.Architecture.*
import static org.gradle.platform.Architecture.AARCH64
import static org.gradle.platform.Architecture.X86_64
import static org.gradle.platform.OperatingSystem.*

class OracleOpenJdkToolchainResolverSpec extends AbstractToolchainResolverSpec {


OracleOpenJdkToolchainResolver resolverImplementation() {
var toolChain = new OracleOpenJdkToolchainResolver() {
@Override
BuildServiceParameters.None getParameters() {
return null
}
}
toolChain.builds = [
new OracleOpenJdkToolchainResolver.ReleasedJdkBuild(JavaLanguageVersion.of(20), "20", "36", "bdc68b4b9cbc4ebcb30745c85038d91d"),
new OracleOpenJdkToolchainResolver.EarlyAccessJdkBuild(JavaLanguageVersion.of(21), "21", "6")
]
toolChain.builds = toolChain.builds.findAll { it instanceof OracleOpenJdkToolchainResolver.EarlyAccessJdkBuild } + [
new OracleOpenJdkToolchainResolver.ReleasedJdkBuild(
JavaLanguageVersion.of(20),
"20",
"36",
"bdc68b4b9cbc4ebcb30745c85038d91d"
)]
toolChain
}

Expand All @@ -44,23 +52,67 @@ class OracleOpenJdkToolchainResolverSpec extends AbstractToolchainResolverSpec {
[20, anyVendor(), LINUX, AARCH64, "https://download.oracle.com/java/GA/jdk20/bdc68b4b9cbc4ebcb30745c85038d91d/36/GPL/openjdk-20_linux-aarch64_bin.tar.gz"],
[20, anyVendor(), WINDOWS, X86_64, "https://download.oracle.com/java/GA/jdk20/bdc68b4b9cbc4ebcb30745c85038d91d/36/GPL/openjdk-20_windows-x64_bin.zip"],
// https://download.java.net/java/early_access/jdk23/23/GPL/openjdk-23-ea+23_macos-aarch64_bin.tar.gz
[21, ORACLE, MAC_OS, X86_64, "https://download.java.net/java/early_access/jdk21/21/GPL/openjdk-21-ea+6_macos-x64_bin.tar.gz"],
[21, ORACLE, MAC_OS, AARCH64, "https://download.java.net/java/early_access/jdk21/21/GPL/openjdk-21-ea+6_macos-aarch64_bin.tar.gz"],
[21, ORACLE, LINUX, X86_64, "https://download.java.net/java/early_access/jdk21/21/GPL/openjdk-21-ea+6_linux-x64_bin.tar.gz"],
[21, ORACLE, LINUX, AARCH64, "https://download.java.net/java/early_access/jdk21/21/GPL/openjdk-21-ea+6_linux-aarch64_bin.tar.gz"],
[21, ORACLE, WINDOWS, X86_64, "https://download.java.net/java/early_access/jdk21/21/GPL/openjdk-21-ea+6_windows-x64_bin.zip"],
[21, anyVendor(), MAC_OS, X86_64, "https://download.java.net/java/early_access/jdk21/21/GPL/openjdk-21-ea+6_macos-x64_bin.tar.gz"],
[21, anyVendor(), MAC_OS, AARCH64, "https://download.java.net/java/early_access/jdk21/21/GPL/openjdk-21-ea+6_macos-aarch64_bin.tar.gz"],
[21, anyVendor(), LINUX, X86_64, "https://download.java.net/java/early_access/jdk21/21/GPL/openjdk-21-ea+6_linux-x64_bin.tar.gz"],
[21, anyVendor(), LINUX, AARCH64, "https://download.java.net/java/early_access/jdk21/21/GPL/openjdk-21-ea+6_linux-aarch64_bin.tar.gz"],
[21, anyVendor(), WINDOWS, X86_64, "https://download.java.net/java/early_access/jdk21/21/GPL/openjdk-21-ea+6_windows-x64_bin.zip"]
]
[24, ORACLE, MAC_OS, X86_64, "https://download.java.net/java/early_access/jdk24/29/GPL/openjdk-24-ea+29_macos-x64_bin.tar.gz"],
[24, ORACLE, MAC_OS, AARCH64, "https://download.java.net/java/early_access/jdk24/29/GPL/openjdk-24-ea+29_macos-aarch64_bin.tar.gz"],
[24, ORACLE, LINUX, X86_64, "https://download.java.net/java/early_access/jdk24/29/GPL/openjdk-24-ea+29_linux-x64_bin.tar.gz"],
[24, ORACLE, LINUX, AARCH64, "https://download.java.net/java/early_access/jdk24/29/GPL/openjdk-24-ea+29_linux-aarch64_bin.tar.gz"],
[24, ORACLE, WINDOWS, X86_64, "https://download.java.net/java/early_access/jdk24/29/GPL/openjdk-24-ea+29_windows-x64_bin.zip"],
[24, anyVendor(), MAC_OS, X86_64, "https://download.java.net/java/early_access/jdk24/29/GPL/openjdk-24-ea+29_macos-x64_bin.tar.gz"],
[24, anyVendor(), MAC_OS, AARCH64, "https://download.java.net/java/early_access/jdk24/29/GPL/openjdk-24-ea+29_macos-aarch64_bin.tar.gz"],
[24, anyVendor(), LINUX, X86_64, "https://download.java.net/java/early_access/jdk24/29/GPL/openjdk-24-ea+29_linux-x64_bin.tar.gz"],
[24, anyVendor(), LINUX, AARCH64, "https://download.java.net/java/early_access/jdk24/29/GPL/openjdk-24-ea+29_linux-aarch64_bin.tar.gz"],
[24, anyVendor(), WINDOWS, X86_64, "https://download.java.net/java/early_access/jdk24/29/GPL/openjdk-24-ea+29_windows-x64_bin.zip"]]
}

@RestoreSystemProperties
def "can provide build number for ea versions"() {
given:
System.setProperty('runtime.java.build', "42")
System.setProperty('runtime.java.25.build', "13")
def resolver = resolverImplementation()

when:
Optional<JavaToolchainDownload> download = resolver.resolve(
request(
JavaLanguageVersion.of(version),
vendor,
platform(os, arch)
)
)

then:
download.get().uri == URI.create(expectedUrl)

where:
version | vendor | os | arch | expectedUrl
24 | ORACLE | MAC_OS | X86_64 | urlPrefix(24) + "42/GPL/openjdk-24-ea+42_macos-x64_bin.tar.gz"
24 | ORACLE | MAC_OS | AARCH64 | urlPrefix(24) + "42/GPL/openjdk-24-ea+42_macos-aarch64_bin.tar.gz"
24 | ORACLE | LINUX | X86_64 | urlPrefix(24) + "42/GPL/openjdk-24-ea+42_linux-x64_bin.tar.gz"
24 | ORACLE | LINUX | AARCH64 | urlPrefix(24) + "42/GPL/openjdk-24-ea+42_linux-aarch64_bin.tar.gz"
24 | ORACLE | WINDOWS | X86_64 | urlPrefix(24) + "42/GPL/openjdk-24-ea+42_windows-x64_bin.zip"
24 | anyVendor() | MAC_OS | X86_64 | urlPrefix(24) + "42/GPL/openjdk-24-ea+42_macos-x64_bin.tar.gz"
24 | anyVendor() | MAC_OS | AARCH64 | urlPrefix(24) + "42/GPL/openjdk-24-ea+42_macos-aarch64_bin.tar.gz"
24 | anyVendor() | LINUX | X86_64 | urlPrefix(24) + "42/GPL/openjdk-24-ea+42_linux-x64_bin.tar.gz"
24 | anyVendor() | LINUX | AARCH64 | urlPrefix(24) + "42/GPL/openjdk-24-ea+42_linux-aarch64_bin.tar.gz"
24 | anyVendor() | WINDOWS | X86_64 | urlPrefix(24) + "42/GPL/openjdk-24-ea+42_windows-x64_bin.zip"
25 | ORACLE | MAC_OS | X86_64 | urlPrefix(25) + "13/GPL/openjdk-25-ea+13_macos-x64_bin.tar.gz"
25 | ORACLE | MAC_OS | AARCH64 | urlPrefix(25) + "13/GPL/openjdk-25-ea+13_macos-aarch64_bin.tar.gz"
25 | ORACLE | LINUX | X86_64 | urlPrefix(25) + "13/GPL/openjdk-25-ea+13_linux-x64_bin.tar.gz"
25 | ORACLE | LINUX | AARCH64 | urlPrefix(25) + "13/GPL/openjdk-25-ea+13_linux-aarch64_bin.tar.gz"
25 | ORACLE | WINDOWS | X86_64 | urlPrefix(25) + "13/GPL/openjdk-25-ea+13_windows-x64_bin.zip"
25 | anyVendor() | MAC_OS | X86_64 | urlPrefix(25) + "13/GPL/openjdk-25-ea+13_macos-x64_bin.tar.gz"
25 | anyVendor() | MAC_OS | AARCH64 | urlPrefix(25) + "13/GPL/openjdk-25-ea+13_macos-aarch64_bin.tar.gz"
25 | anyVendor() | LINUX | X86_64 | urlPrefix(25) + "13/GPL/openjdk-25-ea+13_linux-x64_bin.tar.gz"
25 | anyVendor() | LINUX | AARCH64 | urlPrefix(25) + "13/GPL/openjdk-25-ea+13_linux-aarch64_bin.tar.gz"
25 | anyVendor() | WINDOWS | X86_64 | urlPrefix(25) + "13/GPL/openjdk-25-ea+13_windows-x64_bin.zip"
}

private static String urlPrefix(int i) {
return "https://download.java.net/java/early_access/jdk" + i + "/"
}

def unsupportedRequests() {
[
[20, ORACLE, WINDOWS, AARCH64]
]
[[20, ORACLE, WINDOWS, AARCH64]]
}

}

0 comments on commit f028340

Please sign in to comment.