aboutsummaryrefslogtreecommitdiffstats
path: root/docs/dist/doc/ant-ajc-task.html
blob: 84a13c001d83bc72ab7e04036abc10cc7e972744 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
      
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <meta http-equiv="Content-Language" content="en-us">
   <title>AjcTask Ant Support for AspectJ 1.1</title>
</head>
<body>

<h2>
<a NAME="ajc"></a>AjcTask Ant Support for AspectJ 1.1</h2>
<small><a href="ant-tasks.html">AspectJ Ant Tasks</a></small>

<h3>
Description</h3>

This task uses the AspectJ<small><sup>tm</sup></small> 1.1 compiler 
<code>ajc</code>.

The AspectJ compiler can be used like 
 <a href="http://jakarta.apache.org/ant/manual/CoreTasks/javac.html">Javac</a>
to compile Java sources, but it can also compile AspectJ sources or 
weave binary aspects with Java bytecode.  It can run in normal "batch" mode
or in an "incremental" mode, where it only recompiles files it has to revisit.
For more information on <tt>ajc</tt>, see the links from 
the <a href="index.html">AspectJ docs home</a>,
especially the usage notes in
the <a href="devguide/devguide.html">Development Environment Guide</a>
for command-line mode of the compiler.

<p>
This task is named <tt>iajc</tt> now to avoid conflict with the 
1.0 task <tt>ajc</tt>, but the name may change to <tt>ajc</tt> in
the future.
<p>
See <a href="#compilerMessages">below</a> for 
an introduction to handling compiler messages programmatically.

<p>
<h3>
Parameters</h3>

The following table lists the supported parameters.
For any parameter specified as a Path, 
a single path can be specified directly as an attribute, 
multiple paths can be specified using a nested element of the same name,
and a common path can be reused by defining it as a global
and passing the id to the corresponding {name}ref attribute.
See <a href="#nestedElements">Nested Elements</a> below for more information.

<p>
Some sources must be specified, but all other attributes and
nested elements are optional
(except that the compiler requires <code>aspectjrt.jar</code> 
to be on the classpath).
<p>
<table BORDER CELLSPACING=0 CELLPADDING=2 >
<tr>
<td VALIGN=TOP><b>Attribute</b></td>

<td VALIGN=TOP><b>Description</b></td>

<td ALIGN=CENTER VALIGN=TOP><b>Required</b></td>
</tr>

<tr>
<th colspan="3">Specifying sources</th>
</tr>

<tr> 
<td VALIGN=TOP>argfiles, argfilesRef
 <br>(<a href="#nestedElements">Path</a>)
</td>
<td VALIGN=TOP>An argument file
contains a list of arguments read by the compiler.
Each line is read into one element of the argument
array and may include another argfile by reference.
</td>
<td ALIGN=CENTER VALIGN=TOP>No</td>
</tr>

<tr>
<td VALIGN=TOP>sourceRoots,
 sourceRootsRef
 <br>(<a href="#nestedElements">Path</a>)
</td>

<td VALIGN=TOP>
 Directories containing source files
 (ending with .java or .aj) to compile.
</td>
<td ALIGN=CENTER VALIGN=TOP>Yes, in incremental mode.</td>
</tr>


<tr>
<td VALIGN=TOP>srcdir
 <br>(<a href="#nestedElements">Path</a>)
</td>
<td VALIGN=TOP>Base directory of sources to compile,
	assuming there are <a href="#nestedElements">nested elements</a>
	for <code>includes</code> or <code>excludes</code>.
    This uses the Ant process for matching .java files
    and is not compatible with incremental mode.
    Unless using filters to limit the sources included,
    use <code>sourceroots</code> instead.
</td>
<td ALIGN=CENTER VALIGN=TOP>No</td>
</tr>

<tr>
<td VALIGN=TOP>injars, injarsRef
 <br>(<a href="#nestedElements">Path</a>)
</td>
<td VALIGN=TOP>
 Input zip files with .class file entries for bytecode weaving
</td>
<td ALIGN=CENTER VALIGN=TOP>No</td>
</tr>

<tr>
<td VALIGN=TOP>classpath, classpathRef
 <br>(<a href="#nestedElements">Path</a>)
</td>
<td VALIGN=TOP>The classpath required by the input being compiled.
    Strictly-speaking not required, but the compiler
    insists <code>aspectjrt.jar</code> be on the classpath.
</td>
<td ALIGN=CENTER VALIGN=TOP>No</td>
</tr>

<tr>
<td VALIGN=TOP>Xbootclasspath
</td>
<td VALIGN=TOP><code>ajc</code> does not support a -bootclasspath option,
but this tries to fake it by adding these Path entries
to the start of the classpath.
</td>
<td ALIGN=CENTER VALIGN=TOP>No</td>
</tr>

<tr>
<td VALIGN=TOP>Xextdirs
</td>
<td VALIGN=TOP><code>ajc</code> does not support a -extdirs option,
but this tries to fake it by adding all .jar or .zip files in
the Path entries to the classpath after the so-call bootclasspath
and before the user classpath.
</td>
<td ALIGN=CENTER VALIGN=TOP>No</td>
</tr>

<tr>
<td VALIGN=TOP>aspectpath, aspectpathref
 <br>(<a href="#nestedElements">Path</a>)
</td>
<td VALIGN=TOP>Similar to classpath, aspectpath contains
read-only, binary aspect libraries; unlike classpath,
it only accepts jar/zip files, not directories.
</td>
<td ALIGN=CENTER VALIGN=TOP>No</td>
</tr>

<tr>
<th colspan="3">Specifying output</th>
<tr> 
<td VALIGN=TOP>destdir</td>
<td VALIGN=TOP>The directory in which to place the generated class files.
Conflicts with <code>outjar</code>.
</td>
<td ALIGN=CENTER VALIGN=TOP>No</td>
</tr>

<tr> 
<td VALIGN=TOP>outjar</td>
<td VALIGN=TOP>The zip file in which to place the generated output class files.
Conflicts with <code>destdir</code>.
</td>
<td ALIGN=CENTER VALIGN=TOP>No</td>
</tr>

<tr> 
  <td VALIGN=TOP>copyInjars</td>
  <td VALIGN=TOP>Copy all non-.class files from input jar(s) to the output jar
   or destination directory
   after the compile (or incremental compile) completes
   -- defaults to <tt>false</tt>.
   </td> 
   <td ALIGN=CENTER VALIGN=TOP>No</td>
  </tr>

<tr> 
  <td VALIGN=TOP>sourceRootCopyFilter</td>
  <td VALIGN=TOP>When set, copy all files from the sourceroot directories
   to the output jar or destination directory
   except those specified in the filter pattern.
   The pattern should be compatible with an Ant fileset excludes filter;
   when using this, most developers pass 
   <code>**/CVS/*,**/*.java</code> to exclude
   any CVS directories or source files.
   </td> 
   <td ALIGN=CENTER VALIGN=TOP>No</td>
  </tr>

<tr>
<th colspan="3">Specifying compiler behavior</th>
</tr>

<tr>
  <td VALIGN=TOP>incremental</td>
  <td VALIGN=TOP>incremental mode: 
  Build once, then recompile only required  source files
  when user provides input.
  Requires that source files be specified only using
  <code>sourceroots</code>.
  Defaults to <tt>false</tt>.
  <td ALIGN=CENTER VALIGN=TOP>No</td>
  </tr>

<tr> 
  <td VALIGN=TOP>tagfile</td>
  <td VALIGN=TOP>incremental mode:
  		Build once, then recompile only required source files
  		when the tag file is updated,
  		finally exiting when tag file is deleted
  		(also requires <code>sourceroots</code>).
      </td>
   <td ALIGN=CENTER VALIGN=TOP>No</td>
  </tr>

<tr> 
  <td VALIGN=TOP>X</td>
  <td VALIGN=TOP>Set experimental option(s), using comma-separated list
     of accepted options (unlisted here).
     Options should not contain the leading X.
     XLint options should be specified using the xlint... entries.
     </td> 
   <td ALIGN=CENTER VALIGN=TOP>No</td>
  </tr>

<tr>
<td VALIGN=TOP>Xnoweave</td>
<td VALIGN=TOP>Experimental option to 
produce binaries that can only be used as input for the
-injars option --
defaults to <tt>false</tt>.</td>
<td ALIGN=CENTER VALIGN=TOP>No</td>
</tr>


<tr>
<th colspan="3">Specifying compiler side-effects and messages</th>
</tr>

<tr>
<td VALIGN=TOP>emacssym</td>
<td VALIGN=TOP>Whether to emit <tt>.ajesym</tt> symbol files for Emacs support;
defaults to <tt>false</tt>.</td>
<td ALIGN=CENTER VALIGN=TOP>No</td>
</tr>

<tr>
<td VALIGN=TOP>verbose</td>
<td VALIGN=TOP>Whether to emit compiler status messages during the compile;
defaults to <tt>false</tt>.</td>
<td ALIGN=CENTER VALIGN=TOP>No</td>
</tr>

<tr>
<td VALIGN=TOP>Xlistfileargs</td>
<td VALIGN=TOP>Whether to emit list of file arguments during the compile
(but behaves now like verbose); 
defaults to <tt>false</tt></td>
<td ALIGN=CENTER VALIGN=TOP>No</td>
</tr>

<tr>
<td VALIGN=TOP>version</td>
<td VALIGN=TOP>If true, do not compile - just print AspectJ version;
defaults to <tt>false</tt>.</td>
<td ALIGN=CENTER VALIGN=TOP>No</td>
</tr>

<tr>
<td VALIGN=TOP>help</td>
<td VALIGN=TOP>If true, just print help for the command-line compiler;
defaults to <tt>false</tt>.</td>
<td ALIGN=CENTER VALIGN=TOP>No</td>
</tr>

<tr>
<td VALIGN=TOP>Xlintwarnings</td>
<td VALIGN=TOP>Same as <tt>xlint:warning</tt> - 
if enabled, set default level of all language usage messages to warning;
defaults to <tt>false</tt>.</td>
<td ALIGN=CENTER VALIGN=TOP>No</td>
</tr>

<tr>
<td VALIGN=TOP>Xlint</td>
<td VALIGN=TOP>Specify default level of all language usage messages
to one of (error, warning, ignore).
<td ALIGN=CENTER VALIGN=TOP>No</td>
</tr>

<tr>
<td VALIGN=TOP>Xlintfile</td>
<td VALIGN=TOP>Specify property file containing name:level 
associations setting level for language messages emitted
during compilation.  Any levels set override the default 
associations in 
<code>org/aspectj/weaver/XLintDefault.properties</code>.
</td>
<td ALIGN=CENTER VALIGN=TOP>No</td>
</tr>


<tr>
  <td VALIGN=TOP>failonerror</td>
  <td VALIGN=TOP>Whether the build continues notwithstanding compile errors; 
  defaults to <tt>true</tt>.&nbsp;</td>
  <td ALIGN=CENTER VALIGN=TOP>No</td>
  </tr>

<tr>
<td VALIGN=TOP>messageholderclass</td>
<td VALIGN=TOP>Specify a class to use as the message holder for the compile
process.  The entry must be a fully-qualified name of a class resolveable 
from the task classpath complying with the <tt>org.aspectj.bridge.IMessageHolder</tt>
interface and having a public no-argument constructor.</td>
<td ALIGN=CENTER VALIGN=TOP>No</td>
</tr>


<tr>
<th colspan="3">Eclipse compiler options</th>
</tr>

<tr>
  <td VALIGN=TOP>nowarn</td>
  <td VALIGN=TOP>Same as <tt>warn:none</tt>; 
  defaults to <tt>false</tt>.&nbsp;</td>
  <td ALIGN=CENTER VALIGN=TOP>No</td>
  </tr>

<tr>
  <td VALIGN=TOP>deprecation</td>
  <td VALIGN=TOP>Same as <tt>warn:deprecation</tt>; 
  defaults to <tt>false</tt>.&nbsp;</td>
  <td ALIGN=CENTER VALIGN=TOP>No</td>
  </tr>

<tr>
  <td VALIGN=TOP>warn</td>
  <td VALIGN=TOP>One or more comma-separated warning specifications: 
<tt>constructorName</tt>, 
<tt>packageDefaultMethod</tt>, 
<tt>deprecation</tt>, 
<tt>maskedCatchBlocks</tt>, 
<tt>unusedLocals</tt>, 
<tt>unusedArguments</tt>, 
<tt>unusedImports</tt>, 
<tt>syntheticAccess</tt>, or
<tt>assertIdentifier</tt>.</td>
  <td ALIGN=CENTER VALIGN=TOP>No</td>
  </tr>

<tr>
  <td VALIGN=TOP>debug</td>
  <td VALIGN=TOP>Same as <tt>debug:lines,vars,source</tt></td>
  <td ALIGN=CENTER VALIGN=TOP>No</td>
  </tr>

<tr>
  <td VALIGN=TOP>debuglevel</td>
  <td VALIGN=TOP>One or more comma-separated debug specifications:
     <tt>lines</tt>, 
     <tt>vars</tt>, or 
     <tt>source</tt>.
     </td>
  <td ALIGN=CENTER VALIGN=TOP>No</td>
  </tr>

<tr>
  <td VALIGN=TOP>PreserveAllLocals</td>
  <td VALIGN=TOP>Code gen preserves all local variables (for debug purposes); 
  defaults to <tt>false</tt>.&nbsp;</td>
  <td ALIGN=CENTER VALIGN=TOP>No</td>
  </tr>

<tr>
  <td VALIGN=TOP>noimporterror</td>
  <td VALIGN=TOP>No errors for unresolved imports; 
  defaults to <tt>false</tt>.&nbsp;</td>
  <td ALIGN=CENTER VALIGN=TOP>No</td>
  </tr>

<tr>
  <td VALIGN=TOP>referenceinfo</td>
  <td VALIGN=TOP>Compute reference info; 
  defaults to <tt>false</tt>.&nbsp;</td>
  <td ALIGN=CENTER VALIGN=TOP>No</td>
  </tr>

<tr>
  <td VALIGN=TOP>log</td>
  <td VALIGN=TOP>File to log compiler messages to.</td>
  <td ALIGN=CENTER VALIGN=TOP>No</td>
  </tr>

<tr>
  <td VALIGN=TOP>encoding</td>
  <td VALIGN=TOP>Default source encoding format</td>
  <td ALIGN=CENTER VALIGN=TOP>No</td>
  </tr>

<tr>
  <td VALIGN=TOP>proceedonerror</td>
  <td VALIGN=TOP>Keep compiling when error, dumping class files with problem methods; 
  defaults to <tt>false</tt>.&nbsp;</td>
  <td ALIGN=CENTER VALIGN=TOP>No</td>
  </tr>

<tr>
  <td VALIGN=TOP>progress</td>
  <td VALIGN=TOP>Show progress (requires log); 
  defaults to <tt>false</tt>.&nbsp;</td>
  <td ALIGN=CENTER VALIGN=TOP>No</td>
  </tr>

<tr>
  <td VALIGN=TOP>time</td>
  <td VALIGN=TOP>Display speed information; 
  defaults to <tt>false</tt>.&nbsp;</td>
  <td ALIGN=CENTER VALIGN=TOP>No</td>
  </tr>

<!--
<tr>
  <td VALIGN=TOP>noexit</td>
  <td VALIGN=TOP>Disable System.exit; defaults to <tt>true</tt>.
  (<em>If false, this kills the Ant process</em>;
       to halt compile gracefully, use <tt>failonerror</tt>);
  &nbsp;</td>
  <td ALIGN=CENTER VALIGN=TOP>No</td>
  </tr>
-->
<tr>
  <td VALIGN=TOP>target</td>
  <td VALIGN=TOP>Specify target class file format (must be "1.1" or "1.2"); 
  defaults to 1.1 class file.&nbsp;</td>
  <td ALIGN=CENTER VALIGN=TOP>No</td>
  </tr>

<tr>
  <td VALIGN=TOP>compliance</td>
  <td VALIGN=TOP>Set "1.3" or "1.4" source compliance level 
  (e.g., no import from default package in 1.4); 
  defaults to 1.3 compliance level.&nbsp;</td>
  <td ALIGN=CENTER VALIGN=TOP>No</td>
  </tr>

<tr>
  <td VALIGN=TOP>source</td>
  <td VALIGN=TOP>Source assertion mode ("1.3" or "1.4"); 
  default depends on compliance mode.&nbsp;</td>
  <td ALIGN=CENTER VALIGN=TOP>No</td>
  </tr>

</table>

<br>&nbsp;
<a name="nestedElements"></a>
<h3>
Parameters specified as nested elements</h3>
This task forms an implicit 
<a href="http://jakarta.apache.org/ant/manual/CoreTypes/fileset.html">FileSet</a>
and supports all attributes of <tt>&lt;fileset></tt> 
(<tt>dir</tt> becomes <tt>srcdir</tt>)
as well as the nested
<tt>&lt;include></tt>, <tt>&lt;exclude></tt>,
and <tt>&lt;patternset></tt> elements.
These can be used to specify source files.
However, we recommend using <code>sourceRoots</code>
to specify source directories
unless using filters to exclude some files from compilation.
<p>
Some parameters are path-like structures containing one or
more elements; these are 
<tt>sourceroots</tt>,
<tt>argfiles</tt>,
<tt>injars</tt>,
<tt>classpath</tt>, and
<tt>aspectpath</tt>.

In all cases, these may be specified as nested elements,
something like this:
<pre>
    &lt;iajc {attributes..} /&gt;
        &lt;{name}&gt;    
            &lt;pathelement path="{first-location}"/&gt;
            &lt;pathelement path="{second-location}"/&gt;
            ...
        &lt;{name}&gt;    
        ...
    &lt;/iajc&gt;
</pre>
As with other Path-like structures, they may be defined 
elsewhere and specified using the refid attribute:
<pre>
    &lt;path id="aspect.path"&gt;
        &lt;pathelement path="${home}/lib/persist.jar"/&gt;
        &lt;pathelement path="${home}/lib/trace.jar"/&gt;
    &lt;/path&gt;
    ...
    &lt;iajc {attributes..} /&gt;
        &lt;aspectpath refid="aspect.path"/&gt;    
        ...
    &lt;/iajc&gt;
</pre>

The task also supports an attribute 
<code>{name}ref</code> for each such parameter.  E.g., for 
<code>aspectpath</code>:
<pre>
    &lt;iajc {attributes..} aspectpathref="aspect.path"/&gt;    
</pre>

<p>

<h3>
Examples</h3>

See <a href="examples/build.xml">examples/build.xml</a>
for an example build script and
<a href="ant-tasks.html">ant-tasks.html</a>
for introductory scripts.

<a name="compilerMessages"></>
<h3>Programmatically handling compiler messages</h3>

Users may specify a message holder to which the compiler will
pass all messages as they are generated.  
This will override all of the normal
message printing, but does not prevent the task from failing 
if exceptions were thrown 
or if <tt>failonerror</tt> is true and the compiler detected errors in the sources.

<p>
Handling messages programmatically could be useful 
when using the compiler to verify code.
If aspects consist of declare [error|warning], then
the compiler can act to detect invariants in the code being processed.  
For code to compare expected and actual messages, see the AspectJ
testing module (which is not included in the binary distribution).
<p>

<hr>

</body>
</html>