Add --classpath to CLI

This commit is contained in:
Dave Syer 2013-07-22 16:20:19 +01:00
parent 1c6cbad345
commit b1c5b30de8
7 changed files with 48 additions and 5 deletions

View File

@ -8,4 +8,26 @@ class Example {
return "home";
}
}
@Configuration
@Log
class MvcConfiguration extends WebMvcConfigurerAdapter {
@Override
void addInterceptors(def registry) {
log.info("Registering temporary file interceptor")
registry.addInterceptor(temporaryFileInterceptor())
}
@Bean
HandlerInterceptor temporaryFileInterceptor() {
log.info("Creating temporary file interceptor")
new HandlerInterceptorAdapter() {
@Override
postHandle(def request, def response, def handler, ModelAndView mav) {
log.info("Model: " + model)
}
}
}
}

View File

@ -71,6 +71,8 @@ public class RunCommand extends OptionParsingCommand {
private OptionSpec<Void> localOption;
private OptionSpec<String> classpathOption;
private SpringApplicationRunner runner;
@Override
@ -86,6 +88,8 @@ public class RunCommand extends OptionParsingCommand {
"Do not attempt to guess dependencies");
this.verboseOption = option(asList("verbose", "v"), "Verbose logging");
this.quietOption = option(asList("quiet", "q"), "Quiet logging");
this.classpathOption = option(asList("classpath", "cp"),
"Additional classpath entries").withRequiredArg();
}
@Override
@ -177,6 +181,14 @@ public class RunCommand extends OptionParsingCommand {
return Level.INFO;
}
@Override
public String getClasspath() {
if (this.options.has(RunOptionHandler.this.classpathOption)) {
return this.options.valueOf(RunOptionHandler.this.classpathOption);
}
return "";
}
}
}

View File

@ -240,6 +240,11 @@ public class ScriptCommand implements Command {
return true;
}
@Override
public String getClasspath() {
return "";
}
}
}

View File

@ -72,6 +72,9 @@ public class GroovyCompiler {
CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
this.loader = new ExtendedGroovyClassLoader(getClass().getClassLoader(),
compilerConfiguration);
if (configuration.getClasspath().length() > 0) {
this.loader.addClasspath(configuration.getClasspath());
}
// FIXME: allow the extra resolvers to be switched on (off by default)
addExtraResolvers();
compilerConfiguration

View File

@ -33,4 +33,9 @@ public interface GroovyCompilerConfiguration {
*/
boolean isGuessDependencies();
/**
* @return a path for local resources (colon separated)
*/
String getClasspath();
}

View File

@ -28,7 +28,6 @@ import org.apache.ivy.util.FileUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.cli.command.RunCommand;
@ -142,14 +141,11 @@ public class SampleIntegrationTests {
}
@Test
@Ignore
public void uiSample() throws Exception {
// FIXME Failing on OSX
// To run this one from the command line you need to add target/test-classes to
// CLASSPATH
start("samples/ui.groovy");
start("samples/ui.groovy", "--classpath=.:src/test/resources");
String result = FileUtil.readEntirely(new URL("http://localhost:8080")
.openStream());
assertTrue("Wrong output: " + result, result.contains("Hello World"));