| [aspectj-users] Incremental Compilation 2 |
|
I’ve got the incremental compile working within
eclipse using the message handler technique. I created a class that
implemented IMessageHolder and had empty/return null/return false for all
methods except handleMessage
public
boolean
handleMessage(IMessage
arg0) throws
AbortException {
if
(arg0.getMessage().equals("weaving")) {
File file = new File("iajc.woven.tag");
try
{
file.createNewFile();
} catch
(IOException e) {
e.printStackTrace();
}
}
System.out.println(arg0.getMessage());
return
false;
} Don’t forget to include a no-argument constructor –
otherwise it won’t work. In the build.xml file, I have one task that starts the
aspectJ compiler in the background and leaves it running. I run this the
first time I’m doing a build. <taskdef resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties">
<classpath>
<pathelement location="build_lib/aspectjtools.jar"/>
<pathelement location="bin"/>
</classpath> </taskdef> I included my bin (eclipse build output directory) in my
classpath so iajc could find my IMessageHandler implementation, which is in my
applications general source tree. <target name="startCompiler" description="Start aspectJ compiler"> <delete file="iajc.ant.tag"/> <touch file="iajc.ant.tag"/> <iajc destDir="${app.staging}/APP-INF/classes" tagfile="iajc.ant.tag" verbose="true" messageHolderClass="com.vms.adbase.util.CompileMessageHolder"> <sourceRoots> <pathelement location="appsrc"/> <pathelement location="gen"/> <pathelement location="testsrc"/> </sourceRoots> <classpath> <path refid="project.classpath"/> </classpath> </iajc> </target> Note: You can’t fork this task because fork will
supercede messageHolderClass. Then, the compile method in my normal build process contains
the lines <delete file="iajc.woven.tag"/> <touch file="iajc.ant.tag"/> <echo>Touched iajc tag file</echo> <!-- sleep here until woven tag is
present --> <waitfor maxwait="300" maxwaitunit="second">
<available file="iajc.woven.tag"/> </waitfor> <!—deploy code goes here
--> The startCompiler task causes all messages to go through our
custom handler, which detects the “weaving” message that occurs at
the end of an incremental compile and creates a flag file. The compile
task deletes this flag file, touches the aspectJ compiler’s tag file to
trigger an incremental build and then waits for the flag file to be re-created. Kudos to Nick and and Wes for the start on this. -Steve |