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:
@@ -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)));
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
@org.springframework.modulith.ApplicationModule(id = "gh-1042-nested", displayName = "Nested")
|
||||
package reproducers.gh1042.module.nested;
|
||||
@@ -1,2 +0,0 @@
|
||||
@org.springframework.modulith.ApplicationModule(displayName = "Nested")
|
||||
package reproducers.gh764.nested;
|
||||
Reference in New Issue
Block a user