Skip to content

Commit

Permalink
Ignore warnings on specific missing sources
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez committed Jun 9, 2021
1 parent ab8e7b6 commit deba854
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 deba854

Please sign in to comment.