Snarling radioactive ants!

A big part of agile development is continuous integration and alerting the developer to errors in their code as close to when they created them as possible. Towards that end, Adam Howitt published a method of hooking up the cfcompile.bat file with Ant in Eclipse. The way it works is that you save a file and cfcompile automatically runs on the file you saved to check for compile-time errors. This works wonderfully. However I wanted the notification of the error to be a little more in my face, somewhat following the information radiator concept of agile development.

There's a great little utility on the Mac called Growl that allows programs to send alerts to the user. Fortunately someone has created a similar application for Windows called Snarl (Now who's going to write Grumble for linux?) Also I've taken a cue from one of the commenters to Adam's post and created a more native Ant implementation of the cfcompile.bat file, calling the Java class directly from Ant. 

Note that this Ant code does require the antcontrib.jar file from the ant-contrib project. I had some difficulty getting Eclipse to see those tasks. I had to add the jar to Global Entries in the Ant / Runtime Preferences, then add the task from the jar. I guess that's a more granular approach, I expected the tasks in the jar to be automatically available when the jar was added as a global entry.

Also, this approach seems to require that the ant file be located in the webroot. Otherwise you'll get a complaint from the cfcompile class that the XML file isn't in the webroot.

You may have to adjust some of the properties in the init target to fit your particular CF install. This was created for CF8 on Windows in standalone server mode. 

When I get some time, I'm planning on hooking Growl up for my Mac peeps too

Update: Now on dzone.com...

Here's the XML code:

<?xml version="1.0" encoding="UTF-8"?>
<project name="cfcompileRadiator" default="notify" basedir=".">
<!-- Setup details -->

<target name="init">
    <condition property="pathroot" value="c:" else="/opt">
        <and>
            <os family="windows" />
        </and>
    </condition>
    <property name="cfusion.home" value="${pathroot}${file.separator}ColdFusion8" />
    <property name="webroot" value="${cfusion.home}${file.separator}wwwroot" />
    <property name="webinf" value="${webroot}${file.separator}WEB-INF" />
    <property name="coldfusion.libpath" value="${cfusion.home}${file.separator}lib" />
    <property name="coldfusion.bootstrap.jar" value="${webinf}${file.separator}lib${file.separator}cfmx_bootstrap.jar" />
    <property name="coldfusion.cfx.jar" value="${webinf}${file.separator}lib${file.separator}cfx.jar" />
    <property name="coldfusion.compiler.classpath" value="${coldfusion.libpath}${file.separator}updates,${coldfusion.libpath}" />
    <property name="coldfusion.compiler.libpath" value="${coldfusion.libpath}" />
    <property name="j2ee.jar" value="${cfusion.home}${file.separator}runtime${file.separator}lib${file.separator}jrun.jar" />
    <property name="snarl.path" value="${pathroot}${file.separator}Program Files${file.separator}full phat${file.separator}Snarl${file.separator}extras${file.separator}sncmd" />
</target>

    <target name="compile" depends="init">
        <java classname="coldfusion.tools.CommandLineInvoker"
            failonerror="false"
            fork="true"
            resultproperty="cfcompile.resultCode"
            output="${cfusion.home}${file.separator}cfcompile.log"
            outputProperty="cfcompile.output">
            <classpath>
                <pathelement location="${j2ee.jar}" />
                <pathelement location="${coldfusion.bootstrap.jar}" />
                <pathelement location="${coldfusion.cfx.jar}" />
            </classpath>
            <sysproperty key="coldfusion.classPath" value="${coldfusion.compiler.classpath}" />
            <sysproperty key="coldfusion.libPath" value="${coldfusion.compiler.libpath}" />
            <arg line="Compiler "/>
            <arg line=" -cfroot ${cfusion.home} "/>
            <arg line=" -webinf ${webinf} "/>
            <arg line=" -webroot ${webroot} "/>
            <arg line=" ${resource_loc}"/>
        </java>
    </target>

    <target name="notify" depends="compile">
        <if>
            <equals arg1="${cfcompile.resultCode}" arg2="1" />
            <then>
                <exec failonerror="true" dir="${snarl.path}" executable="cmd.exe">
                    <arg line="/c snarl_command.exe /M &quot;cfcompile failed&quot; &quot;Problem found in ${resource_loc}&quot;" />
                </exec>
            </then>
        </if>
    </target>

</project>

 


About this entry