JAL-1517 source formatting
[jalview.git] / test / jalview / bin / CommandLineOperations.java
index 40263c3..b86eebd 100644 (file)
@@ -43,30 +43,46 @@ public class CommandLineOperations
   public static void tearDownAfterClass() throws Exception
   {
   }
-/***
- * from http://stackoverflow.com/questions/808276/how-to-add-a-timeout-value-when-using-javas-runtime-exec
- * @author jimp
- *
- */
-private static class Worker extends Thread {
-  private final Process process;
-  private Integer exit;
-  private Worker(Process process) {
-    this.process = process;
-  }
-  public void run() {
-    try { 
-      exit = process.waitFor();
-    } catch (InterruptedException ignore) {
-      return;
+
+  /***
+   * from
+   * http://stackoverflow.com/questions/808276/how-to-add-a-timeout-value-when
+   * -using-javas-runtime-exec
+   * 
+   * @author jimp
+   * 
+   */
+  private static class Worker extends Thread
+  {
+    private final Process process;
+
+    private Integer exit;
+
+    private Worker(Process process)
+    {
+      this.process = process;
+    }
+
+    public void run()
+    {
+      try
+      {
+        exit = process.waitFor();
+      } catch (InterruptedException ignore)
+      {
+        return;
+      }
     }
   }
-}
-private Worker jalviewDesktopRunner(boolean withAwt, String cmd, int timeout) throws InterruptedException, IOException
+
+  private Worker jalviewDesktopRunner(boolean withAwt, String cmd,
+          int timeout) throws InterruptedException, IOException
   {
-    String _cmd = "java "+(withAwt ? "-Djava.awt.headless=true":"")+" -Djava.ext.dirs=./lib -classpath ./classes jalview.bin.Jalview ";
-    System.out.println("###############Jalview CMD: " + _cmd+cmd);
-    Process ls2_proc = Runtime.getRuntime().exec(_cmd+cmd);
+    String _cmd = "java "
+            + (withAwt ? "-Djava.awt.headless=true" : "")
+            + " -Djava.ext.dirs=./lib -classpath ./classes jalview.bin.Jalview ";
+    System.out.println("###############Jalview CMD: " + _cmd + cmd);
+    Process ls2_proc = Runtime.getRuntime().exec(_cmd + cmd);
     BufferedReader outputReader = new BufferedReader(new InputStreamReader(
             ls2_proc.getInputStream()));
 
@@ -89,52 +105,66 @@ private Worker jalviewDesktopRunner(boolean withAwt, String cmd, int timeout) th
     }
     return worker;
   }
+
   @Test
   public void testHeadlessModeEPS() throws Exception
   {
-    String[] headlessArgs=new String[] { "nodisplay","headless","nogui"};
-    for (String _harg:headlessArgs)
+    String[] headlessArgs = new String[]
+    { "nodisplay", "headless", "nogui" };
+    for (String _harg : headlessArgs)
     {
-      boolean _switch=false,withAwt=false;
-      do {
+      boolean _switch = false, withAwt = false;
+      do
+      {
         if (_switch)
         {
-          withAwt=true;
+          withAwt = true;
+        }
+        _switch = true;
+        String jalview_input = "examples/uniref50.fa";
+        String jalview_output = "test_uniref50_out.eps";
+        String cmd = "" + _harg + " -open " + jalview_input + " -eps "
+                + jalview_output;
+        String harg = _harg
+                + (withAwt ? "-Djava.awt.headless=true"
+                        : " NO AWT.HEADLESS");
+        System.out.println("Testing with Headless argument: '" + harg
+                + "'\n");
+        Worker worker = jalviewDesktopRunner(withAwt, cmd, 9000);
+        assertTrue("Didn't create an output EPS file.[" + harg + "]",
+                new File("test_uniref50_out.eps").exists());
+        assertTrue("Didn't create an EPS file with any content[" + harg
+                + "]", new File("test_uniref50_out.eps").length() > 4096);
+        if (worker.exit == null)
+        {
+          worker.interrupt();
+          Thread.currentThread().interrupt();
+          worker.process.destroy();
+          fail("Jalview did not exit after EPS generation (try running test again to verify - timeout at 9000ms). ["
+                  + harg + "]");
         }
-        _switch=true;
-    String jalview_input = "examples/uniref50.fa";
-    String jalview_output = "test_uniref50_out.eps";
-    String cmd = ""+_harg+" -open "+ jalview_input + " -eps " + jalview_output;
-    String harg = _harg+(withAwt ? "-Djava.awt.headless=true":" NO AWT.HEADLESS");
-    System.out.println("Testing with Headless argument: '"+harg+"'\n");
-    Worker worker = jalviewDesktopRunner(withAwt, cmd, 9000);
-    assertTrue("Didn't create an output EPS file.["+harg+"]", new File("test_uniref50_out.eps").exists());
-    assertTrue("Didn't create an EPS file with any content["+harg+"]", new File("test_uniref50_out.eps").length()>4096);
-    if (worker.exit == null){
-      worker.interrupt();
-      Thread.currentThread().interrupt();
-      worker.process.destroy();
-      fail("Jalview did not exit after EPS generation (try running test again to verify - timeout at 9000ms). ["+harg+"]");
+      } while (!withAwt);
     }
-    } while (!withAwt);
-    } 
   }
-//  @Test
-//  public void testJalview2XMLDataset() throws Exception
-//  {
-//    String jalview_input = "examples/uniref50.fa";
-//    String jalview_output = "test_uniref50_out.eps";
-//    String cmd = ""+" -open "+ jalview_input + " -eps " + jalview_output;
-//    //String harg = _harg+(withAwt ? "-Djava.awt.headless=true":" NO AWT.HEADLESS");
-//    System.out.println("Testing with Headless argument: '"+harg+"'\n");
-//    Worker worker = jalviewDesktopRunner(withAwt, cmd, 9000);
-//    assertTrue("Didn't create an output EPS file.["+harg+"]", new File("test_uniref50_out.eps").exists());
-//    assertTrue("Didn't create an EPS file with any content["+harg+"]", new File("test_uniref50_out.eps").length()>4096);
-//    if (worker.exit == null){
-//      worker.interrupt();
-//      Thread.currentThread().interrupt();
-//      worker.process.destroy();
-//      fail("Jalview did not exit after EPS generation (try running test again to verify - timeout at 9000ms). ["+harg+"]");
-//    }
-//  }
+  // @Test
+  // public void testJalview2XMLDataset() throws Exception
+  // {
+  // String jalview_input = "examples/uniref50.fa";
+  // String jalview_output = "test_uniref50_out.eps";
+  // String cmd = ""+" -open "+ jalview_input + " -eps " + jalview_output;
+  // //String harg = _harg+(withAwt ?
+  // "-Djava.awt.headless=true":" NO AWT.HEADLESS");
+  // System.out.println("Testing with Headless argument: '"+harg+"'\n");
+  // Worker worker = jalviewDesktopRunner(withAwt, cmd, 9000);
+  // assertTrue("Didn't create an output EPS file.["+harg+"]", new
+  // File("test_uniref50_out.eps").exists());
+  // assertTrue("Didn't create an EPS file with any content["+harg+"]", new
+  // File("test_uniref50_out.eps").length()>4096);
+  // if (worker.exit == null){
+  // worker.interrupt();
+  // Thread.currentThread().interrupt();
+  // worker.process.destroy();
+  // fail("Jalview did not exit after EPS generation (try running test again to verify - timeout at 9000ms). ["+harg+"]");
+  // }
+  // }
 }