use of com.android.ide.common.blame.parser.PatternAwareOutputParser 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());
}
Aggregations