Embedded & Engineering Insights
The new collection of ant tasks from http://ant-contrib.sourceforge.net/ comes with some useful and interesting tasks, that one will find handy when making a build file:
Among those tasks the following ones helped me a lot :
Variable:
<var name=”osfamily” value=”win”/>
use it as a property:
<echo message=”${osfamily}”/>
another cool feature is overriding properties through parameter unset=”true”
having property x:
<property name=”x” value=”aaa”>
you can overwrite it with:
<var name=”x” value”bbb” unset=”true”>
and use it as a normal property:
<echo message=”new value of x is ${x}”>
osfamily
Can detect various os, possible values include “unix”, “dos”, “mac”, “os/2”, “os/400”, “z/os”, “tandem” and “windows”.
<osfamily property=”os.family”/>
<echo message=”os: ${os.family}”/>
<if>
<equals arg1=”${os.family}” arg2=”windows”/ >
<then>
…
</then>
<else>
…
</else>
</if>
antcallback
AntCallBack is identical to the standard ‘antcall’ task, except that it allows properties set in the called target to be available in the calling target.
<target name=”init-db”depends=”init”>
<var name=”databaseURL” value=”url_1″/>
<var name=”databaseDriver” value=”driver_1″/>
</target>
<target name=”install” depends=”init”>
<antcallback target=”init-db” return=”databaseURL” />
<echo message=”foreign prop: databaseURL = ${databaseURL}”/>
</target>
you can use ${databaseURL} as if it was defined locally. This combined with the task gives you complete control of
variable throughout your script.
Propertycopy
Have you ever wished to do something like ${${prop_name}_postfix}, you can do it now like this
<property name="database_type" value="mssql"/>
<property name="mssql_databaseDialect" value="net.sf.hibernate.dialect.SQLServerDialect"/>
<propertycopy name="databaseDialect" from="${database_type}_databaseDialect" />
<echo message="databaseDialect: ${databaseDialect}" />
Shellscript
It is an extension of the “exec” task, and as such, supports the same attributes.
<shellscript shell="sh" dir=".">
chmod +x ${deploy.dir}file.sh
</shellscript>
or
<shellscript shell="sh" dir=".">
file.sh arg1
</shellscript>
Other cool features like:
Logic Tasks( if, for,foreach, outoutdate, runTarget, switch etc),
Network Tasks (HTTP Post, AntServer / RemoteAnt)
Performance Monitoring and Tasks( Performance Monitor, Stopwatch )
Platform Tasks (Osfamily, Shellscript)
Property Tasks (Math, Propertycopy, SortList, URLEncode, Variable )
Process Tasks (Forget, Limit )
Other Tasks (antclipse, IniFile, VerifyDesign )
can be explored at http://ant-contrib.sourceforge.net/tasks/tasks/index.html
Another special task is CC Task – Compile and link task.
cc Task – can compile various source languages and produce executables, shared libraries (aka DLLs), and static libraries. Compiler adaptors are currently available for several C/C++ compilers, FORTRAN, MIDL, and Windows Resource files.
for more info check http://ant-contrib.sourceforge.net/cc.html