Skip to content

Commit

Permalink
Conditionally index test related transaction annotations
Browse files Browse the repository at this point in the history
Fixes: #42342
  • Loading branch information
geoand committed Aug 7, 2024
1 parent b3e6085 commit ca136b6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ public void startRecoveryService(NarayanaJtaRecorder recorder,
@BuildStep(onlyIf = IsTest.class)
void testTx(BuildProducer<GeneratedBeanBuildItem> generatedBeanBuildItemBuildProducer,
BuildProducer<AdditionalBeanBuildItem> 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
Expand All @@ -219,6 +224,15 @@ void testTx(BuildProducer<GeneratedBeanBuildItem> 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public final class PanacheJpaCommonResourceProcessor {
@BuildStep(onlyIf = IsTest.class)
void testTx(BuildProducer<GeneratedBeanBuildItem> generatedBeanBuildItemBuildProducer,
BuildProducer<AdditionalBeanBuildItem> 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
Expand All @@ -76,6 +81,15 @@ void testTx(BuildProducer<GeneratedBeanBuildItem> 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<AdditionalBeanBuildItem> additionalBeans) {
AdditionalBeanBuildItem.Builder builder = AdditionalBeanBuildItem.builder();
Expand Down

0 comments on commit ca136b6

Please sign in to comment.