#33 while task

open
nobody
None
5
2005-03-30
2005-03-30
No

Hi,

I made a while task, using the if task as a starting point.

The task is used like this:
<while>
...
<do>
...
</do>
</while>

Here is the class:

package net.sf.antcontrib.logic;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.Sequential;
import org.apache.tools.ant.taskdefs.condition.Condition;
import
org.apache.tools.ant.taskdefs.condition.ConditionBase;

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();
}
}
}
}

I thought this could be part of ant-contrib.

Regards,

Patrick M.

Discussion


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks