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.
This commit is contained in:
Oliver Drotbohm
2025-01-28 23:47:52 +01:00
parent 0d9d1fe5c9
commit 6f24103fe8
4 changed files with 17 additions and 3 deletions

View File

@@ -79,7 +79,7 @@ public class ApplicationModuleSource {
.flatMap(ANNOTATION_IDENTIFIER_SOURCE::withNestedPackages)
.map(it -> {
var id = ANNOTATION_IDENTIFIER_SOURCE.lookupIdentifier(it)
var id = ANNOTATION_IDENTIFIER_SOURCE.lookupIdentifier(it.toSingle())
.orElseGet(() -> ApplicationModuleIdentifier.of(
fullyQualifiedModuleNames ? it.getName() : rootPackage.getTrailingName(it)));

View File

@@ -42,4 +42,18 @@ class ApplicationModuleSourceUnitTests {
.extracting(ApplicationModuleIdentifier::toString)
.contains("ninvalid", "customId", "invalid", "ni", "ni.nested.b.first", "secondCustomized", "ni.nested");
}
@Test // GH-1042
void doesNotPickUpIdFromNestedPackages() {
var pkg = TestUtils.getPackage("reproducers.gh1042");
var sources = ApplicationModuleSource.from(pkg, ApplicationModuleDetectionStrategy.directSubPackage(), false);
assertThat(sources)
.extracting(ApplicationModuleSource::getIdentifier)
.extracting(ApplicationModuleIdentifier::toString)
.contains("module", // picked from package name not from annotation in nested package
"gh-1042-nested"); // from annotation in nested package
}
}

View File

@@ -0,0 +1,2 @@
@org.springframework.modulith.ApplicationModule(id = "gh-1042-nested", displayName = "Nested")
package reproducers.gh1042.module.nested;

View File

@@ -1,2 +0,0 @@
@org.springframework.modulith.ApplicationModule(displayName = "Nested")
package reproducers.gh764.nested;