Browse Source

Added else attribute to condition task.

PR: 33074


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277520 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 20 years ago
parent
commit
5947ffd64f
5 changed files with 58 additions and 4 deletions
  1. +4
    -0
      WHATSNEW
  2. +9
    -1
      docs/manual/CoreTasks/condition.html
  3. +25
    -0
      src/etc/testcases/taskdefs/condition.xml
  4. +16
    -2
      src/main/org/apache/tools/ant/taskdefs/ConditionTask.java
  5. +4
    -1
      src/testcases/org/apache/tools/ant/taskdefs/ConditionTest.java

+ 4
- 0
WHATSNEW View File

@@ -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
=====================================================



+ 9
- 1
docs/manual/CoreTasks/condition.html View File

@@ -36,6 +36,14 @@ you must specify exactly one condition.</p>
&quot;true&quot;.</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 @@ in the Unix family as well.</p>
operating system is SunOS and if it is running on a sparc architecture.</p>

<hr>
<p align="center">Copyright &copy; 2001-2002 Apache Software
<p align="center">Copyright &copy; 2001-2002, 2005 Apache Software
Foundation. All rights Reserved.</p>

</body>


+ 25
- 0
src/etc/testcases/taskdefs/condition.xml View File

@@ -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" />


+ 16
- 2
src/main/org/apache/tools/ant/taskdefs/ConditionTask.java View File

@@ -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);


+ 4
- 1
src/testcases/org/apache/tools/ant/taskdefs/ConditionTest.java View File

@@ -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");
}
}


Loading…
Cancel
Save