Search in sources :

Example 1 with Message

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

the class AndroidGradleTargetBuilder method handleBuildException.

/**
   * Something went wrong while invoking Gradle. Since we cannot distinguish an execution error from compilation errors easily, we first try
   * to show, in the "Problems" view, compilation errors by parsing the error output. If no errors are found, we show the stack trace in the
   * "Problems" view. The idea is that we need to somehow inform the user that something went wrong.
   */
private static void handleBuildException(BuildException e, CompileContext context, String stdErr) throws ProjectBuildException {
    Iterable<PatternAwareOutputParser> parsers = JpsServiceManager.getInstance().getExtensions(PatternAwareOutputParser.class);
    Collection<Message> compilerMessages = new BuildOutputParser(parsers).parseGradleOutput(stdErr);
    if (!compilerMessages.isEmpty()) {
        boolean hasError = false;
        for (Message message : compilerMessages) {
            if (message.getKind() == Message.Kind.ERROR) {
                hasError = true;
            }
            for (CompilerMessage compilerMessage : AndroidGradleJps.createCompilerMessages(message)) {
                context.processMessage(compilerMessage);
            }
        }
        if (hasError) {
            return;
        }
    }
    // There are no error messages to present. Show some feedback indicating that something went wrong.
    if (!stdErr.isEmpty()) {
        // Show the contents of stderr as a compiler error.
        context.processMessage(createCompilerErrorMessage(stdErr));
    } else {
        // Since we have nothing else to show, just print the stack trace of the caught exception.
        ByteArrayOutputStream out = new ByteArrayOutputStream(BUFFER_SIZE);
        try {
            //noinspection IOResourceOpenedButNotSafelyClosed
            e.printStackTrace(new PrintStream(out));
            String message = "Internal error:" + SystemProperties.getLineSeparator() + out.toString();
            context.processMessage(createCompilerErrorMessage(message));
        } finally {
            try {
                Closeables.close(out, true);
            } catch (IOException e1) {
                LOG.debug(e1);
            }
        }
    }
    throw new ProjectBuildException(e.getMessage());
}
Also used : ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) BuildOutputParser(com.android.tools.idea.gradle.output.parser.BuildOutputParser) PrintStream(java.io.PrintStream) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) Message(com.android.ide.common.blame.Message) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) BuildMessage(org.jetbrains.jps.incremental.messages.BuildMessage) PatternAwareOutputParser(com.android.ide.common.blame.parser.PatternAwareOutputParser) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 2 with Message

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

the class AndroidPluginOutputParser method parse.

@Override
public boolean parse(@NotNull String line, @NotNull OutputLineReader reader, @NotNull List<Message> messages, @NotNull ILogger logger) throws ParsingFailedException {
    if (line.contains("[DEBUG] ") || line.contains("[INFO] ")) {
        // Ignore 'debug' and 'info' messages.
        return false;
    }
    if (IGNORED_MESSAGE_PATTERN.matcher(line).matches()) {
        return false;
    }
    // pattern is type|path|message
    String[] segments = line.split("\\|", SEGMENT_COUNT);
    if (segments.length == SEGMENT_COUNT) {
        Message.Kind kind = Message.Kind.findIgnoringCase(segments[0], Message.Kind.ERROR);
        String path = segments[1];
        if (StringUtil.isEmpty(path)) {
            return false;
        }
        String msg = StringUtil.notNullize(segments[2]);
        // The SourceFile description is the Gradle path of the project.
        messages.add(new Message(kind, msg.trim(), new SourceFilePosition(new SourceFile(path.trim()), SourcePosition.UNKNOWN)));
        return true;
    }
    return false;
}
Also used : SourceFilePosition(com.android.ide.common.blame.SourceFilePosition) Message(com.android.ide.common.blame.Message) SourceFile(com.android.ide.common.blame.SourceFile)

Example 3 with Message

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

the class DexExceptionParser method parse.

@Override
public boolean parse(@NotNull String line, @NotNull OutputLineReader reader, @NotNull List<Message> messages, @NotNull ILogger logger) throws ParsingFailedException {
    Matcher m1 = ERROR.matcher(line);
    if (!m1.matches()) {
        return false;
    }
    String stackTrace = ParserUtil.digestStackTrace(reader);
    if (stackTrace == null) {
        return false;
    }
    Matcher m2 = ALREADY_ADDED_EXCEPTION.matcher(stackTrace);
    if (!m2.matches()) {
        return false;
    }
    String message = String.format("Class %1s has already been added to output. Please remove duplicate copies.", m2.group(1).replace('/', '.').replace('$', '.'));
    messages.add(new Message(Message.Kind.ERROR, message, new SourceFilePosition(SourceFile.UNKNOWN, SourcePosition.UNKNOWN)));
    return true;
}
Also used : SourceFilePosition(com.android.ide.common.blame.SourceFilePosition) Message(com.android.ide.common.blame.Message) Matcher(java.util.regex.Matcher)

Example 4 with Message

use of com.android.ide.common.blame.Message 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)

Example 5 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)

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