Getting Ant Build Updates Via Growl

Posted November 25th, 2009. Filed under Code

I have a few build scripts that take some time to run and I hate staring at the Eclipse console to see how things are progressing.  I've heard of Growl before and today decided to see if I could make this work to popup notices during my build.

Growl is originally for the Mac but there is a port for Windows aptly named Growl For Windows.  Download and install.  I also added the install path to my Windows PATH so I can run the growlnotify script from the command line.

Once you've done this you can verify it's working by popping open a DOS box and typing:

C:> growlnotify "THIS IS A TEST"

And you should get a popup:

Growl Popup

Growl Popup

Next you'll need to grab a few things so you can interact with Growl from Ant...

Download growlbuildlistener

An Ant BuildListener that displays notifications via Growl/JGrowl

Follow the installation instructions (in the wiki section).

This simply involves downloading two files that contain jar files - you'll need:

  • the growllistener jar  (growllistener.jar)
  • the JGrowl jar (binaryblizzard.jar) (from JGrowl)

Drop those in your Ant lib folder, and in Eclipse make sure those jars are added to your classpath (Ant Home Entries).

Next you will need to add a listener so Ant can use the GrowlBuildListener.  Run the following line from a command prompt:

set ANT_ARGS=-listener net.slimeslurp.growl.GrowlListener

Next I had to add a new taskdef line to my build script:

<taskdef name="growl" classname="net.slimeslurp.growl.GrowlEcho"/>

And now you should be able to drop in a new GrowlEcho task in your build file wherever you want a popup to occur.

<growl message="Kicking off build of ${projectname}"/>

Now when I kick off my scripts I see something like this:

Growl Example

Growl Example

I did this mainly for fun but I can see some applicable uses for this. Growl also looks neat because it appears you can configure it to push notices over the network. So in theory I could setup everyone on my team with Growl and when someone kicked off a build we could all be notified.

If you come up with a creative use for this please let me know in the comments!

Cron For Windows

Posted August 15th, 2009. Filed under Code

Marc Escher ( http://mxunit.org/ ) gave a great presentation at CFUnited on automation: batch files, Ant, launchers and Jetty. One thing that came up during the discussion was a replacement for Scheduled Tasks on Windows which I (and apparently others) have found unreliable.

Since I'm a Linux geek I'm familiar with cron on Linux and went looking for a version for Windows.

Cron enables users to schedule jobs (commands or shell scripts) to run automatically at a certain time or date.

Turns out there are quite a few cron solutions available on Windows.  Most of them however were commercial solutions.  After a bit of digging I found nnCron ( http://www.nncron.ru/ ).  nnCron has a commercial version but they offer a free "lite" version which covered the basic features I needed:

nnCron LITE is a small, but full-featured scheduler that can start applications and open documents at a specified time or with specified frequency. nnCron LITE is a perfect freeware Windows clone of a well-known UNIX scheduler Cron (including all the useful Anacron features).

Here are a few of the features of nnCron LITE:

  • it can be started as a system service or as a regular standalone application
  • it understands cron table format (Unix) and is managed with easy-to-edit text crontab files that are fully compatible with Unix crontabs
  • it can set and use environment variables
  • it can run applications authorized as currently logged user

So far I've been using it to schedule a backup task I have for our JIRA and Confluence installs using SyncBack.  And I have a few system utilities setup (defrag, etc) that run occasionally.  Unlike Scheduled Task I've never had an issue with the nnCron service failing.

Did Dreamweaver Determine Your Deployment Method?

Posted July 21st, 2009. Filed under Code

I was reading Glyn Jackson's insightful review of ColdFusion Builder and it got me thinking.

It's been years since I've worked in a shop where we used FTP to deploy files.  I always felt that manual FTP was the worst possible way to move files around (this was before I discovered Ant).  I ended up moving files around with SVN (which I still do today but Ant is the middle man).

I also never used Dreamweaver. I went straight from Homesite to CFEclipse.

Glyn's post got me thinking however.  Does Dreamweaver's 'site' feature force you into FTP?  Do people open Dreamweaver, assume the 'site' feature is the only option and follow that path?

I'm seeing a lot of the same conversations resurrected with the release of ColdFusion Builder as I did when CFEclipse first appeared.  People struggling with Eclipse's "project" concept. And the fact that FTP may not be the only option.

Ant Presentation Files

Posted July 1st, 2009. Filed under Code

I've finally bundled up my Ant presentation files.  I recently gave this presentation at TACFUG (Triangle Area ColdFusion User Group) and got some pretty positive feedback.

Hopefully now with the examples - people who attended can hack these up and do something useful with them!

This file contains:

  • Older PPT version of the presentation I gave on CFMeetup (it has more useful notes in it)
  • JAR files for additional Ant task (there may be newer versions of these but they should get you started)
  • Some example files including a version of the code we use at work (Qasim Rasheed did the macrodef code)

DownloadAnt Presentation (434)

Please note:  Ant can MOVE, COPY, OVERWRITE and DELETE files on your localworkstation and/or production servers, etc.  I take no responsibility if you blow something up with these scripts!! :)

For more information on Ant please check out my wiki:   http://www.thecrumb.com/wiki/ant

Update: If you download these files and do something useful with Ant - please let me know!  I'm always interested to see what people are doing with Ant!

Using Environment Properties In Ant

Posted April 24th, 2009. Filed under Code

Tinking around with Ant I found out you can reference system environment properties within your build file.

So in Windows for example you can run SET at the command line and get a long list of properties:


U:\>set
ALLUSERSPROFILE=C:\Documents and Settings\All Users
ANT_HOME=D:\ant
APPDATA=C:\Documents and Settings\priestj\Application Data
CLIENTNAME=zappa

You can easily reference these in your build file - first set property environment to "env":


<target name="echo">
<property environment="env"/>

</target>

Now we'll add some of our Windows system properties (note these are case sensitive!):


<target name="echo">
<property environment="env"/>
<echo message="env.ALLUSERSPROFILE:   ${env.ALLUSERSPROFILE}" />
<echo message="env.ANT_HOME:   ${env.ANT_HOME}" />
<echo message="env.APPDATA:   ${env.APPDATA}" />
<echo message="env.CLIENTNAME:   ${env.CLIENTNAME}" /> </target>

Running this we can see these properties are picked up by Ant!


Buildfile: D:\build.xml
echo:
[echo] env.ALLUSERSPROFILE:   C:\Documents and Settings\All Users
[echo] env.ANT_HOME:   C:\eclipse\plugins\org.apache.ant_1.7.0.v200803061910
[echo] env.APPDATA:   C:\Documents and Settings\priestj\Application Data
[echo] env.CLIENTNAME:   zappa

Making Your Build Files User Friendly

Posted April 10th, 2009. Filed under Code

I'm working on a build file for the Model-Glue project and want to make it as user friendly as possible.  Turns out this is very easy in Ant!

First always include a description in your build file - you can be a bit more verbose, I kept this short for the example:


<description>
Ant script to create new Model-Glue 3.0 application.
</description>

Of course if anyone edits your build file they will see the description, but we can also display this when the build file is first run. First I make my default target 'help':


<project name="Model-Glue" default="help" basedir=".">

Then create a 'help' target:


<target name="HELP" description="Displays a list of help to the user.">
<java fork="no" classname="org.apache.tools.ant.Main">
<classpath>
<fileset dir="${ant.home}\lib">
<include name="**/*.jar" />
</fileset>
</classpath>
<arg line="-projecthelp" />
</java>
</target>

This is simply running the exec task and running Ant with the '-p' switch (which is short for '-projecthelp' which simply prints a list of the build files targets as well as the description.  In all our other targets we'll make sure to include a 'description':


<target name="build"  description="Copy Model-Glue files to new
project directory.">
<echo message="Copy Model-Glue!"/>
</target>

Now if we run our build file we'll see something like the following output (either at the command line or in the Eclipse console:

D:\>ant
Buildfile: build.xml

help:
 [exec] Buildfile: build.xml
 [exec]
 [exec] Ant script to create new Model-Glue 3.0 application
 [exec]
 [exec] Main targets:
 [exec]
 [exec]  build  Copy Model-Glue files to new project directory.
 [exec]  help   Displays a list of help to the user.
 [exec] Default target: help

Now the user can easily determine the purpose of the build file and see a list of possible targets to run.

Lazy Automation: Ant Meets Autohotkey

Posted March 26th, 2009. Filed under Code

Ok. I'm lazy. Really lazy.

Today I got tired of having to click around in Eclipse to run my Ant tasks  and decided to automate it with a shortcut in Autohotkey:


!r::
Run, %comspec% /c ant -f D:\CFProjects\cares\extensions\ant\avrs.db.build.xml cleanlocal
return

Lets break this down:

  • So the !r:: simply tells Autohotkey to assign this shortcut to Alt+R.
  • Run, %comspec% /c is a shortcut to cmd.exe.
  • Then I simply pass the path of my Ant script and the task I want run (cleanlocal).

This script simply resets my database data back to a know state and I run this frequently when developing.  So now a quick Alt+R and I'm done!

Oracle: Credential Retrieval Failed

Posted March 26th, 2009. Filed under Code

Working on some Ant scripts and Oracle today and out of the blue I get this error:

ORA-12638 credential retrieval failed

Everything was working yesterday!  I restarted Oracle and my workstation - no luck!  Argh.

A quick Google however turned up a simple solution - simply modify your sqlnet.ora file. On my machine running Oracle XE this is located:

C:\oraclexe\app\oracle\product\10.2.0\server\NETWORK\ADMIN

And change one line:

Original Entry - SQLNET.AUTHENTICATION_SERVICES= (NTS)
Modified Entry - SQLNET.AUTHENTICATION_SERVICES= (NONE)

After I changed this I tried it and it worked - no reboot, restart required!  Reading on the Oracle forums - apparently the "NTS" option tries to use your Windows credentials to authenticate with Oracle.  So unless your Oracle logins match your Windows login - this may fail.