Commit b0c5d325 authored by Andy Wilkinson's avatar Andy Wilkinson

Make "." be the CLI's default classpath

Previously, the default classpath was empty. Now, in the absence of the
user providing a classpath via the -cp option, the default classpath
will be ".". If the user does specify a classpath, the classpath that's
used will be exactly what they have specified, i.e. "." will no longer
be on the classpath unless specified by the user.

The app sample integration test has been updated to verify that "." is
only the classpath by default.

Fixes #115
parent f7f53e4e
...@@ -7,7 +7,7 @@ class Example implements CommandLineRunner { ...@@ -7,7 +7,7 @@ class Example implements CommandLineRunner {
private MyService myService private MyService myService
void run(String... args) { void run(String... args) {
print "Hello " + this.myService.sayWorld() println "Hello ${this.myService.sayWorld()} From ${getClass().getClassLoader().getResource('samples/app.groovy')}"
} }
} }
......
...@@ -276,7 +276,7 @@ public class ScriptCommand implements Command { ...@@ -276,7 +276,7 @@ public class ScriptCommand implements Command {
@Override @Override
public String[] getClasspath() { public String[] getClasspath() {
return NO_CLASSPATH; return DEFAULT_CLASSPATH;
} }
@Override @Override
......
...@@ -31,7 +31,7 @@ public interface GroovyCompilerConfiguration { ...@@ -31,7 +31,7 @@ public interface GroovyCompilerConfiguration {
/** /**
* Constant to be used when there is no {@link #getClasspath() classpath}. * Constant to be used when there is no {@link #getClasspath() classpath}.
*/ */
public static final String[] NO_CLASSPATH = {}; public static final String[] DEFAULT_CLASSPATH = { "." };
/** /**
* Returns the scope in which the compiler operates. * Returns the scope in which the compiler operates.
......
...@@ -82,7 +82,7 @@ public class GroovyCompilerConfigurationAdapter implements GroovyCompilerConfigu ...@@ -82,7 +82,7 @@ public class GroovyCompilerConfigurationAdapter implements GroovyCompilerConfigu
if (this.options.has(classpathOption)) { if (this.options.has(classpathOption)) {
return this.options.valueOf(classpathOption).split(":"); return this.options.valueOf(classpathOption).split(":");
} }
return NO_CLASSPATH; return DEFAULT_CLASSPATH;
} }
@Override @Override
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
package org.springframework.boot.cli; package org.springframework.boot.cli;
import java.io.File; import java.io.File;
import java.net.URI;
import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.FileUtils;
import org.junit.BeforeClass; import org.junit.BeforeClass;
...@@ -48,7 +49,9 @@ public class SampleIntegrationTests { ...@@ -48,7 +49,9 @@ public class SampleIntegrationTests {
@Test @Test
public void appSample() throws Exception { public void appSample() throws Exception {
String output = this.cli.run("app.groovy"); String output = this.cli.run("app.groovy");
assertTrue("Wrong output: " + output, output.contains("Hello World")); URI scriptUri = new File("samples/app.groovy").toURI();
assertTrue("Wrong output: " + output,
output.contains("Hello World! From " + scriptUri));
} }
@Test @Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment