Fix war kotlin project

This commit fixes the generation of a web-based project using Kotlin by
propertly detecting the `ServletInitializer` template.

Closes gh-217
This commit is contained in:
Stephane Nicoll
2016-04-08 16:33:46 +02:00
parent faba863db3
commit 544f7482d3
3 changed files with 26 additions and 4 deletions

View File

@@ -132,7 +132,7 @@ class ProjectGenerator {
write(new File(src, "${applicationName}.${extension}"), "Application.$extension", model)
if (request.packaging == 'war') {
def fileName = "ServletInitializer.$language"
def fileName = "ServletInitializer.$extension"
write(new File(src, fileName), fileName, model)
}

View File

@@ -554,6 +554,14 @@ class ProjectGeneratorTests {
.hasDependenciesCount(3)
}
@Test
void kotlinWar() {
def request = createProjectRequest('web')
request.language = 'kotlin'
request.packaging = 'war'
generateProject(request).isKotlinWarProject()
}
@Test
void invalidType() {
def request = createProjectRequest('web')

View File

@@ -130,15 +130,29 @@ class ProjectAssert {
}
ProjectAssert isJavaWarProject(String expectedApplicationName) {
isJavaProject(DEFAULT_PACKAGE_NAME, expectedApplicationName)
.hasStaticAndTemplatesResources(true)
.hasFile('src/main/java/com/example/ServletInitializer.java')
isGenericWarProject(DEFAULT_PACKAGE_NAME, expectedApplicationName, 'java', 'java')
}
ProjectAssert isJavaWarProject() {
isJavaWarProject(DEFAULT_APPLICATION_NAME)
}
ProjectAssert isGroovyWarProject() {
isGenericWarProject(DEFAULT_PACKAGE_NAME, DEFAULT_APPLICATION_NAME, 'groovy', 'groovy')
}
ProjectAssert isKotlinWarProject() {
isGenericWarProject(DEFAULT_PACKAGE_NAME, DEFAULT_APPLICATION_NAME, 'kotlin', 'kt')
}
ProjectAssert isGenericWarProject(String expectedPackageName, String expectedApplicationName,
String codeLocation, String extension) {
String packageName = expectedPackageName.replace('.', '/')
isGenericProject(expectedPackageName, expectedApplicationName, codeLocation, extension)
.hasStaticAndTemplatesResources(true)
.hasFile("src/main/$codeLocation/$packageName/ServletInitializer.$extension")
}
ProjectAssert hasStaticAndTemplatesResources(boolean web) {
assertFile('src/main/resources/templates', web)
assertFile('src/main/resources/static', web)