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;
}
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());
}
}
use of com.intellij.execution.runners.ExecutionEnvironmentBuilder in project intellij-community by JetBrains.
the class ConfigurationsTest method checkCantRun.
private void checkCantRun(RunConfiguration configuration, String reasonBeginning) throws ExecutionException {
try {
configuration.checkConfiguration();
} catch (RuntimeConfigurationException e) {
assertTrue(e.getLocalizedMessage().startsWith(reasonBeginning));
return;
}
RunProfileState state = configuration.getState(DefaultRunExecutor.getRunExecutorInstance(), new ExecutionEnvironmentBuilder(myProject, DefaultRunExecutor.getRunExecutorInstance()).runProfile(configuration).build());
assertTrue(state instanceof JavaCommandLine);
try {
((JavaCommandLine) state).getJavaParameters();
} catch (Throwable e) {
assertTrue(e.getLocalizedMessage().startsWith(reasonBeginning));
return;
}
fail("Should not run");
}
use of com.intellij.execution.runners.ExecutionEnvironmentBuilder in project intellij-community by JetBrains.
the class ProgramRunnerUtil method executeConfiguration.
public static void executeConfiguration(@NotNull Project project, @NotNull RunnerAndConfigurationSettings configuration, @NotNull Executor executor) {
ExecutionEnvironmentBuilder builder;
try {
builder = ExecutionEnvironmentBuilder.create(executor, configuration);
} catch (ExecutionException e) {
LOG.error(e);
return;
}
executeConfiguration(builder.contentToReuse(null).dataContext(null).activeTarget().build(), true, true);
}
use of com.intellij.execution.runners.ExecutionEnvironmentBuilder in project intellij-community by JetBrains.
the class AbstractRerunFailedTestsAction method execute.
void execute(@NotNull AnActionEvent e, @NotNull ExecutionEnvironment environment) {
MyRunProfile profile = getRunProfile(environment);
if (profile == null) {
return;
}
final ExecutionEnvironmentBuilder environmentBuilder = new ExecutionEnvironmentBuilder(environment).runProfile(profile);
final InputEvent event = e.getInputEvent();
if (!(event instanceof MouseEvent) || !event.isShiftDown()) {
performAction(environmentBuilder);
return;
}
final LinkedHashMap<Executor, ProgramRunner> availableRunners = new LinkedHashMap<>();
for (Executor ex : new Executor[] { DefaultRunExecutor.getRunExecutorInstance(), DefaultDebugExecutor.getDebugExecutorInstance() }) {
final ProgramRunner runner = RunnerRegistry.getInstance().getRunner(ex.getId(), profile);
if (runner != null) {
availableRunners.put(ex, runner);
}
}
if (availableRunners.isEmpty()) {
LOG.error(environment.getExecutor().getActionName() + " is not available now");
} else if (availableRunners.size() == 1) {
//noinspection ConstantConditions
performAction(environmentBuilder.runner(availableRunners.get(environment.getExecutor())));
} else {
final JBList list = new JBList(availableRunners.keySet());
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setSelectedValue(environment.getExecutor(), true);
list.setCellRenderer(new DefaultListCellRenderer() {
@NotNull
@Override
public Component getListCellRendererComponent(@NotNull JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
final Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value instanceof Executor) {
setText(UIUtil.removeMnemonic(((Executor) value).getStartActionText()));
setIcon(((Executor) value).getIcon());
}
return component;
}
});
//noinspection ConstantConditions
JBPopupFactory.getInstance().createListPopupBuilder(list).setTitle("Restart Failed Tests").setMovable(false).setResizable(false).setRequestFocus(true).setItemChoosenCallback(() -> {
final Object value = list.getSelectedValue();
if (value instanceof Executor) {
//noinspection ConstantConditions
performAction(environmentBuilder.runner(availableRunners.get(value)).executor((Executor) value));
}
}).createPopup().showUnderneathOf(event.getComponent());
}
}
Aggregations