You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Marcel Ruff <ru...@swand.lake.de> on 2000/11/08 09:18:28 UTC

Control flow (if,while,for) proposal in ant (xml based).

Hi,

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"/>
  </if>


The "while" could look like:

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

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" />
     ...
  </for>

The 'iterator' attribute declares the name of the iterator
variable.
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
...
ALL_ENV=`env`
MY_DEF=""
for i in ${ALL_ENV} ; do
    MY_DEF="${MY_DEF} -Denv.$i"
done
$JAVACMD -classpath $LOCALCLASSPATH -Dant.home=${ANT_HOME} ${MY_DEF}
$ANT_OPTS org.apache.tools.ant.Main $@
-----------------------

The environment variable 
   $TOMCAT_HOME
would be available in build.xml like
   ${env.TOMCAT_HOME}

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


-- 
Marcel Ruff
mailto:ruff@swand.lake.de
http://www.lake.de/home/lake/swand/
http://www.xmlBlaster.org

Re: Control flow (if,while,for) proposal in ant (xml based).

Posted by Stefan Bodewig <bo...@bost.de>.
>>>>> "MR" == Marcel Ruff <ru...@swand.lake.de> writes:

 MR> Hi, what about some control flow in build.xml:

 MR> What do you think

No, please let's keep these things out of Ant.

 MR> does it makes sense?

Yes, but not as a part of Ant. Having a second tool that takes a XML
file containing what you describe and creating a Ant build file (like
configure for make) would be nice though.

Putting these kind of things right into Ant would make Ant something
different than it is today - and not for the better of it IMHO.

Stefan