Search in sources :

Example 6 with ExecutionEnvironmentBuilder

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

the class ExecutionManagerImpl method restartRunProfile.

@Override
public void restartRunProfile(@NotNull Project project, @NotNull Executor executor, @NotNull ExecutionTarget target, @Nullable RunnerAndConfigurationSettings configuration, @Nullable ProcessHandler processHandler) {
    ExecutionEnvironmentBuilder builder = createEnvironmentBuilder(project, executor, configuration);
    if (processHandler != null) {
        for (RunContentDescriptor descriptor : getContentManager().getAllDescriptors()) {
            if (descriptor.getProcessHandler() == processHandler) {
                builder.contentToReuse(descriptor);
                break;
            }
        }
    }
    restartRunProfile(builder.target(target).build());
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder)

Example 7 with ExecutionEnvironmentBuilder

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

the class ExecutionManagerImpl method compileAndRun.

@Override
public void compileAndRun(@NotNull final Runnable startRunnable, @NotNull final ExecutionEnvironment environment, @Nullable final RunProfileState state, @Nullable final Runnable onCancelRunnable) {
    long id = environment.getExecutionId();
    if (id == 0) {
        id = environment.assignNewExecutionId();
    }
    RunProfile profile = environment.getRunProfile();
    if (!(profile instanceof RunConfiguration)) {
        startRunnable.run();
        return;
    }
    final RunConfiguration runConfiguration = (RunConfiguration) profile;
    final List<BeforeRunTask> beforeRunTasks = RunManagerEx.getInstanceEx(myProject).getBeforeRunTasks(runConfiguration);
    if (beforeRunTasks.isEmpty()) {
        startRunnable.run();
    } else {
        DataContext context = environment.getDataContext();
        final DataContext projectContext = context != null ? context : SimpleDataContext.getProjectContext(myProject);
        final long finalId = id;
        final Long executionSessionId = new Long(id);
        ApplicationManager.getApplication().executeOnPooledThread(() -> {
            for (BeforeRunTask task : beforeRunTasks) {
                if (myProject.isDisposed()) {
                    return;
                }
                @SuppressWarnings("unchecked") BeforeRunTaskProvider<BeforeRunTask> provider = BeforeRunTaskProvider.getProvider(myProject, task.getProviderId());
                if (provider == null) {
                    LOG.warn("Cannot find BeforeRunTaskProvider for id='" + task.getProviderId() + "'");
                    continue;
                }
                ExecutionEnvironment taskEnvironment = new ExecutionEnvironmentBuilder(environment).contentToReuse(null).build();
                taskEnvironment.setExecutionId(finalId);
                EXECUTION_SESSION_ID_KEY.set(taskEnvironment, executionSessionId);
                if (!provider.executeTask(projectContext, runConfiguration, taskEnvironment, task)) {
                    if (onCancelRunnable != null) {
                        SwingUtilities.invokeLater(onCancelRunnable);
                    }
                    return;
                }
            }
            doRun(environment, startRunnable);
        });
    }
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) SimpleDataContext(com.intellij.openapi.actionSystem.impl.SimpleDataContext) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) RunProfile(com.intellij.execution.configurations.RunProfile) CompatibilityAwareRunProfile(com.intellij.execution.configuration.CompatibilityAwareRunProfile) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder)

Example 8 with ExecutionEnvironmentBuilder

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

the class ExecutionManagerImpl method createEnvironmentBuilder.

@NotNull
private static ExecutionEnvironmentBuilder createEnvironmentBuilder(@NotNull Project project, @NotNull Executor executor, @Nullable RunnerAndConfigurationSettings configuration) {
    ExecutionEnvironmentBuilder builder = new ExecutionEnvironmentBuilder(project, executor);
    ProgramRunner runner = RunnerRegistry.getInstance().getRunner(executor.getId(), configuration != null ? configuration.getConfiguration() : null);
    if (runner == null && configuration != null) {
        LOG.error("Cannot find runner for " + configuration.getName());
    } else if (runner != null) {
        assert configuration != null;
        builder.runnerAndSettings(runner, configuration);
    }
    return builder;
}
Also used : ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder) ProgramRunner(com.intellij.execution.runners.ProgramRunner) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with ExecutionEnvironmentBuilder

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

the class RunConfigurationBeforeRunProvider method doExecuteTask.

public static boolean doExecuteTask(@NotNull final ExecutionEnvironment env, @NotNull final RunnerAndConfigurationSettings settings) {
    final Executor executor = DefaultRunExecutor.getRunExecutorInstance();
    final String executorId = executor.getId();
    ExecutionEnvironmentBuilder builder = ExecutionEnvironmentBuilder.createOrNull(executor, settings);
    if (builder == null) {
        return false;
    }
    ExecutionTarget compatibleTarget = getCompatibleTarget(env, settings);
    if (compatibleTarget == null) {
        return false;
    }
    final ExecutionEnvironment environment = builder.target(compatibleTarget).build();
    environment.setExecutionId(env.getExecutionId());
    if (!environment.getRunner().canRun(executorId, environment.getRunProfile())) {
        return false;
    } else {
        beforeRun(environment);
        return doRunTask(executorId, environment, environment.getRunner());
    }
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder)

Example 10 with ExecutionEnvironmentBuilder

use of com.intellij.execution.runners.ExecutionEnvironmentBuilder in project buck by facebook.

the class TestExecutionState method attachDebugger.

private void attachDebugger(String title, String port) {
    final RemoteConnection remoteConnection = new RemoteConnection(/* useSockets */
    true, "localhost", port, /* serverMode */
    false);
    final RemoteStateState state = new RemoteStateState(mProject, remoteConnection);
    final String name = title + " debugger (" + port + ")";
    final ConfigurationFactory cfgFactory = ConfigurationTypeUtil.findConfigurationType("Remote").getConfigurationFactories()[0];
    RunnerAndConfigurationSettings runSettings = RunManager.getInstance(mProject).createRunConfiguration(name, cfgFactory);
    final Executor debugExecutor = DefaultDebugExecutor.getDebugExecutorInstance();
    final ExecutionEnvironment env = new ExecutionEnvironmentBuilder(mProject, debugExecutor).runProfile(runSettings.getConfiguration()).build();
    final int pollTimeout = 3000;
    final DebugEnvironment environment = new DefaultDebugEnvironment(env, state, remoteConnection, pollTimeout);
    ApplicationManager.getApplication().invokeLater(() -> {
        try {
            final DebuggerSession debuggerSession = DebuggerManagerEx.getInstanceEx(mProject).attachVirtualMachine(environment);
            if (debuggerSession == null) {
                return;
            }
            XDebuggerManager.getInstance(mProject).startSessionAndShowTab(name, null, new XDebugProcessStarter() {

                @Override
                @NotNull
                public XDebugProcess start(@NotNull XDebugSession session) {
                    return JavaDebugProcess.create(session, debuggerSession);
                }
            });
        } catch (ExecutionException e) {
            LOG.error("failed to attach to debugger on port " + port + " with polling timeout " + pollTimeout);
        }
    });
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) XDebugProcess(com.intellij.xdebugger.XDebugProcess) NotNull(org.jetbrains.annotations.NotNull) DefaultDebugEnvironment(com.intellij.debugger.DefaultDebugEnvironment) DefaultDebugExecutor(com.intellij.execution.executors.DefaultDebugExecutor) Executor(com.intellij.execution.Executor) DebuggerSession(com.intellij.debugger.impl.DebuggerSession) XDebugProcessStarter(com.intellij.xdebugger.XDebugProcessStarter) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) RemoteConnection(com.intellij.execution.configurations.RemoteConnection) RemoteStateState(com.intellij.debugger.engine.RemoteStateState) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder) ExecutionException(com.intellij.execution.ExecutionException) DefaultDebugEnvironment(com.intellij.debugger.DefaultDebugEnvironment) DebugEnvironment(com.intellij.debugger.DebugEnvironment)

Aggregations

ExecutionEnvironmentBuilder (com.intellij.execution.runners.ExecutionEnvironmentBuilder)18 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)7 ExecutionException (com.intellij.execution.ExecutionException)6 NotNull (org.jetbrains.annotations.NotNull)5 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)4 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)4 ProcessEvent (com.intellij.execution.process.ProcessEvent)4 ProgramRunner (com.intellij.execution.runners.ProgramRunner)4 Executor (com.intellij.execution.Executor)3 Key (com.intellij.openapi.util.Key)3 RemoteStateState (com.intellij.debugger.engine.RemoteStateState)2 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)2 RemoteConnection (com.intellij.execution.configurations.RemoteConnection)2 RunProfile (com.intellij.execution.configurations.RunProfile)2 DefaultDebugExecutor (com.intellij.execution.executors.DefaultDebugExecutor)2 ProcessHandler (com.intellij.execution.process.ProcessHandler)2 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)2 Project (com.intellij.openapi.project.Project)2 ThrowableRunnable (com.intellij.util.ThrowableRunnable)2 Client (com.android.ddmlib.Client)1