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

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