Add --classpath to CLI

pull/9/head
Dave Syer 11 years ago
parent 1c6cbad345
commit b1c5b30de8

@ -9,3 +9,25 @@ class Example {
} }
} }
@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)
}
}
}
}

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

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

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

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

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

Loading…
Cancel
Save