diff options
author | mattinger <[email protected]> | 2007-03-07 15:17:05 +0000 |
---|---|---|
committer | mattinger <[email protected]> | 2007-03-07 15:17:05 +0000 |
commit | a65513e8cdb2a4f006ecc877b310ea9a2febdbf7 (patch) | |
tree | 4ba7cb363a1c2c4dfecc3048bcb66f43b5fbb3db | |
parent | 8e97f1595dfa63ef3351f178c29f6d37deab5354 (diff) |
git-svn-id: file:///home/sven/projects/JOGL/temp/ant-contrib/svn/ant-contrib-code/trunk/ant-contrib@97 32d7a393-a5a9-423c-abd3-5d954feb1f2f
-rw-r--r-- | src/java/net/sf/antcontrib/logic/Assert.java | 95 |
1 files changed, 66 insertions, 29 deletions
diff --git a/src/java/net/sf/antcontrib/logic/Assert.java b/src/java/net/sf/antcontrib/logic/Assert.java index 7c77964..232bd83 100644 --- a/src/java/net/sf/antcontrib/logic/Assert.java +++ b/src/java/net/sf/antcontrib/logic/Assert.java @@ -22,63 +22,100 @@ import java.util.List; import net.sf.antcontrib.logic.condition.BooleanConditionBase; import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.ProjectHelper; import org.apache.tools.ant.Task; import org.apache.tools.ant.TaskContainer; import org.apache.tools.ant.taskdefs.Exit; import org.apache.tools.ant.taskdefs.Sequential; import org.apache.tools.ant.taskdefs.condition.Condition; +import org.apache.tools.ant.taskdefs.condition.Equals; /** * */ public class Assert - extends BooleanConditionBase - implements TaskContainer { + extends BooleanConditionBase { private List tasks = new ArrayList(); private String message; - private boolean failOnError; - + private boolean failOnError = true; + private boolean execute = true; + private Sequential sequential; + private String name; + private String value; - public void setFailOnError(boolean failOnError) { - this.failOnError = failOnError; - } - + public Sequential createSequential() { + this.sequential = (Sequential) getProject().createTask("sequential"); + return this.sequential; + } + + public void setName(String name) { + this.name = name; + } + + public void setValue(String value) { + this.value = value; + } + public void setMessage(String message) { this.message = message; } - public void addTask(Task task) { - tasks.add(task); - } - public BooleanConditionBase createBool() { return this; } + public void setExecute(boolean execute) { + this.execute = execute; + } + + public void setFailOnError(boolean failOnError) { + this.failOnError = failOnError; + } + public void execute() { - if (countConditions() == 0) { - throw new BuildException("There is no condition specified."); - } - else if (countConditions() > 1) { - throw new BuildException("There must be exactly one condition specified."); - } + String value = getProject().getProperty("ant.enable.asserts"); + boolean assertsEnabled = Project.toBoolean(value); - Sequential sequential = (Sequential) getProject().createTask("sequential"); - Condition c = (Condition) getConditions().nextElement(); - if (! c.eval()) { - if (failOnError) { - Exit fail = (Exit) getProject().createTask("fail"); - fail.setMessage(message); - sequential.addTask(fail); + if (assertsEnabled) { + if (name != null) { + if (value == null) { + throw new BuildException("The 'value' attribute must accompany the 'name' attribute."); + } + String propVal = getProject().replaceProperties("${" + name + "}"); + Equals e = new Equals(); + e.setArg1(propVal); + e.setArg2(value); + addEquals(e); + } + + if (countConditions() == 0) { + throw new BuildException("There is no condition specified."); + } + else if (countConditions() > 1) { + throw new BuildException("There must be exactly one condition specified."); + } + + Condition c = (Condition) getConditions().nextElement(); + if (! c.eval()) { + if (failOnError) { + Exit fail = (Exit) getProject().createTask("fail"); + fail.setMessage(message); + fail.execute(); + } + } + else { + if (execute) { + this.sequential.execute(); + } } } else { - Iterator it = tasks.iterator(); - while (it.hasNext()) { - sequential.addTask((Task)it.next()); - } + if (execute) { + this.sequential.execute(); + } } } |