Author: bodewig
Date: Tue Feb 9 16:50:45 2010
New Revision: 908112
URL: http://svn.apache.org/viewvc?rev=908112&view=rev
Log:
evaluator that evaluates ant conditions. can certainly be improved, better
tested and documented in the first place, but I wanted to commit the work in
progress before I forget about it
Added:
ant/antlibs/props/trunk/src/main/org/apache/ant/props/ConditionEvaluator.java
(with props)
ant/antlibs/props/trunk/src/tests/antunit/condition-test.xml (with props)
Modified:
ant/antlibs/props/trunk/contributors.xml
ant/antlibs/props/trunk/src/main/org/apache/ant/props/ComponentTypeEvaluator.java
ant/antlibs/props/trunk/src/main/org/apache/ant/props/antlib.xml
Modified: ant/antlibs/props/trunk/contributors.xml
URL:
http://svn.apache.org/viewvc/ant/antlibs/props/trunk/contributors.xml?rev=908112&r1=908111&r2=908112&view=diff
==============================================================================
--- ant/antlibs/props/trunk/contributors.xml (original)
+++ ant/antlibs/props/trunk/contributors.xml Tue Feb 9 16:50:45 2010
@@ -34,4 +34,8 @@
<first>Matt</first>
<last>Benson</last>
</name>
+ <name>
+ <first>Stefan</first>
+ <last>Bodewig</last>
+ </name>
</contributors>
Modified:
ant/antlibs/props/trunk/src/main/org/apache/ant/props/ComponentTypeEvaluator.java
URL:
http://svn.apache.org/viewvc/ant/antlibs/props/trunk/src/main/org/apache/ant/props/ComponentTypeEvaluator.java?rev=908112&r1=908111&r2=908112&view=diff
==============================================================================
---
ant/antlibs/props/trunk/src/main/org/apache/ant/props/ComponentTypeEvaluator.java
(original)
+++
ant/antlibs/props/trunk/src/main/org/apache/ant/props/ComponentTypeEvaluator.java
Tue Feb 9 16:50:45 2010
@@ -36,7 +36,7 @@
* Create a new ComponentTypeEvaluator.
*/
public ComponentTypeEvaluator() {
- setPattern("^(.*?)\\((.*)\\)$");
+ super("^(.*?)\\((.*)\\)$");
}
/**
Added:
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=908112&view=auto
==============================================================================
---
ant/antlibs/props/trunk/src/main/org/apache/ant/props/ConditionEvaluator.java
(added)
+++
ant/antlibs/props/trunk/src/main/org/apache/ant/props/ConditionEvaluator.java
Tue Feb 9 16:50:45 2010
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ant.props;
+
+import org.apache.tools.ant.ComponentHelper;
+import org.apache.tools.ant.IntrospectionHelper;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.PropertyHelper;
+import org.apache.tools.ant.taskdefs.condition.Condition;
+
+/**
+ * Property evaluator that evaluates Ant conditions to a Boolean
+ * instance matching the condition's outcome.
+ *
+ * <p>Default syntax is
+ * <code><em>condition</em>(<em>attribute</em>=<em>value</em>)</code>,
+ * for example <code>os(family=unix)</code>.
+ */
+public class ConditionEvaluator extends RegexBasedEvaluator {
+ public ConditionEvaluator() {
+ super("^(.+?)\\(((?:(?:.+?)=(?:.+?))?(?:,(?:.+?)=(?:.+?))*?)\\)$");
+ }
+
+ protected Object evaluate(String[] groups, PropertyHelper propertyHelper) {
+ Project p = propertyHelper.getProject();
+ Object instance = ComponentHelper.getComponentHelper(p)
+ .createComponent(groups[1]);
+ if (instance instanceof Condition) {
+ Condition cond = (Condition) instance;
+ if (groups[2].length() > 0) {
+ IntrospectionHelper ih =
+ IntrospectionHelper.getHelper(instance.getClass());
+ String[] attributes = groups[2].split(",");
+ for (int i = 0; i < attributes.length; i++) {
+ String[] keyValue = attributes[i].split("=");
+ ih.setAttribute(p, instance, keyValue[0], keyValue[1]);
+ }
+ }
+ return Boolean.valueOf(cond.eval());
+ }
+ return null;
+ }
+}
Propchange:
ant/antlibs/props/trunk/src/main/org/apache/ant/props/ConditionEvaluator.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: ant/antlibs/props/trunk/src/main/org/apache/ant/props/antlib.xml
URL:
http://svn.apache.org/viewvc/ant/antlibs/props/trunk/src/main/org/apache/ant/props/antlib.xml?rev=908112&r1=908111&r2=908112&view=diff
==============================================================================
--- ant/antlibs/props/trunk/src/main/org/apache/ant/props/antlib.xml (original)
+++ ant/antlibs/props/trunk/src/main/org/apache/ant/props/antlib.xml Tue Feb 9
16:50:45 2010
@@ -23,4 +23,5 @@
<typedef name="types"
classname="org.apache.ant.props.ComponentTypeEvaluator" />
<typedef name="refs"
classname="org.apache.ant.props.ReferenceResolvingEvaluator" />
<typedef name="encodeURL"
classname="org.apache.ant.props.EncodeURLEvaluator" />
+ <typedef name="conditions"
classname="org.apache.ant.props.ConditionEvaluator" />
</antlib>
Added: 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=908112&view=auto
==============================================================================
--- ant/antlibs/props/trunk/src/tests/antunit/condition-test.xml (added)
+++ ant/antlibs/props/trunk/src/tests/antunit/condition-test.xml Tue Feb 9
16:50:45 2010
@@ -0,0 +1,33 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns:au="antlib:org.apache.ant.antunit"
+ xmlns:props="antlib:org.apache.ant.props">
+ <target name="setUp">
+ <propertyhelper>
+ <props:conditions />
+ <props:nested />
+ </propertyhelper>
+ </target>
+
+ <target name="testAvailable">
+ <au:assertEquals expected="true"
+
actual="${available(classname=org.apache.ant.props.ConditionEvaluator)}"/>
+ <au:assertEquals expected="false"
+
actual="${available(classname=org.apache.ant.props.ConditionEvaluatorFoo)}"/>
+ </target>
+</project>
Propchange: ant/antlibs/props/trunk/src/tests/antunit/condition-test.xml
------------------------------------------------------------------------------
svn:eol-style = native