blob: a2b5a7d3f22606662bfeec5f48dd8e77d08f2f4b [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Ajc11CompilerAdapter (javac)</title><link rel="stylesheet" href="aspectj-docs.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.44"><link rel="home" href="index.html" title="The AspectJtm Development Environment Guide"><link rel="up" href="antTasks.html" title="Chapter 4. AspectJ Ant Tasks"><link rel="previous" href="antTasks-iajc.html" title="AjcTask (iajc)"><link rel="next" href="antTasks-ajc.html" title="Ajc10 (ajc)"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Ajc11CompilerAdapter (javac)</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="antTasks-iajc.html">Prev</a>&nbsp;</td><th width="60%" align="center">Chapter 4. AspectJ Ant Tasks</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="antTasks-ajc.html">Next</a></td></tr></table><hr></div><div class="sect1"><a name="antTasks-adapter"></a><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="antTasks-adapter"></a>Ajc11CompilerAdapter (javac)</h2></div></div><p>
This CompilerAdapter can be used in javac task calls by setting the
<tt>build.compiler</tt> property.
This enables users to to easily switch between the Javac and AspectJ
compilers. However, because there are differences in source file
handling between the Javac task and the ajc compiler, not all
Javac task invocations can be turned over to iajc. However, ajc can
compile anything that Javac can, so it should be possible for any
given compile job to restate the Javac task in a way that can be
handled by iajc/ajc.
</p><div class="sect2"><a name="antTasks-adapter-sample"></a><div class="titlepage"><div><h3 class="title"><a name="antTasks-adapter-sample"></a>Sample of compiler adapter</h3></div></div><p>
To build using the adapter, put the
<tt>aspectjtools.jar</tt>
on the system/ant classpath (e.g., in
<tt>${ANT_HOME}/lib</tt>)
and define the
<tt>build.compiler</tt>
property as the fully-qualified name of the class,
<tt>org.aspectj.tools.ant.taskdefs.Ajc11CompilerAdapter</tt>.
</p><p>
The AspectJ compiler should run for any compile using the Javac task
(for options, see the Ant documentation for the Javac task).
For example, the call below passes all out-of-date source files in the
<tt>src/org/aspectj</tt> subdirectories to the
<tt>ajc</tt> command along with the destination directory:
</p><pre class="programlisting">
-- command:
cp aspectj1.1/lib/aspectjtools.jar ant/lib
ant/bin/ant -Dbuild.compiler=org.aspectj.tools.ant.taskdefs.Ajc11CompilerAdapter ...
-- task invocation in the build script:
&lt;javac srcdir="src" includes="org/aspectj/**/*.java" destdir="dest" /&gt;
</pre><p>
To pass ajc-specific arguments, use a compilerarg entry.
</p><pre class="programlisting">
-- command
Ant -Dbuild.compiler=org.aspectj.tools.ant.taskdefs.Ajc11CompilerAdapter
-- build script
&lt;property name="ajc"
value="org.aspectj.tools.ant.taskdefs.Ajc11CompilerAdapter"/&gt;
&lt;javac srcdir="src" includes="org/aspectj/**/*.java" destdir="dest" &gt;
&lt;compilerarg compiler="${ajc}" line="-argfile src/args.lst"/&gt;
&lt;javac/&gt;
</pre><p>The Javac task does special handling of source files that
can interfere with ajc. It removes any files that are not out-of-date
with respect to the corresponding .class files. But ajc requires all
source files, since an aspect may affect a source file that is not out
of date. (For a solution to this, see the <tt>build.compiler.clean</tt>
property described below.) Conversely, developers sometimes specify a source directory
to javac, and let it search for files for types it cannot find.
AspectJ will not do this kind of searching under the source directory
(since the programmer needs to control which sources are affected).
(Don't confuse the source directory used by Javac with the source root
used by ajc; if you specify a source root to ajc, it will compile
any source file under that source root (without exception or filtering).)
To replace source dir searching in Javac, use an Ant filter to specify
the source files.
</p></div><div class="sect2"><a name="antTasks-adapter-options"></a><div class="titlepage"><div><h3 class="title"><a name="antTasks-adapter-options"></a>Compiler adapter compilerarg options</h3></div></div><p>
The adapter supports any ajc command-line option passed using compilerarg,
as well as the following options available only in AjcTask.
Find more details on the following options in <a href="antTasks-iajc.html">AjcTask (iajc)</a>.
</p><div class="itemizedlist"><ul><li><p><a name="d0e2230"></a>
<tt>-Xmaxmem</tt>:
set maximum memory for forking (also settable in javac).
</p></li><li><p><a name="d0e2236"></a>
<tt>-Xlistfileargs</tt>:
list file arguments (also settable in javac).
</p></li><li><p><a name="d0e2242"></a>
<tt>-Xfailonerror</tt>:
throw BuildException on compiler error (also settable in javac).
</p></li><li><p><a name="d0e2248"></a>
<tt>-Xmessageholderclass</tt>:
specify fully-qualified name of class to use as the message holder.
</p></li><li><p><a name="d0e2254"></a>
<tt>-Xcopyinjars</tt>:
copy resources from any input jars to output
(default behavior since 1.1.1)
</p></li><li><p><a name="d0e2260"></a>
<tt>-Xsourcerootcopyfilter {filter}</tt>:
copy resources from source directories to output (minus files specified in filter)
</p></li><li><p><a name="d0e2266"></a>
<tt>-Xtagfile {file}</tt>:
use file to control incremental compilation
</p></li><li><p><a name="d0e2272"></a>
<tt>-Xsrcdir {dir}</tt>:
add to list of ajc source roots (all source files will be included).
</p></li></ul></div><p>
Special considerations when using Javac and compilerarg:
</p><div class="itemizedlist"><ul><li><p><a name="d0e2281"></a>
The names above may differ slightly from what you might expect
from AjcTask; use these forms when specifying compilerarg.
</p></li></ul></div><div class="itemizedlist"><ul><li><p><a name="d0e2285"></a>
By default the adapter will mimic the Javac task's copying of resource
files by specifying
<tt>"**/CVS/*,**/*.java,**/*.aj"</tt>
for the sourceroot copy filter.
To change this behavior, supply your own value
(e.g., <tt>"**/*"</tt> to copy nothing).
</p></li></ul></div><div class="itemizedlist"><ul><li><p><a name="d0e2295"></a>
Warning - define the system property
<tt>build.compiler.clean</tt> to compile all files,
when available.
Javac prunes the source file list of "up-to-date" source files
based on the timestamps of corresponding .class files,
and will not compile if no sources are out of date.
This is wrong for ajc which requires all the files for each compile
and which may refer indirectly to sources using argument files.
</p><p>
To work around this, set the global property
<tt>build.compiler.clean</tt>.
This tells the compiler adapter to delete all .class files
in the destination directory and re-execute the javac
task so javac can recalculate the list of source files. e.g.,
</p><pre class="programlisting">
Ant -Dbuild.compiler=org.aspectj.tools.ant.taskdefs.Ajc11CompilerAdapter
-Dbuild.compiler.clean=anything ...
</pre><p>
Caveats to consider when using this global
<tt>build.compiler.clean</tt> property:
</p><div class="orderedlist"><ol type="1"><li><p><a name="d0e2314"></a>
If javac believes there are no out-of-date source files,
then the adapter is never called and cannot clean up,
and the "compile" will appear to complete successfully
though it did nothing.
</p></li><li><p><a name="d0e2317"></a>
Cleaning will makes stepwise build processes fail if
they depend on the results of the prior compilation being
in the same directory, since cleaning deletes all .class files.
</p></li><li><p><a name="d0e2320"></a>
This clean process only permits one compile process at a
time for each destination directory because it tracks
recursion by writing a tag file to the destination directory.
</p></li><li><p><a name="d0e2323"></a>
When running incrementally, the clean happens only before
the initial compile.
</p></li></ol></div></li></ul></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="antTasks-iajc.html">Prev</a>&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="antTasks-ajc.html">Next</a></td></tr><tr><td width="40%" align="left">AjcTask (iajc)&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="antTasks.html">Up</a></td><td width="40%" align="right">&nbsp;Ajc10 (ajc)</td></tr></table></div></body></html>