Merge branch '1.5.x'
This commit is contained in:
commit
263d444d4e
|
@ -195,7 +195,7 @@ abstract class AbstractNestedCondition extends SpringBootCondition
|
||||||
metadata);
|
metadata);
|
||||||
}
|
}
|
||||||
return new ConditionOutcome(condition.matches(this.context, metadata),
|
return new ConditionOutcome(condition.matches(this.context, metadata),
|
||||||
(ConditionMessage) null);
|
ConditionMessage.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConditionOutcome getUltimateOutcome() {
|
public ConditionOutcome getUltimateOutcome() {
|
||||||
|
|
|
@ -28,6 +28,8 @@ import org.springframework.boot.bind.RelaxedDataBinder;
|
||||||
import org.springframework.boot.bind.RelaxedNames;
|
import org.springframework.boot.bind.RelaxedNames;
|
||||||
import org.springframework.context.annotation.ConditionContext;
|
import org.springframework.context.annotation.ConditionContext;
|
||||||
import org.springframework.core.env.ConfigurableEnvironment;
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.core.env.PropertySources;
|
||||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||||
import org.springframework.validation.DataBinder;
|
import org.springframework.validation.DataBinder;
|
||||||
|
|
||||||
|
@ -41,21 +43,20 @@ class OnBootstrapHostsCondition extends SpringBootCondition {
|
||||||
@Override
|
@Override
|
||||||
public ConditionOutcome getMatchOutcome(ConditionContext context,
|
public ConditionOutcome getMatchOutcome(ConditionContext context,
|
||||||
AnnotatedTypeMetadata metadata) {
|
AnnotatedTypeMetadata metadata) {
|
||||||
ConfigurableEnvironment environment = (ConfigurableEnvironment) context
|
Environment environment = context.getEnvironment();
|
||||||
.getEnvironment();
|
PropertyResolver resolver = new PropertyResolver(
|
||||||
PropertyResolver resolver = new PropertyResolver(environment, "spring.couchbase");
|
((ConfigurableEnvironment) environment).getPropertySources(),
|
||||||
|
"spring.couchbase");
|
||||||
Map.Entry<String, Object> entry = resolver.resolveProperty("bootstrap-hosts");
|
Map.Entry<String, Object> entry = resolver.resolveProperty("bootstrap-hosts");
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
return ConditionOutcome.match(
|
return ConditionOutcome.match(ConditionMessage
|
||||||
ConditionMessage.forCondition(OnBootstrapHostsCondition.class.getName())
|
.forCondition(OnBootstrapHostsCondition.class.getName())
|
||||||
.found("property").items("spring.couchbase.bootstrap-hosts"));
|
.found("property").items("spring.couchbase.bootstrap-hosts"));
|
||||||
}
|
}
|
||||||
else {
|
return ConditionOutcome.noMatch(ConditionMessage
|
||||||
return ConditionOutcome.noMatch(
|
.forCondition(OnBootstrapHostsCondition.class.getName())
|
||||||
ConditionMessage.forCondition(OnBootstrapHostsCondition.class.getName())
|
|
||||||
.didNotFind("property").items("spring.couchbase.bootstrap-hosts"));
|
.didNotFind("property").items("spring.couchbase.bootstrap-hosts"));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static class PropertyResolver {
|
private static class PropertyResolver {
|
||||||
|
|
||||||
|
@ -63,12 +64,11 @@ class OnBootstrapHostsCondition extends SpringBootCondition {
|
||||||
|
|
||||||
private final Map<String, Object> content;
|
private final Map<String, Object> content;
|
||||||
|
|
||||||
PropertyResolver(ConfigurableEnvironment environment, String prefix) {
|
PropertyResolver(PropertySources propertySources, String prefix) {
|
||||||
this.prefix = prefix;
|
this.prefix = prefix;
|
||||||
this.content = new HashMap<String, Object>();
|
this.content = new HashMap<String, Object>();
|
||||||
DataBinder binder = new RelaxedDataBinder(this.content, this.prefix);
|
DataBinder binder = new RelaxedDataBinder(this.content, this.prefix);
|
||||||
binder.bind(new PropertySourcesPropertyValues(
|
binder.bind(new PropertySourcesPropertyValues(propertySources));
|
||||||
environment.getPropertySources()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Map.Entry<String, Object> resolveProperty(String name) {
|
Map.Entry<String, Object> resolveProperty(String name) {
|
||||||
|
@ -89,5 +89,3 @@ class OnBootstrapHostsCondition extends SpringBootCondition {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,11 @@ import org.junit.Test;
|
||||||
import org.springframework.boot.test.util.EnvironmentTestUtils;
|
import org.springframework.boot.test.util.EnvironmentTestUtils;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Condition;
|
||||||
|
import org.springframework.context.annotation.ConditionContext;
|
||||||
import org.springframework.context.annotation.Conditional;
|
import org.springframework.context.annotation.Conditional;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
@ -94,6 +97,20 @@ public class AllNestedConditionsTests {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Conditional(NonSpringBootCondition.class)
|
||||||
|
static class SubclassC {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static class NonSpringBootCondition implements Condition {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,11 @@ import org.junit.Test;
|
||||||
import org.springframework.boot.test.util.EnvironmentTestUtils;
|
import org.springframework.boot.test.util.EnvironmentTestUtils;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Condition;
|
||||||
|
import org.springframework.context.annotation.ConditionContext;
|
||||||
import org.springframework.context.annotation.Conditional;
|
import org.springframework.context.annotation.Conditional;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
@ -98,6 +101,20 @@ public class AnyNestedConditionTests {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Conditional(NonSpringBootCondition.class)
|
||||||
|
static class SubclassC {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static class NonSpringBootCondition implements Condition {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,11 @@ import org.junit.Test;
|
||||||
import org.springframework.boot.test.util.EnvironmentTestUtils;
|
import org.springframework.boot.test.util.EnvironmentTestUtils;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Condition;
|
||||||
|
import org.springframework.context.annotation.ConditionContext;
|
||||||
import org.springframework.context.annotation.Conditional;
|
import org.springframework.context.annotation.Conditional;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
@ -94,6 +97,20 @@ public class NoneNestedConditionsTests {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Conditional(NonSpringBootCondition.class)
|
||||||
|
static class SubClassC {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static class NonSpringBootCondition implements Condition {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,6 @@ public class OnBootstrapHostsConditionTests {
|
||||||
assertThat(this.context.containsBean("foo")).isTrue();
|
assertThat(this.context.containsBean("foo")).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void load(Class<?> config, String... environment) {
|
private void load(Class<?> config, String... environment) {
|
||||||
this.context = new AnnotationConfigApplicationContext();
|
this.context = new AnnotationConfigApplicationContext();
|
||||||
EnvironmentTestUtils.addEnvironment(this.context, environment);
|
EnvironmentTestUtils.addEnvironment(this.context, environment);
|
||||||
|
|
|
@ -276,13 +276,20 @@ class ImportsContextCustomizer implements ContextCustomizer {
|
||||||
return (obj != null && getClass().equals(obj.getClass())
|
return (obj != null && getClass().equals(obj.getClass())
|
||||||
&& this.annotations.equals(((ContextCustomizerKey) obj).annotations));
|
&& this.annotations.equals(((ContextCustomizerKey) obj).annotations));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter used to limit considered annotations.
|
||||||
|
*/
|
||||||
private interface AnnotationFilter {
|
private interface AnnotationFilter {
|
||||||
|
|
||||||
boolean isIgnored(Annotation annotation);
|
boolean isIgnored(Annotation annotation);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link AnnotationFilter} for {@literal java.lang} annotations.
|
||||||
|
*/
|
||||||
private static final class JavaLangAnnotationFilter implements AnnotationFilter {
|
private static final class JavaLangAnnotationFilter implements AnnotationFilter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -292,6 +299,9 @@ class ImportsContextCustomizer implements ContextCustomizer {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link AnnotationFilter} for Kotlin annotations.
|
||||||
|
*/
|
||||||
private static final class KotlinAnnotationFilter implements AnnotationFilter {
|
private static final class KotlinAnnotationFilter implements AnnotationFilter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -301,12 +311,14 @@ class ImportsContextCustomizer implements ContextCustomizer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isInKotlinAnnotationPackage(Annotation annotation) {
|
private boolean isInKotlinAnnotationPackage(Annotation annotation) {
|
||||||
return annotation.annotationType().getName()
|
return annotation.annotationType().getName().startsWith("kotlin.annotation.");
|
||||||
.startsWith("kotlin.annotation.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link AnnotationFilter} for Spock annotations.
|
||||||
|
*/
|
||||||
private static final class SpockAnnotationFilter implements AnnotationFilter {
|
private static final class SpockAnnotationFilter implements AnnotationFilter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -318,5 +330,3 @@ class ImportsContextCustomizer implements ContextCustomizer {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -128,10 +128,10 @@ public class ArtifactsLibrariesTests {
|
||||||
this.libs = new ArtifactsLibraries(this.artifacts, null, mock(Log.class));
|
this.libs = new ArtifactsLibraries(this.artifacts, null, mock(Log.class));
|
||||||
this.libs.doWithLibraries(this.callback);
|
this.libs.doWithLibraries(this.callback);
|
||||||
verify(this.callback, times(2)).library(this.libraryCaptor.capture());
|
verify(this.callback, times(2)).library(this.libraryCaptor.capture());
|
||||||
assertThat(this.libraryCaptor.getAllValues().get(0).getName()).isEqualTo(
|
assertThat(this.libraryCaptor.getAllValues().get(0).getName())
|
||||||
"g1-artifact-1.0.jar");
|
.isEqualTo("g1-artifact-1.0.jar");
|
||||||
assertThat(this.libraryCaptor.getAllValues().get(1).getName()).isEqualTo(
|
assertThat(this.libraryCaptor.getAllValues().get(1).getName())
|
||||||
"g2-artifact-1.0.jar");
|
.isEqualTo("g2-artifact-1.0.jar");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue