Completed Java validation for windows.

Possible paths are pulled from the registry and JAVA_HOME. These are sorted by version and whether they point to a JRE or JDK. Each path will be validated using an experimental option which yields the arch of the binary. The first one to  be validated will be selected and returned.
pull/1/head
Daniel Scalzi 2018-03-28 17:13:11 -04:00
parent 4fd202d180
commit 4b2cac1eff
No known key found for this signature in database
GPG Key ID: 5CA2F145B63535F9
1 changed files with 50 additions and 11 deletions

View File

@ -4,7 +4,17 @@ const path = require('path')
const Registry = require('winreg')
/**
* WIP -> get a valid x64 Java path on windows.
* Attempts to find a valid x64 installation of Java on Windows machines.
* Possible paths will be pulled from the registry and the JAVA_HOME environment
* variable. The paths will be sorted with higher versions preceeding lower, and
* JREs preceeding JDKs. The binaries at the sorted paths will then be validated.
* The first validated is returned.
*
* Higher versions > Lower versions
* If versions are equal, JRE > JDK.
*
* @returns {string} The root path of a valid x64 Java installation. If none are
* found, null is returned.
*/
async function _win32Validate(){
@ -20,16 +30,35 @@ async function _win32Validate(){
}
// Convert path set to an array for processing.
const pathArr = Array.from(pathSet)
let pathArr = Array.from(pathSet)
console.log(pathArr) // DEBUGGING
// TODO - Determine best candidate (based on version, etc).
// Sorts array. Higher version numbers preceed lower. JRE preceeds JDK.
pathArr = pathArr.sort((a, b) => {
// Note that Java 9+ uses semver and that will need to be accounted for in
// the future.
const aVer = parseInt(a.split('_')[1])
const bVer = parseInt(b.split('_')[1])
if(bVer === aVer){
return a.indexOf('jdk') > -1 ? 1 : 0
} else {
return bVer - aVer
}
})
console.log(pathArr) // DEBUGGING
// Validate that the binary is actually x64.
for(let i=0; i<pathArr.length; i++) {
let res = await _validateBinary(pathArr[i])
if(res){
return pathArr[i]
}
}
let res = await _validateBinary(pathArr[0]) // DEBUGGING
console.log(res) // DEBUGGING
// No suitable candidates found.
return null;
}
@ -168,29 +197,39 @@ function _scanRegistry(){
* WIP -> get a valid x64 Java path on macOS.
*/
function _darwinValidate(){
return null
}
/**
* WIP -> get a valid x64 Java path on linux.
*/
function _linuxValidate(){
return null
}
// This will eventually return something.
async function validate(){
let res = null
const opSys = process.platform
if(opSys === 'win32'){
await _win32Validate()
res = await _win32Validate()
} else if(opSys === 'darwin'){
_darwinValidate()
res = _darwinValidate()
} else if(opSys === 'linux'){
_linuxValidate()
res = _linuxValidate()
}
return res;
}
validate()
async function test(){
console.log(await validate())
}
test()
module.exports = {
validate