Use corretto on macOS since they use an older version of Xcode. (#70)

Vendor name is now displayed above the selected Java version on the settings page. This is to allow for easier differentiation between versions (ex. Amazon Corretto vs AdoptOpenJDK).
This commit is contained in:
Daniel Scalzi 2020-09-08 21:25:19 -04:00
parent cc86f2a257
commit 9a2c1fd9b9
No known key found for this signature in database
GPG Key ID: D18EA3FB4B142A57
2 changed files with 64 additions and 3 deletions

View File

@ -266,7 +266,11 @@ class JavaGuard extends EventEmitter {
*/ */
/** /**
* Fetch the last open JDK binary. Uses https://api.adoptopenjdk.net/ * Fetch the last open JDK binary.
*
* HOTFIX: Uses Corretto 8 for macOS.
* See: https://github.com/dscalzi/HeliosLauncher/issues/70
* See: https://github.com/AdoptOpenJDK/openjdk-support/issues/101
* *
* @param {string} major The major version of Java to fetch. * @param {string} major The major version of Java to fetch.
* *
@ -274,6 +278,15 @@ class JavaGuard extends EventEmitter {
*/ */
static _latestOpenJDK(major = '8'){ static _latestOpenJDK(major = '8'){
if(process.platform === 'darwin') {
return this._latestCorretto(major)
} else {
return this._latestAdoptOpenJDK(major)
}
}
static _latestAdoptOpenJDK(major) {
const sanitizedOS = process.platform === 'win32' ? 'windows' : (process.platform === 'darwin' ? 'mac' : process.platform) const sanitizedOS = process.platform === 'win32' ? 'windows' : (process.platform === 'darwin' ? 'mac' : process.platform)
const url = `https://api.adoptopenjdk.net/v2/latestAssets/nightly/openjdk${major}?os=${sanitizedOS}&arch=x64&heap_size=normal&openjdk_impl=hotspot&type=jre` const url = `https://api.adoptopenjdk.net/v2/latestAssets/nightly/openjdk${major}?os=${sanitizedOS}&arch=x64&heap_size=normal&openjdk_impl=hotspot&type=jre`
@ -291,6 +304,48 @@ class JavaGuard extends EventEmitter {
} }
}) })
}) })
}
static _latestCorretto(major) {
let sanitizedOS, ext
switch(process.platform) {
case 'win32':
sanitizedOS = 'windows'
ext = 'zip'
break
case 'darwin':
sanitizedOS = 'macos'
ext = 'tar.gz'
break
case 'linux':
sanitizedOS = 'linux'
ext = 'tar.gz'
break
default:
sanitizedOS = process.platform
ext = 'tar.gz'
break
}
const url = `https://corretto.aws/downloads/latest/amazon-corretto-${major}-x64-${sanitizedOS}-jdk.${ext}`
return new Promise((resolve, reject) => {
request.head({url, json: true}, (err, resp) => {
if(!err && resp.statusCode === 200){
resolve({
uri: url,
size: parseInt(resp.headers['content-length']),
name: url.substr(url.lastIndexOf('/')+1)
})
} else {
resolve(null)
}
})
})
} }
/** /**
@ -455,6 +510,11 @@ class JavaGuard extends EventEmitter {
} */ } */
} }
} }
// Space included so we get only the vendor.
} else if(props[i].lastIndexOf('java.vendor ') > -1) {
let vendorName = props[i].split('=')[1].trim()
console.log(props[i].trim())
meta.vendor = vendorName
} }
} }

View File

@ -1139,10 +1139,11 @@ function populateJavaExecDetails(execPath){
const jg = new JavaGuard(DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer()).getMinecraftVersion()) const jg = new JavaGuard(DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer()).getMinecraftVersion())
jg._validateJavaBinary(execPath).then(v => { jg._validateJavaBinary(execPath).then(v => {
if(v.valid){ if(v.valid){
const vendor = v.vendor != null ? ` (${v.vendor})` : ''
if(v.version.major < 9) { if(v.version.major < 9) {
settingsJavaExecDetails.innerHTML = `Selected: Java ${v.version.major} Update ${v.version.update} (x${v.arch})` settingsJavaExecDetails.innerHTML = `Selected: Java ${v.version.major} Update ${v.version.update} (x${v.arch})${vendor}`
} else { } else {
settingsJavaExecDetails.innerHTML = `Selected: Java ${v.version.major}.${v.version.minor}.${v.version.revision} (x${v.arch})` settingsJavaExecDetails.innerHTML = `Selected: Java ${v.version.major}.${v.version.minor}.${v.version.revision} (x${v.arch})${vendor}`
} }
} else { } else {
settingsJavaExecDetails.innerHTML = 'Invalid Selection' settingsJavaExecDetails.innerHTML = 'Invalid Selection'