Skip to content

Commit

Permalink
Update bundled JDK to Java 22 (elastic#106482)
Browse files Browse the repository at this point in the history
# Conflicts:
#	build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/toolchain/OracleOpenJdkToolchainResolver.java
  • Loading branch information
mark-vieira committed Mar 19, 2024
1 parent c7b41ac commit 1b29c7d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import org.apache.commons.compress.utils.Lists;
import org.gradle.jvm.toolchain.JavaLanguageVersion;
import org.gradle.jvm.toolchain.JavaToolchainDownload;
import org.gradle.jvm.toolchain.JavaToolchainRequest;
Expand All @@ -21,25 +20,25 @@
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.util.Comparator;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.StreamSupport;

import static org.gradle.jvm.toolchain.JavaToolchainDownload.fromUri;

public abstract class AdoptiumJdkToolchainResolver extends AbstractCustomJavaToolchainResolver {

// package protected for better testing
final Map<AdoptiumVersionRequest, Optional<AdoptiumVersionInfo>> CACHED_SEMVERS = new ConcurrentHashMap<>();
final Map<AdoptiumVersionRequest, Optional<String>> CACHED_RELEASES = new ConcurrentHashMap<>();

@Override
public Optional<JavaToolchainDownload> resolve(JavaToolchainRequest request) {
if (requestIsSupported(request) == false) {
return Optional.empty();
}
AdoptiumVersionRequest versionRequestKey = toVersionRequest(request);
Optional<AdoptiumVersionInfo> versionInfo = CACHED_SEMVERS.computeIfAbsent(
Optional<String> versionInfo = CACHED_RELEASES.computeIfAbsent(
versionRequestKey,
(r) -> resolveAvailableVersion(versionRequestKey)
);
Expand All @@ -54,12 +53,12 @@ private AdoptiumVersionRequest toVersionRequest(JavaToolchainRequest request) {
return new AdoptiumVersionRequest(platform, arch, javaLanguageVersion);
}

private Optional<AdoptiumVersionInfo> resolveAvailableVersion(AdoptiumVersionRequest requestKey) {
private Optional<String> resolveAvailableVersion(AdoptiumVersionRequest requestKey) {
ObjectMapper mapper = new ObjectMapper();
try {
int languageVersion = requestKey.languageVersion.asInt();
URL source = new URL(
"https://api.adoptium.net/v3/info/release_versions?architecture="
"https://api.adoptium.net/v3/info/release_names?architecture="
+ requestKey.arch
+ "&image_type=jdk&os="
+ requestKey.platform
Expand All @@ -71,14 +70,8 @@ private Optional<AdoptiumVersionInfo> resolveAvailableVersion(AdoptiumVersionReq
+ ")"
);
JsonNode jsonNode = mapper.readTree(source);
JsonNode versionsNode = jsonNode.get("versions");
return Optional.of(
Lists.newArrayList(versionsNode.iterator())
.stream()
.map(this::toVersionInfo)
.max(Comparator.comparing(AdoptiumVersionInfo::semver))
.get()
);
JsonNode versionsNode = jsonNode.get("releases");
return StreamSupport.stream(versionsNode.spliterator(), false).map(JsonNode::textValue).findFirst();
} catch (FileNotFoundException e) {
// request combo not supported (e.g. aarch64 + windows
return Optional.empty();
Expand All @@ -87,21 +80,10 @@ private Optional<AdoptiumVersionInfo> resolveAvailableVersion(AdoptiumVersionReq
}
}

private AdoptiumVersionInfo toVersionInfo(JsonNode node) {
return new AdoptiumVersionInfo(
node.get("build").asInt(),
node.get("major").asInt(),
node.get("minor").asInt(),
node.get("openjdk_version").asText(),
node.get("security").asInt(),
node.get("semver").asText()
);
}

private URI resolveDownloadURI(AdoptiumVersionRequest request, AdoptiumVersionInfo versionInfo) {
private URI resolveDownloadURI(AdoptiumVersionRequest request, String version) {
return URI.create(
"https://api.adoptium.net/v3/binary/version/jdk-"
+ versionInfo.semver
"https://api.adoptium.net/v3/binary/version/"
+ version
+ "/"
+ request.platform
+ "/"
Expand All @@ -118,7 +100,5 @@ private boolean requestIsSupported(JavaToolchainRequest request) {
return anyVendorOr(request.getJavaToolchainSpec().getVendor().get(), JvmVendorSpec.ADOPTIUM);
}

record AdoptiumVersionInfo(int build, int major, int minor, String openjdkVersion, int security, String semver) {}

record AdoptiumVersionRequest(String platform, String arch, JavaLanguageVersion languageVersion) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ package org.elasticsearch.gradle.internal.toolchain
import org.gradle.api.services.BuildServiceParameters
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.jvm.toolchain.JavaToolchainResolver
import org.gradle.platform.OperatingSystem

import static org.elasticsearch.gradle.internal.toolchain.AbstractCustomJavaToolchainResolver.toArchString
import static org.elasticsearch.gradle.internal.toolchain.AbstractCustomJavaToolchainResolver.toOsString
Expand All @@ -38,12 +37,7 @@ class AdoptiumJdkToolchainResolverSpec extends AbstractToolchainResolverSpec {
toOsString(it[2], it[1]),
toArchString(it[3]),
languageVersion);
resolver.CACHED_SEMVERS.put(request, Optional.of(new AdoptiumJdkToolchainResolver.AdoptiumVersionInfo(languageVersion.asInt(),
1,
1,
"" + languageVersion.asInt() + ".1.1.1+37",
0, "" + languageVersion.asInt() + ".1.1.1+37.1"
)))
resolver.CACHED_RELEASES.put(request, Optional.of('jdk-' + languageVersion.asInt() + '.1.1.1+37.1'))

}
return resolver
Expand Down
2 changes: 1 addition & 1 deletion build-tools-internal/version.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ elasticsearch = 8.13.0
lucene = 9.10.0

bundled_jdk_vendor = openjdk
bundled_jdk = 21.0.2+13@f2283984656d49d69e91c558476027ac
bundled_jdk = 22+36@830ec9fcccef480bb3e73fb7ecafe059
# optional dependencies
spatial4j = 0.7
jts = 1.15.0
Expand Down
26 changes: 13 additions & 13 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1684,25 +1684,25 @@
<sha256 value="0a4aa0f2606bd6292a7ccd7d67a0db914bf5874dfb8a6184df3e6d63cdc93702" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="openjdk_21" name="linux" version="21.0.2">
<artifact name="linux-21.0.2-aarch64.tar.gz">
<sha256 value="08db1392a48d4eb5ea5315cf8f18b89dbaf36cda663ba882cf03c704c9257ec2" origin="Generated by Gradle"/>
<component group="openjdk_22" name="linux" version="22">
<artifact name="linux-22-aarch64.tar.gz">
<sha256 value="b272e3228d2a3e04b126d54844d33cc6d137256490526cd08679d7023d07d4b7" origin="Generated by Gradle"/>
</artifact>
<artifact name="linux-21.0.2-x64.tar.gz">
<sha256 value="a2def047a73941e01a73739f92755f86b895811afb1f91243db214cff5bdac3f" origin="Generated by Gradle"/>
<artifact name="linux-22-x64.tar.gz">
<sha256 value="4d65cc6ed28711768fd72c2043a7925f7c83f5f51bb64970bd9d52f7791fc6ac" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="openjdk_21" name="macos" version="21.0.2">
<artifact name="macos-21.0.2-aarch64.tar.gz">
<sha256 value="b3d588e16ec1e0ef9805d8a696591bd518a5cea62567da8f53b5ce32d11d22e4" origin="Generated by Gradle"/>
<component group="openjdk_22" name="macos" version="22">
<artifact name="macos-22-aarch64.tar.gz">
<sha256 value="d10f82429d01047968c52c7975c326388cb5d212791e14c1de21c987463a4b53" origin="Generated by Gradle"/>
</artifact>
<artifact name="macos-21.0.2-x64.tar.gz">
<sha256 value="8fd09e15dc406387a0aba70bf5d99692874e999bf9cd9208b452b5d76ac922d3" origin="Generated by Gradle"/>
<artifact name="macos-22-x64.tar.gz">
<sha256 value="ae31fe10916429e3fe284266095067a5ce9fecbdc03ff1a079d20459f731ca36" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="openjdk_21" name="windows" version="21.0.2">
<artifact name="windows-21.0.2-x64.zip">
<sha256 value="b6c17e747ae78cdd6de4d7532b3164b277daee97c007d3eaa2b39cca99882664" origin="Generated by Gradle"/>
<component group="openjdk_22" name="windows" version="22">
<artifact name="windows-22-x64.zip">
<sha256 value="8f5138fecb53c08c20abd4fa6812f9400051f3852582a2142ffda0dff73a5824" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.abego.treelayout" name="org.abego.treelayout.core" version="1.0.3">
Expand Down

0 comments on commit 1b29c7d

Please sign in to comment.