1
1
/*
2
- * Copyright 2012-2024 the original author or authors.
2
+ * Copyright 2012-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
69
69
import org .gradle .api .tasks .SkipWhenEmpty ;
70
70
import org .gradle .api .tasks .TaskAction ;
71
71
72
+ import org .springframework .beans .factory .config .BeanDefinition ;
73
+ import org .springframework .context .annotation .Role ;
72
74
import org .springframework .util .ResourceUtils ;
73
75
74
76
/**
@@ -149,7 +151,8 @@ private ArchCondition<JavaMethod> onlyHaveParametersThatWillNotCauseEagerInitial
149
151
DescribedPredicate <JavaClass > notOfASafeType = DescribedPredicate
150
152
.not (Predicates .assignableTo ("org.springframework.beans.factory.ObjectProvider" )
151
153
.or (Predicates .assignableTo ("org.springframework.context.ApplicationContext" ))
152
- .or (Predicates .assignableTo ("org.springframework.core.env.Environment" )));
154
+ .or (Predicates .assignableTo ("org.springframework.core.env.Environment" )
155
+ .or (annotatedWithRoleInfrastructure ())));
153
156
return new ArchCondition <>("not have parameters that will cause eager initialization" ) {
154
157
155
158
@ Override
@@ -167,6 +170,18 @@ public void check(JavaMethod item, ConditionEvents events) {
167
170
};
168
171
}
169
172
173
+ private DescribedPredicate <JavaClass > annotatedWithRoleInfrastructure () {
174
+ return new DescribedPredicate <>("annotated with @Role(BeanDefinition.ROLE_INFRASTRUCTURE" ) {
175
+
176
+ @ Override
177
+ public boolean test (JavaClass candidate ) {
178
+ Role role = candidate .getAnnotationOfType (Role .class );
179
+ return (role != null ) && (role .value () == BeanDefinition .ROLE_INFRASTRUCTURE );
180
+ }
181
+
182
+ };
183
+ }
184
+
170
185
private ArchRule allBeanFactoryPostProcessorBeanMethodsShouldBeStaticAndHaveNoParameters () {
171
186
return ArchRuleDefinition .methods ()
172
187
.that ()
0 commit comments