jaroslav@382: /** jaroslav@382: * Back 2 Browser Bytecode Translator jaroslav@382: * Copyright (C) 2012 Jaroslav Tulach jaroslav@382: * jaroslav@382: * This program is free software: you can redistribute it and/or modify jaroslav@382: * it under the terms of the GNU General Public License as published by jaroslav@382: * the Free Software Foundation, version 2 of the License. jaroslav@382: * jaroslav@382: * This program is distributed in the hope that it will be useful, jaroslav@382: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@382: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@382: * GNU General Public License for more details. jaroslav@382: * jaroslav@382: * You should have received a copy of the GNU General Public License jaroslav@382: * along with this program. Look for COPYING file in the top folder. jaroslav@382: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@382: */ jaroslav@382: package org.apidesign.bck2brwsr.launcher; jaroslav@382: jaroslav@382: import java.io.Closeable; jaroslav@382: import java.io.IOException; jaroslav@382: import java.net.URLClassLoader; jaroslav@382: import org.apidesign.vm4brwsr.Bck2Brwsr; jaroslav@382: jaroslav@382: /** An abstraction for executing tests in a Bck2Brwsr virtual machine. jaroslav@382: * Either in JavaScript engine, or in external browser. jaroslav@382: * jaroslav@382: * @author Jaroslav Tulach jaroslav@382: */ jaroslav@382: public abstract class Launcher { jaroslav@382: jaroslav@382: Launcher() { jaroslav@382: } jaroslav@382: jaroslav@526: abstract MethodInvocation addMethod(Class clazz, String method, String html) throws IOException; jaroslav@382: jaroslav@382: public abstract void initialize() throws IOException; jaroslav@382: public abstract void shutdown() throws IOException; jaroslav@526: public MethodInvocation invokeMethod(Class clazz, String method, String html) throws IOException { jaroslav@526: return addMethod(clazz, method, html); jaroslav@382: } jaroslav@382: jaroslav@382: jaroslav@382: jaroslav@382: public static Launcher createJavaScript() { jaroslav@382: final JSLauncher l = new JSLauncher(); jaroslav@382: l.addClassLoader(Bck2Brwsr.class.getClassLoader()); jaroslav@382: return l; jaroslav@382: } jaroslav@382: jaroslav@382: public static Launcher createBrowser(String cmd) { jaroslav@382: final Bck2BrwsrLauncher l = new Bck2BrwsrLauncher(cmd); jaroslav@382: l.addClassLoader(Bck2Brwsr.class.getClassLoader()); jaroslav@382: l.setTimeout(180000); jaroslav@382: return l; jaroslav@382: } jaroslav@382: public static Closeable showURL(URLClassLoader classes, String startpage) throws IOException { jaroslav@382: Bck2BrwsrLauncher l = new Bck2BrwsrLauncher(null); jaroslav@382: l.addClassLoader(classes); jaroslav@382: l.showURL(startpage); jaroslav@382: return l; jaroslav@382: } jaroslav@382: }