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-11 22:24:03 -07:00
parent eb5211960c
commit 923fb58ffc
69 changed files with 626 additions and 365 deletions

View File

@@ -49,7 +49,7 @@ class InitializrStatsAutoConfiguration {
private final StatsProperties statsProperties;
public InitializrStatsAutoConfiguration(StatsProperties statsProperties) {
InitializrStatsAutoConfiguration(StatsProperties statsProperties) {
this.statsProperties = statsProperties;
}

View File

@@ -45,7 +45,7 @@ public class BomRangesInfoContributor implements InfoContributor {
.forEach((k, v) -> {
if (v.getMappings() != null && !v.getMappings().isEmpty()) {
Map<String, Object> bom = new LinkedHashMap<>();
v.getMappings().forEach(it -> {
v.getMappings().forEach((it) -> {
String requirement = "Spring Boot "
+ it.determineVersionRangeRequirement();
bom.put(it.getVersion(), requirement);

View File

@@ -19,6 +19,7 @@ package io.spring.initializr.actuate.info;
import java.util.LinkedHashMap;
import java.util.Map;
import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.metadata.InitializrMetadataProvider;
import io.spring.initializr.util.Version;
import io.spring.initializr.util.VersionRange;
@@ -44,47 +45,9 @@ public class DependencyRangesInfoContributor implements InfoContributor {
@Override
public void contribute(Info.Builder builder) {
Map<String, Object> details = new LinkedHashMap<>();
this.metadataProvider.get().getDependencies().getAll().forEach(d -> {
this.metadataProvider.get().getDependencies().getAll().forEach((d) -> {
if (d.getBom() == null) {
if (!ObjectUtils.isEmpty(d.getMappings())) {
Map<String, VersionRange> dep = new LinkedHashMap<>();
d.getMappings().forEach(it -> {
if (it.getRange() != null && it.getVersion() != null) {
dep.put(it.getVersion(), it.getRange());
}
});
if (!dep.isEmpty()) {
if (d.getRange() == null) {
boolean openRange = dep.values().stream()
.anyMatch(v -> v.getHigherVersion() == null);
if (!openRange) {
Version higher = null;
for (VersionRange versionRange : dep.values()) {
Version candidate = versionRange.getHigherVersion();
if (higher == null) {
higher = candidate;
}
else if (candidate.compareTo(higher) > 0) {
higher = candidate;
}
}
;
dep.put("managed", new VersionRange(higher));
}
}
Map<String, Object> depInfo = new LinkedHashMap<>();
dep.forEach((k, r) -> {
depInfo.put(k, "Spring Boot " + r);
});
details.put(d.getId(), depInfo);
}
}
else if (d.getVersion() != null && d.getRange() != null) {
Map<String, Object> dep = new LinkedHashMap<>();
String requirement = "Spring Boot " + d.getRange();
dep.put(d.getVersion(), requirement);
details.put(d.getId(), dep);
}
contribute(details, d);
}
});
if (!details.isEmpty()) {
@@ -92,4 +55,50 @@ public class DependencyRangesInfoContributor implements InfoContributor {
}
}
private void contribute(Map<String, Object> details, Dependency d) {
if (!ObjectUtils.isEmpty(d.getMappings())) {
Map<String, VersionRange> dep = new LinkedHashMap<>();
d.getMappings().forEach((it) -> {
if (it.getRange() != null && it.getVersion() != null) {
dep.put(it.getVersion(), it.getRange());
}
});
if (!dep.isEmpty()) {
if (d.getRange() == null) {
boolean openRange = dep.values().stream()
.anyMatch((v) -> v.getHigherVersion() == null);
if (!openRange) {
Version higher = getHigher(dep);
dep.put("managed", new VersionRange(higher));
}
}
Map<String, Object> depInfo = new LinkedHashMap<>();
dep.forEach((k, r) -> {
depInfo.put(k, "Spring Boot " + r);
});
details.put(d.getId(), depInfo);
}
}
else if (d.getVersion() != null && d.getRange() != null) {
Map<String, Object> dep = new LinkedHashMap<>();
String requirement = "Spring Boot " + d.getRange();
dep.put(d.getVersion(), requirement);
details.put(d.getId(), dep);
}
}
private Version getHigher(Map<String, VersionRange> dep) {
Version higher = null;
for (VersionRange versionRange : dep.values()) {
Version candidate = versionRange.getHigherVersion();
if (higher == null) {
higher = candidate;
}
else if (candidate.compareTo(higher) > 0) {
higher = candidate;
}
}
return higher;
}
}

View File

@@ -54,7 +54,7 @@ public class ProjectGenerationMetricsListener {
}
protected void handleProjectRequest(ProjectRequest request) {
increment(key("requests"));// Total number of requests
increment(key("requests")); // Total number of requests
handleDependencies(request);
handleType(request);
handleJavaVersion(request);
@@ -67,7 +67,7 @@ public class ProjectGenerationMetricsListener {
protected void handleDependencies(ProjectRequest request) {
List<Dependency> dependencies = request.getResolvedDependencies();
if (dependencies != null) {
dependencies.forEach(it -> {
dependencies.forEach((it) -> {
if (!ProjectRequest.DEFAULT_STARTER.equals(it.getId())) {
String id = sanitize(it.getId());
increment(key("dependency." + id));

View File

@@ -27,7 +27,6 @@ import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.event.EventListener;
import org.springframework.http.MediaType;
import org.springframework.http.RequestEntity;
import org.springframework.retry.RetryCallback;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.util.StringUtils;
@@ -86,11 +85,10 @@ public class ProjectGenerationStatPublisher {
.post(this.statsProperties.getElastic().getEntityUrl())
.contentType(MediaType.APPLICATION_JSON).body(json);
this.retryTemplate
.execute((RetryCallback<Void, RuntimeException>) context -> {
this.restTemplate.exchange(request, String.class);
return null;
});
this.retryTemplate.execute((context) -> {
this.restTemplate.exchange(request, String.class);
return null;
});
}
catch (Exception ex) {
log.warn(String.format(

View File

@@ -103,7 +103,7 @@ public class ProjectRequestDocumentFactory {
List<String> dependencies = new ArrayList<>();
dependencies.addAll(request.getStyle());
dependencies.addAll(request.getDependencies());
dependencies.forEach(id -> {
dependencies.forEach((id) -> {
if (metadata.getDependencies().get(id) != null) {
document.getDependencies().add(id);
}

View File

@@ -38,6 +38,9 @@ public class StatsProperties {
return this.elastic;
}
/**
* Elasicsearch configuration.
*/
public static final class Elastic {
/**
@@ -51,7 +54,7 @@ public class StatsProperties {
private String username;
/**
* Elastic service password
* Elastic service password.
*/
private String password;

View File

@@ -25,10 +25,10 @@ import io.spring.initializr.web.AbstractInitializrIntegrationTests.Config;
import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.test.context.ActiveProfiles;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
/**
* Tests for actuator specific features.
@@ -36,7 +36,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
* @author Stephane Nicoll
*/
@ActiveProfiles("test-default")
@SpringBootTest(classes = Config.class, webEnvironment = RANDOM_PORT, properties = "management.endpoints.web.exposure.include=info,metrics")
@SpringBootTest(classes = Config.class, webEnvironment = WebEnvironment.RANDOM_PORT, properties = "management.endpoints.web.exposure.include=info,metrics")
public class ActuatorIntegrationTests
extends AbstractFullStackInitializrIntegrationTests {

View File

@@ -79,7 +79,7 @@ public class InitializrStatsAutoConfigurationTests {
@Bean
public RestTemplateCustomizer testRestTemplateCustomizer() {
return b -> b.setErrorHandler(errorHandler);
return (b) -> b.setErrorHandler(errorHandler);
}
}

View File

@@ -39,8 +39,6 @@ import org.springframework.web.client.HttpClientErrorException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Integration tests for stats processing.
@@ -88,8 +86,7 @@ public class MainControllerStatsIntegrationTests
String authorization = content.authorization;
assertThat(authorization).as("Authorization header must be set").isNotNull();
assertTrue("Wrong value for authorization header",
authorization.startsWith("Basic "));
assertThat(authorization).startsWith("Basic ");
String token = authorization.substring("Basic ".length(), authorization.length());
String[] data = new String(Base64Utils.decodeFromString(token)).split(":");
assertThat(data[0]).as("Wrong user from " + token).isEqualTo("test-user");
@@ -129,8 +126,9 @@ public class MainControllerStatsIntegrationTests
StatsMockController.Content content = this.statsMockController.stats.get(0);
JsonNode json = parseJson(content.json);
assertFalse("requestIpv4 property should not be set if value is not a valid IPv4",
json.has("requestIpv4"));
assertThat(json.has("requestIpv4"))
.as("requestIpv4 property should not be set if value is not a valid IPv4")
.isFalse();
}
@Test
@@ -142,8 +140,9 @@ public class MainControllerStatsIntegrationTests
StatsMockController.Content content = this.statsMockController.stats.get(0);
JsonNode json = parseJson(content.json);
assertFalse("requestCountry property should not be set if value is set to xx",
json.has("requestCountry"));
assertThat(json.has("requestCountry"))
.as("requestCountry property should not be set if value is set to xx")
.isFalse();
}
@Test

View File

@@ -38,14 +38,14 @@ public class MetricsAssert {
public MetricsAssert hasValue(long value, String... metrics) {
Arrays.asList(metrics).forEach(
metric -> assertThat(this.meterRegistry.get(metric).counter().count())
(metric) -> assertThat(this.meterRegistry.get(metric).counter().count())
.isEqualTo(value));
return this;
}
public MetricsAssert hasNoValue(String... metrics) {
Arrays.asList(metrics).forEach(metric -> assertThat(
Search.in(this.meterRegistry).name(n -> n.startsWith(metric)).counter())
Arrays.asList(metrics).forEach((metric) -> assertThat(
Search.in(this.meterRegistry).name((n) -> n.startsWith(metric)).counter())
.isNull());
return this;
}