mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Polish
This commit is contained in:
parent
fca192fa41
commit
412b7b9e50
@ -20,8 +20,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
|
||||
/**
|
||||
* Configuration properties for MVC endpoints' CORS support.
|
||||
@ -30,23 +28,22 @@ import org.springframework.web.cors.CorsConfiguration;
|
||||
* @since 1.3.0
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "endpoints.cors")
|
||||
public class MvcEndpointCorsProperties {
|
||||
public class EndpointCorsProperties {
|
||||
|
||||
/**
|
||||
* Comma-separated list of origins to allow. '*' allows all origins. When
|
||||
* not set, CORS support is disabled.
|
||||
* Comma-separated list of origins to allow. '*' allows all origins. When not set,
|
||||
* CORS support is disabled.
|
||||
*/
|
||||
private List<String> allowedOrigins = new ArrayList<String>();
|
||||
|
||||
/**
|
||||
* Comma-separated list of methods to allow. '*' allows all methods. When
|
||||
* not set, defaults to GET.
|
||||
* Comma-separated list of methods to allow. '*' allows all methods. When not set,
|
||||
* defaults to GET.
|
||||
*/
|
||||
private List<String> allowedMethods = new ArrayList<String>();
|
||||
|
||||
/**
|
||||
* Comma-separated list of headers to allow in a request. '*' allows all
|
||||
* headers.
|
||||
* Comma-separated list of headers to allow in a request. '*' allows all headers.
|
||||
*/
|
||||
private List<String> allowedHeaders = new ArrayList<String>();
|
||||
|
||||
@ -114,28 +111,4 @@ public class MvcEndpointCorsProperties {
|
||||
this.maxAge = maxAge;
|
||||
}
|
||||
|
||||
CorsConfiguration toCorsConfiguration() {
|
||||
if (CollectionUtils.isEmpty(this.allowedOrigins)) {
|
||||
return null;
|
||||
}
|
||||
CorsConfiguration corsConfiguration = new CorsConfiguration();
|
||||
corsConfiguration.setAllowedOrigins(this.allowedOrigins);
|
||||
if (!CollectionUtils.isEmpty(this.allowedHeaders)) {
|
||||
corsConfiguration.setAllowedHeaders(this.allowedHeaders);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(this.allowedMethods)) {
|
||||
corsConfiguration.setAllowedMethods(this.allowedMethods);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(this.exposedHeaders)) {
|
||||
corsConfiguration.setExposedHeaders(this.exposedHeaders);
|
||||
}
|
||||
if (this.maxAge != null) {
|
||||
corsConfiguration.setMaxAge(this.maxAge);
|
||||
}
|
||||
if (this.allowCredentials != null) {
|
||||
corsConfiguration.setAllowCredentials(this.allowCredentials);
|
||||
}
|
||||
return corsConfiguration;
|
||||
}
|
||||
|
||||
}
|
@ -18,6 +18,7 @@ package org.springframework.boot.actuate.autoconfigure;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
@ -45,6 +46,7 @@ import org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMappingCusto
|
||||
import org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.mvc.MetricsMvcEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.mvc.MvcEndpoints;
|
||||
import org.springframework.boot.actuate.endpoint.mvc.ShutdownMvcEndpoint;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
@ -71,7 +73,9 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.event.ContextClosedEvent;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
import org.springframework.web.servlet.DispatcherServlet;
|
||||
|
||||
@ -94,7 +98,7 @@ import org.springframework.web.servlet.DispatcherServlet;
|
||||
EmbeddedServletContainerAutoConfiguration.class, WebMvcAutoConfiguration.class,
|
||||
ManagementServerPropertiesAutoConfiguration.class })
|
||||
@EnableConfigurationProperties({ HealthMvcEndpointProperties.class,
|
||||
MvcEndpointCorsProperties.class })
|
||||
EndpointCorsProperties.class })
|
||||
public class EndpointWebMvcAutoConfiguration implements ApplicationContextAware,
|
||||
SmartInitializingSingleton {
|
||||
|
||||
@ -109,7 +113,7 @@ public class EndpointWebMvcAutoConfiguration implements ApplicationContextAware,
|
||||
private ManagementServerProperties managementServerProperties;
|
||||
|
||||
@Autowired
|
||||
private MvcEndpointCorsProperties corsMvcEndpointProperties;
|
||||
private EndpointCorsProperties corsProperties;
|
||||
|
||||
@Autowired(required = false)
|
||||
private List<EndpointHandlerMappingCustomizer> mappingCustomizers;
|
||||
@ -123,8 +127,10 @@ public class EndpointWebMvcAutoConfiguration implements ApplicationContextAware,
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public EndpointHandlerMapping endpointHandlerMapping() {
|
||||
EndpointHandlerMapping mapping = new EndpointHandlerMapping(mvcEndpoints()
|
||||
.getEndpoints(), this.corsMvcEndpointProperties.toCorsConfiguration());
|
||||
Set<? extends MvcEndpoint> endpoints = mvcEndpoints().getEndpoints();
|
||||
CorsConfiguration corsConfiguration = getCorsConfiguration(this.corsProperties);
|
||||
EndpointHandlerMapping mapping = new EndpointHandlerMapping(endpoints,
|
||||
corsConfiguration);
|
||||
boolean disabled = ManagementServerPort.get(this.applicationContext) != ManagementServerPort.SAME;
|
||||
mapping.setDisabled(disabled);
|
||||
if (!disabled) {
|
||||
@ -138,6 +144,30 @@ public class EndpointWebMvcAutoConfiguration implements ApplicationContextAware,
|
||||
return mapping;
|
||||
}
|
||||
|
||||
private CorsConfiguration getCorsConfiguration(EndpointCorsProperties properties) {
|
||||
if (CollectionUtils.isEmpty(properties.getAllowedOrigins())) {
|
||||
return null;
|
||||
}
|
||||
CorsConfiguration configuration = new CorsConfiguration();
|
||||
configuration.setAllowedOrigins(properties.getAllowedOrigins());
|
||||
if (!CollectionUtils.isEmpty(properties.getAllowedHeaders())) {
|
||||
configuration.setAllowedHeaders(properties.getAllowedHeaders());
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(properties.getAllowedMethods())) {
|
||||
configuration.setAllowedMethods(properties.getAllowedMethods());
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(properties.getExposedHeaders())) {
|
||||
configuration.setExposedHeaders(properties.getExposedHeaders());
|
||||
}
|
||||
if (properties.getMaxAge() != null) {
|
||||
configuration.setMaxAge(properties.getMaxAge());
|
||||
}
|
||||
if (properties.getAllowCredentials() != null) {
|
||||
configuration.setAllowCredentials(properties.getAllowCredentials());
|
||||
}
|
||||
return configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterSingletonsInstantiated() {
|
||||
ManagementServerPort managementPort = ManagementServerPort
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
* Copyright 2012-2015 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,8 @@ package org.springframework.boot.actuate;
|
||||
import org.springframework.boot.test.AbstractConfigurationClassTests;
|
||||
|
||||
/**
|
||||
* Tests for the actuator module's @Configuration classes
|
||||
* Tests for the actuator module's {@code @Configuration} classes.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class ActuatorConfigurationClassTests extends AbstractConfigurationClassTests {
|
||||
|
@ -52,18 +52,15 @@ public class SpringApplicationHierarchyTests {
|
||||
"--server.port=0");
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration(exclude = {
|
||||
ElasticsearchDataAutoConfiguration.class,
|
||||
ElasticsearchRepositoriesAutoConfiguration.class},
|
||||
excludeName = {"org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchAutoConfiguration"})
|
||||
@EnableAutoConfiguration(exclude = { ElasticsearchDataAutoConfiguration.class,
|
||||
ElasticsearchRepositoriesAutoConfiguration.class }, excludeName = { "org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchAutoConfiguration" })
|
||||
public static class Child {
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration(exclude = {JolokiaAutoConfiguration.class,
|
||||
@EnableAutoConfiguration(exclude = { JolokiaAutoConfiguration.class,
|
||||
EndpointMBeanExportAutoConfiguration.class,
|
||||
ElasticsearchDataAutoConfiguration.class,
|
||||
ElasticsearchRepositoriesAutoConfiguration.class},
|
||||
excludeName = {"org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchAutoConfiguration"})
|
||||
ElasticsearchRepositoriesAutoConfiguration.class }, excludeName = { "org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchAutoConfiguration" })
|
||||
public static class Parent {
|
||||
}
|
||||
|
||||
|
@ -84,6 +84,7 @@ public @interface EnableAutoConfiguration {
|
||||
* Exclude specific auto-configuration class names such that they will never be
|
||||
* applied.
|
||||
* @return the class names to exclude
|
||||
* @since 1.3.0
|
||||
*/
|
||||
String[] excludeName() default {};
|
||||
|
||||
|
@ -21,6 +21,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
@ -73,8 +74,8 @@ class EnableAutoConfigurationImportSelector implements DeferredImportSelector,
|
||||
SpringFactoriesLoader.loadFactoryNames(EnableAutoConfiguration.class,
|
||||
this.beanClassLoader)));
|
||||
|
||||
// Remove those specifically disabled
|
||||
List<String> excluded = new ArrayList<String>();
|
||||
// Remove those specifically excluded
|
||||
Set<String> excluded = new LinkedHashSet<String>();
|
||||
excluded.addAll(Arrays.asList(attributes.getStringArray("exclude")));
|
||||
excluded.addAll(Arrays.asList(attributes.getStringArray("excludeName")));
|
||||
factories.removeAll(excluded);
|
||||
|
@ -57,6 +57,7 @@ public @interface SpringBootApplication {
|
||||
* Exclude specific auto-configuration class names such that they will never be
|
||||
* applied.
|
||||
* @return the class names to exclude
|
||||
* @since 1.3.0
|
||||
*/
|
||||
String[] excludeName() default {};
|
||||
|
||||
|
@ -106,7 +106,8 @@ public class RabbitAutoConfiguration {
|
||||
protected static class RabbitConnectionFactoryCreator {
|
||||
|
||||
@Bean
|
||||
public ConnectionFactory rabbitConnectionFactory(RabbitProperties config) throws Exception {
|
||||
public ConnectionFactory rabbitConnectionFactory(RabbitProperties config)
|
||||
throws Exception {
|
||||
RabbitConnectionFactoryBean factory = new RabbitConnectionFactoryBean();
|
||||
if (config.getHost() != null) {
|
||||
factory.setHost(config.getHost());
|
||||
@ -131,12 +132,13 @@ public class RabbitAutoConfiguration {
|
||||
Properties properties = ssl.createSslProperties();
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
properties.store(outputStream, "SSL config");
|
||||
factory.setSslPropertiesLocation(
|
||||
new ByteArrayResource(outputStream.toByteArray()));
|
||||
factory.setSslPropertiesLocation(new ByteArrayResource(outputStream
|
||||
.toByteArray()));
|
||||
}
|
||||
}
|
||||
factory.afterPropertiesSet();
|
||||
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(factory.getObject());
|
||||
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(
|
||||
factory.getObject());
|
||||
connectionFactory.setAddresses(config.getAddresses());
|
||||
return connectionFactory;
|
||||
}
|
||||
|
@ -73,7 +73,6 @@ public class RabbitProperties {
|
||||
*/
|
||||
private Integer requestedHeartbeat;
|
||||
|
||||
|
||||
public String getHost() {
|
||||
if (this.addresses == null) {
|
||||
return this.host;
|
||||
@ -161,7 +160,7 @@ public class RabbitProperties {
|
||||
}
|
||||
|
||||
public Ssl getSsl() {
|
||||
return ssl;
|
||||
return this.ssl;
|
||||
}
|
||||
|
||||
public String getVirtualHost() {
|
||||
@ -173,7 +172,7 @@ public class RabbitProperties {
|
||||
}
|
||||
|
||||
public Integer getRequestedHeartbeat() {
|
||||
return requestedHeartbeat;
|
||||
return this.requestedHeartbeat;
|
||||
}
|
||||
|
||||
public void setRequestedHeartbeat(Integer requestedHeartbeat) {
|
||||
@ -208,7 +207,7 @@ public class RabbitProperties {
|
||||
private String trustStorePassword;
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
@ -216,7 +215,7 @@ public class RabbitProperties {
|
||||
}
|
||||
|
||||
public String getKeyStore() {
|
||||
return keyStore;
|
||||
return this.keyStore;
|
||||
}
|
||||
|
||||
public void setKeyStore(String keyStore) {
|
||||
@ -224,7 +223,7 @@ public class RabbitProperties {
|
||||
}
|
||||
|
||||
public String getKeyStorePassword() {
|
||||
return keyStorePassword;
|
||||
return this.keyStorePassword;
|
||||
}
|
||||
|
||||
public void setKeyStorePassword(String keyStorePassword) {
|
||||
@ -232,7 +231,7 @@ public class RabbitProperties {
|
||||
}
|
||||
|
||||
public String getTrustStore() {
|
||||
return trustStore;
|
||||
return this.trustStore;
|
||||
}
|
||||
|
||||
public void setTrustStore(String trustStore) {
|
||||
@ -240,7 +239,7 @@ public class RabbitProperties {
|
||||
}
|
||||
|
||||
public String getTrustStorePassword() {
|
||||
return trustStorePassword;
|
||||
return this.trustStorePassword;
|
||||
}
|
||||
|
||||
public void setTrustStorePassword(String trustStorePassword) {
|
||||
@ -249,7 +248,8 @@ public class RabbitProperties {
|
||||
|
||||
/**
|
||||
* Create the ssl configuration as expected by the
|
||||
* {@link org.springframework.amqp.rabbit.connection.RabbitConnectionFactoryBean RabbitConnectionFactoryBean}.
|
||||
* {@link org.springframework.amqp.rabbit.connection.RabbitConnectionFactoryBean
|
||||
* RabbitConnectionFactoryBean}.
|
||||
* @return the ssl configuration
|
||||
*/
|
||||
public Properties createSslProperties() {
|
||||
|
@ -62,6 +62,7 @@ class BasicBatchConfigurer implements BatchConfigurer {
|
||||
|
||||
/**
|
||||
* Create a new {@link BasicBatchConfigurer} instance.
|
||||
* @param properties the batch properties
|
||||
* @param dataSource the underlying data source
|
||||
*/
|
||||
public BasicBatchConfigurer(BatchProperties properties, DataSource dataSource) {
|
||||
@ -70,6 +71,7 @@ class BasicBatchConfigurer implements BatchConfigurer {
|
||||
|
||||
/**
|
||||
* Create a new {@link BasicBatchConfigurer} instance.
|
||||
* @param properties the batch properties
|
||||
* @param dataSource the underlying data source
|
||||
* @param entityManagerFactory the entity manager factory (or {@code null})
|
||||
*/
|
||||
|
@ -141,7 +141,8 @@ public class BatchAutoConfiguration {
|
||||
@ConditionalOnBean(name = "entityManagerFactory")
|
||||
public BatchConfigurer jpaBatchConfigurer(DataSource dataSource,
|
||||
EntityManagerFactory entityManagerFactory) {
|
||||
return new BasicBatchConfigurer(this.properties, dataSource, entityManagerFactory);
|
||||
return new BasicBatchConfigurer(this.properties, dataSource,
|
||||
entityManagerFactory);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
@ -17,6 +17,7 @@
|
||||
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.LinkedHashSet;
|
||||
@ -86,7 +87,7 @@ public class ConditionEvaluationReport {
|
||||
* Records the name of the classes that have been excluded from condition evaluation
|
||||
* @param exclusions the names of the excluded classes
|
||||
*/
|
||||
public void recordExclusions(List<String> exclusions) {
|
||||
public void recordExclusions(Collection<String> exclusions) {
|
||||
Assert.notNull(exclusions, "exclusions must not be null");
|
||||
this.exclusions = new ArrayList<String>(exclusions);
|
||||
}
|
||||
|
@ -47,13 +47,13 @@ class JndiSessionConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public Session session() {
|
||||
String jndiName = this.properties.getJndiName();
|
||||
try {
|
||||
return new JndiLocatorDelegate()
|
||||
.lookup(this.properties.getJndiName(), Session.class);
|
||||
return new JndiLocatorDelegate().lookup(jndiName, Session.class);
|
||||
}
|
||||
catch (NamingException e) {
|
||||
catch (NamingException ex) {
|
||||
throw new IllegalStateException(String.format(
|
||||
"Unable to find Session in JNDI location %s", this.properties.getJndiName()));
|
||||
"Unable to find Session in JNDI location %s", jndiName), ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,4 +118,5 @@ public class MailProperties {
|
||||
public String getJndiName() {
|
||||
return this.jndiName;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,7 +16,9 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.mail;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.activation.MimeType;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
@ -65,25 +67,33 @@ public class MailSenderAutoConfiguration {
|
||||
sender.setSession(this.session);
|
||||
}
|
||||
else {
|
||||
sender.setHost(this.properties.getHost());
|
||||
if (this.properties.getPort() != null) {
|
||||
sender.setPort(this.properties.getPort());
|
||||
}
|
||||
sender.setUsername(this.properties.getUsername());
|
||||
sender.setPassword(this.properties.getPassword());
|
||||
sender.setDefaultEncoding(this.properties.getDefaultEncoding());
|
||||
if (!this.properties.getProperties().isEmpty()) {
|
||||
Properties properties = new Properties();
|
||||
properties.putAll(this.properties.getProperties());
|
||||
sender.setJavaMailProperties(properties);
|
||||
}
|
||||
applyProperties(sender);
|
||||
}
|
||||
return sender;
|
||||
}
|
||||
|
||||
private void applyProperties(JavaMailSenderImpl sender) {
|
||||
sender.setHost(this.properties.getHost());
|
||||
if (this.properties.getPort() != null) {
|
||||
sender.setPort(this.properties.getPort());
|
||||
}
|
||||
sender.setUsername(this.properties.getUsername());
|
||||
sender.setPassword(this.properties.getPassword());
|
||||
sender.setDefaultEncoding(this.properties.getDefaultEncoding());
|
||||
if (!this.properties.getProperties().isEmpty()) {
|
||||
sender.setJavaMailProperties(asProperties(this.properties.getProperties()));
|
||||
}
|
||||
}
|
||||
|
||||
private Properties asProperties(Map<String, String> source) {
|
||||
Properties properties = new Properties();
|
||||
properties.putAll(source);
|
||||
return properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Condition to trigger the creation of a {@link JavaMailSenderImpl}. This kicks in
|
||||
* if either the host or jndi name property is set.
|
||||
* Condition to trigger the creation of a {@link JavaMailSenderImpl}. This kicks in if
|
||||
* either the host or jndi name property is set.
|
||||
*/
|
||||
static class MailSenderCondition extends AnyNestedCondition {
|
||||
|
||||
|
@ -37,7 +37,6 @@ import org.springframework.social.connect.ConnectionFactory;
|
||||
import org.springframework.social.connect.ConnectionRepository;
|
||||
import org.springframework.social.connect.web.GenericConnectionStatusView;
|
||||
import org.springframework.social.facebook.api.Facebook;
|
||||
import org.springframework.social.facebook.api.impl.FacebookTemplate;
|
||||
import org.springframework.social.facebook.connect.FacebookConnectionFactory;
|
||||
import org.springframework.web.servlet.View;
|
||||
|
||||
|
@ -463,14 +463,36 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer, Ord
|
||||
if (getBasedir() != null) {
|
||||
factory.setBaseDirectory(getBasedir());
|
||||
}
|
||||
customizeBackgroundProcessorDelay(factory);
|
||||
customizeHeaders(factory);
|
||||
if (this.maxThreads > 0) {
|
||||
customizeMaxThreads(factory);
|
||||
}
|
||||
if (this.maxHttpHeaderSize > 0) {
|
||||
customizeMaxHttpHeaderSize(factory);
|
||||
}
|
||||
customizeCompression(factory);
|
||||
if (this.accessLogEnabled) {
|
||||
customizeAccessLog(factory);
|
||||
}
|
||||
if (getUriEncoding() != null) {
|
||||
factory.setUriEncoding(getUriEncoding());
|
||||
}
|
||||
}
|
||||
|
||||
private void customizeBackgroundProcessorDelay(
|
||||
TomcatEmbeddedServletContainerFactory factory) {
|
||||
factory.addContextCustomizers(new TomcatContextCustomizer() {
|
||||
|
||||
@Override
|
||||
public void customize(Context context) {
|
||||
context.setBackgroundProcessorDelay(Tomcat.this.backgroundProcessorDelay);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private void customizeHeaders(TomcatEmbeddedServletContainerFactory factory) {
|
||||
String remoteIpHeader = getRemoteIpHeader();
|
||||
String protocolHeader = getProtocolHeader();
|
||||
if (StringUtils.hasText(remoteIpHeader)
|
||||
@ -482,35 +504,42 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer, Ord
|
||||
valve.setPortHeader(getPortHeader());
|
||||
factory.addContextValves(valve);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.maxThreads > 0) {
|
||||
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
|
||||
@Override
|
||||
public void customize(Connector connector) {
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractProtocol) {
|
||||
@SuppressWarnings("rawtypes")
|
||||
AbstractProtocol protocol = (AbstractProtocol) handler;
|
||||
protocol.setMaxThreads(Tomcat.this.maxThreads);
|
||||
}
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void customizeMaxThreads(TomcatEmbeddedServletContainerFactory factory) {
|
||||
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
|
||||
@Override
|
||||
public void customize(Connector connector) {
|
||||
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractProtocol) {
|
||||
AbstractProtocol protocol = (AbstractProtocol) handler;
|
||||
protocol.setMaxThreads(Tomcat.this.maxThreads);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (this.maxHttpHeaderSize > 0) {
|
||||
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
|
||||
@Override
|
||||
public void customize(Connector connector) {
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractHttp11Protocol) {
|
||||
@SuppressWarnings("rawtypes")
|
||||
AbstractHttp11Protocol protocol = (AbstractHttp11Protocol) handler;
|
||||
protocol.setMaxHttpHeaderSize(Tomcat.this.maxHttpHeaderSize);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void customizeMaxHttpHeaderSize(
|
||||
TomcatEmbeddedServletContainerFactory factory) {
|
||||
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
|
||||
|
||||
@Override
|
||||
public void customize(Connector connector) {
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractHttp11Protocol) {
|
||||
AbstractHttp11Protocol protocol = (AbstractHttp11Protocol) handler;
|
||||
protocol.setMaxHttpHeaderSize(Tomcat.this.maxHttpHeaderSize);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private void customizeCompression(TomcatEmbeddedServletContainerFactory factory) {
|
||||
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
|
||||
|
||||
@Override
|
||||
@ -535,22 +564,14 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer, Ord
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
if (this.accessLogEnabled) {
|
||||
AccessLogValve valve = new AccessLogValve();
|
||||
String accessLogPattern = getAccessLogPattern();
|
||||
if (accessLogPattern != null) {
|
||||
valve.setPattern(accessLogPattern);
|
||||
}
|
||||
else {
|
||||
valve.setPattern("common");
|
||||
}
|
||||
valve.setSuffix(".log");
|
||||
factory.addContextValves(valve);
|
||||
}
|
||||
if (getUriEncoding() != null) {
|
||||
factory.setUriEncoding(getUriEncoding());
|
||||
}
|
||||
private void customizeAccessLog(TomcatEmbeddedServletContainerFactory factory) {
|
||||
AccessLogValve valve = new AccessLogValve();
|
||||
String accessLogPattern = getAccessLogPattern();
|
||||
valve.setPattern(accessLogPattern == null ? "common" : accessLogPattern);
|
||||
valve.setSuffix(".log");
|
||||
factory.addContextValves(valve);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
* Copyright 2012-2015 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,8 @@ package org.springframework.boot.autoconfigure;
|
||||
import org.springframework.boot.test.AbstractConfigurationClassTests;
|
||||
|
||||
/**
|
||||
* Tests for the autoconfigure module's <code>@Configuration</code> classes
|
||||
* Tests for the auto-configure module's {@code @Configuration} classes.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class AutoConfigureConfigurationClassTests extends AbstractConfigurationClassTests {
|
||||
|
@ -81,7 +81,8 @@ public class EnableAutoConfigurationImportSelectorTests {
|
||||
|
||||
@Test
|
||||
public void classExclusionsAreApplied() {
|
||||
configureExclusions(new String[]{FreeMarkerAutoConfiguration.class.getName()}, new String[0]);
|
||||
configureExclusions(new String[] { FreeMarkerAutoConfiguration.class.getName() },
|
||||
new String[0]);
|
||||
String[] imports = this.importSelector.selectImports(this.annotationMetadata);
|
||||
assertThat(imports.length,
|
||||
is(equalTo(getAutoConfigurationClassNames().size() - 1)));
|
||||
@ -91,7 +92,8 @@ public class EnableAutoConfigurationImportSelectorTests {
|
||||
|
||||
@Test
|
||||
public void classNamesExclusionsAreApplied() {
|
||||
configureExclusions(new String[0], new String[]{VelocityAutoConfiguration.class.getName()});
|
||||
configureExclusions(new String[0],
|
||||
new String[] { VelocityAutoConfiguration.class.getName() });
|
||||
String[] imports = this.importSelector.selectImports(this.annotationMetadata);
|
||||
assertThat(imports.length,
|
||||
is(equalTo(getAutoConfigurationClassNames().size() - 1)));
|
||||
@ -101,12 +103,13 @@ public class EnableAutoConfigurationImportSelectorTests {
|
||||
|
||||
@Test
|
||||
public void bothExclusionsAreApplied() {
|
||||
configureExclusions(new String[]{VelocityAutoConfiguration.class.getName()},
|
||||
new String[]{FreeMarkerAutoConfiguration.class.getName()});
|
||||
configureExclusions(new String[] { VelocityAutoConfiguration.class.getName() },
|
||||
new String[] { FreeMarkerAutoConfiguration.class.getName() });
|
||||
String[] imports = this.importSelector.selectImports(this.annotationMetadata);
|
||||
assertThat(imports.length,
|
||||
is(equalTo(getAutoConfigurationClassNames().size() - 2)));
|
||||
assertThat(ConditionEvaluationReport.get(this.beanFactory).getExclusions(),
|
||||
assertThat(
|
||||
ConditionEvaluationReport.get(this.beanFactory).getExclusions(),
|
||||
containsInAnyOrder(FreeMarkerAutoConfiguration.class.getName(),
|
||||
VelocityAutoConfiguration.class.getName()));
|
||||
}
|
||||
@ -116,8 +119,10 @@ public class EnableAutoConfigurationImportSelectorTests {
|
||||
this.annotationMetadata.getAnnotationAttributes(
|
||||
EnableAutoConfiguration.class.getName(), true)).willReturn(
|
||||
this.annotationAttributes);
|
||||
given(this.annotationAttributes.getStringArray("exclude")).willReturn(classExclusion);
|
||||
given(this.annotationAttributes.getStringArray("excludeName")).willReturn(nameExclusion);
|
||||
given(this.annotationAttributes.getStringArray("exclude")).willReturn(
|
||||
classExclusion);
|
||||
given(this.annotationAttributes.getStringArray("excludeName")).willReturn(
|
||||
nameExclusion);
|
||||
}
|
||||
|
||||
private List<String> getAutoConfigurationClassNames() {
|
||||
|
@ -212,13 +212,15 @@ public class RabbitAutoConfigurationTests {
|
||||
public void enableSsl() {
|
||||
load(TestConfiguration.class, "spring.rabbitmq.ssl.enabled:true");
|
||||
com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory = getTargetConnectionFactory();
|
||||
assertTrue("SocketFactory must use SSL", rabbitConnectionFactory.getSocketFactory() instanceof SSLSocketFactory);
|
||||
assertTrue("SocketFactory must use SSL",
|
||||
rabbitConnectionFactory.getSocketFactory() instanceof SSLSocketFactory);
|
||||
}
|
||||
|
||||
@Test // Make sure that we at least attempt to load the store
|
||||
@Test
|
||||
// Make sure that we at least attempt to load the store
|
||||
public void enableSslWithExtraConfig() {
|
||||
thrown.expectMessage("foo");
|
||||
thrown.expectMessage("does not exist");
|
||||
this.thrown.expectMessage("foo");
|
||||
this.thrown.expectMessage("does not exist");
|
||||
load(TestConfiguration.class, "spring.rabbitmq.ssl.enabled:true",
|
||||
"spring.rabbitmq.ssl.keyStore=foo",
|
||||
"spring.rabbitmq.ssl.keyStorePassword=secret",
|
||||
@ -229,8 +231,8 @@ public class RabbitAutoConfigurationTests {
|
||||
private com.rabbitmq.client.ConnectionFactory getTargetConnectionFactory() {
|
||||
CachingConnectionFactory connectionFactory = this.context
|
||||
.getBean(CachingConnectionFactory.class);
|
||||
return (com.rabbitmq.client.ConnectionFactory)
|
||||
new DirectFieldAccessor(connectionFactory).getPropertyValue("rabbitConnectionFactory");
|
||||
return (com.rabbitmq.client.ConnectionFactory) new DirectFieldAccessor(
|
||||
connectionFactory).getPropertyValue("rabbitConnectionFactory");
|
||||
}
|
||||
|
||||
private void load(Class<?> config, String... environment) {
|
||||
|
@ -69,7 +69,7 @@ public class DataSourceJsonSerializationTests {
|
||||
public void serializerWithMixin() throws Exception {
|
||||
DataSource dataSource = new DataSource();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.addMixInAnnotations(DataSource.class, DataSourceJson.class);
|
||||
mapper.addMixIn(DataSource.class, DataSourceJson.class);
|
||||
String value = mapper.writeValueAsString(dataSource);
|
||||
assertTrue(value.contains("\"url\":"));
|
||||
assertEquals(1, StringUtils.countOccurrencesOf(value, "\"url\""));
|
||||
|
@ -79,9 +79,10 @@ public class DataSourceTransactionManagerAutoConfigurationTests {
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
DataSourceTransactionManagerAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertEquals("No transaction manager should be been created", 1,
|
||||
this.context.getBeansOfType(PlatformTransactionManager.class).size());
|
||||
assertEquals("Wrong transaction manager", this.context.getBean("myTransactionManager"),
|
||||
assertEquals("No transaction manager should be been created", 1, this.context
|
||||
.getBeansOfType(PlatformTransactionManager.class).size());
|
||||
assertEquals("Wrong transaction manager",
|
||||
this.context.getBean("myTransactionManager"),
|
||||
this.context.getBean(PlatformTransactionManager.class));
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,12 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.mail;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.mail.Session;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
@ -31,12 +37,6 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||
|
||||
import javax.mail.Session;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
@ -78,7 +78,8 @@ public class MailSenderAutoConfigurationTests {
|
||||
if (this.initialContextFactory != null) {
|
||||
System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
|
||||
this.initialContextFactory);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
System.clearProperty(Context.INITIAL_CONTEXT_FACTORY);
|
||||
}
|
||||
if (this.context != null) {
|
||||
@ -138,20 +139,18 @@ public class MailSenderAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void jndiSessionAvailable() throws NamingException {
|
||||
Session session = configureJndiSession("foo");
|
||||
Session session = configureJndiSession("foo");
|
||||
load(EmptyConfig.class, "spring.mail.jndi-name:foo");
|
||||
|
||||
Session sessionBean = this.context.getBean(Session.class);
|
||||
assertEquals(session, sessionBean);
|
||||
assertEquals(sessionBean, this.context.getBean(JavaMailSenderImpl.class).getSession());
|
||||
assertEquals(sessionBean, this.context.getBean(JavaMailSenderImpl.class)
|
||||
.getSession());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jndiSessionIgnoredIfJndiNameNotSet() throws NamingException {
|
||||
configureJndiSession("foo");
|
||||
|
||||
load(EmptyConfig.class, "spring.mail.host:smtp.acme.org");
|
||||
|
||||
assertEquals(0, this.context.getBeanNamesForType(Session.class).length);
|
||||
assertNotNull(this.context.getBean(JavaMailSender.class));
|
||||
}
|
||||
@ -159,23 +158,20 @@ public class MailSenderAutoConfigurationTests {
|
||||
@Test
|
||||
public void jndiSessionNotUsedIfJndiNameNotSet() throws NamingException {
|
||||
configureJndiSession("foo");
|
||||
|
||||
load(EmptyConfig.class);
|
||||
|
||||
assertEquals(0, this.context.getBeanNamesForType(Session.class).length);
|
||||
assertEquals(0, this.context.getBeanNamesForType(JavaMailSender.class).length);
|
||||
assertEquals(0, this.context.getBeanNamesForType(JavaMailSender.class).length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jndiSessionNotAvailableWithJndiName() throws NamingException {
|
||||
thrown.expect(BeanCreationException.class);
|
||||
thrown.expectMessage("Unable to find Session in JNDI location foo");
|
||||
|
||||
this.thrown.expect(BeanCreationException.class);
|
||||
this.thrown.expectMessage("Unable to find Session in JNDI location foo");
|
||||
load(EmptyConfig.class, "spring.mail.jndi-name:foo");
|
||||
}
|
||||
|
||||
private Session configureJndiSession(String name)
|
||||
throws IllegalStateException, NamingException {
|
||||
private Session configureJndiSession(String name) throws IllegalStateException,
|
||||
NamingException {
|
||||
Properties properties = new Properties();
|
||||
Session session = Session.getDefaultInstance(properties);
|
||||
TestableInitialContextFactory.bind(name, session);
|
||||
|
@ -18,8 +18,6 @@ package org.springframework.boot.autoconfigure.mobile;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.thymeleaf.spring4.view.ThymeleafViewResolver;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.PropertyAccessor;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
@ -38,6 +36,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.mobile.device.view.AbstractDeviceDelegatingViewResolver;
|
||||
import org.springframework.mobile.device.view.LiteDeviceDelegatingViewResolver;
|
||||
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
||||
import org.thymeleaf.spring4.view.ThymeleafViewResolver;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@ -93,7 +92,7 @@ public class DeviceDelegatingViewResolverAutoConfigurationTests {
|
||||
try {
|
||||
this.context.getBean(ThymeleafViewResolver.class);
|
||||
}
|
||||
catch (NoSuchBeanDefinitionException e) {
|
||||
catch (NoSuchBeanDefinitionException ex) {
|
||||
// expected. ThymeleafViewResolver shouldn't be defined.
|
||||
}
|
||||
assertTrue(deviceDelegatingViewResolver.getOrder() == internalResourceViewResolver
|
||||
@ -114,7 +113,7 @@ public class DeviceDelegatingViewResolverAutoConfigurationTests {
|
||||
try {
|
||||
this.context.getBean(ThymeleafViewResolver.class);
|
||||
}
|
||||
catch (NoSuchBeanDefinitionException e) {
|
||||
catch (NoSuchBeanDefinitionException ex) {
|
||||
// expected. ThymeleafViewResolver shouldn't be defined.
|
||||
}
|
||||
this.context.getBean("deviceDelegatingViewResolver",
|
||||
@ -177,7 +176,8 @@ public class DeviceDelegatingViewResolverAutoConfigurationTests {
|
||||
.getBean("deviceDelegatingViewResolver",
|
||||
LiteDeviceDelegatingViewResolver.class);
|
||||
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(liteDeviceDelegatingViewResolver);
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(
|
||||
liteDeviceDelegatingViewResolver);
|
||||
assertEquals(false, accessor.getPropertyValue("enableFallback"));
|
||||
assertEquals("", accessor.getPropertyValue("normalPrefix"));
|
||||
assertEquals("mobile/", accessor.getPropertyValue("mobilePrefix"));
|
||||
@ -224,7 +224,7 @@ public class DeviceDelegatingViewResolverAutoConfigurationTests {
|
||||
PropertyAccessor accessor = getLiteDeviceDelegatingViewResolverAccessor(
|
||||
"spring.mobile.devicedelegatingviewresolver.enabled:true",
|
||||
"spring.mobile.devicedelegatingviewresolver.normalSuffix:.nor");
|
||||
assertEquals(".nor", accessor.getPropertyValue("normalSuffix"));
|
||||
assertEquals(".nor", accessor.getPropertyValue("normalSuffix"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -232,7 +232,7 @@ public class DeviceDelegatingViewResolverAutoConfigurationTests {
|
||||
PropertyAccessor accessor = getLiteDeviceDelegatingViewResolverAccessor(
|
||||
"spring.mobile.devicedelegatingviewresolver.enabled:true",
|
||||
"spring.mobile.devicedelegatingviewresolver.mobileSuffix:.mob");
|
||||
assertEquals(".mob", accessor.getPropertyValue("mobileSuffix"));
|
||||
assertEquals(".mob", accessor.getPropertyValue("mobileSuffix"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -243,7 +243,8 @@ public class DeviceDelegatingViewResolverAutoConfigurationTests {
|
||||
assertEquals(".tab", accessor.getPropertyValue("tabletSuffix"));
|
||||
}
|
||||
|
||||
private PropertyAccessor getLiteDeviceDelegatingViewResolverAccessor(String... configuration) {
|
||||
private PropertyAccessor getLiteDeviceDelegatingViewResolverAccessor(
|
||||
String... configuration) {
|
||||
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
|
||||
EnvironmentTestUtils.addEnvironment(this.context, configuration);
|
||||
this.context.register(Config.class, WebMvcAutoConfiguration.class,
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
* Copyright 2012-2015 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.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
* Copyright 2012-2015 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.
|
||||
|
@ -130,19 +130,15 @@ public class InitCommand extends OptionParsingCommand {
|
||||
|
||||
private void projectGenerationOptions() {
|
||||
this.groupId = option(Arrays.asList("groupId", "g"),
|
||||
"Project coordinates (for example 'org.test')")
|
||||
.withRequiredArg();
|
||||
"Project coordinates (for example 'org.test')").withRequiredArg();
|
||||
this.artifactId = option(Arrays.asList("artifactId", "a"),
|
||||
"Project coordinates; infer archive name (for example 'test')")
|
||||
.withRequiredArg();
|
||||
this.version = option(Arrays.asList("version", "v"),
|
||||
"Project version (for example '0.0.1-SNAPSHOT')")
|
||||
.withRequiredArg();
|
||||
"Project version (for example '0.0.1-SNAPSHOT')").withRequiredArg();
|
||||
this.name = option(Arrays.asList("name", "n"),
|
||||
"Project name; infer application name")
|
||||
.withRequiredArg();
|
||||
this.description = option("description",
|
||||
"Project description")
|
||||
"Project name; infer application name").withRequiredArg();
|
||||
this.description = option("description", "Project description")
|
||||
.withRequiredArg();
|
||||
this.packaging = option(Arrays.asList("packaging", "p"),
|
||||
"Project packaging (for example 'jar')").withRequiredArg();
|
||||
@ -162,8 +158,7 @@ public class InitCommand extends OptionParsingCommand {
|
||||
this.javaVersion = option(Arrays.asList("java-version", "j"),
|
||||
"Language level (for example '1.8')").withRequiredArg();
|
||||
this.language = option(Arrays.asList("language", "l"),
|
||||
"Programming language (for example 'java')")
|
||||
.withRequiredArg();
|
||||
"Programming language (for example 'java')").withRequiredArg();
|
||||
this.bootVersion = option(Arrays.asList("boot-version", "b"),
|
||||
"Spring Boot version (for example '1.2.0.RELEASE')")
|
||||
.withRequiredArg();
|
||||
@ -240,22 +235,22 @@ public class InitCommand extends OptionParsingCommand {
|
||||
if (options.has(this.type)) {
|
||||
request.setType(options.valueOf(this.type));
|
||||
}
|
||||
if(options.has(this.language)) {
|
||||
if (options.has(this.language)) {
|
||||
request.setLanguage(options.valueOf(this.language));
|
||||
}
|
||||
if(options.has(this.groupId)) {
|
||||
if (options.has(this.groupId)) {
|
||||
request.setGroupId(options.valueOf(this.groupId));
|
||||
}
|
||||
if (options.has(this.artifactId)) {
|
||||
request.setArtifactId(options.valueOf(this.artifactId));
|
||||
}
|
||||
if(options.has(this.name)) {
|
||||
if (options.has(this.name)) {
|
||||
request.setName(options.valueOf(this.name));
|
||||
}
|
||||
if(options.has(this.version)) {
|
||||
if (options.has(this.version)) {
|
||||
request.setVersion(options.valueOf(this.version));
|
||||
}
|
||||
if(options.has(this.description)) {
|
||||
if (options.has(this.description)) {
|
||||
request.setDescription(options.valueOf(this.description));
|
||||
}
|
||||
request.setExtract(options.has(this.extract));
|
||||
|
@ -25,7 +25,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.http.client.utils.URIBuilder;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@ -392,7 +391,7 @@ class ProjectGenerationRequest {
|
||||
private static void filter(Map<String, ProjectType> projects, String tag,
|
||||
String tagValue) {
|
||||
for (Iterator<Map.Entry<String, ProjectType>> it = projects.entrySet().iterator(); it
|
||||
.hasNext(); ) {
|
||||
.hasNext();) {
|
||||
Map.Entry<String, ProjectType> entry = it.next();
|
||||
String value = entry.getValue().getTags().get(tag);
|
||||
if (!tagValue.equals(value)) {
|
||||
|
@ -81,7 +81,6 @@ public abstract class CompilerAutoConfiguration {
|
||||
|
||||
/**
|
||||
* Apply any additional configuration.
|
||||
*
|
||||
* @param loader the class loader being used during compilation
|
||||
* @param configuration the compiler configuration
|
||||
* @param generatorContext the current context
|
||||
@ -93,4 +92,5 @@ public abstract class CompilerAutoConfiguration {
|
||||
GroovyCompilerConfiguration configuration, GeneratorContext generatorContext,
|
||||
SourceUnit source, ClassNode classNode) throws CompilationFailedException {
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -100,11 +100,9 @@ public class DependencyManagementBomTransformation extends AnnotatedNodeASTTrans
|
||||
|
||||
private List<Map<String, String>> createDependencyMaps(Expression valueExpression) {
|
||||
Map<String, String> dependency = null;
|
||||
|
||||
List<ConstantExpression> constantExpressions = getConstantExpressions(valueExpression);
|
||||
List<Map<String, String>> dependencies = new ArrayList<Map<String, String>>(
|
||||
constantExpressions.size());
|
||||
|
||||
for (ConstantExpression expression : constantExpressions) {
|
||||
Object value = expression.getValue();
|
||||
if (value instanceof String) {
|
||||
@ -122,7 +120,6 @@ public class DependencyManagementBomTransformation extends AnnotatedNodeASTTrans
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
@ -130,12 +127,10 @@ public class DependencyManagementBomTransformation extends AnnotatedNodeASTTrans
|
||||
if (valueExpression instanceof ListExpression) {
|
||||
return getConstantExpressions((ListExpression) valueExpression);
|
||||
}
|
||||
|
||||
if (valueExpression instanceof ConstantExpression
|
||||
&& ((ConstantExpression) valueExpression).getValue() instanceof String) {
|
||||
return Arrays.asList((ConstantExpression) valueExpression);
|
||||
}
|
||||
|
||||
reportError("@DependencyManagementBom requires an inline constant that is a "
|
||||
+ "string or a string array", valueExpression);
|
||||
return Collections.emptyList();
|
||||
@ -166,16 +161,13 @@ public class DependencyManagementBomTransformation extends AnnotatedNodeASTTrans
|
||||
List<Map<String, String>> bomDependencies) {
|
||||
URI[] uris = Grape.getInstance().resolve(null,
|
||||
bomDependencies.toArray(new Map[bomDependencies.size()]));
|
||||
|
||||
DefaultModelBuilder modelBuilder = new DefaultModelBuilderFactory().newInstance();
|
||||
|
||||
for (URI uri : uris) {
|
||||
try {
|
||||
DefaultModelBuildingRequest request = new DefaultModelBuildingRequest();
|
||||
request.setModelResolver(new GrapeModelResolver());
|
||||
request.setModelSource(new UrlModelSource(uri.toURL()));
|
||||
Model model = modelBuilder.build(request).getEffectiveModel();
|
||||
|
||||
this.resolutionContext
|
||||
.addDependencyManagement(new MavenModelDependencyManagement(model));
|
||||
}
|
||||
@ -236,4 +228,5 @@ public class DependencyManagementBomTransformation extends AnnotatedNodeASTTrans
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,23 +28,21 @@ public interface DependencyManagement {
|
||||
|
||||
/**
|
||||
* Returns the managed dependencies.
|
||||
*
|
||||
* @return the managed dependencies
|
||||
*/
|
||||
List<Dependency> getDependencies();
|
||||
|
||||
/**
|
||||
* Returns the managed version of Spring Boot. May be {@code null}.
|
||||
*
|
||||
* @return the Spring Boot version, or {@code null}
|
||||
*/
|
||||
String getSpringBootVersion();
|
||||
|
||||
/**
|
||||
* Finds the managed dependency with the given {@code artifactId}.
|
||||
*
|
||||
* @param artifactId The artifact ID of the dependency to find
|
||||
* @return the dependency, or {@code null}
|
||||
*/
|
||||
Dependency find(String artifactId);
|
||||
|
||||
}
|
||||
|
@ -19,7 +19,8 @@ package org.springframework.boot.cli.compiler.dependencies;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* {@link ArtifactCoordinatesResolver} backed by {@link SpringBootDependenciesDependencyManagement}.
|
||||
* {@link ArtifactCoordinatesResolver} backed by
|
||||
* {@link SpringBootDependenciesDependencyManagement}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
@ -70,4 +71,5 @@ public class DependencyManagementArtifactCoordinatesResolver implements
|
||||
Dependency dependency = find(module);
|
||||
return dependency == null ? null : dependency.getVersion();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -75,4 +75,5 @@ public class MavenModelDependencyManagement implements DependencyManagement {
|
||||
public Dependency find(String artifactId) {
|
||||
return this.byArtifactId.get(artifactId);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import joptsimple.OptionSet;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.junit.Before;
|
||||
@ -34,7 +35,6 @@ import org.junit.rules.TemporaryFolder;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import org.springframework.boot.cli.command.status.ExitStatus;
|
||||
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
* Copyright 2012-2015 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,6 @@ import org.json.JSONObject;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.StreamUtils;
|
||||
@ -118,7 +117,7 @@ public class ProjectGenerationRequestTests {
|
||||
public void customLanguage() {
|
||||
this.request.setLanguage("groovy");
|
||||
assertEquals(createDefaultUrl("?type=test-type&language=groovy"),
|
||||
this.request.generateUrl(createDefaultMetadata()));
|
||||
this.request.generateUrl(createDefaultMetadata()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -127,8 +126,9 @@ public class ProjectGenerationRequestTests {
|
||||
this.request.setArtifactId("sample");
|
||||
this.request.setVersion("1.0.1-SNAPSHOT");
|
||||
this.request.setDescription("Spring Boot Test");
|
||||
assertEquals(createDefaultUrl("?groupId=org.acme&artifactId=sample&version=1.0.1-SNAPSHOT" +
|
||||
"&description=Spring+Boot+Test&type=test-type"),
|
||||
assertEquals(
|
||||
createDefaultUrl("?groupId=org.acme&artifactId=sample&version=1.0.1-SNAPSHOT"
|
||||
+ "&description=Spring+Boot+Test&type=test-type"),
|
||||
this.request.generateUrl(createDefaultMetadata()));
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,6 @@ public class CompositeDependencyManagementTests {
|
||||
public void unknownSpringBootVersion() {
|
||||
given(this.dependencyManagement1.getSpringBootVersion()).willReturn(null);
|
||||
given(this.dependencyManagement2.getSpringBootVersion()).willReturn(null);
|
||||
|
||||
assertThat(new CompositeDependencyManagement(this.dependencyManagement1,
|
||||
this.dependencyManagement2).getSpringBootVersion(), is(nullValue()));
|
||||
}
|
||||
@ -56,7 +55,6 @@ public class CompositeDependencyManagementTests {
|
||||
public void knownSpringBootVersion() {
|
||||
given(this.dependencyManagement1.getSpringBootVersion()).willReturn("1.2.3");
|
||||
given(this.dependencyManagement2.getSpringBootVersion()).willReturn("1.2.4");
|
||||
|
||||
assertThat(new CompositeDependencyManagement(this.dependencyManagement1,
|
||||
this.dependencyManagement2).getSpringBootVersion(), is("1.2.3"));
|
||||
}
|
||||
@ -65,7 +63,6 @@ public class CompositeDependencyManagementTests {
|
||||
public void unknownDependency() {
|
||||
given(this.dependencyManagement1.find("artifact")).willReturn(null);
|
||||
given(this.dependencyManagement2.find("artifact")).willReturn(null);
|
||||
|
||||
assertThat(new CompositeDependencyManagement(this.dependencyManagement1,
|
||||
this.dependencyManagement2).find("artifact"), is(nullValue()));
|
||||
}
|
||||
@ -76,7 +73,6 @@ public class CompositeDependencyManagementTests {
|
||||
new Dependency("test", "artifact", "1.2.3"));
|
||||
given(this.dependencyManagement2.find("artifact")).willReturn(
|
||||
new Dependency("test", "artifact", "1.2.4"));
|
||||
|
||||
assertThat(new CompositeDependencyManagement(this.dependencyManagement1,
|
||||
this.dependencyManagement2).find("artifact"), is(new Dependency("test",
|
||||
"artifact", "1.2.3")));
|
||||
@ -88,11 +84,11 @@ public class CompositeDependencyManagementTests {
|
||||
Arrays.asList(new Dependency("test", "artifact", "1.2.3")));
|
||||
given(this.dependencyManagement2.getDependencies()).willReturn(
|
||||
Arrays.asList(new Dependency("test", "artifact", "1.2.4")));
|
||||
|
||||
assertThat(
|
||||
new CompositeDependencyManagement(this.dependencyManagement1,
|
||||
this.dependencyManagement2).getDependencies(),
|
||||
contains(new Dependency("test", "artifact", "1.2.3"), new Dependency(
|
||||
"test", "artifact", "1.2.4")));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
* Copyright 2012-2015 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.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
* Copyright 2012-2015 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,11 +16,6 @@
|
||||
|
||||
package sample.ui.github;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrlPattern;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -35,6 +30,11 @@ import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrlPattern;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
|
||||
|
||||
/**
|
||||
* Basic integration tests for github sso application.
|
||||
*
|
||||
@ -47,20 +47,20 @@ import org.springframework.web.context.WebApplicationContext;
|
||||
public class SampleGithubApplicationTests {
|
||||
|
||||
@Autowired
|
||||
WebApplicationContext context;
|
||||
private WebApplicationContext context;
|
||||
|
||||
@Autowired
|
||||
FilterChainProxy filterChain;
|
||||
private FilterChainProxy filterChain;
|
||||
|
||||
@Autowired
|
||||
OAuth2ClientContextFilter filter;
|
||||
private OAuth2ClientContextFilter filter;
|
||||
|
||||
private MockMvc mvc;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.mvc = webAppContextSetup(this.context).addFilters(this.filter, this.filterChain)
|
||||
.build();
|
||||
this.mvc = webAppContextSetup(this.context).addFilters(this.filter,
|
||||
this.filterChain).build();
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
|
@ -43,8 +43,10 @@ public interface ConfigurableEmbeddedServletContainer {
|
||||
void setContextPath(String contextPath);
|
||||
|
||||
/**
|
||||
* Sets the display name of the application deployed in the embedded servlet container.
|
||||
* Sets the display name of the application deployed in the embedded servlet
|
||||
* container.
|
||||
* @param displayName the displayName to set
|
||||
* @since 1.3.0
|
||||
*/
|
||||
void setDisplayName(String displayName);
|
||||
|
||||
|
@ -388,7 +388,7 @@ public class UndertowEmbeddedServletContainerFactory extends
|
||||
}
|
||||
|
||||
private void createAccessLogDirectoryIfNecessary() {
|
||||
Assert.notNull(this.accessLogDirectory, "accesslogDirectory must not be null");
|
||||
Assert.state(this.accessLogDirectory != null, "Access log directory is not set");
|
||||
if (!this.accessLogDirectory.isDirectory() && !this.accessLogDirectory.mkdirs()) {
|
||||
throw new IllegalStateException("Failed to create access log directory '"
|
||||
+ this.accessLogDirectory + "'");
|
||||
|
@ -112,7 +112,6 @@ public abstract class SpringBootServletInitializer implements WebApplicationInit
|
||||
* Returns the {@code SpringApplicationBuilder} that is used to configure and create
|
||||
* the {@link SpringApplication}. The default implementation returns a new
|
||||
* {@code SpringApplicationBuilder} in its default state.
|
||||
*
|
||||
* @return the {@code SpringApplicationBuilder}.
|
||||
* @since 1.3.0
|
||||
*/
|
||||
|
@ -34,7 +34,6 @@ public abstract class JsonParserFactory {
|
||||
* Static factory for the "best" JSON parser available on the classpath. Tries Jackson
|
||||
* 2, then JSON (from eclipse), Simple JSON, Gson, Snake YAML, and then falls back to
|
||||
* the {@link BasicJsonParser}.
|
||||
*
|
||||
* @return a {@link JsonParser}
|
||||
*/
|
||||
public static JsonParser getJsonParser() {
|
||||
|
@ -164,11 +164,9 @@ public class Log4J2LoggingSystem extends Slf4JLoggingSystem {
|
||||
private ConfigurationSource getConfigurationSource(URL url) throws IOException {
|
||||
InputStream stream = url.openStream();
|
||||
if (ResourceUtils.isFileURL(url)) {
|
||||
return new ConfigurationSource(stream,
|
||||
ResourceUtils.getFile(url));
|
||||
} else {
|
||||
return new ConfigurationSource(stream, url);
|
||||
return new ConfigurationSource(stream, ResourceUtils.getFile(url));
|
||||
}
|
||||
return new ConfigurationSource(stream, url);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
* Copyright 2012-2015 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.
|
||||
@ -329,5 +329,7 @@ public class BindingPreparationTests {
|
||||
public void setFoo(String foo) {
|
||||
this.foo = foo;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,7 +33,6 @@ import org.springframework.mock.web.MockServletContext;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
@ -77,7 +76,7 @@ public class SpringBootServletInitializerTests {
|
||||
public void applicationBuilderCanBeCustomized() throws Exception {
|
||||
CustomSpringBootServletInitializer servletInitializer = new CustomSpringBootServletInitializer();
|
||||
servletInitializer.createRootApplicationContext(this.servletContext);
|
||||
assertThat(servletInitializer.applicationBuilder.built, is(true));
|
||||
assertThat(servletInitializer.applicationBuilder.built, equalTo(true));
|
||||
}
|
||||
|
||||
private Matcher<? super Set<Object>> equalToSet(Object... items) {
|
||||
|
@ -21,7 +21,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.core.config.Configuration;
|
||||
@ -30,12 +29,13 @@ import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.logging.AbstractLoggingSystemTests;
|
||||
import org.springframework.boot.logging.LogLevel;
|
||||
import org.springframework.boot.test.OutputCapture;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import static org.hamcrest.Matchers.arrayContaining;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
@ -183,7 +183,8 @@ public class Log4J2LoggingSystemTests extends AbstractLoggingSystemTests {
|
||||
}
|
||||
|
||||
public Configuration getConfiguration() {
|
||||
return ((org.apache.logging.log4j.core.LoggerContext) LogManager.getContext(false)).getConfiguration();
|
||||
return ((org.apache.logging.log4j.core.LoggerContext) LogManager
|
||||
.getContext(false)).getConfiguration();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
* Copyright 2012-2015 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,6 +37,8 @@ import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Abstract base class for {@code @Configuration} sanity checks.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public abstract class AbstractConfigurationClassTests {
|
||||
@ -56,7 +58,6 @@ public abstract class AbstractConfigurationClassTests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals("Found non-public @Bean methods: " + nonPublicBeanMethods, 0,
|
||||
nonPublicBeanMethods.size());
|
||||
}
|
||||
@ -65,7 +66,6 @@ public abstract class AbstractConfigurationClassTests {
|
||||
Set<AnnotationMetadata> configurationClasses = new HashSet<AnnotationMetadata>();
|
||||
Resource[] resources = this.resolver.getResources("classpath*:"
|
||||
+ getClass().getPackage().getName().replace(".", "/") + "/**/*.class");
|
||||
|
||||
for (Resource resource : resources) {
|
||||
if (!isTestClass(resource)) {
|
||||
MetadataReader metadataReader = new SimpleMetadataReaderFactory()
|
||||
@ -89,7 +89,6 @@ public abstract class AbstractConfigurationClassTests {
|
||||
private boolean isPublic(MethodMetadata methodMetadata) {
|
||||
int access = (Integer) new DirectFieldAccessor(methodMetadata)
|
||||
.getPropertyValue("access");
|
||||
|
||||
return (access & Opcodes.ACC_PUBLIC) != 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user