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());
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations