You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Javadoc.java 69 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119
  1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. * Copyright (c) 2000-2003 The Apache Software Foundation. All rights
  5. * reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if
  20. * any, must include the following acknowlegement:
  21. * "This product includes software developed by the
  22. * Apache Software Foundation (http://www.apache.org/)."
  23. * Alternately, this acknowlegement may appear in the software itself,
  24. * if and wherever such third-party acknowlegements normally appear.
  25. *
  26. * 4. The names "Ant" and "Apache Software
  27. * Foundation" must not be used to endorse or promote products derived
  28. * from this software without prior written permission. For written
  29. * permission, please contact apache@apache.org.
  30. *
  31. * 5. Products derived from this software may not be called "Apache"
  32. * nor may "Apache" appear in their names without prior written
  33. * permission of the Apache Group.
  34. *
  35. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46. * SUCH DAMAGE.
  47. * ====================================================================
  48. *
  49. * This software consists of voluntary contributions made by many
  50. * individuals on behalf of the Apache Software Foundation. For more
  51. * information on the Apache Software Foundation, please see
  52. * <http://www.apache.org/>.
  53. */
  54. package org.apache.tools.ant.taskdefs;
  55. import java.io.File;
  56. import java.io.FileWriter;
  57. import java.io.FilenameFilter;
  58. import java.io.IOException;
  59. import java.io.PrintWriter;
  60. import java.io.BufferedReader;
  61. import java.io.FileReader;
  62. import java.net.MalformedURLException;
  63. import java.net.URL;
  64. import java.util.Enumeration;
  65. import java.util.Locale;
  66. import java.util.StringTokenizer;
  67. import java.util.Vector;
  68. import org.apache.tools.ant.BuildException;
  69. import org.apache.tools.ant.DirectoryScanner;
  70. import org.apache.tools.ant.Project;
  71. import org.apache.tools.ant.ProjectComponent;
  72. import org.apache.tools.ant.Task;
  73. import org.apache.tools.ant.types.Commandline;
  74. import org.apache.tools.ant.types.DirSet;
  75. import org.apache.tools.ant.types.EnumeratedAttribute;
  76. import org.apache.tools.ant.types.FileSet;
  77. import org.apache.tools.ant.types.Path;
  78. import org.apache.tools.ant.types.PatternSet;
  79. import org.apache.tools.ant.types.Reference;
  80. import org.apache.tools.ant.util.FileUtils;
  81. import org.apache.tools.ant.util.JavaEnvUtils;
  82. /**
  83. * Generates Javadoc documentation for a collection
  84. * of source code.
  85. *
  86. * <P>Current known limitations are:
  87. *
  88. * <P><UL>
  89. * <LI>patterns must be of the form "xxx.*", every other pattern doesn't
  90. * work.
  91. * <LI>there is no control on arguments sanity since they are left
  92. * to the javadoc implementation.
  93. * <LI>argument J in javadoc1 is not supported (what is that for anyway?)
  94. * </UL>
  95. *
  96. * <P>If no <CODE>doclet</CODE> is set, then the <CODE>version</CODE> and
  97. * <CODE>author</CODE> are by default <CODE>"yes"</CODE>.
  98. *
  99. * <P>Note: This task is run on another VM because the Javadoc code calls
  100. * <CODE>System.exit()</CODE> which would break Ant functionality.
  101. *
  102. * @author Jon S. Stevens <a href="mailto:jon@clearink.com">jon@clearink.com</a>
  103. * @author Stefano Mazzocchi
  104. * <a href="mailto:stefano@apache.org">stefano@apache.org</a>
  105. * @author Patrick Chanezon
  106. * <a href="mailto:chanezon@netscape.com">chanezon@netscape.com</a>
  107. * @author Ernst de Haan <a href="mailto:ernst@jollem.com">ernst@jollem.com</a>
  108. * @author Stefan Bodewig
  109. *
  110. * @since Ant 1.1
  111. *
  112. * @ant.task category="java"
  113. */
  114. public class Javadoc extends Task {
  115. /**
  116. * Inner class used to manage doclet parameters.
  117. */
  118. public class DocletParam {
  119. /** The parameter name */
  120. private String name;
  121. /** The parameter value */
  122. private String value;
  123. /**
  124. * Set the name of the parameter.
  125. *
  126. * @param name the name of the doclet parameter
  127. */
  128. public void setName(String name) {
  129. this.name = name;
  130. }
  131. /**
  132. * Get the parameter name.
  133. *
  134. * @return the parameter's name.
  135. */
  136. public String getName() {
  137. return name;
  138. }
  139. /**
  140. * Set the parameter value.
  141. *
  142. * Note that only string values are supported. No resolution of file
  143. * paths is performed.
  144. *
  145. * @param value the parameter value.
  146. */
  147. public void setValue(String value) {
  148. this.value = value;
  149. }
  150. /**
  151. * Get the parameter value.
  152. *
  153. * @return the parameter value.
  154. */
  155. public String getValue() {
  156. return value;
  157. }
  158. }
  159. /**
  160. * A project aware class used for Javadoc extensions which take a name
  161. * and a path such as doclet and taglet arguments.
  162. *
  163. * @author Conor MacNeill
  164. */
  165. public static class ExtensionInfo extends ProjectComponent {
  166. /** The name of the extension */
  167. private String name;
  168. /** The optional path to use to load the extension */
  169. private Path path;
  170. /**
  171. * Set the name of the extension
  172. *
  173. * @param name the extension's name.
  174. */
  175. public void setName(String name) {
  176. this.name = name;
  177. }
  178. /**
  179. * Get the name of the extension.
  180. *
  181. * @return the extension's name.
  182. */
  183. public String getName() {
  184. return name;
  185. }
  186. /**
  187. * Set the path to use when loading the component.
  188. *
  189. * @param path a Path instance containing the classpath to use.
  190. */
  191. public void setPath(Path path) {
  192. if (this.path == null) {
  193. this.path = path;
  194. } else {
  195. this.path.append(path);
  196. }
  197. }
  198. /**
  199. * Get the extension's path.
  200. *
  201. * @return the path to be used to load the extension.
  202. * May be <code>null</code>
  203. */
  204. public Path getPath() {
  205. return path;
  206. }
  207. /**
  208. * Create an empty nested path to be configured by Ant with the
  209. * classpath for the extension.
  210. *
  211. * @return a new Path instance to be configured.
  212. */
  213. public Path createPath() {
  214. if (path == null) {
  215. path = new Path(getProject());
  216. }
  217. return path.createPath();
  218. }
  219. /**
  220. * Adds a reference to a CLASSPATH defined elsewhere.
  221. *
  222. * @param r the reference containing the path.
  223. */
  224. public void setPathRef(Reference r) {
  225. createPath().setRefid(r);
  226. }
  227. }
  228. /**
  229. * This class stores info about doclets.
  230. *
  231. * @author Conor MacNeill
  232. */
  233. public class DocletInfo extends ExtensionInfo {
  234. /** Collection of doclet parameters. */
  235. private Vector params = new Vector();
  236. /**
  237. * Create a doclet parameter to be configured by Ant.
  238. *
  239. * @return a new DocletParam instance to be configured.
  240. */
  241. public DocletParam createParam() {
  242. DocletParam param = new DocletParam();
  243. params.addElement(param);
  244. return param;
  245. }
  246. /**
  247. * Get the doclet's parameters.
  248. *
  249. * @return an Enumeration of DocletParam instances.
  250. */
  251. public Enumeration getParams() {
  252. return params.elements();
  253. }
  254. }
  255. /**
  256. * Used to track info about the packages to be javadoc'd
  257. */
  258. public static class PackageName {
  259. /** The package name */
  260. private String name;
  261. /**
  262. * Set the name of the package
  263. *
  264. * @param name the package name.
  265. */
  266. public void setName(String name) {
  267. this.name = name.trim();
  268. }
  269. /**
  270. * Get the package name.
  271. *
  272. * @return the package's name.
  273. */
  274. public String getName() {
  275. return name;
  276. }
  277. /**
  278. * @see java.lang.Object#toString
  279. */
  280. public String toString() {
  281. return getName();
  282. }
  283. }
  284. /**
  285. * This class is used to manage the source files to be processed.
  286. */
  287. public static class SourceFile {
  288. /** The source file */
  289. private File file;
  290. public SourceFile() {}
  291. public SourceFile(File file) {
  292. this.file = file;
  293. }
  294. /**
  295. * Set the source file.
  296. *
  297. * @param file the source file.
  298. */
  299. public void setFile(File file) {
  300. this.file = file;
  301. }
  302. /**
  303. * Get the source file.
  304. *
  305. * @return the source file.
  306. */
  307. public File getFile() {
  308. return file;
  309. }
  310. }
  311. /**
  312. * An HTML element in the javadoc.
  313. *
  314. * This class is used for those javadoc elements which contain HTML such as
  315. * footers, headers, etc.
  316. */
  317. public static class Html {
  318. /** The text for the element */
  319. private StringBuffer text = new StringBuffer();
  320. /**
  321. * Add text to the element.
  322. *
  323. * @param t the text to be added.
  324. */
  325. public void addText(String t) {
  326. text.append(t);
  327. }
  328. /**
  329. * Get the current text for the element.
  330. *
  331. * @return the current text.
  332. */
  333. public String getText() {
  334. return text.substring(0);
  335. }
  336. }
  337. /**
  338. * EnumeratedAttribute implementation supporting the javadoc scoping
  339. * values.
  340. */
  341. public static class AccessType extends EnumeratedAttribute {
  342. /**
  343. * @see EnumeratedAttribute#getValues().
  344. */
  345. public String[] getValues() {
  346. // Protected first so if any GUI tool offers a default
  347. // based on enum #0, it will be right.
  348. return new String[] {"protected", "public", "package", "private"};
  349. }
  350. }
  351. /** The command line built to execute Javadoc. */
  352. private Commandline cmd = new Commandline();
  353. /** Flag which indicates if javadoc from JDK 1.1 is to be used. */
  354. private static boolean javadoc1 =
  355. JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1);
  356. /** Flag which indicates if javadoc from JDK 1.4 is available */
  357. private static boolean javadoc4 =
  358. (!JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1) &&
  359. !JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2) &&
  360. !JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_3));
  361. /**
  362. * Utility method to add an argument to the command line conditionally
  363. * based on the given flag.
  364. *
  365. * @param b the flag which controls if the argument is added.
  366. * @param arg the argument value.
  367. */
  368. private void addArgIf(boolean b, String arg) {
  369. if (b) {
  370. cmd.createArgument().setValue(arg);
  371. }
  372. }
  373. /**
  374. * Utility method to add a non JDK1.1 javadoc argument.
  375. *
  376. * @param key the argument name.
  377. * @param value the argument value.
  378. */
  379. private void add12ArgIfNotEmpty(String key, String value) {
  380. if (!javadoc1) {
  381. if (value != null && value.length() != 0) {
  382. cmd.createArgument().setValue(key);
  383. cmd.createArgument().setValue(value);
  384. } else {
  385. log("Warning: Leaving out empty argument '" + key + "'",
  386. Project.MSG_WARN);
  387. }
  388. }
  389. }
  390. /**
  391. * Utility method to add a non-JDK1.1 argument to the command line
  392. * conditionally based on the given flag.
  393. *
  394. * @param b the flag which controls if the argument is added.
  395. * @param arg the argument value.
  396. */
  397. private void add12ArgIf(boolean b, String arg) {
  398. if (!javadoc1 && b) {
  399. cmd.createArgument().setValue(arg);
  400. }
  401. }
  402. /**
  403. * Flag which indicates if the task should fail if there is a
  404. * javadoc error.
  405. */
  406. private boolean failOnError = false;
  407. private Path sourcePath = null;
  408. private File destDir = null;
  409. private Vector sourceFiles = new Vector();
  410. private Vector packageNames = new Vector(5);
  411. private Vector excludePackageNames = new Vector(1);
  412. private boolean author = true;
  413. private boolean version = true;
  414. private DocletInfo doclet = null;
  415. private Path classpath = null;
  416. private Path bootclasspath = null;
  417. private String group = null;
  418. private String packageList = null;
  419. private Vector links = new Vector(2);
  420. private Vector groups = new Vector(2);
  421. private Vector tags = new Vector(5);
  422. private boolean useDefaultExcludes = true;
  423. private Html doctitle = null;
  424. private Html header = null;
  425. private Html footer = null;
  426. private Html bottom = null;
  427. private boolean useExternalFile = false;
  428. private FileUtils fileUtils = FileUtils.newFileUtils();
  429. private String source = null;
  430. private boolean linksource = false;
  431. private boolean breakiterator = false;
  432. private String noqualifier;
  433. private Vector fileSets = new Vector();
  434. private Vector packageSets = new Vector();
  435. /**
  436. * Work around command line length limit by using an external file
  437. * for the sourcefiles.
  438. *
  439. * @param b true if an external file is to be used.
  440. */
  441. public void setUseExternalFile(boolean b) {
  442. if (!javadoc1) {
  443. useExternalFile = b;
  444. }
  445. }
  446. /**
  447. * Sets whether default exclusions should be used or not.
  448. *
  449. * @param useDefaultExcludes "true"|"on"|"yes" when default exclusions
  450. * should be used, "false"|"off"|"no" when they
  451. * shouldn't be used.
  452. */
  453. public void setDefaultexcludes(boolean useDefaultExcludes) {
  454. this.useDefaultExcludes = useDefaultExcludes;
  455. }
  456. /**
  457. * Set the maximum memory to be used by the javadoc process
  458. *
  459. * @param max a string indicating the maximum memory according to the
  460. * JVM conventions (e.g. 128m is 128 Megabytes)
  461. */
  462. public void setMaxmemory(String max){
  463. if (javadoc1) {
  464. cmd.createArgument().setValue("-J-mx" + max);
  465. } else {
  466. cmd.createArgument().setValue("-J-Xmx" + max);
  467. }
  468. }
  469. /**
  470. * Set an additional parameter on the command line
  471. *
  472. * @param add the additional command line parameter for the javadoc task.
  473. */
  474. public void setAdditionalparam(String add){
  475. cmd.createArgument().setLine(add);
  476. }
  477. /**
  478. * Adds a command-line argument.
  479. * @since Ant 1.6
  480. */
  481. public Commandline.Argument createArg() {
  482. return cmd.createArgument();
  483. }
  484. /**
  485. * Specify where to find source file
  486. *
  487. * @param src a Path instance containing the various source directories.
  488. */
  489. public void setSourcepath(Path src) {
  490. if (sourcePath == null) {
  491. sourcePath = src;
  492. } else {
  493. sourcePath.append(src);
  494. }
  495. }
  496. /**
  497. * Create a path to be configured with the locations of the source
  498. * files.
  499. *
  500. * @return a new Path instance to be configured by the Ant core.
  501. */
  502. public Path createSourcepath() {
  503. if (sourcePath == null) {
  504. sourcePath = new Path(getProject());
  505. }
  506. return sourcePath.createPath();
  507. }
  508. /**
  509. * Adds a reference to a CLASSPATH defined elsewhere.
  510. *
  511. * @param r the reference containing the source path definition.
  512. */
  513. public void setSourcepathRef(Reference r) {
  514. createSourcepath().setRefid(r);
  515. }
  516. /**
  517. * Set the directory where the Javadoc output will be generated.
  518. *
  519. * @param dir the destination directory.
  520. */
  521. public void setDestdir(File dir) {
  522. destDir = dir;
  523. cmd.createArgument().setValue("-d");
  524. cmd.createArgument().setFile(destDir);
  525. }
  526. /**
  527. * Set the list of source files to process.
  528. *
  529. * @param src a comma separated list of source files.
  530. */
  531. public void setSourcefiles(String src) {
  532. StringTokenizer tok = new StringTokenizer(src, ",");
  533. while (tok.hasMoreTokens()) {
  534. String f = tok.nextToken();
  535. SourceFile sf = new SourceFile();
  536. sf.setFile(getProject().resolveFile(f.trim()));
  537. addSource(sf);
  538. }
  539. }
  540. /**
  541. * Add a single source file.
  542. *
  543. * @param sf the source file to be processed.
  544. */
  545. public void addSource(SourceFile sf) {
  546. sourceFiles.addElement(sf);
  547. }
  548. /**
  549. * Set the package names to be processed.
  550. *
  551. * @param packages a comma separated list of packages specs
  552. * (may be wildcarded).
  553. *
  554. * @see #addPackage for wildcard information.
  555. */
  556. public void setPackagenames(String packages) {
  557. StringTokenizer tok = new StringTokenizer(packages, ",");
  558. while (tok.hasMoreTokens()) {
  559. String p = tok.nextToken();
  560. PackageName pn = new PackageName();
  561. pn.setName(p);
  562. addPackage(pn);
  563. }
  564. }
  565. /**
  566. * Add a single package to be processed.
  567. *
  568. * If the package name ends with &quot;.*&quot; the Javadoc task
  569. * will find and process all subpackages.
  570. *
  571. * @param pn the package name, possibly wildcarded.
  572. */
  573. public void addPackage(PackageName pn) {
  574. packageNames.addElement(pn);
  575. }
  576. /**
  577. * Set the list of packages to be excluded.
  578. *
  579. * @param packages a comma separated list of packages to be excluded.
  580. * This may not include wildcards.
  581. */
  582. public void setExcludePackageNames(String packages) {
  583. StringTokenizer tok = new StringTokenizer(packages, ",");
  584. while (tok.hasMoreTokens()) {
  585. String p = tok.nextToken();
  586. PackageName pn = new PackageName();
  587. pn.setName(p);
  588. addExcludePackage(pn);
  589. }
  590. }
  591. /**
  592. * Add a package to be excluded from the javadoc run.
  593. *
  594. * @param pn the name of the package (wildcards are not permitted).
  595. */
  596. public void addExcludePackage(PackageName pn) {
  597. excludePackageNames.addElement(pn);
  598. }
  599. /**
  600. * Specify the file containing the overview to be included in the generated
  601. * documentation.
  602. *
  603. * @param f the file containing the overview.
  604. */
  605. public void setOverview(File f) {
  606. if (!javadoc1) {
  607. cmd.createArgument().setValue("-overview");
  608. cmd.createArgument().setFile(f);
  609. }
  610. }
  611. /**
  612. * Indicate whether only public classes and members are to be included in
  613. * the scope processed
  614. *
  615. * @param b true if scope is to be public.
  616. */
  617. public void setPublic(boolean b) {
  618. addArgIf(b, "-public");
  619. }
  620. /**
  621. * Indicate whether only protected and public classes and members are to
  622. * be included in the scope processed
  623. *
  624. * @param b true if scope is to be protected.
  625. */
  626. public void setProtected(boolean b) {
  627. addArgIf(b, "-protected");
  628. }
  629. /**
  630. * Indicate whether only package, protected and public classes and
  631. * members are to be included in the scope processed
  632. *
  633. * @param b true if scope is to be package level.
  634. */
  635. public void setPackage(boolean b) {
  636. addArgIf(b, "-package");
  637. }
  638. /**
  639. * Indicate whether all classes and
  640. * members are to be included in the scope processed
  641. *
  642. * @param b true if scope is to be private level.
  643. */
  644. public void setPrivate(boolean b) {
  645. addArgIf(b, "-private");
  646. }
  647. /**
  648. * Set the scope to be processed. This is an alternative to the
  649. * use of the setPublic, setPrivate, etc methods. It gives better build
  650. * file control over what scope is processed.
  651. *
  652. * @param at the scope to be processed.
  653. */
  654. public void setAccess(AccessType at) {
  655. cmd.createArgument().setValue("-" + at.getValue());
  656. }
  657. /**
  658. * Set the class that starts the doclet used in generating the
  659. * documentation.
  660. *
  661. * @param docletName the name of the doclet class.
  662. */
  663. public void setDoclet(String docletName) {
  664. if (doclet == null) {
  665. doclet = new DocletInfo();
  666. doclet.setProject(getProject());
  667. }
  668. doclet.setName(docletName);
  669. }
  670. /**
  671. * Set the classpath used to find the doclet class.
  672. *
  673. * @param docletPath the doclet classpath.
  674. */
  675. public void setDocletPath(Path docletPath) {
  676. if (doclet == null) {
  677. doclet = new DocletInfo();
  678. doclet.setProject(getProject());
  679. }
  680. doclet.setPath(docletPath);
  681. }
  682. /**
  683. * Set the classpath used to find the doclet class by reference.
  684. *
  685. * @param r the reference to the Path instance to use as the doclet
  686. * classpath.
  687. */
  688. public void setDocletPathRef(Reference r) {
  689. if (doclet == null) {
  690. doclet = new DocletInfo();
  691. doclet.setProject(getProject());
  692. }
  693. doclet.createPath().setRefid(r);
  694. }
  695. /**
  696. * Create a doclet to be used in the documentation generation.
  697. *
  698. * @return a new DocletInfo instance to be configured.
  699. */
  700. public DocletInfo createDoclet() {
  701. doclet = new DocletInfo();
  702. return doclet;
  703. }
  704. /**
  705. * Add a taglet
  706. *
  707. * @param tagletInfo information about the taglet.
  708. */
  709. public void addTaglet(ExtensionInfo tagletInfo) {
  710. tags.addElement(tagletInfo);
  711. }
  712. /**
  713. * Indicate whether Javadoc should produce old style (JDK 1.1)
  714. * documentation.
  715. *
  716. * This is not supported by JDK 1.1 and has been phased out in JDK 1.4
  717. *
  718. * @param b if true attempt to generate old style documentation.
  719. */
  720. public void setOld(boolean b) {
  721. if (b) {
  722. if (javadoc1) {
  723. log("Javadoc 1.1 doesn't support the -1.1 switch",
  724. Project.MSG_WARN);
  725. } else if (javadoc4) {
  726. log("Javadoc 1.4 doesn't support the -1.1 switch anymore",
  727. Project.MSG_WARN);
  728. } else {
  729. cmd.createArgument().setValue("-1.1");
  730. }
  731. }
  732. }
  733. /**
  734. * Set the classpath to be used for this javadoc run.
  735. *
  736. * @param path an Ant Path object containing the compilation
  737. * classpath.
  738. */
  739. public void setClasspath(Path path) {
  740. if (classpath == null) {
  741. classpath = path;
  742. } else {
  743. classpath.append(path);
  744. }
  745. }
  746. /**
  747. * Create a Path to be configured with the classpath to use
  748. *
  749. * @return a new Path instance to be configured with the classpath.
  750. */
  751. public Path createClasspath() {
  752. if (classpath == null) {
  753. classpath = new Path(getProject());
  754. }
  755. return classpath.createPath();
  756. }
  757. /**
  758. * Adds a reference to a CLASSPATH defined elsewhere.
  759. *
  760. * @param r the reference to an instance defining the classpath.
  761. */
  762. public void setClasspathRef(Reference r) {
  763. createClasspath().setRefid(r);
  764. }
  765. /**
  766. * Set the boot classpath to use.
  767. *
  768. * @param path the boot classpath.
  769. */
  770. public void setBootclasspath(Path path) {
  771. if (bootclasspath == null) {
  772. bootclasspath = path;
  773. } else {
  774. bootclasspath.append(path);
  775. }
  776. }
  777. /**
  778. * Create a Path to be configured with the boot classpath
  779. *
  780. * @return a new Path instance to be configured with the boot classpath.
  781. */
  782. public Path createBootclasspath() {
  783. if (bootclasspath == null) {
  784. bootclasspath = new Path(getProject());
  785. }
  786. return bootclasspath.createPath();
  787. }
  788. /**
  789. * Adds a reference to a CLASSPATH defined elsewhere.
  790. *
  791. * @param r the reference to an instance defining the bootclasspath.
  792. */
  793. public void setBootClasspathRef(Reference r) {
  794. createBootclasspath().setRefid(r);
  795. }
  796. /**
  797. * Set the location of the extensions directories.
  798. *
  799. * @param path the string version of the path.
  800. * @deprecated Use the {@link #setExtdirs(Path)} version.
  801. */
  802. public void setExtdirs(String path) {
  803. if (!javadoc1) {
  804. cmd.createArgument().setValue("-extdirs");
  805. cmd.createArgument().setValue(path);
  806. }
  807. }
  808. /**
  809. * Set the location of the extensions directories.
  810. *
  811. * @param path a path containing the extension directories.
  812. */
  813. public void setExtdirs(Path path) {
  814. if (!javadoc1) {
  815. cmd.createArgument().setValue("-extdirs");
  816. cmd.createArgument().setPath(path);
  817. }
  818. }
  819. /**
  820. * Run javadoc in verbose mode
  821. *
  822. * @param b true if operation is to be verbose.
  823. */
  824. public void setVerbose(boolean b) {
  825. add12ArgIf(b, "-verbose");
  826. }
  827. /**
  828. * Set the local to use in documentation generation.
  829. *
  830. * @param locale the locale to use.
  831. */
  832. public void setLocale(String locale) {
  833. if (!javadoc1) {
  834. // createArgument(true) is necessary to make sure, -locale
  835. // is the first argument (required in 1.3+).
  836. cmd.createArgument(true).setValue(locale);
  837. cmd.createArgument(true).setValue("-locale");
  838. }
  839. }
  840. /**
  841. * Set the encoding name of the source files,
  842. *
  843. * @param enc the name of the encoding for the source files.
  844. */
  845. public void setEncoding(String enc) {
  846. cmd.createArgument().setValue("-encoding");
  847. cmd.createArgument().setValue(enc);
  848. }
  849. /**
  850. * Include the version tag in the generated documentation.
  851. *
  852. * @param b true if the version tag should be included.
  853. */
  854. public void setVersion(boolean b) {
  855. this.version = b;
  856. }
  857. /**
  858. * Generate the &quot;use&quot page for each package.
  859. *
  860. * @param b true if the use page should be generated.
  861. */
  862. public void setUse(boolean b) {
  863. add12ArgIf(b, "-use");
  864. }
  865. /**
  866. * Include the author tag in the generated documentation.
  867. *
  868. * @param b true if the author tag should be included.
  869. */
  870. public void setAuthor(boolean b) {
  871. author = b;
  872. }
  873. /**
  874. * Generate a split index
  875. *
  876. * @param b true if the index should be split into a file per letter.
  877. */
  878. public void setSplitindex(boolean b) {
  879. add12ArgIf(b, "-splitindex");
  880. }
  881. /**
  882. * Set the title to be placed in the HTML &lt;title&gt; tag of the
  883. * generated documentation.
  884. *
  885. * @param title the window title to use.
  886. */
  887. public void setWindowtitle(String title) {
  888. add12ArgIfNotEmpty("-windowtitle", title);
  889. }
  890. /**
  891. * Set the title of the generated overview page.
  892. *
  893. * @param doctitle the Document title.
  894. */
  895. public void setDoctitle(String doctitle) {
  896. Html h = new Html();
  897. h.addText(doctitle);
  898. addDoctitle(h);
  899. }
  900. /**
  901. * Add a document title to use for the overview page.
  902. *
  903. * @param text the HTML element containing the document title.
  904. */
  905. public void addDoctitle(Html text) {
  906. if (!javadoc1) {
  907. doctitle = text;
  908. }
  909. }
  910. /**
  911. * Set the header text to be placed at the top of each output file.
  912. *
  913. * @param header the header text
  914. */
  915. public void setHeader(String header) {
  916. Html h = new Html();
  917. h.addText(header);
  918. addHeader(h);
  919. }
  920. /**
  921. * Set the header text to be placed at the top of each output file.
  922. *
  923. * @param text the header text
  924. */
  925. public void addHeader(Html text) {
  926. if (!javadoc1) {
  927. header = text;
  928. }
  929. }
  930. /**
  931. * Set the footer text to be placed at the bottom of each output file.
  932. *
  933. * @param footer the footer text.
  934. */
  935. public void setFooter(String footer) {
  936. Html h = new Html();
  937. h.addText(footer);
  938. addFooter(h);
  939. }
  940. /**
  941. * Set the footer text to be placed at the bottom of each output file.
  942. *
  943. * @param text the footer text.
  944. */
  945. public void addFooter(Html text) {
  946. if (!javadoc1) {
  947. footer = text;
  948. }
  949. }
  950. /**
  951. * Set the text to be placed at the bottom of each output file.
  952. *
  953. * @param bottom the bottom text.
  954. */
  955. public void setBottom(String bottom) {
  956. Html h = new Html();
  957. h.addText(bottom);
  958. addBottom(h);
  959. }
  960. /**
  961. * Set the text to be placed at the bottom of each output file.
  962. *
  963. * @param text the bottom text.
  964. */
  965. public void addBottom(Html text) {
  966. if (!javadoc1) {
  967. bottom = text;
  968. }
  969. }
  970. /**
  971. * Link to docs at "url" using package list at "url2"
  972. * - separate the URLs by using a space character.
  973. */
  974. public void setLinkoffline(String src) {
  975. if (!javadoc1) {
  976. LinkArgument le = createLink();
  977. le.setOffline(true);
  978. String linkOfflineError = "The linkoffline attribute must include"
  979. + " a URL and a package-list file location separated by a"
  980. + " space";
  981. if (src.trim().length() == 0) {
  982. throw new BuildException(linkOfflineError);
  983. }
  984. StringTokenizer tok = new StringTokenizer(src, " ", false);
  985. le.setHref(tok.nextToken());
  986. if (!tok.hasMoreTokens()) {
  987. throw new BuildException(linkOfflineError);
  988. }
  989. le.setPackagelistLoc(getProject().resolveFile(tok.nextToken()));
  990. }
  991. }
  992. /**
  993. * Group specified packages together in overview page.
  994. */
  995. public void setGroup(String src) {
  996. group = src;
  997. }
  998. /**
  999. * Create links to javadoc output at the given URL.
  1000. */
  1001. public void setLink(String src) {
  1002. if (!javadoc1) {
  1003. createLink().setHref(src);
  1004. }
  1005. }
  1006. /**
  1007. * If true, do not include @deprecated information.
  1008. */
  1009. public void setNodeprecated(boolean b) {
  1010. addArgIf(b, "-nodeprecated");
  1011. }
  1012. /**
  1013. * If true, do not generate deprecated list.
  1014. */
  1015. public void setNodeprecatedlist(boolean b) {
  1016. add12ArgIf(b, "-nodeprecatedlist");
  1017. }
  1018. /**
  1019. * If true, do not generate class hierarchy.
  1020. */
  1021. public void setNotree(boolean b) {
  1022. addArgIf(b, "-notree");
  1023. }
  1024. /**
  1025. * If true, do not generate index.
  1026. */
  1027. public void setNoindex(boolean b) {
  1028. addArgIf(b, "-noindex");
  1029. }
  1030. /**
  1031. * If true, do not generate help link
  1032. */
  1033. public void setNohelp(boolean b) {
  1034. add12ArgIf(b, "-nohelp");
  1035. }
  1036. /**
  1037. * If true, do not generate navigation bar.
  1038. */
  1039. public void setNonavbar(boolean b) {
  1040. add12ArgIf(b, "-nonavbar");
  1041. }
  1042. /**
  1043. * If true, generate warning about @serial tag.
  1044. */
  1045. public void setSerialwarn(boolean b) {
  1046. add12ArgIf(b, "-serialwarn");
  1047. }
  1048. /**
  1049. * Specifies the CSS stylesheet file to use.
  1050. */
  1051. public void setStylesheetfile(File f) {
  1052. if (!javadoc1) {
  1053. cmd.createArgument().setValue("-stylesheetfile");
  1054. cmd.createArgument().setFile(f);
  1055. }
  1056. }
  1057. /**
  1058. * Specifies the HTML help file to use.
  1059. */
  1060. public void setHelpfile(File f) {
  1061. if (!javadoc1) {
  1062. cmd.createArgument().setValue("-helpfile");
  1063. cmd.createArgument().setFile(f);
  1064. }
  1065. }
  1066. /**
  1067. * Output file encoding name.
  1068. */
  1069. public void setDocencoding(String enc) {
  1070. cmd.createArgument().setValue("-docencoding");
  1071. cmd.createArgument().setValue(enc);
  1072. }
  1073. /**
  1074. * The name of a file containing the packages to process.
  1075. */
  1076. public void setPackageList(String src) {
  1077. if (!javadoc1) {
  1078. packageList = src;
  1079. }
  1080. }
  1081. /**
  1082. * Create link to javadoc output at the given URL.
  1083. */
  1084. public LinkArgument createLink() {
  1085. LinkArgument la = new LinkArgument();
  1086. links.addElement(la);
  1087. return la;
  1088. }
  1089. public class LinkArgument {
  1090. private String href;
  1091. private boolean offline = false;
  1092. private File packagelistLoc;
  1093. public LinkArgument() {
  1094. }
  1095. public void setHref(String hr) {
  1096. href = hr;
  1097. }
  1098. public String getHref() {
  1099. return href;
  1100. }
  1101. public void setPackagelistLoc(File src) {
  1102. packagelistLoc = src;
  1103. }
  1104. public File getPackagelistLoc() {
  1105. return packagelistLoc;
  1106. }
  1107. public void setOffline(boolean offline) {
  1108. this.offline = offline;
  1109. }
  1110. public boolean isLinkOffline() {
  1111. return offline;
  1112. }
  1113. }
  1114. /**
  1115. * Creates and adds a -tag argument. This is used to specify
  1116. * custom tags. This argument is only available for JavaDoc 1.4,
  1117. * and will generate a verbose message (and then be ignored)
  1118. * when run on Java versions below 1.4.
  1119. */
  1120. public TagArgument createTag() {
  1121. if (!javadoc4) {
  1122. log ("-tag option not supported on JavaDoc < 1.4",
  1123. Project.MSG_VERBOSE);
  1124. }
  1125. TagArgument ta = new TagArgument();
  1126. tags.addElement (ta);
  1127. return ta;
  1128. }
  1129. /**
  1130. * Scope element verbose names. (Defined here as fields
  1131. * cannot be static in inner classes.) The first letter
  1132. * from each element is used to build up the scope string.
  1133. */
  1134. static final String[] SCOPE_ELEMENTS = {
  1135. "overview", "packages", "types", "constructors",
  1136. "methods", "fields"
  1137. };
  1138. /**
  1139. * Class representing a -tag argument.
  1140. */
  1141. public class TagArgument extends FileSet {
  1142. /** Name of the tag. */
  1143. private String name = null;
  1144. /** Description of the tag to place in the JavaDocs. */
  1145. private String description = null;
  1146. /** Whether or not the tag is enabled. */
  1147. private boolean enabled = true;
  1148. /**
  1149. * Scope string of the tag. This will form the middle
  1150. * argument of the -tag parameter when the tag is enabled
  1151. * (with an X prepended for and is parsed from human-readable form.
  1152. */
  1153. private String scope = "a";
  1154. /** Sole constructor. */
  1155. public TagArgument () {
  1156. }
  1157. /**
  1158. * Sets the name of the tag.
  1159. *
  1160. * @param name The name of the tag.
  1161. * Must not be <code>null</code> or empty.
  1162. */
  1163. public void setName (String name) {
  1164. this.name = name;
  1165. }
  1166. /**
  1167. * Sets the description of the tag. This is what appears in
  1168. * the JavaDoc.
  1169. *
  1170. * @param description The description of the tag.
  1171. * Must not be <code>null</code> or empty.
  1172. */
  1173. public void setDescription (String description) {
  1174. this.description = description;
  1175. }
  1176. /**
  1177. * Sets the scope of the tag. This is in comma-separated
  1178. * form, with each element being one of "all" (the default),
  1179. * "overview", "packages", "types", "constructors", "methods",
  1180. * "fields". The elements are treated in a case-insensitive
  1181. * manner.
  1182. *
  1183. * @param verboseScope The scope of the tag.
  1184. * Must not be <code>null</code>,
  1185. * should not be empty.
  1186. *
  1187. * @exception BuildException if all is specified along with
  1188. * other elements, if any elements are repeated, if no
  1189. * elements are specified, or if any unrecognised elements are
  1190. * specified.
  1191. */
  1192. public void setScope (String verboseScope) throws BuildException {
  1193. verboseScope = verboseScope.toLowerCase(Locale.US);
  1194. boolean[] elements = new boolean[SCOPE_ELEMENTS.length];
  1195. boolean gotAll = false;
  1196. boolean gotNotAll = false;
  1197. // Go through the tokens one at a time, updating the
  1198. // elements array and issuing warnings where appropriate.
  1199. StringTokenizer tok = new StringTokenizer (verboseScope, ",");
  1200. while (tok.hasMoreTokens()) {
  1201. String next = tok.nextToken().trim();
  1202. if (next.equals("all")) {
  1203. if (gotAll) {
  1204. getProject().log ("Repeated tag scope element: all",
  1205. Project.MSG_VERBOSE);
  1206. }
  1207. gotAll = true;
  1208. } else {
  1209. int i;
  1210. for (i = 0; i < SCOPE_ELEMENTS.length; i++) {
  1211. if (next.equals (SCOPE_ELEMENTS[i]))
  1212. break;
  1213. }
  1214. if (i == SCOPE_ELEMENTS.length) {
  1215. throw new BuildException ("Unrecognised scope element: "
  1216. + next);
  1217. } else {
  1218. if (elements[i]) {
  1219. getProject().log ("Repeated tag scope element: "
  1220. + next, Project.MSG_VERBOSE);
  1221. }
  1222. elements[i] = true;
  1223. gotNotAll = true;
  1224. }
  1225. }
  1226. }
  1227. if (gotNotAll && gotAll) {
  1228. throw new BuildException ("Mixture of \"all\" and other scope "
  1229. + "elements in tag parameter.");
  1230. }
  1231. if (!gotNotAll && !gotAll) {
  1232. throw new BuildException ("No scope elements specified in tag "
  1233. + "parameter.");
  1234. }
  1235. if (gotAll) {
  1236. this.scope = "a";
  1237. } else {
  1238. StringBuffer buff = new StringBuffer (elements.length);
  1239. for (int i = 0; i < elements.length; i++) {
  1240. if (elements[i]) {
  1241. buff.append (SCOPE_ELEMENTS[i].charAt(0));
  1242. }
  1243. }
  1244. this.scope = buff.toString();
  1245. }
  1246. }
  1247. /**
  1248. * Sets whether or not the tag is enabled.
  1249. *
  1250. * @param enabled Whether or not this tag is enabled.
  1251. */
  1252. public void setEnabled (boolean enabled) {
  1253. this.enabled = enabled;
  1254. }
  1255. /**
  1256. * Returns the -tag parameter this argument represented.
  1257. *
  1258. * @exception BuildException if either the name or description
  1259. * is <code>null</code> or empty.
  1260. */
  1261. public String getParameter () throws BuildException {
  1262. if (name == null || name.equals("")) {
  1263. throw new BuildException ("No name specified for custom tag.");
  1264. }
  1265. if (description != null) {
  1266. return name + ":" + (enabled ? "" : "X")
  1267. + scope + ":" + description;
  1268. } else {
  1269. return name;
  1270. }
  1271. }
  1272. }
  1273. /**
  1274. * Separates packages on the overview page into whatever
  1275. * groups you specify, one group per table.
  1276. */
  1277. public GroupArgument createGroup() {
  1278. GroupArgument ga = new GroupArgument();
  1279. groups.addElement(ga);
  1280. return ga;
  1281. }
  1282. public class GroupArgument {
  1283. private Html title;
  1284. private Vector packages = new Vector(3);
  1285. public GroupArgument() {
  1286. }
  1287. public void setTitle(String src) {
  1288. Html h = new Html();
  1289. h.addText(src);
  1290. addTitle(h);
  1291. }
  1292. public void addTitle(Html text) {
  1293. title = text;
  1294. }
  1295. public String getTitle() {
  1296. return title != null ? title.getText() : null;
  1297. }
  1298. public void setPackages(String src) {
  1299. StringTokenizer tok = new StringTokenizer(src, ",");
  1300. while (tok.hasMoreTokens()) {
  1301. String p = tok.nextToken();
  1302. PackageName pn = new PackageName();
  1303. pn.setName(p);
  1304. addPackage(pn);
  1305. }
  1306. }
  1307. public void addPackage(PackageName pn) {
  1308. packages.addElement(pn);
  1309. }
  1310. public String getPackages() {
  1311. StringBuffer p = new StringBuffer();
  1312. for (int i = 0; i < packages.size(); i++) {
  1313. if (i > 0) {
  1314. p.append(":");
  1315. }
  1316. p.append(packages.elementAt(i).toString());
  1317. }
  1318. return p.toString();
  1319. }
  1320. }
  1321. /**
  1322. * Charset for cross-platform viewing of generated documentation.
  1323. */
  1324. public void setCharset(String src) {
  1325. this.add12ArgIfNotEmpty("-charset", src);
  1326. }
  1327. /**
  1328. * Should the build process fail if javadoc fails (as indicated by
  1329. * a non zero return code)?
  1330. *
  1331. * <p>Default is false.</p>
  1332. */
  1333. public void setFailonerror(boolean b) {
  1334. failOnError = b;
  1335. }
  1336. /**
  1337. * Enables the -source switch, will be ignored if javadoc is not
  1338. * the 1.4 version.
  1339. *
  1340. * @since Ant 1.5
  1341. */
  1342. public void setSource(String source) {
  1343. if (!javadoc4) {
  1344. log ("-source option not supported on JavaDoc < 1.4",
  1345. Project.MSG_VERBOSE);
  1346. }
  1347. this.source = source;
  1348. }
  1349. /**
  1350. * Adds a packageset.
  1351. *
  1352. * <p>All included directories will be translated into package
  1353. * names be converting the directory separator into dots.</p>
  1354. *
  1355. * @since 1.5
  1356. */
  1357. public void addPackageset(DirSet packageSet) {
  1358. packageSets.addElement(packageSet);
  1359. }
  1360. /**
  1361. * Adds a fileset.
  1362. *
  1363. * <p>All included files will be added as sourcefiles. The task
  1364. * will automatically add
  1365. * <code>includes=&quot;**&#47;*.java&quot;</code> to the
  1366. * fileset.</p>
  1367. *
  1368. * @since 1.5
  1369. */
  1370. public void addFileset(FileSet fs) {
  1371. fileSets.addElement(fs);
  1372. }
  1373. /**
  1374. * Enables the -linksource switch, will be ignored if javadoc is not
  1375. * the 1.4 version. Default is false
  1376. *
  1377. * @since Ant 1.6
  1378. */
  1379. public void setLinksource(boolean b) {
  1380. if (!javadoc4) {
  1381. log ("-linksource option not supported on JavaDoc < 1.4",
  1382. Project.MSG_VERBOSE);
  1383. }
  1384. this.linksource = b;
  1385. }
  1386. /**
  1387. * Enables the -linksource switch, will be ignored if javadoc is not
  1388. * the 1.4 version. Default is false
  1389. *
  1390. * @since Ant 1.6
  1391. */
  1392. public void setBreakiterator(boolean b) {
  1393. if (!javadoc4) {
  1394. log ("-breakiterator option not supported on JavaDoc < 1.4",
  1395. Project.MSG_VERBOSE);
  1396. }
  1397. this.breakiterator = b;
  1398. }
  1399. /**
  1400. * Enables the -noqualifier switch, will be ignored if javadoc is not
  1401. * the 1.4 version.
  1402. *
  1403. * @since Ant 1.6
  1404. */
  1405. public void setNoqualifier(String noqualifier) {
  1406. if (!javadoc4) {
  1407. log ("-noqualifier option not supported on JavaDoc < 1.4",
  1408. Project.MSG_VERBOSE);
  1409. }
  1410. this.noqualifier = noqualifier;
  1411. }
  1412. public void execute() throws BuildException {
  1413. if ("javadoc2".equals(getTaskType())) {
  1414. log("!! javadoc2 is deprecated. Use javadoc instead. !!");
  1415. }
  1416. Vector packagesToDoc = new Vector();
  1417. Path sourceDirs = new Path(getProject());
  1418. if (packageList != null && sourcePath == null) {
  1419. String msg = "sourcePath attribute must be set when "
  1420. + "specifying packagelist.";
  1421. throw new BuildException(msg);
  1422. }
  1423. if (sourcePath != null) {
  1424. sourceDirs.addExisting(sourcePath);
  1425. }
  1426. parsePackages(packagesToDoc, sourceDirs);
  1427. if (packagesToDoc.size() != 0 && sourceDirs.size() == 0) {
  1428. String msg = "sourcePath attribute must be set when "
  1429. + "specifying package names.";
  1430. throw new BuildException(msg);
  1431. }
  1432. Vector sourceFilesToDoc = (Vector) sourceFiles.clone();
  1433. addFileSets(sourceFilesToDoc);
  1434. if (packageList == null && packagesToDoc.size() == 0
  1435. && sourceFilesToDoc.size() == 0) {
  1436. throw new BuildException("No source files and no packages have "
  1437. + "been specified.");
  1438. }
  1439. log("Generating Javadoc", Project.MSG_INFO);
  1440. Commandline toExecute = (Commandline) cmd.clone();
  1441. toExecute.setExecutable(JavaEnvUtils.getJdkExecutable("javadoc"));
  1442. // ------------------------------------------ general javadoc arguments
  1443. if (doctitle != null) {
  1444. toExecute.createArgument().setValue("-doctitle");
  1445. toExecute.createArgument().setValue(expand(doctitle.getText()));
  1446. }
  1447. if (header != null) {
  1448. toExecute.createArgument().setValue("-header");
  1449. toExecute.createArgument().setValue(expand(header.getText()));
  1450. }
  1451. if (footer != null) {
  1452. toExecute.createArgument().setValue("-footer");
  1453. toExecute.createArgument().setValue(expand(footer.getText()));
  1454. }
  1455. if (bottom != null) {
  1456. toExecute.createArgument().setValue("-bottom");
  1457. toExecute.createArgument().setValue(expand(bottom.getText()));
  1458. }
  1459. if (classpath == null) {
  1460. classpath = (new Path(getProject())).concatSystemClasspath("last");
  1461. } else {
  1462. classpath = classpath.concatSystemClasspath("ignore");
  1463. }
  1464. if (!javadoc1) {
  1465. if (classpath.size() > 0) {
  1466. toExecute.createArgument().setValue("-classpath");
  1467. toExecute.createArgument().setPath(classpath);
  1468. }
  1469. if (sourceDirs.size() > 0) {
  1470. toExecute.createArgument().setValue("-sourcepath");
  1471. toExecute.createArgument().setPath(sourceDirs);
  1472. }
  1473. } else {
  1474. sourceDirs.append(classpath);
  1475. if (sourceDirs.size() > 0) {
  1476. toExecute.createArgument().setValue("-classpath");
  1477. toExecute.createArgument().setPath(sourceDirs);
  1478. }
  1479. }
  1480. if (version && doclet == null) {
  1481. toExecute.createArgument().setValue("-version");
  1482. }
  1483. if (author && doclet == null) {
  1484. toExecute.createArgument().setValue("-author");
  1485. }
  1486. if (javadoc1 || doclet == null) {
  1487. if (destDir == null) {
  1488. String msg = "destDir attribute must be set!";
  1489. throw new BuildException(msg);
  1490. }
  1491. }
  1492. // ---------------------------- javadoc2 arguments for default doclet
  1493. if (!javadoc1) {
  1494. if (doclet != null) {
  1495. if (doclet.getName() == null) {
  1496. throw new BuildException("The doclet name must be "
  1497. + "specified.", getLocation());
  1498. } else {
  1499. toExecute.createArgument().setValue("-doclet");
  1500. toExecute.createArgument().setValue(doclet.getName());
  1501. if (doclet.getPath() != null) {
  1502. Path docletPath
  1503. = doclet.getPath().concatSystemClasspath("ignore");
  1504. if (docletPath.size() != 0) {
  1505. toExecute.createArgument().setValue("-docletpath");
  1506. toExecute.createArgument().setPath(docletPath);
  1507. }
  1508. }
  1509. for (Enumeration e = doclet.getParams();
  1510. e.hasMoreElements();) {
  1511. DocletParam param = (DocletParam) e.nextElement();
  1512. if (param.getName() == null) {
  1513. throw new BuildException("Doclet parameters must "
  1514. + "have a name");
  1515. }
  1516. toExecute.createArgument().setValue(param.getName());
  1517. if (param.getValue() != null) {
  1518. toExecute.createArgument()
  1519. .setValue(param.getValue());
  1520. }
  1521. }
  1522. }
  1523. }
  1524. if (bootclasspath != null && bootclasspath.size() > 0) {
  1525. toExecute.createArgument().setValue("-bootclasspath");
  1526. toExecute.createArgument().setPath(bootclasspath);
  1527. }
  1528. // add the links arguments
  1529. if (links.size() != 0) {
  1530. for (Enumeration e = links.elements(); e.hasMoreElements();) {
  1531. LinkArgument la = (LinkArgument) e.nextElement();
  1532. if (la.getHref() == null || la.getHref().length() == 0) {
  1533. log("No href was given for the link - skipping",
  1534. Project.MSG_VERBOSE);
  1535. continue;
  1536. } else {
  1537. // is the href a valid URL
  1538. try {
  1539. URL base = new URL("file://.");
  1540. new URL(base, la.getHref());
  1541. } catch (MalformedURLException mue) {
  1542. // ok - just skip
  1543. log("Link href \"" + la.getHref()
  1544. + "\" is not a valid url - skipping link",
  1545. Project.MSG_WARN);
  1546. continue;
  1547. }
  1548. }
  1549. if (la.isLinkOffline()) {
  1550. File packageListLocation = la.getPackagelistLoc();
  1551. if (packageListLocation == null) {
  1552. throw new BuildException("The package list "
  1553. + " location for link " + la.getHref()
  1554. + " must be provided because the link is "
  1555. + "offline");
  1556. }
  1557. File packageListFile =
  1558. new File(packageListLocation, "package-list");
  1559. if (packageListFile.exists()) {
  1560. try {
  1561. String packageListURL =
  1562. fileUtils.getFileURL(packageListLocation)
  1563. .toExternalForm();
  1564. toExecute.createArgument()
  1565. .setValue("-linkoffline");
  1566. toExecute.createArgument()
  1567. .setValue(la.getHref());
  1568. toExecute.createArgument()
  1569. .setValue(packageListURL);
  1570. } catch (MalformedURLException ex) {
  1571. log("Warning: Package list location was "
  1572. + "invalid " + packageListLocation,
  1573. Project.MSG_WARN);
  1574. }
  1575. } else {
  1576. log("Warning: No package list was found at "
  1577. + packageListLocation, Project.MSG_VERBOSE);
  1578. }
  1579. } else {
  1580. toExecute.createArgument().setValue("-link");
  1581. toExecute.createArgument().setValue(la.getHref());
  1582. }
  1583. }
  1584. }
  1585. // add the single group arguments
  1586. // Javadoc 1.2 rules:
  1587. // Multiple -group args allowed.
  1588. // Each arg includes 3 strings: -group [name] [packagelist].
  1589. // Elements in [packagelist] are colon-delimited.
  1590. // An element in [packagelist] may end with the * wildcard.
  1591. // Ant javadoc task rules for group attribute:
  1592. // Args are comma-delimited.
  1593. // Each arg is 2 space-delimited strings.
  1594. // E.g., group="XSLT_Packages org.apache.xalan.xslt*,
  1595. // XPath_Packages org.apache.xalan.xpath*"
  1596. if (group != null) {
  1597. StringTokenizer tok = new StringTokenizer(group, ",", false);
  1598. while (tok.hasMoreTokens()) {
  1599. String grp = tok.nextToken().trim();
  1600. int space = grp.indexOf(" ");
  1601. if (space > 0){
  1602. String name = grp.substring(0, space);
  1603. String pkgList = grp.substring(space + 1);
  1604. toExecute.createArgument().setValue("-group");
  1605. toExecute.createArgument().setValue(name);
  1606. toExecute.createArgument().setValue(pkgList);
  1607. }
  1608. }
  1609. }
  1610. // add the group arguments
  1611. if (groups.size() != 0) {
  1612. for (Enumeration e = groups.elements(); e.hasMoreElements();) {
  1613. GroupArgument ga = (GroupArgument) e.nextElement();
  1614. String title = ga.getTitle();
  1615. String packages = ga.getPackages();
  1616. if (title == null || packages == null) {
  1617. throw new BuildException("The title and packages must "
  1618. + "be specified for group "
  1619. + "elements.");
  1620. }
  1621. toExecute.createArgument().setValue("-group");
  1622. toExecute.createArgument().setValue(expand(title));
  1623. toExecute.createArgument().setValue(packages);
  1624. }
  1625. }
  1626. // JavaDoc 1.4 parameters
  1627. if (javadoc4) {
  1628. for (Enumeration e = tags.elements(); e.hasMoreElements();) {
  1629. Object element = e.nextElement();
  1630. if (element instanceof TagArgument) {
  1631. TagArgument ta = (TagArgument) element;
  1632. File tagDir = ta.getDir(getProject());
  1633. if (tagDir == null ) {
  1634. // The tag element is not used as a fileset,
  1635. // but specifies the tag directly.
  1636. toExecute.createArgument().setValue ("-tag");
  1637. toExecute.createArgument().setValue (ta.getParameter());
  1638. } else {
  1639. // The tag element is used as a fileset. Parse all the files and
  1640. // create -tag arguments.
  1641. DirectoryScanner tagDefScanner = ta.getDirectoryScanner(getProject());
  1642. String[] files = tagDefScanner.getIncludedFiles();
  1643. for (int i = 0; i < files.length; i++) {
  1644. File tagDefFile = new File( tagDir, files[i] );
  1645. try {
  1646. BufferedReader in = new BufferedReader( new FileReader(tagDefFile) );
  1647. String line = null;
  1648. while( (line = in.readLine()) != null ) {
  1649. toExecute.createArgument().setValue ("-tag");
  1650. toExecute.createArgument().setValue (line);
  1651. }
  1652. in.close();
  1653. } catch( IOException ioe ) {
  1654. throw new BuildException( "Couldn't read tag file from " + tagDefFile.getAbsolutePath(), ioe );
  1655. }
  1656. }
  1657. }
  1658. } else {
  1659. ExtensionInfo tagletInfo = (ExtensionInfo) element;
  1660. toExecute.createArgument().setValue("-taglet");
  1661. toExecute.createArgument().setValue(tagletInfo
  1662. .getName());
  1663. if (tagletInfo.getPath() != null) {
  1664. Path tagletPath = tagletInfo.getPath()
  1665. .concatSystemClasspath("ignore");
  1666. if (tagletPath.size() != 0) {
  1667. toExecute.createArgument()
  1668. .setValue("-tagletpath");
  1669. toExecute.createArgument().setPath(tagletPath);
  1670. }
  1671. }
  1672. }
  1673. }
  1674. if (source != null) {
  1675. toExecute.createArgument().setValue("-source");
  1676. toExecute.createArgument().setValue(source);
  1677. }
  1678. if (linksource && doclet == null) {
  1679. toExecute.createArgument().setValue("-linksource");
  1680. }
  1681. if (breakiterator && doclet == null) {
  1682. toExecute.createArgument().setValue("-breakiterator");
  1683. }
  1684. if (noqualifier != null && doclet == null) {
  1685. toExecute.createArgument().setValue("-noqualifier");
  1686. toExecute.createArgument().setValue(noqualifier);
  1687. }
  1688. }
  1689. }
  1690. File tmpList = null;
  1691. PrintWriter srcListWriter = null;
  1692. try {
  1693. /**
  1694. * Write sourcefiles and package names to a temporary file
  1695. * if requested.
  1696. */
  1697. if (useExternalFile) {
  1698. if (tmpList == null) {
  1699. tmpList = fileUtils.createTempFile("javadoc", "", null);
  1700. toExecute.createArgument()
  1701. .setValue("@" + tmpList.getAbsolutePath());
  1702. }
  1703. srcListWriter = new PrintWriter(
  1704. new FileWriter(tmpList.getAbsolutePath(),
  1705. true));
  1706. }
  1707. Enumeration enum = packagesToDoc.elements();
  1708. while (enum.hasMoreElements()) {
  1709. String packageName = (String) enum.nextElement();
  1710. if (useExternalFile) {
  1711. srcListWriter.println(packageName);
  1712. } else {
  1713. toExecute.createArgument().setValue(packageName);
  1714. }
  1715. }
  1716. enum = sourceFilesToDoc.elements();
  1717. while (enum.hasMoreElements()) {
  1718. SourceFile sf = (SourceFile) enum.nextElement();
  1719. String sourceFileName = sf.getFile().getAbsolutePath();
  1720. if (useExternalFile) {
  1721. if (javadoc4 && sourceFileName.indexOf(" ") > -1) {
  1722. srcListWriter.println("\"" + sourceFileName + "\"");
  1723. } else {
  1724. srcListWriter.println(sourceFileName);
  1725. }
  1726. } else {
  1727. toExecute.createArgument().setValue(sourceFileName);
  1728. }
  1729. }
  1730. } catch (IOException e) {
  1731. tmpList.delete();
  1732. throw new BuildException("Error creating temporary file",
  1733. e, getLocation());
  1734. } finally {
  1735. if (srcListWriter != null) {
  1736. srcListWriter.close();
  1737. }
  1738. }
  1739. if (packageList != null) {
  1740. toExecute.createArgument().setValue("@" + packageList);
  1741. }
  1742. log(toExecute.describeCommand(), Project.MSG_VERBOSE);
  1743. log("Javadoc execution", Project.MSG_INFO);
  1744. JavadocOutputStream out = new JavadocOutputStream(Project.MSG_INFO);
  1745. JavadocOutputStream err = new JavadocOutputStream(Project.MSG_WARN);
  1746. Execute exe = new Execute(new PumpStreamHandler(out, err));
  1747. exe.setAntRun(getProject());
  1748. /*
  1749. * No reason to change the working directory as all filenames and
  1750. * path components have been resolved already.
  1751. *
  1752. * Avoid problems with command line length in some environments.
  1753. */
  1754. exe.setWorkingDirectory(null);
  1755. try {
  1756. exe.setCommandline(toExecute.getCommandline());
  1757. int ret = exe.execute();
  1758. if (ret != 0 && failOnError) {
  1759. throw new BuildException("Javadoc returned " + ret, getLocation());
  1760. }
  1761. } catch (IOException e) {
  1762. throw new BuildException("Javadoc failed: " + e, e, getLocation());
  1763. } finally {
  1764. if (tmpList != null) {
  1765. tmpList.delete();
  1766. tmpList = null;
  1767. }
  1768. out.logFlush();
  1769. err.logFlush();
  1770. try {
  1771. out.close();
  1772. err.close();
  1773. } catch (IOException e) {}
  1774. }
  1775. }
  1776. /**
  1777. * Add the files matched by the nested filesets to the Vector as
  1778. * SourceFile instances.
  1779. *
  1780. * @since 1.5
  1781. */
  1782. private void addFileSets(Vector sf) {
  1783. Enumeration enum = fileSets.elements();
  1784. while (enum.hasMoreElements()) {
  1785. FileSet fs = (FileSet) enum.nextElement();
  1786. if (!fs.hasPatterns() && !fs.hasSelectors()) {
  1787. fs = (FileSet) fs.clone();
  1788. fs.createInclude().setName("**/*.java");
  1789. }
  1790. File baseDir = fs.getDir(getProject());
  1791. DirectoryScanner ds = fs.getDirectoryScanner(getProject());
  1792. String[] files = ds.getIncludedFiles();
  1793. for (int i = 0; i < files.length; i++) {
  1794. sf.addElement(new SourceFile(new File(baseDir, files[i])));
  1795. }
  1796. }
  1797. }
  1798. /**
  1799. * Add the directories matched by the nested dirsets to the Vector
  1800. * and the base directories of the dirsets to the Path. It also
  1801. * handles the packages and excludepackages attributes and
  1802. * elements.
  1803. *
  1804. * @since 1.5
  1805. */
  1806. private void parsePackages(Vector pn, Path sp) {
  1807. Vector addedPackages = new Vector();
  1808. Vector dirSets = (Vector) packageSets.clone();
  1809. // for each sourcePath entry, add a directoryset with includes
  1810. // taken from packagenames attribute and nested package
  1811. // elements and excludes taken from excludepackages attribute
  1812. // and nested excludepackage elements
  1813. if (sourcePath != null && packageNames.size() > 0) {
  1814. PatternSet ps = new PatternSet();
  1815. Enumeration enum = packageNames.elements();
  1816. while (enum.hasMoreElements()) {
  1817. PackageName p = (PackageName) enum.nextElement();
  1818. String pkg = p.getName().replace('.', '/');
  1819. if (pkg.endsWith("*")) {
  1820. pkg += "*";
  1821. }
  1822. ps.createInclude().setName(pkg);
  1823. }
  1824. enum = excludePackageNames.elements();
  1825. while (enum.hasMoreElements()) {
  1826. PackageName p = (PackageName) enum.nextElement();
  1827. String pkg = p.getName().replace('.', '/');
  1828. if (pkg.endsWith("*")) {
  1829. pkg += "*";
  1830. }
  1831. ps.createExclude().setName(pkg);
  1832. }
  1833. String[] pathElements = sourcePath.list();
  1834. for (int i = 0; i < pathElements.length; i++) {
  1835. DirSet ds = new DirSet();
  1836. ds.setDefaultexcludes(useDefaultExcludes);
  1837. ds.setDir(new File(pathElements[i]));
  1838. ds.createPatternSet().addConfiguredPatternset(ps);
  1839. dirSets.addElement(ds);
  1840. }
  1841. }
  1842. Enumeration enum = dirSets.elements();
  1843. while (enum.hasMoreElements()) {
  1844. DirSet ds = (DirSet) enum.nextElement();
  1845. File baseDir = ds.getDir(getProject());
  1846. log("scanning " + baseDir + " for packages.", Project.MSG_DEBUG);
  1847. DirectoryScanner dsc = ds.getDirectoryScanner(getProject());
  1848. String[] dirs = dsc.getIncludedDirectories();
  1849. boolean containsPackages = false;
  1850. for (int i = 0; i < dirs.length; i++) {
  1851. // are there any java files in this directory?
  1852. File pd = new File(baseDir, dirs[i]);
  1853. String[] files = pd.list(new FilenameFilter () {
  1854. public boolean accept(File dir1, String name) {
  1855. if (name.endsWith(".java")) {
  1856. return true;
  1857. }
  1858. return false; // ignore dirs
  1859. }
  1860. });
  1861. if (files.length > 0) {
  1862. containsPackages = true;
  1863. String packageName =
  1864. dirs[i].replace(File.separatorChar, '.');
  1865. if (!addedPackages.contains(packageName)) {
  1866. addedPackages.addElement(packageName);
  1867. pn.addElement(packageName);
  1868. }
  1869. }
  1870. }
  1871. if (containsPackages) {
  1872. // We don't need to care for duplicates here,
  1873. // Path.list does it for us.
  1874. sp.createPathElement().setLocation(baseDir);
  1875. } else {
  1876. log(baseDir + " doesn\'t contain any packages, dropping it.",
  1877. Project.MSG_VERBOSE);
  1878. }
  1879. }
  1880. }
  1881. private class JavadocOutputStream extends LogOutputStream {
  1882. JavadocOutputStream(int level) {
  1883. super(Javadoc.this, level);
  1884. }
  1885. //
  1886. // Override the logging of output in order to filter out Generating
  1887. // messages. Generating messages are set to a priority of VERBOSE
  1888. // unless they appear after what could be an informational message.
  1889. //
  1890. private String queuedLine = null;
  1891. protected void processLine(String line, int messageLevel) {
  1892. if (messageLevel == Project.MSG_INFO
  1893. && line.startsWith("Generating ")) {
  1894. if (queuedLine != null) {
  1895. super.processLine(queuedLine, Project.MSG_VERBOSE);
  1896. }
  1897. queuedLine = line;
  1898. } else {
  1899. if (queuedLine != null) {
  1900. if (line.startsWith("Building ")) {
  1901. super.processLine(queuedLine, Project.MSG_VERBOSE);
  1902. } else {
  1903. super.processLine(queuedLine, Project.MSG_INFO);
  1904. }
  1905. queuedLine = null;
  1906. }
  1907. super.processLine(line, messageLevel);
  1908. }
  1909. }
  1910. protected void logFlush() {
  1911. if (queuedLine != null) {
  1912. super.processLine(queuedLine, Project.MSG_VERBOSE);
  1913. queuedLine = null;
  1914. }
  1915. }
  1916. }
  1917. /**
  1918. * Convenience method to expand properties.
  1919. */
  1920. protected String expand(String content) {
  1921. return getProject().replaceProperties(content);
  1922. }
  1923. }