Skip to content

Commit f8bf0e2

Browse files
author
Phillip Webb
committed
Polish
1 parent 5e1552b commit f8bf0e2

File tree

14 files changed

+114
-93
lines changed

14 files changed

+114
-93
lines changed

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpoint.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
/**
3333
* Adapter to expose {@link HealthEndpoint} as an {@link MvcEndpoint}.
34-
*
34+
*
3535
* @author Christian Dupuis
3636
* @since 1.1.0
3737
*/

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/MongoHealthIndicator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/**
2525
* Simple implementation of a {@link HealthIndicator} returning status information for
2626
* Mongo data stores.
27-
*
27+
*
2828
* @author Christian Dupuis
2929
* @since 1.1.0
3030
*/

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfiguration.java

+18-16
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
@ConfigurationProperties(prefix = "spring.messages")
5454
public class MessageSourceAutoConfiguration {
5555

56+
private static final Resource[] NO_RESOURCES = {};
57+
5658
private String basename = "messages";
5759

5860
private String encoding = "utf-8";
@@ -103,27 +105,27 @@ public ConditionOutcome getMatchOutcome(ConditionContext context,
103105
String basename = context.getEnvironment().getProperty(
104106
"spring.messages.basename", "messages");
105107
for (String name : commaDelimitedListToStringArray(trimAllWhitespace(basename))) {
106-
Resource[] resources;
107-
try {
108-
resources = new PathMatchingResourcePatternResolver(
109-
context.getClassLoader()).getResources("classpath*:" + name
110-
+ "*.properties");
111-
}
112-
catch (IOException e) {
113-
continue;
114-
}
115-
for (Resource resource : resources) {
116-
108+
for (Resource resource : getResources(context.getClassLoader(), name)) {
117109
if (resource.exists()) {
118-
return ConditionOutcome
119-
.match("Bundle found for spring.messages.basename: "
120-
+ name);
110+
return ConditionOutcome.match("Bundle found for "
111+
+ "spring.messages.basename: " + name);
121112
}
122113
}
123114
}
124-
return ConditionOutcome
125-
.noMatch("No bundle found for spring.messages.basename: " + basename);
115+
return ConditionOutcome.noMatch("No bundle found for "
116+
+ "spring.messages.basename: " + basename);
126117
}
118+
119+
private Resource[] getResources(ClassLoader classLoader, String name) {
120+
try {
121+
return new PathMatchingResourcePatternResolver(classLoader)
122+
.getResources("classpath*:" + name + "*.properties");
123+
}
124+
catch (IOException ex) {
125+
return NO_RESOURCES;
126+
}
127+
}
128+
127129
}
128130

129131
}

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ private String parseAddresses(String addresses) {
107107
}
108108
result.add(address);
109109
}
110-
return result.isEmpty() ? null : StringUtils.collectionToCommaDelimitedString(result);
110+
return (result.isEmpty() ? null : StringUtils
111+
.collectionToCommaDelimitedString(result));
111112
}
112113

113114
public void setPort(int port) {

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpMessageConverters.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,8 @@ public HttpMessageConverters(Collection<HttpMessageConverter<?>> additionalConve
9393

9494
private List<HttpMessageConverter<?>> getDefaultConverters() {
9595
List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
96-
if (ClassUtils
97-
.isPresent(
98-
"org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport",
99-
null)) {
96+
if (ClassUtils.isPresent("org.springframework.web.servlet.config.annotation."
97+
+ "WebMvcConfigurationSupport", null)) {
10098
converters.addAll(new WebMvcConfigurationSupport() {
10199
public List<HttpMessageConverter<?>> defaultMessageConverters() {
102100
return super.getMessageConverters();

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpMessageConvertersAutoConfiguration.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.boot.autoconfigure.web;
1818

19-
import java.util.ArrayList;
2019
import java.util.Collections;
2120
import java.util.List;
2221

@@ -53,9 +52,7 @@ public class HttpMessageConvertersAutoConfiguration {
5352
@Bean
5453
@ConditionalOnMissingBean
5554
public HttpMessageConverters messageConverters() {
56-
List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>(
57-
this.converters);
58-
return new HttpMessageConverters(converters);
55+
return new HttpMessageConverters(this.converters);
5956
}
6057

6158
@Configuration

spring-boot-cli/samples/http.groovy

+1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ class Example implements CommandLineRunner {
2020
def world = new RESTClient("http://localhost:" + port).get(path:"/").data.text
2121
print "Hello " + world
2222
}
23+
2324
}

spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

-1
Original file line numberDiff line numberDiff line change
@@ -2004,7 +2004,6 @@ the actual port that was allocated for the duration of the tests.
20042004

20052005
[[boot-features-testing-spring-boot-applications-with-spock]]
20062006
==== Using Spock to test Spring Boot applications
2007-
20082007
If you wish to use Spock to test a Spring Boot application you should add a dependency
20092008
on Spock's `spock-spring` module to your application's build. `spock-spring` integrates
20102009
Spring's test framework into Spock.

spring-boot/src/main/java/org/springframework/boot/bind/PropertySourcesPropertyValues.java

+55-38
Original file line numberDiff line numberDiff line change
@@ -72,65 +72,67 @@ public PropertySourcesPropertyValues(PropertySources propertySources,
7272
this.propertySources = propertySources;
7373
PropertySourcesPropertyResolver resolver = new PropertySourcesPropertyResolver(
7474
propertySources);
75-
String[] includes = patterns == null ? new String[0] : patterns
76-
.toArray(new String[0]);
77-
String[] exacts = names == null ? new String[0] : names.toArray(new String[0]);
75+
String[] includes = toArray(patterns);
76+
String[] exacts = toArray(names);
7877
for (PropertySource<?> source : propertySources) {
7978
processPropertySource(source, resolver, includes, exacts);
8079
}
8180
}
8281

82+
private String[] toArray(Collection<String> strings) {
83+
if (strings == null) {
84+
return new String[0];
85+
}
86+
return strings.toArray(new String[strings.size()]);
87+
}
88+
8389
private void processPropertySource(PropertySource<?> source,
8490
PropertySourcesPropertyResolver resolver, String[] includes, String[] exacts) {
8591
if (source instanceof EnumerablePropertySource) {
86-
EnumerablePropertySource<?> enumerable = (EnumerablePropertySource<?>) source;
87-
if (enumerable.getPropertyNames().length > 0) {
88-
for (String propertyName : enumerable.getPropertyNames()) {
89-
if (this.NON_ENUMERABLE_ENUMERABLES.contains(source.getName())
90-
&& !PatternMatchUtils.simpleMatch(includes, propertyName)) {
91-
continue;
92-
}
93-
Object value = source.getProperty(propertyName);
94-
try {
95-
value = resolver.getProperty(propertyName);
96-
}
97-
catch (RuntimeException ex) {
98-
// Probably could not resolve placeholders, ignore it here
99-
}
100-
if (!this.propertyValues.containsKey(propertyName)) {
101-
this.propertyValues.put(propertyName, new PropertyValue(
102-
propertyName, value));
103-
}
104-
}
105-
}
92+
processEnumerablePropertySource((EnumerablePropertySource<?>) source,
93+
resolver, includes, exacts);
10694
}
10795
else if (source instanceof CompositePropertySource) {
108-
CompositePropertySource composite = (CompositePropertySource) source;
109-
for (PropertySource<?> nested : extractSources(composite)) {
110-
processPropertySource(nested, resolver, includes, exacts);
111-
}
96+
processCompositePropertySource((CompositePropertySource) source, resolver,
97+
includes, exacts);
11298
}
11399
else {
114100
// We can only do exact matches for non-enumerable property names, but
115101
// that's better than nothing...
116-
for (String propertyName : exacts) {
117-
Object value;
118-
value = resolver.getProperty(propertyName);
119-
if (value != null && !this.propertyValues.containsKey(propertyName)) {
120-
this.propertyValues.put(propertyName, new PropertyValue(propertyName,
121-
value));
102+
processDefaultPropertySource(source, resolver, includes, exacts);
103+
}
104+
}
105+
106+
private void processEnumerablePropertySource(EnumerablePropertySource<?> source,
107+
PropertySourcesPropertyResolver resolver, String[] includes, String[] exacts) {
108+
if (source.getPropertyNames().length > 0) {
109+
for (String propertyName : source.getPropertyNames()) {
110+
if (this.NON_ENUMERABLE_ENUMERABLES.contains(source.getName())
111+
&& !PatternMatchUtils.simpleMatch(includes, propertyName)) {
122112
continue;
123113
}
124-
value = source.getProperty(propertyName.toUpperCase());
125-
if (value != null && !this.propertyValues.containsKey(propertyName)) {
114+
Object value = source.getProperty(propertyName);
115+
try {
116+
value = resolver.getProperty(propertyName);
117+
}
118+
catch (RuntimeException ex) {
119+
// Probably could not resolve placeholders, ignore it here
120+
}
121+
if (!this.propertyValues.containsKey(propertyName)) {
126122
this.propertyValues.put(propertyName, new PropertyValue(propertyName,
127123
value));
128-
continue;
129124
}
130125
}
131126
}
132127
}
133128

129+
private void processCompositePropertySource(CompositePropertySource source,
130+
PropertySourcesPropertyResolver resolver, String[] includes, String[] exacts) {
131+
for (PropertySource<?> nested : extractSources(source)) {
132+
processPropertySource(nested, resolver, includes, exacts);
133+
}
134+
}
135+
134136
private Collection<PropertySource<?>> extractSources(CompositePropertySource composite) {
135137
Field field = ReflectionUtils.findField(CompositePropertySource.class,
136138
"propertySources");
@@ -141,9 +143,24 @@ private Collection<PropertySource<?>> extractSources(CompositePropertySource com
141143
.get(composite);
142144
return collection;
143145
}
144-
catch (Exception e) {
146+
catch (Exception ex) {
145147
throw new IllegalStateException(
146-
"Cannot extract property sources from composite", e);
148+
"Cannot extract property sources from composite", ex);
149+
}
150+
}
151+
152+
private void processDefaultPropertySource(PropertySource<?> source,
153+
PropertySourcesPropertyResolver resolver, String[] includes, String[] exacts) {
154+
for (String propertyName : exacts) {
155+
Object value = resolver.getProperty(propertyName);
156+
if (value == null) {
157+
value = source.getProperty(propertyName.toUpperCase());
158+
}
159+
if (value != null && !this.propertyValues.containsKey(propertyName)) {
160+
this.propertyValues.put(propertyName, new PropertyValue(propertyName,
161+
value));
162+
continue;
163+
}
147164
}
148165
}
149166

spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainer.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,21 @@ private synchronized void initialize() {
7676
this.server.start();
7777
}
7878
catch (Exception ex) {
79-
try {
80-
// Ensure process isn't left running
81-
this.server.stop();
82-
}
83-
catch (Exception e) {
84-
}
79+
// Ensure process isn't left running
80+
stopSilently();
8581
throw new EmbeddedServletContainerException(
8682
"Unable to start embedded Jetty servlet container", ex);
8783
}
8884
}
8985

86+
private void stopSilently() {
87+
try {
88+
this.server.stop();
89+
}
90+
catch (Exception ex) {
91+
}
92+
}
93+
9094
@Override
9195
public void start() throws EmbeddedServletContainerException {
9296
this.server.setConnectors(this.connectors);

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

+9-6
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ private synchronized void initialize() throws EmbeddedServletContainerException
9595
this.tomcat.stop();
9696
throw new IllegalStateException("Tomcat connector in failed state");
9797
}
98-
9998
}
10099
catch (Exception ex) {
101100
throw new EmbeddedServletContainerException(
@@ -154,15 +153,19 @@ public void start() throws EmbeddedServletContainerException {
154153
}
155154
// Ensure process isn't left running if it actually failed to start
156155
if (LifecycleState.FAILED.equals(this.tomcat.getConnector().getState())) {
157-
try {
158-
this.tomcat.stop();
159-
}
160-
catch (LifecycleException e) {
161-
}
156+
stopSilently();
162157
throw new IllegalStateException("Tomcat connector in failed state");
163158
}
164159
}
165160

161+
private void stopSilently() {
162+
try {
163+
this.tomcat.stop();
164+
}
165+
catch (LifecycleException ex) {
166+
}
167+
}
168+
166169
private void addPreviouslyRemovedConnectors() {
167170
Service[] services = this.tomcat.getServer().findServices();
168171
for (Service service : services) {

spring-boot/src/main/java/org/springframework/boot/context/web/ErrorPageFilter.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -77,28 +77,27 @@ class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContainer imple
7777
private final Map<Class<?>, String> exceptions = new HashMap<Class<?>, String>();
7878

7979
private final Map<Class<?>, Class<?>> subtypes = new HashMap<Class<?>, Class<?>>();
80-
81-
private final OncePerRequestFilter delegate = new OncePerRequestFilter(
82-
) {
83-
80+
81+
private final OncePerRequestFilter delegate = new OncePerRequestFilter() {
82+
8483
@Override
8584
protected void doFilterInternal(HttpServletRequest request,
86-
HttpServletResponse response, FilterChain chain)
87-
throws ServletException, IOException {
85+
HttpServletResponse response, FilterChain chain) throws ServletException,
86+
IOException {
8887
ErrorPageFilter.this.doFilter(request, response, chain);
8988
}
9089

9190
};
9291

9392
@Override
9493
public void init(FilterConfig filterConfig) throws ServletException {
95-
delegate.init(filterConfig);
94+
this.delegate.init(filterConfig);
9695
}
9796

9897
@Override
9998
public void doFilter(ServletRequest request, ServletResponse response,
10099
FilterChain chain) throws IOException, ServletException {
101-
delegate.doFilter(request, response, chain);
100+
this.delegate.doFilter(request, response, chain);
102101
}
103102

104103
private void doFilter(HttpServletRequest request, HttpServletResponse response,

spring-boot/src/test/java/org/springframework/boot/bind/PropertiesConfigurationFactoryMapTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2013 the original author or authors.
2+
* Copyright 2012-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-boot/src/test/java/org/springframework/boot/context/web/ErrorPageFilterTests.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616

1717
package org.springframework.boot.context.web;
1818

19-
import static org.hamcrest.Matchers.equalTo;
20-
import static org.junit.Assert.assertNotNull;
21-
import static org.junit.Assert.assertThat;
22-
import static org.junit.Assert.assertTrue;
23-
2419
import java.io.IOException;
2520

2621
import javax.servlet.RequestDispatcher;
@@ -38,6 +33,11 @@
3833
import org.springframework.mock.web.MockHttpServletRequest;
3934
import org.springframework.mock.web.MockHttpServletResponse;
4035

36+
import static org.hamcrest.Matchers.equalTo;
37+
import static org.junit.Assert.assertNotNull;
38+
import static org.junit.Assert.assertThat;
39+
import static org.junit.Assert.assertTrue;
40+
4141
/**
4242
* Tests for {@link ErrorPageFilter}.
4343
*
@@ -110,7 +110,7 @@ public void doFilter(ServletRequest request, ServletResponse response)
110110
super.doFilter(request, response);
111111
}
112112
};
113-
filter.init(new MockFilterConfig("FILTER"));
113+
this.filter.init(new MockFilterConfig("FILTER"));
114114
this.filter.doFilter(this.request, this.response, this.chain);
115115
}
116116

0 commit comments

Comments
 (0)