You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

IntrospectionHelper.java 69 kB

PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. package org.apache.tools.ant;
  19. import java.lang.reflect.Constructor;
  20. import java.lang.reflect.InvocationTargetException;
  21. import java.lang.reflect.Method;
  22. import java.util.ArrayList;
  23. import java.util.Collections;
  24. import java.util.Enumeration;
  25. import java.util.Hashtable;
  26. import java.util.HashMap;
  27. import java.util.List;
  28. import java.util.Locale;
  29. import java.util.Map;
  30. import org.apache.tools.ant.types.EnumeratedAttribute;
  31. import org.apache.tools.ant.types.Resource;
  32. import org.apache.tools.ant.types.resources.FileProvider;
  33. import org.apache.tools.ant.types.resources.FileResource;
  34. import org.apache.tools.ant.taskdefs.PreSetDef;
  35. import org.apache.tools.ant.util.StringUtils;
  36. /**
  37. * Helper class that collects the methods a task or nested element
  38. * holds to set attributes, create nested elements or hold PCDATA
  39. * elements.
  40. *
  41. * It contains hashtables containing classes that use introspection
  42. * to handle all the invocation of the project-component specific methods.
  43. *
  44. * This class is somewhat complex, as it implements the O/X mapping between
  45. * Ant XML and Java class instances. This is not the best place for someone new
  46. * to Ant to start contributing to the codebase, as a change here can break the
  47. * entire system in interesting ways. Always run a full test of Ant before checking
  48. * in/submitting changes to this file.
  49. *
  50. * The class is final and has a private constructor.
  51. * To get an instance for a specific (class,project) combination,
  52. * use {@link #getHelper(Project,Class)}.
  53. * This may return an existing version, or a new one
  54. * ...do not make any assumptions about its uniqueness, or its validity after the Project
  55. * instance has finished its build.
  56. *
  57. */
  58. public final class IntrospectionHelper {
  59. /**
  60. * Helper instances we've already created (Class.getName() to IntrospectionHelper).
  61. */
  62. private static final Map HELPERS = new Hashtable();
  63. /**
  64. * Map from primitive types to wrapper classes for use in
  65. * createAttributeSetter (Class to Class). Note that char
  66. * and boolean are in here even though they get special treatment
  67. * - this way we only need to test for the wrapper class.
  68. */
  69. private static final Map PRIMITIVE_TYPE_MAP = new HashMap(8);
  70. // Set up PRIMITIVE_TYPE_MAP
  71. static {
  72. Class[] primitives = {Boolean.TYPE, Byte.TYPE, Character.TYPE, Short.TYPE,
  73. Integer.TYPE, Long.TYPE, Float.TYPE, Double.TYPE};
  74. Class[] wrappers = {Boolean.class, Byte.class, Character.class, Short.class,
  75. Integer.class, Long.class, Float.class, Double.class};
  76. for (int i = 0; i < primitives.length; i++) {
  77. PRIMITIVE_TYPE_MAP.put (primitives[i], wrappers[i]);
  78. }
  79. }
  80. private static final int MAX_REPORT_NESTED_TEXT = 20;
  81. private static final String ELLIPSIS = "...";
  82. /**
  83. * Map from attribute names to attribute types
  84. * (String to Class).
  85. */
  86. private final Hashtable attributeTypes = new Hashtable();
  87. /**
  88. * Map from attribute names to attribute setter methods
  89. * (String to AttributeSetter).
  90. */
  91. private final Hashtable attributeSetters = new Hashtable();
  92. /**
  93. * Map from attribute names to nested types
  94. * (String to Class).
  95. */
  96. private final Hashtable nestedTypes = new Hashtable();
  97. /**
  98. * Map from attribute names to methods to create nested types
  99. * (String to NestedCreator).
  100. */
  101. private final Hashtable nestedCreators = new Hashtable();
  102. /**
  103. * Vector of methods matching add[Configured](Class) pattern.
  104. */
  105. private final List addTypeMethods = new ArrayList();
  106. /**
  107. * The method to invoke to add PCDATA.
  108. */
  109. private final Method addText;
  110. /**
  111. * The class introspected by this instance.
  112. */
  113. private final Class bean;
  114. /**
  115. * Sole constructor, which is private to ensure that all
  116. * IntrospectionHelpers are created via {@link #getHelper(Class) getHelper}.
  117. * Introspects the given class for bean-like methods.
  118. * Each method is examined in turn, and the following rules are applied:
  119. * <p>
  120. * <ul>
  121. * <li>If the method is <code>Task.setLocation(Location)</code>,
  122. * <code>Task.setTaskType(String)</code>
  123. * or <code>TaskContainer.addTask(Task)</code>, it is ignored. These
  124. * methods are handled differently elsewhere.
  125. * <li><code>void addText(String)</code> is recognised as the method for
  126. * adding PCDATA to a bean.
  127. * <li><code>void setFoo(Bar)</code> is recognised as a method for
  128. * setting the value of attribute <code>foo</code>, so long as
  129. * <code>Bar</code> is non-void and is not an array type.
  130. * As of Ant 1.8, a Resource or FileProvider parameter overrides a java.io.File parameter;
  131. * in practice the only effect of this is to allow objects rendered from
  132. * the 1.8 PropertyHelper implementation to be used as Resource parameters,
  133. * since Resources set from Strings are resolved as project-relative files
  134. * to preserve backward compatibility. Beyond this, non-String
  135. * parameter types always overload String parameter types; these are
  136. * the only guarantees made in terms of priority.
  137. * <li><code>Foo createBar()</code> is recognised as a method for
  138. * creating a nested element called <code>bar</code> of type
  139. * <code>Foo</code>, so long as <code>Foo</code> is not a primitive or
  140. * array type.
  141. * <li><code>void addConfiguredFoo(Bar)</code> is recognised as a
  142. * method for storing a pre-configured element called
  143. * <code>foo</code> and of type <code>Bar</code>, so long as
  144. * <code>Bar</code> is not an array, primitive or String type.
  145. * <code>Bar</code> must have an accessible constructor taking no
  146. * arguments.
  147. * <li><code>void addFoo(Bar)</code> is recognised as a method for storing
  148. * an element called <code>foo</code> and of type <code>Bar</code>, so
  149. * long as <code>Bar</code> is not an array, primitive or String type.
  150. * <code>Bar</code> must have an accessible constructor taking no
  151. * arguments. This is distinct from the 'addConfigured' idiom in that
  152. * the nested element is added to the parent immediately after it is
  153. * constructed; in practice this means that <code>addFoo(Bar)</code> should
  154. * do little or nothing with its argument besides storing it for later use.
  155. * </ul>
  156. * Note that only one method is retained to create/set/addConfigured/add
  157. * any element or attribute.
  158. *
  159. * @param bean The bean type to introspect.
  160. * Must not be <code>null</code>.
  161. *
  162. * @see #getHelper(Class)
  163. */
  164. private IntrospectionHelper(final Class bean) {
  165. this.bean = bean;
  166. Method[] methods = bean.getMethods();
  167. Method addTextMethod = null;
  168. for (int i = 0; i < methods.length; i++) {
  169. final Method m = methods[i];
  170. final String name = m.getName();
  171. Class returnType = m.getReturnType();
  172. Class[] args = m.getParameterTypes();
  173. // check of add[Configured](Class) pattern
  174. if (args.length == 1 && java.lang.Void.TYPE.equals(returnType)
  175. && ("add".equals(name) || "addConfigured".equals(name))) {
  176. insertAddTypeMethod(m);
  177. continue;
  178. }
  179. // not really user settable properties on tasks/project components
  180. if (org.apache.tools.ant.ProjectComponent.class.isAssignableFrom(bean)
  181. && args.length == 1 && isHiddenSetMethod(name, args[0])) {
  182. continue;
  183. }
  184. // hide addTask for TaskContainers
  185. if (isContainer() && args.length == 1 && "addTask".equals(name)
  186. && org.apache.tools.ant.Task.class.equals(args[0])) {
  187. continue;
  188. }
  189. if ("addText".equals(name) && java.lang.Void.TYPE.equals(returnType)
  190. && args.length == 1 && java.lang.String.class.equals(args[0])) {
  191. addTextMethod = methods[i];
  192. } else if (name.startsWith("set") && java.lang.Void.TYPE.equals(returnType)
  193. && args.length == 1 && !args[0].isArray()) {
  194. String propName = getPropertyName(name, "set");
  195. AttributeSetter as = (AttributeSetter) attributeSetters.get(propName);
  196. if (as != null) {
  197. if (java.lang.String.class.equals(args[0])) {
  198. /*
  199. Ignore method m, as there is an overloaded
  200. form of this method that takes in a
  201. non-string argument, which gains higher
  202. priority.
  203. */
  204. continue;
  205. }
  206. if (java.io.File.class.equals(args[0])) {
  207. // Ant Resources/FileProviders override java.io.File
  208. if (Resource.class.equals(as.type) || FileProvider.class.equals(as.type)) {
  209. continue;
  210. }
  211. }
  212. /*
  213. In cases other than those just explicitly covered,
  214. we just override that with the new one.
  215. This mechanism does not guarantee any specific order
  216. in which the methods will be selected: so any code
  217. that depends on the order in which "set" methods have
  218. been defined, is not guaranteed to be selected in any
  219. particular order.
  220. */
  221. }
  222. as = createAttributeSetter(m, args[0], propName);
  223. if (as != null) {
  224. attributeTypes.put(propName, args[0]);
  225. attributeSetters.put(propName, as);
  226. }
  227. } else if (name.startsWith("create") && !returnType.isArray()
  228. && !returnType.isPrimitive() && args.length == 0) {
  229. String propName = getPropertyName(name, "create");
  230. // Check if a create of this property is already present
  231. // add takes preference over create for CB purposes
  232. if (nestedCreators.get(propName) == null) {
  233. nestedTypes.put(propName, returnType);
  234. nestedCreators.put(propName, new CreateNestedCreator(m));
  235. }
  236. } else if (name.startsWith("addConfigured")
  237. && java.lang.Void.TYPE.equals(returnType) && args.length == 1
  238. && !java.lang.String.class.equals(args[0])
  239. && !args[0].isArray() && !args[0].isPrimitive()) {
  240. try {
  241. Constructor constructor = null;
  242. try {
  243. constructor = args[0].getConstructor(new Class[] {});
  244. } catch (NoSuchMethodException ex) {
  245. constructor = args[0].getConstructor(new Class[] {Project.class});
  246. }
  247. String propName = getPropertyName(name, "addConfigured");
  248. nestedTypes.put(propName, args[0]);
  249. nestedCreators.put(propName, new AddNestedCreator(m,
  250. constructor, AddNestedCreator.ADD_CONFIGURED));
  251. } catch (NoSuchMethodException nse) {
  252. // ignore
  253. }
  254. } else if (name.startsWith("add")
  255. && java.lang.Void.TYPE.equals(returnType) && args.length == 1
  256. && !java.lang.String.class.equals(args[0])
  257. && !args[0].isArray() && !args[0].isPrimitive()) {
  258. try {
  259. Constructor constructor = null;
  260. try {
  261. constructor = args[0].getConstructor(new Class[] {});
  262. } catch (NoSuchMethodException ex) {
  263. constructor = args[0].getConstructor(new Class[] {Project.class});
  264. }
  265. String propName = getPropertyName(name, "add");
  266. if (nestedTypes.get(propName) != null) {
  267. /*
  268. * Ignore this method as there is an addConfigured
  269. * form of this method that has a higher
  270. * priority
  271. */
  272. continue;
  273. }
  274. nestedTypes.put(propName, args[0]);
  275. nestedCreators.put(propName, new AddNestedCreator(m,
  276. constructor, AddNestedCreator.ADD));
  277. } catch (NoSuchMethodException nse) {
  278. // ignore
  279. }
  280. }
  281. }
  282. addText = addTextMethod;
  283. }
  284. /**
  285. * Certain set methods are part of the Ant core interface to tasks and
  286. * therefore not to be considered for introspection
  287. *
  288. * @param name the name of the set method
  289. * @param type the type of the set method's parameter
  290. * @return true if the given set method is to be hidden.
  291. */
  292. private boolean isHiddenSetMethod(String name, Class type) {
  293. if ("setLocation".equals(name) && org.apache.tools.ant.Location.class.equals(type)) {
  294. return true;
  295. }
  296. if ("setTaskType".equals(name) && java.lang.String.class.equals(type)) {
  297. return true;
  298. }
  299. return false;
  300. }
  301. /**
  302. * Returns a helper for the given class, either from the cache
  303. * or by creating a new instance.
  304. *
  305. * @param c The class for which a helper is required.
  306. * Must not be <code>null</code>.
  307. *
  308. * @return a helper for the specified class
  309. */
  310. public static synchronized IntrospectionHelper getHelper(Class c) {
  311. return getHelper(null, c);
  312. }
  313. /**
  314. * Returns a helper for the given class, either from the cache
  315. * or by creating a new instance.
  316. *
  317. * The method will make sure the helper will be cleaned up at the end of
  318. * the project, and only one instance will be created for each class.
  319. *
  320. * @param p the project instance. Can be null, in which case the helper is not cached.
  321. * @param c The class for which a helper is required.
  322. * Must not be <code>null</code>.
  323. *
  324. * @return a helper for the specified class
  325. */
  326. public static IntrospectionHelper getHelper(Project p, Class c) {
  327. IntrospectionHelper ih = (IntrospectionHelper) HELPERS.get(c.getName());
  328. // If a helper cannot be found, or if the helper is for another
  329. // classloader, create a new IH
  330. if (ih == null || ih.bean != c) {
  331. ih = new IntrospectionHelper(c);
  332. if (p != null) {
  333. // #30162: do *not* cache this if there is no project, as we
  334. // cannot guarantee that the cache will be cleared.
  335. HELPERS.put(c.getName(), ih);
  336. }
  337. }
  338. return ih;
  339. }
  340. /**
  341. * Sets the named attribute in the given element, which is part of the
  342. * given project.
  343. *
  344. * @param p The project containing the element. This is used when files
  345. * need to be resolved. Must not be <code>null</code>.
  346. * @param element The element to set the attribute in. Must not be
  347. * <code>null</code>.
  348. * @param attributeName The name of the attribute to set. Must not be
  349. * <code>null</code>.
  350. * @param value The value to set the attribute to. This may be interpreted
  351. * or converted to the necessary type if the setter method
  352. * doesn't accept an object of the supplied type.
  353. *
  354. * @exception BuildException if the introspected class doesn't support
  355. * the given attribute, or if the setting
  356. * method fails.
  357. */
  358. public void setAttribute(Project p, Object element, String attributeName,
  359. Object value) throws BuildException {
  360. AttributeSetter as = (AttributeSetter) attributeSetters.get(
  361. attributeName.toLowerCase(Locale.US));
  362. if (as == null && value != null) {
  363. if (element instanceof DynamicAttributeNS) {
  364. DynamicAttributeNS dc = (DynamicAttributeNS) element;
  365. String uriPlusPrefix = ProjectHelper.extractUriFromComponentName(attributeName);
  366. String uri = ProjectHelper.extractUriFromComponentName(uriPlusPrefix);
  367. String localName = ProjectHelper.extractNameFromComponentName(attributeName);
  368. String qName = "".equals(uri) ? localName : uri + ":" + localName;
  369. dc.setDynamicAttribute(uri, localName, qName, value.toString());
  370. return;
  371. }
  372. if (element instanceof DynamicAttribute) {
  373. DynamicAttribute dc = (DynamicAttribute) element;
  374. dc.setDynamicAttribute(attributeName.toLowerCase(Locale.US), value.toString());
  375. return;
  376. }
  377. if (attributeName.indexOf(':') >= 0) {
  378. return; // Ignore attribute from unknown uri's
  379. }
  380. String msg = getElementName(p, element)
  381. + " doesn't support the \"" + attributeName + "\" attribute.";
  382. throw new UnsupportedAttributeException(msg, attributeName);
  383. }
  384. try {
  385. as.setObject(p, element, value);
  386. } catch (IllegalAccessException ie) {
  387. // impossible as getMethods should only return public methods
  388. throw new BuildException(ie);
  389. } catch (InvocationTargetException ite) {
  390. throw extractBuildException(ite);
  391. }
  392. }
  393. /**
  394. * Sets the named attribute in the given element, which is part of the
  395. * given project.
  396. *
  397. * @param p The project containing the element. This is used when files
  398. * need to be resolved. Must not be <code>null</code>.
  399. * @param element The element to set the attribute in. Must not be
  400. * <code>null</code>.
  401. * @param attributeName The name of the attribute to set. Must not be
  402. * <code>null</code>.
  403. * @param value The value to set the attribute to. This may be interpreted
  404. * or converted to the necessary type if the setter method
  405. * doesn't just take a string. Must not be <code>null</code>.
  406. *
  407. * @exception BuildException if the introspected class doesn't support
  408. * the given attribute, or if the setting
  409. * method fails.
  410. */
  411. public void setAttribute(Project p, Object element, String attributeName,
  412. String value) throws BuildException {
  413. setAttribute(p, element, attributeName, (Object) value);
  414. }
  415. /**
  416. * Adds PCDATA to an element, using the element's
  417. * <code>void addText(String)</code> method, if it has one. If no
  418. * such method is present, a BuildException is thrown if the
  419. * given text contains non-whitespace.
  420. *
  421. * @param project The project which the element is part of.
  422. * Must not be <code>null</code>.
  423. * @param element The element to add the text to.
  424. * Must not be <code>null</code>.
  425. * @param text The text to add.
  426. * Must not be <code>null</code>.
  427. *
  428. * @exception BuildException if non-whitespace text is provided and no
  429. * method is available to handle it, or if
  430. * the handling method fails.
  431. */
  432. public void addText(Project project, Object element, String text)
  433. throws BuildException {
  434. if (addText == null) {
  435. text = text.trim();
  436. // Element doesn't handle text content
  437. if (text.length() == 0) {
  438. // Only whitespace - ignore
  439. return;
  440. }
  441. // Not whitespace - fail
  442. throw new BuildException(project.getElementName(element)
  443. + " doesn't support nested text data (\"" + condenseText(text) + "\").");
  444. }
  445. try {
  446. addText.invoke(element, new Object[] {text});
  447. } catch (IllegalAccessException ie) {
  448. // impossible as getMethods should only return public methods
  449. throw new BuildException(ie);
  450. } catch (InvocationTargetException ite) {
  451. throw extractBuildException(ite);
  452. }
  453. }
  454. /**
  455. * Utility method to throw a NotSupported exception
  456. *
  457. * @param project the Project instance.
  458. * @param parent the object which doesn't support a requested element
  459. * @param elementName the name of the Element which is trying to be created.
  460. */
  461. public void throwNotSupported(Project project, Object parent, String elementName) {
  462. String msg = project.getElementName(parent)
  463. + " doesn't support the nested \"" + elementName + "\" element.";
  464. throw new UnsupportedElementException(msg, elementName);
  465. }
  466. /**
  467. * Get the specific NestedCreator for a given project/parent/element combination
  468. * @param project ant project
  469. * @param parentUri URI of the parent.
  470. * @param parent the parent class
  471. * @param elementName element to work with. This can contain
  472. * a URI,localname tuple of of the form uri:localname
  473. * @param child the bit of XML to work with
  474. * @return a nested creator that can handle the child elements.
  475. * @throws BuildException if the parent does not support child elements of that name
  476. */
  477. private NestedCreator getNestedCreator(
  478. Project project, String parentUri, Object parent,
  479. String elementName, UnknownElement child) throws BuildException {
  480. String uri = ProjectHelper.extractUriFromComponentName(elementName);
  481. String name = ProjectHelper.extractNameFromComponentName(elementName);
  482. if (uri.equals(ProjectHelper.ANT_CORE_URI)) {
  483. uri = "";
  484. }
  485. if (parentUri.equals(ProjectHelper.ANT_CORE_URI)) {
  486. parentUri = "";
  487. }
  488. NestedCreator nc = null;
  489. if (uri.equals(parentUri) || uri.length() == 0) {
  490. nc = (NestedCreator) nestedCreators.get(name.toLowerCase(Locale.US));
  491. }
  492. if (nc == null) {
  493. nc = createAddTypeCreator(project, parent, elementName);
  494. }
  495. if (nc == null && parent instanceof DynamicElementNS) {
  496. DynamicElementNS dc = (DynamicElementNS) parent;
  497. String qName = child == null ? name : child.getQName();
  498. final Object nestedElement = dc.createDynamicElement(
  499. child == null ? "" : child.getNamespace(), name, qName);
  500. if (nestedElement != null) {
  501. nc = new NestedCreator(null) {
  502. Object create(Project project, Object parent, Object ignore) {
  503. return nestedElement;
  504. }
  505. };
  506. }
  507. }
  508. if (nc == null && parent instanceof DynamicElement) {
  509. DynamicElement dc = (DynamicElement) parent;
  510. final Object nestedElement = dc.createDynamicElement(name.toLowerCase(Locale.US));
  511. if (nestedElement != null) {
  512. nc = new NestedCreator(null) {
  513. Object create(Project project, Object parent, Object ignore) {
  514. return nestedElement;
  515. }
  516. };
  517. }
  518. }
  519. if (nc == null) {
  520. throwNotSupported(project, parent, elementName);
  521. }
  522. return nc;
  523. }
  524. /**
  525. * Creates a named nested element. Depending on the results of the
  526. * initial introspection, either a method in the given parent instance
  527. * or a simple no-arg constructor is used to create an instance of the
  528. * specified element type.
  529. *
  530. * @param project Project to which the parent object belongs.
  531. * Must not be <code>null</code>. If the resulting
  532. * object is an instance of ProjectComponent, its
  533. * Project reference is set to this parameter value.
  534. * @param parent Parent object used to create the instance.
  535. * Must not be <code>null</code>.
  536. * @param elementName Name of the element to create an instance of.
  537. * Must not be <code>null</code>.
  538. *
  539. * @return an instance of the specified element type
  540. * @deprecated since 1.6.x.
  541. * This is not a namespace aware method.
  542. *
  543. * @exception BuildException if no method is available to create the
  544. * element instance, or if the creating method fails.
  545. */
  546. public Object createElement(Project project, Object parent, String elementName)
  547. throws BuildException {
  548. NestedCreator nc = getNestedCreator(project, "", parent, elementName, null);
  549. try {
  550. Object nestedElement = nc.create(project, parent, null);
  551. if (project != null) {
  552. project.setProjectReference(nestedElement);
  553. }
  554. return nestedElement;
  555. } catch (IllegalAccessException ie) {
  556. // impossible as getMethods should only return public methods
  557. throw new BuildException(ie);
  558. } catch (InstantiationException ine) {
  559. // impossible as getMethods should only return public methods
  560. throw new BuildException(ine);
  561. } catch (InvocationTargetException ite) {
  562. throw extractBuildException(ite);
  563. }
  564. }
  565. /**
  566. * returns an object that creates and stores an object
  567. * for an element of a parent.
  568. *
  569. * @param project Project to which the parent object belongs.
  570. * @param parentUri The namespace uri of the parent object.
  571. * @param parent Parent object used to create the creator object to
  572. * create and store and instance of a subelement.
  573. * @param elementName Name of the element to create an instance of.
  574. * @param ue The unknown element associated with the element.
  575. * @return a creator object to create and store the element instance.
  576. */
  577. public Creator getElementCreator(
  578. Project project, String parentUri, Object parent, String elementName, UnknownElement ue) {
  579. NestedCreator nc = getNestedCreator(project, parentUri, parent, elementName, ue);
  580. return new Creator(project, parent, nc);
  581. }
  582. /**
  583. * Indicates whether the introspected class is a dynamic one,
  584. * supporting arbitrary nested elements and/or attributes.
  585. *
  586. * @return <code>true<code> if the introspected class is dynamic;
  587. * <code>false<code> otherwise.
  588. * @since Ant 1.6.3
  589. *
  590. * @see DynamicElement
  591. * @see DynamicElementNS
  592. */
  593. public boolean isDynamic() {
  594. return DynamicElement.class.isAssignableFrom(bean)
  595. || DynamicElementNS.class.isAssignableFrom(bean);
  596. }
  597. /**
  598. * Indicates whether the introspected class is a task container,
  599. * supporting arbitrary nested tasks/types.
  600. *
  601. * @return <code>true<code> if the introspected class is a container;
  602. * <code>false<code> otherwise.
  603. * @since Ant 1.6.3
  604. *
  605. * @see TaskContainer
  606. */
  607. public boolean isContainer() {
  608. return TaskContainer.class.isAssignableFrom(bean);
  609. }
  610. /**
  611. * Indicates if this element supports a nested element of the
  612. * given name.
  613. *
  614. * @param elementName the name of the nested element being checked
  615. *
  616. * @return true if the given nested element is supported
  617. */
  618. public boolean supportsNestedElement(String elementName) {
  619. return supportsNestedElement("", elementName);
  620. }
  621. /**
  622. * Indicate if this element supports a nested element of the
  623. * given name.
  624. *
  625. * @param parentUri the uri of the parent
  626. * @param elementName the name of the nested element being checked
  627. *
  628. * @return true if the given nested element is supported
  629. */
  630. public boolean supportsNestedElement(String parentUri, String elementName) {
  631. if (isDynamic() || addTypeMethods.size() > 0) {
  632. return true;
  633. }
  634. return supportsReflectElement(parentUri, elementName);
  635. }
  636. /**
  637. * Check if this element supports a nested element from reflection.
  638. *
  639. * @param parentUri the uri of the parent
  640. * @param elementName the name of the nested element being checked
  641. *
  642. * @return true if the given nested element is supported
  643. * @since Ant 1.8.0
  644. */
  645. public boolean supportsReflectElement(
  646. String parentUri, String elementName) {
  647. String name = ProjectHelper.extractNameFromComponentName(elementName);
  648. if (!nestedCreators.containsKey(name.toLowerCase(Locale.US))) {
  649. return false;
  650. }
  651. String uri = ProjectHelper.extractUriFromComponentName(elementName);
  652. if (uri.equals(ProjectHelper.ANT_CORE_URI)) {
  653. uri = "";
  654. }
  655. if ("".equals(uri)) {
  656. return true;
  657. }
  658. if (parentUri.equals(ProjectHelper.ANT_CORE_URI)) {
  659. parentUri = "";
  660. }
  661. return uri.equals(parentUri);
  662. }
  663. /**
  664. * Stores a named nested element using a storage method determined
  665. * by the initial introspection. If no appropriate storage method
  666. * is available, this method returns immediately.
  667. *
  668. * @param project Ignored in this implementation.
  669. * May be <code>null</code>.
  670. *
  671. * @param parent Parent instance to store the child in.
  672. * Must not be <code>null</code>.
  673. *
  674. * @param child Child instance to store in the parent.
  675. * Should not be <code>null</code>.
  676. *
  677. * @param elementName Name of the child element to store.
  678. * May be <code>null</code>, in which case
  679. * this method returns immediately.
  680. *
  681. * @exception BuildException if the storage method fails.
  682. */
  683. public void storeElement(Project project, Object parent, Object child,
  684. String elementName) throws BuildException {
  685. if (elementName == null) {
  686. return;
  687. }
  688. NestedCreator ns = (NestedCreator) nestedCreators.get(elementName.toLowerCase(Locale.US));
  689. if (ns == null) {
  690. return;
  691. }
  692. try {
  693. ns.store(parent, child);
  694. } catch (IllegalAccessException ie) {
  695. // impossible as getMethods should only return public methods
  696. throw new BuildException(ie);
  697. } catch (InstantiationException ine) {
  698. // impossible as getMethods should only return public methods
  699. throw new BuildException(ine);
  700. } catch (InvocationTargetException ite) {
  701. throw extractBuildException(ite);
  702. }
  703. }
  704. /**
  705. * Helper method to extract the inner fault from an {@link InvocationTargetException}, and turn
  706. * it into a BuildException. If it is already a BuildException, it is type cast and returned; if
  707. * not a new BuildException is created containing the child as nested text.
  708. * @param ite
  709. * @return the nested exception
  710. */
  711. private static BuildException extractBuildException(InvocationTargetException ite) {
  712. Throwable t = ite.getTargetException();
  713. if (t instanceof BuildException) {
  714. return (BuildException) t;
  715. }
  716. return new BuildException(t);
  717. }
  718. /**
  719. * Returns the type of a named nested element.
  720. *
  721. * @param elementName The name of the element to find the type of.
  722. * Must not be <code>null</code>.
  723. *
  724. * @return the type of the nested element with the specified name.
  725. * This will never be <code>null</code>.
  726. *
  727. * @exception BuildException if the introspected class does not
  728. * support the named nested element.
  729. */
  730. public Class getElementType(String elementName) throws BuildException {
  731. Class nt = (Class) nestedTypes.get(elementName);
  732. if (nt == null) {
  733. throw new UnsupportedElementException("Class "
  734. + bean.getName() + " doesn't support the nested \""
  735. + elementName + "\" element.", elementName);
  736. }
  737. return nt;
  738. }
  739. /**
  740. * Returns the type of a named attribute.
  741. *
  742. * @param attributeName The name of the attribute to find the type of.
  743. * Must not be <code>null</code>.
  744. *
  745. * @return the type of the attribute with the specified name.
  746. * This will never be <code>null</code>.
  747. *
  748. * @exception BuildException if the introspected class does not
  749. * support the named attribute.
  750. */
  751. public Class getAttributeType(String attributeName) throws BuildException {
  752. Class at = (Class) attributeTypes.get(attributeName);
  753. if (at == null) {
  754. throw new UnsupportedAttributeException("Class "
  755. + bean.getName() + " doesn't support the \""
  756. + attributeName + "\" attribute.", attributeName);
  757. }
  758. return at;
  759. }
  760. /**
  761. * Returns the addText method when the introspected
  762. * class supports nested text.
  763. *
  764. * @return the method on this introspected class that adds nested text.
  765. * Cannot be <code>null</code>.
  766. * @throws BuildException if the introspected class does not
  767. * support the nested text.
  768. * @since Ant 1.6.3
  769. */
  770. public Method getAddTextMethod() throws BuildException {
  771. if (!supportsCharacters()) {
  772. throw new BuildException("Class " + bean.getName()
  773. + " doesn't support nested text data.");
  774. }
  775. return addText;
  776. }
  777. /**
  778. * Returns the adder or creator method of a named nested element.
  779. *
  780. * @param elementName The name of the attribute to find the setter
  781. * method of. Must not be <code>null</code>.
  782. * @return the method on this introspected class that adds or creates this
  783. * nested element. Can be <code>null</code> when the introspected
  784. * class is a dynamic configurator!
  785. * @throws BuildException if the introspected class does not
  786. * support the named nested element.
  787. * @since Ant 1.6.3
  788. */
  789. public Method getElementMethod(String elementName) throws BuildException {
  790. Object creator = nestedCreators.get(elementName);
  791. if (creator == null) {
  792. throw new UnsupportedElementException("Class "
  793. + bean.getName() + " doesn't support the nested \""
  794. + elementName + "\" element.", elementName);
  795. }
  796. return ((NestedCreator) creator).method;
  797. }
  798. /**
  799. * Returns the setter method of a named attribute.
  800. *
  801. * @param attributeName The name of the attribute to find the setter
  802. * method of. Must not be <code>null</code>.
  803. * @return the method on this introspected class that sets this attribute.
  804. * This will never be <code>null</code>.
  805. * @throws BuildException if the introspected class does not
  806. * support the named attribute.
  807. * @since Ant 1.6.3
  808. */
  809. public Method getAttributeMethod(String attributeName) throws BuildException {
  810. Object setter = attributeSetters.get(attributeName);
  811. if (setter == null) {
  812. throw new UnsupportedAttributeException("Class "
  813. + bean.getName() + " doesn't support the \""
  814. + attributeName + "\" attribute.", attributeName);
  815. }
  816. return ((AttributeSetter) setter).method;
  817. }
  818. /**
  819. * Returns whether or not the introspected class supports PCDATA.
  820. *
  821. * @return whether or not the introspected class supports PCDATA.
  822. */
  823. public boolean supportsCharacters() {
  824. return addText != null;
  825. }
  826. /**
  827. * Returns an enumeration of the names of the attributes supported by the introspected class.
  828. *
  829. * @return an enumeration of the names of the attributes supported by the introspected class.
  830. * @see #getAttributeMap
  831. */
  832. public Enumeration getAttributes() {
  833. return attributeSetters.keys();
  834. }
  835. /**
  836. * Returns a read-only map of attributes supported by the introspected class.
  837. *
  838. * @return an attribute name to attribute <code>Class</code>
  839. * unmodifiable map. Can be empty, but never <code>null</code>.
  840. * @since Ant 1.6.3
  841. */
  842. public Map getAttributeMap() {
  843. return attributeTypes.isEmpty()
  844. ? Collections.EMPTY_MAP : Collections.unmodifiableMap(attributeTypes);
  845. }
  846. /**
  847. * Returns an enumeration of the names of the nested elements supported
  848. * by the introspected class.
  849. *
  850. * @return an enumeration of the names of the nested elements supported
  851. * by the introspected class.
  852. * @see #getNestedElementMap
  853. */
  854. public Enumeration getNestedElements() {
  855. return nestedTypes.keys();
  856. }
  857. /**
  858. * Returns a read-only map of nested elements supported
  859. * by the introspected class.
  860. *
  861. * @return a nested-element name to nested-element <code>Class</code>
  862. * unmodifiable map. Can be empty, but never <code>null</code>.
  863. * @since Ant 1.6.3
  864. */
  865. public Map getNestedElementMap() {
  866. return nestedTypes.isEmpty()
  867. ? Collections.EMPTY_MAP : Collections.unmodifiableMap(nestedTypes);
  868. }
  869. /**
  870. * Returns a read-only list of extension points supported
  871. * by the introspected class.
  872. * <p>
  873. * A task/type or nested element with void methods named <code>add()<code>
  874. * or <code>addConfigured()</code>, taking a single class or interface
  875. * argument, supports extensions point. This method returns the list of
  876. * all these <em>void add[Configured](type)</em> methods.
  877. *
  878. * @return a list of void, single argument add() or addConfigured()
  879. * <code>Method<code>s of all supported extension points.
  880. * These methods are sorted such that if the argument type of a
  881. * method derives from another type also an argument of a method
  882. * of this list, the method with the most derived argument will
  883. * always appear first. Can be empty, but never <code>null</code>.
  884. * @since Ant 1.6.3
  885. */
  886. public List getExtensionPoints() {
  887. return addTypeMethods.isEmpty()
  888. ? Collections.EMPTY_LIST : Collections.unmodifiableList(addTypeMethods);
  889. }
  890. /**
  891. * Creates an implementation of AttributeSetter for the given
  892. * attribute type. Conversions (where necessary) are automatically
  893. * made for the following types:
  894. * <ul>
  895. * <li>String (left as it is)
  896. * <li>Character/char (first character is used)
  897. * <li>Boolean/boolean
  898. * ({@link Project#toBoolean(String) Project.toBoolean(String)} is used)
  899. * <li>Class (Class.forName is used)
  900. * <li>File (resolved relative to the appropriate project)
  901. * <li>Path (resolve relative to the appropriate project)
  902. * <li>Resource (resolved as a FileResource relative to the appropriate project)
  903. * <li>FileProvider (resolved as a FileResource relative to the appropriate project)
  904. * <li>EnumeratedAttribute (uses its own
  905. * {@link EnumeratedAttribute#setValue(String) setValue} method)
  906. * <li>Other primitive types (wrapper classes are used with constructors
  907. * taking String)
  908. * </ul>
  909. *
  910. * If none of the above covers the given parameters, a constructor for the
  911. * appropriate class taking a String parameter is used if it is available.
  912. *
  913. * @param m The method to invoke on the bean when the setter is invoked.
  914. * Must not be <code>null</code>.
  915. * @param arg The type of the single argument of the bean's method.
  916. * Must not be <code>null</code>.
  917. * @param attrName the name of the attribute for which the setter is being
  918. * created.
  919. *
  920. * @return an appropriate AttributeSetter instance, or <code>null</code>
  921. * if no appropriate conversion is available.
  922. */
  923. private AttributeSetter createAttributeSetter(final Method m,
  924. Class arg,
  925. final String attrName) {
  926. // use wrappers for primitive classes, e.g. int and
  927. // Integer are treated identically
  928. final Class reflectedArg = PRIMITIVE_TYPE_MAP.containsKey(arg)
  929. ? (Class) PRIMITIVE_TYPE_MAP.get(arg) : arg;
  930. // Object.class - it gets handled differently by AttributeSetter
  931. if (java.lang.Object.class == reflectedArg) {
  932. return new AttributeSetter(m, arg) {
  933. public void set(Project p, Object parent, String value)
  934. throws InvocationTargetException,
  935. IllegalAccessException {
  936. throw new BuildException(
  937. "Internal ant problem - this should not get called");
  938. }
  939. };
  940. }
  941. // simplest case - setAttribute expects String
  942. if (java.lang.String.class.equals(reflectedArg)) {
  943. return new AttributeSetter(m, arg) {
  944. public void set(Project p, Object parent, String value)
  945. throws InvocationTargetException, IllegalAccessException {
  946. m.invoke(parent, (Object[]) new String[] {value});
  947. }
  948. };
  949. }
  950. // char and Character get special treatment - take the first character
  951. if (java.lang.Character.class.equals(reflectedArg)) {
  952. return new AttributeSetter(m, arg) {
  953. public void set(Project p, Object parent, String value)
  954. throws InvocationTargetException, IllegalAccessException {
  955. if (value.length() == 0) {
  956. throw new BuildException("The value \"\" is not a "
  957. + "legal value for attribute \"" + attrName + "\"");
  958. }
  959. m.invoke(parent, (Object[]) new Character[] {new Character(value.charAt(0))});
  960. }
  961. };
  962. }
  963. // boolean and Boolean get special treatment because we have a nice method in Project
  964. if (java.lang.Boolean.class.equals(reflectedArg)) {
  965. return new AttributeSetter(m, arg) {
  966. public void set(Project p, Object parent, String value)
  967. throws InvocationTargetException, IllegalAccessException {
  968. m.invoke(parent, (Object[]) new Boolean[] {
  969. Project.toBoolean(value) ? Boolean.TRUE : Boolean.FALSE });
  970. }
  971. };
  972. }
  973. // Class doesn't have a String constructor but a decent factory method
  974. if (java.lang.Class.class.equals(reflectedArg)) {
  975. return new AttributeSetter(m, arg) {
  976. public void set(Project p, Object parent, String value)
  977. throws InvocationTargetException, IllegalAccessException, BuildException {
  978. try {
  979. m.invoke(parent, new Object[] {Class.forName(value)});
  980. } catch (ClassNotFoundException ce) {
  981. throw new BuildException(ce);
  982. }
  983. }
  984. };
  985. }
  986. // resolve relative paths through Project
  987. if (java.io.File.class.equals(reflectedArg)) {
  988. return new AttributeSetter(m, arg) {
  989. public void set(Project p, Object parent, String value)
  990. throws InvocationTargetException, IllegalAccessException {
  991. m.invoke(parent, new Object[] {p.resolveFile(value)});
  992. }
  993. };
  994. }
  995. // resolve Resources/FileProviders as FileResources relative to Project:
  996. if (Resource.class.equals(reflectedArg) || FileProvider.class.equals(reflectedArg)) {
  997. return new AttributeSetter(m, arg) {
  998. void set(Project p, Object parent, String value) throws InvocationTargetException,
  999. IllegalAccessException, BuildException {
  1000. m.invoke(parent, new Object[] { new FileResource(p, p.resolveFile(value)) });
  1001. };
  1002. };
  1003. }
  1004. // EnumeratedAttributes have their own helper class
  1005. if (EnumeratedAttribute.class.isAssignableFrom(reflectedArg)) {
  1006. return new AttributeSetter(m, arg) {
  1007. public void set(Project p, Object parent, String value)
  1008. throws InvocationTargetException, IllegalAccessException, BuildException {
  1009. try {
  1010. EnumeratedAttribute ea = (EnumeratedAttribute) reflectedArg.newInstance();
  1011. ea.setValue(value);
  1012. m.invoke(parent, new Object[] {ea});
  1013. } catch (InstantiationException ie) {
  1014. throw new BuildException(ie);
  1015. }
  1016. }
  1017. };
  1018. }
  1019. AttributeSetter setter = getEnumSetter(reflectedArg, m, arg);
  1020. if (setter != null) {
  1021. return setter;
  1022. }
  1023. if (java.lang.Long.class.equals(reflectedArg)) {
  1024. return new AttributeSetter(m, arg) {
  1025. public void set(Project p, Object parent, String value)
  1026. throws InvocationTargetException, IllegalAccessException, BuildException {
  1027. try {
  1028. m.invoke(parent, new Object[] {
  1029. new Long(StringUtils.parseHumanSizes(value)) });
  1030. } catch (InvocationTargetException e) {
  1031. throw e;
  1032. } catch (IllegalAccessException e) {
  1033. throw e;
  1034. } catch (Exception e) {
  1035. throw new BuildException(e);
  1036. }
  1037. }
  1038. };
  1039. }
  1040. // worst case. look for a public String constructor and use it
  1041. // also supports new Whatever(Project, String) as for Path or Reference
  1042. // This is used (deliberately) for all primitives/wrappers other than
  1043. // char, boolean, and long.
  1044. boolean includeProject;
  1045. Constructor c;
  1046. try {
  1047. // First try with Project.
  1048. c = reflectedArg.getConstructor(new Class[] {Project.class, String.class});
  1049. includeProject = true;
  1050. } catch (NoSuchMethodException nme) {
  1051. // OK, try without.
  1052. try {
  1053. c = reflectedArg.getConstructor(new Class[] {String.class});
  1054. includeProject = false;
  1055. } catch (NoSuchMethodException nme2) {
  1056. // Well, no matching constructor.
  1057. return null;
  1058. }
  1059. }
  1060. final boolean finalIncludeProject = includeProject;
  1061. final Constructor finalConstructor = c;
  1062. return new AttributeSetter(m, arg) {
  1063. public void set(Project p, Object parent, String value)
  1064. throws InvocationTargetException, IllegalAccessException, BuildException {
  1065. try {
  1066. Object[] args = finalIncludeProject
  1067. ? new Object[] {p, value} : new Object[] {value};
  1068. Object attribute = finalConstructor.newInstance(args);
  1069. if (p != null) {
  1070. p.setProjectReference(attribute);
  1071. }
  1072. m.invoke(parent, new Object[] {attribute});
  1073. } catch (InstantiationException ie) {
  1074. throw new BuildException(ie);
  1075. }
  1076. }
  1077. };
  1078. }
  1079. private AttributeSetter getEnumSetter(
  1080. final Class reflectedArg, final Method m, Class arg) {
  1081. Class enumClass = null;
  1082. try {
  1083. enumClass = Class.forName("java.lang.Enum");
  1084. } catch (ClassNotFoundException e) {
  1085. //ignore
  1086. }
  1087. if (enumClass != null && enumClass.isAssignableFrom(reflectedArg)) {
  1088. return new AttributeSetter(m, arg) {
  1089. public void set(Project p, Object parent, String value)
  1090. throws InvocationTargetException, IllegalAccessException,
  1091. BuildException {
  1092. try {
  1093. m.invoke(
  1094. parent, new Object[] {
  1095. reflectedArg.getMethod(
  1096. "valueOf", new Class[] {String.class}).
  1097. invoke(null, new Object[] {value})});
  1098. } catch (InvocationTargetException x) {
  1099. //there is specific logic here for the value
  1100. // being out of the allowed set of enumerations.
  1101. if (x.getTargetException() instanceof IllegalArgumentException) {
  1102. throw new BuildException(
  1103. "'" + value + "' is not a permitted value for "
  1104. + reflectedArg.getName());
  1105. }
  1106. //only if the exception is not an IllegalArgument do we
  1107. // request the
  1108. //BuildException via extractBuildException():
  1109. throw extractBuildException(x);
  1110. } catch (Exception x) {
  1111. //any other failure of invoke() to work.
  1112. throw new BuildException(x);
  1113. }
  1114. }
  1115. };
  1116. }
  1117. return null;
  1118. }
  1119. /**
  1120. * Returns a description of the type of the given element in
  1121. * relation to a given project. This is used for logging purposes
  1122. * when the element is asked to cope with some data it has no way of handling.
  1123. *
  1124. * @param project The project the element is defined in. Must not be <code>null</code>.
  1125. *
  1126. * @param element The element to describe. Must not be <code>null</code>.
  1127. *
  1128. * @return a description of the element type
  1129. */
  1130. private String getElementName(Project project, Object element) {
  1131. return project.getElementName(element);
  1132. }
  1133. /**
  1134. * Extracts the name of a property from a method name by subtracting
  1135. * a given prefix and converting into lower case. It is up to calling
  1136. * code to make sure the method name does actually begin with the
  1137. * specified prefix - no checking is done in this method.
  1138. *
  1139. * @param methodName The name of the method in question. Must not be <code>null</code>.
  1140. * @param prefix The prefix to remove. Must not be <code>null</code>.
  1141. *
  1142. * @return the lower-cased method name with the prefix removed.
  1143. */
  1144. private static String getPropertyName(String methodName, String prefix) {
  1145. return methodName.substring(prefix.length()).toLowerCase(Locale.US);
  1146. }
  1147. /**
  1148. * creator - allows use of create/store external
  1149. * to IntrospectionHelper.
  1150. * The class is final as it has a private constructor.
  1151. */
  1152. public static final class Creator {
  1153. private NestedCreator nestedCreator;
  1154. private Object parent;
  1155. private Project project;
  1156. private Object nestedObject;
  1157. private String polyType;
  1158. /**
  1159. * Creates a new Creator instance.
  1160. * This object is given to the UnknownElement to create
  1161. * objects for sub-elements. UnknownElement calls
  1162. * create to create an object, the object then gets
  1163. * configured and then UnknownElement calls store.
  1164. * SetPolyType may be used to override the type used
  1165. * to create the object with. SetPolyType gets called before create.
  1166. *
  1167. * @param project the current project
  1168. * @param parent the parent object to create the object in
  1169. * @param nestedCreator the nested creator object to use
  1170. */
  1171. private Creator(Project project, Object parent, NestedCreator nestedCreator) {
  1172. this.project = project;
  1173. this.parent = parent;
  1174. this.nestedCreator = nestedCreator;
  1175. }
  1176. /**
  1177. * Used to override the class used to create the object.
  1178. *
  1179. * @param polyType a ant component type name
  1180. */
  1181. public void setPolyType(String polyType) {
  1182. this.polyType = polyType;
  1183. }
  1184. /**
  1185. * Create an object using this creator, which is determined by introspection.
  1186. *
  1187. * @return the created object
  1188. */
  1189. public Object create() {
  1190. if (polyType != null) {
  1191. if (!nestedCreator.isPolyMorphic()) {
  1192. throw new BuildException(
  1193. "Not allowed to use the polymorphic form for this element");
  1194. }
  1195. ComponentHelper helper = ComponentHelper.getComponentHelper(project);
  1196. nestedObject = helper.createComponent(polyType);
  1197. if (nestedObject == null) {
  1198. throw new BuildException("Unable to create object of type " + polyType);
  1199. }
  1200. }
  1201. try {
  1202. nestedObject = nestedCreator.create(project, parent, nestedObject);
  1203. if (project != null) {
  1204. project.setProjectReference(nestedObject);
  1205. }
  1206. return nestedObject;
  1207. } catch (IllegalAccessException ex) {
  1208. throw new BuildException(ex);
  1209. } catch (InstantiationException ex) {
  1210. throw new BuildException(ex);
  1211. } catch (IllegalArgumentException ex) {
  1212. if (polyType == null) {
  1213. throw ex;
  1214. }
  1215. throw new BuildException("Invalid type used " + polyType);
  1216. } catch (InvocationTargetException ex) {
  1217. throw extractBuildException(ex);
  1218. }
  1219. }
  1220. /**
  1221. * @return the real object (used currently only for presetdef).
  1222. */
  1223. public Object getRealObject() {
  1224. return nestedCreator.getRealObject();
  1225. }
  1226. /**
  1227. * Stores the nested element object using a storage method determined by introspection.
  1228. *
  1229. */
  1230. public void store() {
  1231. try {
  1232. nestedCreator.store(parent, nestedObject);
  1233. } catch (IllegalAccessException ex) {
  1234. throw new BuildException(ex);
  1235. } catch (InstantiationException ex) {
  1236. throw new BuildException(ex);
  1237. } catch (IllegalArgumentException ex) {
  1238. if (polyType == null) {
  1239. throw ex;
  1240. }
  1241. throw new BuildException("Invalid type used " + polyType);
  1242. } catch (InvocationTargetException ex) {
  1243. throw extractBuildException(ex);
  1244. }
  1245. }
  1246. }
  1247. /**
  1248. * Internal interface used to create nested elements. Not documented
  1249. * in detail for reasons of source code readability.
  1250. */
  1251. private abstract static class NestedCreator {
  1252. private Method method; // the method called to add/create the nested element
  1253. protected NestedCreator(Method m) {
  1254. method = m;
  1255. }
  1256. Method getMethod() {
  1257. return method;
  1258. }
  1259. boolean isPolyMorphic() {
  1260. return false;
  1261. }
  1262. Object getRealObject() {
  1263. return null;
  1264. }
  1265. abstract Object create(Project project, Object parent, Object child)
  1266. throws InvocationTargetException, IllegalAccessException, InstantiationException;
  1267. void store(Object parent, Object child)
  1268. throws InvocationTargetException, IllegalAccessException, InstantiationException {
  1269. // DO NOTHING
  1270. }
  1271. }
  1272. private static class CreateNestedCreator extends NestedCreator {
  1273. CreateNestedCreator(Method m) {
  1274. super(m);
  1275. }
  1276. Object create(Project project, Object parent, Object ignore)
  1277. throws InvocationTargetException, IllegalAccessException {
  1278. return getMethod().invoke(parent, new Object[] {});
  1279. }
  1280. }
  1281. /** Version to use for addXXX and addConfiguredXXX */
  1282. private static class AddNestedCreator extends NestedCreator {
  1283. static final int ADD = 1;
  1284. static final int ADD_CONFIGURED = 2;
  1285. private Constructor constructor;
  1286. private int behavior; // ADD or ADD_CONFIGURED
  1287. AddNestedCreator(Method m, Constructor c, int behavior) {
  1288. super(m);
  1289. this.constructor = c;
  1290. this.behavior = behavior;
  1291. }
  1292. boolean isPolyMorphic() {
  1293. return true;
  1294. }
  1295. Object create(Project project, Object parent, Object child)
  1296. throws InvocationTargetException, IllegalAccessException, InstantiationException {
  1297. if (child == null) {
  1298. child = constructor.newInstance(
  1299. constructor.getParameterTypes().length == 0
  1300. ? new Object[] {} : new Object[] {project});
  1301. }
  1302. if (child instanceof PreSetDef.PreSetDefinition) {
  1303. child = ((PreSetDef.PreSetDefinition) child).createObject(project);
  1304. }
  1305. if (behavior == ADD) {
  1306. istore(parent, child);
  1307. }
  1308. return child;
  1309. }
  1310. void store(Object parent, Object child)
  1311. throws InvocationTargetException, IllegalAccessException, InstantiationException {
  1312. if (behavior == ADD_CONFIGURED) {
  1313. istore(parent, child);
  1314. }
  1315. }
  1316. private void istore(Object parent, Object child)
  1317. throws InvocationTargetException, IllegalAccessException, InstantiationException {
  1318. getMethod().invoke(parent, new Object[] {child});
  1319. }
  1320. }
  1321. /**
  1322. * Internal interface used to setting element attributes. Not documented
  1323. * in detail for reasons of source code readability.
  1324. */
  1325. private abstract static class AttributeSetter {
  1326. private Method method; // the method called to set the attribute
  1327. private Class type;
  1328. protected AttributeSetter(Method m, Class type) {
  1329. method = m;
  1330. this.type = type;
  1331. }
  1332. void setObject(Project p, Object parent, Object value)
  1333. throws InvocationTargetException, IllegalAccessException, BuildException {
  1334. if (type != null) {
  1335. Class useType = type;
  1336. if (type.isPrimitive()) {
  1337. if (value == null) {
  1338. throw new BuildException(
  1339. "Attempt to set primitive "
  1340. + getPropertyName(method.getName(), "set")
  1341. + " to null on " + parent);
  1342. }
  1343. useType = (Class) PRIMITIVE_TYPE_MAP.get(type);
  1344. }
  1345. if (value == null || useType.isInstance(value)) {
  1346. method.invoke(parent, new Object[] {value});
  1347. return;
  1348. }
  1349. }
  1350. set(p, parent, value.toString());
  1351. }
  1352. abstract void set(Project p, Object parent, String value)
  1353. throws InvocationTargetException, IllegalAccessException, BuildException;
  1354. }
  1355. /**
  1356. * Clears the static cache of on build finished.
  1357. */
  1358. public static void clearCache() {
  1359. HELPERS.clear();
  1360. }
  1361. /**
  1362. * Create a NestedCreator for the given element.
  1363. * @param project owning project
  1364. * @param parent Parent object used to create the instance.
  1365. * @param elementName name of the element
  1366. * @return a nested creator, or null if there is no component of the given name, or it
  1367. * has no matching add type methods
  1368. * @throws BuildException
  1369. */
  1370. private NestedCreator createAddTypeCreator(
  1371. Project project, Object parent, String elementName) throws BuildException {
  1372. if (addTypeMethods.size() == 0) {
  1373. return null;
  1374. }
  1375. ComponentHelper helper = ComponentHelper.getComponentHelper(project);
  1376. MethodAndObject restricted = createRestricted(
  1377. helper, elementName, addTypeMethods);
  1378. MethodAndObject topLevel = createTopLevel(
  1379. helper, elementName, addTypeMethods);
  1380. if (restricted == null && topLevel == null) {
  1381. return null;
  1382. }
  1383. if (restricted != null && topLevel != null) {
  1384. throw new BuildException(
  1385. "ambiguous: type and component definitions for "
  1386. + elementName);
  1387. }
  1388. MethodAndObject methodAndObject
  1389. = restricted != null ? restricted : topLevel;
  1390. Object rObject = methodAndObject.object;
  1391. if (methodAndObject.object instanceof PreSetDef.PreSetDefinition) {
  1392. rObject = ((PreSetDef.PreSetDefinition) methodAndObject.object)
  1393. .createObject(project);
  1394. }
  1395. final Object nestedObject = methodAndObject.object;
  1396. final Object realObject = rObject;
  1397. return new NestedCreator(methodAndObject.method) {
  1398. Object create(Project project, Object parent, Object ignore)
  1399. throws InvocationTargetException, IllegalAccessException {
  1400. if (!getMethod().getName().endsWith("Configured")) {
  1401. getMethod().invoke(parent, new Object[] {realObject});
  1402. }
  1403. return nestedObject;
  1404. }
  1405. Object getRealObject() {
  1406. return realObject;
  1407. }
  1408. void store(Object parent, Object child) throws InvocationTargetException,
  1409. IllegalAccessException, InstantiationException {
  1410. if (getMethod().getName().endsWith("Configured")) {
  1411. getMethod().invoke(parent, new Object[] {realObject});
  1412. }
  1413. }
  1414. };
  1415. }
  1416. /**
  1417. * Inserts an add or addConfigured method into
  1418. * the addTypeMethods array. The array is
  1419. * ordered so that the more derived classes are first.
  1420. * If both add and addConfigured are present, the addConfigured will take priority.
  1421. * @param method the <code>Method</code> to insert.
  1422. */
  1423. private void insertAddTypeMethod(Method method) {
  1424. Class argClass = method.getParameterTypes()[0];
  1425. for (int c = 0; c < addTypeMethods.size(); ++c) {
  1426. Method current = (Method) addTypeMethods.get(c);
  1427. if (current.getParameterTypes()[0].equals(argClass)) {
  1428. if (method.getName().equals("addConfigured")) {
  1429. // add configured replaces the add method
  1430. addTypeMethods.set(c, method);
  1431. }
  1432. return; // Already present
  1433. }
  1434. if (current.getParameterTypes()[0].isAssignableFrom(argClass)) {
  1435. addTypeMethods.add(c, method);
  1436. return; // higher derived
  1437. }
  1438. }
  1439. addTypeMethods.add(method);
  1440. }
  1441. /**
  1442. * Search the list of methods to find the first method
  1443. * that has a parameter that accepts the nested element object.
  1444. * @param paramClass the <code>Class</code> type to search for.
  1445. * @param methods the <code>List</code> of methods to search.
  1446. * @return a matching <code>Method</code>; null if none found.
  1447. */
  1448. private Method findMatchingMethod(Class paramClass, List methods) {
  1449. if (paramClass == null) {
  1450. return null;
  1451. }
  1452. Class matchedClass = null;
  1453. Method matchedMethod = null;
  1454. for (int i = 0; i < methods.size(); ++i) {
  1455. Method method = (Method) methods.get(i);
  1456. Class methodClass = method.getParameterTypes()[0];
  1457. if (methodClass.isAssignableFrom(paramClass)) {
  1458. if (matchedClass == null) {
  1459. matchedClass = methodClass;
  1460. matchedMethod = method;
  1461. } else if (!methodClass.isAssignableFrom(matchedClass)) {
  1462. throw new BuildException("ambiguous: types " + matchedClass.getName() + " and "
  1463. + methodClass.getName() + " match " + paramClass.getName());
  1464. }
  1465. }
  1466. }
  1467. return matchedMethod;
  1468. }
  1469. private String condenseText(final String text) {
  1470. if (text.length() <= MAX_REPORT_NESTED_TEXT) {
  1471. return text;
  1472. }
  1473. int ends = (MAX_REPORT_NESTED_TEXT - ELLIPSIS.length()) / 2;
  1474. return new StringBuffer(text).replace(ends, text.length() - ends, ELLIPSIS).toString();
  1475. }
  1476. private class MethodAndObject {
  1477. private Method method;
  1478. private Object object;
  1479. public MethodAndObject(Method method, Object object) {
  1480. this.method = method;
  1481. this.object = object;
  1482. }
  1483. }
  1484. /**
  1485. *
  1486. */
  1487. private AntTypeDefinition findRestrictedDefinition(
  1488. ComponentHelper helper, String componentName, List methods) {
  1489. AntTypeDefinition definition = null;
  1490. Class matchedDefinitionClass = null;
  1491. List definitions = helper.getRestrictedDefinitions(componentName);
  1492. if (definitions == null) {
  1493. return null;
  1494. }
  1495. synchronized (definitions) {
  1496. for (int i = 0; i < definitions.size(); ++i) {
  1497. AntTypeDefinition d = (AntTypeDefinition) definitions.get(i);
  1498. Class exposedClass = d.getExposedClass(helper.getProject());
  1499. if (exposedClass == null) {
  1500. continue;
  1501. }
  1502. Method method = findMatchingMethod(exposedClass, methods);
  1503. if (method == null) {
  1504. continue;
  1505. }
  1506. if (matchedDefinitionClass != null) {
  1507. throw new BuildException(
  1508. "ambiguous: restricted definitions for "
  1509. + componentName + " "
  1510. + matchedDefinitionClass + " and " + exposedClass);
  1511. }
  1512. matchedDefinitionClass = exposedClass;
  1513. definition = d;
  1514. }
  1515. }
  1516. return definition;
  1517. }
  1518. private MethodAndObject createRestricted(
  1519. ComponentHelper helper, String elementName, List addTypeMethods) {
  1520. Project project = helper.getProject();
  1521. AntTypeDefinition restrictedDefinition =
  1522. findRestrictedDefinition(helper, elementName, addTypeMethods);
  1523. if (restrictedDefinition == null) {
  1524. return null;
  1525. }
  1526. Method addMethod = findMatchingMethod(
  1527. restrictedDefinition.getExposedClass(project), addTypeMethods);
  1528. if (addMethod == null) {
  1529. throw new BuildException(
  1530. "Ant Internal Error - contract mismatch for "
  1531. + elementName);
  1532. }
  1533. Object addedObject = restrictedDefinition.create(project);
  1534. if (addedObject == null) {
  1535. throw new BuildException(
  1536. "Failed to create object " + elementName
  1537. + " of type " + restrictedDefinition.getTypeClass(project));
  1538. }
  1539. return new MethodAndObject(addMethod, addedObject);
  1540. }
  1541. private MethodAndObject createTopLevel(
  1542. ComponentHelper helper, String elementName, List methods) {
  1543. Class clazz = helper.getComponentClass(elementName);
  1544. if (clazz == null) {
  1545. return null;
  1546. }
  1547. Method addMethod = findMatchingMethod(clazz, addTypeMethods);
  1548. if (addMethod == null) {
  1549. return null;
  1550. }
  1551. Object addedObject = helper.createComponent(elementName);
  1552. return new MethodAndObject(addMethod, addedObject);
  1553. }
  1554. }