use of com.intellij.execution.ui.RunContentDescriptor in project intellij-community by JetBrains.
the class JavaTestFrameworkDebuggerRunner method createContentDescriptor.
@Nullable
@Override
protected RunContentDescriptor createContentDescriptor(@NotNull final RunProfileState state, @NotNull final ExecutionEnvironment environment) throws ExecutionException {
final RunContentDescriptor res = super.createContentDescriptor(state, environment);
final ServerSocket socket = ((JavaTestFrameworkRunnableState) state).getForkSocket();
if (socket != null) {
Thread thread = new Thread(getThreadName() + " debugger runner") {
@Override
public void run() {
try {
final Socket accept = socket.accept();
try {
DataInputStream stream = new DataInputStream(accept.getInputStream());
try {
int read = stream.readInt();
while (read != -1) {
final DebugProcess process = DebuggerManager.getInstance(environment.getProject()).getDebugProcess(res.getProcessHandler());
if (process == null)
break;
final RemoteConnection connection = new RemoteConnection(true, "127.0.0.1", String.valueOf(read), true);
final DebugEnvironment env = new DefaultDebugEnvironment(environment, state, connection, true);
SwingUtilities.invokeLater(() -> {
try {
((DebugProcessImpl) process).reattach(env);
accept.getOutputStream().write(0);
} catch (Exception e) {
e.printStackTrace();
}
});
read = stream.readInt();
}
} finally {
stream.close();
}
} finally {
accept.close();
}
} catch (EOFException ignored) {
} catch (IOException e) {
e.printStackTrace();
}
}
};
thread.setDaemon(true);
thread.start();
}
return res;
}
use of com.intellij.execution.ui.RunContentDescriptor in project intellij-community by JetBrains.
the class JavaDebuggerLauncherImpl method startDebugSession.
@Override
public void startDebugSession(@NotNull JavaDebugConnectionData info, @NotNull ExecutionEnvironment executionEnvironment, @NotNull RemoteServer<?> server) throws ExecutionException {
final Project project = executionEnvironment.getProject();
final DebuggerPanelsManager manager = DebuggerPanelsManager.getInstance(project);
final JavaDebugServerModeHandler serverModeHandler = info.getServerModeHandler();
boolean serverMode = serverModeHandler != null;
final RemoteConnection remoteConnection = new RemoteConnection(true, info.getHost(), String.valueOf(info.getPort()), serverMode);
DebugEnvironment debugEnvironment = new RemoteServerDebugEnvironment(project, remoteConnection, executionEnvironment.getRunProfile());
DebugUIEnvironment debugUIEnvironment = new RemoteServerDebugUIEnvironment(debugEnvironment, executionEnvironment);
RunContentDescriptor debugContentDescriptor = manager.attachVirtualMachine(debugUIEnvironment);
LOG.assertTrue(debugContentDescriptor != null);
ProcessHandler processHandler = debugContentDescriptor.getProcessHandler();
LOG.assertTrue(processHandler != null);
if (serverMode) {
serverModeHandler.attachRemote();
DebuggerManager.getInstance(executionEnvironment.getProject()).addDebugProcessListener(processHandler, new DebugProcessListener() {
public void processDetached(DebugProcess process, boolean closedByUser) {
try {
serverModeHandler.detachRemote();
} catch (ExecutionException e) {
LOG.info(e);
}
}
});
}
}
use of com.intellij.execution.ui.RunContentDescriptor in project intellij-community by JetBrains.
the class RunIdeConsoleAction method executeQuery.
private static void executeQuery(@NotNull Project project, @NotNull VirtualFile file, @NotNull Editor editor, @NotNull IdeScriptEngine engine) {
String command = getCommandText(project, editor);
if (StringUtil.isEmptyOrSpaces(command))
return;
String profile = getProfileText(file);
RunContentDescriptor descriptor = getConsoleView(project, file);
ConsoleViewImpl consoleView = (ConsoleViewImpl) descriptor.getExecutionConsole();
prepareEngine(project, engine, descriptor);
try {
long ts = System.currentTimeMillis();
//myHistoryController.getModel().addToHistory(command);
consoleView.print("> " + command, ConsoleViewContentType.USER_INPUT);
consoleView.print("\n", ConsoleViewContentType.USER_INPUT);
String script = profile == null ? command : profile + "\n" + command;
Object o = engine.eval(script);
String prefix = "[" + (StringUtil.formatDuration(System.currentTimeMillis() - ts)) + "]";
consoleView.print(prefix + "=> " + o, ConsoleViewContentType.NORMAL_OUTPUT);
consoleView.print("\n", ConsoleViewContentType.NORMAL_OUTPUT);
} catch (Throwable e) {
//noinspection ThrowableResultOfMethodCallIgnored
Throwable ex = ExceptionUtil.getRootCause(e);
consoleView.print(ex.getClass().getSimpleName() + ": " + ex.getMessage(), ConsoleViewContentType.ERROR_OUTPUT);
consoleView.print("\n", ConsoleViewContentType.ERROR_OUTPUT);
}
selectContent(descriptor);
}
use of com.intellij.execution.ui.RunContentDescriptor in project intellij-community by JetBrains.
the class ExecutionManagerImpl method restartRunProfile.
@Override
public void restartRunProfile(@NotNull final ExecutionEnvironment environment) {
RunnerAndConfigurationSettings configuration = environment.getRunnerAndConfigurationSettings();
List<RunContentDescriptor> runningIncompatible;
if (configuration == null) {
runningIncompatible = Collections.emptyList();
} else {
runningIncompatible = getIncompatibleRunningDescriptors(configuration);
}
RunContentDescriptor contentToReuse = environment.getContentToReuse();
final List<RunContentDescriptor> runningOfTheSameType = new SmartList<>();
if (configuration != null && configuration.isSingleton()) {
runningOfTheSameType.addAll(getRunningDescriptorsOfTheSameConfigType(configuration));
} else if (isProcessRunning(contentToReuse)) {
runningOfTheSameType.add(contentToReuse);
}
List<RunContentDescriptor> runningToStop = ContainerUtil.concat(runningOfTheSameType, runningIncompatible);
if (!runningToStop.isEmpty()) {
if (configuration != null) {
if (!runningOfTheSameType.isEmpty() && (runningOfTheSameType.size() > 1 || contentToReuse == null || runningOfTheSameType.get(0) != contentToReuse) && !userApprovesStopForSameTypeConfigurations(environment.getProject(), configuration.getName(), runningOfTheSameType.size())) {
return;
}
if (!runningIncompatible.isEmpty() && !userApprovesStopForIncompatibleConfigurations(myProject, configuration.getName(), runningIncompatible)) {
return;
}
}
for (RunContentDescriptor descriptor : runningToStop) {
stopProcess(descriptor);
}
}
if (myAwaitingRunProfiles.get(environment.getRunProfile()) == environment) {
// defense from rerunning exactly the same ExecutionEnvironment
return;
}
myAwaitingRunProfiles.put(environment.getRunProfile(), environment);
awaitTermination(new Runnable() {
@Override
public void run() {
if (myAwaitingRunProfiles.get(environment.getRunProfile()) != environment) {
// a new rerun has been requested before starting this one, ignore this rerun
return;
}
if ((DumbService.getInstance(myProject).isDumb() && !Registry.is("dumb.aware.run.configurations")) || ExecutorRegistry.getInstance().isStarting(environment)) {
awaitTermination(this, 100);
return;
}
for (RunContentDescriptor descriptor : runningOfTheSameType) {
ProcessHandler processHandler = descriptor.getProcessHandler();
if (processHandler != null && !processHandler.isProcessTerminated()) {
awaitTermination(this, 100);
return;
}
}
myAwaitingRunProfiles.remove(environment.getRunProfile());
start(environment);
}
}, 50);
}
use of com.intellij.execution.ui.RunContentDescriptor in project intellij-community by JetBrains.
the class CloseAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final RunContentDescriptor contentDescriptor = getContentDescriptor();
if (contentDescriptor == null) {
return;
}
final boolean removedOk = ExecutionManager.getInstance(myProject).getContentManager().removeRunContent(getExecutor(), contentDescriptor);
if (removedOk) {
myContentDescriptor = null;
myExecutor = null;
}
}
Aggregations