Update to CAT.NET NAnt Target

This post was written by dpx on January 1, 2009
Posted Under: .NET, Programming

Yesterday I posted about automating CAT.NET. Today while adding it to another build file, I ran across a great error! The tool did not detect any vulnerabilities in my code and therefore the XPath used in the xmlpeek task failed! This caused the build to fail with a false positive. I’ve updated my target to include the failonerror=”false” for the xmlpeek task and an if statement around the fail task that checks for the hasError property first. If it doesn’t exist the xmlpeek task did not find anything to put in the property and we do not need to fail the build.

Here is the new task:

<target name=”catnet” description=”Runs the CAT.NET static code analysis tool on a set of libraries”>
<exec program=”${root.dir}\Microsoft\CAT.NET\CatNetCmd.exe” workingdir=”.” output=”catnetout.log”>
<arg value=”/file:${build.dir}\${project::get-name()}.Models.dll” />
<arg value=”/file:${build.dir}\${project::get-name()}.Views.dll” />
<arg value=”/file:${build.dir}/${project::get-name()}.Presenters.dll” />
<arg value=”/file:${build.dir}/${project::get-name()}.Web.dll” />
<arg value=”/report:${reports.dir}\CatNetReport.xml” />
<arg value=”/reportxsloutput:${reports.dir}\CatNetReport.html” />
</exec>

<!– Check for errors since the command doesn’t throw error codes –>
<loadfile file=”catnetout.log” property=”catnetout” />
<fail if=”${string::contains(catnetout, ‘ERROR’)}” message=”There was an error running CAT.NET Static Analysis” />
<!– Clean up if we didn’t error out –>
<delete file=”catnetout.log” />

<xmlpeek file=”${reports.dir}\CatNetReport.xml”
property=”hasErrors”
xpath=”//Rule[TotalResults>0]/Results/Result/ProblemDescription” failonerror=”false” />
<if test=”${property::exists(‘hasErrors’)}”>
<fail if=”${string::get-length(hasErrors) &gt; 0}” message=”CAT.NET found at least one problem: ${hasErrors}” />
</if>
</target>

Add a Comment

You must be logged in to post a comment.