Merge branch '1.5.x'

This commit is contained in:
Phillip Webb 2016-10-11 23:42:14 -07:00
commit 01900c8342
25 changed files with 130 additions and 118 deletions

View File

@ -89,14 +89,13 @@ public class AutoConfigurationReportEndpoint extends AbstractEndpoint<Report> {
add(this.negativeMatches, entry.getKey(), entry.getValue());
}
}
this.parent = report.getParent() != null ? new Report(report.getParent())
: null;
boolean hasParent = report.getParent() != null;
this.parent = (hasParent ? new Report(report.getParent()) : null);
}
private void add(Map<String, MessageAndConditions> map, String source,
ConditionAndOutcomes conditionAndOutcomes) {
String name = ClassUtils.getShortName(source);
map.put(name, new MessageAndConditions(conditionAndOutcomes));
}

View File

@ -42,7 +42,8 @@ public abstract class AbstractDatabaseInitializer {
private final ResourceLoader resourceLoader;
protected AbstractDatabaseInitializer(DataSource dataSource, ResourceLoader resourceLoader) {
protected AbstractDatabaseInitializer(DataSource dataSource,
ResourceLoader resourceLoader) {
Assert.notNull(dataSource, "DataSource must not be null");
Assert.notNull(resourceLoader, "ResourceLoader must not be null");
this.dataSource = dataSource;
@ -51,17 +52,18 @@ public abstract class AbstractDatabaseInitializer {
@PostConstruct
protected void initialize() {
if (isEnabled()) {
ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
String schemaLocation = getSchemaLocation();
if (schemaLocation.contains(PLATFORM_PLACEHOLDER)) {
String platform = getDatabaseName();
schemaLocation = schemaLocation.replace(PLATFORM_PLACEHOLDER, platform);
}
populator.addScript(this.resourceLoader.getResource(schemaLocation));
populator.setContinueOnError(true);
DatabasePopulatorUtils.execute(populator, this.dataSource);
if (!isEnabled()) {
return;
}
ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
String schemaLocation = getSchemaLocation();
if (schemaLocation.contains(PLATFORM_PLACEHOLDER)) {
String platform = getDatabaseName();
schemaLocation = schemaLocation.replace(PLATFORM_PLACEHOLDER, platform);
}
populator.addScript(this.resourceLoader.getResource(schemaLocation));
populator.setContinueOnError(true);
DatabasePopulatorUtils.execute(populator, this.dataSource);
}
protected abstract boolean isEnabled();
@ -70,11 +72,10 @@ public abstract class AbstractDatabaseInitializer {
protected String getDatabaseName() {
try {
String databaseProductName = JdbcUtils.extractDatabaseMetaData(
this.dataSource, "getDatabaseProductName").toString();
databaseProductName = JdbcUtils.commonDatabaseName(databaseProductName);
DatabaseDriver databaseDriver = DatabaseDriver.fromProductName(
databaseProductName);
String productName = JdbcUtils.commonDatabaseName(JdbcUtils
.extractDatabaseMetaData(this.dataSource, "getDatabaseProductName")
.toString());
DatabaseDriver databaseDriver = DatabaseDriver.fromProductName(productName);
if (databaseDriver == DatabaseDriver.UNKNOWN) {
throw new IllegalStateException("Unable to detect database type");
}

View File

@ -32,8 +32,8 @@ public class BatchDatabaseInitializer extends AbstractDatabaseInitializer {
private final BatchProperties properties;
public BatchDatabaseInitializer(DataSource dataSource,
ResourceLoader resourceLoader, BatchProperties properties) {
public BatchDatabaseInitializer(DataSource dataSource, ResourceLoader resourceLoader,
BatchProperties properties) {
super(dataSource, resourceLoader);
Assert.notNull(properties, "BatchProperties must not be null");
this.properties = properties;

View File

@ -65,8 +65,7 @@ public class RepositoryRestProperties {
/**
* Strategy to use to determine which repositories get exposed.
*/
private RepositoryDetectionStrategies detectionStrategy =
RepositoryDetectionStrategies.DEFAULT;
private RepositoryDetectionStrategies detectionStrategy = RepositoryDetectionStrategies.DEFAULT;
/**
* Content type to use as a default when none is specified.

View File

@ -41,7 +41,7 @@ import org.springframework.jms.support.destination.DestinationResolver;
* @author Stephane Nicoll
*/
@Configuration
@ConditionalOnClass({Message.class, JmsTemplate.class})
@ConditionalOnClass({ Message.class, JmsTemplate.class })
@ConditionalOnBean(ConnectionFactory.class)
@EnableConfigurationProperties(JmsProperties.class)
@Import(JmsAnnotationDrivenConfiguration.class)

View File

@ -135,8 +135,8 @@ public class JmsProperties {
public static class Template {
/**
* Default destination to use on send/receive operations that do not
* have a destination parameter.
* Default destination to use on send/receive operations that do not have a
* destination parameter.
*/
private String defaultDestination;
@ -156,16 +156,14 @@ public class JmsProperties {
private Integer priority;
/**
* Time-to-live of a message when sending in milliseconds. Enable
* QoS when set.
* Time-to-live of a message when sending in milliseconds. Enable QoS when set.
*/
private Long timeToLive;
/**
* Enable explicit QoS when sending a message. When enabled, the
* delivery mode, priority and time-to-live properties will be
* used when sending a message. QoS is automatically enabled when
* at least one of those settings is customized.
* Enable explicit QoS when sending a message. When enabled, the delivery mode,
* priority and time-to-live properties will be used when sending a message. QoS
* is automatically enabled when at least one of those settings is customized.
*/
private Boolean qosEnabled;
@ -291,8 +289,8 @@ public class JmsProperties {
NON_PERSISTENT(1),
/*
* Instructs the JMS provider to log the message to stable storage as part of
* the client's send operation.
* Instructs the JMS provider to log the message to stable storage as part of the
* client's send operation.
*/
PERSISTENT(2);

View File

@ -658,15 +658,15 @@ public class ServerProperties
private Charset uriEncoding;
/**
* Maximum number of connections that the server will accept and process
* at any given time. Once the limit has been reached, the operating system
* may still accept connections based on the "acceptCount" property.
* Maximum number of connections that the server will accept and process at any
* given time. Once the limit has been reached, the operating system may still
* accept connections based on the "acceptCount" property.
*/
private int maxConnections = 0;
/**
* Maximum queue length for incoming connection requests when all possible
* request processing threads are in use.
* Maximum queue length for incoming connection requests when all possible request
* processing threads are in use.
*/
private int acceptCount = 0;
@ -827,34 +827,37 @@ public class ServerProperties
public void customize(Connector connector) {
ProtocolHandler handler = connector.getProtocolHandler();
if (handler instanceof AbstractProtocol) {
AbstractProtocol protocol = (AbstractProtocol) handler;
AbstractProtocol<?> protocol = (AbstractProtocol<?>) handler;
protocol.setBacklog(Tomcat.this.acceptCount);
}
}
});
}
private void customizeMaxConnections(TomcatEmbeddedServletContainerFactory factory) {
private void customizeMaxConnections(
TomcatEmbeddedServletContainerFactory factory) {
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
@Override
public void customize(Connector connector) {
ProtocolHandler handler = connector.getProtocolHandler();
if (handler instanceof AbstractProtocol) {
AbstractProtocol protocol = (AbstractProtocol) handler;
AbstractProtocol<?> protocol = (AbstractProtocol<?>) handler;
protocol.setMaxConnections(Tomcat.this.maxConnections);
}
}
});
}
private void customizeConnectionTimeout(
TomcatEmbeddedServletContainerFactory factory, int connectionTimeout) {
for (Connector connector : factory.getAdditionalTomcatConnectors()) {
if (connector.getProtocolHandler() instanceof AbstractProtocol) {
AbstractProtocol<?> handler = (AbstractProtocol<?>) connector
.getProtocolHandler();
handler.setConnectionTimeout(connectionTimeout);
ProtocolHandler handler = connector.getProtocolHandler();
if (handler instanceof AbstractProtocol) {
AbstractProtocol<?> protocol = (AbstractProtocol<?>) handler;
protocol.setConnectionTimeout(connectionTimeout);
}
}
}
@ -1108,6 +1111,7 @@ public class ServerProperties
JettyEmbeddedServletContainerFactory factory,
final int connectionTimeout) {
factory.addServerCustomizers(new JettyServerCustomizer() {
@Override
public void customize(Server server) {
for (org.eclipse.jetty.server.Connector connector : server
@ -1118,6 +1122,7 @@ public class ServerProperties
}
}
}
});
}

View File

@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.data.cassandra;
import java.util.Set;
import com.datastax.driver.core.Session;
import org.junit.After;
import org.junit.Test;

View File

@ -191,7 +191,8 @@ public class NoSuchBeanDefinitionFailureAnalyzerTests {
private void assertClassDisabled(FailureAnalysis analysis, String description,
String methodName) {
String expected = String.format("Bean method '%s' not loaded because", methodName);
String expected = String.format("Bean method '%s' not loaded because",
methodName);
assertThat(analysis.getDescription()).contains(expected);
assertThat(analysis.getDescription()).contains(description);
}

View File

@ -56,14 +56,13 @@ public class EmbeddedDataSourceConfigurationTests {
@Test
public void generateUniqueName() throws Exception {
this.context = load("spring.datasource.generate-unique-name=true");
AnnotationConfigApplicationContext context2 =
load("spring.datasource.generate-unique-name=true");
AnnotationConfigApplicationContext context2 = load(
"spring.datasource.generate-unique-name=true");
try {
DataSource dataSource = this.context.getBean(DataSource.class);
DataSource dataSource2 = context2.getBean(DataSource.class);
assertThat(getDatabaseName(dataSource))
.isNotEqualTo(getDatabaseName(dataSource2));
System.out.println(dataSource2);
}
finally {
context2.close();

View File

@ -259,8 +259,7 @@ public class JmsAutoConfigurationTests {
"spring.jms.template.default-destination=testQueue",
"spring.jms.template.delivery-delay=500",
"spring.jms.template.delivery-mode=non-persistent",
"spring.jms.template.priority=6",
"spring.jms.template.time-to-live=6000",
"spring.jms.template.priority=6", "spring.jms.template.time-to-live=6000",
"spring.jms.template.receive-timeout=2000");
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
assertThat(jmsTemplate.getMessageConverter())

View File

@ -444,9 +444,9 @@ public class ServerPropertiesTests {
TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory();
this.properties.customize(container);
TomcatEmbeddedServletContainer embeddedContainer =
(TomcatEmbeddedServletContainer) container.getEmbeddedServletContainer();
assertThat(((AbstractProtocol) embeddedContainer.getTomcat().getConnector()
TomcatEmbeddedServletContainer embeddedContainer = (TomcatEmbeddedServletContainer) container
.getEmbeddedServletContainer();
assertThat(((AbstractProtocol<?>) embeddedContainer.getTomcat().getConnector()
.getProtocolHandler()).getBacklog()).isEqualTo(10);
}
@ -458,9 +458,9 @@ public class ServerPropertiesTests {
TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory();
this.properties.customize(container);
TomcatEmbeddedServletContainer embeddedContainer =
(TomcatEmbeddedServletContainer) container.getEmbeddedServletContainer();
assertThat(((AbstractProtocol) embeddedContainer.getTomcat().getConnector()
TomcatEmbeddedServletContainer embeddedContainer = (TomcatEmbeddedServletContainer) container
.getEmbeddedServletContainer();
assertThat(((AbstractProtocol<?>) embeddedContainer.getTomcat().getConnector()
.getProtocolHandler()).getMaxConnections()).isEqualTo(5);
}

View File

@ -56,8 +56,7 @@ public class WarCommandIT {
assertThat(invocation.getOutput()).contains("Tomcat started");
assertThat(invocation.getOutput())
.contains("/WEB-INF/lib-provided/tomcat-embed-core");
assertThat(invocation.getOutput())
.contains("WEB-INF/classes!/root.properties");
assertThat(invocation.getOutput()).contains("WEB-INF/classes!/root.properties");
process.destroy();
}

View File

@ -289,10 +289,9 @@ abstract class ArchiveCommand extends OptionParsingCommand {
return libraries;
}
protected void writeClasspathEntry(JarWriter writer,
MatchedResource entry) throws IOException {
writer.writeEntry(entry.getName(),
new FileInputStream(entry.getFile()));
protected void writeClasspathEntry(JarWriter writer, MatchedResource entry)
throws IOException {
writer.writeEntry(entry.getName(), new FileInputStream(entry.getFile()));
}
protected abstract LibraryScope getLibraryScope(File file);

View File

@ -18,7 +18,6 @@ package sample.hibernate52.service;
import org.junit.Test;
import org.junit.runner.RunWith;
import sample.hibernate52.domain.City;
import sample.hibernate52.service.CityRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

View File

@ -24,8 +24,6 @@ import sample.hibernate52.domain.Hotel;
import sample.hibernate52.domain.HotelSummary;
import sample.hibernate52.domain.Rating;
import sample.hibernate52.domain.RatingCount;
import sample.hibernate52.service.CityRepository;
import sample.hibernate52.service.HotelRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

View File

@ -23,7 +23,6 @@ import org.hamcrest.TypeSafeMatcher;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import sample.web.thymeleaf3.SampleWebThymeleaf3Application;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;

View File

@ -478,8 +478,11 @@ public class MockitoPostProcessor extends InstantiationAwareBeanPostProcessorAda
}
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName)
public Object postProcessAfterInitialization(Object bean, String beanName)
throws BeansException {
if (bean instanceof FactoryBean) {
return bean;
}
return createSpyIfNecessary(bean, beanName);
}

View File

@ -42,7 +42,6 @@ import org.springframework.boot.configurationsample.lombok.LombokInnerClassPrope
import org.springframework.boot.configurationsample.lombok.LombokSimpleDataProperties;
import org.springframework.boot.configurationsample.lombok.LombokSimpleProperties;
import org.springframework.boot.configurationsample.lombok.SimpleLombokPojo;
import org.springframework.boot.configurationsample.method.DeprecatedClassMethodConfig;
import org.springframework.boot.configurationsample.method.DeprecatedMethodConfig;
import org.springframework.boot.configurationsample.method.EmptyTypeMethodConfig;
import org.springframework.boot.configurationsample.method.InvalidMethodConfig;
@ -290,8 +289,7 @@ public class ConfigurationMetadataAnnotationProcessorTests {
public void deprecatedMethodConfig() throws Exception {
Class<DeprecatedMethodConfig> type = DeprecatedMethodConfig.class;
ConfigurationMetadata metadata = compile(type);
assertThat(metadata)
.has(Metadata.withGroup("foo").fromSource(type));
assertThat(metadata).has(Metadata.withGroup("foo").fromSource(type));
assertThat(metadata).has(Metadata.withProperty("foo.name", String.class)
.fromSource(DeprecatedMethodConfig.Foo.class)
.withDeprecation(null, null));
@ -301,16 +299,18 @@ public class ConfigurationMetadataAnnotationProcessorTests {
}
@Test
@SuppressWarnings("deprecation")
public void deprecatedMethodConfigOnClass() throws Exception {
Class<DeprecatedClassMethodConfig> type = DeprecatedClassMethodConfig.class;
Class<?> type = org.springframework.boot.configurationsample.method.DeprecatedClassMethodConfig.class;
ConfigurationMetadata metadata = compile(type);
assertThat(metadata)
.has(Metadata.withGroup("foo").fromSource(type));
assertThat(metadata).has(Metadata.withGroup("foo").fromSource(type));
assertThat(metadata).has(Metadata.withProperty("foo.name", String.class)
.fromSource(DeprecatedClassMethodConfig.Foo.class)
.fromSource(
org.springframework.boot.configurationsample.method.DeprecatedClassMethodConfig.Foo.class)
.withDeprecation(null, null));
assertThat(metadata).has(Metadata.withProperty("foo.flag", Boolean.class)
.fromSource(DeprecatedClassMethodConfig.Foo.class)
.fromSource(
org.springframework.boot.configurationsample.method.DeprecatedClassMethodConfig.Foo.class)
.withDeprecation(null, null));
}

View File

@ -52,6 +52,7 @@ public class DeprecatedClassMethodConfig {
public void setFlag(boolean flag) {
this.flag = flag;
}
}
}

View File

@ -51,8 +51,16 @@ public class RunProcess {
private volatile long endTime;
/**
* Creates new {@link RunProcess} instance for the specified command
* and working directory.
* Creates new {@link RunProcess} instance for the specified command.
* @param command the program to execute and it's arguments
*/
public RunProcess(String... command) {
this(null, command);
}
/**
* Creates new {@link RunProcess} instance for the specified working directory and
* command.
* @param workingDirectory the working directory of the child process or {@code null}
* to run in the working directory of the current Java process
* @param command the program to execute and it's arguments
@ -62,14 +70,6 @@ public class RunProcess {
this.command = command;
}
/**
* Creates new {@link RunProcess} instance for the specified command.
* @param command the program to execute and it's arguments
*/
public RunProcess(String... command) {
this(null, command);
}
public int run(boolean waitForProcess, String... args) throws IOException {
return run(waitForProcess, Arrays.asList(args));
}

View File

@ -149,8 +149,8 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
/**
* Flag to indicate if the run processes should be forked. {@code fork} is
* automatically enabled if an agent, jvmArguments or working directory are
* specified, or if devtools is present.
* automatically enabled if an agent, jvmArguments or working directory are specified,
* or if devtools is present.
* @since 1.2
*/
@Parameter(property = "fork")
@ -206,7 +206,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
}
private boolean hasWorkingDirectorySet() {
return (this.workingDirectory != null);
return this.workingDirectory != null;
}
private void findAgent() {

View File

@ -64,9 +64,11 @@ public class RunMojo extends AbstractRunMojo {
}
@Override
protected void runWithForkedJvm(File workingDirectory, List<String> args) throws MojoExecutionException {
protected void runWithForkedJvm(File workingDirectory, List<String> args)
throws MojoExecutionException {
try {
RunProcess runProcess = new RunProcess(workingDirectory, new JavaExecutable().toString());
RunProcess runProcess = new RunProcess(workingDirectory,
new JavaExecutable().toString());
Runtime.getRuntime()
.addShutdownHook(new Thread(new RunProcessKiller(runProcess)));
int exitCode = runProcess.run(true, args.toArray(new String[args.size()]));

View File

@ -30,9 +30,9 @@ import org.springframework.context.annotation.Configuration;
* standard {@code @Configuration} annotation so that configuration can be found
* automatically (for example in tests).
* <p>
* Application should only ever include <em>one</em>
* {@code @SpringBootConfiguration} and most idiomatic Spring Boot applications
* will inherit it from {@code @SpringBootApplication}.
* Application should only ever include <em>one</em> {@code @SpringBootConfiguration} and
* most idiomatic Spring Boot applications will inherit it from
* {@code @SpringBootApplication}.
*
* @author Phillip Webb
* @since 1.4.0

View File

@ -39,40 +39,42 @@ class BeanCurrentlyInCreationFailureAnalyzer
@Override
protected FailureAnalysis analyze(Throwable rootFailure,
BeanCurrentlyInCreationException cause) {
List<BeanInCycle> beansInCycle = new ArrayList<BeanInCycle>();
List<BeanInCycle> cycle = new ArrayList<BeanInCycle>();
Throwable candidate = rootFailure;
int cycleStart = -1;
while (candidate != null) {
if (candidate instanceof BeanCreationException) {
BeanCreationException creationEx = (BeanCreationException) candidate;
if (StringUtils.hasText(creationEx.getBeanName())) {
BeanInCycle beanInCycle = new BeanInCycle(creationEx);
int index = beansInCycle.indexOf(beanInCycle);
if (index == -1) {
beansInCycle.add(beanInCycle);
}
else {
cycleStart = index;
}
BeanInCycle beanInCycle = BeanInCycle.get(candidate);
if (beanInCycle != null) {
int index = cycle.indexOf(beanInCycle);
if (index == -1) {
cycle.add(beanInCycle);
}
cycleStart = (cycleStart == -1 ? index : cycleStart);
}
candidate = candidate.getCause();
}
String message = buildMessage(cycle, cycleStart);
return new FailureAnalysis(message, null, cause);
}
private String buildMessage(List<BeanInCycle> beansInCycle, int cycleStart) {
StringBuilder message = new StringBuilder();
message.append(String.format("The dependencies of some of the beans in the "
+ "application context form a cycle:%n%n"));
for (int i = 0; i < beansInCycle.size(); i++) {
BeanInCycle beanInCycle = beansInCycle.get(i);
if (i == cycleStart) {
message.append(String.format("┌─────┐%n"));
}
else if (i > 0) {
message.append(String.format("%s ↓%n", i < cycleStart ? " " : ""));
String leftSide = (i < cycleStart ? " " : "");
message.append(String.format("%s ↓%n", leftSide));
}
message.append(String.format("%s %s%n", i < cycleStart ? " " : "|",
beansInCycle.get(i)));
String leftSide = i < cycleStart ? " " : "|";
message.append(String.format("%s %s%n", leftSide, beanInCycle));
}
message.append(String.format("└─────┘%n"));
return new FailureAnalysis(message.toString(), null, cause);
return message.toString();
}
private static final class BeanInCycle {
@ -114,14 +116,10 @@ class BeanCurrentlyInCreationFailureAnalyzer
if (this == obj) {
return true;
}
if (obj == null) {
if (obj == null || getClass() != obj.getClass()) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
BeanInCycle other = (BeanInCycle) obj;
return this.name.equals(other.name);
return this.name.equals(((BeanInCycle) obj).name);
}
@Override
@ -129,6 +127,20 @@ class BeanCurrentlyInCreationFailureAnalyzer
return this.name + this.description;
}
public static BeanInCycle get(Throwable ex) {
if (ex instanceof BeanCreationException) {
return get((BeanCreationException) ex);
}
return null;
}
private static BeanInCycle get(BeanCreationException ex) {
if (StringUtils.hasText(ex.getBeanName())) {
return new BeanInCycle(ex);
}
return null;
}
}
}