From 20a2db79bdcf8fd7d73d96da043dc4c9d5375dc2 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 6 Oct 2016 15:49:20 +0100 Subject: [PATCH] Separate conditions that did and did not match in auto-config report Closes gh-7098 --- .../ConditionEvaluationReportMessage.java | 60 ++++++++++++++----- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/logging/ConditionEvaluationReportMessage.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/logging/ConditionEvaluationReportMessage.java index 15f2585d2a4..9b5aa7939ed 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/logging/ConditionEvaluationReportMessage.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/logging/ConditionEvaluationReportMessage.java @@ -55,7 +55,7 @@ public class ConditionEvaluationReportMessage { report.getConditionAndOutcomesBySource()); for (Map.Entry entry : shortOutcomes.entrySet()) { if (entry.getValue().isFullMatch()) { - addLogMessage(message, entry.getKey(), entry.getValue()); + addMatchLogMessage(message, entry.getKey(), entry.getValue()); } } message.append(String.format("%n%n")); @@ -63,7 +63,7 @@ public class ConditionEvaluationReportMessage { message.append(String.format("-----------------%n")); for (Map.Entry entry : shortOutcomes.entrySet()) { if (!entry.getValue().isFullMatch()) { - addLogMessage(message, entry.getKey(), entry.getValue()); + addNonMatchLogMessage(message, entry.getKey(), entry.getValue()); } } message.append(String.format("%n%n")); @@ -109,26 +109,54 @@ public class ConditionEvaluationReportMessage { return result; } - private void addLogMessage(StringBuilder message, String source, + private void addMatchLogMessage(StringBuilder message, String source, + ConditionAndOutcomes matches) { + message.append(String.format("%n %s matched:%n", source)); + for (ConditionAndOutcome match : matches) { + logConditionAndOutcome(message, " ", match); + } + } + + private void addNonMatchLogMessage(StringBuilder message, String source, ConditionAndOutcomes conditionAndOutcomes) { - message.append(String.format("%n %s", source)); - message.append(conditionAndOutcomes.isFullMatch() ? " matched" : " did not match") - .append(String.format("%n")); + message.append(String.format("%n %s:%n", source)); + List matches = new ArrayList(); + List nonMatches = new ArrayList(); for (ConditionAndOutcome conditionAndOutcome : conditionAndOutcomes) { - message.append(" - "); - String outcomeMessage = conditionAndOutcome.getOutcome().getMessage(); - if (StringUtils.hasLength(outcomeMessage)) { - message.append(outcomeMessage); + if (conditionAndOutcome.getOutcome().isMatch()) { + matches.add(conditionAndOutcome); } else { - message.append(conditionAndOutcome.getOutcome().isMatch() ? "matched" - : "did not match"); + nonMatches.add(conditionAndOutcome); } - message.append(" ("); - message.append(ClassUtils - .getShortName(conditionAndOutcome.getCondition().getClass())); - message.append(String.format(")%n")); } + message.append(String.format(" Did not match:%n")); + for (ConditionAndOutcome nonMatch : nonMatches) { + logConditionAndOutcome(message, " ", nonMatch); + } + if (!matches.isEmpty()) { + message.append(String.format(" Matched:%n")); + for (ConditionAndOutcome match : matches) { + logConditionAndOutcome(message, " ", match); + } + } + } + + private void logConditionAndOutcome(StringBuilder message, String indent, + ConditionAndOutcome conditionAndOutcome) { + message.append(String.format("%s- ", indent)); + String outcomeMessage = conditionAndOutcome.getOutcome().getMessage(); + if (StringUtils.hasLength(outcomeMessage)) { + message.append(outcomeMessage); + } + else { + message.append(conditionAndOutcome.getOutcome().isMatch() ? "matched" + : "did not match"); + } + message.append(" ("); + message.append( + ClassUtils.getShortName(conditionAndOutcome.getCondition().getClass())); + message.append(String.format(")%n")); } @Override