1 19 package jline; 20 21 import java.io.*; 22 import java.text.*; 23 import java.util.*; 24 25 26 34 public class ConsoleRunner 35 { 36 public static void main (String [] args) 37 throws Exception 38 { 39 List argList = new ArrayList (Arrays.asList (args)); 40 if (argList.size () == 0) 41 { 42 usage (); 43 return; 44 } 45 46 String mainClass = (String )argList.remove (0); 48 49 ConsoleReader reader = new ConsoleReader (); 51 reader.setHistory (new History (new File ( 52 System.getProperty ("user.home"), ".jline-" + mainClass 53 + ".history"))); 54 55 String completors = System.getProperty (ConsoleRunner.class.getName () 56 + ".completors", ""); 57 List completorList = new ArrayList (); 58 for (StringTokenizer tok = new StringTokenizer (completors, ","); 59 tok.hasMoreTokens (); ) 60 { 61 completorList.add ((Completor)Class.forName (tok.nextToken ()) 62 .newInstance ()); 63 } 64 65 if (completorList.size () > 0) 66 reader.addCompletor (new ArgumentCompletor (completorList)); 67 68 ConsoleReaderInputStream.setIn (reader); 69 try 70 { 71 Class.forName (mainClass) 72 .getMethod ("main", new Class [] { String [].class}) 73 .invoke (null, new Object [] { argList.toArray (new String [0])}); 74 } 75 finally 76 { 77 ConsoleReaderInputStream.restoreIn (); 79 } 80 } 81 82 83 private static void usage () 84 { 85 throw new IllegalArgumentException ("Usage: java " 86 + ConsoleRunner.class.getName () 87 + " <target class name> [args]"); 88 } 89 } 90 91 | Popular Tags |