1 23 package org.hammurapi; 24 25 import java.io.File ; 26 import java.io.FileNotFoundException ; 27 import java.io.FileOutputStream ; 28 import java.io.IOException ; 29 import java.io.InputStream ; 30 import java.io.PrintStream ; 31 import java.text.ParseException ; 32 import java.text.SimpleDateFormat ; 33 import java.util.ArrayList ; 34 import java.util.Collection ; 35 import java.util.Date ; 36 import java.util.Enumeration ; 37 import java.util.HashSet ; 38 import java.util.Iterator ; 39 import java.util.LinkedList ; 40 import java.util.List ; 41 import java.util.zip.ZipEntry ; 42 import java.util.zip.ZipException ; 43 import java.util.zip.ZipFile ; 44 45 import javax.xml.parsers.DocumentBuilderFactory ; 46 import javax.xml.parsers.FactoryConfigurationError ; 47 import javax.xml.parsers.ParserConfigurationException ; 48 import javax.xml.transform.TransformerException ; 49 50 import org.apache.commons.cli.CommandLine; 51 import org.apache.commons.cli.HelpFormatter; 52 import org.apache.commons.cli.Option; 53 import org.apache.commons.cli.OptionBuilder; 54 import org.apache.commons.cli.Options; 55 import org.apache.tools.ant.BuildException; 56 import org.apache.tools.ant.BuildLogger; 57 import org.apache.tools.ant.DefaultLogger; 58 import org.apache.tools.ant.DemuxOutputStream; 59 import org.apache.tools.ant.Project; 60 import org.apache.tools.ant.Task; 61 import org.apache.tools.ant.types.FileSet; 62 import org.apache.tools.ant.types.Path; 63 import org.apache.xpath.CachedXPathAPI; 64 import org.hammurapi.render.dom.DetailedResultsRenderer; 65 import org.hammurapi.results.persistent.jdbc.BaselineSetupViolationFilter; 66 import org.hammurapi.results.persistent.jdbc.BaselineViolationFilter; 67 import org.w3c.dom.Document ; 68 import org.w3c.dom.Element ; 69 import org.w3c.dom.traversal.NodeIterator; 70 import org.xml.sax.SAXException ; 71 72 import com.pavelvlasov.ant.ObjectEntry; 73 import com.pavelvlasov.ant.XmlSourceEntry; 74 import com.pavelvlasov.jsel.RevisionMapper; 75 import com.pavelvlasov.render.RenderRequest; 76 import com.pavelvlasov.render.RenderingException; 77 import com.pavelvlasov.render.dom.AbstractRenderer; 78 import com.pavelvlasov.review.Signed; 79 import com.pavelvlasov.util.ClassResourceLoader; 80 import com.pavelvlasov.xml.dom.AbstractDomObject; 81 82 87 public class TaskBase extends Task { 88 89 protected void deleteFile(File file) { 90 if (file!=null) { 91 if (file.isDirectory()) { 92 File [] children=file.listFiles(); 93 if (children!=null) { 94 for (int i=0; i<children.length; i++) { 95 deleteFile(children[i]); 96 } 97 } 98 } 99 100 if (file.isFile() || file.isDirectory()) { 101 file.delete(); 102 } 103 } 104 } 105 106 109 protected List getReviewAcceptorEntries() { 110 return reviewAcceptorEntries; 111 } 112 113 116 protected Integer getSeverityThreshold() { 117 return severityThreshold; 118 } 119 120 123 protected Double getSigmaThreshold() { 124 return sigmaThreshold; 125 } 126 127 130 protected Integer getDpmoThreshold() { 131 return dpmoThreshold; 132 } 133 134 137 protected boolean isFailOnWarnings() { 138 return failOnWarnings; 139 } 140 141 private File unpackDir; 142 143 149 public void setUnpackDir(File unpackDir) { 150 this.unpackDir=unpackDir; 151 } 152 153 157 public String getDebugType() { 158 return debugType; 159 } 160 161 protected Collection srcFiles = new LinkedList (); 162 163 protected static void loadEmbeddedInspectors(InspectorSet inspectorSet) throws BuildException, HammurapiException { 164 ClassResourceLoader crl=new ClassResourceLoader(TaskBase.class); 165 InputStream inspectorStream=crl.getResourceAsStream(null, null, "xml"); 166 if (inspectorStream==null) { 167 throw new BuildException("Cannot load embedded inspectors"); 168 } 169 170 DomInspectorSource source=new DomInspectorSource(inspectorStream, "Hammurapi.jar"); 171 source.loadInspectors(inspectorSet); 172 } 173 174 177 protected static void populateOptions(Options options) { 178 Option waiverStubsOption=OptionBuilder 179 .withArgName("waiverStubs") 180 .hasArg() 181 .withDescription("Where to output waiver stubs") 182 .isRequired(false) 183 .create("w"); 184 185 options.addOption(waiverStubsOption); 186 187 Option databaseOption=OptionBuilder 188 .withDescription("Database name") 189 .withArgName("local database") 190 .hasArg() 191 .isRequired(false) 192 .create("D"); 193 194 options.addOption(databaseOption); 195 196 Option includeInspectorOption=OptionBuilder 197 .withDescription("Enable inspector") 198 .withArgName("inspector name") 199 .hasArg() 200 .isRequired(false) 201 .create("I"); 202 203 options.addOption(includeInspectorOption); 204 205 Option configFileOption=OptionBuilder 206 .withDescription("Config file") 207 .withArgName("file") 208 .hasArg() 209 .isRequired(false) 210 .create("m"); 211 212 options.addOption(configFileOption); 213 214 Option configUrlOption=OptionBuilder 215 .withDescription("Config url") 216 .withArgName("url") 217 .hasArg() 218 .isRequired(false) 219 .create("q"); 220 221 options.addOption(configUrlOption); 222 223 Option unpackDirOption=OptionBuilder 224 .withDescription("Unpack directory") 225 .withArgName("directory") 226 .hasArg() 227 .isRequired(false) 228 .create("r"); 229 230 options.addOption(unpackDirOption); 231 232 Option excludeInspectorOption=OptionBuilder 233 .withDescription("Disable inspector") 234 .withArgName("inspector name") 235 .hasArg() 236 .isRequired(false) 237 .create("X"); 238 239 options.addOption(excludeInspectorOption); 240 241 Option archiveFileOption=OptionBuilder 242 .withArgName("archive") 243 .hasArg() 244 .withDescription("Hammurapi archive") 245 .isRequired(false) 246 .create("A"); 247 248 options.addOption(archiveFileOption); 249 Option waiversFileOption=OptionBuilder 250 .withArgName("waivers file") 251 .hasArg() 252 .withDescription("Waivers File") 253 .isRequired(false) 254 .create("W"); 255 256 options.addOption(waiversFileOption); 257 258 Option forceOption=OptionBuilder 259 .withDescription("Force reviews of unchanged files") 260 .isRequired(false) 261 .create("f"); 262 263 Option baseliningOption=OptionBuilder 265 .withArgName("off|on|set") 266 .hasArg() 267 .withDescription("Baselining mode") 268 .isRequired(false) 269 .create("B"); 270 271 options.addOption(forceOption); 272 273 Option forceOnWarningsOption=OptionBuilder 274 .withDescription("Do not force reviews of files with warnings") 275 .isRequired(false) 276 .create("k"); 277 278 options.addOption(forceOnWarningsOption); 279 280 Option doNotEvictOption=OptionBuilder 281 .withDescription("Evict bad inspectors") 282 .isRequired(false) 283 .create("E"); 284 285 options.addOption(doNotEvictOption); 286 287 Option waiversUrlOption=OptionBuilder 288 .withArgName("waivers url") 289 .hasArg() 290 .withDescription("Waivers URL") 291 .isRequired(false) 292 .create("U"); 293 294 options.addOption(waiversUrlOption); 295 296 Option classPathOption=OptionBuilder 297 .withArgName("classpath") 298 .hasArg() 299 .withDescription("ClassPath") 300 .isRequired(false) 301 .create("c"); 302 303 options.addOption(classPathOption); 304 305 Option sigmaThresholdOption=OptionBuilder 306 .withArgName("sigmaThreshold") 307 .hasArg() 308 .withDescription("Sigma threshold") 309 .isRequired(false) 310 .create("s"); 311 312 options.addOption(sigmaThresholdOption); 313 314 Option dpmoThresholdOption=OptionBuilder 315 .withArgName("dpmoThreshold") 316 .hasArg() 317 .withDescription("DPMO Threshold") 318 .isRequired(false) 319 .create("d"); 320 321 options.addOption(dpmoThresholdOption); 322 323 Option severityThresholdOption=OptionBuilder 324 .withArgName("severityThreshold") 325 .hasArg() 326 .withDescription("Severity threshold") 327 .isRequired(false) 328 .create("S"); 329 330 options.addOption(severityThresholdOption); 331 332 Option noEmbeddedInspectorsOption=OptionBuilder 333 .withDescription("Do not load embedded inspectors") 334 .isRequired(false) 335 .create("e"); 336 337 options.addOption(noEmbeddedInspectorsOption); 338 339 Option inspectorsFileOption=OptionBuilder 340 .withArgName("inspectorsFile") 341 .hasArg() 342 .withDescription("Inspectors file") 343 .isRequired(false) 344 .create("i"); 345 346 options.addOption(inspectorsFileOption); 347 348 Option inspectorsURLOption=OptionBuilder 349 .withArgName("inspectorsURL") 350 .hasArg() 351 .withDescription("Inspectors URL") 352 .isRequired(false) 353 .create("u"); 354 355 options.addOption(inspectorsURLOption); 356 357 Option titleOption=OptionBuilder 358 .withArgName("title") 359 .hasArg() 360 .withDescription("Report title") 361 .isRequired(false) 362 .create("T"); 363 364 options.addOption(titleOption); 365 366 Option debugTypeOption=OptionBuilder 367 .withArgName("debug type") 368 .hasArg() 369 .withDescription("Jsel type to debug") 370 .isRequired(false) 371 .create("t"); 372 373 options.addOption(debugTypeOption); 374 375 Option listenerOption=OptionBuilder 376 .withArgName("class name") 377 .hasArg() 378 .withDescription("Review listener") 379 .isRequired(false) 380 .create("l"); 381 382 options.addOption(listenerOption); 383 384 Option debugOption=OptionBuilder 385 .withDescription("Debug") 386 .isRequired(false) 387 .create("g"); 388 389 options.addOption(debugOption); 390 391 Option verboseOption=OptionBuilder 392 .withDescription("Verbose") 393 .isRequired(false) 394 .create("v"); 395 396 options.addOption(verboseOption); 397 398 Option xmlOption=OptionBuilder 399 .withDescription("Output XML") 400 .isRequired(false) 401 .create("x"); 402 403 options.addOption(xmlOption); 404 405 Option suppressOutputOption=OptionBuilder 406 .withDescription("Suppress output") 407 .isRequired(false) 408 .create("o"); 409 410 options.addOption(suppressOutputOption); 411 412 Option descriptionOption=OptionBuilder 413 .withDescription("Review description") 414 .withArgName("description") 415 .hasArg() 416 .isRequired(false) 417 .create("y"); 418 419 options.addOption(descriptionOption); 420 421 Option helpOption=OptionBuilder.withDescription("Print this message").isRequired(false).create("h"); 422 options.addOption(helpOption); 423 } 424 425 protected static void printHelpAndExit(Options options) { 426 HelpFormatter formatter=new HelpFormatter(); 427 formatter.printHelp("Usage: hammurapi [options] <output dir> <source files/dirs>", options, false); 428 System.exit(1); 429 } 430 431 435 public void setDebugType(String debugType) { 436 this.debugType=debugType; 437 } 438 439 443 public void setEmbeddedInspectors(boolean embeddedInspectors) { 444 this.embeddedInspectors=embeddedInspectors; 445 } 446 447 private String debugType; 448 protected boolean embeddedInspectors = true; 449 protected List srcFileSets = new LinkedList (); 450 451 455 public FileSet createSrc() { 456 FileSet ret=new HammurapiFileSet("**/*.java"); 457 srcFileSets.add(ret); 458 return ret; 459 } 460 461 protected void setHadExceptions() { 462 hadExceptions=true; 463 } 464 465 470 protected void writeWaiverStubs(final Collection rejectedViolations) throws RenderingException, FileNotFoundException { 471 if (waiverStubs!=null) { 472 class WaiverStubsRenderer extends AbstractRenderer { 473 WaiverStubsRenderer() { 474 super(new RenderRequest(rejectedViolations)); 475 } 476 477 public Element render(Document document) { 478 Element ret=document.createElement("waivers"); 479 Iterator it=rejectedViolations.iterator(); 480 final Date now=new Date (); 481 while (it.hasNext()) { 482 final Violation violation=(Violation) it.next(); 483 484 StringBuffer comment=new StringBuffer (); 485 comment.append("Source: "); 486 comment.append(violation.getSource().getSourceURL()); 487 488 comment.append("\nLine: "); 489 comment.append(violation.getSource().getLine()); 490 491 comment.append("\nCol: "); 492 comment.append(violation.getSource().getColumn()); 493 494 comment.append("\nDescription: "); 495 comment.append(violation.getDescriptor().getDescription()); 496 497 comment.append("\nMesssage: "); 498 comment.append(violation.getMessage()); 499 500 ret.appendChild(document.createComment(comment.toString())); 501 502 Waiver waiver=new Waiver() { 503 504 public String getInspectorName() { 505 return violation.getDescriptor().getName(); 506 } 507 508 public Date getExpirationDate() { 509 return now; 510 } 511 512 public String getReason() { 513 return "*** Put reason here ***"; 514 } 515 516 public boolean waive(Violation violation, boolean peek) { 517 return false; 519 } 520 521 public boolean isActive() { 522 return false; 524 } 525 526 Collection signatures=new HashSet (); 527 528 { 529 if (violation.getSource() instanceof Signed) { 530 signatures.add(((Signed) violation.getSource()).getSignature()); 531 } 532 } 533 534 public Collection getSignatures() { 535 return signatures; 536 } 537 }; 538 ret.appendChild(DetailedResultsRenderer.renderWaiver(waiver, document)); 539 } 540 return ret; 541 } 542 } 543 WaiverStubsRenderer renderer=new WaiverStubsRenderer(); 544 renderer.setEmbeddedStyle(false); 545 renderer.render(new FileOutputStream (waiverStubs)); 546 } 547 } 548 549 protected File processArchive() { 550 if (archive==null) { 551 return null; 552 } 553 554 String tmpDirProperty=System.getProperty("java.io.tmpdir"); 555 File tmpDir=tmpDirProperty==null ? new File (".") : new File (tmpDirProperty); 556 SimpleDateFormat sdf=new SimpleDateFormat ("yyyyMMddHHmmss"); 557 String prefix = "har_"+sdf.format(new Date ()); 558 File workDir = unpackDir==null ? new File (tmpDir, prefix) : unpackDir; 559 560 for (int i=0; unpackDir==null && workDir.exists(); i++) { 561 workDir=new File (tmpDir, prefix+"_"+Integer.toString(i, Character.MAX_RADIX)); 562 } 563 564 if (workDir.exists() || workDir.mkdir()) { 565 try { 566 ZipFile zipFile=new ZipFile (archive); 567 Enumeration entries = zipFile.entries(); 568 while (entries.hasMoreElements()) { 569 ZipEntry entry=(ZipEntry ) entries.nextElement(); 570 if (!entry.getName().endsWith("/")) { 571 File outFile=new File (workDir, entry.getName().replace('/', File.separatorChar)); 572 if (!outFile.getParentFile().exists() && !outFile.getParentFile().mkdirs()) { 573 throw new BuildException("Directory does not exist and cannot be created: "+outFile.getParentFile().getAbsolutePath()); 574 } 575 576 log("Archive entry "+entry.getName()+" unpacked to "+outFile.getAbsolutePath(), Project.MSG_DEBUG); 577 578 byte[] buf=new byte[4096]; 579 int l; 580 InputStream in=zipFile.getInputStream(entry); 581 FileOutputStream fos=new FileOutputStream (outFile); 582 while ((l=in.read(buf))!=-1) { 583 fos.write(buf, 0, l); 584 } 585 in.close(); 586 fos.close(); 587 } 588 } 589 zipFile.close(); 590 591 File configFile=new File (workDir, "config.xml"); 592 if (configFile.exists() && configFile.isFile()) { 593 Document configDoc=DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(configFile); 594 processConfig(workDir, configDoc.getDocumentElement()); 595 } else { 596 throw new BuildException("Archive configuration file does not exist or is not a file"); 597 } 598 } catch (ZipException e) { 599 throw new BuildException(e.toString(), e); 600 } catch (IOException e) { 601 throw new BuildException(e.toString(), e); 602 } catch (SAXException e) { 603 throw new BuildException(e.toString(), e); 604 } catch (ParserConfigurationException e) { 605 throw new BuildException(e.toString(), e); 606 } catch (FactoryConfigurationError e) { 607 throw new BuildException(e.toString(), e); 608 } 609 } else { 610 throw new BuildException("Could not create directory "+workDir.getAbsolutePath()); 611 } 612 return unpackDir==null ? workDir : null; 613 } 614 615 621 private void processConfig(File workDir, Element config) { 622 if (config!=null) { 623 try { 624 setAttributes(config); 625 626 CachedXPathAPI cxpa=new CachedXPathAPI(); 627 NodeIterator nit=cxpa.selectNodeIterator(config, "sources/source"); 628 Element element; 629 while ((element=(Element ) nit.nextNode())!=null) { 630 srcFiles.add(new File (workDir, AbstractDomObject.getElementText(element))); 631 } 632 633 nit=cxpa.selectNodeIterator(config, "classpath/path"); 634 while ((element=(Element ) nit.nextNode())!=null) { 635 File cpe = new File (workDir, AbstractDomObject.getElementText(element)); 636 if (cpe.exists()) { 637 createClasspath().setLocation(cpe); 638 log("File "+cpe.getAbsolutePath()+" added to classpath", Project.MSG_DEBUG); 639 } else { 640 throw new BuildException("Classpath element "+cpe.getAbsolutePath()+" does not exist"); 641 } 642 } 643 } catch (TransformerException e) { 644 throw new BuildException("Cannot load config", e); 645 } 646 } 647 } 648 649 653 protected void setAttributes(Element config) { 654 if (config.hasAttribute("title")) { 655 setTitle(config.getAttribute("title")); 656 } 657 658 if (config.hasAttribute("dpmo-threshold")) { 659 setDpmoThreshold(Integer.parseInt(config.getAttribute("dpmo-threshold"))); 660 } 661 662 if (config.hasAttribute("sigma-threshold")) { 663 setSigmaThreshold(Double.parseDouble(config.getAttribute("sigma-threshold"))); 664 } 665 666 if (config.hasAttribute("severity-threshold")) { 667 setSeverityThreshold(Integer.parseInt(config.getAttribute("severity-threshold"))); 668 } 669 670 if (config.hasAttribute("force")) { 671 setForce("yes".equals(config.getAttribute("force"))); 672 } 673 674 if (config.hasAttribute("force-on-warnings")) { 675 setForceOnWarnings("yes".equals(config.getAttribute("force-on-warnings"))); 676 } 677 678 if (config.hasAttribute("review-description")) { 679 setReviewDescription(config.getAttribute("review-description")); 680 } 681 682 if (config.hasAttribute("baselining")) { 684 setBaselining(config.getAttribute("baselining")); 685 } 686 } 687 688 protected boolean suppressLogo; 689 690 694 public Output createOutput() { 695 Output output=new Output(this); 696 outputs.add(output); 697 return output; 698 } 699 700 705 public HistoryOutput createHistoryOutput() { 706 HistoryOutput historyOutput=new HistoryOutput(); 707 outputs.add(historyOutput); 708 return historyOutput; 709 } 710 711 protected List outputs = new LinkedList (); 712 protected boolean hadExceptions; 713 714 718 public Path createClasspath() { 719 if (classPath == null) { 720 classPath = new Path(project); 721 } 722 return classPath.createPath(); 723 } 724 725 public void setClassPath(Path classPath) { 726 if (this.classPath == null) { 727 this.classPath = classPath; 728 } else { 729 this.classPath.append(classPath); 730 } 731 } 732 733 737 protected Path classPath; 738 739 743 public InspectorEntry createInspector() { 744 InspectorEntry inspectorEntry=new InspectorEntry(); 745 inspectors.add(inspectorEntry); 746 return inspectorEntry; 747 } 748 749 protected List inspectors = new LinkedList (); 750 751 755 public WaiverSourceEntry createWaivers() { 756 WaiverSourceEntry ret=new WaiverSourceEntry(); 757 ret.setProject(getProject()); 758 waivers.add(ret); 759 return ret; 760 } 761 762 private Collection configs=new ArrayList (); 763 764 protected void processConfigs(File baseDir) { 765 Iterator it=configs.iterator(); 766 while (it.hasNext()) { 767 XmlSourceEntry xse=(XmlSourceEntry) it.next(); 768 processConfig(xse.getFile()==null ? baseDir : xse.getFile(), xse.getDocumentElement()); 769 } 770 } 771 772 777 public XmlSourceEntry createConfig() { 778 XmlSourceEntry ret=new XmlSourceEntry(); 779 configs.add(ret); 780 ret.setProject(getProject()); 781 return ret; 782 } 783 784 788 public InspectorSourceEntry createInspectors() { 789 InspectorSourceEntry ret=new InspectorSourceEntry(); 790 inspectors.add(ret); 791 ret.setProject(getProject()); 792 return ret; 793 } 794 795 800 public void setArchive(File archive) { 801 this.archive=archive; 802 } 803 804 private File archive; 805 806 810 public void setDpmoThreshold(int dpmoThreshold) throws BuildException { 811 this.dpmoThreshold=new Integer (dpmoThreshold); 812 } 813 814 818 public void setSigmaThreshold(double sigmaThreshold) throws BuildException { 819 this.sigmaThreshold=new Double (sigmaThreshold); 820 } 821 822 protected Collection waivers = new LinkedList (); 823 private Integer dpmoThreshold; 824 private Double sigmaThreshold; 825 826 830 public void addConfiguredListener(ListenerEntry listener) { 831 listenerEntries.add(listener); 832 } 833 834 838 public void addConfiguredReviewAcceptor(ReviewAcceptorEntry reviewAcceptor) throws BuildException { 839 reviewAcceptorEntries.add(reviewAcceptor); 840 } 841 842 private List reviewAcceptorEntries = new LinkedList (); 843 844 848 public void setFailOnFirstException(boolean failOnFirstException) { 849 this.failOnFirstException=failOnFirstException; 850 } 851 852 protected boolean failOnFirstException = false; 853 854 858 public void setFailOnWarnings(boolean failOnWarnings) { 859 this.failOnWarnings=failOnWarnings; 860 } 861 862 private boolean failOnWarnings = true; 863 864 868 public void setSeverityThreshold(int severityThreshold) { 869 this.severityThreshold=new Integer (severityThreshold); 870 } 871 872 876 public void setTitle(String title) { 877 this.title=title; 878 } 879 880 protected String title = "Summary "+new Date (); 881 882 888 protected void configure(Options options, CommandLine line) { 889 String [] largs=line.getArgs(); 890 if (largs.length==0) { 891 System.out.println("Output dir has to be provided"); 892 printHelpAndExit(options); 893 } 894 895 if (!line.hasOption('o')) { 896 new File (largs[0]).mkdirs(); 897 Output output=createOutput(); 898 output.setDir(largs[0]); 899 900 if (line.hasOption('x')) { 901 output.setEmbeddedStyle(false); 902 output.setExtension(".xml"); 903 } 904 } 905 906 if (largs.length==1 && !line.hasOption('A')) { 907 System.out.println("At least one source directory or archive must be provided"); 908 printHelpAndExit(options); 909 } 910 911 if (line.hasOption('y')) { 912 setReviewDescription(line.getOptionValue('y')); 913 } 914 915 for (int i=1; i<largs.length; i++) { 916 File file = new File (largs[i]); 917 if (file.isFile()) { 918 srcFiles.add(file); 919 } else if (file.isDirectory()) { 920 createSrc().setDir(file); 921 } 922 } 923 924 String [] values=line.getOptionValues('c'); 925 for (int i=0; values!=null && i<values.length; i++) { 926 createClasspath().append(new Path(project, values[i])); 927 } 928 929 values=line.getOptionValues('m'); 930 for (int i=0; values!=null && i<values.length; i++) { 931 createConfig().setFile(new File (values[i])); 932 } 933 934 values=line.getOptionValues('q'); 935 for (int i=0; values!=null && i<values.length; i++) { 936 createConfig().setURL(values[i]); 937 } 938 939 values=line.getOptionValues('I'); 940 for (int i=0; values!=null && i<values.length; i++) { 941 InspectorEntry ie = createInspector(); 942 ie.setName(values[i]); 943 ie.setEnabled(true); 944 } 945 946 values=line.getOptionValues('X'); 947 for (int i=0; values!=null && i<values.length; i++) { 948 InspectorEntry ie = createInspector(); 949 ie.setName(values[i]); 950 ie.setEnabled(false); 951 } 952 953 setEvictBadInspectors(line.hasOption('E')); 954 955 setEmbeddedInspectors(!line.hasOption('e')); 956 957 if (line.hasOption('t')) { 958 setDebugType(line.getOptionValue('t')); 959 } 960 961 if (line.hasOption('r')) { 962 setUnpackDir(new File (line.getOptionValue('r'))); 963 } 964 965 if (line.hasOption('T')) { 966 setTitle(line.getOptionValue('T')); 967 } 968 969 BuildLogger logger = new DefaultLogger(); 970 logger.setMessageOutputLevel(Project.MSG_INFO); 971 logger.setOutputPrintStream(System.out); 972 logger.setErrorPrintStream(System.err); 973 logger.setEmacsMode(false); 974 975 if (line.hasOption('v')) { 976 logger.setMessageOutputLevel(Project.MSG_VERBOSE); 977 } 978 979 if (line.hasOption('g')) { 980 logger.setMessageOutputLevel(Project.MSG_DEBUG); 981 } 982 983 project.addBuildListener(logger); 984 985 System.setOut(new PrintStream (new DemuxOutputStream(project, false))); 986 System.setErr(new PrintStream (new DemuxOutputStream(project, true))); 987 988 if (line.hasOption('w')) { 989 setWaiverStubs(new File (line.getOptionValue('w'))); 990 } 991 992 if (line.hasOption('s')) { 993 setSigmaThreshold(Double.parseDouble(line.getOptionValue('s'))); 994 } 995 996 if (line.hasOption('d')) { 997 setDpmoThreshold(Integer.parseInt(line.getOptionValue('d'))); 998 } 999 1000 if (line.hasOption('S')) { 1001 setSeverityThreshold(Integer.parseInt(line.getOptionValue('S'))); 1002 } 1003 1004 if (line.hasOption('f')) { 1005 setForce(true); 1006 } 1007 1008 if (line.hasOption('k')) { 1009 setForceOnWarnings(false); 1010 } 1011 1012 if (line.hasOption('D')) { 1013 setDatabase(new File (line.getOptionValue('D'))); 1014 } 1015 1016 values=line.getOptionValues('i'); 1017 for (int i=0; values!=null && i<values.length; i++) { 1018 createInspectors().setFile(new File (values[i])); 1019 } 1020 1021 values=line.getOptionValues('u'); 1022 for (int i=0; values!=null && i<values.length; i++) { 1023 createInspectors().setURL(values[i]); 1024 } 1025 1026 values=line.getOptionValues('l'); 1027 for (int i=0; values!=null && i<values.length; i++) { 1028 ListenerEntry listenerEntry = new ListenerEntry(); 1029 listenerEntry.setClassName(values[i]); 1030 addConfiguredListener(listenerEntry); 1031 } 1032 1033 values=line.getOptionValues('W'); 1034 for (int i=0; values!=null && i<values.length; i++) { 1035 createWaivers().setFile(new File (values[i])); 1036 } 1037 1038 values=line.getOptionValues('U'); 1039 for (int i=0; values!=null && i<values.length; i++) { 1040 createWaivers().setURL(values[i]); 1041 } 1042 1043 if (line.hasOption('A')) { 1044 setArchive(new File (line.getOptionValue('A'))); 1045 } 1046 1047 if (line.hasOption('B')) { 1049 setBaselining(line.getOptionValue('B')); 1050 } 1051 } 1052 1053 1058 public void setWaiverStubs(File waiverStubs) { 1059 this.waiverStubs=waiverStubs; 1060 } 1061 1062 1067 public ObjectEntry createRevisionMapper() { 1068 if (revisionMapper==null) { 1069 revisionMapper = new ObjectEntry() { 1070 protected void validateClass(Class clazz) throws BuildException { 1071 super.validateClass(clazz); 1072 if (!RevisionMapper.class.isAssignableFrom(clazz)) { 1073 throw new BuildException(clazz.getName()+" doesn't implement "+RevisionMapper.class.getName()); 1074 } 1075 } 1076 }; 1077 return revisionMapper; 1078 } else { 1079 throw new BuildException("Revision mapper already defined"); 1080 } 1081 } 1082 1083 private File waiverStubs; 1084 private Integer severityThreshold; 1085 protected List listenerEntries = new LinkedList (); 1086 ObjectEntry revisionMapper; 1087 protected boolean force = false; 1088 protected boolean evictBadInspectors = false; 1089 1090 1096 public void setEvictBadInspectors(boolean evictBadInspectors) { 1097 this.evictBadInspectors=evictBadInspectors; 1098 } 1099 1100 1105 public void setForce(boolean force) { 1106 this.force=force; 1107 } 1108 1109 1123 public void setBaselining(String baselineMode) { 1124 if ("off".equals(baselineMode)) { 1125 } else if ("on".equals(baselineMode)) { 1127 violationFilters.add(new BaselineViolationFilter()); 1128 } else if ("set".equalsIgnoreCase(baselineMode)) { 1129 violationFilters.add(new BaselineSetupViolationFilter()); 1130 } else { 1131 throw new BuildException("Invalid baselining mode: "+baselineMode); 1132 } 1133 1134 } 1135 1136 1137 protected boolean forceOnWarnings = true; 1138 1139 1145 public void setForceOnWarnings(boolean forceOnWarnings) { 1146 this.forceOnWarnings=forceOnWarnings; 1147 } 1148 1149 protected File database; 1150 protected String reviewDescription; 1151 1152 1157 public void setReviewDescription(String reviewDescription) { 1158 this.reviewDescription=reviewDescription; 1159 } 1160 1161 1168 public void setDatabase(File database) { 1169 this.database=database; 1170 } 1171 1172 protected boolean isForceOnWarnings() { 1173 return forceOnWarnings; 1174 } 1175 1176 protected boolean isForce() { 1177 return force; 1178 } 1179 1180 protected int tabSize=8; 1181 1182 1187 public void setTabSize(int tabSize) { 1188 this.tabSize = tabSize; 1189 } 1190 1191 protected Collection violationFilters = new ArrayList (); 1192 1193 private String encoding; 1194 1195 1200 public void setEncoding(String encoding) { 1201 this.encoding = encoding; 1202 } 1203 1204 protected String getEncoding() { 1205 return encoding; 1206 } 1207} 1208 | Popular Tags |