Skip to content

Commit

Permalink
GH-801 - Properly guard for presence of jMolecules' @module type.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
odrotbohm committed Sep 12, 2024
1 parent 1015570 commit dc74b41
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,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<? extends Annotation> getModuleAnnotationTypeIfPresent() {

try {
return isPresent()
return isModulePresent()
? (Class<? extends Annotation>) ClassUtils.forName(MODULE, JMoleculesTypes.class.getClassLoader())
: null;
} catch (Exception o_O) {
Expand Down

0 comments on commit dc74b41

Please sign in to comment.