Skip to content

Commit 6f24103

Browse files
committed
GH-1043 - Fix module identifier lookup in ApplicationModuleSource.
Before this commit, ApplicationModuleSource inspected all package-info.java contained in given packages, including the sub-packages of those. That caused identifiers explicitly defined in an @ApplicationModule on a package-info.java in nested packages picked up for top-level packages. This is now fixed by only considering the files in the top-level packages.
1 parent 0d9d1fe commit 6f24103

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public static Stream<ApplicationModuleSource> from(JavaPackage rootPackage,
7979
.flatMap(ANNOTATION_IDENTIFIER_SOURCE::withNestedPackages)
8080
.map(it -> {
8181

82-
var id = ANNOTATION_IDENTIFIER_SOURCE.lookupIdentifier(it)
82+
var id = ANNOTATION_IDENTIFIER_SOURCE.lookupIdentifier(it.toSingle())
8383
.orElseGet(() -> ApplicationModuleIdentifier.of(
8484
fullyQualifiedModuleNames ? it.getName() : rootPackage.getTrailingName(it)));
8585

spring-modulith-core/src/test/java/org/springframework/modulith/core/ApplicationModuleSourceUnitTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,18 @@ void detectsSources() {
4242
.extracting(ApplicationModuleIdentifier::toString)
4343
.contains("ninvalid", "customId", "invalid", "ni", "ni.nested.b.first", "secondCustomized", "ni.nested");
4444
}
45+
46+
@Test // GH-1042
47+
void doesNotPickUpIdFromNestedPackages() {
48+
49+
var pkg = TestUtils.getPackage("reproducers.gh1042");
50+
51+
var sources = ApplicationModuleSource.from(pkg, ApplicationModuleDetectionStrategy.directSubPackage(), false);
52+
53+
assertThat(sources)
54+
.extracting(ApplicationModuleSource::getIdentifier)
55+
.extracting(ApplicationModuleIdentifier::toString)
56+
.contains("module", // picked from package name not from annotation in nested package
57+
"gh-1042-nested"); // from annotation in nested package
58+
}
4559
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@org.springframework.modulith.ApplicationModule(id = "gh-1042-nested", displayName = "Nested")
2+
package reproducers.gh1042.module.nested;

spring-modulith-core/src/test/java/reproducers/gh764/nested/package-info.java

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)