use of com.intellij.execution.impl.ConsoleViewImpl in project intellij-community by JetBrains.
the class GroovyConsole method createConsole.
@Nullable
public static GroovyConsole createConsole(@NotNull final Project project, @NotNull final VirtualFile contentFile, @NotNull Module module) {
final ProcessHandler processHandler = createProcessHandler(module);
if (processHandler == null)
return null;
final GroovyConsoleStateService consoleStateService = GroovyConsoleStateService.getInstance(project);
consoleStateService.setFileModule(contentFile, module);
final String title = consoleStateService.getSelectedModuleTitle(contentFile);
final ConsoleViewImpl consoleView = new ConsoleViewImpl(project, true);
final RunContentDescriptor descriptor = new RunContentDescriptor(consoleView, processHandler, new JPanel(new BorderLayout()), title);
final GroovyConsole console = new GroovyConsole(project, descriptor, consoleView, processHandler);
// must call getComponent before createConsoleActions()
final JComponent consoleViewComponent = consoleView.getComponent();
final DefaultActionGroup actionGroup = new DefaultActionGroup();
actionGroup.add(new BuildAndRestartConsoleAction(module, project, defaultExecutor, descriptor, restarter(project, contentFile)));
actionGroup.addSeparator();
actionGroup.addAll(consoleView.createConsoleActions());
actionGroup.add(new CloseAction(defaultExecutor, descriptor, project) {
@Override
public void actionPerformed(AnActionEvent e) {
// use force
processHandler.destroyProcess();
super.actionPerformed(e);
}
});
final ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, actionGroup, false);
toolbar.setTargetComponent(consoleViewComponent);
final JComponent ui = descriptor.getComponent();
ui.add(consoleViewComponent, BorderLayout.CENTER);
ui.add(toolbar.getComponent(), BorderLayout.WEST);
project.getMessageBus().connect().subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {
@Override
public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
if (file.equals(contentFile)) {
// if file was closed then kill process and hide console content
console.stop();
}
}
});
processHandler.addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(ProcessEvent event) {
if (contentFile.getUserData(GROOVY_CONSOLE) == console) {
// process terminated either by closing file or by close action
contentFile.putUserData(GROOVY_CONSOLE, null);
}
}
});
contentFile.putUserData(GROOVY_CONSOLE, console);
consoleView.attachToProcess(processHandler);
processHandler.startNotify();
ExecutionManager.getInstance(project).getContentManager().showRunContent(defaultExecutor, descriptor);
return console;
}
use of com.intellij.execution.impl.ConsoleViewImpl in project intellij-community by JetBrains.
the class PyUnitTestTask method getHighlightedStrings.
/**
* Gets highlighted information from test console. Some parts of output (like file links) may be highlighted, and you need to check them.
*
* @return pair of [[ranges], [texts]] where range is [from,to] in doc. for each region, and "text" is text extracted from this region.
* For example assume that in document "spam eggs ham" words "ham" and "spam" are highlighted.
* You should have 2 ranges (0, 4) and (10, 13) and 2 strings (spam and ham)
*/
@NotNull
public final Pair<List<Pair<Integer, Integer>>, List<String>> getHighlightedStrings() {
final ConsoleView console = myConsoleView.getConsole();
assert console instanceof ConsoleViewImpl : "Console has no editor!";
final ConsoleViewImpl consoleView = (ConsoleViewImpl) console;
final Editor editor = consoleView.getEditor();
final List<String> resultStrings = new ArrayList<>();
final List<Pair<Integer, Integer>> resultRanges = new ArrayList<>();
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override
public void run() {
/**
* To fetch data from console we need to flush it first.
* It works locally, but does not work on TC (reasons are not clear yet and need to be investigated).
* So, we flush it explicitly to make test run on TC.
*/
consoleView.flushDeferredText();
for (final RangeHighlighter highlighter : editor.getMarkupModel().getAllHighlighters()) {
if (highlighter instanceof RangeHighlighterEx) {
final int start = ((RangeHighlighterEx) highlighter).getAffectedAreaStartOffset();
final int end = ((RangeHighlighterEx) highlighter).getAffectedAreaEndOffset();
resultRanges.add(Pair.create(start, end));
resultStrings.add(editor.getDocument().getText().substring(start, end));
}
}
}
});
final String message = String.format("Following output is searched for hightlighed strings: %s \n", editor.getDocument().getText());
Logger.getInstance(getClass()).warn(message);
return Pair.create(resultRanges, resultStrings);
}
Aggregations