From 507d32de0dc7b20f9c9d0d282106ae1544417f2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Wed, 20 Jul 2022 14:22:17 +0200 Subject: [PATCH] Don't even try to resolve @SearchExtension for runtime configuration when Hibernate Search is disabled --- ...HibernateSearchElasticsearchProcessor.java | 2 +- .../HibernateSearchElasticsearchRecorder.java | 27 ++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/extensions/hibernate-search-orm-elasticsearch/deployment/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/deployment/HibernateSearchElasticsearchProcessor.java b/extensions/hibernate-search-orm-elasticsearch/deployment/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/deployment/HibernateSearchElasticsearchProcessor.java index 53cbfdb401b89..d6a830014ca79 100644 --- a/extensions/hibernate-search-orm-elasticsearch/deployment/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/deployment/HibernateSearchElasticsearchProcessor.java +++ b/extensions/hibernate-search-orm-elasticsearch/deployment/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/deployment/HibernateSearchElasticsearchProcessor.java @@ -160,7 +160,7 @@ private void buildForPersistenceUnit(HibernateSearchElasticsearchRecorder record // we need a runtime listener even when Hibernate Search is disabled, // just to let Hibernate Search boot up until the point where it checks whether it's enabled or not runtimeIntegrations.produce(new HibernateOrmIntegrationRuntimeConfiguredBuildItem(HIBERNATE_SEARCH_ELASTICSEARCH, - persistenceUnitName).setInitListener(recorder.createDisabledRuntimeInitListener(persistenceUnitName))); + persistenceUnitName).setInitListener(recorder.createDisabledRuntimeInitListener())); return; } diff --git a/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchRecorder.java b/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchRecorder.java index 23c8f0a1956f8..e5fa8196bb49b 100644 --- a/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchRecorder.java +++ b/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchRecorder.java @@ -75,9 +75,8 @@ public HibernateOrmIntegrationRuntimeInitListener createRuntimeInitListener( backendAndIndexNamesForSearchExtensions, integrationRuntimeInitListeners); } - public HibernateOrmIntegrationRuntimeInitListener createDisabledRuntimeInitListener(String persistenceUnitName) { - return new HibernateSearchIntegrationRuntimeInitListener(persistenceUnitName, null, Collections.emptyMap(), - Collections.emptyList()); + public HibernateOrmIntegrationRuntimeInitListener createDisabledRuntimeInitListener() { + return new HibernateSearchIntegrationRuntimeInitDisabledListener(); } public Supplier searchMappingSupplier(HibernateSearchElasticsearchRuntimeConfig runtimeConfig, @@ -262,6 +261,28 @@ private void contributeBackendIndexBuildTimeProperties(BiConsumer propertyCollector) { + // Not strictly necessary since this should be set during static init, + // but let's be on the safe side. + propertyCollector.accept(HibernateOrmMapperSettings.ENABLED, false); + } + + @Override + public List> contributeServiceInitiators() { + return List.of( + // The service must be initiated even if Hibernate Search is disabled, + // because it's also responsible for determining that Hibernate Search is disabled. + new HibernateSearchPreIntegrationService.Initiator()); + } + } + private static final class HibernateSearchIntegrationRuntimeInitListener implements HibernateOrmIntegrationRuntimeInitListener {