You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by an...@apache.org on 2013/12/15 04:47:16 UTC

svn commit: r1550999 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/RuntimeConfigurable.java src/tests/antunit/core/ant-attribute-test.xml

Author: antoine
Date: Sun Dec 15 03:47:15 2013
New Revision: 1550999

URL: http://svn.apache.org/r1550999
Log:
removing the restricted attributes from what gets fed to macrodefs, Bugzilla Report 55885

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/ant/RuntimeConfigurable.java
    ant/core/trunk/src/tests/antunit/core/ant-attribute-test.xml

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=1550999&r1=1550998&r2=1550999&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Sun Dec 15 03:47:15 2013
@@ -18,6 +18,10 @@ Fixed bugs:
  * <mail>'s mailport still didn't work proprly when using smtps.
    Bugzilla Report 49267.
 
+ * using attributes belonging to the if and unless namespaces
+   made macrodef fail.
+   Bugzilla Report 55885.
+
 Other changes:
 --------------
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/RuntimeConfigurable.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/RuntimeConfigurable.java?rev=1550999&r1=1550998&r2=1550999&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/RuntimeConfigurable.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/RuntimeConfigurable.java Sun Dec 15 03:47:15 2013
@@ -125,6 +125,48 @@ public class RuntimeConfigurable impleme
     }
 
     /**
+     * contains the attribute component name and boolean restricted set to true when
+     * the attribute is in one of the name spaces managed by ant (if and unless currently)
+     * @since Ant 1.9.3
+     */
+    private static class AttributeComponentInformation {
+        String componentName;
+        boolean restricted;
+
+        private AttributeComponentInformation(String componentName, boolean restricted) {
+            this.componentName = componentName;
+            this.restricted = restricted;
+        }
+
+        public String getComponentName() {
+            return componentName;
+        }
+
+        public boolean isRestricted() {
+            return restricted;
+        }
+    }
+
+    /**
+     *
+     * @param name    the name of the attribute.
+     * @param componentHelper current component helper
+     * @return AttributeComponentInformation instance
+     */
+    private AttributeComponentInformation isRestrictedAttribute(String name, ComponentHelper componentHelper) {
+        if (name.indexOf(':') == -1) {
+            return new AttributeComponentInformation(null, false);
+        }
+        String componentName = attrToComponent(name);
+        String ns = ProjectHelper.extractUriFromComponentName(componentName);
+        if (componentHelper.getRestrictedDefinitions(
+                ProjectHelper.nsToComponentName(ns)) == null) {
+            return new AttributeComponentInformation(null, false);
+        }
+        return new AttributeComponentInformation(componentName, true);
+    }
+
+    /**
      * Check if an UE is enabled.
      * This looks tru the attributes and checks if there
      * are any Ant attributes, and if so, the method calls the
@@ -146,27 +188,20 @@ public class RuntimeConfigurable impleme
                 owner.getProject(), EnableAttributeConsumer.class);
         for (int i = 0; i < attributeMap.keySet().size(); ++i) {
             String name = (String) attributeMap.keySet().toArray()[i];
-            if (name.indexOf(':') == -1) {
-                continue;
-            }
-            String componentName = attrToComponent(name);
-            String ns = ProjectHelper.extractUriFromComponentName(componentName);
-            if (componentHelper.getRestrictedDefinitions(
-                    ProjectHelper.nsToComponentName(ns)) == null) {
+            AttributeComponentInformation attributeComponentInformation = isRestrictedAttribute(name, componentHelper);
+            if (!attributeComponentInformation.isRestricted())  {
                 continue;
             }
-
             String value = (String) attributeMap.get(name);
-
             EnableAttribute enable = null;
             try {
                 enable = (EnableAttribute)
                     ih.createElement(
                         owner.getProject(), new EnableAttributeConsumer(),
-                        componentName);
+                        attributeComponentInformation.getComponentName());
             } catch (BuildException ex) {
                 throw new BuildException(
-                    "Unsupported attribute " + componentName);
+                    "Unsupported attribute " + attributeComponentInformation.getComponentName());
             }
             if (enable == null) {
                 continue;
@@ -460,12 +495,16 @@ public class RuntimeConfigurable impleme
 
         IntrospectionHelper ih =
             IntrospectionHelper.getHelper(p, target.getClass());
-
+         ComponentHelper componentHelper = ComponentHelper.getComponentHelper(p);
         if (attributeMap != null) {
             for (Entry<String, Object> entry : attributeMap.entrySet()) {
                 String name = entry.getKey();
+                // skip restricted attributes such as if:set
+                AttributeComponentInformation attributeComponentInformation = isRestrictedAttribute(name, componentHelper);
+                if (attributeComponentInformation.isRestricted())  {
+                    continue;
+                }
                 Object value = entry.getValue();
-
                 // reflect these into the target, defer for
                 // MacroInstance where properties are expanded for the
                 // nested sequential

Modified: ant/core/trunk/src/tests/antunit/core/ant-attribute-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/core/ant-attribute-test.xml?rev=1550999&r1=1550998&r2=1550999&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/core/ant-attribute-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/core/ant-attribute-test.xml Sun Dec 15 03:47:15 2013
@@ -57,4 +57,18 @@
     <au:assertLogContains text="message6"/>
   </target>
 
+
+
+
+  <target name="test-macrodef">
+    <property name="verbose" value="true"/>
+    <macrodef name="sayhi">
+      <sequential>
+        <echo>hi</echo>
+      </sequential>
+    </macrodef>
+    <sayhi if:set="verbose" />
+    <au:assertLogContains text="hi"/>
+  </target>
+
 </project>