Skip to content

Commit

Permalink
Merge pull request #42352 from geoand/#42342
Browse files Browse the repository at this point in the history
Conditionally index test related transaction annotations
  • Loading branch information
geoand authored Aug 7, 2024
2 parents 7e21779 + ca136b6 commit fb0009e
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 fb0009e

Please sign in to comment.