use of com.intellij.execution.process.ProcessAdapter in project android by JetBrains.
the class AndroidCommonUtils method handleDexCompilationResult.
public static void handleDexCompilationResult(@NotNull Process process, @NotNull String commandLine, @NotNull String outputFilePath, @NotNull final Map<AndroidCompilerMessageKind, List<String>> messages, boolean multiDex) {
final BaseOSProcessHandler handler = new BaseOSProcessHandler(process, commandLine, null);
handler.addProcessListener(new ProcessAdapter() {
private AndroidCompilerMessageKind myCategory = null;
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
String[] msgs = event.getText().split("\\n");
for (String msg : msgs) {
msg = msg.trim();
String msglc = msg.toLowerCase();
if (outputType == ProcessOutputTypes.STDERR) {
if (WARNING_PATTERN.matcher(msglc).matches()) {
myCategory = AndroidCompilerMessageKind.WARNING;
}
if (ERROR_PATTERN.matcher(msglc).matches() || EXCEPTION_PATTERN.matcher(msglc).matches() || myCategory == null) {
myCategory = AndroidCompilerMessageKind.ERROR;
}
messages.get(myCategory).add(msg);
} else if (outputType == ProcessOutputTypes.STDOUT) {
if (!msglc.startsWith("processing")) {
messages.get(AndroidCompilerMessageKind.INFORMATION).add(msg);
}
}
LOG.debug(msg);
}
}
});
handler.startNotify();
handler.waitFor();
final List<String> errors = messages.get(AndroidCompilerMessageKind.ERROR);
if (new File(outputFilePath).isFile()) {
// if compilation finished correctly, show all errors as warnings
messages.get(AndroidCompilerMessageKind.WARNING).addAll(errors);
errors.clear();
} else if (errors.size() == 0 && !multiDex) {
errors.add("Cannot create classes.dex file");
}
}
use of com.intellij.execution.process.ProcessAdapter in project intellij-community by JetBrains.
the class AbstractToolBeforeRunTask method execute.
public boolean execute(final DataContext context, final long executionId) {
final Semaphore targetDone = new Semaphore();
final Ref<Boolean> result = new Ref<>(false);
try {
ApplicationManager.getApplication().invokeAndWait(() -> ToolAction.runTool(myToolActionId, context, null, executionId, new ProcessAdapter() {
public void startNotified(final ProcessEvent event) {
targetDone.down();
}
@Override
public void processTerminated(ProcessEvent event) {
result.set(event.getExitCode() == 0);
targetDone.up();
}
}), ModalityState.NON_MODAL);
} catch (Exception e) {
LOG.error(e);
return false;
}
targetDone.waitFor();
return result.get();
}
use of com.intellij.execution.process.ProcessAdapter in project intellij-community by JetBrains.
the class XDebugSessionImpl method init.
XDebugSessionTab init(@NotNull XDebugProcess process, @Nullable RunContentDescriptor contentToReuse) {
LOG.assertTrue(myDebugProcess == null);
myDebugProcess = process;
if (myDebugProcess.checkCanInitBreakpoints()) {
initBreakpoints();
}
myDebugProcess.getProcessHandler().addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(final ProcessEvent event) {
stopImpl();
myDebugProcess.getProcessHandler().removeProcessListener(this);
}
});
//todo[nik] make 'createConsole()' method return ConsoleView
myConsoleView = (ConsoleView) myDebugProcess.createConsole();
if (!myShowTabOnSuspend.get()) {
initSessionTab(contentToReuse);
}
return mySessionTab;
}
use of com.intellij.execution.process.ProcessAdapter in project intellij-community by JetBrains.
the class RunContentManagerImpl method showRunContent.
private void showRunContent(@NotNull final Executor executor, @NotNull final RunContentDescriptor descriptor, final long executionId) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
return;
}
final ContentManager contentManager = getContentManagerForRunner(executor, descriptor);
RunContentDescriptor oldDescriptor = chooseReuseContentForDescriptor(contentManager, descriptor, executionId, descriptor.getDisplayName());
final Content content;
if (oldDescriptor == null) {
content = createNewContent(descriptor, executor);
} else {
content = oldDescriptor.getAttachedContent();
LOG.assertTrue(content != null);
getSyncPublisher().contentRemoved(oldDescriptor, executor);
// is of the same category, can be reused
Disposer.dispose(oldDescriptor);
}
content.setExecutionId(executionId);
content.setComponent(descriptor.getComponent());
content.setPreferredFocusedComponent(descriptor.getPreferredFocusComputable());
content.putUserData(RunContentDescriptor.DESCRIPTOR_KEY, descriptor);
content.putUserData(EXECUTOR_KEY, executor);
content.setDisplayName(descriptor.getDisplayName());
descriptor.setAttachedContent(content);
String toolWindowId = getToolWindowIdForRunner(executor, descriptor);
final ToolWindow toolWindow = ToolWindowManager.getInstance(myProject).getToolWindow(toolWindowId);
final ProcessHandler processHandler = descriptor.getProcessHandler();
if (processHandler != null) {
final ProcessAdapter processAdapter = new ProcessAdapter() {
@Override
public void startNotified(final ProcessEvent event) {
UIUtil.invokeLaterIfNeeded(() -> {
content.setIcon(ExecutionUtil.getLiveIndicator(descriptor.getIcon()));
toolWindow.setIcon(ExecutionUtil.getLiveIndicator(myToolwindowIdToBaseIconMap.get(toolWindowId)));
});
}
@Override
public void processTerminated(final ProcessEvent event) {
ApplicationManager.getApplication().invokeLater(() -> {
boolean alive = false;
ContentManager manager = myToolwindowIdToContentManagerMap.get(toolWindowId);
if (manager == null)
return;
for (Content content1 : manager.getContents()) {
RunContentDescriptor descriptor1 = getRunContentDescriptorByContent(content1);
if (descriptor1 != null) {
ProcessHandler handler = descriptor1.getProcessHandler();
if (handler != null && !handler.isProcessTerminated()) {
alive = true;
break;
}
}
}
Icon base = myToolwindowIdToBaseIconMap.get(toolWindowId);
toolWindow.setIcon(alive ? ExecutionUtil.getLiveIndicator(base) : base);
Icon icon = descriptor.getIcon();
content.setIcon(icon == null ? executor.getDisabledIcon() : IconLoader.getTransparentIcon(icon));
});
}
};
processHandler.addProcessListener(processAdapter);
final Disposable disposer = content.getDisposer();
if (disposer != null) {
Disposer.register(disposer, new Disposable() {
@Override
public void dispose() {
processHandler.removeProcessListener(processAdapter);
}
});
}
}
if (oldDescriptor == null) {
contentManager.addContent(content);
new CloseListener(content, executor);
}
content.getManager().setSelectedContent(content);
if (!descriptor.isActivateToolWindowWhenAdded()) {
return;
}
ApplicationManager.getApplication().invokeLater(() -> {
ToolWindow window = ToolWindowManager.getInstance(myProject).getToolWindow(toolWindowId);
// let's activate tool window, but don't move focus
//
// window.show() isn't valid here, because it will not
// mark the window as "last activated" windows and thus
// some action like navigation up/down in stacktrace wont
// work correctly
descriptor.getPreferredFocusComputable();
window.activate(descriptor.getActivationCallback(), descriptor.isAutoFocusContent(), descriptor.isAutoFocusContent());
}, myProject.getDisposed());
}
use of com.intellij.execution.process.ProcessAdapter 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()));
}
Aggregations