From 12c0da4a91ca0788bd54453eeead8910b799c560 Mon Sep 17 00:00:00 2001 From: Charlie Voiselle <464492+angrycub@users.noreply.github.com> Date: Thu, 29 Oct 2020 16:33:16 -0400 Subject: [PATCH 1/4] Fix for Java fingerprinter on macOS --- drivers/java/driver.go | 10 ++++++++++ drivers/java/utils.go | 21 ++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/drivers/java/driver.go b/drivers/java/driver.go index 22093504694..920e3d32c43 100644 --- a/drivers/java/driver.go +++ b/drivers/java/driver.go @@ -223,6 +223,16 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint { return fp } } + if runtime.GOOS == "darwin" { + _, err := checkForMacJVM() + // return no error, as it isn't an error to not find java, it just means we + // can't use it. + + fp.Health = drivers.HealthStateUndetected + fp.HealthDescription = "" + d.logger.Trace("macOS jvm not found", "error", err) + return fp + } version, runtime, vm, err := javaVersionInfo() if err != nil { diff --git a/drivers/java/utils.go b/drivers/java/utils.go index b41eec69137..7b1e8ed3567 100644 --- a/drivers/java/utils.go +++ b/drivers/java/utils.go @@ -9,10 +9,29 @@ import ( ) var javaVersionCommand = []string{"java", "-version"} +var macOSJavaTestCommand = "/usr/libexec/java_home" -func javaVersionInfo() (version, runtime, vm string, err error) { +func checkForMacJVM() (ok bool, err error) { + // test for java differently because of the shim application var out bytes.Buffer + cmd := exec.Command(macOSJavaTestCommand) + cmd.Stdout = &out + cmd.Stderr = &out + err = cmd.Run() + if err != nil { + err = fmt.Errorf("failed check for macOS jvm: %v, out: %v", err, strings.Replace(strings.Replace(out.String(), "\n", " ", -1), `"`, `\"`, -1)) + return false, err + } + return true, nil +} +func javaVersionInfo() (version, runtime, vm string, err error) { + var out bytes.Buffer + _, err = checkForMacJVM() + if err != nil { + err = fmt.Errorf("failed to check java version: %v", err) + return + } cmd := exec.Command(javaVersionCommand[0], javaVersionCommand[1:]...) cmd.Stdout = &out cmd.Stderr = &out From 490116fc0158614bb35dfef712ece7d9e630e2de Mon Sep 17 00:00:00 2001 From: Charlie Voiselle <464492+angrycub@users.noreply.github.com> Date: Thu, 29 Oct 2020 16:42:49 -0400 Subject: [PATCH 2/4] Missing 'if' :( --- drivers/java/driver.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/java/driver.go b/drivers/java/driver.go index 920e3d32c43..7696e115ea6 100644 --- a/drivers/java/driver.go +++ b/drivers/java/driver.go @@ -225,13 +225,15 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint { } if runtime.GOOS == "darwin" { _, err := checkForMacJVM() - // return no error, as it isn't an error to not find java, it just means we - // can't use it. + if err != nil { + // return no error, as it isn't an error to not find java, it just means we + // can't use it. - fp.Health = drivers.HealthStateUndetected - fp.HealthDescription = "" - d.logger.Trace("macOS jvm not found", "error", err) - return fp + fp.Health = drivers.HealthStateUndetected + fp.HealthDescription = "" + d.logger.Trace("macOS jvm not found", "error", err) + return fp + } } version, runtime, vm, err := javaVersionInfo() From 4008866a6387d3639fd6f863bee4cb2335764a29 Mon Sep 17 00:00:00 2001 From: Charlie Voiselle <464492+angrycub@users.noreply.github.com> Date: Thu, 29 Oct 2020 16:50:46 -0400 Subject: [PATCH 3/4] Add check for darwin --- drivers/java/utils.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/java/utils.go b/drivers/java/utils.go index 7b1e8ed3567..c01b905e443 100644 --- a/drivers/java/utils.go +++ b/drivers/java/utils.go @@ -27,11 +27,15 @@ func checkForMacJVM() (ok bool, err error) { func javaVersionInfo() (version, runtime, vm string, err error) { var out bytes.Buffer - _, err = checkForMacJVM() - if err != nil { - err = fmt.Errorf("failed to check java version: %v", err) - return + + if runtime.GOOS == "darwin" { + _, err = checkForMacJVM() + if err != nil { + err = fmt.Errorf("failed to check java version: %v", err) + return + } } + cmd := exec.Command(javaVersionCommand[0], javaVersionCommand[1:]...) cmd.Stdout = &out cmd.Stderr = &out From 3acb399618d766b2cd3b1acbb010b6754e6d4490 Mon Sep 17 00:00:00 2001 From: Charlie Voiselle <464492+angrycub@users.noreply.github.com> Date: Thu, 29 Oct 2020 17:02:34 -0400 Subject: [PATCH 4/4] fix conflict on runtime --- drivers/java/utils.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/java/utils.go b/drivers/java/utils.go index c01b905e443..1615ea643d0 100644 --- a/drivers/java/utils.go +++ b/drivers/java/utils.go @@ -5,6 +5,7 @@ import ( "fmt" "os/exec" "regexp" + rt "runtime" "strings" ) @@ -28,7 +29,7 @@ func checkForMacJVM() (ok bool, err error) { func javaVersionInfo() (version, runtime, vm string, err error) { var out bytes.Buffer - if runtime.GOOS == "darwin" { + if rt.GOOS == "darwin" { _, err = checkForMacJVM() if err != nil { err = fmt.Errorf("failed to check java version: %v", err)