Tuesday, January 20, 2009

My experiments with Apache ANT

For the past few days I have been experimenting with Apache ANT for automating the build process in my project.

First let me explain the situation that demanded this. One of the projects which is under support in our team is a web wrapper for a Honeywell proprietary stand alone applicaton called NexSys. So every time NexSys undergoes a change we need to do certain tasks manually. This activity gets sort of repeated atleast once a month. It was my TL and team mate who came up with this idea of automating it for every NexSys change, forseeing it as a productivity improvement for the project.

The idea sounded definitely interesting to me…:) and soon I started to dive into the world of Apache ANT…

The whole thing looked "simple" when explained by our TL whom we call “boss” … but implementing the same did not seem as easy though… well with the assurance that I could get any help from my team mates I started off…

First few days I spent collecting and reading stuff related to that… I also got a script written sometime back by another friend of mine… I worked upon it and started to change it to see how it could meet my needs… that was my first hands on experience in the so called ANT... :)

Well let me give a general overview on ANT scripts.

Apache Ant is a software tool for automating software build processes. It uses XML to describe the build process and its dependencies.  By default the XML file is named build.xml. Each buildfile contains one project and at least one (default) target. Targets contain task elements. Each task element of the buildfile can have an id attribute and can later be referred to by the value supplied to this. The value has to be unique.

Now let me explain how we used it for meeting our need. First, we broke up the whole project into tasks like:

downloadNexSysExe, InstallNexSysExe, ProxyGen, Buildproj, BuildEar, FtpEar and sendMail.

Soon I’ll also provide the snippets which will give you a better understanding of ANT.

{To be continued…)

Its after a long while that I am continuing with this blog entry... was wondering if I would ever complete this...

Lets see how we define a target for instance the first sub task in this project: downloadNexExe 

 <<target name="downloadNexExe">
     <echo message="About to download NexSys exe" />
     <get src="${NexDownloadURL}" dest="${NexInstallDir}\\${NexVersion}" verbose="true" usetimestamp="true" />
     <echo message="After download NexSys exe" />
target>

This target is written for downloading the NexSys exe from the NexSys site to our local machine.
The src and dest should be defined as shown:
    <property name="NexInstallDir" value="D:\\NexSys Installable" />
    <property name="NexVersion" value="NexSys-x-xy-xyz-00xyz.exe" />

DSimilarly we define the other tasks one after the other as shown below:

 "InstallExe" This is the task for installing NexSys using the install shield installer for NexSys 
<target name="installNexExe" depends="downloadNexExe">
  <echo message="About to Install NexSys exe" />
  <exec dir="${NexInstallDir}" executable="${NexInstallDir}\\${NexVersion}" />
  <echo message="After install NexSys exe" />
    target>

 "checkOutFromVSS" This is the task for checking out the proxy files and the property file from the VSS
<target name="checkOutFromVSS" depends="installNexExe">
  <echo message="About to check out the proxy java files" />
  <vsscheckout localPath="${dest}\\javaproxy" recursive="true" vsspath="${vssPath}\\javaproxy" serverPath="${ssDir}" />
  <vsscheckout localPath="${dest}\\dbProxy" recursive="true" vsspath="${vssPath}\\dbProxy" serverPath="${ssDir}" />
  <echo message="After check out of the proxy java files" />
  <echo message="About to check out the property file" />
  <vsscheckout localPath="D:\\Anand\\eNexSysWeb\\JavaSource\\enexsysresources\\resources" recursive="true" vsspath="${vsseNexPath}\\enexsysresources\\resources\\DEV_ApplicationResources.properties" serverPath="${ssDir}" />
  <echo message="After check out of the property file" />
    target>

"proxygen" This is the task for generating proxy Java files from the COM dlls of NexSys core that has been installed

<target name="proxygen" depends="checkOutFromVSS">
  <echo message="About to generate the proxy java files" />
  <exec dir="${B2JDir}" executable="${B2JExe}">
  <arg value="${nexDir}\\DynamicSchematic.dll" />
  <arg value="${dest}" />
  <arg value="dbProxy" />
      exec>
<echo message="After generation of the proxy java files" />
    target>

<target name="compile" description="To compile all classes" depends="checkIntoVSS">
  <javac executable="${iSight.java.bin}" classpathref="classpath" srcdir="." destdir="D:\\Anand\\NexSysWeb\\WebContent\\WEB-INF\\classes" debug="on" />
    target>

    <target name="nexSysWar" depends="compile">
 <war destfile="D:\\ANT\\myapp.war" webxml="D:\\Anand\\NexSysWeb\\WebContent\\WEB-INF\\web.xml" basedir="D:\\Anand\\NexSysWeb\\WebContent" compress="true" level="9">
  <fileset dir="D:\\Anand\\NexSysWeb\\WebContent" />
  <lib dir="D:\\Anand\\NexSysWeb\\WebContent\\WEB-INF\\lib" />
  <classes dir="D:\\Anand\\NexSysWeb\\WebContent\\WEB-INF\\classes" />
    war>
    target>


<target name="nexSysEar" depends="nexSysWar">
  <echo>Going to generate the ear file...echo>
  <ear destfile="D:\\ANT\\myapp.ear" appxml="D:\\Anand\\NexSys\\META-INF\\application.xml">
  <fileset dir="D:\\ANT" includes="*.war" />
     ear>
    target>

    <target name="ftpEar" depends="nexSysEar">
<ftp server="199.63.32.110" action="put" remotedir="/users/appuser/eNexsys/eNexSys_Phase3/QA_Build/eNexsys_Pahse3_QA_9.3/Test" userid="appuser" password="appuser">
  <fileset file="D:\\ANT\\myapp.ear" />
    ftp>  
    target>


<target name="sendMail" depends="ftpEar">
  <echo>Going to send mailecho>
  <mail mailhost="smtp.xyz.com" from="xyz@xyz.com" tolist="xyz@xyz.com" subject="Automatic eNexSys build" messagefile="build.txt" />
  <echo>mail has been sentecho>
    target>

 







No comments: