launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Launcher.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Wed, 30 Jan 2013 18:27:57 +0100
branchemul
changeset 613 a4a06840209a
parent 526 a0d8b5ab79a2
child 622 a07253cf2ca4
permissions -rw-r--r--
Using internal server to execute the HTML page
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@613
    21
import java.io.File;
jaroslav@382
    22
import java.io.IOException;
jaroslav@382
    23
import java.net.URLClassLoader;
jaroslav@382
    24
import org.apidesign.vm4brwsr.Bck2Brwsr;
jaroslav@382
    25
jaroslav@382
    26
/** An abstraction for executing tests in a Bck2Brwsr virtual machine.
jaroslav@382
    27
 * Either in JavaScript engine, or in external browser.
jaroslav@382
    28
 *
jaroslav@382
    29
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@382
    30
 */
jaroslav@382
    31
public abstract class Launcher {
jaroslav@382
    32
jaroslav@382
    33
    Launcher() {
jaroslav@382
    34
    }
jaroslav@382
    35
    
jaroslav@526
    36
    abstract MethodInvocation addMethod(Class<?> clazz, String method, String html) throws IOException; 
jaroslav@382
    37
jaroslav@382
    38
    public abstract void initialize() throws IOException;
jaroslav@382
    39
    public abstract void shutdown() throws IOException;
jaroslav@526
    40
    public MethodInvocation invokeMethod(Class<?> clazz, String method, String html) throws IOException {
jaroslav@526
    41
        return addMethod(clazz, method, html);
jaroslav@382
    42
    }
jaroslav@382
    43
    
jaroslav@382
    44
    
jaroslav@382
    45
jaroslav@382
    46
    public static Launcher createJavaScript() {
jaroslav@382
    47
        final JSLauncher l = new JSLauncher();
jaroslav@382
    48
        l.addClassLoader(Bck2Brwsr.class.getClassLoader());
jaroslav@382
    49
        return l;
jaroslav@382
    50
    }
jaroslav@382
    51
    
jaroslav@382
    52
    public static Launcher createBrowser(String cmd) {
jaroslav@382
    53
        final Bck2BrwsrLauncher l = new Bck2BrwsrLauncher(cmd);
jaroslav@382
    54
        l.addClassLoader(Bck2Brwsr.class.getClassLoader());
jaroslav@382
    55
        l.setTimeout(180000);
jaroslav@382
    56
        return l;
jaroslav@382
    57
    }
jaroslav@382
    58
    public static Closeable showURL(URLClassLoader classes, String startpage) throws IOException {
jaroslav@382
    59
        Bck2BrwsrLauncher l = new Bck2BrwsrLauncher(null);
jaroslav@382
    60
        l.addClassLoader(classes);
jaroslav@382
    61
        l.showURL(startpage);
jaroslav@382
    62
        return l;
jaroslav@382
    63
    }
jaroslav@613
    64
    public static Closeable showDir(File directory, String startpage) throws IOException {
jaroslav@613
    65
        Bck2BrwsrLauncher l = new Bck2BrwsrLauncher(null);
jaroslav@613
    66
        l.showDirectory(directory, startpage);
jaroslav@613
    67
        return l;
jaroslav@613
    68
    }
jaroslav@613
    69
jaroslav@382
    70
}