From 69c25309da01d0a9a8482475eaa15e358eba8fa0 Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Thu, 16 Jan 2025 16:31:52 +1300 Subject: [PATCH 1/2] [querybean-generator] FilerException trying to write EntityClassRegister with Quarkus dev mode / hot reload #3541 Drop to log at WARN level when we catch FilerException such that Quarkus dev mode / hot reload works --- .../generator/ProcessingContext.java | 8 +++---- .../ebean/querybean/generator/Processor.java | 23 +++--------------- .../generator/SimpleModuleInfoWriter.java | 2 -- querybean-generator/pom.xml | 3 ++- .../generator/ProcessingContext.java | 5 +++- .../ebean/querybean/generator/Processor.java | 24 ++++--------------- 6 files changed, 17 insertions(+), 48 deletions(-) diff --git a/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/ProcessingContext.java b/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/ProcessingContext.java index e946197158..2af1140779 100644 --- a/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/ProcessingContext.java +++ b/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/ProcessingContext.java @@ -415,9 +415,10 @@ void logError(Element e, String msg, Object... args) { messager.printMessage(Diagnostic.Kind.ERROR, String.format(msg, args), e); } - /** - * Log a info message. - */ + void logWarn(String msg, Object... args) { + messager.printMessage(Diagnostic.Kind.WARNING, String.format(msg, args)); + } + void logNote(String msg, Object... args) { messager.printMessage(Diagnostic.Kind.NOTE, String.format(msg, args)); } @@ -559,7 +560,6 @@ String loadMetaInfServices() { } catch (FilerException e) { logNote(null, "FilerException reading services file: " + e.getMessage()); } catch (Exception e) { - e.printStackTrace(); logError(null, "Error reading services file: " + e.getMessage()); } return null; diff --git a/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/Processor.java b/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/Processor.java index 44215410ce..3f336019b9 100644 --- a/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/Processor.java +++ b/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/Processor.java @@ -19,14 +19,12 @@ public class Processor extends AbstractProcessor implements Constants { private static final String KAPT_KOTLIN_GENERATED_OPTION = "kapt.kotlin.generated"; private ProcessingContext processingContext; - private SimpleModuleInfoWriter moduleWriter; public Processor() { } @Override public Set getSupportedOptions() { - Set options = new LinkedHashSet<>(); options.add(KAPT_KOTLIN_GENERATED_OPTION); options.add(GENERATE_KOTLIN_CODE_OPTION); @@ -61,7 +59,6 @@ public boolean process(Set annotations, RoundEnvironment int count = processEntities(roundEnv); processOthers(roundEnv); final int loaded = processingContext.complete(); - initModuleInfoBean(); if (roundEnv.processingOver()) { writeModuleInfoBean(); } @@ -98,26 +95,12 @@ private void processOthers(RoundEnvironment roundEnv, TypeElement otherType) { } } - private void initModuleInfoBean() { - try { - if (moduleWriter == null) { - moduleWriter = new SimpleModuleInfoWriter(processingContext); - } - } catch (Throwable e) { - e.printStackTrace(); - processingContext.logError(null, "Failed to initialise EntityClassRegister error:" + e + " stack:" + Arrays.toString(e.getStackTrace())); - } - } - private void writeModuleInfoBean() { try { - if (moduleWriter == null) { - processingContext.logError(null, "EntityClassRegister was not initialised and not written"); - } else { - moduleWriter.write(); - } + new SimpleModuleInfoWriter(processingContext).write(); + } catch (FilerException e) { + processingContext.logWarn(null, "FilerException trying to write EntityClassRegister error: " + e); } catch (Throwable e) { - e.printStackTrace(); processingContext.logError(null, "Failed to write EntityClassRegister error:" + e + " stack:" + Arrays.toString(e.getStackTrace())); } } diff --git a/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/SimpleModuleInfoWriter.java b/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/SimpleModuleInfoWriter.java index b2b698bd11..ced829cc00 100644 --- a/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/SimpleModuleInfoWriter.java +++ b/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/SimpleModuleInfoWriter.java @@ -50,7 +50,6 @@ private void writeServicesFile() { } } catch (IOException e) { - e.printStackTrace(); processingContext.logError(null, "Failed to write services file " + e.getMessage()); } } @@ -70,7 +69,6 @@ private void writeManifestFile() { } } catch (IOException e) { - e.printStackTrace(); processingContext.logError(null, "Failed to write services file " + e.getMessage()); } } diff --git a/querybean-generator/pom.xml b/querybean-generator/pom.xml index 468575971f..65d10a5d8c 100644 --- a/querybean-generator/pom.xml +++ b/querybean-generator/pom.xml @@ -7,9 +7,10 @@ 14.8.1 + 14.8.2-RC2 querybean generator - Querybean generator querybean-generator + Querybean generator diff --git a/querybean-generator/src/main/java/io/ebean/querybean/generator/ProcessingContext.java b/querybean-generator/src/main/java/io/ebean/querybean/generator/ProcessingContext.java index bbc8728039..f149ecbb7c 100644 --- a/querybean-generator/src/main/java/io/ebean/querybean/generator/ProcessingContext.java +++ b/querybean-generator/src/main/java/io/ebean/querybean/generator/ProcessingContext.java @@ -403,6 +403,10 @@ void logError(Element e, String msg, Object... args) { messager.printMessage(Diagnostic.Kind.ERROR, String.format(msg, args), e); } + void logWarn(String msg, Object... args) { + messager.printMessage(Diagnostic.Kind.WARNING, String.format(msg, args)); + } + void logNote(String msg, Object... args) { messager.printMessage(Diagnostic.Kind.NOTE, String.format(msg, args)); } @@ -549,7 +553,6 @@ String loadMetaInfServices() { } catch (FilerException e) { logNote(null, "FilerException reading services file: " + e.getMessage()); } catch (Exception e) { - e.printStackTrace(); logError(null, "Error reading services file: " + e.getMessage()); } return null; diff --git a/querybean-generator/src/main/java/io/ebean/querybean/generator/Processor.java b/querybean-generator/src/main/java/io/ebean/querybean/generator/Processor.java index 9579042a30..8e87ee5691 100644 --- a/querybean-generator/src/main/java/io/ebean/querybean/generator/Processor.java +++ b/querybean-generator/src/main/java/io/ebean/querybean/generator/Processor.java @@ -1,6 +1,7 @@ package io.ebean.querybean.generator; import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.FilerException; import javax.annotation.processing.ProcessingEnvironment; import javax.annotation.processing.RoundEnvironment; import javax.lang.model.SourceVersion; @@ -16,7 +17,6 @@ public class Processor extends AbstractProcessor implements Constants { private ProcessingContext processingContext; - private SimpleModuleInfoWriter moduleWriter; public Processor() { } @@ -49,7 +49,6 @@ public boolean process(Set annotations, RoundEnvironment int count = processEntities(roundEnv); processOthers(roundEnv); final int loaded = processingContext.complete(); - initModuleInfoBean(); if (roundEnv.processingOver()) { writeModuleInfoBean(); } @@ -86,26 +85,12 @@ private void processOthers(RoundEnvironment roundEnv, TypeElement otherType) { } } - private void initModuleInfoBean() { - try { - if (moduleWriter == null) { - moduleWriter = new SimpleModuleInfoWriter(processingContext); - } - } catch (Throwable e) { - e.printStackTrace(); - processingContext.logError(null, "Failed to initialise EntityClassRegister error:" + e + " stack:" + Arrays.toString(e.getStackTrace())); - } - } - private void writeModuleInfoBean() { try { - if (moduleWriter == null) { - processingContext.logError(null, "EntityClassRegister was not initialised and not written"); - } else { - moduleWriter.write(); - } + new SimpleModuleInfoWriter(processingContext).write(); + } catch (FilerException e) { + processingContext.logWarn(null, "FilerException trying to write EntityClassRegister error: " + e); } catch (Throwable e) { - e.printStackTrace(); processingContext.logError(null, "Failed to write EntityClassRegister error:" + e + " stack:" + Arrays.toString(e.getStackTrace())); } } @@ -115,7 +100,6 @@ private void generateQueryBeans(Element element) { SimpleQueryBeanWriter beanWriter = new SimpleQueryBeanWriter((TypeElement) element, processingContext); beanWriter.writeRootBean(); } catch (Throwable e) { - e.printStackTrace(); processingContext.logError(element, "Error generating query beans: " + e); } } From 52729d9802796b69af830e74733360bac74d46f4 Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Thu, 16 Jan 2025 16:40:43 +1300 Subject: [PATCH 2/2] Missing import and adjust warning message --- .../src/main/java/io/ebean/querybean/generator/Processor.java | 3 ++- .../src/main/java/io/ebean/querybean/generator/Processor.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/Processor.java b/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/Processor.java index 3f336019b9..6986138ca3 100644 --- a/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/Processor.java +++ b/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/Processor.java @@ -1,6 +1,7 @@ package io.ebean.querybean.generator; import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.FilerException; import javax.annotation.processing.ProcessingEnvironment; import javax.annotation.processing.RoundEnvironment; import javax.lang.model.SourceVersion; @@ -99,7 +100,7 @@ private void writeModuleInfoBean() { try { new SimpleModuleInfoWriter(processingContext).write(); } catch (FilerException e) { - processingContext.logWarn(null, "FilerException trying to write EntityClassRegister error: " + e); + processingContext.logWarn(null, "FilerException trying to write EntityClassRegister: " + e); } catch (Throwable e) { processingContext.logError(null, "Failed to write EntityClassRegister error:" + e + " stack:" + Arrays.toString(e.getStackTrace())); } diff --git a/querybean-generator/src/main/java/io/ebean/querybean/generator/Processor.java b/querybean-generator/src/main/java/io/ebean/querybean/generator/Processor.java index 8e87ee5691..c32f3123d8 100644 --- a/querybean-generator/src/main/java/io/ebean/querybean/generator/Processor.java +++ b/querybean-generator/src/main/java/io/ebean/querybean/generator/Processor.java @@ -89,7 +89,7 @@ private void writeModuleInfoBean() { try { new SimpleModuleInfoWriter(processingContext).write(); } catch (FilerException e) { - processingContext.logWarn(null, "FilerException trying to write EntityClassRegister error: " + e); + processingContext.logWarn(null, "FilerException trying to write EntityClassRegister: " + e); } catch (Throwable e) { processingContext.logError(null, "Failed to write EntityClassRegister error:" + e + " stack:" + Arrays.toString(e.getStackTrace())); }