Fix for Java fingerprinter on macOS (#9225)
Use alternative test for macOS JVM with /usr/libexec/java_home
This commit is contained in:
parent
ab4b04e940
commit
16b6098df8
|
@ -223,6 +223,18 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint {
|
|||
return fp
|
||||
}
|
||||
}
|
||||
if runtime.GOOS == "darwin" {
|
||||
_, err := checkForMacJVM()
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
version, runtime, vm, err := javaVersionInfo()
|
||||
if err != nil {
|
||||
|
|
|
@ -5,14 +5,38 @@ import (
|
|||
"fmt"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
rt "runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var javaVersionCommand = []string{"java", "-version"}
|
||||
var macOSJavaTestCommand = "/usr/libexec/java_home"
|
||||
|
||||
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
|
||||
|
||||
if rt.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
|
||||
|
|
Loading…
Reference in a new issue