vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/LaunchSetup.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 25 Dec 2012 17:46:21 +0100
changeset 384 269d99fd6421
parent 383 88ed1f51eb22
child 681 93196a859fc5
permissions -rw-r--r--
Keeping single instance of LaunchSetup
jaroslav@356
     1
/**
jaroslav@356
     2
 * Back 2 Browser Bytecode Translator
jaroslav@356
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@356
     4
 *
jaroslav@356
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@356
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@356
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@356
     8
 *
jaroslav@356
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@356
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@356
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@356
    12
 * GNU General Public License for more details.
jaroslav@356
    13
 *
jaroslav@356
    14
 * You should have received a copy of the GNU General Public License
jaroslav@356
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@356
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@356
    17
 */
jaroslav@372
    18
package org.apidesign.bck2brwsr.vmtest.impl;
jaroslav@356
    19
jaroslav@370
    20
import java.io.IOException;
jaroslav@383
    21
import java.util.LinkedHashMap;
jaroslav@383
    22
import java.util.Map;
jaroslav@382
    23
import org.apidesign.bck2brwsr.launcher.Launcher;
jaroslav@372
    24
import org.testng.annotations.AfterGroups;
jaroslav@372
    25
import org.testng.annotations.BeforeGroups;
jaroslav@356
    26
jaroslav@356
    27
/**
jaroslav@356
    28
 *
jaroslav@356
    29
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@356
    30
 */
jaroslav@383
    31
public final class LaunchSetup {
jaroslav@384
    32
    static LaunchSetup INSTANCE = new LaunchSetup();
jaroslav@356
    33
    
jaroslav@384
    34
    private final Launcher js = Launcher.createJavaScript();
jaroslav@384
    35
    private final Map<String,Launcher> brwsrs = new LinkedHashMap<>();
jaroslav@372
    36
    
jaroslav@384
    37
    private LaunchSetup() {
jaroslav@383
    38
    }
jaroslav@383
    39
    
jaroslav@384
    40
    public  Launcher javaScript() {
jaroslav@384
    41
        return js;
jaroslav@383
    42
    } 
jaroslav@383
    43
    
jaroslav@384
    44
    public synchronized Launcher brwsr(String cmd) {
jaroslav@384
    45
        Launcher s = brwsrs.get(cmd);
jaroslav@383
    46
        if (s == null) {
jaroslav@384
    47
            s = Launcher.createBrowser(cmd);
jaroslav@384
    48
            brwsrs.put(cmd, s);
jaroslav@383
    49
        }
jaroslav@383
    50
        return s;
jaroslav@356
    51
    }
jaroslav@356
    52
jaroslav@372
    53
    @BeforeGroups("run")
jaroslav@372
    54
    public void initializeLauncher() throws IOException {
jaroslav@384
    55
        js.initialize();
jaroslav@384
    56
        for (Launcher launcher : brwsrs.values()) {
jaroslav@384
    57
            launcher.initialize();
jaroslav@384
    58
        }
jaroslav@356
    59
    }
jaroslav@356
    60
jaroslav@372
    61
    @AfterGroups("run")
jaroslav@372
    62
    public void shutDownLauncher() throws IOException, InterruptedException {
jaroslav@384
    63
        js.shutdown();
jaroslav@384
    64
        for (Launcher launcher : brwsrs.values()) {
jaroslav@384
    65
            launcher.shutdown();
jaroslav@384
    66
        }
jaroslav@356
    67
    }
jaroslav@356
    68
}