[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
This commit is contained in:
Dave Syer 2013-05-24 13:36:55 +01:00
parent 35a376b403
commit a112717fd3
4 changed files with 20 additions and 2 deletions

View File

@ -53,6 +53,8 @@ public class RunCommand extends OptionParsingCommand {
private OptionSpec<Void> quietOption;
private OptionSpec<Void> 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)) {

View File

@ -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");
}

View File

@ -38,4 +38,9 @@ public interface BootstrapRunnerConfiguration extends GroovyCompilerConfiguratio
*/
Level getLogLevel();
/**
* Returns {@code true} if the dependencies should be cached locally
*/
boolean isLocal();
}

View File

@ -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