Search in sources :

Example 1 with JstdServerLifeCycleAdapter

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

the class JstdRunProfileState method createProcessHandler.

@NotNull
private ProcessHandler createProcessHandler(@Nullable JstdServer ideServer) throws ExecutionException {
    String serverUrl = getServerUrl(ideServer);
    if (serverUrl != null) {
        return createOSProcessHandler(serverUrl);
    }
    final NopProcessHandler nopProcessHandler = new NopProcessHandler();
    if (ideServer != null) {
        ideServer.addLifeCycleListener(new JstdServerLifeCycleAdapter() {

            @Override
            public void onServerTerminated(int exitCode) {
                nopProcessHandler.destroyProcess();
            }
        }, myEnvironment.getProject());
    }
    return nopProcessHandler;
}
Also used : NopProcessHandler(com.intellij.execution.process.NopProcessHandler) JstdServerLifeCycleAdapter(com.google.jstestdriver.idea.server.JstdServerLifeCycleAdapter) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with JstdServerLifeCycleAdapter

use of com.google.jstestdriver.idea.server.JstdServerLifeCycleAdapter 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 3 with JstdServerLifeCycleAdapter

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

the class JstdConsoleView method initUI.

@Override
public void initUI() {
    super.initUI();
    if (myServer == null) {
        return;
    }
    TestTreeView treeView = this.getResultsViewer().getTreeView();
    TestTreeRenderer originalRenderer = ObjectUtils.tryCast(treeView.getCellRenderer(), TestTreeRenderer.class);
    if (originalRenderer != null) {
        myFormatter = new JstdRootTestProxyFormatter(myServer, treeView);
        originalRenderer.setAdditionalRootFormatter(myFormatter);
    }
    if (!myServer.isStopped() && myServer.getCapturedBrowsers().isEmpty()) {
        myServer.addLifeCycleListener(new JstdServerLifeCycleAdapter() {

            @Override
            public void onServerStarted() {
                print("To capture a browser open ", ConsoleViewContentType.SYSTEM_OUTPUT);
                String url = myServer.getServerUrl() + "/capture";
                printHyperlink(url, new OpenUrlHyperlinkInfo(url));
                print("\n", ConsoleViewContentType.SYSTEM_OUTPUT);
            }
        }, this);
    }
    myServer.addLifeCycleListener(new JstdServerLifeCycleAdapter() {

        @Override
        public void onServerTerminated(int exitCode) {
            print("JsTestDriver server finished with exit code " + exitCode + "\n", ConsoleViewContentType.SYSTEM_OUTPUT);
            JstdToolWindowManager.getInstance(getProperties().getProject()).show();
        }
    }, this);
}
Also used : TestTreeRenderer(com.intellij.execution.testframework.sm.runner.ui.TestTreeRenderer) OpenUrlHyperlinkInfo(com.intellij.ide.browsers.OpenUrlHyperlinkInfo) TestTreeView(com.intellij.execution.testframework.TestTreeView) JstdServerLifeCycleAdapter(com.google.jstestdriver.idea.server.JstdServerLifeCycleAdapter)

Example 4 with JstdServerLifeCycleAdapter

use of com.google.jstestdriver.idea.server.JstdServerLifeCycleAdapter 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 5 with JstdServerLifeCycleAdapter

use of com.google.jstestdriver.idea.server.JstdServerLifeCycleAdapter 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)

Aggregations

JstdServerLifeCycleAdapter (com.google.jstestdriver.idea.server.JstdServerLifeCycleAdapter)6 JstdBrowserInfo (com.google.jstestdriver.idea.server.JstdBrowserInfo)3 NopProcessHandler (com.intellij.execution.process.NopProcessHandler)3 ExecutionResult (com.intellij.execution.ExecutionResult)2 RunContentBuilder (com.intellij.execution.runners.RunContentBuilder)2 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)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 TestTreeView (com.intellij.execution.testframework.TestTreeView)1 TestTreeRenderer (com.intellij.execution.testframework.sm.runner.ui.TestTreeRenderer)1 OpenUrlHyperlinkInfo (com.intellij.ide.browsers.OpenUrlHyperlinkInfo)1 Alarm (com.intellij.util.Alarm)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1