JAL-3247 Launcher start improvements. RPM and DEB no longer packaged with getdown...
[jalview.git] / src / jalview / bin / Launcher.java
index 9957a40..412f119 100644 (file)
@@ -12,6 +12,8 @@ public class Launcher
 
   private final static int maxHeapSizePerCent = 90;
 
+  private final static String maxHeapSizePerCentProperty = "jvmmempc";
+
   private final static String dockIconPath = "JalviewLogo_Huge.png";
 
   public static void main(String[] args)
@@ -22,6 +24,8 @@ public class Launcher
     ArrayList<String> command = new ArrayList<>();
     command.add(javaBin);
 
+    String memSetting = null;
+
     boolean isAMac = System.getProperty("os.name").indexOf("Mac") > -1;
 
     for (String jvmArg : ManagementFactory.getRuntimeMXBean()
@@ -46,6 +50,7 @@ public class Launcher
       String arg = command.get(i);
       if (arg.startsWith("-Xmx"))
       {
+        memSetting = arg;
         memSet = true;
       }
       else if (arg.startsWith("-Xdock:icon"))
@@ -61,10 +66,32 @@ public class Launcher
     if (!memSet)
     {
       long maxMemLong = -1;
+      int percent = maxHeapSizePerCent;
+      String jvmmempc = System.getProperty(maxHeapSizePerCentProperty);
+      try
+      {
+        if (jvmmempc != null)
+        {
+          int trypercent = Integer.parseInt(jvmmempc);
+          if (0 < trypercent && trypercent <= 100)
+          {
+            percent = trypercent;
+          }
+          else
+          {
+            System.out.println("Property '" + maxHeapSizePerCentProperty
+                    + "' should be in range 1..100");
+          }
+        }
+      } catch (Exception e)
+      {
+        System.out.println("Error parsing " + maxHeapSizePerCentProperty
+                + " '" + jvmmempc + "'");
+      }
 
       try
       {
-        maxMemLong = MemorySetting.memPercent(maxHeapSizePerCent);
+        maxMemLong = MemorySetting.memPercent(percent);
       } catch (Exception e)
       {
         e.printStackTrace();
@@ -75,7 +102,8 @@ public class Launcher
 
       if (maxMemLong > 0)
       {
-        command.add("-Xmx" + Long.toString(maxMemLong));
+        memSetting = "-Xmx" + Long.toString(maxMemLong);
+        command.add(memSetting);
       }
     }
 
@@ -98,7 +126,9 @@ public class Launcher
 
     final ProcessBuilder builder = new ProcessBuilder(command);
 
-    System.out.println("COMMAND: " + String.join(" ", builder.command()));
+    // System.out.println("COMMAND: " + String.join(" ", builder.command()));
+    System.out.println("Running " + startClass + " with "
+            + (memSetting == null ? "no memSetting" : memSetting));
 
     try
     {