diff --git a/buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureRules.java b/buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureRules.java index bf7a947dfaf..4a21121dd16 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureRules.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureRules.java @@ -120,9 +120,9 @@ final class ArchitectureRules { .stream() .filter(notAnnotatedWithLazy) .filter((parameter) -> notOfASafeType.test(parameter.getRawType())) - .forEach((parameter) -> events.add(SimpleConditionEvent.violated(parameter, + .forEach((parameter) -> addViolation(events, parameter, parameter.getDescription() + " will cause eager initialization as it is " - + notAnnotatedWithLazy.getDescription() + " and is " + notOfASafeType.getDescription()))); + + notAnnotatedWithLazy.getDescription() + " and is " + notOfASafeType.getDescription())); } private static ArchRule allBeanFactoryPostProcessorBeanMethodsShouldBeStaticAndHaveOnlyInjectEnvironment() { @@ -140,7 +140,7 @@ final class ArchitectureRules { private static void onlyInjectEnvironment(JavaMethod item, ConditionEvents events) { if (item.getParameters().stream().anyMatch(ArchitectureRules::isNotEnvironment)) { - events.add(SimpleConditionEvent.violated(item, item.getDescription() + " should only inject Environment")); + addViolation(events, item, item.getDescription() + " should only inject Environment"); } } @@ -208,8 +208,8 @@ final class ArchitectureRules { if (!properties.containsKey("type") && !properties.containsKey("name")) { conditionalAnnotation.get("value").ifPresent((value) -> { if (containsOnlySingleType((JavaType[]) value, item.getReturnType())) { - events.add(SimpleConditionEvent.violated(item, conditionalAnnotation.getDescription() - + " should not specify only a value that is the same as the method's return type")); + addViolation(events, item, conditionalAnnotation.getDescription() + + " should not specify only a value that is the same as the method's return type"); } }); } @@ -237,8 +237,8 @@ final class ArchitectureRules { if (properties.size() == 1 && item.getParameterTypes().size() == 1) { enumSourceAnnotation.get("value").ifPresent((value) -> { if (value.equals(item.getParameterTypes().get(0))) { - events.add(SimpleConditionEvent.violated(item, enumSourceAnnotation.getDescription() - + " should not specify only a value that is the same as the method's parameter type")); + addViolation(events, item, enumSourceAnnotation.getDescription() + + " should not specify only a value that is the same as the method's parameter type"); } }); } @@ -297,6 +297,10 @@ final class ArchitectureRules { }; } + private static void addViolation(ConditionEvents events, Object correspondingObject, String message) { + events.add(SimpleConditionEvent.violated(correspondingObject, message)); + } + private static String shouldUse(String string) { return string + " should be used instead"; }