GH-1139 - Detect @NamedInterface on composed annotations.

This commit is contained in:
Oliver Drotbohm
2025-04-04 17:05:30 +02:00
parent 2fcde209b3
commit fd3542b3b0
5 changed files with 68 additions and 1 deletions

View File

@@ -291,7 +291,7 @@ public class NamedInterfaces implements Iterable<NamedInterface> {
.filter(it -> !JavaPackage.isPackageInfoType(it)) //
.forEach(it -> {
if (!it.isAnnotatedWith(org.springframework.modulith.NamedInterface.class)) {
if (!it.isMetaAnnotatedWith(org.springframework.modulith.NamedInterface.class)) {
return;
}

View File

@@ -0,0 +1,22 @@
/*
* Copyright 2025 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 example.metani;
/**
* @author Oliver Drotbohm
*/
@ModuleApi
public class Exposed {}

View File

@@ -0,0 +1,32 @@
/*
* Copyright 2025 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 example.metani;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import org.springframework.modulith.NamedInterface;
/**
* @author Oliver Drotbohm
*/
@Retention(RUNTIME)
@Target({ TYPE })
@NamedInterface("api")
public @interface ModuleApi {}

View File

@@ -37,6 +37,7 @@ class ApplicationModulesUnitTests {
.containsExactlyInAnyOrder(
"invalid",
"customId",
"metani",
"ni",
"ni.nested",
"ni.nested.b.first",

View File

@@ -142,6 +142,18 @@ class NamedInterfacesUnitTests {
assertThat(interfaces).hasSizeGreaterThan(1);
}
@Test // GH-1139
void discoveredNamedInterfaceOnComposedAnnotation() {
var pkg = TestUtils.getPackage(example.metani.Exposed.class);
var result = NamedInterfaces.discoverNamedInterfaces(pkg);
assertThat(result).hasSize(2)
.extracting(NamedInterface::getName)
.containsExactlyInAnyOrder(NamedInterface.UNNAMED_NAME, "api");
}
private static void assertInterfaceContains(NamedInterfaces interfaces, String name, Class<?>... types) {
var classNames = Arrays.stream(types).map(Class::getName).toArray(String[]::new);