diff --git a/WHATSNEW b/WHATSNEW index 2927efe62..11cf9de08 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -89,6 +89,10 @@ Other changes: * 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 ===================================================== diff --git a/docs/manual/CoreTasks/condition.html b/docs/manual/CoreTasks/condition.html index 78a00c6d6..33e571b7c 100644 --- a/docs/manual/CoreTasks/condition.html +++ b/docs/manual/CoreTasks/condition.html @@ -36,6 +36,14 @@ you must specify exactly one condition.

"true". No + + else + The value to set the property to if the condition + evaluates to false. By default the property will remain unset. + Since Ant 1.6.3 + + No +

Parameters specified as nested elements

All conditions to test are specified as nested elements, for a @@ -80,7 +88,7 @@ in the Unix family as well.

operating system is SunOS and if it is running on a sparc architecture.


-

Copyright © 2001-2002 Apache Software +

Copyright © 2001-2002, 2005 Apache Software Foundation. All rights Reserved.

diff --git a/src/etc/testcases/taskdefs/condition.xml b/src/etc/testcases/taskdefs/condition.xml index a9a576531..2b0aed56c 100644 --- a/src/etc/testcases/taskdefs/condition.xml +++ b/src/etc/testcases/taskdefs/condition.xml @@ -347,6 +347,31 @@ ${isfalse-incomplete} + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/org/apache/tools/ant/taskdefs/ConditionTask.java b/src/main/org/apache/tools/ant/taskdefs/ConditionTask.java index 53859dc0e..e90bb9129 100644 --- a/src/main/org/apache/tools/ant/taskdefs/ConditionTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/ConditionTask.java @@ -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 @@ public class ConditionTask extends ConditionBase { private String property = null; private String value = "true"; + private String alternative = null; /** * The name of the property to set. Required. @@ -62,6 +63,16 @@ public class ConditionTask extends ConditionBase { 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. * @@ -80,12 +91,15 @@ public class ConditionTask extends ConditionBase { 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); diff --git a/src/testcases/org/apache/tools/ant/taskdefs/ConditionTest.java b/src/testcases/org/apache/tools/ant/taskdefs/ConditionTest.java index f30968c24..ae7dd1d71 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/ConditionTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/ConditionTest.java @@ -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 @@ public class ConditionTest extends BuildFileTest { "Nothing to test for falsehood"); } + public void testElse() { + executeTarget("testElse"); + } }