From ca136b66305e4690136a40ed5e5655d0cb7ec572 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Wed, 7 Aug 2024 09:12:19 +0300 Subject: [PATCH] Conditionally index test related transaction annotations Fixes: #42342 --- .../jta/deployment/NarayanaJtaProcessor.java | 14 ++++++++++++++ .../PanacheJpaCommonResourceProcessor.java | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/extensions/narayana-jta/deployment/src/main/java/io/quarkus/narayana/jta/deployment/NarayanaJtaProcessor.java b/extensions/narayana-jta/deployment/src/main/java/io/quarkus/narayana/jta/deployment/NarayanaJtaProcessor.java index c661f5ea866b6..214fa3bf3ec0b 100644 --- a/extensions/narayana-jta/deployment/src/main/java/io/quarkus/narayana/jta/deployment/NarayanaJtaProcessor.java +++ b/extensions/narayana-jta/deployment/src/main/java/io/quarkus/narayana/jta/deployment/NarayanaJtaProcessor.java @@ -204,6 +204,11 @@ public void startRecoveryService(NarayanaJtaRecorder recorder, @BuildStep(onlyIf = IsTest.class) void testTx(BuildProducer generatedBeanBuildItemBuildProducer, BuildProducer additionalBeans) { + + if (!testTransactionOnClassPath()) { + return; + } + //generate the annotated interceptor with gizmo //all the logic is in the parent, but we don't have access to the //binding annotation here @@ -219,6 +224,15 @@ void testTx(BuildProducer generatedBeanBuildItemBuildPro .addBeanClass(TEST_TRANSACTION).build()); } + private static boolean testTransactionOnClassPath() { + try { + Class.forName(TEST_TRANSACTION, false, Thread.currentThread().getContextClassLoader()); + return true; + } catch (ClassNotFoundException ignored) { + return false; + } + } + @BuildStep public ContextConfiguratorBuildItem transactionContext(ContextRegistrationPhaseBuildItem contextRegistrationPhase) { return new ContextConfiguratorBuildItem(contextRegistrationPhase.getContext() diff --git a/extensions/panache/hibernate-reactive-panache-common/deployment/src/main/java/io/quarkus/hibernate/reactive/panache/common/deployment/PanacheJpaCommonResourceProcessor.java b/extensions/panache/hibernate-reactive-panache-common/deployment/src/main/java/io/quarkus/hibernate/reactive/panache/common/deployment/PanacheJpaCommonResourceProcessor.java index 307a82c770060..8190c8dfa5989 100644 --- a/extensions/panache/hibernate-reactive-panache-common/deployment/src/main/java/io/quarkus/hibernate/reactive/panache/common/deployment/PanacheJpaCommonResourceProcessor.java +++ b/extensions/panache/hibernate-reactive-panache-common/deployment/src/main/java/io/quarkus/hibernate/reactive/panache/common/deployment/PanacheJpaCommonResourceProcessor.java @@ -61,6 +61,11 @@ public final class PanacheJpaCommonResourceProcessor { @BuildStep(onlyIf = IsTest.class) void testTx(BuildProducer generatedBeanBuildItemBuildProducer, BuildProducer additionalBeans) { + + if (!testReactiveTransactionOnClassPath()) { + return; + } + //generate the annotated interceptor with gizmo //all the logic is in the parent, but we don't have access to the //binding annotation here @@ -76,6 +81,15 @@ void testTx(BuildProducer generatedBeanBuildItemBuildPro .addBeanClass(TEST_REACTIVE_TRANSACTION).build()); } + private static boolean testReactiveTransactionOnClassPath() { + try { + Class.forName(TEST_REACTIVE_TRANSACTION, false, Thread.currentThread().getContextClassLoader()); + return true; + } catch (ClassNotFoundException ignored) { + return false; + } + } + @BuildStep void registerInterceptors(BuildProducer additionalBeans) { AdditionalBeanBuildItem.Builder builder = AdditionalBeanBuildItem.builder();