GH-74 - Bean references in Application Module Canvas now get de-duplicated.
This commit is contained in:
@@ -17,7 +17,9 @@ package org.springframework.modulith.model;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
@@ -73,6 +75,23 @@ public class ApplicationModuleDependencies {
|
||||
return dependencies.stream();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all {@link ApplicationModuleDependency} instances unique by the value extracted using the given
|
||||
* {@link Function}.
|
||||
*
|
||||
* @param extractor will never be {@literal null}.
|
||||
* @return will never be {@literal null}.
|
||||
*/
|
||||
public Stream<ApplicationModuleDependency> uniqueStream(Function<ApplicationModuleDependency, Object> extractor) {
|
||||
|
||||
Assert.notNull(extractor, "Extractor function must not be null!");
|
||||
|
||||
var seenTargets = new HashSet<>();
|
||||
|
||||
return dependencies.stream()
|
||||
.filter(it -> seenTargets.add(extractor.apply(it)));
|
||||
}
|
||||
|
||||
public ApplicationModuleDependencies withType(DependencyType type) {
|
||||
|
||||
var filtered = dependencies.stream()
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.modulith.docs.ConfigurationProperties.ModuleProperty;
|
||||
import org.springframework.modulith.docs.Documenter.CanvasOptions;
|
||||
import org.springframework.modulith.docs.Documenter.CanvasOptions.Groupings;
|
||||
import org.springframework.modulith.model.ApplicationModule;
|
||||
import org.springframework.modulith.model.ApplicationModuleDependency;
|
||||
import org.springframework.modulith.model.ApplicationModules;
|
||||
import org.springframework.modulith.model.ArchitecturallyEvidentType;
|
||||
import org.springframework.modulith.model.DependencyType;
|
||||
@@ -363,7 +364,8 @@ class Asciidoctor {
|
||||
*/
|
||||
public String renderBeanReferences(ApplicationModule module) {
|
||||
|
||||
var bullets = module.getDependencies(modules, DependencyType.USES_COMPONENT).stream()
|
||||
var bullets = module.getDependencies(modules, DependencyType.USES_COMPONENT)
|
||||
.uniqueStream(ApplicationModuleDependency::getTargetType)
|
||||
.map(it -> "%s (in %s)".formatted(toInlineCode(it.getTargetType()), it.getTargetModule().getDisplayName()))
|
||||
.map(this::toBulletPoint)
|
||||
.collect(Collectors.joining("\n"));
|
||||
|
||||
Reference in New Issue
Block a user