Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore warnings on specific missing sources #17798

Merged
merged 1 commit into from
Jun 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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