Skip to content

Commit 79bd413

Browse files
committed
GH-766 - Prevent ApplicationModuleInformation from picking up info from nested packages.
1 parent 8ea71a6 commit 79bd413

File tree

5 files changed

+70
-9
lines changed

5 files changed

+70
-9
lines changed

spring-modulith-core/src/main/java/org/springframework/modulith/core/ApplicationModuleInformation.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121
import java.util.function.Supplier;
2222
import java.util.stream.Stream;
2323

24-
import org.jmolecules.ddd.annotation.Module;
2524
import org.springframework.modulith.ApplicationModule;
25+
import org.springframework.modulith.core.Types.JMoleculesTypes;
2626
import org.springframework.util.Assert;
27-
import org.springframework.util.ClassUtils;
2827
import org.springframework.util.StringUtils;
2928

3029
/**
@@ -43,13 +42,11 @@ interface ApplicationModuleInformation {
4342
*/
4443
public static ApplicationModuleInformation of(JavaPackage javaPackage) {
4544

46-
if (ClassUtils.isPresent("org.jmolecules.ddd.annotation.Module",
47-
ApplicationModuleInformation.class.getClassLoader())
48-
&& JMoleculesModule.supports(javaPackage)) {
49-
return new JMoleculesModule(javaPackage);
50-
}
45+
var rootPackage = javaPackage.toSingle();
5146

52-
return new SpringModulithModule(javaPackage);
47+
return JMoleculesTypes.isPresent() && JMoleculesModule.supports(rootPackage)
48+
? new JMoleculesModule(rootPackage)
49+
: new SpringModulithModule(rootPackage);
5350
}
5451

5552
/**

spring-modulith-core/src/main/java/org/springframework/modulith/core/Types.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@ static class JMoleculesTypes {
5050
private static final String ARCHUNIT_RULES = BASE_PACKAGE + ".archunit.JMoleculesDddRules";
5151
private static final String MODULE = ANNOTATION_PACKAGE + ".Module";
5252

53+
private static final boolean PRESENT = ClassUtils.isPresent(AT_ENTITY, JMoleculesTypes.class.getClassLoader());
54+
5355
static final String AT_DOMAIN_EVENT_HANDLER = BASE_PACKAGE + ".event.annotation.DomainEventHandler";
5456
static final String AT_DOMAIN_EVENT = BASE_PACKAGE + ".event.annotation.DomainEvent";
5557
static final String DOMAIN_EVENT = BASE_PACKAGE + ".event.types.DomainEvent";
5658

5759
public static boolean isPresent() {
58-
return ClassUtils.isPresent(AT_ENTITY, JMoleculesTypes.class.getClassLoader());
60+
return PRESENT;
5961
}
6062

6163
@Nullable
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.modulith.core;
17+
18+
import static org.assertj.core.api.Assertions.*;
19+
20+
import reproducers.gh764.Entry;
21+
22+
import org.junit.jupiter.api.Test;
23+
24+
/**
25+
* Unit tests for {@link ApplicationModuleInformation}.
26+
*
27+
* @author Oliver Drotbohm
28+
*/
29+
class ApplicationModuleInformationUnitTests {
30+
31+
@Test // GH-764
32+
void doesNotConsiderAnnotationOnNestedPackageInfos() {
33+
34+
var pkg = TestUtils.getPackage(Entry.class);
35+
var info = ApplicationModuleInformation.of(pkg);
36+
37+
assertThat(info.getDisplayName()).isEmpty();
38+
}
39+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package reproducers.gh764;
17+
18+
/**
19+
* @author Oliver Drotbohm
20+
*/
21+
public class Entry {}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@org.springframework.modulith.ApplicationModule(displayName = "Nested")
2+
package reproducers.gh764.nested;

0 commit comments

Comments
 (0)