varScoper Ant Target example

July 8, 2008 by Mike Henke    4 Comments
Posted under: Ant · ColdFusion · MXUnit

If you haven't heard of the vaScoper tool created and maintained by Mike Schierberl, it is definately worth checking out. It has the stamp of approval of Raymond Camden and Sean Corfield.

Here is a varScoper ant target recently added to the MXUnit build ant. Download both tools and give them a test drive.

<target name="varScopeCheck" depends="init">
<!— MUST HAVE VARSCOPER IN WEBROOT —>
<echo>Check for unscoped variables</echo>
<!— load the varScoper task —>
<taskdef name="conGet" classname="com.varscoper.ant.task.ConditionalGet" classpathref="project.classpath" />

<property file="${antrunner.file}" />
<property name="filePathToUse" value="${webroot}"/>
<property name="recursiveDirectory" value="true" />

<conGet dest="varScoper.csv" url="
http://${server}:${port}/varscoper/varScoper.cfm" >
<parameter name ="filePath" value="${filePathToUse}" />
<parameter name="displayFormat" value ="csv" />
<parameter name="recursiveDirectory" value = "${recursiveDirectory}" />

<!—
<FailIfNotFound pattern="&lt;results&gt;&lt;/results&gt;" />
<FailIfFound pattern=".cfc" message="var scope violation is found." />
<FailIfFound pattern=".cfm" message="var scope violation is found." />
—>
</conGet>

<!— check csv file for any violations —>
<loadfile srcfile="varScoper.csv" property="varScoper.cvs">
<filterchain>
<headfilter skip="1"/>
<trim/>
</filterchain>
</loadfile>

<!— will be set if violations found else variable will be unset —>
<echo>${varScoper.cvs}</echo>

<fail message="var scope violation is found.">
<condition>
<isset property="varScoper.cvs"/>
</condition>
</fail>

<echo>Successful check for unscoped variables</echo>
</target>

4 Comments + Add Comment

  • Jim Priest

    So do I need MXUnit to make use of this? Added to the wiki!

  • Mike Henke

    No, but reviewing the MXUnit build file Marc created might help. I'll try to add a zip with everything set. Until then you should be able to plug in the the varScoper ant target and run with it in your ant script just make sure the properties are set somewhere like ${filePathToUse}.

  • Mike Schierberl

    Mike, I simplified the build.xml file that I'm including in the next release. There's really no need to use the external .jar and the conGet task.

    You can remove the taskdef and replace the conGet with...



    This makes the build file simpler and makes setup easier now that we don't rely on an external .jar.

  • Mike Henke

    Great. I can't wait for the next release.

  • Got anything to say? Go ahead and leave a comment!