From a112717fd390661dca164d558bce371257873a77 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Fri, 24 May 2013 13:36:55 +0100 Subject: [PATCH] [bs-136] Add 'spring run --local ...' Use this to download and cache the dependencies to ./grapes. Good for running on virgin system (like PaaS). [Fixes #50511883] Add --local to RunCommand --- .../springframework/bootstrap/cli/RunCommand.java | 12 ++++++++++++ .../SpringMvcCompilerAutoConfiguration.java | 3 ++- .../cli/runner/BootstrapRunnerConfiguration.java | 5 +++++ spring-bootstrap-cli/src/main/scripts/spring | 2 +- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/RunCommand.java b/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/RunCommand.java index f5bc8e4739..b38bdde565 100644 --- a/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/RunCommand.java +++ b/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/RunCommand.java @@ -53,6 +53,8 @@ public class RunCommand extends OptionParsingCommand { private OptionSpec quietOption; + private OptionSpec localOption; + private BootstrapRunner runner; public RunCommand() { @@ -75,6 +77,8 @@ public class RunCommand extends OptionParsingCommand { OptionParser parser = new OptionParser(); this.watchOption = parser .accepts("watch", "Watch the specified file for changes"); + this.localOption = parser.accepts("local", + "Accumulate the dependencies in a local folder (./grapes)"); this.editOption = parser.acceptsAll(asList("edit", "e"), "Open the file with the default system editor"); this.noGuessImportsOption = parser.accepts("no-guess-imports", @@ -99,6 +103,9 @@ public class RunCommand extends OptionParsingCommand { BootstrapRunnerConfiguration configuration = new BootstrapRunnerConfigurationAdapter( options); + if (configuration.isLocal() && System.getProperty("grape.root") == null) { + System.setProperty("grape.root", "."); + } this.runner = new BootstrapRunner(configuration, files, args.toArray(new String[args.size()])); this.runner.compileAndRun(); @@ -153,6 +160,11 @@ public class RunCommand extends OptionParsingCommand { return !this.options.has(RunCommand.this.noGuessDependenciesOption); } + @Override + public boolean isLocal() { + return this.options.has(RunCommand.this.localOption); + } + @Override public Level getLogLevel() { if (this.options.has(RunCommand.this.verboseOption)) { diff --git a/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/compiler/autoconfigure/SpringMvcCompilerAutoConfiguration.java b/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/compiler/autoconfigure/SpringMvcCompilerAutoConfiguration.java index e57f966484..4210232c4d 100644 --- a/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/compiler/autoconfigure/SpringMvcCompilerAutoConfiguration.java +++ b/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/compiler/autoconfigure/SpringMvcCompilerAutoConfiguration.java @@ -56,7 +56,8 @@ public class SpringMvcCompilerAutoConfiguration extends CompilerAutoConfiguratio @Override public void applyImports(ImportCustomizer imports) { imports.addStarImports("org.springframework.web.bind.annotation", - "org.springframework.web.servlet.config.annotation"); + "org.springframework.web.servlet.config.annotation", + "org.springframework.http"); imports.addStaticImport( "org.springframework.bootstrap.cli.template.GroovyTemplate", "template"); } diff --git a/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/runner/BootstrapRunnerConfiguration.java b/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/runner/BootstrapRunnerConfiguration.java index a8dbaa895a..501c976af0 100644 --- a/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/runner/BootstrapRunnerConfiguration.java +++ b/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/runner/BootstrapRunnerConfiguration.java @@ -38,4 +38,9 @@ public interface BootstrapRunnerConfiguration extends GroovyCompilerConfiguratio */ Level getLogLevel(); + /** + * Returns {@code true} if the dependencies should be cached locally + */ + boolean isLocal(); + } diff --git a/spring-bootstrap-cli/src/main/scripts/spring b/spring-bootstrap-cli/src/main/scripts/spring index 19121254f5..bb38c61e74 100755 --- a/spring-bootstrap-cli/src/main/scripts/spring +++ b/spring-bootstrap-cli/src/main/scripts/spring @@ -66,7 +66,7 @@ mkdir -p "${TARGETDIR%/}" CLASSPATH="${CLASSPATH}":"${SPRING_BIN}":"${TARGETDIR}" -for f in "${SPRING_HOME}"/*.jar "${SPRING_HOME}"/lib/*.jar "${SPRING_HOME}"/classes; do +for f in "${SPRING_HOME}"/classes "${SPRING_HOME}"/*.jar "${SPRING_HOME}"/lib/*.jar; do [ -f $f ] && CLASSPATH="${CLASSPATH}":$f done