Skip to content

Commit 013bd8b

Browse files
committed
GH-1042 - 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 fe2c0c1 commit 013bd8b

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public static Stream<ApplicationModuleSource> from(JavaPackage rootPackage,
8585
.flatMap(ANNOTATION_IDENTIFIER_SOURCE::withNestedPackages)
8686
.map(it -> {
8787

88-
var id = ANNOTATION_IDENTIFIER_SOURCE.lookupIdentifier(it)
88+
var id = ANNOTATION_IDENTIFIER_SOURCE.lookupIdentifier(it.toSingle())
8989
.orElseGet(() -> ApplicationModuleIdentifier.of(
9090
fullyQualifiedModuleNames ? it.getName() : rootPackage.getTrailingName(it)));
9191

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

+14
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
}
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;

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

-2
This file was deleted.

0 commit comments

Comments
 (0)