diff --git a/spring-modulith-core/src/main/java/org/springframework/modulith/model/ApplicationModule.java b/spring-modulith-core/src/main/java/org/springframework/modulith/model/ApplicationModule.java index 7be2af26..98e4b5ff 100644 --- a/spring-modulith-core/src/main/java/org/springframework/modulith/model/ApplicationModule.java +++ b/spring-modulith-core/src/main/java/org/springframework/modulith/model/ApplicationModule.java @@ -60,6 +60,8 @@ import com.tngtech.archunit.thirdparty.com.google.common.base.Supplier; import com.tngtech.archunit.thirdparty.com.google.common.base.Suppliers; /** + * An application module. + * * @author Oliver Drotbohm */ @EqualsAndHashCode(doNotUseGetters = true) @@ -86,12 +88,24 @@ public class ApplicationModule { this.publishedEvents = Suppliers.memoize(() -> findPublishedEvents()); } + /** + * Returns the logical name of the module. + * + * @return will never be {@literal null} or empty. + */ public String getName() { return useFullyQualifiedModuleNames ? basePackage.getName() : basePackage.getLocalName(); } + /** + * Returns the name of the {@link ApplicationModule} for display purposes. + * + * @return will never be {@literal null} or empty. + */ public String getDisplayName() { - return information.getDisplayName(); + + return information.getDisplayName() + .orElseGet(() -> getName()); } public List getDependencies(ApplicationModules modules, DependencyType... type) { diff --git a/spring-modulith-core/src/main/java/org/springframework/modulith/model/ApplicationModuleInformation.java b/spring-modulith-core/src/main/java/org/springframework/modulith/model/ApplicationModuleInformation.java index 8d225b02..3395b47f 100644 --- a/spring-modulith-core/src/main/java/org/springframework/modulith/model/ApplicationModuleInformation.java +++ b/spring-modulith-core/src/main/java/org/springframework/modulith/model/ApplicationModuleInformation.java @@ -15,13 +15,11 @@ */ package org.springframework.modulith.model; -import lombok.AccessLevel; -import lombok.RequiredArgsConstructor; - import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; +import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -39,7 +37,8 @@ interface ApplicationModuleInformation { public static ApplicationModuleInformation of(JavaPackage javaPackage) { - if (ClassUtils.isPresent("org.jmolecules.ddd.annotation.Module", ApplicationModuleInformation.class.getClassLoader()) + if (ClassUtils.isPresent("org.jmolecules.ddd.annotation.Module", + ApplicationModuleInformation.class.getClassLoader()) && MoleculesModule.supports(javaPackage)) { return new MoleculesModule(javaPackage); } @@ -47,26 +46,13 @@ interface ApplicationModuleInformation { return new ModulithsModule(javaPackage); } - String getDisplayName(); + default Optional getDisplayName() { + return Optional.empty(); + } List getAllowedDependencies(); - @RequiredArgsConstructor(access = AccessLevel.PROTECTED) - static abstract class AbstractModuleInformation implements ApplicationModuleInformation { - - private final JavaPackage javaPackage; - - /* - * (non-Javadoc) - * @see org.springframework.modulith.model.ModuleInformation#getName() - */ - @Override - public String getDisplayName() { - return javaPackage.getName(); - } - } - - static class MoleculesModule extends AbstractModuleInformation { + static class MoleculesModule implements ApplicationModuleInformation { private final Optional annotation; @@ -75,31 +61,29 @@ interface ApplicationModuleInformation { } public MoleculesModule(JavaPackage javaPackage) { - - super(javaPackage); - this.annotation = javaPackage.getAnnotation(org.jmolecules.ddd.annotation.Module.class); } /* * (non-Javadoc) - * @see org.springframework.modulith.model.ModuleInformation#getName() + * @see org.springframework.modulith.model.ApplicationModuleInformation#getDisplayName() */ @Override - public String getDisplayName() { + public Optional getDisplayName() { + + Supplier> fallback = () -> annotation // + .map(org.jmolecules.ddd.annotation.Module::value) // + .filter(StringUtils::hasText); return annotation // .map(org.jmolecules.ddd.annotation.Module::name) // .filter(StringUtils::hasText) - .orElseGet(() -> annotation // - .map(org.jmolecules.ddd.annotation.Module::value) // - .filter(StringUtils::hasText) // - .orElseGet(super::getDisplayName)); + .or(fallback); } /* * (non-Javadoc) - * @see org.springframework.modulith.model.ModuleInformation#getAllowedDependencies() + * @see org.springframework.modulith.model.ApplicationModuleInformation#getAllowedDependencies() */ @Override public List getAllowedDependencies() { @@ -107,7 +91,7 @@ interface ApplicationModuleInformation { } } - static class ModulithsModule extends AbstractModuleInformation { + static class ModulithsModule implements ApplicationModuleInformation { private final Optional annotation; @@ -116,28 +100,24 @@ interface ApplicationModuleInformation { } public ModulithsModule(JavaPackage javaPackage) { - - super(javaPackage); - this.annotation = javaPackage.getAnnotation(ApplicationModule.class); } /* * (non-Javadoc) - * @see org.springframework.modulith.model.ModuleInformation.AbstractModuleInformation#getName() + * @see org.springframework.modulith.model.ApplicationModuleInformation#getDisplayName() */ @Override - public String getDisplayName() { + public Optional getDisplayName() { return annotation // .map(ApplicationModule::displayName) // - .filter(StringUtils::hasText) // - .orElseGet(super::getDisplayName); + .filter(StringUtils::hasText); } /* * (non-Javadoc) - * @see org.springframework.modulith.model.ModuleInformation#getAllowedDependencies() + * @see org.springframework.modulith.model.ApplicationModuleInformation#getAllowedDependencies() */ @Override public List getAllowedDependencies() { diff --git a/spring-modulith-docs/src/main/java/org/springframework/modulith/docs/Documenter.java b/spring-modulith-docs/src/main/java/org/springframework/modulith/docs/Documenter.java index 4a00b7e2..47c6e8e2 100644 --- a/spring-modulith-docs/src/main/java/org/springframework/modulith/docs/Documenter.java +++ b/spring-modulith-docs/src/main/java/org/springframework/modulith/docs/Documenter.java @@ -365,8 +365,6 @@ public class Documenter { .filter(options.getComponentFilter()) // .forEach(view::add); - // view.getViewSet().getConfiguration().getStyles().findElementStyle(element).getBackground() - // Remove filtered dependency types DependencyType.allBut(options.getDependencyTypes()) // .map(Object::toString) // @@ -605,7 +603,7 @@ public class Documenter { */ public static Options defaults() { return new Options(ALL_TYPES, DependencyDepth.IMMEDIATE, it -> false, it -> true, it -> false, null, - __ -> Optional.empty(), it -> it.getDisplayName(), DiagramStyle.UML, ElementsWithoutRelationships.HIDDEN); + __ -> Optional.empty(), it -> it.getDisplayName(), DiagramStyle.C4, ElementsWithoutRelationships.HIDDEN); } /**