Skip to content

Commit

Permalink
Update for 0.5.0.M1
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Syer committed Aug 4, 2013
1 parent 9d4a6bf commit 0ccc883
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 60 deletions.
1 change: 0 additions & 1 deletion .cfignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
.classpath
.project
.settings
bin
build
target
.springBeans
Expand Down
77 changes: 64 additions & 13 deletions app.groovy
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -14,6 +15,9 @@ class MainController {
@Value('${TMPDIR:.}')
private String tmpdir

@Autowired
private Reactor reactor

private gettingStartedRepos = []

@RequestMapping("/")
Expand All @@ -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<byte[]> spring() {
Expand All @@ -54,9 +52,12 @@ class MainController {
@ResponseBody
ResponseEntity<byte[]> 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)
Expand All @@ -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:"**")
}
Expand Down Expand Up @@ -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/**")
Expand All @@ -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() {
Expand Down
20 changes: 4 additions & 16 deletions logback.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="CONSOLE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${PID:- } [%t] --- %-40.40logger{39} : %m%n%wex"/>

<conversionRule conversionWord="wex" converterClass="org.springframework.bootstrap.logging.logback.WhitespaceThrowableProxyConverter" />

<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
</encoder>
</appender>

<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>

<logger name="org.springframework.zero" level="DEBUG"/>
<logger name="org.springframework.security" level="DEBUG"/>
<logger name="sun.net.www.protocol.http.HttpURLConnection" level="TRACE"/>
<include resource="org/springframework/boot/logging/logback/base.xml"/>

<logger name="org.springframework" level="DEBUG"/>
<logger name="org.springframework.core.env" level="WARN"/>
<logger name="org.springframework.jndi" level="WARN"/>

</configuration>
2 changes: 1 addition & 1 deletion manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
96 changes: 96 additions & 0 deletions static/install.sh
Original file line number Diff line number Diff line change
@@ -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
29 changes: 0 additions & 29 deletions templates/installer.sh

This file was deleted.

0 comments on commit 0ccc883

Please sign in to comment.