ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marcel Ruff <>
Subject Control flow (if,while,for) proposal in ant (xml based).
Date Wed, 08 Nov 2000 08:18:28 GMT

what about some control flow in build.xml:

  <if string="${MYAPP}" equals="cool" target="build_cool" />

Here if the environment MYAPP is set to "cool",
the target "build_cool" is invoked.
Other attributes could be 'notequals' 'contains_substring' etc.

  <if string="${MYAPP}" length="0" target="build_error" />

Here if the string size is 0 (MYAPP not set) we jump
to target "build_error".

The "else if" control flow could look as follows:

  <if string="${MYAPP}" length="0" target="build_error">
    <elseif string="${MYAPP}" equals="cool" target="build_cool"/>
    <elseif string="${MYAPP}" equals="tomcat" target="deploy_tomcat"/>
    <else target="deploy_jboss"/>

The "while" could look like:

     <if string="${MYAPP}" length="0" action="continue" />
     <if string="${MYAPP}" equals="cool" target="build_cool" />
     <if string="${STOP_IT}" equals="true" action="break" />

Anywhere else we can set

  <property name="STOP_IT" value="true"/>

to stop the loop.

The "for" could look like:

  <for iterator="ii" start="0" end="10" step="1">
     <if int="${ii}" equals="5" target="build_cool" />
     <if int="${ii}" ge="7" target="build_other" />
     <if string="${STOP_IT}" equals="true" action="break" />

The 'iterator' attribute declares the name of the iterator
The attributes for 'if' when of type 'int' could be
'ge' (greater or equals), le (lower or equals) etc.

To know more about the users environment, we could extend
the "ant" script with a shell loop feeding all OS env settings
to ant:

# ant
for i in ${ALL_ENV} ; do
    MY_DEF="${MY_DEF} -Denv.$i"
$JAVACMD -classpath $LOCALCLASSPATH -Dant.home=${ANT_HOME} ${MY_DEF}

The environment variable 
would be available in build.xml like

The token 'env.' is a namespace to classify operating system
environment variables.

(I don't know how such stuff is done with Windows, is anybody
out there still using win?)

I could implement it (but the next weeks i have no time
at all).

What do you think
does it makes sense?


Marcel Ruff

View raw message