Ant Task

InfraRED ships with an Ant task that can be used for preparing an application. This is useful largely to use InfraRED with offline (compile-time) weaving. It is recommended that you try using this only after you have sucessfully used it with AspectWerkz load-time weaving as described in the installation page.

The usage of the ant task might look like:

    
<project ..>
  ..

    <taskdef name="infrared" classname="net.sf.infrared.tools.ant.InfraRedTask">
        <classpath>
            <pathelement location="infrared-ant-XX.jar"/>            
        </classpath>
    </taskdef>

    <infrared system="aw" offline="true" server="tomcat" agentConfiguration="infrared-agent.properties">
        <war src="my.war" dest="my.instrumented.war">
            <include name="WEB-INF/classes/**"/>
            <exclude name="WEB-INF/classes/do/not/instrument/**"/>
        </war>
    
        <ear src="my.ear" dest="my.instrumented.ear">
            <module name="ejb-module" type="ejb">
                <include name="**/*.class"/>
                <exclude name="do/not/instrument/**"/>
            </module>
        
            <module name="web-module" type="war">
                <include name="WEB-INF/classes/**"/>
                <exclude name="WEB-INF/classes/do/not/instrument/**"/>
            </module>
        </ear>
    
        <aspectpath>
            <pathelement location="${myaspects.dir}"/>
        </aspectpath>
    
        <extraclasspath>
            <pathelement location="${j2ee.jar}"/>
        </extraclasspath>
    </infrared>
    ..
</project>
 
            

Configuring the Ant Task

The task supports the following configuration attributes:

Attribue Description Default Value
systemaj|aw|aspectwerkz|aspectj. Specifies what aspect system to use.aspectwerkz
offlinetrue|false. Specifies whether aspects should be weaved into the classes prior to deployment or at load-time. Only AspectWerkz right now supports load-time weaving, so the combination system="aj" offline="false" is illegal.true
servertomcat|jboss|weblogic. Specifies which server the application is to be deployed on. Mandatory attribute.-
agentConfigurationThe location of the properties file that would be used to configure InfraRED. The name of this file should be infrared-agent.properties. Mandatory attribute.-
applicationNameThe name of the application. Is needed only when server is Jbossunknown-app
applicationPortThe port of the application. Is needed only when server is Jboss.0

The ant task can take additional inputs using nested war, ear, aspectpath and extraclasspath tags. These are described in the subsequent sections.

Specifying applications

The ant task can take nested war and ear tags which specifies the applications to instrument. Their attributes are desribed below.

  • War tag

    <war> tag specifies a WAR web application. It can take nested includes and excludes tags which specify what portion of the war needs instrumentation. If neither includes or excludes is specified nothing gets instrumented. Attributes of the war tag are described below:

    Attribue Description Default Value
    srcSpecifies the source of the war application. This can be file or a directory (exploded wars).Mandatory attribute.-
    destSpecifies the destination of the instrumented war application. If 'src' was an exploded war, the output would be an exploded war, else it would be a compressed war file. Mandatory attribute.-

    Example:

        
    <war src="my.war" dest="my.instrumented.war">
        <include name="WEB-INF/classes/**"/>
        <exclude name="WEB-INF/classes/do/not/instrument/**"/>
        <include name="WEB-INF/lib/*.jar"/>
        <exclude name="WEB-INF/lib/log4j*.jar"/>
    </war>
                             
                        
  • Ear tag

    <ear> tag specifies an EAR application. It can take nested <module> tags which specify which portions of the archive should be instrumented. If no modules are specified nothing gets instrumented. Attributes of the ear tag are described below:

    Attribue Description Default Value
    srcSpecifies the source of the ear application. This can be file or a directory (exploded wars).Mandatory attribute.-
    destSpecifies the destination of the instrumented ear application. If 'src' was an exploded ear, the output would be an exploded ear, else it would be a compressed war file. Mandatory attribute.-

    The <module> tag identifies a module with an ear, and is very similar to <war> tag

    , except that it has a name attribute instead of src and dest attributes which <war> has. The name attribute identifies the name of the module within an ear. <module> tag also supports a type attribute, the legal values of which are ejb, java, war, classes and jar.
    Attribue Description Default Value
    nameSpecifies the name of the module within an ear. Mandatory attribute.-
    typeejb|java|war|classes|jar. Specifies the type of the module. ejb = ejb module java = java module war = web module classes = directory of classes jar = a jar file Mandatory attribute.-
    Again like <war>, you can provide nested includes and excludes tags which specify what portion of a moudle needs instrumentation

    Example:

        
    <ear src="my.ear" dest="my.instrumented.ear">
        <module name="ejb-module" type="ejb">
            <include name="**/*.class"/>
            <exclude name="do/not/instrument/**"/>
        </module>
            
        <module name="web-module" type="war">
            <include name="WEB-INF/classes/**"/>
            <exclude name="WEB-INF/classes/do/not/instrument/**"/>
        </module>    
        
        <module name="APP-INF/classes" type="classes">
            <include name="**/*.class"/>        
        </module>    
    </war>
                             
                        

Specifying aspects and classpath

Aspects are specified using the <aspectpath> tag. This is a regular Ant <path> tag. This path should refer to the compiled aspect classes. When using AspectWerkz system, you might need to have a META-INF/aop.xml file also in this path. The aspect classes specified by this path would be copied into the appropriate location within the application.

Often you might needs some classes that is needed for compilation, but are not packaged withing the application itself - for example, the jars containing J2EE classes. These needs to be specified using the <extraclasspath> tag. The classes in this path will be used for aspect compilation, but will not be copied into the application.

The aspects that are shipped with InfraRED are packaged in INFRARED_HOME/infrared-agent-all-servlet-XX.jar. If you need offline process you application to using these, add them as part of the <extraclasspath>. We dont need to copy these into the application because they are available in the server's classpath.

Preserving the working directory

The Ant task uncompresses your application archive into a working directory, and deletes this directory when the task finishes execution. Sometimes you might want to inspect this directory to debug issues you might run into with the Ant task. In that case, enabling the system propery infrared.dont.clean preserves the working directory.