1 package spoon; 2 3 import java.io.File ; 4 import java.lang.reflect.Method ; 5 import java.util.ArrayList ; 6 7 import spoon.processing.ProcessingManager; 8 import spoon.support.RuntimeProcessingManager; 9 10 import com.martiansoftware.jsap.FlaggedOption; 11 import com.martiansoftware.jsap.JSAP; 12 import com.martiansoftware.jsap.JSAPException; 13 14 23 public class LtLauncher extends Launcher { 24 25 34 static public void main(String args[]) throws JSAPException { 35 new LtLauncher(args).run(); 36 } 37 38 41 public LtLauncher(String [] args) throws JSAPException { 42 super(args); 43 } 44 45 48 protected JSAP defineArgs() throws JSAPException { 49 JSAP jsap = super.defineArgs(); 50 51 FlaggedOption opt2 = new FlaggedOption("ltprocessors"); 53 opt2.setShortFlag('l'); 54 opt2.setLongFlag("ltprocessors"); 55 opt2.setHelp("List of load-time processors to use"); 56 opt2.setStringParser(JSAP.STRING_PARSER); 57 opt2.setRequired(false); 58 jsap.registerParameter(opt2); 59 60 opt2 = new FlaggedOption("sourcepath"); 61 opt2.setLongFlag("sourcepath"); 62 opt2.setHelp("Specify where to find input source files"); 63 opt2.setStringParser(JSAP.STRING_PARSER); 64 opt2.setRequired(false); 65 jsap.registerParameter(opt2); 66 67 return jsap; 68 } 69 70 java.util.List <String > ltprocessors = new ArrayList <String >(); 71 72 75 @Override 76 public void addProcessor(String name) { 77 super.addProcessor(name); 78 ltprocessors.add(name); 79 } 80 81 84 protected java.util.List <String > getLtProcessorTypes() { 85 if (getArguments().getString("ltprocessors") != null) { 86 for (String processorName : getArguments() 87 .getString("ltprocessors").split(File.pathSeparator)) { 88 ltprocessors.add(processorName); 89 } 90 } 91 return ltprocessors; 92 } 93 94 97 public void run() { 98 try { 99 getFactory().getEnvironment().debugMessage( 100 "loading command-line arguments"); 101 processArguments(); 102 103 getFactory().getEnvironment().debugMessage("Start Pre-processing"); 104 build(); 105 process(); 106 107 SpoonClassLoader ccl = new SpoonClassLoader(); 109 ccl.setFactory(getFactory()); 110 if (getArguments().getString("sourcepath") != null) 111 ccl.setSourcePath(new File (getArguments().getString( 112 "sourcepath"))); 113 114 ProcessingManager pm = new RuntimeProcessingManager(getFactory()); 116 for (String s : getLtProcessorTypes()) 117 pm.addProcessor(s); 118 ccl.setProcessingManager(pm); 119 120 getFactory().getEnvironment().debugMessage("Running"); 121 String progClass = getArguments().getString("class"); 123 String progArgs[] = getArguments().getStringArray("arguments"); 124 125 Class clas = ccl.loadClass(progClass); 127 Class mainArgType[] = { (new String [0]).getClass() }; 128 Method main = clas.getMethod("main", mainArgType); 129 Object argsArray[] = { progArgs }; 130 main.invoke(null, argsArray); 131 } catch (Exception e) { 132 e.printStackTrace(); 133 } 134 } 135 } 136 | Popular Tags |