Commit 72707b9d authored by dreis2211's avatar dreis2211 Committed by Stephane Nicoll

Polish OnWebApplicationCondition

Closes gh-14015
parent 481bc94c
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -62,8 +62,6 @@ class OnWebApplicationCondition extends SpringBootCondition { ...@@ -62,8 +62,6 @@ class OnWebApplicationCondition extends SpringBootCondition {
private ConditionOutcome isWebApplication(ConditionContext context, private ConditionOutcome isWebApplication(ConditionContext context,
AnnotatedTypeMetadata metadata, boolean required) { AnnotatedTypeMetadata metadata, boolean required) {
ConditionMessage.Builder message = ConditionMessage.forCondition(
ConditionalOnWebApplication.class, required ? "(required)" : "");
Type type = deduceType(metadata); Type type = deduceType(metadata);
if (Type.SERVLET == type) { if (Type.SERVLET == type) {
return isServletWebApplication(context); return isServletWebApplication(context);
...@@ -72,23 +70,30 @@ class OnWebApplicationCondition extends SpringBootCondition { ...@@ -72,23 +70,30 @@ class OnWebApplicationCondition extends SpringBootCondition {
return isReactiveWebApplication(context); return isReactiveWebApplication(context);
} }
else { else {
ConditionOutcome servletOutcome = isServletWebApplication(context); return isAnyWebApplication(context, required);
if (servletOutcome.isMatch() && required) { }
return new ConditionOutcome(servletOutcome.isMatch(), }
message.because(servletOutcome.getMessage()));
} private ConditionOutcome isAnyWebApplication(ConditionContext context,
ConditionOutcome reactiveOutcome = isReactiveWebApplication(context); boolean required) {
if (reactiveOutcome.isMatch() && required) { ConditionMessage.Builder message = ConditionMessage.forCondition(
return new ConditionOutcome(reactiveOutcome.isMatch(), ConditionalOnWebApplication.class, required ? "(required)" : "");
message.because(reactiveOutcome.getMessage())); ConditionOutcome servletOutcome = isServletWebApplication(context);
} if (servletOutcome.isMatch() && required) {
boolean finalOutcome = (required return new ConditionOutcome(servletOutcome.isMatch(),
? servletOutcome.isMatch() && reactiveOutcome.isMatch() message.because(servletOutcome.getMessage()));
: servletOutcome.isMatch() || reactiveOutcome.isMatch()); }
return new ConditionOutcome(finalOutcome, ConditionOutcome reactiveOutcome = isReactiveWebApplication(context);
message.because(servletOutcome.getMessage()).append("and") if (reactiveOutcome.isMatch() && required) {
.append(reactiveOutcome.getMessage())); return new ConditionOutcome(reactiveOutcome.isMatch(),
message.because(reactiveOutcome.getMessage()));
} }
boolean finalOutcome = (required
? servletOutcome.isMatch() && reactiveOutcome.isMatch()
: servletOutcome.isMatch() || reactiveOutcome.isMatch());
return new ConditionOutcome(finalOutcome,
message.because(servletOutcome.getMessage()).append("and")
.append(reactiveOutcome.getMessage()));
} }
private ConditionOutcome isServletWebApplication(ConditionContext context) { private ConditionOutcome isServletWebApplication(ConditionContext context) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment