Search in sources :

Example 11 with Message

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);
    }
}
Also used : Message(com.android.ide.common.blame.Message)

Example 12 with 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);
        }
    }
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) SyncMessages(com.android.tools.idea.gradle.project.sync.messages.SyncMessages) Project(com.intellij.openapi.project.Project) SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) Message(com.android.ide.common.blame.Message) ExternalSystemException(com.intellij.openapi.externalSystem.model.ExternalSystemException) SyncErrorHandler(com.android.tools.idea.gradle.project.sync.errors.SyncErrorHandler) PositionInFile(com.android.tools.idea.gradle.util.PositionInFile) MessageType(com.android.tools.idea.gradle.project.sync.messages.MessageType) NotificationCategory(com.intellij.openapi.externalSystem.service.notification.NotificationCategory) NotificationData(com.intellij.openapi.externalSystem.service.notification.NotificationData)

Example 13 with 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());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) SourceFilePosition(com.android.ide.common.blame.SourceFilePosition) SyncMessageSubject.syncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessageSubject.syncMessage) SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) Message(com.android.ide.common.blame.Message) SourcePosition(com.android.ide.common.blame.SourcePosition) PositionInFile(com.android.tools.idea.gradle.util.PositionInFile) Module(com.intellij.openapi.module.Module)

Example 14 with Message

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;
}
Also used : SourceFilePosition(com.android.ide.common.blame.SourceFilePosition) Message(com.android.ide.common.blame.Message) SourcePosition(com.android.ide.common.blame.SourcePosition) File(java.io.File)

Example 15 with Message

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;
}
Also used : SourceFilePosition(com.android.ide.common.blame.SourceFilePosition) Message(com.android.ide.common.blame.Message) Matcher(java.util.regex.Matcher) SourcePosition(com.android.ide.common.blame.SourcePosition) SourceFile(com.android.ide.common.blame.SourceFile) SourceFile(com.android.ide.common.blame.SourceFile) File(java.io.File)

Aggregations

Message (com.android.ide.common.blame.Message)22 SourceFilePosition (com.android.ide.common.blame.SourceFilePosition)11 SourcePosition (com.android.ide.common.blame.SourcePosition)9 File (java.io.File)8 Test (org.junit.Test)7 SourceFile (com.android.ide.common.blame.SourceFile)4 Matcher (java.util.regex.Matcher)4 SyncMessage (com.android.tools.idea.gradle.project.sync.messages.SyncMessage)3 SyncMessageSubject.syncMessage (com.android.tools.idea.gradle.project.sync.messages.SyncMessageSubject.syncMessage)2 PositionInFile (com.android.tools.idea.gradle.util.PositionInFile)2 NotificationData (com.intellij.openapi.externalSystem.service.notification.NotificationData)2 Module (com.intellij.openapi.module.Module)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 ParsingFailedException (com.android.ide.common.blame.parser.ParsingFailedException)1 PatternAwareOutputParser (com.android.ide.common.blame.parser.PatternAwareOutputParser)1 BuildOutputParser (com.android.tools.idea.gradle.output.parser.BuildOutputParser)1 SyncErrorHandler (com.android.tools.idea.gradle.project.sync.errors.SyncErrorHandler)1 MessageType (com.android.tools.idea.gradle.project.sync.messages.MessageType)1 SyncMessages (com.android.tools.idea.gradle.project.sync.messages.SyncMessages)1 ExternalSystemException (com.intellij.openapi.externalSystem.model.ExternalSystemException)1