*/
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 org.testng.Assert;
import org.testng.FileAssert;
+import org.testng.annotations.BeforeClass;
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
{
- private static final int TEST_TIMEOUT = 4000;
+
+ @BeforeClass(alwaysRun = true)
+ public void setUpJvOptionPane()
+ {
+ JvOptionPane.setInteractiveMode(false);
+ JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+ }
+
+ private static final int TEST_TIMEOUT = 9000; // Note longer timeout needed on
+ // full test run than on
+ // individual tests
private static final int SETUP_TIMEOUT = 9000;
private static final int MINFILESIZE_BIG = 4096;
- private ArrayList<String> successfulCMDs = new ArrayList<String>();
+ private ArrayList<String> successfulCMDs = new ArrayList<>();
- /***
- * 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 BufferedReader outputReader;
+ private static ClassGraph scanner = null;
- private BufferedReader errorReader;
+ private static String classpath = null;
- private Integer exit;
-
- private Worker(Process process)
+ public synchronized static String getClassPath()
+ {
+ if (scanner == null)
{
- this.process = process;
+ scanner = new ClassGraph();
+ ScanResult scan = scanner.scan();
+ classpath = scan.getClasspath();
}
-
- @Override
- public void run()
+ while (classpath == null)
{
try
{
- exit = process.waitFor();
- } catch (InterruptedException ignore)
+ Thread.sleep(10);
+ } catch (InterruptedException x)
{
- return;
- }
- }
- public BufferedReader getOutputReader()
- {
- return outputReader;
- }
-
- public void setOutputReader(BufferedReader outputReader)
- {
- this.outputReader = outputReader;
- }
-
- public BufferedReader getErrorReader()
- {
- return errorReader;
- }
-
- public void setErrorReader(BufferedReader errorReader)
- {
- this.errorReader = errorReader;
+ }
}
+ 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" : "")
- + " -Djava.ext.dirs=./lib -classpath ./classes jalview.bin.Jalview ";
- System.out.println("CMD [" + cmd + "]");
+ + " -classpath " + classpath + " jalview.bin.Jalview ";
Process ls2_proc = null;
Worker worker = null;
try
break;
}
}
- if (worker != null && worker.exit == null)
+ if (worker != null && worker.getExitValue() == null)
{
- worker.interrupt();
- Thread.currentThread().interrupt();
- worker.process.destroy();
+ worker.destroyProcess();
+
}
}
FileAssert.assertFile(file, "Didn't create an output" + type
+ " file.[" + harg + "]");
FileAssert.assertMinLength(new File(fileName), expectedMinFileSize);
- if (worker != null && worker.exit == null)
+ if (worker != null && worker.getExitValue() == null)
{
- worker.interrupt();
- Thread.currentThread().interrupt();
- worker.process.destroy();
+ worker.destroyProcess();
Assert.fail("Jalview did not exit after "
+ type
+ " generation (try running test again to verify - timeout at "