author | Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
Tue, 25 Dec 2012 15:08:39 +0100 | |
changeset 382 | 57fc3a0563c9 |
child 526 | a0d8b5ab79a2 |
permissions | -rw-r--r-- |
jaroslav@382 | 1 |
/** |
jaroslav@382 | 2 |
* Back 2 Browser Bytecode Translator |
jaroslav@382 | 3 |
* Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
jaroslav@382 | 4 |
* |
jaroslav@382 | 5 |
* This program is free software: you can redistribute it and/or modify |
jaroslav@382 | 6 |
* it under the terms of the GNU General Public License as published by |
jaroslav@382 | 7 |
* the Free Software Foundation, version 2 of the License. |
jaroslav@382 | 8 |
* |
jaroslav@382 | 9 |
* This program is distributed in the hope that it will be useful, |
jaroslav@382 | 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
jaroslav@382 | 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
jaroslav@382 | 12 |
* GNU General Public License for more details. |
jaroslav@382 | 13 |
* |
jaroslav@382 | 14 |
* You should have received a copy of the GNU General Public License |
jaroslav@382 | 15 |
* along with this program. Look for COPYING file in the top folder. |
jaroslav@382 | 16 |
* If not, see http://opensource.org/licenses/GPL-2.0. |
jaroslav@382 | 17 |
*/ |
jaroslav@382 | 18 |
package org.apidesign.bck2brwsr.launcher; |
jaroslav@382 | 19 |
|
jaroslav@382 | 20 |
import java.io.Closeable; |
jaroslav@382 | 21 |
import java.io.IOException; |
jaroslav@382 | 22 |
import java.net.URLClassLoader; |
jaroslav@382 | 23 |
import org.apidesign.vm4brwsr.Bck2Brwsr; |
jaroslav@382 | 24 |
|
jaroslav@382 | 25 |
/** An abstraction for executing tests in a Bck2Brwsr virtual machine. |
jaroslav@382 | 26 |
* Either in JavaScript engine, or in external browser. |
jaroslav@382 | 27 |
* |
jaroslav@382 | 28 |
* @author Jaroslav Tulach <jtulach@netbeans.org> |
jaroslav@382 | 29 |
*/ |
jaroslav@382 | 30 |
public abstract class Launcher { |
jaroslav@382 | 31 |
|
jaroslav@382 | 32 |
Launcher() { |
jaroslav@382 | 33 |
} |
jaroslav@382 | 34 |
|
jaroslav@382 | 35 |
abstract MethodInvocation addMethod(Class<?> clazz, String method) throws IOException; |
jaroslav@382 | 36 |
|
jaroslav@382 | 37 |
public abstract void initialize() throws IOException; |
jaroslav@382 | 38 |
public abstract void shutdown() throws IOException; |
jaroslav@382 | 39 |
public MethodInvocation invokeMethod(Class<?> clazz, String method) throws IOException { |
jaroslav@382 | 40 |
return addMethod(clazz, method); |
jaroslav@382 | 41 |
} |
jaroslav@382 | 42 |
|
jaroslav@382 | 43 |
|
jaroslav@382 | 44 |
|
jaroslav@382 | 45 |
public static Launcher createJavaScript() { |
jaroslav@382 | 46 |
final JSLauncher l = new JSLauncher(); |
jaroslav@382 | 47 |
l.addClassLoader(Bck2Brwsr.class.getClassLoader()); |
jaroslav@382 | 48 |
return l; |
jaroslav@382 | 49 |
} |
jaroslav@382 | 50 |
|
jaroslav@382 | 51 |
public static Launcher createBrowser(String cmd) { |
jaroslav@382 | 52 |
final Bck2BrwsrLauncher l = new Bck2BrwsrLauncher(cmd); |
jaroslav@382 | 53 |
l.addClassLoader(Bck2Brwsr.class.getClassLoader()); |
jaroslav@382 | 54 |
l.setTimeout(180000); |
jaroslav@382 | 55 |
return l; |
jaroslav@382 | 56 |
} |
jaroslav@382 | 57 |
public static Closeable showURL(URLClassLoader classes, String startpage) throws IOException { |
jaroslav@382 | 58 |
Bck2BrwsrLauncher l = new Bck2BrwsrLauncher(null); |
jaroslav@382 | 59 |
l.addClassLoader(classes); |
jaroslav@382 | 60 |
l.showURL(startpage); |
jaroslav@382 | 61 |
return l; |
jaroslav@382 | 62 |
} |
jaroslav@382 | 63 |
} |