diff --git a/app.groovy b/app.groovy index 45582735..dfd63db1 100644 --- a/app.groovy +++ b/app.groovy @@ -10,7 +10,7 @@ class MainController { @Value('${info.home:http://localhost:8080/}') private String home - @Value('${info.spring-boot.version:1.0.1.RELEASE}') + @Value('${info.spring-boot.version:1.0.2.RELEASE}') private String bootVersion @Value('${TMPDIR:.}') @@ -29,6 +29,7 @@ class MainController { // sort lists model['styles'] = projects.styles.sort { it.name } model['types'] = projects.types.sort { it.name } + model['packagings'] = projects.packagings.sort { it.name } template 'home.html', model } @@ -43,7 +44,7 @@ class MainController { zipfileset(dir:'.', includes:'spring/**', excludes:'spring/bin/**') } } - log.info('Downloading: ' + download) + log.info('Uploading: ' + download) new ResponseEntity(download.bytes, ['Content-Type':'application/zip'] as HttpHeaders, HttpStatus.OK) } @@ -64,7 +65,7 @@ class MainController { log.info("Uploading: ${download} (${download.bytes.length} bytes)") def result = new ResponseEntity(download.bytes, ['Content-Type':'application/x-compress'] as HttpHeaders, HttpStatus.OK) - log.info('Notifying reactor: ' + download) + log.fine('Notifying reactor: ' + download) reactor.notify('tempfiles', Event.wrap(tempFiles)) result @@ -93,7 +94,7 @@ class MainController { result } - def getProjectFiles(File dir, PomRequest request) { + def getProjectFiles(File dir, PomRequest request) { def tempFiles = [] @@ -102,15 +103,21 @@ class MainController { dir.delete() dir.mkdirs() - String pom = new String(pom(request, model).body) - new File(dir, 'pom.xml').write(pom) - - String gradle = new String(gradle(request, model).body) - new File(dir, 'build.gradle').write(gradle) + if (request.type.contains('gradle')) { + String gradle = new String(gradle(request, model).body) + new File(dir, 'build.gradle').write(gradle) + } else { + String pom = new String(pom(request, model).body) + new File(dir, 'pom.xml').write(pom) + } File src = new File(new File(dir, 'src/main/java'),request.packageName.replace('.', '/')) src.mkdirs() write(src, 'Application.java', model) + + if (request.packaging=='war') { + write(src, 'ServletInitializer.java', model) + } File test = new File(new File(dir, 'src/test/java'),request.packageName.replace('.', '/')) test.mkdirs() @@ -154,6 +161,10 @@ class MainController { byte[] render(String path, PomRequest request, Map model) { + if (request.packaging=='war' && !request.style.any { isWebStyle(it) }) { + request.style << 'web' + } + def style = request.style log.info('Styles requested: ' + style) @@ -166,6 +177,7 @@ class MainController { model.name = request.name model.description = request.description model.packageName = request.packageName + model.packaging = request.packaging if (style==null || style.size()==0) { style = [''] @@ -182,6 +194,10 @@ class MainController { body } + private boolean isWebStyle(String style) { + return style.contains('web') || style.contains('thymeleaf') || style.contains('freemarker') || style.contains('velocity') || style.contains('groovy-template') + } + } @EnableReactor @@ -194,7 +210,7 @@ class TemporaryFileCleaner { @Selector('tempfiles') void clean(def tempFiles) { - log.info 'Tempfiles: ' + tempFiles + log.fine 'Tempfiles: ' + tempFiles if (tempFiles) { tempFiles.each { File file = it as File @@ -218,6 +234,7 @@ class PomRequest { String groupId = 'org.test' String artifactId String version = '0.0.1-SNAPSHOT' + String packaging = 'jar' String packageName String getArtifactId() { artifactId == null ? name : artifactId @@ -231,5 +248,17 @@ class PomRequest { @ConfigurationProperties(prefix='projects', ignoreUnknownFields=false) class Projects { List> styles - List> types + List types + List packagings + static class Packaging { + String name + String value + boolean selected + } + static class Type { + String name + String action + String value + boolean selected + } } \ No newline at end of file diff --git a/application.yml b/application.yml index ddbc677f..f18e0913 100644 --- a/application.yml +++ b/application.yml @@ -4,12 +4,20 @@ info: version: 0.1.0 # remember to update static/install.sh as well: spring-boot: - version: 1.1.0.RELEASE + version: 1.1.0.BUILD-SNAPSHOT projects: styles: - name: Web value: web + - name: Websocket + value: websocket + - name: Freemarker + value: freemarker + - name: Velocity + value: velocity + - name: Groovy Templates + value: groovy-templates - name: Thymeleaf value: thymeleaf - name: Actuator @@ -32,19 +40,43 @@ projects: value: data-mongodb - name: Redis value: redis + - name: Gemfire + value: data-gemfire + - name: Solr + value: data-solr - name: Rest Repositories value: data-rest - name: Remote Shell value: remote-shell - name: Mobile value: mobile + - name: Facebook + value: social-facebook + - name: LinkedIn + value: social-linkedin + - name: Twitter + value: social-twitter types: - name: Maven POM + action: /pom.xml value: pom.xml selected: false - name: Maven Project + action: /starter.zip value: starter.zip selected: true - - name: Gradle + - name: Gradle Config + action: /build.gradle value: build.gradle selected: false + - name: Gradle Project + action: /starter.zip + value: gradle.zip + selected: false + packagings: + - name: Jar + value: jar + selected: true + - name: War + value: war + selected: false diff --git a/templates/ServletInitializer.java b/templates/ServletInitializer.java new file mode 100644 index 00000000..20ace458 --- /dev/null +++ b/templates/ServletInitializer.java @@ -0,0 +1,13 @@ +package ${packageName}; + +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.context.web.SpringBootServletInitializer; + +public class ServletInitializer extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(Application.class); + } + +} diff --git a/templates/home.html b/templates/home.html index 36020487..ef8fb87f 100644 --- a/templates/home.html +++ b/templates/home.html @@ -49,7 +49,13 @@ <% types.each { %> <% } %> + + <% packagings.each { %> + <% } %> diff --git a/templates/starter-build.gradle b/templates/starter-build.gradle index 9d2fa0a7..2f0092d8 100644 --- a/templates/starter-build.gradle +++ b/templates/starter-build.gradle @@ -16,9 +16,11 @@ buildscript { apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'idea' -apply plugin: 'spring-boot' +apply plugin: 'spring-boot' <% if (packaging=='war') { %> +apply plugin: 'war' +<% } %> -jar { +<% if (packaging=='war') { %>war<% } else { %>jar<% } %> { baseName = '${artifactId}' version = '${version}' } diff --git a/templates/starter-pom.xml b/templates/starter-pom.xml index 9a4c09ef..74d67063 100644 --- a/templates/starter-pom.xml +++ b/templates/starter-pom.xml @@ -6,6 +6,7 @@ ${groupId} ${artifactId} ${version} + ${packaging} ${name} ${description} @@ -82,4 +83,4 @@ <% } %> - \ No newline at end of file + diff --git a/test/integration.groovy b/test/integration.groovy index 0e8ef4e8..f9aa534c 100644 --- a/test/integration.groovy +++ b/test/integration.groovy @@ -15,6 +15,12 @@ class IntegrationTests { assertTrue('Wrong body:\n' + body, body.contains('action="/starter.zip"')) } + @Test + void webIsAdded() { + String body = new TestRestTemplate().getForObject('http://localhost:' + port + '/pom.xml?packaging=war', String) + assertTrue('Wrong body:\n' + body, body.contains('spring-boot-starter-web')) + } + @Test void infoHasExternalProperties() { String body = new TestRestTemplate().getForObject('http://localhost:' + port + '/info', String) @@ -36,7 +42,7 @@ class IntegrationTests { } -// CLI compliled classes are not @ComponentScannable so we have to create +// CLI compiled classes are not @ComponentScannable so we have to create // an explicit configuration for the test @Configuration @Import([app.MainController, app.Projects, app.TemporaryFileCleaner])