Skip to content

Commit

Permalink
Add --classpath to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
dsyer committed Jul 22, 2013
1 parent 1c6cbad commit b1c5b30
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 5 deletions.
22 changes: 22 additions & 0 deletions spring-cli/samples/ui.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ private static class RunOptionHandler extends OptionHandler {

private OptionSpec<Void> localOption;

private OptionSpec<String> classpathOption;

private SpringApplicationRunner runner;

@Override
Expand All @@ -86,6 +88,8 @@ protected void options() {
"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
Expand Down Expand Up @@ -177,6 +181,14 @@ public Level getLogLevel() {
return Level.INFO;
}

@Override
public String getClasspath() {
if (this.options.has(RunOptionHandler.this.classpathOption)) {
return this.options.valueOf(RunOptionHandler.this.classpathOption);
}
return "";
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ public boolean isGuessDependencies() {
return true;
}

@Override
public String getClasspath() {
return "";
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public GroovyCompiler(final GroovyCompilerConfiguration configuration) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ public interface GroovyCompilerConfiguration {
*/
boolean isGuessDependencies();

/**
* @return a path for local resources (colon separated)
*/
String getClasspath();

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
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;

Expand Down Expand Up @@ -142,14 +141,11 @@ public void webSample() throws Exception {
}

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

0 comments on commit b1c5b30

Please sign in to comment.