1 24 25 package org.aspectj.compiler.base; 26 27 import java.util.*; 28 import java.io.File ; 29 import java.lang.reflect.Field ; 30 import java.lang.reflect.Modifier ; 31 32 33 public class Options { 34 public static final String version = org.aspectj.compiler.Version.text; 35 public static final long build = org.aspectj.compiler.Version.time; 36 private static final File defaultOutputDir = new File ("."); 37 public static File getDefaultOutputDir() { return defaultOutputDir; } 38 39 public File outputDir = defaultOutputDir; 40 public File workingDir = new File ("ajworkingdir"); 41 42 public String classpath = null; 43 public String defaultClasspath = null; 45 46 public String bootclasspath = null; 47 public String extdirs = null; 48 49 public String source = "1.3"; 50 51 public boolean lenient = false; 52 public boolean strict = false; 53 54 public String encoding = null; 55 56 public boolean porting = false; 57 58 public boolean ignoreErrors = false; 59 60 public boolean runForever = false; 61 62 public boolean mangler = false; 63 64 public boolean force = true; 65 public boolean nocomments = false; public boolean verbose = false; public boolean preprocess = false; 68 public boolean usejavac = false; 69 public boolean bcgverbose = false; 70 public boolean bcgtrace = false; 71 72 public boolean newWeaving = true; 73 74 public boolean strictTree = false; 75 76 87 public boolean XtargetNearSource = false; 88 89 public boolean O = false; 90 public boolean deprecation = false; 91 92 public boolean noMetaJoinPointOptimization = false; 93 public boolean alwaysMakeAroundClosures = false; 94 95 public boolean Xlint = false; 97 98 public boolean XserializableAspects = false; 100 101 public boolean XaddSafePrefix = false; 103 104 public boolean XOcodeSize = false; 106 107 public boolean g = false; 109 110 public String target = null; 111 112 public boolean dumpstack = false; 114 public boolean timings = false; 115 public boolean noVersionWarnings = false; 116 117 public boolean prettyPrint = false; 118 119 public boolean nosymbols = false; 120 121 public boolean emacssym = false; 122 123 128 public boolean torture = false; 129 public boolean developer = false; 130 131 public boolean jvmTorture = false; 133 134 135 public int threads = 0; 138 public int procs = 1; 139 140 public boolean incremental = false; 142 143 public boolean isStringOption(String key) { 144 try { 145 Field field = Options.class.getField(key); 146 if (Modifier.isFinal(field.getModifiers())) return false; 147 if (field.getType() != String .class) return false; 148 return true; 149 } catch (NoSuchFieldException e) { 150 return false; 151 } 152 } 153 154 public boolean isIntegerOption(String key) { 155 try { 156 Field field = Options.class.getField(key); 157 if (Modifier.isFinal(field.getModifiers())) return false; 158 if (field.getType() != Integer.TYPE) return false; 159 return true; 160 } catch (NoSuchFieldException e) { 161 return false; 162 } 163 } 164 165 public boolean set(String key, Object value) { 166 try { 167 Field field = Options.class.getField(key); 168 if (Modifier.isFinal(field.getModifiers())) return false; 169 if (Modifier.isStatic(field.getModifiers())) { 170 field.set(null,value); 171 } else { 172 field.set(this,value); 173 } 174 return true; 175 } catch (IllegalArgumentException e) { 176 return false; 177 } catch (NoSuchFieldException e) { 178 return false; 179 } catch (IllegalAccessException e) { 180 throw new RuntimeException ("internal error setting option: "+key); 181 } 182 } 183 184 public String setOptions(String [] args, File currentWorkingDir) { 185 for (int i = 0; i < args.length ; i++) { 186 String arg = args[i]; 187 String key = arg.substring(1); 189 Object value = Boolean.TRUE; 190 191 if (arg.equals("-d")) { 192 if ((i+1) >= args.length) return arg; 193 outputDir = qualifiedFile(args[++i], currentWorkingDir); 194 continue; 195 } else if (arg.equals("-workingdir")) { 196 if ((i+1) >= args.length) return arg; 197 workingDir = qualifiedFile(args[++i], currentWorkingDir); 198 continue; 199 } else if (isStringOption(key)) { 200 if ((i+1) >= args.length) return arg; 201 value = args[++i]; 202 } 203 else if (isIntegerOption(key)) { 204 if ((i+1) >= args.length) return arg; 205 value = Integer.valueOf(args[++i]); 206 } 207 if (!set(key, value)) { 208 return arg; 209 } 210 } 211 return null; 212 } 213 214 private File qualifiedFile(String name, File currentWorkingDir) { 215 name = name.replace('/', File.separatorChar); 216 File file = new File (name); 217 if (!file.isAbsolute() && currentWorkingDir != null) { 218 file = new File (currentWorkingDir, name); 219 } 220 return file; 221 } 222 223 224 } 225 | Popular Tags |