24
24
public class GroovyBootstrapMainStarter extends BootstrapMainStarter {
25
25
@ Override
26
26
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 ());
30
37
Thread .currentThread ().setContextClassLoader (contextClassLoader );
31
38
Class <?> mainClass = contextClassLoader .loadClass ("groovy.ui.GroovyMain" );
32
39
Method mainMethod = mainClass .getMethod ("main" , String [].class );
@@ -36,21 +43,12 @@ public void start(String[] args, File gradleHome) throws Exception {
36
43
}
37
44
}
38
45
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" )) {
42
49
return file ;
43
50
}
44
51
}
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 ));
55
53
}
56
54
}
0 commit comments