From eebe0e3e21ded6e58f0d36e514d4d32b2379a725 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Wed, 22 May 2024 11:30:14 +0200 Subject: [PATCH] HHH-18019 fix package present detection on ecj Signed-off-by: Gavin King --- .../processor/HibernateProcessor.java | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/HibernateProcessor.java b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/HibernateProcessor.java index a7f26dd2ea..04f14831ef 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/HibernateProcessor.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/HibernateProcessor.java @@ -186,38 +186,39 @@ public class HibernateProcessor extends AbstractProcessor { PackageElement quarkusReactivePanachePackage = context.getProcessingEnvironment().getElementUtils() .getPackageElement( "io.quarkus.hibernate.reactive.panache" ); - if ( quarkusReactivePanachePackage != null - && quarkusOrmPanachePackage != null ) { + + if ( packagePresent(quarkusReactivePanachePackage) + && packagePresent(quarkusOrmPanachePackage) ) { context.logMessage( Diagnostic.Kind.WARNING, "Both Quarkus Hibernate ORM and Hibernate Reactive with Panache detected: this is not supported, so will proceed as if none were there" ); quarkusOrmPanachePackage = quarkusReactivePanachePackage = null; } - - context.setAddInjectAnnotation( jakartaInjectPackage != null ); - context.setAddNonnullAnnotation( jakartaAnnotationPackage != null ); - context.setAddGeneratedAnnotation( jakartaAnnotationPackage != null ); - context.setAddDependentAnnotation( jakartaContextPackage != null ); - context.setAddTransactionScopedAnnotation( jakartaTransactionsPackage != null ); - context.setQuarkusInjection( quarkusOrmPackage != null ); - context.setUsesQuarkusOrm( quarkusOrmPanachePackage != null ); - context.setUsesQuarkusReactive( quarkusReactivePanachePackage != null ); + + context.setAddInjectAnnotation( packagePresent(jakartaInjectPackage) ); + context.setAddNonnullAnnotation( packagePresent(jakartaAnnotationPackage) ); + context.setAddGeneratedAnnotation( packagePresent(jakartaAnnotationPackage) ); + context.setAddDependentAnnotation( packagePresent(jakartaContextPackage) ); + context.setAddTransactionScopedAnnotation( packagePresent(jakartaTransactionsPackage) ); + context.setQuarkusInjection( packagePresent(quarkusOrmPackage) ); + context.setUsesQuarkusOrm( packagePresent(quarkusOrmPanachePackage) ); + context.setUsesQuarkusReactive( packagePresent(quarkusReactivePanachePackage) ); final Map options = environment.getOptions(); - boolean suppressJakartaData = parseBoolean( options.get( SUPPRESS_JAKARTA_DATA_METAMODEL ) ); + final boolean suppressJakartaData = parseBoolean( options.get( SUPPRESS_JAKARTA_DATA_METAMODEL ) ); - context.setGenerateJakartaDataStaticMetamodel( !suppressJakartaData && jakartaDataPackage != null ); + context.setGenerateJakartaDataStaticMetamodel( !suppressJakartaData && packagePresent(jakartaDataPackage) ); - String setting = options.get( ADD_GENERATED_ANNOTATION ); + final String setting = options.get( ADD_GENERATED_ANNOTATION ); if ( setting != null ) { context.setAddGeneratedAnnotation( parseBoolean( setting ) ); } context.setAddGenerationDate( parseBoolean( options.get( ADD_GENERATION_DATE ) ) ); - String suppressedWarnings = options.get( ADD_SUPPRESS_WARNINGS_ANNOTATION ); + final String suppressedWarnings = options.get( ADD_SUPPRESS_WARNINGS_ANNOTATION ); if ( suppressedWarnings != null ) { if ( parseBoolean(suppressedWarnings) ) { // legacy behavior from HHH-12068 @@ -231,6 +232,12 @@ public class HibernateProcessor extends AbstractProcessor { return parseBoolean( options.get( FULLY_ANNOTATION_CONFIGURED_OPTION ) ); } + private static boolean packagePresent(@Nullable PackageElement pack) { + return pack != null + //HHH-18019 ejc always returns a non-null PackageElement + && !pack.getEnclosedElements().isEmpty(); + } + @Override public SourceVersion getSupportedSourceVersion() { return SourceVersion.latestSupported();