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:
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.acme.myproject.open.internal;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.acme.myproject.openclient.ClientToInternal;
|
||||
|
||||
/**
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
@Component
|
||||
public class Internal {
|
||||
|
||||
ClientToInternal clientToInternal;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
@ApplicationModule(type = Type.OPEN)
|
||||
package com.acme.myproject.open;
|
||||
|
||||
import org.springframework.modulith.ApplicationModule;
|
||||
import org.springframework.modulith.ApplicationModule.Type;
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.acme.myproject.openclient;
|
||||
|
||||
import com.acme.myproject.open.internal.Internal;
|
||||
|
||||
/**
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
public class ClientToInternal {
|
||||
|
||||
Internal internal;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.acme.myproject.opendisallowedclient;
|
||||
|
||||
import com.acme.myproject.open.internal.Internal;
|
||||
|
||||
/**
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
public class DisallowedClientOfInternal {
|
||||
Internal internal;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
@org.springframework.modulith.ApplicationModule(allowedDependencies = "moduleA")
|
||||
package com.acme.myproject.opendisallowedclient;
|
||||
@@ -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 -> {
|
||||
|
||||
@@ -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 -> {
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
spring.main.banner-mode=off
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
<logger name="org.springframework.modulith" level="error" />
|
||||
|
||||
<root level="error">
|
||||
<root level="off">
|
||||
<appender-ref ref="console" />
|
||||
</root>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user