Search in sources :

Example 51 with ExecutionException

use of com.intellij.execution.ExecutionException in project intellij-plugins by JetBrains.

the class DartRunner method doExecute.

@Override
protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNull ExecutionEnvironment env) throws ExecutionException {
    final String executorId = env.getExecutor().getId();
    if (!DefaultDebugExecutor.EXECUTOR_ID.equals(executorId)) {
        LOG.error("Unexpected executor id: " + executorId);
        return null;
    }
    try {
        final String dasExecutionContextId;
        final RunProfile runConfig = env.getRunProfile();
        if (runConfig instanceof DartRunConfigurationBase && DartAnalysisServerService.getInstance(env.getProject()).serverReadyForRequest(env.getProject())) {
            final String path = ((DartRunConfigurationBase) runConfig).getRunnerParameters().getFilePath();
            // already checked
            assert path != null;
            dasExecutionContextId = DartAnalysisServerService.getInstance(env.getProject()).execution_createContext(path);
        } else {
            // remote debug or can't start DAS
            dasExecutionContextId = null;
        }
        return doExecuteDartDebug(state, env, dasExecutionContextId);
    } catch (RuntimeConfigurationError e) {
        throw new ExecutionException(e);
    }
}
Also used : DartRunConfigurationBase(com.jetbrains.lang.dart.ide.runner.base.DartRunConfigurationBase) RunProfile(com.intellij.execution.configurations.RunProfile) ExecutionException(com.intellij.execution.ExecutionException) RuntimeConfigurationError(com.intellij.execution.configurations.RuntimeConfigurationError)

Example 52 with ExecutionException

use of com.intellij.execution.ExecutionException in project intellij-plugins by JetBrains.

the class DartCommandLineRunningState method setupParameters.

private void setupParameters(@NotNull final GeneralCommandLine commandLine, @Nullable final String overriddenMainFilePath) throws ExecutionException {
    int customObservatoryPort = -1;
    final String vmOptions = myRunnerParameters.getVMOptions();
    if (vmOptions != null) {
        final StringTokenizer vmOptionsTokenizer = new CommandLineTokenizer(vmOptions);
        while (vmOptionsTokenizer.hasMoreTokens()) {
            final String vmOption = vmOptionsTokenizer.nextToken();
            commandLine.addParameter(vmOption);
            try {
                if (vmOption.equals("--enable-vm-service") || vmOption.equals("--observe")) {
                    // default port, see https://www.dartlang.org/tools/dart-vm/
                    customObservatoryPort = 8181;
                } else if (vmOption.startsWith("--enable-vm-service:")) {
                    customObservatoryPort = parseIntBeforeSlash(vmOption.substring("--enable-vm-service:".length()));
                } else if (vmOption.startsWith("--observe:")) {
                    customObservatoryPort = parseIntBeforeSlash(vmOption.substring("--observe:".length()));
                }
            } catch (NumberFormatException ignore) {
            /**/
            }
        }
    }
    if (myRunnerParameters.isCheckedMode()) {
        commandLine.addParameter(DartiumUtil.CHECKED_MODE_OPTION);
    }
    final VirtualFile dartFile;
    try {
        dartFile = myRunnerParameters.getDartFileOrDirectory();
    } catch (RuntimeConfigurationError e) {
        throw new ExecutionException(e);
    }
    if (DefaultDebugExecutor.EXECUTOR_ID.equals(getEnvironment().getExecutor().getId())) {
        commandLine.addParameter("--pause_isolates_on_start");
    }
    if (customObservatoryPort > 0) {
        myObservatoryPort = customObservatoryPort;
    } else {
        try {
            myObservatoryPort = NetUtils.findAvailableSocketPort();
        } catch (IOException e) {
            throw new ExecutionException(e);
        }
        commandLine.addParameter("--enable-vm-service:" + myObservatoryPort);
        if (getEnvironment().getRunner() instanceof DartCoverageProgramRunner) {
            commandLine.addParameter("--pause-isolates-on-exit");
        }
    }
    commandLine.addParameter(FileUtil.toSystemDependentName(overriddenMainFilePath == null ? dartFile.getPath() : overriddenMainFilePath));
    final String arguments = myRunnerParameters.getArguments();
    if (arguments != null) {
        StringTokenizer argumentsTokenizer = new CommandLineTokenizer(arguments);
        while (argumentsTokenizer.hasMoreTokens()) {
            commandLine.addParameter(argumentsTokenizer.nextToken());
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IOException(java.io.IOException) ExecutionException(com.intellij.execution.ExecutionException) RuntimeConfigurationError(com.intellij.execution.configurations.RuntimeConfigurationError) DartCoverageProgramRunner(com.jetbrains.lang.dart.coverage.DartCoverageProgramRunner) CommandLineTokenizer(com.intellij.execution.configurations.CommandLineTokenizer)

Example 53 with ExecutionException

use of com.intellij.execution.ExecutionException in project intellij-plugins by JetBrains.

the class JstdRunProfileState method buildTestFileScope.

@NotNull
private static TestFileScope buildTestFileScope(@NotNull Project project, @NotNull JstdRunSettings settings) throws ExecutionException {
    TestType testType = settings.getTestType();
    if (testType == TestType.ALL_CONFIGS_IN_DIRECTORY || testType == TestType.CONFIG_FILE) {
        return TestFileScope.allScope();
    }
    if (testType == TestType.JS_FILE) {
        File jsFile = new File(settings.getJsFilePath());
        if (jsFile.isAbsolute() && jsFile.isFile()) {
            VirtualFile virtualFile = VfsUtil.findFileByIoFile(jsFile, true);
            if (virtualFile != null) {
                PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
                if (psiFile instanceof JSFile) {
                    JSFile jsPsiFile = (JSFile) psiFile;
                    TestFileStructurePack pack = TestFileStructureManager.fetchTestFileStructurePackByJsFile(jsPsiFile);
                    if (pack != null) {
                        List<String> testCases = pack.getTopLevelElements();
                        if (testCases.isEmpty()) {
                            throw new ExecutionException("No tests found in " + jsPsiFile.getName());
                        }
                        Map<String, Set<String>> scope = ContainerUtil.newHashMap();
                        for (String testCase : testCases) {
                            scope.put(testCase, Collections.emptySet());
                        }
                        return TestFileScope.customScope(scope);
                    }
                }
            }
        }
        throw new ExecutionException("Unable to extract tests from " + jsFile.getName());
    }
    if (testType == TestType.TEST_CASE) {
        Map<String, Set<String>> scope = Collections.singletonMap(settings.getTestCaseName(), Collections.<String>emptySet());
        return TestFileScope.customScope(scope);
    }
    if (testType == TestType.TEST_METHOD) {
        Map<String, Set<String>> scope = Collections.singletonMap(settings.getTestCaseName(), Collections.singleton(settings.getTestMethodName()));
        return TestFileScope.customScope(scope);
    }
    throw new RuntimeException("Unexpected test type: " + testType);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TestFileStructurePack(com.intellij.javascript.testFramework.TestFileStructurePack) ImmutableSet(com.google.common.collect.ImmutableSet) PsiFile(com.intellij.psi.PsiFile) TestType(com.google.jstestdriver.idea.execution.settings.TestType) JSFile(com.intellij.lang.javascript.psi.JSFile) ExecutionException(com.intellij.execution.ExecutionException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) JSFile(com.intellij.lang.javascript.psi.JSFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 54 with ExecutionException

use of com.intellij.execution.ExecutionException in project intellij-plugins by JetBrains.

the class JstdRunProfileState method executeWithServer.

@NotNull
public ExecutionResult executeWithServer(@Nullable JstdServer ideServer) throws ExecutionException {
    if (!myRunSettings.isExternalServerType() && ideServer == null) {
        throw new ExecutionException("[Internal error] Local JsTestDriver server running in IDE not found");
    }
    ProcessHandler processHandler = createProcessHandler(ideServer);
    ConsoleView consoleView = createSMTRunnerConsoleView(ideServer);
    consoleView.attachToProcess(processHandler);
    DefaultExecutionResult executionResult = new DefaultExecutionResult(consoleView, processHandler);
    executionResult.setRestartActions(new ToggleAutoTestAction());
    return executionResult;
}
Also used : DefaultExecutionResult(com.intellij.execution.DefaultExecutionResult) SMTRunnerConsoleView(com.intellij.execution.testframework.sm.runner.ui.SMTRunnerConsoleView) ConsoleView(com.intellij.execution.ui.ConsoleView) NopProcessHandler(com.intellij.execution.process.NopProcessHandler) KillableColoredProcessHandler(com.intellij.execution.process.KillableColoredProcessHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler) ToggleAutoTestAction(com.intellij.execution.testframework.autotest.ToggleAutoTestAction) ExecutionException(com.intellij.execution.ExecutionException) NotNull(org.jetbrains.annotations.NotNull)

Example 55 with ExecutionException

use of com.intellij.execution.ExecutionException in project intellij-plugins by JetBrains.

the class JstdRunProgramRunner method execute.

@NotNull
@Override
protected Promise<RunContentDescriptor> execute(@NotNull ExecutionEnvironment environment, @NotNull RunProfileState state) throws ExecutionException {
    JstdRunProfileState jstdState = JstdRunProfileState.cast(state);
    if (jstdState.getRunSettings().isExternalServerType()) {
        return Promise.resolve(start(null, false, state, environment));
    }
    JstdToolWindowManager jstdToolWindowManager = JstdToolWindowManager.getInstance(environment.getProject());
    jstdToolWindowManager.setAvailable(true);
    JstdServer server = JstdServerRegistry.getInstance().getServer();
    if (server != null && !server.isStopped()) {
        return Promise.resolve(start(server, false, state, environment));
    }
    return jstdToolWindowManager.restartServer().thenAsync(it -> {
        try {
            return it == null ? null : Promises.resolvedPromise(start(it, false, state, environment));
        } catch (ExecutionException e) {
            return Promises.rejectedPromise(e);
        }
    });
}
Also used : JstdToolWindowManager(com.google.jstestdriver.idea.server.ui.JstdToolWindowManager) JstdServer(com.google.jstestdriver.idea.server.JstdServer) ExecutionException(com.intellij.execution.ExecutionException) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ExecutionException (com.intellij.execution.ExecutionException)154 NotNull (org.jetbrains.annotations.NotNull)42 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)39 IOException (java.io.IOException)35 File (java.io.File)34 VirtualFile (com.intellij.openapi.vfs.VirtualFile)26 Sdk (com.intellij.openapi.projectRoots.Sdk)20 Nullable (org.jetbrains.annotations.Nullable)20 Project (com.intellij.openapi.project.Project)19 ProcessHandler (com.intellij.execution.process.ProcessHandler)17 ProcessOutput (com.intellij.execution.process.ProcessOutput)17 Module (com.intellij.openapi.module.Module)13 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)12 Key (com.intellij.openapi.util.Key)12 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)10 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)9 ProcessEvent (com.intellij.execution.process.ProcessEvent)8 JavaParameters (com.intellij.execution.configurations.JavaParameters)7 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)7 ArrayList (java.util.ArrayList)7