Tips on Ant script

Tokenizer user input

ANT can be used as great tool for tokenizing user input during application builiding process. This script will take a string from user input and tokenize in multiple string.

Limitation : Currently this script tokenize single seperator only.


[input] Enter site name
[input] Enter seperator
[echo] www
[echo] google
[echo] com

The script is as follows :

<?xml version=”1.0″ encoding=”UTF-8″?>
<project name=”Split input parameter” basedir=”.” default=”split”>

<taskdef resource=”net/sf/antcontrib/antlib.xml”>
<pathelement location=”${basedir}/lib/ant-contrib-1.0b3.jar”/>

<scriptdef name=”split” language=”javascript”>
<attribute name=”value”/>
<attribute name=”sep”/>
<attribute name=”prefix”/>
values = attributes.get(“value”).split(attributes.get(“sep”));
str = “”;
for(i=0; i<values.length; i++) {
str = str + “,” + values[i];
str = str.substring(str.indexOf(“,”) + 1, str.length);
project.setNewProperty(attributes.get(“prefix”),    str);

<target name=”split” description=”Tokenised input parameter”>
<input message=”Enter site name” addproperty=”site”/>
<input message=”Enter seperator” addproperty=”seperator”/>
<split value=”${site}” sep=”${seperator}” prefix=”value”/>
<property name=”list” value=”${value}”/>
<for list=”${list}” param=”letter”>
<echo message=”@{letter}”/>

This entry was posted in ANT. Bookmark the permalink.

One Response to Tips on Ant script

  1. Pingback: jesse

Leave a Reply