Using jarnotator in ant builds

Using jarnotator in an Ant build

Since jarnotator provides a Ant task it can be used directly from within Apache Ant build scripts. The Ant task provides all the jarnotator options. All in all the Ant task fairly easy to use. Analyzing your classes as part of a build is trivial.

The necessary setup to use the jarnotator task is that of any other external Ant task. The remainder of this page briefly outlines how to get started. For more detailed information please refer to the Apache Ant documentation related to the use of external Ant tasks.

Make jarnotator available to Apache Ant

Ant has its own mechanisms to load Ant tasks. It looks in the following location or uses the following options:

  • via command line argument -lib
  • adding to ${user.home}/.ant/lib
  • adding to ${ant.home}/lib

Define the task with your build script

To refer to the jarnotator task within your targets you first need to define the task. The following line does the job:

<taskdef name="jarnotator" classname="be.biggerbytes.jarnotator.run.JarnotatorTask"/>

Next you need to invoke this task into your target. Since Ant does not impose a life cycle like maven does you need to take care of invoking the jarnotator task once the bytecode has been created. In other words after compilation. The jarnotator task can handle classes directories as well as jar files.

Using the jarnotator task

>The jarnotator task has a single mandatory parameter, fileName. The parameter points the task at the classes located in this directory or jar with that name.

The example below also includes all parameters accepted by the jarnotator ant task. The values are the default values and are meant for illustration. One can leave them out.

A nested claspath element can be provided to indicate the location of third party libraries required by the classes being analysed. If those libraries have in turn been processed by jarnotator (or manually annotated with jsr305 annotation) these annotations can be picked up during the analysis.

    <property name="myjar" location="target\classes"/>
    <property name="lib" location="libdir"/>

    <target name="main">
        <!--
        All values below except fileName and the path correspond
        to the default value.
        -->
        <jarnotator fileName="${myjar}"
                    annotateInterfaces="true"
                    annotateAbstractMethods="true"
                    processOlderJava="false"
                    verify="true"
                    showByteCode="false"
                    keepOriginal="false"
                    backupFileExtension="orig"
                    quiet="false"
                    simpleDebug="true">

            <!-- Class path used during analysis of your classes -->
            <classpath>
                <fileset dir="${lib}" includes="**/*.jar"/>
            </classpath>
        </jarnotator>
    </target>
</project>

Complete example

Below you'll find a complete example of how to process your classes (fictitiously located in target\classes).

<?xml version="1.0"?>

<project name="OwnTaskExample" default="main" basedir=".">
    <taskdef name="jarnotator" classname="be.biggerbytes.jarnotator.run.JarnotatorTask"/>

    <property name="myjar" location="target\classes"/>
    <property name="lib" location="libdir"/>

    <target name="main">
        <!--
        All values below except fileName and the path correspond
        to the default value.
        -->
        <jarnotator fileName="${myjar}"
                    annotateInterfaces="true"
                    annotateAbstractMethods="true"
                    processOlderJava="false"
                    verify="true"
                    showByteCode="false"
                    keepOriginal="false"
                    backupFileExtension="orig"
                    quiet="false"
                    simpleDebug="true">

            <!-- Class path used during analysis of your classes -->
            <classpath>
                <fileset dir="${lib}" includes="**/*.jar"/>
            </classpath>
        </jarnotator>
    </target>
</project>

Follow Me

Follow us on Twitter

Feed Display

Linux Today
Linux Today News Service
Linux Today
  • Linux File System Fsck Testing -- The Results Are In
    EnterpriseStorageForum: "It has been a while since we started the fsck project to test fsck (file system check) times on Linux file systems. After an extended delay, the Linux File System fsck testing results can now be presented."
  • Firefox 11 Gets SPDY
    Datamation: Google's speed-enhancing SPDY protocol lands in upcoming version of Mozilla's open source browser.
  • Piracy and the value of freedom
    Linux User & Developer: "If I were a victim of actual piracy while sailing the seas, I would probably consider the word's rampant misuse in technology circles as massively insulting."

Phoca - Google AdSense Easy

Google Search

Webwww.biggerbytes.be

RSS socialnet

Add to MyYahoo!
Subscribe in NewsGator Online
Add to Newsburst
Add to Google
Add to My AOL
Add to Pluck
Subscribe in FeedLounge
Add to Windows Live
Add to NetVibes
Subscribe in Rojo
Subscribe in Bloglines
Add to MyMSN
Add to Plusmo for your cellphone
Add to PageFlakes
Add to Technorati
Add to BlinkBits
Copyright © 2012 BiggerBytes.Be. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.