diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/jmx/JmxEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/jmx/JmxEndpointAutoConfiguration.java index 54cb45d92be..efc7a043723 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/jmx/JmxEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/jmx/JmxEndpointAutoConfiguration.java @@ -16,8 +16,7 @@ package org.springframework.boot.actuate.autoconfigure.endpoint.jmx; -import java.util.Collection; -import java.util.Collections; +import java.util.stream.Collectors; import javax.management.MBeanServer; @@ -75,11 +74,11 @@ public class JmxEndpointAutoConfiguration { @ConditionalOnMissingBean(JmxEndpointsSupplier.class) public JmxEndpointDiscoverer jmxAnnotationEndpointDiscoverer( ParameterValueMapper parameterValueMapper, - ObjectProvider> invokerAdvisors, - ObjectProvider>> filters) { + ObjectProvider invokerAdvisors, + ObjectProvider> filters) { return new JmxEndpointDiscoverer(this.applicationContext, parameterValueMapper, - invokerAdvisors.getIfAvailable(Collections::emptyList), - filters.getIfAvailable(Collections::emptyList)); + invokerAdvisors.orderedStream().collect(Collectors.toList()), + filters.orderedStream().collect(Collectors.toList())); } @Bean diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointAutoConfiguration.java index b070cae4949..cf5c7f4991d 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointAutoConfiguration.java @@ -20,6 +20,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration; @@ -95,12 +96,12 @@ public class WebEndpointAutoConfiguration { public WebEndpointDiscoverer webEndpointDiscoverer( ParameterValueMapper parameterValueMapper, EndpointMediaTypes endpointMediaTypes, PathMapper webEndpointPathMapper, - ObjectProvider> invokerAdvisors, - ObjectProvider>> filters) { + ObjectProvider invokerAdvisors, + ObjectProvider> filters) { return new WebEndpointDiscoverer(this.applicationContext, parameterValueMapper, endpointMediaTypes, webEndpointPathMapper, - invokerAdvisors.getIfAvailable(Collections::emptyList), - filters.getIfAvailable(Collections::emptyList)); + invokerAdvisors.orderedStream().collect(Collectors.toList()), + filters.orderedStream().collect(Collectors.toList())); } @Bean @@ -144,10 +145,10 @@ public class WebEndpointAutoConfiguration { @ConditionalOnMissingBean(ServletEndpointsSupplier.class) public ServletEndpointDiscoverer servletEndpointDiscoverer( ApplicationContext applicationContext, PathMapper webEndpointPathMapper, - ObjectProvider>> filters) { + ObjectProvider> filters) { return new ServletEndpointDiscoverer(applicationContext, webEndpointPathMapper, - filters.getIfAvailable(Collections::emptyList)); + filters.orderedStream().collect(Collectors.toList())); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/info/InfoEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/info/InfoEndpointAutoConfiguration.java index 2b1583f9290..33ec1761154 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/info/InfoEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/info/InfoEndpointAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * 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"); * you may not use this file except in compliance with the License. @@ -16,8 +16,7 @@ package org.springframework.boot.actuate.autoconfigure.info; -import java.util.Collections; -import java.util.List; +import java.util.stream.Collectors; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint; @@ -42,9 +41,9 @@ public class InfoEndpointAutoConfiguration { @Bean @ConditionalOnMissingBean @ConditionalOnEnabledEndpoint - public InfoEndpoint infoEndpoint( - ObjectProvider> infoContributors) { - return new InfoEndpoint(infoContributors.getIfAvailable(Collections::emptyList)); + public InfoEndpoint infoEndpoint(ObjectProvider infoContributors) { + return new InfoEndpoint( + infoContributors.orderedStream().collect(Collectors.toList())); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthIndicatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthIndicatorAutoConfiguration.java index 9484ac44fed..496716247bb 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthIndicatorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthIndicatorAutoConfiguration.java @@ -19,6 +19,7 @@ package org.springframework.boot.actuate.autoconfigure.jdbc; import java.util.Collection; import java.util.LinkedHashMap; import java.util.Map; +import java.util.stream.Collectors; import javax.sql.DataSource; @@ -73,9 +74,10 @@ public class DataSourceHealthIndicatorAutoConfiguration extends public DataSourceHealthIndicatorAutoConfiguration( ObjectProvider> dataSources, - ObjectProvider> metadataProviders) { + ObjectProvider metadataProviders) { this.dataSources = filterDataSources(dataSources.getIfAvailable()); - this.metadataProviders = metadataProviders.getIfAvailable(); + this.metadataProviders = metadataProviders.orderedStream() + .collect(Collectors.toList()); } private Map filterDataSources( diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/scheduling/ScheduledTasksEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/scheduling/ScheduledTasksEndpointAutoConfiguration.java index 0c47fd8859a..e2ec1d5489c 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/scheduling/ScheduledTasksEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/scheduling/ScheduledTasksEndpointAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * 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"); * you may not use this file except in compliance with the License. @@ -16,8 +16,7 @@ package org.springframework.boot.actuate.autoconfigure.scheduling; -import java.util.Collections; -import java.util.List; +import java.util.stream.Collectors; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint; @@ -41,8 +40,9 @@ public class ScheduledTasksEndpointAutoConfiguration { @ConditionalOnMissingBean @ConditionalOnEnabledEndpoint public ScheduledTasksEndpoint scheduledTasksEndpoint( - ObjectProvider> holders) { - return new ScheduledTasksEndpoint(holders.getIfAvailable(Collections::emptyList)); + ObjectProvider holders) { + return new ScheduledTasksEndpoint( + holders.orderedStream().collect(Collectors.toList())); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/jersey/JerseyManagementChildContextConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/jersey/JerseyManagementChildContextConfiguration.java index 72254e309e7..c9375606bf0 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/jersey/JerseyManagementChildContextConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/jersey/JerseyManagementChildContextConfiguration.java @@ -16,8 +16,7 @@ package org.springframework.boot.actuate.autoconfigure.web.jersey; -import java.util.Collections; -import java.util.List; +import java.util.stream.Stream; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.servlet.ServletContainer; @@ -48,12 +47,11 @@ import org.springframework.context.annotation.Bean; @ConditionalOnMissingClass("org.springframework.web.servlet.DispatcherServlet") public class JerseyManagementChildContextConfiguration { - private final List resourceConfigCustomizers; + private final Stream resourceConfigCustomizers; public JerseyManagementChildContextConfiguration( - ObjectProvider> resourceConfigCustomizers) { - this.resourceConfigCustomizers = resourceConfigCustomizers - .getIfAvailable(Collections::emptyList); + ObjectProvider resourceConfigCustomizers) { + this.resourceConfigCustomizers = resourceConfigCustomizers.orderedStream(); } @Bean @@ -65,9 +63,8 @@ public class JerseyManagementChildContextConfiguration { @Bean public ResourceConfig endpointResourceConfig() { ResourceConfig resourceConfig = new ResourceConfig(); - for (ResourceConfigCustomizer customizer : this.resourceConfigCustomizers) { - customizer.customize(resourceConfig); - } + this.resourceConfigCustomizers + .forEach((customizer) -> customizer.customize(resourceConfig)); return resourceConfig; } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/mappings/MappingsEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/mappings/MappingsEndpointAutoConfiguration.java index 0236567801b..89d6d7898fe 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/mappings/MappingsEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/mappings/MappingsEndpointAutoConfiguration.java @@ -16,8 +16,7 @@ package org.springframework.boot.actuate.autoconfigure.web.mappings; -import java.util.Collection; -import java.util.Collections; +import java.util.stream.Collectors; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint; @@ -50,9 +49,9 @@ public class MappingsEndpointAutoConfiguration { @Bean @ConditionalOnEnabledEndpoint public MappingsEndpoint mappingsEndpoint(ApplicationContext applicationContext, - ObjectProvider> descriptionProviders) { + ObjectProvider descriptionProviders) { return new MappingsEndpoint( - descriptionProviders.getIfAvailable(Collections::emptyList), + descriptionProviders.orderedStream().collect(Collectors.toList()), applicationContext); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfiguration.java index c21f7ef4068..0ad49cd7412 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * 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"); * you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ package org.springframework.boot.autoconfigure.admin; -import java.util.List; - import javax.management.MalformedObjectNameException; import org.springframework.beans.factory.ObjectProvider; @@ -57,13 +55,13 @@ public class SpringApplicationAdminJmxAutoConfiguration { */ private static final String DEFAULT_JMX_NAME = "org.springframework.boot:type=Admin,name=SpringApplication"; - private final List mbeanExporters; + private final Iterable mbeanExporters; private final Environment environment; public SpringApplicationAdminJmxAutoConfiguration( - ObjectProvider> mbeanExporters, Environment environment) { - this.mbeanExporters = mbeanExporters.getIfAvailable(); + ObjectProvider mbeanExporters, Environment environment) { + this.mbeanExporters = mbeanExporters; this.environment = environment; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAnnotationDrivenConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAnnotationDrivenConfiguration.java index 68f4fd42dbb..2be022cb668 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAnnotationDrivenConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAnnotationDrivenConfiguration.java @@ -16,7 +16,7 @@ package org.springframework.boot.autoconfigure.amqp; -import java.util.List; +import java.util.stream.Collectors; import org.springframework.amqp.rabbit.annotation.EnableRabbit; import org.springframework.amqp.rabbit.config.DirectRabbitListenerContainerFactory; @@ -47,13 +47,13 @@ class RabbitAnnotationDrivenConfiguration { private final ObjectProvider messageRecoverer; - private final ObjectProvider> retryTemplateCustomizers; + private final ObjectProvider retryTemplateCustomizers; private final RabbitProperties properties; RabbitAnnotationDrivenConfiguration(ObjectProvider messageConverter, ObjectProvider messageRecoverer, - ObjectProvider> retryTemplateCustomizers, + ObjectProvider retryTemplateCustomizers, RabbitProperties properties) { this.messageConverter = messageConverter; this.messageRecoverer = messageRecoverer; @@ -67,8 +67,8 @@ class RabbitAnnotationDrivenConfiguration { SimpleRabbitListenerContainerFactoryConfigurer configurer = new SimpleRabbitListenerContainerFactoryConfigurer(); configurer.setMessageConverter(this.messageConverter.getIfUnique()); configurer.setMessageRecoverer(this.messageRecoverer.getIfUnique()); - configurer.setRetryTemplateCustomizers( - this.retryTemplateCustomizers.getIfAvailable()); + configurer.setRetryTemplateCustomizers(this.retryTemplateCustomizers + .orderedStream().collect(Collectors.toList())); configurer.setRabbitProperties(this.properties); return configurer; } @@ -90,8 +90,8 @@ class RabbitAnnotationDrivenConfiguration { DirectRabbitListenerContainerFactoryConfigurer configurer = new DirectRabbitListenerContainerFactoryConfigurer(); configurer.setMessageConverter(this.messageConverter.getIfUnique()); configurer.setMessageRecoverer(this.messageRecoverer.getIfUnique()); - configurer.setRetryTemplateCustomizers( - this.retryTemplateCustomizers.getIfAvailable()); + configurer.setRetryTemplateCustomizers(this.retryTemplateCustomizers + .orderedStream().collect(Collectors.toList())); configurer.setRabbitProperties(this.properties); return configurer; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java index 17edff75658..ec30db5fac1 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java @@ -17,7 +17,7 @@ package org.springframework.boot.autoconfigure.amqp; import java.time.Duration; -import java.util.List; +import java.util.stream.Collectors; import com.rabbitmq.client.Channel; @@ -161,11 +161,11 @@ public class RabbitAutoConfiguration { private final ObjectProvider messageConverter; - private final ObjectProvider> retryTemplateCustomizers; + private final ObjectProvider retryTemplateCustomizers; public RabbitTemplateConfiguration(RabbitProperties properties, ObjectProvider messageConverter, - ObjectProvider> retryTemplateCustomizers) { + ObjectProvider retryTemplateCustomizers) { this.properties = properties; this.messageConverter = messageConverter; this.retryTemplateCustomizers = retryTemplateCustomizers; @@ -185,8 +185,9 @@ public class RabbitAutoConfiguration { RabbitProperties.Template properties = this.properties.getTemplate(); if (properties.getRetry().isEnabled()) { template.setRetryTemplate(new RetryTemplateFactory( - this.retryTemplateCustomizers.getIfAvailable()) - .createRetryTemplate(properties.getRetry(), + this.retryTemplateCustomizers.orderedStream() + .collect(Collectors.toList())).createRetryTemplate( + properties.getRetry(), RabbitRetryTemplateCustomizer.Target.SENDER)); } map.from(properties::getReceiveTimeout).whenNonNull().as(Duration::toMillis) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfiguration.java index d5ff2058277..ec56805d2bc 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfiguration.java @@ -16,7 +16,7 @@ package org.springframework.boot.autoconfigure.cache; -import java.util.List; +import java.util.stream.Collectors; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.ObjectProvider; @@ -67,8 +67,9 @@ public class CacheAutoConfiguration { @Bean @ConditionalOnMissingBean public CacheManagerCustomizers cacheManagerCustomizers( - ObjectProvider>> customizers) { - return new CacheManagerCustomizers(customizers.getIfAvailable()); + ObjectProvider> customizers) { + return new CacheManagerCustomizers( + customizers.orderedStream().collect(Collectors.toList())); } @Bean diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.java index ec308ad0b6d..76039134583 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.util.Iterator; import java.util.List; import java.util.Properties; +import java.util.stream.Stream; import javax.cache.CacheManager; import javax.cache.Caching; @@ -42,7 +43,6 @@ import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.core.Ordered; -import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.annotation.Order; import org.springframework.core.io.Resource; import org.springframework.core.type.AnnotatedTypeMetadata; @@ -70,22 +70,22 @@ class JCacheCacheConfiguration implements BeanClassLoaderAware { private final javax.cache.configuration.Configuration defaultCacheConfiguration; - private final List cacheManagerCustomizers; + private final Stream cacheManagerCustomizers; - private final List cachePropertiesCustomizers; + private final Stream cachePropertiesCustomizers; private ClassLoader beanClassLoader; JCacheCacheConfiguration(CacheProperties cacheProperties, CacheManagerCustomizers customizers, ObjectProvider> defaultCacheConfiguration, - ObjectProvider> cacheManagerCustomizers, - ObjectProvider> cachePropertiesCustomizers) { + ObjectProvider cacheManagerCustomizers, + ObjectProvider cachePropertiesCustomizers) { this.cacheProperties = cacheProperties; this.customizers = customizers; this.defaultCacheConfiguration = defaultCacheConfiguration.getIfAvailable(); - this.cacheManagerCustomizers = cacheManagerCustomizers.getIfAvailable(); - this.cachePropertiesCustomizers = cachePropertiesCustomizers.getIfAvailable(); + this.cacheManagerCustomizers = cacheManagerCustomizers.orderedStream(); + this.cachePropertiesCustomizers = cachePropertiesCustomizers.orderedStream(); } @Override @@ -135,11 +135,8 @@ class JCacheCacheConfiguration implements BeanClassLoaderAware { private Properties createCacheManagerProperties() { Properties properties = new Properties(); - if (this.cachePropertiesCustomizers != null) { - for (JCachePropertiesCustomizer customizer : this.cachePropertiesCustomizers) { - customizer.customize(this.cacheProperties, properties); - } - } + this.cachePropertiesCustomizers.forEach( + (customizer) -> customizer.customize(this.cacheProperties, properties)); return properties; } @@ -151,12 +148,8 @@ class JCacheCacheConfiguration implements BeanClassLoaderAware { } private void customize(CacheManager cacheManager) { - if (this.cacheManagerCustomizers != null) { - AnnotationAwareOrderComparator.sort(this.cacheManagerCustomizers); - for (JCacheManagerCustomizer customizer : this.cacheManagerCustomizers) { - customizer.customize(cacheManager); - } - } + this.cacheManagerCustomizers + .forEach((customizer) -> customizer.customize(cacheManager)); } /** diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java index bfc9b4776a1..1fc46a84490 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java @@ -17,7 +17,7 @@ package org.springframework.boot.autoconfigure.cassandra; import java.time.Duration; -import java.util.List; +import java.util.stream.Stream; import com.datastax.driver.core.Cluster; import com.datastax.driver.core.PoolingOptions; @@ -51,12 +51,12 @@ public class CassandraAutoConfiguration { private final CassandraProperties properties; - private final List builderCustomizers; + private final Stream builderCustomizers; public CassandraAutoConfiguration(CassandraProperties properties, - ObjectProvider> builderCustomizers) { + ObjectProvider builderCustomizers) { this.properties = properties; - this.builderCustomizers = builderCustomizers.getIfAvailable(); + this.builderCustomizers = builderCustomizers.orderedStream(); } @Bean @@ -88,11 +88,7 @@ public class CassandraAutoConfiguration { } private void customize(Cluster.Builder builder) { - if (this.builderCustomizers != null) { - for (ClusterBuilderCustomizer customizer : this.builderCustomizers) { - customizer.customize(builder); - } - } + this.builderCustomizers.forEach((customizer) -> customizer.customize(builder)); } private QueryOptions getQueryOptions() { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java index 8d5d33fa588..15b763ab6d5 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java @@ -70,15 +70,10 @@ public class Neo4jDataAutoConfiguration { @Bean public SessionFactory sessionFactory(org.neo4j.ogm.config.Configuration configuration, ApplicationContext applicationContext, - ObjectProvider> eventListeners) { + ObjectProvider eventListeners) { SessionFactory sessionFactory = new SessionFactory(configuration, getPackagesToScan(applicationContext)); - List providedEventListeners = eventListeners.getIfAvailable(); - if (providedEventListeners != null) { - for (EventListener eventListener : providedEventListeners) { - sessionFactory.register(eventListener); - } - } + eventListeners.stream().forEach(sessionFactory::register); return sessionFactory; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/JedisConnectionConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/JedisConnectionConfiguration.java index e4d5a40b172..21a19b136b2 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/JedisConnectionConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/JedisConnectionConfiguration.java @@ -1,5 +1,5 @@ /* - * 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"); * you may not use this file except in compliance with the License. @@ -18,8 +18,7 @@ package org.springframework.boot.autoconfigure.data.redis; import java.net.UnknownHostException; import java.time.Duration; -import java.util.Collections; -import java.util.List; +import java.util.stream.Stream; import org.apache.commons.pool2.impl.GenericObjectPool; import redis.clients.jedis.Jedis; @@ -51,16 +50,15 @@ class JedisConnectionConfiguration extends RedisConnectionConfiguration { private final RedisProperties properties; - private final List builderCustomizers; + private final Stream builderCustomizers; JedisConnectionConfiguration(RedisProperties properties, ObjectProvider sentinelConfiguration, ObjectProvider clusterConfiguration, - ObjectProvider> builderCustomizers) { + ObjectProvider builderCustomizers) { super(properties, sentinelConfiguration, clusterConfiguration); this.properties = properties; - this.builderCustomizers = builderCustomizers - .getIfAvailable(Collections::emptyList); + this.builderCustomizers = builderCustomizers.orderedStream(); } @Bean @@ -133,9 +131,7 @@ class JedisConnectionConfiguration extends RedisConnectionConfiguration { private void customize( JedisClientConfiguration.JedisClientConfigurationBuilder builder) { - for (JedisClientConfigurationBuilderCustomizer customizer : this.builderCustomizers) { - customizer.customize(builder); - } + this.builderCustomizers.forEach((customizer) -> customizer.customize(builder)); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/LettuceConnectionConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/LettuceConnectionConfiguration.java index 7adbc364bde..2bd846d5812 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/LettuceConnectionConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/LettuceConnectionConfiguration.java @@ -17,8 +17,7 @@ package org.springframework.boot.autoconfigure.data.redis; import java.net.UnknownHostException; -import java.util.Collections; -import java.util.List; +import java.util.stream.Stream; import io.lettuce.core.RedisClient; import io.lettuce.core.resource.ClientResources; @@ -52,16 +51,15 @@ class LettuceConnectionConfiguration extends RedisConnectionConfiguration { private final RedisProperties properties; - private final List builderCustomizers; + private final Stream builderCustomizers; LettuceConnectionConfiguration(RedisProperties properties, ObjectProvider sentinelConfigurationProvider, ObjectProvider clusterConfigurationProvider, - ObjectProvider> builderCustomizers) { + ObjectProvider builderCustomizers) { super(properties, sentinelConfigurationProvider, clusterConfigurationProvider); this.properties = properties; - this.builderCustomizers = builderCustomizers - .getIfAvailable(Collections::emptyList); + this.builderCustomizers = builderCustomizers.orderedStream(); } @Bean(destroyMethod = "shutdown") @@ -139,9 +137,7 @@ class LettuceConnectionConfiguration extends RedisConnectionConfiguration { private void customize( LettuceClientConfiguration.LettuceClientConfigurationBuilder builder) { - for (LettuceClientConfigurationBuilderCustomizer customizer : this.builderCustomizers) { - customizer.customize(builder); - } + this.builderCustomizers.forEach((customizer) -> customizer.customize(builder)); } /** diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/jest/JestAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/jest/JestAutoConfiguration.java index 02fa06ca908..109f6d85584 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/jest/JestAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/jest/JestAutoConfiguration.java @@ -17,7 +17,7 @@ package org.springframework.boot.autoconfigure.elasticsearch.jest; import java.time.Duration; -import java.util.List; +import java.util.stream.Stream; import com.google.gson.Gson; import io.searchbox.client.JestClient; @@ -54,13 +54,13 @@ public class JestAutoConfiguration { private final ObjectProvider gsonProvider; - private final List builderCustomizers; + private final Stream builderCustomizers; public JestAutoConfiguration(JestProperties properties, ObjectProvider gson, - ObjectProvider> builderCustomizers) { + ObjectProvider builderCustomizers) { this.properties = properties; this.gsonProvider = gson; - this.builderCustomizers = builderCustomizers.getIfAvailable(); + this.builderCustomizers = builderCustomizers.orderedStream(); } @Bean(destroyMethod = "shutdownClient") @@ -93,11 +93,7 @@ public class JestAutoConfiguration { } private void customize(HttpClientConfig.Builder builder) { - if (this.builderCustomizers != null) { - for (HttpClientConfigBuilderCustomizer customizer : this.builderCustomizers) { - customizer.customize(builder); - } - } + this.builderCustomizers.forEach((customizer) -> customizer.customize(builder)); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientAutoConfiguration.java index 9598af3432d..a46a58c75c2 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientAutoConfiguration.java @@ -16,8 +16,7 @@ package org.springframework.boot.autoconfigure.elasticsearch.rest; -import java.util.Collections; -import java.util.List; +import java.util.stream.Stream; import org.apache.http.HttpHost; import org.apache.http.auth.AuthScope; @@ -51,13 +50,12 @@ public class RestClientAutoConfiguration { private final RestClientProperties properties; - private final List builderCustomizers; + private final Stream builderCustomizers; public RestClientAutoConfiguration(RestClientProperties properties, - ObjectProvider> builderCustomizers) { + ObjectProvider builderCustomizers) { this.properties = properties; - this.builderCustomizers = builderCustomizers - .getIfAvailable(Collections::emptyList); + this.builderCustomizers = builderCustomizers.orderedStream(); } @Bean diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java index bd66b057a79..79482d75f2c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java @@ -23,6 +23,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.function.Supplier; +import java.util.stream.Collectors; import javax.persistence.EntityManagerFactory; import javax.sql.DataSource; @@ -92,9 +93,8 @@ public class FlywayAutoConfiguration { @Bean public FlywaySchemaManagementProvider flywayDefaultDdlModeProvider( - ObjectProvider> flyways) { - return new FlywaySchemaManagementProvider( - flyways.getIfAvailable(Collections::emptyList)); + ObjectProvider flyways) { + return new FlywaySchemaManagementProvider(flyways); } @Configuration @@ -123,16 +123,17 @@ public class FlywayAutoConfiguration { ObjectProvider dataSource, @FlywayDataSource ObjectProvider flywayDataSource, ObjectProvider migrationStrategy, - ObjectProvider> callbacks, - ObjectProvider> flywayCallbacks) { + ObjectProvider callbacks, + ObjectProvider flywayCallbacks) { this.properties = properties; this.dataSourceProperties = dataSourceProperties; this.resourceLoader = resourceLoader; this.dataSource = dataSource.getIfUnique(); this.flywayDataSource = flywayDataSource.getIfAvailable(); this.migrationStrategy = migrationStrategy.getIfAvailable(); - this.callbacks = callbacks.getIfAvailable(Collections::emptyList); - this.flywayCallbacks = flywayCallbacks.getIfAvailable(Collections::emptyList); + this.callbacks = callbacks.orderedStream().collect(Collectors.toList()); + this.flywayCallbacks = flywayCallbacks.orderedStream() + .collect(Collectors.toList()); } @Bean diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywaySchemaManagementProvider.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywaySchemaManagementProvider.java index f31e92b2892..47a75ca5de8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywaySchemaManagementProvider.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywaySchemaManagementProvider.java @@ -1,5 +1,5 @@ /* - * 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"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package org.springframework.boot.autoconfigure.flyway; -import java.util.List; +import java.util.stream.StreamSupport; import javax.sql.DataSource; @@ -33,20 +33,18 @@ import org.springframework.boot.jdbc.SchemaManagementProvider; */ class FlywaySchemaManagementProvider implements SchemaManagementProvider { - private final List flywayInstances; + private final Iterable flywayInstances; - FlywaySchemaManagementProvider(List flywayInstances) { + FlywaySchemaManagementProvider(Iterable flywayInstances) { this.flywayInstances = flywayInstances; } @Override public SchemaManagement getSchemaManagement(DataSource dataSource) { - for (Flyway flywayInstance : this.flywayInstances) { - if (dataSource.equals(flywayInstance.getDataSource())) { - return SchemaManagement.MANAGED; - } - } - return SchemaManagement.UNMANAGED; + return StreamSupport.stream(this.flywayInstances.spliterator(), false) + .map(Flyway::getDataSource).filter(dataSource::equals).findFirst() + .map((managedDataSource) -> SchemaManagement.MANAGED) + .orElse(SchemaManagement.UNMANAGED); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/HttpMessageConvertersAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/HttpMessageConvertersAutoConfiguration.java index 6a50195520c..d412a1d4636 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/HttpMessageConvertersAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/HttpMessageConvertersAutoConfiguration.java @@ -16,8 +16,8 @@ package org.springframework.boot.autoconfigure.http; -import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.AutoConfigureAfter; @@ -61,15 +61,14 @@ public class HttpMessageConvertersAutoConfiguration { private final List> converters; public HttpMessageConvertersAutoConfiguration( - ObjectProvider>> convertersProvider) { - this.converters = convertersProvider.getIfAvailable(); + ObjectProvider> convertersProvider) { + this.converters = convertersProvider.orderedStream().collect(Collectors.toList()); } @Bean @ConditionalOnMissingBean public HttpMessageConverters messageConverters() { - return new HttpMessageConverters( - (this.converters != null) ? this.converters : Collections.emptyList()); + return new HttpMessageConverters(this.converters); } @Configuration diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfiguration.java index fd8a54779f5..2d5b2923abf 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfiguration.java @@ -18,7 +18,7 @@ package org.springframework.boot.autoconfigure.jersey; import java.util.Arrays; import java.util.EnumSet; -import java.util.List; +import java.util.stream.Stream; import javax.annotation.PostConstruct; import javax.servlet.DispatcherType; @@ -60,7 +60,6 @@ import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; -import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.annotation.Order; import org.springframework.util.ClassUtils; @@ -94,15 +93,15 @@ public class JerseyAutoConfiguration implements ServletContextAware { private final ResourceConfig config; - private final List customizers; + private final Stream customizers; private String path; public JerseyAutoConfiguration(JerseyProperties jersey, ResourceConfig config, - ObjectProvider> customizers) { + ObjectProvider customizers) { this.jersey = jersey; this.config = config; - this.customizers = customizers.getIfAvailable(); + this.customizers = customizers.orderedStream(); } @PostConstruct @@ -122,12 +121,7 @@ public class JerseyAutoConfiguration implements ServletContextAware { } private void customize() { - if (this.customizers != null) { - AnnotationAwareOrderComparator.sort(this.customizers); - for (ResourceConfigCustomizer customizer : this.customizers) { - customizer.customize(this.config); - } - } + this.customizers.forEach((customizer) -> customizer.customize(this.config)); } @Bean diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java index 3eeaddceb42..a7116b379f7 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java @@ -17,6 +17,7 @@ package org.springframework.boot.autoconfigure.jms.activemq; import java.util.List; +import java.util.stream.Collectors; import javax.jms.ConnectionFactory; @@ -61,11 +62,11 @@ class ActiveMQConnectionFactoryConfiguration { SimpleConnectionFactoryConfiguration(JmsProperties jmsProperties, ActiveMQProperties properties, - ObjectProvider> connectionFactoryCustomizers) { + ObjectProvider connectionFactoryCustomizers) { this.jmsProperties = jmsProperties; this.properties = properties; this.connectionFactoryCustomizers = connectionFactoryCustomizers - .getIfAvailable(); + .orderedStream().collect(Collectors.toList()); } @Bean @@ -102,9 +103,10 @@ class ActiveMQConnectionFactoryConfiguration { @ConditionalOnProperty(prefix = "spring.activemq.pool", name = "enabled", havingValue = "true", matchIfMissing = false) public JmsPoolConnectionFactory pooledJmsConnectionFactory( ActiveMQProperties properties, - ObjectProvider> factoryCustomizers) { + ObjectProvider factoryCustomizers) { ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactoryFactory( - properties, factoryCustomizers.getIfAvailable()) + properties, + factoryCustomizers.orderedStream().collect(Collectors.toList())) .createConnectionFactory(ActiveMQConnectionFactory.class); return new JmsPoolConnectionFactoryFactory(properties.getPool()) .createPooledConnectionFactory(connectionFactory); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQXAConnectionFactoryConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQXAConnectionFactoryConfiguration.java index 42d2506e943..dcb9aa62fe5 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQXAConnectionFactoryConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQXAConnectionFactoryConfiguration.java @@ -16,7 +16,7 @@ package org.springframework.boot.autoconfigure.jms.activemq; -import java.util.List; +import java.util.stream.Collectors; import javax.jms.ConnectionFactory; import javax.transaction.TransactionManager; @@ -50,10 +50,11 @@ class ActiveMQXAConnectionFactoryConfiguration { @Primary @Bean(name = { "jmsConnectionFactory", "xaJmsConnectionFactory" }) public ConnectionFactory jmsConnectionFactory(ActiveMQProperties properties, - ObjectProvider> factoryCustomizers, + ObjectProvider factoryCustomizers, XAConnectionFactoryWrapper wrapper) throws Exception { ActiveMQXAConnectionFactory connectionFactory = new ActiveMQConnectionFactoryFactory( - properties, factoryCustomizers.getIfAvailable()) + properties, + factoryCustomizers.orderedStream().collect(Collectors.toList())) .createConnectionFactory(ActiveMQXAConnectionFactory.class); return wrapper.wrapConnectionFactory(connectionFactory); } @@ -62,9 +63,9 @@ class ActiveMQXAConnectionFactoryConfiguration { @ConditionalOnProperty(prefix = "spring.activemq.pool", name = "enabled", havingValue = "false", matchIfMissing = true) public ActiveMQConnectionFactory nonXaJmsConnectionFactory( ActiveMQProperties properties, - ObjectProvider> factoryCustomizers) { + ObjectProvider factoryCustomizers) { return new ActiveMQConnectionFactoryFactory(properties, - factoryCustomizers.getIfAvailable()) + factoryCustomizers.orderedStream().collect(Collectors.toList())) .createConnectionFactory(ActiveMQConnectionFactory.class); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisEmbeddedServerConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisEmbeddedServerConfiguration.java index 938875f9bf0..d6847cafa30 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisEmbeddedServerConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisEmbeddedServerConfiguration.java @@ -1,5 +1,5 @@ /* - * 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"); * you may not use this file except in compliance with the License. @@ -18,6 +18,8 @@ package org.springframework.boot.autoconfigure.jms.artemis; import java.util.Collection; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.apache.activemq.artemis.jms.server.config.JMSConfiguration; import org.apache.activemq.artemis.jms.server.config.JMSQueueConfiguration; @@ -33,7 +35,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.core.annotation.AnnotationAwareOrderComparator; /** * Configuration used to create the embedded Artemis server. @@ -49,20 +50,22 @@ class ArtemisEmbeddedServerConfiguration { private final ArtemisProperties properties; - private final List configurationCustomizers; + private final Stream configurationCustomizers; private final List queuesConfiguration; private final List topicsConfiguration; ArtemisEmbeddedServerConfiguration(ArtemisProperties properties, - ObjectProvider> configurationCustomizers, - ObjectProvider> queuesConfiguration, - ObjectProvider> topicsConfiguration) { + ObjectProvider configurationCustomizers, + ObjectProvider queuesConfiguration, + ObjectProvider topicsConfiguration) { this.properties = properties; - this.configurationCustomizers = configurationCustomizers.getIfAvailable(); - this.queuesConfiguration = queuesConfiguration.getIfAvailable(); - this.topicsConfiguration = topicsConfiguration.getIfAvailable(); + this.configurationCustomizers = configurationCustomizers.orderedStream(); + this.queuesConfiguration = queuesConfiguration.orderedStream() + .collect(Collectors.toList()); + this.topicsConfiguration = topicsConfiguration.orderedStream() + .collect(Collectors.toList()); } @Bean @@ -87,12 +90,8 @@ class ArtemisEmbeddedServerConfiguration { private void customize( org.apache.activemq.artemis.core.config.Configuration configuration) { - if (this.configurationCustomizers != null) { - AnnotationAwareOrderComparator.sort(this.configurationCustomizers); - for (ArtemisConfigurationCustomizer customizer : this.configurationCustomizers) { - customizer.customize(configuration); - } - } + this.configurationCustomizers + .forEach((customizer) -> customizer.customize(configuration)); } @Bean diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java index 06675abae97..cb42a581ae7 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java @@ -17,8 +17,6 @@ package org.springframework.boot.autoconfigure.liquibase; import java.lang.reflect.Method; -import java.util.Collections; -import java.util.List; import java.util.function.Supplier; import javax.annotation.PostConstruct; @@ -75,9 +73,8 @@ public class LiquibaseAutoConfiguration { @Bean public LiquibaseSchemaManagementProvider liquibaseDefaultDdlModeProvider( - ObjectProvider> liquibases) { - return new LiquibaseSchemaManagementProvider( - liquibases.getIfAvailable(Collections::emptyList)); + ObjectProvider liquibases) { + return new LiquibaseSchemaManagementProvider(liquibases); } @Configuration diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseSchemaManagementProvider.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseSchemaManagementProvider.java index 53aebf89276..773d40c63cd 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseSchemaManagementProvider.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseSchemaManagementProvider.java @@ -1,5 +1,5 @@ /* - * 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"); * you may not use this file except in compliance with the License. @@ -16,12 +16,13 @@ package org.springframework.boot.autoconfigure.liquibase; -import java.util.List; +import java.util.stream.StreamSupport; import javax.sql.DataSource; import liquibase.integration.spring.SpringLiquibase; +import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.jdbc.SchemaManagement; import org.springframework.boot.jdbc.SchemaManagementProvider; @@ -33,20 +34,18 @@ import org.springframework.boot.jdbc.SchemaManagementProvider; */ class LiquibaseSchemaManagementProvider implements SchemaManagementProvider { - private final List liquibaseInstances; + private final Iterable liquibaseInstances; - LiquibaseSchemaManagementProvider(List liquibases) { + LiquibaseSchemaManagementProvider(ObjectProvider liquibases) { this.liquibaseInstances = liquibases; } @Override public SchemaManagement getSchemaManagement(DataSource dataSource) { - for (SpringLiquibase liquibaseInstance : this.liquibaseInstances) { - if (dataSource.equals(liquibaseInstance.getDataSource())) { - return SchemaManagement.MANAGED; - } - } - return SchemaManagement.UNMANAGED; + return StreamSupport.stream(this.liquibaseInstances.spliterator(), false) + .map(SpringLiquibase::getDataSource).filter(dataSource::equals) + .findFirst().map((managedDataSource) -> SchemaManagement.MANAGED) + .orElse(SchemaManagement.UNMANAGED); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfiguration.java index 50388953244..390edb1007d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfiguration.java @@ -16,7 +16,7 @@ package org.springframework.boot.autoconfigure.mongo; -import java.util.List; +import java.util.stream.Collectors; import javax.annotation.PreDestroy; @@ -68,9 +68,10 @@ public class MongoReactiveAutoConfiguration { @ConditionalOnMissingBean public MongoClient reactiveStreamsMongoClient(MongoProperties properties, Environment environment, - ObjectProvider> builderCustomizers) { + ObjectProvider builderCustomizers) { ReactiveMongoClientFactory factory = new ReactiveMongoClientFactory(properties, - environment, builderCustomizers.getIfAvailable()); + environment, + builderCustomizers.orderedStream().collect(Collectors.toList())); this.mongo = factory.createMongoClient(this.settings); return this.mongo; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateDefaultDdlAutoProvider.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateDefaultDdlAutoProvider.java index f5ea3765630..eb1c72e6f8c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateDefaultDdlAutoProvider.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateDefaultDdlAutoProvider.java @@ -1,5 +1,5 @@ /* - * 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"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package org.springframework.boot.autoconfigure.orm.jpa; -import java.util.List; +import java.util.stream.StreamSupport; import javax.sql.DataSource; @@ -32,9 +32,9 @@ import org.springframework.boot.jdbc.SchemaManagementProvider; */ class HibernateDefaultDdlAutoProvider implements SchemaManagementProvider { - private final List providers; + private final Iterable providers; - HibernateDefaultDdlAutoProvider(List providers) { + HibernateDefaultDdlAutoProvider(Iterable providers) { this.providers = providers; } @@ -52,13 +52,10 @@ class HibernateDefaultDdlAutoProvider implements SchemaManagementProvider { @Override public SchemaManagement getSchemaManagement(DataSource dataSource) { - for (SchemaManagementProvider provider : this.providers) { - SchemaManagement schemaManagement = provider.getSchemaManagement(dataSource); - if (SchemaManagement.MANAGED.equals(schemaManagement)) { - return schemaManagement; - } - } - return SchemaManagement.UNMANAGED; + return StreamSupport.stream(this.providers.spliterator(), false) + .map((provider) -> provider.getSchemaManagement(dataSource)) + .filter(SchemaManagement.MANAGED::equals).findFirst() + .orElse(SchemaManagement.UNMANAGED); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.java index 64b18919607..b468a6f875c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.java @@ -18,12 +18,12 @@ package org.springframework.boot.autoconfigure.orm.jpa; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.function.Supplier; +import java.util.stream.Collectors; import javax.sql.DataSource; @@ -89,21 +89,20 @@ class HibernateJpaConfiguration extends JpaBaseConfiguration { ObjectProvider transactionManagerCustomizers, HibernateProperties hibernateProperties, ObjectProvider> metadataProviders, - ObjectProvider> providers, + ObjectProvider providers, ObjectProvider physicalNamingStrategy, ObjectProvider implicitNamingStrategy, - ObjectProvider> hibernatePropertiesCustomizers) { + ObjectProvider hibernatePropertiesCustomizers) { super(dataSource, jpaProperties, jtaTransactionManager, transactionManagerCustomizers); this.hibernateProperties = hibernateProperties; - this.defaultDdlAutoProvider = new HibernateDefaultDdlAutoProvider( - providers.getIfAvailable(Collections::emptyList)); + this.defaultDdlAutoProvider = new HibernateDefaultDdlAutoProvider(providers); this.poolMetadataProvider = new CompositeDataSourcePoolMetadataProvider( metadataProviders.getIfAvailable()); this.hibernatePropertiesCustomizers = determineHibernatePropertiesCustomizers( physicalNamingStrategy.getIfAvailable(), - implicitNamingStrategy.getIfAvailable(), - hibernatePropertiesCustomizers.getIfAvailable(Collections::emptyList)); + implicitNamingStrategy.getIfAvailable(), hibernatePropertiesCustomizers + .orderedStream().collect(Collectors.toList())); } private List determineHibernatePropertiesCustomizers( diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java index d7dd669813b..56a03693751 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java @@ -16,7 +16,6 @@ package org.springframework.boot.autoconfigure.orm.jpa; -import java.util.Collections; import java.util.List; import java.util.Map; @@ -121,14 +120,12 @@ public abstract class JpaBaseConfiguration implements BeanFactoryAware { public EntityManagerFactoryBuilder entityManagerFactoryBuilder( JpaVendorAdapter jpaVendorAdapter, ObjectProvider persistenceUnitManager, - ObjectProvider> customizers) { + ObjectProvider customizers) { EntityManagerFactoryBuilder builder = new EntityManagerFactoryBuilder( jpaVendorAdapter, this.properties.getProperties(), persistenceUnitManager.getIfAvailable()); - for (EntityManagerFactoryBuilderCustomizer customizer : customizers - .getIfAvailable(Collections::emptyList)) { - customizer.customize(builder); - } + customizers.orderedStream() + .forEach((customizer) -> customizer.customize(builder)); return builder; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfiguration.java index 658010ae7c3..0f9ff19bc47 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfiguration.java @@ -16,9 +16,9 @@ package org.springframework.boot.autoconfigure.quartz; -import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.stream.Stream; import javax.sql.DataSource; @@ -61,7 +61,7 @@ public class QuartzAutoConfiguration { private final QuartzProperties properties; - private final List customizers; + private final Stream customizers; private final JobDetail[] jobDetails; @@ -72,12 +72,12 @@ public class QuartzAutoConfiguration { private final ApplicationContext applicationContext; public QuartzAutoConfiguration(QuartzProperties properties, - ObjectProvider> customizers, + ObjectProvider customizers, ObjectProvider jobDetails, ObjectProvider> calendars, ObjectProvider triggers, ApplicationContext applicationContext) { this.properties = properties; - this.customizers = customizers.getIfAvailable(); + this.customizers = customizers.orderedStream(); this.jobDetails = jobDetails.getIfAvailable(); this.calendars = calendars.getIfAvailable(); this.triggers = triggers.getIfAvailable(); @@ -124,11 +124,8 @@ public class QuartzAutoConfiguration { } private void customize(SchedulerFactoryBean schedulerFactoryBean) { - if (this.customizers != null) { - for (SchedulerFactoryBeanCustomizer customizer : this.customizers) { - customizer.customize(schedulerFactoryBean); - } - } + this.customizers + .forEach((customizer) -> customizer.customize(schedulerFactoryBean)); } @Configuration diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java index 97c9d783a66..97e308db1d9 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java @@ -17,8 +17,8 @@ package org.springframework.boot.autoconfigure.thymeleaf; import java.util.Collection; -import java.util.Collections; import java.util.LinkedHashMap; +import java.util.stream.Stream; import javax.annotation.PostConstruct; @@ -136,14 +136,14 @@ public class ThymeleafAutoConfiguration { private final Collection templateResolvers; - private final Collection dialects; + private final Stream dialects; public ThymeleafDefaultConfiguration(ThymeleafProperties properties, Collection templateResolvers, - ObjectProvider> dialectsProvider) { + ObjectProvider dialectsProvider) { this.properties = properties; this.templateResolvers = templateResolvers; - this.dialects = dialectsProvider.getIfAvailable(Collections::emptyList); + this.dialects = dialectsProvider.orderedStream(); } @Bean @@ -224,14 +224,14 @@ public class ThymeleafAutoConfiguration { private final Collection templateResolvers; - private final Collection dialects; + private final Stream dialects; ThymeleafReactiveConfiguration(ThymeleafProperties properties, Collection templateResolvers, - ObjectProvider> dialectsProvider) { + ObjectProvider dialectsProvider) { this.properties = properties; this.templateResolvers = templateResolvers; - this.dialects = dialectsProvider.getIfAvailable(Collections::emptyList); + this.dialects = dialectsProvider.orderedStream(); } @Bean diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionAutoConfiguration.java index 2f65e1c1464..4a0b3ad202e 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionAutoConfiguration.java @@ -16,7 +16,7 @@ package org.springframework.boot.autoconfigure.transaction; -import java.util.List; +import java.util.stream.Collectors; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.AutoConfigureAfter; @@ -55,8 +55,9 @@ public class TransactionAutoConfiguration { @Bean @ConditionalOnMissingBean public TransactionManagerCustomizers platformTransactionManagerCustomizers( - ObjectProvider>> customizers) { - return new TransactionManagerCustomizers(customizers.getIfAvailable()); + ObjectProvider> customizers) { + return new TransactionManagerCustomizers( + customizers.orderedStream().collect(Collectors.toList())); } @Configuration diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfiguration.java index b35208c93c2..620f044e0a5 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * 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"); * you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ package org.springframework.boot.autoconfigure.web.client; -import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.AutoConfigureAfter; @@ -30,7 +30,6 @@ import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.boot.web.client.RestTemplateCustomizer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.util.CollectionUtils; import org.springframework.web.client.RestTemplate; @@ -48,11 +47,11 @@ public class RestTemplateAutoConfiguration { private final ObjectProvider messageConverters; - private final ObjectProvider> restTemplateCustomizers; + private final ObjectProvider restTemplateCustomizers; public RestTemplateAutoConfiguration( ObjectProvider messageConverters, - ObjectProvider> restTemplateCustomizers) { + ObjectProvider restTemplateCustomizers) { this.messageConverters = messageConverters; this.restTemplateCustomizers = restTemplateCustomizers; } @@ -65,11 +64,10 @@ public class RestTemplateAutoConfiguration { if (converters != null) { builder = builder.messageConverters(converters.getConverters()); } + List customizers = this.restTemplateCustomizers - .getIfAvailable(); + .orderedStream().collect(Collectors.toList()); if (!CollectionUtils.isEmpty(customizers)) { - customizers = new ArrayList<>(customizers); - AnnotationAwareOrderComparator.sort(customizers); builder = builder.customizers(customizers); } return builder; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration.java index bc8e2a38a59..a58463aebe0 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration.java @@ -18,8 +18,8 @@ package org.springframework.boot.autoconfigure.web.reactive; import java.time.Duration; import java.util.Collection; -import java.util.List; import java.util.concurrent.TimeUnit; +import java.util.stream.Stream; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -46,7 +46,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.core.Ordered; -import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.GenericConverter; import org.springframework.format.Formatter; @@ -115,43 +114,39 @@ public class WebFluxAutoConfiguration { private final ListableBeanFactory beanFactory; - private final List argumentResolvers; + private final Stream argumentResolvers; - private final List codecCustomizers; + private final Stream codecCustomizers; private final ResourceHandlerRegistrationCustomizer resourceHandlerRegistrationCustomizer; - private final List viewResolvers; + private final Stream viewResolvers; public WebFluxConfig(ResourceProperties resourceProperties, WebFluxProperties webFluxProperties, ListableBeanFactory beanFactory, - ObjectProvider> resolvers, - ObjectProvider> codecCustomizers, + ObjectProvider resolvers, + ObjectProvider codecCustomizers, ObjectProvider resourceHandlerRegistrationCustomizer, - ObjectProvider> viewResolvers) { + ObjectProvider viewResolvers) { this.resourceProperties = resourceProperties; this.webFluxProperties = webFluxProperties; this.beanFactory = beanFactory; - this.argumentResolvers = resolvers.getIfAvailable(); - this.codecCustomizers = codecCustomizers.getIfAvailable(); + this.argumentResolvers = resolvers.orderedStream(); + this.codecCustomizers = codecCustomizers.orderedStream(); this.resourceHandlerRegistrationCustomizer = resourceHandlerRegistrationCustomizer .getIfAvailable(); - this.viewResolvers = viewResolvers.getIfAvailable(); + this.viewResolvers = viewResolvers.orderedStream(); } @Override public void configureArgumentResolvers(ArgumentResolverConfigurer configurer) { - if (this.argumentResolvers != null) { - this.argumentResolvers.forEach(configurer::addCustomResolver); - } + this.argumentResolvers.forEach(configurer::addCustomResolver); } @Override public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) { - if (this.codecCustomizers != null) { - this.codecCustomizers - .forEach((customizer) -> customizer.customize(configurer)); - } + this.codecCustomizers + .forEach((customizer) -> customizer.customize(configurer)); } @Override @@ -186,10 +181,7 @@ public class WebFluxAutoConfiguration { @Override public void configureViewResolvers(ViewResolverRegistry registry) { - if (this.viewResolvers != null) { - AnnotationAwareOrderComparator.sort(this.viewResolvers); - this.viewResolvers.forEach(registry::viewResolver); - } + this.viewResolvers.forEach(registry::viewResolver); } @Override diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/ErrorWebFluxAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/ErrorWebFluxAutoConfiguration.java index 81d14a8e943..40d66dd0102 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/ErrorWebFluxAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/ErrorWebFluxAutoConfiguration.java @@ -16,8 +16,8 @@ package org.springframework.boot.autoconfigure.web.reactive.error; -import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.AutoConfigureBefore; @@ -67,14 +67,14 @@ public class ErrorWebFluxAutoConfiguration { public ErrorWebFluxAutoConfiguration(ServerProperties serverProperties, ResourceProperties resourceProperties, - ObjectProvider> viewResolversProvider, + ObjectProvider viewResolversProvider, ServerCodecConfigurer serverCodecConfigurer, ApplicationContext applicationContext) { this.serverProperties = serverProperties; this.applicationContext = applicationContext; this.resourceProperties = resourceProperties; - this.viewResolvers = viewResolversProvider - .getIfAvailable(() -> Collections.emptyList()); + this.viewResolvers = viewResolversProvider.orderedStream() + .collect(Collectors.toList()); this.serverCodecConfigurer = serverCodecConfigurer; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/function/client/WebClientAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/function/client/WebClientAutoConfiguration.java index f775d406125..81123298e2d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/function/client/WebClientAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/function/client/WebClientAutoConfiguration.java @@ -16,7 +16,6 @@ package org.springframework.boot.autoconfigure.web.reactive.function.client; -import java.util.ArrayList; import java.util.List; import org.springframework.beans.factory.ObjectProvider; @@ -31,9 +30,7 @@ import org.springframework.boot.web.reactive.function.client.WebClientCustomizer import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Scope; -import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.annotation.Order; -import org.springframework.util.CollectionUtils; import org.springframework.web.reactive.function.client.WebClient; /** @@ -56,15 +53,10 @@ public class WebClientAutoConfiguration { private final WebClient.Builder webClientBuilder; public WebClientAutoConfiguration( - ObjectProvider> customizerProvider) { + ObjectProvider customizerProvider) { this.webClientBuilder = WebClient.builder(); - List customizers = customizerProvider.getIfAvailable(); - if (!CollectionUtils.isEmpty(customizers)) { - customizers = new ArrayList<>(customizers); - AnnotationAwareOrderComparator.sort(customizers); - customizers - .forEach((customizer) -> customizer.customize(this.webClientBuilder)); - } + customizerProvider.orderedStream() + .forEach((customizer) -> customizer.customize(this.webClientBuilder)); } @Bean diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/error/ErrorMvcAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/error/ErrorMvcAutoConfiguration.java index 7622691600a..d1f6a8a527e 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/error/ErrorMvcAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/error/ErrorMvcAutoConfiguration.java @@ -20,6 +20,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import javax.servlet.Servlet; import javax.servlet.http.HttpServletRequest; @@ -103,10 +104,11 @@ public class ErrorMvcAutoConfiguration { public ErrorMvcAutoConfiguration(ServerProperties serverProperties, DispatcherServletPath dispatcherServletPath, - ObjectProvider> errorViewResolversProvider) { + ObjectProvider errorViewResolvers) { this.serverProperties = serverProperties; this.dispatcherServletPath = dispatcherServletPath; - this.errorViewResolvers = errorViewResolversProvider.getIfAvailable(); + this.errorViewResolvers = errorViewResolvers.orderedStream() + .collect(Collectors.toList()); } @Bean diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/client/WebServiceTemplateAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/client/WebServiceTemplateAutoConfiguration.java index d7a2edfeb24..ced2ec830ad 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/client/WebServiceTemplateAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/client/WebServiceTemplateAutoConfiguration.java @@ -16,8 +16,8 @@ package org.springframework.boot.autoconfigure.webservices.client; -import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -27,7 +27,6 @@ import org.springframework.boot.webservices.client.WebServiceTemplateBuilder; import org.springframework.boot.webservices.client.WebServiceTemplateCustomizer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.oxm.Marshaller; import org.springframework.oxm.Unmarshaller; import org.springframework.util.CollectionUtils; @@ -43,10 +42,10 @@ import org.springframework.ws.client.core.WebServiceTemplate; @ConditionalOnClass({ WebServiceTemplate.class, Unmarshaller.class, Marshaller.class }) public class WebServiceTemplateAutoConfiguration { - private final ObjectProvider> webServiceTemplateCustomizers; + private final ObjectProvider webServiceTemplateCustomizers; public WebServiceTemplateAutoConfiguration( - ObjectProvider> webServiceTemplateCustomizers) { + ObjectProvider webServiceTemplateCustomizers) { this.webServiceTemplateCustomizers = webServiceTemplateCustomizers; } @@ -55,10 +54,8 @@ public class WebServiceTemplateAutoConfiguration { public WebServiceTemplateBuilder webServiceTemplateBuilder() { WebServiceTemplateBuilder builder = new WebServiceTemplateBuilder(); List customizers = this.webServiceTemplateCustomizers - .getIfAvailable(); + .orderedStream().collect(Collectors.toList()); if (!CollectionUtils.isEmpty(customizers)) { - customizers = new ArrayList<>(customizers); - AnnotationAwareOrderComparator.sort(customizers); builder = builder.customizers(customizers); } return builder; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateDefaultDdlAutoProviderTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateDefaultDdlAutoProviderTests.java index 65f693f427c..5045fde148c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateDefaultDdlAutoProviderTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateDefaultDdlAutoProviderTests.java @@ -1,5 +1,5 @@ /* - * 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"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsAutoConfiguration.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsAutoConfiguration.java index 03ff7808e60..ecef410f02d 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsAutoConfiguration.java @@ -16,8 +16,6 @@ package org.springframework.boot.test.autoconfigure.restdocs; -import java.util.List; - import io.restassured.builder.RequestSpecBuilder; import io.restassured.specification.RequestSpecification; @@ -60,17 +58,13 @@ public class RestDocsAutoConfiguration { @Bean @ConditionalOnMissingBean public MockMvcRestDocumentationConfigurer restDocsMockMvcConfigurer( - ObjectProvider> configurationCustomizerProvider, + ObjectProvider configurationCustomizers, RestDocumentationContextProvider contextProvider) { MockMvcRestDocumentationConfigurer configurer = MockMvcRestDocumentation .documentationConfiguration(contextProvider); - List configurationCustomizers = configurationCustomizerProvider - .getIfAvailable(); - if (configurationCustomizers != null) { - configurationCustomizers - .forEach((configurationCustomizer) -> configurationCustomizer - .customize(configurer)); - } + configurationCustomizers.orderedStream() + .forEach((configurationCustomizer) -> configurationCustomizer + .customize(configurer)); return configurer; } @@ -94,17 +88,13 @@ public class RestDocsAutoConfiguration { @Bean @ConditionalOnMissingBean public RequestSpecification restDocsRestAssuredConfigurer( - ObjectProvider> configurationCustomizerProvider, + ObjectProvider configurationCustomizers, RestDocumentationContextProvider contextProvider) { RestAssuredRestDocumentationConfigurer configurer = RestAssuredRestDocumentation .documentationConfiguration(contextProvider); - List configurationCustomizers = configurationCustomizerProvider - .getIfAvailable(); - if (configurationCustomizers != null) { - configurationCustomizers - .forEach((configurationCustomizer) -> configurationCustomizer - .customize(configurer)); - } + configurationCustomizers.orderedStream() + .forEach((configurationCustomizer) -> configurationCustomizer + .customize(configurer)); return new RequestSpecBuilder().addFilter(configurer).build(); } @@ -125,17 +115,13 @@ public class RestDocsAutoConfiguration { @Bean @ConditionalOnMissingBean public WebTestClientRestDocumentationConfigurer restDocsWebTestClientConfigurer( - ObjectProvider> configurationCustomizerProvider, + ObjectProvider configurationCustomizers, RestDocumentationContextProvider contextProvider) { WebTestClientRestDocumentationConfigurer configurer = WebTestClientRestDocumentation .documentationConfiguration(contextProvider); - List configurationCustomizers = configurationCustomizerProvider - .getIfAvailable(); - if (configurationCustomizers != null) { - configurationCustomizers - .forEach((configurationCustomizer) -> configurationCustomizer - .customize(configurer)); - } + configurationCustomizers.orderedStream() + .forEach((configurationCustomizer) -> configurationCustomizer + .customize(configurer)); return configurer; } diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebTestClientAutoConfiguration.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebTestClientAutoConfiguration.java index 2eaa216ce96..adcadcf1b62 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebTestClientAutoConfiguration.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebTestClientAutoConfiguration.java @@ -16,9 +16,8 @@ package org.springframework.boot.test.autoconfigure.web.reactive; -import java.util.Collection; -import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.AutoConfigureAfter; @@ -74,9 +73,9 @@ public class WebTestClientAutoConfiguration { @Bean @ConfigurationProperties(prefix = "spring.test.webtestclient") public SpringBootWebTestClientBuilderCustomizer springBootWebTestClientBuilderCustomizer( - ObjectProvider> codecCustomizers) { + ObjectProvider codecCustomizers) { return new SpringBootWebTestClientBuilderCustomizer( - codecCustomizers.getIfAvailable(Collections::emptyList)); + codecCustomizers.orderedStream().collect(Collectors.toList())); } }