@Override public void onTextAvailable(ProcessEvent event, Key outputType) { String text = event.getText(); if (outputType == ProcessOutputTypes.STDERR) { output.append(text); // We loop until the state stabilizes State lastState; do { lastState = state; switch (state) { case WAITING: { Matcher matcher = matcher(DIAGNOSTIC_PATTERN); if (find(matcher)) { currentCompilerMessage = new CompilerMessage(); currentCompilerMessage.setMessageCategoryFromString(matcher.group(1)); state = State.ATTRIBUTES; } break; } case ATTRIBUTES: { Matcher matcher = matcher(ATTRIBUTE_PATTERN); int indexDelta = 0; while (matcher.find()) { handleSkippedOutput( output.subSequence( firstUnprocessedIndex + indexDelta, firstUnprocessedIndex + matcher.start())); currentCompilerMessage.setAttributeFromStrings( matcher.group(1), matcher.group(2)); indexDelta = matcher.end(); } firstUnprocessedIndex += indexDelta; Matcher endMatcher = matcher(OPEN_TAG_END_PATTERN); if (find(endMatcher)) { state = State.MESSAGE; } break; } case MESSAGE: { Matcher matcher = matcher(MESSAGE_PATTERN); if (find(matcher)) { currentCompilerMessage.setMessage(matcher.group(1)); currentCompilerMessage.reportTo(compileContext); state = State.WAITING; } break; } } } while (state != lastState); } else { compileContext.addMessage(INFORMATION, text, "", -1, -1); } }
private static VirtualFile getVirtualFile(final CompilerMessage message) { VirtualFile virtualFile = message.getVirtualFile(); if (virtualFile == null) { Navigatable navigatable = message.getNavigatable(); if (navigatable instanceof OpenFileDescriptor) { virtualFile = ((OpenFileDescriptor) navigatable).getFile(); } } return virtualFile; }
public void addMessage(final CompilerMessage message) { prepareMessageView(); final CompilerMessageCategory messageCategory = message.getCategory(); if (CompilerMessageCategory.WARNING.equals(messageCategory)) { myWarningCount += 1; } else if (CompilerMessageCategory.ERROR.equals(messageCategory)) { myErrorCount += 1; informWolf(message); } if (ApplicationManager.getApplication().isDispatchThread()) { openMessageView(); doAddMessage(message); } else { final Window window = getWindow(); final ModalityState modalityState = window != null ? ModalityState.stateForComponent(window) : ModalityState.NON_MODAL; ApplicationManager.getApplication() .invokeLater( new Runnable() { public void run() { if (!myProject.isDisposed()) { openMessageView(); doAddMessage(message); } } }, modalityState); } }
public static TextRange getTextRange(final CompilerMessage message) { Navigatable navigatable = message.getNavigatable(); if (navigatable instanceof OpenFileDescriptor) { int offset = ((OpenFileDescriptor) navigatable).getOffset(); return new TextRange(offset, offset); } return TextRange.EMPTY_RANGE; }
private void doAddMessage(final CompilerMessage message) { synchronized (myMessageViewLock) { if (myErrorTreeView != null) { final Navigatable navigatable = message.getNavigatable(); final VirtualFile file = message.getVirtualFile(); final CompilerMessageCategory category = message.getCategory(); final int type = translateCategory(category); final String[] text = convertMessage(message); if (navigatable != null) { final String groupName = file != null ? file.getPresentableUrl() : category.getPresentableText(); myErrorTreeView.addMessage( type, text, groupName, navigatable, message.getExportTextPrefix(), message.getRenderTextPrefix(), message.getVirtualFile()); } else { myErrorTreeView.addMessage(type, text, file, -1, -1, message.getVirtualFile()); } final boolean shouldAutoActivate = !myMessagesAutoActivated && (CompilerMessageCategory.ERROR.equals(category) || (CompilerMessageCategory.WARNING.equals(category) && !ErrorTreeViewConfiguration.getInstance(myProject).isHideWarnings())); if (shouldAutoActivate) { myMessagesAutoActivated = true; activateMessageView(); } } } }
@Override public void addMessage(CompilerMessage msg) { if (ApplicationManager.getApplication().isUnitTestMode()) { LOG.info("addMessage: " + msg + " this=" + this); } Collection<CompilerMessage> messages = myMessages.get(msg.getCategory()); if (messages == null) { messages = new LinkedHashSet<CompilerMessage>(); myMessages.put(msg.getCategory(), messages); } if (messages.add(msg)) { myTask.addMessage(msg); } if (ApplicationManager.getApplication().isCompilerServerMode()) { VirtualFile virtualFile = msg.getVirtualFile(); CompilerClientConnector.getInstance(myProject) .addMessage( msg.getCategory(), msg.getMessage(), virtualFile == null ? null : virtualFile.getPath(), msg.getLine(), msg.getColumn()); } else { ProblemsView.getInstance(myProject).addMessage(msg); } }
private static String[] convertMessage(final CompilerMessage message) { String text = message.getMessage(); if (!text.contains("\n")) { return new String[] {text}; } ArrayList<String> lines = new ArrayList<String>(); StringTokenizer tokenizer = new StringTokenizer(text, "\n", false); while (tokenizer.hasMoreTokens()) { lines.add(tokenizer.nextToken()); } return ArrayUtil.toStringArray(lines); }
@Override public void finished( boolean aborted, int errors, int warnings, final CompileContext compileContext) { try { for (CompilerMessageCategory category : CompilerMessageCategory.values()) { for (CompilerMessage message : compileContext.getMessages(category)) { final String msg = message.getMessage(); if (category != CompilerMessageCategory.INFORMATION || !msg.startsWith("Compilation completed successfully")) { myMessages.add(category + ": " + msg); } } } if (errors > 0) { fail("Compiler errors occurred! " + StringUtil.join(myMessages, "\n")); } assertFalse("Code did not compile!", aborted); } catch (Throwable t) { myError = t; } finally { mySemaphore.up(); } }