PR: 33074 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277520 13f79535-47bb-0310-9956-ffa450edef68master
@@ -89,6 +89,10 @@ Other changes: | |||||
* Added clone task. Bugzilla report 32631. | * Added clone task. Bugzilla report 32631. | ||||
* Add else attribute to the condition task, which specifies an | |||||
optional alternate value to set the property to if the nested | |||||
condition evaluates to false. Bugzilla report 33074. | |||||
Changes from Ant 1.6.2 to current Ant 1.6 CVS version | Changes from Ant 1.6.2 to current Ant 1.6 CVS version | ||||
===================================================== | ===================================================== | ||||
@@ -36,6 +36,14 @@ you must specify exactly one condition.</p> | |||||
"true".</td> | "true".</td> | ||||
<td valign="top" align="center">No</td> | <td valign="top" align="center">No</td> | ||||
</tr> | </tr> | ||||
<tr> | |||||
<td valign="top">else</td> | |||||
<td valign="top">The value to set the property to if the condition | |||||
evaluates to <i>false</i>. By default the property will remain unset. | |||||
<em>Since Ant 1.6.3</em> | |||||
</td> | |||||
<td valign="top" align="center">No</td> | |||||
</tr> | |||||
</table> | </table> | ||||
<h3><a name="nested">Parameters specified as nested elements</a></h3> | <h3><a name="nested">Parameters specified as nested elements</a></h3> | ||||
<p>All conditions to test are specified as nested elements, for a | <p>All conditions to test are specified as nested elements, for a | ||||
@@ -80,7 +88,7 @@ in the Unix family as well.</p> | |||||
operating system is SunOS and if it is running on a sparc architecture.</p> | operating system is SunOS and if it is running on a sparc architecture.</p> | ||||
<hr> | <hr> | ||||
<p align="center">Copyright © 2001-2002 Apache Software | |||||
<p align="center">Copyright © 2001-2002, 2005 Apache Software | |||||
Foundation. All rights Reserved.</p> | Foundation. All rights Reserved.</p> | ||||
</body> | </body> | ||||
@@ -347,6 +347,31 @@ | |||||
</condition> | </condition> | ||||
<echo>${isfalse-incomplete}</echo> | <echo>${isfalse-incomplete}</echo> | ||||
</target> | </target> | ||||
<target name="testElse"> | |||||
<condition property="unset" value="foo"> | |||||
<or /> | |||||
</condition> | |||||
<condition property="value" value="foo" else="bar"> | |||||
<and /> | |||||
</condition> | |||||
<condition property="else" value="foo" else="bar"> | |||||
<or /> | |||||
</condition> | |||||
<fail> | |||||
<condition> | |||||
<or> | |||||
<isset property="unset" /> | |||||
<not> | |||||
<and> | |||||
<equals arg1="${value}" arg2="foo" /> | |||||
<equals arg1="${else}" arg2="bar" /> | |||||
</and> | |||||
</not> | |||||
</or> | |||||
</condition> | |||||
</fail> | |||||
</target> | |||||
<target name="cleanup" > | <target name="cleanup" > | ||||
<delete file="match1.txt" /> | <delete file="match1.txt" /> | ||||
@@ -1,5 +1,5 @@ | |||||
/* | /* | ||||
* Copyright 2001-2004 The Apache Software Foundation | |||||
* Copyright 2001-2005 The Apache Software Foundation | |||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -42,6 +42,7 @@ public class ConditionTask extends ConditionBase { | |||||
private String property = null; | private String property = null; | ||||
private String value = "true"; | private String value = "true"; | ||||
private String alternative = null; | |||||
/** | /** | ||||
* The name of the property to set. Required. | * The name of the property to set. Required. | ||||
@@ -62,6 +63,16 @@ public class ConditionTask extends ConditionBase { | |||||
value = v; | value = v; | ||||
} | } | ||||
/** | |||||
* The value for the property to set, if condition evaluates to false. | |||||
* If this attribute is not specified, the property will not be set. | |||||
* @param e the alternate value of the property. | |||||
* @since Ant 1.6.3 | |||||
*/ | |||||
public void setElse(String e) { | |||||
alternative = e; | |||||
} | |||||
/** | /** | ||||
* See whether our nested condition holds and set the property. | * See whether our nested condition holds and set the property. | ||||
* | * | ||||
@@ -80,12 +91,15 @@ public class ConditionTask extends ConditionBase { | |||||
if (property == null) { | if (property == null) { | ||||
throw new BuildException("The property attribute is required."); | throw new BuildException("The property attribute is required."); | ||||
} | } | ||||
Condition c = (Condition) getConditions().nextElement(); | Condition c = (Condition) getConditions().nextElement(); | ||||
if (c.eval()) { | if (c.eval()) { | ||||
log("Condition true; setting " + property + " to " + value, | log("Condition true; setting " + property + " to " + value, | ||||
Project.MSG_DEBUG); | Project.MSG_DEBUG); | ||||
getProject().setNewProperty(property, value); | getProject().setNewProperty(property, value); | ||||
} else if (alternative != null) { | |||||
log("Condition false; setting " + property + " to " + alternative, | |||||
Project.MSG_DEBUG); | |||||
getProject().setNewProperty(property, alternative); | |||||
} else { | } else { | ||||
log("Condition false; not setting " + property, | log("Condition false; not setting " + property, | ||||
Project.MSG_DEBUG); | Project.MSG_DEBUG); | ||||
@@ -1,5 +1,5 @@ | |||||
/* | /* | ||||
* Copyright 2002,2004 The Apache Software Foundation | |||||
* Copyright 2002, 2004-2005 The Apache Software Foundation | |||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -226,5 +226,8 @@ public class ConditionTest extends BuildFileTest { | |||||
"Nothing to test for falsehood"); | "Nothing to test for falsehood"); | ||||
} | } | ||||
public void testElse() { | |||||
executeTarget("testElse"); | |||||
} | |||||
} | } | ||||