1 17 package org.apache.tools.ant.taskdefs.optional.metamata; 18 19 import java.io.File ; 20 import java.io.FileOutputStream ; 21 import java.io.IOException ; 22 import java.io.OutputStream ; 23 import java.util.Vector ; 24 import org.apache.tools.ant.BuildException; 25 import org.apache.tools.ant.Project; 26 import org.apache.tools.ant.taskdefs.ExecuteStreamHandler; 27 import org.apache.tools.ant.taskdefs.LogStreamHandler; 28 import org.apache.tools.ant.types.FileSet; 29 import org.apache.tools.ant.types.Path; 30 31 41 public class MAudit extends AbstractMetamataTask { 42 43 69 70 72 73 74 static final String AUDIT_PATTERN = "(?:file:)?(.+):(\\d+)\\s*:\\s+(.*)"; 76 77 private File outFile = null; 78 79 private Path searchPath = null; 80 81 private Path rulesPath = null; 82 83 private boolean fix = false; 84 85 private boolean list = false; 86 87 private boolean unused = false; 88 89 private boolean quiet = false; 91 private boolean exit = false; 92 private boolean offsets = false; 93 private boolean verbose = false; 94 private boolean fullsemanticize = false; 95 96 97 public MAudit() { 98 super("com.metamata.gui.rc.MAudit"); 99 } 100 101 104 105 public void setTofile(File outFile) { 106 this.outFile = outFile; 107 } 108 109 114 public void setFix(boolean flag) { 115 this.fix = flag; 116 } 117 118 123 public void setList(boolean flag) { 124 this.list = flag; 125 } 126 127 133 public void setUnused(boolean flag) { 134 this.unused = flag; 135 } 136 137 142 public void setQuiet(boolean flag) { 143 this.quiet = flag; 144 } 145 146 151 public void setExit(boolean flag) { 152 this.exit = flag; 153 } 154 155 159 public void setOffsets(boolean flag) { 160 this.offsets = flag; 161 } 162 163 168 public void setVerbose(boolean flag) { 169 this.verbose = flag; 170 } 171 172 176 public void setFullsemanticize(boolean flag) { 177 this.fullsemanticize = flag; 178 } 179 180 184 public Path createRulespath() { 185 if (rulesPath == null) { 186 rulesPath = new Path(getProject()); 187 } 188 return rulesPath; 189 } 190 191 195 public Path createSearchpath() { 196 if (searchPath == null) { 197 searchPath = new Path(getProject()); 198 } 199 return searchPath; 200 } 201 202 205 protected Vector getOptions() { 206 Vector options = new Vector (512); 207 for (int i = 0; i < fileSets.size(); i++) { 210 FileSet fs = (FileSet) fileSets.elementAt(i); 211 Path path = createSourcepath(); 212 File dir = fs.getDir(getProject()); 213 path.setLocation(dir); 214 } 215 216 if (sourcePath != null) { 220 sourcePath.append(classPath); classPath = sourcePath; 222 sourcePath = null; } 224 225 if (classPath != null) { 227 options.addElement("-classpath"); 228 options.addElement(classPath.toString()); 229 } 230 if (quiet) { 233 options.addElement("-quiet"); 234 } 235 if (fullsemanticize) { 236 options.addElement("-full-semanticize"); 237 } 238 if (verbose) { 239 options.addElement("-verbose"); 240 } 241 if (offsets) { 242 options.addElement("-offsets"); 243 } 244 if (exit) { 245 options.addElement("-exit"); 246 } 247 if (fix) { 248 options.addElement("-fix"); 249 } 250 options.addElement("-fullpath"); 251 252 if (list) { 256 options.addElement("-list"); 257 } 258 if (sourcePath != null) { 259 options.addElement("-sourcepath"); 260 options.addElement(sourcePath.toString()); 261 } 262 addAllVector(options, includedFiles.keys()); 263 if (unused) { 264 options.addElement("-unused"); 265 options.addElement(searchPath.toString()); 266 } 267 return options; 268 } 269 270 273 protected void checkOptions() throws BuildException { 274 super.checkOptions(); 275 if (unused && searchPath == null) { 276 throw new BuildException("'searchpath' element must be set when " 277 + "looking for 'unused' declarations."); 278 } 279 if (!unused && searchPath != null) { 280 log("'searchpath' element ignored. 'unused' attribute is disabled.", 281 Project.MSG_WARN); 282 } 283 if (rulesPath != null) { 284 cmdl.createClasspath(getProject()).addExisting(rulesPath); 285 } 286 } 287 288 protected ExecuteStreamHandler createStreamHandler() throws BuildException { 289 if (outFile == null) { 291 return new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_ERR); 292 } 293 ExecuteStreamHandler handler = null; 294 OutputStream out = null; 295 try { 296 out = new FileOutputStream (outFile); 297 handler = new MAuditStreamHandler(this, out); 298 } catch (IOException e) { 299 throw new BuildException(e); 300 } finally { 301 if (out == null) { 302 try { 303 out.close(); 304 } catch (IOException e) { 305 } 306 } 307 } 308 return handler; 309 } 310 311 protected void cleanUp() throws BuildException { 312 super.cleanUp(); 313 318 321 } 322 323 } 324 325 | Popular Tags |