jalviewDesktopRunner now a static method from Worker
authorJim Procter <jprocter@issues.jalview.org>
Mon, 17 Sep 2018 08:52:18 +0000 (09:52 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Mon, 17 Sep 2018 08:52:18 +0000 (09:52 +0100)
test/jalview/bin/CommandLineOperations.java

index a017fcf..b3e6af9 100644 (file)
@@ -23,10 +23,8 @@ package jalview.bin;
 import jalview.gui.JvOptionPane;
 import jalview.ws.utils.Worker;
 
-import java.io.BufferedReader;
 import java.io.File;
 import java.io.IOException;
-import java.io.InputStreamReader;
 import java.util.ArrayList;
 
 import org.testng.Assert;
@@ -36,9 +34,6 @@ import org.testng.annotations.BeforeTest;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
-import io.github.classgraph.ClassGraph;
-import io.github.classgraph.ScanResult;
-
 public class CommandLineOperations
 {
 
@@ -62,69 +57,6 @@ public class CommandLineOperations
   private ArrayList<String> successfulCMDs = new ArrayList<>();
 
 
-  private static ClassGraph scanner = null;
-
-  private static String classpath = null;
-
-  public synchronized static String getClassPath()
-  {
-    if (scanner == null)
-    {
-      scanner = new ClassGraph();
-      ScanResult scan = scanner.scan();
-      classpath = scan.getClasspath();
-    }
-    while (classpath == null)
-    {
-      try
-      {
-        Thread.sleep(10);
-      } catch (InterruptedException x)
-      {
-
-      }
-    }
-    return classpath;
-  }
-  private Worker jalviewDesktopRunner(boolean withAwt, String cmd,
-          int timeout)
-  {
-    // Note: JAL-3065 - don't include quotes for lib/* because the arguments are
-    // not expanded by the shell
-    String classpath = getClassPath();
-    String _cmd = "java "
-            + (withAwt ? "-Djava.awt.headless=true" : "")
-            + " -classpath " + classpath + " jalview.bin.Jalview ";
-    Process ls2_proc = null;
-    Worker worker = null;
-    try
-    {
-      ls2_proc = Runtime.getRuntime().exec(_cmd + cmd);
-    } catch (IOException e1)
-    {
-      e1.printStackTrace();
-    }
-    if (ls2_proc != null)
-    {
-      BufferedReader outputReader = new BufferedReader(
-              new InputStreamReader(ls2_proc.getInputStream()));
-      BufferedReader errorReader = new BufferedReader(
-              new InputStreamReader(ls2_proc.getErrorStream()));
-      worker = new Worker(ls2_proc);
-      worker.start();
-      try
-      {
-        worker.join(timeout);
-      } catch (InterruptedException e)
-      {
-        // e.printStackTrace();
-      }
-      worker.setOutputReader(outputReader);
-      worker.setErrorReader(errorReader);
-    }
-    return worker;
-  }
-
   @BeforeTest(alwaysRun = true)
   public void initialize()
   {
@@ -138,7 +70,7 @@ public class CommandLineOperations
     String cmds = "nodisplay -open examples/uniref50.fa -sortbytree -props FILE -colour zappo "
             + "-jabaws http://www.compbio.dundee.ac.uk/jabaws -nosortbytree -dasserver nickname=www.test.com "
             + "-features examples/testdata/plantfdx.features -annotations examples/testdata/plantfdx.annotations -tree examples/testdata/uniref50_test_tree";
-    Worker worker = jalviewDesktopRunner(true, cmds, SETUP_TIMEOUT);
+    Worker worker = Worker.jalviewDesktopRunner(true, cmds, SETUP_TIMEOUT);
     String ln = null;
     while ((ln = worker.getOutputReader().readLine()) != null)
     {
@@ -151,7 +83,7 @@ public class CommandLineOperations
   public void setUpForCommandLineInputOperations() throws IOException
   {
     String cmds = "-open examples/uniref50.fa -noquestionnaire -nousagestats";
-    Worker worker = jalviewDesktopRunner(false, cmds, SETUP_TIMEOUT);
+    Worker worker = Worker.jalviewDesktopRunner(false, cmds, SETUP_TIMEOUT);
     String ln = null;
     int count = 0;
     while ((ln = worker.getErrorReader().readLine()) != null)
@@ -187,7 +119,7 @@ public class CommandLineOperations
     String cmd = harg + type + " " + fileName;
     // System.out.println(">>>>>>>>>>>>>>>> Command : " + cmd);
     File file = new File(fileName);
-    Worker worker = jalviewDesktopRunner(withAWT, cmd, timeout);
+    Worker worker = Worker.jalviewDesktopRunner(withAWT, cmd, timeout);
 
     FileAssert.assertFile(file, "Didn't create an output" + type
             + " file.[" + harg + "]");