polishing

This commit is contained in:
Stephane Nicoll 2014-09-02 11:16:09 +02:00
parent 2f9a435334
commit 3fa1f72c4f
16 changed files with 77 additions and 69 deletions

View File

@ -52,7 +52,7 @@ class DefaultInitializrMetadataProvider implements InitializrMetadataProvider {
def url = metadata.env.springBootMetadataUrl
if (url) {
try {
log.info('Fetching boot metadata from '+ url)
log.info("Fetching boot metadata from $url")
return new SpringBootMetadataReader(url).getBootVersions()
} catch (Exception e) {
log.warn('Failed to fetch spring boot metadata', e)

View File

@ -138,8 +138,7 @@ class InitializrMetadata {
private void indexDependency(String id, Dependency dependency) {
def existing = indexedDependencies[id]
if (existing) {
throw new IllegalArgumentException('Could not register ' + dependency +
': another dependency has also the "' + id + '" id ' + existing)
throw new IllegalArgumentException("Could not register $dependency another dependency has also the '$id' id $existing");
}
indexedDependencies[id] = dependency
}
@ -148,8 +147,8 @@ class InitializrMetadata {
def id = dependency.id
if (id == null) {
if (!dependency.hasCoordinates()) {
throw new InvalidInitializrMetadataException('Invalid dependency, ' +
'should have at least an id or a groupId/artifactId pair.')
throw new InvalidInitializrMetadataException(
'Invalid dependency, should have at least an id or a groupId/artifactId pair.')
}
dependency.generateId()
} else if (!dependency.hasCoordinates()) {
@ -164,8 +163,8 @@ class InitializrMetadata {
dependency.version = st.nextToken()
}
} else {
throw new InvalidInitializrMetadataException('Invalid dependency, id should ' +
'have the form groupId:artifactId[:version] but got ' + id)
throw new InvalidInitializrMetadataException(
"Invalid dependency, id should have the form groupId:artifactId[:version] but got $id")
}
}
}
@ -176,7 +175,7 @@ class InitializrMetadata {
return element.id
}
}
log.warn('No default found amongst' + elements)
log.warn("No default found amongst $elements")
return (elements.isEmpty() ? null : elements.get(0).id)
}
@ -229,8 +228,8 @@ class InitializrMetadata {
*/
def generateId() {
if (groupId == null || artifactId == null) {
throw new IllegalArgumentException('Could not generate id for ' + this
+ ': at least groupId and artifactId must be set.')
throw new IllegalArgumentException(
"Could not generate id for $this: at least groupId and artifactId must be set.")
}
StringBuilder sb = new StringBuilder()
sb.append(groupId).append(':').append(artifactId)

View File

@ -49,37 +49,43 @@ class ProjectGenerationMetricsListener implements ProjectGenerationListener {
protected void handleDependencies(ProjectRequest request) {
request.dependencies.each {
increment(key('dependency.' + sanitize(it.id)))
def id = sanitize(it.id)
increment(key("dependency.$id"))
}
}
protected void handleType(ProjectRequest request) {
if (StringUtils.hasText(request.type)) {
increment(key('type.' + sanitize(request.type)))
def type = sanitize(request.type)
increment(key("type.$type"))
}
}
protected void handleJavaVersion(ProjectRequest request) {
if (StringUtils.hasText(request.javaVersion)) {
increment(key('java_version.' + sanitize(request.javaVersion)))
def javaVersion = sanitize(request.javaVersion)
increment(key("java_version.$javaVersion"))
}
}
protected void handlePackaging(ProjectRequest request) {
if (StringUtils.hasText(request.packaging)) {
increment(key('packaging.' + sanitize(request.packaging)))
def packaging = sanitize(request.packaging)
increment(key("packaging.$packaging"))
}
}
protected void handleLanguage(ProjectRequest request) {
if (StringUtils.hasText(request.language)) {
increment(key('language.' + sanitize(request.language)))
def language = sanitize(request.language)
increment(key("language.$language"))
}
}
protected void handleBootVersion(ProjectRequest request) {
if (StringUtils.hasText(request.bootVersion)) {
increment(key('boot_version.' + sanitize(request.bootVersion)))
def bootVersion = sanitize(request.bootVersion)
increment(key("boot_version.$bootVersion"))
}
}
@ -88,7 +94,7 @@ class ProjectGenerationMetricsListener implements ProjectGenerationListener {
}
protected String key(String part) {
'initializr.' + part
"initializr.$part"
}
protected String sanitize(String s) {

View File

@ -86,15 +86,15 @@ class ProjectGenerator {
def language = request.language
def src = new File(new File(dir, 'src/main/' + language), request.packageName.replace('.', '/'))
def src = new File(new File(dir, "src/main/$language"), request.packageName.replace('.', '/'))
src.mkdirs()
write(src, 'Application.' + language, model)
write(src, "Application.$language", model)
if (request.packaging == 'war') {
write(src, 'ServletInitializer.' + language, model)
write(src, "ServletInitializer.$language", model)
}
def test = new File(new File(dir, 'src/test/' + language), request.packageName.replace('.', '/'))
def test = new File(new File(dir, "src/test/$language"), request.packageName.replace('.', '/'))
test.mkdirs()
if (request.hasWebFacet()) {
model.testAnnotations = '@WebAppConfiguration\n'
@ -103,7 +103,7 @@ class ProjectGenerator {
model.testAnnotations = ''
model.testImports = ''
}
write(test, 'ApplicationTests.' + language, model)
write(test, "ApplicationTests.$language", model)
def resources = new File(dir, 'src/main/resources')
resources.mkdirs()
@ -158,8 +158,8 @@ class ProjectGenerator {
request.resolve(metadata)
// request resolved so we can log what has been requested
log.info('Processing request{type=' + request.type + ', ' +
'dependencies=' + request.dependencies.collect {it.id}+ '}')
def dependencies = request.dependencies.collect { it.id }
log.info("Processing request{type=$request.type, dependencies=$dependencies}")
request.properties.each { model[it.key] = it.value }
model
@ -182,7 +182,7 @@ class ProjectGenerator {
private void addTempFile(String group, File file) {
def content = temporaryFiles[group]
if (content == null) {
if (!content) {
content = []
temporaryFiles[group] = content
}

View File

@ -57,9 +57,9 @@ class ProjectRequest {
def dependency = metadata.getDependency(it)
if (dependency == null) {
if (it.contains(':')) {
throw new IllegalArgumentException('Unknown dependency ' + it + ' check project metadata')
throw new IllegalArgumentException("Unknown dependency '$it' check project metadata")
}
log.warn('No known dependency for style ' + it + ' assuming spring-boot-starter')
log.warn("No known dependency for style '$it' assuming spring-boot-starter")
dependency = new InitializrMetadata.Dependency()
dependency.asSpringBootStarter(it)
}

View File

@ -67,12 +67,14 @@ class MainController extends AbstractInitializrController {
@RequestMapping('/spring')
String spring() {
'redirect:' + metadataProvider.get().createCliDistributionURl('zip')
def url = metadataProvider.get().createCliDistributionURl('zip')
"redirect:$url"
}
@RequestMapping(value = ['/spring.tar.gz', 'spring.tgz'])
String springTgz() {
'redirect:' + metadataProvider.get().createCliDistributionURl('tar.gz')
def url = metadataProvider.get().createCliDistributionURl('tar.gz')
"redirect:$url"
}
@RequestMapping('/pom')

View File

@ -38,7 +38,7 @@ class SpringBootMetadataReaderTests {
assertNotNull 'Name must be set', it.name
if (it.default) {
if (defaultFound) {
fail('One default version was already found ' + it.id)
fail("One default version was already found $it.id")
}
defaultFound = true
}

View File

@ -44,24 +44,24 @@ class GradleBuildAssert {
}
GradleBuildAssert hasArtifactId(String artifactId) {
contains('baseName = \'' + artifactId + '\'')
contains("baseName = '$artifactId'")
}
GradleBuildAssert hasVersion(String version) {
contains('version = \'' + version + '\'')
contains("version = '$version'")
}
GradleBuildAssert hasBootVersion(String bootVersion) {
contains('springBootVersion = \'' + bootVersion + '\'')
contains("springBootVersion = '$bootVersion'")
}
GradleBuildAssert hasJavaVersion(String javaVersion) {
contains('sourceCompatibility = ' + javaVersion + '')
contains('targetCompatibility = ' + javaVersion + '')
contains("sourceCompatibility = $javaVersion")
contains("targetCompatibility = $javaVersion")
}
GradleBuildAssert contains(String expression) {
assertTrue expression + ' has not been found in gradle build', content.contains(expression)
assertTrue "$expression has not been found in gradle build", content.contains(expression)
this
}
}

View File

@ -36,21 +36,21 @@ class MetricsAssert {
metrics.each {
def actual = counterService.values[it]
if (actual == null) {
fail('Metric ' + it + ' not found, got ' + counterService.values.keySet())
fail("Metric '$it' not found, got '${counterService.values.keySet()}")
}
assertEquals 'Wrong value for metric ' + it, value, actual
assertEquals "Wrong value for metric $it", value, actual
}
this
}
MetricsAssert hasNoValue(String... metrics) {
metrics.each {
assertEquals 'Metric ' + it + ' should not be registered', null, counterService.values[it]
assertEquals "Metric '$it' should not be registered", null, counterService.values[it]
}
}
MetricsAssert metricsCount(int count) {
assertEquals 'Wrong number of metrics, got ' + counterService.values.keySet(),
assertEquals "Wrong number of metrics, got '${counterService.values.keySet()}",
count, counterService.values.size()
this
}

View File

@ -105,12 +105,13 @@ class PomAssert {
}
PomAssert hasDependenciesCount(int count) {
assertEquals 'Wrong number of declared dependencies -->' + dependencies.keySet(), count, dependencies.size()
assertEquals "Wrong number of declared dependencies -->'${dependencies.keySet()}",
count, dependencies.size()
this
}
PomAssert hasSpringBootStarterDependency(String dependency) {
hasDependency('org.springframework.boot', 'spring-boot-starter-' + dependency)
hasDependency('org.springframework.boot', "spring-boot-starter-$dependency")
}
PomAssert hasSpringBootStarterRootDependency() {
@ -124,9 +125,9 @@ class PomAssert {
PomAssert hasDependency(String groupId, String artifactId, String version) {
def id = generateId(groupId, artifactId)
def dependency = dependencies[id]
assertNotNull 'No dependency found with ' + id + ' --> ' + dependencies.keySet(), dependency
assertNotNull "No dependency found with '$id' --> ${dependencies.keySet()}", dependency
if (version) {
assertEquals 'Wrong version for '+dependency, version, dependency.version
assertEquals "Wrong version for $dependency", version, dependency.version
}
this
}
@ -149,7 +150,7 @@ class PomAssert {
return
}
}
throw new IllegalArgumentException('No repository found with id ' + name)
throw new IllegalArgumentException("No repository found with id $name")
}
def hasPluginRepository(String name) {
@ -159,15 +160,15 @@ class PomAssert {
return
}
}
throw new IllegalArgumentException('No plugin repository found with id ' + name)
throw new IllegalArgumentException("No plugin repository found with id $name")
}
static String createPropertyNodeXpath(String propertyName) {
createRootNodeXPath('properties/pom:' + propertyName)
createRootNodeXPath("properties/pom:$propertyName")
}
static String createRootNodeXPath(String node) {
'/pom:project/pom:' + node
"/pom:project/pom:$node"
}
private def parseDependencies() {

View File

@ -83,7 +83,7 @@ class ProjectAssert {
ProjectAssert assertFile(String localPath, boolean exist) {
def candidate = file(localPath)
assertEquals 'Invalid presence (' + exist + ') for ' + localPath, exist, candidate.exists()
assertEquals "Invalid presence ('$exist') for $localPath", exist, candidate.exists()
this
}

View File

@ -110,7 +110,7 @@ abstract class AbstractInitializerControllerFormIntegrationTests extends Abstrac
}
HomePage home() {
def request = new WebRequest(new URL('http://localhost' + homeContext()), 'text/html')
def request = new WebRequest(new URL("http://localhost${homeContext()}"), 'text/html')
def home = webClient.getPage(request)
createHomePage(home)
}

View File

@ -55,7 +55,7 @@ abstract class AbstractInitializrControllerIntegrationTests {
final RestTemplate restTemplate = new RestTemplate()
String createUrl(String context) {
'http://localhost:' + port + context
"http://localhost:$port$context"
}
String htmlHome() {

View File

@ -34,8 +34,8 @@ class MainControllerEnvIntegrationTests extends AbstractInitializrControllerInte
void downloadCliWithCustomRepository() {
def entity = restTemplate.getForEntity(createUrl('/spring'), HttpEntity.class)
assertEquals HttpStatus.FOUND, entity.getStatusCode()
assertEquals new URI('https://repo.spring.io/lib-release/org/springframework/boot/spring-boot-cli/1.1.4.RELEASE' +
'/spring-boot-cli-1.1.4.RELEASE-bin.zip'), entity.getHeaders().getLocation()
def expected = "https://repo.spring.io/lib-release/org/springframework/boot/spring-boot-cli/1.1.4.RELEASE/spring-boot-cli-1.1.4.RELEASE-bin.zip"
assertEquals new URI(expected), entity.getHeaders().getLocation()
}
}

View File

@ -95,8 +95,8 @@ class MainControllerIntegrationTests extends AbstractInitializrControllerIntegra
private void assertSpringCliRedirect(String context, String extension) {
def entity = restTemplate.getForEntity(createUrl(context), ResponseEntity.class)
assertEquals HttpStatus.FOUND, entity.getStatusCode()
assertEquals new URI('https://repo.spring.io/release/org/springframework/boot/spring-boot-cli/1.1.4.RELEASE' +
'/spring-boot-cli-1.1.4.RELEASE-bin.'+extension), entity.getHeaders().getLocation()
def expected = "https://repo.spring.io/release/org/springframework/boot/spring-boot-cli/1.1.4.RELEASE/spring-boot-cli-1.1.4.RELEASE-bin.$extension"
assertEquals new URI(expected), entity.getHeaders().getLocation()
}
@ -149,47 +149,47 @@ class MainControllerIntegrationTests extends AbstractInitializrControllerIntegra
@Test
void homeIsForm() {
def body = htmlHome()
assertTrue 'Wrong body:\n' + body, body.contains('action="/starter.zip"')
assertTrue "Wrong body:\n$body", body.contains('action="/starter.zip"')
}
@Test
void homeIsJson() {
def body = restTemplate.getForObject(createUrl('/'), String)
assertTrue('Wrong body:\n' + body, body.contains('{"dependencies"'))
assertTrue("Wrong body:\n$body", body.contains('{"dependencies"'))
}
@Test
void webIsAddedPom() {
def body = restTemplate.getForObject(createUrl('/pom.xml?packaging=war'), String)
assertTrue('Wrong body:\n' + body, body.contains('spring-boot-starter-web'))
assertTrue('Wrong body:\n' + body, body.contains('provided'))
assertTrue("Wrong body:\n$body", body.contains('spring-boot-starter-web'))
assertTrue("Wrong body:\n$body", body.contains('provided'))
}
@Test
void webIsAddedGradle() {
def body = restTemplate.getForObject(createUrl('/build.gradle?packaging=war'), String)
assertTrue('Wrong body:\n' + body, body.contains('spring-boot-starter-web'))
assertTrue('Wrong body:\n' + body, body.contains('providedRuntime'))
assertTrue("Wrong body:\n$body", body.contains('spring-boot-starter-web'))
assertTrue("Wrong body:\n$body", body.contains('providedRuntime'))
}
@Test
void infoHasExternalProperties() {
def body = restTemplate.getForObject(createUrl('/info'), String)
assertTrue('Wrong body:\n' + body, body.contains('"spring-boot"'))
assertTrue('Wrong body:\n' + body, body.contains('"version":"1.1.4.RELEASE"'))
assertTrue("Wrong body:\n$body", body.contains('"spring-boot"'))
assertTrue("Wrong body:\n$body", body.contains('"version":"1.1.4.RELEASE"'))
}
@Test
void homeHasWebStyle() {
def body = htmlHome()
assertTrue('Wrong body:\n' + body, body.contains('name="style" value="web"'))
assertTrue("Wrong body:\n$body", body.contains('name="style" value="web"'))
}
@Test
void homeHasBootVersion() {
def body = htmlHome()
assertTrue('Wrong body:\n' + body, body.contains('name="bootVersion"'))
assertTrue('Wrong body:\n' + body, body.contains('1.2.0.BUILD-SNAPSHOT"'))
assertTrue("Wrong body:\n$body", body.contains('name="bootVersion"'))
assertTrue("Wrong body:\n$body", body.contains('1.2.0.BUILD-SNAPSHOT"'))
}
@Test
@ -218,7 +218,7 @@ class MainControllerIntegrationTests extends AbstractInitializrControllerIntegra
}
private static JSONObject readJson(String version) {
def resource = new ClassPathResource('metadata/test-default-' + version + '.json')
def resource = new ClassPathResource("metadata/test-default-$version" + ".json")
def stream = resource.inputStream
try {
def json = StreamUtils.copyToString(stream, Charset.forName('UTF-8'))

View File

@ -85,8 +85,8 @@ abstract class HomePage {
if (checkBox) {
checkBox.checked = true
} else {
throw new IllegalArgumentException('No dependency with name '
+ dependency + ' was found amongst ' + allStyles.keySet())
throw new IllegalArgumentException(
"No dependency with name '$dependency' was found amongst '${allStyles.keySet()}")
}
}
}