Skip to content

Commit

Permalink
Adds Commons CLI and JUnit to the classpath and includes a couple tes…
Browse files Browse the repository at this point in the history
…ts! Fixes #2
  • Loading branch information
Cervator committed Jun 20, 2017
1 parent 9bf3d4d commit 8f0f260
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 18 deletions.
18 changes: 18 additions & 0 deletions Test.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Test extends GroovyTestCase {

Test() {
println "I live!"
}

void testIvy() {
def report = new org.apache.ivy.Ivy()
def ivyHome = report.getIvyHomeURL()
assertTrue(ivyHome.contains("apache.org"))
}

void testCLI() {
def cli = new CliBuilder(usage: 'Usage')
def expected = 'Usage'
assertToString(cli.usage, expected)
}
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apply plugin: 'java'

version = '1.0.1'
version = '1.0.2'

dependencies {
compile files('gradle/wrapper/gradle-wrapper.jar')
Expand Down
Binary file modified gradle/wrapper/groovy-wrapper.jar
Binary file not shown.
30 changes: 14 additions & 16 deletions src/main/java/org/gradle/wrapper/GroovyBootstrapMainStarter.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,16 @@
public class GroovyBootstrapMainStarter extends BootstrapMainStarter {
@Override
public void start(String[] args, File gradleHome) throws Exception {
File groovyJar = findGroovyJar(gradleHome);
File ivyJar = findIvyJar(gradleHome);
URLClassLoader contextClassLoader = new URLClassLoader(new URL[]{groovyJar.toURI().toURL(),ivyJar.toURI().toURL()}, ClassLoader.getSystemClassLoader().getParent());
File groovyJar = findJar("groovy-all", gradleHome, "lib");
File ivyJar = findJar("ivy", gradleHome, "lib/plugins");
File cliJar = findJar("commons-cli", gradleHome, "lib/plugins");
File junitJar = findJar("junit", gradleHome, "lib/plugins");
URLClassLoader contextClassLoader = new URLClassLoader(new URL[]{
groovyJar.toURI().toURL()
,ivyJar.toURI().toURL()
,cliJar.toURI().toURL()
,junitJar.toURI().toURL()
}, ClassLoader.getSystemClassLoader().getParent());
Thread.currentThread().setContextClassLoader(contextClassLoader);
Class<?> mainClass = contextClassLoader.loadClass("groovy.ui.GroovyMain");
Method mainMethod = mainClass.getMethod("main", String[].class);
Expand All @@ -36,21 +43,12 @@ public void start(String[] args, File gradleHome) throws Exception {
}
}

private File findGroovyJar(File gradleHome) {
for (File file : new File(gradleHome, "lib").listFiles()) {
if (file.getName().matches("groovy-all-.*\\.jar")) {
private File findJar(String fragment, File gradleHome, String subdir) {
for (File file : new File(gradleHome, subdir).listFiles()) {
if (file.getName().matches(fragment + "-.*\\.jar")) {
return file;
}
}
throw new RuntimeException(String.format("Could not locate the Groovy JAR in Gradle distribution '%s'.", gradleHome));
}

private File findIvyJar(File gradleHome) {
for (File file : new File(gradleHome, "lib/plugins").listFiles()) {
if (file.getName().matches("ivy-.*\\.jar")) {
return file;
}
}
throw new RuntimeException(String.format("Could not locate the Ivy JAR in Gradle distribution '%s'.", gradleHome));
throw new RuntimeException(String.format("Could not locate the JAR for " + fragment + " in Gradle distribution '%s'.", gradleHome));
}
}
1 change: 0 additions & 1 deletion test.groovy

This file was deleted.

0 comments on commit 8f0f260

Please sign in to comment.