Skip to content

Commit

Permalink
Merge pull request #17798 from radcortez/fix-17618
Browse files Browse the repository at this point in the history
Ignore warnings on specific missing sources
  • Loading branch information
geoand authored Jun 10, 2021
2 parents d485042 + deba854 commit d7ad0a1
Showing 1 changed file with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class JavaCompilationProvider implements CompilationProvider {
// -parameters is used to generate metadata for reflection on method parameters
// this is useful when people using debuggers against their hot-reloaded app
private static final Set<String> COMPILER_OPTIONS = new HashSet<>(Arrays.asList("-g", "-parameters"));
private static final Set<String> IGNORE_NAMESPACES = new HashSet<>(Collections.singletonList("org.osgi"));

JavaCompiler compiler;
StandardJavaFileManager fileManager;
Expand Down Expand Up @@ -74,17 +75,10 @@ public void compile(Set<File> filesToCompile, Context context) {
throw new RuntimeException("Compilation failed" + diagnostics.getDiagnostics());
}

for (Diagnostic<? extends JavaFileObject> diagnostic : diagnostics.getDiagnostics()) {
log.logf(diagnostic.getKind() == Diagnostic.Kind.ERROR ? Logger.Level.ERROR : Logger.Level.WARN,
"%s, line %d in %s", diagnostic.getMessage(null), diagnostic.getLineNumber(),
diagnostic.getSource() == null ? "[unknown source]" : diagnostic.getSource().getName());
}
logDiagnostics(diagnostics);

if (!fileManagerDiagnostics.getDiagnostics().isEmpty()) {
for (Diagnostic<? extends JavaFileObject> diagnostic : fileManagerDiagnostics.getDiagnostics()) {
log.logf(diagnostic.getKind() == Diagnostic.Kind.ERROR ? Logger.Level.ERROR : Logger.Level.WARN,
"%s, line %d in %s", diagnostic.getMessage(null), diagnostic.getLineNumber(),
diagnostic.getSource() == null ? "[unknown source]" : diagnostic.getSource().getName());
}
logDiagnostics(fileManagerDiagnostics);
fileManager.close();
fileManagerDiagnostics = null;
fileManager = null;
Expand Down Expand Up @@ -117,6 +111,28 @@ public void close() throws IOException {
}
}

private void logDiagnostics(final DiagnosticCollector<JavaFileObject> diagnostics) {
for (Diagnostic<? extends JavaFileObject> diagnostic : diagnostics.getDiagnostics()) {
Logger.Level level = diagnostic.getKind() == Diagnostic.Kind.ERROR ? Logger.Level.ERROR : Logger.Level.WARN;
String message = diagnostic.getMessage(null);
if (level.equals(Logger.Level.WARN) && ignoreWarningForNamespace(message)) {
continue;
}

log.logf(level, "%s, line %d in %s", message, diagnostic.getLineNumber(),
diagnostic.getSource() == null ? "[unknown source]" : diagnostic.getSource().getName());
}
}

private static boolean ignoreWarningForNamespace(String message) {
for (String ignoreNamespace : IGNORE_NAMESPACES) {
if (message.contains(ignoreNamespace)) {
return true;
}
}
return false;
}

static class RuntimeUpdatesClassVisitor extends ClassVisitor {
private final PathsCollection sourcePaths;
private final String classesPath;
Expand Down

0 comments on commit d7ad0a1

Please sign in to comment.