Code formatting

This commit is contained in:
Stephane Nicoll
2017-02-10 12:14:55 +01:00
parent 53679aa860
commit 5296d6a05f
99 changed files with 722 additions and 660 deletions

View File

@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.spring.initializr</groupId>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,12 +16,12 @@
package io.spring.initializr.actuate.autoconfigure;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import io.spring.initializr.actuate.info.BomRangesInfoContributor;
import io.spring.initializr.metadata.InitializrMetadataProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
* Auto-configuration} to improve actuator endpoints with initializr specific information.

View File

@@ -16,7 +16,8 @@
package io.spring.initializr.actuate.autoconfigure;
import org.springframework.beans.factory.annotation.Autowired;
import io.spring.initializr.actuate.metric.ProjectGenerationMetricsListener;
import org.springframework.boot.actuate.autoconfigure.ExportMetricWriter;
import org.springframework.boot.actuate.autoconfigure.MetricExportAutoConfiguration;
import org.springframework.boot.actuate.metrics.CounterService;
@@ -34,8 +35,6 @@ import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.util.ObjectUtils;
import io.spring.initializr.actuate.metric.ProjectGenerationMetricsListener;
/**
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
* Auto-configuration} to handle the metrics of an initializr instance.

View File

@@ -18,6 +18,11 @@ package io.spring.initializr.actuate.autoconfigure;
import java.util.Collections;
import io.spring.initializr.actuate.stat.ProjectGenerationStatPublisher;
import io.spring.initializr.actuate.stat.ProjectRequestDocumentFactory;
import io.spring.initializr.actuate.stat.StatsProperties;
import io.spring.initializr.metadata.InitializrMetadataProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@@ -28,11 +33,6 @@ import org.springframework.retry.backoff.ExponentialBackOffPolicy;
import org.springframework.retry.policy.SimpleRetryPolicy;
import org.springframework.retry.support.RetryTemplate;
import io.spring.initializr.actuate.stat.ProjectGenerationStatPublisher;
import io.spring.initializr.actuate.stat.ProjectRequestDocumentFactory;
import io.spring.initializr.actuate.stat.StatsProperties;
import io.spring.initializr.metadata.InitializrMetadataProvider;
/**
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
* Auto-configuration} to publish statistics of each generated project.
@@ -63,8 +63,8 @@ class InitializrStatsAutoConfiguration {
backOffPolicy.setInitialInterval(3000L);
backOffPolicy.setMultiplier(3);
SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(
statsProperties.getElastic().getMaxAttempts(), Collections
.<Class<? extends Throwable>, Boolean> singletonMap(Exception.class, true));
statsProperties.getElastic().getMaxAttempts(),
Collections.singletonMap(Exception.class, true));
retryTemplate.setBackOffPolicy(backOffPolicy);
retryTemplate.setRetryPolicy(retryPolicy);
return retryTemplate;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,11 +19,11 @@ package io.spring.initializr.actuate.info;
import java.util.LinkedHashMap;
import java.util.Map;
import io.spring.initializr.metadata.InitializrMetadataProvider;
import org.springframework.boot.actuate.info.Info;
import org.springframework.boot.actuate.info.InfoContributor;
import io.spring.initializr.metadata.InitializrMetadataProvider;
/**
* An {@link InfoContributor} that exposes the actual ranges used by each bom
* defined in the project.
@@ -41,8 +41,8 @@ public class BomRangesInfoContributor implements InfoContributor {
@Override
public void contribute(Info.Builder builder) {
Map<String, Object> details = new LinkedHashMap<>();
metadataProvider.get().getConfiguration().getEnv().getBoms().forEach( (k, v) -> {
if (v.getMappings()!=null && !v.getMappings().isEmpty()) {
metadataProvider.get().getConfiguration().getEnv().getBoms().forEach((k, v) -> {
if (v.getMappings() != null && !v.getMappings().isEmpty()) {
Map<String, Object> bom = new LinkedHashMap<>();
v.getMappings().forEach(it -> {
String requirement = "Spring Boot " + it.determineVersionRangeRequirement();

View File

@@ -16,14 +16,14 @@
package io.spring.initializr.actuate.metric;
import java.util.List;
import io.spring.initializr.generator.ProjectFailedEvent;
import io.spring.initializr.generator.ProjectGeneratedEvent;
import io.spring.initializr.generator.ProjectRequest;
import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.util.Agent;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.metrics.CounterService;
import org.springframework.context.event.EventListener;

View File

@@ -16,8 +16,13 @@
package io.spring.initializr.actuate.stat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.spring.initializr.generator.ProjectRequestEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.event.EventListener;
import org.springframework.http.MediaType;
@@ -28,12 +33,6 @@ import org.springframework.retry.support.RetryTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.client.RestTemplate;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.spring.initializr.generator.ProjectRequestEvent;
/**
* Publish stats for each project generated to an Elastic index.
*

View File

@@ -21,8 +21,6 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.springframework.util.StringUtils;
import io.spring.initializr.generator.ProjectFailedEvent;
import io.spring.initializr.generator.ProjectRequest;
import io.spring.initializr.generator.ProjectRequestEvent;
@@ -30,6 +28,8 @@ import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.metadata.InitializrMetadataProvider;
import io.spring.initializr.util.Agent;
import org.springframework.util.StringUtils;
/**
* Create {@link ProjectRequestDocument} instances.
*
@@ -54,13 +54,13 @@ public class ProjectRequestDocumentFactory {
handleCloudFlareHeaders(request, document);
String candidate = (String) request.getParameters().get("x-forwarded-for");
if (!StringUtils.hasText(document.getRequestIp()) && candidate!=null) {
if (!StringUtils.hasText(document.getRequestIp()) && candidate != null) {
document.setRequestIp(candidate);
document.setRequestIpv4(extractIpv4(candidate));
}
Agent agent = extractAgentInformation(request);
if (agent!=null) {
if (agent != null) {
document.setClientId(agent.getId().getId());
document.setClientVersion(agent.getVersion());
}
@@ -71,25 +71,25 @@ public class ProjectRequestDocumentFactory {
document.setBootVersion(request.getBootVersion());
document.setJavaVersion(request.getJavaVersion());
if (StringUtils.hasText(request.getJavaVersion()) && metadata.getJavaVersions().get(request.getJavaVersion())==null) {
if (StringUtils.hasText(request.getJavaVersion()) && metadata.getJavaVersions().get(request.getJavaVersion()) == null) {
document.setInvalid(true);
document.setInvalidJavaVersion(true);
}
document.setLanguage(request.getLanguage());
if (StringUtils.hasText(request.getLanguage()) && metadata.getLanguages().get(request.getLanguage())==null) {
if (StringUtils.hasText(request.getLanguage()) && metadata.getLanguages().get(request.getLanguage()) == null) {
document.setInvalid(true);
document.setInvalidLanguage(true);
}
document.setPackaging(request.getPackaging());
if (StringUtils.hasText(request.getPackaging()) && metadata.getPackagings().get(request.getPackaging())==null) {
if (StringUtils.hasText(request.getPackaging()) && metadata.getPackagings().get(request.getPackaging()) == null) {
document.setInvalid(true);
document.setInvalidPackaging(true);
}
document.setType(request.getType());
if (StringUtils.hasText(request.getType()) && metadata.getTypes().get(request.getType())==null) {
if (StringUtils.hasText(request.getType()) && metadata.getTypes().get(request.getType()) == null) {
document.setInvalid(true);
document.setInvalidType(true);
}
@@ -98,10 +98,11 @@ public class ProjectRequestDocumentFactory {
List<String> dependencies = new ArrayList<>();
dependencies.addAll(request.getStyle());
dependencies.addAll(request.getDependencies());
dependencies.forEach( id -> {
if (metadata.getDependencies().get(id)!=null) {
dependencies.forEach(id -> {
if (metadata.getDependencies().get(id) != null) {
document.getDependencies().add(id);
} else {
}
else {
document.setInvalid(true);
document.getInvalidDependencies().add(id);
}
@@ -111,7 +112,7 @@ public class ProjectRequestDocumentFactory {
if (event instanceof ProjectFailedEvent) {
ProjectFailedEvent failed = (ProjectFailedEvent) event;
document.setInvalid(true);
if (failed.getCause()!=null) {
if (failed.getCause() != null) {
document.setErrorMessage(failed.getCause().getMessage());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,14 +16,14 @@
package io.spring.initializr.actuate;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import io.spring.initializr.web.AbstractFullStackInitializrIntegrationTests;
import org.json.JSONObject;
import org.junit.Test;
import org.springframework.test.context.ActiveProfiles;
import io.spring.initializr.web.AbstractFullStackInitializrIntegrationTests;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Tests for actuator specific features.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,18 +16,18 @@
package io.spring.initializr.actuate.info;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import java.util.Map;
import org.junit.Test;
import org.springframework.boot.actuate.info.Info;
import io.spring.initializr.metadata.BillOfMaterials;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.metadata.SimpleInitializrMetadataProvider;
import io.spring.initializr.test.metadata.InitializrMetadataTestBuilder;
import org.junit.Test;
import org.springframework.boot.actuate.info.Info;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
/**
* Tests for {@link BomRangesInfoContributor}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,12 +16,20 @@
package io.spring.initializr.actuate.metric;
import static org.junit.Assert.assertTrue;
import io.spring.initializr.actuate.metric.MetricsExportTests.Config;
import io.spring.initializr.actuate.test.RedisRunning;
import io.spring.initializr.generator.ProjectGeneratedEvent;
import io.spring.initializr.generator.ProjectRequest;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.metadata.InitializrMetadataBuilder;
import io.spring.initializr.metadata.InitializrMetadataProvider;
import io.spring.initializr.metadata.InitializrProperties;
import io.spring.initializr.metadata.SimpleInitializrMetadataProvider;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.actuate.metrics.repository.redis.RedisMetricRepository;
@@ -33,15 +41,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringRunner;
import io.spring.initializr.actuate.metric.MetricsExportTests.Config;
import io.spring.initializr.actuate.test.RedisRunning;
import io.spring.initializr.generator.ProjectGeneratedEvent;
import io.spring.initializr.generator.ProjectRequest;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.metadata.InitializrMetadataBuilder;
import io.spring.initializr.metadata.InitializrMetadataProvider;
import io.spring.initializr.metadata.InitializrProperties;
import io.spring.initializr.metadata.SimpleInitializrMetadataProvider;
import static org.junit.Assert.assertTrue;
/**
* @author Dave Syer

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,9 +18,6 @@ package io.spring.initializr.actuate.metric;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
import io.spring.initializr.actuate.test.MetricsAssert;
import io.spring.initializr.actuate.test.TestCounterService;
import io.spring.initializr.generator.ProjectFailedEvent;
@@ -29,6 +26,8 @@ import io.spring.initializr.generator.ProjectRequest;
import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.test.metadata.InitializrMetadataTestBuilder;
import org.junit.Before;
import org.junit.Test;
/**
* @author Stephane Nicoll
@@ -237,7 +236,7 @@ public class ProjectGenerationMetricsListenerTests {
@Test
public void incrementMetrics() {
ProjectRequest request = initialize();
request.getStyle().addAll(Arrays.asList("security","spring-data"));
request.getStyle().addAll(Arrays.asList("security", "spring-data"));
request.resolve(metadata);
fireProjectGeneratedEvent(request);
metricsAssert.hasValue(1, "initializr.requests",

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,20 +16,17 @@
package io.spring.initializr.actuate.stat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import io.spring.initializr.actuate.stat.MainControllerStatsIntegrationTests.StatsMockController;
import io.spring.initializr.web.AbstractFullStackInitializrIntegrationTests;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Import;
import org.springframework.http.HttpHeaders;
@@ -42,9 +39,11 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.HttpClientErrorException;
import io.spring.initializr.actuate.stat.MainControllerStatsIntegrationTests.StatsMockController;
import io.spring.initializr.actuate.stat.MainControllerStatsIntegrationTests.StatsMockController.Content;
import io.spring.initializr.web.AbstractFullStackInitializrIntegrationTests;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* Integration tests for stats processing.
@@ -66,14 +65,14 @@ public class MainControllerStatsIntegrationTests
public void setup() {
this.statsMockController.stats.clear();
// Make sure our mock is going to be invoked with the stats
this.statsProperties.getElastic().setUri( "http://localhost:" + port + "/elastic");
this.statsProperties.getElastic().setUri("http://localhost:" + port + "/elastic");
}
@Test
public void simpleProject() {
downloadArchive("/starter.zip?groupId=com.foo&artifactId=bar&dependencies=web");
assertEquals("No stat got generated", 1, statsMockController.stats.size());
Content content = statsMockController.stats.get(0);
StatsMockController.Content content = statsMockController.stats.get(0);
JSONObject json = new JSONObject(content.json);
assertEquals("com.foo", json.get("groupId"));
@@ -87,7 +86,7 @@ public class MainControllerStatsIntegrationTests
public void authorizationHeaderIsSet() {
downloadArchive("/starter.zip");
assertEquals("No stat got generated", 1, statsMockController.stats.size());
Content content = statsMockController.stats.get(0);
StatsMockController.Content content = statsMockController.stats.get(0);
String authorization = content.authorization;
assertNotNull("Authorization header must be set", authorization);
@@ -102,7 +101,7 @@ public class MainControllerStatsIntegrationTests
public void requestIpNotSetByDefault() {
downloadArchive("/starter.zip?groupId=com.foo&artifactId=bar&dependencies=web");
assertEquals("No stat got generated", 1, statsMockController.stats.size());
Content content = statsMockController.stats.get(0);
StatsMockController.Content content = statsMockController.stats.get(0);
JSONObject json = new JSONObject(content.json);
assertFalse("requestIp property should not be set", json.has("requestIp"));
@@ -114,7 +113,7 @@ public class MainControllerStatsIntegrationTests
.header("X-FORWARDED-FOR", "10.0.0.123").build();
getRestTemplate().exchange(request, String.class);
assertEquals("No stat got generated", 1, statsMockController.stats.size());
Content content = statsMockController.stats.get(0);
StatsMockController.Content content = statsMockController.stats.get(0);
JSONObject json = new JSONObject(content.json);
assertEquals("Wrong requestIp", "10.0.0.123", json.get("requestIp"));
@@ -126,7 +125,7 @@ public class MainControllerStatsIntegrationTests
.header("x-forwarded-for", "foo-bar").build();
getRestTemplate().exchange(request, String.class);
assertEquals("No stat got generated", 1, statsMockController.stats.size());
Content content = statsMockController.stats.get(0);
StatsMockController.Content content = statsMockController.stats.get(0);
JSONObject json = new JSONObject(content.json);
assertFalse("requestIpv4 property should not be set if value is not a valid IPv4",
@@ -139,7 +138,7 @@ public class MainControllerStatsIntegrationTests
.header("cf-ipcountry", "XX").build();
getRestTemplate().exchange(request, String.class);
assertEquals("No stat got generated", 1, statsMockController.stats.size());
Content content = statsMockController.stats.get(0);
StatsMockController.Content content = statsMockController.stats.get(0);
JSONObject json = new JSONObject(content.json);
assertFalse("requestCountry property should not be set if value is set to xx",
@@ -151,11 +150,12 @@ public class MainControllerStatsIntegrationTests
try {
downloadArchive("/starter.zip?type=invalid-type");
fail("Should have failed to generate project with invalid type");
} catch (HttpClientErrorException ex) {
}
catch (HttpClientErrorException ex) {
assertEquals(HttpStatus.BAD_REQUEST, ex.getStatusCode());
}
assertEquals("No stat got generated", 1, statsMockController.stats.size());
Content content = statsMockController.stats.get(0);
StatsMockController.Content content = statsMockController.stats.get(0);
JSONObject json = new JSONObject(content.json);
assertEquals("com.example", json.get("groupId"));

View File

@@ -1,14 +1,14 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 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 obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an \"AS IS\" BASIS,
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
@@ -16,16 +16,15 @@
package io.spring.initializr.actuate.stat;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.jsonPath;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus;
import java.util.Collections;
import java.util.UUID;
import io.spring.initializr.actuate.stat.StatsProperties.Elastic;
import io.spring.initializr.generator.ProjectGeneratedEvent;
import io.spring.initializr.generator.ProjectRequest;
import org.junit.Before;
import org.junit.Test;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
@@ -33,9 +32,10 @@ import org.springframework.retry.policy.SimpleRetryPolicy;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.test.web.client.MockRestServiceServer;
import io.spring.initializr.actuate.stat.StatsProperties.Elastic;
import io.spring.initializr.generator.ProjectGeneratedEvent;
import io.spring.initializr.generator.ProjectRequest;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.jsonPath;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus;
/**
* @author Stephane Nicoll
@@ -69,9 +69,8 @@ public class ProjectGenerationStatPublisherTests extends AbstractInitializrStatT
.andExpect(jsonPath("$.groupId").value("com.example.foo"))
.andExpect(jsonPath("$.artifactId").value("my-project"))
.andRespond(withStatus(HttpStatus.CREATED)
.body(mockResponse(UUID.randomUUID().toString(), true))
.contentType(MediaType.APPLICATION_JSON)
);
.body(mockResponse(UUID.randomUUID().toString(), true))
.contentType(MediaType.APPLICATION_JSON));
this.statPublisher.handleEvent(new ProjectGeneratedEvent(request));
mockServer.verify();
@@ -92,8 +91,8 @@ public class ProjectGenerationStatPublisherTests extends AbstractInitializrStatT
mockServer.expect(requestTo("http://example.com/elastic/initializr/request"))
.andExpect(method(HttpMethod.POST))
.andRespond(withStatus(HttpStatus.CREATED)
.body(mockResponse(UUID.randomUUID().toString(), true))
.contentType(MediaType.APPLICATION_JSON));
.body(mockResponse(UUID.randomUUID().toString(), true))
.contentType(MediaType.APPLICATION_JSON));
this.statPublisher.handleEvent(new ProjectGeneratedEvent(request));
mockServer.verify();
@@ -103,7 +102,7 @@ public class ProjectGenerationStatPublisherTests extends AbstractInitializrStatT
public void fatalErrorOnlyLogs() {
ProjectRequest request = createProjectRequest();
this.retryTemplate.setRetryPolicy(new SimpleRetryPolicy(2,
Collections.<Class<? extends Throwable>, Boolean> singletonMap(Exception.class, true)));
Collections.singletonMap(Exception.class, true)));
mockServer.expect(requestTo("http://example.com/elastic/initializr/request"))
.andExpect(method(HttpMethod.POST))

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,18 +16,17 @@
package io.spring.initializr.actuate.stat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import org.junit.Test;
import io.spring.initializr.generator.ProjectFailedEvent;
import io.spring.initializr.generator.ProjectGeneratedEvent;
import io.spring.initializr.generator.ProjectRequest;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/**
*
@@ -60,7 +59,7 @@ public class ProjectRequestDocumentFactoryTests extends AbstractInitializrStatTe
@Test
public void createDocumentWithRequestIp() {
ProjectRequest request = createProjectRequest();
request.getParameters().put("x-forwarded-for","10.0.0.123");
request.getParameters().put("x-forwarded-for", "10.0.0.123");
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request);
ProjectRequestDocument document = factory.createDocument(event);
assertEquals("10.0.0.123", document.getRequestIp());
@@ -83,7 +82,7 @@ public class ProjectRequestDocumentFactoryTests extends AbstractInitializrStatTe
public void createDocumentWithCloudFlareHeaders() {
ProjectRequest request = createProjectRequest();
request.getParameters().put("cf-connecting-ip", "10.0.0.123");
request.getParameters().put("cf-ipcountry","BE");
request.getParameters().put("cf-ipcountry", "BE");
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request);
ProjectRequestDocument document = factory.createDocument(event);
assertEquals("10.0.0.123", document.getRequestIp());
@@ -126,7 +125,7 @@ public class ProjectRequestDocumentFactoryTests extends AbstractInitializrStatTe
@Test
public void createDocumentWithUserAgent() {
ProjectRequest request = createProjectRequest();
request.getParameters().put("user-agent","HTTPie/0.8.0");
request.getParameters().put("user-agent", "HTTPie/0.8.0");
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request);
ProjectRequestDocument document = factory.createDocument(event);
assertEquals("httpie", document.getClientId());
@@ -136,7 +135,7 @@ public class ProjectRequestDocumentFactoryTests extends AbstractInitializrStatTe
@Test
public void createDocumentWithUserAgentNoVersion() {
ProjectRequest request = createProjectRequest();
request.getParameters().put("user-agent","IntelliJ IDEA");
request.getParameters().put("user-agent", "IntelliJ IDEA");
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request);
ProjectRequestDocument document = factory.createDocument(event);
assertEquals("intellijidea", document.getClientId());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,11 +16,10 @@
package io.spring.initializr.actuate.stat;
import io.spring.initializr.actuate.stat.StatsProperties;
import org.junit.Test;
import static org.junit.Assert.assertThat;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
/**
* @author Stephane Nicoll

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,11 +16,11 @@
package io.spring.initializr.actuate.test;
import java.util.Arrays;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.util.Arrays;
/**
* Metrics assertion based on {@link TestCounterService}.
*

View File

@@ -20,6 +20,7 @@ import org.junit.Assume;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
/**
@@ -39,7 +40,8 @@ public class RedisRunning extends TestWatcher {
}
try {
connectionFactory.getConnection();
} catch (Exception e) {
}
catch (Exception e) {
Assume.assumeNoException("Cannot connect to Redis (so skipping tests)", e);
}
return super.apply(base, description);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,14 +33,14 @@ public class TestCounterService implements CounterService {
@Override
public void increment(String metricName) {
Long value = getValues().get(metricName);
Long valueToSet = value!=null ? ++value : 1;
Long valueToSet = value != null ? ++value : 1;
getValues().put(metricName, valueToSet);
}
@Override
public void decrement(String metricName) {
Long value = getValues().get(metricName);
Long valueToSet = value!=null ? +--value : -1;
Long valueToSet = value != null ? +--value : -1;
getValues().put(metricName, valueToSet);
}

View File

@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.spring.initializr</groupId>

View File

@@ -21,13 +21,13 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.beans.BeanWrapperImpl;
import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.metadata.Type;
import io.spring.initializr.util.TemplateRenderer;
import org.springframework.beans.BeanWrapperImpl;
/**
* Generate help pages for command-line clients.
*

View File

@@ -28,16 +28,6 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.util.Assert;
import org.springframework.util.FileSystemUtils;
import org.springframework.util.StreamUtils;
import io.spring.initializr.InitializrException;
import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.metadata.InitializrConfiguration.Env.Maven.ParentPom;
@@ -45,6 +35,16 @@ import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.metadata.InitializrMetadataProvider;
import io.spring.initializr.util.TemplateRenderer;
import io.spring.initializr.util.Version;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.util.Assert;
import org.springframework.util.FileSystemUtils;
import org.springframework.util.StreamUtils;
/**
* Generate a project based on the configured metadata.
@@ -384,17 +384,17 @@ public class ProjectGenerator {
Map<String, String> versions = new LinkedHashMap<String, String>();
model.put("buildPropertiesVersions", versions.entrySet());
request.getBuildProperties().getVersions().forEach((k,v) -> {
request.getBuildProperties().getVersions().forEach((k, v) -> {
versions.put(k, v.get());
});
Map<String, String> gradle = new LinkedHashMap<String, String>();
model.put("buildPropertiesGradle", gradle.entrySet());
request.getBuildProperties().getGradle().forEach((k,v) -> {
request.getBuildProperties().getGradle().forEach((k, v) -> {
gradle.put(k, v.get());
});
Map<String, String> maven = new LinkedHashMap<String, String>();
model.put("buildPropertiesMaven", maven.entrySet());
request.getBuildProperties().getMaven().forEach((k,v) -> {
request.getBuildProperties().getMaven().forEach((k, v) -> {
maven.put(k, v.get());
});
@@ -404,7 +404,7 @@ public class ProjectGenerator {
model.put("kotlinVersion",
metadata.getConfiguration().getEnv().getKotlin().getVersion());
if ("kotlin".equals(request.getLanguage())) {
model.put("kotlin", true);
model.put("kotlin", true);
}
if ("groovy".equals(request.getLanguage())) {
model.put("groovy", true);
@@ -423,7 +423,7 @@ public class ProjectGenerator {
model.put("springBootPluginName",
(VERSION_1_4_2_M1
.compareTo(Version.safeParse(request.getBootVersion())) <= 0
? "org.springframework.boot" : "spring-boot"));
? "org.springframework.boot" : "spring-boot"));
// New testing stuff
model.put("newTestInfrastructure", isNewTestInfrastructureAvailable(request));

View File

@@ -22,9 +22,6 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.util.StringUtils;
import io.spring.initializr.metadata.BillOfMaterials;
import io.spring.initializr.metadata.DefaultMetadataElement;
import io.spring.initializr.metadata.Dependency;
@@ -33,6 +30,9 @@ import io.spring.initializr.metadata.Repository;
import io.spring.initializr.metadata.Type;
import io.spring.initializr.util.Version;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.util.StringUtils;
/**
* A request to generate a project.
*

View File

@@ -1,12 +1,28 @@
/*
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.spring.initializr.generator;
import java.util.ArrayList;
import java.util.List;
import org.springframework.util.Assert;
import io.spring.initializr.metadata.InitializrMetadata;
import org.springframework.util.Assert;
/**
* Resolve {@link ProjectRequest} instances, honouring callback hook points.
*

View File

@@ -22,7 +22,6 @@ import java.util.List;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.spring.initializr.util.InvalidVersionException;
import io.spring.initializr.util.Version;
import io.spring.initializr.util.VersionParser;

View File

@@ -45,7 +45,7 @@ public class DefaultMetadataElement extends MetadataElement {
public boolean isDefault() {
return this.defaultValue;
}
public static DefaultMetadataElement create(String id, boolean defaultValue) {
return new DefaultMetadataElement(id, defaultValue);
}

View File

@@ -24,7 +24,6 @@ import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.spring.initializr.util.VersionParser;
/**

View File

@@ -21,16 +21,15 @@ import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;
import org.springframework.util.StringUtils;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.spring.initializr.util.InvalidVersionException;
import io.spring.initializr.util.Version;
import io.spring.initializr.util.VersionParser;
import io.spring.initializr.util.VersionRange;
import org.springframework.util.StringUtils;
/**
* Meta-data for a dependency. Each dependency has a primary identifier and an arbitrary
* number of {@code aliases}.
@@ -38,7 +37,6 @@ import io.spring.initializr.util.VersionRange;
* @author Stephane Nicoll
*/
@JsonInclude(JsonInclude.Include.NON_EMPTY)
// @AutoClone(style = AutoCloneStyle.COPY_CONSTRUCTOR)
public class Dependency extends MetadataElement implements Describable {
public static final String SCOPE_COMPILE = "compile";
@@ -249,7 +247,7 @@ public class Dependency extends MetadataElement implements Describable {
* Specify if this dependency is available for the specified Spring Boot version.
*/
public boolean match(Version version) {
if (range!=null) {
if (range != null) {
return range.match(version);
}
return true;

View File

@@ -55,7 +55,7 @@ public class DependencyGroup {
private String repository;
final List<Dependency> content = new ArrayList<>();
public String getName() {
return name;
}
@@ -96,6 +96,6 @@ public class DependencyGroup {
DependencyGroup group = new DependencyGroup();
group.setName(name);
return group;
}
}
}

View File

@@ -40,7 +40,7 @@ public class DependencyMetadata {
}
public DependencyMetadata(Version bootVersion, Map<String, Dependency> dependencies,
Map<String, Repository> repositories, Map<String, BillOfMaterials> boms) {
Map<String, Repository> repositories, Map<String, BillOfMaterials> boms) {
this.bootVersion = bootVersion;
this.dependencies = dependencies;
this.repositories = repositories;

View File

@@ -462,8 +462,8 @@ public class InitializrConfiguration {
&& !StringUtils.hasText(artifactId)
&& !StringUtils.hasText(version))
|| (StringUtils.hasText(groupId)
&& StringUtils.hasText(artifactId)
&& StringUtils.hasText(version)))) {
&& StringUtils.hasText(artifactId)
&& StringUtils.hasText(version)))) {
throw new InvalidInitializrMetadataException("Custom maven pom "
+ "requires groupId, artifactId and version");
}

View File

@@ -20,14 +20,14 @@ import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource;
import org.springframework.util.StreamUtils;
import org.springframework.util.StringUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* Builder for {@link InitializrMetadata}. Allows to read metadata from any arbitrary
* resource, including remote URLs.

View File

@@ -19,11 +19,11 @@ package io.spring.initializr.metadata;
import java.util.ArrayList;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.StringUtils;
import com.fasterxml.jackson.annotation.JsonIgnore;
/**
* Configuration of the initializr service.
*

View File

@@ -68,14 +68,14 @@ public class Link {
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
private String description;
public Link() {
}
private Link(String rel, String href) {
this(rel, href, (String)null);
this(rel, href, null);
}
private Link(String rel, String href, String description) {
this.rel = rel;
this.href = href;
@@ -124,11 +124,11 @@ public class Link {
}
public void resolve() {
if (rel==null) {
if (rel == null) {
throw new InvalidInitializrMetadataException(
"Invalid link " + this + ": rel attribute is mandatory");
}
if (href==null) {
if (href == null) {
throw new InvalidInitializrMetadataException(
"Invalid link " + this + ": href attribute is mandatory");
}
@@ -147,13 +147,13 @@ public class Link {
*/
public URI expand(Map<String, String> parameters) {
AtomicReference<String> result = new AtomicReference<String>(href);
templateVariables.forEach( var -> {
templateVariables.forEach(var -> {
Object value = parameters.get(var);
if (value==null) {
if (value == null) {
throw new IllegalArgumentException(
"Could not expand " + href + ", missing value for '" + var + "'");
}
result.set(result.get().replace("{" + var+"}", value.toString()));
result.set(result.get().replace("{" + var + "}", value.toString()));
});
try {
return new URI(result.get());

View File

@@ -33,7 +33,7 @@ public class MetadataElement {
* The unique id of this element for a given capability.
*/
private String id;
public MetadataElement() {
}
@@ -47,7 +47,7 @@ public class MetadataElement {
}
public String getName() {
return name!=null ? name: id;
return name != null ? name : id;
}
public String getId() {

View File

@@ -16,12 +16,12 @@
package io.spring.initializr.metadata;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* Defines a capability of the initializr service. Each capability is defined by a id and
* a {@link ServiceCapabilityType type}.

View File

@@ -56,7 +56,7 @@ public class TypeCapability extends ServiceCapability<List<Type>> implements Def
@Override
public void merge(List<Type> otherContent) {
otherContent.forEach(it -> {
if (get(it.getId())==null) {
if (get(it.getId()) == null) {
content.add(it);
}
});

View File

@@ -22,16 +22,16 @@ import java.nio.charset.Charset;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.ResourceLoader;
import org.springframework.util.ConcurrentReferenceHashMap;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Mustache.Compiler;
import com.samskivert.mustache.Mustache.TemplateLoader;
import com.samskivert.mustache.Template;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.ResourceLoader;
import org.springframework.util.ConcurrentReferenceHashMap;
/**
* @author Dave Syer

View File

@@ -81,9 +81,9 @@ public final class Version implements Serializable, Comparable<Version> {
@Override
public String toString() {
return major + "." + minor + "." + patch +
(qualifier!=null ? "." + qualifier.qualifier +
(qualifier.version!=null ? qualifier.version : "") : "");
return major + "." + minor + "." + patch +
(qualifier != null ? "." + qualifier.qualifier +
(qualifier.version != null ? qualifier.version : "") : "");
}
/**
@@ -109,7 +109,8 @@ public final class Version implements Serializable, Comparable<Version> {
public static Version safeParse(String text) {
try {
return parse(text);
} catch (InvalidVersionException e) {
}
catch (InvalidVersionException e) {
return null;
}
}
@@ -135,37 +136,45 @@ public final class Version implements Serializable, Comparable<Version> {
}
private static int safeCompare(Integer first, Integer second) {
Integer firstIndex = first !=null ? first : 0;
Integer secondIndex = second !=null ? second : 0;
Integer firstIndex = first != null ? first : 0;
Integer secondIndex = second != null ? second : 0;
return firstIndex.compareTo(secondIndex);
}
public static class Qualifier {
public Qualifier() {
}
public Qualifier(String qualifier) {
this.qualifier = qualifier;
}
String qualifier;
Integer version;
public String getQualifier() {
return qualifier;
}
public void setQualifier(String qualifier) {
this.qualifier = qualifier;
}
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
@Override
public String toString() {
return "Qualifier ["
+ (qualifier != null ? "qualifier=" + qualifier + ", " : "")
+ (version != null ? "version=" + version : "") + "]";
}
@Override
public int hashCode() {
final int prime = 31;
@@ -174,6 +183,7 @@ public final class Version implements Serializable, Comparable<Version> {
result = prime * result + ((version == null) ? 0 : version.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
@@ -258,16 +268,16 @@ public final class Version implements Serializable, Comparable<Version> {
@Override
public int compare(Qualifier o1, Qualifier o2) {
Qualifier first = o1!=null ? o1 : new Qualifier(RELEASE);
Qualifier second = o2!=null ? o2 : new Qualifier(RELEASE);
Qualifier first = o1 != null ? o1 : new Qualifier(RELEASE);
Qualifier second = o2 != null ? o2 : new Qualifier(RELEASE);
int qualifier = compareQualifier(first, second);
return qualifier!=0 ? qualifier : compareQualifierVersion(first, second);
return qualifier != 0 ? qualifier : compareQualifierVersion(first, second);
}
private static int compareQualifierVersion(Qualifier first, Qualifier second) {
Integer firstVersion = first.getVersion()!=null ? first.getVersion() : 0;
Integer secondVersion = second.getVersion()!=null ? second.getVersion(): 0;
Integer firstVersion = first.getVersion() != null ? first.getVersion() : 0;
Integer secondVersion = second.getVersion() != null ? second.getVersion() : 0;
return firstVersion.compareTo(secondVersion);
}
@@ -277,13 +287,15 @@ public final class Version implements Serializable, Comparable<Version> {
if (firstIndex == -1 && secondIndex == -1) { // Unknown qualifier, alphabetic ordering
return first.qualifier.compareTo(second.qualifier);
} else {
}
else {
return firstIndex.compareTo(secondIndex);
}
}
private static int getQualifierIndex(String qualifier) {
return StringUtils.hasText(qualifier) ? KNOWN_QUALIFIERS.indexOf(qualifier) : 0;
return StringUtils.hasText(qualifier) ? KNOWN_QUALIFIERS.indexOf(qualifier)
: 0;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,11 +22,11 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import io.spring.initializr.util.Version.Qualifier;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import io.spring.initializr.util.Version.Qualifier;
/**
* Parser for {@link Version} and {@link VersionRange} that allows to resolve the minor
* and patch value against a configurable list of "latest versions".
@@ -84,12 +84,14 @@ public class VersionParser {
if ("x".equals(minor) || "x".equals(patch)) {
Integer minorInt = "x".equals(minor) ? null : Integer.parseInt(minor);
Version latest = findLatestVersion(major, minorInt, qualifier);
if (latest==null) {
return new Version(major, ("x".equals(minor) ? 999 : Integer.parseInt(minor)),
if (latest == null) {
return new Version(major, ("x".equals(minor) ? 999
: Integer.parseInt(minor)),
("x".equals(patch) ? 999 : Integer.parseInt(patch)), qualifier);
}
return new Version(major, latest.getMinor(), latest.getPatch(), latest.getQualifier());
} else {
}
else {
return new Version(major, Integer.parseInt(minor), Integer.parseInt(patch), qualifier);
}
}
@@ -105,7 +107,8 @@ public class VersionParser {
public Version safeParse(String text) {
try {
return parse(text);
} catch (InvalidVersionException ex) {
}
catch (InvalidVersionException ex) {
return null;
}
}
@@ -133,15 +136,15 @@ public class VersionParser {
}
private Version findLatestVersion(Integer major, Integer minor,
Version.Qualifier qualifier) {
Version.Qualifier qualifier) {
List<Version> matches = this.latestVersions.stream().filter(it -> {
if (major!=null && !major.equals(it.getMajor())) {
if (major != null && !major.equals(it.getMajor())) {
return false;
}
if (minor!=null && !minor.equals(it.getMinor())) {
if (minor != null && !minor.equals(it.getMinor())) {
return false;
}
if (qualifier!=null && !qualifier.equals(it.getQualifier())) {
if (qualifier != null && !qualifier.equals(it.getQualifier())) {
return false;
}
return true;

View File

@@ -40,7 +40,7 @@ public class VersionRange {
final boolean lowerInclusive;
final Version higherVersion;
final boolean higherInclusive;
// For Jackson
@SuppressWarnings("unused")
private VersionRange() {
@@ -48,7 +48,7 @@ public class VersionRange {
}
protected VersionRange(Version lowerVersion, boolean lowerInclusive,
Version higherVersion, boolean higherInclusive) {
Version higherVersion, boolean higherInclusive) {
this.lowerVersion = lowerVersion;
this.lowerInclusive = lowerInclusive;
this.higherVersion = higherVersion;
@@ -64,14 +64,16 @@ public class VersionRange {
int lower = lowerVersion.compareTo(version);
if (lower > 0) {
return false;
} else if (!lowerInclusive && lower == 0) {
}
else if (!lowerInclusive && lower == 0) {
return false;
}
if (higherVersion!=null) {
if (higherVersion != null) {
int higher = higherVersion.compareTo(version);
if (higher < 0) {
return false;
} else if (!higherInclusive && higher == 0) {
}
else if (!higherInclusive && higher == 0) {
return false;
}
}
@@ -95,13 +97,12 @@ public class VersionRange {
}
@Override
public
String toString() {
public String toString() {
StringBuffer sb = new StringBuffer();
if (lowerVersion!=null) {
if (lowerVersion != null) {
sb.append((lowerInclusive ? ">=" : ">") + lowerVersion);
}
if (higherVersion!=null) {
if (higherVersion != null) {
sb.append(" and " + (higherInclusive ? "<=" : "<") + higherVersion);
}
return sb.toString();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,22 +16,11 @@
package io.spring.initializr.generator;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;
import org.mockito.ArgumentMatcher;
import org.springframework.context.ApplicationEventPublisher;
import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.metadata.SimpleInitializrMetadataProvider;
@@ -39,6 +28,17 @@ import io.spring.initializr.test.generator.GradleBuildAssert;
import io.spring.initializr.test.generator.PomAssert;
import io.spring.initializr.test.generator.ProjectAssert;
import io.spring.initializr.test.metadata.InitializrMetadataTestBuilder;
import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;
import org.mockito.ArgumentMatcher;
import org.springframework.context.ApplicationEventPublisher;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
/**
*
@@ -97,8 +97,7 @@ public abstract class AbstractProjectGeneratorTests {
projectGenerator.setMetadataProvider(new SimpleInitializrMetadataProvider(metadata));
}
protected void verifyProjectSuccessfulEventFor(ProjectRequest request)
{
protected void verifyProjectSuccessfulEventFor(ProjectRequest request) {
verify(eventPublisher, times(1)).publishEvent(argThat(new ProjectGeneratedEventMatcher(request)));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,18 +16,17 @@
package io.spring.initializr.generator;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import org.junit.Before;
import org.junit.Test;
import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.metadata.Type;
import io.spring.initializr.test.metadata.InitializrMetadataTestBuilder;
import io.spring.initializr.util.TemplateRenderer;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
/**
* @author Stephane Nicoll
@@ -35,7 +34,7 @@ import io.spring.initializr.util.TemplateRenderer;
public class CommandLineHelpGeneratorTests {
private CommandLineHelpGenerator generator;
@Before
public void init() {
generator = new CommandLineHelpGenerator(new TemplateRenderer());
@@ -111,7 +110,7 @@ public class CommandLineHelpGeneratorTests {
createDependency("id-b", "depB"),
createDependency("id-a", "depA", "and some description")).build();
String content = generator.generateSpringBootCliCapabilities(metadata, "https://fake-service");
assertThat(content, containsString("| Id"));
assertThat(content, containsString("| Id"));
assertThat(content, containsString("| Tags"));
assertThat(content, containsString("id-a | and some description |"));
assertThat(content, containsString("id-b | depB"));

View File

@@ -16,16 +16,16 @@
package io.spring.initializr.generator;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.springframework.core.io.ClassPathResource;
import io.spring.initializr.metadata.BillOfMaterials;
import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.test.generator.ProjectAssert;
import io.spring.initializr.test.metadata.InitializrMetadataTestBuilder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.springframework.core.io.ClassPathResource;
/**
* Project generator tests for supported build systems.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,15 +16,15 @@
package io.spring.initializr.generator;
import static io.spring.initializr.test.generator.ProjectAssert.DEFAULT_APPLICATION_NAME;
import static io.spring.initializr.test.generator.ProjectAssert.DEFAULT_PACKAGE_NAME;
import io.spring.initializr.test.generator.ProjectAssert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.springframework.core.io.ClassPathResource;
import io.spring.initializr.test.generator.ProjectAssert;
import static io.spring.initializr.test.generator.ProjectAssert.DEFAULT_APPLICATION_NAME;
import static io.spring.initializr.test.generator.ProjectAssert.DEFAULT_PACKAGE_NAME;
/**
* Project generator tests for supported languages.
@@ -121,7 +121,7 @@ public class ProjectGeneratorLanguageTests extends AbstractProjectGeneratorTests
ProjectRequest request = createProjectRequest();
request.setLanguage(language);
request.setPackaging("war");
if (bootVersion!=null) {
if (bootVersion != null) {
request.setBootVersion(bootVersion);
}
ProjectAssert project = generateProject(request);

View File

@@ -16,26 +16,26 @@
package io.spring.initializr.generator;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import java.util.Collections;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import io.spring.initializr.metadata.BillOfMaterials;
import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.test.generator.ProjectAssert;
import io.spring.initializr.test.metadata.InitializrMetadataTestBuilder;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
/**
* Tests for {@link ProjectGenerator}
@@ -186,10 +186,8 @@ public class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
generateGradleBuild(request)
.contains(
"compile('org.springframework.boot:spring-boot-starter-data-jpa')")
.contains("compile('org.springframework.boot:spring-boot-starter-web')") // Added
// by
// war
// packaging
// Added by warpackaging
.contains("compile('org.springframework.boot:spring-boot-starter-web')")
.contains(
"testCompile('org.springframework.boot:spring-boot-starter-test')")
.contains("configurations {") // declare providedRuntime config
@@ -464,9 +462,8 @@ public class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
.contains("compile('org.springframework.boot:spring-boot-starter-web')")
.contains(
"compile('org.springframework.boot:spring-boot-starter-data-jpa')")
.contains("runtime('org.h2:h2')").contains("configurations {") // declare
// providedRuntime
// config
// declare providedRuntime config
.contains("runtime('org.h2:h2')").contains("configurations {")
.contains("providedRuntime")
.contains("providedRuntime('javax.servlet:servlet-api')")
.contains("testCompile('org.hamcrest:hamcrest')");

View File

@@ -1,6 +1,20 @@
package io.spring.initializr.generator;
/*
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import static org.junit.Assert.*;
package io.spring.initializr.generator;
import java.util.ArrayList;
import java.util.Arrays;
@@ -8,12 +22,14 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.BeanWrapperImpl;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.test.metadata.InitializrMetadataTestBuilder;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.BeanWrapperImpl;
import static org.junit.Assert.assertEquals;
/**
* Tests for {@link ProjectRequestResolver}.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,20 +16,19 @@
package io.spring.initializr.generator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.util.Arrays;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import io.spring.initializr.metadata.BillOfMaterials;
import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.metadata.InitializrMetadataBuilder;
import io.spring.initializr.test.metadata.InitializrMetadataTestBuilder;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
/**
* @author Stephane Nicoll

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,20 +16,19 @@
package io.spring.initializr.metadata;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.junit.Assert.assertThat;
import java.util.Arrays;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import io.spring.initializr.metadata.BillOfMaterials.Mapping;
import io.spring.initializr.util.Version;
import io.spring.initializr.util.VersionParser;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.junit.Assert.assertThat;
/**
* @author Stephane Nicoll

View File

@@ -16,18 +16,17 @@
package io.spring.initializr.metadata;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import java.util.Arrays;
import io.spring.initializr.util.Version;
import io.spring.initializr.util.VersionParser;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import io.spring.initializr.util.Version;
import io.spring.initializr.util.VersionParser;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
/**
* @author Stephane Nicoll

View File

@@ -16,14 +16,12 @@
package io.spring.initializr.metadata;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.net.URL;
import java.util.Map;
import java.util.Properties;
import org.junit.Test;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.boot.bind.PropertiesConfigurationFactory;
import org.springframework.core.env.MutablePropertySources;
@@ -31,6 +29,9 @@ import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* @author Stephane Nicoll
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,18 +16,17 @@
package io.spring.initializr.metadata;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Arrays;
import java.util.List;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import io.spring.initializr.metadata.BillOfMaterials.Mapping;
import io.spring.initializr.test.metadata.InitializrMetadataTestBuilder;
import io.spring.initializr.util.Version;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Stephane Nicoll

View File

@@ -16,10 +16,6 @@
package io.spring.initializr.metadata;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.net.URI;
import java.util.Collections;
import java.util.LinkedHashMap;
@@ -29,6 +25,10 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Tests for {@link Link}.
*

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,7 +36,7 @@ public class SingleSelectCapabilityTests {
public void defaultNoDefault() {
SingleSelectCapability capability = new SingleSelectCapability("test");
capability.getContent().add(DefaultMetadataElement.create("foo", false));
capability.getContent().add(DefaultMetadataElement.create("bar",false));
capability.getContent().add(DefaultMetadataElement.create("bar", false));
assertNull(capability.getDefault());
}
@@ -44,7 +44,7 @@ public class SingleSelectCapabilityTests {
public void defaultType() {
SingleSelectCapability capability = new SingleSelectCapability("test");
capability.getContent().add(DefaultMetadataElement.create("foo", false));
DefaultMetadataElement second = DefaultMetadataElement.create("bar",true);
DefaultMetadataElement second = DefaultMetadataElement.create("bar", true);
capability.getContent().add(second);
assertEquals(second, capability.getDefault());
}
@@ -56,7 +56,7 @@ public class SingleSelectCapabilityTests {
capability.getContent().add(foo);
SingleSelectCapability anotherCapability = new SingleSelectCapability("test");
DefaultMetadataElement bar =DefaultMetadataElement.create("bar", false);
DefaultMetadataElement bar = DefaultMetadataElement.create("bar", false);
anotherCapability.getContent().add(bar);
capability.merge(anotherCapability);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,10 +16,10 @@
package io.spring.initializr.metadata;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* @author Stephane Nicoll
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,11 +16,11 @@
package io.spring.initializr.metadata;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.junit.Test;
/**
* @author Stephane Nicoll
*/
@@ -63,20 +63,20 @@ public class TypeCapabilityTests {
@Test
public void mergeAddEntry() {
TypeCapability capability = new TypeCapability();
Type first = new Type();
first.setId("foo");
first.setDefault(false);
capability.getContent().add(first);
Type first = new Type();
first.setId("foo");
first.setDefault(false);
capability.getContent().add(first);
TypeCapability anotherCapability = new TypeCapability();
Type another = new Type();
another.setId("foo");
another.setDefault(false);
Type second = new Type();
second.setId("bar");
second.setDefault(true);
anotherCapability.getContent().add(another);
anotherCapability.getContent().add(second);
Type another = new Type();
another.setId("foo");
another.setDefault(false);
Type second = new Type();
second.setId("bar");
second.setDefault(true);
anotherCapability.getContent().add(another);
anotherCapability.getContent().add(second);
capability.merge(anotherCapability);
assertEquals(2, capability.getContent().size());

View File

@@ -44,7 +44,7 @@ public class GradleBuildAssert {
}
public GradleBuildAssert hasArtifactId(String artifactId) {
return contains("baseName = '"+ artifactId+"'");
return contains("baseName = '" + artifactId + "'");
}
public GradleBuildAssert hasVersion(String version) {

View File

@@ -16,16 +16,16 @@
package io.spring.initializr.test.generator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.LinkedHashMap;
import java.util.Map;
import io.spring.initializr.generator.ProjectRequest;
import io.spring.initializr.metadata.BillOfMaterials;
import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.metadata.InitializrConfiguration.Env.Maven.ParentPom;
import io.spring.initializr.metadata.Repository;
import org.custommonkey.xmlunit.SimpleNamespaceContext;
import org.custommonkey.xmlunit.XMLUnit;
import org.custommonkey.xmlunit.XpathEngine;
@@ -37,11 +37,10 @@ import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import io.spring.initializr.generator.ProjectRequest;
import io.spring.initializr.metadata.BillOfMaterials;
import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.metadata.InitializrConfiguration.Env.Maven.ParentPom;
import io.spring.initializr.metadata.Repository;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
* XPath assertions that are specific to a standard Maven POM.
@@ -231,7 +230,7 @@ public class PomAssert {
dependency.getScope());
}
if (expected.getType() != null) {
assertEquals("Wrong type for "+ dependency, expected.getType(),
assertEquals("Wrong type for " + dependency, expected.getType(),
dependency.getType());
}
return this;

View File

@@ -16,9 +16,6 @@
package io.spring.initializr.test.generator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -30,6 +27,9 @@ import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.util.StreamUtils;
import org.springframework.util.StringUtils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Various project based assertions.
*
@@ -74,8 +74,8 @@ public class ProjectAssert {
assertTrue("No directory " + name + " found in " + dir.getAbsolutePath(),
projectDir.exists());
assertTrue(name + " is not a directory", projectDir.isDirectory());
return new ProjectAssert(projectDir); // Replacing the root dir so that other
// assertions match the root
// Replacing the root dir so that other assertions match the root
return new ProjectAssert(projectDir);
}
/**
@@ -201,8 +201,8 @@ public class ProjectAssert {
String packageName = expectedPackageName.replace(".", "/");
return isGenericProject(expectedPackageName, expectedApplicationName,
codeLocation, extension).hasStaticAndTemplatesResources(true)
.hasFile("src/main/" + codeLocation + "/" + packageName
+ "/ServletInitializer." + extension);
.hasFile("src/main/" + codeLocation + "/" + packageName
+ "/ServletInitializer." + extension);
}
public ProjectAssert hasStaticAndTemplatesResources(boolean web) {

View File

@@ -20,8 +20,6 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import org.springframework.util.StringUtils;
import io.spring.initializr.metadata.BillOfMaterials;
import io.spring.initializr.metadata.DefaultMetadataElement;
import io.spring.initializr.metadata.Dependency;
@@ -32,6 +30,8 @@ import io.spring.initializr.metadata.InitializrMetadataBuilder;
import io.spring.initializr.metadata.Repository;
import io.spring.initializr.metadata.Type;
import org.springframework.util.StringUtils;
/**
* Easily create a {@link InitializrMetadata} instance for testing purposes.
*
@@ -111,7 +111,7 @@ public class InitializrMetadataTestBuilder {
}
public InitializrMetadataTestBuilder addPackaging(String id, boolean defaultValue) {
builder.withCustomizer(it -> {
builder.withCustomizer(it -> {
DefaultMetadataElement packaging = new DefaultMetadataElement();
packaging.setId(id);
packaging.setName(id);
@@ -126,7 +126,7 @@ public class InitializrMetadataTestBuilder {
}
public InitializrMetadataTestBuilder addJavaVersion(String version, boolean defaultValue) {
builder.withCustomizer(it -> {
builder.withCustomizer(it -> {
DefaultMetadataElement element = new DefaultMetadataElement();
element.setId(version);
element.setName(version);
@@ -141,7 +141,7 @@ public class InitializrMetadataTestBuilder {
}
public InitializrMetadataTestBuilder addLanguage(String id, boolean defaultValue) {
builder.withCustomizer(it -> {
builder.withCustomizer(it -> {
DefaultMetadataElement element = new DefaultMetadataElement();
element.setId(id);
element.setName(id);
@@ -157,7 +157,7 @@ public class InitializrMetadataTestBuilder {
}
public InitializrMetadataTestBuilder addBootVersion(String id, boolean defaultValue) {
builder.withCustomizer(it -> {
builder.withCustomizer(it -> {
DefaultMetadataElement element = new DefaultMetadataElement();
element.setId(id);
element.setName(id);
@@ -173,29 +173,29 @@ public class InitializrMetadataTestBuilder {
}
public InitializrMetadataTestBuilder addBom(String id, BillOfMaterials bom) {
builder.withCustomizer( it -> {
builder.withCustomizer(it -> {
it.getConfiguration().getEnv().getBoms().put(id, bom);
});
return this;
}
public InitializrMetadataTestBuilder setGradleEnv(String dependencyManagementPluginVersion) {
builder.withCustomizer( it-> {
builder.withCustomizer(it -> {
it.getConfiguration().getEnv().getGradle().setDependencyManagementPluginVersion(dependencyManagementPluginVersion);
});
return this;
}
public InitializrMetadataTestBuilder setKotlinEnv(String kotlinVersion) {
builder.withCustomizer( it-> {
builder.withCustomizer(it -> {
it.getConfiguration().getEnv().getKotlin().setVersion(kotlinVersion);
});
return this;
}
public InitializrMetadataTestBuilder setMavenParent(String groupId, String artifactId,
String version, boolean includeSpringBootBom) {
builder.withCustomizer( it-> {
String version, boolean includeSpringBootBom) {
builder.withCustomizer(it -> {
ParentPom parent = it.getConfiguration().getEnv().getMaven().getParent();
parent.setGroupId(groupId);
parent.setArtifactId(artifactId);
@@ -206,7 +206,7 @@ public class InitializrMetadataTestBuilder {
}
public InitializrMetadataTestBuilder addRepository(String id, String name, String url, boolean snapshotsEnabled) {
builder.withCustomizer( it-> {
builder.withCustomizer(it -> {
Repository repo = new Repository();
repo.setName(name);
try {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,13 +16,13 @@
package io.spring.initializr.util;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
import org.junit.Test;
/**
* Tests for {@link Agent}.
*

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,11 +16,6 @@
package io.spring.initializr.util;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.lessThan;
import static org.junit.Assert.assertNull;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -29,6 +24,11 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.lessThan;
import static org.junit.Assert.assertNull;
/**
* Tests for {@link VersionParser}.
*

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,6 @@
package io.spring.initializr.util;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import java.util.Arrays;
import java.util.Collections;
@@ -28,6 +25,9 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
/**
* @author Stephane Nicoll
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,16 +16,16 @@
package io.spring.initializr.util;
import java.util.Collections;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.comparesEqualTo;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.lessThan;
import java.util.Collections;
import org.junit.Test;
/**
* @author Stephane Nicoll
*/

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@@ -66,7 +67,9 @@
<dotGitDirectory>${project.basedir}/../.git</dotGitDirectory>
<dateFormat>yyyy-MM-dd'T'HH:mm:ssZ</dateFormat>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
<generateGitPropertiesFilename>
${project.build.outputDirectory}/git.properties
</generateGitPropertiesFilename>
</configuration>
</plugin>
<plugin>
@@ -89,7 +92,8 @@
</goals>
<configuration>
<additionalProperties>
<versions.spring-boot>${spring.boot.version}</versions.spring-boot>
<versions.spring-boot>${spring.boot.version}
</versions.spring-boot>
</additionalProperties>
</configuration>
</execution>

View File

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.spring.initializr</groupId>
@@ -120,7 +121,8 @@
<configuration>
<attach>true</attach>
<descriptors>
<descriptor>${basedir}/src/assembly/snippets.xml</descriptor>
<descriptor>${basedir}/src/assembly/snippets.xml
</descriptor>
<descriptor>${basedir}/src/assembly/stub.xml</descriptor>
</descriptors>
</configuration>

View File

@@ -46,9 +46,9 @@ public class CloudfoundryEnvironmentPostProcessor
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment,
SpringApplication springApplication) {
SpringApplication springApplication) {
Map<String,Object> map = new LinkedHashMap<>();
Map<String, Object> map = new LinkedHashMap<>();
String uri = environment.getProperty("vcap.services.stats-index.credentials.uri");
if (StringUtils.hasText(uri)) {
UriComponents uriComponents = UriComponentsBuilder.fromUriString(uri).build();
@@ -71,7 +71,7 @@ public class CloudfoundryEnvironmentPostProcessor
}
private static void addOrReplace(MutablePropertySources propertySources,
Map<String, Object> map) {
Map<String, Object> map) {
MapPropertySource target = null;
if (propertySources.contains(PROPERTY_SOURCE_NAME)) {
PropertySource<?> source = propertySources.get(PROPERTY_SOURCE_NAME);

View File

@@ -21,6 +21,22 @@ import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import com.github.benmanes.caffeine.cache.Caffeine;
import io.spring.initializr.generator.ProjectGenerator;
import io.spring.initializr.generator.ProjectRequestPostProcessor;
import io.spring.initializr.generator.ProjectRequestResolver;
import io.spring.initializr.generator.ProjectResourceLocator;
import io.spring.initializr.metadata.DependencyMetadataProvider;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.metadata.InitializrMetadataBuilder;
import io.spring.initializr.metadata.InitializrMetadataProvider;
import io.spring.initializr.metadata.InitializrProperties;
import io.spring.initializr.util.TemplateRenderer;
import io.spring.initializr.web.project.MainController;
import io.spring.initializr.web.support.DefaultDependencyMetadataProvider;
import io.spring.initializr.web.support.DefaultInitializrMetadataProvider;
import io.spring.initializr.web.ui.UiController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.bind.RelaxedPropertyResolver;
@@ -37,23 +53,6 @@ import org.springframework.core.env.Environment;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.resource.ResourceUrlProvider;
import com.github.benmanes.caffeine.cache.Caffeine;
import io.spring.initializr.generator.ProjectGenerator;
import io.spring.initializr.generator.ProjectRequestPostProcessor;
import io.spring.initializr.generator.ProjectRequestResolver;
import io.spring.initializr.generator.ProjectResourceLocator;
import io.spring.initializr.metadata.DependencyMetadataProvider;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.metadata.InitializrMetadataBuilder;
import io.spring.initializr.metadata.InitializrMetadataProvider;
import io.spring.initializr.metadata.InitializrProperties;
import io.spring.initializr.util.TemplateRenderer;
import io.spring.initializr.web.project.MainController;
import io.spring.initializr.web.support.DefaultDependencyMetadataProvider;
import io.spring.initializr.web.support.DefaultInitializrMetadataProvider;
import io.spring.initializr.web.ui.UiController;
/**
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
* Auto-configuration} to configure Spring initializr. In a web environment,
@@ -81,10 +80,10 @@ public class InitializrAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public MainController initializrMainController(InitializrMetadataProvider metadataProvider,
TemplateRenderer templateRenderer,
ResourceUrlProvider resourceUrlProvider,
ProjectGenerator projectGenerator,
DependencyMetadataProvider dependencyMetadataProvider) {
TemplateRenderer templateRenderer,
ResourceUrlProvider resourceUrlProvider,
ProjectGenerator projectGenerator,
DependencyMetadataProvider dependencyMetadataProvider) {
return new MainController(metadataProvider, templateRenderer, resourceUrlProvider
, projectGenerator, dependencyMetadataProvider);
}

View File

@@ -21,6 +21,9 @@ import java.util.List;
import javax.servlet.http.HttpServletRequest;
import io.spring.initializr.util.Agent;
import io.spring.initializr.util.Agent.AgentId;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.util.StringUtils;
@@ -31,9 +34,6 @@ import org.springframework.web.servlet.config.annotation.ContentNegotiationConfi
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.util.UrlPathHelper;
import io.spring.initializr.util.Agent;
import io.spring.initializr.util.Agent.AgentId;
/**
* Spring Initializr web configuration.
*
@@ -62,12 +62,12 @@ public class WebConfig extends WebMvcConfigurerAdapter {
return Collections.emptyList();
}
String userAgent = request.getHeader(HttpHeaders.USER_AGENT);
if (userAgent!=null) {
if (userAgent != null) {
Agent agent = Agent.fromUserAgent(userAgent);
if (agent!=null) {
if (AgentId.CURL.equals(agent.getId()) || AgentId.HTTPIE.equals(agent.getId())) {
return Collections.singletonList(MediaType.TEXT_PLAIN);
}
if (agent != null) {
if (AgentId.CURL.equals(agent.getId()) || AgentId.HTTPIE.equals(agent.getId())) {
return Collections.singletonList(MediaType.TEXT_PLAIN);
}
}
}
return Collections.singletonList(MediaType.APPLICATION_JSON);

View File

@@ -20,12 +20,11 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;
import org.json.JSONObject;
import io.spring.initializr.metadata.BillOfMaterials;
import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.metadata.DependencyMetadata;
import io.spring.initializr.metadata.Repository;
import org.json.JSONObject;
/**
* A {@link DependencyMetadataJsonMapper} handling the metadata format for v2.1.

View File

@@ -20,14 +20,14 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.metadata.Type;
import org.json.JSONObject;
import org.springframework.hateoas.TemplateVariable;
import org.springframework.hateoas.TemplateVariables;
import org.springframework.hateoas.UriTemplate;
import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.metadata.Type;
/**
* A {@link InitializrMetadataJsonMapper} handling the metadata format for v2.1
* <p>
@@ -50,7 +50,7 @@ public class InitializrMetadataV21JsonMapper extends InitializrMetadataV2JsonMap
@Override
protected Map<String, Object> links(JSONObject parent, List<Type> types, String appUrl) {
Map<String, Object> links = super.links(parent, types, appUrl);
links.put("dependencies", dependenciesLink(appUrl));
links.put("dependencies", dependenciesLink(appUrl));
parent.put("_links", links);
return links;
}
@@ -58,10 +58,10 @@ public class InitializrMetadataV21JsonMapper extends InitializrMetadataV2JsonMap
@Override
protected Map<String, Object> mapDependency(Dependency dependency) {
Map<String, Object> content = mapValue(dependency);
if (dependency.getVersionRange()!=null) {
if (dependency.getVersionRange() != null) {
content.put("versionRange", dependency.getVersionRange());
}
if (dependency.getLinks()!=null && !dependency.getLinks().isEmpty()) {
if (dependency.getLinks() != null && !dependency.getLinks().isEmpty()) {
content.put("_links", LinkMapper.mapLinks(dependency.getLinks()));
}
return content;

View File

@@ -22,12 +22,6 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.json.JSONObject;
import org.springframework.hateoas.TemplateVariable;
import org.springframework.hateoas.TemplateVariables;
import org.springframework.hateoas.UriTemplate;
import org.springframework.util.StringUtils;
import io.spring.initializr.metadata.DefaultMetadataElement;
import io.spring.initializr.metadata.DependenciesCapability;
import io.spring.initializr.metadata.Dependency;
@@ -39,6 +33,12 @@ import io.spring.initializr.metadata.SingleSelectCapability;
import io.spring.initializr.metadata.TextCapability;
import io.spring.initializr.metadata.Type;
import io.spring.initializr.metadata.TypeCapability;
import org.json.JSONObject;
import org.springframework.hateoas.TemplateVariable;
import org.springframework.hateoas.TemplateVariables;
import org.springframework.hateoas.UriTemplate;
import org.springframework.util.StringUtils;
/**
* A {@link InitializrMetadataJsonMapper} handling the metadata format for v2.
@@ -176,7 +176,7 @@ public class InitializrMetadataV2JsonMapper implements InitializrMetadataJsonMap
}
protected Map<String, Object> mapDependency(Dependency dependency) {
if (dependency.getVersionRange() == null) {
if (dependency.getVersionRange() == null) {
// only map the dependency if no versionRange is set
return mapValue(dependency);
}

View File

@@ -23,17 +23,17 @@ import java.util.function.Function;
import javax.servlet.http.HttpServletResponse;
import io.spring.initializr.generator.InvalidProjectRequestException;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.metadata.InitializrMetadataProvider;
import io.spring.initializr.metadata.TypeCapability;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.resource.ResourceUrlProvider;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import io.spring.initializr.generator.InvalidProjectRequestException;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.metadata.InitializrMetadataProvider;
import io.spring.initializr.metadata.TypeCapability;
/**
* A base controller that uses a {@link InitializrMetadataProvider}
*
@@ -72,7 +72,7 @@ public abstract class AbstractInitializrController {
/**
* Render the home page with the specified template.
*/
protected void renderHome(Map<String,Object> model) throws Exception {
protected void renderHome(Map<String, Object> model) throws Exception {
InitializrMetadata metadata = metadataProvider.get();
model.put("serviceUrl", generateAppUrl());
@@ -80,7 +80,8 @@ public abstract class AbstractInitializrController {
for (PropertyDescriptor descriptor : wrapper.getPropertyDescriptors()) {
if ("types".equals(descriptor.getName())) {
model.put("types", removeTypes(metadata.getTypes()));
} else {
}
else {
model.put(descriptor.getName(), wrapper.getPropertyValue(descriptor.getName()));
}
}
@@ -101,7 +102,7 @@ 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;
}

View File

@@ -18,12 +18,12 @@ package io.spring.initializr.web.project;
import java.util.Map;
import io.spring.initializr.metadata.InitializrMetadataProvider;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.resource.ResourceUrlProvider;
import io.spring.initializr.metadata.InitializrMetadataProvider;
/**
* A controller used to serve the legacy home page used by STS.
*
@@ -35,7 +35,7 @@ public class LegacyStsController extends AbstractInitializrController {
public LegacyStsController(InitializrMetadataProvider metadataProvider, ResourceUrlProvider resourceUrlProvider) {
super(metadataProvider, resourceUrlProvider);
}
@RequestMapping(value = "/sts", produces = "text/html")
public String stsHome(Map<String, Object> model) throws Exception {
renderHome(model);

View File

@@ -16,10 +16,6 @@
package io.spring.initializr.web.project;
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;
import java.io.File;
import java.io.FileInputStream;
import java.io.UnsupportedEncodingException;
@@ -28,26 +24,7 @@ import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.rauschig.jarchivelib.ArchiverFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.CacheControl;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.ResponseEntity.BodyBuilder;
import org.springframework.stereotype.Controller;
import org.springframework.util.DigestUtils;
import org.springframework.util.StreamUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.resource.ResourceUrlProvider;
import com.samskivert.mustache.Mustache;
import io.spring.initializr.generator.BasicProjectRequest;
import io.spring.initializr.generator.CommandLineHelpGenerator;
import io.spring.initializr.generator.ProjectGenerator;
@@ -64,6 +41,28 @@ import io.spring.initializr.web.mapper.InitializrMetadataJsonMapper;
import io.spring.initializr.web.mapper.InitializrMetadataV21JsonMapper;
import io.spring.initializr.web.mapper.InitializrMetadataV2JsonMapper;
import io.spring.initializr.web.mapper.InitializrMetadataVersion;
import org.rauschig.jarchivelib.ArchiverFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.CacheControl;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.ResponseEntity.BodyBuilder;
import org.springframework.stereotype.Controller;
import org.springframework.util.DigestUtils;
import org.springframework.util.StreamUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
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
@@ -179,10 +178,10 @@ public class MainController extends AbstractInitializrController {
private static InitializrMetadataJsonMapper getJsonMapper(
InitializrMetadataVersion version) {
switch (version) {
case V2:
return new InitializrMetadataV2JsonMapper();
default:
return new InitializrMetadataV21JsonMapper();
case V2:
return new InitializrMetadataV2JsonMapper();
default:
return new InitializrMetadataV21JsonMapper();
}
}

View File

@@ -19,8 +19,6 @@ package io.spring.initializr.web.support;
import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.cache.annotation.Cacheable;
import io.spring.initializr.metadata.BillOfMaterials;
import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.metadata.DependencyMetadata;
@@ -29,6 +27,8 @@ import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.metadata.Repository;
import io.spring.initializr.util.Version;
import org.springframework.cache.annotation.Cacheable;
/**
* A default {@link DependencyMetadataProvider} implementation.
*
@@ -48,14 +48,14 @@ public class DefaultDependencyMetadataProvider implements DependencyMetadataProv
Map<String, Repository> repositories = new LinkedHashMap<>();
for (Dependency d : dependencies.values()) {
if (d.getRepository()!=null) {
if (d.getRepository() != null) {
repositories.put(d.getRepository(), metadata.getConfiguration().getEnv().getRepositories().get(d.getRepository()));
}
}
Map<String, BillOfMaterials> boms = new LinkedHashMap<>();
for (Dependency d : dependencies.values()) {
if (d.getBom()!=null) {
if (d.getBom() != null) {
boms.put(d.getBom(), metadata.getConfiguration().getEnv().getBoms().get(d.getBom()).resolve(bootVersion));
}
}

View File

@@ -18,15 +18,15 @@ package io.spring.initializr.web.support;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;
import io.spring.initializr.metadata.DefaultMetadataElement;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.metadata.InitializrMetadataProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;
/**
* A default {@link InitializrMetadataProvider} that is able to refresh
@@ -35,7 +35,7 @@ import io.spring.initializr.metadata.InitializrMetadataProvider;
* @author Stephane Nicoll
*/
public class DefaultInitializrMetadataProvider implements InitializrMetadataProvider {
private static final Logger log = LoggerFactory
.getLogger(DefaultInitializrMetadataProvider.class);
@@ -56,7 +56,7 @@ public class DefaultInitializrMetadataProvider implements InitializrMetadataProv
protected void updateInitializrMetadata(InitializrMetadata metadata) {
List<DefaultMetadataElement> bootVersions = fetchBootVersions();
if (bootVersions!=null && !bootVersions.isEmpty()) {
if (bootVersions != null && !bootVersions.isEmpty()) {
if (bootVersions.stream().noneMatch(it -> it.isDefault())) { // No default specified
bootVersions.get(0).setDefault(true);
}
@@ -70,7 +70,8 @@ public class DefaultInitializrMetadataProvider implements InitializrMetadataProv
try {
log.info("Fetching boot metadata from {}", url);
return new SpringBootMetadataReader(restTemplate, url).getBootVersions();
} catch (Exception e) {
}
catch (Exception e) {
log.warn("Failed to fetch spring boot metadata", e);
}
}

View File

@@ -19,12 +19,11 @@ package io.spring.initializr.web.support;
import java.util.ArrayList;
import java.util.List;
import io.spring.initializr.metadata.DefaultMetadataElement;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;
import io.spring.initializr.metadata.DefaultMetadataElement;
import org.springframework.web.client.RestTemplate;
/**
* Reads metadata from the main spring.io website. This is a stateful
@@ -50,7 +49,7 @@ public class SpringBootMetadataReader {
public List<DefaultMetadataElement> getBootVersions() {
JSONArray array = content.getJSONArray("projectReleases");
List<DefaultMetadataElement> list = new ArrayList<>();
for (int i=0; i<array.length(); i++) {
for (int i = 0; i < array.length(); i++) {
JSONObject it = array.getJSONObject(i);
DefaultMetadataElement version = new DefaultMetadataElement();
version.setId(it.getString("version"));

View File

@@ -22,7 +22,12 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.metadata.DependencyGroup;
import io.spring.initializr.metadata.InitializrMetadataProvider;
import io.spring.initializr.util.Version;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
@@ -33,11 +38,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.metadata.DependencyGroup;
import io.spring.initializr.metadata.InitializrMetadataProvider;
import io.spring.initializr.util.Version;
/**
* UI specific controller providing dedicated endpoints for the Web UI.
*
@@ -56,11 +56,12 @@ public class UiController {
Version v = StringUtils.isEmpty(version) ? null : Version.parse(version);
dependencyGroups.forEach(g -> {
g.getContent().forEach(d -> {
if (v!=null && d.getVersionRange()!=null) {
if (v != null && d.getVersionRange() != null) {
if (d.match(v)) {
content.add(new DependencyItem(g.getName(), d));
}
} else {
}
else {
content.add(new DependencyItem(g.getName(), d));
}
});
@@ -84,10 +85,10 @@ public class UiController {
result.put("id", d.getId());
result.put("name", d.getName());
result.put("group", item.group);
if (d.getDescription()!=null) {
if (d.getDescription() != null) {
result.put("description", d.getDescription());
}
if (d.getWeight()>0) {
if (d.getWeight() > 0) {
result.put("weight", d.getWeight());
}
if (!CollectionUtils.isEmpty(d.getKeywords()) || !CollectionUtils.isEmpty(d.getAliases())) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,14 +16,15 @@
package io.spring.initializr.web;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
import io.spring.initializr.web.AbstractInitializrIntegrationTests.Config;
import org.junit.runner.RunWith;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
/**
* @author Stephane Nicoll
* @author Dave Syer

View File

@@ -16,6 +16,10 @@
package io.spring.initializr.web;
import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests.RestTemplateConfig;
import io.spring.initializr.web.test.MockMvcClientHttpRequestFactory;
import io.spring.initializr.web.test.MockMvcClientHttpRequestFactoryTestExecutionListener;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
@@ -27,10 +31,6 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.TestExecutionListeners.MergeMode;
import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests.RestTemplateConfig;
import io.spring.initializr.web.test.MockMvcClientHttpRequestFactory;
import io.spring.initializr.web.test.MockMvcClientHttpRequestFactoryTestExecutionListener;
/**
* @author Stephane Nicoll
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,6 @@
package io.spring.initializr.web;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -28,6 +26,14 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.metadata.InitializrMetadataBuilder;
import io.spring.initializr.metadata.InitializrMetadataProvider;
import io.spring.initializr.metadata.InitializrProperties;
import io.spring.initializr.test.generator.ProjectAssert;
import io.spring.initializr.web.AbstractInitializrIntegrationTests.Config;
import io.spring.initializr.web.mapper.InitializrMetadataVersion;
import io.spring.initializr.web.support.DefaultInitializrMetadataProvider;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Rule;
@@ -36,6 +42,7 @@ import org.junit.runner.RunWith;
import org.rauschig.jarchivelib.ArchiverFactory;
import org.skyscreamer.jsonassert.JSONAssert;
import org.skyscreamer.jsonassert.JSONCompareMode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
@@ -51,14 +58,7 @@ import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.StreamUtils;
import org.springframework.web.client.RestTemplate;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.metadata.InitializrMetadataBuilder;
import io.spring.initializr.metadata.InitializrMetadataProvider;
import io.spring.initializr.metadata.InitializrProperties;
import io.spring.initializr.test.generator.ProjectAssert;
import io.spring.initializr.web.AbstractInitializrIntegrationTests.Config;
import io.spring.initializr.web.mapper.InitializrMetadataVersion;
import io.spring.initializr.web.support.DefaultInitializrMetadataProvider;
import static org.junit.Assert.assertTrue;
/**
* @author Stephane Nicoll
@@ -183,12 +183,12 @@ public abstract class AbstractInitializrIntegrationTests {
File project = folder.newFolder();
switch (archiveType) {
case ZIP:
ArchiverFactory.createArchiver("zip").extract(archiveFile, project);
break;
case TGZ:
ArchiverFactory.createArchiver("tar", "gz").extract(archiveFile, project);
break;
case ZIP:
ArchiverFactory.createArchiver("zip").extract(archiveFile, project);
break;
case TGZ:
ArchiverFactory.createArchiver("tar", "gz").extract(archiveFile, project);
break;
}
return new ProjectAssert(project);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,14 +16,15 @@
package io.spring.initializr.web.autoconfigure;
import org.junit.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.mock.env.MockEnvironment;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
import org.junit.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.mock.env.MockEnvironment;
/**
* @author Stephane Nicoll
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,19 +16,18 @@
package io.spring.initializr.web.mapper;
import static org.junit.Assert.assertEquals;
import java.net.URL;
import java.util.Collections;
import org.json.JSONObject;
import org.junit.Test;
import io.spring.initializr.metadata.BillOfMaterials;
import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.metadata.DependencyMetadata;
import io.spring.initializr.metadata.Repository;
import io.spring.initializr.util.Version;
import org.json.JSONObject;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* @author Stephane Nicoll

View File

@@ -16,16 +16,15 @@
package io.spring.initializr.web.mapper;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.json.JSONObject;
import org.junit.Test;
import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.metadata.Link;
import io.spring.initializr.test.metadata.InitializrMetadataTestBuilder;
import org.json.JSONObject;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* @author Stephane Nicoll
@@ -51,12 +50,12 @@ public class InitializrMetadataJsonMapperTests {
String json = jsonMapper.write(metadata, "http://server:8080/my-app");
JSONObject result = new JSONObject(json);
assertEquals("http://server:8080/my-app/foo.zip?type=foo{&dependencies,packaging,javaVersion," +
"language,bootVersion,groupId,artifactId,version,name,description,packageName}",
"language,bootVersion,groupId,artifactId,version,name,description,packageName}",
get(result, "_links.foo.href"));
}
@Test
public void linksRendered() {
public void linksRendered() {
Dependency dependency = Dependency.withId("foo", "com.example", "foo");
dependency.getLinks().add(Link.create("guide", "https://example.com/how-to"));
dependency.getLinks().add(Link.create("reference", "https://example.com/doc"));
@@ -66,17 +65,17 @@ public class InitializrMetadataJsonMapperTests {
int first = json.indexOf("https://example.com/how-to");
int second = json.indexOf("https://example.com/doc");
// JSON objects are not ordered
assertTrue(first>0);
assertTrue(second>0);
assertTrue(first > 0);
assertTrue(second > 0);
}
private Object get(JSONObject result, String path) {
String[] nodes = path.split("\\.");
for (int i = 0; i < nodes.length-1; i++) {
for (int i = 0; i < nodes.length - 1; i++) {
String node = nodes[i];
result = result.getJSONObject(node);
}
return result.getString(nodes[nodes.length-1]);
return result.getString(nodes[nodes.length - 1]);
}
}

View File

@@ -16,16 +16,15 @@
package io.spring.initializr.web.mapper;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import io.spring.initializr.metadata.Link;
import org.junit.Test;
import io.spring.initializr.metadata.Link;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Tests for {@link LinkMapper}.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,12 +16,12 @@
package io.spring.initializr.web.project;
import org.junit.Test;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;
import io.spring.initializr.test.generator.PomAssert;
import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
import org.junit.Test;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;
/**
* Validate that the "raw" HTTP commands that are described in the

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,11 +16,13 @@
package io.spring.initializr.web.project;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import io.spring.initializr.metadata.InitializrMetadataProvider;
import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
import io.spring.initializr.web.project.LegacyStsControllerIntegrationTests.LegacyConfig;
import org.junit.Test;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpEntity;
@@ -31,9 +33,7 @@ import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.web.servlet.resource.ResourceUrlProvider;
import io.spring.initializr.metadata.InitializrMetadataProvider;
import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
import io.spring.initializr.web.project.LegacyStsControllerIntegrationTests.LegacyConfig;
import static org.junit.Assert.assertTrue;
/**
* @author Stephane Nicoll
@@ -49,8 +49,8 @@ public class LegacyStsControllerIntegrationTests
assertTrue("groupId not found", body.contains("com.example"));
assertTrue("artifactId not found", body.contains("demo"));
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\"/>"));
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\"/>"));
}
protected String htmlHome() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,18 +16,18 @@
package io.spring.initializr.web.project;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.springframework.test.context.ActiveProfiles;
import io.spring.initializr.test.generator.PomAssert;
import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
import org.junit.Test;
import org.springframework.test.context.ActiveProfiles;
import static org.junit.Assert.assertTrue;
/**
* @author Stephane Nicoll
*/
@ActiveProfiles({"test-default", "test-custom-defaults"})
@ActiveProfiles({ "test-default", "test-custom-defaults" })
public class MainControllerDefaultsIntegrationTests extends AbstractInitializrControllerIntegrationTests {
// see defaults customization

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,24 +16,24 @@
package io.spring.initializr.web.project;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.net.URI;
import io.spring.initializr.test.generator.ProjectAssert;
import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
import org.junit.Test;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;
import io.spring.initializr.test.generator.ProjectAssert;
import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* @author Stephane Nicoll
*/
@ActiveProfiles({"test-default", "test-custom-env"})
@ActiveProfiles({ "test-default", "test-custom-env" })
public class MainControllerEnvIntegrationTests extends AbstractInitializrControllerIntegrationTests {
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,24 @@
package io.spring.initializr.web.project;
import java.net.URI;
import java.net.URISyntaxException;
import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
import io.spring.initializr.web.mapper.InitializrMetadataVersion;
import org.json.JSONObject;
import org.junit.Ignore;
import org.junit.Test;
import org.skyscreamer.jsonassert.JSONCompareMode;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.web.client.HttpClientErrorException;
import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.nullValue;
@@ -27,24 +45,6 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.net.URI;
import java.net.URISyntaxException;
import org.json.JSONObject;
import org.junit.Ignore;
import org.junit.Test;
import org.skyscreamer.jsonassert.JSONCompareMode;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.web.client.HttpClientErrorException;
import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
import io.spring.initializr.web.mapper.InitializrMetadataVersion;
/**
* @author Stephane Nicoll
*/
@@ -81,7 +81,7 @@ public class MainControllerIntegrationTests
@Test
public void dependencyNotInRange() {
try {
execute("/starter.tgz?style=org.acme:bur", byte[].class, null, (String[])null);
execute("/starter.tgz?style=org.acme:bur", byte[].class, null, (String[]) null);
}
catch (HttpClientErrorException ex) {
assertEquals(HttpStatus.NOT_ACCEPTABLE, ex.getStatusCode());
@@ -92,8 +92,8 @@ public class MainControllerIntegrationTests
public void noDependencyProject() {
downloadZip("/starter.zip").isJavaProject().isMavenProject()
.hasStaticAndTemplatesResources(false).pomAssert().hasDependenciesCount(2)
.hasSpringBootStarterRootDependency() // the root dep is added if none is
// specified
// the root dep is added if none is specified
.hasSpringBootStarterRootDependency()
.hasSpringBootStarterTest();
}
@@ -349,7 +349,8 @@ public class MainControllerIntegrationTests
try {
downloadArchive("/starter.zip?style=foo:bar");
fail("Should have failed");
} catch (HttpClientErrorException ex) {
}
catch (HttpClientErrorException ex) {
assertEquals(HttpStatus.BAD_REQUEST, ex.getStatusCode());
assertStandardErrorBody(ex.getResponseBodyAsString(),
"Unknown dependency 'foo:bar' check project metadata");
@@ -361,7 +362,8 @@ public class MainControllerIntegrationTests
try {
downloadArchive("/starter.zip?style=foo");
fail("Should have failed");
} catch (HttpClientErrorException ex) {
}
catch (HttpClientErrorException ex) {
assertEquals(HttpStatus.BAD_REQUEST, ex.getStatusCode());
assertStandardErrorBody(ex.getResponseBodyAsString(),
"Unknown dependency 'foo' check project metadata");
@@ -371,18 +373,18 @@ public class MainControllerIntegrationTests
@Test
public void homeIsForm() {
String body = htmlHome();
assertTrue ("Wrong body:\n" + body, body.contains("action=\"/starter.zip\""));
assertTrue ("Wrong body:\n" + body, body.contains("Web dependency description"));
assertFalse ("Wrong body:\n" + body, body.contains("${"));
assertFalse ("Wrong body:\n" + body, body.contains("{{"));
assertFalse ("Wrong body:\n" + body, body.contains("}}"));
assertTrue ("Wrong body:\n" + body, body.contains("<option value=\"groovy\">"));
assertTrue ("Wrong body:\n" + body, body.contains("<option value=\"java\" selected>"));
assertTrue("Wrong body:\n" + body, body.contains("action=\"/starter.zip\""));
assertTrue("Wrong body:\n" + body, body.contains("Web dependency description"));
assertFalse("Wrong body:\n" + body, body.contains("${"));
assertFalse("Wrong body:\n" + body, body.contains("{{"));
assertFalse("Wrong body:\n" + body, body.contains("}}"));
assertTrue("Wrong body:\n" + body, body.contains("<option value=\"groovy\">"));
assertTrue("Wrong body:\n" + body, body.contains("<option value=\"java\" selected>"));
}
@Test
public void homeIsJson() {
String body = invokeHome(null, (String[])null).getBody();
String body = invokeHome(null, (String[]) null).getBody();
assertTrue("Wrong body:\n$body", body.contains("\"dependencies\""));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,16 +16,15 @@
package io.spring.initializr.web.project;
import static org.junit.Assert.assertEquals;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.metadata.InitializrMetadataBuilder;
import io.spring.initializr.metadata.InitializrMetadataProvider;
import io.spring.initializr.web.AbstractFullStackInitializrIntegrationTests;
import org.json.JSONObject;
import org.junit.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.skyscreamer.jsonassert.JSONCompareMode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.UrlResource;
import org.springframework.http.HttpStatus;
@@ -34,6 +33,8 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.web.client.HttpClientErrorException;
import static org.junit.Assert.assertEquals;
/**
* @author Stephane Nicoll
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,16 +16,14 @@
package io.spring.initializr.web.project;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.stream.Collectors;
import io.spring.initializr.test.generator.ProjectAssert;
import io.spring.initializr.web.AbstractFullStackInitializrIntegrationTests;
import org.junit.After;
import org.junit.Assume;
import org.junit.Before;
@@ -41,11 +39,13 @@ import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.Select;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.util.StreamUtils;
import io.spring.initializr.test.generator.ProjectAssert;
import io.spring.initializr.web.AbstractFullStackInitializrIntegrationTests;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* @author Dave Syer

View File

@@ -1,11 +1,20 @@
package io.spring.initializr.web.project;
/*
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.junit.Test;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.annotation.Order;
import org.springframework.test.context.ActiveProfiles;
package io.spring.initializr.web.project;
import io.spring.initializr.generator.ProjectRequest;
import io.spring.initializr.generator.ProjectRequestPostProcessor;
@@ -13,6 +22,13 @@ import io.spring.initializr.generator.ProjectRequestPostProcessorAdapter;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
import io.spring.initializr.web.project.ProjectGenerationPostProcessorTests.ProjectRequestPostProcessorConfiguration;
import org.junit.Test;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.annotation.Order;
import org.springframework.test.context.ActiveProfiles;
@ActiveProfiles("test-default")
@Import(ProjectRequestPostProcessorConfiguration.class)

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,7 +26,7 @@ import io.spring.initializr.util.Version;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;;
import static org.junit.Assert.assertSame;
/**
* @author Stephane Nicoll

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,16 +16,14 @@
package io.spring.initializr.web.support;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus;
import java.util.List;
import io.spring.initializr.metadata.DefaultMetadataElement;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.test.metadata.InitializrMetadataTestBuilder;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
@@ -34,9 +32,11 @@ import org.springframework.http.MediaType;
import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.web.client.RestTemplate;
import io.spring.initializr.metadata.DefaultMetadataElement;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.test.metadata.InitializrMetadataTestBuilder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus;
/**
* @author Stephane Nicoll
@@ -102,8 +102,8 @@ public class DefaultInitializrMetadataProviderTests {
this.mockServer.expect(requestTo(url))
.andExpect(method(HttpMethod.GET))
.andRespond(withStatus(HttpStatus.OK)
.body(new ClassPathResource(bodyPath))
.headers(httpHeaders));
.body(new ClassPathResource(bodyPath))
.headers(httpHeaders));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,10 +16,14 @@
package io.spring.initializr.web.support;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import io.spring.initializr.metadata.DefaultMetadataElement;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.metadata.InitializrMetadataBuilder;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.MediaType;
import org.springframework.test.web.client.MockRestServiceServer;
@@ -30,9 +34,6 @@ import static org.junit.Assert.fail;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* @author Stephane Nicoll
* @author Dave Syer
@@ -48,7 +49,7 @@ public class SpringBootMetadataReaderTests {
@Test
public void readAvailableVersions() {
server.expect(requestTo("https://spring.io/project_metadata/spring-boot")).andRespond(
withSuccess(new ClassPathResource("metadata/sagan/spring-boot.json"), MediaType.APPLICATION_JSON));
withSuccess(new ClassPathResource("metadata/sagan/spring-boot.json"), MediaType.APPLICATION_JSON));
List<DefaultMetadataElement> versions = new SpringBootMetadataReader(restTemplate,
metadata.getConfiguration().getEnv().getSpringBootMetadataUrl()).getBootVersions();
assertNotNull("spring boot versions should not be null", versions);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@ import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.servlet.RequestDispatcher;
import org.springframework.http.HttpHeaders;
@@ -39,9 +40,10 @@ import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.util.Assert;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.*;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.request;
/**
* @author Dave Syer

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,11 +17,11 @@
package io.spring.initializr.web.ui;
import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
import org.json.JSONObject;
import org.junit.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.skyscreamer.jsonassert.JSONCompareMode;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;