From 2c89d9918f96aab191c32d9c09676682d848e5b5 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 19 Jan 2017 14:00:40 -0800 Subject: [PATCH 01/14] Relocate AutoConfigurations from root package Move PropertyPlaceholder and MessageSource auto-configuration from the root package to the `context` subpackage. Fixes gh-8071 --- .../EndpointWebMvcAutoConfiguration.java | 4 +- ...ointMBeanExportAutoConfigurationTests.java | 4 +- .../EndpointMvcIntegrationTests.java | 4 +- .../EndpointWebMvcAutoConfigurationTests.java | 4 +- ...vcManagementContextConfigurationTests.java | 4 +- ...HealthIndicatorAutoConfigurationTests.java | 2 +- .../JolokiaAutoConfigurationTests.java | 4 +- ...mentWebSecurityAutoConfigurationTests.java | 4 +- .../MetricExportAutoConfigurationTests.java | 4 +- .../MinimalActuatorHypermediaApplication.java | 4 +- .../TraceWebFilterAutoConfigurationTests.java | 4 +- ...FoundryActuatorAutoConfigurationTests.java | 4 +- .../mvc/MvcEndpointCorsIntegrationTests.java | 4 +- .../mvc/MvcEndpointIntegrationTests.java | 4 +- ...rityHealthMvcEndpointIntegrationTests.java | 4 +- .../health/LdapHealthIndicatorTests.java | 2 +- .../health/MongoHealthIndicatorTests.java | 4 +- .../health/RabbitHealthIndicatorTests.java | 4 +- .../health/RedisHealthIndicatorTests.java | 4 +- .../health/SolrHealthIndicatorTests.java | 4 +- .../MessageSourceAutoConfiguration.java | 166 ++------------- .../PropertyPlaceholderAutoConfiguration.java | 27 ++- .../MessageSourceAutoConfiguration.java | 194 ++++++++++++++++++ .../PropertyPlaceholderAutoConfiguration.java | 45 ++++ .../main/resources/META-INF/spring.factories | 4 +- .../boot/autoconfigure/SpringJUnitTests.java | 3 +- .../batch/BatchAutoConfigurationTests.java | 4 +- .../CassandraAutoConfigurationTests.java | 4 +- .../ConditionalOnMissingBeanTests.java | 4 +- ...urceAutoConfigurationIntegrationTests.java | 5 +- ...geSourceAutoConfigurationProfileTests.java | 5 +- .../MessageSourceAutoConfigurationTests.java | 4 +- ...ertyPlaceholderAutoConfigurationTests.java | 4 +- ...stractCouchbaseAutoConfigurationTests.java | 4 +- .../CassandraDataAutoConfigurationTests.java | 4 +- ...draRepositoriesAutoConfigurationTests.java | 4 +- .../CouchbaseDataAutoConfigurationTests.java | 4 +- ...aseRepositoriesAutoConfigurationTests.java | 4 +- .../ElasticsearchAutoConfigurationTests.java | 4 +- ...asticsearchDataAutoConfigurationTests.java | 4 +- ...rchRepositoriesAutoConfigurationTests.java | 4 +- ...JpaRepositoriesAutoConfigurationTests.java | 4 +- .../jpa/JpaWebAutoConfigurationTests.java | 4 +- .../ldap/LdapDataAutoConfigurationTests.java | 2 +- ...dapRepositoriesAutoConfigurationTests.java | 2 +- .../MongoDataAutoConfigurationTests.java | 4 +- ...ngoRepositoriesAutoConfigurationTests.java | 4 +- .../Neo4jDataAutoConfigurationTests.java | 4 +- ...o4jRepositoriesAutoConfigurationTests.java | 4 +- .../redis/RedisAutoConfigurationTests.java | 4 +- ...disRepositoriesAutoConfigurationTests.java | 4 +- ...positoryRestMvcAutoConfigurationTests.java | 2 +- ...olrRepositoriesAutoConfigurationTests.java | 4 +- .../flyway/FlywayAutoConfigurationTests.java | 4 +- .../ProjectInfoAutoConfigurationTests.java | 4 +- .../DataSourceAutoConfigurationTests.java | 4 +- .../jdbc/DataSourceInitializerTests.java | 4 +- .../JdbcTemplateAutoConfigurationTests.java | 4 +- ...igurationCustomFilterContextPathTests.java | 4 +- ...utoConfigurationCustomFilterPathTests.java | 4 +- ...ConfigurationCustomLoadOnStartupTests.java | 4 +- ...rationCustomObjectMapperProviderTests.java | 4 +- ...gurationCustomServletContextPathTests.java | 4 +- ...toConfigurationCustomServletPathTests.java | 4 +- ...toConfigurationDefaultFilterPathTests.java | 4 +- ...oConfigurationDefaultServletPathTests.java | 4 +- ...onfigurationObjectMapperProviderTests.java | 4 +- ...utoConfigurationServletContainerTests.java | 4 +- ...figurationWithoutApplicationPathTests.java | 4 +- .../jooq/JooqAutoConfigurationTests.java | 4 +- .../ldap/LdapAutoConfigurationTests.java | 2 +- .../EmbeddedLdapAutoConfigurationTests.java | 2 +- .../LiquibaseAutoConfigurationTests.java | 4 +- ...gurationReportLoggingInitializerTests.java | 4 +- ...ingViewResolverAutoConfigurationTests.java | 4 +- .../DeviceResolverAutoConfigurationTests.java | 4 +- .../SitePreferenceAutoConfigurationTests.java | 4 +- .../mongo/MongoAutoConfigurationTests.java | 4 +- .../EmbeddedMongoAutoConfigurationTests.java | 2 +- ...acheAutoConfigurationIntegrationTests.java | 4 +- .../MustacheStandaloneIntegrationTests.java | 4 +- .../web/MustacheWebIntegrationTests.java | 4 +- .../AbstractJpaAutoConfigurationTests.java | 4 +- ...tomHibernateJpaAutoConfigurationTests.java | 2 +- .../SecurityAutoConfigurationTests.java | 4 +- ...ConfigurationEarlyInitializationTests.java | 4 +- .../SecurityFilterAutoConfigurationTests.java | 4 +- ...ringBootWebSecurityConfigurationTests.java | 4 +- .../security/jpa/JpaUserDetailsTests.java | 4 +- ...ServerTokenServicesConfigurationTests.java | 2 +- ...serInfoTokenServicesRefreshTokenTests.java | 4 +- .../sso/MinimalSecureWebConfiguration.java | 4 +- ...AbstractSessionAutoConfigurationTests.java | 4 +- .../ThymeleafAutoConfigurationTests.java | 4 +- ...asicErrorControllerDirectMockMvcTests.java | 4 +- .../web/BasicErrorControllerMockMvcTests.java | 4 +- .../web/DefaultErrorViewIntegrationTests.java | 4 +- .../web/FilterOrderingIntegrationTests.java | 4 +- .../RemappedErrorViewIntegrationTests.java | 4 +- ...erverPropertiesAutoConfigurationTests.java | 4 +- .../web/WebMvcAutoConfigurationTests.java | 4 +- .../RemoteDevToolsAutoConfigurationTests.java | 4 +- .../appendix-application-properties.adoc | 2 +- .../SampleAtmosphereApplicationTests.java | 4 +- ...igurationSampleTomcatApplicationTests.java | 4 +- .../SampleWebSocketsApplicationTests.java | 4 +- ...omContainerWebSocketsApplicationTests.java | 4 +- .../SampleWebSocketsApplicationTests.java | 4 +- ...omContainerWebSocketsApplicationTests.java | 4 +- .../SampleWebSocketsApplicationTests.java | 4 +- ...omContainerWebSocketsApplicationTests.java | 4 +- .../SampleWebSocketsApplicationTests.java | 4 +- ...omContainerWebSocketsApplicationTests.java | 4 +- .../main/resources/META-INF/spring.factories | 2 +- 114 files changed, 482 insertions(+), 367 deletions(-) create mode 100644 spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/context/MessageSourceAutoConfiguration.java create mode 100644 spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/context/PropertyPlaceholderAutoConfiguration.java rename spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/{ => context}/MessageSourceAutoConfigurationIntegrationTests.java (90%) rename spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/{ => context}/MessageSourceAutoConfigurationProfileTests.java (90%) rename spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/{ => context}/MessageSourceAutoConfigurationTests.java (98%) rename spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/{ => context}/PropertyPlaceholderAutoConfigurationTests.java (96%) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java index e66bc9fb0dd..f63c34a85ed 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -39,13 +39,13 @@ import org.springframework.boot.actuate.endpoint.Endpoint; import org.springframework.boot.actuate.endpoint.mvc.ManagementServletContext; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionMessage; import org.springframework.boot.autoconfigure.condition.ConditionOutcome; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.condition.SpringBootCondition; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration; import org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMBeanExportAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMBeanExportAutoConfigurationTests.java index 6e0f787c1fb..5c921482ecc 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMBeanExportAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMBeanExportAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -29,7 +29,7 @@ import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.boot.actuate.endpoint.AbstractEndpoint; import org.springframework.boot.actuate.endpoint.Endpoint; import org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMvcIntegrationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMvcIntegrationTests.java index 1e288ef6152..d6312f7dc34 100755 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMvcIntegrationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMvcIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -38,8 +38,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.endpoint.Endpoint; import org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping; import org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMappingCustomizer; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java index 519b468626c..44dac20d9f7 100755 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -53,7 +53,7 @@ import org.springframework.boot.actuate.endpoint.mvc.LoggersMvcEndpoint; import org.springframework.boot.actuate.endpoint.mvc.MetricsMvcEndpoint; import org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint; import org.springframework.boot.actuate.endpoint.mvc.ShutdownMvcEndpoint; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcManagementContextConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcManagementContextConfigurationTests.java index 92ef72ccafc..ae96f997c3d 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcManagementContextConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcManagementContextConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -24,7 +24,7 @@ import org.junit.Test; import org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping; import org.springframework.boot.actuate.endpoint.mvc.MvcEndpointSecurityInterceptor; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration; import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration; diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java index 36630d4ab0f..8175809dc3a 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java @@ -41,8 +41,8 @@ import org.springframework.boot.actuate.health.MongoHealthIndicator; import org.springframework.boot.actuate.health.RabbitHealthIndicator; import org.springframework.boot.actuate.health.RedisHealthIndicator; import org.springframework.boot.actuate.health.SolrHealthIndicator; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration; import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration; import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfigurationTests.java index 68639f84406..be4d595fc80 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -27,7 +27,7 @@ import org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping; import org.springframework.boot.actuate.endpoint.mvc.JolokiaMvcEndpoint; import org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint; import org.springframework.boot.actuate.endpoint.mvc.MvcEndpointSecurityInterceptor; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ManagementWebSecurityAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ManagementWebSecurityAutoConfigurationTests.java index 164f604437c..5e8f8e14223 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ManagementWebSecurityAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ManagementWebSecurityAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -26,7 +26,7 @@ import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.autoconfigure.security.FallbackWebSecurityAutoConfiguration; import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration; diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricExportAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricExportAutoConfigurationTests.java index df2ce54b0ab..9d901963189 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricExportAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricExportAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -33,7 +33,7 @@ import org.springframework.boot.actuate.metrics.export.MetricExporters; import org.springframework.boot.actuate.metrics.statsd.StatsdMetricWriter; import org.springframework.boot.actuate.metrics.writer.GaugeWriter; import org.springframework.boot.actuate.metrics.writer.MetricWriter; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MinimalActuatorHypermediaApplication.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MinimalActuatorHypermediaApplication.java index c01d788de0b..47479021961 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MinimalActuatorHypermediaApplication.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MinimalActuatorHypermediaApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -23,7 +23,7 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/TraceWebFilterAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/TraceWebFilterAutoConfigurationTests.java index 39960396534..91cd9c7bcb4 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/TraceWebFilterAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/TraceWebFilterAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -23,7 +23,7 @@ import org.junit.Test; import org.springframework.boot.actuate.trace.TraceProperties; import org.springframework.boot.actuate.trace.TraceRepository; import org.springframework.boot.actuate.trace.WebRequestTraceFilter; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryActuatorAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryActuatorAutoConfigurationTests.java index 374bdb977b3..10977301638 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryActuatorAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryActuatorAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -28,7 +28,7 @@ import org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfigur import org.springframework.boot.actuate.autoconfigure.EndpointWebMvcManagementContextConfiguration; import org.springframework.boot.actuate.autoconfigure.ManagementServerPropertiesAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.ManagementWebSecurityAutoConfiguration; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.autoconfigure.security.IgnoredRequestCustomizer; import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration; diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/MvcEndpointCorsIntegrationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/MvcEndpointCorsIntegrationTests.java index e3823257c51..c54a8419bb0 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/MvcEndpointCorsIntegrationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/MvcEndpointCorsIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -24,7 +24,7 @@ import org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.JolokiaAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.ManagementServerPropertiesAutoConfiguration; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/MvcEndpointIntegrationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/MvcEndpointIntegrationTests.java index db6199693c5..b0beda8e885 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/MvcEndpointIntegrationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/MvcEndpointIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -25,7 +25,7 @@ import org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfigur import org.springframework.boot.actuate.autoconfigure.ManagementServerPropertiesAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.ManagementWebSecurityAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration; import org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/NoSpringSecurityHealthMvcEndpointIntegrationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/NoSpringSecurityHealthMvcEndpointIntegrationTests.java index c74e18138b6..c77accdb353 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/NoSpringSecurityHealthMvcEndpointIntegrationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/NoSpringSecurityHealthMvcEndpointIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -26,7 +26,7 @@ import org.springframework.boot.actuate.autoconfigure.ManagementServerProperties import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/LdapHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/LdapHealthIndicatorTests.java index e2a6afebf5f..cfb4aa41969 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/LdapHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/LdapHealthIndicatorTests.java @@ -22,7 +22,7 @@ import org.junit.Test; import org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfiguration; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.data.ldap.LdapDataAutoConfiguration; import org.springframework.boot.autoconfigure.ldap.LdapAutoConfiguration; import org.springframework.context.annotation.AnnotationConfigApplicationContext; diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MongoHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MongoHealthIndicatorTests.java index 4110b222d8d..840f34d3bba 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MongoHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MongoHealthIndicatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -23,7 +23,7 @@ import org.junit.Test; import org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfiguration; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration; import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; import org.springframework.context.annotation.AnnotationConfigApplicationContext; diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RabbitHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RabbitHealthIndicatorTests.java index 02dbbd4443b..e4d98e967b7 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RabbitHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RabbitHealthIndicatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -22,8 +22,8 @@ import org.junit.Test; import org.springframework.amqp.rabbit.core.RabbitAdmin; import org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfiguration; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RedisHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RedisHealthIndicatorTests.java index 43566660d3d..7d6e8a98053 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RedisHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RedisHealthIndicatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -25,7 +25,7 @@ import org.junit.Test; import org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfiguration; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.data.redis.RedisConnectionFailureException; diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/SolrHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/SolrHealthIndicatorTests.java index 402d1ec1565..e4d055c39e5 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/SolrHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/SolrHealthIndicatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -26,7 +26,7 @@ import org.junit.Test; import org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfiguration; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration; import org.springframework.context.annotation.AnnotationConfigApplicationContext; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfiguration.java index 65cd9a0a0b9..71cc0617b84 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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,28 +16,12 @@ package org.springframework.boot.autoconfigure; -import java.nio.charset.Charset; - -import org.springframework.boot.autoconfigure.MessageSourceAutoConfiguration.ResourceBundleCondition; -import org.springframework.boot.autoconfigure.condition.ConditionMessage; -import org.springframework.boot.autoconfigure.condition.ConditionOutcome; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.SearchStrategy; -import org.springframework.boot.autoconfigure.condition.SpringBootCondition; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.MessageSource; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ConditionContext; -import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; -import org.springframework.context.support.ResourceBundleMessageSource; +import org.springframework.context.annotation.Import; +import org.springframework.context.annotation.ImportSelector; import org.springframework.core.Ordered; -import org.springframework.core.io.Resource; -import org.springframework.core.io.support.PathMatchingResourcePatternResolver; -import org.springframework.core.type.AnnotatedTypeMetadata; -import org.springframework.util.ConcurrentReferenceHashMap; -import org.springframework.util.StringUtils; +import org.springframework.core.type.AnnotationMetadata; /** * {@link EnableAutoConfiguration Auto-configuration} for {@link MessageSource}. @@ -45,146 +29,24 @@ import org.springframework.util.StringUtils; * @author Dave Syer * @author Phillip Webb * @author Eddú Meléndez + * @deprecated as of 1.5 in favor of + * {@link org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration} */ @Configuration -@ConditionalOnMissingBean(value = MessageSource.class, search = SearchStrategy.CURRENT) @AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE) -@Conditional(ResourceBundleCondition.class) -@EnableConfigurationProperties -@ConfigurationProperties(prefix = "spring.messages") +@Deprecated +@Import(MessageSourceAutoConfiguration.Selector.class) public class MessageSourceAutoConfiguration { - private static final Resource[] NO_RESOURCES = {}; + private static final String[] REPLACEMENT = { + "org.springframework.boot.autoconfigure.context." + + "MessageSourceAutoConfiguration" }; - /** - * Comma-separated list of basenames, each following the ResourceBundle convention. - * Essentially a fully-qualified classpath location. If it doesn't contain a package - * qualifier (such as "org.mypackage"), it will be resolved from the classpath root. - */ - private String basename = "messages"; - - /** - * Message bundles encoding. - */ - private Charset encoding = Charset.forName("UTF-8"); - - /** - * Loaded resource bundle files cache expiration, in seconds. When set to -1, bundles - * are cached forever. - */ - private int cacheSeconds = -1; - - /** - * Set whether to fall back to the system Locale if no files for a specific Locale - * have been found. if this is turned off, the only fallback will be the default file - * (e.g. "messages.properties" for basename "messages"). - */ - private boolean fallbackToSystemLocale = true; - - /** - * Set whether to always apply the MessageFormat rules, parsing even messages without - * arguments. - */ - private boolean alwaysUseMessageFormat = false; - - @Bean - public MessageSource messageSource() { - ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); - if (StringUtils.hasText(this.basename)) { - messageSource.setBasenames(StringUtils.commaDelimitedListToStringArray( - StringUtils.trimAllWhitespace(this.basename))); - } - if (this.encoding != null) { - messageSource.setDefaultEncoding(this.encoding.name()); - } - messageSource.setFallbackToSystemLocale(this.fallbackToSystemLocale); - messageSource.setCacheSeconds(this.cacheSeconds); - messageSource.setAlwaysUseMessageFormat(this.alwaysUseMessageFormat); - return messageSource; - } - - public String getBasename() { - return this.basename; - } - - public void setBasename(String basename) { - this.basename = basename; - } - - public Charset getEncoding() { - return this.encoding; - } - - public void setEncoding(Charset encoding) { - this.encoding = encoding; - } - - public int getCacheSeconds() { - return this.cacheSeconds; - } - - public void setCacheSeconds(int cacheSeconds) { - this.cacheSeconds = cacheSeconds; - } - - public boolean isFallbackToSystemLocale() { - return this.fallbackToSystemLocale; - } - - public void setFallbackToSystemLocale(boolean fallbackToSystemLocale) { - this.fallbackToSystemLocale = fallbackToSystemLocale; - } - - public boolean isAlwaysUseMessageFormat() { - return this.alwaysUseMessageFormat; - } - - public void setAlwaysUseMessageFormat(boolean alwaysUseMessageFormat) { - this.alwaysUseMessageFormat = alwaysUseMessageFormat; - } - - protected static class ResourceBundleCondition extends SpringBootCondition { - - private static ConcurrentReferenceHashMap cache = new ConcurrentReferenceHashMap(); + static class Selector implements ImportSelector { @Override - public ConditionOutcome getMatchOutcome(ConditionContext context, - AnnotatedTypeMetadata metadata) { - String basename = context.getEnvironment() - .getProperty("spring.messages.basename", "messages"); - ConditionOutcome outcome = cache.get(basename); - if (outcome == null) { - outcome = getMatchOutcomeForBasename(context, basename); - cache.put(basename, outcome); - } - return outcome; - } - - private ConditionOutcome getMatchOutcomeForBasename(ConditionContext context, - String basename) { - ConditionMessage.Builder message = ConditionMessage - .forCondition("ResourceBundle"); - for (String name : StringUtils.commaDelimitedListToStringArray( - StringUtils.trimAllWhitespace(basename))) { - for (Resource resource : getResources(context.getClassLoader(), name)) { - if (resource.exists()) { - return ConditionOutcome - .match(message.found("bundle").items(resource)); - } - } - } - return ConditionOutcome.noMatch( - message.didNotFind("bundle with basename " + basename).atAll()); - } - - private Resource[] getResources(ClassLoader classLoader, String name) { - try { - return new PathMatchingResourcePatternResolver(classLoader) - .getResources("classpath*:" + name + ".properties"); - } - catch (Exception ex) { - return NO_RESOURCES; - } + public String[] selectImports(AnnotationMetadata importingClassMetadata) { + return REPLACEMENT; } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/PropertyPlaceholderAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/PropertyPlaceholderAutoConfiguration.java index 4d08c179bd5..70a2da95c1b 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/PropertyPlaceholderAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/PropertyPlaceholderAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2017 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,12 @@ package org.springframework.boot.autoconfigure; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.SearchStrategy; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.context.annotation.ImportSelector; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.core.Ordered; +import org.springframework.core.type.AnnotationMetadata; /** * {@link EnableAutoConfiguration Auto-configuration} for @@ -29,15 +29,26 @@ import org.springframework.core.Ordered; * * @author Phillip Webb * @author Dave Syer + * @deprecated as of 1.5 in favor of + * {@link org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration} */ @Configuration @AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE) +@Deprecated +@Import(PropertyPlaceholderAutoConfiguration.Selector.class) public class PropertyPlaceholderAutoConfiguration { - @Bean - @ConditionalOnMissingBean(search = SearchStrategy.CURRENT) - public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { - return new PropertySourcesPlaceholderConfigurer(); + private static final String[] REPLACEMENT = { + "org.springframework.boot.autoconfigure.context." + + "PropertyPlaceholderAutoConfiguration" }; + + static class Selector implements ImportSelector { + + @Override + public String[] selectImports(AnnotationMetadata importingClassMetadata) { + return REPLACEMENT; + } + } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/context/MessageSourceAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/context/MessageSourceAutoConfiguration.java new file mode 100644 index 00000000000..5b292d6b8f6 --- /dev/null +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/context/MessageSourceAutoConfiguration.java @@ -0,0 +1,194 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.context; + +import java.nio.charset.Charset; + +import org.springframework.boot.autoconfigure.AutoConfigureOrder; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionMessage; +import org.springframework.boot.autoconfigure.condition.ConditionOutcome; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.SearchStrategy; +import org.springframework.boot.autoconfigure.condition.SpringBootCondition; +import org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration.ResourceBundleCondition; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.MessageSource; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ConditionContext; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.support.ResourceBundleMessageSource; +import org.springframework.core.Ordered; +import org.springframework.core.io.Resource; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.core.type.AnnotatedTypeMetadata; +import org.springframework.util.ConcurrentReferenceHashMap; +import org.springframework.util.StringUtils; + +/** + * {@link EnableAutoConfiguration Auto-configuration} for {@link MessageSource}. + * + * @author Dave Syer + * @author Phillip Webb + * @author Eddú Meléndez + */ +@Configuration +@ConditionalOnMissingBean(value = MessageSource.class, search = SearchStrategy.CURRENT) +@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE) +@Conditional(ResourceBundleCondition.class) +@EnableConfigurationProperties +@ConfigurationProperties(prefix = "spring.messages") +public class MessageSourceAutoConfiguration { + + private static final Resource[] NO_RESOURCES = {}; + + /** + * Comma-separated list of basenames, each following the ResourceBundle convention. + * Essentially a fully-qualified classpath location. If it doesn't contain a package + * qualifier (such as "org.mypackage"), it will be resolved from the classpath root. + */ + private String basename = "messages"; + + /** + * Message bundles encoding. + */ + private Charset encoding = Charset.forName("UTF-8"); + + /** + * Loaded resource bundle files cache expiration, in seconds. When set to -1, bundles + * are cached forever. + */ + private int cacheSeconds = -1; + + /** + * Set whether to fall back to the system Locale if no files for a specific Locale + * have been found. if this is turned off, the only fallback will be the default file + * (e.g. "messages.properties" for basename "messages"). + */ + private boolean fallbackToSystemLocale = true; + + /** + * Set whether to always apply the MessageFormat rules, parsing even messages without + * arguments. + */ + private boolean alwaysUseMessageFormat = false; + + @Bean + public MessageSource messageSource() { + ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); + if (StringUtils.hasText(this.basename)) { + messageSource.setBasenames(StringUtils.commaDelimitedListToStringArray( + StringUtils.trimAllWhitespace(this.basename))); + } + if (this.encoding != null) { + messageSource.setDefaultEncoding(this.encoding.name()); + } + messageSource.setFallbackToSystemLocale(this.fallbackToSystemLocale); + messageSource.setCacheSeconds(this.cacheSeconds); + messageSource.setAlwaysUseMessageFormat(this.alwaysUseMessageFormat); + return messageSource; + } + + public String getBasename() { + return this.basename; + } + + public void setBasename(String basename) { + this.basename = basename; + } + + public Charset getEncoding() { + return this.encoding; + } + + public void setEncoding(Charset encoding) { + this.encoding = encoding; + } + + public int getCacheSeconds() { + return this.cacheSeconds; + } + + public void setCacheSeconds(int cacheSeconds) { + this.cacheSeconds = cacheSeconds; + } + + public boolean isFallbackToSystemLocale() { + return this.fallbackToSystemLocale; + } + + public void setFallbackToSystemLocale(boolean fallbackToSystemLocale) { + this.fallbackToSystemLocale = fallbackToSystemLocale; + } + + public boolean isAlwaysUseMessageFormat() { + return this.alwaysUseMessageFormat; + } + + public void setAlwaysUseMessageFormat(boolean alwaysUseMessageFormat) { + this.alwaysUseMessageFormat = alwaysUseMessageFormat; + } + + protected static class ResourceBundleCondition extends SpringBootCondition { + + private static ConcurrentReferenceHashMap cache = new ConcurrentReferenceHashMap(); + + @Override + public ConditionOutcome getMatchOutcome(ConditionContext context, + AnnotatedTypeMetadata metadata) { + String basename = context.getEnvironment() + .getProperty("spring.messages.basename", "messages"); + ConditionOutcome outcome = cache.get(basename); + if (outcome == null) { + outcome = getMatchOutcomeForBasename(context, basename); + cache.put(basename, outcome); + } + return outcome; + } + + private ConditionOutcome getMatchOutcomeForBasename(ConditionContext context, + String basename) { + ConditionMessage.Builder message = ConditionMessage + .forCondition("ResourceBundle"); + for (String name : StringUtils.commaDelimitedListToStringArray( + StringUtils.trimAllWhitespace(basename))) { + for (Resource resource : getResources(context.getClassLoader(), name)) { + if (resource.exists()) { + return ConditionOutcome + .match(message.found("bundle").items(resource)); + } + } + } + return ConditionOutcome.noMatch( + message.didNotFind("bundle with basename " + basename).atAll()); + } + + private Resource[] getResources(ClassLoader classLoader, String name) { + try { + return new PathMatchingResourcePatternResolver(classLoader) + .getResources("classpath*:" + name + ".properties"); + } + catch (Exception ex) { + return NO_RESOURCES; + } + } + + } + +} diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/context/PropertyPlaceholderAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/context/PropertyPlaceholderAutoConfiguration.java new file mode 100644 index 00000000000..499f519516c --- /dev/null +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/context/PropertyPlaceholderAutoConfiguration.java @@ -0,0 +1,45 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.context; + +import org.springframework.boot.autoconfigure.AutoConfigureOrder; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.SearchStrategy; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; +import org.springframework.core.Ordered; + +/** + * {@link EnableAutoConfiguration Auto-configuration} for + * {@link PropertySourcesPlaceholderConfigurer}. + * + * @author Phillip Webb + * @author Dave Syer + */ +@Configuration +@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE) +public class PropertyPlaceholderAutoConfiguration { + + @Bean + @ConditionalOnMissingBean(search = SearchStrategy.CURRENT) + public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { + return new PropertySourcesPlaceholderConfigurer(); + } + +} diff --git a/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories b/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories index 47120cc1989..47b01e82ef2 100644 --- a/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories +++ b/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories @@ -12,13 +12,13 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration,\ org.springframework.boot.autoconfigure.aop.AopAutoConfiguration,\ org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration,\ -org.springframework.boot.autoconfigure.MessageSourceAutoConfiguration,\ -org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration,\ org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration,\ org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration,\ org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration,\ org.springframework.boot.autoconfigure.cloud.CloudAutoConfiguration,\ org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration,\ +org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration,\ +org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration,\ org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration,\ org.springframework.boot.autoconfigure.dao.PersistenceExceptionTranslationAutoConfiguration,\ org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration,\ diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/SpringJUnitTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/SpringJUnitTests.java index b1fb48c9d01..34ab4a5668d 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/SpringJUnitTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/SpringJUnitTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -21,6 +21,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Configuration; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java index 6505f7cba30..f8b47a54437 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -47,8 +47,8 @@ import org.springframework.batch.core.repository.support.MapJobRepositoryFactory import org.springframework.batch.support.transaction.ResourcelessTransactionManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.test.City; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfigurationTests.java index 0627fddf1eb..48c5ede3056 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -20,7 +20,7 @@ import com.datastax.driver.core.Cluster; import org.junit.After; import org.junit.Test; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnMissingBeanTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnMissingBeanTests.java index 138726aaa4b..14a16799a99 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnMissingBeanTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnMissingBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -24,9 +24,9 @@ import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.condition.scan.ScannedFactoryBeanConfiguration; import org.springframework.boot.autoconfigure.condition.scan.ScannedFactoryBeanWithBeanMethodArgumentsConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfigurationIntegrationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/MessageSourceAutoConfigurationIntegrationTests.java similarity index 90% rename from spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfigurationIntegrationTests.java rename to spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/MessageSourceAutoConfigurationIntegrationTests.java index 40c514aac99..3643c5e252b 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfigurationIntegrationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/MessageSourceAutoConfigurationIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure; +package org.springframework.boot.autoconfigure.context; import java.util.Locale; @@ -22,6 +22,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Configuration; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfigurationProfileTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/MessageSourceAutoConfigurationProfileTests.java similarity index 90% rename from spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfigurationProfileTests.java rename to spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/MessageSourceAutoConfigurationProfileTests.java index dbd77e3b0e2..a52937ec198 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfigurationProfileTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/MessageSourceAutoConfigurationProfileTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure; +package org.springframework.boot.autoconfigure.context; import java.util.Locale; @@ -22,6 +22,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Configuration; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/MessageSourceAutoConfigurationTests.java similarity index 98% rename from spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfigurationTests.java rename to spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/MessageSourceAutoConfigurationTests.java index da2dda0ae0d..30a70e27503 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/MessageSourceAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure; +package org.springframework.boot.autoconfigure.context; import java.util.Locale; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/PropertyPlaceholderAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/PropertyPlaceholderAutoConfigurationTests.java similarity index 96% rename from spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/PropertyPlaceholderAutoConfigurationTests.java rename to spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/PropertyPlaceholderAutoConfigurationTests.java index 052f0b29884..4acb7d79118 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/PropertyPlaceholderAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/PropertyPlaceholderAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure; +package org.springframework.boot.autoconfigure.context; import org.junit.After; import org.junit.Test; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/AbstractCouchbaseAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/AbstractCouchbaseAutoConfigurationTests.java index f6486bf811b..cf7a84a119e 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/AbstractCouchbaseAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/AbstractCouchbaseAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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,7 +18,7 @@ package org.springframework.boot.autoconfigure.couchbase; import org.junit.After; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationTests.java index 3025350dd30..638cd497940 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -22,8 +22,8 @@ import com.datastax.driver.core.Session; import org.junit.After; import org.junit.Test; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.data.cassandra.city.City; import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.boot.test.util.EnvironmentTestUtils; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraRepositoriesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraRepositoriesAutoConfigurationTests.java index ef1f7f45d1d..85f875907fa 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraRepositoriesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraRepositoriesAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -24,9 +24,9 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.data.alt.cassandra.CityCassandraRepository; import org.springframework.boot.autoconfigure.data.cassandra.city.City; import org.springframework.boot.autoconfigure.data.cassandra.city.CityRepository; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseDataAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseDataAutoConfigurationTests.java index 17a6a723a50..ef632fb8b3a 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseDataAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseDataAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -22,7 +22,7 @@ import java.util.Set; import org.junit.After; import org.junit.Test; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration; import org.springframework.boot.autoconfigure.couchbase.CouchbaseProperties; import org.springframework.boot.autoconfigure.couchbase.CouchbaseTestConfigurer; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseRepositoriesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseRepositoriesAutoConfigurationTests.java index ae4ea12a529..051465633a1 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseRepositoriesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseRepositoriesAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -19,8 +19,8 @@ package org.springframework.boot.autoconfigure.data.couchbase; import org.junit.After; import org.junit.Test; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration; import org.springframework.boot.autoconfigure.couchbase.CouchbaseTestConfigurer; import org.springframework.boot.autoconfigure.data.couchbase.city.City; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfigurationTests.java index 320c490c5eb..5941467e1f2 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -24,7 +24,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.springframework.beans.factory.BeanCreationException; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfigurationTests.java index 531abe724ac..46619269f06 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -19,7 +19,7 @@ package org.springframework.boot.autoconfigure.data.elasticsearch; import org.junit.After; import org.junit.Test; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchRepositoriesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchRepositoriesAutoConfigurationTests.java index dd670900974..b3ad7eab71c 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchRepositoriesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchRepositoriesAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -20,8 +20,8 @@ import org.elasticsearch.client.Client; import org.junit.After; import org.junit.Test; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.data.alt.elasticsearch.CityElasticsearchDbRepository; import org.springframework.boot.autoconfigure.data.elasticsearch.city.City; import org.springframework.boot.autoconfigure.data.elasticsearch.city.CityRepository; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jpa/JpaRepositoriesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jpa/JpaRepositoriesAutoConfigurationTests.java index b10d2e4538d..43884b6c3d0 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jpa/JpaRepositoriesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jpa/JpaRepositoriesAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -22,8 +22,8 @@ import org.junit.After; import org.junit.Test; import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.data.alt.mongo.CityMongoDbRepository; import org.springframework.boot.autoconfigure.data.alt.solr.CitySolrRepository; import org.springframework.boot.autoconfigure.data.jpa.city.City; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jpa/JpaWebAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jpa/JpaWebAutoConfigurationTests.java index a0de61f142b..770a91d8931 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jpa/JpaWebAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jpa/JpaWebAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -19,8 +19,8 @@ package org.springframework.boot.autoconfigure.data.jpa; import org.junit.After; import org.junit.Test; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.data.jpa.city.City; import org.springframework.boot.autoconfigure.data.jpa.city.CityRepository; import org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/ldap/LdapDataAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/ldap/LdapDataAutoConfigurationTests.java index 7f92ededb2c..537eb694535 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/ldap/LdapDataAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/ldap/LdapDataAutoConfigurationTests.java @@ -19,7 +19,7 @@ package org.springframework.boot.autoconfigure.data.ldap; import org.junit.After; import org.junit.Test; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.ldap.LdapAutoConfiguration; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/ldap/LdapRepositoriesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/ldap/LdapRepositoriesAutoConfigurationTests.java index 6ebb70597a4..09b3004d482 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/ldap/LdapRepositoriesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/ldap/LdapRepositoriesAutoConfigurationTests.java @@ -19,8 +19,8 @@ package org.springframework.boot.autoconfigure.data.ldap; import org.junit.After; import org.junit.Test; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.data.alt.ldap.PersonLdapRepository; import org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage; import org.springframework.boot.autoconfigure.data.ldap.person.Person; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfigurationTests.java index 566751c01f0..07ee35fea22 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -29,7 +29,7 @@ import org.junit.rules.ExpectedException; import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.UnsatisfiedDependencyException; import org.springframework.boot.autoconfigure.AutoConfigurationPackages; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.data.mongo.city.City; import org.springframework.boot.autoconfigure.data.mongo.country.Country; import org.springframework.boot.autoconfigure.domain.EntityScan; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/mongo/MongoRepositoriesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/mongo/MongoRepositoriesAutoConfigurationTests.java index c86dfeb0561..fd169b7d79e 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/mongo/MongoRepositoriesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/mongo/MongoRepositoriesAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -24,8 +24,8 @@ import org.junit.After; import org.junit.Test; import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.data.alt.mongo.CityMongoDbRepository; import org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage; import org.springframework.boot.autoconfigure.data.mongo.city.City; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java index eed110b8651..5de4b2f1c69 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -28,7 +28,7 @@ import org.neo4j.ogm.session.event.PersistenceEvent; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.boot.autoconfigure.AutoConfigurationPackages; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.data.neo4j.city.City; import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration; import org.springframework.boot.test.util.EnvironmentTestUtils; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jRepositoriesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jRepositoriesAutoConfigurationTests.java index 878eb483733..62b2eadeb27 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jRepositoriesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jRepositoriesAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -21,8 +21,8 @@ import org.junit.Test; import org.neo4j.ogm.session.SessionFactory; import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.data.alt.neo4j.CityNeo4jRepository; import org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage; import org.springframework.boot.autoconfigure.data.neo4j.city.City; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationTests.java index 69be81f6dca..ab313ee5c57 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -24,7 +24,7 @@ import org.junit.Before; import org.junit.Test; import redis.clients.jedis.Jedis; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisRepositoriesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisRepositoriesAutoConfigurationTests.java index 657c4b22e4d..4b6a7084282 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisRepositoriesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisRepositoriesAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -20,8 +20,8 @@ import org.junit.After; import org.junit.Rule; import org.junit.Test; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.data.alt.redis.CityRedisRepository; import org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage; import org.springframework.boot.autoconfigure.data.redis.city.City; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestMvcAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestMvcAutoConfigurationTests.java index dc2e7c89516..3e3462284d5 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestMvcAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestMvcAutoConfigurationTests.java @@ -26,8 +26,8 @@ import org.junit.After; import org.junit.Test; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration; import org.springframework.boot.autoconfigure.data.jpa.city.City; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/solr/SolrRepositoriesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/solr/SolrRepositoriesAutoConfigurationTests.java index 32254294553..fd44a8f5a3b 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/solr/SolrRepositoriesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/solr/SolrRepositoriesAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -22,8 +22,8 @@ import org.junit.After; import org.junit.Test; import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.data.alt.solr.CitySolrRepository; import org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage; import org.springframework.boot.autoconfigure.data.solr.city.City; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java index aeca7652c00..f01bbe957c5 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -33,7 +33,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.springframework.beans.factory.BeanCreationException; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/info/ProjectInfoAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/info/ProjectInfoAutoConfigurationTests.java index 4d9f52a4531..d8d1355eadc 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/info/ProjectInfoAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/info/ProjectInfoAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -22,7 +22,7 @@ import java.util.Properties; import org.junit.After; import org.junit.Test; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.info.BuildProperties; import org.springframework.boot.info.GitProperties; import org.springframework.boot.test.util.EnvironmentTestUtils; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java index bf35dee8b36..a51a9118d39 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -36,7 +36,7 @@ import org.junit.Before; import org.junit.Test; import org.springframework.beans.factory.BeanCreationException; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.jdbc.DatabaseDriver; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerTests.java index 8417a4e794c..28e43544840 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -31,7 +31,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.springframework.beans.factory.BeanCreationException; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.test.util.EnvironmentTestUtils; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateAutoConfigurationTests.java index a4ff2b1c339..365e111c8ec 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -25,7 +25,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterContextPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterContextPathTests.java index 5d5fd9b1090..3c0c6a24f06 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterContextPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterContextPathTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -33,7 +33,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterPathTests.java index 32afffbe3be..c6795085460 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterPathTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -33,7 +33,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomLoadOnStartupTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomLoadOnStartupTests.java index d6f6974e19e..c5467ada60a 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomLoadOnStartupTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomLoadOnStartupTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -28,7 +28,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomObjectMapperProviderTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomObjectMapperProviderTests.java index 60a67e5014a..7f8a8496a97 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomObjectMapperProviderTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomObjectMapperProviderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -32,7 +32,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletContextPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletContextPathTests.java index 2ea08f65734..0e0f0992f4b 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletContextPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletContextPathTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -33,7 +33,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletPathTests.java index 88c2b740a4a..387031f8856 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletPathTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -33,7 +33,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultFilterPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultFilterPathTests.java index 2b331d96476..6c8e7cc06ae 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultFilterPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultFilterPathTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -32,7 +32,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultServletPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultServletPathTests.java index 1e5b79f671e..46a0dbf8c00 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultServletPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultServletPathTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -32,7 +32,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationObjectMapperProviderTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationObjectMapperProviderTests.java index d71e162732d..50ae8b60bf6 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationObjectMapperProviderTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationObjectMapperProviderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -33,7 +33,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationServletContainerTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationServletContainerTests.java index 9c31f625ed9..6a2ef4ab4e3 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationServletContainerTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationServletContainerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -30,7 +30,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationServletContainerTests.Application; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationWithoutApplicationPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationWithoutApplicationPathTests.java index 489597b39bd..24e589443b2 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationWithoutApplicationPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationWithoutApplicationPathTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -32,7 +32,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfigurationTests.java index 28c12412f6e..8bbffb356bb 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -37,7 +37,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfigurationTests.java index 8381792c746..1f9807997ab 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfigurationTests.java @@ -19,7 +19,7 @@ package org.springframework.boot.autoconfigure.ldap; import org.junit.After; import org.junit.Test; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.ldap.core.ContextSource; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfigurationTests.java index c425850826d..d5d5e54daee 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfigurationTests.java @@ -26,7 +26,7 @@ import org.junit.Before; import org.junit.Test; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.data.ldap.LdapDataAutoConfiguration; import org.springframework.boot.autoconfigure.ldap.LdapAutoConfiguration; import org.springframework.boot.test.util.EnvironmentTestUtils; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java index c9a3f58c19c..c98d09ce073 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -30,7 +30,7 @@ import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.springframework.beans.factory.BeanCreationException; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; import org.springframework.boot.liquibase.CommonsLoggingLiquibaseLogger; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/logging/AutoConfigurationReportLoggingInitializerTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/logging/AutoConfigurationReportLoggingInitializerTests.java index 5727d6ceadd..658566eeef3 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/logging/AutoConfigurationReportLoggingInitializerTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/logging/AutoConfigurationReportLoggingInitializerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -32,8 +32,8 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; import org.springframework.boot.context.event.ApplicationFailedEvent; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mobile/DeviceDelegatingViewResolverAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mobile/DeviceDelegatingViewResolverAutoConfigurationTests.java index 75747dfc718..d0779d8dc5c 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mobile/DeviceDelegatingViewResolverAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mobile/DeviceDelegatingViewResolverAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -29,7 +29,7 @@ import org.thymeleaf.spring4.view.ThymeleafViewResolver; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.PropertyAccessor; import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration; import org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration; import org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mobile/DeviceResolverAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mobile/DeviceResolverAutoConfigurationTests.java index 64fa947b244..b17ed352990 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mobile/DeviceResolverAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mobile/DeviceResolverAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -20,7 +20,7 @@ import org.junit.After; import org.junit.Test; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration; import org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration; import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mobile/SitePreferenceAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mobile/SitePreferenceAutoConfigurationTests.java index bf76b030e1e..833eaaa5aac 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mobile/SitePreferenceAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mobile/SitePreferenceAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -20,7 +20,7 @@ import org.junit.After; import org.junit.Test; import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; import org.springframework.boot.test.util.EnvironmentTestUtils; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfigurationTests.java index 85bc2ee0a78..888ff87d982 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -24,7 +24,7 @@ import com.mongodb.MongoClientOptions; import org.junit.After; import org.junit.Test; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfigurationTests.java index ff00e3402b1..55be935dacc 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfigurationTests.java @@ -28,7 +28,7 @@ import org.junit.After; import org.junit.Test; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration; import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; import org.springframework.boot.test.util.EnvironmentTestUtils; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationIntegrationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationIntegrationTests.java index 19104e9f4a5..7f24f2bcb41 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationIntegrationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -30,7 +30,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheStandaloneIntegrationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheStandaloneIntegrationTests.java index e1556d8ae8e..ab05824c9f8 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheStandaloneIntegrationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheStandaloneIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -23,7 +23,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.context.annotation.Configuration; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/web/MustacheWebIntegrationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/web/MustacheWebIntegrationTests.java index 9bd164815da..a9892c7a590 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/web/MustacheWebIntegrationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/web/MustacheWebIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -33,7 +33,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration; import org.springframework.boot.autoconfigure.mustache.MustacheResourceTemplateLoader; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java index 6aa692c2978..6a66bc0a98a 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -30,8 +30,8 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.springframework.beans.factory.BeanCreationException; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/CustomHibernateJpaAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/CustomHibernateJpaAutoConfigurationTests.java index e0fff71ec8b..19ee7c518d1 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/CustomHibernateJpaAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/CustomHibernateJpaAutoConfigurationTests.java @@ -26,8 +26,8 @@ import javax.sql.DataSource; import org.junit.After; import org.junit.Test; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.test.City; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfigurationTests.java index 9d7f81e547d..45472bd5823 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -23,8 +23,8 @@ import javax.servlet.DispatcherType; import org.junit.After; import org.junit.Test; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.test.City; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityFilterAutoConfigurationEarlyInitializationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityFilterAutoConfigurationEarlyInitializationTests.java index ee440b95613..5cabcc96f48 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityFilterAutoConfigurationEarlyInitializationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityFilterAutoConfigurationEarlyInitializationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -27,7 +27,7 @@ import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.autoconfigure.security.SecurityAutoConfigurationTests.WebSecurity; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityFilterAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityFilterAutoConfigurationTests.java index dafd3b3d65e..331627dedaf 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityFilterAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityFilterAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -19,7 +19,7 @@ package org.springframework.boot.autoconfigure.security; import org.junit.Test; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.autoconfigure.security.SecurityAutoConfigurationTests.WebSecurity; import org.springframework.boot.autoconfigure.security.SecurityFilterAutoConfigurationEarlyInitializationTests.ConverterBean; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SpringBootWebSecurityConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SpringBootWebSecurityConfigurationTests.java index dbfc8e27c1e..07812e28911 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SpringBootWebSecurityConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SpringBootWebSecurityConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -30,7 +30,7 @@ import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/jpa/JpaUserDetailsTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/jpa/JpaUserDetailsTests.java index 4a6e447d887..ce30f0327b1 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/jpa/JpaUserDetailsTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/jpa/JpaUserDetailsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -20,7 +20,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfigurationTests.java index 3deccd09f8d..877dab79911 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfigurationTests.java @@ -25,7 +25,7 @@ import org.junit.Test; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.security.oauth2.OAuth2ClientProperties; import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2RestOperationsConfiguration; import org.springframework.boot.autoconfigure.social.FacebookAutoConfiguration; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/UserInfoTokenServicesRefreshTokenTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/UserInfoTokenServicesRefreshTokenTests.java index 0538be2fbc7..8062db40142 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/UserInfoTokenServicesRefreshTokenTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/UserInfoTokenServicesRefreshTokenTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -24,7 +24,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/sso/MinimalSecureWebConfiguration.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/sso/MinimalSecureWebConfiguration.java index b38b0f1afe5..6aa4994e947 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/sso/MinimalSecureWebConfiguration.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/sso/MinimalSecureWebConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2017 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. @@ -22,7 +22,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/AbstractSessionAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/AbstractSessionAutoConfigurationTests.java index 2d589660a43..3e656bd1a78 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/AbstractSessionAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/AbstractSessionAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -21,7 +21,7 @@ import java.util.Collection; import org.junit.After; import org.springframework.beans.DirectFieldAccessor; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.session.SessionRepository; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfigurationTests.java index 490dde9381e..86c3b34ce41 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -33,7 +33,7 @@ import org.thymeleaf.templateresolver.ITemplateResolver; import org.thymeleaf.templateresolver.TemplateResolver; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.test.rule.OutputCapture; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerDirectMockMvcTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerDirectMockMvcTests.java index d57fd82acf8..4879481093a 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerDirectMockMvcTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerDirectMockMvcTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -34,7 +34,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.test.util.ApplicationContextTestUtils; import org.springframework.context.annotation.Configuration; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerMockMvcTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerMockMvcTests.java index 6bcea6e7cd2..3ed4e8a9a0c 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerMockMvcTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerMockMvcTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -34,7 +34,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/DefaultErrorViewIntegrationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/DefaultErrorViewIntegrationTests.java index edc47133d46..129b9506a83 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/DefaultErrorViewIntegrationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/DefaultErrorViewIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -28,7 +28,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/FilterOrderingIntegrationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/FilterOrderingIntegrationTests.java index 94cfb99c9ee..3f7121df6e9 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/FilterOrderingIntegrationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/FilterOrderingIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -25,7 +25,7 @@ import javax.servlet.Filter; import org.junit.After; import org.junit.Test; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration; import org.springframework.boot.autoconfigure.session.SessionAutoConfiguration; import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/RemappedErrorViewIntegrationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/RemappedErrorViewIntegrationTests.java index af605151782..035af39c4d0 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/RemappedErrorViewIntegrationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/RemappedErrorViewIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -19,7 +19,7 @@ package org.springframework.boot.autoconfigure.web; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfigurationTests.java index 358f3e458e1..0c2ad2fa72d 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -24,7 +24,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java index 17e0fbf30db..dc713a38f44 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -37,7 +37,7 @@ import org.junit.rules.ExpectedException; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration.WelcomePageHandlerMapping; import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; diff --git a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/RemoteDevToolsAutoConfigurationTests.java b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/RemoteDevToolsAutoConfigurationTests.java index c9b591c6f01..5b44d59dd8d 100644 --- a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/RemoteDevToolsAutoConfigurationTests.java +++ b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/RemoteDevToolsAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -25,7 +25,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.devtools.remote.server.DispatcherFilter; import org.springframework.boot.devtools.restart.MockRestarter; diff --git a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index ec778d3eda6..4a273a33f84 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -113,7 +113,7 @@ content into your application; rather pick only the properties that you need. # FILE ENCODING ({sc-spring-boot}/context/FileEncodingApplicationListener.{sc-ext}[FileEncodingApplicationListener]) spring.mandatory-file-encoding= # Expected character encoding the application must use. - # INTERNATIONALIZATION ({sc-spring-boot-autoconfigure}/MessageSourceAutoConfiguration.{sc-ext}[MessageSourceAutoConfiguration]) + # INTERNATIONALIZATION ({sc-spring-boot-autoconfigure}/context/MessageSourceAutoConfiguration.{sc-ext}[MessageSourceAutoConfiguration]) spring.messages.always-use-message-format=false # Set whether to always apply the MessageFormat rules, parsing even messages without arguments. spring.messages.basename=messages # Comma-separated list of basenames, each following the ResourceBundle convention. spring.messages.cache-seconds=-1 # Loaded resource bundle files cache expiration, in seconds. When set to -1, bundles are cached forever. diff --git a/spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java b/spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java index a811d589012..af9dbc744ee 100644 --- a/spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -27,7 +27,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; diff --git a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java index 2ec1de04674..d028fddc668 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -23,7 +23,7 @@ import sample.tomcat.web.SampleController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration; diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/SampleWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/SampleWebSocketsApplicationTests.java index 35031bc9b18..063f8849526 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/SampleWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/SampleWebSocketsApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -32,7 +32,7 @@ import samples.websocket.jetty.client.SimpleGreetingService; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/echo/CustomContainerWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/echo/CustomContainerWebSocketsApplicationTests.java index 675aa5c07f6..095d75e6e24 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/echo/CustomContainerWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/echo/CustomContainerWebSocketsApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -34,7 +34,7 @@ import samples.websocket.jetty.echo.CustomContainerWebSocketsApplicationTests.Cu import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/test/java/samples/websocket/jetty93/SampleWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/test/java/samples/websocket/jetty93/SampleWebSocketsApplicationTests.java index a3ae520cf9e..da4364c7d72 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/test/java/samples/websocket/jetty93/SampleWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/test/java/samples/websocket/jetty93/SampleWebSocketsApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -31,7 +31,7 @@ import samples.websocket.jetty93.client.SimpleGreetingService; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/test/java/samples/websocket/jetty93/echo/CustomContainerWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/test/java/samples/websocket/jetty93/echo/CustomContainerWebSocketsApplicationTests.java index 92790abcc37..6a868989226 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/test/java/samples/websocket/jetty93/echo/CustomContainerWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty93/src/test/java/samples/websocket/jetty93/echo/CustomContainerWebSocketsApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -32,7 +32,7 @@ import samples.websocket.jetty93.echo.CustomContainerWebSocketsApplicationTests. import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/SampleWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/SampleWebSocketsApplicationTests.java index 4e9ed88d217..83bf872272c 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/SampleWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/SampleWebSocketsApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -30,7 +30,7 @@ import samples.websocket.tomcat.client.SimpleGreetingService; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/echo/CustomContainerWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/echo/CustomContainerWebSocketsApplicationTests.java index bf46eb74ea5..2a9c7d9cf43 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/echo/CustomContainerWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/echo/CustomContainerWebSocketsApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -32,7 +32,7 @@ import samples.websocket.tomcat.echo.CustomContainerWebSocketsApplicationTests.C import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/SampleWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/SampleWebSocketsApplicationTests.java index 1752753b40f..383b3a478c7 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/SampleWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/SampleWebSocketsApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -30,7 +30,7 @@ import samples.websocket.undertow.client.SimpleGreetingService; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/echo/CustomContainerWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/echo/CustomContainerWebSocketsApplicationTests.java index 647b75985ca..329840959fb 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/echo/CustomContainerWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/echo/CustomContainerWebSocketsApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -32,7 +32,7 @@ import samples.websocket.undertow.echo.CustomContainerWebSocketsApplicationTests import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory; diff --git a/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring.factories b/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring.factories index 9b55493c204..9d022f55f9d 100644 --- a/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring.factories +++ b/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring.factories @@ -77,12 +77,12 @@ org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration # AutoConfigureWebMvc auto-configuration imports org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureWebMvc=\ +org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration,\ org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration,\ org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration,\ org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration,\ org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration,\ org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration,\ -org.springframework.boot.autoconfigure.MessageSourceAutoConfiguration,\ org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration,\ org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration,\ org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration,\ From b225b7f33a7db95cd5623de941c6f0fe3a2035af Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 19 Jan 2017 14:08:59 -0800 Subject: [PATCH 02/14] Rename EnableAutoConfigurationImportSelector Rename EnableAutoConfigurationImportSelector to the more general AutoConfigurationImportSelector since it's now used for more than just the enable annotation. The existing EnableAutoConfigurationImportSelector class remains in a deprecated form so that it can be made package-private again in Spring Boot 2.0. Fixes gh-8072 --- .../AutoConfigurationImportSelector.java | 315 ++++++++++++++++++ .../EnableAutoConfiguration.java | 3 +- ...EnableAutoConfigurationImportSelector.java | 276 +-------------- ...ImportAutoConfigurationImportSelector.java | 5 +- ...AutoConfigurationImportSelectorTests.java} | 12 +- 5 files changed, 330 insertions(+), 281 deletions(-) create mode 100644 spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java rename spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/{EnableAutoConfigurationImportSelectorTests.java => AutoConfigurationImportSelectorTests.java} (95%) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java new file mode 100644 index 00000000000..a42b8afe691 --- /dev/null +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java @@ -0,0 +1,315 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanClassLoaderAware; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.BeanFactoryAware; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport; +import org.springframework.boot.bind.PropertySourcesPropertyValues; +import org.springframework.boot.bind.RelaxedDataBinder; +import org.springframework.boot.bind.RelaxedPropertyResolver; +import org.springframework.context.EnvironmentAware; +import org.springframework.context.ResourceLoaderAware; +import org.springframework.context.annotation.DeferredImportSelector; +import org.springframework.core.Ordered; +import org.springframework.core.annotation.AnnotationAttributes; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.Environment; +import org.springframework.core.io.ResourceLoader; +import org.springframework.core.io.support.SpringFactoriesLoader; +import org.springframework.core.type.AnnotationMetadata; +import org.springframework.core.type.classreading.CachingMetadataReaderFactory; +import org.springframework.core.type.classreading.MetadataReaderFactory; +import org.springframework.util.Assert; +import org.springframework.util.ClassUtils; + +/** + * {@link DeferredImportSelector} to handle {@link EnableAutoConfiguration + * auto-configuration}. This class can also be subclassed if a custom variant of + * {@link EnableAutoConfiguration @EnableAutoConfiguration}. is needed. + * + * @author Phillip Webb + * @author Andy Wilkinson + * @author Stephane Nicoll + * @author Madhura Bhave + * @since 1.3.0 + * @see EnableAutoConfiguration + */ +public class AutoConfigurationImportSelector + implements DeferredImportSelector, BeanClassLoaderAware, ResourceLoaderAware, + BeanFactoryAware, EnvironmentAware, Ordered { + + private static final String[] NO_IMPORTS = {}; + + private ConfigurableListableBeanFactory beanFactory; + + private Environment environment; + + private ClassLoader beanClassLoader; + + private ResourceLoader resourceLoader; + + @Override + public String[] selectImports(AnnotationMetadata metadata) { + if (!isEnabled(metadata)) { + return NO_IMPORTS; + } + try { + AnnotationAttributes attributes = getAttributes(metadata); + List configurations = getCandidateConfigurations(metadata, + attributes); + configurations = removeDuplicates(configurations); + Set exclusions = getExclusions(metadata, attributes); + checkExcludedClasses(configurations, exclusions); + configurations.removeAll(exclusions); + configurations = sort(configurations); + recordWithConditionEvaluationReport(configurations, exclusions); + return configurations.toArray(new String[configurations.size()]); + } + catch (IOException ex) { + throw new IllegalStateException(ex); + } + } + + protected boolean isEnabled(AnnotationMetadata metadata) { + if (getClass().equals(AutoConfigurationImportSelector.class)) { + return this.environment.getProperty( + EnableAutoConfiguration.ENABLED_OVERRIDE_PROPERTY, Boolean.class, + true); + } + return true; + } + + /** + * Return the appropriate {@link AnnotationAttributes} from the + * {@link AnnotationMetadata}. By default this method will return attributes for + * {@link #getAnnotationClass()}. + * @param metadata the annotation metadata + * @return annotation attributes + */ + protected AnnotationAttributes getAttributes(AnnotationMetadata metadata) { + String name = getAnnotationClass().getName(); + AnnotationAttributes attributes = AnnotationAttributes + .fromMap(metadata.getAnnotationAttributes(name, true)); + Assert.notNull(attributes, + "No auto-configuration attributes found. Is " + metadata.getClassName() + + " annotated with " + ClassUtils.getShortName(name) + "?"); + return attributes; + } + + /** + * Return the source annotation class used by the selector. + * @return the annotation class + */ + protected Class getAnnotationClass() { + return EnableAutoConfiguration.class; + } + + /** + * Return the auto-configuration class names that should be considered. By default + * this method will load candidates using {@link SpringFactoriesLoader} with + * {@link #getSpringFactoriesLoaderFactoryClass()}. + * @param metadata the source metadata + * @param attributes the {@link #getAttributes(AnnotationMetadata) annotation + * attributes} + * @return a list of candidate configurations + */ + protected List getCandidateConfigurations(AnnotationMetadata metadata, + AnnotationAttributes attributes) { + List configurations = SpringFactoriesLoader.loadFactoryNames( + getSpringFactoriesLoaderFactoryClass(), getBeanClassLoader()); + Assert.notEmpty(configurations, + "No auto configuration classes found in META-INF/spring.factories. If you " + + "are using a custom packaging, make sure that file is correct."); + return configurations; + } + + /** + * Return the class used by {@link SpringFactoriesLoader} to load configuration + * candidates. + * @return the factory class + */ + protected Class getSpringFactoriesLoaderFactoryClass() { + return EnableAutoConfiguration.class; + } + + private void checkExcludedClasses(List configurations, + Set exclusions) { + List invalidExcludes = new ArrayList(); + for (String exclusion : exclusions) { + if (ClassUtils.isPresent(exclusion, getClass().getClassLoader()) + && !configurations.contains(exclusion)) { + invalidExcludes.add(exclusion); + } + } + if (!invalidExcludes.isEmpty()) { + handleInvalidExcludes(invalidExcludes); + } + } + + /** + * Handle any invalid excludes that have been specified. + * @param invalidExcludes the list of invalid excludes (will always have at least one + * element) + */ + protected void handleInvalidExcludes(List invalidExcludes) { + StringBuilder message = new StringBuilder(); + for (String exclude : invalidExcludes) { + message.append("\t- ").append(exclude).append(String.format("%n")); + } + throw new IllegalStateException(String + .format("The following classes could not be excluded because they are" + + " not auto-configuration classes:%n%s", message)); + } + + /** + * Return any exclusions that limit the candidate configurations. + * @param metadata the source metadata + * @param attributes the {@link #getAttributes(AnnotationMetadata) annotation + * attributes} + * @return exclusions or an empty set + */ + protected Set getExclusions(AnnotationMetadata metadata, + AnnotationAttributes attributes) { + Set excluded = new LinkedHashSet(); + excluded.addAll(asList(attributes, "exclude")); + excluded.addAll(Arrays.asList(attributes.getStringArray("excludeName"))); + excluded.addAll(getExcludeAutoConfigurationsProperty()); + return excluded; + } + + private List getExcludeAutoConfigurationsProperty() { + if (getEnvironment() instanceof ConfigurableEnvironment) { + Excludes excludes = new Excludes(); + RelaxedDataBinder binder = new RelaxedDataBinder(excludes, + "spring.autoconfigure."); + binder.bind(new PropertySourcesPropertyValues( + ((ConfigurableEnvironment) getEnvironment()).getPropertySources())); + return excludes.getExclude(); + } + RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(getEnvironment(), + "spring.autoconfigure."); + String[] exclude = resolver.getProperty("exclude", String[].class); + return (Arrays.asList(exclude == null ? new String[0] : exclude)); + } + + private List sort(List configurations) throws IOException { + configurations = new AutoConfigurationSorter(getMetadataReaderFactory()) + .getInPriorityOrder(configurations); + return configurations; + } + + private MetadataReaderFactory getMetadataReaderFactory() { + try { + return getBeanFactory().getBean( + SharedMetadataReaderFactoryContextInitializer.BEAN_NAME, + MetadataReaderFactory.class); + } + catch (NoSuchBeanDefinitionException ex) { + return new CachingMetadataReaderFactory(this.resourceLoader); + } + } + + private void recordWithConditionEvaluationReport(List configurations, + Collection exclusions) throws IOException { + ConditionEvaluationReport report = ConditionEvaluationReport + .get(getBeanFactory()); + report.recordEvaluationCandidates(configurations); + report.recordExclusions(exclusions); + } + + protected final List removeDuplicates(List list) { + return new ArrayList(new LinkedHashSet(list)); + } + + protected final List asList(AnnotationAttributes attributes, String name) { + String[] value = attributes.getStringArray(name); + return Arrays.asList(value == null ? new String[0] : value); + } + + @Override + public void setBeanFactory(BeanFactory beanFactory) throws BeansException { + Assert.isInstanceOf(ConfigurableListableBeanFactory.class, beanFactory); + this.beanFactory = (ConfigurableListableBeanFactory) beanFactory; + } + + protected final ConfigurableListableBeanFactory getBeanFactory() { + return this.beanFactory; + } + + @Override + public void setBeanClassLoader(ClassLoader classLoader) { + this.beanClassLoader = classLoader; + } + + protected ClassLoader getBeanClassLoader() { + return this.beanClassLoader; + } + + @Override + public void setEnvironment(Environment environment) { + this.environment = environment; + } + + protected final Environment getEnvironment() { + return this.environment; + } + + @Override + public void setResourceLoader(ResourceLoader resourceLoader) { + this.resourceLoader = resourceLoader; + } + + protected final ResourceLoader getResourceLoader() { + return this.resourceLoader; + } + + @Override + public int getOrder() { + return Ordered.LOWEST_PRECEDENCE - 1; + } + + /** + * Bindable object used to get excludes. + */ + static class Excludes { + + private List exclude = new ArrayList(); + + public List getExclude() { + return this.exclude; + } + + public void setExclude(List excludes) { + this.exclude = excludes; + } + + } + +} diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfiguration.java index 810237d3ecd..95fcaa4cf46 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -67,6 +67,7 @@ import org.springframework.core.io.support.SpringFactoriesLoader; * @see ConditionalOnClass * @see AutoConfigureAfter */ +@SuppressWarnings("deprecation") @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelector.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelector.java index ea167be8c6e..50fcb11ed31 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelector.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelector.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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,44 +16,15 @@ package org.springframework.boot.autoconfigure; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; - -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.BeanClassLoaderAware; -import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport; -import org.springframework.boot.bind.PropertySourcesPropertyValues; -import org.springframework.boot.bind.RelaxedDataBinder; -import org.springframework.boot.bind.RelaxedPropertyResolver; -import org.springframework.context.EnvironmentAware; -import org.springframework.context.ResourceLoaderAware; import org.springframework.context.annotation.DeferredImportSelector; -import org.springframework.core.Ordered; -import org.springframework.core.annotation.AnnotationAttributes; -import org.springframework.core.env.ConfigurableEnvironment; -import org.springframework.core.env.Environment; -import org.springframework.core.io.ResourceLoader; -import org.springframework.core.io.support.SpringFactoriesLoader; import org.springframework.core.type.AnnotationMetadata; -import org.springframework.core.type.classreading.CachingMetadataReaderFactory; -import org.springframework.core.type.classreading.MetadataReaderFactory; -import org.springframework.util.Assert; -import org.springframework.util.ClassUtils; /** * {@link DeferredImportSelector} to handle {@link EnableAutoConfiguration * auto-configuration}. This class can also be subclassed if a custom variant of * {@link EnableAutoConfiguration @EnableAutoConfiguration}. is needed. * + * @deprecated as of 1.5 in favor of {@link AutoConfigurationImportSelector} * @author Phillip Webb * @author Andy Wilkinson * @author Stephane Nicoll @@ -61,255 +32,18 @@ import org.springframework.util.ClassUtils; * @since 1.3.0 * @see EnableAutoConfiguration */ +@Deprecated public class EnableAutoConfigurationImportSelector - implements DeferredImportSelector, BeanClassLoaderAware, ResourceLoaderAware, - BeanFactoryAware, EnvironmentAware, Ordered { - - private static final String[] NO_IMPORTS = {}; - - private ConfigurableListableBeanFactory beanFactory; - - private Environment environment; - - private ClassLoader beanClassLoader; - - private ResourceLoader resourceLoader; + extends AutoConfigurationImportSelector { @Override - public String[] selectImports(AnnotationMetadata metadata) { - if (!isEnabled(metadata)) { - return NO_IMPORTS; - } - try { - AnnotationAttributes attributes = getAttributes(metadata); - List configurations = getCandidateConfigurations(metadata, - attributes); - configurations = removeDuplicates(configurations); - Set exclusions = getExclusions(metadata, attributes); - checkExcludedClasses(configurations, exclusions); - configurations.removeAll(exclusions); - configurations = sort(configurations); - recordWithConditionEvaluationReport(configurations, exclusions); - return configurations.toArray(new String[configurations.size()]); - } - catch (IOException ex) { - throw new IllegalStateException(ex); - } - } - protected boolean isEnabled(AnnotationMetadata metadata) { if (getClass().equals(EnableAutoConfigurationImportSelector.class)) { - return this.environment.getProperty( + return getEnvironment().getProperty( EnableAutoConfiguration.ENABLED_OVERRIDE_PROPERTY, Boolean.class, true); } return true; } - /** - * Return the appropriate {@link AnnotationAttributes} from the - * {@link AnnotationMetadata}. By default this method will return attributes for - * {@link #getAnnotationClass()}. - * @param metadata the annotation metadata - * @return annotation attributes - */ - protected AnnotationAttributes getAttributes(AnnotationMetadata metadata) { - String name = getAnnotationClass().getName(); - AnnotationAttributes attributes = AnnotationAttributes - .fromMap(metadata.getAnnotationAttributes(name, true)); - Assert.notNull(attributes, - "No auto-configuration attributes found. Is " + metadata.getClassName() - + " annotated with " + ClassUtils.getShortName(name) + "?"); - return attributes; - } - - /** - * Return the source annotation class used by the selector. - * @return the annotation class - */ - protected Class getAnnotationClass() { - return EnableAutoConfiguration.class; - } - - /** - * Return the auto-configuration class names that should be considered. By default - * this method will load candidates using {@link SpringFactoriesLoader} with - * {@link #getSpringFactoriesLoaderFactoryClass()}. - * @param metadata the source metadata - * @param attributes the {@link #getAttributes(AnnotationMetadata) annotation - * attributes} - * @return a list of candidate configurations - */ - protected List getCandidateConfigurations(AnnotationMetadata metadata, - AnnotationAttributes attributes) { - List configurations = SpringFactoriesLoader.loadFactoryNames( - getSpringFactoriesLoaderFactoryClass(), getBeanClassLoader()); - Assert.notEmpty(configurations, - "No auto configuration classes found in META-INF/spring.factories. If you " - + "are using a custom packaging, make sure that file is correct."); - return configurations; - } - - /** - * Return the class used by {@link SpringFactoriesLoader} to load configuration - * candidates. - * @return the factory class - */ - protected Class getSpringFactoriesLoaderFactoryClass() { - return EnableAutoConfiguration.class; - } - - private void checkExcludedClasses(List configurations, - Set exclusions) { - List invalidExcludes = new ArrayList(); - for (String exclusion : exclusions) { - if (ClassUtils.isPresent(exclusion, getClass().getClassLoader()) - && !configurations.contains(exclusion)) { - invalidExcludes.add(exclusion); - } - } - if (!invalidExcludes.isEmpty()) { - handleInvalidExcludes(invalidExcludes); - } - } - - /** - * Handle any invalid excludes that have been specified. - * @param invalidExcludes the list of invalid excludes (will always have at least one - * element) - */ - protected void handleInvalidExcludes(List invalidExcludes) { - StringBuilder message = new StringBuilder(); - for (String exclude : invalidExcludes) { - message.append("\t- ").append(exclude).append(String.format("%n")); - } - throw new IllegalStateException(String - .format("The following classes could not be excluded because they are" - + " not auto-configuration classes:%n%s", message)); - } - - /** - * Return any exclusions that limit the candidate configurations. - * @param metadata the source metadata - * @param attributes the {@link #getAttributes(AnnotationMetadata) annotation - * attributes} - * @return exclusions or an empty set - */ - protected Set getExclusions(AnnotationMetadata metadata, - AnnotationAttributes attributes) { - Set excluded = new LinkedHashSet(); - excluded.addAll(asList(attributes, "exclude")); - excluded.addAll(Arrays.asList(attributes.getStringArray("excludeName"))); - excluded.addAll(getExcludeAutoConfigurationsProperty()); - return excluded; - } - - private List getExcludeAutoConfigurationsProperty() { - if (getEnvironment() instanceof ConfigurableEnvironment) { - Excludes excludes = new Excludes(); - RelaxedDataBinder binder = new RelaxedDataBinder(excludes, - "spring.autoconfigure."); - binder.bind(new PropertySourcesPropertyValues( - ((ConfigurableEnvironment) getEnvironment()).getPropertySources())); - return excludes.getExclude(); - } - RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(getEnvironment(), - "spring.autoconfigure."); - String[] exclude = resolver.getProperty("exclude", String[].class); - return (Arrays.asList(exclude == null ? new String[0] : exclude)); - } - - private List sort(List configurations) throws IOException { - configurations = new AutoConfigurationSorter(getMetadataReaderFactory()) - .getInPriorityOrder(configurations); - return configurations; - } - - private MetadataReaderFactory getMetadataReaderFactory() { - try { - return getBeanFactory().getBean( - SharedMetadataReaderFactoryContextInitializer.BEAN_NAME, - MetadataReaderFactory.class); - } - catch (NoSuchBeanDefinitionException ex) { - return new CachingMetadataReaderFactory(this.resourceLoader); - } - } - - private void recordWithConditionEvaluationReport(List configurations, - Collection exclusions) throws IOException { - ConditionEvaluationReport report = ConditionEvaluationReport - .get(getBeanFactory()); - report.recordEvaluationCandidates(configurations); - report.recordExclusions(exclusions); - } - - protected final List removeDuplicates(List list) { - return new ArrayList(new LinkedHashSet(list)); - } - - protected final List asList(AnnotationAttributes attributes, String name) { - String[] value = attributes.getStringArray(name); - return Arrays.asList(value == null ? new String[0] : value); - } - - @Override - public void setBeanFactory(BeanFactory beanFactory) throws BeansException { - Assert.isInstanceOf(ConfigurableListableBeanFactory.class, beanFactory); - this.beanFactory = (ConfigurableListableBeanFactory) beanFactory; - } - - protected final ConfigurableListableBeanFactory getBeanFactory() { - return this.beanFactory; - } - - @Override - public void setBeanClassLoader(ClassLoader classLoader) { - this.beanClassLoader = classLoader; - } - - protected ClassLoader getBeanClassLoader() { - return this.beanClassLoader; - } - - @Override - public void setEnvironment(Environment environment) { - this.environment = environment; - } - - protected final Environment getEnvironment() { - return this.environment; - } - - @Override - public void setResourceLoader(ResourceLoader resourceLoader) { - this.resourceLoader = resourceLoader; - } - - protected final ResourceLoader getResourceLoader() { - return this.resourceLoader; - } - - @Override - public int getOrder() { - return Ordered.LOWEST_PRECEDENCE - 1; - } - - /** - * Bindable object used to get excludes. - */ - static class Excludes { - - private List exclude = new ArrayList(); - - public List getExclude() { - return this.exclude; - } - - public void setExclude(List excludes) { - this.exclude = excludes; - } - - } - } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelector.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelector.java index 44021075a95..834e392cb18 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelector.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelector.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -44,8 +44,7 @@ import org.springframework.util.ObjectUtils; * @author Phillip Webb * @author Andy Wilkinson */ -class ImportAutoConfigurationImportSelector - extends EnableAutoConfigurationImportSelector { +class ImportAutoConfigurationImportSelector extends AutoConfigurationImportSelector { private static final Set ANNOTATION_NAMES; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelectorTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelectorTests.java similarity index 95% rename from spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelectorTests.java rename to spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelectorTests.java index 7c95df0df5d..f95ced6b63c 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelectorTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -39,15 +39,15 @@ import org.springframework.mock.env.MockEnvironment; import static org.assertj.core.api.Assertions.assertThat; /** - * Tests for {@link EnableAutoConfigurationImportSelector} + * Tests for {@link AutoConfigurationImportSelector} * * @author Andy Wilkinson * @author Stephane Nicoll * @author Madhura Bhave */ -public class EnableAutoConfigurationImportSelectorTests { +public class AutoConfigurationImportSelectorTests { - private final EnableAutoConfigurationImportSelector importSelector = new EnableAutoConfigurationImportSelector(); + private final AutoConfigurationImportSelector importSelector = new AutoConfigurationImportSelector(); private final ConfigurableListableBeanFactory beanFactory = new DefaultListableBeanFactory(); @@ -191,7 +191,7 @@ public class EnableAutoConfigurationImportSelectorTests { throws Exception { this.environment.setProperty("spring.autoconfigure.exclude", "org.springframework.boot.autoconfigure." - + "EnableAutoConfigurationImportSelectorTests.TestConfiguration"); + + "AutoConfigurationImportSelectorTests.TestConfiguration"); this.expected.expect(IllegalStateException.class); selectImports(BasicEnableAutoConfiguration.class); } @@ -252,7 +252,7 @@ public class EnableAutoConfigurationImportSelectorTests { } - @EnableAutoConfiguration(excludeName = "org.springframework.boot.autoconfigure.EnableAutoConfigurationImportSelectorTests.TestConfiguration") + @EnableAutoConfiguration(excludeName = "org.springframework.boot.autoconfigure.AutoConfigurationImportSelectorTests.TestConfiguration") private class EnableAutoConfigurationWithFaultyClassNameExclude { } From 9650668291a72be93dc28f7ba1124704c90152d7 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sun, 22 Jan 2017 21:31:07 -0800 Subject: [PATCH 03/14] Remove dependency from `root` to `condition` Remove the slightly unusual dependency from the root autoconfigure pacakge to `condition`. Prior to this commit the link was required in ordere to populate the `ConditionEvaluationReport`. We now introduce a `AutoConfigurationImportListener` strategy that allows anyone to listen for AutoConfigurationImportEvents. The listener implementation is now used to update the ConditionEvaluationReport. Fixes gh-8073 --- .../AutoConfigurationImportEvent.java | 61 ++++++++++++++ .../AutoConfigurationImportListener.java | 52 ++++++++++++ .../AutoConfigurationImportSelector.java | 54 ++++++++---- ...ReportAutoConfigurationImportListener.java | 53 ++++++++++++ .../main/resources/META-INF/spring.factories | 4 + .../AutoConfigurationImportSelectorTests.java | 80 ++++++++++-------- ...eAutoConfigurationImportSelectorTests.java | 80 ++++++++++++++++++ ...tAutoConfigurationImportListenerTests.java | 84 +++++++++++++++++++ 8 files changed, 416 insertions(+), 52 deletions(-) create mode 100644 spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportEvent.java create mode 100644 spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportListener.java create mode 100644 spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReportAutoConfigurationImportListener.java create mode 100644 spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelectorTests.java create mode 100644 spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReportAutoConfigurationImportListenerTests.java diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportEvent.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportEvent.java new file mode 100644 index 00000000000..522d594a051 --- /dev/null +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportEvent.java @@ -0,0 +1,61 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure; + +import java.util.Collections; +import java.util.EventObject; +import java.util.List; +import java.util.Set; + +/** + * Event fired when auto-configuration classes are imported. + * + * @author Phillip Webb + * @since 1.5.0 + */ +public class AutoConfigurationImportEvent extends EventObject { + + private final List candidateConfigurations; + + private final Set exclusions; + + public AutoConfigurationImportEvent(Object source, + List candidateConfigurations, Set exclusions) { + super(source); + this.candidateConfigurations = Collections + .unmodifiableList(candidateConfigurations); + this.exclusions = Collections.unmodifiableSet(exclusions); + } + + /** + * Return the auto-configuration candidate configurations that are going to be + * imported. + * @return the configurations the auto-configuration candidates + */ + public List getCandidateConfigurations() { + return this.candidateConfigurations; + } + + /** + * Return the exclusions that were applied. + * @return the exclusions the exclusions applied + */ + public Set getExclusions() { + return this.exclusions; + } + +} diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportListener.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportListener.java new file mode 100644 index 00000000000..f904c145b74 --- /dev/null +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportListener.java @@ -0,0 +1,52 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure; + +import java.util.EventListener; + +import org.springframework.beans.factory.BeanClassLoaderAware; +import org.springframework.beans.factory.BeanFactoryAware; +import org.springframework.context.EnvironmentAware; +import org.springframework.context.ResourceLoaderAware; + +/** + * Listener that can be registered with {@code spring.factories} to receive details of + * imported auto-configurations. + *

+ * An {@link AutoConfigurationImportListener} may implement any of the following + * {@link org.springframework.beans.factory.Aware Aware} interfaces, and their respective + * methods will be called prior to + * {@link #onAutoConfigurationImportEvent(AutoConfigurationImportEvent)}: + *

    + *
  • {@link EnvironmentAware}
  • + *
  • {@link BeanFactoryAware }
  • + *
  • {@link BeanClassLoaderAware }
  • + *
  • {@link ResourceLoaderAware}
  • + *
+ * + * @author Phillip Webb + * @since 1.5.0 + */ +public interface AutoConfigurationImportListener extends EventListener { + + /** + * Handle an auto-configuration import event. + * @param event the event to respond to + */ + void onAutoConfigurationImportEvent(AutoConfigurationImportEvent event); + +} diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java index a42b8afe691..c4ba455780e 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java @@ -19,18 +19,17 @@ package org.springframework.boot.autoconfigure; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import org.springframework.beans.BeansException; +import org.springframework.beans.factory.Aware; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport; import org.springframework.boot.bind.PropertySourcesPropertyValues; import org.springframework.boot.bind.RelaxedDataBinder; import org.springframework.boot.bind.RelaxedPropertyResolver; @@ -89,7 +88,7 @@ public class AutoConfigurationImportSelector checkExcludedClasses(configurations, exclusions); configurations.removeAll(exclusions); configurations = sort(configurations); - recordWithConditionEvaluationReport(configurations, exclusions); + fireAutoConfigurationImportListeners(configurations, exclusions); return configurations.toArray(new String[configurations.size()]); } catch (IOException ex) { @@ -98,11 +97,6 @@ public class AutoConfigurationImportSelector } protected boolean isEnabled(AnnotationMetadata metadata) { - if (getClass().equals(AutoConfigurationImportSelector.class)) { - return this.environment.getProperty( - EnableAutoConfiguration.ENABLED_OVERRIDE_PROPERTY, Boolean.class, - true); - } return true; } @@ -236,14 +230,6 @@ public class AutoConfigurationImportSelector } } - private void recordWithConditionEvaluationReport(List configurations, - Collection exclusions) throws IOException { - ConditionEvaluationReport report = ConditionEvaluationReport - .get(getBeanFactory()); - report.recordEvaluationCandidates(configurations); - report.recordExclusions(exclusions); - } - protected final List removeDuplicates(List list) { return new ArrayList(new LinkedHashSet(list)); } @@ -253,6 +239,42 @@ public class AutoConfigurationImportSelector return Arrays.asList(value == null ? new String[0] : value); } + private void fireAutoConfigurationImportListeners(List configurations, + Set exclusions) { + List listeners = getAutoConfigurationImportListeners(); + if (!listeners.isEmpty()) { + AutoConfigurationImportEvent event = new AutoConfigurationImportEvent(this, + configurations, exclusions); + for (AutoConfigurationImportListener listener : listeners) { + invokeAwareMethods(listener); + listener.onAutoConfigurationImportEvent(event); + } + } + } + + protected List getAutoConfigurationImportListeners() { + return SpringFactoriesLoader.loadFactories(AutoConfigurationImportListener.class, + this.beanClassLoader); + } + + private void invokeAwareMethods(AutoConfigurationImportListener listener) { + if (listener instanceof Aware) { + if (listener instanceof BeanClassLoaderAware) { + ((BeanClassLoaderAware) listener) + .setBeanClassLoader(this.beanClassLoader); + } + if (listener instanceof BeanFactoryAware) { + ((BeanFactoryAware) listener).setBeanFactory(this.beanFactory); + } + if (listener instanceof EnvironmentAware) { + ((EnvironmentAware) listener).setEnvironment(this.environment); + } + if (listener instanceof ResourceLoaderAware) { + ((ResourceLoaderAware) listener).setResourceLoader(this.resourceLoader); + } + } + } + @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { Assert.isInstanceOf(ConfigurableListableBeanFactory.class, beanFactory); diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReportAutoConfigurationImportListener.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReportAutoConfigurationImportListener.java new file mode 100644 index 00000000000..208c7e25d02 --- /dev/null +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReportAutoConfigurationImportListener.java @@ -0,0 +1,53 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.condition; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.BeanFactoryAware; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.boot.autoconfigure.AutoConfigurationImportEvent; +import org.springframework.boot.autoconfigure.AutoConfigurationImportListener; + +/** + * {@link AutoConfigurationImportListener} to record results with the + * {@link ConditionEvaluationReport}. + * + * @author Phillip Webb + */ +class ConditionEvaluationReportAutoConfigurationImportListener + implements AutoConfigurationImportListener, BeanFactoryAware { + + private ConfigurableListableBeanFactory beanFactory; + + @Override + public void onAutoConfigurationImportEvent(AutoConfigurationImportEvent event) { + if (this.beanFactory != null) { + ConditionEvaluationReport report = ConditionEvaluationReport + .get(this.beanFactory); + report.recordEvaluationCandidates(event.getCandidateConfigurations()); + report.recordExclusions(event.getExclusions()); + } + } + + @Override + public void setBeanFactory(BeanFactory beanFactory) throws BeansException { + this.beanFactory = (beanFactory instanceof ConfigurableListableBeanFactory + ? (ConfigurableListableBeanFactory) beanFactory : null); + } + +} diff --git a/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories b/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories index 47b01e82ef2..876a630e29c 100644 --- a/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories +++ b/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories @@ -7,6 +7,10 @@ org.springframework.boot.autoconfigure.logging.AutoConfigurationReportLoggingIni org.springframework.context.ApplicationListener=\ org.springframework.boot.autoconfigure.BackgroundPreinitializer +# Auto Configuration Import Listeners +org.springframework.boot.autoconfigure.AutoConfigurationImportListener=\ +org.springframework.boot.autoconfigure.condition.ConditionEvaluationReportAutoConfigurationImportListener + # Auto Configure org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration,\ diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelectorTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelectorTests.java index f95ced6b63c..cd703994748 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelectorTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelectorTests.java @@ -16,6 +16,7 @@ package org.springframework.boot.autoconfigure; +import java.util.Collections; import java.util.List; import org.junit.Before; @@ -26,7 +27,6 @@ import org.mockito.MockitoAnnotations; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport; import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration; import org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration; import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration; @@ -47,7 +47,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ public class AutoConfigurationImportSelectorTests { - private final AutoConfigurationImportSelector importSelector = new AutoConfigurationImportSelector(); + private final TestAutoConfigurationImportSelector importSelector = new TestAutoConfigurationImportSelector(); private final ConfigurableListableBeanFactory beanFactory = new DefaultListableBeanFactory(); @@ -69,8 +69,7 @@ public class AutoConfigurationImportSelectorTests { String[] imports = selectImports(BasicEnableAutoConfiguration.class); assertThat(imports).hasSameSizeAs(SpringFactoriesLoader.loadFactoryNames( EnableAutoConfiguration.class, getClass().getClassLoader())); - assertThat(ConditionEvaluationReport.get(this.beanFactory).getExclusions()) - .isEmpty(); + assertThat(this.importSelector.getLastEvent().getExclusions()).isEmpty(); } @Test @@ -78,7 +77,7 @@ public class AutoConfigurationImportSelectorTests { String[] imports = selectImports( EnableAutoConfigurationWithClassExclusions.class); assertThat(imports).hasSize(getAutoConfigurationClassNames().size() - 1); - assertThat(ConditionEvaluationReport.get(this.beanFactory).getExclusions()) + assertThat(this.importSelector.getLastEvent().getExclusions()) .contains(FreeMarkerAutoConfiguration.class.getName()); } @@ -86,7 +85,7 @@ public class AutoConfigurationImportSelectorTests { public void classExclusionsAreAppliedWhenUsingSpringBootApplication() { String[] imports = selectImports(SpringBootApplicationWithClassExclusions.class); assertThat(imports).hasSize(getAutoConfigurationClassNames().size() - 1); - assertThat(ConditionEvaluationReport.get(this.beanFactory).getExclusions()) + assertThat(this.importSelector.getLastEvent().getExclusions()) .contains(FreeMarkerAutoConfiguration.class.getName()); } @@ -95,7 +94,7 @@ public class AutoConfigurationImportSelectorTests { String[] imports = selectImports( EnableAutoConfigurationWithClassNameExclusions.class); assertThat(imports).hasSize(getAutoConfigurationClassNames().size() - 1); - assertThat(ConditionEvaluationReport.get(this.beanFactory).getExclusions()) + assertThat(this.importSelector.getLastEvent().getExclusions()) .contains(MustacheAutoConfiguration.class.getName()); } @@ -104,7 +103,7 @@ public class AutoConfigurationImportSelectorTests { String[] imports = selectImports( SpringBootApplicationWithClassNameExclusions.class); assertThat(imports).hasSize(getAutoConfigurationClassNames().size() - 1); - assertThat(ConditionEvaluationReport.get(this.beanFactory).getExclusions()) + assertThat(this.importSelector.getLastEvent().getExclusions()) .contains(MustacheAutoConfiguration.class.getName()); } @@ -114,7 +113,7 @@ public class AutoConfigurationImportSelectorTests { FreeMarkerAutoConfiguration.class.getName()); String[] imports = selectImports(BasicEnableAutoConfiguration.class); assertThat(imports).hasSize(getAutoConfigurationClassNames().size() - 1); - assertThat(ConditionEvaluationReport.get(this.beanFactory).getExclusions()) + assertThat(this.importSelector.getLastEvent().getExclusions()) .contains(FreeMarkerAutoConfiguration.class.getName()); } @@ -125,9 +124,9 @@ public class AutoConfigurationImportSelectorTests { + MustacheAutoConfiguration.class.getName()); String[] imports = selectImports(BasicEnableAutoConfiguration.class); assertThat(imports).hasSize(getAutoConfigurationClassNames().size() - 2); - assertThat(ConditionEvaluationReport.get(this.beanFactory).getExclusions()) - .contains(FreeMarkerAutoConfiguration.class.getName(), - MustacheAutoConfiguration.class.getName()); + assertThat(this.importSelector.getLastEvent().getExclusions()).contains( + FreeMarkerAutoConfiguration.class.getName(), + MustacheAutoConfiguration.class.getName()); } @Test @@ -138,9 +137,9 @@ public class AutoConfigurationImportSelectorTests { MustacheAutoConfiguration.class.getName()); String[] imports = selectImports(BasicEnableAutoConfiguration.class); assertThat(imports).hasSize(getAutoConfigurationClassNames().size() - 2); - assertThat(ConditionEvaluationReport.get(this.beanFactory).getExclusions()) - .contains(FreeMarkerAutoConfiguration.class.getName(), - MustacheAutoConfiguration.class.getName()); + assertThat(this.importSelector.getLastEvent().getExclusions()).contains( + FreeMarkerAutoConfiguration.class.getName(), + MustacheAutoConfiguration.class.getName()); } @Test @@ -150,26 +149,10 @@ public class AutoConfigurationImportSelectorTests { String[] imports = selectImports( EnableAutoConfigurationWithClassAndClassNameExclusions.class); assertThat(imports).hasSize(getAutoConfigurationClassNames().size() - 3); - assertThat(ConditionEvaluationReport.get(this.beanFactory).getExclusions()) - .contains(FreeMarkerAutoConfiguration.class.getName(), - MustacheAutoConfiguration.class.getName(), - ThymeleafAutoConfiguration.class.getName()); - } - - @Test - public void propertyOverrideSetToTrue() throws Exception { - this.environment.setProperty(EnableAutoConfiguration.ENABLED_OVERRIDE_PROPERTY, - "true"); - String[] imports = selectImports(BasicEnableAutoConfiguration.class); - assertThat(imports).isNotEmpty(); - } - - @Test - public void propertyOverrideSetToFalse() throws Exception { - this.environment.setProperty(EnableAutoConfiguration.ENABLED_OVERRIDE_PROPERTY, - "false"); - String[] imports = selectImports(BasicEnableAutoConfiguration.class); - assertThat(imports).isEmpty(); + assertThat(this.importSelector.getLastEvent().getExclusions()).contains( + FreeMarkerAutoConfiguration.class.getName(), + MustacheAutoConfiguration.class.getName(), + ThymeleafAutoConfiguration.class.getName()); } @Test @@ -202,7 +185,7 @@ public class AutoConfigurationImportSelectorTests { this.environment.setProperty("spring.autoconfigure.exclude", "org.springframework.boot.autoconfigure.DoesNotExist2"); selectImports(EnableAutoConfigurationWithAbsentClassNameExclude.class); - assertThat(ConditionEvaluationReport.get(this.beanFactory).getExclusions()) + assertThat(this.importSelector.getLastEvent().getExclusions()) .containsExactlyInAnyOrder( "org.springframework.boot.autoconfigure.DoesNotExist1", "org.springframework.boot.autoconfigure.DoesNotExist2"); @@ -217,6 +200,31 @@ public class AutoConfigurationImportSelectorTests { getClass().getClassLoader()); } + private static class TestAutoConfigurationImportSelector + extends AutoConfigurationImportSelector { + + private AutoConfigurationImportEvent lastEvent; + + @Override + protected List getAutoConfigurationImportListeners() { + return Collections.singletonList( + new AutoConfigurationImportListener() { + + @Override + public void onAutoConfigurationImportEvent( + AutoConfigurationImportEvent event) { + TestAutoConfigurationImportSelector.this.lastEvent = event; + } + + }); + } + + public AutoConfigurationImportEvent getLastEvent() { + return this.lastEvent; + } + + } + @Configuration private class TestConfiguration { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelectorTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelectorTests.java new file mode 100644 index 00000000000..218ea0722ac --- /dev/null +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelectorTests.java @@ -0,0 +1,80 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.MockitoAnnotations; + +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.core.io.DefaultResourceLoader; +import org.springframework.core.type.StandardAnnotationMetadata; +import org.springframework.mock.env.MockEnvironment; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link EnableAutoConfigurationImportSelector} + * + * @author Andy Wilkinson + * @author Stephane Nicoll + * @author Madhura Bhave + */ +@SuppressWarnings("deprecation") +public class EnableAutoConfigurationImportSelectorTests { + + private final EnableAutoConfigurationImportSelector importSelector = new EnableAutoConfigurationImportSelector(); + + private final ConfigurableListableBeanFactory beanFactory = new DefaultListableBeanFactory(); + + private final MockEnvironment environment = new MockEnvironment(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + this.importSelector.setBeanFactory(this.beanFactory); + this.importSelector.setEnvironment(this.environment); + this.importSelector.setResourceLoader(new DefaultResourceLoader()); + } + + @Test + public void propertyOverrideSetToTrue() throws Exception { + this.environment.setProperty(EnableAutoConfiguration.ENABLED_OVERRIDE_PROPERTY, + "true"); + String[] imports = selectImports(BasicEnableAutoConfiguration.class); + assertThat(imports).isNotEmpty(); + } + + @Test + public void propertyOverrideSetToFalse() throws Exception { + this.environment.setProperty(EnableAutoConfiguration.ENABLED_OVERRIDE_PROPERTY, + "false"); + String[] imports = selectImports(BasicEnableAutoConfiguration.class); + assertThat(imports).isEmpty(); + } + + private String[] selectImports(Class source) { + return this.importSelector.selectImports(new StandardAnnotationMetadata(source)); + } + + @EnableAutoConfiguration + private class BasicEnableAutoConfiguration { + + } + +} diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReportAutoConfigurationImportListenerTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReportAutoConfigurationImportListenerTests.java new file mode 100644 index 00000000000..953b217c9a8 --- /dev/null +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReportAutoConfigurationImportListenerTests.java @@ -0,0 +1,84 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.condition; + +import java.util.Collections; +import java.util.List; +import java.util.Set; + +import org.junit.Before; +import org.junit.Test; + +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.boot.autoconfigure.AutoConfigurationImportEvent; +import org.springframework.boot.autoconfigure.AutoConfigurationImportListener; +import org.springframework.core.io.support.SpringFactoriesLoader; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link ConditionEvaluationReportAutoConfigurationImportListener}. + * + * @author Phillip Webb + */ +public class ConditionEvaluationReportAutoConfigurationImportListenerTests { + + private ConditionEvaluationReportAutoConfigurationImportListener listener; + + private final ConfigurableListableBeanFactory beanFactory = new DefaultListableBeanFactory(); + + @Before + public void setup() { + this.listener = new ConditionEvaluationReportAutoConfigurationImportListener(); + this.listener.setBeanFactory(this.beanFactory); + } + + @Test + public void shouldBeInSpringFactories() throws Exception { + List factories = SpringFactoriesLoader + .loadFactories(AutoConfigurationImportListener.class, null); + assertThat(factories).hasAtLeastOneElementOfType( + ConditionEvaluationReportAutoConfigurationImportListener.class); + } + + @Test + public void onAutoConfigurationImportEventShouldRecordCandidates() throws Exception { + List candidateConfigurations = Collections.singletonList("Test"); + Set exclusions = Collections.emptySet(); + AutoConfigurationImportEvent event = new AutoConfigurationImportEvent(this, + candidateConfigurations, exclusions); + this.listener.onAutoConfigurationImportEvent(event); + ConditionEvaluationReport report = ConditionEvaluationReport + .get(this.beanFactory); + assertThat(report.getUnconditionalClasses()) + .containsExactlyElementsOf(candidateConfigurations); + } + + @Test + public void onAutoConfigurationImportEventShouldRecordExclusions() throws Exception { + List candidateConfigurations = Collections.emptyList(); + Set exclusions = Collections.singleton("Test"); + AutoConfigurationImportEvent event = new AutoConfigurationImportEvent(this, + candidateConfigurations, exclusions); + this.listener.onAutoConfigurationImportEvent(event); + ConditionEvaluationReport report = ConditionEvaluationReport + .get(this.beanFactory); + assertThat(report.getExclusions()).containsExactlyElementsOf(exclusions); + } + +} From 996afafac6c495bcba5c88279f7dcdc2e4fb465a Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 19 Jan 2017 21:52:51 -0800 Subject: [PATCH 04/14] Optimize OnClassCondition isPresent check Update `OnClassCondition` to use its own `isPresent` rather than using `ClassUtils.isPresent`. Using our own implementation saves a few cycles since we never need to check for native types, and we don't support nested class references specified in the non `$` notation. See gh-7573 --- .../condition/OnClassCondition.java | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnClassCondition.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnClassCondition.java index 1709b23268b..62200e4007e 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnClassCondition.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnClassCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -111,7 +111,7 @@ class OnClassCondition extends SpringBootCondition { @Override public boolean matches(String className, ConditionContext context) { - return ClassUtils.isPresent(className, context.getClassLoader()); + return isPresent(className, context.getClassLoader()); } }, @@ -120,11 +120,32 @@ class OnClassCondition extends SpringBootCondition { @Override public boolean matches(String className, ConditionContext context) { - return !ClassUtils.isPresent(className, context.getClassLoader()); + return !isPresent(className, context.getClassLoader()); } }; + private static boolean isPresent(String className, ClassLoader classLoader) { + if (classLoader == null) { + classLoader = ClassUtils.getDefaultClassLoader(); + } + try { + forName(className, classLoader); + return true; + } + catch (Throwable ex) { + return false; + } + } + + private static Class forName(String className, ClassLoader classLoader) + throws ClassNotFoundException { + if (classLoader != null) { + return classLoader.loadClass(className); + } + return Class.forName(className); + } + public abstract boolean matches(String className, ConditionContext context); } From cfd5a73b64f674ed456f7c83c3d915212e626937 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sat, 21 Jan 2017 21:37:15 -0800 Subject: [PATCH 05/14] Don't call ReflectionUtils do deduce bean type Update `OnBeanCondition` to no longer call `ReflectionUtils` when deducing the bean method return type. Since Spring Framework 4.2 the return type has been directly available from `MethodMetadata`. See gh-7573 --- .../condition/OnBeanCondition.java | 31 ++++++------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnBeanCondition.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnBeanCondition.java index fddf6631c21..988eab9418a 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnBeanCondition.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnBeanCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -17,7 +17,6 @@ package org.springframework.boot.autoconfigure.condition; import java.lang.annotation.Annotation; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -43,8 +42,6 @@ import org.springframework.core.type.MethodMetadata; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.MultiValueMap; -import org.springframework.util.ReflectionUtils; -import org.springframework.util.ReflectionUtils.MethodCallback; import org.springframework.util.StringUtils; /** @@ -349,33 +346,23 @@ class OnBeanCondition extends SpringBootCondition implements ConfigurationCondit AnnotatedTypeMetadata metadata, final List beanTypes) { if (metadata instanceof MethodMetadata && metadata.isAnnotated(Bean.class.getName())) { - addDeducedBeanTypeForBeanMethod(context, metadata, beanTypes, - (MethodMetadata) metadata); + addDeducedBeanTypeForBeanMethod(context, (MethodMetadata) metadata, + beanTypes); } } private void addDeducedBeanTypeForBeanMethod(ConditionContext context, - AnnotatedTypeMetadata metadata, final List beanTypes, - final MethodMetadata methodMetadata) { + MethodMetadata metadata, final List beanTypes) { try { // We should be safe to load at this point since we are in the // REGISTER_BEAN phase - Class configClass = ClassUtils.forName( - methodMetadata.getDeclaringClassName(), context.getClassLoader()); - ReflectionUtils.doWithMethods(configClass, new MethodCallback() { - @Override - public void doWith(Method method) - throws IllegalArgumentException, IllegalAccessException { - if (methodMetadata.getMethodName().equals(method.getName())) { - beanTypes.add(method.getReturnType().getName()); - } - } - }); + Class returnType = ClassUtils.forName(metadata.getReturnTypeName(), + context.getClassLoader()); + beanTypes.add(returnType.getName()); } catch (Throwable ex) { - throw new BeanTypeDeductionException( - methodMetadata.getDeclaringClassName(), - methodMetadata.getMethodName(), ex); + throw new BeanTypeDeductionException(metadata.getDeclaringClassName(), + metadata.getMethodName(), ex); } } From 49fc72770684ab014369b2f7ef6d9ae66f1d22f2 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sat, 21 Jan 2017 07:05:27 -0800 Subject: [PATCH 06/14] Lazy initialize JacksonJsonParser ObjectMapper Update `JacksonJsonParser` to that the `ObjectMapper` is only initialized on first use. This performance optimization helps with startup times if nothing uses the parser. Fixes gh-8074 --- .../boot/json/JacksonJsonParser.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/json/JacksonJsonParser.java b/spring-boot/src/main/java/org/springframework/boot/json/JacksonJsonParser.java index c7a7c162daf..107f725d979 100644 --- a/spring-boot/src/main/java/org/springframework/boot/json/JacksonJsonParser.java +++ b/spring-boot/src/main/java/org/springframework/boot/json/JacksonJsonParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -34,12 +34,12 @@ public class JacksonJsonParser implements JsonParser { private static final TypeReference LIST_TYPE = new ListTypeReference(); - private final ObjectMapper objectMapper = new ObjectMapper(); + private ObjectMapper objectMapper; // Late binding @Override public Map parseMap(String json) { try { - return this.objectMapper.readValue(json, MAP_TYPE); + return getObjectMapper().readValue(json, MAP_TYPE); } catch (Exception ex) { throw new IllegalArgumentException("Cannot parse JSON", ex); @@ -49,13 +49,20 @@ public class JacksonJsonParser implements JsonParser { @Override public List parseList(String json) { try { - return this.objectMapper.readValue(json, LIST_TYPE); + return getObjectMapper().readValue(json, LIST_TYPE); } catch (Exception ex) { throw new IllegalArgumentException("Cannot parse JSON", ex); } } + private ObjectMapper getObjectMapper() { + if (this.objectMapper == null) { + this.objectMapper = new ObjectMapper(); + } + return this.objectMapper; + } + private static class MapTypeReference extends TypeReference> { }; From f8ded6de633aee8cba00722d98f912eaf1bde22d Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sat, 21 Jan 2017 07:38:52 -0800 Subject: [PATCH 07/14] Don't use DataBinder to work out excludes Update `AutoConfigurationImportSelector` so that exclude properties are loaded without invoking a `DataBinder`. This optimization helps to improve application startup time. See gh-7573 --- .../AutoConfigurationImportSelector.java | 44 ++++++++----------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java index c4ba455780e..0df9a1c36d5 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java @@ -19,8 +19,10 @@ package org.springframework.boot.autoconfigure; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; +import java.util.Map; import java.util.Set; import org.springframework.beans.BeansException; @@ -30,8 +32,6 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.boot.bind.PropertySourcesPropertyValues; -import org.springframework.boot.bind.RelaxedDataBinder; import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.context.EnvironmentAware; import org.springframework.context.ResourceLoaderAware; @@ -47,6 +47,7 @@ import org.springframework.core.type.classreading.CachingMetadataReaderFactory; import org.springframework.core.type.classreading.MetadataReaderFactory; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; +import org.springframework.util.StringUtils; /** * {@link DeferredImportSelector} to handle {@link EnableAutoConfiguration @@ -200,12 +201,22 @@ public class AutoConfigurationImportSelector private List getExcludeAutoConfigurationsProperty() { if (getEnvironment() instanceof ConfigurableEnvironment) { - Excludes excludes = new Excludes(); - RelaxedDataBinder binder = new RelaxedDataBinder(excludes, - "spring.autoconfigure."); - binder.bind(new PropertySourcesPropertyValues( - ((ConfigurableEnvironment) getEnvironment()).getPropertySources())); - return excludes.getExclude(); + RelaxedPropertyResolver resolver = new RelaxedPropertyResolver( + this.environment, "spring.autoconfigure."); + Map properties = resolver.getSubProperties("exclude"); + if (properties.isEmpty()) { + return Collections.emptyList(); + } + List excludes = new ArrayList(); + for (Map.Entry entry : properties.entrySet()) { + String name = entry.getKey(); + Object value = entry.getValue(); + if (name.isEmpty() || name.startsWith("[") && value != null) { + excludes.addAll( + StringUtils.commaDelimitedListToSet(String.valueOf(value))); + } + } + return excludes; } RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(getEnvironment(), "spring.autoconfigure."); @@ -317,21 +328,4 @@ public class AutoConfigurationImportSelector return Ordered.LOWEST_PRECEDENCE - 1; } - /** - * Bindable object used to get excludes. - */ - static class Excludes { - - private List exclude = new ArrayList(); - - public List getExclude() { - return this.exclude; - } - - public void setExclude(List excludes) { - this.exclude = excludes; - } - - } - } From ccf964eb9a9e1b6dafe02853d2097eacd553e47c Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sun, 22 Jan 2017 18:45:37 -0800 Subject: [PATCH 08/14] Optimize OnEnabledResourceChainCondition Optimize OnEnabledResourceChainCondition by removing the DataBinder. Properties are now read directly from the Environment. See gh-7573 --- .../web/OnEnabledResourceChainCondition.java | 22 +++++++++++++------ .../autoconfigure/web/ResourceProperties.java | 12 ++++++---- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/OnEnabledResourceChainCondition.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/OnEnabledResourceChainCondition.java index 04ab0800d83..52e702c5b6b 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/OnEnabledResourceChainCondition.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/OnEnabledResourceChainCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -19,11 +19,11 @@ package org.springframework.boot.autoconfigure.web; import org.springframework.boot.autoconfigure.condition.ConditionMessage; import org.springframework.boot.autoconfigure.condition.ConditionOutcome; import org.springframework.boot.autoconfigure.condition.SpringBootCondition; -import org.springframework.boot.bind.PropertySourcesPropertyValues; -import org.springframework.boot.bind.RelaxedDataBinder; +import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.context.annotation.Condition; import org.springframework.context.annotation.ConditionContext; import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.PropertyResolver; import org.springframework.core.type.AnnotatedTypeMetadata; import org.springframework.util.ClassUtils; @@ -32,6 +32,7 @@ import org.springframework.util.ClassUtils; * enabled. * * @author Stephane Nicoll + * @author Phillip Webb * @see ConditionalOnEnabledResourceChain */ class OnEnabledResourceChainCondition extends SpringBootCondition { @@ -43,10 +44,10 @@ class OnEnabledResourceChainCondition extends SpringBootCondition { AnnotatedTypeMetadata metadata) { ConfigurableEnvironment environment = (ConfigurableEnvironment) context .getEnvironment(); - ResourceProperties properties = new ResourceProperties(); - RelaxedDataBinder binder = new RelaxedDataBinder(properties, "spring.resources"); - binder.bind(new PropertySourcesPropertyValues(environment.getPropertySources())); - Boolean match = properties.getChain().getEnabled(); + boolean fixed = getEnabledProperty(environment, "strategy.fixed.", false); + boolean content = getEnabledProperty(environment, "strategy.content.", false); + Boolean chain = getEnabledProperty(environment, "", null); + Boolean match = ResourceProperties.Chain.getEnabled(fixed, content, chain); ConditionMessage.Builder message = ConditionMessage .forCondition(ConditionalOnEnabledResourceChain.class); if (match == null) { @@ -63,4 +64,11 @@ class OnEnabledResourceChainCondition extends SpringBootCondition { return ConditionOutcome.noMatch(message.because("disabled")); } + private Boolean getEnabledProperty(ConfigurableEnvironment environment, String key, + Boolean defaultValue) { + PropertyResolver resolver = new RelaxedPropertyResolver(environment, + "spring.resources.chain." + key); + return resolver.getProperty("enabled", Boolean.class, defaultValue); + } + } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java index 943edc202dd..71080b136b4 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -186,9 +186,8 @@ public class ResourceProperties implements ResourceLoaderAware { * settings are present. */ public Boolean getEnabled() { - Boolean strategyEnabled = getStrategy().getFixed().isEnabled() - || getStrategy().getContent().isEnabled(); - return (strategyEnabled ? Boolean.TRUE : this.enabled); + return getEnabled(getStrategy().getFixed().isEnabled(), + getStrategy().getContent().isEnabled(), this.enabled); } public void setEnabled(boolean enabled) { @@ -223,6 +222,11 @@ public class ResourceProperties implements ResourceLoaderAware { this.gzipped = gzipped; } + static Boolean getEnabled(boolean fixedEnabled, boolean contentEnabled, + Boolean chainEnabled) { + return (fixedEnabled || contentEnabled ? Boolean.TRUE : chainEnabled); + } + } /** From ca435512c0493a8c811c30d41890ba033c6c3558 Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Fri, 20 Jan 2017 14:02:51 -0800 Subject: [PATCH 09/14] Introduce spring-boot-autoconfigure-processor Add an annotation processor that generates properties files for certain auto-configuration class annotations. Currently attribute values from @AutoConfigureOrder, @AutoConfigureBefore, @AutoConfigureAfter and @ConditionalOnClass annotations are stored. The properties file will allow optimizations to be added in the `spring-boot-autoconfigure` project. Primarily by removing the need to ASM parse as many `.class` files. See gh-7573 --- eclipse/spring-boot-project.setup | 2 +- spring-boot-actuator/pom.xml | 5 + spring-boot-autoconfigure/pom.xml | 5 + spring-boot-dependencies/pom.xml | 5 + spring-boot-devtools/pom.xml | 5 + .../boot/junit/compiler}/TestCompiler.java | 11 +- .../boot/junit/compiler/package-info.java | 20 ++ spring-boot-tools/pom.xml | 1 + .../pom.xml | 40 ++++ .../AutoConfigureAnnotationProcessor.java | 214 ++++++++++++++++++ .../javax.annotation.processing.Processor | 1 + ...AutoConfigureAnnotationProcessorTests.java | 117 ++++++++++ .../TestAutoConfigureAfter.java | 38 ++++ .../TestAutoConfigureBefore.java | 38 ++++ .../TestAutoConfigureOrder.java | 36 +++ .../TestClassConfiguration.java | 35 +++ ...stConditionMetdataAnnotationProcessor.java | 76 +++++++ .../TestConditionalOnClass.java | 39 ++++ .../TestConfiguration.java | 38 ++++ .../TestMethodConfiguration.java | 33 +++ .../TestOrderedClassConfiguration.java | 32 +++ .../pom.xml | 4 + ...ationMetadataAnnotationProcessorTests.java | 3 +- .../configurationprocessor/TestProject.java | 12 +- .../AbstractFieldValuesProcessorTests.java | 4 +- 25 files changed, 799 insertions(+), 15 deletions(-) rename {spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor => spring-boot-test-support/src/main/java/org/springframework/boot/junit/compiler}/TestCompiler.java (93%) create mode 100644 spring-boot-test-support/src/main/java/org/springframework/boot/junit/compiler/package-info.java create mode 100644 spring-boot-tools/spring-boot-autoconfigure-processor/pom.xml create mode 100644 spring-boot-tools/spring-boot-autoconfigure-processor/src/main/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessor.java create mode 100644 spring-boot-tools/spring-boot-autoconfigure-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor create mode 100644 spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessorTests.java create mode 100644 spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestAutoConfigureAfter.java create mode 100644 spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestAutoConfigureBefore.java create mode 100644 spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestAutoConfigureOrder.java create mode 100644 spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestClassConfiguration.java create mode 100644 spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestConditionMetdataAnnotationProcessor.java create mode 100644 spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestConditionalOnClass.java create mode 100644 spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestConfiguration.java create mode 100644 spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestMethodConfiguration.java create mode 100644 spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestOrderedClassConfiguration.java diff --git a/eclipse/spring-boot-project.setup b/eclipse/spring-boot-project.setup index 9f83d7a96b8..acd7baeb571 100644 --- a/eclipse/spring-boot-project.setup +++ b/eclipse/spring-boot-project.setup @@ -143,7 +143,7 @@ name="spring-boot-tools"> + pattern="spring-boot-(tools|antlib|configuration-.*|loader|.*-tools|.*-plugin|autoconfigure-processor)"/> diff --git a/spring-boot-actuator/pom.xml b/spring-boot-actuator/pom.xml index 3204b8fc08b..9832d01777d 100644 --- a/spring-boot-actuator/pom.xml +++ b/spring-boot-actuator/pom.xml @@ -274,6 +274,11 @@ true + + org.springframework.boot + spring-boot-autoconfigure-processor + true + org.springframework.boot spring-boot-configuration-processor diff --git a/spring-boot-autoconfigure/pom.xml b/spring-boot-autoconfigure/pom.xml index e55696c6c46..877d6a1775e 100755 --- a/spring-boot-autoconfigure/pom.xml +++ b/spring-boot-autoconfigure/pom.xml @@ -608,6 +608,11 @@ true + + org.springframework.boot + spring-boot-autoconfigure-processor + true + org.springframework.boot spring-boot-configuration-processor diff --git a/spring-boot-dependencies/pom.xml b/spring-boot-dependencies/pom.xml index bbffcec697c..de02d5ca4b4 100644 --- a/spring-boot-dependencies/pom.xml +++ b/spring-boot-dependencies/pom.xml @@ -271,6 +271,11 @@ spring-boot-autoconfigure 1.5.0.BUILD-SNAPSHOT + + org.springframework.boot + spring-boot-autoconfigure-processor + 1.5.0.BUILD-SNAPSHOT + org.springframework.boot spring-boot-configuration-metadata diff --git a/spring-boot-devtools/pom.xml b/spring-boot-devtools/pom.xml index 9928841f277..a54da7d8e72 100644 --- a/spring-boot-devtools/pom.xml +++ b/spring-boot-devtools/pom.xml @@ -80,6 +80,11 @@ true + + org.springframework.boot + spring-boot-autoconfigure-processor + true + org.springframework.boot spring-boot-configuration-processor diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/TestCompiler.java b/spring-boot-test-support/src/main/java/org/springframework/boot/junit/compiler/TestCompiler.java similarity index 93% rename from spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/TestCompiler.java rename to spring-boot-test-support/src/main/java/org/springframework/boot/junit/compiler/TestCompiler.java index 37143a6f453..53328c7a965 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/TestCompiler.java +++ b/spring-boot-test-support/src/main/java/org/springframework/boot/junit/compiler/TestCompiler.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2017 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.configurationprocessor; +package org.springframework.boot.junit.compiler; import java.io.File; import java.io.IOException; @@ -40,7 +40,10 @@ import org.junit.rules.TemporaryFolder; */ public class TestCompiler { - public static final File ORIGINAL_SOURCE_FOLDER = new File("src/test/java"); + /** + * The default source folder. + */ + public static final File SOURCE_FOLDER = new File("src/test/java"); private final JavaCompiler compiler; @@ -100,7 +103,7 @@ public class TestCompiler { } protected File getSourceFolder() { - return ORIGINAL_SOURCE_FOLDER; + return SOURCE_FOLDER; } /** diff --git a/spring-boot-test-support/src/main/java/org/springframework/boot/junit/compiler/package-info.java b/spring-boot-test-support/src/main/java/org/springframework/boot/junit/compiler/package-info.java new file mode 100644 index 00000000000..e76ad73ef96 --- /dev/null +++ b/spring-boot-test-support/src/main/java/org/springframework/boot/junit/compiler/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Utilities to work with the Java compiler at test time. + */ +package org.springframework.boot.junit.compiler; diff --git a/spring-boot-tools/pom.xml b/spring-boot-tools/pom.xml index cbf35f78954..bfdd833c91c 100644 --- a/spring-boot-tools/pom.xml +++ b/spring-boot-tools/pom.xml @@ -20,6 +20,7 @@ ${basedir}/.. + spring-boot-autoconfigure-processor spring-boot-configuration-metadata spring-boot-configuration-processor spring-boot-loader diff --git a/spring-boot-tools/spring-boot-autoconfigure-processor/pom.xml b/spring-boot-tools/spring-boot-autoconfigure-processor/pom.xml new file mode 100644 index 00000000000..2695eafa86a --- /dev/null +++ b/spring-boot-tools/spring-boot-autoconfigure-processor/pom.xml @@ -0,0 +1,40 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-tools + 1.5.0.BUILD-SNAPSHOT + + spring-boot-autoconfigure-processor + Spring Boot Auto-Configure Annotation Processor + Spring Auto-Configure Annotation Processor + http://projects.spring.io/spring-boot/ + + Pivotal Software, Inc. + http://www.spring.io + + + ${basedir}/../.. + + + + org.springframework.boot + spring-boot-test-support + test + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + none + + + + + diff --git a/spring-boot-tools/spring-boot-autoconfigure-processor/src/main/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessor.java b/spring-boot-tools/spring-boot-autoconfigure-processor/src/main/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessor.java new file mode 100644 index 00000000000..fe09512e664 --- /dev/null +++ b/spring-boot-tools/spring-boot-autoconfigure-processor/src/main/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessor.java @@ -0,0 +1,214 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigureprocessor; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.AnnotationValue; +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.TypeElement; +import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.TypeMirror; +import javax.tools.FileObject; +import javax.tools.StandardLocation; + +/** + * Annotation processor to store certain annotations from auto-configuration classes in a + * property file. + * + * @author Madhura Bhave + * @author Phillip Webb + */ +@SupportedAnnotationTypes({ "org.springframework.context.annotation.Configuration", + "org.springframework.boot.autoconfigure.condition.ConditionalOnClass", + "org.springframework.boot.autoconfigure.AutoConfigureBefore", + "org.springframework.boot.autoconfigure.AutoConfigureAfter", + "org.springframework.boot.autoconfigure.AutoConfigureOrder" }) +public class AutoConfigureAnnotationProcessor extends AbstractProcessor { + + protected static final String PROPERTIES_PATH = "META-INF/" + + "spring-autoconfigure-metadata.properties"; + + private Map annotations; + + private final Properties properties = new Properties(); + + public AutoConfigureAnnotationProcessor() { + Map annotations = new LinkedHashMap(); + addAnnotations(annotations); + this.annotations = Collections.unmodifiableMap(annotations); + } + + protected void addAnnotations(Map annotations) { + annotations.put("Configuration", + "org.springframework.context.annotation.Configuration"); + annotations.put("ConditionalOnClass", + "org.springframework.boot.autoconfigure.condition.ConditionalOnClass"); + annotations.put("AutoConfigureBefore", + "org.springframework.boot.autoconfigure.AutoConfigureBefore"); + annotations.put("AutoConfigureAfter", + "org.springframework.boot.autoconfigure.AutoConfigureAfter"); + annotations.put("AutoConfigureOrder", + "org.springframework.boot.autoconfigure.AutoConfigureOrder"); + } + + @Override + public boolean process(Set annotations, + RoundEnvironment roundEnv) { + for (Map.Entry entry : this.annotations.entrySet()) { + process(roundEnv, entry.getKey(), entry.getValue()); + } + if (roundEnv.processingOver()) { + try { + writeProperties(); + } + catch (Exception ex) { + throw new IllegalStateException("Failed to write metadata", ex); + } + } + return false; + } + + private void process(RoundEnvironment roundEnv, String propertyKey, + String annotationName) { + TypeElement annotationType = this.processingEnv.getElementUtils() + .getTypeElement(annotationName); + if (annotationType != null) { + for (Element element : roundEnv.getElementsAnnotatedWith(annotationType)) { + Element enclosingElement = element.getEnclosingElement(); + if (enclosingElement != null + && enclosingElement.getKind() == ElementKind.PACKAGE) { + processElement(element, propertyKey, annotationName); + } + } + } + } + + private void processElement(Element element, String propertyKey, + String annotationName) { + try { + String qualifiedName = getQualifiedName(element); + AnnotationMirror annotation = getAnnotation(element, annotationName); + if (qualifiedName != null && annotation != null) { + List values = getValues(annotation); + this.properties.put(qualifiedName + "." + propertyKey, + toCommaDelimitedString(values)); + this.properties.put(qualifiedName, ""); + } + } + catch (Exception ex) { + throw new IllegalStateException( + "Error processing configuration meta-data on " + element, ex); + } + } + + private AnnotationMirror getAnnotation(Element element, String type) { + if (element != null) { + for (AnnotationMirror annotation : element.getAnnotationMirrors()) { + if (type.equals(annotation.getAnnotationType().toString())) { + return annotation; + } + } + } + return null; + } + + private String toCommaDelimitedString(List list) { + StringBuilder result = new StringBuilder(); + for (Object item : list) { + result.append(result.length() != 0 ? "," : ""); + result.append(item); + } + return result.toString(); + } + + @SuppressWarnings("unchecked") + private List getValues(AnnotationMirror annotation) { + List result = new ArrayList(); + for (Map.Entry entry : annotation + .getElementValues().entrySet()) { + String attributeName = entry.getKey().getSimpleName().toString(); + if ("name".equals(attributeName) || "value".equals(attributeName)) { + Object value = entry.getValue().getValue(); + if (value instanceof List) { + for (AnnotationValue annotationValue : (List) value) { + result.add(annotationValue.getValue()); + } + } + else { + result.add(value); + } + } + } + return result; + } + + private String getQualifiedName(Element element) { + if (element != null) { + TypeElement enclosingElement = getEnclosingTypeElement(element.asType()); + if (enclosingElement != null) { + return getQualifiedName(enclosingElement) + "$" + + ((DeclaredType) element.asType()).asElement().getSimpleName() + .toString(); + } + if (element instanceof TypeElement) { + return ((TypeElement) element).getQualifiedName().toString(); + } + } + return null; + } + + private TypeElement getEnclosingTypeElement(TypeMirror type) { + if (type instanceof DeclaredType) { + DeclaredType declaredType = (DeclaredType) type; + Element enclosingElement = declaredType.asElement().getEnclosingElement(); + if (enclosingElement != null && enclosingElement instanceof TypeElement) { + return (TypeElement) enclosingElement; + } + } + return null; + } + + private void writeProperties() throws IOException { + if (!this.properties.isEmpty()) { + FileObject file = this.processingEnv.getFiler() + .createResource(StandardLocation.CLASS_OUTPUT, "", PROPERTIES_PATH); + OutputStream outputStream = file.openOutputStream(); + try { + this.properties.store(outputStream, null); + } + finally { + outputStream.close(); + } + } + } + +} diff --git a/spring-boot-tools/spring-boot-autoconfigure-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/spring-boot-tools/spring-boot-autoconfigure-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor new file mode 100644 index 00000000000..70a37f4e279 --- /dev/null +++ b/spring-boot-tools/spring-boot-autoconfigure-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor @@ -0,0 +1 @@ +org.springframework.boot.autoconfigureprocessor.AutoConfigureAnnotationProcessor diff --git a/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessorTests.java b/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessorTests.java new file mode 100644 index 00000000000..26d4744e934 --- /dev/null +++ b/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessorTests.java @@ -0,0 +1,117 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigureprocessor; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.rules.TemporaryFolder; + +import org.springframework.boot.junit.compiler.TestCompiler; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link AutoConfigureAnnotationProcessor}. + * + * @author Madhura Bhave + */ +public class AutoConfigureAnnotationProcessorTests { + + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + private TestCompiler compiler; + + @Before + public void createCompiler() throws IOException { + this.compiler = new TestCompiler(this.temporaryFolder); + } + + @Test + public void annotatedClass() throws Exception { + Properties properties = compile(TestClassConfiguration.class); + System.out.println(properties); + assertThat(properties).hasSize(3); + assertThat(properties).containsEntry( + "org.springframework.boot.autoconfigureprocessor." + + "TestClassConfiguration.ConditionalOnClass", + "java.io.InputStream,java.io.OutputStream"); + assertThat(properties).containsKey( + "org.springframework.boot.autoconfigureprocessor.TestClassConfiguration"); + assertThat(properties).containsKey( + "org.springframework.boot.autoconfigureprocessor.TestClassConfiguration.Configuration"); + assertThat(properties).doesNotContainKey( + "org.springframework.boot.autoconfigureprocessor.TestClassConfiguration$Nested"); + } + + @Test + public void annotatedMethod() throws Exception { + Properties properties = compile(TestMethodConfiguration.class); + List matching = new ArrayList(); + for (Object key : properties.keySet()) { + if (key.toString().startsWith( + "org.springframework.boot.autoconfigureprocessor.TestMethodConfiguration")) { + matching.add(key.toString()); + } + } + assertThat(matching).hasSize(2) + .contains("org.springframework.boot.autoconfigureprocessor." + + "TestMethodConfiguration") + .contains("org.springframework.boot.autoconfigureprocessor." + + "TestMethodConfiguration.Configuration"); + } + + @Test + public void annotatedClassWithOrder() throws Exception { + Properties properties = compile(TestOrderedClassConfiguration.class); + assertThat(properties).containsEntry( + "org.springframework.boot.autoconfigureprocessor." + + "TestOrderedClassConfiguration.ConditionalOnClass", + "java.io.InputStream,java.io.OutputStream"); + assertThat(properties).containsEntry( + "org.springframework.boot.autoconfigureprocessor." + + "TestOrderedClassConfiguration.AutoConfigureBefore", + "test.before1,test.before2"); + assertThat(properties).containsEntry( + "org.springframework.boot.autoconfigureprocessor." + + "TestOrderedClassConfiguration.AutoConfigureAfter", + "java.io.ObjectInputStream"); + assertThat(properties) + .containsEntry( + "org.springframework.boot.autoconfigureprocessor." + + "TestOrderedClassConfiguration.AutoConfigureOrder", + "123"); + } + + private Properties compile(Class... types) throws IOException { + TestConditionMetdataAnnotationProcessor processor = new TestConditionMetdataAnnotationProcessor( + this.compiler.getOutputLocation()); + this.compiler.getTask(types).call(processor); + return processor.getWrittenProperties(); + } + +} diff --git a/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestAutoConfigureAfter.java b/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestAutoConfigureAfter.java new file mode 100644 index 00000000000..7f9334360aa --- /dev/null +++ b/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestAutoConfigureAfter.java @@ -0,0 +1,38 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigureprocessor; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Alternative to Spring Boot's {@code @AutoConfigureAfter} for testing (removes the need + * for a dependency on the real annotation). + * + * @author Phillip Webb + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.TYPE }) +public @interface TestAutoConfigureAfter { + + Class[] value() default {}; + + String[] name() default {}; + +} diff --git a/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestAutoConfigureBefore.java b/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestAutoConfigureBefore.java new file mode 100644 index 00000000000..53f306d5574 --- /dev/null +++ b/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestAutoConfigureBefore.java @@ -0,0 +1,38 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigureprocessor; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Alternative to Spring Boot's {@code @AutoConfigureBefore} for testing (removes the need + * for a dependency on the real annotation). + * + * @author Phillip Webb + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.TYPE }) +public @interface TestAutoConfigureBefore { + + Class[] value() default {}; + + String[] name() default {}; + +} diff --git a/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestAutoConfigureOrder.java b/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestAutoConfigureOrder.java new file mode 100644 index 00000000000..17caa158db9 --- /dev/null +++ b/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestAutoConfigureOrder.java @@ -0,0 +1,36 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigureprocessor; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Alternative to Spring Boot's {@code @AutoConfigureOrder} for testing (removes the need + * for a dependency on the real annotation). + * + * @author Phillip Webb + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.FIELD }) +public @interface TestAutoConfigureOrder { + + int value() default Integer.MAX_VALUE; + +} diff --git a/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestClassConfiguration.java b/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestClassConfiguration.java new file mode 100644 index 00000000000..7ca07f4323e --- /dev/null +++ b/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestClassConfiguration.java @@ -0,0 +1,35 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigureprocessor; + +import java.io.OutputStream; + +/** + * Test configuration with an annotated class. + * + * @author Madhura Bhave + */ +@TestConfiguration +@TestConditionalOnClass(name = "java.io.InputStream", value = OutputStream.class) +public class TestClassConfiguration { + + @TestAutoConfigureOrder + public static class Nested { + + } + +} diff --git a/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestConditionMetdataAnnotationProcessor.java b/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestConditionMetdataAnnotationProcessor.java new file mode 100644 index 00000000000..08d0c60d15c --- /dev/null +++ b/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestConditionMetdataAnnotationProcessor.java @@ -0,0 +1,76 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigureprocessor; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Map; +import java.util.Properties; + +import javax.annotation.processing.SupportedAnnotationTypes; + +/** + * Version of {@link AutoConfigureAnnotationProcessor} used for testing. + * + * @author Madhura Bhave + */ +@SupportedAnnotationTypes({ + "org.springframework.boot.autoconfigureprocessor.TestConfiguration", + "org.springframework.boot.autoconfigureprocessor.TestConditionalOnClass", + "org.springframework.boot.autoconfigureprocessor.TestAutoConfigureBefore", + "org.springframework.boot.autoconfigureprocessor.TestAutoConfigureAfter", + "org.springframework.boot.autoconfigureprocessor.TestAutoConfigureOrder" }) +public class TestConditionMetdataAnnotationProcessor + extends AutoConfigureAnnotationProcessor { + + private final File outputLocation; + + public TestConditionMetdataAnnotationProcessor(File outputLocation) { + this.outputLocation = outputLocation; + } + + @Override + protected void addAnnotations(Map annotations) { + put(annotations, "Configuration", TestConfiguration.class); + put(annotations, "ConditionalOnClass", TestConditionalOnClass.class); + put(annotations, "AutoConfigureBefore", TestAutoConfigureBefore.class); + put(annotations, "AutoConfigureAfter", TestAutoConfigureAfter.class); + put(annotations, "AutoConfigureOrder", TestAutoConfigureOrder.class); + } + + private void put(Map annotations, String key, Class value) { + annotations.put(key, value.getName()); + } + + public Properties getWrittenProperties() throws IOException { + File file = new File(this.outputLocation, PROPERTIES_PATH); + if (!file.exists()) { + return null; + } + FileInputStream inputStream = new FileInputStream(file); + try { + Properties properties = new Properties(); + properties.load(inputStream); + return properties; + } + finally { + inputStream.close(); + } + } + +} diff --git a/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestConditionalOnClass.java b/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestConditionalOnClass.java new file mode 100644 index 00000000000..b946e2b2bf2 --- /dev/null +++ b/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestConditionalOnClass.java @@ -0,0 +1,39 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigureprocessor; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Fake {@code @ConditionalOnClass} annotation used for testing. + * + * @author Madhura Bhave + */ +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface TestConditionalOnClass { + + Class[] value() default {}; + + String[] name() default {}; + +} diff --git a/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestConfiguration.java b/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestConfiguration.java new file mode 100644 index 00000000000..2015f31f5be --- /dev/null +++ b/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestConfiguration.java @@ -0,0 +1,38 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigureprocessor; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Alternative to Spring's {@code @Configuration} for testing (removes the need for a + * dependency on the real annotation). + * + * @author Phillip Webb + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface TestConfiguration { + + String value() default ""; + +} diff --git a/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestMethodConfiguration.java b/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestMethodConfiguration.java new file mode 100644 index 00000000000..d2fe126d0cb --- /dev/null +++ b/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestMethodConfiguration.java @@ -0,0 +1,33 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigureprocessor; + +import java.io.OutputStream; + +/** + * Test configuration with an annoated method. + * + * @author Madhura Bhave + */ +@TestConfiguration +public class TestMethodConfiguration { + + @TestConditionalOnClass(name = "java.io.InputStream", value = OutputStream.class) + public Object method() { + return null; + } +} diff --git a/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestOrderedClassConfiguration.java b/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestOrderedClassConfiguration.java new file mode 100644 index 00000000000..625fd14ed0c --- /dev/null +++ b/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestOrderedClassConfiguration.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigureprocessor; + +import java.io.ObjectInputStream; +import java.io.OutputStream; + +/** + * Test configuration with an annotated class. + * + * @author Phillip Webb + */ +@TestAutoConfigureBefore(name = { "test.before1", "test.before2" }) +@TestAutoConfigureAfter(ObjectInputStream.class) +@TestConditionalOnClass(name = "java.io.InputStream", value = OutputStream.class) +@TestAutoConfigureOrder(123) +public class TestOrderedClassConfiguration { +} diff --git a/spring-boot-tools/spring-boot-configuration-processor/pom.xml b/spring-boot-tools/spring-boot-configuration-processor/pom.xml index 0db592f9863..78aa0d1ea4d 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/pom.xml +++ b/spring-boot-tools/spring-boot-configuration-processor/pom.xml @@ -24,6 +24,10 @@ com.vaadin.external.google android-json + + org.springframework.boot + spring-boot-test-support + org.projectlombok diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java index aa371a7a20e..a145f0361e7 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -68,6 +68,7 @@ import org.springframework.boot.configurationsample.specific.InnerClassRootConfi import org.springframework.boot.configurationsample.specific.InvalidAccessorProperties; import org.springframework.boot.configurationsample.specific.InvalidDoubleRegistrationProperties; import org.springframework.boot.configurationsample.specific.SimplePojo; +import org.springframework.boot.junit.compiler.TestCompiler; import org.springframework.util.FileCopyUtils; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/TestProject.java b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/TestProject.java index 9225e09b122..ff5ec89fdd5 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/TestProject.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/TestProject.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -33,16 +33,14 @@ import java.util.Set; import org.junit.Assert; import org.junit.rules.TemporaryFolder; -import org.springframework.boot.configurationprocessor.TestCompiler.TestCompilationTask; import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; import org.springframework.boot.configurationsample.ConfigurationProperties; import org.springframework.boot.configurationsample.NestedConfigurationProperty; +import org.springframework.boot.junit.compiler.TestCompiler; +import org.springframework.boot.junit.compiler.TestCompiler.TestCompilationTask; import org.springframework.util.FileCopyUtils; import org.springframework.util.FileSystemUtils; -import static org.springframework.boot.configurationprocessor.TestCompiler.ORIGINAL_SOURCE_FOLDER; -import static org.springframework.boot.configurationprocessor.TestCompiler.sourcePathFor; - /** * A TestProject contains a copy of a subset of test sample code. *

@@ -96,7 +94,7 @@ public class TestProject { } public File getSourceFile(Class type) { - return new File(this.sourceFolder, sourcePathFor(type)); + return new File(this.sourceFolder, TestCompiler.sourcePathFor(type)); } public ConfigurationMetadata fullBuild() { @@ -192,7 +190,7 @@ public class TestProject { * code. */ private File getOriginalSourceFile(Class type) { - return new File(ORIGINAL_SOURCE_FOLDER, sourcePathFor(type)); + return new File(TestCompiler.SOURCE_FOLDER, TestCompiler.sourcePathFor(type)); } private static void putContents(File targetFile, String contents) diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/fieldvalues/AbstractFieldValuesProcessorTests.java b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/fieldvalues/AbstractFieldValuesProcessorTests.java index 54600b119cb..1a6793cdec3 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/fieldvalues/AbstractFieldValuesProcessorTests.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/fieldvalues/AbstractFieldValuesProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -33,8 +33,8 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import org.springframework.boot.configurationprocessor.TestCompiler; import org.springframework.boot.configurationsample.fieldvalues.FieldValues; +import org.springframework.boot.junit.compiler.TestCompiler; import static org.assertj.core.api.Assertions.assertThat; From 1cbda9bd605f04a68eaf730a19a3efc6d4116638 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 23 Jan 2017 14:53:02 -0800 Subject: [PATCH 10/14] Add AutoConfigurationMetadata abstraction Add AutoConfigurationMetadata interface and a an internal loader that allows easy access to data written by `spring-boot-configure-processor`. See gh-7573 --- .../AutoConfigurationMetadata.java | 88 +++++++++++++ .../AutoConfigurationMetadataLoader.java | 121 ++++++++++++++++++ .../AutoConfigurationMetadataLoaderTests.java | 98 ++++++++++++++ ...onfigurationMetadataLoaderTests.properties | 4 + 4 files changed, 311 insertions(+) create mode 100644 spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationMetadata.java create mode 100644 spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationMetadataLoader.java create mode 100644 spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationMetadataLoaderTests.java create mode 100644 spring-boot-autoconfigure/src/test/resources/META-INF/AutoConfigurationMetadataLoaderTests.properties diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationMetadata.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationMetadata.java new file mode 100644 index 00000000000..c38acea7d58 --- /dev/null +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationMetadata.java @@ -0,0 +1,88 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure; + +import java.util.Set; + +/** + * Provides access to meta-data written by the auto-configure annotation processor. + * + * @author Phillip Webb + * @since 1.5.0 + */ +public interface AutoConfigurationMetadata { + + /** + * Return {@code true} if the specified class name was processed by the annotation + * processor. + * @param className the source class + * @return if the class was processed + */ + boolean wasProcessed(String className); + + /** + * Get an {@link Integer} value from the meta-data. + * @param className the source class + * @param key the meta-data key + * @return the meta-data value or {@code null} + */ + Integer getInteger(String className, String key); + + /** + * Get an {@link Integer} value from the meta-data. + * @param className the source class + * @param key the meta-data key + * @param defaultValue the default value + * @return the meta-data value or {@code defaultValue} + */ + Integer getInteger(String className, String key, Integer defaultValue); + + /** + * Get a {@link Set} value from the meta-data. + * @param className the source class + * @param key the meta-data key + * @return the meta-data value or {@code null} + */ + Set getSet(String className, String key); + + /** + * Get a {@link Set} value from the meta-data. + * @param className the source class + * @param key the meta-data key + * @param defaultValue the default value + * @return the meta-data value or {@code defaultValue} + */ + Set getSet(String className, String key, Set defaultValue); + + /** + * Get an {@link String} value from the meta-data. + * @param className the source class + * @param key the meta-data key + * @return the meta-data value or {@code null} + */ + String get(String className, String key); + + /** + * Get an {@link String} value from the meta-data. + * @param className the source class + * @param key the meta-data key + * @param defaultValue the default value + * @return the meta-data value or {@code defaultValue} + */ + String get(String className, String key, String defaultValue); + +} diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationMetadataLoader.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationMetadataLoader.java new file mode 100644 index 00000000000..c99e2172091 --- /dev/null +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationMetadataLoader.java @@ -0,0 +1,121 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure; + +import java.io.IOException; +import java.net.URL; +import java.util.Enumeration; +import java.util.Properties; +import java.util.Set; + +import org.springframework.core.io.UrlResource; +import org.springframework.core.io.support.PropertiesLoaderUtils; +import org.springframework.util.StringUtils; + +/** + * Internal utility used to load {@link AutoConfigurationMetadata}. + * + * @author Phillip Webb + */ +final class AutoConfigurationMetadataLoader { + + protected static final String PATH = "META-INF/" + + "spring-autoconfigure-metadata.properties"; + + private AutoConfigurationMetadataLoader() { + } + + public static AutoConfigurationMetadata loadMetadata(ClassLoader classLoader) { + return loadMetadata(classLoader, PATH); + } + + static AutoConfigurationMetadata loadMetadata(ClassLoader classLoader, String path) { + try { + Enumeration urls = (classLoader != null ? classLoader.getResources(path) + : ClassLoader.getSystemResources(path)); + Properties properties = new Properties(); + while (urls.hasMoreElements()) { + properties.putAll(PropertiesLoaderUtils + .loadProperties(new UrlResource(urls.nextElement()))); + } + return loadMetadata(properties); + } + catch (IOException ex) { + throw new IllegalArgumentException( + "Unable to load @ConditionalOnClass location [" + path + "]", ex); + } + } + + static AutoConfigurationMetadata loadMetadata(Properties properties) { + return new PropertiesAutoConfigurationMetadata(properties); + } + + /** + * {@link AutoConfigurationMetadata} implementation backed by a properties file. + */ + private static class PropertiesAutoConfigurationMetadata + implements AutoConfigurationMetadata { + + private final Properties properties; + + PropertiesAutoConfigurationMetadata(Properties properties) { + this.properties = properties; + } + + @Override + public boolean wasProcessed(String className) { + return this.properties.containsKey(className); + } + + @Override + public Integer getInteger(String className, String key) { + return getInteger(className, key, null); + } + + @Override + public Integer getInteger(String className, String key, Integer defaultValue) { + String value = get(className, key); + return (value != null ? Integer.valueOf(value) : defaultValue); + } + + @Override + public Set getSet(String className, String key) { + return getSet(className, key, null); + } + + @Override + public Set getSet(String className, String key, + Set defaultValue) { + String value = get(className, key); + return (value != null ? StringUtils.commaDelimitedListToSet(value) + : defaultValue); + } + + @Override + public String get(String className, String key) { + return get(className, key, null); + } + + @Override + public String get(String className, String key, String defaultValue) { + String value = this.properties.getProperty(className + "." + key); + return (value != null ? value : defaultValue); + } + + } + +} diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationMetadataLoaderTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationMetadataLoaderTests.java new file mode 100644 index 00000000000..06213654d05 --- /dev/null +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationMetadataLoaderTests.java @@ -0,0 +1,98 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure; + +import java.util.Collections; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test for {@link AutoConfigurationMetadataLoader}. + * + * @author Phillip Webb + */ +public class AutoConfigurationMetadataLoaderTests { + + @Test + public void loadShouldLoadProperties() throws Exception { + assertThat(load()).isNotNull(); + } + + @Test + public void wasProcessedWhenProcessedShouldReturnTrue() throws Exception { + assertThat(load().wasProcessed("test")).isTrue(); + } + + @Test + public void wasProcessedWhenNotProcessedShouldReturnFalse() throws Exception { + assertThat(load().wasProcessed("testx")).isFalse(); + } + + @Test + public void getIntegerShouldReturnValue() throws Exception { + assertThat(load().getInteger("test", "int")).isEqualTo(123); + } + + @Test + public void getIntegerWhenMissingShouldReturnNull() throws Exception { + assertThat(load().getInteger("test", "intx")).isNull(); + } + + @Test + public void getIntegerWithDefaultWhenMissingShouldReturnDefault() throws Exception { + assertThat(load().getInteger("test", "intx", 345)).isEqualTo(345); + } + + @Test + public void getSetShouldReturnValue() throws Exception { + assertThat(load().getSet("test", "set")).containsExactly("a", "b", "c"); + } + + @Test + public void getSetWhenMissingShouldReturnNull() throws Exception { + assertThat(load().getSet("test", "setx")).isNull(); + } + + @Test + public void getSetWithDefaultWhenMissingShouldReturnDefault() throws Exception { + assertThat(load().getSet("test", "setx", Collections.singleton("x"))) + .containsExactly("x"); + } + + @Test + public void getShouldReturnValue() throws Exception { + assertThat(load().get("test", "string")).isEqualTo("abc"); + } + + @Test + public void getWhenMissingShouldReturnNull() throws Exception { + assertThat(load().get("test", "stringx")).isNull(); + } + + @Test + public void getWithDefaultWhenMissingShouldReturnDefault() throws Exception { + assertThat(load().get("test", "stringx", "xyz")).isEqualTo("xyz"); + } + + private AutoConfigurationMetadata load() { + return AutoConfigurationMetadataLoader.loadMetadata(null, + "META-INF/AutoConfigurationMetadataLoaderTests.properties"); + } + +} diff --git a/spring-boot-autoconfigure/src/test/resources/META-INF/AutoConfigurationMetadataLoaderTests.properties b/spring-boot-autoconfigure/src/test/resources/META-INF/AutoConfigurationMetadataLoaderTests.properties new file mode 100644 index 00000000000..2dc12708cec --- /dev/null +++ b/spring-boot-autoconfigure/src/test/resources/META-INF/AutoConfigurationMetadataLoaderTests.properties @@ -0,0 +1,4 @@ +test= +test.string=abc +test.int=123 +test.set=a,b,b,c From 02641a820759f157b24594e3167f23a9f388f79c Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sun, 22 Jan 2017 22:51:15 -0800 Subject: [PATCH 11/14] Optimize AutoConfigurationSorter Optimize `AutoConfigurationSorter` by used properties generated by the annotation processor whenever possible. The removes the need for each candidate class to be ASM parsed just to access the order annotations. See gh-7573 --- .../AutoConfigurationImportSelector.java | 21 ++-- .../AutoConfigurationSorter.java | 100 ++++++++++++++---- .../AutoConfigurationSorterTests.java | 65 +++++++++++- .../TestAutoConfigurationSorter.java | 7 +- 4 files changed, 158 insertions(+), 35 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java index 0df9a1c36d5..034d5bf3b47 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java @@ -76,19 +76,21 @@ public class AutoConfigurationImportSelector private ResourceLoader resourceLoader; @Override - public String[] selectImports(AnnotationMetadata metadata) { - if (!isEnabled(metadata)) { + public String[] selectImports(AnnotationMetadata annotationMetadata) { + if (!isEnabled(annotationMetadata)) { return NO_IMPORTS; } try { - AnnotationAttributes attributes = getAttributes(metadata); - List configurations = getCandidateConfigurations(metadata, + AutoConfigurationMetadata autoConfigurationMetadata = AutoConfigurationMetadataLoader + .loadMetadata(this.beanClassLoader); + AnnotationAttributes attributes = getAttributes(annotationMetadata); + List configurations = getCandidateConfigurations(annotationMetadata, attributes); configurations = removeDuplicates(configurations); - Set exclusions = getExclusions(metadata, attributes); + configurations = sort(configurations, autoConfigurationMetadata); + Set exclusions = getExclusions(annotationMetadata, attributes); checkExcludedClasses(configurations, exclusions); configurations.removeAll(exclusions); - configurations = sort(configurations); fireAutoConfigurationImportListeners(configurations, exclusions); return configurations.toArray(new String[configurations.size()]); } @@ -224,9 +226,10 @@ public class AutoConfigurationImportSelector return (Arrays.asList(exclude == null ? new String[0] : exclude)); } - private List sort(List configurations) throws IOException { - configurations = new AutoConfigurationSorter(getMetadataReaderFactory()) - .getInPriorityOrder(configurations); + private List sort(List configurations, + AutoConfigurationMetadata autoConfigurationMetadata) throws IOException { + configurations = new AutoConfigurationSorter(getMetadataReaderFactory(), + autoConfigurationMetadata).getInPriorityOrder(configurations); return configurations; } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java index 62a307520a7..762f32c1741 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -35,8 +35,8 @@ import org.springframework.util.Assert; /** * Sort {@link EnableAutoConfiguration auto-configuration} classes into priority order by - * reading {@link Ordered}, {@link AutoConfigureBefore} and {@link AutoConfigureAfter} - * annotations (without loading classes). + * reading {@link AutoConfigureOrder}, {@link AutoConfigureBefore} and + * {@link AutoConfigureAfter} annotations (without loading classes). * * @author Phillip Webb */ @@ -44,26 +44,31 @@ class AutoConfigurationSorter { private final MetadataReaderFactory metadataReaderFactory; - AutoConfigurationSorter(MetadataReaderFactory metadataReaderFactory) { + private final AutoConfigurationMetadata autoConfigurationMetadata; + + AutoConfigurationSorter(MetadataReaderFactory metadataReaderFactory, + AutoConfigurationMetadata autoConfigurationMetadata) { Assert.notNull(metadataReaderFactory, "MetadataReaderFactory must not be null"); this.metadataReaderFactory = metadataReaderFactory; + this.autoConfigurationMetadata = autoConfigurationMetadata; } - public List getInPriorityOrder(Collection classNames) - throws IOException { + public List getInPriorityOrder(Collection classNames) { final AutoConfigurationClasses classes = new AutoConfigurationClasses( - this.metadataReaderFactory, classNames); + this.metadataReaderFactory, this.autoConfigurationMetadata, classNames); List orderedClassNames = new ArrayList(classNames); // Initially sort alphabetically Collections.sort(orderedClassNames); // Then sort by order Collections.sort(orderedClassNames, new Comparator() { + @Override public int compare(String o1, String o2) { int i1 = classes.get(o1).getOrder(); int i2 = classes.get(o2).getOrder(); return (i1 < i2) ? -1 : (i1 > i2) ? 1 : 0; } + }); // Then respect @AutoConfigureBefore @AutoConfigureAfter orderedClassNames = sortByAnnotation(classes, orderedClassNames); @@ -104,11 +109,11 @@ class AutoConfigurationSorter { private final Map classes = new HashMap(); AutoConfigurationClasses(MetadataReaderFactory metadataReaderFactory, - Collection classNames) throws IOException { + AutoConfigurationMetadata autoConfigurationMetadata, + Collection classNames) { for (String className : classNames) { - MetadataReader metadataReader = metadataReaderFactory - .getMetadataReader(className); - this.classes.put(className, new AutoConfigurationClass(metadataReader)); + this.classes.put(className, new AutoConfigurationClass(className, + metadataReaderFactory, autoConfigurationMetadata)); } } @@ -132,29 +137,65 @@ class AutoConfigurationSorter { private static class AutoConfigurationClass { - private final AnnotationMetadata metadata; + private final String className; - AutoConfigurationClass(MetadataReader metadataReader) { - this.metadata = metadataReader.getAnnotationMetadata(); - } + private final MetadataReaderFactory metadataReaderFactory; - public int getOrder() { - Map orderedAnnotation = this.metadata - .getAnnotationAttributes(AutoConfigureOrder.class.getName()); - return (orderedAnnotation == null ? Ordered.LOWEST_PRECEDENCE - : (Integer) orderedAnnotation.get("value")); + private final AutoConfigurationMetadata autoConfigurationMetadata; + + private AnnotationMetadata annotationMetadata; + + private final Set before; + + private final Set after; + + AutoConfigurationClass(String className, + MetadataReaderFactory metadataReaderFactory, + AutoConfigurationMetadata autoConfigurationMetadata) { + this.className = className; + this.metadataReaderFactory = metadataReaderFactory; + this.autoConfigurationMetadata = autoConfigurationMetadata; + this.before = readBefore(); + this.after = readAfter(); } public Set getBefore() { - return getAnnotationValue(AutoConfigureBefore.class); + return this.before; } public Set getAfter() { + return this.after; + } + + private int getOrder() { + if (this.autoConfigurationMetadata.wasProcessed(this.className)) { + return this.autoConfigurationMetadata.getInteger(this.className, + "AutoConfigureOrder", Ordered.LOWEST_PRECEDENCE); + } + Map attributes = getAnnotationMetadata() + .getAnnotationAttributes(AutoConfigureOrder.class.getName()); + return (attributes == null ? Ordered.LOWEST_PRECEDENCE + : (Integer) attributes.get("value")); + } + + private Set readBefore() { + if (this.autoConfigurationMetadata.wasProcessed(this.className)) { + return this.autoConfigurationMetadata.getSet(this.className, + "AutoConfigureBefore", Collections.emptySet()); + } + return getAnnotationValue(AutoConfigureBefore.class); + } + + private Set readAfter() { + if (this.autoConfigurationMetadata.wasProcessed(this.className)) { + return this.autoConfigurationMetadata.getSet(this.className, + "AutoConfigureAfter", Collections.emptySet()); + } return getAnnotationValue(AutoConfigureAfter.class); } private Set getAnnotationValue(Class annotation) { - Map attributes = this.metadata + Map attributes = getAnnotationMetadata() .getAnnotationAttributes(annotation.getName(), true); if (attributes == null) { return Collections.emptySet(); @@ -165,6 +206,21 @@ class AutoConfigurationSorter { return value; } + private AnnotationMetadata getAnnotationMetadata() { + if (this.annotationMetadata == null) { + try { + MetadataReader metadataReader = this.metadataReaderFactory + .getMetadataReader(this.className); + this.annotationMetadata = metadataReader.getAnnotationMetadata(); + } + catch (IOException ex) { + throw new IllegalStateException( + "Unable to read meta-data for class " + this.className, ex); + } + } + return this.annotationMetadata; + } + } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationSorterTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationSorterTests.java index 5e76e1ed724..3536492ee35 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationSorterTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationSorterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -17,7 +17,10 @@ package org.springframework.boot.autoconfigure; import java.util.Arrays; +import java.util.LinkedHashSet; import java.util.List; +import java.util.Properties; +import java.util.Set; import org.junit.Before; import org.junit.Rule; @@ -26,8 +29,12 @@ import org.junit.rules.ExpectedException; import org.springframework.core.Ordered; import org.springframework.core.type.classreading.CachingMetadataReaderFactory; +import org.springframework.core.type.classreading.MetadataReaderFactory; +import org.springframework.util.ClassUtils; +import org.springframework.util.StringUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; /** * Tests for {@link AutoConfigurationSorter}. @@ -67,9 +74,13 @@ public class AutoConfigurationSorterTests { private AutoConfigurationSorter sorter; + private AutoConfigurationMetadata autoConfigurationMetadata = mock( + AutoConfigurationMetadata.class); + @Before public void setup() { - this.sorter = new AutoConfigurationSorter(new CachingMetadataReaderFactory()); + this.sorter = new AutoConfigurationSorter(new CachingMetadataReaderFactory(), + this.autoConfigurationMetadata); } @Test @@ -132,6 +143,56 @@ public class AutoConfigurationSorterTests { this.sorter.getInPriorityOrder(Arrays.asList(A, B, C, D)); } + @Test + public void usesAnnotationPropertiesWhenPossible() throws Exception { + MetadataReaderFactory readerFactory = mock(MetadataReaderFactory.class); + this.autoConfigurationMetadata = getAutoConfigurationMetadata(A2, B, C, W2, X); + this.sorter = new AutoConfigurationSorter(readerFactory, + this.autoConfigurationMetadata); + List actual = this.sorter + .getInPriorityOrder(Arrays.asList(A2, B, C, W2, X)); + assertThat(actual).containsExactly(C, W2, B, A2, X); + } + + private AutoConfigurationMetadata getAutoConfigurationMetadata(String... classNames) + throws Exception { + Properties properties = new Properties(); + for (String className : classNames) { + Class type = ClassUtils.forName(className, null); + properties.put(type.getName(), ""); + AutoConfigureOrder order = type + .getDeclaredAnnotation(AutoConfigureOrder.class); + if (order != null) { + properties.put(className + ".AutoConfigureOrder", + String.valueOf(order.value())); + } + AutoConfigureBefore autoConfigureBefore = type + .getDeclaredAnnotation(AutoConfigureBefore.class); + if (autoConfigureBefore != null) { + properties.put(className + ".AutoConfigureBefore", + merge(autoConfigureBefore.value(), autoConfigureBefore.name())); + } + AutoConfigureAfter autoConfigureAfter = type + .getDeclaredAnnotation(AutoConfigureAfter.class); + if (autoConfigureAfter != null) { + properties.put(className + ".AutoConfigureAfter", + merge(autoConfigureAfter.value(), autoConfigureAfter.name())); + } + } + return AutoConfigurationMetadataLoader.loadMetadata(properties); + } + + private String merge(Class[] value, String[] name) { + Set items = new LinkedHashSet(); + for (Class type : value) { + items.add(type.getName()); + } + for (String type : name) { + items.add(type); + } + return StringUtils.collectionToCommaDelimitedString(items); + } + @AutoConfigureOrder(Ordered.LOWEST_PRECEDENCE) public static class OrderLowest { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/TestAutoConfigurationSorter.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/TestAutoConfigurationSorter.java index 12a07d37687..aa99f7cf1d5 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/TestAutoConfigurationSorter.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/TestAutoConfigurationSorter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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,6 +16,8 @@ package org.springframework.boot.autoconfigure; +import java.util.Properties; + import org.springframework.core.type.classreading.MetadataReaderFactory; /** @@ -26,7 +28,8 @@ import org.springframework.core.type.classreading.MetadataReaderFactory; public class TestAutoConfigurationSorter extends AutoConfigurationSorter { public TestAutoConfigurationSorter(MetadataReaderFactory metadataReaderFactory) { - super(metadataReaderFactory); + super(metadataReaderFactory, + AutoConfigurationMetadataLoader.loadMetadata(new Properties())); } } From 20a20b77116bbb65ac1708210e7ac7d653fc390b Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sun, 22 Jan 2017 23:14:17 -0800 Subject: [PATCH 12/14] Add AutoConfigurationImportFilter support Add `AutoConfigurationImportFilter` strategy interface which can be used to filter auto-configuration candidates before they are loaded. See gh-7573 --- .../AutoConfigurationImportFilter.java | 58 ++++++++++++++++ .../AutoConfigurationImportSelector.java | 67 +++++++++++++++--- .../AutoConfigurationImportSelectorTests.java | 69 ++++++++++++++++++- 3 files changed, 183 insertions(+), 11 deletions(-) create mode 100644 spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportFilter.java diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportFilter.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportFilter.java new file mode 100644 index 00000000000..38f102038da --- /dev/null +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportFilter.java @@ -0,0 +1,58 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure; + +import org.springframework.beans.factory.BeanClassLoaderAware; +import org.springframework.beans.factory.BeanFactoryAware; +import org.springframework.context.EnvironmentAware; +import org.springframework.context.ResourceLoaderAware; + +/** + * Filter that can be registered in {@code spring.factories} to limit the + * auto-configuration classes considered. This interface is designed to allow fast removal + * of auto-configuration classes before their bytecode is even read. + *

+ * An {@link AutoConfigurationImportFilter} may implement any of the following + * {@link org.springframework.beans.factory.Aware Aware} interfaces, and their respective + * methods will be called prior to {@link #match}: + *

    + *
  • {@link EnvironmentAware}
  • + *
  • {@link BeanFactoryAware }
  • + *
  • {@link BeanClassLoaderAware }
  • + *
  • {@link ResourceLoaderAware}
  • + *
+ * + * @author Phillip Webb + * @since 1.5.0 + */ +public interface AutoConfigurationImportFilter { + + /** + * Apply the filter to the given auto-configuration class candidates. + * @param autoConfigurationClasses the auto-configuration classes being considered. + * Implementations should not change the values in this array. + * @param autoConfigurationMetadata access to the meta-data generated by the + * auto-configure annotation processor + * @return a boolean array indicating which of the auto-configuration classes should + * be imported. The returned array must be the same size as the incoming + * {@code autoConfigurationClasses} parameter. Entries containing {@code false} will + * not be imported. + */ + boolean[] match(String[] autoConfigurationClasses, + AutoConfigurationMetadata autoConfigurationMetadata); + +} diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java index 034d5bf3b47..8d51e1111d4 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java @@ -24,6 +24,10 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.beans.BeansException; import org.springframework.beans.factory.Aware; @@ -67,6 +71,9 @@ public class AutoConfigurationImportSelector private static final String[] NO_IMPORTS = {}; + private static final Log logger = LogFactory + .getLog(AutoConfigurationImportSelector.class); + private ConfigurableListableBeanFactory beanFactory; private Environment environment; @@ -91,6 +98,7 @@ public class AutoConfigurationImportSelector Set exclusions = getExclusions(annotationMetadata, attributes); checkExcludedClasses(configurations, exclusions); configurations.removeAll(exclusions); + configurations = filter(configurations, autoConfigurationMetadata); fireAutoConfigurationImportListeners(configurations, exclusions); return configurations.toArray(new String[configurations.size()]); } @@ -233,6 +241,45 @@ public class AutoConfigurationImportSelector return configurations; } + private List filter(List configurations, + AutoConfigurationMetadata autoConfigurationMetadata) { + long startTime = System.nanoTime(); + String[] candidates = configurations.toArray(new String[configurations.size()]); + boolean[] skip = new boolean[candidates.length]; + boolean skipped = false; + for (AutoConfigurationImportFilter filter : getAutoConfigurationImportFilters()) { + invokeAwareMethods(filter); + boolean[] match = filter.match(candidates, autoConfigurationMetadata); + for (int i = 0; i < match.length; i++) { + if (!match[i]) { + skip[i] = true; + skipped = true; + } + } + } + if (!skipped) { + return configurations; + } + List result = new ArrayList(candidates.length); + for (int i = 0; i < candidates.length; i++) { + if (!skip[i]) { + result.add(candidates[i]); + } + } + if (logger.isTraceEnabled()) { + int numberFiltered = configurations.size() - result.size(); + logger.trace("Filtered " + numberFiltered + " auto configuration class in " + + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime) + + " ms"); + } + return new ArrayList(result); + } + + protected List getAutoConfigurationImportFilters() { + return SpringFactoriesLoader.loadFactories(AutoConfigurationImportFilter.class, + this.beanClassLoader); + } + private MetadataReaderFactory getMetadataReaderFactory() { try { return getBeanFactory().getBean( @@ -271,20 +318,20 @@ public class AutoConfigurationImportSelector this.beanClassLoader); } - private void invokeAwareMethods(AutoConfigurationImportListener listener) { - if (listener instanceof Aware) { - if (listener instanceof BeanClassLoaderAware) { - ((BeanClassLoaderAware) listener) + private void invokeAwareMethods(Object instance) { + if (instance instanceof Aware) { + if (instance instanceof BeanClassLoaderAware) { + ((BeanClassLoaderAware) instance) .setBeanClassLoader(this.beanClassLoader); } - if (listener instanceof BeanFactoryAware) { - ((BeanFactoryAware) listener).setBeanFactory(this.beanFactory); + if (instance instanceof BeanFactoryAware) { + ((BeanFactoryAware) instance).setBeanFactory(this.beanFactory); } - if (listener instanceof EnvironmentAware) { - ((EnvironmentAware) listener).setEnvironment(this.environment); + if (instance instanceof EnvironmentAware) { + ((EnvironmentAware) instance).setEnvironment(this.environment); } - if (listener instanceof ResourceLoaderAware) { - ((ResourceLoaderAware) listener).setResourceLoader(this.resourceLoader); + if (instance instanceof ResourceLoaderAware) { + ((ResourceLoaderAware) instance).setResourceLoader(this.resourceLoader); } } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelectorTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelectorTests.java index cd703994748..9be2c9ad08f 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelectorTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelectorTests.java @@ -16,8 +16,11 @@ package org.springframework.boot.autoconfigure; +import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.junit.Before; import org.junit.Rule; @@ -25,6 +28,9 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.mockito.MockitoAnnotations; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration; @@ -53,6 +59,8 @@ public class AutoConfigurationImportSelectorTests { private final MockEnvironment environment = new MockEnvironment(); + private List filters = new ArrayList(); + @Rule public ExpectedException expected = ExpectedException.none(); @@ -191,6 +199,26 @@ public class AutoConfigurationImportSelectorTests { "org.springframework.boot.autoconfigure.DoesNotExist2"); } + @Test + public void filterShouldFilterImports() throws Exception { + String[] defaultImports = selectImports(BasicEnableAutoConfiguration.class); + this.filters.add(new TestAutoConfigurationImportFilter(defaultImports, 1)); + this.filters.add(new TestAutoConfigurationImportFilter(defaultImports, 3, 4)); + String[] filtered = selectImports(BasicEnableAutoConfiguration.class); + assertThat(filtered).hasSize(defaultImports.length - 3); + assertThat(filtered).doesNotContain(defaultImports[1], defaultImports[3], + defaultImports[4]); + } + + @Test + public void filterShouldSupportAware() throws Exception { + TestAutoConfigurationImportFilter filter = new TestAutoConfigurationImportFilter( + new String[] {}); + this.filters.add(filter); + selectImports(BasicEnableAutoConfiguration.class); + assertThat(filter.getBeanFactory()).isEqualTo(this.beanFactory); + } + private String[] selectImports(Class source) { return this.importSelector.selectImports(new StandardAnnotationMetadata(source)); } @@ -200,11 +228,16 @@ public class AutoConfigurationImportSelectorTests { getClass().getClassLoader()); } - private static class TestAutoConfigurationImportSelector + private class TestAutoConfigurationImportSelector extends AutoConfigurationImportSelector { private AutoConfigurationImportEvent lastEvent; + @Override + protected List getAutoConfigurationImportFilters() { + return AutoConfigurationImportSelectorTests.this.filters; + } + @Override protected List getAutoConfigurationImportListeners() { return Collections.singletonList( @@ -225,6 +258,40 @@ public class AutoConfigurationImportSelectorTests { } + private static class TestAutoConfigurationImportFilter + implements AutoConfigurationImportFilter, BeanFactoryAware { + + private final Set nonMatching = new HashSet(); + + private BeanFactory beanFactory; + + TestAutoConfigurationImportFilter(String[] configurations, int... nonMatching) { + for (int i : nonMatching) { + this.nonMatching.add(configurations[i]); + } + } + + @Override + public boolean[] match(String[] autoConfigurationClasses, + AutoConfigurationMetadata autoConfigurationMetadata) { + boolean[] result = new boolean[autoConfigurationClasses.length]; + for (int i = 0; i < result.length; i++) { + result[i] = !this.nonMatching.contains(autoConfigurationClasses[i]); + } + return result; + } + + @Override + public void setBeanFactory(BeanFactory beanFactory) throws BeansException { + this.beanFactory = beanFactory; + } + + public BeanFactory getBeanFactory() { + return this.beanFactory; + } + + } + @Configuration private class TestConfiguration { From de50cfa21e5f140a8558a5bc78d133a1b563d040 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sun, 22 Jan 2017 23:14:23 -0800 Subject: [PATCH 13/14] Make OnClassCondition an AutoConfigurationImportFilter Update OnClassCondition to implement AutoConfigurationImportFilter so that auto-configuration candidates can be filtered early. The optimization helps to improve application startup time by reducing the number of classes that are loaded. See gh-7573 --- .../condition/OnClassCondition.java | 213 +++++++++++++++--- .../condition/SpringBootCondition.java | 4 +- .../main/resources/META-INF/spring.factories | 4 + ...ionAutoConfigurationImportFilterTests.java | 86 +++++++ 4 files changed, 270 insertions(+), 37 deletions(-) create mode 100644 spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/OnClassConditionAutoConfigurationImportFilterTests.java diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnClassCondition.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnClassCondition.java index 62200e4007e..e838c95adf5 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnClassCondition.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnClassCondition.java @@ -16,11 +16,20 @@ package org.springframework.boot.autoconfigure.condition; +import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedList; import java.util.List; +import java.util.Set; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanClassLoaderAware; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.BeanFactoryAware; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.boot.autoconfigure.AutoConfigurationImportFilter; +import org.springframework.boot.autoconfigure.AutoConfigurationMetadata; import org.springframework.boot.autoconfigure.condition.ConditionMessage.Style; import org.springframework.context.annotation.Condition; import org.springframework.context.annotation.ConditionContext; @@ -31,24 +40,113 @@ import org.springframework.util.ClassUtils; import org.springframework.util.MultiValueMap; /** - * {@link Condition} that checks for the presence or absence of specific classes. + * {@link Condition} and {@link AutoConfigurationImportFilter} that checks for the + * presence or absence of specific classes. * * @author Phillip Webb * @see ConditionalOnClass * @see ConditionalOnMissingClass */ @Order(Ordered.HIGHEST_PRECEDENCE) -class OnClassCondition extends SpringBootCondition { +class OnClassCondition extends SpringBootCondition + implements AutoConfigurationImportFilter, BeanFactoryAware, BeanClassLoaderAware { + + private BeanFactory beanFactory; + + private ClassLoader beanClassLoader; + + @Override + public boolean[] match(String[] autoConfigurationClasses, + AutoConfigurationMetadata autoConfigurationMetadata) { + ConditionEvaluationReport report = getConditionEvaluationReport(); + ConditionOutcome[] outcomes = getOutcomes(autoConfigurationClasses, + autoConfigurationMetadata); + boolean[] match = new boolean[outcomes.length]; + for (int i = 0; i < outcomes.length; i++) { + match[i] = (outcomes[i] == null || outcomes[i].isMatch()); + if (!match[i] && outcomes[i] != null) { + logOutcome(autoConfigurationClasses[i], outcomes[i]); + if (report != null) { + report.recordConditionEvaluation(autoConfigurationClasses[i], this, + outcomes[i]); + } + } + } + return match; + } + + private ConditionEvaluationReport getConditionEvaluationReport() { + if (this.beanFactory != null + && this.beanFactory instanceof ConfigurableBeanFactory) { + return ConditionEvaluationReport + .get((ConfigurableListableBeanFactory) this.beanFactory); + } + return null; + } + + private ConditionOutcome[] getOutcomes(String[] autoConfigurationClasses, + AutoConfigurationMetadata autoConfigurationMetadata) { + // Split the work and perform half in a background thread. Using a single + // additional thread seems to offer the best performance. More threads make + // things worse + int split = autoConfigurationClasses.length / 2; + GetOutcomesThread thread = new GetOutcomesThread(autoConfigurationClasses, 0, + split, autoConfigurationMetadata); + thread.start(); + ConditionOutcome[] secondHalf = getOutcomes(autoConfigurationClasses, split, + autoConfigurationClasses.length, autoConfigurationMetadata); + try { + thread.join(); + } + catch (InterruptedException ex) { + Thread.currentThread().interrupt(); + } + ConditionOutcome[] firstHalf = thread.getResult(); + ConditionOutcome[] outcomes = new ConditionOutcome[autoConfigurationClasses.length]; + System.arraycopy(firstHalf, 0, outcomes, 0, firstHalf.length); + System.arraycopy(secondHalf, 0, outcomes, split, secondHalf.length); + return outcomes; + } + + private ConditionOutcome[] getOutcomes(final String[] autoConfigurationClasses, + int start, int end, AutoConfigurationMetadata autoConfigurationMetadata) { + ConditionOutcome[] outcomes = new ConditionOutcome[end - start]; + for (int i = start; i < end; i++) { + String autoConfigurationClass = autoConfigurationClasses[i]; + Set candidates = autoConfigurationMetadata + .getSet(autoConfigurationClass, "ConditionalOnClass"); + if (candidates != null) { + outcomes[i - start] = getOutcome(candidates); + } + } + return outcomes; + } + + private ConditionOutcome getOutcome(Set candidates) { + try { + List missing = getMatches(candidates, MatchType.MISSING, + this.beanClassLoader); + if (!missing.isEmpty()) { + return ConditionOutcome + .noMatch(ConditionMessage.forCondition(ConditionalOnClass.class) + .didNotFind("required class", "required classes") + .items(Style.QUOTE, missing)); + } + } + catch (Exception ex) { + // We'll get another chance later + } + return null; + } @Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { + ClassLoader classLoader = context.getClassLoader(); ConditionMessage matchMessage = ConditionMessage.empty(); - MultiValueMap onClasses = getAttributes(metadata, - ConditionalOnClass.class); + List onClasses = getCandidates(metadata, ConditionalOnClass.class); if (onClasses != null) { - List missing = getMatchingClasses(onClasses, MatchType.MISSING, - context); + List missing = getMatches(onClasses, MatchType.MISSING, classLoader); if (!missing.isEmpty()) { return ConditionOutcome .noMatch(ConditionMessage.forCondition(ConditionalOnClass.class) @@ -57,13 +155,13 @@ class OnClassCondition extends SpringBootCondition { } matchMessage = matchMessage.andCondition(ConditionalOnClass.class) .found("required class", "required classes").items(Style.QUOTE, - getMatchingClasses(onClasses, MatchType.PRESENT, context)); + getMatches(onClasses, MatchType.PRESENT, classLoader)); } - MultiValueMap onMissingClasses = getAttributes(metadata, + List onMissingClasses = getCandidates(metadata, ConditionalOnMissingClass.class); if (onMissingClasses != null) { - List present = getMatchingClasses(onMissingClasses, MatchType.PRESENT, - context); + List present = getMatches(onMissingClasses, MatchType.PRESENT, + classLoader); if (!present.isEmpty()) { return ConditionOutcome.noMatch( ConditionMessage.forCondition(ConditionalOnMissingClass.class) @@ -71,30 +169,23 @@ class OnClassCondition extends SpringBootCondition { .items(Style.QUOTE, present)); } matchMessage = matchMessage.andCondition(ConditionalOnMissingClass.class) - .didNotFind("unwanted class", "unwanted classes") - .items(Style.QUOTE, getMatchingClasses(onMissingClasses, - MatchType.MISSING, context)); + .didNotFind("unwanted class", "unwanted classes").items(Style.QUOTE, + getMatches(onMissingClasses, MatchType.MISSING, classLoader)); } return ConditionOutcome.match(matchMessage); } - private MultiValueMap getAttributes(AnnotatedTypeMetadata metadata, + private List getCandidates(AnnotatedTypeMetadata metadata, Class annotationType) { - return metadata.getAllAnnotationAttributes(annotationType.getName(), true); - } - - private List getMatchingClasses(MultiValueMap attributes, - MatchType matchType, ConditionContext context) { - List matches = new LinkedList(); - addAll(matches, attributes.get("value")); - addAll(matches, attributes.get("name")); - Iterator iterator = matches.iterator(); - while (iterator.hasNext()) { - if (!matchType.matches(iterator.next(), context)) { - iterator.remove(); - } + MultiValueMap attributes = metadata + .getAllAnnotationAttributes(annotationType.getName(), true); + List candidates = new ArrayList(); + if (attributes == null) { + return Collections.emptyList(); } - return matches; + addAll(candidates, attributes.get("value")); + addAll(candidates, attributes.get("name")); + return candidates; } private void addAll(List list, List itemsToAdd) { @@ -105,13 +196,34 @@ class OnClassCondition extends SpringBootCondition { } } + private List getMatches(Collection candiates, MatchType matchType, + ClassLoader classLoader) { + List matches = new ArrayList(candiates.size()); + for (String candidate : candiates) { + if (matchType.matches(candidate, classLoader)) { + matches.add(candidate); + } + } + return matches; + } + + @Override + public void setBeanFactory(BeanFactory beanFactory) throws BeansException { + this.beanFactory = beanFactory; + } + + @Override + public void setBeanClassLoader(ClassLoader classLoader) { + this.beanClassLoader = classLoader; + } + private enum MatchType { PRESENT { @Override - public boolean matches(String className, ConditionContext context) { - return isPresent(className, context.getClassLoader()); + public boolean matches(String className, ClassLoader classLoader) { + return isPresent(className, classLoader); } }, @@ -119,8 +231,8 @@ class OnClassCondition extends SpringBootCondition { MISSING { @Override - public boolean matches(String className, ConditionContext context) { - return !isPresent(className, context.getClassLoader()); + public boolean matches(String className, ClassLoader classLoader) { + return !isPresent(className, classLoader); } }; @@ -146,8 +258,39 @@ class OnClassCondition extends SpringBootCondition { return Class.forName(className); } - public abstract boolean matches(String className, ConditionContext context); + public abstract boolean matches(String className, ClassLoader classLoader); } + private class GetOutcomesThread extends Thread { + + private final String[] autoConfigurationClasses; + + private final int start; + + private final int end; + + private final AutoConfigurationMetadata autoConfigurationMetadata; + + private ConditionOutcome[] outcomes; + + GetOutcomesThread(String[] autoConfigurationClasses, int start, int end, + AutoConfigurationMetadata autoConfigurationMetadata) { + this.autoConfigurationClasses = autoConfigurationClasses; + this.start = start; + this.end = end; + this.autoConfigurationMetadata = autoConfigurationMetadata; + } + + @Override + public void run() { + this.outcomes = getOutcomes(this.autoConfigurationClasses, this.start, + this.end, this.autoConfigurationMetadata); + } + + public ConditionOutcome[] getResult() { + return this.outcomes; + } + + } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/SpringBootCondition.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/SpringBootCondition.java index d19a733080d..1345df71737 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/SpringBootCondition.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/SpringBootCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2017 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. @@ -87,7 +87,7 @@ public abstract class SpringBootCondition implements Condition { + methodMetadata.getMethodName(); } - private void logOutcome(String classOrMethodName, ConditionOutcome outcome) { + protected final void logOutcome(String classOrMethodName, ConditionOutcome outcome) { if (this.logger.isTraceEnabled()) { this.logger.trace(getLogMessage(classOrMethodName, outcome)); } diff --git a/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories b/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories index 876a630e29c..9963275324a 100644 --- a/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories +++ b/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories @@ -11,6 +11,10 @@ org.springframework.boot.autoconfigure.BackgroundPreinitializer org.springframework.boot.autoconfigure.AutoConfigurationImportListener=\ org.springframework.boot.autoconfigure.condition.ConditionEvaluationReportAutoConfigurationImportListener +# Auto Configuration Import Filters +org.springframework.boot.autoconfigure.AutoConfigurationImportFilter=\ +org.springframework.boot.autoconfigure.condition.OnClassCondition + # Auto Configure org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration,\ diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/OnClassConditionAutoConfigurationImportFilterTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/OnClassConditionAutoConfigurationImportFilterTests.java new file mode 100644 index 00000000000..a8f34dd52ee --- /dev/null +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/OnClassConditionAutoConfigurationImportFilterTests.java @@ -0,0 +1,86 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.condition; + +import java.util.Collections; + +import org.junit.Before; +import org.junit.Test; + +import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.boot.autoconfigure.AutoConfigurationImportFilter; +import org.springframework.boot.autoconfigure.AutoConfigurationMetadata; +import org.springframework.core.io.support.SpringFactoriesLoader; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; + +/** + * Tests for the {@link AutoConfigurationImportFilter} part of {@link OnClassCondition}. + * + * @author Phillip Webb + */ +public class OnClassConditionAutoConfigurationImportFilterTests { + + private OnClassCondition filter = new OnClassCondition(); + + private DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); + + @Before + public void setup() { + this.filter.setBeanClassLoader(getClass().getClassLoader()); + this.filter.setBeanFactory(this.beanFactory); + } + + @Test + public void shouldBeRegistered() throws Exception { + assertThat(SpringFactoriesLoader + .loadFactories(AutoConfigurationImportFilter.class, null)) + .hasAtLeastOneElementOfType(OnClassCondition.class); + } + + @Test + public void matchShouldMatchClasses() throws Exception { + String[] autoConfigurationClasses = new String[] { "test.match", "test.nomatch" }; + boolean[] result = this.filter.match(autoConfigurationClasses, + getAutoConfigurationMetadata()); + assertThat(result).containsExactly(true, false); + } + + @Test + public void matchShouldRecordOutcome() throws Exception { + String[] autoConfigurationClasses = new String[] { "test.match", "test.nomatch" }; + this.filter.match(autoConfigurationClasses, getAutoConfigurationMetadata()); + ConditionEvaluationReport report = ConditionEvaluationReport + .get(this.beanFactory); + assertThat(report.getConditionAndOutcomesBySource()).hasSize(1) + .containsKey("test.nomatch"); + } + + private AutoConfigurationMetadata getAutoConfigurationMetadata() { + AutoConfigurationMetadata metadata = mock(AutoConfigurationMetadata.class); + given(metadata.wasProcessed("test.match")).willReturn(true); + given(metadata.getSet("test.match", "ConditionalOnClass")) + .willReturn(Collections.singleton("java.io.InputStream")); + given(metadata.wasProcessed("test.nomatch")).willReturn(true); + given(metadata.getSet("test.nomatch", "ConditionalOnClass")) + .willReturn(Collections.singleton("java.io.DoesNotExist")); + return metadata; + } + +} From b0e06c30a0570367d9a2d3f7716d31842c107be1 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sun, 22 Jan 2017 23:03:40 -0800 Subject: [PATCH 14/14] Polish --- .../boot/autoconfigure/AutoConfigurationImportSelector.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java index 8d51e1111d4..cb27934cfa9 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java @@ -166,7 +166,7 @@ public class AutoConfigurationImportSelector private void checkExcludedClasses(List configurations, Set exclusions) { - List invalidExcludes = new ArrayList(); + List invalidExcludes = new ArrayList(exclusions.size()); for (String exclusion : exclusions) { if (ClassUtils.isPresent(exclusion, getClass().getClassLoader()) && !configurations.contains(exclusion)) {