Skip to content

Commit 9e4ccbd

Browse files
committed
Merge pull request #14015 from dreis2211:polish-onwebapplicationcondition
* pr/14015: Polish OnWebApplicationCondition
2 parents 481bc94 + 72707b9 commit 9e4ccbd

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnWebApplicationCondition.java

Lines changed: 24 additions & 19 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-2018 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.
@@ -62,8 +62,6 @@ public ConditionOutcome getMatchOutcome(ConditionContext context,
6262

6363
private ConditionOutcome isWebApplication(ConditionContext context,
6464
AnnotatedTypeMetadata metadata, boolean required) {
65-
ConditionMessage.Builder message = ConditionMessage.forCondition(
66-
ConditionalOnWebApplication.class, required ? "(required)" : "");
6765
Type type = deduceType(metadata);
6866
if (Type.SERVLET == type) {
6967
return isServletWebApplication(context);
@@ -72,23 +70,30 @@ else if (Type.REACTIVE == type) {
7270
return isReactiveWebApplication(context);
7371
}
7472
else {
75-
ConditionOutcome servletOutcome = isServletWebApplication(context);
76-
if (servletOutcome.isMatch() && required) {
77-
return new ConditionOutcome(servletOutcome.isMatch(),
78-
message.because(servletOutcome.getMessage()));
79-
}
80-
ConditionOutcome reactiveOutcome = isReactiveWebApplication(context);
81-
if (reactiveOutcome.isMatch() && required) {
82-
return new ConditionOutcome(reactiveOutcome.isMatch(),
83-
message.because(reactiveOutcome.getMessage()));
84-
}
85-
boolean finalOutcome = (required
86-
? servletOutcome.isMatch() && reactiveOutcome.isMatch()
87-
: servletOutcome.isMatch() || reactiveOutcome.isMatch());
88-
return new ConditionOutcome(finalOutcome,
89-
message.because(servletOutcome.getMessage()).append("and")
90-
.append(reactiveOutcome.getMessage()));
73+
return isAnyWebApplication(context, required);
74+
}
75+
}
76+
77+
private ConditionOutcome isAnyWebApplication(ConditionContext context,
78+
boolean required) {
79+
ConditionMessage.Builder message = ConditionMessage.forCondition(
80+
ConditionalOnWebApplication.class, required ? "(required)" : "");
81+
ConditionOutcome servletOutcome = isServletWebApplication(context);
82+
if (servletOutcome.isMatch() && required) {
83+
return new ConditionOutcome(servletOutcome.isMatch(),
84+
message.because(servletOutcome.getMessage()));
85+
}
86+
ConditionOutcome reactiveOutcome = isReactiveWebApplication(context);
87+
if (reactiveOutcome.isMatch() && required) {
88+
return new ConditionOutcome(reactiveOutcome.isMatch(),
89+
message.because(reactiveOutcome.getMessage()));
9190
}
91+
boolean finalOutcome = (required
92+
? servletOutcome.isMatch() && reactiveOutcome.isMatch()
93+
: servletOutcome.isMatch() || reactiveOutcome.isMatch());
94+
return new ConditionOutcome(finalOutcome,
95+
message.because(servletOutcome.getMessage()).append("and")
96+
.append(reactiveOutcome.getMessage()));
9297
}
9398

9499
private ConditionOutcome isServletWebApplication(ConditionContext context) {

0 commit comments

Comments
 (0)