Browse Source

Polish

pull/13050/head
Andy Wilkinson 8 years ago
parent
commit
06cf698387
  1. 21
      spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/BeanTypeRegistry.java
  2. 19
      spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java
  3. 6
      spring-boot-devtools/src/main/java/org/springframework/boot/devtools/livereload/Connection.java
  4. 3
      spring-boot-test/src/test/java/org/springframework/boot/test/json/JsonContentTests.java
  5. 4
      spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainer.java
  6. 5
      spring-boot/src/main/java/org/springframework/boot/env/PropertySourcesLoader.java

21
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/BeanTypeRegistry.java

@ -167,7 +167,7 @@ final class BeanTypeRegistry implements SmartInitializingSingleton {
&& !requiresEagerInit(beanDefinition.getFactoryBeanName())) { && !requiresEagerInit(beanDefinition.getFactoryBeanName())) {
if (this.beanFactory.isFactoryBean(factoryName)) { if (this.beanFactory.isFactoryBean(factoryName)) {
Class<?> factoryBeanGeneric = getFactoryBeanGeneric(this.beanFactory, Class<?> factoryBeanGeneric = getFactoryBeanGeneric(this.beanFactory,
beanDefinition, name); beanDefinition);
this.beanTypes.put(name, factoryBeanGeneric); this.beanTypes.put(name, factoryBeanGeneric);
this.beanTypes.put(factoryName, this.beanTypes.put(factoryName,
this.beanFactory.getType(factoryName)); this.beanFactory.getType(factoryName));
@ -216,13 +216,12 @@ final class BeanTypeRegistry implements SmartInitializingSingleton {
* generics in its method signature. * generics in its method signature.
* @param beanFactory the source bean factory * @param beanFactory the source bean factory
* @param definition the bean definition * @param definition the bean definition
* @param name the name of the bean
* @return the generic type of the {@link FactoryBean} or {@code null} * @return the generic type of the {@link FactoryBean} or {@code null}
*/ */
private Class<?> getFactoryBeanGeneric(ConfigurableListableBeanFactory beanFactory, private Class<?> getFactoryBeanGeneric(ConfigurableListableBeanFactory beanFactory,
BeanDefinition definition, String name) { BeanDefinition definition) {
try { try {
return doGetFactoryBeanGeneric(beanFactory, definition, name); return doGetFactoryBeanGeneric(beanFactory, definition);
} }
catch (Exception ex) { catch (Exception ex) {
return null; return null;
@ -230,21 +229,21 @@ final class BeanTypeRegistry implements SmartInitializingSingleton {
} }
private Class<?> doGetFactoryBeanGeneric(ConfigurableListableBeanFactory beanFactory, private Class<?> doGetFactoryBeanGeneric(ConfigurableListableBeanFactory beanFactory,
BeanDefinition definition, String name) BeanDefinition definition)
throws Exception, ClassNotFoundException, LinkageError { throws Exception, ClassNotFoundException, LinkageError {
if (StringUtils.hasLength(definition.getFactoryBeanName()) if (StringUtils.hasLength(definition.getFactoryBeanName())
&& StringUtils.hasLength(definition.getFactoryMethodName())) { && StringUtils.hasLength(definition.getFactoryMethodName())) {
return getConfigurationClassFactoryBeanGeneric(beanFactory, definition, name); return getConfigurationClassFactoryBeanGeneric(beanFactory, definition);
} }
if (StringUtils.hasLength(definition.getBeanClassName())) { if (StringUtils.hasLength(definition.getBeanClassName())) {
return getDirectFactoryBeanGeneric(beanFactory, definition, name); return getDirectFactoryBeanGeneric(beanFactory, definition);
} }
return null; return null;
} }
private Class<?> getConfigurationClassFactoryBeanGeneric( private Class<?> getConfigurationClassFactoryBeanGeneric(
ConfigurableListableBeanFactory beanFactory, BeanDefinition definition, ConfigurableListableBeanFactory beanFactory, BeanDefinition definition)
String name) throws Exception { throws Exception {
Method method = getFactoryMethod(beanFactory, definition); Method method = getFactoryMethod(beanFactory, definition);
Class<?> generic = ResolvableType.forMethodReturnType(method) Class<?> generic = ResolvableType.forMethodReturnType(method)
.as(FactoryBean.class).resolveGeneric(); .as(FactoryBean.class).resolveGeneric();
@ -305,8 +304,8 @@ final class BeanTypeRegistry implements SmartInitializingSingleton {
} }
private Class<?> getDirectFactoryBeanGeneric( private Class<?> getDirectFactoryBeanGeneric(
ConfigurableListableBeanFactory beanFactory, BeanDefinition definition, ConfigurableListableBeanFactory beanFactory, BeanDefinition definition)
String name) throws ClassNotFoundException, LinkageError { throws ClassNotFoundException, LinkageError {
Class<?> factoryBeanClass = ClassUtils.forName(definition.getBeanClassName(), Class<?> factoryBeanClass = ClassUtils.forName(definition.getBeanClassName(),
beanFactory.getBeanClassLoader()); beanFactory.getBeanClassLoader());
Class<?> generic = ResolvableType.forClass(factoryBeanClass).as(FactoryBean.class) Class<?> generic = ResolvableType.forClass(factoryBeanClass).as(FactoryBean.class)

19
spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,7 +20,7 @@ import java.io.File;
import java.net.URL; import java.net.URL;
import java.util.List; import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@ -62,12 +62,16 @@ public class LocalDevToolsAutoConfiguration {
@ConditionalOnProperty(prefix = "spring.devtools.livereload", name = "enabled", matchIfMissing = true) @ConditionalOnProperty(prefix = "spring.devtools.livereload", name = "enabled", matchIfMissing = true)
static class LiveReloadConfiguration { static class LiveReloadConfiguration {
@Autowired
private DevToolsProperties properties; private DevToolsProperties properties;
@Autowired(required = false)
private LiveReloadServer liveReloadServer; private LiveReloadServer liveReloadServer;
LiveReloadConfiguration(DevToolsProperties properties,
ObjectProvider<LiveReloadServer> liveReloadServer) {
this.properties = properties;
this.liveReloadServer = liveReloadServer.getIfAvailable();
}
@Bean @Bean
@RestartScope @RestartScope
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ -102,8 +106,11 @@ public class LocalDevToolsAutoConfiguration {
@ConditionalOnProperty(prefix = "spring.devtools.restart", name = "enabled", matchIfMissing = true) @ConditionalOnProperty(prefix = "spring.devtools.restart", name = "enabled", matchIfMissing = true)
static class RestartConfiguration { static class RestartConfiguration {
@Autowired private final DevToolsProperties properties;
private DevToolsProperties properties;
RestartConfiguration(DevToolsProperties properties) {
this.properties = properties;
}
@EventListener @EventListener
public void onClassPathChanged(ClassPathChangedEvent event) { public void onClassPathChanged(ClassPathChangedEvent event) {

6
spring-boot-devtools/src/main/java/org/springframework/boot/devtools/livereload/Connection.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -80,7 +80,7 @@ class Connection {
public void run() throws Exception { public void run() throws Exception {
if (this.header.contains("Upgrade: websocket") if (this.header.contains("Upgrade: websocket")
&& this.header.contains("Sec-WebSocket-Version: 13")) { && this.header.contains("Sec-WebSocket-Version: 13")) {
runWebSocket(this.header); runWebSocket();
} }
if (this.header.contains("GET /livereload.js")) { if (this.header.contains("GET /livereload.js")) {
this.outputStream.writeHttp(getClass().getResourceAsStream("livereload.js"), this.outputStream.writeHttp(getClass().getResourceAsStream("livereload.js"),
@ -88,7 +88,7 @@ class Connection {
} }
} }
private void runWebSocket(String header) throws Exception { private void runWebSocket() throws Exception {
String accept = getWebsocketAcceptResponse(); String accept = getWebsocketAcceptResponse();
this.outputStream.writeHeaders("HTTP/1.1 101 Switching Protocols", this.outputStream.writeHeaders("HTTP/1.1 101 Switching Protocols",
"Upgrade: websocket", "Connection: Upgrade", "Upgrade: websocket", "Connection: Upgrade",

3
spring-boot-test/src/test/java/org/springframework/boot/test/json/JsonContentTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -60,6 +60,7 @@ public class JsonContentTests {
assertThat(content).isNotNull(); assertThat(content).isNotNull();
} }
@SuppressWarnings("deprecation")
@Test @Test
public void assertThatShouldReturnJsonContentAssert() throws Exception { public void assertThatShouldReturnJsonContentAssert() throws Exception {
JsonContent<ExampleObject> content = new JsonContent<ExampleObject>(getClass(), JsonContent<ExampleObject> content = new JsonContent<ExampleObject>(getClass(),

4
spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainer.java

@ -208,7 +208,7 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
addPreviouslyRemovedConnectors(); addPreviouslyRemovedConnectors();
Connector connector = this.tomcat.getConnector(); Connector connector = this.tomcat.getConnector();
if (connector != null && this.autoStart) { if (connector != null && this.autoStart) {
startConnector(connector); performDeferredLoadOnStartup();
} }
checkThatConnectorsHaveStarted(); checkThatConnectorsHaveStarted();
this.started = true; this.started = true;
@ -281,7 +281,7 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
} }
} }
private void startConnector(Connector connector) { private void performDeferredLoadOnStartup() {
try { try {
for (Container child : this.tomcat.getHost().findChildren()) { for (Container child : this.tomcat.getHost().findChildren()) {
if (child instanceof TomcatEmbeddedContext) { if (child instanceof TomcatEmbeddedContext) {

5
spring-boot/src/main/java/org/springframework/boot/env/PropertySourcesLoader.java vendored

@ -127,7 +127,7 @@ public class PropertySourcesLoader {
if (canLoadFileExtension(loader, resource)) { if (canLoadFileExtension(loader, resource)) {
PropertySource<?> specific = loader.load(sourceName, resource, PropertySource<?> specific = loader.load(sourceName, resource,
profile); profile);
addPropertySource(group, specific, profile); addPropertySource(group, specific);
return specific; return specific;
} }
} }
@ -154,8 +154,7 @@ public class PropertySourcesLoader {
return false; return false;
} }
private void addPropertySource(String basename, PropertySource<?> source, private void addPropertySource(String basename, PropertySource<?> source) {
String profile) {
if (source == null) { if (source == null) {
return; return;

Loading…
Cancel
Save