From 44c00d53a7e343b2460bb3af8cdd00544ef972aa Mon Sep 17 00:00:00 2001 From: ishmal Date: Thu, 3 Apr 2008 03:17:12 +0000 Subject: [PATCH] improve jvm search to allow an embedded jre. fix missed "public" on method --- src/bind/java/org/inkscape/cmn/Gateway.java | 2 +- src/bind/javabind.cpp | 78 +++++++++++++++------ 2 files changed, 58 insertions(+), 22 deletions(-) diff --git a/src/bind/java/org/inkscape/cmn/Gateway.java b/src/bind/java/org/inkscape/cmn/Gateway.java index d1fa47a2b..fa70d2b7d 100644 --- a/src/bind/java/org/inkscape/cmn/Gateway.java +++ b/src/bind/java/org/inkscape/cmn/Gateway.java @@ -132,7 +132,7 @@ public Document stringToDoc(String xmlStr) /** * Serialize an XML Document to a string */ -String docToString(Document doc) +public String docToString(Document doc) { if (doc == null) return ""; diff --git a/src/bind/javabind.cpp b/src/bind/javabind.cpp index 6bffe0cd7..c62981f1f 100644 --- a/src/bind/javabind.cpp +++ b/src/bind/javabind.cpp @@ -324,32 +324,73 @@ static const char *commonJavaPaths[] = NULL }; + +static String getExePath() +{ + char exeName[80]; + GetModuleFileName(NULL, exeName, 80); + char *slashPos = strrchr(exeName, '\\'); + if (slashPos) + *slashPos = '\0'; + String s = exeName; + return s; +} + + +static String checkPathUnderRoot(const String &root) +{ + for (const char **path = commonJavaPaths ; *path ; path++) + { + String jpath = root; + jpath.append(*path); + //msg("trying '%s'", jpath.c_str()); + struct stat finfo; + if (stat(jpath.c_str(), &finfo)>=0) + { + //msg("found"); + return jpath; + } + } + return ""; +} + + + static CreateVMFunc getCreateVMFunc() { bool found = false; String libname; /** - * First, look for JAVA_HOME. This will allow the user + * First, look for an embedded jre in the $INKSCAPE dir. + * This allows us to package our own JRE if we want to. + */ + String inkscapeHome = getExePath(); + inkscapeHome.append("\\jre"); + msg("INKSCAPE_HOME='%s'", inkscapeHome.c_str()); + String path = checkPathUnderRoot(inkscapeHome); + if (path.size() > 0) + { + libname = path; + found = true; + } + + /** + * Next, look for JAVA_HOME. This will allow the user * to override what's in the registry - */ - const char *envStr = getenv("JAVA_HOME"); - if (envStr) + */ + if (!found) { - String javaHome = cleanPath(envStr); - msg("JAVA_HOME='%s'", javaHome.c_str()); - for (const char **path = commonJavaPaths ; *path ; path++) + const char *envStr = getenv("JAVA_HOME"); + if (envStr) { - String jpath = javaHome; - jpath.append(*path); - //msg("trying '%s'", jpath.c_str()); - struct stat finfo; - if (stat(jpath.c_str(), &finfo)>=0) + String javaHome = cleanPath(envStr); + msg("JAVA_HOME='%s'", javaHome.c_str()); + path = checkPathUnderRoot(javaHome); + if (path.size() > 0) { - //msg("found"); - libname = jpath; + libname = path; found = true; - break; } } } @@ -416,12 +457,7 @@ static CreateVMFunc getCreateVMFunc() static void getJavaRoot(String &javaroot) { - char exeName[80]; - GetModuleFileName(NULL, exeName, 80); - char *slashPos = strrchr(exeName, '\\'); - if (slashPos) - *slashPos = '\0'; - javaroot = exeName; + javaroot = getExePath(); javaroot.append("\\"); javaroot.append(INKSCAPE_BINDDIR); javaroot.append("\\java"); -- 2.30.2