Search in sources :

Example 1 with KarmaServer

use of com.intellij.javascript.karma.server.KarmaServer in project intellij-plugins by JetBrains.

the class KarmaRunProfileState method getServerOrStart.

@Nullable
public KarmaServer getServerOrStart(@NotNull final Executor executor) throws ExecutionException {
    NodeJsInterpreter interpreter = myRunSettings.getInterpreterRef().resolve(myProject);
    NodeJsLocalInterpreter localInterpreter = NodeJsLocalInterpreter.castAndValidate(interpreter);
    KarmaServerSettings serverSettings = new KarmaServerSettings.Builder().setNodeInterpreter(localInterpreter).setKarmaPackage(myKarmaPackage).setRunSettings(myRunSettings).setWithCoverage(myExecutionType == KarmaExecutionType.COVERAGE).setDebug(myExecutionType == KarmaExecutionType.DEBUG).build();
    KarmaServerRegistry registry = KarmaServerRegistry.getInstance(myProject);
    KarmaServer server = registry.getServer(serverSettings);
    if (server != null && server.getRestarter().isRestartRequired()) {
        server.shutdownAsync();
        server = null;
    }
    if (server == null) {
        registry.startServer(serverSettings, new CatchingConsumer<KarmaServer, Exception>() {

            @Override
            public void consume(KarmaServer server) {
                RunnerAndConfigurationSettings configuration = myEnvironment.getRunnerAndConfigurationSettings();
                if (configuration != null) {
                    ProgramRunnerUtil.executeConfiguration(myProject, configuration, executor);
                }
            }

            @Override
            public void consume(final Exception e) {
                LOG.error(e);
                showServerStartupError(e);
            }
        });
    }
    return server;
}
Also used : NodeJsInterpreter(com.intellij.javascript.nodejs.interpreter.NodeJsInterpreter) KarmaServer(com.intellij.javascript.karma.server.KarmaServer) NodeJsLocalInterpreter(com.intellij.javascript.nodejs.interpreter.local.NodeJsLocalInterpreter) KarmaServerRegistry(com.intellij.javascript.karma.server.KarmaServerRegistry) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with KarmaServer

use of com.intellij.javascript.karma.server.KarmaServer in project intellij-plugins by JetBrains.

the class KarmaRunProgramRunner method doExecute.

@Nullable
@Override
protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNull ExecutionEnvironment environment) throws ExecutionException {
    FileDocumentManager.getInstance().saveAllDocuments();
    ExecutionResult executionResult = state.execute(environment.getExecutor(), this);
    if (executionResult == null) {
        return null;
    }
    KarmaConsoleView consoleView = KarmaConsoleView.get(executionResult, state);
    final RunContentDescriptor descriptor = KarmaUtil.createDefaultDescriptor(executionResult, environment);
    if (consoleView == null) {
        return descriptor;
    }
    KarmaServer server = consoleView.getKarmaExecutionSession().getKarmaServer();
    if (!server.areBrowsersReady()) {
        server.onBrowsersReady(() -> ExecutionUtil.restartIfActive(descriptor));
    } else {
        RerunTestsNotification.showRerunNotification(environment.getContentToReuse(), executionResult.getExecutionConsole());
    }
    RerunTestsAction.register(descriptor);
    return descriptor;
}
Also used : KarmaServer(com.intellij.javascript.karma.server.KarmaServer) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ExecutionResult(com.intellij.execution.ExecutionResult) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with KarmaServer

use of com.intellij.javascript.karma.server.KarmaServer in project intellij-plugins by JetBrains.

the class KarmaDebugProgramRunner method execute.

@NotNull
@Override
protected Promise<RunContentDescriptor> execute(@NotNull ExecutionEnvironment environment, @NotNull RunProfileState state) throws ExecutionException {
    FileDocumentManager.getInstance().saveAllDocuments();
    ExecutionResult executionResult = state.execute(environment.getExecutor(), this);
    if (executionResult == null) {
        return Promise.resolve(null);
    }
    KarmaConsoleView consoleView = KarmaConsoleView.get(executionResult, state);
    if (consoleView == null) {
        return Promise.resolve(KarmaUtil.createDefaultDescriptor(executionResult, environment));
    }
    KarmaServer karmaServer = consoleView.getKarmaExecutionSession().getKarmaServer();
    if (karmaServer.areBrowsersReady()) {
        KarmaDebugBrowserSelector browserSelector = new KarmaDebugBrowserSelector(karmaServer.getCapturedBrowsers(), environment, consoleView);
        DebuggableWebBrowser debuggableWebBrowser = browserSelector.selectDebugEngine();
        if (debuggableWebBrowser == null) {
            return Promises.resolvedPromise(KarmaUtil.createDefaultDescriptor(executionResult, environment));
        }
        return KarmaKt.prepareKarmaDebugger(environment.getProject(), debuggableWebBrowser, () -> createDescriptor(environment, executionResult, consoleView, karmaServer, debuggableWebBrowser));
    } else {
        RunContentDescriptor descriptor = KarmaUtil.createDefaultDescriptor(executionResult, environment);
        karmaServer.onBrowsersReady(() -> ExecutionUtil.restartIfActive(descriptor));
        return Promises.resolvedPromise(descriptor);
    }
}
Also used : KarmaServer(com.intellij.javascript.karma.server.KarmaServer) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) KarmaConsoleView(com.intellij.javascript.karma.execution.KarmaConsoleView) ExecutionResult(com.intellij.execution.ExecutionResult) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with KarmaServer

use of com.intellij.javascript.karma.server.KarmaServer in project intellij-plugins by JetBrains.

the class KarmaCoverageProgramRunner method listenForCoverageFile.

private static void listenForCoverageFile(@NotNull ExecutionEnvironment env, @NotNull KarmaServer server) throws ExecutionException {
    KarmaRunConfiguration runConfiguration = (KarmaRunConfiguration) env.getRunProfile();
    CoverageEnabledConfiguration coverageEnabledConfiguration = CoverageEnabledConfiguration.getOrCreate(runConfiguration);
    CoverageHelper.resetCoverageSuit(runConfiguration);
    String coverageFilePath = coverageEnabledConfiguration.getCoverageFilePath();
    if (coverageFilePath != null) {
        KarmaCoveragePeer coveragePeer = server.getCoveragePeer();
        Objects.requireNonNull(coveragePeer);
        coveragePeer.startCoverageSession(new KarmaCoverageSession() {

            @Override
            public void onCoverageSessionFinished(@Nullable File lcovFile) {
                LOG.info("Processing karma coverage file: " + lcovFile);
                UIUtil.invokeLaterIfNeeded(() -> {
                    Project project = env.getProject();
                    if (project.isDisposed())
                        return;
                    if (lcovFile != null) {
                        processLcovInfoFile(lcovFile, coverageFilePath, env, server, runConfiguration);
                    } else {
                        int response = Messages.showYesNoDialog(project, "Cannot find karma test coverage report - lcov.info", "Missing Karma Coverage Report", "Select lcov.info", "Cancel", Messages.getWarningIcon());
                        if (response == Messages.YES) {
                            FileChooser.chooseFile(FileChooserDescriptorFactory.createSingleFileDescriptor(), project, null, null, file -> {
                                File selected = file != null ? VfsUtilCore.virtualToIoFile(file) : null;
                                if (selected != null) {
                                    processLcovInfoFile(selected, coverageFilePath, env, server, runConfiguration);
                                }
                            });
                        }
                    }
                });
            }
        });
    }
}
Also used : KarmaRunConfiguration(com.intellij.javascript.karma.execution.KarmaRunConfiguration) KarmaUtil(com.intellij.javascript.karma.util.KarmaUtil) KarmaRunConfiguration(com.intellij.javascript.karma.execution.KarmaRunConfiguration) UIUtil(com.intellij.util.ui.UIUtil) FileChooserDescriptorFactory(com.intellij.openapi.fileChooser.FileChooserDescriptorFactory) ExecutionException(com.intellij.execution.ExecutionException) CoverageHelper(com.intellij.coverage.CoverageHelper) RunProfileState(com.intellij.execution.configurations.RunProfileState) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) Project(com.intellij.openapi.project.Project) ExecutionResult(com.intellij.execution.ExecutionResult) Messages(com.intellij.openapi.ui.Messages) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) CoverageEnabledConfiguration(com.intellij.execution.configurations.coverage.CoverageEnabledConfiguration) CoverageRunnerData(com.intellij.coverage.CoverageRunnerData) ConfigurationInfoProvider(com.intellij.execution.configurations.ConfigurationInfoProvider) GenericProgramRunner(com.intellij.execution.runners.GenericProgramRunner) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) KarmaServer(com.intellij.javascript.karma.server.KarmaServer) CoverageDataManager(com.intellij.coverage.CoverageDataManager) RunProfile(com.intellij.execution.configurations.RunProfile) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) IOException(java.io.IOException) RunnerSettings(com.intellij.execution.configurations.RunnerSettings) File(java.io.File) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) CoverageExecutor(com.intellij.coverage.CoverageExecutor) ExecutionUtil(com.intellij.execution.runners.ExecutionUtil) KarmaConsoleView(com.intellij.javascript.karma.execution.KarmaConsoleView) NotNull(org.jetbrains.annotations.NotNull) FileChooser(com.intellij.openapi.fileChooser.FileChooser) Project(com.intellij.openapi.project.Project) CoverageEnabledConfiguration(com.intellij.execution.configurations.coverage.CoverageEnabledConfiguration) File(java.io.File)

Example 5 with KarmaServer

use of com.intellij.javascript.karma.server.KarmaServer in project intellij-plugins by JetBrains.

the class KarmaCoverageProgramRunner method doExecute.

@Override
protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNull final ExecutionEnvironment env) throws ExecutionException {
    FileDocumentManager.getInstance().saveAllDocuments();
    ExecutionResult executionResult = state.execute(env.getExecutor(), this);
    if (executionResult == null) {
        return null;
    }
    RunContentDescriptor descriptor = KarmaUtil.createDefaultDescriptor(executionResult, env);
    KarmaConsoleView consoleView = KarmaConsoleView.get(executionResult, state);
    if (consoleView == null) {
        return descriptor;
    }
    KarmaServer server = consoleView.getKarmaExecutionSession().getKarmaServer();
    if (server.areBrowsersReady()) {
        listenForCoverageFile(env, server);
    } else {
        server.onBrowsersReady(() -> ExecutionUtil.restartIfActive(descriptor));
    }
    return descriptor;
}
Also used : KarmaServer(com.intellij.javascript.karma.server.KarmaServer) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) KarmaConsoleView(com.intellij.javascript.karma.execution.KarmaConsoleView) ExecutionResult(com.intellij.execution.ExecutionResult)

Aggregations

KarmaServer (com.intellij.javascript.karma.server.KarmaServer)5 ExecutionResult (com.intellij.execution.ExecutionResult)4 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)4 KarmaConsoleView (com.intellij.javascript.karma.execution.KarmaConsoleView)3 Nullable (org.jetbrains.annotations.Nullable)3 NotNull (org.jetbrains.annotations.NotNull)2 CoverageDataManager (com.intellij.coverage.CoverageDataManager)1 CoverageExecutor (com.intellij.coverage.CoverageExecutor)1 CoverageHelper (com.intellij.coverage.CoverageHelper)1 CoverageRunnerData (com.intellij.coverage.CoverageRunnerData)1 ExecutionException (com.intellij.execution.ExecutionException)1 ConfigurationInfoProvider (com.intellij.execution.configurations.ConfigurationInfoProvider)1 RunProfile (com.intellij.execution.configurations.RunProfile)1 RunProfileState (com.intellij.execution.configurations.RunProfileState)1 RunnerSettings (com.intellij.execution.configurations.RunnerSettings)1 CoverageEnabledConfiguration (com.intellij.execution.configurations.coverage.CoverageEnabledConfiguration)1 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)1 ExecutionUtil (com.intellij.execution.runners.ExecutionUtil)1 GenericProgramRunner (com.intellij.execution.runners.GenericProgramRunner)1 KarmaRunConfiguration (com.intellij.javascript.karma.execution.KarmaRunConfiguration)1