use of com.intellij.execution.process.ProcessListener in project intellij-community by JetBrains.
the class ConfigurationBasedProcessRunner method runProcess.
@Override
final void runProcess(@NotNull final String sdkPath, @NotNull final Project project, @NotNull final ProcessListener processListener, @NotNull final String tempWorkingPath) throws ExecutionException {
ensureConsoleOk(myConsole);
// Do not create new environment from factory, if child provided environment to rerun
final ExecutionEnvironment executionEnvironment = // TODO: RENAME
(myRerunExecutionEnvironment != null ? myRerunExecutionEnvironment : createExecutionEnvironment(sdkPath, project, tempWorkingPath));
// Engine to be run after process end to post process console
final ProcessListener consolePostprocessor = new ProcessAdapter() {
@Override
public void processTerminated(final ProcessEvent event) {
super.processTerminated(event);
ApplicationManager.getApplication().invokeAndWait(() -> prepareConsoleAfterProcessEnd(), ModalityState.NON_MODAL);
}
};
/// Find all available runners to report them to the test
myAvailableRunnersForLastRun.clear();
for (final ProgramRunner<?> runner : ProgramRunner.PROGRAM_RUNNER_EP.getExtensions()) {
for (final Executor executor : Executor.EXECUTOR_EXTENSION_NAME.getExtensions()) {
if (runner.canRun(executor.getId(), executionEnvironment.getRunProfile())) {
myAvailableRunnersForLastRun.add(runner);
}
}
}
executionEnvironment.getRunner().execute(executionEnvironment, new ProgramRunner.Callback() {
@Override
public void processStarted(final RunContentDescriptor descriptor) {
final ProcessHandler handler = descriptor.getProcessHandler();
assert handler != null : "No process handler";
handler.addProcessListener(consolePostprocessor);
handler.addProcessListener(processListener);
myConsole = null;
fetchConsoleAndSetToField(descriptor);
assert myConsole != null : "fetchConsoleAndSetToField did not set console!";
// Console does not work with out of this method
final JComponent component = myConsole.getComponent();
assert component != null;
myLastProcessDescriptor = descriptor;
}
});
}
use of com.intellij.execution.process.ProcessListener in project intellij-community by JetBrains.
the class StudyRunAction method executeFile.
private void executeFile(@NotNull final Project project, @NotNull final VirtualFile openedFile, @NotNull final String filePath) {
GeneralCommandLine cmd = new GeneralCommandLine();
cmd.withWorkDirectory(openedFile.getParent().getCanonicalPath());
TaskFile selectedTaskFile = StudyUtils.getTaskFile(project, openedFile);
assert selectedTaskFile != null;
final Task currentTask = selectedTaskFile.getTask();
final Sdk sdk = StudyUtils.findSdk(currentTask, project);
if (sdk == null) {
StudyUtils.showNoSdkNotification(currentTask, project);
return;
}
String sdkHomePath = sdk.getHomePath();
if (sdkHomePath != null) {
cmd.setExePath(sdkHomePath);
StudyUtils.setCommandLineParameters(cmd, project, filePath, sdkHomePath, currentTask);
try {
myHandler = new OSProcessHandler(cmd);
} catch (ExecutionException e) {
LOG.error(e);
return;
}
for (ProcessListener processListener : myProcessListeners) {
myHandler.addProcessListener(processListener);
}
final RunContentExecutor executor = StudyUtils.getExecutor(project, currentTask, myHandler);
if (executor != null) {
Disposer.register(project, executor);
executor.run();
}
EduUtils.synchronize();
}
}
use of com.intellij.execution.process.ProcessListener in project intellij-community by JetBrains.
the class RemoteProcessSupport method getProcessListener.
private ProcessListener getProcessListener(@NotNull final Pair<Target, Parameters> key) {
return new ProcessListener() {
@Override
public void startNotified(ProcessEvent event) {
ProcessHandler processHandler = event.getProcessHandler();
processHandler.putUserData(ProcessHandler.SILENTLY_DESTROY_ON_CLOSE, Boolean.TRUE);
Info o;
synchronized (myProcMap) {
o = myProcMap.get(key);
if (o instanceof PendingInfo) {
myProcMap.put(key, new PendingInfo(((PendingInfo) o).ref, processHandler));
}
}
}
@Override
public void processTerminated(ProcessEvent event) {
if (dropProcessInfo(key, null, event.getProcessHandler())) {
fireModificationCountChanged();
}
}
@Override
public void processWillTerminate(ProcessEvent event, boolean willBeDestroyed) {
if (dropProcessInfo(key, null, event.getProcessHandler())) {
fireModificationCountChanged();
}
}
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
String text = StringUtil.notNullize(event.getText());
if (outputType == ProcessOutputTypes.STDERR) {
LOG.warn(text.trim());
} else {
LOG.info(text.trim());
}
RunningInfo result = null;
PendingInfo info;
synchronized (myProcMap) {
Info o = myProcMap.get(key);
logText(key.second, event, outputType, o);
if (o instanceof PendingInfo) {
info = (PendingInfo) o;
if (outputType == ProcessOutputTypes.STDOUT) {
String prefix = "Port/ID:";
if (text.startsWith(prefix)) {
String pair = text.substring(prefix.length()).trim();
int idx = pair.indexOf("/");
result = new RunningInfo(info.handler, Integer.parseInt(pair.substring(0, idx)), pair.substring(idx + 1));
myProcMap.put(key, result);
myProcMap.notifyAll();
}
} else if (outputType == ProcessOutputTypes.STDERR) {
info.stderr.append(text);
}
} else {
info = null;
}
}
if (result != null) {
synchronized (info.ref) {
info.ref.set(result);
info.ref.notifyAll();
}
fireModificationCountChanged();
try {
RemoteDeadHand.TwoMinutesTurkish.startCooking("localhost", result.port);
} catch (Throwable e) {
LOG.warn("The cook failed to start due to " + ExceptionUtil.getRootCause(e));
}
}
}
};
}
use of com.intellij.execution.process.ProcessListener in project intellij-community by JetBrains.
the class AbstractAutoTestManager method clearRestarterListener.
private static void clearRestarterListener(@NotNull ProcessHandler processHandler) {
ProcessListener restarterListener = ON_TERMINATION_RESTARTER_KEY.get(processHandler, null);
if (restarterListener != null) {
processHandler.removeProcessListener(restarterListener);
ON_TERMINATION_RESTARTER_KEY.set(processHandler, null);
}
}
use of com.intellij.execution.process.ProcessListener in project intellij-community by JetBrains.
the class AbstractAutoTestManager method scheduleRestartOnTermination.
private void scheduleRestartOnTermination(@NotNull final RunContentDescriptor descriptor, @NotNull final ProcessHandler processHandler, final int modificationStamp, @NotNull final AutoTestWatcher watcher) {
ProcessListener restarterListener = ON_TERMINATION_RESTARTER_KEY.get(processHandler);
if (restarterListener != null) {
clearRestarterListener(processHandler);
}
restarterListener = new ProcessAdapter() {
@Override
public void processTerminated(ProcessEvent event) {
clearRestarterListener(processHandler);
ApplicationManager.getApplication().invokeLater(() -> {
if (isAutoTestEnabledForDescriptor(descriptor) && watcher.isUpToDate(modificationStamp)) {
restart(descriptor);
}
}, ModalityState.any());
}
};
ON_TERMINATION_RESTARTER_KEY.set(processHandler, restarterListener);
processHandler.addProcessListener(restarterListener);
}
Aggregations