HHH-18019 fix package present detection on ecj

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-05-22 11:30:14 +02:00
parent 97e2ca0d3a
commit cd577a813b
1 changed files with 22 additions and 15 deletions

View File

@ -203,8 +203,9 @@ public class HibernateProcessor extends AbstractProcessor {
PackageElement quarkusReactivePanachePackage = PackageElement quarkusReactivePanachePackage =
context.getProcessingEnvironment().getElementUtils() context.getProcessingEnvironment().getElementUtils()
.getPackageElement( "io.quarkus.hibernate.reactive.panache" ); .getPackageElement( "io.quarkus.hibernate.reactive.panache" );
if ( quarkusReactivePanachePackage != null
&& quarkusOrmPanachePackage != null ) { if ( packagePresent(quarkusReactivePanachePackage)
&& packagePresent(quarkusOrmPanachePackage) ) {
context.logMessage( context.logMessage(
Diagnostic.Kind.WARNING, 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" "Both Quarkus Hibernate ORM and Hibernate Reactive with Panache detected: this is not supported, so will proceed as if none were there"
@ -212,29 +213,29 @@ public class HibernateProcessor extends AbstractProcessor {
quarkusOrmPanachePackage = quarkusReactivePanachePackage = null; quarkusOrmPanachePackage = quarkusReactivePanachePackage = null;
} }
context.setAddInjectAnnotation( jakartaInjectPackage != null ); context.setAddInjectAnnotation( packagePresent(jakartaInjectPackage) );
context.setAddNonnullAnnotation( jakartaAnnotationPackage != null ); context.setAddNonnullAnnotation( packagePresent(jakartaAnnotationPackage) );
context.setAddGeneratedAnnotation( jakartaAnnotationPackage != null ); context.setAddGeneratedAnnotation( packagePresent(jakartaAnnotationPackage) );
context.setAddDependentAnnotation( jakartaContextPackage != null ); context.setAddDependentAnnotation( packagePresent(jakartaContextPackage) );
context.setAddTransactionScopedAnnotation( jakartaTransactionsPackage != null ); context.setAddTransactionScopedAnnotation( packagePresent(jakartaTransactionsPackage) );
context.setQuarkusInjection( quarkusOrmPackage != null ); context.setQuarkusInjection( packagePresent(quarkusOrmPackage) );
context.setUsesQuarkusOrm( quarkusOrmPanachePackage != null ); context.setUsesQuarkusOrm( packagePresent(quarkusOrmPanachePackage) );
context.setUsesQuarkusReactive( quarkusReactivePanachePackage != null ); context.setUsesQuarkusReactive( packagePresent(quarkusReactivePanachePackage) );
final Map<String, String> options = environment.getOptions(); final Map<String, String> 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 ) { if ( setting != null ) {
context.setAddGeneratedAnnotation( parseBoolean( setting ) ); context.setAddGeneratedAnnotation( parseBoolean( setting ) );
} }
context.setAddGenerationDate( parseBoolean( options.get( ADD_GENERATION_DATE ) ) ); 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 ( suppressedWarnings != null ) {
if ( parseBoolean(suppressedWarnings) ) { if ( parseBoolean(suppressedWarnings) ) {
// legacy behavior from HHH-12068 // legacy behavior from HHH-12068
@ -251,6 +252,12 @@ public class HibernateProcessor extends AbstractProcessor {
return parseBoolean( options.get( FULLY_ANNOTATION_CONFIGURED_OPTION ) ); 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 @Override
public SourceVersion getSupportedSourceVersion() { public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latestSupported(); return SourceVersion.latestSupported();