| 1 18 package org.apache.tools.ant.taskdefs; 19 20 import java.io.File ; 21 import java.io.FileWriter ; 22 import java.io.FilenameFilter ; 23 import java.io.IOException ; 24 import java.io.PrintWriter ; 25 import java.io.BufferedReader ; 26 import java.io.FileReader ; 27 import java.net.MalformedURLException ; 28 import java.net.URL ; 29 import java.util.ArrayList ; 30 import java.util.Enumeration ; 31 import java.util.Iterator ; 32 import java.util.Locale ; 33 import java.util.StringTokenizer ; 34 import java.util.Vector ; 35 import org.apache.tools.ant.BuildException; 36 import org.apache.tools.ant.DirectoryScanner; 37 import org.apache.tools.ant.MagicNames; 38 import org.apache.tools.ant.Project; 39 import org.apache.tools.ant.ProjectComponent; 40 import org.apache.tools.ant.Task; 41 import org.apache.tools.ant.types.Commandline; 42 import org.apache.tools.ant.types.DirSet; 43 import org.apache.tools.ant.types.EnumeratedAttribute; 44 import org.apache.tools.ant.types.FileSet; 45 import org.apache.tools.ant.types.Path; 46 import org.apache.tools.ant.types.PatternSet; 47 import org.apache.tools.ant.types.Reference; 48 import org.apache.tools.ant.types.ResourceCollection; 49 import org.apache.tools.ant.types.resources.FileResource; 50 import org.apache.tools.ant.util.FileUtils; 51 import org.apache.tools.ant.util.JavaEnvUtils; 52 53 76 public class Javadoc extends Task { 77 80 public class DocletParam { 81 82 private String name; 83 84 85 private String value; 86 87 92 public void setName(String name) { 93 this.name = name; 94 } 95 96 101 public String getName() { 102 return name; 103 } 104 105 113 public void setValue(String value) { 114 this.value = value; 115 } 116 117 122 public String getValue() { 123 return value; 124 } 125 } 126 127 132 public static class ExtensionInfo extends ProjectComponent { 133 134 private String name; 135 136 137 private Path path; 138 139 144 public void setName(String name) { 145 this.name = name; 146 } 147 148 153 public String getName() { 154 return name; 155 } 156 157 162 public void setPath(Path path) { 163 if (this.path == null) { 164 this.path = path; 165 } else { 166 this.path.append(path); 167 } 168 } 169 170 176 public Path getPath() { 177 return path; 178 } 179 180 186 public Path createPath() { 187 if (path == null) { 188 path = new Path(getProject()); 189 } 190 return path.createPath(); 191 } 192 193 198 public void setPathRef(Reference r) { 199 createPath().setRefid(r); 200 } 201 } 202 203 207 public class DocletInfo extends ExtensionInfo { 208 209 210 private Vector params = new Vector (); 211 212 217 public DocletParam createParam() { 218 DocletParam param = new DocletParam(); 219 params.addElement(param); 220 221 return param; 222 } 223 224 229 public Enumeration getParams() { 230 return params.elements(); 231 } 232 } 233 234 237 public static class PackageName { 238 239 private String name; 240 241 246 public void setName(String name) { 247 this.name = name.trim(); 248 } 249 250 255 public String getName() { 256 return name; 257 } 258 259 263 public String toString() { 264 return getName(); 265 } 266 } 267 268 271 public static class SourceFile { 272 273 private File file; 274 275 278 public SourceFile() { 279 } 281 282 287 public SourceFile(File file) { 288 this.file = file; 289 } 290 291 296 public void setFile(File file) { 297 this.file = file; 298 } 299 300 305 public File getFile() { 306 return file; 307 } 308 } 309 310 316 public static class Html { 317 318 private StringBuffer text = new StringBuffer (); 319 320 325 public void addText(String t) { 326 text.append(t); 327 } 328 329 334 public String getText() { 335 return text.substring(0); 336 } 337 } 338 339 343 public static class AccessType extends EnumeratedAttribute { 344 347 public String [] getValues() { 348 return new String [] {"protected", "public", "package", "private"}; 351 } 352 } 353 354 361 public class ResourceCollectionContainer { 362 private ArrayList rcs = new ArrayList (); 363 367 public void add(ResourceCollection rc) { 368 rcs.add(rc); 369 } 370 371 375 private Iterator iterator() { 376 return rcs.iterator(); 377 } 378 } 379 380 private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); 381 382 383 private Commandline cmd = new Commandline(); 384 385 392 private void addArgIf(boolean b, String arg) { 393 if (b) { 394 cmd.createArgument().setValue(arg); 395 } 396 } 397 398 404 private void addArgIfNotEmpty(String key, String value) { 405 if (value != null && value.length() != 0) { 406 cmd.createArgument().setValue(key); 407 cmd.createArgument().setValue(value); 408 } else { 409 log("Warning: Leaving out empty argument '" + key + "'", 410 Project.MSG_WARN); 411 } 412 } 413 414 418 private boolean failOnError = false; 419 private Path sourcePath = null; 420 private File destDir = null; 421 private Vector sourceFiles = new Vector (); 422 private Vector packageNames = new Vector (); 423 private Vector excludePackageNames = new Vector (1); 424 private boolean author = true; 425 private boolean version = true; 426 private DocletInfo doclet = null; 427 private Path classpath = null; 428 private Path bootclasspath = null; 429 private String group = null; 430 private String packageList = null; 431 private Vector links = new Vector (); 432 private Vector groups = new Vector (); 433 private Vector tags = new Vector (); 434 private boolean useDefaultExcludes = true; 435 private Html doctitle = null; 436 private Html header = null; 437 private Html footer = null; 438 private Html bottom = null; 439 private boolean useExternalFile = false; 440 private String source = null; 441 private boolean linksource = false; 442 private boolean breakiterator = false; 443 private String noqualifier; 444 private boolean includeNoSourcePackages = false; 445 private boolean old = false; 446 private String executable = null; 447 448 private ResourceCollectionContainer nestedSourceFiles 449 = new ResourceCollectionContainer(); 450 private Vector packageSets = new Vector (); 451 452 458 public void setUseExternalFile(boolean b) { 459 useExternalFile = b; 460 } 461 462 469 public void setDefaultexcludes(boolean useDefaultExcludes) { 470 this.useDefaultExcludes = useDefaultExcludes; 471 } 472 473 479 public void setMaxmemory(String max) { 480 cmd.createArgument().setValue("-J-Xmx" + max); 481 } 482 483 488 public void setAdditionalparam(String add) { 489 cmd.createArgument().setLine(add); 490 } 491 492 497 public Commandline.Argument createArg() { 498 return cmd.createArgument(); 499 } 500 501 506 public void setSourcepath(Path src) { 507 if (sourcePath == null) { 508 sourcePath = src; 509 } else { 510 sourcePath.append(src); 511 } 512 } 513 514 520 public Path createSourcepath() { 521 if (sourcePath == null) { 522 sourcePath = new Path(getProject()); 523 } 524 return sourcePath.createPath(); 525 } 526 527 532 public void setSourcepathRef(Reference r) { 533 createSourcepath().setRefid(r); 534 } 535 536 541 public void setDestdir(File dir) { 542 destDir = dir; 543 cmd.createArgument().setValue("-d"); 544 cmd.createArgument().setFile(destDir); 545 } 546 547 552 public void setSourcefiles(String src) { 553 StringTokenizer tok = new StringTokenizer (src, ","); 554 while (tok.hasMoreTokens()) { 555 String f = tok.nextToken(); 556 SourceFile sf = new SourceFile(); 557 sf.setFile(getProject().resolveFile(f.trim())); 558 addSource(sf); 559 } 560 } 561 562 567 public void addSource(SourceFile sf) { 568 sourceFiles.addElement(sf); 569 } 570 571 579 public void setPackagenames(String packages) { 580 StringTokenizer tok = new StringTokenizer (packages, ","); 581 while (tok.hasMoreTokens()) { 582 String p = tok.nextToken(); 583 PackageName pn = new PackageName(); 584 pn.setName(p); 585 addPackage(pn); 586 } 587 } 588 589 597 public void addPackage(PackageName pn) { 598 packageNames.addElement(pn); 599 } 600 601 607 public void setExcludePackageNames(String packages) { 608 StringTokenizer tok = new StringTokenizer (packages, ","); 609 while (tok.hasMoreTokens()) { 610 String p = tok.nextToken(); 611 PackageName pn = new PackageName(); 612 pn.setName(p); 613 addExcludePackage(pn); 614 } 615 } 616 617 622 public void addExcludePackage(PackageName pn) { 623 excludePackageNames.addElement(pn); 624 } 625 626 632 public void setOverview(File f) { 633 cmd.createArgument().setValue("-overview"); 634 cmd.createArgument().setFile(f); 635 } 636 637 643 public void setPublic(boolean b) { 644 addArgIf(b, "-public"); 645 } 646 647 653 public void setProtected(boolean b) { 654 addArgIf(b, "-protected"); 655 } 656 657 663 public void setPackage(boolean b) { 664 addArgIf(b, "-package"); 665 } 666 667 673 public void setPrivate(boolean b) { 674 addArgIf(b, "-private"); 675 } 676 677 684 public void setAccess(AccessType at) { 685 cmd.createArgument().setValue("-" + at.getValue()); 686 } 687 688 694 public void setDoclet(String docletName) { 695 if (doclet == null) { 696 doclet = new DocletInfo(); 697 doclet.setProject(getProject()); 698 } 699 doclet.setName(docletName); 700 } 701 702 707 public void setDocletPath(Path docletPath) { 708 if (doclet == null) { 709 doclet = new DocletInfo(); 710 doclet.setProject(getProject()); 711 } 712 doclet.setPath(docletPath); 713 } 714 715 721 public void setDocletPathRef(Reference r) { 722 if (doclet == null) { 723 doclet = new DocletInfo(); 724 doclet.setProject(getProject()); 725 } 726 doclet.createPath().setRefid(r); 727 } 728 729 734 public DocletInfo createDoclet() { 735 if (doclet == null) { 736 doclet = new DocletInfo(); 737 } 738 return doclet; 739 } 740 741 746 public void addTaglet(ExtensionInfo tagletInfo) { 747 tags.addElement(tagletInfo); 748 } 749 750 758 public void setOld(boolean b) { 759 old = b; 760 } 761 762 768 public void setClasspath(Path path) { 769 if (classpath == null) { 770 classpath = path; 771 } else { 772 classpath.append(path); 773 } 774 } 775 776 781 public Path createClasspath() { 782 if (classpath == null) { 783 classpath = new Path(getProject()); 784 } 785 return classpath.createPath(); 786 } 787 788 793 public void setClasspathRef(Reference r) { 794 createClasspath().setRefid(r); 795 } 796 797 802 public void setBootclasspath(Path path) { 803 if (bootclasspath == null) { 804 bootclasspath = path; 805 } else { 806 bootclasspath.append(path); 807 } 808 } 809 810 815 public Path createBootclasspath() { 816 if (bootclasspath == null) { 817 bootclasspath = new Path(getProject()); 818 } 819 return bootclasspath.createPath(); 820 } 821 822 827 public void setBootClasspathRef(Reference r) { 828 createBootclasspath().setRefid(r); 829 } 830 831 838 public void setExtdirs(String path) { 839 cmd.createArgument().setValue("-extdirs"); 840 cmd.createArgument().setValue(path); 841 } 842 843 848 public void setExtdirs(Path path) { 849 cmd.createArgument().setValue("-extdirs"); 850 cmd.createArgument().setPath(path); 851 } 852 853 858 public void setVerbose(boolean b) { 859 addArgIf(b, "-verbose"); 860 } 861 862 867 public void setLocale(String locale) { 868 cmd.createArgument(true).setValue(locale); 871 cmd.createArgument(true).setValue("-locale"); 872 } 873 874 879 public void setEncoding(String enc) { 880 cmd.createArgument().setValue("-encoding"); 881 cmd.createArgument().setValue(enc); 882 } 883 884 889 public void setVersion(boolean b) { 890 this.version = b; 891 } 892 893 898 public void setUse(boolean b) { 899 addArgIf(b, "-use"); 900 } 901 902 903 908 public void setAuthor(boolean b) { 909 author = b; 910 } 911 912 917 public void setSplitindex(boolean b) { 918 addArgIf(b, "-splitindex"); 919 } 920 921 927 public void setWindowtitle(String title) { 928 addArgIfNotEmpty("-windowtitle", title); 929 } 930 931 936 public void setDoctitle(String doctitle) { 937 Html h = new Html(); 938 h.addText(doctitle); 939 addDoctitle(h); 940 } 941 942 947 public void addDoctitle(Html text) { 948 doctitle = text; 949 } 950 951 956 pu
|