diff --git a/.cfignore b/.cfignore index 87bb3d5cb9..f569284e2f 100644 --- a/.cfignore +++ b/.cfignore @@ -6,7 +6,6 @@ .classpath .project .settings -bin build target .springBeans diff --git a/app.groovy b/app.groovy index eccd04df2b..b84f344859 100644 --- a/app.groovy +++ b/app.groovy @@ -1,4 +1,5 @@ -@Grab("org.springframework.zero:spring-actuator:0.5.0.BUILD-SNAPSHOT") +package app + @Grab("org.codehaus.groovy:groovy-ant:2.1.6") @Grab("org.codehaus.groovy.modules.http-builder:http-builder:0.5.2") @Grab(group='net.sf.json-lib', module='json-lib', version='2.3', classifier='jdk15') @@ -14,6 +15,9 @@ class MainController { @Value('${TMPDIR:.}') private String tmpdir + @Autowired + private Reactor reactor + private gettingStartedRepos = [] @RequestMapping("/") @@ -29,12 +33,6 @@ class MainController { template "home.html", model } - @RequestMapping("/installer") - @ResponseBody - String installer(@RequestHeader(required=false) String host) { - template "installer.sh", [host: host!=null ? host : home] - } - @RequestMapping("/spring") @ResponseBody ResponseEntity spring() { @@ -54,9 +52,12 @@ class MainController { @ResponseBody ResponseEntity spring(PomRequest request) { + def tempFiles = [] + def model = [:] String pom = new String(pom(request, model).body) File dir = File.createTempFile("tmp","",new File(tmpdir)); + tempFiles << dir dir.delete() dir.mkdirs() new File(dir, "pom.xml").write(pom) @@ -65,12 +66,15 @@ class MainController { src.mkdirs() def body = template "Application.java", model - log.info("Creating: " + src + "Application.java") + 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) - + tempFiles << download + + reactor.notify("tempfiles", Event.wrap(tempFiles)) + new AntBuilder().zip(destfile: download) { zipfileset(dir:dir, includes:"**") } @@ -135,13 +139,60 @@ class MainController { } -import org.springframework.actuate.properties.SecurityProperties +import reactor.spring.context.ConsumerBeanPostProcessor; +@Configuration +@EnableReactor +class ReactorConfiguration { + + @Bean + public reactor.core.Environment reactorEnvironment() { + return new reactor.core.Environment(); // TODO: use Spring Environment to configure? + } + + @Bean + public Reactor rootReactor() { + return reactorEnvironment().getRootReactor(); + } + +} + +@Component +@Log +class TemporaryFileCleaner { + + @Autowired + Reactor reactor + + @PostConstruct + void init() { + reactor.on(Selectors.$("tempfiles"), [ + accept: { + def tempFiles = event.data + log.info "Tempfiles: " + tempFiles + if (tempFiles) { + tempFiles.each { + File file = it as File + if (file.directory) { + file.deleteDir() + } else { + file.delete() + } + } + } + } + ] as Consumer) + } + +} + +@Grab("org.springframework.boot:spring-boot-starter-actuator:0.5.0.M1") +import org.springframework.boot.ops.properties.SecurityProperties @EnableWebSecurity @Configuration @Log class SecurityConfiguration { - @Bean(name = "org.springframework.actuate.properties.SecurityProperties") + @Bean(name = "org.springframework.boot.ops.properties.SecurityProperties") SecurityProperties securityProperties() { SecurityProperties security = new SecurityProperties() security.getBasic().setPath("/gs/**") @@ -165,12 +216,12 @@ class PomRequest { def style = [] String name = "demo" - String description = "Demo project for Spring Zero" + String description = "Demo project for Spring Boot" String groupId = "org.test" String artifactId String version = "0.0.1.SNAPSHOT" String packageName - String getName() { + String getArtifactId() { artifactId == null ? name : artifactId } String getPackageName() { diff --git a/logback.xml b/logback.xml index c08f8de959..3ac8b951ef 100644 --- a/logback.xml +++ b/logback.xml @@ -1,22 +1,10 @@ - - - - - - ${CONSOLE_LOG_PATTERN} - - - - - - - - - - + + + + diff --git a/manifest.yml b/manifest.yml index b551e4a1bd..c7054702fd 100644 --- a/manifest.yml +++ b/manifest.yml @@ -5,5 +5,5 @@ applications: instances: 1 url: initializr.cfapps.io path: . - command: java -jar ./spring/lib/*.jar run --local app.groovy -- --server.port=$PORT + command: java -jar ./spring/lib/*.jar run --cp . --local app.groovy -- --server.port=$PORT # buildpack: https://github.com/dsyer/cloudfoundry-buildpack-java diff --git a/static/install.sh b/static/install.sh new file mode 100644 index 0000000000..58b3869f9a --- /dev/null +++ b/static/install.sh @@ -0,0 +1,96 @@ +#!/bin/sh + +set -e +# set -x + +VERSION="0.5.0.M1" +if [ -z "${PREFIX}" ]; then + PREFIX="/usr/local/bin" +fi +if [ -z "${JAR_FILE}" ]; then + JAR_FILE="/tmp/spring.jar" + if [ -z "${JAR_URL}" ]; then + + echo "Downloading spring ${VERSION} distribution" + echo + + JAR_URL="https://repo.springsource.org/milestone/org/springframework/boot/spring-boot-cli/${VERSION}/spring-boot-cli-${VERSION}.jar" + curl --progress-bar --fail "$JAR_URL" -o "$JAR_FILE" + + fi +fi +trap "echo Installation failed." EXIT + +test -f "${JAR_FILE}" + +SPRING_HOME="${HOME}/.spring" +mkdir -p "$SPRING_HOME" +cp "$JAR_FILE" "${SPRING_HOME}/spring.jar" +cd "${SPRING_HOME}" +echo + +rm -rf "${SPRING_HOME}"/spring +cat > "${SPRING_HOME}"/spring <<"EOF" +#!/bin/sh +java -jar ${SPRING_HOME}/spring.jar \$* +EOF +chmod +x "${SPRING_HOME}/spring" +test -x "${SPRING_HOME}/spring" + +echo "spring ${VERSION} has been installed in your home directory (~/.spring)." +echo + +if rm -f "$PREFIX/spring" && ln -sf "${SPRING_HOME}/spring" "$PREFIX/spring" >/dev/null 2>&1; then + echo + echo "Linking ~/.spring/spring to $PREFIX/spring for your convenience." + cat <<"EOF" + +To get started: + + $ spring --version + $ spring help + +And take a look at the README at https://github.com/springsource/spring-boot#readme. + +EOF +elif type sudo >/dev/null 2>&1; then + echo "Linking ~/.spring/spring to $PREFIX/spring for your convenience." + echo "This may prompt for your password." + if sudo rm -f "$PREFIX/spring" && sudo ln -sf "${SPRING_HOME}/spring" "$PREFIX/spring" >/dev/null 2>&1; then + cat <<"EOF" + +To get started: + + $ spring --version + $ spring help + +And take a look at the README at https://github.com/springsource/spring-boot#readme. + +EOF + else + cat <<"EOF" +Couldn't create the symlink. Please either: + (1) Run the following as root: + cp ~/.spring/spring /usr/bin/spring + (2) Add ~/.spring to your path, or + (3) Rerun this command to try again. + +Then to get started, take a look at 'spring help' or see the README at +https://github.com/springsource/spring-boot#readme. +EOF + fi +else + cat <<"EOF" + +Now you need to do one of the following: + + (1) Add ~/.spring to your path, or + (2) Run this command as root: + cp ~/.spring/spring /usr/bin/spring + +Then to get started, take a look at 'spring help' or see the README at +https://github.com/springsource/spring-boot#readme. +EOF +fi + +trap - EXIT \ No newline at end of file diff --git a/templates/installer.sh b/templates/installer.sh deleted file mode 100644 index 37ee13a065..0000000000 --- a/templates/installer.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -if [ -e spring -a ! -d spring ]; then - echo "You already have a local file called 'spring' and it's not a directory" - echo "Remove it before trying again" - exit 1 -fi - -if [ -d spring ]; then - echo "You already have a local directory called 'spring'. Removing..." - rm -rf spring -fi - -echo "Installing Spring in local directory..." - -if [ ! -e spring.zip ]; then - wget ${host}/spring.zip -else - echo "Using locally cached spring.zip" -fi - -echo "Unpacking spring.zip" -unzip -u spring.zip -rm spring.zip - -echo "To use the spring CLI:" -echo " export SPRING_HOME="`pwd`/spring -echo " export PATH="`pwd`/spring/bin':\$PATH' -echo "And (e.g.) 'spring run app.groovy'"