Author: mbenson
Date: Thu Feb 25 23:24:00 2010
New Revision: 916485
URL: http://svn.apache.org/viewvc?rev=916485&view=rev
Log:
add condition negation
Modified:
ant/antlibs/props/trunk/docs/index.html
ant/antlibs/props/trunk/src/main/org/apache/ant/props/ConditionEvaluator.java
ant/antlibs/props/trunk/src/tests/antunit/condition-test.xml
Modified: ant/antlibs/props/trunk/docs/index.html
URL:
http://svn.apache.org/viewvc/ant/antlibs/props/trunk/docs/index.html?rev=916485&r1=916484&r2=916485&view=diff
==============================================================================
--- ant/antlibs/props/trunk/docs/index.html (original)
+++ ant/antlibs/props/trunk/docs/index.html Thu Feb 25 23:24:00 2010
@@ -128,9 +128,10 @@
attempts to invoke an Ant condition of the given name
setting the given attibute values and evaluates to either
Boolean.TRUE or Boolean.FALSE. Usage looks
- like <em>${os(family=unix)}</em>. This is probably most
- useful together with the if/unless attributes of tasks or
- targets.</td>
+ like <em>${os(family=unix)}</em> / <em>${!os(family=unix)}</em>.
+ This is probably most useful together with the
+ <code>if</code>/<code>unless</code> attributes of tasks or targets.
+ </td>
</tr>
<tr>
<a name="encodeURL" />
Modified:
ant/antlibs/props/trunk/src/main/org/apache/ant/props/ConditionEvaluator.java
URL:
http://svn.apache.org/viewvc/ant/antlibs/props/trunk/src/main/org/apache/ant/props/ConditionEvaluator.java?rev=916485&r1=916484&r2=916485&view=diff
==============================================================================
---
ant/antlibs/props/trunk/src/main/org/apache/ant/props/ConditionEvaluator.java
(original)
+++
ant/antlibs/props/trunk/src/main/org/apache/ant/props/ConditionEvaluator.java
Thu Feb 25 23:24:00 2010
@@ -44,7 +44,7 @@
* Create a new ConditionEvaluator instance.
*/
public ConditionEvaluator() {
- super("^(.+?)\\(((?:(?:.+?)=(?:.+?))?(?:,(?:.+?)=(?:.+?))*?)\\)$");
+ super("^(!)?(.+?)\\(((?:(?:.+?)=(?:.+?))?(?:,(?:.+?)=(?:.+?))*?)\\)$");
}
/**
@@ -52,9 +52,13 @@
*/
protected Object evaluate(String[] groups, PropertyHelper propertyHelper) {
Project p = propertyHelper.getProject();
- Condition cond = createCondition(p, groups[1]);
+ boolean negate = false;
+ if ("!".equals(groups[1])) {
+ negate = true;
+ }
+ Condition cond = createCondition(p, groups[2]);
if (cond != null) {
- if (groups[2].length() > 0) {
+ if (groups[3].length() > 0) {
Object realObject = TypeAdapter.class.isInstance(cond) ?
((TypeAdapter) cond)
.getProxy() : cond;
if (realObject == null) {
@@ -62,13 +66,13 @@
"Found null proxy object for adapted condition " +
cond.toString());
}
IntrospectionHelper ih =
IntrospectionHelper.getHelper(realObject.getClass());
- String[] attributes = COMMA.split(groups[2]);
+ String[] attributes = COMMA.split(groups[3]);
for (int i = 0; i < attributes.length; i++) {
String[] keyValue = EQ.split(attributes[i]);
ih.setAttribute(p, realObject, keyValue[0].trim(),
keyValue[1].trim());
}
}
- return Boolean.valueOf(cond.eval());
+ return Boolean.valueOf(cond.eval() ^ negate);
}
return null;
}
Modified: ant/antlibs/props/trunk/src/tests/antunit/condition-test.xml
URL:
http://svn.apache.org/viewvc/ant/antlibs/props/trunk/src/tests/antunit/condition-test.xml?rev=916485&r1=916484&r2=916485&view=diff
==============================================================================
--- ant/antlibs/props/trunk/src/tests/antunit/condition-test.xml (original)
+++ ant/antlibs/props/trunk/src/tests/antunit/condition-test.xml Thu Feb 25
23:24:00 2010
@@ -99,4 +99,11 @@
</antunit>
</target>
+ <target name="testNegation">
+ <property name="foo" value="false" />
+ <au:assertTrue>
+ <istrue value="${!istrue(value=${foo})}" />
+ </au:assertTrue>
+ </target>
+
</project>