ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Patrick Martin <antu...@gmail.com>
Subject Re: AW: AW: loop in ant
Date Tue, 24 Jan 2006 16:05:13 GMT
Hello,

I once tried to implement a while task but I had an issue with some
conditions like equal.

<while>
  <equal arg1="${myprop}" arg2="myvalue"/>
  <do> ... </do>
</while>

the property used in equal is evaluated before the call to equal, and only
once. So it will never change.
Is there a way to avoid that?

Here is the code I used:

public class WhileTask extends ConditionBase {

    private Sequential todo = null;

    public void addDo(Sequential t) {
        if (todo != null) {
            throw new BuildException("You must not nest more than one <do>
into <while>");
        }
        todo = t;
    }

    public void execute() throws BuildException {
        if (countConditions() > 1) {
            throw new BuildException("You must not nest more than one
condition into <while>");
        }
        if (countConditions() < 1) {
            throw new BuildException("You must nest a condition into
<while>");
        }
        Condition c = (Condition) getConditions().nextElement();
        while (c.eval()) {
            if (todo != null) {
                todo.execute();
            }
        }
    }
}

Patrick.

On 1/24/06, Jan.Materne@rzf.fin-nrw.de <Jan.Materne@rzf.fin-nrw.de> wrote:
>
> >Ok. Sorry about that.
>
> no problem.
>
> >But there's no other way to do it? I
> >cant make my own tasks.
>
> It´s not difficult.
> Basically you can do the same using <script>/<scriptdef> and programming
> with a scripting language against the Ant API. But I think dealing with
> mappers and conditions could be easier using Java. Especially if you want to
> use threads.
>
>
> Jan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message