Search in sources :

Example 26 with ExecutionException

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

the class MavenExternalExecutor method execute.

public boolean execute(final ProgressIndicator indicator) {
    displayProgress();
    try {
        if (myParameterCreationError != null) {
            throw myParameterCreationError;
        }
        myProcessHandler = new OSProcessHandler(myJavaParameters.toCommandLine()) {

            @Override
            public void notifyTextAvailable(String text, Key outputType) {
                // todo move this logic to ConsoleAdapter class
                if (!myConsole.isSuppressed(text)) {
                    super.notifyTextAvailable(text, outputType);
                }
                updateProgress(indicator, text);
            }
        };
        myConsole.attachToProcess(myProcessHandler);
    } catch (ExecutionException e) {
        myConsole.systemMessage(MavenServerConsole.LEVEL_FATAL, RunnerBundle.message("external.startup.failed", e.getMessage()), null);
        return false;
    }
    start();
    readProcessOutput();
    stop();
    return printExitSummary();
}
Also used : OSProcessHandler(com.intellij.execution.process.OSProcessHandler) ExecutionException(com.intellij.execution.ExecutionException) Key(com.intellij.openapi.util.Key)

Example 27 with ExecutionException

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

the class MavenExternalParameters method getJdk.

@NotNull
private static Sdk getJdk(@Nullable Project project, MavenRunnerSettings runnerSettings, boolean isGlobalRunnerSettings) throws ExecutionException {
    String name = runnerSettings.getJreName();
    if (name.equals(MavenRunnerSettings.USE_INTERNAL_JAVA)) {
        return JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
    }
    if (name.equals(MavenRunnerSettings.USE_PROJECT_JDK)) {
        if (project != null) {
            Sdk res = ProjectRootManager.getInstance(project).getProjectSdk();
            if (res != null) {
                return res;
            }
            Module[] modules = ModuleManager.getInstance(project).getModules();
            for (Module module : modules) {
                Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
                if (sdk != null && sdk.getSdkType() instanceof JavaSdkType) {
                    return sdk;
                }
            }
        }
        if (project == null) {
            Sdk recent = ProjectJdkTable.getInstance().findMostRecentSdkOfType(JavaSdk.getInstance());
            if (recent != null)
                return recent;
            return JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
        }
        throw new ProjectJdkSettingsOpenerExecutionException("Project JDK is not specified. <a href=''>Configure</a>", project);
    }
    if (name.equals(MavenRunnerSettings.USE_JAVA_HOME)) {
        final String javaHome = System.getenv("JAVA_HOME");
        if (StringUtil.isEmptyOrSpaces(javaHome)) {
            throw new ExecutionException(RunnerBundle.message("maven.java.home.undefined"));
        }
        final Sdk jdk = JavaSdk.getInstance().createJdk("", javaHome);
        if (jdk == null) {
            throw new ExecutionException(RunnerBundle.message("maven.java.home.invalid", javaHome));
        }
        return jdk;
    }
    for (Sdk projectJdk : ProjectJdkTable.getInstance().getAllJdks()) {
        if (projectJdk.getName().equals(name)) {
            return projectJdk;
        }
    }
    if (isGlobalRunnerSettings) {
        throw new ExecutionException(RunnerBundle.message("maven.java.not.found.default.config", name));
    } else {
        throw new ExecutionException(RunnerBundle.message("maven.java.not.found", name));
    }
}
Also used : JavaSdkType(com.intellij.openapi.projectRoots.JavaSdkType) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module) ExecutionException(com.intellij.execution.ExecutionException) NotNull(org.jetbrains.annotations.NotNull)

Example 28 with ExecutionException

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

the class PySdkUtil method getProcessOutput.

public static ProcessOutput getProcessOutput(@NotNull GeneralCommandLine cmd, @Nullable String homePath, @Nullable @NonNls Map<String, String> extraEnv, int timeout, @Nullable byte[] stdin, boolean needEOFMarker) {
    if (homePath == null || !new File(homePath).exists()) {
        return new ProcessOutput();
    }
    final Map<String, String> systemEnv = System.getenv();
    final Map<String, String> expandedCmdEnv = mergeEnvVariables(systemEnv, cmd.getEnvironment());
    final Map<String, String> env = extraEnv != null ? mergeEnvVariables(expandedCmdEnv, extraEnv) : expandedCmdEnv;
    PythonEnvUtil.resetHomePathChanges(homePath, env);
    try {
        final GeneralCommandLine commandLine = cmd.withWorkDirectory(homePath).withEnvironment(env);
        final CapturingProcessHandler processHandler = new CapturingProcessHandler(commandLine);
        if (stdin != null) {
            final OutputStream processInput = processHandler.getProcessInput();
            assert processInput != null;
            processInput.write(stdin);
            if (SystemInfo.isWindows && needEOFMarker) {
                processInput.write(SUBSTITUTE);
                processInput.flush();
            } else {
                processInput.close();
            }
        }
        return processHandler.runProcess(timeout);
    } catch (ExecutionException | IOException e) {
        return getOutputForException(e);
    }
}
Also used : ProcessOutput(com.intellij.execution.process.ProcessOutput) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) OutputStream(java.io.OutputStream) IOException(java.io.IOException) ExecutionException(com.intellij.execution.ExecutionException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) CapturingProcessHandler(com.intellij.execution.process.CapturingProcessHandler)

Example 29 with ExecutionException

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

the class TestsPattern method createSearchingForTestsTask.

@Override
public SearchForTestsTask createSearchingForTestsTask() {
    final JUnitConfiguration.Data data = getConfiguration().getPersistentData();
    final Project project = getConfiguration().getProject();
    final Set<String> classNames = new LinkedHashSet<>();
    for (String className : data.getPatterns()) {
        final PsiClass psiClass = getTestClass(project, className);
        if (psiClass != null && JUnitUtil.isTestClass(psiClass)) {
            classNames.add(className);
        }
    }
    if (classNames.size() == data.getPatterns().size()) {
        return new SearchForTestsTask(project, myServerSocket) {

            @Override
            protected void search() throws ExecutionException {
                final Function<String, String> nameFunction = StringUtil.isEmpty(data.METHOD_NAME) ? FunctionUtil.<String>id() : (Function<String, String>) className -> className;
                addClassesListToJavaParameters(classNames, nameFunction, "", false, getJavaParameters());
            }

            @Override
            protected void onFound() {
            }
        };
    }
    return super.createSearchingForTestsTask();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) RuntimeConfigurationException(com.intellij.execution.configurations.RuntimeConfigurationException) ExecutionException(com.intellij.execution.ExecutionException) StringUtil(com.intellij.openapi.util.text.StringUtil) RefactoringElementListener(com.intellij.refactoring.listeners.RefactoringElementListener) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Set(java.util.Set) JavaExecutionUtil(com.intellij.execution.JavaExecutionUtil) Nullable(org.jetbrains.annotations.Nullable) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) RefactoringElementListenerComposite(com.intellij.refactoring.listeners.RefactoringElementListenerComposite) Function(com.intellij.util.Function) SearchForTestsTask(com.intellij.execution.testframework.SearchForTestsTask) Project(com.intellij.openapi.project.Project) com.intellij.psi(com.intellij.psi) FunctionUtil(com.intellij.util.FunctionUtil) CantRunException(com.intellij.execution.CantRunException) RuntimeConfigurationWarning(com.intellij.execution.configurations.RuntimeConfigurationWarning) Module(com.intellij.openapi.module.Module) LinkedHashSet(java.util.LinkedHashSet) Project(com.intellij.openapi.project.Project) SearchForTestsTask(com.intellij.execution.testframework.SearchForTestsTask)

Example 30 with ExecutionException

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

the class PyAbstractTestProcessRunner method rerunFailedTests.

/**
   * Rerun current tests. Make sure there is at least one failed test.
   * <strong>Run in AWT thread only!</strong>
   */
public void rerunFailedTests() {
    assert getFailedTestsCount() > 0 : "No failed tests. What you want to rerun?";
    assert myLastProcessDescriptor != null : "No last run descriptor. First run tests at least one time";
    final List<ProgramRunner<?>> run = getAvailableRunnersForLastRun();
    Assert.assertFalse("No runners to rerun", run.isEmpty());
    final ProgramRunner<?> runner = run.get(0);
    final ExecutionEnvironment restartAction = RerunFailedActionsTestTools.findRestartAction(myLastProcessDescriptor);
    Assert.assertNotNull("No restart action", restartAction);
    final Ref<ProcessHandler> handlerRef = new Ref<>();
    try {
        runner.execute(restartAction, descriptor -> handlerRef.set(descriptor.getProcessHandler()));
    } catch (final ExecutionException e) {
        throw new AssertionError("ExecutionException can't be thrown in tests. Probably, API changed. Got: " + e);
    }
    final ProcessHandler handler = handlerRef.get();
    if (handler == null) {
        return;
    }
    handler.waitFor();
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) Ref(com.intellij.openapi.util.Ref) ProcessHandler(com.intellij.execution.process.ProcessHandler) ProgramRunner(com.intellij.execution.runners.ProgramRunner) ExecutionException(com.intellij.execution.ExecutionException)

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