mbenson 2005/01/27 13:01:05
Modified: . WHATSNEW
src/main/org/apache/tools/ant/taskdefs ConditionTask.java
src/testcases/org/apache/tools/ant/taskdefs
ConditionTest.java
src/etc/testcases/taskdefs condition.xml
docs/manual/CoreTasks condition.html
Log:
Added else attribute to condition task.
PR: 33074
Revision Changes Path
1.732 +4 -0 ant/WHATSNEW
Index: WHATSNEW
===================================================================
RCS file: /home/cvs/ant/WHATSNEW,v
retrieving revision 1.731
retrieving revision 1.732
diff -u -r1.731 -r1.732
--- WHATSNEW 27 Jan 2005 16:36:11 -0000 1.731
+++ WHATSNEW 27 Jan 2005 21:01:05 -0000 1.732
@@ -89,6 +89,10 @@
* 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
=====================================================
1.21 +17 -3
ant/src/main/org/apache/tools/ant/taskdefs/ConditionTask.java
Index: ConditionTask.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/ConditionTask.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- ConditionTask.java 9 Mar 2004 16:48:04 -0000 1.20
+++ ConditionTask.java 27 Jan 2005 21:01:05 -0000 1.21
@@ -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");
* you may not use this file except in compliance with the License.
@@ -42,6 +42,7 @@
private String property = null;
private String value = "true";
+ private String alternative = null;
/**
* The name of the property to set. Required.
@@ -63,6 +64,16 @@
}
/**
+ * 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.
*
* @since Ant 1.4
@@ -80,12 +91,15 @@
if (property == null) {
throw new BuildException("The property attribute is required.");
}
-
Condition c = (Condition) getConditions().nextElement();
if (c.eval()) {
log("Condition true; setting " + property + " to " + value,
Project.MSG_DEBUG);
getProject().setNewProperty(property, value);
+ } else if (alternative != null) {
+ log("Condition false; setting " + property + " to " +
alternative,
+ Project.MSG_DEBUG);
+ getProject().setNewProperty(property, alternative);
} else {
log("Condition false; not setting " + property,
Project.MSG_DEBUG);
1.11 +4 -1
ant/src/testcases/org/apache/tools/ant/taskdefs/ConditionTest.java
Index: ConditionTest.java
===================================================================
RCS file:
/home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/ConditionTest.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ConditionTest.java 9 Mar 2004 16:48:57 -0000 1.10
+++ ConditionTest.java 27 Jan 2005 21:01:05 -0000 1.11
@@ -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");
* you may not use this file except in compliance with the License.
@@ -226,5 +226,8 @@
"Nothing to test for falsehood");
}
+ public void testElse() {
+ executeTarget("testElse");
+ }
}
1.4 +25 -0 ant/src/etc/testcases/taskdefs/condition.xml
Index: condition.xml
===================================================================
RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/condition.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- condition.xml 1 Jun 2002 12:26:36 -0000 1.3
+++ condition.xml 27 Jan 2005 21:01:05 -0000 1.4
@@ -347,6 +347,31 @@
</condition>
<echo>${isfalse-incomplete}</echo>
</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" >
<delete file="match1.txt" />
1.14 +9 -1 ant/docs/manual/CoreTasks/condition.html
Index: condition.html
===================================================================
RCS file: /home/cvs/ant/docs/manual/CoreTasks/condition.html,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- condition.html 4 Sep 2002 11:05:16 -0000 1.13
+++ condition.html 27 Jan 2005 21:01:05 -0000 1.14
@@ -36,6 +36,14 @@
"true".</td>
<td valign="top" align="center">No</td>
</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>
<h3><a name="nested">Parameters specified as nested elements</a></h3>
<p>All conditions to test are specified as nested elements, for a
@@ -80,7 +88,7 @@
operating system is SunOS and if it is running on a sparc architecture.</p>
<hr>
-<p align="center">Copyright © 2001-2002 Apache Software
+<p align="center">Copyright © 2001-2002, 2005 Apache Software
Foundation. All rights Reserved.</p>
</body>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]