Polish contribution

Closes gh-161
This commit is contained in:
Stephane Nicoll 2015-12-30 14:50:44 +01:00
parent 560333494c
commit 5b3eb6ccf0
12 changed files with 64 additions and 35 deletions

View File

@ -34,7 +34,8 @@ initializr:
version: 1.0.0.BUILD-SNAPSHOT
additionalBoms: [cloud-bom]
repositories: spring-snapshots,spring-milestones
kotlinVersion: 1.0.0-beta-2423
kotlin:
version: 1.0.0
dependencies:
- name: Core
content:

View File

@ -34,6 +34,7 @@ import static io.spring.initializr.util.GroovyTemplate.template
*
* @author Dave Syer
* @author Stephane Nicoll
* @author Sebastien Deleuze
* @since 1.0
*/
@Slf4j
@ -200,7 +201,9 @@ class ProjectGenerator {
protected Map initializeModel(ProjectRequest request) {
Assert.notNull request.bootVersion, 'boot version must not be null'
def model = [:]
request.resolve(metadataProvider.get())
def metadata = metadataProvider.get()
request.resolve(metadata)
// request resolved so we can log what has been requested
def dependencies = request.resolvedDependencies
@ -214,6 +217,9 @@ class ProjectGenerator {
model['providedDependencies'] = filterDependencies(dependencies, Dependency.SCOPE_PROVIDED)
model['testDependencies'] = filterDependencies(dependencies, Dependency.SCOPE_TEST)
// Add kotlinVersion
model['kotlinVersion'] = metadata.configuration.env.kotlin.version
// @SpringBootApplication available as from 1.2.0.RC1
model['useSpringBootApplication'] = VERSION_1_2_0_RC1
.compareTo(Version.safeParse(request.bootVersion)) <= 0

View File

@ -141,8 +141,6 @@ class ProjectRequest extends BasicProjectRequest {
initializeRepositories(metadata, requestedVersion)
kotlinVersion = metadata.configuration.env.kotlinVersion
afterResolution(metadata)
}

View File

@ -154,11 +154,6 @@ class InitializrConfiguration {
*/
boolean forceSsl = true
/**
* Kotlin version
*/
String kotlinVersion
/**
* The "BillOfMaterials" that are referenced in this instance, identified by an
* arbitrary identifier that can be used in the dependencies definition.
@ -171,6 +166,11 @@ class InitializrConfiguration {
*/
final Map<String, Repository> repositories = [:]
/**
* Kotlin-specific settings.
*/
final Kotlin kotlin = new Kotlin()
Env() {
repositories['spring-snapshots'] = new Repository(name: 'Spring Snapshots',
url: new URL('https://repo.spring.io/snapshot'), snapshotsEnabled: true)
@ -198,7 +198,7 @@ class InitializrConfiguration {
fallbackApplicationName = other.fallbackApplicationName
invalidApplicationNames = other.invalidApplicationNames
forceSsl = other.forceSsl
kotlinVersion = other.kotlinVersion
kotlin.version = other.kotlin.version
other.boms.each { id, bom ->
if (!boms[id]) {
boms[id] = bom
@ -211,6 +211,14 @@ class InitializrConfiguration {
}
}
static class Kotlin {
/**
* Kotlin version to use.
*/
String version
}
}
}

View File

@ -23,6 +23,12 @@
"sourceType": "io.spring.initializr.metadata.InitializrProperties",
"sourceMethod": "getEnv()"
},
{
"name": "initializr.env.kotlin",
"type": "io.spring.initializr.metadata.InitializrConfiguration$Env$Kotlin",
"sourceType": "io.spring.initializr.metadata.InitializrConfiguration$Env",
"sourceMethod": "getKotlin()"
},
{
"name": "initializr.group-id",
"type": "io.spring.initializr.metadata.InitializrProperties$SimpleElement",
@ -157,6 +163,12 @@
"sourceType": "io.spring.initializr.metadata.InitializrConfiguration$Env",
"defaultValue": ["org.springframework"]
},
{
"name": "initializr.env.kotlin.version",
"type": "java.lang.String",
"description": "Kotlin version to use.",
"sourceType": "io.spring.initializr.metadata.InitializrConfiguration$Env$Kotlin"
},
{
"name": "initializr.env.repositories",
"type": "java.util.Map<java.lang.String,io.spring.initializr.metadata.Repository>",

View File

@ -1,7 +1,7 @@
buildscript {
ext {
springBootVersion = '${bootVersion}'<% if (language=='kotlin') { %>
kotlinVersion = '${kotlinVersion}'<% } %>
kotlinVersion = '${kotlinVersion}'<% } %>
}
repositories {
mavenCentral()<% if (!bootVersion.contains("RELEASE")) { %>
@ -43,8 +43,7 @@ dependencies {<% compileDependencies.each { %>
compile('${it.groupId}:${it.artifactId}${it.version ? ":$it.version" : ""}')<% } %><% if (language=='groovy') { %>
compile('org.codehaus.groovy:groovy')<% } %><% if (language=='kotlin') { %>
compile("org.jetbrains.kotlin:kotlin-stdlib:\${kotlinVersion}")<% } %><% runtimeDependencies.each { %>
runtime('${it.groupId}:${it.artifactId}${it.version ? ":$it.version" : ""}')<% } %><% if (packaging=='war') { %>
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')<% } %><% providedDependencies.each { %>
runtime('${it.groupId}:${it.artifactId}${it.version ? ":$it.version" : ""}')<% } %><% providedDependencies.each { %>
providedRuntime('${it.groupId}:${it.artifactId}${it.version ? ":$it.version" : ""}')<% } %>
testCompile('org.springframework.boot:spring-boot-starter-test') <% testDependencies.each { %>
testCompile('${it.groupId}:${it.artifactId}${it.version ? ":$it.version" : ""}')<% } %>

View File

@ -177,7 +177,7 @@ class ProjectGenerationMetricsListenerTests {
def request = initialize()
request.language = 'kotlin'
request.resolve(metadata)
listener.onGeneratedProject(request)
fireProjectGeneratedEvent(request)
metricsAssert.hasValue(1, 'initializr.language.kotlin')
}

View File

@ -138,7 +138,7 @@ class InitializrMetadataBuilderTests {
assertEquals defaultEnv.springBootMetadataUrl, actualEnv.springBootMetadataUrl
assertEquals defaultEnv.fallbackApplicationName, actualEnv.fallbackApplicationName
assertEquals defaultEnv.forceSsl, actualEnv.forceSsl
assertEquals defaultEnv.kotlinVersion, actualEnv.kotlinVersion
assertEquals defaultEnv.kotlin.version, actualEnv.kotlin.version
}
@Test
@ -154,7 +154,7 @@ class InitializrMetadataBuilderTests {
assertEquals defaultEnv.springBootMetadataUrl, actualEnv.springBootMetadataUrl
assertEquals 'FooBarApplication', actualEnv.fallbackApplicationName
assertEquals false, actualEnv.forceSsl
assertEquals '1.0.0-beta-2423', actualEnv.kotlinVersion
assertEquals '1.0.0-beta-2423', actualEnv.kotlin.version
}
@Test

View File

@ -98,10 +98,7 @@ class ProjectAssert {
}
ProjectAssert isJavaProject(String expectedPackageName, String expectedApplicationName) {
String packageName = expectedPackageName.replace('.', '/')
hasFile("src/main/java/$packageName/${expectedApplicationName}.java",
"src/test/java/$packageName/${expectedApplicationName}Tests.java",
'src/main/resources/application.properties')
isGenericProject(expectedPackageName, expectedApplicationName, 'java', 'java')
}
ProjectAssert isJavaProject() {
@ -109,16 +106,11 @@ class ProjectAssert {
}
ProjectAssert isGroovyProject(String expectedPackageName, String expectedApplicationName) {
String packageName = expectedPackageName.replace('.', '/')
hasFile("src/main/groovy/$packageName/${expectedApplicationName}.groovy",
"src/test/groovy/$packageName/${expectedApplicationName}Tests.groovy",
'src/main/resources/application.properties')
isGenericProject(expectedPackageName, expectedApplicationName, 'groovy', 'groovy')
}
ProjectAssert isKotlinProject(String expectedApplicationName) {
hasFile("src/main/kotlin/com/example/${expectedApplicationName}.kt",
"src/test/kotlin/com/example/${expectedApplicationName}Tests.kt",
'src/main/resources/application.properties')
ProjectAssert isKotlinProject(String expectedPackageName, String expectedApplicationName) {
isGenericProject(expectedPackageName, expectedApplicationName, 'kotlin', 'kt')
}
ProjectAssert isGroovyProject() {
@ -126,7 +118,15 @@ class ProjectAssert {
}
ProjectAssert isKotlinProject() {
isKotlinProject(DEFAULT_APPLICATION_NAME)
isKotlinProject(DEFAULT_PACKAGE_NAME, DEFAULT_APPLICATION_NAME)
}
private ProjectAssert isGenericProject(String expectedPackageName, String expectedApplicationName,
String codeLocation, String extension) {
String packageName = expectedPackageName.replace('.', '/')
hasFile("src/main/$codeLocation/$packageName/${expectedApplicationName}.$extension",
"src/test/$codeLocation/$packageName/${expectedApplicationName}Tests.$extension",
'src/main/resources/application.properties')
}
ProjectAssert isJavaWarProject(String expectedApplicationName) {

View File

@ -202,8 +202,9 @@ class ProjectGenerationSmokeTests extends AbstractInitializrControllerIntegratio
}
@Test
void createDefaultKotlinProject() {
void createKotlinProject() {
toHome {
page.advanced.click()
page.language = 'kotlin'
page.generateProject.click()
at HomePage
@ -216,7 +217,6 @@ class ProjectGenerationSmokeTests extends AbstractInitializrControllerIntegratio
}
}
@Test
void createWarProject() {
toHome {
@ -298,18 +298,20 @@ class ProjectGenerationSmokeTests extends AbstractInitializrControllerIntegratio
@Test
void createKotlinProjectWithCustomDefaults() {
toHome {
page.language = 'kotlin'
page.groupId = 'org.biz'
page.artifactId = 'kotlin-project'
page.advanced.click()
page.language = 'kotlin'
page.name = 'My Kotlin project'
page.description = 'A description for my Kotlin project'
page.packageName = 'com.example.biz'
page.dependency('web').click()
page.dependency('data-jpa').click()
page.generateProject.click()
at HomePage
def projectAssert = zipProjectAssert(from('kotlin-project.zip'))
projectAssert.hasBaseDir("kotlin-project").isMavenProject()
.isGroovyProject('MyKotlinProjectApplication')
.isKotlinProject('com.example.biz', 'MyKotlinProjectApplication')
.hasStaticAndTemplatesResources(true)
.pomAssert().hasGroupId('org.biz').hasArtifactId('kotlin-project')
.hasName('My Kotlin project').hasDescription('A description for my Kotlin project')

View File

@ -6,4 +6,5 @@ initializr:
fallbackApplicationName: FooBarApplication
invalidApplicationNames:
- InvalidApplication
kotlinVersion: 1.0.0-beta-2423
kotlin:
version: 1.0.0-beta-2423

View File

@ -33,7 +33,9 @@
"artifactRepository": "https://repo.spring.io/release/",
"fallbackApplicationName": "Application",
"forceSsl": true,
"kotlinVersion": null,
"kotlin": {
"version": null
},
"googleAnalyticsTrackingCode": null,
"invalidApplicationNames": [
"SpringApplication",