Search in sources :

Example 16 with ExecutionEnvironmentBuilder

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

the class MavenResumeAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    Project project = myEnvironment.getProject();
    try {
        MavenRunConfiguration runConfiguration = ((MavenRunConfiguration) myEnvironment.getRunProfile()).clone();
        List<String> goals = runConfiguration.getRunnerParameters().getGoals();
        if (goals.size() > 2 && "-rf".equals(goals.get(goals.size() - 2))) {
            // This runConfiguration was created by other MavenResumeAction.
            goals.set(goals.size() - 1, myResumeModuleId);
        } else {
            goals.add("-rf");
            goals.add(myResumeModuleId);
        }
        runConfiguration.getRunnerParameters().setGoals(goals);
        myRunner.execute(new ExecutionEnvironmentBuilder(myEnvironment).contentToReuse(null).runProfile(runConfiguration).build());
    } catch (RunCanceledByUserException ignore) {
    } catch (ExecutionException e1) {
        Messages.showErrorDialog(project, e1.getMessage(), ExecutionBundle.message("restart.error.message.title"));
    }
}
Also used : RunCanceledByUserException(com.intellij.execution.RunCanceledByUserException) Project(com.intellij.openapi.project.Project) MavenProject(org.jetbrains.idea.maven.project.MavenProject) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder) ExecutionException(com.intellij.execution.ExecutionException)

Example 17 with ExecutionEnvironmentBuilder

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

the class ConnectJavaDebuggerTask method launchDebugger.

@Override
public ProcessHandler launchDebugger(@NotNull LaunchInfo currentLaunchInfo, @NotNull final Client client, @NotNull ProcessHandlerLaunchStatus launchStatus, @NotNull ProcessHandlerConsolePrinter printer) {
    String debugPort = Integer.toString(client.getDebuggerListenPort());
    final int pid = client.getClientData().getPid();
    Logger.getInstance(ConnectJavaDebuggerTask.class).info(String.format(Locale.US, "Attempting to connect debugger to port %1$s [client %2$d]", debugPort, pid));
    // detach old process handler
    RunContentDescriptor descriptor = currentLaunchInfo.env.getContentToReuse();
    // reach here before the EDT gets around to creating the descriptor?
    assert descriptor != null : "ConnectJavaDebuggerTask expects an existing descriptor that will be reused";
    final ProcessHandler processHandler = descriptor.getProcessHandler();
    assert processHandler != null;
    // create a new process handler
    RemoteConnection connection = new RemoteConnection(true, "localhost", debugPort, false);
    final AndroidRemoteDebugProcessHandler debugProcessHandler = new AndroidRemoteDebugProcessHandler(myProject, myMonitorRemoteProcess);
    // switch the launch status and console printers to point to the new process handler
    // this is required, esp. for AndroidTestListener which holds a reference to the launch status and printers, and those should
    // be updated to point to the new process handlers, otherwise test results will not be forwarded appropriately
    launchStatus.setProcessHandler(debugProcessHandler);
    printer.setProcessHandler(debugProcessHandler);
    // detach after the launch status has been updated to point to the new process handler
    processHandler.detachProcess();
    AndroidDebugState debugState = new AndroidDebugState(myProject, debugProcessHandler, connection, currentLaunchInfo.consoleProvider);
    RunContentDescriptor debugDescriptor;
    try {
        // @formatter:off
        ExecutionEnvironment debugEnv = new ExecutionEnvironmentBuilder(currentLaunchInfo.env).executor(currentLaunchInfo.executor).runner(currentLaunchInfo.runner).contentToReuse(descriptor).build();
        debugDescriptor = DebuggerPanelsManager.getInstance(myProject).attachVirtualMachine(debugEnv, debugState, connection, false);
    // @formatter:on
    } catch (ExecutionException e) {
        processHandler.notifyTextAvailable("ExecutionException: " + e.getMessage() + '.', STDERR);
        return null;
    }
    if (debugDescriptor == null) {
        processHandler.notifyTextAvailable("Unable to connect debugger to Android application", STDERR);
        return null;
    }
    // re-run the collected text from the old process handler to the new
    // TODO: is there a race between messages received once the debugger has been connected, and these messages that are printed out?
    final AndroidProcessText oldText = AndroidProcessText.get(processHandler);
    if (oldText != null) {
        oldText.printTo(debugProcessHandler);
    }
    RunProfile runProfile = currentLaunchInfo.env.getRunProfile();
    int uniqueId = runProfile instanceof RunConfigurationBase ? ((RunConfigurationBase) runProfile).getUniqueID() : -1;
    AndroidSessionInfo value = new AndroidSessionInfo(debugProcessHandler, debugDescriptor, uniqueId, currentLaunchInfo.executor.getId(), InstantRunUtils.isInstantRunEnabled(currentLaunchInfo.env));
    debugProcessHandler.putUserData(AndroidSessionInfo.KEY, value);
    debugProcessHandler.putUserData(AndroidSessionInfo.ANDROID_DEBUG_CLIENT, client);
    debugProcessHandler.putUserData(AndroidSessionInfo.ANDROID_DEVICE_API_LEVEL, client.getDevice().getVersion());
    final String pkgName = client.getClientData().getClientDescription();
    final IDevice device = client.getDevice();
    // kill the process when the debugger is stopped
    debugProcessHandler.addProcessListener(new ProcessAdapter() {

        @Override
        public void processTerminated(ProcessEvent event) {
            debugProcessHandler.removeProcessListener(this);
            Client currentClient = device.getClient(pkgName);
            if (currentClient != null && currentClient.getClientData().getPid() != pid) {
                // a new process has been launched for the same package name, we aren't interested in killing this
                return;
            }
            Logger.getInstance(ConnectJavaDebuggerTask.class).info("Debugger terminating, so terminating process: " + pkgName);
            // Note: client.kill() doesn't work when the debugger is attached, we explicitly stop by package id..
            try {
                device.executeShellCommand("am force-stop " + pkgName, new NullOutputReceiver());
            } catch (Exception e) {
            // don't care..
            }
        }
    });
    return debugProcessHandler;
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) IDevice(com.android.ddmlib.IDevice) RunProfile(com.intellij.execution.configurations.RunProfile) ExecutionException(com.intellij.execution.ExecutionException) RunConfigurationBase(com.intellij.execution.configurations.RunConfigurationBase) ProcessHandler(com.intellij.execution.process.ProcessHandler) RemoteConnection(com.intellij.execution.configurations.RemoteConnection) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder) ExecutionException(com.intellij.execution.ExecutionException) Client(com.android.ddmlib.Client) NullOutputReceiver(com.android.ddmlib.NullOutputReceiver)

Example 18 with ExecutionEnvironmentBuilder

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

the class JstdAssertionFrameworkLineMarkerProvider method execute.

private static void execute(@NotNull Project project, @NotNull Executor executor, @NotNull RunnerAndConfigurationSettings configuration, boolean created) {
    RunManager runManager = RunManager.getInstance(project);
    if (created) {
        runManager.setTemporaryConfiguration(configuration);
    }
    runManager.setSelectedConfiguration(configuration);
    ExecutionEnvironmentBuilder builder = ExecutionEnvironmentBuilder.createOrNull(executor, configuration);
    if (builder != null) {
        ExecutionManager.getInstance(project).restartRunProfile(builder.build());
    }
}
Also used : ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder)

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