Skip to content

Commit b0c5d32

Browse files
committed
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 spring-projects#115
1 parent f7f53e4 commit b0c5d32

File tree

5 files changed

+8
-5
lines changed

5 files changed

+8
-5
lines changed

spring-boot-cli/samples/app.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Example implements CommandLineRunner {
77
private MyService myService
88

99
void run(String... args) {
10-
print "Hello " + this.myService.sayWorld()
10+
println "Hello ${this.myService.sayWorld()} From ${getClass().getClassLoader().getResource('samples/app.groovy')}"
1111
}
1212
}
1313

spring-boot-cli/src/main/java/org/springframework/boot/cli/command/ScriptCommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public boolean isGuessDependencies() {
276276

277277
@Override
278278
public String[] getClasspath() {
279-
return NO_CLASSPATH;
279+
return DEFAULT_CLASSPATH;
280280
}
281281

282282
@Override

spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompilerConfiguration.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public interface GroovyCompilerConfiguration {
3131
/**
3232
* Constant to be used when there is no {@link #getClasspath() classpath}.
3333
*/
34-
public static final String[] NO_CLASSPATH = {};
34+
public static final String[] DEFAULT_CLASSPATH = { "." };
3535

3636
/**
3737
* Returns the scope in which the compiler operates.

spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompilerConfigurationAdapter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public String[] getClasspath() {
8282
if (this.options.has(classpathOption)) {
8383
return this.options.valueOf(classpathOption).split(":");
8484
}
85-
return NO_CLASSPATH;
85+
return DEFAULT_CLASSPATH;
8686
}
8787

8888
@Override

spring-boot-cli/src/test/java/org/springframework/boot/cli/SampleIntegrationTests.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.boot.cli;
1818

1919
import java.io.File;
20+
import java.net.URI;
2021

2122
import org.codehaus.plexus.util.FileUtils;
2223
import org.junit.BeforeClass;
@@ -48,7 +49,9 @@ public static void cleanGrapes() throws Exception {
4849
@Test
4950
public void appSample() throws Exception {
5051
String output = this.cli.run("app.groovy");
51-
assertTrue("Wrong output: " + output, output.contains("Hello World"));
52+
URI scriptUri = new File("samples/app.groovy").toURI();
53+
assertTrue("Wrong output: " + output,
54+
output.contains("Hello World! From " + scriptUri));
5255
}
5356

5457
@Test

0 commit comments

Comments
 (0)