From c91e83c7d2d0ec5f99b030b8201125d51328a777 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Wed, 24 Apr 2013 11:38:57 +0100 Subject: [PATCH] [bs-59] Add zip packaging for cli module * Also added "spring" shell script (in zip), so you can unzip it and run out of the box * To run in developer mode use SPRING_HOME, e.g. $ cd spring-bootstrap-cli $ SPRING_HOME=target src/main/scripts/spring run samples/web.groovy * Also added "clean" command to remove spring bootstrap grapes (useful to force a refresh of snapshot jars) [#48644271] --- .../dependency-reduced-pom.xml | 2 +- spring-bootstrap-cli/pom.xml | 2 +- .../bootstrap/cli/CleanCommand.java | 68 +++++++++++++++++ .../bootstrap/cli/SpringBootstrapCli.java | 8 +- .../bootstrap/cli/VersionCommand.java | 5 +- spring-bootstrap-cli/src/main/scripts/spring | 74 +++++++++++++++++++ .../cli/SpringBootstrapCliTests.java | 2 +- .../dependency-reduced-pom.xml | 18 +++-- 8 files changed, 164 insertions(+), 15 deletions(-) create mode 100644 spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/CleanCommand.java create mode 100755 spring-bootstrap-cli/src/main/scripts/spring diff --git a/spring-bootstrap-cli/dependency-reduced-pom.xml b/spring-bootstrap-cli/dependency-reduced-pom.xml index 22577eb5a7..52d703aacb 100644 --- a/spring-bootstrap-cli/dependency-reduced-pom.xml +++ b/spring-bootstrap-cli/dependency-reduced-pom.xml @@ -62,7 +62,7 @@ make-distribution - install + package single diff --git a/spring-bootstrap-cli/pom.xml b/spring-bootstrap-cli/pom.xml index d153b35172..cb502a93f0 100644 --- a/spring-bootstrap-cli/pom.xml +++ b/spring-bootstrap-cli/pom.xml @@ -79,7 +79,7 @@ make-distribution - install + package single diff --git a/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/CleanCommand.java b/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/CleanCommand.java new file mode 100644 index 0000000000..d1d9cd432e --- /dev/null +++ b/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/CleanCommand.java @@ -0,0 +1,68 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.bootstrap.cli; + +import java.io.File; + +import org.apache.ivy.util.FileUtil; + +/** + * {@link Command} to 'clean' up grapes. + * + * @author Dave Syer + * + */ +public class CleanCommand extends AbstractCommand { + + public CleanCommand() { + super("clean", + "Clean up groovy grapes (useful if snapshots are needed and you need an update)"); + } + + @Override + public void run(String... args) throws Exception { + + String dir = System.getenv("GROOVY_HOME"); + String userdir = System.getProperty("user.home"); + + File home; + if (dir == null || !new File(dir).exists()) { + dir = userdir; + home = new File(dir, ".groovy"); + } else { + home = new File(dir); + } + if (dir == null || !new File(dir).exists()) { + return; + } + + if (!home.exists()) { + return; + } + + File grapes = new File(home, "grapes"); + // TODO: add support for other packages as args + String[] packages = new String[] { "org.springframework.bootstrap" }; + for (String pkg : packages) { + File file = new File(grapes, pkg); + if (file.exists()) { + FileUtil.forceDelete(file); + } + } + + } + +} diff --git a/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/SpringBootstrapCli.java b/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/SpringBootstrapCli.java index 3824882a6b..1abbb67027 100644 --- a/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/SpringBootstrapCli.java +++ b/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/SpringBootstrapCli.java @@ -40,7 +40,7 @@ import java.util.Set; */ public class SpringBootstrapCli { - public static final String CLI_APP = "spr"; + public static final String CLI_APP = "spring"; private static final Set NO_EXCEPTION_OPTIONS = EnumSet .noneOf(BootstrapCliException.Option.class); @@ -53,7 +53,7 @@ public class SpringBootstrapCli { */ public SpringBootstrapCli() { setCommands(Arrays.asList(new VersionCommand(), new RunCommand(), - new CreateCommand())); + new CreateCommand(), new CleanCommand())); } /** @@ -143,8 +143,8 @@ public class SpringBootstrapCli { } } System.out.println(""); - System.out - .println("See 'spr help ' for more information on a specific command."); + System.out.println("See '" + CLI_APP + + " help ' for more information on a specific command."); } protected void errorMessage(String message) { diff --git a/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/VersionCommand.java b/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/VersionCommand.java index dcf29c4189..3d9201cf82 100644 --- a/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/VersionCommand.java +++ b/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/VersionCommand.java @@ -17,7 +17,7 @@ package org.springframework.bootstrap.cli; /** - * {@link Command} to displat the 'version' number. + * {@link Command} to display the 'version' number. * * @author Phillip Webb */ @@ -29,7 +29,8 @@ public class VersionCommand extends AbstractCommand { @Override public void run(String... args) { - throw new IllegalStateException("Not implemented"); // FIXME + // FIXME: add version introspection + throw new IllegalStateException("Not implemented"); } } diff --git a/spring-bootstrap-cli/src/main/scripts/spring b/spring-bootstrap-cli/src/main/scripts/spring new file mode 100755 index 0000000000..4efa9a19fa --- /dev/null +++ b/spring-bootstrap-cli/src/main/scripts/spring @@ -0,0 +1,74 @@ +#!/bin/bash + +# OS specific support (must be 'true' or 'false'). +cygwin=false; +darwin=false; +case "`uname`" in + CYGWIN*) + cygwin=true + ;; + + Darwin*) + darwin=true + ;; +esac + +if [ -z "${JAVA_HOME}" ]; then + if $darwin ; then + [ -z "$JAVA_HOME" -a -f "/usr/libexec/java_home" ] && export JAVA_HOME=`/usr/libexec/java_home` + [ -z "$JAVA_HOME" -a -d "/Library/Java/Home" ] && export JAVA_HOME="/Library/Java/Home" + [ -z "$JAVA_HOME" -a -d "/System/Library/Frameworks/JavaVM.framework/Home" ] && export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Home" + else + javaExecutable="`which javac`" + [ -z "$javaExecutable" -o "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ] && die "JAVA_HOME not set and cannot find javac to deduce location, please set JAVA_HOME." + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + [ `expr "$readLink" : '\([^ ]*\)'` = "no" ] && die "JAVA_HOME not set and readlink not available, please set JAVA_HOME." + javaExecutable="`readlink -f \"$javaExecutable\"`" + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi +fi + +if [ ! -f "${JAVA_HOME}/bin/java" ]; then + echo "" + echo "======================================================================================================" + echo " Please ensure that your JAVA_HOME points to a valid Java SDK." + echo " You are currently pointing to:" + echo "" + echo " ${JAVA_HOME}" + echo "" + echo " This does not seem to be valid. Please rectify and restart." + echo "======================================================================================================" + echo "" + exit 1 +fi + +if [ "$SPRING_HOME" == "" ]; then + SPRING_HOME=`cd "$(dirname $0)"/.. && pwd` +fi +SPRING_BIN=$(dirname $0) + +TARGETDIR=target/classes +if [ -f build.gradle ]; then + TARGETDIR=build/classes/main +fi +mkdir -p "${TARGETDIR%/}" + +CLASSPATH="${SPRING_BIN}":"${TARGETDIR}" + +for f in "${SPRING_HOME}"/lib/*.jar; do + CLASSPATH="${CLASSPATH}":$f +done + +for f in "${SPRING_HOME}"/*.jar; do + CLASSPATH="${CLASSPATH}":$f +done + +if $cygwin; then + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` +fi + +${JAVA_HOME}/bin/java -cp "$CLASSPATH" org.springframework.bootstrap.cli.SpringBootstrapCli $* \ No newline at end of file diff --git a/spring-bootstrap-cli/src/test/java/org/springframework/bootstrap/cli/SpringBootstrapCliTests.java b/spring-bootstrap-cli/src/test/java/org/springframework/bootstrap/cli/SpringBootstrapCliTests.java index 4967baeae3..e256024035 100644 --- a/spring-bootstrap-cli/src/test/java/org/springframework/bootstrap/cli/SpringBootstrapCliTests.java +++ b/spring-bootstrap-cli/src/test/java/org/springframework/bootstrap/cli/SpringBootstrapCliTests.java @@ -159,7 +159,7 @@ public class SpringBootstrapCliTests { assertThat(new NoSuchOptionException("name").getMessage(), equalTo("Unknown option: --name")); assertThat(new NoSuchCommandException("name").getMessage(), - equalTo("spr: 'name' is not a valid command. See 'spr --help'.")); + equalTo("spring: 'name' is not a valid command. See 'spring --help'.")); } @Test diff --git a/spring-bootstrap-samples/spring-bootstrap-service-sample/dependency-reduced-pom.xml b/spring-bootstrap-samples/spring-bootstrap-service-sample/dependency-reduced-pom.xml index 8c59a58702..84fbc0f02f 100644 --- a/spring-bootstrap-samples/spring-bootstrap-service-sample/dependency-reduced-pom.xml +++ b/spring-bootstrap-samples/spring-bootstrap-service-sample/dependency-reduced-pom.xml @@ -21,14 +21,10 @@ org.apache.tomcat.embed tomcat-embed-core - 7.0.35 - compile org.apache.tomcat.embed tomcat-embed-logging-juli - 7.0.35 - compile @@ -38,10 +34,20 @@ org.eclipse.jetty jetty-webapp + 8.1.9.v20130131 + compile + + + javax.servlet + org.eclipse.jetty.orbit + + - javax.servlet - javax.servlet-api + org.eclipse.jetty + jetty-jsp + 8.1.9.v20130131 + compile