Search in sources :

Example 1 with RunnerAndConfigurationSettingsImpl

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

the class JUnit4IntegrationTest method ignoredTestMethod.

@Test
public void ignoredTestMethod() throws Throwable {
    EdtTestUtil.runInEdtAndWait(() -> {
        PsiClass psiClass = findClass(getModule1(), CLASS_NAME);
        assertNotNull(psiClass);
        PsiMethod testMethod = psiClass.findMethodsByName(METHOD_NAME, false)[0];
        JUnitConfiguration configuration = createConfiguration(testMethod);
        Executor executor = DefaultRunExecutor.getRunExecutorInstance();
        RunnerAndConfigurationSettingsImpl settings = new RunnerAndConfigurationSettingsImpl(RunManagerImpl.getInstanceImpl(getProject()), configuration, false);
        ExecutionEnvironment environment = new ExecutionEnvironment(executor, ProgramRunnerUtil.getRunner(DefaultRunExecutor.EXECUTOR_ID, settings), settings, getProject());
        TestObject state = configuration.getState(executor, environment);
        JavaParameters parameters = state.getJavaParameters();
        parameters.setUseDynamicClasspath(getProject());
        GeneralCommandLine commandLine = parameters.toCommandLine();
        StringBuffer buf = new StringBuffer();
        StringBuffer err = new StringBuffer();
        OSProcessHandler process = new OSProcessHandler(commandLine);
        process.addProcessListener(new ProcessAdapter() {

            @Override
            public void onTextAvailable(ProcessEvent event, Key outputType) {
                String text = event.getText();
                try {
                    if (outputType == ProcessOutputTypes.STDOUT && !text.isEmpty() && ServiceMessage.parse(text.trim()) == null) {
                        buf.append(text);
                    }
                    if (outputType == ProcessOutputTypes.STDERR) {
                        err.append(text);
                    }
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        });
        process.startNotify();
        process.waitFor();
        process.destroyProcess();
        String testOutput = buf.toString();
        assertEmpty(err.toString());
        switch(myJUnitVersion) {
            //shouldn't work for old versions
            case "4.4":
            //shouldn't work for old versions
            case "4.5":
                break;
            default:
                assertTrue(testOutput, testOutput.contains("Test1"));
        }
    });
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) PsiMethod(com.intellij.psi.PsiMethod) ProcessEvent(com.intellij.execution.process.ProcessEvent) JUnitConfiguration(com.intellij.execution.junit.JUnitConfiguration) PsiClass(com.intellij.psi.PsiClass) TestObject(com.intellij.execution.junit.TestObject) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) Executor(com.intellij.execution.Executor) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) RunnerAndConfigurationSettingsImpl(com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl) JavaParameters(com.intellij.execution.configurations.JavaParameters) ParseException(java.text.ParseException) Key(com.intellij.openapi.util.Key) Test(org.junit.Test)

Example 2 with RunnerAndConfigurationSettingsImpl

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

the class CopyConfigurationAction method doActionPerformed.

@Override
@SuppressWarnings("unchecked")
protected void doActionPerformed(DashboardRunConfigurationNode node) {
    RunManagerEx runManager = RunManagerEx.getInstanceEx(node.getProject());
    RunnerAndConfigurationSettings settings = node.getConfigurationSettings();
    RunnerAndConfigurationSettings copiedSettings = ((RunnerAndConfigurationSettingsImpl) settings).clone();
    runManager.setUniqueNameIfNeed(copiedSettings);
    copiedSettings.setFolderName(settings.getFolderName());
    final ConfigurationFactory factory = settings.getFactory();
    if (factory instanceof ConfigurationFactoryEx) {
        ((ConfigurationFactoryEx) factory).onConfigurationCopied(settings.getConfiguration());
    }
    if (RunDialog.editConfiguration(node.getProject(), copiedSettings, ExecutionBundle.message("run.dashboard.edit.configuration.dialog.title"))) {
        runManager.addConfiguration(copiedSettings, runManager.isConfigurationShared(settings), runManager.getBeforeRunTasks(settings.getConfiguration()), false);
    }
}
Also used : RunManagerEx(com.intellij.execution.RunManagerEx) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory) ConfigurationFactoryEx(com.intellij.execution.configuration.ConfigurationFactoryEx) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) RunnerAndConfigurationSettingsImpl(com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl)

Example 3 with RunnerAndConfigurationSettingsImpl

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

the class CompoundRunConfiguration method getState.

@Nullable
@Override
public RunProfileState getState(@NotNull Executor executor, @NotNull final ExecutionEnvironment environment) throws ExecutionException {
    try {
        checkConfiguration();
    } catch (RuntimeConfigurationException e) {
        throw new ExecutionException(e.getMessage());
    }
    return new RunProfileState() {

        @Nullable
        @Override
        public ExecutionResult execute(final Executor executor, @NotNull ProgramRunner runner) throws ExecutionException {
            ApplicationManager.getApplication().invokeLater(() -> {
                RunManagerImpl manager = RunManagerImpl.getInstanceImpl(getProject());
                for (RunConfiguration configuration : getSetToRun()) {
                    RunnerAndConfigurationSettings settings = new RunnerAndConfigurationSettingsImpl(manager, configuration, false);
                    ExecutionEnvironmentBuilder builder = ExecutionEnvironmentBuilder.createOrNull(executor, settings);
                    if (builder != null) {
                        ExecutionManager.getInstance(getProject()).restartRunProfile(builder.activeTarget().dataContext(null).build());
                    }
                }
            });
            return null;
        }
    };
}
Also used : DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) RunnerAndConfigurationSettingsImpl(com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl) ProgramRunner(com.intellij.execution.runners.ProgramRunner) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder) NotNull(org.jetbrains.annotations.NotNull) RunManagerImpl(com.intellij.execution.impl.RunManagerImpl) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with RunnerAndConfigurationSettingsImpl

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

the class ConfigurationRefactoringsTest method testRenameBadTestClass.

public void testRenameBadTestClass() throws IOException {
    PsiClass psiClass = mySource.createClass("NotATest", NOT_A_TEST);
    assertNotNull(psiClass);
    JUnitConfigurationType instance = JUnitConfigurationType.getInstance();
    assertNotNull(instance);
    JUnitConfiguration configuration = new JUnitConfiguration("notATest", myProject, instance.getConfigurationFactories()[0]);
    configuration.setMainClass(psiClass);
    configuration.setModule(configuration.getValidModules().iterator().next());
    checkConfigurationException("NotATest isn't test class", configuration);
    RunManagerEx.getInstanceEx(myProject).setTemporaryConfiguration(new RunnerAndConfigurationSettingsImpl(null, configuration, false));
    rename(psiClass, "NotATest2");
    JUnitConfiguration.Data data = configuration.getPersistentData();
    assertEquals("NotATest2", data.getMainClassName());
    data.METHOD_NAME = "test";
    data.TEST_OBJECT = JUnitConfiguration.TEST_METHOD;
    checkConfigurationException("Test method 'test' doesn't exist", configuration);
    rename(psiClass.findMethodsByName("test", false)[0], "test2");
    assertEquals("NotATest2", data.getMainClassName());
    assertEquals("test2", data.getMethodName());
}
Also used : JUnitConfiguration(com.intellij.execution.junit.JUnitConfiguration) RunnerAndConfigurationSettingsImpl(com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl) JUnitConfigurationType(com.intellij.execution.junit.JUnitConfigurationType)

Example 5 with RunnerAndConfigurationSettingsImpl

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

the class ConfigurationRefactoringsTest method createConfiguration.

@Override
protected <T extends RunConfiguration> T createConfiguration(@NotNull PsiElement psiClass, @NotNull MapDataContext dataContext) {
    T configuration = super.createConfiguration(psiClass, dataContext);
    RunManagerEx.getInstanceEx(myProject).setTemporaryConfiguration(new RunnerAndConfigurationSettingsImpl(null, configuration, false));
    return configuration;
}
Also used : RunnerAndConfigurationSettingsImpl(com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl)

Aggregations

RunnerAndConfigurationSettingsImpl (com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl)7 JUnitConfiguration (com.intellij.execution.junit.JUnitConfiguration)3 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)2 RunManagerImpl (com.intellij.execution.impl.RunManagerImpl)2 Executor (com.intellij.execution.Executor)1 RunManagerEx (com.intellij.execution.RunManagerEx)1 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 ConfigurationFactoryEx (com.intellij.execution.configuration.ConfigurationFactoryEx)1 ConfigurationFactory (com.intellij.execution.configurations.ConfigurationFactory)1 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)1 JavaParameters (com.intellij.execution.configurations.JavaParameters)1 JUnitConfigurationType (com.intellij.execution.junit.JUnitConfigurationType)1 TestObject (com.intellij.execution.junit.TestObject)1 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)1 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)1 ProcessEvent (com.intellij.execution.process.ProcessEvent)1 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)1 ExecutionEnvironmentBuilder (com.intellij.execution.runners.ExecutionEnvironmentBuilder)1 ProgramRunner (com.intellij.execution.runners.ProgramRunner)1 AppPropertiesComponentImpl (com.intellij.ide.util.AppPropertiesComponentImpl)1