Search in sources :

Example 1 with ParsingFailedException

use of com.android.ide.common.blame.parser.ParsingFailedException in project android by JetBrains.

the class ManifestMergeFailureParser method parse.

@Override
public boolean parse(@NotNull String line, @NotNull OutputLineReader reader, @NotNull List<Message> messages, @NotNull ILogger logger) throws ParsingFailedException {
    Matcher m = ERROR1.matcher(line);
    if (m.matches()) {
        String sourcePath = m.group(1);
        int lineNumber;
        try {
            lineNumber = Integer.parseInt(m.group(2));
        } catch (NumberFormatException e) {
            throw new ParsingFailedException(e);
        }
        String message = m.group(3);
        messages.add(new Message(Message.Kind.ERROR, message, new SourceFilePosition(new File(sourcePath), new SourcePosition(lineNumber - 1, -1, -1))));
        return true;
    }
    m = ERROR2.matcher(line);
    if (m.matches()) {
        String sourcePath = removeLeadingTab(m.group(1)).trim();
        int lineNumber;
        try {
            lineNumber = Integer.parseInt(m.group(2));
        } catch (NumberFormatException e) {
            throw new ParsingFailedException(e);
        }
        int column;
        try {
            column = Integer.parseInt(m.group(3));
        } catch (NumberFormatException e) {
            throw new ParsingFailedException(e);
        }
        if (lineNumber == 0 && column == 0) {
            // When both line number and column is zero, it is just a message saying "Validation failed, exiting". No need to display it.
            String next = reader.peek(0);
            if (next != null && next.contains("Validation failed, exiting")) {
                reader.readLine();
                return true;
            }
        } else {
            String msg = reader.readLine();
            if (msg != null) {
                msg = removeLeadingTab(msg).trim();
                Message.Kind kind = Message.Kind.findIgnoringCase(m.group(4), Message.Kind.ERROR);
                messages.add(new Message(kind, msg.trim(), new SourceFilePosition(new File(sourcePath), new SourcePosition(lineNumber - 1, column - 1, -1))));
                return true;
            }
        }
    }
    return false;
}
Also used : ParsingFailedException(com.android.ide.common.blame.parser.ParsingFailedException) 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) File(java.io.File)

Aggregations

Message (com.android.ide.common.blame.Message)1 SourceFile (com.android.ide.common.blame.SourceFile)1 SourceFilePosition (com.android.ide.common.blame.SourceFilePosition)1 SourcePosition (com.android.ide.common.blame.SourcePosition)1 ParsingFailedException (com.android.ide.common.blame.parser.ParsingFailedException)1 File (java.io.File)1 Matcher (java.util.regex.Matcher)1