diff --git a/app.groovy b/app.groovy index be7d820c..f2d1e3d5 100644 --- a/app.groovy +++ b/app.groovy @@ -22,7 +22,13 @@ class MainController { @Autowired private Projects projects - @RequestMapping('/') + @RequestMapping(value='/') + @ResponseBody + Projects projects() { + projects + } + + @RequestMapping(value='/', produces='text/html') @ResponseBody String home() { def model = [:] @@ -31,6 +37,7 @@ class MainController { model['types'] = projects.types.sort { it.name } model['packagings'] = projects.packagings.sort { it.name } model['javaVersions'] = projects.javaVersions + model['languages'] = projects.languages template 'home.html', model } @@ -112,15 +119,17 @@ class MainController { new File(dir, 'pom.xml').write(pom) } - File src = new File(new File(dir, 'src/main/java'),request.packageName.replace('.', '/')) + String language = request.language + + File src = new File(new File(dir, 'src/main/' + language),request.packageName.replace('.', '/')) src.mkdirs() - write(src, 'Application.java', model) + write(src, 'Application.' + language, model) if (request.packaging=='war') { - write(src, 'ServletInitializer.java', model) + write(src, 'ServletInitializer.' + language, model) } - File test = new File(new File(dir, 'src/test/java'),request.packageName.replace('.', '/')) + File test = new File(new File(dir, 'src/test/' + language),request.packageName.replace('.', '/')) test.mkdirs() if (model.styles.contains('-web')) { model.testAnnotations = '@WebAppConfiguration\n' @@ -129,7 +138,7 @@ class MainController { model.testAnnotations = '' model.testImports = '' } - write(test, 'ApplicationTests.java', model) + write(test, 'ApplicationTests.' + language, model) File resources = new File(dir, 'src/main/resources') resources.mkdirs() @@ -180,6 +189,7 @@ class MainController { model.packageName = request.packageName model.packaging = request.packaging model.javaVersion = request.javaVersion + model.language = request.language if (style==null || style.size()==0) { style = [''] @@ -237,6 +247,7 @@ class PomRequest { String artifactId String version = '0.0.1-SNAPSHOT' String packaging = 'jar' + String language = 'java' String packageName String javaVersion = '1.7' String getArtifactId() { @@ -254,6 +265,12 @@ class Projects { List types List packagings List javaVersions + List languages + static class Language { + String name + String value + boolean selected + } static class JavaVersion { String value boolean selected diff --git a/application.yml b/application.yml index 8edf6224..ebbad5b3 100644 --- a/application.yml +++ b/application.yml @@ -87,3 +87,10 @@ projects: selected: true - value: 1.8 selected: false + languages: + - name: Groovy + value: groovy + selected: false + - name: Java + value: java + selected: true diff --git a/templates/Application.groovy b/templates/Application.groovy new file mode 100644 index 00000000..d31ef8d6 --- /dev/null +++ b/templates/Application.groovy @@ -0,0 +1,16 @@ +package ${packageName} + +import org.springframework.boot.SpringApplication +import org.springframework.boot.autoconfigure.EnableAutoConfiguration +import org.springframework.context.annotation.ComponentScan +import org.springframework.context.annotation.Configuration + +@Configuration +@ComponentScan +@EnableAutoConfiguration +class Application { + + static void main(String[] args) { + SpringApplication.run Application, args + } +} diff --git a/templates/ApplicationTests.groovy b/templates/ApplicationTests.groovy new file mode 100644 index 00000000..749f35ad --- /dev/null +++ b/templates/ApplicationTests.groovy @@ -0,0 +1,16 @@ +package ${packageName} + +import org.junit.Test +import org.junit.runner.RunWith +${testImports}import org.springframework.boot.test.SpringApplicationConfiguration +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner + +@RunWith(SpringJUnit4ClassRunner) +@SpringApplicationConfiguration(classes = Application) +${testAnnotations}class ApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/templates/ServletInitializer.groovy b/templates/ServletInitializer.groovy new file mode 100644 index 00000000..b490c903 --- /dev/null +++ b/templates/ServletInitializer.groovy @@ -0,0 +1,13 @@ +package ${packageName} + +import org.springframework.boot.builder.SpringApplicationBuilder +import org.springframework.boot.context.web.SpringBootServletInitializer + +class ServletInitializer extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + application.sources(Application) + } + +} diff --git a/templates/home.html b/templates/home.html index d14d8d38..a899008d 100644 --- a/templates/home.html +++ b/templates/home.html @@ -64,6 +64,12 @@ ${it.value} <% } %> + + <% languages.each { %> + <% } %> diff --git a/templates/starter-build.gradle b/templates/starter-build.gradle index 7c525d0a..ec242d33 100644 --- a/templates/starter-build.gradle +++ b/templates/starter-build.gradle @@ -13,7 +13,7 @@ buildscript { } } -apply plugin: 'java' +apply plugin: '${language}' apply plugin: 'eclipse' apply plugin: 'idea' apply plugin: 'spring-boot' <% if (packaging=='war') { %> @@ -35,8 +35,9 @@ repositories { } dependencies {<% styles.each { %> - compile("org.springframework.boot:spring-boot-starter${it}:\${springBootVersion}")<% } %> - testCompile("org.springframework.boot:spring-boot-starter-test:\${springBootVersion}") + compile("org.springframework.boot:spring-boot-starter${it}")<% } %> + <% if (language=='groovy') { %>compile("org.codehaus.groovy:groovy")<% } %> + testCompile("org.springframework.boot:spring-boot-starter-test") } task wrapper(type: Wrapper) { diff --git a/templates/starter-pom.xml b/templates/starter-pom.xml index 49e3d9f7..6ebe1e75 100644 --- a/templates/starter-pom.xml +++ b/templates/starter-pom.xml @@ -22,6 +22,10 @@ org.springframework.boot spring-boot-starter${it} + <% } %><% if (language=='groovy') { %> + + org.codehaus.groovy + groovy <% } %> org.springframework.boot @@ -41,7 +45,31 @@ org.springframework.boot spring-boot-maven-plugin - + <% if (language=='groovy') { %> + + maven-compiler-plugin + + groovy-eclipse-compiler + + + + org.codehaus.groovy + groovy-eclipse-compiler + 2.8.0-01 + + + org.codehaus.groovy + groovy-eclipse-batch + 2.1.8-01 + + + + + org.codehaus.groovy + groovy-eclipse-compiler + 2.8.0-01 + true + <% } %> <% if (!bootVersion.contains("RELEASE")) { %> diff --git a/test/integration.groovy b/test/integration.groovy index f9aa534c..024c8c4d 100644 --- a/test/integration.groovy +++ b/test/integration.groovy @@ -8,13 +8,25 @@ class IntegrationTests { @Value('${local.server.port}') int port + + private String home() { + HttpHeaders headers = new HttpHeaders() + headers.setAccept([MediaType.TEXT_HTML]) + new TestRestTemplate().exchange('http://localhost:' + port, HttpMethod.GET, new HttpEntity(headers), String).body + } @Test void homeIsForm() { - String body = new TestRestTemplate().getForObject('http://localhost:' + port, String) + String body = home() assertTrue('Wrong body:\n' + body, body.contains('action="/starter.zip"')) } + @Test + void homeIsJson() { + String body = new TestRestTemplate().getForObject('http://localhost:' + port, String) + assertTrue('Wrong body:\n' + body, body.contains('{"styles"')) + } + @Test void webIsAdded() { String body = new TestRestTemplate().getForObject('http://localhost:' + port + '/pom.xml?packaging=war', String) @@ -29,7 +41,7 @@ class IntegrationTests { @Test void homeHasWebStyle() { - String body = new TestRestTemplate().getForObject('http://localhost:' + port, String) + String body = home() assertTrue('Wrong body:\n' + body, body.contains('name="style" value="web"')) }