Skip to content

Commit c0b1e97

Browse files
committed
GH-1247 - Consistent order when iterating modules.
We now consistently iterate modules in topological order once established. Before that, modules iteration follows the natural order of the base package names.
1 parent 28b7473 commit c0b1e97

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

spring-modulith-core/src/main/java/org/springframework/modulith/core/ApplicationModules.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,7 @@ public boolean contains(JavaClass type) {
328328

329329
Assert.notNull(type, "Type must not be null!");
330330

331-
return modules.values().stream() //
332-
.anyMatch(module -> module.contains(type));
331+
return modules.values().stream().anyMatch(module -> module.contains(type));
333332
}
334333

335334
/**
@@ -499,7 +498,7 @@ public Violations detectViolations(VerificationOptions options) {
499498
.flatMap(it -> it.getDetails().stream())
500499
.collect(toViolations());
501500

502-
var dependencyViolations = Stream.concat(rootModules.get().stream(), modules.values().stream()) //
501+
var dependencyViolations = allModules() //
503502
.map(it -> it.detectDependencies(this)) //
504503
.reduce(NONE, Violations::and);
505504

@@ -585,10 +584,7 @@ public boolean hasParent(ApplicationModule module) {
585584
*/
586585
@Override
587586
public Iterator<ApplicationModule> iterator() {
588-
589-
return orderedNames != null
590-
? orderedNames.stream().map(this::getRequiredModule).iterator()
591-
: modules.values().iterator();
587+
return orderedModules().iterator();
592588
}
593589

594590
/*
@@ -661,7 +657,13 @@ private ApplicationModule getRequiredModule(ApplicationModuleIdentifier identifi
661657
* @since 1.1
662658
*/
663659
private Stream<ApplicationModule> allModules() {
664-
return Stream.concat(modules.values().stream(), rootModules.get().stream());
660+
return Stream.concat(orderedModules(), rootModules.get().stream());
661+
}
662+
663+
private Stream<ApplicationModule> orderedModules() {
664+
return orderedNames != null
665+
? orderedNames.stream().map(this::getRequiredModule)
666+
: modules.values().stream().sorted();
665667
}
666668

667669
/**

0 commit comments

Comments
 (0)