1 package org.incava.doctorj; 2 3 import java.io.*; 4 import java.util.*; 5 import org.incava.analysis.ContextReport; 6 import org.incava.jagol.*; 7 import org.incava.lang.StringExt; 8 9 10 20 public class Options extends OptionSet 21 { 22 public static int MAXIMUM_WARNING_LEVEL = 100; 23 24 public static int MINIMUM_WARNING_LEVEL = -1; 25 26 public static int DEFAULT_WARNING_LEVEL = 4; 27 28 31 public static int warningLevel = DEFAULT_WARNING_LEVEL; 32 33 38 public static boolean emacsOutput = false; 39 40 43 public static String VERSION = "5.1.2"; 44 45 48 public static String source = "1.4"; 49 50 53 private IntegerOption _levelOpt; 54 55 58 private IntegerOption _warningOpt; 59 60 63 private BooleanOption _errorsOpt; 64 65 70 75 80 85 90 93 private BooleanOption _emacsOpt; 94 95 98 private IntegerOption _tabWidthOpt; 99 100 103 private BooleanOption _verboseOpt; 104 105 108 private ListOption _dictOpt; 109 110 113 private BooleanOption _versionOpt; 114 115 118 private StringOption _sourceOpt; 119 120 private static Options instance = null; 121 122 public static Options get() 123 { 124 if (instance == null) { 125 instance = new Options(); 126 } 127 return instance; 128 } 129 130 protected Options() 131 { 132 super("doctorj", "Analyzes and validates Java and Javadoc"); 133 134 136 Boolean emacs = new Boolean (emacsOutput); 137 String emacsProperty = System.getProperty("doctorj.emacs"); 138 tr.Ace.log("emacs property: " + emacsProperty); 139 if (emacsProperty != null) { 140 emacs = new Boolean (emacsProperty); 141 tr.Ace.log("emacs: " + emacs); 142 } 143 144 Integer lvl = new Integer (warningLevel); 145 String warningLvlProperty = System.getProperty("doctorj.level"); 146 if (warningLvlProperty == null) { 147 warningLvlProperty = System.getProperty("doctorj.warning"); 148 } 149 150 if (warningLvlProperty != null) { 151 lvl = new Integer (warningLvlProperty); 152 } 153 154 Integer tabWidth = new Integer (ContextReport.tabWidth); 155 String tabWidthProperty = System.getProperty("doctorj.tabwidth"); 156 if (tabWidthProperty != null) { 157 tabWidth = new Integer (tabWidthProperty); 158 } 159 160 Boolean verbose = new Boolean (false); 161 String verboseProperty = System.getProperty("doctorj.verbose"); 162 if (verboseProperty != null) { 163 verbose = new Boolean (verboseProperty); 164 } 165 166 List wordLists = new ArrayList(); 167 String dirProperty = System.getProperty("doctorj.dir"); 168 tr.Ace.log("dirProperty: " + dirProperty); 169 170 if (dirProperty != null) { 171 Locale locale = Locale.getDefault(); 172 tr.Ace.log("locale: " + locale); 173 174 String wordListFile = dirProperty + "/words." + locale; 175 tr.Ace.log("wordListFile: " + wordListFile); 176 177 wordLists.add(wordListFile); 178 } 179 180 String dictProperty = System.getProperty("doctorj.dictionaries"); 181 tr.Ace.log("dictProperty", dictProperty); 182 183 if (dictProperty != null) { 184 List list = StringExt.listify(dictProperty); 185 Iterator it = list.iterator(); 186 while (it.hasNext()) { 187 String s = (String )it.next(); 188 wordLists.add(s); 189 } 190 } 191 192 add(_emacsOpt = new BooleanOption("emacs", "whether to list violations in Emacs form (single line)", emacs)); 193 add(_levelOpt = new IntegerOption("level", "the level of warnings to be output, with 0 being to check only errors", lvl)); 194 add(_warningOpt = new IntegerOption("warning", "same as --level", lvl)); 195 196 203 add(_tabWidthOpt = new IntegerOption("tabwidth", "the number of spaces to treat tabs equal to", tabWidth)); 204 add(_dictOpt = new ListOption("dictionaries", "the list of dictionary (word list) files", wordLists)); 205 add(_verboseOpt = new BooleanOption("verbose", "whether to run in verbose mode (for debugging)", verbose)); 206 add(_versionOpt = new BooleanOption("version", "Displays the version")); 207 add(_sourceOpt = new StringOption("source", "the Java source version; either 1.3, 1.4 (the default), or 1.5", source)); 208 _versionOpt.setShortName('v'); 209 210 addRunControlFile("/etc/doctorj.conf"); 211 addRunControlFile("~/.doctorjrc"); 212 } 213 214 219 public String [] process(String [] args) 220 { 221 tr.Ace.log("args: " + args); 222 String [] unprocessed = super.process(args); 223 224 Integer tabWidthInt = _tabWidthOpt.getValue(); 225 if (tabWidthInt != null) { 226 tr.Ace.log("setting tab width: " + tabWidthInt); 227 ContextReport.tabWidth = tabWidthInt.intValue(); 228 } 229 230 Integer levelInt = _levelOpt.getValue(); 231 if (levelInt != null) { 232 tr.Ace.log("setting warning level: " + levelInt); 233 warningLevel = levelInt.intValue(); 234 } 235 236 255 Boolean emacsBool = _emacsOpt.getValue(); 256 if (emacsBool != null) { 257 tr.Ace.log("setting output format: " + emacsBool); 258 emacsOutput = emacsBool.booleanValue(); 259 } 260 261 Boolean verboseBool = _verboseOpt.getValue(); 262 if (verboseBool != null) { 263 tr.Ace.setVerbose(verboseBool.booleanValue()); 264 } 265 266 Boolean versionBool = _versionOpt.getValue(); 267 if (versionBool != null) { 268 System.out.println("doctorj, version " + VERSION); 269 System.out.println("Written by Jeff Pace (jpace [at] incava [dot] org)"); 270 System.out.println("Released under the Lesser GNU Public License"); 271 System.exit(0); 272 } 273 274 List dictList = _dictOpt.getValue(); 275 if (dictList != null) { 276 Iterator it = dictList.iterator(); 277 while (it.hasNext()) { 278 String dict = (String )it.next(); 279 ItemDocAnalyzer.spellChecker.addDictionary(dict); 280 } 281 } 282 283 String sourceStr = _sourceOpt.getValue(); 284 if (sourceStr != null) { 285 tr.Ace.log("sourceStr", sourceStr); 286 source = sourceStr; 287 } 288 289 tr.Ace.blue("unprocessed", unprocessed); 290 291 return unprocessed; 292 } 293 294 } 295 | Popular Tags |