Handle java-home non-existent folder. More logging for JVM lookup.
This commit is contained in:
32
nodejs-packages/jvm-launch-utils/package-lock.json
generated
32
nodejs-packages/jvm-launch-utils/package-lock.json
generated
@@ -1,28 +1,28 @@
|
||||
{
|
||||
"name": "@pivotal-tools/jvm-launch-utils",
|
||||
"version": "0.0.14",
|
||||
"version": "0.0.16",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@pivotal-tools/jvm-launch-utils",
|
||||
"version": "0.0.14",
|
||||
"version": "0.0.16",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/node": "^9.4.6",
|
||||
"typescript": "^2.7.2"
|
||||
"@types/node": "^16.6.0",
|
||||
"typescript": "^4.2.4"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "9.6.39",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-9.6.39.tgz",
|
||||
"integrity": "sha512-c3OkjgNpSMdHan56WhklP0FMOk5ocilKz2Mpa0NOGzu8jw5YERjCf9FG0epYB1+TxScv/oI4uJ204u2mUg7Hcw==",
|
||||
"version": "16.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.6.0.tgz",
|
||||
"integrity": "sha512-OyiZPohMMjZEYqcVo/UJ04GyAxXOJEZO/FpzyXxcH4r/ArrVoXHf4MbUrkLp0Tz7/p1mMKpo5zJ6ZHl8XBNthQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"version": "2.9.2",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-2.9.2.tgz",
|
||||
"integrity": "sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w==",
|
||||
"version": "4.3.5",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.5.tgz",
|
||||
"integrity": "sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
@@ -35,15 +35,15 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/node": {
|
||||
"version": "9.6.39",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-9.6.39.tgz",
|
||||
"integrity": "sha512-c3OkjgNpSMdHan56WhklP0FMOk5ocilKz2Mpa0NOGzu8jw5YERjCf9FG0epYB1+TxScv/oI4uJ204u2mUg7Hcw==",
|
||||
"version": "16.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.6.0.tgz",
|
||||
"integrity": "sha512-OyiZPohMMjZEYqcVo/UJ04GyAxXOJEZO/FpzyXxcH4r/ArrVoXHf4MbUrkLp0Tz7/p1mMKpo5zJ6ZHl8XBNthQ==",
|
||||
"dev": true
|
||||
},
|
||||
"typescript": {
|
||||
"version": "2.9.2",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-2.9.2.tgz",
|
||||
"integrity": "sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w==",
|
||||
"version": "4.3.5",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.5.tgz",
|
||||
"integrity": "sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pivotal-tools/jvm-launch-utils",
|
||||
"version": "0.0.15",
|
||||
"version": "0.0.17",
|
||||
"description": "Provides utilities useful for launching Java processes from node packages.",
|
||||
"files": [
|
||||
"src",
|
||||
@@ -28,7 +28,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/spring-projects/sts4/nodejs-packages/jvm-launch-utils/README.md",
|
||||
"devDependencies": {
|
||||
"@types/node": "^9.4.6",
|
||||
"typescript": "^2.7.2"
|
||||
"@types/node": "^16.6.0",
|
||||
"typescript": "^4.2.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,9 +42,12 @@ export interface JVM {
|
||||
* The returned JVM may or may not be a JDK. Methods are provided to obtain corresponding
|
||||
* toolsjar and to check whether the JVM is a JDK.
|
||||
*/
|
||||
export function findJvm(javaHome?: string) : Promise<JVM | null> {
|
||||
export function findJvm(javaHome: string, log?: (msg: string) => void) : Promise<JVM | null> {
|
||||
if (!log) {
|
||||
log = console.log;
|
||||
}
|
||||
try {
|
||||
let javaExe = findJavaExe(javaHome);
|
||||
let javaExe = findJavaExe(javaHome, log);
|
||||
if (javaExe) {
|
||||
return getJavaInfo(javaExe).then(javaProps => new JVMImpl(
|
||||
javaProps.get("java.home"),
|
||||
@@ -62,13 +65,16 @@ export function findJvm(javaHome?: string) : Promise<JVM | null> {
|
||||
* Like findJvm, but additionally, if the found JVM is not a JDK tries to
|
||||
* find a companion JDK that may be installed alongside it.
|
||||
*/
|
||||
export function findJdk(javaHome?: string) : Promise<JVM | null> {
|
||||
return findJvm(javaHome).then(jvm => {
|
||||
export function findJdk(javaHome: string, log?: (msg: string) => void) : Promise<JVM | null> {
|
||||
if (!log) {
|
||||
log = console.log;
|
||||
}
|
||||
return findJvm(javaHome, log).then(jvm => {
|
||||
if(!jvm) {
|
||||
return null;
|
||||
}
|
||||
if (!jvm.isJdk()) {
|
||||
console.log("found jvm is not a JDK");
|
||||
log(`found JVM at location "${jvm.getJavaHome()}" is not a JDK`);
|
||||
|
||||
//Try to find a 'sibling' JDK.
|
||||
//Mainly for windows where it is common to have side-by-side install of a jre and jdk, instead of a
|
||||
@@ -79,20 +85,16 @@ export function findJdk(javaHome?: string) : Promise<JVM | null> {
|
||||
//C:\ProgramFiles\Java\jre1.8.0_161
|
||||
|
||||
let javaExe = jvm.getJavaExecutable();
|
||||
console.log("javaExe = ", javaExe);
|
||||
// javaExe example: C:\ProgramFiles\Java\jre1.8.0_161\bin\java.exe
|
||||
let jhome = jvm.getJavaHome();
|
||||
console.log("jhome = ", jhome);
|
||||
let basename : string = Path.basename(jhome);
|
||||
console.log("basename = ", basename);
|
||||
let altBasename : string = basename.replace("jre", "jdk");
|
||||
console.log("altBasename = ", altBasename);
|
||||
if (altBasename!==basename) {
|
||||
let altHome = Path.join(Path.dirname(jhome), altBasename);
|
||||
console.log("altHome = ", altHome);
|
||||
log(`Trying to find JDK corresping to currently found JRE. Checking for JDK at ${altHome}`);
|
||||
if (FS.existsSync(altHome)) {
|
||||
let altExe = Path.resolve(altHome, "bin", correctBinname("java"));
|
||||
console.log("altExe = ", altExe);
|
||||
log("altExe = " + altExe);
|
||||
return new JVMImpl(altHome, altExe, jvm.getMajorVersion());
|
||||
}
|
||||
}
|
||||
@@ -107,14 +109,20 @@ export function findJdk(javaHome?: string) : Promise<JVM | null> {
|
||||
* Optionally, a specific javaHome can be passed in. This shortcuts the
|
||||
* search logic and uses that javaHome as is, not looking anywhere else.
|
||||
*/
|
||||
function findJavaExe(javaHome?: string) : string | null {
|
||||
function findJavaExe(javaHome: string, log?: (msg: string) => void) : string | null {
|
||||
if (!log) {
|
||||
log = console.log;
|
||||
}
|
||||
//Try java home first
|
||||
if (!javaHome) {
|
||||
log('No user specified java-home setting. Looking for JAVA_HOME env variable...');
|
||||
javaHome = process.env["JAVA_HOME"];
|
||||
}
|
||||
if (javaHome) {
|
||||
//Resolve symlinks
|
||||
javaHome = FS.realpathSync(javaHome);
|
||||
} else {
|
||||
log('JAVA_HOME environment variable not set');
|
||||
}
|
||||
let binName = correctBinname("java");
|
||||
if (javaHome) {
|
||||
@@ -122,8 +130,11 @@ function findJavaExe(javaHome?: string) : string | null {
|
||||
if (FS.existsSync(javaExe)) {
|
||||
return javaExe;
|
||||
}
|
||||
// Fall through invalid JVM specified by JAVA_HOME varable
|
||||
log(`JAVA_HOME env variable points to location that does NOT exist: ${javaHome}`)
|
||||
}
|
||||
|
||||
log('Looking for the path to JVM inside PATH env variable');
|
||||
for (let searchPath of process.env['PATH'].split(Path.delimiter)) {
|
||||
let javaExe = Path.resolve(searchPath, binName);
|
||||
if (FS.existsSync(javaExe)) {
|
||||
@@ -131,6 +142,7 @@ function findJavaExe(javaHome?: string) : string | null {
|
||||
return FS.realpathSync(javaExe);
|
||||
}
|
||||
}
|
||||
log('No valid JVM found on the system!!!');
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user