Search in sources :

Example 41 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) {
    //noinspection ConstantConditions
    final JUnitConfiguration configuration = (JUnitConfiguration) myConsoleProperties.getConfiguration();
    final TestMethods testMethods = new TestMethods(configuration, environment, getFailedTests(configuration.getProject()));
    return new MyRunProfile(configuration) {

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

        @Override
        public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) {
            testMethods.clear();
            return testMethods;
        }
    };
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) Executor(com.intellij.execution.Executor) JUnitConfiguration(com.intellij.execution.junit.JUnitConfiguration) TestMethods(com.intellij.execution.junit.TestMethods) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 42 with ExecutionEnvironment

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

the class JUnitClasspathTest method testWorkingDirsFileWhenConfigurationSpansToMultipleModules.

public void testWorkingDirsFileWhenConfigurationSpansToMultipleModules() throws Exception {
    final Module mod1 = setupModule("mod1", "T1");
    final Module mod2 = setupModule("mod2", "T2");
    final JUnitConfiguration configuration = new JUnitConfiguration("p", getProject(), JUnitConfigurationType.getInstance().getConfigurationFactories()[0]);
    configuration.setWorkingDirectory("$MODULE_DIR$");
    final JUnitConfiguration.Data persistentData = configuration.getPersistentData();
    persistentData.setScope(TestSearchScope.SINGLE_MODULE);
    configuration.setModule(mod1);
    persistentData.PACKAGE_NAME = "p";
    persistentData.TEST_OBJECT = JUnitConfiguration.TEST_PACKAGE;
    final ExecutionEnvironment environment = ExecutionEnvironmentBuilder.create(DefaultRunExecutor.getRunExecutorInstance(), configuration).build();
    final TestPackage aPackage = new TestPackage(configuration, environment) {

        @Override
        protected boolean createTempFiles() {
            return true;
        }
    };
    //ensure no fork if single module is selected
    aPackage.createSearchingForTestsTask().startSearch();
    File workingDirsFile = aPackage.getWorkingDirsFile();
    assertNotNull(workingDirsFile);
    assertEmpty(FileUtil.loadFile(workingDirsFile));
    //ensure fork when whole project is used
    persistentData.setScope(TestSearchScope.WHOLE_PROJECT);
    aPackage.createSearchingForTestsTask().startSearch();
    workingDirsFile = aPackage.getWorkingDirsFile();
    assertNotNull(workingDirsFile);
    String file;
    aPackage.createSearchingForTestsTask().startSearch();
    workingDirsFile = aPackage.getWorkingDirsFile();
    assertNotNull(workingDirsFile);
    file = preparePathsForComparison(FileUtil.loadFile(workingDirsFile), mod1, mod2);
    assertEquals("p\n" + "MODULE_1\n" + "mod1\n" + "CLASSPATH\n" + "1\n" + "p.T1\n" + "MODULE_2\n" + "mod2\n" + "CLASSPATH\n" + "1\n" + "p.T2", file);
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 43 with ExecutionEnvironment

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

the class JUnitClasspathTest method testNoWorkingDirsFileWhenOnlyOneModuleExist.

public void testNoWorkingDirsFileWhenOnlyOneModuleExist() throws Exception {
    setupModule("mod1", "T1");
    final JUnitConfiguration configuration = new JUnitConfiguration("p", getProject(), JUnitConfigurationType.getInstance().getConfigurationFactories()[0]);
    configuration.setWorkingDirectory("$MODULE_DIR$");
    final JUnitConfiguration.Data persistentData = configuration.getPersistentData();
    persistentData.setScope(TestSearchScope.WHOLE_PROJECT);
    persistentData.PACKAGE_NAME = "p";
    persistentData.TEST_OBJECT = JUnitConfiguration.TEST_PACKAGE;
    final ExecutionEnvironment environment = ExecutionEnvironmentBuilder.create(DefaultRunExecutor.getRunExecutorInstance(), configuration).build();
    final TestPackage aPackage = new TestPackage(configuration, environment);
    aPackage.createSearchingForTestsTask().startSearch();
    final File workingDirsFile = aPackage.getWorkingDirsFile();
    assertNotNull(workingDirsFile);
    assertEmpty(FileUtil.loadFile(workingDirsFile));
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 44 with ExecutionEnvironment

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

the class DebuggerTestCase method createLocalProcess.

protected DebuggerSession createLocalProcess(int transport, final JavaParameters javaParameters) throws ExecutionException, InterruptedException, InvocationTargetException {
    createBreakpoints(javaParameters.getMainClass());
    final DebuggerSession[] debuggerSession = new DebuggerSession[] { null };
    DebuggerSettings.getInstance().DEBUGGER_TRANSPORT = transport;
    GenericDebuggerRunnerSettings debuggerRunnerSettings = new GenericDebuggerRunnerSettings();
    debuggerRunnerSettings.LOCAL = true;
    debuggerRunnerSettings.setDebugPort(String.valueOf(DEFAULT_ADDRESS));
    ExecutionEnvironment environment = new ExecutionEnvironmentBuilder(myProject, DefaultDebugExecutor.getDebugExecutorInstance()).runnerSettings(debuggerRunnerSettings).runProfile(new MockConfiguration()).build();
    final JavaCommandLineState javaCommandLineState = new JavaCommandLineState(environment) {

        @Override
        protected JavaParameters createJavaParameters() {
            return javaParameters;
        }

        @Override
        protected GeneralCommandLine createCommandLine() throws ExecutionException {
            return getJavaParameters().toCommandLine();
        }
    };
    final RemoteConnection debugParameters = DebuggerManagerImpl.createDebugParameters(javaCommandLineState.getJavaParameters(), debuggerRunnerSettings, true);
    UIUtil.invokeAndWaitIfNeeded(new Runnable() {

        @Override
        public void run() {
            try {
                debuggerSession[0] = attachVirtualMachine(javaCommandLineState, javaCommandLineState.getEnvironment(), debugParameters, false);
            } catch (ExecutionException e) {
                fail(e.getMessage());
            }
        }
    });
    final ProcessHandler processHandler = debuggerSession[0].getProcess().getProcessHandler();
    debuggerSession[0].getProcess().addProcessListener(new ProcessAdapter() {

        @Override
        public void onTextAvailable(ProcessEvent event, Key outputType) {
            print(event.getText(), outputType);
        }
    });
    DebugProcessImpl process = (DebugProcessImpl) DebuggerManagerEx.getInstanceEx(myProject).getDebugProcess(processHandler);
    assertNotNull(process);
    return debuggerSession[0];
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) ThrowableRunnable(com.intellij.util.ThrowableRunnable) ProcessHandler(com.intellij.execution.process.ProcessHandler) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder) ExecutionException(com.intellij.execution.ExecutionException) Key(com.intellij.openapi.util.Key)

Example 45 with ExecutionEnvironment

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

the class ExternalSystemUtil method createExecutionEnvironment.

@Nullable
public static ExecutionEnvironment createExecutionEnvironment(@NotNull Project project, @NotNull ProjectSystemId externalSystemId, @NotNull ExternalSystemTaskExecutionSettings taskSettings, @NotNull String executorId) {
    Executor executor = ExecutorRegistry.getInstance().getExecutorById(executorId);
    if (executor == null)
        return null;
    String runnerId = getRunnerId(executorId);
    if (runnerId == null)
        return null;
    ProgramRunner runner = RunnerRegistry.getInstance().findRunnerById(runnerId);
    if (runner == null)
        return null;
    RunnerAndConfigurationSettings settings = createExternalSystemRunnerAndConfigurationSettings(taskSettings, project, externalSystemId);
    if (settings == null)
        return null;
    return new ExecutionEnvironment(executor, runner, settings, project);
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) DefaultDebugExecutor(com.intellij.execution.executors.DefaultDebugExecutor) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) ProgramRunner(com.intellij.execution.runners.ProgramRunner) Nullable(org.jetbrains.annotations.Nullable)

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