From dde9400380931264edad5b7c4f1d57fa747df7f4 Mon Sep 17 00:00:00 2001 From: Timo Kilpilehto Date: Sun, 6 Oct 2019 12:55:44 +0300 Subject: [PATCH 1/2] Support resolving java from jenv shims If the proposed java version looks like a jenv shim, try calling jenv which on it to really resolve the proposed java --- src/index.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/index.ts b/src/index.ts index 74b04e1..81c7d80 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,6 +18,7 @@ import * as path from "path"; import * as cp from "child_process"; import which from "which"; import WinReg, { Registry } from "winreg"; +import { execSync } from 'child_process'; const isWindows: boolean = process.platform.indexOf('win') === 0; const jdkRegistryKeyPaths: string[] = [ @@ -91,6 +92,15 @@ function findInPath(JAVA_FILENAME: string) { return resolve(null); } + if (proposed.match(".jenv/shims")) { + try { + const jenvProposed: string = execSync(`jenv which ${JAVA_FILENAME}`).toString().trim(); + proposed = jenvProposed; + } catch (ex) { + console.error(ex); + } + } + //resolve symlinks proposed = findLinkedFile(proposed); From 23d6eb06bd98773b1250f54e394a3674cfd40eea Mon Sep 17 00:00:00 2001 From: Timo Kilpilehto Date: Thu, 10 Oct 2019 22:50:02 +0300 Subject: [PATCH 2/2] Better to do pattern matching other way around That way we never need to worry about the about the type of the variable we're testing against. --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 81c7d80..8301dd9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -92,7 +92,7 @@ function findInPath(JAVA_FILENAME: string) { return resolve(null); } - if (proposed.match(".jenv/shims")) { + if (/\.jenv\/shims/.test(proposed)) { try { const jenvProposed: string = execSync(`jenv which ${JAVA_FILENAME}`).toString().trim(); proposed = jenvProposed;