Search in sources :

Example 1 with JstdBrowserInfo

use of com.google.jstestdriver.idea.server.JstdBrowserInfo in project intellij-plugins by JetBrains.

the class JstdCoverageProgramRunner method start.

@Nullable
private static RunContentDescriptor start(@Nullable JstdServer server, @NotNull ExecutionEnvironment environment) throws ExecutionException {
    FileDocumentManager.getInstance().saveAllDocuments();
    JstdRunConfiguration runConfiguration = (JstdRunConfiguration) environment.getRunProfile();
    CoverageEnabledConfiguration coverageEnabledConfiguration = CoverageEnabledConfiguration.getOrCreate(runConfiguration);
    String coverageFilePath = coverageEnabledConfiguration.getCoverageFilePath();
    JstdRunProfileState jstdState = new JstdRunProfileState(environment, runConfiguration.getRunSettings(), coverageFilePath);
    ExecutionResult executionResult = jstdState.executeWithServer(server);
    RunContentBuilder contentBuilder = new RunContentBuilder(executionResult, environment);
    final RunContentDescriptor descriptor = contentBuilder.showRunContent(environment.getContentToReuse());
    ProcessHandler processHandler = executionResult.getProcessHandler();
    if (processHandler instanceof NopProcessHandler) {
        if (server != null) {
            server.addLifeCycleListener(new JstdServerLifeCycleAdapter() {

                @Override
                public void onBrowserCaptured(@NotNull JstdBrowserInfo info) {
                    ExecutionUtil.restartIfActive(descriptor);
                    server.removeLifeCycleListener(this);
                }
            }, contentBuilder);
        }
    } else {
        CoverageHelper.attachToProcess(runConfiguration, processHandler, environment.getRunnerSettings());
    }
    return descriptor;
}
Also used : JstdRunConfiguration(com.google.jstestdriver.idea.execution.JstdRunConfiguration) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) CoverageEnabledConfiguration(com.intellij.execution.configurations.coverage.CoverageEnabledConfiguration) JstdRunProfileState(com.google.jstestdriver.idea.execution.JstdRunProfileState) NopProcessHandler(com.intellij.execution.process.NopProcessHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler) ExecutionResult(com.intellij.execution.ExecutionResult) NopProcessHandler(com.intellij.execution.process.NopProcessHandler) RunContentBuilder(com.intellij.execution.runners.RunContentBuilder) JstdServerLifeCycleAdapter(com.google.jstestdriver.idea.server.JstdServerLifeCycleAdapter) JstdBrowserInfo(com.google.jstestdriver.idea.server.JstdBrowserInfo) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with JstdBrowserInfo

use of com.google.jstestdriver.idea.server.JstdBrowserInfo in project intellij-plugins by JetBrains.

the class JstdRunProgramRunner method start.

public static RunContentDescriptor start(@Nullable JstdServer server, boolean fromDebug, @NotNull RunProfileState state, @NotNull ExecutionEnvironment environment) throws ExecutionException {
    FileDocumentManager.getInstance().saveAllDocuments();
    JstdRunProfileState jstdState = JstdRunProfileState.cast(state);
    ExecutionResult executionResult = jstdState.executeWithServer(server);
    RunContentBuilder contentBuilder = new RunContentBuilder(executionResult, environment);
    final RunContentDescriptor descriptor = contentBuilder.showRunContent(environment.getContentToReuse());
    if (server != null && executionResult.getProcessHandler() instanceof NopProcessHandler) {
        server.addLifeCycleListener(new JstdServerLifeCycleAdapter() {

            @Override
            public void onBrowserCaptured(@NotNull JstdBrowserInfo info) {
                if (fromDebug) {
                    final Alarm alarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD, descriptor);
                    alarm.addRequest(() -> ExecutionUtil.restartIfActive(descriptor), 1000);
                } else {
                    ExecutionUtil.restartIfActive(descriptor);
                }
                server.removeLifeCycleListener(this);
            }
        }, contentBuilder);
    }
    return descriptor;
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) Alarm(com.intellij.util.Alarm) ExecutionResult(com.intellij.execution.ExecutionResult) NopProcessHandler(com.intellij.execution.process.NopProcessHandler) RunContentBuilder(com.intellij.execution.runners.RunContentBuilder) JstdServerLifeCycleAdapter(com.google.jstestdriver.idea.server.JstdServerLifeCycleAdapter) JstdBrowserInfo(com.google.jstestdriver.idea.server.JstdBrowserInfo)

Example 3 with JstdBrowserInfo

use of com.google.jstestdriver.idea.server.JstdBrowserInfo in project intellij-plugins by JetBrains.

the class JstdServerStatusView method attachToServer.

public void attachToServer(@NotNull final JstdServer server) {
    setInfoBodyHtml("Starting up...");
    server.addLifeCycleListener(new JstdServerLifeCycleAdapter() {

        @Override
        public void onServerStarted() {
            JstdServerSettings settings = server.getSettings();
            String url = "http://127.0.0.1:" + settings.getPort() + "/capture";
            setInfoBodyHtml("To capture a browser open <a href='" + url + "'>" + url + "</a>");
            updateCapturedBrowsersCount(server);
        }

        @Override
        public void onServerStopped() {
            setInfoBodyHtml("Not running");
            updateCapturedBrowsersCount(server);
        }

        @Override
        public void onBrowserCaptured(@NotNull JstdBrowserInfo info) {
            updateCapturedBrowsersCount(server);
        }

        @Override
        public void onBrowserPanicked(@NotNull JstdBrowserInfo info) {
            updateCapturedBrowsersCount(server);
        }
    }, myDisposable);
}
Also used : JstdServerSettings(com.google.jstestdriver.idea.server.JstdServerSettings) JstdServerLifeCycleAdapter(com.google.jstestdriver.idea.server.JstdServerLifeCycleAdapter) JstdBrowserInfo(com.google.jstestdriver.idea.server.JstdBrowserInfo)

Example 4 with JstdBrowserInfo

use of com.google.jstestdriver.idea.server.JstdBrowserInfo in project intellij-plugins by JetBrains.

the class JstdDebugBrowserInfo method build.

@Nullable
public static JstdDebugBrowserInfo build(@NotNull JstdServer server, @NotNull JstdRunSettings runSettings) {
    Collection<JstdBrowserInfo> capturedBrowsers = server.getCapturedBrowsers();
    List<JstdDebugBrowserInfo> debugBrowserInfos = new SmartList<>();
    for (JstdBrowserInfo browserInfo : capturedBrowsers) {
        Pair<JavaScriptDebugEngine, WebBrowser> engine = JavaScriptDebugEngine.Companion.findByBrowserIdOrName(browserInfo.getName());
        if (engine != null) {
            debugBrowserInfos.add(new JstdDebugBrowserInfo(engine, server.getSettings(), browserInfo));
        }
    }
    if (debugBrowserInfos.size() == 1) {
        return debugBrowserInfos.get(0);
    }
    if (debugBrowserInfos.size() > 1) {
        WebBrowser preferredBrowser = runSettings.getPreferredDebugBrowser();
        for (JstdDebugBrowserInfo info : debugBrowserInfos) {
            if (preferredBrowser.equals(info.getBrowser())) {
                return info;
            }
        }
    }
    return null;
}
Also used : WebBrowser(com.intellij.ide.browsers.WebBrowser) SmartList(com.intellij.util.SmartList) JstdBrowserInfo(com.google.jstestdriver.idea.server.JstdBrowserInfo) JavaScriptDebugEngine(com.intellij.javascript.debugger.JavaScriptDebugEngine) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

JstdBrowserInfo (com.google.jstestdriver.idea.server.JstdBrowserInfo)4 JstdServerLifeCycleAdapter (com.google.jstestdriver.idea.server.JstdServerLifeCycleAdapter)3 ExecutionResult (com.intellij.execution.ExecutionResult)2 NopProcessHandler (com.intellij.execution.process.NopProcessHandler)2 RunContentBuilder (com.intellij.execution.runners.RunContentBuilder)2 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)2 Nullable (org.jetbrains.annotations.Nullable)2 JstdRunConfiguration (com.google.jstestdriver.idea.execution.JstdRunConfiguration)1 JstdRunProfileState (com.google.jstestdriver.idea.execution.JstdRunProfileState)1 JstdServerSettings (com.google.jstestdriver.idea.server.JstdServerSettings)1 CoverageEnabledConfiguration (com.intellij.execution.configurations.coverage.CoverageEnabledConfiguration)1 ProcessHandler (com.intellij.execution.process.ProcessHandler)1 WebBrowser (com.intellij.ide.browsers.WebBrowser)1 JavaScriptDebugEngine (com.intellij.javascript.debugger.JavaScriptDebugEngine)1 Alarm (com.intellij.util.Alarm)1 SmartList (com.intellij.util.SmartList)1