From 6e123272dc67490d63ee90457f33a6a994bc08ce Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Thu, 12 Sep 2024 16:57:44 +0200 Subject: [PATCH] GH-816 - Properly guard for presence of jMolecules' @Module type. As @Module is absent from the Kotlin flavor of jMolecules, code that refers to that is now guarded with a more specific check for that type in particular. --- .../core/ApplicationModuleInformation.java | 2 +- .../org/springframework/modulith/core/Types.java | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/spring-modulith-core/src/main/java/org/springframework/modulith/core/ApplicationModuleInformation.java b/spring-modulith-core/src/main/java/org/springframework/modulith/core/ApplicationModuleInformation.java index 1a19ab2f..56dc066e 100644 --- a/spring-modulith-core/src/main/java/org/springframework/modulith/core/ApplicationModuleInformation.java +++ b/spring-modulith-core/src/main/java/org/springframework/modulith/core/ApplicationModuleInformation.java @@ -50,7 +50,7 @@ public static ApplicationModuleInformation of(JavaPackage javaPackage) { var lookup = AnnotationLookup.of(javaPackage.toSingle(), __ -> true); - return JMoleculesTypes.isPresent() && JMoleculesModule.supports(lookup) + return JMoleculesTypes.isModulePresent() && JMoleculesModule.supports(lookup) ? new JMoleculesModule(lookup) : new SpringModulithModule(lookup); } diff --git a/spring-modulith-core/src/main/java/org/springframework/modulith/core/Types.java b/spring-modulith-core/src/main/java/org/springframework/modulith/core/Types.java index 0a7d5b80..661a1418 100644 --- a/spring-modulith-core/src/main/java/org/springframework/modulith/core/Types.java +++ b/spring-modulith-core/src/main/java/org/springframework/modulith/core/Types.java @@ -52,21 +52,35 @@ static class JMoleculesTypes { private static final String MODULE = ANNOTATION_PACKAGE + ".Module"; private static final boolean PRESENT = ClassUtils.isPresent(AT_ENTITY, JMoleculesTypes.class.getClassLoader()); + private static final boolean MODULE_PRESENT = ClassUtils.isPresent(MODULE, JMoleculesTypes.class.getClassLoader()); static final String AT_DOMAIN_EVENT_HANDLER = BASE_PACKAGE + ".event.annotation.DomainEventHandler"; static final String AT_DOMAIN_EVENT = BASE_PACKAGE + ".event.annotation.DomainEvent"; static final String DOMAIN_EVENT = BASE_PACKAGE + ".event.types.DomainEvent"; + /** + * Returns whether jMolecules is generally present. + * + * @see #isModulePresent() + */ public static boolean isPresent() { return PRESENT; } + /** + * Returns whether the jMolecules {@link Module} type is present. We need to guard for this explicitly as the Kotlin + * variant of jMolecules DDD does not ship that type. + */ + public static boolean isModulePresent() { + return MODULE_PRESENT; + } + @Nullable @SuppressWarnings("unchecked") public static Class getModuleAnnotationTypeIfPresent() { try { - return isPresent() + return isModulePresent() ? (Class) ClassUtils.forName(MODULE, JMoleculesTypes.class.getClassLoader()) : null; } catch (Exception o_O) {