Fix CLI script

This commit is contained in:
Dave Syer 2013-07-21 08:11:08 +01:00
parent 5d4f075011
commit 01ebd6da08
8 changed files with 25 additions and 14 deletions

View File

@ -30,7 +30,7 @@ instructions will look like this:
2) Get Spring
$ curl -s spring.cfapps.io/installer | bash
$ curl -s initializr.cfapps.io/installer | bash
or use the [Windows installer](#installing)
@ -43,7 +43,7 @@ or above.
An `alias` can be used for the Spring Zero command line tool:
$ alias spr="java -jar ~/.m2/repository/org/springframework/zero/spring-cli/0.5.0.BUILD-SNAPSHOT/spring-cli-0.5.0.BUILD-SNAPSHOT.jar"
$ alias spring="java -jar ~/.m2/repository/org/springframework/zero/spring-cli/0.5.0.BUILD-SNAPSHOT/spring-cli-0.5.0.BUILD-SNAPSHOT.jar"
_Also see [docs/CONTRIBUTING](docs/CONTRIBUTING.md) if you want to submit pull requests._
@ -62,7 +62,7 @@ snippets that can just run, for example:
}
}
<ctrl-d>
$ spr run app.groovy
$ spring run app.groovy
$ curl localhost:8080
Hello World!
@ -165,7 +165,7 @@ _See [spring-launcher/README](spring-launcher/README.md) &
## Samples
Groovy samples for use with the command line application are available in
[spring-cli/samples](spring-cli/samples/#). To run the CLI samples type
`spr run <sample>.groovy` from samples directory.
`spring run <sample>.groovy` from samples directory.
Java samples are available in [spring-zero-sample](spring-zero-samples/#) and should
be build with maven and run use `java -jar target/<sample>.jar`. The following java

View File

@ -38,6 +38,8 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
private final Log logger = LogFactory.getLog(TomcatEmbeddedServletContainer.class);
private static int containerCounter = 0;
private final Tomcat tomcat;
/**
@ -55,7 +57,7 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
this.tomcat.start();
// Unlike Jetty, all Tomcat threads are daemon threads. We create a
// blocking non-daemon to stop immediate shutdown
Thread awaitThread = new Thread() {
Thread awaitThread = new Thread("container-" + (containerCounter++)) {
@Override
public void run() {
TomcatEmbeddedServletContainer.this.tomcat.getServer().await();

View File

@ -39,6 +39,7 @@ import static org.junit.Assert.assertTrue;
@Configuration
public class SimpleMainTests {
private static final String SPRING_STARTUP = "root of context hierarchy";
private PrintStream savedOutput;
private ByteArrayOutputStream output;
@ -58,33 +59,33 @@ public class SimpleMainTests {
@Test(expected = IllegalArgumentException.class)
public void emptyApplicationContext() throws Exception {
SpringApplication.main(getArgs());
assertTrue(getOutput().contains("Pre-instantiating singletons"));
assertTrue(getOutput().contains(SPRING_STARTUP));
}
@Test
public void basePackageScan() throws Exception {
SpringApplication.main(getArgs(ClassUtils.getPackageName(getClass())
+ ".sampleconfig"));
assertTrue(getOutput().contains("Pre-instantiating singletons"));
assertTrue(getOutput().contains(SPRING_STARTUP));
}
@Test
public void configClassContext() throws Exception {
SpringApplication.main(getArgs(getClass().getName()));
assertTrue(getOutput().contains("Pre-instantiating singletons"));
assertTrue(getOutput().contains(SPRING_STARTUP));
}
@Test
public void xmlContext() throws Exception {
SpringApplication.main(getArgs("org/springframework/bootstrap/sample-beans.xml"));
assertTrue(getOutput().contains("Pre-instantiating singletons"));
assertTrue(getOutput().contains(SPRING_STARTUP));
}
@Test
public void mixedContext() throws Exception {
SpringApplication.main(getArgs(getClass().getName(),
"org/springframework/bootstrap/sample-beans.xml"));
assertTrue(getOutput().contains("Pre-instantiating singletons"));
assertTrue(getOutput().contains(SPRING_STARTUP));
}
private String[] getArgs(String... args) {

View File

@ -71,6 +71,7 @@ public class LoggingApplicationContextInitializerTests {
System.clearProperty("LOG_PATH");
System.clearProperty("PID");
System.setOut(this.savedOutput);
System.out.println(getOutput());
}
private String getOutput() {

View File

@ -39,7 +39,7 @@ import java.util.Set;
*/
public class SpringCli {
public static final String CLI_APP = "spr";
public static final String CLI_APP = "spring";
private static final Set<SpringCliException.Option> NO_EXCEPTION_OPTIONS = EnumSet
.noneOf(SpringCliException.Option.class);

View File

@ -33,6 +33,10 @@ import org.springframework.cli.compiler.GroovyCompiler;
*/
public class SpringApplicationRunner {
private static int watcherCounter = 0;
private static int runnerCounter = 0;
// FIXME logging
private SpringApplicationRunnerConfiguration configuration;
@ -118,6 +122,7 @@ public class SpringApplicationRunner {
* @param sources the sources to launch
*/
public RunThread(Object... sources) {
super("runner-" + (runnerCounter++));
this.sources = sources;
if (sources.length != 0 && sources[0] instanceof Class) {
setContextClassLoader(((Class<?>) sources[0]).getClassLoader());
@ -171,6 +176,7 @@ public class SpringApplicationRunner {
private long previous;
public FileWatchThread() {
super("filewatcher-" + (watcherCounter++));
this.previous = 0;
for (File file : SpringApplicationRunner.this.files) {
long current = file.lastModified();

View File

@ -63,7 +63,7 @@ if [ -f build.gradle ]; then
TARGETDIR=build/classes/main
fi
for f in "${TARGETDIR}" "${SPRING_HOME}"/classes "${SPRING_BIN}" "${SPRING_HOME}"/*.jar "${SPRING_HOME}"/lib/*.jar; do
for f in . "${TARGETDIR}" "${SPRING_HOME}"/classes "${SPRING_BIN}" "${SPRING_HOME}"/*.jar "${SPRING_HOME}"/lib/*.jar; do
if [ -f $f -o -d $f ]; then
if [ "${CLASSPATH}" == "" ]; then
CLASSPATH="${f}"
@ -77,4 +77,4 @@ if $cygwin; then
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
fi
${JAVA_HOME}/bin/java ${JAVA_OPTS} -cp "$CLASSPATH" org.springframework.bootstrap.cli.SpringBootstrapCli $*
${JAVA_HOME}/bin/java ${JAVA_OPTS} -cp "$CLASSPATH" org.springframework.cli.SpringCli $*

View File

@ -133,7 +133,8 @@ public class SpringCliTests {
@Test
public void exceptionMessages() throws Exception {
assertThat(new NoSuchCommandException("name").getMessage(),
equalTo("spr: 'name' is not a valid command. See 'spr help'."));
equalTo(SpringCli.CLI_APP + ": 'name' is not a valid command. See '"
+ SpringCli.CLI_APP + " help'."));
}
@Test