X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FLaunchUtils.java;fp=src%2Fjalview%2Futil%2FLaunchUtils.java;h=5894fecea7eac71d04bbf00a647e300686de49ac;hb=e83ce5d8ef826fc0b509a51f154abdf734501077;hp=5bd4a08491e0c9bba73e30223898a0455d37eb64;hpb=786475501a15799d7c4058dbf74e4bf896d03736;p=jalview.git diff --git a/src/jalview/util/LaunchUtils.java b/src/jalview/util/LaunchUtils.java index 5bd4a08..5894fec 100644 --- a/src/jalview/util/LaunchUtils.java +++ b/src/jalview/util/LaunchUtils.java @@ -31,6 +31,15 @@ import java.util.Properties; public class LaunchUtils { + // setting these is LaunchUtils so don't need to import Platform + public final static boolean isMac = System.getProperty("os.name") + .indexOf("Mac") > -1; + + public final static boolean isWindows = System.getProperty("os.name") + .indexOf("Win") > -1; + + private static boolean isJS = /** @j2sNative true || */ + false; public static void loadChannelProps(File dir) { @@ -65,7 +74,7 @@ public class LaunchUtils return null; } catch (IOException e) { - System.err.println(e.getMessage()); + ErrorLog.errPrintln(e.getMessage()); return null; } } @@ -81,7 +90,7 @@ public class LaunchUtils public static int getJavaCompileVersion() { - if (Platform.isJS()) + if (LaunchUtils.isJS) { return -1; } @@ -95,7 +104,7 @@ public class LaunchUtils try { URL localFileURL = new URL(buildDetails); - InputStream in = localFileURL.openStream(); + InputStream in = HttpUtils.openStream(localFileURL); Properties buildProperties = new Properties(); buildProperties.load(in); in.close(); @@ -103,22 +112,21 @@ public class LaunchUtils null); if (JCV == null) { - System.out.println( - "Could not obtain JAVA_COMPILE_VERSION for comparison"); + ErrorLog.errPrintln("Could not obtain JAVA_COMPILE_VERSION for comparison"); return -2; } JAVA_COMPILE_VERSION = Integer.parseInt(JCV); } catch (MalformedURLException e) { - System.err.println("Could not find " + buildDetails); + ErrorLog.errPrintln("Could not find " + buildDetails); return -3; } catch (IOException e) { - System.err.println("Could not load " + buildDetails); + ErrorLog.errPrintln("Could not load " + buildDetails); return -4; } catch (NumberFormatException e) { - System.err.println("Could not parse JAVA_COMPILE_VERSION"); + ErrorLog.errPrintln("Could not parse JAVA_COMPILE_VERSION"); return -5; } @@ -129,7 +137,7 @@ public class LaunchUtils public static int getJavaVersion() { - if (Platform.isJS()) + if (LaunchUtils.isJS) { return -1; } @@ -142,7 +150,7 @@ public class LaunchUtils String JV = System.getProperty("java.version"); if (JV == null) { - System.out.println("Could not obtain java.version for comparison"); + ErrorLog.errPrintln("Could not obtain java.version for comparison"); return -2; } if (JV.startsWith("1.")) @@ -153,7 +161,7 @@ public class LaunchUtils : Integer.parseInt(JV.substring(0, JV.indexOf("."))); } catch (NumberFormatException e) { - System.err.println("Could not parse java.version"); + ErrorLog.errPrintln("Could not parse java.version"); return -3; } return JAVA_VERSION; @@ -161,7 +169,7 @@ public class LaunchUtils public static boolean checkJavaVersion() { - if (Platform.isJS()) + if (LaunchUtils.isJS) { return true; } @@ -174,7 +182,7 @@ public class LaunchUtils if (java_compile_version <= 0 || java_version <= 0) { - System.out.println("Could not make Java version check"); + ErrorLog.errPrintln("Could not make Java version check"); return true; } // Warn if these java.version and JAVA_COMPILE_VERSION conditions exist @@ -186,4 +194,88 @@ public class LaunchUtils return true; } + + public static String findJavaBin(boolean winConsole) + { + return findJavaBin(System.getProperty("java.home"), winConsole, true); + } + + /* + * Returns a string path to the most likely java binary wanted to run this + * installation of Jalview. + * + * @param winConsole whether to use java.exe (console) in preference to javaw.exe + * (only affects Windows). + * @param javaHome Try this javaHome dir (defaults to the running java.home). + * @param generic Return a generic java command if not found. + */ + public static String findJavaBin(String javaHome, boolean winConsole, + boolean generic) + { + String javaBin = null; + final String javaExe = winConsole ? "java.exe" : "javaw.exe"; + final String java = "java"; + + if (javaHome != null) + { + // property "channel.app_name" is set by install4j when launching getdown + String propertyAppName = System.getProperty("channel.app_name"); + final String appName = (propertyAppName != null + && propertyAppName.length() > 0) ? propertyAppName + : ChannelProperties.getProperty("app_name"); + + final String javaBinDir = javaHome + File.separator + "bin" + + File.separator; + + // appName and "Jalview" will not point to javaw.exe or java.exe but in + // this case that's okay because the taskbar display name problem doesn't + // manifest in Windows. See JAL-3820, JAL-4189. + for (String name : new String[] { appName, "Jalview", java, javaExe }) + { + if (LaunchUtils.checkJVMSymlink(javaBinDir + name, winConsole)) + { + javaBin = javaBinDir + name; + break; + } + } + } + + if (javaBin == null && generic) + { + javaBin = LaunchUtils.isWindows ? javaExe : java; + } + + return javaBin; + } + + /* + * checkJVMSymlink returns true if the path in testBin *is* a java binary, or + * points to a java binary. + * @param testBin The binary or symbolic link to check + * @param winConsole whether we are in/want a Windows console (only relevant for Windows, + * determines whether we use java.exe or javaw.exe) + */ + private static boolean checkJVMSymlink(String testBin, boolean winConsole) + { + File testBinFile = new File(testBin); + if (!testBinFile.exists()) + { + return false; + } + File targetFile = null; + try + { + targetFile = testBinFile.getCanonicalFile(); + } catch (IOException e) + { + return false; + } + final String javaExe = winConsole ? "java.exe" : "javaw.exe"; + if (targetFile != null && ("java".equals(targetFile.getName()) + || javaExe.equals(targetFile.getName()))) + { + return true; + } + return false; + } }