1.1 --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Launcher.java Wed Jan 30 18:27:57 2013 +0100
1.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Launcher.java Wed Feb 06 18:24:53 2013 +0100
1.3 @@ -24,7 +24,8 @@
1.4 import org.apidesign.vm4brwsr.Bck2Brwsr;
1.5
1.6 /** An abstraction for executing tests in a Bck2Brwsr virtual machine.
1.7 - * Either in JavaScript engine, or in external browser.
1.8 + * Either in {@linkm Launcher#createJavaScript JavaScript engine},
1.9 + * or in {@linkm Launcher#createBrowser external browser}.
1.10 *
1.11 * @author Jaroslav Tulach <jtulach@netbeans.org>
1.12 */
1.13 @@ -32,39 +33,83 @@
1.14
1.15 Launcher() {
1.16 }
1.17 +
1.18 + /** Initializes the launcher. This may mean starting a web browser or
1.19 + * initializing execution engine.
1.20 + * @throws IOException if something goes wrong
1.21 + */
1.22 + public abstract void initialize() throws IOException;
1.23
1.24 - abstract MethodInvocation addMethod(Class<?> clazz, String method, String html) throws IOException;
1.25 -
1.26 - public abstract void initialize() throws IOException;
1.27 + /** Shuts down the launcher.
1.28 + * @throws IOException if something goes wrong
1.29 + */
1.30 public abstract void shutdown() throws IOException;
1.31 - public MethodInvocation invokeMethod(Class<?> clazz, String method, String html) throws IOException {
1.32 - return addMethod(clazz, method, html);
1.33 +
1.34 +
1.35 + /** Builds an invocation context. The context can later be customized
1.36 + * and {@link InvocationContext#invoke() invoked}.
1.37 + *
1.38 + * @param clazz the class to execute method from
1.39 + * @param method the method to execute
1.40 + * @return the context pointing to the selected method
1.41 + */
1.42 + public InvocationContext createInvocation(Class<?> clazz, String method) {
1.43 + return new InvocationContext(this, clazz, method);
1.44 }
1.45
1.46 -
1.47
1.48 + /** Creates launcher that uses internal JavaScript engine (Rhino).
1.49 + * @return the launcher
1.50 + */
1.51 public static Launcher createJavaScript() {
1.52 final JSLauncher l = new JSLauncher();
1.53 l.addClassLoader(Bck2Brwsr.class.getClassLoader());
1.54 return l;
1.55 }
1.56
1.57 + /** Creates launcher that is using external browser.
1.58 + *
1.59 + * @param cmd <code>null</code> to use <code>java.awt.Desktop</code> to show the launcher
1.60 + * or a string to execute in an external process (with a parameter to the URL)
1.61 + * @return launcher executing in external browser.
1.62 + */
1.63 public static Launcher createBrowser(String cmd) {
1.64 final Bck2BrwsrLauncher l = new Bck2BrwsrLauncher(cmd);
1.65 l.addClassLoader(Bck2Brwsr.class.getClassLoader());
1.66 l.setTimeout(180000);
1.67 return l;
1.68 }
1.69 +
1.70 + /** Starts an HTTP server which provides access to classes and resources
1.71 + * available in the <code>classes</code> URL and shows a start page
1.72 + * available as {@link ClassLoader#getResource(java.lang.String)} from the
1.73 + * provide classloader. Opens a browser with URL showing the start page.
1.74 + *
1.75 + * @param classes classloader offering access to classes and resources
1.76 + * @param startpage page to show in the browser
1.77 + * @return interface that allows one to stop the server
1.78 + * @throws IOException if something goes wrong
1.79 + */
1.80 public static Closeable showURL(URLClassLoader classes, String startpage) throws IOException {
1.81 Bck2BrwsrLauncher l = new Bck2BrwsrLauncher(null);
1.82 l.addClassLoader(classes);
1.83 l.showURL(startpage);
1.84 return l;
1.85 }
1.86 + /** Starts an HTTP server which provides access to certain directory.
1.87 + * The <code>startpage</code> should be relative location inside the root
1.88 + * driecotry
1.89 + * Opens a browser with URL showing the start page.
1.90 + *
1.91 + * @param directory the root directory on disk
1.92 + * @praam startpage relative path from the root to the page
1.93 + * @exception IOException if something goes wrong.
1.94 + */
1.95 public static Closeable showDir(File directory, String startpage) throws IOException {
1.96 Bck2BrwsrLauncher l = new Bck2BrwsrLauncher(null);
1.97 l.showDirectory(directory, startpage);
1.98 return l;
1.99 }
1.100
1.101 + abstract InvocationContext runMethod(InvocationContext c) throws IOException;
1.102 }