Skip to content

Commit 56e31a8

Browse files
committed
Polish
1 parent 1f0d45d commit 56e31a8

File tree

20 files changed

+74
-77
lines changed

20 files changed

+74
-77
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2014 the original author or authors.
2+
* Copyright 2012-2015 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-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/PublicMetricsAutoConfigurationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2014 the original author or authors.
2+
* Copyright 2012-2015 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-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestMvcBootConfiguration.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package org.springframework.boot.autoconfigure.data.rest;
1818

19-
import com.fasterxml.jackson.databind.ObjectMapper;
20-
2119
import org.springframework.beans.factory.annotation.Autowired;
2220
import org.springframework.boot.context.properties.ConfigurationProperties;
2321
import org.springframework.context.annotation.Bean;
@@ -26,10 +24,11 @@
2624
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
2725
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
2826

27+
import com.fasterxml.jackson.databind.ObjectMapper;
28+
2929
/**
30-
* A specialized {@link RepositoryRestMvcConfiguration} that applies configuration
31-
* items from the {@code spring.data.rest} namespace. Also configure Jackson if it's
32-
* available
30+
* A specialized {@link RepositoryRestMvcConfiguration} that applies configuration items
31+
* from the {@code spring.data.rest} namespace. Also configures Jackson if it's available
3332
* <p>
3433
* Favor an extension of this class instead of extending directly from
3534
* {@link RepositoryRestMvcConfiguration}.
@@ -38,8 +37,7 @@
3837
* @since 1.2.2
3938
*/
4039
@Configuration
41-
public class RepositoryRestMvcBootConfiguration extends
42-
RepositoryRestMvcConfiguration {
40+
public class RepositoryRestMvcBootConfiguration extends RepositoryRestMvcConfiguration {
4341

4442
@Autowired(required = false)
4543
private Jackson2ObjectMapperBuilder objectMapperBuilder;

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,22 @@ static class JodaDateTimeJacksonConfiguration {
117117
@Bean
118118
public Module jodaDateTimeSerializationModule() {
119119
SimpleModule module = new SimpleModule();
120+
JacksonJodaFormat jacksonJodaFormat = getJacksonJodaFormat();
121+
if (jacksonJodaFormat != null) {
122+
module.addSerializer(DateTime.class, new DateTimeSerializer(
123+
jacksonJodaFormat));
124+
}
125+
return module;
126+
}
120127

121-
JacksonJodaFormat jacksonJodaFormat = null;
122-
128+
private JacksonJodaFormat getJacksonJodaFormat() {
123129
if (this.jacksonProperties.getJodaDateTimeFormat() != null) {
124-
jacksonJodaFormat = new JacksonJodaFormat(DateTimeFormat.forPattern(
130+
return new JacksonJodaFormat(DateTimeFormat.forPattern(
125131
this.jacksonProperties.getJodaDateTimeFormat()).withZoneUTC());
126132
}
127-
else if (this.jacksonProperties.getDateFormat() != null) {
133+
if (this.jacksonProperties.getDateFormat() != null) {
128134
try {
129-
jacksonJodaFormat = new JacksonJodaFormat(DateTimeFormat.forPattern(
135+
return new JacksonJodaFormat(DateTimeFormat.forPattern(
130136
this.jacksonProperties.getDateFormat()).withZoneUTC());
131137
}
132138
catch (IllegalArgumentException ex) {
@@ -138,14 +144,9 @@ else if (this.jacksonProperties.getDateFormat() != null) {
138144
}
139145
}
140146
}
141-
142-
if (jacksonJodaFormat != null) {
143-
module.addSerializer(DateTime.class, new DateTimeSerializer(
144-
jacksonJodaFormat));
145-
}
146-
147-
return module;
147+
return null;
148148
}
149+
149150
}
150151

151152
@Configuration

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2014 the original author or authors.
2+
* Copyright 2012-2015 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-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SpringBootWebSecurityConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2014 the original author or authors.
2+
* Copyright 2012-2015 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-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestMvcAutoConfigurationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 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-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SpringBootWebSecurityConfigurationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2014 the original author or authors.
2+
* Copyright 2012-2015 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-cli/src/main/java/org/springframework/boot/cli/command/init/InitializrService.java

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ class InitializrService {
5151
/**
5252
* Accept header to use to retrieve the json meta-data.
5353
*/
54-
public static final String ACCEPT_META_DATA =
55-
"application/vnd.initializr.v2.1+json,application/vnd.initializr.v2+json";
54+
public static final String ACCEPT_META_DATA = "application/vnd.initializr.v2.1+"
55+
+ "json,application/vnd.initializr.v2+json";
5656

5757
/**
5858
* Accept header to use to retrieve the service capabilities of the service. If the
5959
* service does not offer such feature, the json meta-data are retrieved instead.
6060
*/
61-
public static final String ACCEPT_SERVICE_CAPABILITIES =
62-
"text/plain," + ACCEPT_META_DATA;
61+
public static final String ACCEPT_SERVICE_CAPABILITIES = "text/plain,"
62+
+ ACCEPT_META_DATA;
6363

6464
/**
6565
* Late binding HTTP client.
@@ -110,27 +110,29 @@ public InitializrServiceMetadata loadMetadata(String serviceUrl) throws IOExcept
110110
}
111111

112112
/**
113-
* Loads the service capabilities of the service at the specified url.
114-
* <p>If the service supports generating a textual representation of the
115-
* capabilities, it is returned. Otherwhise the json meta-data as a
116-
* {@link JSONObject} is returned.
113+
* Loads the service capabilities of the service at the specified URL. If the service
114+
* supports generating a textual representation of the capabilities, it is returned,
115+
* otherwise {@link InitializrServiceMetadata} is returned.
117116
* @param serviceUrl to url of the initializer service
118-
* @return the service capabilities (as a String) or the metadata describing the service
117+
* @return the service capabilities (as a String) or the
118+
* {@link InitializrServiceMetadata} describing the service
119119
* @throws IOException if the service capabilities cannot be loaded
120120
*/
121-
public Object loadServiceCapabilities(String serviceUrl) throws IOException {
122-
CloseableHttpResponse httpResponse = executeServiceCapabilitiesRetrieval(serviceUrl);
121+
public Object loadServiceCapabilities(String serviceUrl) throws IOException {
122+
HttpGet request = new HttpGet(serviceUrl);
123+
request.setHeader(new BasicHeader(HttpHeaders.ACCEPT, ACCEPT_SERVICE_CAPABILITIES));
124+
CloseableHttpResponse httpResponse = execute(request, serviceUrl, "retrieve help");
123125
validateResponse(httpResponse, serviceUrl);
124126
HttpEntity httpEntity = httpResponse.getEntity();
125127
ContentType contentType = ContentType.getOrDefault(httpEntity);
126128
if (contentType.getMimeType().equals("text/plain")) {
127-
return getContent(httpEntity);
128-
} else {
129-
return parseJsonMetadata(httpEntity);
129+
return getContent(httpEntity);
130130
}
131+
return parseJsonMetadata(httpEntity);
131132
}
132133

133-
private InitializrServiceMetadata parseJsonMetadata(HttpEntity httpEntity) throws IOException {
134+
private InitializrServiceMetadata parseJsonMetadata(HttpEntity httpEntity)
135+
throws IOException {
134136
try {
135137
return new InitializrServiceMetadata(getContentAsJson(httpEntity));
136138
}
@@ -179,15 +181,6 @@ private CloseableHttpResponse executeInitializrMetadataRetrieval(String url) {
179181
return execute(request, url, "retrieve metadata");
180182
}
181183

182-
/**
183-
* Retrieves the service capabilities of the service at the specified URL
184-
*/
185-
private CloseableHttpResponse executeServiceCapabilitiesRetrieval(String url) {
186-
HttpGet request = new HttpGet(url);
187-
request.setHeader(new BasicHeader(HttpHeaders.ACCEPT, ACCEPT_SERVICE_CAPABILITIES));
188-
return execute(request, url, "retrieve help");
189-
}
190-
191184
private CloseableHttpResponse execute(HttpUriRequest request, Object url,
192185
String description) {
193186
try {

spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/ServiceCapabilitiesReportGenerator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class ServiceCapabilitiesReportGenerator {
4848

4949
/**
5050
* Generate a report for the specified service. The report contains the available
51-
* capabilities as advertized by the root endpoint.
51+
* capabilities as advertised by the root endpoint.
5252
* @param url the url of the service
5353
* @return the report that describes the service
5454
* @throws IOException if the report cannot be generated
@@ -57,9 +57,8 @@ public String generate(String url) throws IOException {
5757
Object content = this.initializrService.loadServiceCapabilities(url);
5858
if (content instanceof InitializrServiceMetadata) {
5959
return generateHelp(url, (InitializrServiceMetadata) content);
60-
} else {
61-
return content.toString();
6260
}
61+
return content.toString();
6362
}
6463

6564
private String generateHelp(String url, InitializrServiceMetadata metadata) {

0 commit comments

Comments
 (0)