diff -r a4a06840209a -r a07253cf2ca4 launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Launcher.java --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Launcher.java Wed Jan 30 18:27:57 2013 +0100 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Launcher.java Thu Jan 31 16:58:27 2013 +0100 @@ -24,7 +24,8 @@ import org.apidesign.vm4brwsr.Bck2Brwsr; /** An abstraction for executing tests in a Bck2Brwsr virtual machine. - * Either in JavaScript engine, or in external browser. + * Either in {@linkm Launcher#createJavaScript JavaScript engine}, + * or in {@linkm Launcher#createBrowser external browser}. * * @author Jaroslav Tulach */ @@ -32,39 +33,83 @@ Launcher() { } + + /** Initializes the launcher. This may mean starting a web browser or + * initializing execution engine. + * @throws IOException if something goes wrong + */ + public abstract void initialize() throws IOException; - abstract MethodInvocation addMethod(Class clazz, String method, String html) throws IOException; - - public abstract void initialize() throws IOException; + /** Shuts down the launcher. + * @throws IOException if something goes wrong + */ public abstract void shutdown() throws IOException; - public MethodInvocation invokeMethod(Class clazz, String method, String html) throws IOException { - return addMethod(clazz, method, html); + + + /** Builds an invocation context. The context can later be customized + * and {@link InvocationContext#invoke() invoked}. + * + * @param clazz the class to execute method from + * @param method the method to execute + * @return the context pointing to the selected method + */ + public InvocationContext createInvocation(Class clazz, String method) { + return new InvocationContext(this, clazz, method); } - + /** Creates launcher that uses internal JavaScript engine (Rhino). + * @return the launcher + */ public static Launcher createJavaScript() { final JSLauncher l = new JSLauncher(); l.addClassLoader(Bck2Brwsr.class.getClassLoader()); return l; } + /** Creates launcher that is using external browser. + * + * @param cmd null to use java.awt.Desktop to show the launcher + * or a string to execute in an external process (with a parameter to the URL) + * @return launcher executing in external browser. + */ public static Launcher createBrowser(String cmd) { final Bck2BrwsrLauncher l = new Bck2BrwsrLauncher(cmd); l.addClassLoader(Bck2Brwsr.class.getClassLoader()); l.setTimeout(180000); return l; } + + /** Starts an HTTP server which provides access to classes and resources + * available in the classes URL and shows a start page + * available as {@link ClassLoader#getResource(java.lang.String)} from the + * provide classloader. Opens a browser with URL showing the start page. + * + * @param classes classloader offering access to classes and resources + * @param startpage page to show in the browser + * @return interface that allows one to stop the server + * @throws IOException if something goes wrong + */ public static Closeable showURL(URLClassLoader classes, String startpage) throws IOException { Bck2BrwsrLauncher l = new Bck2BrwsrLauncher(null); l.addClassLoader(classes); l.showURL(startpage); return l; } + /** Starts an HTTP server which provides access to certain directory. + * The startpage should be relative location inside the root + * driecotry + * Opens a browser with URL showing the start page. + * + * @param directory the root directory on disk + * @praam startpage relative path from the root to the page + * @exception IOException if something goes wrong. + */ public static Closeable showDir(File directory, String startpage) throws IOException { Bck2BrwsrLauncher l = new Bck2BrwsrLauncher(null); l.showDirectory(directory, startpage); return l; } + abstract InvocationContext runMethod(InvocationContext c) throws IOException; }