Change SearchStrategy EXHAUSTIVE to TYPE_HIERARCHY

Fixup references following upstream Spring Framework change.
This commit is contained in:
Phillip Webb
2019-07-31 15:09:54 +01:00
parent 5926547767
commit da4f436140
17 changed files with 23 additions and 22 deletions

View File

@@ -101,7 +101,7 @@ abstract class AbstractEndpointCondition extends SpringBootCondition {
}
protected AnnotationAttributes getEndpointAttributes(Class<?> type) {
MergedAnnotations annotations = MergedAnnotations.from(type, SearchStrategy.EXHAUSTIVE);
MergedAnnotations annotations = MergedAnnotations.from(type, SearchStrategy.TYPE_HIERARCHY);
MergedAnnotation<Endpoint> endpoint = annotations.get(Endpoint.class);
if (endpoint.isPresent()) {
return endpoint.asAnnotationAttributes();

View File

@@ -403,8 +403,8 @@ public abstract class EndpointDiscoverer<E extends ExposableEndpoint<O>, O exten
private Set<ExtensionBean> extensions = new LinkedHashSet<>();
EndpointBean(String beanName, Object bean) {
MergedAnnotation<Endpoint> annotation = MergedAnnotations.from(bean.getClass(), SearchStrategy.EXHAUSTIVE)
.get(Endpoint.class);
MergedAnnotation<Endpoint> annotation = MergedAnnotations
.from(bean.getClass(), SearchStrategy.TYPE_HIERARCHY).get(Endpoint.class);
String id = annotation.getString("id");
Assert.state(StringUtils.hasText(id),
() -> "No @Endpoint id attribute specified for " + bean.getClass().getName());
@@ -470,7 +470,7 @@ public abstract class EndpointDiscoverer<E extends ExposableEndpoint<O>, O exten
.get(EndpointExtension.class);
Class<?> endpointType = extensionAnnotation.getClass("endpoint");
MergedAnnotation<Endpoint> endpointAnnotation = MergedAnnotations
.from(endpointType, SearchStrategy.EXHAUSTIVE).get(Endpoint.class);
.from(endpointType, SearchStrategy.TYPE_HIERARCHY).get(Endpoint.class);
Assert.state(endpointAnnotation.isPresent(),
() -> "Extension " + endpointType.getName() + " does not specify an endpoint");
this.endpointId = EndpointId.of(endpointAnnotation.getString("id"));

View File

@@ -153,7 +153,7 @@ class WebEndpointTestInvocationContextProvider implements TestTemplateInvocation
}
private boolean isConfiguration(Class<?> candidate) {
return MergedAnnotations.from(candidate, SearchStrategy.EXHAUSTIVE).isPresent(Configuration.class);
return MergedAnnotations.from(candidate, SearchStrategy.TYPE_HIERARCHY).isPresent(Configuration.class);
}
@Override

View File

@@ -117,7 +117,7 @@ final class BeanTypeRegistry implements SmartInitializingSingleton {
updateTypesIfNecessary();
return this.beanTypes.entrySet().stream()
.filter((entry) -> entry.getValue() != null && MergedAnnotations
.from(entry.getValue().resolve(), MergedAnnotations.SearchStrategy.EXHAUSTIVE)
.from(entry.getValue().resolve(), MergedAnnotations.SearchStrategy.TYPE_HIERARCHY)
.isPresent(annotation))
.map(Map.Entry::getKey).collect(Collectors.toCollection(LinkedHashSet::new));
}

View File

@@ -566,7 +566,7 @@ class OnBeanCondition extends FilteringSpringBootCondition implements Configurat
}
private boolean isBeanMethod(Method method) {
return method != null && MergedAnnotations.from(method, MergedAnnotations.SearchStrategy.EXHAUSTIVE)
return method != null && MergedAnnotations.from(method, MergedAnnotations.SearchStrategy.TYPE_HIERARCHY)
.isPresent(Bean.class);
}

View File

@@ -53,7 +53,7 @@ public class DefaultJerseyApplicationPath implements JerseyApplicationPath {
return this.applicationPath;
}
// Jersey doesn't like to be the default servlet, so map to /* as a fallback
return MergedAnnotations.from(this.config.getApplication().getClass(), SearchStrategy.EXHAUSTIVE)
return MergedAnnotations.from(this.config.getApplication().getClass(), SearchStrategy.TYPE_HIERARCHY)
.get(ApplicationPath.class).getValue(MergedAnnotation.VALUE, String.class).orElse("/*");
}

View File

@@ -39,7 +39,7 @@ class OverrideAutoConfigurationContextCustomizerFactory implements ContextCustom
@Override
public ContextCustomizer createContextCustomizer(Class<?> testClass,
List<ContextConfigurationAttributes> configurationAttributes) {
boolean enabled = MergedAnnotations.from(testClass, SearchStrategy.EXHAUSTIVE)
boolean enabled = MergedAnnotations.from(testClass, SearchStrategy.TYPE_HIERARCHY)
.get(OverrideAutoConfiguration.class).getValue("enabled", Boolean.class).orElse(true);
return !enabled ? new DisableAutoConfigurationContextCustomizer() : null;
}

View File

@@ -41,7 +41,7 @@ class ImportsContextCustomizerFactory implements ContextCustomizerFactory {
@Override
public ContextCustomizer createContextCustomizer(Class<?> testClass,
List<ContextConfigurationAttributes> configAttributes) {
if (MergedAnnotations.from(testClass, SearchStrategy.EXHAUSTIVE).isPresent(Import.class)) {
if (MergedAnnotations.from(testClass, SearchStrategy.TYPE_HIERARCHY).isPresent(Import.class)) {
assertHasNoBeanMethods(testClass);
return new ImportsContextCustomizer(testClass);
}

View File

@@ -151,7 +151,7 @@ public class SpringBootContextLoader extends AbstractContextLoader {
* @see SpringApplication#run(String...)
*/
protected String[] getArgs(MergedContextConfiguration config) {
return MergedAnnotations.from(config.getTestClass(), SearchStrategy.EXHAUSTIVE).get(SpringBootTest.class)
return MergedAnnotations.from(config.getTestClass(), SearchStrategy.TYPE_HIERARCHY).get(SpringBootTest.class)
.getValue("args", String[].class).orElse(NO_ARGS);
}
@@ -215,7 +215,7 @@ public class SpringBootContextLoader extends AbstractContextLoader {
}
private boolean isEmbeddedWebEnvironment(MergedContextConfiguration config) {
return MergedAnnotations.from(config.getTestClass(), SearchStrategy.EXHAUSTIVE).get(SpringBootTest.class)
return MergedAnnotations.from(config.getTestClass(), SearchStrategy.TYPE_HIERARCHY).get(SpringBootTest.class)
.getValue("webEnvironment", WebEnvironment.class).orElse(WebEnvironment.NONE).isEmbedded();
}

View File

@@ -196,7 +196,7 @@ public class SpringBootTestContextBootstrapper extends DefaultTestContextBootstr
* @since 2.1.6
*/
protected String determineResourceBasePath(MergedContextConfiguration configuration) {
return MergedAnnotations.from(configuration.getTestClass(), SearchStrategy.EXHAUSTIVE)
return MergedAnnotations.from(configuration.getTestClass(), SearchStrategy.TYPE_HIERARCHY)
.get(WebAppConfiguration.class).getValue(MergedAnnotation.VALUE, String.class)
.orElse("src/main/webapp");
}

View File

@@ -161,7 +161,8 @@ final class ModifiedClassPathClassLoader extends URLClassLoader {
}
private static URL[] processUrls(URL[] urls, Class<?> testClass) {
MergedAnnotations annotations = MergedAnnotations.from(testClass, MergedAnnotations.SearchStrategy.EXHAUSTIVE);
MergedAnnotations annotations = MergedAnnotations.from(testClass,
MergedAnnotations.SearchStrategy.TYPE_HIERARCHY);
ClassPathEntryFilter filter = new ClassPathEntryFilter(annotations.get(ClassPathExclusions.class));
List<URL> processedUrls = new ArrayList<>();
List<URL> additionalUrls = getAdditionalUrls(annotations.get(ClassPathOverrides.class));

View File

@@ -276,7 +276,7 @@ class BeanDefinitionLoader {
private boolean isComponent(Class<?> type) {
// This has to be a bit of a guess. The only way to be sure that this type is
// eligible is to make a bean definition out of it and try to instantiate it.
if (MergedAnnotations.from(type, SearchStrategy.EXHAUSTIVE).isPresent(Component.class)) {
if (MergedAnnotations.from(type, SearchStrategy.TYPE_HIERARCHY).isPresent(Component.class)) {
return true;
}
// Nested anonymous classes are not eligible for registration, nor are groovy

View File

@@ -48,8 +48,8 @@ final class ConfigurationPropertiesBeanDefinitionRegistrar {
}
static void register(BeanDefinitionRegistry registry, ConfigurableListableBeanFactory beanFactory, Class<?> type) {
MergedAnnotation<ConfigurationProperties> annotation = MergedAnnotations.from(type, SearchStrategy.EXHAUSTIVE)
.get(ConfigurationProperties.class);
MergedAnnotation<ConfigurationProperties> annotation = MergedAnnotations
.from(type, SearchStrategy.TYPE_HIERARCHY).get(ConfigurationProperties.class);
String name = getName(type, annotation);
if (!containsBeanDefinition(beanFactory, name)) {
registerBeanDefinition(registry, beanFactory, name, type, annotation);

View File

@@ -110,7 +110,7 @@ class ConfigurationPropertiesScanRegistrar
private void validateScanConfiguration(Class<?> type) {
MergedAnnotation<Component> component = MergedAnnotations
.from(type, MergedAnnotations.SearchStrategy.EXHAUSTIVE).get(Component.class);
.from(type, MergedAnnotations.SearchStrategy.TYPE_HIERARCHY).get(Component.class);
if (component.isPresent()) {
throw new InvalidConfigurationPropertiesException(type, component.getRoot().getType());
}

View File

@@ -80,8 +80,8 @@ public class JsonComponentModule extends SimpleModule implements BeanFactoryAwar
}
private void addJsonBean(Object bean) {
MergedAnnotation<JsonComponent> annotation = MergedAnnotations.from(bean.getClass(), SearchStrategy.EXHAUSTIVE)
.get(JsonComponent.class);
MergedAnnotation<JsonComponent> annotation = MergedAnnotations
.from(bean.getClass(), SearchStrategy.TYPE_HIERARCHY).get(JsonComponent.class);
Class<?>[] types = annotation.getClassArray("type");
Scope scope = annotation.getEnum("scope", JsonComponent.Scope.class);
addJsonBean(bean, types, scope);

View File

@@ -84,7 +84,7 @@ public class DefaultErrorAttributes implements ErrorAttributes {
errorAttributes.put("path", request.path());
Throwable error = getError(request);
MergedAnnotation<ResponseStatus> responseStatusAnnotation = MergedAnnotations
.from(error.getClass(), SearchStrategy.EXHAUSTIVE).get(ResponseStatus.class);
.from(error.getClass(), SearchStrategy.TYPE_HIERARCHY).get(ResponseStatus.class);
HttpStatus errorStatus = determineHttpStatus(error, responseStatusAnnotation);
errorAttributes.put("status", errorStatus.value());
errorAttributes.put("error", errorStatus.getReasonPhrase());

View File

@@ -119,7 +119,7 @@ public abstract class SpringBootServletInitializer implements WebApplicationInit
builder.listeners(new WebEnvironmentPropertySourceInitializer(servletContext));
SpringApplication application = builder.build();
if (application.getAllSources().isEmpty()
&& MergedAnnotations.from(getClass(), SearchStrategy.EXHAUSTIVE).isPresent(Configuration.class)) {
&& MergedAnnotations.from(getClass(), SearchStrategy.TYPE_HIERARCHY).isPresent(Configuration.class)) {
application.addPrimarySources(Collections.singleton(getClass()));
}
Assert.state(!application.getAllSources().isEmpty(),