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

antsupport.adoc 32KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  1. [[antTasks]]
  2. = AspectJ Ant Tasks
  3. [[antTasks-intro]]
  4. == Introduction
  5. AspectJ contains a compiler, `ajc`, that can be run from Ant. Included
  6. in the `aspectjtools.jar` are Ant binaries to support three ways of
  7. running the compiler:
  8. [arabic]
  9. . xref:#antTasks-iajc[AjcTask (iajc)], a task to run the AspectJ
  10. post-1.1 compiler, which supports all the eclipse and ajc options,
  11. including incremental mode.
  12. . xref:#antTasks-adapter[Ajc11CompilerAdapter (javac)], an adapter class
  13. to run the new compiler using Javac tasks by setting the build.compiler
  14. property
  15. . xref:#antTasks-ajc[Ajc10 (ajc)], a task to run build scripts
  16. compatible with the AspectJ 1.0 tasks
  17. This describes how to install and use the tasks and the adapter. For an
  18. example Ant script, see xref:../examples/build.xml[examples/build.xml].
  19. [[antTasks-install]]
  20. == Installing Ant Tasks
  21. Install Jakarta Ant 1.5.1: Please see the official Jakarta Ant website
  22. for more information and the 1.5.1 distribution. This release is
  23. source-compatible with Ant 1.3 and Ant 1.4, but the task sources must be
  24. compiled with those versions of the Ant libraries to be used under those
  25. versions of Ant. Sources are available under the Eclipse Public License
  26. v 2.0 at https://eclipse.org/aspectj.
  27. In Ant 1.5, third-party tasks can be declared using a taskdef entry in
  28. the build script, to identify the name and classes. When declaring a
  29. task, include the `aspectjtools.jar` either in the taskdef classpath or
  30. in `$\{ANT_HOME}/lib` where it will be added to the system class path by
  31. the ant script. You may specify the task script names directly, or use
  32. the "resource" attribute to specify the default names:
  33. [source, xml]
  34. ....
  35. <taskdef resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties"/>
  36. ....
  37. The current resource file retains the name "ajc" for the Ajc10 task, and
  38. uses "iajc" for the AspectJ post-1.1 task.
  39. In Ant 1.6, third-party tasks are declared in their own namespace using
  40. `antlib.xml`. For example, the following script would build and run the
  41. spacewar example, if you put the script in the examples directory and
  42. `aspectjtools.jar` in the `$\{ANT_HOME}/lib` directory.
  43. [source, xml]
  44. ....
  45. <project name="aspectj-ant1.6" default="spacewar"
  46. xmlns:aspectj="antlib:org.aspectj" basedir=".">
  47. <target name="spacewar">
  48. <aspectj:iajc
  49. argfiles="spacewar/debug.lst"
  50. outjar="spacewar.jar"
  51. classpath="../../lib/aspectjrt.jar"
  52. />
  53. <java classname="spacewar.Game"
  54. classpath="spacewar.jar:../../lib/aspectjrt.jar"/>
  55. </target>
  56. </project>
  57. ....
  58. For more information on using Ant, please refer to Jakarta's
  59. documentation on integrating user-defined Ant tasks into builds.
  60. [[antTasks-iajc]]
  61. == AjcTask (iajc)
  62. This task uses the AspectJ post-1.1 compiler ajc. The AspectJ compiler
  63. can be used like Javac to compile Java sources, but it can also compile
  64. AspectJ sources or weave binary aspects with Java bytecode. It can run
  65. in normal "batch" mode or in an "incremental" mode, where it only
  66. recompiles files it has to revisit. For more information on ajc, see
  67. xref:ajc.adoc[`ajc`, the AspectJ compiler/weaver]. Unlike Javac or the Javac Ant task, this task always
  68. compiles the specified files since aspects can apply to other (updated)
  69. files. For a workaround, see xref:#antTasks-iajc-uptodate[Avoiding clean
  70. compiles].
  71. Beyond the normal ajc compiler options, this task also supports an
  72. experimental option for an incremental "tag" file, and it can copy
  73. resources from source directories or input jars to the output jar or
  74. directory.
  75. This task is named iajc to avoid conflict with the 1.0 task ajc.
  76. [[antTasks-iajc-options]]
  77. === AjcTask (iajc) Options
  78. The following tables list the supported parameters. For any parameter
  79. specified as a Path, a single path can be specified directly as an
  80. attribute, multiple paths can be specified using a nested element of the
  81. same name, and a common path can be reused by defining it as a global
  82. and passing the id to the corresponding \{name}ref attribute. See
  83. xref:#antTasks-iajc-paths[Path] below for more details.
  84. Most attributes and nested elements are optional. The compiler requires
  85. that the same version of `aspectjrt.jar` be specified on the classpath,
  86. and that some sources be be specified (using one or more of
  87. `sourceroots`, `injars`, `inpath`, `argfiles`, and/or `srcdir` (with
  88. patterns)). When in incremental mode, only `sourceroots` may be
  89. specified.
  90. Boolean parameters default to `false` unless otherwise stated.
  91. *AjcTask (iajc) options for specifying sources*
  92. [cols=",",options="header",]
  93. |===
  94. |Attribute |Description
  95. |argfiles, argfilesRef (xref:#antTasks-iajc-paths[Path]) |An argument
  96. file contains a list of arguments read by the compiler. Each line is
  97. read into one element of the argument array and may include another
  98. argfile by reference.
  99. |sourceRoots, sourceRootsRef (xref:#antTasks-iajc-paths[Path])
  100. |Directories containing source files (ending with .java or .aj) to
  101. compile.
  102. |srcdir (xref:#antTasks-iajc-paths[Path]) |Base directory of sources to
  103. compile, assuming there are xref:#antTasks-nested-includes[nested
  104. matches]. This approach uses the Ant process for matching .java files
  105. and is not compatible with incremental mode. Unless using filters to
  106. limit the sources included, use sourceroots instead.
  107. |injars, injarsRef (xref:#antTasks-iajc-paths[Path]) |Deprecated - use
  108. inpath instead. Read .class files for bytecode weaving from zip files
  109. (only).
  110. |inpath, inpathRef (xref:#antTasks-iajc-paths[Path]) |Read .class files
  111. for bytecode weaving from directories or zip files (like classpath).
  112. |classpath, classpathRef (xref:#antTasks-iajc-paths[Path]) |The
  113. classpath used by the sources being compiled. When compiling aspects,
  114. include the same version of the `aspectjrt.jar`.
  115. |bootclasspath, bootclasspathRef (xref:#antTasks-iajc-paths[Path]) |The
  116. bootclasspath specifies types to use instead of the invoking VM's when
  117. seeking types during compilation.
  118. |extDirs, extDirsRef (xref:#antTasks-iajc-paths[Path]) |The extension
  119. directories to use instead of those in the invoking VM when seeking
  120. types during compilation.
  121. |aspectPath, aspectPathRef (xref:#antTasks-iajc-paths[Path]) |Similar to
  122. classpath, aspectpath contains read-only, binary aspect libraries that
  123. are woven into sources but not included in the output. `aspectpath`
  124. accepts jar/zip files (but, unlike classpath, not directories).
  125. |===
  126. *AjcTask (iajc) options for specifying output*
  127. [cols=",",options="header",]
  128. |===
  129. |Attribute |Description
  130. |destDir |The directory in which to place the generated class files.
  131. Only one of `destDir` and `outJar` may be set.
  132. |outJar |The zip file in which to place the generated output class
  133. files. Only one of `destDir` and `outJar` may be set.
  134. |copyInjars |(Deprecated/ignored; ajc does this.) If true, copy all
  135. non-.class files from input jar(s) to the output jar or destination
  136. directory after the compile (or incremental compile) completes. In
  137. forked mode, this copies only after the process completes, not after
  138. incremental compiles.
  139. |sourceRootCopyFilter |When set, copy all files from the sourceroot
  140. directories to the output jar or destination directory except those
  141. specified in the filter pattern. The pattern should be compatible with
  142. an Ant fileset excludes filter; when using this, most developers pass
  143. `**/CVS/*,**/*.java` to exclude any CVS directories or source files. See
  144. `inpathDirCopyFilter`. Requires `destDir` or `outJar`.
  145. |inpathDirCopyFilter |When set, copy all files from the inpath
  146. directories to the output jar or destination directory except those
  147. specified in the filter pattern. The pattern should be compatible with
  148. an Ant fileset excludes filter; when using this, most developers pass
  149. `**/CVS/*,**/*.java,**/*.class` to exclude any CVS directories, source
  150. files, or unwoven .class files. (If `**/*.class` is not specified, it
  151. will be prepended to the filter.) See `sourceRootCopyFilter`. (Note that
  152. ajc itself copies all resources from input jar/zip files on the inpath.)
  153. Requires `destDir` or `outJar`.
  154. |===
  155. *AjcTask (iajc) options for specifying compiler behavior*
  156. [cols=",",options="header",]
  157. |===
  158. |Attribute |Description
  159. |fork |Run process in another VM. This gets the forking classpath either
  160. explicitly from a `forkclasspath` entry or by searching the task or
  161. system/Ant classpath for the first readable file with a name of the form
  162. `aspectj{-}tools{.*}.jar`. When forking you can specify the amount of
  163. memory used with `maxmem`. Fork cannot be used in incremental mode,
  164. unless using a tag file.
  165. |forkclasspath, forkclasspathRef (xref:#antTasks-iajc-paths[Path])
  166. |Specify the classpath to use for the compiler when forking.
  167. |maxmem |The maximum memory to use for the new VM when fork is true.
  168. Values should have the same form as accepted by the VM, e.g., "128m".
  169. |incremental |incremental mode: Build once, then recompile only required
  170. source files when user provides input. Requires that source files be
  171. specified only using `sourceroots`. Incompatible with forking.
  172. |tagfile |incremental mode: Build once, then recompile only required
  173. source files when the tag file is updated, finally exiting when tag file
  174. is deleted. Requires that source files be specified only using
  175. `sourceroots`.
  176. |X |Set experimental option(s), using comma-separated list of accepted
  177. options Options should not contain the leading X. Some commonly-used
  178. experimental options have their own entries. The other permitted ones
  179. (currently) are serializableAspects, incrementalFile, lazyTjp,
  180. reweavable, notReweavable, noInline, terminateAfterCompilation,
  181. ajruntimelevel:1.2, and ajruntimelevel:1.5. Of these, some were
  182. deprecated in AspectJ 5 (reweavable, terminateAfterCompilation, etc.).
  183. |XterminateAfterCompilation |Terminates before the weaving process,
  184. dumping out unfinished class files.
  185. |===
  186. *AjcTask (iajc) options for specifying compiler side-effects and
  187. messages*
  188. [cols=",",options="header",]
  189. |===
  190. |Attribute |Description
  191. |emacssym |If true, emit `.ajesym` symbol files for Emacs support.
  192. |crossref |If true, emit `.ajsym` file into the output directory.
  193. |verbose |If true, log compiler verbose messages as Project.INFO during
  194. the compile.
  195. |logCommand |If true, log compiler command elements as Project.INFO
  196. (rather than the usual Project.VERBOSE level).
  197. |Xlistfileargs |If true, emit list of file arguments during the compile
  198. (but behaves now like verbose).
  199. |version |If true, do not compile - just print AspectJ version.
  200. |help |If true, just print help for the command-line compiler.
  201. |Xlintwarnings |Same as `xlint:warning`: if true, set default level of
  202. all language usage messages to warning.
  203. |Xlint |Specify default level of all language usage messages to one of
  204. [`error warning ignore`].
  205. |XlintFile |Specify property file containing `name:level` associations
  206. setting level for language messages emitted during compilation. Any
  207. levels set override the default associations in
  208. `org/aspectj/weaver/XLintDefault.properties`.
  209. |failonerror |If true, throw BuildException to halt build if there are
  210. any compiler errors. If false, continue notwithstanding compile errors.
  211. Defaults to `true`.
  212. |messageHolderClass |Specify a class to use as the message holder for
  213. the compile process. The entry must be a fully-qualified name of a class
  214. resolveable from the task classpath complying with the
  215. `org.aspectj.bridge.IMessageHolder` interface and having a public
  216. no-argument constructor.
  217. |showWeaveInfo |If true, emit weaver messages. Defaults to `false`.
  218. |===
  219. *AjcTask (iajc) options for specifying Eclipse compiler options*
  220. [cols=",",options="header",]
  221. |===
  222. |Attribute |Description
  223. |nowarn |If true, same as `warn:none`.
  224. |deprecation |If true, same as `warn:deprecation`
  225. |warn |One or more comma-separated warning specifications from
  226. [`constructorName packageDefaultMethod deprecation,
  227. maskedCatchBlocks unusedLocals unusedArguments,
  228. unusedImports syntheticAccess assertIdentifier`].
  229. |debug |If true, same as `debug:lines,vars,source`
  230. |debugLevel |One or more comma-separated debug specifications from
  231. [`lines vars source`].
  232. |PreserveAllLocals |If true, code gen preserves all local variables (for
  233. debug purposes).
  234. |noimporterror |If true, emit no errors for unresolved imports.
  235. |referenceinfo |If true, compute reference info.
  236. |log |File to log compiler messages to.
  237. |encoding |Default source encoding format (per-file encoding not
  238. supported in Ant tasks).
  239. |proceedOnError |If true, keep compiling after errors encountered,
  240. dumping class files with problem methods.
  241. |progress |If true, emit progress (requires log).
  242. |time |If true, display speed information.
  243. |target |Specify target class file format as one of [`1.1 1.2`].
  244. Defaults to 1.1 class file.
  245. |source |Set source compliance level to one of [`1.3 1.4 1.5`] (default
  246. is 1.4). 1.3 implies -source 1.3 and -target 1.1. 1.4 implies -source
  247. 1.4 and -target 1.2. 1.5 implies -source 1.5 and -target 1.5.
  248. |source |Set source assertion mode to one of [`1.3 1.4`]. Default
  249. depends on compliance mode.
  250. |===
  251. [[antTasks-nested-includes]]
  252. === AjcTask matching parameters specified as nested elements
  253. This task forms an implicit FileSet and supports all attributes of
  254. `fileset` (dir becomes srcdir) as well as the nested `include`,
  255. `exclude`, and `patternset` elements. These can be used to specify
  256. source files. However, it is better to use `sourceroots` to specify
  257. source directories unless using filters to exclude some files from
  258. compilation.
  259. [[antTasks-iajc-paths]]
  260. === AjcTask Path-like Structures
  261. Some parameters are path-like structures containing one or more
  262. elements; these are `sourceroots`, `argfiles`, `injars`, `inpath`,
  263. `classpath`, `bootclasspath`, `forkclasspath`, and `aspectpath`. In all
  264. cases, these may be specified as nested elements, something like this:
  265. [source, xml]
  266. ....
  267. <iajc {attributes..} />
  268. <{name}>
  269. <pathelement path="{first-location}"/>
  270. <pathelement path="{second-location}"/>
  271. ...
  272. <{name}>
  273. ...
  274. </iajc>
  275. ....
  276. As with other Path-like structures, they may be defined elsewhere and
  277. specified using the refid attribute:
  278. [source, xml]
  279. ....
  280. <path id="aspect.path">
  281. <pathelement path="${home}/lib/persist.jar"/>
  282. <pathelement path="${home}/lib/trace.jar"/>
  283. </path>
  284. ...
  285. <iajc {attributes..} />
  286. <aspectpath refid="aspect.path"/>
  287. ...
  288. </iajc>
  289. ....
  290. The task also supports an attribute `\{name}ref` for each such parameter.
  291. E.g., for `aspectpath`:
  292. [source, xml]
  293. ....
  294. <iajc {attributes..} aspectpathref="aspect.path"/>
  295. ....
  296. [[antTasks-iajc-sample]]
  297. === Sample of iajc task
  298. A minimal build script defines the task and runs it, specifying the
  299. sources:
  300. [source, xml]
  301. ....
  302. <project name="simple-example" default="compile" >
  303. <taskdef
  304. resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties">
  305. <classpath>
  306. <pathelement location="${home.dir}/tools/aspectj/lib/aspectjtools.jar"/>
  307. </classpath>
  308. </taskdef>
  309. <target name="compile" >
  310. <iajc sourceroots="${home.dir}/ec/project/src"
  311. classpath="${home.dir}/tools/aspectj/lib/aspectjrt.jar"/>
  312. </target>
  313. </project>
  314. ....
  315. Below is script with most everything in it. The compile process...
  316. [arabic]
  317. . Runs in incremental mode, recompiling when the user hits return;
  318. . Reads all the source files from two directories;
  319. . Reads binary .class files from input jar and directory;
  320. . Uses a binary aspect library for persistence;
  321. . Outputs to an application jar; and
  322. . Copies resources from the source directories and binary input jar and
  323. directories to the application jar.
  324. When this target is built, the compiler will build once and then wait
  325. for input from the user. Messages are printed as usual. When the user
  326. has quit, then this runs the application.
  327. [source, xml]
  328. ....
  329. <target name="build-test" >
  330. <iajc outjar="${home.dir}/output/application.jar"
  331. sourceRootCopyFilter="**/CVS/*,**/*.java"
  332. inpathDirCopyFilter="**/CVS/*,**/*.java,**/*.class"
  333. incremental="true" >
  334. <sourceroots>
  335. <pathelement location="${home.dir}/ec/project/src"/>
  336. <pathelement location="${home.dir}/ec/project/testsrc"/>
  337. </sourceroots>
  338. <inpath>
  339. <pathelement location="${home.dir}/build/module.jar"/>
  340. <pathelement location="${home.dir}/build/binary-input"/>
  341. </inpath>
  342. <aspectpath>
  343. <pathelement location="${home.dir}/ec/int/persist.jar"/>
  344. </aspectpath>
  345. <classpath>
  346. <pathelement location="${home.dir}/tools/aspectj/lib/aspectjrt.jar"/>
  347. </classpath>
  348. </iajc>
  349. <java classname="org.smart.app.Main">
  350. <classpath>
  351. <pathelement location="${home.dir}/tools/aspectj/lib/aspectjrt.jar"/>
  352. <pathelement location="${home.dir}/ec/int/persist.jar"/>
  353. <pathelement location="${home.dir}/output/application.jar"/>
  354. </classpath>
  355. </java>
  356. </target>
  357. ....
  358. For an example of a build script, see ../examples/build.xml.
  359. [[antTasks-iajc-uptodate]]
  360. === Avoiding clean compiles
  361. Unlike javac, the ajc compiler always processes all input because new
  362. aspects can apply to updated classes and vice-versa. However, in the
  363. case where no files have been updated, there is no reason to recompile
  364. sources. One way to implement that is with an explicit dependency check
  365. using the uptodate task:
  366. [source, xml]
  367. ....
  368. <target name="check.aspects.jar">
  369. <uptodate property="build.unnecessary"
  370. targetfile="${aspects.module-jar}" >
  371. <srcfiles dir="${src1}" includes="**/*.aj"/>
  372. <srcfiles dir="${src2}/" includes="**/*.aj"/>
  373. </uptodate>
  374. </target>
  375. <target name="compile.aspects" depends="prepare,check.aspects.jar"
  376. unless="build.unnecessary">
  377. <iajc ...
  378. ....
  379. When using this technique, be careful to verify that binary input jars
  380. are themselves up-to-date after they would have been modified by any
  381. build commands.
  382. === Programmatically handling compiler messages
  383. Users may specify a message holder to which the compiler will pass all
  384. messages as they are generated. This will override all of the normal
  385. message printing, but does not prevent the task from failing if
  386. exceptions were thrown or if failonerror is true and the compiler
  387. detected errors in the sources.
  388. Handling messages programmatically could be useful when using the
  389. compiler to verify code. If aspects consist of declare [error|warning],
  390. then the compiler can act to detect invariants in the code being
  391. processed. For code to compare expected and actual messages, see the
  392. AspectJ testing module (which is not included in the binary
  393. distribution).
  394. [[antTasks-adapter]]
  395. == Ajc11CompilerAdapter (javac)
  396. This CompilerAdapter can be used in javac task calls by setting the
  397. `build.compiler` property. This enables users to to easily switch
  398. between the Javac and AspectJ compilers. However, because there are
  399. differences in source file handling between the Javac task and the ajc
  400. compiler, not all Javac task invocations can be turned over to iajc.
  401. However, ajc can compile anything that Javac can, so it should be
  402. possible for any given compile job to restate the Javac task in a way
  403. that can be handled by iajc/ajc.
  404. [[antTasks-adapter-sample]]
  405. === Sample of compiler adapter
  406. To build using the adapter, put the `aspectjtools.jar` on the system/ant
  407. classpath (e.g., in `$\{ANT_HOME}/lib`) and define the `build.compiler`
  408. property as the fully-qualified name of the class,
  409. `org.aspectj.tools.ant.taskdefs.Ajc11CompilerAdapter`.
  410. The AspectJ compiler should run for any compile using the Javac task
  411. (for options, see the Ant documentation for the Javac task). For
  412. example, the call below passes all out-of-date source files in the
  413. `src/org/aspectj` subdirectories to the `ajc` command along with the
  414. destination directory:
  415. [source, text]
  416. ....
  417. -- command:
  418. cp aspectj1.1/lib/aspectjtools.jar ant/lib
  419. ant/bin/ant -Dbuild.compiler=org.aspectj.tools.ant.taskdefs.Ajc11CompilerAdapter ...
  420. -- task invocation in the build script:
  421. <javac srcdir="src" includes="org/aspectj/**/*.java" destdir="dest" />
  422. ....
  423. To pass ajc-specific arguments, use a compilerarg entry.
  424. [source, text]
  425. ....
  426. -- command
  427. Ant -Dbuild.compiler=org.aspectj.tools.ant.taskdefs.Ajc11CompilerAdapter
  428. -- build script
  429. <property name="ajc"
  430. value="org.aspectj.tools.ant.taskdefs.Ajc11CompilerAdapter"/>
  431. <javac srcdir="src" includes="org/aspectj/**/*.java" destdir="dest" >
  432. <compilerarg compiler="${ajc}" line="-argfile src/args.lst"/>
  433. <javac/>
  434. ....
  435. The Javac task does special handling of source files that can interfere
  436. with ajc. It removes any files that are not out-of-date with respect to
  437. the corresponding .class files. But ajc requires all source files, since
  438. an aspect may affect a source file that is not out of date. (For a
  439. solution to this, see the `build.compiler.clean` property described
  440. below.) Conversely, developers sometimes specify a source directory to
  441. javac, and let it search for files for types it cannot find. AspectJ
  442. will not do this kind of searching under the source directory (since the
  443. programmer needs to control which sources are affected). (Don't confuse
  444. the source directory used by Javac with the source root used by ajc; if
  445. you specify a source root to ajc, it will compile any source file under
  446. that source root (without exception or filtering).) To replace source
  447. dir searching in Javac, use an Ant filter to specify the source files.
  448. [[antTasks-adapter-options]]
  449. === Compiler adapter compilerarg options
  450. The adapter supports any ajc command-line option passed using
  451. compilerarg, as well as the following options available only in AjcTask.
  452. Find more details on the following options in
  453. xref:#antTasks-iajc[AjcTask (iajc)].
  454. * `-Xmaxmem`: set maximum memory for forking (also settable in javac).
  455. * `-Xlistfileargs`: list file arguments (also settable in javac).
  456. * `-Xfailonerror`: throw BuildException on compiler error (also settable
  457. in javac).
  458. * `-Xmessageholderclass`: specify fully-qualified name of class to use
  459. as the message holder.
  460. * `-Xcopyinjars`: copy resources from any input jars to output (default
  461. behavior since 1.1.1)
  462. * `-Xsourcerootcopyfilter \{filter}`: copy resources from source
  463. directories to output (minus files specified in filter)
  464. * `-Xtagfile \{file}`: use file to control incremental compilation
  465. * `-Xsrcdir \{dir}`: add to list of ajc source roots (all source files
  466. will be included).
  467. Special considerations when using Javac and compilerarg:
  468. * The names above may differ slightly from what you might expect from
  469. AjcTask; use these forms when specifying compilerarg.
  470. * By default the adapter will mimic the Javac task's copying of resource
  471. files by specifying `"**/CVS/*,**/*.java,**/*.aj"` for the sourceroot
  472. copy filter. To change this behavior, supply your own value (e.g.,
  473. `"**/*"` to copy nothing).
  474. * Warning - define the system property `build.compiler.clean` to compile
  475. all files, when available. Javac prunes the source file list of
  476. "up-to-date" source files based on the timestamps of corresponding
  477. .class files, and will not compile if no sources are out of date. This
  478. is wrong for ajc which requires all the files for each compile and which
  479. may refer indirectly to sources using argument files.
  480. +
  481. To work around this, set the global property `build.compiler.clean`.
  482. This tells the compiler adapter to delete all .class files in the
  483. destination directory and re-execute the javac task so javac can
  484. recalculate the list of source files. e.g.,
  485. +
  486. [source, text]
  487. ....
  488. Ant -Dbuild.compiler=org.aspectj.tools.ant.taskdefs.Ajc11CompilerAdapter
  489. -Dbuild.compiler.clean=anything ...
  490. ....
  491. +
  492. Caveats to consider when using this global `build.compiler.clean`
  493. property:
  494. [arabic]
  495. . If javac believes there are no out-of-date source files, then the
  496. adapter is never called and cannot clean up, and the "compile" will
  497. appear to complete successfully though it did nothing.
  498. . Cleaning will makes stepwise build processes fail if they depend on
  499. the results of the prior compilation being in the same directory, since
  500. cleaning deletes all .class files.
  501. . This clean process only permits one compile process at a time for each
  502. destination directory because it tracks recursion by writing a tag file
  503. to the destination directory.
  504. . When running incrementally, the clean happens only before the initial
  505. compile.
  506. [[antTasks-ajc]]
  507. == Ajc10 (ajc)
  508. This task handles the same arguments as those used by the AspectJ 1.0
  509. task. This should permit those with existing build scripts using the Ajc
  510. Ant task to continue using the same scripts when compiling with 1.1.
  511. This will list any use of options no longer supported in 1.1 (e.g.,
  512. `lenient, strict, workingdir, preprocess, usejavac`,...), and does not
  513. provide access to the new features of AspectJ 1.1. (Developers using
  514. AspectJ 1.1 only should upgrade their scripts to use AjcTask instead.
  515. This will not work for AspectJ 1.2 or later.)
  516. [[antTasks-ajc-options]]
  517. === Ajc10 (ajc) Options
  518. Most attributes and nested elements are optional. The compiler requires
  519. that the same version of `aspectjrt.jar` be specified on the classpath,
  520. and that some sources be be specified (using one or more of `argfiles`
  521. and `srcdir` (with patterns)).
  522. Boolean parameters default to `false` unless otherwise stated.
  523. .AjcTask (ajc) options for specifying sources
  524. [cols=",",options="header",]
  525. |===
  526. |Attribute |Description
  527. |srcdir |The base directory of the java files. See
  528. |destdir |The target directory for the output .class files
  529. |includes |Comma-separated list of patterns of files that must be
  530. included. No files are included when omitted.
  531. |includesfile |The path to a file containing include patterns.
  532. |excludes |Comma-separated list of patterns of files that must be
  533. excluded. No files (except default excludes) are excluded when omitted.
  534. |excludesfile |The path to a file containing exclude patterns.
  535. |defaultexcludes |If true, then default excludes are used. Default
  536. excludes are used when omitted (i.e., defaults to `true`).
  537. |classpath, classpathref |The classpath to use, optionally given as a
  538. reference to a classpath Path element defined elsewhere.
  539. |bootclasspath, bootclasspathref |The bootclasspath to use, optionally
  540. given as a reference to a bootclasspath Path element defined elsewhere.
  541. |extdirs |Paths to directories containting installed extensions.
  542. |debug |If true, emit debug info in the .class files.
  543. |deprecation |If true, emit messages about use of deprecated API.
  544. |verbose |Emit compiler status messages during the compile.
  545. |version |Emit version information and quit.
  546. |failonerror |If true, throw BuildException to halt build if there are
  547. any compiler errors. If false, continue notwithstanding compile errors.
  548. Defaults to `true`.
  549. |source |Value of -source option - ignored unless `1.4`.
  550. |===
  551. .Parameters ignored by the old ajc taskdef, but now supported or buggy
  552. [cols=",,",options="header",]
  553. |===
  554. |Attribute |Description |Supported?
  555. |encoding |Default encoding of source files. |yes
  556. |optimize |Whether source should be compiled with optimization. |yes?
  557. |target |Generate class files for specific VM version, one of
  558. [`1.1 1.2`]. |yes
  559. |depend |Enables dependency-tracking. |no
  560. |includeAntRuntime |Whether to include the Ant run-time libraries. |no
  561. |includeJavaRuntime |Whether to include the run-time libraries from the
  562. executing VM. |no
  563. |threads |Multi-threaded compilation |no
  564. |===
  565. The following table shows that many of the unique parameters in AspectJ
  566. 1.0 are no longer supported.
  567. .Parameters unique to ajc
  568. [cols=",",options="header",]
  569. |===
  570. |Attribute |Description
  571. |X |deprecated X options include reweavable (on by default)
  572. reweavable:compress (compressed by default)
  573. |emacssym |Generate symbols for Emacs IDE support.
  574. |argfiles |A comma-delimited list of argfiles that contain a
  575. line-delimited list of source file paths (absolute or relative to the
  576. argfile).
  577. |===
  578. ==== argfiles - argument list files
  579. An argument file is a file (usually `\{file}.lst`) containing a list of
  580. source file paths (absolute or relative to the argfile). You can use it
  581. to specify all source files to be compiled, which ajc requires to avoid
  582. searching every possible source file in the source path when building
  583. aspects. If you specify an argfile to the ajc task, it will not include
  584. all files in any specified source directory (which is the default
  585. behavior for the Javac task when no includes are specified). Conversely,
  586. if you specify excludes, they will be removed from the list of files
  587. compiled even if they were specified in an argument file.
  588. The compiler also accepts arguments that are not source files, but the
  589. IDE support for such files varies, and Javac does not support them. Be
  590. sure to include exactly one argument on each line.
  591. [[antTasks-ajc-nested]]
  592. === Ajc10 parameters specified as nested elements
  593. This task forms an implicit FileSet and supports all attributes of
  594. `fileset` (dir becomes srcdir) as well as the nested `include`,
  595. `exclude`, and `patternset` elements. These can be used to specify
  596. source files.
  597. ``ajc``'s `srcdir`, `classpath`, `bootclasspath`, `extdirs`, and `jvmarg`
  598. attributes are path-like structures and can also be set via nested
  599. `src`, `classpath`, `bootclasspath`, `extdirs`, and `jvmargs`
  600. elements, respectively.
  601. [[antTasks-ajc-sample]]
  602. === Sample of ajc task
  603. Following is a declaration for the ajc task and a sample invocation that
  604. uses the ajc compiler to compile the files listed in `default.lst` into
  605. the dest dir:
  606. [source, xml]
  607. ....
  608. <project name="example" default="compile" >
  609. <taskdef name="ajc"
  610. classname="org.aspectj.tools.ant.taskdefs.Ajc10" >
  611. <!-- declare classes needed to run the tasks and tools -->
  612. <classpath>
  613. <pathelement location="${home.dir}/tools/aspectj/lib/aspectjtools.jar"/>
  614. </classpath>
  615. </taskdef>
  616. <target name="compile" >
  617. <mkdir dir="dest" />
  618. <ajc destdir="dest" argfiles="default.lst" >
  619. <!-- declare classes needed to compile the target files -->
  620. <classpath>
  621. <pathelement location="${home.dir}/tools/aspectj/lib/aspectjrt.jar"/>
  622. </classpath>
  623. </ajc>
  624. </target>
  625. </project>
  626. ....
  627. This build script snippet
  628. [source, xml]
  629. ....
  630. <ajc srcdir="${src}"
  631. destdir="${build}"
  632. argfiles="demo.lst"
  633. />
  634. ....
  635. compiles all .java files specified in the demo.lst and stores the .class
  636. files in the $\{build} directory. Unlike the Javac task, the includes
  637. attribute is empty by default, so only those files specified in demo.lst
  638. are included.
  639. This next example
  640. [source, xml]
  641. ....
  642. <ajc srcdir="${src}"
  643. destdir="${build}"
  644. includes="spacewar/*,coordination/*"
  645. excludes="spacewar/Debug.java"
  646. />
  647. ....
  648. compiles .java files under the `$\{src}` directory in the spacewar and
  649. coordination packages, and stores the .class files in the `$\{build}`
  650. directory. All source files under spacewar/ and coordination/ are used,
  651. except Debug.java.
  652. See ../examples/build.xml for an example build script.
  653. [[antTasks-problems]]
  654. == Isolating problems running the Ant tasks
  655. If you have problems with the tasks not solved by the documentation,
  656. please try to see if you have the same problems when running ajc
  657. directly on the command line.
  658. * If the problem occurs on the command line also, then the problem is
  659. not in the task. (It may be in the tools; please send bug reports.)
  660. * If the problem does not occur on the command line, then it may lie in
  661. the parameters you are supplying in Ant or in the task's handling of
  662. them.
  663. * If the build script looks correct and the problem only occurs when
  664. building from Ant, then please send a report (including your build file,
  665. if possible).
  666. [[antTasks-knownProblems]]
  667. === Known issues with the Ant tasks
  668. For the most up-to-date information on known problems, see the
  669. https://bugs.eclipse.org/bugs[bug database] for unresolved
  670. https://bugs.eclipse.org/bugs/buglist.cgi?&product=AspectJ&component=Compiler&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED[compiler
  671. bugs] or
  672. https://bugs.eclipse.org/bugs/buglist.cgi?&product=AspectJ&component=Ant&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED[taskdef
  673. bugs] .
  674. When running Ant build scripts under Eclipse 2.x variants, you will get
  675. a VerifyError because the Eclipse Ant support fails to isolate the Ant
  676. runtime properly. To run in this context, set up iajc to fork (and use
  677. forkclasspath). Eclipse 3.0 will fork Ant processes to avoid problems
  678. like this.
  679. Memory and forking: Users email most often about the ajc task running
  680. out of memory. This is not a problem with the task; some compiles take a
  681. lot of memory, often more than similar compiles using javac.
  682. Forking is now supported in both the
  683. xref:#antTasks-adapter[Ajc11CompilerAdapter (javac)] and
  684. xref:#antTasks-iajc[AjcTask (iajc)], and you can set the maximum memory
  685. available. You can also not fork and increase the memory available to
  686. Ant (see the Ant documentation, searching for ANT_OPTS, the variable
  687. they use in their scripts to pass VM options, e.g., ANT_OPTS=-Xmx128m).
  688. [[antTasks-feedback]]
  689. === Ant task questions and bugs
  690. For questions, you can send email to aspectj-users@dev.eclipse.org. (Do
  691. join the list to participate!) We also welcome any bug reports, patches,
  692. and features; you can submit them to the bug database at
  693. https://bugs.eclipse.org/bugs using the AspectJ product and Ant
  694. component.