From deba854cda5525cb6d46c386185eb9f1225922c8 Mon Sep 17 00:00:00 2001 From: Roberto Cortez Date: Wed, 9 Jun 2021 12:55:15 +0100 Subject: [PATCH] Ignore warnings on specific missing sources --- .../dev/JavaCompilationProvider.java | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/JavaCompilationProvider.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/JavaCompilationProvider.java index 2346fba5cbfb7..487a874b6f9af 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/JavaCompilationProvider.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/JavaCompilationProvider.java @@ -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 COMPILER_OPTIONS = new HashSet<>(Arrays.asList("-g", "-parameters")); + private static final Set IGNORE_NAMESPACES = new HashSet<>(Collections.singletonList("org.osgi")); JavaCompiler compiler; StandardJavaFileManager fileManager; @@ -74,17 +75,10 @@ public void compile(Set filesToCompile, Context context) { throw new RuntimeException("Compilation failed" + diagnostics.getDiagnostics()); } - for (Diagnostic 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 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; @@ -117,6 +111,28 @@ public void close() throws IOException { } } + private void logDiagnostics(final DiagnosticCollector diagnostics) { + for (Diagnostic 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;