Login | Register
My pages Projects Community openCollabNet

AOP metrics ant task


Ant task is a prefered way to launch aopmetrics metrics suite. You can also use the command line described in a separate page.

The task is using AspectJ compiler. It launches an internal build of sources specified by <fileset> or lst config file. Compiled class files are stored in the workdir. Then, Java and AspectJ syntax trees are analysed and all supported metrics are generated. Finally, aopmetrics exports measurements' results to specified resultfile (or writes to the standard output, by default).

Currently, aopmetrics provides two export file formats:

  • Simple XML-based format. Useful for an automatic processing (scripts, programs) or transformations (to HTML). An example is shown below.
  • <project name="aop-metrics">
      <package name="org.tigris.aopmetrics.metrics">
        <type kind="class" name="DepthOfInheritanceTree">
          <metric name="LOCC" value="39"/>
          <metric name="WOM" value="3"/>
          <metric name="DIT" value="0"/>
        <metric name="NOT" value="38"/>
        <metric name="Ce" value="52"/>
        <metric name="Ca" value="1"/>
      <package name="org.tigris.aopmetrics">
  • XLS format (Ms Excel). Useful for a human analysis. Can be viewed by Gnumeric. Here is a sample (metrics' results for the aopmetrics project).


Attribute Description Required
configfile Specifies a config file (.lst), which is commonly used in AspectJ projects. The config file contains paths of all source files (separated by newline). Yes, unless nested fileset is used.
export Specifies an export type. Currently only 'xml' and 'xls' types are supported. No, default: xml.
resultsfile Specifies a file, where the aopmetrics writes results of all measurements. If the file is not specified, then the results will be printed to the standard output. No
workdir Specifies a directory, where aopmetrics stores temporary files (compiled sources by AspectJ compiler). If the directory doesn't exist, then the task creates it. Yes
sourcelevel Specifies a source compiliance level. The value is passed to the AspectJ compiler. Currently, the compiler supports '1.3', '1.4' and '1.5' levels. No, default: 1.4.
verbose Specifies a verbosity level. The attribute is useful for debugging. Currently, 'normal', 'info' and 'debug' levels are supported. No, default: normal.
charset Specifies a character encoding of given sources. No.

Nested elements


Nested fileset elements can be used for specifying source files for measurements. This is simpler than using AspectJ config file (.lst), when you don't use it in your project. Usually this element is identical to filesets in javac or ajc tasks.


Nested classpath elements can be used for specifying user class files. Usually this element is identical to classpaths in javac or ajc tasks.


Example of the aopmetrics task's definition:

<path id="cp.aopmetrics">
	<fileset dir="tools/aopmetrics">
		<include name="*.jar" />

<taskdef name="aopmetrics" classname="org.tigris.aopmetrics.AopMetricsTask">
	<classpath refid="cp.aopmetrics"/>

Specifying source files using a nested fileset:

<path id="cp.compile">
	<fileset dir="lib">
		<include name="*.jar" />

<aopmetrics workdir="build/workdir" sourcelevel="1.5"
	<fileset dir="src" includes="**/*.java"/>
	<fileset dir="testsrc" includes="**/*.java"/>
	<classpath refid="cp.compile"/>

Specifying source files using a config file. Results are printed to the standard output:

<aopmetrics workdir="build/workdir" configfile="without-tracing.lst">
	<classpath refid="cp.compile"/>

For more a complex example see aopmetrics old build file.