diff --git a/WHATSNEW b/WHATSNEW index 8ddbccfa6..a2b1ff263 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -18,6 +18,10 @@ Fixed bugs: * '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: -------------- diff --git a/src/main/org/apache/tools/ant/RuntimeConfigurable.java b/src/main/org/apache/tools/ant/RuntimeConfigurable.java index 5ab6b6d8c..9ed40561c 100644 --- a/src/main/org/apache/tools/ant/RuntimeConfigurable.java +++ b/src/main/org/apache/tools/ant/RuntimeConfigurable.java @@ -124,6 +124,48 @@ public class RuntimeConfigurable implements Serializable { } } + /** + * 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 @@ -146,27 +188,20 @@ public class RuntimeConfigurable implements Serializable { 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 implements Serializable { IntrospectionHelper ih = IntrospectionHelper.getHelper(p, target.getClass()); - + ComponentHelper componentHelper = ComponentHelper.getComponentHelper(p); if (attributeMap != null) { for (Entry 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 diff --git a/src/tests/antunit/core/ant-attribute-test.xml b/src/tests/antunit/core/ant-attribute-test.xml index 5d76c7a20..6f6dc51dd 100644 --- a/src/tests/antunit/core/ant-attribute-test.xml +++ b/src/tests/antunit/core/ant-attribute-test.xml @@ -57,4 +57,18 @@ + + + + + + + + hi + + + + + +