Quote:
The problem with velocity logging is that it thinks everything is a warning
Did find the verbosity of logging annoying yet helpful and necessary last time i used tools (reveng).
Discussion prompted me to dig up some of my own codegen codebase which elicited the usual (for me anyway..) cringe factor when you look at stuff you wrote more than a few years ago:
Eg. Logging from a template, assumes you inject a commons logger into the model as 'logger' (rarely ever used this, but as an example of the powerfully dangerous 'eval' built-in..):
Code:
<#macro log message level="info">${"logger.${level}"?eval("${message}")}</#macro>
Dont recall *ever* using this abomination but I must have written it!
Code:
<#macro logvars object members level="info">
<#list members?word_list as member>
${"logger.${level}"?eval("${object}.${member} = ${object?eval[member]}")}
</#list>
</#macro>
Can u detect the aroma of perl here? eval is your friend ;o)
The essential parameter list:
Code:
<#macro csv list postfix="">
<#compress>
<#list list as item>${item.name}${postfix}<#if item_has_next>, </#if></#list>
</#compress>
</#macro>
And la pièce de résistance, extracting the class name from a fqn:
Code:
<#macro shortType type>
<#compress>
<#assign
lastdot = type?last_index_of('.')
length = type?length
>
<#if lastdot != 0>
${type[(lastdot + 1) .. (length - 1)]}
<#else>
${type}
</#if>
</#compress>
</#macro>
Never used freemarker for ant build files, but experience tells me that writing a macro will clean the escaping up for you. The macro might be as ugly as hell (see above) but your core templates (ie. what yours users see) will be cleaner.
Of course you can also apply DRY priciples and create 'components' using macros; they can call other macros, do callbacks to java code etc. The end result is your templates look a lot more like your target files. (I use freemarker to generate C/C++/Java/SQL code :o)
Will try and have a look at the branch this weekend to give you some feedback.
A.