ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r555174 - in /ant/core/trunk/src: main/org/apache/tools/ant/taskdefs/PropertyHelperTask.java tests/antunit/taskdefs/propertyhelper-test.xml
Date Wed, 11 Jul 2007 05:28:04 GMT
Author: mbenson
Date: Tue Jul 10 22:28:04 2007
New Revision: 555174

URL: http://svn.apache.org/viewvc?view=rev&rev=555174
Log:
add nested delegate ref to PHtask w/ script example

Added:
    ant/core/trunk/src/tests/antunit/taskdefs/propertyhelper-test.xml   (with props)
Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/PropertyHelperTask.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/PropertyHelperTask.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/PropertyHelperTask.java?view=diff&rev=555174&r1=555173&r2=555174
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/PropertyHelperTask.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/PropertyHelperTask.java Tue Jul
10 22:28:04 2007
@@ -35,6 +35,39 @@
  * @since Ant 1.8
  */
 public class PropertyHelperTask extends Task {
+    /**
+     * Nested delegate for refid usage.
+     */
+    public class DelegateElement {
+        private String refid;
+
+        private DelegateElement() {
+        }
+
+        /**
+         * Get the refid.
+         * @return String
+         */
+        public String getRefid() {
+            return refid;
+        }
+
+        /**
+         * Set the refid.
+         * @param refid the String to set
+         */
+        public void setRefid(String refid) {
+            this.refid = refid;
+        }
+
+        private PropertyHelper.Delegate resolve() {
+            if (refid == null) {
+                throw new BuildException("refid required for generic delegate");
+            }
+            return (PropertyHelper.Delegate) getProject().getReference(refid);
+        }
+    }
+
     private PropertyHelper propertyHelper;
     private List delegates;
 
@@ -65,10 +98,17 @@
      * @param delegate the delegate to add.
      */
     public synchronized void addConfigured(PropertyHelper.Delegate delegate) {
-        if (delegates == null) {
-            delegates = new ArrayList();
-        }
-        delegates.add(delegate);
+        getAddDelegateList().add(delegate);
+    }
+
+    /**
+     * Add a nested <delegate refid="foo" /> element.
+     * @return DelegateElement
+     */
+    public DelegateElement createDelegate() {
+        DelegateElement result = new DelegateElement();
+        getAddDelegateList().add(result);
+        return result;
     }
 
     /**
@@ -89,7 +129,9 @@
         synchronized (ph) {
             if (delegates != null) {
                 for (Iterator iter = delegates.iterator(); iter.hasNext();) {
-                    PropertyHelper.Delegate delegate = (PropertyHelper.Delegate) iter.next();
+                    Object o = iter.next();
+                    PropertyHelper.Delegate delegate = o instanceof DelegateElement
+                            ? ((DelegateElement) o).resolve() : (PropertyHelper.Delegate)
o;
                     log("Adding PropertyHelper delegate " + delegate, Project.MSG_DEBUG);
                     ph.add(delegate);
                 }
@@ -97,9 +139,15 @@
         }
         if (propertyHelper != null) {
             log("Installing PropertyHelper " + propertyHelper, Project.MSG_DEBUG);
-            //TODO copy existing properties to new PH?
+            // TODO copy existing properties to new PH?
             getProject().addReference(MagicNames.REFID_PROPERTY_HELPER, propertyHelper);
         }
     }
 
+    private synchronized List getAddDelegateList() {
+        if (delegates == null) {
+            delegates = new ArrayList();
+        }
+        return delegates;
+    }
 }

Added: ant/core/trunk/src/tests/antunit/taskdefs/propertyhelper-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/propertyhelper-test.xml?view=auto&rev=555174
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/propertyhelper-test.xml (added)
+++ ant/core/trunk/src/tests/antunit/taskdefs/propertyhelper-test.xml Tue Jul 10 22:28:04
2007
@@ -0,0 +1,25 @@
+<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit">
+  <import file="../antunit-base.xml" />
+
+  <target name="testScript">
+    <script language="beanshell" manager="bsf">
+      import org.apache.tools.ant.PropertyHelper;
+      public class FooEvaluator implements PropertyHelper.PropertyEvaluator {
+        public Object evaluate(String property, PropertyHelper propertyHelper) {
+          return "foo".equals(property) ? "foo.value" : null;
+        }
+      }
+      project.addReference("fooEvaluator", new FooEvaluator());
+    </script>
+    <au:assertFalse>
+      <isset property="foo" />
+    </au:assertFalse>
+    <propertyhelper>
+      <delegate refid="fooEvaluator" />
+    </propertyhelper>
+    <au:assertTrue>
+      <equals arg1="${foo}" arg2="foo.value" />
+    </au:assertTrue>
+  </target>
+
+</project>

Propchange: ant/core/trunk/src/tests/antunit/taskdefs/propertyhelper-test.xml
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message