AspectJ extension - Overview

This framework is an extension to the AspectJ compiler which allows to output Ajc errors messages in XML format. It is implemented as an extension of the AspectJ Ajc Ant task.

Example

Here is an example on how to use it from a java application:

AjcXml compiler = new AjcXml();

compiler.createSrc().setPath("src/aspect");
compiler.setDestdir("target/classes");
compiler.setResultFile("result.xml");

compiler.execute();

Here is an example on how to use it from an Ant script:

<taskdef name="ajcxml" classname="patterntesting.tool.aspectj.AjcXmlTask" >
    <classpath>
        <pathelement path="${aspectj.home}/lib/aspectjtools.jar" />
        <pathelement path="${m2.repo}/commons-io/commons-io/1.4/commons-io-1.4.jar" />
        <pathelement path="${m2.repo}/commons-lang/commons-lang/2.3/commons-lang-2.3.jar" />
        <pathelement path="${m2.repo}/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar" />
        <pathelement path="${m2.repo}/org/patterntesting/patterntesting-rt/1.0.0-SNAPSHOT/patterntesting-rt-1.0.0-SNAPSHOT.jar" />
        <pathelement path="${m2.repo}/org/patterntesting/patterntesting-tools/1.0.0-SNAPSHOT/patterntesting-tools-1.0.0-SNAPSHOT.jar" />
        <pathelement path="${target.classes.dir}"/>
    </classpath>
</taskdef>

<target name="compile.ajcxml" depends="init"
        description="compile sources with AjcXmlTask" >
    <ajcxml destdir="${target.classes.dir}" resultFile="target/patterntesting-output.xml">
        <src path="src/test/sample"/>
        <classpath>
            <pathelement path="${aspectj.home}/lib/aspectjrt.jar" />
        </classpath>
    </ajcxml>
</target>

The default output format of the resulting file is XML. If you want it as plain text, use the attribute "formatter" with the value "plain".

<target name="compile.ajcxml.plain" depends="init"
        description="compile sources with AjcXmlTask (with plain text as output)" >
    <ajcxml destdir="${target.classes.dir}" resultFile="target/patterntesting-output.txt"
           formatter="plain">
        <src path="src/test/sample"/>
        <classpath>
            <pathelement path="${aspectj.home}/lib/aspectjrt.jar" />
        </classpath>
    </ajcxml>
</target>

Usages

It can be used in Test Cases if you wish to assert results of AspectJ compilation. For example, if you're expecting an Aspect to produce a compilation error, you will be able to assert the XML result by either comparing the XML string or better by using XMLUnit.

In addition, it is useful if you need to produce reports about the result of the compilation. You can easily use DVSL to transform the XML into an HTML report.