build.xml

My main build.xml file. All properties are set in external property files so you should not have to modify this file.

:!: You may of course need to tweak it initially to make it suitable for your work environment!

<?xml version="1.0"?>
<!-- * define your project name -->
<project name="MYPROJECTNAME" default="build" basedir=".">
	<!-- load task used to hide password during user input -->
	<taskdef name="query" classname="com.jera.anttasks.Query"/>	
	<!-- load SVNAnt task -->
	<typedef resource="org/tigris/subversion/svnant/svnantlib.xml"/> 
 
	<description>
		This buildfile will deploy your project files from the SVN repository
		* modify targets in external property files to accomodate for your needs
		* be aware that this script deletes files - doublecheck your paths!
 
		Before building ensure you have the following setup correctly:
	     * you must add TNS_ADMIN to your System or User variables - this should point to the full path of your tnsnames.ora file (for Oracle)
		 * this can be verified / set via: Control Panel > System > Advanced > Environment Variables 
	     * make sure you have the additional tasks setup correctly:
		 	* jera ant tasks - for secure password dialog
		 	* SVNAnt task - for interacting with Subversion
            * if you are going to interact with SVN - you will need Subversion installed locally
 
		Things you should define * (see property files)
			1) source and destination paths for build files (note: beware of case sensitivity when defining paths!!)
			2) email address and log file name defined
 
		To run the script - run the desired target:
			1) run 'build' you will be prompted for a destination
	</description>
 
	<target name="prepare" description="Prepare environment for build">
		<!-- prompt the user to enter their username, password and revision 
			Note: input task does not work in Eclipse 3.3 - use query instead:
			<query name="svn.revision" message="Enter revision (HEAD or #)"/>
		-->
 
		<!-- include external properies - common values for build file -->
		<property file="common.properties"/>
		<property file="${user.name}.properties"/>
 
 
		<input message="Where do you want to deploy to?"
		        validargs="${deploy.list}" 
		        addproperty="deploy.server"
		        defaultvalue="${deploy.default}"/> 
 
		<input message="Where do you want to deploy to?"
		        validargs="${deploy.listdir}" 
		        addproperty="deploy.dir"
		        defaultvalue="${deploy.defaultdir}"/> 
 
 
		<!-- load server specific properties -->
		<property file="${deploy.server}.properties"/>
 
		<input message="Enter revision (HEAD or number:  Hit &lt;enter&gt; to use default value of HEAD)" addproperty="svn.revision" defaultvalue="HEAD" /> 
		<query name="svn.username" message="Enter your SVN username (lowercase)"/>
	    <query name="svn.password" message="Enter your SVN password" password="true"/>
 
		<!-- Define log file -->
		<record name="${build.logfile}"/>
 
		<!-- Create the time stamp -->
		<tstamp>
			<format property="svn.builddate" pattern="MM/dd/yy hh:mmaa"/>
		</tstamp>
		<echo message="Preparing to deploy to: ${deploy.server}"/>
	</target>
 
	<!-- Setup local temp directories -->
	<target name="init" depends="prepare" description="Create temp local directories for build">
		<delete dir="${project.build.src}" />
		<mkdir dir="${project.build.src}" />
		<echo message="Temporary build directories created successfully!"/>
	</target>
 
	<!-- * Checkout and get the revision number for this build 
		-  Add or remove directories you need to checkout here
	-->
	<target name="exportSVN" depends="init" description="Clean export of entire application">
	   	<svn username="${svn.username}" password="${svn.password}">
			<export srcUrl= "${svn.privurl}" destPath="${project.export}\${deploy.dir}" force="true"/>
		</svn>
		<echo message="Project exported to: ${project.export}\${deploy.dir}"/>
	</target>
 
	<!-- * Checkout and get the revision number for this build 
		-  Add or remove directories you need to checkout here
	-->
	<target name="checkoutSVN" depends="init" description="Checkout code from SVN repository into the local temp directory">
	   	<svn username="${svn.username}" password="${svn.password}">
			<checkout url= "${svn.privurl}" destPath="${project.build.src}${build.temp}\${deploy.dir}" revision="${svn.revision}"/>
		</svn>
		<svn username="${svn.username}" password="${svn.password}">
            <wcVersion path="${project.build.src}${build.temp}\${deploy.dir}" prefix="svn." />
        </svn>
	    <echo message="Files checked out to temp directory successfully!"/>
	</target>	
 
	<!-- * Write revision number into application.cfc
	This assumes you have a token setup in your application.cfc - @@@revision-number@@@
	-->
	<target name="writeRevision" depends="checkoutSVN" description="Write revision into application.cfc on destination">
		<replace file="${project.build.src}${build.temp}\${deploy.dir}\application.cfm" token="@@@revision-number@@@" value="Last updated: r${svn.revision.max} - Date: ${svn.builddate}"/>
	    <echo message="Application.cfm modified successfully!"/>
	</target>
 
	<!-- Clean up files in temp and copy files to clean dir -->
	<target name="cleanDir" depends="writeRevision" description="Delete any unnecessary directories and files and copy to clean dir">
		<copy todir="${project.build.src}${build.clean}\${deploy.dir}">
			<fileset dir="${project.build.src}${build.temp}\${deploy.dir}">
 
			<!-- * add/remove any additional directories or files you want to remove -->
				<exclude name="**/_notes/**" />
                <exclude name="**/install/**" />
				<exclude name="build*.xml" />
				<exclude name="**/*.zip" />
				<exclude name=".project" />
			</fileset>
		</copy>
   	    <echo message="Build cleanup complete!"/>
	</target>	
 
<!--
==========================================================================
IMPORTANT: 	MAKE SURE YOU DO NOT DELETE THE ROOT DIRS 
(PRIV/PUB/SPUB/EXTENSIONS) ON THE REMOTE SERVER!!!!
IF YOU DO SYSADMIN WILL HAVE TO RECREATE WITH THE PROPER PERMISSIONS!!!!
========================================================================== 
-->
	<target name="build" depends="cleanDir" description="Sync files between 'clean' directory and server">	
 
		<!-- * NOTICE: Here we are first deleting ALL the files within the target directory!!!
		Make sure you want to do this!! -->  
		<echo message="Files copied successfully ${deploy.server}"/>
 
		<delete includeemptydirs="true">
		    <fileset dir="${deploy.server}\${deploy.dir}" includes="**/*"/>
		</delete>
 
		<sync todir="${deploy.server}\${deploy.dir}" verbose="true" includeemptydirs="true" >
			<fileset dir="${project.build.src}${build.clean}\${deploy.dir}"/>
		</sync>
 
		<echo message="Files copied successfully ${deploy.server}\${deploy.dir}!"/>
 
		<!-- end build process - reset server (if applicable), clean up temp directories and send email -->
		<antcall target="reset" />  
		<antcall target="sendMail" />
		<antcall target="cleanUp" /> 
	</target>
 
	<!-- optional email -->
	<target name="sendMail" description="Send email notification">	
		<mail mailhost="smtp.niehs.nih.gov" mailport="25" 
			subject="'${project.name}' build at revision ${svn.revision.max} successful" 
			messagefile="${build.logfile}">
		  <from address="${email.toaddress}"/>
		  <to address="${email.fromaddress}"/>
		</mail>
	    <echo message="Mail sent!"/>
	</target>
 
	<!-- *	This will open a browser to your application - use it to 'reset' your framework 	-->
  	<target name="reset" description="Resets the application">	
		<!-- * you must modify/verify:
		 - the path to your browser exe
		 - the URL to reset your application   
			<exec executable="C:/Program Files/Mozilla Firefox/firefox.exe">
				<arg value="${deploy.reseturl}" />
			</exec> -->
			<echo message="Browser open - verify application reset!"/>
  	</target> 
 
	<!--* Final step - deletes all the local temp directories created -->
  	<target name="cleanUp" description="Cleans up local temp directories and resets the application">	
		<delete dir="${project.build.src}" />
  		<echo message="Files moved to ${deploy.server}\${deploy.dir} successfully!"/>
		<echo message="Build complete!"/>
  	</target>  
</project>
 
/home/thecrumb/public_html/wiki/data/pages/ant/buildfile.txt · Last modified: 2008/04/04 19:58 by thecrumb
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki