use of com.intellij.execution.process.ProcessHandler in project intellij-community by JetBrains.
the class RunConfigurationBeforeRunProvider method doRunTask.
public static boolean doRunTask(final String executorId, final ExecutionEnvironment environment, ProgramRunner<?> runner) {
final Semaphore targetDone = new Semaphore();
final Ref<Boolean> result = new Ref<>(false);
final Disposable disposable = Disposer.newDisposable();
environment.getProject().getMessageBus().connect(disposable).subscribe(ExecutionManager.EXECUTION_TOPIC, new ExecutionListener() {
@Override
public void processStartScheduled(@NotNull final String executorIdLocal, @NotNull final ExecutionEnvironment environmentLocal) {
if (executorId.equals(executorIdLocal) && environment.equals(environmentLocal)) {
targetDone.down();
}
}
@Override
public void processNotStarted(@NotNull final String executorIdLocal, @NotNull final ExecutionEnvironment environmentLocal) {
if (executorId.equals(executorIdLocal) && environment.equals(environmentLocal)) {
Boolean skipRun = environment.getUserData(ExecutionManagerImpl.EXECUTION_SKIP_RUN);
if (skipRun != null && skipRun) {
result.set(true);
}
targetDone.up();
}
}
@Override
public void processTerminated(@NotNull String executorIdLocal, @NotNull ExecutionEnvironment environmentLocal, @NotNull ProcessHandler handler, int exitCode) {
if (executorId.equals(executorIdLocal) && environment.equals(environmentLocal)) {
result.set(exitCode == 0);
targetDone.up();
}
}
});
try {
ApplicationManager.getApplication().invokeAndWait(() -> {
try {
runner.execute(environment);
} catch (ExecutionException e) {
targetDone.up();
LOG.error(e);
}
}, ModalityState.NON_MODAL);
} catch (Exception e) {
LOG.error(e);
Disposer.dispose(disposable);
return false;
}
targetDone.waitFor();
Disposer.dispose(disposable);
return result.get();
}
use of com.intellij.execution.process.ProcessHandler in project intellij-community by JetBrains.
the class RemoteProcessSupport method startProcess.
private void startProcess(Target target, Parameters configuration, @NotNull Pair<Target, Parameters> key) {
ProgramRunner runner = new DefaultProgramRunner() {
@Override
@NotNull
public String getRunnerId() {
return "MyRunner";
}
@Override
public boolean canRun(@NotNull String executorId, @NotNull RunProfile profile) {
return true;
}
};
Executor executor = DefaultRunExecutor.getRunExecutorInstance();
ProcessHandler processHandler;
try {
RunProfileState state = getRunProfileState(target, configuration, executor);
ExecutionResult result = state.execute(executor, runner);
//noinspection ConstantConditions
processHandler = result.getProcessHandler();
} catch (Exception e) {
dropProcessInfo(key, e instanceof ExecutionException ? e.getMessage() : ExceptionUtil.getUserStackTrace(e, LOG), null);
return;
}
processHandler.addProcessListener(getProcessListener(key));
processHandler.startNotify();
}
use of com.intellij.execution.process.ProcessHandler in project intellij-community by JetBrains.
the class RunDashboardManagerImpl method initToolWindowListeners.
private void initToolWindowListeners() {
RunManagerEx.getInstanceEx(myProject).addRunManagerListener(new RunManagerListener() {
@Override
public void runConfigurationAdded(@NotNull RunnerAndConfigurationSettings settings) {
updateDashboardIfNeeded(settings);
}
@Override
public void runConfigurationRemoved(@NotNull RunnerAndConfigurationSettings settings) {
updateDashboardIfNeeded(settings);
}
@Override
public void runConfigurationChanged(@NotNull RunnerAndConfigurationSettings settings) {
updateDashboardIfNeeded(settings);
}
});
MessageBusConnection connection = myProject.getMessageBus().connect(myProject);
connection.subscribe(ExecutionManager.EXECUTION_TOPIC, new ExecutionListener() {
@Override
public void processStarted(@NotNull String executorId, @NotNull ExecutionEnvironment env, @NotNull final ProcessHandler handler) {
updateDashboardIfNeeded(env.getRunnerAndConfigurationSettings());
}
@Override
public void processTerminated(@NotNull String executorId, @NotNull ExecutionEnvironment env, @NotNull ProcessHandler handler, int exitCode) {
updateDashboardIfNeeded(env.getRunnerAndConfigurationSettings());
}
});
connection.subscribe(RunDashboardManager.DASHBOARD_TOPIC, new DashboardListener() {
@Override
public void contentChanged(boolean withStructure) {
updateDashboard(withStructure);
}
});
connection.subscribe(DumbService.DUMB_MODE, new DumbService.DumbModeListener() {
@Override
public void enteredDumbMode() {
}
@Override
public void exitDumbMode() {
updateDashboard(false);
}
});
}
use of com.intellij.execution.process.ProcessHandler in project intellij-community by JetBrains.
the class DefaultJavaProgramRunner method addDefaultActions.
private static void addDefaultActions(@NotNull RunContentBuilder contentBuilder, @NotNull ExecutionResult executionResult) {
final ExecutionConsole executionConsole = executionResult.getExecutionConsole();
final JComponent consoleComponent = executionConsole != null ? executionConsole.getComponent() : null;
final ControlBreakAction controlBreakAction = new ControlBreakAction(executionResult.getProcessHandler());
if (consoleComponent != null) {
controlBreakAction.registerCustomShortcutSet(controlBreakAction.getShortcutSet(), consoleComponent);
final ProcessHandler processHandler = executionResult.getProcessHandler();
assert processHandler != null : executionResult;
processHandler.addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(final ProcessEvent event) {
processHandler.removeProcessListener(this);
controlBreakAction.unregisterCustomShortcutSet(consoleComponent);
}
});
}
contentBuilder.addAction(controlBreakAction);
contentBuilder.addAction(new SoftExitAction(executionResult.getProcessHandler()));
}
use of com.intellij.execution.process.ProcessHandler 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);
}
}
});
}
}
Aggregations