1.1 --- a/rt/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Launcher.java Tue Mar 05 07:57:16 2013 +0100
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,117 +0,0 @@
1.4 -/**
1.5 - * Back 2 Browser Bytecode Translator
1.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
1.7 - *
1.8 - * This program is free software: you can redistribute it and/or modify
1.9 - * it under the terms of the GNU General Public License as published by
1.10 - * the Free Software Foundation, version 2 of the License.
1.11 - *
1.12 - * This program is distributed in the hope that it will be useful,
1.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.15 - * GNU General Public License for more details.
1.16 - *
1.17 - * You should have received a copy of the GNU General Public License
1.18 - * along with this program. Look for COPYING file in the top folder.
1.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
1.20 - */
1.21 -package org.apidesign.bck2brwsr.launcher;
1.22 -
1.23 -import java.io.Closeable;
1.24 -import java.io.File;
1.25 -import java.io.IOException;
1.26 -import java.net.URLClassLoader;
1.27 -import org.apidesign.vm4brwsr.Bck2Brwsr;
1.28 -
1.29 -/** An abstraction for executing tests in a Bck2Brwsr virtual machine.
1.30 - * Either in {@linkm Launcher#createJavaScript JavaScript engine},
1.31 - * or in {@linkm Launcher#createBrowser external browser}.
1.32 - * <p>
1.33 - * There also are methods to {@link #showDir(java.io.File, java.lang.String) display pages}
1.34 - * in an external browser served by internal HTTP server.
1.35 - *
1.36 - * @author Jaroslav Tulach <jtulach@netbeans.org>
1.37 - */
1.38 -public abstract class Launcher {
1.39 -
1.40 - Launcher() {
1.41 - }
1.42 -
1.43 - /** Initializes the launcher. This may mean starting a web browser or
1.44 - * initializing execution engine.
1.45 - * @throws IOException if something goes wrong
1.46 - */
1.47 - public abstract void initialize() throws IOException;
1.48 -
1.49 - /** Shuts down the launcher.
1.50 - * @throws IOException if something goes wrong
1.51 - */
1.52 - public abstract void shutdown() throws IOException;
1.53 -
1.54 -
1.55 - /** Builds an invocation context. The context can later be customized
1.56 - * and {@link InvocationContext#invoke() invoked}.
1.57 - *
1.58 - * @param clazz the class to execute method from
1.59 - * @param method the method to execute
1.60 - * @return the context pointing to the selected method
1.61 - */
1.62 - public InvocationContext createInvocation(Class<?> clazz, String method) {
1.63 - return new InvocationContext(this, clazz, method);
1.64 - }
1.65 -
1.66 -
1.67 - /** Creates launcher that uses internal JavaScript engine (Rhino).
1.68 - * @return the launcher
1.69 - */
1.70 - public static Launcher createJavaScript() {
1.71 - final JSLauncher l = new JSLauncher();
1.72 - l.addClassLoader(Bck2Brwsr.class.getClassLoader());
1.73 - return l;
1.74 - }
1.75 -
1.76 - /** Creates launcher that is using external browser.
1.77 - *
1.78 - * @param cmd <code>null</code> to use <code>java.awt.Desktop</code> to show the launcher
1.79 - * or a string to execute in an external process (with a parameter to the URL)
1.80 - * @return launcher executing in external browser.
1.81 - */
1.82 - public static Launcher createBrowser(String cmd) {
1.83 - final Bck2BrwsrLauncher l = new Bck2BrwsrLauncher(cmd);
1.84 - l.addClassLoader(Bck2Brwsr.class.getClassLoader());
1.85 - l.setTimeout(180000);
1.86 - return l;
1.87 - }
1.88 -
1.89 - /** Starts an HTTP server which provides access to classes and resources
1.90 - * available in the <code>classes</code> URL and shows a start page
1.91 - * available as {@link ClassLoader#getResource(java.lang.String)} from the
1.92 - * provide classloader. Opens a browser with URL showing the start page.
1.93 - *
1.94 - * @param classes classloader offering access to classes and resources
1.95 - * @param startpage page to show in the browser
1.96 - * @return interface that allows one to stop the server
1.97 - * @throws IOException if something goes wrong
1.98 - */
1.99 - public static Closeable showURL(URLClassLoader classes, String startpage) throws IOException {
1.100 - Bck2BrwsrLauncher l = new Bck2BrwsrLauncher(null);
1.101 - l.addClassLoader(classes);
1.102 - l.showURL(startpage);
1.103 - return l;
1.104 - }
1.105 - /** Starts an HTTP server which provides access to certain directory.
1.106 - * The <code>startpage</code> should be relative location inside the root
1.107 - * directory. Opens a browser with URL showing the start page.
1.108 - *
1.109 - * @param directory the root directory on disk
1.110 - * @param startpage relative path from the root to the page
1.111 - * @exception IOException if something goes wrong.
1.112 - */
1.113 - public static Closeable showDir(File directory, String startpage) throws IOException {
1.114 - Bck2BrwsrLauncher l = new Bck2BrwsrLauncher(null);
1.115 - l.showDirectory(directory, startpage);
1.116 - return l;
1.117 - }
1.118 -
1.119 - abstract InvocationContext runMethod(InvocationContext c) throws IOException;
1.120 -}