From 248bd8413707bd82beb8dd6a89a994f90140d072 Mon Sep 17 00:00:00 2001 From: Julien Ponge Date: Sat, 18 Jan 2025 08:55:52 +0100 Subject: [PATCH] Remove logger usage to converge to the annotation processor messager This brings more consistent message and error reporting than what JDK logging does, and it does not mess with build tools output. --- vertx-codegen-json/pom.xml | 1 + vertx-codegen-processor/README.md | 1 + vertx-codegen-processor/pom.xml | 1 + .../vertx/codegen/processor/ClassModel.java | 4 +--- .../io/vertx/codegen/processor/CodeGen.java | 2 -- .../io/vertx/codegen/processor/Processor.java | 20 ++++++++++++------- vertx-codegen-protobuf/pom.xml | 1 + .../src/main/asciidoc/index.adoc | 1 + 8 files changed, 19 insertions(+), 12 deletions(-) diff --git a/vertx-codegen-json/pom.xml b/vertx-codegen-json/pom.xml index 5d774c2fd..a1d1cdbd3 100644 --- a/vertx-codegen-json/pom.xml +++ b/vertx-codegen-json/pom.xml @@ -53,6 +53,7 @@ default-compile + true io.vertx diff --git a/vertx-codegen-processor/README.md b/vertx-codegen-processor/README.md index 08688b300..ca133e2ab 100644 --- a/vertx-codegen-processor/README.md +++ b/vertx-codegen-processor/README.md @@ -48,6 +48,7 @@ You can configure the `>io.vertx.codegen.processor.Processor` as any Java annota ${project.build.sourceEncoding} false + true diff --git a/vertx-codegen-processor/pom.xml b/vertx-codegen-processor/pom.xml index b377990a6..a916b28fb 100644 --- a/vertx-codegen-processor/pom.xml +++ b/vertx-codegen-processor/pom.xml @@ -214,6 +214,7 @@ ${project.build.directory}/test-classpath ${project.basedir}/src/tck/resources + true io.vertx.codegen.processor.Processor diff --git a/vertx-codegen-processor/src/main/java/io/vertx/codegen/processor/ClassModel.java b/vertx-codegen-processor/src/main/java/io/vertx/codegen/processor/ClassModel.java index f8dcbb4bc..5421a303d 100644 --- a/vertx-codegen-processor/src/main/java/io/vertx/codegen/processor/ClassModel.java +++ b/vertx-codegen-processor/src/main/java/io/vertx/codegen/processor/ClassModel.java @@ -34,7 +34,6 @@ import javax.lang.model.util.Types; import javax.tools.Diagnostic; import java.util.*; -import java.util.logging.Logger; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -54,7 +53,6 @@ public class ClassModel implements Model { public static final String ITERATOR = "java.util.Iterator"; public static final String FUNCTION = "java.util.function.Function"; public static final String SUPPLIER = "java.util.function.Supplier"; - private static final Logger logger = Logger.getLogger(ClassModel.class.getName()); protected final ProcessingEnvironment env; protected final AnnotationValueInfoFactory annotationValueInfoFactory; @@ -697,7 +695,7 @@ private MethodInfo createMethod(ExecutableElement modelMethod, boolean allowAnyJ String msg = "Interface " + modelElt + " does not redeclare the @Fluent return type " + " of method " + modelMethod + " declared by " + declaringElt; messager.printMessage(Diagnostic.Kind.WARNING, msg, modelElt, fluentAnnotation); - logger.warning(msg); + env.getMessager().printMessage(Diagnostic.Kind.WARNING, msg); } else { TypeMirror fluentType = modelMethod.getReturnType(); if (!typeUtils.isAssignable(fluentType, modelElt.asType())) { diff --git a/vertx-codegen-processor/src/main/java/io/vertx/codegen/processor/CodeGen.java b/vertx-codegen-processor/src/main/java/io/vertx/codegen/processor/CodeGen.java index 370e837c1..71ef179f2 100644 --- a/vertx-codegen-processor/src/main/java/io/vertx/codegen/processor/CodeGen.java +++ b/vertx-codegen-processor/src/main/java/io/vertx/codegen/processor/CodeGen.java @@ -20,7 +20,6 @@ import java.util.*; import java.util.function.Predicate; import java.util.function.Supplier; -import java.util.logging.Logger; import java.util.stream.Stream; /** @@ -46,7 +45,6 @@ public class CodeGen { PROVIDERS = list; } - private static final Logger logger = Logger.getLogger(CodeGen.class.getName()); final static Map loaderMap = new WeakHashMap<>(); private final Map>> models = new HashMap<>(); diff --git a/vertx-codegen-processor/src/main/java/io/vertx/codegen/processor/Processor.java b/vertx-codegen-processor/src/main/java/io/vertx/codegen/processor/Processor.java index 88812685f..e1d2c4dc6 100644 --- a/vertx-codegen-processor/src/main/java/io/vertx/codegen/processor/Processor.java +++ b/vertx-codegen-processor/src/main/java/io/vertx/codegen/processor/Processor.java @@ -23,8 +23,6 @@ import java.nio.file.Path; import java.util.*; import java.util.function.Predicate; -import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -37,7 +35,6 @@ public class Processor extends AbstractProcessor { private static final String JSON_MAPPERS_PROPERTIES_PATH = "META-INF/vertx/json-mappers.properties"; - public static final Logger log = Logger.getLogger(Processor.class.getName()); private File outputDirectory; private List> codeGenerators; private Map generatedResources = new HashMap<>(); @@ -155,6 +152,15 @@ private Path determineSourcePathInEclipse() { return null; } + private String throwableToMessageString(Throwable e) { + StringBuilder builder = new StringBuilder(); + builder.append(e.getMessage()).append("\n"); + for (StackTraceElement stackTraceElement : e.getStackTrace()) { + builder.append(" ").append(stackTraceElement.toString()).append("\n"); + } + return builder.toString(); + } + private List loadJsonMappers() { Exception exception = null; List merged = new ArrayList<>(); @@ -199,7 +205,7 @@ private List loadJsonMappers() { loadJsonMappers(merged, is); processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Loaded json-mappers.properties from '" + source + "'"); } catch (IOException e) { - log.log(Level.SEVERE, "Could not load json-mappers.properties", e); + processingEnv.getMessager().printMessage(Diagnostic.Kind.MANDATORY_WARNING, "Could not load json-mappers.properties: " + throwableToMessageString(e)); processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, "Unable to open properties file at " + source); } } @@ -220,7 +226,7 @@ private List loadJsonMappers() { loadJsonMappers(merged, is); processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Loaded json-mappers.properties from '" + source + "'"); } catch (IOException e) { - log.log(Level.SEVERE, "Could not load json-mappers.properties", e); + processingEnv.getMessager().printMessage(Diagnostic.Kind.MANDATORY_WARNING, "Could not load json-mappers.properties: " + throwableToMessageString(e)); processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, "Unable to open properties file at " + source); } } @@ -342,13 +348,13 @@ private void reportGenException(GenException e) { name = e.element.getEnclosingElement() + "#" + name; } String msg = "Could not generate model for " + name + ": " + e.msg; - log.log(Level.SEVERE, msg, e); + processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, msg + "\nCaused by: " + throwableToMessageString(e)); processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, msg, e.element); } private void reportException(Exception e, Element elt) { String msg = "Could not generate element for " + elt + ": " + e.getMessage(); - log.log(Level.SEVERE, msg, e); + processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, msg + "\nCaused by: " + throwableToMessageString(e)); processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, msg, elt); } diff --git a/vertx-codegen-protobuf/pom.xml b/vertx-codegen-protobuf/pom.xml index 2ad9b9726..5d516b0a0 100644 --- a/vertx-codegen-protobuf/pom.xml +++ b/vertx-codegen-protobuf/pom.xml @@ -74,6 +74,7 @@ processor + true -Adocgen.source=${asciidoc.dir} -Adocgen.output=${project.build.directory}/asciidoc/java diff --git a/vertx-codegen-protobuf/src/main/asciidoc/index.adoc b/vertx-codegen-protobuf/src/main/asciidoc/index.adoc index ec61e032c..06ffc8375 100644 --- a/vertx-codegen-protobuf/src/main/asciidoc/index.adoc +++ b/vertx-codegen-protobuf/src/main/asciidoc/index.adoc @@ -147,6 +147,7 @@ Lombok uses internal compiler API to update Abstract Syntax Tree of the compiler ${vertx.version} + true ----