Skip to content

Commit

Permalink
Use Azul Zulu JDK8 distribution instead of Adoptium/OpenJDK on MacOS …
Browse files Browse the repository at this point in the history
…with Apple Silicon (#87733) (#87934)

Co-authored-by: Amey Kulkarni <ameykulkarni@live.in>
  • Loading branch information
mark-vieira and ap-kulkarni committed Jun 22, 2022
1 parent 5b8b981 commit 15f5229
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class Jdk implements Buildable, Iterable<File> {

private static final List<String> ALLOWED_ARCHITECTURES = List.of("aarch64", "x64");
private static final List<String> ALLOWED_VENDORS = List.of("adoptium", "openjdk");
private static final List<String> ALLOWED_VENDORS = List.of("adoptium", "openjdk", "zulu");
private static final List<String> 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}))?"
Expand All @@ -37,6 +37,7 @@ public class Jdk implements Buildable, Iterable<File> {
private final Property<String> version;
private final Property<String> platform;
private final Property<String> architecture;
private final Property<String> distributionVersion;
private String baseVersion;
private String major;
private String build;
Expand All @@ -49,6 +50,7 @@ public class Jdk implements Buildable, Iterable<File> {
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() {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -179,6 +189,7 @@ void finalizeValues() {
platform.finalizeValue();
vendor.finalizeValue();
architecture.finalizeValue();
distributionVersion.finalizeValue();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class JdkDownloadPlugin implements Plugin<Project> {

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";
Expand Down Expand Up @@ -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() + "]");
}
Expand All @@ -147,14 +159,16 @@ public static NamedDomainObjectContainer<Jdk> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
);
}

Expand Down
5 changes: 5 additions & 0 deletions modules/reindex/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions x-pack/qa/repository-old-versions/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ restResources {
}
}

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 repository-old-versions tests because we can't get the pid file on windows")
tasks.named("testingConventions").configure { enabled = false }
Expand Down

0 comments on commit 15f5229

Please sign in to comment.