Build view: javac output parser handle 'Note' messages, e.g. notes about unchecked or unsafe operations usage.

This commit is contained in:
Vladislav.Soroka
2018-01-23 16:29:42 +03:00
parent 5b211cc012
commit e93ddccb40
2 changed files with 34 additions and 0 deletions
@@ -51,6 +51,21 @@ public class JavacOutputParser implements BuildOutputParser {
messageConsumer.accept(new MessageEventImpl(reader.getBuildId(), MessageEvent.Kind.ERROR, COMPILER_MESSAGES_GROUP, line, line));
return true;
}
if (part1.equalsIgnoreCase("Note")) {
String message = line.substring(colonIndex1 + 1).trim();
int javaFileExtensionIndex = message.indexOf(".java");
if (javaFileExtensionIndex > 0) {
File file = new File(message.substring(0, javaFileExtensionIndex + ".java".length()));
if (file.isFile()) {
message = message.substring(javaFileExtensionIndex + ".java".length() + 1);
String detailedMessage = amendNextInfoLinesIfNeeded(file.getPath() + ":\n" + message, reader);
messageConsumer.accept(new FileMessageEventImpl(reader.getBuildId(), MessageEvent.Kind.INFO, COMPILER_MESSAGES_GROUP,
message, detailedMessage,
new FilePosition(file, 0, 0)));
return true;
}
}
}
int colonIndex2 = line.indexOf(COLON, colonIndex1 + 1);
if (colonIndex2 >= 0) {
@@ -127,6 +142,24 @@ public class JavacOutputParser implements BuildOutputParser {
return false;
}
private static String amendNextInfoLinesIfNeeded(String str, BuildOutputInstantReader reader) {
StringBuilder builder = new StringBuilder(str);
String nextLine = reader.readLine();
while (nextLine != null) {
if (nextLine.startsWith("Note: ")) {
int index = nextLine.indexOf(".java");
if (index < 0) {
builder.append("\n").append(nextLine.substring("Note: ".length()));
nextLine = reader.readLine();
continue;
}
}
reader.pushBack();
break;
}
return builder.toString();
}
@Contract("null -> false")
private static boolean isMessageEnd(@Nullable String line) {
return line != null && line.length() > 0 && Character.isWhitespace(line.charAt(0));
@@ -96,6 +96,7 @@ class KotlincOutputParser : BuildOutputParser {
val colonIndex1 = indexOf(COLON)
return colonIndex1 == 0
|| (colonIndex1 >= 0 && substring(0, colonIndex1).startsWithSeverityPrefix()) // Next Kotlin message
|| StringUtil.startsWith(this, "Note: ") // Next javac info message candidate
|| StringUtil.containsIgnoreCase(this, "FAILURE")
|| StringUtil.containsIgnoreCase(this, "FAILED")
}