Skip to content

Commit 8f0f260

Browse files
committed
Adds Commons CLI and JUnit to the classpath and includes a couple tests! Fixes #2
1 parent 9bf3d4d commit 8f0f260

File tree

5 files changed

+33
-18
lines changed

5 files changed

+33
-18
lines changed

Test.groovy

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Test extends GroovyTestCase {
2+
3+
Test() {
4+
println "I live!"
5+
}
6+
7+
void testIvy() {
8+
def report = new org.apache.ivy.Ivy()
9+
def ivyHome = report.getIvyHomeURL()
10+
assertTrue(ivyHome.contains("apache.org"))
11+
}
12+
13+
void testCLI() {
14+
def cli = new CliBuilder(usage: 'Usage')
15+
def expected = 'Usage'
16+
assertToString(cli.usage, expected)
17+
}
18+
}

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
apply plugin: 'java'
22

3-
version = '1.0.1'
3+
version = '1.0.2'
44

55
dependencies {
66
compile files('gradle/wrapper/gradle-wrapper.jar')

gradle/wrapper/groovy-wrapper.jar

147 Bytes
Binary file not shown.

src/main/java/org/gradle/wrapper/GroovyBootstrapMainStarter.java

+14-16
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,16 @@
2424
public class GroovyBootstrapMainStarter extends BootstrapMainStarter {
2525
@Override
2626
public void start(String[] args, File gradleHome) throws Exception {
27-
File groovyJar = findGroovyJar(gradleHome);
28-
File ivyJar = findIvyJar(gradleHome);
29-
URLClassLoader contextClassLoader = new URLClassLoader(new URL[]{groovyJar.toURI().toURL(),ivyJar.toURI().toURL()}, ClassLoader.getSystemClassLoader().getParent());
27+
File groovyJar = findJar("groovy-all", gradleHome, "lib");
28+
File ivyJar = findJar("ivy", gradleHome, "lib/plugins");
29+
File cliJar = findJar("commons-cli", gradleHome, "lib/plugins");
30+
File junitJar = findJar("junit", gradleHome, "lib/plugins");
31+
URLClassLoader contextClassLoader = new URLClassLoader(new URL[]{
32+
groovyJar.toURI().toURL()
33+
,ivyJar.toURI().toURL()
34+
,cliJar.toURI().toURL()
35+
,junitJar.toURI().toURL()
36+
}, ClassLoader.getSystemClassLoader().getParent());
3037
Thread.currentThread().setContextClassLoader(contextClassLoader);
3138
Class<?> mainClass = contextClassLoader.loadClass("groovy.ui.GroovyMain");
3239
Method mainMethod = mainClass.getMethod("main", String[].class);
@@ -36,21 +43,12 @@ public void start(String[] args, File gradleHome) throws Exception {
3643
}
3744
}
3845

39-
private File findGroovyJar(File gradleHome) {
40-
for (File file : new File(gradleHome, "lib").listFiles()) {
41-
if (file.getName().matches("groovy-all-.*\\.jar")) {
46+
private File findJar(String fragment, File gradleHome, String subdir) {
47+
for (File file : new File(gradleHome, subdir).listFiles()) {
48+
if (file.getName().matches(fragment + "-.*\\.jar")) {
4249
return file;
4350
}
4451
}
45-
throw new RuntimeException(String.format("Could not locate the Groovy JAR in Gradle distribution '%s'.", gradleHome));
46-
}
47-
48-
private File findIvyJar(File gradleHome) {
49-
for (File file : new File(gradleHome, "lib/plugins").listFiles()) {
50-
if (file.getName().matches("ivy-.*\\.jar")) {
51-
return file;
52-
}
53-
}
54-
throw new RuntimeException(String.format("Could not locate the Ivy JAR in Gradle distribution '%s'.", gradleHome));
52+
throw new RuntimeException(String.format("Could not locate the JAR for " + fragment + " in Gradle distribution '%s'.", gradleHome));
5553
}
5654
}

test.groovy

-1
This file was deleted.

0 commit comments

Comments
 (0)