Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GitHub actions #998

Merged
merged 2 commits into from
Aug 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/qz/build/JLink.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ public JLink(String targetPlatform, String arch, String gcEngine) throws IOExcep
this.javaVendor = getJavaVendor(arch);
this.targetPlatform = targetPlatform;

// jdeps and jlink require matching major JDK versions. Download if needed.
if(Constants.JAVA_VERSION.getMajorVersion() != Integer.parseInt(JAVA_MAJOR)) {
if(needsDownload(SystemUtilities.getJavaVersion(JAVA_VERSION), Constants.JAVA_VERSION)) {
log.warn("Java versions are incompatible, locating a suitable runtime for Java " + JAVA_MAJOR + "...");
String hostArch = System.getProperty("os.arch");
String hostJdk = downloadJdk(getJavaVendor(hostArch), null, hostArch, gcEngine);
Expand Down Expand Up @@ -83,6 +82,26 @@ public static void main(String ... args) throws IOException {
args.length > 2 ? args[2] : null);
}

/**
* Handle incompatibilities between JDKs, download a fresh one if needed
*/
private static boolean needsDownload(Version want, Version installed) {
// jdeps and jlink historically require matching major JDK versions. Download if needed.
boolean downloadJdk = installed.getMajorVersion() != want.getMajorVersion();

// Per JDK-8240734: Major versions checks aren't enough starting with 11.0.16+8
// see also https://github.com/adoptium/adoptium-support/issues/557
Version bad = SystemUtilities.getJavaVersion("11.0.16+8");
if(installed.greaterThanOrEqualTo(bad)) {
if(want.lessThan(bad)) {
// Force download
// Fixes "Hash of java.rmi differs from expected hash"
downloadJdk = true;
}
}
return downloadJdk;
}

private String getJavaVendor(String arch) {
String vendor;
switch(SystemUtilities.getJreArch(arch)) {
Expand Down