Skip to content

Commit 33b9321

Browse files
committed
Track condition evaluation per-context when determining delta
Closes gh-15766
1 parent 1be794f commit 33b9321

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/ConditionEvaluationDeltaLoggingListener.java

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,12 +16,16 @@
1616

1717
package org.springframework.boot.devtools.autoconfigure;
1818

19+
import java.util.concurrent.ConcurrentHashMap;
20+
1921
import org.apache.commons.logging.Log;
2022
import org.apache.commons.logging.LogFactory;
2123

2224
import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport;
2325
import org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportMessage;
2426
import org.springframework.boot.context.event.ApplicationReadyEvent;
27+
import org.springframework.context.ApplicationContext;
28+
import org.springframework.context.ApplicationContextAware;
2529
import org.springframework.context.ApplicationListener;
2630

2731
/**
@@ -31,32 +35,47 @@
3135
* @author Andy Wilkinson
3236
*/
3337
class ConditionEvaluationDeltaLoggingListener
34-
implements ApplicationListener<ApplicationReadyEvent> {
38+
implements ApplicationListener<ApplicationReadyEvent>, ApplicationContextAware {
39+
40+
private static final ConcurrentHashMap<String, ConditionEvaluationReport> previousReports = new ConcurrentHashMap<>();
3541

36-
private final Log logger = LogFactory.getLog(getClass());
42+
private static final Log logger = LogFactory
43+
.getLog(ConditionEvaluationDeltaLoggingListener.class);
3744

38-
private static ConditionEvaluationReport previousReport;
45+
private volatile ApplicationContext context;
3946

4047
@Override
4148
public void onApplicationEvent(ApplicationReadyEvent event) {
49+
if (!event.getApplicationContext().equals(this.context)) {
50+
return;
51+
}
4252
ConditionEvaluationReport report = event.getApplicationContext()
4353
.getBean(ConditionEvaluationReport.class);
54+
ConditionEvaluationReport previousReport = previousReports
55+
.get(event.getApplicationContext().getId());
4456
if (previousReport != null) {
4557
ConditionEvaluationReport delta = report.getDelta(previousReport);
4658
if (!delta.getConditionAndOutcomesBySource().isEmpty()
4759
|| !delta.getExclusions().isEmpty()
4860
|| !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"));
5366
}
5467
}
5568
else {
56-
this.logger.info("Condition evaluation unchanged");
69+
ConditionEvaluationDeltaLoggingListener.logger
70+
.info("Condition evaluation unchanged");
5771
}
5872
}
59-
previousReport = report;
73+
previousReports.put(event.getApplicationContext().getId(), report);
74+
}
75+
76+
@Override
77+
public void setApplicationContext(ApplicationContext applicationContext) {
78+
this.context = applicationContext;
6079
}
6180

6281
}

0 commit comments

Comments
 (0)