Ant Sync Task - That Was Easy!

I've been slowing building an Ant task I use to push my application to our development server.

It does the following:

  1. Creates a 'temp' dir on my local drive
  2. Checks out a revision from our SVN repository (I can enter a revision or HEAD via a prompt)
  3. It then 'cleans up' the checked out working copy (removes a few files, etc)
  4. Converts my CFC's to duck type* (using Adam Haskell's script)
  5. Replace a few tokens in application.cfm with some information about the build
  6. Zip up and copy the files to our development server and unzip them
  7. Delete all the temp directories and files and email a log

It does all that at the push of a button in CFEclipse.

While digging around recently I noticed a 'sync' Ant task and bookmarked it away for further reading. Today I finally had some time to check it out and it was really easy to implement!

My copy and ZIP code:

CODE:
  1. <target name="zipBuild" description="Set ZIP filename, then ZIP clean dir"
  2.  
  3. <property name="build.filename" value="myProject_${svn.versionnum}.zip" />
  4.    
  5. <zip destfile="${project.build.src}${build.clean}/${build.filename}" basedir="${project.build.src}${build.clean}" />
  6.    
  7. <copy todir="${project.build.dev}">
  8.  <fileset dir="${project.build.src}${build.clean}" includes="${build.filename}" />
  9. </copy>
  10.    
  11. <unzip src="${project.build.dev}\${build.filename}" dest="${project.build.dev}"/>
  12.  
  13. <delete file="${project.build.dev}\${build.filename}"/>
  14. <delete dir="${project.build.src}${build.temp}" />
  15. <delete dir="${project.build.src}${build.clean}" />
  16.    
  17. <echo message="Files moved to development succesfully!"/>
  18. </target>

To change it to use 'sync' instead was really simple - it was almost the same syntax as the copy task:

CODE:
  1. <target name="syncBuild" description="Sync files between 'clean' directory and server"
  2.  
  3. <sync todir="${project.build.dev}" verbose="true">
  4.  <fileset dir="${project.build.src}${build.clean}"/>
  5. </sync>
  6.  
  7. <delete dir="${project.build.src}${build.temp}" />
  8. <delete dir="${project.build.src}${build.clean}" />
  9. <echo message="Files moved to production succesfully!"/>
  10. </target>

Interestingly they both take almost exactly the same amount of time to run (~36 seconds) - I would have thought sync would have been a bit faster without the overhead of zipping and unzipping.

Next I need to add in some dependencies between targets to make sure everything runs correctly and in order and add our production server and I should be done!

If you haven't checked out Ant yet - do it! It's a great tool!

I have a lot of Ant links on my wiki!

* Please note I didn't do this for performance reasons, it was more along the lines of 'because I could'

Creative Commons License

Creative Commons License This article: Ant Sync Task - That Was Easy!, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License .

Copyright © 2007 thecrumb.com. All rights reserved.