Browse Source

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

Fixes #53
Adam Shannon 6 years ago
parent
commit
4f82e1cf78
1 changed files with 18 additions and 4 deletions
  1. 18 4
      truststore_java.go

+ 18 - 4
truststore_java.go

@@ -13,8 +13,8 @@ import (
 	"hash"
 	"os"
 	"os/exec"
-	"path"
 	"path/filepath"
+	"runtime"
 	"strings"
 )
 
@@ -29,17 +29,31 @@ var (
 )
 
 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 != "" {
 		hasJava = true
 		javaHome = v
 
-		_, err := os.Stat(path.Join(v, "bin/keytool"))
+		_, err := os.Stat(filepath.Join(v, keytoolPath))
 		if err == nil {
 			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")
+		}
 	}
 }