Don't suppress non-NOTE diagnostics for failed builds
To avoid hiding compiler.warn.sun.proprietary warnings when running with -Werror.
Fixes bazelbuild/bazel#4564
@@ -43,6 +43,7 @@ import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
+import javax.tools.Diagnostic;
import javax.tools.StandardLocation;
/**
@@ -129,7 +130,7 @@ public class BlazeJavacMain {
}
errWriter.flush();
return new BlazeJavacResult(
- ok, filterDiagnostics(diagnostics.build()), errOutput.toString(), compiler);
+ ok, filterDiagnostics(ok, diagnostics.build()), errOutput.toString(), compiler);
}
private static final ImmutableSet<String> IGNORED_DIAGNOSTIC_CODES =
@@ -147,14 +148,22 @@ public class BlazeJavacMain {
"compiler.warn.sun.proprietary");
private static ImmutableList<FormattedDiagnostic> filterDiagnostics(
- ImmutableList<FormattedDiagnostic> diagnostics) {
- // TODO(cushon): toImmutableList
- ImmutableList.Builder<FormattedDiagnostic> result = ImmutableList.builder();
- diagnostics
+ boolean ok, ImmutableList<FormattedDiagnostic> diagnostics) {
+ return diagnostics
.stream()
- .filter(d -> !IGNORED_DIAGNOSTIC_CODES.contains(d.getCode()))
- .forEach(result::add);
- return result.build();
+ .filter(d -> shouldReportDiagnostic(ok, d))
+ .collect(toImmutableList());
+ }
+
+ private static boolean shouldReportDiagnostic(boolean ok, FormattedDiagnostic diagnostic) {
+ if (!IGNORED_DIAGNOSTIC_CODES.contains(diagnostic.getCode())) {
+ return true;
+ }
+ if (!ok && diagnostic.getKind() != Diagnostic.Kind.NOTE) {
+ // show compiler.warn.sun.proprietary in case we're running with -Werror
+ return true;
+ }
+ return false;
}
/** Processes Plugin-specific arguments and removes them from the args array. */
