You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Nico Seessle <Ni...@epost.de> on 2000/11/08 09:34:27 UTC

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

Another try to include extended control-flow :-)

How about extending the pattern of a Task to allow any task to become and
element of a task if it allow it?

For Example:

<if ...>
  <echo...>
  <fail ...>
</if>

iff the task "if" has a method "public Task createTask(String name)".

This will allow people to include stuff like this (and even <foreach
in="a,b,c"/> which is missing below :-) )

Nico

----- Original Message -----
From: "Marcel Ruff" <ru...@swand.lake.de>
To: "ant-user" <an...@jakarta.apache.org>
Sent: Wednesday, November 08, 2000 9:18 AM
Subject: 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: Fw: Control flow (if,while,for) proposal in ant (xml based).

Posted by Stefan Bodewig <bo...@bost.de>.
Nico Seessle <Ni...@epost.de> wrote:

> From: "Stefan Bodewig" <bo...@bost.de>

>> If we wanted to allow for something like this, I'd probably see it
>> along the lines of

>> public abstract class EnvelopeTask extends Task {

>> and add a EnvelopeTaskHandler to ProjectHelper to support this.

> I'm not sure I understand this...

> ProjectHelper will only allow for createTask in subclasses of
> EnvelopeTask?

That's the idea, yes. I wouldn't want to have people accidently
enclose a task into mkdir for example. If you want a Task that can
hold other tasks (like a <while> task), say so by extending
EnvelopeTask.

And keep in mind, that I'm not really proposing to do something like
this, just lining out what *I* could live with.

Stefan

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

Posted by Nico Seessle <Ni...@epost.de>.
----- Original Message -----
From: "Stefan Bodewig" <bo...@bost.de>
To: <an...@jakarta.apache.org>
Sent: Thursday, November 09, 2000 3:07 PM
Subject: Re: Fw: Control flow (if,while,for) proposal in ant (xml based).


> Nico Seessle <Ni...@epost.de> wrote:
>
> > How about extending the pattern of a Task to allow any task to
> > become and element of a task if it allow it?
>
> If we wanted to allow for something like this, I'd probably see it
> along the lines of
>
> public abstract class EnvelopeTask extends Task {
>
>     file://call project.createTask and do something clever with it
>     public abstract Task createTask(String name);
> }
>
> and add a EnvelopeTaskHandler to ProjectHelper to support this.

I'm not sure I understand this...

ProjectHelper will only allow for createTask in subclasses of EnvelopeTask?

Nico



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

Posted by Stefan Bodewig <bo...@bost.de>.
Nico Seessle <Ni...@epost.de> wrote:

> How about extending the pattern of a Task to allow any task to
> become and element of a task if it allow it?

If we wanted to allow for something like this, I'd probably see it
along the lines of

public abstract class EnvelopeTask extends Task {

    //call project.createTask and do something clever with it
    public abstract Task createTask(String name);
}

and add a EnvelopeTaskHandler to ProjectHelper to support this.

This would allow people to write <if>, <switch>, <while> tasks with
all kinds of logic in them - and it still was inside a task, not
inside Ant.

I'd prefer a solution like this over extending control structures
internal to Ant, but I'm not really fond of it.

+0

is probably my best answer.

Stefan