|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.tools.ant.ProjectComponent org.apache.tools.ant.taskdefs.condition.ConditionBase net.sf.antcontrib.logic.IfTask
public class IfTask
Perform some tasks based on whether a given condition holds true or not.
This task is heavily based on the Condition framework that can be found in Ant 1.4 and later, therefore it cannot be used in conjunction with versions of Ant prior to 1.4.
This task doesn't have any attributes, the condition to test is
specified by a nested element - see the documentation of your
<condition>
task (see
the
online documentation for example) for a complete list of nested
elements.
Just like the <condition>
task, only a single
condition can be specified - you combine them using
<and>
or <or>
conditions.
In addition to the condition, you can specify three different
child elements, <elseif>
, <then>
and
<else>
. All three subelements are optional.
Both <then>
and <else>
must not be
used more than once inside the if task. Both are
containers for Ant tasks, just like Ant's
<parallel>
and <sequential>
tasks - in fact they are implemented using the same class as Ant's
<sequential>
task.
<elseif>
behaves exactly like an <if>
except that it cannot contain the <else>
element
inside of it. You may specify as may of these as you like, and the
order they are specified is the order they are evaluated in. If the
condition on the <if>
is false, then the first
<elseif>
who's conditional evaluates to true
will be executed. The <else>
will be executed
only if the <if>
and all <elseif>
conditions are false.
Use the following task to define the <if>
task before you use it the first time:
<taskdef name="if" classname="net.sf.antcontrib.logic.IfTask" />
<if> <equals arg1="${foo}" arg2="bar" /> <then> <echo message="The value of property foo is bar" /> </then> <else> <echo message="The value of property foo is not bar" /> </else> </if>
<if> <equals arg1="${foo}" arg2="bar" /> <then> <echo message="The value of property foo is 'bar'" /> </then> <elseif> <equals arg1="${foo}" arg2="foo" /> <then> <echo message="The value of property foo is 'foo'" /> </then> </elseif> <else> <echo message="The value of property foo is not 'foo' or 'bar'" /> </else> </if>
Nested Class Summary | |
---|---|
static class |
IfTask.ElseIf
|
Field Summary |
---|
Fields inherited from class org.apache.tools.ant.ProjectComponent |
---|
project |
Constructor Summary | |
---|---|
IfTask()
|
Method Summary | |
---|---|
void |
addElse(org.apache.tools.ant.taskdefs.Sequential e)
A nested <else> element - a container of tasks that will be run if the condition doesn't hold true. |
void |
addElseIf(IfTask.ElseIf ei)
A nested Else if task |
void |
addThen(org.apache.tools.ant.taskdefs.Sequential t)
A nested <then> element - a container of tasks that will be run if the condition holds true. |
void |
execute()
|
Methods inherited from class org.apache.tools.ant.taskdefs.condition.ConditionBase |
---|
add, addAnd, addAvailable, addChecksum, addContains, addEquals, addFilesMatch, addHttp, addIsFalse, addIsReference, addIsSet, addIsTrue, addNot, addOr, addOs, addSocket, addUptodate, countConditions, getConditions |
Methods inherited from class org.apache.tools.ant.ProjectComponent |
---|
getProject, log, log, setProject |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public IfTask()
Method Detail |
---|
public void addElseIf(IfTask.ElseIf ei)
public void addThen(org.apache.tools.ant.taskdefs.Sequential t)
Not required.
public void addElse(org.apache.tools.ant.taskdefs.Sequential e)
Not required.
public void execute() throws org.apache.tools.ant.BuildException
org.apache.tools.ant.BuildException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |