JAL-3820 JAL-4189 Move checks for java executable symlinks to LaunchUtils ready for...
[jalview.git] / src / jalview / bin / Launcher.java
index c333e2e..20a466b 100644 (file)
@@ -52,29 +52,6 @@ public class Launcher
 
   private final static String headlessProperty = "java.awt.headless";
 
-  private static boolean checkJVMSymlink(String testBin)
-  {
-    File testBinFile = new File(testBin);
-    if (!testBinFile.exists())
-    {
-      return false;
-    }
-    File targetFile = null;
-    try
-    {
-      targetFile = testBinFile.getCanonicalFile();
-    } catch (IOException e)
-    {
-      return false;
-    }
-    if (targetFile != null && ("java".equals(targetFile.getName())
-            || "java.exe".equals(targetFile.getName())))
-    {
-      return true;
-    }
-    return false;
-  }
-
   /**
    * main method for jalview.bin.Launcher. This restarts the same JRE's JVM with
    * the same arguments but with memory adjusted based on extracted -jvmmempc
@@ -92,38 +69,6 @@ public class Launcher
               + ") may lead to problems. This installation of Jalview should be used with Java "
               + LaunchUtils.getJavaCompileVersion() + ".");
     }
-    final String appName = ChannelProperties.getProperty("app_name");
-    final String javaBinDir = System.getProperty("java.home")
-            + File.separator + "bin" + File.separator;
-    String javaBin = null;
-    for (String name : new String[] { appName, "Jalview", "java",
-        "java.exe" })
-    {
-      if (checkJVMSymlink(javaBinDir + name))
-      {
-        javaBin = javaBinDir + name;
-        break;
-      }
-    }
-    if (javaBin == null)
-    {
-      javaBin = "java";
-    }
-
-    List<String> command = new ArrayList<>();
-    command.add(javaBin);
-
-    String memSetting = null;
-
-    boolean isAMac = System.getProperty("os.name").indexOf("Mac") > -1;
-
-    for (String jvmArg : ManagementFactory.getRuntimeMXBean()
-            .getInputArguments())
-    {
-      command.add(jvmArg);
-    }
-    command.add("-cp");
-    command.add(ManagementFactory.getRuntimeMXBean().getClassPath());
 
     String jvmmempc = null;
     String jvmmemmax = null;
@@ -218,6 +163,24 @@ public class Launcher
       headless = false;
     }
 
+    final String appName = ChannelProperties.getProperty("app_name");
+
+    // if we're using jalview.bin.Launcher we always assume a console is in use
+    final String javaBin = LaunchUtils.findJavaBin(true);
+
+    List<String> command = new ArrayList<>();
+    command.add(javaBin);
+
+    String memSetting = null;
+
+    for (String jvmArg : ManagementFactory.getRuntimeMXBean()
+            .getInputArguments())
+    {
+      command.add(jvmArg);
+    }
+    command.add("-cp");
+    command.add(ManagementFactory.getRuntimeMXBean().getClassPath());
+
     // use saved preferences if no cmdline args
     boolean useCustomisedSettings = LaunchUtils
             .getBooleanUserPreference(MemorySetting.CUSTOMISED_SETTINGS);
@@ -278,7 +241,7 @@ public class Launcher
       }
     }
 
-    if (isAMac)
+    if (LaunchUtils.isMac)
     {
       if (!dockIcon)
       {