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 68 kB

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