GH-284 - Support for open application modules.

Application modules can now be declared as open, which causes internal components being exposed for access by other modules.
This commit is contained in:
Oliver Drotbohm
2024-02-29 12:47:10 +01:00
parent b73b4ca70a
commit f3c111f769
19 changed files with 331 additions and 22 deletions

View File

@@ -61,7 +61,7 @@ class ModulithTest {
assertThatExceptionOfType(Violations.class).isThrownBy(() -> {
ApplicationModules
.of(Application.class, DEFAULT_EXCLUSIONS.or(Filters.withoutModule("invalid")))
.of(Application.class, DEFAULT_EXCLUSIONS.or(Filters.withoutModules("invalid", "opendisallowedclient")))
.verify();
}).satisfies(it -> {

View File

@@ -211,6 +211,29 @@ class ApplicationModulesIntegrationTest {
});
}
@Test // GH-284
void detectsOpenModule() {
assertThat(modules.getModuleByName("open")).hasValueSatisfying(it -> {
assertThat(it.isOpen()).isTrue();
});
var detectViolations = modules.detectViolations().getMessages();
assertThat(detectViolations)
.isNotEmpty()
// No invalid references to internals from unrestricted module
.noneMatch(it -> it.matches("Module 'openclient' depends on non-exposed type .* within module 'open'"))
// Invalid reference to internals from restricted module
.anyMatch(it -> it.contains("Module 'opendisallowedclient' depends on module 'open'"))
// No cycle detection
.anyMatch(it -> it.contains("Cycle detected: Slice cycleA"))
.noneMatch(it -> it.contains("Cycle detected: Slice open"));
}
private static void verifyNamedInterfaces(NamedInterfaces interfaces, String name, Class<?>... types) {
Stream.of(types).forEach(type -> {