Browse Source

removing the restricted attributes from what gets fed to macrodefs, Bugzilla Report 55885

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1550999 13f79535-47bb-0310-9956-ffa450edef68
master
Antoine Levy-Lambert 11 years ago
parent
commit
cb20f50880
3 changed files with 70 additions and 13 deletions
  1. +4
    -0
      WHATSNEW
  2. +52
    -13
      src/main/org/apache/tools/ant/RuntimeConfigurable.java
  3. +14
    -0
      src/tests/antunit/core/ant-attribute-test.xml

+ 4
- 0
WHATSNEW View File

@@ -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:
--------------



+ 52
- 13
src/main/org/apache/tools/ant/RuntimeConfigurable.java View File

@@ -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<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


+ 14
- 0
src/tests/antunit/core/ant-attribute-test.xml View File

@@ -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>

Loading…
Cancel
Save