diff --git a/docs/manual/CoreTasks/fail.html b/docs/manual/CoreTasks/fail.html index 125bc2075..7801fe7f4 100644 --- a/docs/manual/CoreTasks/fail.html +++ b/docs/manual/CoreTasks/fail.html @@ -41,10 +41,10 @@ or character data nested into the element.
As an alternative to the if/unless attributes,
- conditional failure can be achieved using a single nested condition.
- For a complete list of core conditions, as well as information
- about custom conditions, see here.
- Since Ant 1.6.2
+ conditional failure can be achieved using a single nested
+ <condition> element, which should contain exactly one
+ core or custom condition. For information about conditions, see
+ here.
Since Ant 1.6.2
<fail> - <not> - <isset property="thisdoesnotexist"/> - </not> + <condition> + <not> + <isset property="thisdoesnotexist"/> + </not> + </condition> </fail>diff --git a/src/etc/testcases/taskdefs/fail.xml b/src/etc/testcases/taskdefs/fail.xml index b7b7f3037..d32c2c6c9 100644 --- a/src/etc/testcases/taskdefs/fail.xml +++ b/src/etc/testcases/taskdefs/fail.xml @@ -28,54 +28,87 @@
ConditionBase
.
+ * @since Ant 1.6.2
+ */
+ public ConditionBase createCondition() {
+ if (nestedCondition != null) {
+ throw new BuildException("Only one nested condition is allowed.");
+ }
+ nestedCondition = new NestedCondition();
+ return nestedCondition;
+ }
+
/**
* test the if condition
* @return true if there is no if condition, or the named property exists
@@ -156,21 +183,22 @@ public class Exit extends ConditionBase {
* @return true if there is none, or it evaluates to true
*/
private boolean testNestedCondition() {
- if (ifCondition != null || unlessCondition != null) {
- throw new BuildException("Nested conditions "
- + "not permitted in conjunction with if/unless attributes");
- }
+ boolean result = nestedConditionPresent();
- int count = countConditions();
- if (count > 1) {
- throw new BuildException("Too many conditions: " + count);
+ if (result && ifCondition != null || unlessCondition != null) {
+ throw new BuildException("Nested conditions "
+ + "not permitted in conjunction with if/unless attributes");
}
- return (count == 0) ? true
- : (((Condition)(getConditions().nextElement())).eval());
+ return result && nestedCondition.eval();
}
+ /**
+ * test whether there is a nested condition.
+ * @return boolean
.
+ */
private boolean nestedConditionPresent() {
- return (countConditions() > 0);
+ return (nestedCondition != null);
}
+
}
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/FailTest.java b/src/testcases/org/apache/tools/ant/taskdefs/FailTest.java
index f5df9932d..033865894 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/FailTest.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/FailTest.java
@@ -138,7 +138,7 @@ public class FailTest extends BuildFileTest {
public void testNested5() {
expectSpecificBuildException("testNested5",
"it is required to fail :-)",
- "Too many conditions: 2");
+ "Only one nested condition is allowed.");
}
public void testNested6() {
@@ -147,4 +147,17 @@ public class FailTest extends BuildFileTest {
"testNested6\ntestNested6\ntestNested6");
}
- }
+ public void testNested7() {
+ String specificMessage = "A single nested condition is required.";
+
+ char[] c = {'a', 'b'};
+ StringBuffer target = new StringBuffer("testNested7x");
+
+ for (int i = 0; i < c.length; i++) {
+ target.setCharAt(target.length() - 1, c[i]);
+ expectSpecificBuildException(target.toString(),
+ "it is required to fail :-)", specificMessage);
+ }
+ }
+
+}