Monday, November 9, 2009

Using ANT to replace tokens

Just thought I would post this little snippet from an ANT build file.  I wanted to literally copy code into a file during the build instead of using a <cfinclude> in my code. This eeked out a 2-3% faster performance.  Basically the <loadfile> loads the contains of the file into a property and then I use the <replace> task to look for a token and replace it with the value from the property.  Hope this helps somebody else.





<echo message="Converting custom tag library includes to inline."/>
<loadfile srcfile="${dest}/MachII/customtags/baseTagBuilder.cfm" property="include.baseTagBuilder" />
<replace dir="${dest}/MachII/customtags/"
    includes="**/*.cfm"
    value="${include.baseTagBuilder}">
    <replacetoken><![CDATA[<cfinclude template="/MachII/customtags/baseTagBuilder.cfm" />]]></replacetoken>
</replace>
<loadfile srcfile="${dest}/MachII/customtags/form/helper/formTagBuilder.cfm" property="include.formTagBuilder" />
<replace dir="${dest}/MachII/customtags/"
    includes="**/*.cfm"
    value="${include.formTagBuilder}">
    <replacetoken><![CDATA[<cfinclude template="/MachII/customtags/form/helper/formTagBuilder.cfm" />]]></replacetoken>
</replace>
<loadfile srcfile="${dest}/MachII/customtags/view/helper/viewTagBuilder.cfm" property="include.viewTagBuilder" />
<replace dir="${dest}/MachII/customtags/"
    includes="**/*.cfm"
    value="${include.viewTagBuilder}">
    <replacetoken><![CDATA[<cfinclude template="/MachII/customtags/view/helper/viewTagBuilder.cfm" />]]></replacetoken>
</replace>


No comments:

Post a Comment