Skip to content

Commit 22993f4

Browse files
committed
GH-74 - Bean references in Application Module Canvas now get de-duplicated.
1 parent 9d95d87 commit 22993f4

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

spring-modulith-core/src/main/java/org/springframework/modulith/model/ApplicationModuleDependencies.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
import lombok.RequiredArgsConstructor;
1919

20+
import java.util.HashSet;
2021
import java.util.List;
22+
import java.util.function.Function;
2123
import java.util.stream.Stream;
2224

2325
import org.springframework.util.Assert;
@@ -73,6 +75,23 @@ public Stream<ApplicationModuleDependency> stream() {
7375
return dependencies.stream();
7476
}
7577

78+
/**
79+
* Return all {@link ApplicationModuleDependency} instances unique by the value extracted using the given
80+
* {@link Function}.
81+
*
82+
* @param extractor will never be {@literal null}.
83+
* @return will never be {@literal null}.
84+
*/
85+
public Stream<ApplicationModuleDependency> uniqueStream(Function<ApplicationModuleDependency, Object> extractor) {
86+
87+
Assert.notNull(extractor, "Extractor function must not be null!");
88+
89+
var seenTargets = new HashSet<>();
90+
91+
return dependencies.stream()
92+
.filter(it -> seenTargets.add(extractor.apply(it)));
93+
}
94+
7695
public ApplicationModuleDependencies withType(DependencyType type) {
7796

7897
var filtered = dependencies.stream()

spring-modulith-docs/src/main/java/org/springframework/modulith/docs/Asciidoctor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.springframework.modulith.docs.Documenter.CanvasOptions;
3030
import org.springframework.modulith.docs.Documenter.CanvasOptions.Groupings;
3131
import org.springframework.modulith.model.ApplicationModule;
32+
import org.springframework.modulith.model.ApplicationModuleDependency;
3233
import org.springframework.modulith.model.ApplicationModules;
3334
import org.springframework.modulith.model.ArchitecturallyEvidentType;
3435
import org.springframework.modulith.model.DependencyType;
@@ -363,7 +364,8 @@ public String toAsciidoctor(String source) {
363364
*/
364365
public String renderBeanReferences(ApplicationModule module) {
365366

366-
var bullets = module.getDependencies(modules, DependencyType.USES_COMPONENT).stream()
367+
var bullets = module.getDependencies(modules, DependencyType.USES_COMPONENT)
368+
.uniqueStream(ApplicationModuleDependency::getTargetType)
367369
.map(it -> "%s (in %s)".formatted(toInlineCode(it.getTargetType()), it.getTargetModule().getDisplayName()))
368370
.map(this::toBulletPoint)
369371
.collect(Collectors.joining("\n"));

0 commit comments

Comments
 (0)