Skip to content

Commit 6b654f4

Browse files
committed
Merge branch '3.4.x'
2 parents 680c168 + 67a585e commit 6b654f4

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureRules.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ private static void allBeanPostProcessorBeanMethodsShouldBeStaticAndNotCausePrem
127127
.stream()
128128
.filter(notAnnotatedWithLazy)
129129
.filter((parameter) -> notOfASafeType.test(parameter.getRawType()))
130-
.forEach((parameter) -> events.add(SimpleConditionEvent.violated(parameter,
130+
.forEach((parameter) -> addViolation(events, parameter,
131131
parameter.getDescription() + " will cause eager initialization as it is "
132-
+ notAnnotatedWithLazy.getDescription() + " and is " + notOfASafeType.getDescription())));
132+
+ notAnnotatedWithLazy.getDescription() + " and is " + notOfASafeType.getDescription()));
133133
}
134134

135135
private static DescribedPredicate<JavaClass> notAnnotatedWithRoleInfrastructure() {
@@ -154,7 +154,7 @@ private static ArchCondition<JavaMethod> onlyInjectEnvironment() {
154154

155155
private static void onlyInjectEnvironment(JavaMethod item, ConditionEvents events) {
156156
if (item.getParameters().stream().anyMatch(ArchitectureRules::isNotEnvironment)) {
157-
events.add(SimpleConditionEvent.violated(item, item.getDescription() + " should only inject Environment"));
157+
addViolation(events, item, item.getDescription() + " should only inject Environment");
158158
}
159159
}
160160

@@ -222,8 +222,8 @@ private static ArchCondition<? super JavaMethod> notSpecifyOnlyATypeThatIsTheSam
222222
if (!properties.containsKey("type") && !properties.containsKey("name")) {
223223
conditionalAnnotation.get("value").ifPresent((value) -> {
224224
if (containsOnlySingleType((JavaType[]) value, item.getReturnType())) {
225-
events.add(SimpleConditionEvent.violated(item, conditionalAnnotation.getDescription()
226-
+ " should not specify only a value that is the same as the method's return type"));
225+
addViolation(events, item, conditionalAnnotation.getDescription()
226+
+ " should not specify only a value that is the same as the method's return type");
227227
}
228228
});
229229
}
@@ -251,8 +251,8 @@ private static void notSpecifyOnlyATypeThatIsTheSameAsTheMethodParameterType(Jav
251251
if (properties.size() == 1 && item.getParameterTypes().size() == 1) {
252252
enumSourceAnnotation.get("value").ifPresent((value) -> {
253253
if (value.equals(item.getParameterTypes().get(0))) {
254-
events.add(SimpleConditionEvent.violated(item, enumSourceAnnotation.getDescription()
255-
+ " should not specify only a value that is the same as the method's parameter type"));
254+
addViolation(events, item, enumSourceAnnotation.getDescription()
255+
+ " should not specify only a value that is the same as the method's parameter type");
256256
}
257257
});
258258
}
@@ -285,8 +285,8 @@ private static void notSpecifyOnlyPrefixAttributeOfConfigurationProperties(HasAn
285285
.getAnnotationOfType("org.springframework.boot.context.properties.ConfigurationProperties");
286286
Map<String, Object> properties = configurationPropertiesAnnotation.getProperties();
287287
if (properties.size() == 1 && properties.containsKey("prefix")) {
288-
events.add(SimpleConditionEvent.violated(item, configurationPropertiesAnnotation.getDescription()
289-
+ " should specify implicit 'value' attribute other than explicit 'prefix' attribute"));
288+
addViolation(events, item, configurationPropertiesAnnotation.getDescription()
289+
+ " should specify implicit 'value' attribute other than explicit 'prefix' attribute");
290290
}
291291
}
292292

@@ -354,6 +354,10 @@ public void check(T item, ConditionEvents events) {
354354
};
355355
}
356356

357+
private static void addViolation(ConditionEvents events, Object correspondingObject, String message) {
358+
events.add(SimpleConditionEvent.violated(correspondingObject, message));
359+
}
360+
357361
private static String shouldUse(String string) {
358362
return string + " should be used instead";
359363
}

0 commit comments

Comments
 (0)