Part 2: The ANT Build file

As mentioned previously, the ANT build file is just an XML file.

There are a number of important features in the file.

1. Declare properties
You will have a number of variables that will be used frequently throughout the build file, eg. database logon username, password, Oracle SID, etc. These should all be declared at the top of the build file.

<?xml version=”1.0″ encoding=”UTF-8″?>
<project name=”Demo Database build” default=”about-ant” basedir=”.”>
<description>
Build file for test database.
</description>

<!– declare properties –>
<property name=”build.dir” location=”.”/>
<property name=”build.prod.dir” location=”${build.dir}\development” />
<property name=”db.user” value=”username” />
<property name=”db.pwd” value=”password” />
<property name=”db.tnsname” value=”MYSERVER” />
<property name=”db.sid” value=”xyz001″ />
<property name=”db.run.tests.script”     location=”${build.prod.dir}\run_ounit_tests.sql”/>
<property name=”db.run.build.script”     location=”${build.prod.dir}\dev_build.sql”/>
<property name=”db.failing.tests.script” location=”${build.prod.dir}\no_of_failing_plsql_tests.sql”/>

2. Logon to SQL*PLUS
So you can call your sql file to build the database

<!– rebuild database –>
<echo message=”Logging on to SQLPLUS”/>
<exec executable=”sqlplus”
dir=”${build.prod.dir}”
failonerror=”true”>
<arg value=”-S” />
<arg line=”${db.user}/${db.pwd}@’${db.sid}'”/>
<arg value=”@${db.run.build.script}”/>
</exec>

3. Load test data with SQL*LOADER.

<!– load test data –>
<echo message=”Loading Test data with SQLLoader”/>
<exec executable=”sqlldr”
dir=”${build.prod.dir}”
failonerror=”true”>
<arg line=”${db.user}/${db.pwd}@’${db.sid}'”/>
<arg value=”control=data\customer.ctl”/>
</exec>

4. Run unit tests
Call sql file with executes UTPLSQL tests

<!– run unit tests –>
<echo message=”Running Unit tests”/>

<exec executable=”sqlplus”
dir=”${build.prod.dir}”
failonerror=”true”
description=”Run test via sqlplus.”>
<arg value=”-S”/>
<arg line=”${db.user}/${db.pwd}@’${db.sid}'”/>
<arg value=”@${db.run.tests.script}”/>
</exec>

5. Interogate results of unit tests
Query UTPLSQL for the results of the test

<echo message=”Look for test results from UTPLSQL”/>
<exec executable=”sqlplus”
outputproperty=”db.no.failing.tests”
description=”Retrieve the number of failing unit tests into a property.”>
<arg value=”-S” />
<arg line=”${db.user}/${db.pwd}@’${db.sid}'”/>
<arg value=”@${db.failing.tests.script}”/>
</exec>

6. Email the results back to you

<echo message=”Send email saying that Daily Build has run”/>
<mail mailhost=”mailhost.server” mailport=”25″ subject=”Test Database build”>
<from address=”dailybuild@mydomain.com”/>
<replyto address=”dailybuild@mydomain.com”/>
<to address=”me@mydomain.com”/>
<message>The TEST database daily build has completed</message>
</mail>

On to Part 3

Leave a Reply

Your email address will not be published. Required fields are marked *