use of com.android.ide.common.blame.Message in project android by JetBrains.
the class JavacOutputParser method addMessage.
private static void addMessage(@NotNull Message message, @NotNull List<Message> messages) {
boolean duplicatesPrevious = false;
int messageCount = messages.size();
if (messageCount > 0) {
Message lastMessage = messages.get(messageCount - 1);
duplicatesPrevious = lastMessage.equals(message);
}
if (!duplicatesPrevious) {
messages.add(message);
}
}
use of com.android.ide.common.blame.Message in project android by JetBrains.
the class ExternalNdkBuildIssuesReporter method report.
@Override
void report(@NotNull SyncIssue syncIssue, @NotNull Module module, @Nullable VirtualFile buildFile) {
String group = "External Native Build Issues";
String nativeToolOutput = syncIssue.getData();
if (nativeToolOutput != null) {
SyncMessages messages = getSyncMessages(module);
// Parse the native build tool output with the list of existing parsers.
List<Message> compilerMessages = myBuildOutputParser.parseGradleOutput(nativeToolOutput);
for (Message compilerMessage : compilerMessages) {
MessageType type = MessageType.findMatching(compilerMessage.getKind());
PositionInFile position = createPosition(compilerMessage.getSourceFilePositions());
String text = compilerMessage.getText();
Project project = module.getProject();
if (type == ERROR) {
// TODO make error handlers work with SyncMessage, instead of NotificationData.
NotificationCategory category = type.convertToCategory();
NotificationData notification = messages.createNotification(group, text, category, position);
// Try to parse the error messages using the list of existing error handlers to find any potential quick-fixes.
for (SyncErrorHandler handler : myErrorHandlers) {
if (handler.handleError(new ExternalSystemException(text), notification, project)) {
break;
}
}
messages.report(notification);
continue;
}
SyncMessage message;
if (position != null) {
message = new SyncMessage(project, group, type, position, text);
} else {
message = new SyncMessage(group, type, text);
}
messages.report(message);
}
}
}
use of com.android.ide.common.blame.Message in project android by JetBrains.
the class ExternalNdkBuildIssuesReporterTest method testReportWithWarning.
public void testReportWithWarning() throws Exception {
loadSimpleApplication();
mySyncMessagesStub.clearReportedMessages();
Module appModule = myModules.getAppModule();
String nativeToolOutput = "Failed to compile something";
when(mySyncIssue.getData()).thenReturn(nativeToolOutput);
VirtualFile buildFile = getGradleBuildFile(appModule);
assertNotNull(buildFile);
int line = 6;
int column = 8;
SourcePosition sourcePosition = new SourcePosition(line, column, 0);
SourceFilePosition sourceFilePosition = new SourceFilePosition(virtualToIoFile(buildFile), sourcePosition);
Message compilerMessage = new Message(WARNING, nativeToolOutput, sourceFilePosition);
List<Message> compilerMessages = Lists.newArrayList(compilerMessage);
when(myOutputParser.parseGradleOutput(nativeToolOutput)).thenReturn(compilerMessages);
myReporter.report(mySyncIssue, appModule, buildFile);
SyncMessage message = mySyncMessagesStub.getFirstReportedMessage();
assertNotNull(message);
assertThat(message.getText()).hasLength(1);
assertAbout(syncMessage()).that(message).hasMessageLine(nativeToolOutput, 0);
PositionInFile position = message.getPosition();
assertNotNull(position);
assertEquals(buildFile, position.file);
assertEquals(line, position.line);
assertEquals(column, position.column);
assertThat(message.getQuickFixes()).isEmpty();
assertFalse(myErrorHandler.isInvoked());
}
use of com.android.ide.common.blame.Message in project android by JetBrains.
the class MergingExceptionParser method parse.
@Override
public boolean parse(@NotNull String line, @NotNull OutputLineReader reader, @NotNull List<Message> messages, @NotNull ILogger logger) throws ParsingFailedException {
boolean hasError = false;
int messageIndex;
Message.Kind kind = null;
//noinspection SpellCheckingInspection
if (line.contains("rror: ")) {
messageIndex = line.indexOf(": Error: ");
if (messageIndex == -1) {
messageIndex = line.indexOf(": error: ");
if (messageIndex == -1) {
return false;
}
}
kind = Message.Kind.ERROR;
} else {
//noinspection SpellCheckingInspection
if (line.contains("arning: ")) {
messageIndex = line.indexOf(": Warning: ");
if (messageIndex == -1) {
messageIndex = line.indexOf(": warning: ");
if (messageIndex == -1) {
return false;
}
}
kind = Message.Kind.WARNING;
} else {
return false;
}
}
// TODO: This doesn't handle ambiguous scenarios where the error message itself contains ": " or the path contains " : ".
// I could disambiguate this by checking file existence on the path component containing a ":" !
// See if it's preceded by a line number and/or a column
String path;
int lineNumber = -1;
int column = -1;
int colon = line.lastIndexOf(':', messageIndex - 1);
if (colon != -1) {
// Is there a column?
int colon2 = line.lastIndexOf(':', colon - 1);
if (colon2 != -1) {
// Both line number and column
//lineNumber =
String columnString = line.substring(colon + 1, messageIndex);
String lineString = line.substring(colon2 + 1, colon);
try {
column = Integer.parseInt(columnString);
lineNumber = Integer.parseInt(lineString);
} catch (NumberFormatException e) {
// Could it be a Windows path with drive letters (and no line number) ?
if (colon2 == 1) {
String p = line.substring(0, colon);
if (new File(p).exists()) {
colon2 = colon;
} else {
return false;
}
} else {
return false;
}
}
path = line.substring(0, colon2);
} else {
// Just one number: it's the line
try {
lineNumber = Integer.parseInt(line.substring(colon + 1, messageIndex));
} catch (NumberFormatException e) {
// Could it be a Windows path with drive letters (and no line number) ?
if (colon == 1) {
String p = line.substring(0, messageIndex);
if (new File(p).exists()) {
colon = messageIndex;
} else {
return false;
}
} else {
return false;
}
}
path = line.substring(0, colon);
}
} else {
path = line.substring(0, messageIndex);
}
String message = line.substring(messageIndex + 2);
messages.add(new Message(kind, message, new SourceFilePosition(new File(path), new SourcePosition(lineNumber - 1, column - 1, -1))));
return true;
}
use of com.android.ide.common.blame.Message in project android by JetBrains.
the class XmlValidationErrorParser method parse.
@Override
public boolean parse(@NotNull String line, @NotNull OutputLineReader reader, @NotNull List<Message> messages, @NotNull ILogger logger) throws ParsingFailedException {
Matcher m1 = FATAL_ERROR.matcher(line);
if (!m1.matches()) {
// Sometimes the parse failure message appears by itself (for example with duplicate resources);
// in this case also recognize the line by itself even though it's separated from the next message
Matcher m2 = FILE_REFERENCE.matcher(line);
if (m2.matches()) {
File sourceFile = new File(m2.group(1));
if (sourceFile.exists()) {
String message = line;
// Eat the entire stacktrace
String exceptionMessage = ParserUtil.digestStackTrace(reader);
if (exceptionMessage != null) {
message = exceptionMessage + ": " + message;
}
messages.add(new Message(Message.Kind.ERROR, message, new SourceFilePosition(sourceFile, SourcePosition.UNKNOWN)));
return true;
}
}
return false;
}
String message = m1.group(3);
int lineNumber = Integer.parseInt(m1.group(1));
int column = Integer.parseInt(m1.group(2));
SourceFile sourceFile = SourceFile.UNKNOWN;
String nextLine = reader.peek(0);
if (nextLine == null) {
return false;
}
Matcher m2 = FILE_REFERENCE.matcher(nextLine);
if (m2.matches()) {
// digest peeked line
reader.readLine();
File possibleSourceFile = new File(m2.group(1));
if (possibleSourceFile.exists()) {
sourceFile = new SourceFile(possibleSourceFile);
}
}
messages.add(new Message(Message.Kind.ERROR, message, new SourceFilePosition(sourceFile, new SourcePosition(lineNumber - 1, column - 1, -1))));
return true;
}
Aggregations