1 46 package org.codehaus.groovy.tools; 47 48 import org.codehaus.classworlds.ClassRealm; 49 import org.codehaus.classworlds.ClassWorld; 50 import java.lang.reflect .*; 51 import groovy.ui.GroovyMain; 52 import groovy.ui.InteractiveShell; 53 54 55 56 59 public class GroovyStarter { 60 61 static void printUsage() { 62 System.out.println("possible programs are 'groovyc','groovy','console','grok' and 'groovysh'"); 63 System.exit(1); 64 } 65 66 public static void main(String oldArgs[],ClassWorld classWorld ) { 67 try { 68 ClassRealm system = classWorld.newRealm("system"); 70 71 ClassRealm groovy = classWorld.getRealm("groovy"); 73 74 groovy.importFrom("system", ""); 77 78 if (oldArgs.length==0) { 79 printUsage(); 80 System.exit(1); 81 } 82 83 String program = oldArgs[0].toLowerCase(); 84 String [] args = new String [oldArgs.length-1]; 85 for (int i=0; i<args.length; i++) { 86 args[i] = oldArgs[i+1]; 87 } 88 89 if (program.equals("groovyc")) { 90 org.codehaus.groovy.tools.FileSystemCompiler.main(args); 91 } else if (program.equals("groovy")) { 92 GroovyMain.main(args); 93 } else if (program.equals("console")) { 94 Class c = Class.forName("groovy.ui.Console"); 96 Method m= c.getMethod("main", new Class []{String [].class}); 97 m.invoke(null, new Object []{args}); 98 } else if (program.equals("groovysh")) { 99 InteractiveShell.main(args); 100 } else if (program.equals("grok")) { 101 org.codehaus.groovy.tools.Grok.main(args); 102 } else { 103 System.out.println("unknown program "+program); 104 printUsage(); 105 System.exit(1); 106 } 107 108 } catch (Exception e) { 109 e.printStackTrace(); 110 System.exit(1); 111 } 112 113 } 114 } 115 | Popular Tags |