Search in sources :

Example 36 with ExecutionEnvironment

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

the class AbstractRerunFailedTestsAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    ExecutionEnvironment environment = e.getData(LangDataKeys.EXECUTION_ENVIRONMENT);
    if (environment == null) {
        return;
    }
    execute(e, environment);
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment)

Example 37 with ExecutionEnvironment

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

the class RerunFailedTestsAction method getAction.

private static boolean getAction(@NotNull AnActionEvent e, boolean execute) {
    Project project = e.getProject();
    if (project == null) {
        return false;
    }
    RunContentDescriptor contentDescriptor = ExecutionManager.getInstance(project).getContentManager().getSelectedContent();
    if (contentDescriptor == null) {
        return false;
    }
    JComponent component = contentDescriptor.getComponent();
    if (component == null) {
        return false;
    }
    ExecutionEnvironment environment = LangDataKeys.EXECUTION_ENVIRONMENT.getData(DataManager.getInstance().getDataContext(component));
    if (environment == null) {
        return false;
    }
    AnAction[] actions = contentDescriptor.getRestartActions();
    if (actions.length == 0) {
        return false;
    }
    for (AnAction action : actions) {
        if (action instanceof AbstractRerunFailedTestsAction) {
            if (execute) {
                ((AbstractRerunFailedTestsAction) action).execute(e, environment);
            }
            return true;
        }
    }
    return false;
}
Also used : Project(com.intellij.openapi.project.Project) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 38 with ExecutionEnvironment

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

the class GradleRerunFailedTestsAction method getRunProfile.

@Nullable
@Override
protected MyRunProfile getRunProfile(@NotNull ExecutionEnvironment environment) {
    ExternalSystemRunConfiguration configuration = (ExternalSystemRunConfiguration) myConsoleProperties.getConfiguration();
    final List<AbstractTestProxy> failedTests = getFailedTests(configuration.getProject());
    return new MyRunProfile(configuration) {

        @NotNull
        @Override
        public Module[] getModules() {
            return Module.EMPTY_ARRAY;
        }

        @Nullable
        @Override
        public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment environment) throws ExecutionException {
            ExternalSystemRunConfiguration runProfile = ((ExternalSystemRunConfiguration) getPeer()).clone();
            Project project = runProfile.getProject();
            Set<String> scriptParameters = ContainerUtil.newLinkedHashSet();
            Set<String> tasksToRun = ContainerUtil.newLinkedHashSet();
            boolean useResolvedTasks = true;
            for (AbstractTestProxy test : failedTests) {
                if (test instanceof GradleSMTestProxy) {
                    String testName = test.getName();
                    String className = ((GradleSMTestProxy) test).getClassName();
                    scriptParameters.add(TestMethodGradleConfigurationProducer.createTestFilter(className, testName));
                    if (!useResolvedTasks)
                        continue;
                    if (className == null) {
                        useResolvedTasks = false;
                        continue;
                    }
                    final PsiClass psiClass = JavaPsiFacade.getInstance(project).findClass(className, GlobalSearchScope.projectScope(project));
                    if (psiClass == null) {
                        useResolvedTasks = false;
                        continue;
                    }
                    final PsiFile psiFile = psiClass.getContainingFile();
                    if (psiFile == null) {
                        useResolvedTasks = false;
                        continue;
                    }
                    final Module moduleForFile = ProjectFileIndex.SERVICE.getInstance(project).getModuleForFile(psiFile.getVirtualFile());
                    if (moduleForFile == null) {
                        useResolvedTasks = false;
                        continue;
                    }
                    ContainerUtil.addAllNotNull(tasksToRun, GradleTestRunConfigurationProducer.getTasksToRun(moduleForFile));
                }
            }
            runProfile.getSettings().setScriptParameters(StringUtil.join(scriptParameters, " "));
            if (useResolvedTasks && !tasksToRun.isEmpty()) {
                runProfile.getSettings().setTaskNames(ContainerUtil.newArrayList(tasksToRun));
            }
            return runProfile.getState(executor, environment);
        }
    };
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) GradleSMTestProxy(org.jetbrains.plugins.gradle.execution.test.runner.GradleSMTestProxy) PsiClass(com.intellij.psi.PsiClass) ExternalSystemRunConfiguration(com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration) AbstractTestProxy(com.intellij.execution.testframework.AbstractTestProxy) NotNull(org.jetbrains.annotations.NotNull) Project(com.intellij.openapi.project.Project) Executor(com.intellij.execution.Executor) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 39 with ExecutionEnvironment

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

the class RerunFailedTestsAction method getRunProfile.

@Override
protected MyRunProfile getRunProfile(@NotNull ExecutionEnvironment environment) {
    final TestNGConfiguration configuration = (TestNGConfiguration) myConsoleProperties.getConfiguration();
    final List<AbstractTestProxy> failedTests = getFailedTests(configuration.getProject());
    return new MyRunProfile(configuration) {

        @Override
        @NotNull
        public Module[] getModules() {
            return configuration.getModules();
        }

        @Override
        public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) {
            return new TestNGRunnableState(env, configuration) {

                @Override
                public SearchingForTestsTask createSearchingForTestsTask() {
                    return new SearchingForTestsTask(myServerSocket, getConfiguration(), myTempFile) {

                        @Override
                        protected void fillTestObjects(final Map<PsiClass, Map<PsiMethod, List<String>>> classes) throws CantRunException {
                            final HashMap<PsiClass, Map<PsiMethod, List<String>>> fullClassList = ContainerUtil.newHashMap();
                            super.fillTestObjects(fullClassList);
                            for (final PsiClass aClass : fullClassList.keySet()) {
                                if (!ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {

                                    @Override
                                    public Boolean compute() {
                                        return TestNGUtil.hasTest(aClass);
                                    }
                                })) {
                                    classes.put(aClass, fullClassList.get(aClass));
                                }
                            }
                            final GlobalSearchScope scope = getConfiguration().getConfigurationModule().getSearchScope();
                            final Project project = getConfiguration().getProject();
                            for (final AbstractTestProxy proxy : failedTests) {
                                ApplicationManager.getApplication().runReadAction(() -> includeFailedTestWithDependencies(classes, scope, project, proxy));
                            }
                        }
                    };
                }
            };
        }
    };
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) PsiMethod(com.intellij.psi.PsiMethod) TestNGConfiguration(com.theoryinpractice.testng.configuration.TestNGConfiguration) PsiClass(com.intellij.psi.PsiClass) AbstractTestProxy(com.intellij.execution.testframework.AbstractTestProxy) NotNull(org.jetbrains.annotations.NotNull) Project(com.intellij.openapi.project.Project) Executor(com.intellij.execution.Executor) TestNGRunnableState(com.theoryinpractice.testng.configuration.TestNGRunnableState) SearchingForTestsTask(com.theoryinpractice.testng.configuration.SearchingForTestsTask) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Module(com.intellij.openapi.module.Module) Computable(com.intellij.openapi.util.Computable)

Example 40 with ExecutionEnvironment

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

the class MavenRunConfigurationType method runConfiguration.

public static void runConfiguration(Project project, @NotNull MavenRunnerParameters params, @Nullable MavenGeneralSettings settings, @Nullable MavenRunnerSettings runnerSettings, @Nullable ProgramRunner.Callback callback) {
    RunnerAndConfigurationSettings configSettings = createRunnerAndConfigurationSettings(settings, runnerSettings, params, project);
    ProgramRunner runner = DefaultJavaProgramRunner.getInstance();
    Executor executor = DefaultRunExecutor.getRunExecutorInstance();
    try {
        runner.execute(new ExecutionEnvironment(executor, runner, configSettings, project), callback);
    } catch (ExecutionException e) {
        MavenUtil.showError(project, "Failed to execute Maven goal", e);
    }
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) DefaultJavaProgramRunner(com.intellij.execution.impl.DefaultJavaProgramRunner) ProgramRunner(com.intellij.execution.runners.ProgramRunner)

Aggregations

ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)50 ProcessHandler (com.intellij.execution.process.ProcessHandler)13 ProcessEvent (com.intellij.execution.process.ProcessEvent)12 NotNull (org.jetbrains.annotations.NotNull)12 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)11 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)11 Project (com.intellij.openapi.project.Project)11 Nullable (org.jetbrains.annotations.Nullable)11 ExecutionException (com.intellij.execution.ExecutionException)10 ProgramRunner (com.intellij.execution.runners.ProgramRunner)10 Executor (com.intellij.execution.Executor)8 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)8 ExecutionEnvironmentBuilder (com.intellij.execution.runners.ExecutionEnvironmentBuilder)8 Key (com.intellij.openapi.util.Key)8 RunProfile (com.intellij.execution.configurations.RunProfile)7 DefaultDebugExecutor (com.intellij.execution.executors.DefaultDebugExecutor)7 Ref (com.intellij.openapi.util.Ref)7 Module (com.intellij.openapi.module.Module)6 IOException (java.io.IOException)5 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)4