Fix checkstyle violations

Fix checkstyle violations using a pre-release version of the
spring-javaformat rules.
This commit is contained in:
Phillip Webb
2018-04-13 12:36:06 -07:00
parent eb5211960c
commit 923fb58ffc
69 changed files with 626 additions and 365 deletions
@@ -124,6 +124,9 @@ public class InitializrAutoConfiguration {
return new DefaultDependencyMetadataProvider();
}
/**
* Initializr web configuration.
*/
@Configuration
@ConditionalOnWebApplication
static class InitializrWebConfiguration {
@@ -154,13 +157,16 @@ public class InitializrAutoConfiguration {
}
/**
* Initializr cache configuration.
*/
@Configuration
@ConditionalOnClass(javax.cache.CacheManager.class)
static class InitializrCacheConfiguration {
@Bean
public JCacheManagerCustomizer initializrCacheManagerCustomizer() {
return cm -> {
return (cm) -> {
cm.createCache("initializr.metadata", config().setExpiryPolicyFactory(
CreatedExpiryPolicy.factoryOf(Duration.TEN_MINUTES)));
cm.createCache("initializr.dependency-metadata", config());
@@ -27,6 +27,8 @@ interface DependencyMetadataJsonMapper {
/**
* Write a json representation of the specified metadata.
* @param metadata the dependency metadata
* @return the JSON representation
*/
String write(DependencyMetadata metadata);
@@ -44,13 +44,13 @@ public class DependencyMetadataV21JsonMapper implements DependencyMetadataJsonMa
json.set("dependencies",
mapNode(metadata.getDependencies().entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey,
entry -> mapDependency(entry.getValue())))));
(entry) -> mapDependency(entry.getValue())))));
json.set("repositories",
mapNode(metadata.getRepositories().entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey,
entry -> mapRepository(entry.getValue())))));
json.set("boms", mapNode(metadata.getBoms().entrySet().stream().collect(
Collectors.toMap(Map.Entry::getKey, entry -> mapBom(entry.getValue())))));
(entry) -> mapRepository(entry.getValue())))));
json.set("boms", mapNode(metadata.getBoms().entrySet().stream().collect(Collectors
.toMap(Map.Entry::getKey, (entry) -> mapBom(entry.getValue())))));
return json.toString();
}
@@ -27,7 +27,10 @@ public interface InitializrMetadataJsonMapper {
/**
* Write a json representation of the specified metadata.
* @param metadata The intializr metadata
* @param appUrl the app URL
* @return the JSON representation
*/
String write(InitializrMetadata metadata, String appUrl);
}
}
@@ -101,7 +101,7 @@ public class InitializrMetadataV2JsonMapper implements InitializrMetadataJsonMap
protected ObjectNode links(ObjectNode parent, List<Type> types, String appUrl) {
ObjectNode content = nodeFactory.objectNode();
types.forEach(it -> content.set(it.getId(), link(appUrl, it)));
types.forEach((it) -> content.set(it.getId(), link(appUrl, it)));
parent.set("_links", content);
return content;
}
@@ -176,7 +176,7 @@ public class InitializrMetadataV2JsonMapper implements InitializrMetadataJsonMap
result.put("description", ((Describable) group).getDescription());
}
ArrayNode items = nodeFactory.arrayNode();
group.getContent().forEach(it -> {
group.getContent().forEach((it) -> {
JsonNode dependency = mapDependency(it);
if (dependency != null) {
items.add(dependency);
@@ -47,4 +47,4 @@ public enum InitializrMetadataVersion {
return this.mediaType;
}
}
}
@@ -27,14 +27,17 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import io.spring.initializr.metadata.Link;
/**
* Generate a json representation for {@link Link}
* Generate a json representation for {@link Link}.
*
* @author Stephane Nicoll
*/
public class LinkMapper {
public final class LinkMapper {
private static final JsonNodeFactory nodeFactory = JsonNodeFactory.instance;
private LinkMapper() {
}
/**
* Map the specified links to a json model. If several links share the same relation,
* they are grouped together.
@@ -44,8 +47,8 @@ public class LinkMapper {
public static ObjectNode mapLinks(List<Link> links) {
ObjectNode result = nodeFactory.objectNode();
Map<String, List<Link>> byRel = new LinkedHashMap<>();
links.forEach(
it -> byRel.computeIfAbsent(it.getRel(), k -> new ArrayList<>()).add(it));
links.forEach((it) -> byRel.computeIfAbsent(it.getRel(), (k) -> new ArrayList<>())
.add(it));
byRel.forEach((rel, l) -> {
if (l.size() == 1) {
ObjectNode root = JsonNodeFactory.instance.objectNode();
@@ -54,7 +57,7 @@ public class LinkMapper {
}
else {
ArrayNode root = JsonNodeFactory.instance.arrayNode();
l.forEach(link -> {
l.forEach((link) -> {
ObjectNode node = JsonNodeFactory.instance.objectNode();
mapLink(link, node);
root.add(node);
@@ -35,7 +35,7 @@ import org.springframework.web.servlet.resource.ResourceUrlProvider;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
/**
* A base controller that uses a {@link InitializrMetadataProvider}
* A base controller that uses a {@link InitializrMetadataProvider}.
*
* @author Stephane Nicoll
*/
@@ -50,7 +50,7 @@ public abstract class AbstractInitializrController {
protected AbstractInitializrController(InitializrMetadataProvider metadataProvider,
ResourceUrlProvider resourceUrlProvider) {
this.metadataProvider = metadataProvider;
this.linkTo = link -> {
this.linkTo = (link) -> {
String result = resourceUrlProvider.getForLookupPath(link);
return result == null ? link : result;
};
@@ -73,6 +73,7 @@ public abstract class AbstractInitializrController {
/**
* Render the home page with the specified template.
* @param model the model data
*/
protected void renderHome(Map<String, Object> model) {
InitializrMetadata metadata = this.metadataProvider.get();
@@ -105,13 +106,14 @@ public abstract class AbstractInitializrController {
result.setTitle(types.getTitle());
result.getContent().addAll(types.getContent());
// Only keep project type
result.getContent().removeIf(t -> !"project".equals(t.getTags().get("format")));
result.getContent().removeIf((t) -> !"project".equals(t.getTags().get("format")));
return result;
}
/**
* Generate a full URL of the service, mostly for use in templates.
* @see io.spring.initializr.metadata.InitializrConfiguration.Env#forceSsl
* @return the app URL
* @see io.spring.initializr.metadata.InitializrConfiguration.Env#isForceSsl()
*/
protected String generateAppUrl() {
ServletUriComponentsBuilder builder = ServletUriComponentsBuilder
@@ -35,6 +35,7 @@ import io.spring.initializr.metadata.DependencyMetadataProvider;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.metadata.InitializrMetadataProvider;
import io.spring.initializr.util.Agent;
import io.spring.initializr.util.Agent.AgentId;
import io.spring.initializr.util.TemplateRenderer;
import io.spring.initializr.util.Version;
import io.spring.initializr.web.mapper.DependencyMetadataV21JsonMapper;
@@ -65,10 +66,6 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.resource.ResourceUrlProvider;
import static io.spring.initializr.util.Agent.AgentId.CURL;
import static io.spring.initializr.util.Agent.AgentId.HTTPIE;
import static io.spring.initializr.util.Agent.AgentId.SPRING_BOOT_CLI;
/**
* The main initializr controller provides access to the configured metadata and serves as
* a central endpoint to generate projects or build files.
@@ -81,6 +78,9 @@ public class MainController extends AbstractInitializrController {
private static final Logger log = LoggerFactory.getLogger(MainController.class);
/**
* HAL JSON content type.
*/
public static final MediaType HAL_JSON_CONTENT_TYPE = MediaType
.parseMediaType("application/hal+json");
@@ -130,17 +130,17 @@ public class MainController extends AbstractInitializrController {
if (userAgent != null) {
Agent agent = Agent.fromUserAgent(userAgent);
if (agent != null) {
if (CURL.equals(agent.getId())) {
if (AgentId.CURL.equals(agent.getId())) {
String content = this.commandLineHelpGenerator
.generateCurlCapabilities(metadata, appUrl);
return builder.eTag(createUniqueId(content)).body(content);
}
if (HTTPIE.equals(agent.getId())) {
if (AgentId.HTTPIE.equals(agent.getId())) {
String content = this.commandLineHelpGenerator
.generateHttpieCapabilities(metadata, appUrl);
return builder.eTag(createUniqueId(content)).body(content);
}
if (SPRING_BOOT_CLI.equals(agent.getId())) {
if (AgentId.SPRING_BOOT_CLI.equals(agent.getId())) {
String content = this.commandLineHelpGenerator
.generateSpringBootCliCapabilities(metadata, appUrl);
return builder.eTag(createUniqueId(content)).body(content);
@@ -38,7 +38,11 @@ public class SpringBootMetadataReader {
private final JsonNode content;
/**
* Parse the content of the metadata at the specified url
* Parse the content of the metadata at the specified url.
* @param objectMapper the object mapper
* @param restTemplate the rest template
* @param url the metadata URL
* @throws IOException on load error
*/
public SpringBootMetadataReader(ObjectMapper objectMapper, RestTemplate restTemplate,
String url) throws IOException {
@@ -48,6 +52,7 @@ public class SpringBootMetadataReader {
/**
* Return the boot versions parsed by this instance.
* @return the versions
*/
public List<DefaultMetadataElement> getBootVersions() {
ArrayNode array = (ArrayNode) this.content.get("projectReleases");
@@ -58,7 +58,7 @@ public class UiController {
.getDependencies().getContent();
List<DependencyItem> content = new ArrayList<>();
Version v = StringUtils.isEmpty(version) ? null : Version.parse(version);
dependencyGroups.forEach(g -> g.getContent().forEach(d -> {
dependencyGroups.forEach((g) -> g.getContent().forEach((d) -> {
if (v != null && d.getVersionRange() != null) {
if (d.match(v)) {
content.add(new DependencyItem(g.getName(), d));
@@ -76,7 +76,7 @@ public class UiController {
private static String writeDependencies(List<DependencyItem> items) {
ObjectNode json = JsonNodeFactory.instance.objectNode();
ArrayNode maps = JsonNodeFactory.instance.arrayNode();
items.forEach(d -> maps.add(mapDependency(d)));
items.forEach((d) -> maps.add(mapDependency(d)));
json.set("dependencies", maps);
return json.toString();
}
@@ -102,6 +102,13 @@ public class UiController {
return node;
}
private String createUniqueId(String content) {
StringBuilder builder = new StringBuilder();
DigestUtils.appendMd5DigestAsHex(content.getBytes(StandardCharsets.UTF_8),
builder);
return builder.toString();
}
private static class DependencyItem {
private final String group;
@@ -115,11 +122,4 @@ public class UiController {
}
private String createUniqueId(String content) {
StringBuilder builder = new StringBuilder();
DigestUtils.appendMd5DigestAsHex(content.getBytes(StandardCharsets.UTF_8),
builder);
return builder.toString();
}
}
@@ -20,17 +20,16 @@ import io.spring.initializr.web.AbstractInitializrIntegrationTests.Config;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.test.context.junit4.SpringRunner;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
/**
* @author Stephane Nicoll
* @author Dave Syer
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Config.class, webEnvironment = RANDOM_PORT)
@SpringBootTest(classes = Config.class, webEnvironment = WebEnvironment.RANDOM_PORT)
public abstract class AbstractFullStackInitializrIntegrationTests
extends AbstractInitializrIntegrationTests {
@@ -60,7 +60,7 @@ public abstract class AbstractInitializrControllerIntegrationTests
@Bean
RestTemplateCustomizer mockMvcCustomizer(BeanFactory beanFactory) {
return template -> template.setRequestFactory(
return (template) -> template.setRequestFactory(
beanFactory.getBean(MockMvcClientHttpRequestFactory.class));
}
@@ -62,7 +62,7 @@ import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.StreamUtils;
import org.springframework.web.client.RestTemplate;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Stephane Nicoll
@@ -100,12 +100,15 @@ public abstract class AbstractInitializrIntegrationTests {
/**
* Validate the "Content-Type" header of the specified response.
* @param response the response
* @param expected the expected result
*/
protected void validateContentType(ResponseEntity<String> response,
MediaType expected) {
MediaType actual = response.getHeaders().getContentType();
assertTrue("Non compatible media-type, expected " + expected + ", got " + actual,
actual.isCompatibleWith(expected));
assertThat(actual.isCompatibleWith(expected))
.as("Non compatible media-type, expected " + expected + ", got " + actual)
.isTrue();
}
protected JsonNode parseJson(String text) {
@@ -65,7 +65,7 @@ public class InitializrAutoConfigurationTests {
@Bean
public RestTemplateCustomizer testRestTemplateCustomizer() {
return b -> b.setErrorHandler(errorHandler);
return (b) -> b.setErrorHandler(errorHandler);
}
}
@@ -39,7 +39,7 @@ class HomePage {
private final WebDriver driver;
public HomePage(WebDriver driver) {
HomePage(WebDriver driver) {
this.driver = driver;
PageFactory.initElements(driver, this);
}
@@ -34,7 +34,6 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.web.servlet.resource.ResourceUrlProvider;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
/**
* @author Stephane Nicoll
@@ -47,14 +46,9 @@ public class LegacyStsControllerIntegrationTests
@Test
public void legacyStsHome() {
String body = htmlHome();
assertThat(body.contains("com.example")).as("groupId not found").isTrue();
assertThat(body.contains("demo")).as("artifactId not found").isTrue();
assertTrue("custom description not found",
body.contains("Demo project for Spring Boot"));
assertTrue("Wrong body:\n" + body, body
.contains("<input type=\"radio\" name=\"language\" value=\"groovy\"/>"));
assertTrue("Wrong body:\n" + body, body.contains(
"<input type=\"radio\" name=\"language\" value=\"java\" checked=\"true\"/>"));
assertThat(body).contains("com.example", "demo", "Demo project for Spring Boot",
"<input type=\"radio\" name=\"language\" value=\"groovy\"/>",
"<input type=\"radio\" name=\"language\" value=\"java\" checked=\"true\"/>");
}
@Override
@@ -28,8 +28,6 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.core.IsNot.not;
/**
* @author Stephane Nicoll
@@ -27,7 +27,6 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
/**
* @author Stephane Nicoll
@@ -66,8 +65,7 @@ public class MainControllerEnvIntegrationTests
@Test
public void googleAnalytics() {
String body = htmlHome();
assertTrue("google tag manager should be enabled",
body.contains("https://www.googletagmanager.com/gtm.js"));
assertThat(body).contains("https://www.googletagmanager.com/gtm.js");
}
}
@@ -26,7 +26,6 @@ import io.spring.initializr.util.Version;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertSame;
/**
* @author Stephane Nicoll
@@ -101,8 +100,8 @@ public class DefaultDependencyMetadataProviderTests {
assertThat(dependencyMetadata.getDependencies()).hasSize(3);
assertThat(dependencyMetadata.getRepositories()).hasSize(1);
assertThat(dependencyMetadata.getBoms()).isEmpty();
assertSame(metadata.getConfiguration().getEnv().getRepositories().get("repo-foo"),
dependencyMetadata.getRepositories().get("repo-foo"));
assertThat(dependencyMetadata.getRepositories().get("repo-foo")).isSameAs(
metadata.getConfiguration().getEnv().getRepositories().get("repo-foo"));
}
@Test
@@ -64,7 +64,7 @@ public class SpringBootMetadataReaderTests {
.getBootVersions();
assertThat(versions).as("spring boot versions should not be null").isNotNull();
AtomicBoolean defaultFound = new AtomicBoolean(false);
versions.forEach(it -> {
versions.forEach((it) -> {
assertThat(it.getId()).as("Id must be set").isNotNull();
assertThat(it.getName()).as("Name must be set").isNotNull();
if (it.isDefault()) {
@@ -33,14 +33,15 @@ final class JsonFieldProcessor {
boolean hasField(JsonFieldPath fieldPath, Object payload) {
final AtomicReference<Boolean> hasField = new AtomicReference<>(false);
traverse(new ProcessingContext(payload, fieldPath), match -> hasField.set(true));
traverse(new ProcessingContext(payload, fieldPath),
(match) -> hasField.set(true));
return hasField.get();
}
Object extract(JsonFieldPath path, Object payload) {
final List<Object> matches = new ArrayList<>();
traverse(new ProcessingContext(payload, path),
match -> matches.add(match.getValue()));
(match) -> matches.add(match.getValue()));
if (matches.isEmpty()) {
throw new IllegalArgumentException("Field does not exist: " + path);
}
@@ -137,4 +137,4 @@ public class MockMvcClientHttpRequestFactory implements ClientHttpRequestFactory
this.fields = Arrays.asList(fields);
}
}
}
@@ -52,4 +52,4 @@ public final class MockMvcClientHttpRequestFactoryTestExecutionListener
}
}
}
}