java: fix paths for Windows and JRE (#54)

Fixes #53
This commit is contained in:
Adam Shannon 2018-08-19 17:56:28 -05:00 committed by Filippo Valsorda
parent 70f19a1cf6
commit 4f82e1cf78

@ -13,8 +13,8 @@ import (
"hash" "hash"
"os" "os"
"os/exec" "os/exec"
"path"
"path/filepath" "path/filepath"
"runtime"
"strings" "strings"
) )
@ -29,17 +29,31 @@ var (
) )
func init() { func init() {
if runtime.GOOS == "windows" {
keytoolPath = filepath.Join("bin", "keytool.exe")
} else {
keytoolPath = filepath.Join("bin", "keytool")
}
if v := os.Getenv("JAVA_HOME"); v != "" { if v := os.Getenv("JAVA_HOME"); v != "" {
hasJava = true hasJava = true
javaHome = v javaHome = v
_, err := os.Stat(path.Join(v, "bin/keytool")) _, err := os.Stat(filepath.Join(v, keytoolPath))
if err == nil { if err == nil {
hasKeytool = true hasKeytool = true
keytoolPath = path.Join(v, "bin/keytool") keytoolPath = filepath.Join(v, keytoolPath)
} }
cacertsPath = path.Join(v, "jre/lib/security/cacerts") _, err = os.Stat(filepath.Join(v, "lib", "security", "cacerts"))
if err == nil {
cacertsPath = filepath.Join(v, "lib", "security", "cacerts")
}
_, err = os.Stat(filepath.Join(v, "jre", "lib", "security", "cacerts"))
if err == nil {
cacertsPath = filepath.Join(v, "jre", "lib", "security", "cacerts")
}
} }
} }