mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Add --classpath to CLI
This commit is contained in:
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<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 "";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -240,6 +240,11 @@ public class ScriptCommand implements Command {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClasspath() {
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -33,4 +33,9 @@ public interface GroovyCompilerConfiguration {
|
||||
*/
|
||||
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.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"));
|
||||
|
Loading…
Reference in New Issue
Block a user