From 9d4a6bf6c51d2f656543bd88b2ae7374043491f2 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Mon, 22 Jul 2013 14:40:50 +0100 Subject: [PATCH] Download starter.zip from home page --- .cfignore | 14 +++++++++++++ .gitignore | 1 + app.groovy | 41 +++++++++++++++++++++++++++++--------- manifest.yml | 2 +- system.properties | 1 + templates/Application.java | 14 +++++++++++++ templates/home.html | 2 +- templates/starter-pom.xml | 8 ++++---- 8 files changed, 68 insertions(+), 15 deletions(-) create mode 100644 .cfignore create mode 100644 system.properties create mode 100644 templates/Application.java diff --git a/.cfignore b/.cfignore new file mode 100644 index 00000000..87bb3d5c --- /dev/null +++ b/.cfignore @@ -0,0 +1,14 @@ +.gradle +*.sw? +.#* +*# +*~ +.classpath +.project +.settings +bin +build +target +.springBeans +tmp* +spring.zip diff --git a/.gitignore b/.gitignore index 974d784c..7cb15ab0 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ bin build target .springBeans +tmp* spring grapes spring.zip diff --git a/app.groovy b/app.groovy index 82051916..eccd04df 100644 --- a/app.groovy +++ b/app.groovy @@ -50,14 +50,42 @@ class MainController { new ResponseEntity(download.bytes, ["Content-Type":"application/zip"] as HttpHeaders, HttpStatus.OK) } + @RequestMapping("/starter") + @ResponseBody + ResponseEntity spring(PomRequest request) { + + def model = [:] + String pom = new String(pom(request, model).body) + File dir = File.createTempFile("tmp","",new File(tmpdir)); + dir.delete() + dir.mkdirs() + new File(dir, "pom.xml").write(pom) + + File src = new File(new File(dir, "src/main/java"),request.packageName.replace(".", "/")) + src.mkdirs() + + def body = template "Application.java", model + log.info("Creating: " + src + "Application.java") + new File(src, "Application.java").write(body) + + File download = new File(tmpdir, dir.name + ".zip") + log.info("Creating: " + download) + + new AntBuilder().zip(destfile: download) { + zipfileset(dir:dir, includes:"**") + } + log.info("Downloading: " + download) + new ResponseEntity(download.bytes, ["Content-Type":"application/zip"] as HttpHeaders, HttpStatus.OK) + + } + @RequestMapping("/pom") @ResponseBody - ResponseEntity pom(PomRequest request) { + ResponseEntity pom(PomRequest request, Map model) { def style = request.style log.info("Styles requested: " + style) - def model = [:] model.groupId = request.groupId model.artifactId = request.artifactId model.version = request.version @@ -68,7 +96,7 @@ class MainController { if (style==null || style.size()==0) { style = [""] } - model["styles"] = style.collect{ it=="" ? "" : it + "-" } + model["styles"] = style.collect{ it=="" ? "" : "-" + it } log.info("Model: " + model) @@ -107,13 +135,8 @@ class MainController { } -@Grab("org.springframework.security:spring-security-config:3.2.0.M2") -@Grab(value="org.springframework.security:spring-security-web:3.2.0.M2", transitive=false) -import org.springframework.security.config.annotation.web.* -import org.springframework.security.authentication.* -import org.springframework.security.core.Authentication -import org.springframework.security.core.authority.AuthorityUtils import org.springframework.actuate.properties.SecurityProperties +@EnableWebSecurity @Configuration @Log class SecurityConfiguration { diff --git a/manifest.yml b/manifest.yml index 10eb2ba7..b551e4a1 100644 --- a/manifest.yml +++ b/manifest.yml @@ -6,4 +6,4 @@ applications: url: initializr.cfapps.io path: . command: java -jar ./spring/lib/*.jar run --local app.groovy -- --server.port=$PORT - buildpack: https://github.com/cloudfoundry/cloudfoundry-buildpack-java +# buildpack: https://github.com/dsyer/cloudfoundry-buildpack-java diff --git a/system.properties b/system.properties new file mode 100644 index 00000000..3e06d15e --- /dev/null +++ b/system.properties @@ -0,0 +1 @@ +java.runtime.version=1.6 \ No newline at end of file diff --git a/templates/Application.java b/templates/Application.java new file mode 100644 index 00000000..66cd599a --- /dev/null +++ b/templates/Application.java @@ -0,0 +1,14 @@ +package ${packageName}; + +import org.springframework.bootstrap.SpringApplication; +import org.springframework.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; + +@ComponentScan +@EnableAutoConfiguration +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/templates/home.html b/templates/home.html index 50c80fb1..77308492 100644 --- a/templates/home.html +++ b/templates/home.html @@ -39,7 +39,7 @@

Spring Initializr

-
+ diff --git a/templates/starter-pom.xml b/templates/starter-pom.xml index c2b7202e..ade8eddd 100644 --- a/templates/starter-pom.xml +++ b/templates/starter-pom.xml @@ -19,19 +19,19 @@ <% styles.each { %> org.springframework.zero - spring-starter-${it} + spring-starter${it} <% } %> - ${packageName}.ApplicationConfiguration + ${packageName}.Application - org.apache.maven.plugins - maven-shade-plugin + org.springframework.zero + spring-package-maven-plugin