jaroslav@356: /** jaroslav@356: * Back 2 Browser Bytecode Translator jaroslav@356: * Copyright (C) 2012 Jaroslav Tulach jaroslav@356: * jaroslav@356: * This program is free software: you can redistribute it and/or modify jaroslav@356: * it under the terms of the GNU General Public License as published by jaroslav@356: * the Free Software Foundation, version 2 of the License. jaroslav@356: * jaroslav@356: * This program is distributed in the hope that it will be useful, jaroslav@356: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@356: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@356: * GNU General Public License for more details. jaroslav@356: * jaroslav@356: * You should have received a copy of the GNU General Public License jaroslav@356: * along with this program. Look for COPYING file in the top folder. jaroslav@356: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@356: */ jaroslav@372: package org.apidesign.bck2brwsr.vmtest.impl; jaroslav@356: jaroslav@370: import java.io.IOException; jaroslav@383: import java.util.LinkedHashMap; jaroslav@383: import java.util.Map; jaroslav@382: import org.apidesign.bck2brwsr.launcher.Launcher; jaroslav@372: import org.testng.annotations.AfterGroups; jaroslav@372: import org.testng.annotations.BeforeGroups; jaroslav@356: jaroslav@356: /** jaroslav@356: * jaroslav@356: * @author Jaroslav Tulach jaroslav@356: */ jaroslav@383: public final class LaunchSetup { jaroslav@384: static LaunchSetup INSTANCE = new LaunchSetup(); jaroslav@356: jaroslav@681: private Launcher js; jaroslav@384: private final Map brwsrs = new LinkedHashMap<>(); jaroslav@372: jaroslav@384: private LaunchSetup() { jaroslav@383: } jaroslav@383: jaroslav@681: public Launcher javaScript() { jaroslav@681: return js(true); jaroslav@681: } jaroslav@681: private synchronized Launcher js(boolean create) { jaroslav@681: if (js == null && create) { jaroslav@681: js = Launcher.createJavaScript(); jaroslav@681: } jaroslav@384: return js; jaroslav@383: } jaroslav@383: jaroslav@384: public synchronized Launcher brwsr(String cmd) { jaroslav@384: Launcher s = brwsrs.get(cmd); jaroslav@383: if (s == null) { jaroslav@384: s = Launcher.createBrowser(cmd); jaroslav@384: brwsrs.put(cmd, s); jaroslav@383: } jaroslav@383: return s; jaroslav@356: } jaroslav@356: jaroslav@372: @BeforeGroups("run") jaroslav@372: public void initializeLauncher() throws IOException { jaroslav@681: if (js(false) != null) { jaroslav@681: js(true).initialize(); jaroslav@681: } jaroslav@384: for (Launcher launcher : brwsrs.values()) { jaroslav@384: launcher.initialize(); jaroslav@384: } jaroslav@356: } jaroslav@356: jaroslav@372: @AfterGroups("run") jaroslav@372: public void shutDownLauncher() throws IOException, InterruptedException { jaroslav@681: if (js(false) != null) { jaroslav@681: js(true).shutdown(); jaroslav@681: } jaroslav@384: for (Launcher launcher : brwsrs.values()) { jaroslav@384: launcher.shutdown(); jaroslav@384: } jaroslav@356: } jaroslav@356: }