|
1 | 1 | /* |
2 | | - * Copyright 2012-2017 the original author or authors. |
| 2 | + * Copyright 2012-2019 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. |
|
16 | 16 |
|
17 | 17 | package org.springframework.boot.devtools.autoconfigure; |
18 | 18 |
|
| 19 | +import java.util.concurrent.ConcurrentHashMap; |
| 20 | + |
19 | 21 | import org.apache.commons.logging.Log; |
20 | 22 | import org.apache.commons.logging.LogFactory; |
21 | 23 |
|
22 | 24 | import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport; |
23 | 25 | import org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportMessage; |
24 | 26 | import org.springframework.boot.context.event.ApplicationReadyEvent; |
| 27 | +import org.springframework.context.ApplicationContext; |
| 28 | +import org.springframework.context.ApplicationContextAware; |
25 | 29 | import org.springframework.context.ApplicationListener; |
26 | 30 |
|
27 | 31 | /** |
|
31 | 35 | * @author Andy Wilkinson |
32 | 36 | */ |
33 | 37 | class ConditionEvaluationDeltaLoggingListener |
34 | | - implements ApplicationListener<ApplicationReadyEvent> { |
| 38 | + implements ApplicationListener<ApplicationReadyEvent>, ApplicationContextAware { |
| 39 | + |
| 40 | + private static final ConcurrentHashMap<String, ConditionEvaluationReport> previousReports = new ConcurrentHashMap<>(); |
35 | 41 |
|
36 | | - private final Log logger = LogFactory.getLog(getClass()); |
| 42 | + private static final Log logger = LogFactory |
| 43 | + .getLog(ConditionEvaluationDeltaLoggingListener.class); |
37 | 44 |
|
38 | | - private static ConditionEvaluationReport previousReport; |
| 45 | + private volatile ApplicationContext context; |
39 | 46 |
|
40 | 47 | @Override |
41 | 48 | public void onApplicationEvent(ApplicationReadyEvent event) { |
| 49 | + if (!event.getApplicationContext().equals(this.context)) { |
| 50 | + return; |
| 51 | + } |
42 | 52 | ConditionEvaluationReport report = event.getApplicationContext() |
43 | 53 | .getBean(ConditionEvaluationReport.class); |
| 54 | + ConditionEvaluationReport previousReport = previousReports |
| 55 | + .get(event.getApplicationContext().getId()); |
44 | 56 | if (previousReport != null) { |
45 | 57 | ConditionEvaluationReport delta = report.getDelta(previousReport); |
46 | 58 | if (!delta.getConditionAndOutcomesBySource().isEmpty() |
47 | 59 | || !delta.getExclusions().isEmpty() |
48 | 60 | || !delta.getUnconditionalClasses().isEmpty()) { |
49 | | - if (this.logger.isInfoEnabled()) { |
50 | | - this.logger.info("Condition evaluation delta:" |
51 | | - + new ConditionEvaluationReportMessage(delta, |
52 | | - "CONDITION EVALUATION DELTA")); |
| 61 | + if (ConditionEvaluationDeltaLoggingListener.logger.isInfoEnabled()) { |
| 62 | + ConditionEvaluationDeltaLoggingListener.logger |
| 63 | + .info("Condition evaluation delta:" |
| 64 | + + new ConditionEvaluationReportMessage(delta, |
| 65 | + "CONDITION EVALUATION DELTA")); |
53 | 66 | } |
54 | 67 | } |
55 | 68 | else { |
56 | | - this.logger.info("Condition evaluation unchanged"); |
| 69 | + ConditionEvaluationDeltaLoggingListener.logger |
| 70 | + .info("Condition evaluation unchanged"); |
57 | 71 | } |
58 | 72 | } |
59 | | - previousReport = report; |
| 73 | + previousReports.put(event.getApplicationContext().getId(), report); |
| 74 | + } |
| 75 | + |
| 76 | + @Override |
| 77 | + public void setApplicationContext(ApplicationContext applicationContext) { |
| 78 | + this.context = applicationContext; |
60 | 79 | } |
61 | 80 |
|
62 | 81 | } |
0 commit comments