From 455153e73fad51d6ea905f5661629974afebbdab Mon Sep 17 00:00:00 2001 From: Mark Vieira Date: Wed, 22 Jun 2022 15:03:03 -0700 Subject: [PATCH] Use Azul Zulu JDK8 distribution instead of Adoptium/OpenJDK on MacOS with Apple Silicon (#87733) (#87935) # Conflicts: # x-pack/qa/repository-old-versions/build.gradle Co-authored-by: Amey Kulkarni --- .../java/org/elasticsearch/gradle/Jdk.java | 13 +++++++++++- .../gradle/JdkDownloadPlugin.java | 20 ++++++++++++++++--- .../gradle/JdkDownloadPluginTests.java | 2 +- modules/reindex/build.gradle | 5 +++++ 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/build-tools/src/main/java/org/elasticsearch/gradle/Jdk.java b/build-tools/src/main/java/org/elasticsearch/gradle/Jdk.java index 1a339ce54ee6a..f378f6c48af2a 100644 --- a/build-tools/src/main/java/org/elasticsearch/gradle/Jdk.java +++ b/build-tools/src/main/java/org/elasticsearch/gradle/Jdk.java @@ -23,7 +23,7 @@ public class Jdk implements Buildable, Iterable { private static final List ALLOWED_ARCHITECTURES = List.of("aarch64", "x64"); - private static final List ALLOWED_VENDORS = List.of("adoptium", "openjdk"); + private static final List ALLOWED_VENDORS = List.of("adoptium", "openjdk", "zulu"); private static final List ALLOWED_PLATFORMS = List.of("darwin", "linux", "windows", "mac"); private static final Pattern VERSION_PATTERN = Pattern.compile( "(\\d+)(\\.\\d+\\.\\d+(?:\\.\\d+)?)?\\+(\\d+(?:\\.\\d+)?)(@([a-f0-9]{32}))?" @@ -37,6 +37,7 @@ public class Jdk implements Buildable, Iterable { private final Property version; private final Property platform; private final Property architecture; + private final Property distributionVersion; private String baseVersion; private String major; private String build; @@ -49,6 +50,7 @@ public class Jdk implements Buildable, Iterable { this.version = objectFactory.property(String.class); this.platform = objectFactory.property(String.class); this.architecture = objectFactory.property(String.class); + this.distributionVersion = objectFactory.property(String.class); } public String getName() { @@ -104,6 +106,14 @@ public void setArchitecture(final String architecture) { this.architecture.set(architecture); } + public String getDistributionVersion() { + return distributionVersion.get(); + } + + public void setDistributionVersion(String distributionVersion) { + this.distributionVersion.set(distributionVersion); + } + public String getBaseVersion() { return baseVersion; } @@ -179,6 +189,7 @@ void finalizeValues() { platform.finalizeValue(); vendor.finalizeValue(); architecture.finalizeValue(); + distributionVersion.finalizeValue(); } @Override diff --git a/build-tools/src/main/java/org/elasticsearch/gradle/JdkDownloadPlugin.java b/build-tools/src/main/java/org/elasticsearch/gradle/JdkDownloadPlugin.java index 2abe42cbf3bf7..bcca5333d759d 100644 --- a/build-tools/src/main/java/org/elasticsearch/gradle/JdkDownloadPlugin.java +++ b/build-tools/src/main/java/org/elasticsearch/gradle/JdkDownloadPlugin.java @@ -26,6 +26,7 @@ public class JdkDownloadPlugin implements Plugin { public static final String VENDOR_ADOPTIUM = "adoptium"; public static final String VENDOR_OPENJDK = "openjdk"; + public static final String VENDOR_ZULU = "zulu"; private static final String REPO_NAME_PREFIX = "jdk_repo_"; private static final String EXTENSION_NAME = "jdks"; @@ -125,6 +126,17 @@ private void setupRepository(Project project, Jdk jdk) { + jdk.getBuild() + "/GPL/openjdk-[revision]_[module]-[classifier]_bin.[ext]"; } + } else if (jdk.getVendor().equals(VENDOR_ZULU)) { + repoUrl = "https://cdn.azul.com"; + if (jdk.getMajor().equals("8") && isJdkOnMacOsPlatform(jdk) && jdk.getArchitecture().equals("aarch64")) { + artifactPattern = "zulu/bin/zulu" + + jdk.getDistributionVersion() + + "-ca-jdk" + + jdk.getBaseVersion().replace("u", ".0.") + + "-[module]x_[classifier].[ext]"; + } else { + throw new GradleException("JDK vendor zulu is supported only for JDK8 on MacOS with Apple Silicon."); + } } else { throw new GradleException("Unknown JDK vendor [" + jdk.getVendor() + "]"); } @@ -147,14 +159,16 @@ public static NamedDomainObjectContainer getContainer(Project project) { } private static String dependencyNotation(Jdk jdk) { - String platformDep = jdk.getPlatform().equals("darwin") || jdk.getPlatform().equals("mac") - ? (jdk.getVendor().equals(VENDOR_ADOPTIUM) ? "mac" : "macos") - : jdk.getPlatform(); + String platformDep = isJdkOnMacOsPlatform(jdk) ? (jdk.getVendor().equals(VENDOR_ADOPTIUM) ? "mac" : "macos") : jdk.getPlatform(); String extension = jdk.getPlatform().equals("windows") ? "zip" : "tar.gz"; return groupName(jdk) + ":" + platformDep + ":" + jdk.getBaseVersion() + ":" + jdk.getArchitecture() + "@" + extension; } + private static boolean isJdkOnMacOsPlatform(Jdk jdk) { + return jdk.getPlatform().equals("darwin") || jdk.getPlatform().equals("mac"); + } + private static String groupName(Jdk jdk) { return jdk.getVendor() + "_" + jdk.getMajor(); } diff --git a/build-tools/src/test/java/org/elasticsearch/gradle/JdkDownloadPluginTests.java b/build-tools/src/test/java/org/elasticsearch/gradle/JdkDownloadPluginTests.java index 5d1c58f0a6d36..7cf0ac0201963 100644 --- a/build-tools/src/test/java/org/elasticsearch/gradle/JdkDownloadPluginTests.java +++ b/build-tools/src/test/java/org/elasticsearch/gradle/JdkDownloadPluginTests.java @@ -36,7 +36,7 @@ public void testUnknownVendor() { "11.0.2+33", "linux", "x64", - "unknown vendor [unknown] for jdk [testjdk], must be one of [adoptium, openjdk]" + "unknown vendor [unknown] for jdk [testjdk], must be one of [adoptium, openjdk, zulu]" ); } diff --git a/modules/reindex/build.gradle b/modules/reindex/build.gradle index 11b81bc681301..311b3432e05c7 100644 --- a/modules/reindex/build.gradle +++ b/modules/reindex/build.gradle @@ -93,6 +93,11 @@ jdks { } } +if (Os.isFamily(Os.FAMILY_MAC) && Architecture.current() == Architecture.AARCH64) { + jdks.legacy.vendor = 'zulu' + jdks.legacy.distributionVersion = '8.56.0.23' +} + if (Os.isFamily(Os.FAMILY_WINDOWS)) { logger.warn("Disabling reindex-from-old tests because we can't get the pid file on windows") tasks.named("javaRestTest").configure {