Search in sources :

Example 1 with ConfigurationFactory

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

the class PyCommandLineTestCase method createConfiguration.

protected <T extends AbstractPythonRunConfiguration> T createConfiguration(final ConfigurationType configurationType, Class<T> cls) {
    final ConfigurationFactory factory = configurationType.getConfigurationFactories()[0];
    final Project project = myFixture.getProject();
    return cls.cast(factory.createTemplateConfiguration(project));
}
Also used : Project(com.intellij.openapi.project.Project) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory)

Example 2 with ConfigurationFactory

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

the class PyDebuggerTask method runTestOn.

public void runTestOn(String sdkHome) throws Exception {
    final Project project = getProject();
    final ConfigurationFactory factory = PythonConfigurationType.getInstance().getConfigurationFactories()[0];
    final RunnerAndConfigurationSettings settings = RunManager.getInstance(project).createRunConfiguration("test", factory);
    myRunConfiguration = (PythonRunConfiguration) settings.getConfiguration();
    myRunConfiguration.setSdkHome(sdkHome);
    myRunConfiguration.setScriptName(getScriptName());
    myRunConfiguration.setWorkingDirectory(myFixture.getTempDirPath());
    myRunConfiguration.setScriptParameters(getScriptParameters());
    new WriteAction() {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            RunManagerEx.getInstanceEx(project).addConfiguration(settings, false);
            RunManagerEx.getInstanceEx(project).setSelectedConfiguration(settings);
            Assert.assertSame(settings, RunManagerEx.getInstanceEx(project).getSelectedConfiguration());
        }
    }.execute();
    final PyDebugRunner runner = (PyDebugRunner) ProgramRunnerUtil.getRunner(getExecutorId(), settings);
    Assert.assertTrue(runner.canRun(getExecutorId(), myRunConfiguration));
    final Executor executor = DefaultDebugExecutor.getDebugExecutorInstance();
    final ExecutionEnvironment env = new ExecutionEnvironment(executor, runner, settings, project);
    final PythonCommandLineState pyState = (PythonCommandLineState) myRunConfiguration.getState(executor, env);
    assert pyState != null;
    pyState.setMultiprocessDebug(isMultiprocessDebug());
    final ServerSocket serverSocket;
    try {
        //noinspection SocketOpenedButNotSafelyClosed
        serverSocket = new ServerSocket(0);
    } catch (IOException e) {
        throw new ExecutionException("Failed to find free socket port", e);
    }
    final int serverLocalPort = serverSocket.getLocalPort();
    final RunProfile profile = env.getRunProfile();
    //turn off exception breakpoints by default
    PythonDebuggerTest.createExceptionBreak(myFixture, false, false, false);
    before();
    setProcessCanTerminate(false);
    myTerminateSemaphore = new Semaphore(0);
    new WriteAction<ExecutionResult>() {

        @Override
        protected void run(@NotNull Result<ExecutionResult> result) throws Throwable {
            myExecutionResult = pyState.execute(executor, runner.createCommandLinePatchers(myFixture.getProject(), pyState, profile, serverLocalPort));
            mySession = XDebuggerManager.getInstance(getProject()).startSession(env, new XDebugProcessStarter() {

                @NotNull
                public XDebugProcess start(@NotNull final XDebugSession session) {
                    myDebugProcess = new PyDebugProcess(session, serverSocket, myExecutionResult.getExecutionConsole(), myExecutionResult.getProcessHandler(), isMultiprocessDebug());
                    StringBuilder output = new StringBuilder();
                    myDebugProcess.getProcessHandler().addProcessListener(new ProcessAdapter() {

                        @Override
                        public void onTextAvailable(ProcessEvent event, Key outputType) {
                            output.append(event.getText());
                        }

                        @Override
                        public void processTerminated(ProcessEvent event) {
                            myTerminateSemaphore.release();
                            if (event.getExitCode() != 0 && !myProcessCanTerminate) {
                                Assert.fail("Process terminated unexpectedly\n" + output.toString());
                            }
                        }
                    });
                    myDebugProcess.getProcessHandler().startNotify();
                    return myDebugProcess;
                }
            });
            result.setResult(myExecutionResult);
        }
    }.execute().getResultObject();
    OutputPrinter myOutputPrinter = null;
    if (shouldPrintOutput) {
        myOutputPrinter = new OutputPrinter();
        myOutputPrinter.start();
    }
    myPausedSemaphore = new Semaphore(0);
    mySession.addSessionListener(new XDebugSessionListener() {

        @Override
        public void sessionPaused() {
            if (myPausedSemaphore != null) {
                myPausedSemaphore.release();
            }
        }
    });
    doTest(myOutputPrinter);
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) PyDebugRunner(com.jetbrains.python.debugger.PyDebugRunner) Semaphore(java.util.concurrent.Semaphore) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result) PyDebugProcess(com.jetbrains.python.debugger.PyDebugProcess) DefaultDebugExecutor(com.intellij.execution.executors.DefaultDebugExecutor) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) PythonCommandLineState(com.jetbrains.python.run.PythonCommandLineState) WriteAction(com.intellij.openapi.application.WriteAction) ProcessEvent(com.intellij.execution.process.ProcessEvent) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) RunProfile(com.intellij.execution.configurations.RunProfile) Project(com.intellij.openapi.project.Project) Key(com.intellij.openapi.util.Key)

Example 3 with ConfigurationFactory

use of com.intellij.execution.configurations.ConfigurationFactory 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 4 with ConfigurationFactory

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

the class BaseExecuteBeforeRunDialog method doOKAction.

@Override
protected void doOKAction() {
    final RunManagerImpl runManager = (RunManagerImpl) RunManagerEx.getInstanceEx(myProject);
    for (Enumeration nodes = myRoot.depthFirstEnumeration(); nodes.hasMoreElements(); ) {
        final DefaultMutableTreeNode node = (DefaultMutableTreeNode) nodes.nextElement();
        final Descriptor descriptor = (Descriptor) node.getUserObject();
        final boolean isChecked = descriptor.isChecked();
        if (descriptor instanceof ConfigurationTypeDescriptor) {
            ConfigurationTypeDescriptor typeDesc = (ConfigurationTypeDescriptor) descriptor;
            for (ConfigurationFactory factory : typeDesc.getConfigurationType().getConfigurationFactories()) {
                RunnerAndConfigurationSettings settings = runManager.getConfigurationTemplate(factory);
                update(settings.getConfiguration(), isChecked, runManager);
            }
        } else if (descriptor instanceof ConfigurationDescriptor) {
            ConfigurationDescriptor configDesc = (ConfigurationDescriptor) descriptor;
            update(configDesc.getConfiguration(), isChecked, runManager);
        }
    }
    RunManagerImpl.getInstanceImpl(myProject).fireBeforeRunTasksUpdated();
    close(OK_EXIT_CODE);
}
Also used : Enumeration(java.util.Enumeration) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory)

Example 5 with ConfigurationFactory

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

the class ProjectStartupConfigurable method createNewWrapper.

private ChooseRunConfigurationPopup.ItemWrapper<Void> createNewWrapper(final AnActionButton button) {
    return new ChooseRunConfigurationPopup.ItemWrapper<Void>(null) {

        @Override
        public Icon getIcon() {
            return IconUtil.getAddIcon();
        }

        @Override
        public String getText() {
            return UIUtil.removeMnemonic(ExecutionBundle.message("add.new.run.configuration.acrtion.name"));
        }

        @Override
        public void perform(@NotNull final Project project, @NotNull final Executor executor, @NotNull DataContext context) {
            final RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(project);
            final ConfigurationType[] factories = runManager.getConfigurationFactories();
            final Condition<ConfigurationType> filter = new Condition<ConfigurationType>() {

                private final RunnerRegistry myRegistry = RunnerRegistry.getInstance();

                @Override
                public boolean value(ConfigurationType configurationType) {
                    ConfigurationFactory factory;
                    return !UnknownConfigurationType.INSTANCE.equals(configurationType) && ((factory = runManager.getFactory(configurationType.getId(), null)) != null) && myRegistry.getRunner(executor.getId(), runManager.getConfigurationTemplate(factory).getConfiguration()) != null;
                }
            };
            final List<ConfigurationType> factoriesList = ContainerUtil.filter(Arrays.asList(factories), filter);
            final ListPopup popup = NewRunConfigurationPopup.createAddPopup(factoriesList, "", factory -> ApplicationManager.getApplication().invokeLater(() -> {
                final EditConfigurationsDialog dialog = new EditConfigurationsDialog(project, factory);
                if (dialog.showAndGet()) {
                    ApplicationManager.getApplication().invokeLater(() -> {
                        RunnerAndConfigurationSettings configuration = RunManager.getInstance(project).getSelectedConfiguration();
                        if (configuration != null) {
                            addConfiguration(configuration);
                        }
                    }, ModalityState.any(), project.getDisposed());
                }
            }, ModalityState.any(), project.getDisposed()), null, EmptyRunnable.getInstance(), false);
            showPopup(button, popup);
        }

        @Override
        public boolean available(Executor executor) {
            return true;
        }
    };
}
Also used : ConfigurationType(com.intellij.execution.configurations.ConfigurationType) UnknownConfigurationType(com.intellij.execution.configurations.UnknownConfigurationType) Condition(com.intellij.openapi.util.Condition) EditConfigurationsDialog(com.intellij.execution.impl.EditConfigurationsDialog) ListPopup(com.intellij.openapi.ui.popup.ListPopup) NotNull(org.jetbrains.annotations.NotNull) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory) RunManagerImpl(com.intellij.execution.impl.RunManagerImpl)

Aggregations

ConfigurationFactory (com.intellij.execution.configurations.ConfigurationFactory)38 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)23 Project (com.intellij.openapi.project.Project)14 RunManagerEx (com.intellij.execution.RunManagerEx)11 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)9 BeforeRunTask (com.intellij.execution.BeforeRunTask)7 RunManagerImpl (com.intellij.execution.impl.RunManagerImpl)6 ArrayList (java.util.ArrayList)6 NotNull (org.jetbrains.annotations.NotNull)6 ConfigurationType (com.intellij.execution.configurations.ConfigurationType)4 RemoteConfiguration (com.intellij.execution.remote.RemoteConfiguration)4 Module (com.intellij.openapi.module.Module)4 RunManager (com.intellij.execution.RunManager)3 DefaultDebugExecutor (com.intellij.execution.executors.DefaultDebugExecutor)3 RunnerAndConfigurationSettingsImpl (com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl)3 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)3 MakeBeforeRunTaskProvider (com.android.tools.idea.gradle.run.MakeBeforeRunTaskProvider)2 DebuggerSession (com.intellij.debugger.impl.DebuggerSession)2 ExecutionException (com.intellij.execution.ExecutionException)2 ConfigurationFactoryEx (com.intellij.execution.configuration.ConfigurationFactoryEx)2