GH-40 - Switch to C4 component diagrams by default.
We now render the module component diagrams in C4 style by default. Changed the implementation of ApplicationModuleInformation to fallback to the simple module name by default unless fully-qualified module names are enabled.
This commit is contained in:
@@ -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<ApplicationModule> getDependencies(ApplicationModules modules, DependencyType... type) {
|
||||
|
||||
@@ -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<String> getDisplayName() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
List<String> 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<org.jmolecules.ddd.annotation.Module> 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<String> getDisplayName() {
|
||||
|
||||
Supplier<Optional<String>> 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<String> getAllowedDependencies() {
|
||||
@@ -107,7 +91,7 @@ interface ApplicationModuleInformation {
|
||||
}
|
||||
}
|
||||
|
||||
static class ModulithsModule extends AbstractModuleInformation {
|
||||
static class ModulithsModule implements ApplicationModuleInformation {
|
||||
|
||||
private final Optional<ApplicationModule> 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<String> 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<String> getAllowedDependencies() {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user