mirror of
https://gitee.com/dcren/initializr.git
synced 2025-05-05 21:28:03 +08:00
Polish contribution
Closes gh-161
This commit is contained in:
parent
560333494c
commit
5b3eb6ccf0
@ -34,7 +34,8 @@ initializr:
|
|||||||
version: 1.0.0.BUILD-SNAPSHOT
|
version: 1.0.0.BUILD-SNAPSHOT
|
||||||
additionalBoms: [cloud-bom]
|
additionalBoms: [cloud-bom]
|
||||||
repositories: spring-snapshots,spring-milestones
|
repositories: spring-snapshots,spring-milestones
|
||||||
kotlinVersion: 1.0.0-beta-2423
|
kotlin:
|
||||||
|
version: 1.0.0
|
||||||
dependencies:
|
dependencies:
|
||||||
- name: Core
|
- name: Core
|
||||||
content:
|
content:
|
||||||
|
@ -34,6 +34,7 @@ import static io.spring.initializr.util.GroovyTemplate.template
|
|||||||
*
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
|
* @author Sebastien Deleuze
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ -200,7 +201,9 @@ class ProjectGenerator {
|
|||||||
protected Map initializeModel(ProjectRequest request) {
|
protected Map initializeModel(ProjectRequest request) {
|
||||||
Assert.notNull request.bootVersion, 'boot version must not be null'
|
Assert.notNull request.bootVersion, 'boot version must not be null'
|
||||||
def model = [:]
|
def model = [:]
|
||||||
request.resolve(metadataProvider.get())
|
def metadata = metadataProvider.get()
|
||||||
|
|
||||||
|
request.resolve(metadata)
|
||||||
|
|
||||||
// request resolved so we can log what has been requested
|
// request resolved so we can log what has been requested
|
||||||
def dependencies = request.resolvedDependencies
|
def dependencies = request.resolvedDependencies
|
||||||
@ -214,6 +217,9 @@ class ProjectGenerator {
|
|||||||
model['providedDependencies'] = filterDependencies(dependencies, Dependency.SCOPE_PROVIDED)
|
model['providedDependencies'] = filterDependencies(dependencies, Dependency.SCOPE_PROVIDED)
|
||||||
model['testDependencies'] = filterDependencies(dependencies, Dependency.SCOPE_TEST)
|
model['testDependencies'] = filterDependencies(dependencies, Dependency.SCOPE_TEST)
|
||||||
|
|
||||||
|
// Add kotlinVersion
|
||||||
|
model['kotlinVersion'] = metadata.configuration.env.kotlin.version
|
||||||
|
|
||||||
// @SpringBootApplication available as from 1.2.0.RC1
|
// @SpringBootApplication available as from 1.2.0.RC1
|
||||||
model['useSpringBootApplication'] = VERSION_1_2_0_RC1
|
model['useSpringBootApplication'] = VERSION_1_2_0_RC1
|
||||||
.compareTo(Version.safeParse(request.bootVersion)) <= 0
|
.compareTo(Version.safeParse(request.bootVersion)) <= 0
|
||||||
|
@ -141,8 +141,6 @@ class ProjectRequest extends BasicProjectRequest {
|
|||||||
|
|
||||||
initializeRepositories(metadata, requestedVersion)
|
initializeRepositories(metadata, requestedVersion)
|
||||||
|
|
||||||
kotlinVersion = metadata.configuration.env.kotlinVersion
|
|
||||||
|
|
||||||
afterResolution(metadata)
|
afterResolution(metadata)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,11 +154,6 @@ class InitializrConfiguration {
|
|||||||
*/
|
*/
|
||||||
boolean forceSsl = true
|
boolean forceSsl = true
|
||||||
|
|
||||||
/**
|
|
||||||
* Kotlin version
|
|
||||||
*/
|
|
||||||
String kotlinVersion
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The "BillOfMaterials" that are referenced in this instance, identified by an
|
* The "BillOfMaterials" that are referenced in this instance, identified by an
|
||||||
* arbitrary identifier that can be used in the dependencies definition.
|
* arbitrary identifier that can be used in the dependencies definition.
|
||||||
@ -171,6 +166,11 @@ class InitializrConfiguration {
|
|||||||
*/
|
*/
|
||||||
final Map<String, Repository> repositories = [:]
|
final Map<String, Repository> repositories = [:]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kotlin-specific settings.
|
||||||
|
*/
|
||||||
|
final Kotlin kotlin = new Kotlin()
|
||||||
|
|
||||||
Env() {
|
Env() {
|
||||||
repositories['spring-snapshots'] = new Repository(name: 'Spring Snapshots',
|
repositories['spring-snapshots'] = new Repository(name: 'Spring Snapshots',
|
||||||
url: new URL('https://repo.spring.io/snapshot'), snapshotsEnabled: true)
|
url: new URL('https://repo.spring.io/snapshot'), snapshotsEnabled: true)
|
||||||
@ -198,7 +198,7 @@ class InitializrConfiguration {
|
|||||||
fallbackApplicationName = other.fallbackApplicationName
|
fallbackApplicationName = other.fallbackApplicationName
|
||||||
invalidApplicationNames = other.invalidApplicationNames
|
invalidApplicationNames = other.invalidApplicationNames
|
||||||
forceSsl = other.forceSsl
|
forceSsl = other.forceSsl
|
||||||
kotlinVersion = other.kotlinVersion
|
kotlin.version = other.kotlin.version
|
||||||
other.boms.each { id, bom ->
|
other.boms.each { id, bom ->
|
||||||
if (!boms[id]) {
|
if (!boms[id]) {
|
||||||
boms[id] = bom
|
boms[id] = bom
|
||||||
@ -211,6 +211,14 @@ class InitializrConfiguration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class Kotlin {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kotlin version to use.
|
||||||
|
*/
|
||||||
|
String version
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,12 @@
|
|||||||
"sourceType": "io.spring.initializr.metadata.InitializrProperties",
|
"sourceType": "io.spring.initializr.metadata.InitializrProperties",
|
||||||
"sourceMethod": "getEnv()"
|
"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",
|
"name": "initializr.group-id",
|
||||||
"type": "io.spring.initializr.metadata.InitializrProperties$SimpleElement",
|
"type": "io.spring.initializr.metadata.InitializrProperties$SimpleElement",
|
||||||
@ -157,6 +163,12 @@
|
|||||||
"sourceType": "io.spring.initializr.metadata.InitializrConfiguration$Env",
|
"sourceType": "io.spring.initializr.metadata.InitializrConfiguration$Env",
|
||||||
"defaultValue": ["org.springframework"]
|
"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",
|
"name": "initializr.env.repositories",
|
||||||
"type": "java.util.Map<java.lang.String,io.spring.initializr.metadata.Repository>",
|
"type": "java.util.Map<java.lang.String,io.spring.initializr.metadata.Repository>",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
ext {
|
ext {
|
||||||
springBootVersion = '${bootVersion}'<% if (language=='kotlin') { %>
|
springBootVersion = '${bootVersion}'<% if (language=='kotlin') { %>
|
||||||
kotlinVersion = '${kotlinVersion}'<% } %>
|
kotlinVersion = '${kotlinVersion}'<% } %>
|
||||||
}
|
}
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()<% if (!bootVersion.contains("RELEASE")) { %>
|
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('${it.groupId}:${it.artifactId}${it.version ? ":$it.version" : ""}')<% } %><% if (language=='groovy') { %>
|
||||||
compile('org.codehaus.groovy:groovy')<% } %><% if (language=='kotlin') { %>
|
compile('org.codehaus.groovy:groovy')<% } %><% if (language=='kotlin') { %>
|
||||||
compile("org.jetbrains.kotlin:kotlin-stdlib:\${kotlinVersion}")<% } %><% runtimeDependencies.each { %>
|
compile("org.jetbrains.kotlin:kotlin-stdlib:\${kotlinVersion}")<% } %><% runtimeDependencies.each { %>
|
||||||
runtime('${it.groupId}:${it.artifactId}${it.version ? ":$it.version" : ""}')<% } %><% if (packaging=='war') { %>
|
runtime('${it.groupId}:${it.artifactId}${it.version ? ":$it.version" : ""}')<% } %><% providedDependencies.each { %>
|
||||||
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')<% } %><% providedDependencies.each { %>
|
|
||||||
providedRuntime('${it.groupId}:${it.artifactId}${it.version ? ":$it.version" : ""}')<% } %>
|
providedRuntime('${it.groupId}:${it.artifactId}${it.version ? ":$it.version" : ""}')<% } %>
|
||||||
testCompile('org.springframework.boot:spring-boot-starter-test') <% testDependencies.each { %>
|
testCompile('org.springframework.boot:spring-boot-starter-test') <% testDependencies.each { %>
|
||||||
testCompile('${it.groupId}:${it.artifactId}${it.version ? ":$it.version" : ""}')<% } %>
|
testCompile('${it.groupId}:${it.artifactId}${it.version ? ":$it.version" : ""}')<% } %>
|
||||||
|
@ -177,7 +177,7 @@ class ProjectGenerationMetricsListenerTests {
|
|||||||
def request = initialize()
|
def request = initialize()
|
||||||
request.language = 'kotlin'
|
request.language = 'kotlin'
|
||||||
request.resolve(metadata)
|
request.resolve(metadata)
|
||||||
listener.onGeneratedProject(request)
|
fireProjectGeneratedEvent(request)
|
||||||
metricsAssert.hasValue(1, 'initializr.language.kotlin')
|
metricsAssert.hasValue(1, 'initializr.language.kotlin')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ class InitializrMetadataBuilderTests {
|
|||||||
assertEquals defaultEnv.springBootMetadataUrl, actualEnv.springBootMetadataUrl
|
assertEquals defaultEnv.springBootMetadataUrl, actualEnv.springBootMetadataUrl
|
||||||
assertEquals defaultEnv.fallbackApplicationName, actualEnv.fallbackApplicationName
|
assertEquals defaultEnv.fallbackApplicationName, actualEnv.fallbackApplicationName
|
||||||
assertEquals defaultEnv.forceSsl, actualEnv.forceSsl
|
assertEquals defaultEnv.forceSsl, actualEnv.forceSsl
|
||||||
assertEquals defaultEnv.kotlinVersion, actualEnv.kotlinVersion
|
assertEquals defaultEnv.kotlin.version, actualEnv.kotlin.version
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -154,7 +154,7 @@ class InitializrMetadataBuilderTests {
|
|||||||
assertEquals defaultEnv.springBootMetadataUrl, actualEnv.springBootMetadataUrl
|
assertEquals defaultEnv.springBootMetadataUrl, actualEnv.springBootMetadataUrl
|
||||||
assertEquals 'FooBarApplication', actualEnv.fallbackApplicationName
|
assertEquals 'FooBarApplication', actualEnv.fallbackApplicationName
|
||||||
assertEquals false, actualEnv.forceSsl
|
assertEquals false, actualEnv.forceSsl
|
||||||
assertEquals '1.0.0-beta-2423', actualEnv.kotlinVersion
|
assertEquals '1.0.0-beta-2423', actualEnv.kotlin.version
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -98,10 +98,7 @@ class ProjectAssert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ProjectAssert isJavaProject(String expectedPackageName, String expectedApplicationName) {
|
ProjectAssert isJavaProject(String expectedPackageName, String expectedApplicationName) {
|
||||||
String packageName = expectedPackageName.replace('.', '/')
|
isGenericProject(expectedPackageName, expectedApplicationName, 'java', 'java')
|
||||||
hasFile("src/main/java/$packageName/${expectedApplicationName}.java",
|
|
||||||
"src/test/java/$packageName/${expectedApplicationName}Tests.java",
|
|
||||||
'src/main/resources/application.properties')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectAssert isJavaProject() {
|
ProjectAssert isJavaProject() {
|
||||||
@ -109,16 +106,11 @@ class ProjectAssert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ProjectAssert isGroovyProject(String expectedPackageName, String expectedApplicationName) {
|
ProjectAssert isGroovyProject(String expectedPackageName, String expectedApplicationName) {
|
||||||
String packageName = expectedPackageName.replace('.', '/')
|
isGenericProject(expectedPackageName, expectedApplicationName, 'groovy', 'groovy')
|
||||||
hasFile("src/main/groovy/$packageName/${expectedApplicationName}.groovy",
|
|
||||||
"src/test/groovy/$packageName/${expectedApplicationName}Tests.groovy",
|
|
||||||
'src/main/resources/application.properties')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectAssert isKotlinProject(String expectedApplicationName) {
|
ProjectAssert isKotlinProject(String expectedPackageName, String expectedApplicationName) {
|
||||||
hasFile("src/main/kotlin/com/example/${expectedApplicationName}.kt",
|
isGenericProject(expectedPackageName, expectedApplicationName, 'kotlin', 'kt')
|
||||||
"src/test/kotlin/com/example/${expectedApplicationName}Tests.kt",
|
|
||||||
'src/main/resources/application.properties')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectAssert isGroovyProject() {
|
ProjectAssert isGroovyProject() {
|
||||||
@ -126,7 +118,15 @@ class ProjectAssert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ProjectAssert isKotlinProject() {
|
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) {
|
ProjectAssert isJavaWarProject(String expectedApplicationName) {
|
||||||
|
@ -202,8 +202,9 @@ class ProjectGenerationSmokeTests extends AbstractInitializrControllerIntegratio
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createDefaultKotlinProject() {
|
void createKotlinProject() {
|
||||||
toHome {
|
toHome {
|
||||||
|
page.advanced.click()
|
||||||
page.language = 'kotlin'
|
page.language = 'kotlin'
|
||||||
page.generateProject.click()
|
page.generateProject.click()
|
||||||
at HomePage
|
at HomePage
|
||||||
@ -216,7 +217,6 @@ class ProjectGenerationSmokeTests extends AbstractInitializrControllerIntegratio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createWarProject() {
|
void createWarProject() {
|
||||||
toHome {
|
toHome {
|
||||||
@ -298,18 +298,20 @@ class ProjectGenerationSmokeTests extends AbstractInitializrControllerIntegratio
|
|||||||
@Test
|
@Test
|
||||||
void createKotlinProjectWithCustomDefaults() {
|
void createKotlinProjectWithCustomDefaults() {
|
||||||
toHome {
|
toHome {
|
||||||
page.language = 'kotlin'
|
|
||||||
page.groupId = 'org.biz'
|
page.groupId = 'org.biz'
|
||||||
page.artifactId = 'kotlin-project'
|
page.artifactId = 'kotlin-project'
|
||||||
|
page.advanced.click()
|
||||||
|
page.language = 'kotlin'
|
||||||
page.name = 'My Kotlin project'
|
page.name = 'My Kotlin project'
|
||||||
page.description = 'A description for my Kotlin project'
|
page.description = 'A description for my Kotlin project'
|
||||||
|
page.packageName = 'com.example.biz'
|
||||||
page.dependency('web').click()
|
page.dependency('web').click()
|
||||||
page.dependency('data-jpa').click()
|
page.dependency('data-jpa').click()
|
||||||
page.generateProject.click()
|
page.generateProject.click()
|
||||||
at HomePage
|
at HomePage
|
||||||
def projectAssert = zipProjectAssert(from('kotlin-project.zip'))
|
def projectAssert = zipProjectAssert(from('kotlin-project.zip'))
|
||||||
projectAssert.hasBaseDir("kotlin-project").isMavenProject()
|
projectAssert.hasBaseDir("kotlin-project").isMavenProject()
|
||||||
.isGroovyProject('MyKotlinProjectApplication')
|
.isKotlinProject('com.example.biz', 'MyKotlinProjectApplication')
|
||||||
.hasStaticAndTemplatesResources(true)
|
.hasStaticAndTemplatesResources(true)
|
||||||
.pomAssert().hasGroupId('org.biz').hasArtifactId('kotlin-project')
|
.pomAssert().hasGroupId('org.biz').hasArtifactId('kotlin-project')
|
||||||
.hasName('My Kotlin project').hasDescription('A description for my Kotlin project')
|
.hasName('My Kotlin project').hasDescription('A description for my Kotlin project')
|
||||||
|
@ -6,4 +6,5 @@ initializr:
|
|||||||
fallbackApplicationName: FooBarApplication
|
fallbackApplicationName: FooBarApplication
|
||||||
invalidApplicationNames:
|
invalidApplicationNames:
|
||||||
- InvalidApplication
|
- InvalidApplication
|
||||||
kotlinVersion: 1.0.0-beta-2423
|
kotlin:
|
||||||
|
version: 1.0.0-beta-2423
|
@ -33,7 +33,9 @@
|
|||||||
"artifactRepository": "https://repo.spring.io/release/",
|
"artifactRepository": "https://repo.spring.io/release/",
|
||||||
"fallbackApplicationName": "Application",
|
"fallbackApplicationName": "Application",
|
||||||
"forceSsl": true,
|
"forceSsl": true,
|
||||||
"kotlinVersion": null,
|
"kotlin": {
|
||||||
|
"version": null
|
||||||
|
},
|
||||||
"googleAnalyticsTrackingCode": null,
|
"googleAnalyticsTrackingCode": null,
|
||||||
"invalidApplicationNames": [
|
"invalidApplicationNames": [
|
||||||
"SpringApplication",
|
"SpringApplication",
|
||||||
|
Loading…
Reference in New Issue
Block a user