git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@436992 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -258,6 +258,9 @@ Fixed bugs: | |||||
| * Copy of UnknownElement in macroinstance was not recursive. | * Copy of UnknownElement in macroinstance was not recursive. | ||||
| Bugzilla report 40238. | Bugzilla report 40238. | ||||
| * mixing of add and addConfigured methods in Mapper/ChainedMapper | |||||
| causes incorrect chaining. Bugzilla report 40228. | |||||
| Other changes: | Other changes: | ||||
| -------------- | -------------- | ||||
| @@ -67,6 +67,9 @@ | |||||
| <typedef loaderref="nested.loader" | <typedef loaderref="nested.loader" | ||||
| name = "myaddconfigured" | name = "myaddconfigured" | ||||
| classname="${nested.package}AddTypeTest$MyAddConfigured"/> | classname="${nested.package}AddTypeTest$MyAddConfigured"/> | ||||
| <typedef loaderref="nested.loader" | |||||
| name = "myaddconfiguredvalue" | |||||
| classname="${nested.package}AddTypeTest$MyAddConfiguredValue"/> | |||||
| <typedef loaderref="nested.loader" | <typedef loaderref="nested.loader" | ||||
| name = "myvalue" | name = "myvalue" | ||||
| classname="${nested.package}AddTypeTest$MyValue"/> | classname="${nested.package}AddTypeTest$MyValue"/> | ||||
| @@ -127,6 +130,12 @@ | |||||
| </myaddconfigured> | </myaddconfigured> | ||||
| </target> | </target> | ||||
| <target name="myaddconfiguredvalue" depends="init"> | |||||
| <myaddconfiguredvalue> | |||||
| <value>Value Set</value> | |||||
| </myaddconfiguredvalue> | |||||
| </target> | |||||
| <target name="namespacetest" xmlns:prefix="uri"> | <target name="namespacetest" xmlns:prefix="uri"> | ||||
| <typedef name="eq" uri="uri" | <typedef name="eq" uri="uri" | ||||
| classname="org.apache.tools.ant.taskdefs.condition.Equals"/> | classname="org.apache.tools.ant.taskdefs.condition.Equals"/> | ||||
| @@ -267,7 +267,16 @@ public final class IntrospectionHelper implements BuildListener { | |||||
| constructor = | constructor = | ||||
| args[0].getConstructor(new Class[] {Project.class}); | args[0].getConstructor(new Class[] {Project.class}); | ||||
| } | } | ||||
| String propName = getPropertyName(name, "add"); | String propName = getPropertyName(name, "add"); | ||||
| if (nestedTypes.get(propName) != null) { | |||||
| /* | |||||
| * Ignore this method as there is an addConfigured | |||||
| * form of this method that has a higher | |||||
| * priority | |||||
| */ | |||||
| continue; | |||||
| } | |||||
| nestedTypes.put(propName, args[0]); | nestedTypes.put(propName, args[0]); | ||||
| nestedCreators.put(propName, new AddNestedCreator(m, | nestedCreators.put(propName, new AddNestedCreator(m, | ||||
| constructor, AddNestedCreator.ADD)); | constructor, AddNestedCreator.ADD)); | ||||
| @@ -1439,6 +1448,8 @@ public final class IntrospectionHelper implements BuildListener { | |||||
| * the addTypeMethods array. The array is | * the addTypeMethods array. The array is | ||||
| * ordered so that the more derived classes | * ordered so that the more derived classes | ||||
| * are first. | * are first. | ||||
| * If both add and addConfigured are present, the addConfigured | |||||
| * will take priority. | |||||
| * @param method the <code>Method</code> to insert. | * @param method the <code>Method</code> to insert. | ||||
| */ | */ | ||||
| private void insertAddTypeMethod(Method method) { | private void insertAddTypeMethod(Method method) { | ||||
| @@ -1446,6 +1457,10 @@ public final class IntrospectionHelper implements BuildListener { | |||||
| for (int c = 0; c < addTypeMethods.size(); ++c) { | for (int c = 0; c < addTypeMethods.size(); ++c) { | ||||
| Method current = (Method) addTypeMethods.get(c); | Method current = (Method) addTypeMethods.get(c); | ||||
| if (current.getParameterTypes()[0].equals(argClass)) { | if (current.getParameterTypes()[0].equals(argClass)) { | ||||
| if (method.getName().equals("addConfigured")) { | |||||
| // add configured replaces the add method | |||||
| addTypeMethods.set(c, method); | |||||
| } | |||||
| return; // Already present | return; // Already present | ||||
| } | } | ||||
| if (current.getParameterTypes()[0].isAssignableFrom( | if (current.getParameterTypes()[0].isAssignableFrom( | ||||
| @@ -57,6 +57,15 @@ public class Mapper extends DataType implements Cloneable { | |||||
| this.type = type; | this.type = type; | ||||
| } | } | ||||
| /** | |||||
| * Cannot mix add and addconfigured in same type, so | |||||
| * provide this to override the add method. | |||||
| * @param fileNameMapper the <code>FileNameMapper</code> to add. | |||||
| */ | |||||
| public void addConfigured(FileNameMapper fileNameMapper) { | |||||
| add(fileNameMapper); | |||||
| } | |||||
| /** | /** | ||||
| * Add a nested <code>FileNameMapper</code>. | * Add a nested <code>FileNameMapper</code>. | ||||
| * @param fileNameMapper the <code>FileNameMapper</code> to add. | * @param fileNameMapper the <code>FileNameMapper</code> to add. | ||||
| @@ -40,6 +40,19 @@ public abstract class ContainerMapper implements FileNameMapper { | |||||
| add(mapper.getImplementation()); | add(mapper.getImplementation()); | ||||
| } | } | ||||
| /** | |||||
| * An add configured version of the add method. | |||||
| * This class used to contain an add method and an | |||||
| * addConfiguredMapper method. Dur to ordering, | |||||
| * the add method was always called first. This | |||||
| * addConfigued method has been added to allow | |||||
| * chaining to work correctly. | |||||
| * @param fileNameMapper a <code>FileNameMapper</code>. | |||||
| */ | |||||
| public void addConfigured(FileNameMapper fileNameMapper) { | |||||
| add(fileNameMapper); | |||||
| } | |||||
| /** | /** | ||||
| * Add a <code>FileNameMapper</code>. | * Add a <code>FileNameMapper</code>. | ||||
| * @param fileNameMapper a <code>FileNameMapper</code>. | * @param fileNameMapper a <code>FileNameMapper</code>. | ||||
| @@ -18,6 +18,7 @@ | |||||
| package org.apache.tools.ant.types; | package org.apache.tools.ant.types; | ||||
| import org.apache.tools.ant.BuildFileTest; | import org.apache.tools.ant.BuildFileTest; | ||||
| import org.apache.tools.ant.BuildException; | |||||
| import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
| import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
| import org.apache.tools.ant.taskdefs.condition.Condition; | import org.apache.tools.ant.taskdefs.condition.Condition; | ||||
| @@ -86,6 +87,12 @@ public class AddTypeTest extends BuildFileTest { | |||||
| "myaddconfigured", "value is Value Setexecute: value is Value Set"); | "myaddconfigured", "value is Value Setexecute: value is Value Set"); | ||||
| } | } | ||||
| public void testAddConfiguredValue() { | |||||
| expectLogContaining( | |||||
| "myaddconfiguredvalue", | |||||
| "value is Value Setexecute: value is Value Set"); | |||||
| } | |||||
| public void testNamespace() { | public void testNamespace() { | ||||
| executeTarget("namespacetest"); | executeTarget("namespacetest"); | ||||
| } | } | ||||
| @@ -151,6 +158,25 @@ public class AddTypeTest extends BuildFileTest { | |||||
| log("value is " + value); | log("value is " + value); | ||||
| this.value = value; | this.value = value; | ||||
| } | } | ||||
| public void add(MyValue value) { | |||||
| throw new BuildException("Should not be called"); | |||||
| } | |||||
| public void execute() { | |||||
| log("execute: value is " + value); | |||||
| } | |||||
| } | |||||
| public static class MyAddConfiguredValue | |||||
| extends Task | |||||
| { | |||||
| MyValue value; | |||||
| public void addConfiguredValue(MyValue value) { | |||||
| log("value is " + value); | |||||
| this.value = value; | |||||
| } | |||||
| public void addValue(MyValue value) { | |||||
| throw new BuildException("Should not be called"); | |||||
| } | |||||
| public void execute() { | public void execute() { | ||||
| log("execute: value is " + value); | log("execute: value is " + value); | ||||
| } | } | ||||