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 73 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
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
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739
  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.ENGLISH));
  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 DynamicObjectAttribute) {
  373. DynamicObjectAttribute dc = (DynamicObjectAttribute) element;
  374. dc.setDynamicAttribute(attributeName.toLowerCase(Locale.ENGLISH), value);
  375. return;
  376. }
  377. if (element instanceof DynamicAttribute) {
  378. DynamicAttribute dc = (DynamicAttribute) element;
  379. dc.setDynamicAttribute(attributeName.toLowerCase(Locale.ENGLISH), value.toString());
  380. return;
  381. }
  382. if (attributeName.indexOf(':') >= 0) {
  383. return; // Ignore attribute from unknown uri's
  384. }
  385. String msg = getElementName(p, element)
  386. + " doesn't support the \"" + attributeName + "\" attribute.";
  387. throw new UnsupportedAttributeException(msg, attributeName);
  388. }
  389. try {
  390. as.setObject(p, element, value);
  391. } catch (IllegalAccessException ie) {
  392. // impossible as getMethods should only return public methods
  393. throw new BuildException(ie);
  394. } catch (InvocationTargetException ite) {
  395. throw extractBuildException(ite);
  396. }
  397. }
  398. /**
  399. * Sets the named attribute in the given element, which is part of the
  400. * given project.
  401. *
  402. * @param p The project containing the element. This is used when files
  403. * need to be resolved. Must not be <code>null</code>.
  404. * @param element The element to set the attribute in. Must not be
  405. * <code>null</code>.
  406. * @param attributeName The name of the attribute to set. Must not be
  407. * <code>null</code>.
  408. * @param value The value to set the attribute to. This may be interpreted
  409. * or converted to the necessary type if the setter method
  410. * doesn't just take a string. Must not be <code>null</code>.
  411. *
  412. * @exception BuildException if the introspected class doesn't support
  413. * the given attribute, or if the setting
  414. * method fails.
  415. */
  416. public void setAttribute(Project p, Object element, String attributeName,
  417. String value) throws BuildException {
  418. setAttribute(p, element, attributeName, (Object) value);
  419. }
  420. /**
  421. * Adds PCDATA to an element, using the element's
  422. * <code>void addText(String)</code> method, if it has one. If no
  423. * such method is present, a BuildException is thrown if the
  424. * given text contains non-whitespace.
  425. *
  426. * @param project The project which the element is part of.
  427. * Must not be <code>null</code>.
  428. * @param element The element to add the text to.
  429. * Must not be <code>null</code>.
  430. * @param text The text to add.
  431. * Must not be <code>null</code>.
  432. *
  433. * @exception BuildException if non-whitespace text is provided and no
  434. * method is available to handle it, or if
  435. * the handling method fails.
  436. */
  437. public void addText(Project project, Object element, String text)
  438. throws BuildException {
  439. if (addText == null) {
  440. text = text.trim();
  441. // Element doesn't handle text content
  442. if (text.length() == 0) {
  443. // Only whitespace - ignore
  444. return;
  445. }
  446. // Not whitespace - fail
  447. throw new BuildException(project.getElementName(element)
  448. + " doesn't support nested text data (\"" + condenseText(text) + "\").");
  449. }
  450. try {
  451. addText.invoke(element, new Object[] {text});
  452. } catch (IllegalAccessException ie) {
  453. // impossible as getMethods should only return public methods
  454. throw new BuildException(ie);
  455. } catch (InvocationTargetException ite) {
  456. throw extractBuildException(ite);
  457. }
  458. }
  459. /**
  460. * part of the error message created by {@link #throwNotSupported
  461. * throwNotSupported}.
  462. * @since Ant 1.8.0
  463. */
  464. protected static final String NOT_SUPPORTED_CHILD_PREFIX =
  465. " doesn't support the nested \"";
  466. /**
  467. * part of the error message created by {@link #throwNotSupported
  468. * throwNotSupported}.
  469. * @since Ant 1.8.0
  470. */
  471. protected static final String NOT_SUPPORTED_CHILD_POSTFIX = "\" element.";
  472. /**
  473. * Utility method to throw a NotSupported exception
  474. *
  475. * @param project the Project instance.
  476. * @param parent the object which doesn't support a requested element
  477. * @param elementName the name of the Element which is trying to be created.
  478. */
  479. public void throwNotSupported(Project project, Object parent, String elementName) {
  480. String msg = project.getElementName(parent)
  481. + NOT_SUPPORTED_CHILD_PREFIX + elementName
  482. + NOT_SUPPORTED_CHILD_POSTFIX;
  483. throw new UnsupportedElementException(msg, elementName);
  484. }
  485. /**
  486. * Get the specific NestedCreator for a given project/parent/element combination
  487. * @param project ant project
  488. * @param parentUri URI of the parent.
  489. * @param parent the parent class
  490. * @param elementName element to work with. This can contain
  491. * a URI,localname tuple of of the form uri:localname
  492. * @param child the bit of XML to work with
  493. * @return a nested creator that can handle the child elements.
  494. * @throws BuildException if the parent does not support child elements of that name
  495. */
  496. private NestedCreator getNestedCreator(
  497. Project project, String parentUri, Object parent,
  498. String elementName, UnknownElement child) throws BuildException {
  499. String uri = ProjectHelper.extractUriFromComponentName(elementName);
  500. String name = ProjectHelper.extractNameFromComponentName(elementName);
  501. if (uri.equals(ProjectHelper.ANT_CORE_URI)) {
  502. uri = "";
  503. }
  504. if (parentUri.equals(ProjectHelper.ANT_CORE_URI)) {
  505. parentUri = "";
  506. }
  507. NestedCreator nc = null;
  508. if (uri.equals(parentUri) || uri.length() == 0) {
  509. nc = (NestedCreator) nestedCreators.get(name.toLowerCase(Locale.ENGLISH));
  510. }
  511. if (nc == null) {
  512. nc = createAddTypeCreator(project, parent, elementName);
  513. }
  514. if (nc == null &&
  515. (parent instanceof DynamicElementNS
  516. || parent instanceof DynamicElement)
  517. ) {
  518. String qName = child == null ? name : child.getQName();
  519. final Object nestedElement =
  520. createDynamicElement(parent,
  521. child == null ? "" : child.getNamespace(),
  522. name, qName);
  523. if (nestedElement != null) {
  524. nc = new NestedCreator(null) {
  525. Object create(Project project, Object parent, Object ignore) {
  526. return nestedElement;
  527. }
  528. };
  529. }
  530. }
  531. if (nc == null) {
  532. throwNotSupported(project, parent, elementName);
  533. }
  534. return nc;
  535. }
  536. /**
  537. * Invokes the "correct" createDynamicElement method on parent in
  538. * order to obtain a child element by name.
  539. *
  540. * @since Ant 1.8.0.
  541. */
  542. private Object createDynamicElement(Object parent, String ns,
  543. String localName, String qName) {
  544. Object nestedElement = null;
  545. if (parent instanceof DynamicElementNS) {
  546. DynamicElementNS dc = (DynamicElementNS) parent;
  547. nestedElement = dc.createDynamicElement(ns, localName, qName);
  548. }
  549. if (nestedElement == null && parent instanceof DynamicElement) {
  550. DynamicElement dc = (DynamicElement) parent;
  551. nestedElement =
  552. dc.createDynamicElement(localName.toLowerCase(Locale.ENGLISH));
  553. }
  554. return nestedElement;
  555. }
  556. /**
  557. * Creates a named nested element. Depending on the results of the
  558. * initial introspection, either a method in the given parent instance
  559. * or a simple no-arg constructor is used to create an instance of the
  560. * specified element type.
  561. *
  562. * @param project Project to which the parent object belongs.
  563. * Must not be <code>null</code>. If the resulting
  564. * object is an instance of ProjectComponent, its
  565. * Project reference is set to this parameter value.
  566. * @param parent Parent object used to create the instance.
  567. * Must not be <code>null</code>.
  568. * @param elementName Name of the element to create an instance of.
  569. * Must not be <code>null</code>.
  570. *
  571. * @return an instance of the specified element type
  572. * @deprecated since 1.6.x.
  573. * This is not a namespace aware method.
  574. *
  575. * @exception BuildException if no method is available to create the
  576. * element instance, or if the creating method fails.
  577. */
  578. public Object createElement(Project project, Object parent, String elementName)
  579. throws BuildException {
  580. NestedCreator nc = getNestedCreator(project, "", parent, elementName, null);
  581. try {
  582. Object nestedElement = nc.create(project, parent, null);
  583. if (project != null) {
  584. project.setProjectReference(nestedElement);
  585. }
  586. return nestedElement;
  587. } catch (IllegalAccessException ie) {
  588. // impossible as getMethods should only return public methods
  589. throw new BuildException(ie);
  590. } catch (InstantiationException ine) {
  591. // impossible as getMethods should only return public methods
  592. throw new BuildException(ine);
  593. } catch (InvocationTargetException ite) {
  594. throw extractBuildException(ite);
  595. }
  596. }
  597. /**
  598. * returns an object that creates and stores an object
  599. * for an element of a parent.
  600. *
  601. * @param project Project to which the parent object belongs.
  602. * @param parentUri The namespace uri of the parent object.
  603. * @param parent Parent object used to create the creator object to
  604. * create and store and instance of a subelement.
  605. * @param elementName Name of the element to create an instance of.
  606. * @param ue The unknown element associated with the element.
  607. * @return a creator object to create and store the element instance.
  608. */
  609. public Creator getElementCreator(
  610. Project project, String parentUri, Object parent, String elementName, UnknownElement ue) {
  611. NestedCreator nc = getNestedCreator(project, parentUri, parent, elementName, ue);
  612. return new Creator(project, parent, nc);
  613. }
  614. /**
  615. * Indicates whether the introspected class is a dynamic one,
  616. * supporting arbitrary nested elements and/or attributes.
  617. *
  618. * @return <code>true<code> if the introspected class is dynamic;
  619. * <code>false<code> otherwise.
  620. * @since Ant 1.6.3
  621. *
  622. * @see DynamicElement
  623. * @see DynamicElementNS
  624. */
  625. public boolean isDynamic() {
  626. return DynamicElement.class.isAssignableFrom(bean)
  627. || DynamicElementNS.class.isAssignableFrom(bean);
  628. }
  629. /**
  630. * Indicates whether the introspected class is a task container,
  631. * supporting arbitrary nested tasks/types.
  632. *
  633. * @return <code>true<code> if the introspected class is a container;
  634. * <code>false<code> otherwise.
  635. * @since Ant 1.6.3
  636. *
  637. * @see TaskContainer
  638. */
  639. public boolean isContainer() {
  640. return TaskContainer.class.isAssignableFrom(bean);
  641. }
  642. /**
  643. * Indicates if this element supports a nested element of the
  644. * given name.
  645. *
  646. * @param elementName the name of the nested element being checked
  647. *
  648. * @return true if the given nested element is supported
  649. */
  650. public boolean supportsNestedElement(String elementName) {
  651. return supportsNestedElement("", elementName);
  652. }
  653. /**
  654. * Indicate if this element supports a nested element of the
  655. * given name.
  656. *
  657. * <p>Note that this method will always return true if the
  658. * introspected class is {@link #isDynamic dynamic} or contains a
  659. * method named "add" with void return type and a single argument.
  660. * To ge a more thorough answer, use the four-arg version of this
  661. * method instead.</p>
  662. *
  663. * @param parentUri the uri of the parent
  664. * @param elementName the name of the nested element being checked
  665. *
  666. * @return true if the given nested element is supported
  667. */
  668. public boolean supportsNestedElement(String parentUri, String elementName) {
  669. if (isDynamic() || addTypeMethods.size() > 0) {
  670. return true;
  671. }
  672. return supportsReflectElement(parentUri, elementName);
  673. }
  674. /**
  675. * Indicate if this element supports a nested element of the
  676. * given name.
  677. *
  678. * <p>Note that this method will always return true if the
  679. * introspected class is {@link #isDynamic dynamic}, so be
  680. * prepared to catch an exception about unsupported children when
  681. * calling {@link #getElementCreator getElementCreator}.</p>
  682. *
  683. * @param parentUri the uri of the parent
  684. * @param elementName the name of the nested element being checked
  685. * @param project currently executing project instance
  686. * @param parent the parent element
  687. *
  688. * @return true if the given nested element is supported
  689. * @since Ant 1.8.0.
  690. */
  691. public boolean supportsNestedElement(String parentUri, String elementName,
  692. Project project, Object parent) {
  693. if (addTypeMethods.size() > 0
  694. && createAddTypeCreator(project, parent, elementName) != null) {
  695. return true;
  696. }
  697. return isDynamic() || supportsReflectElement(parentUri, elementName);
  698. }
  699. /**
  700. * Check if this element supports a nested element from reflection.
  701. *
  702. * @param parentUri the uri of the parent
  703. * @param elementName the name of the nested element being checked
  704. *
  705. * @return true if the given nested element is supported
  706. * @since Ant 1.8.0
  707. */
  708. public boolean supportsReflectElement(
  709. String parentUri, String elementName) {
  710. String name = ProjectHelper.extractNameFromComponentName(elementName);
  711. if (!nestedCreators.containsKey(name.toLowerCase(Locale.ENGLISH))) {
  712. return false;
  713. }
  714. String uri = ProjectHelper.extractUriFromComponentName(elementName);
  715. if (uri.equals(ProjectHelper.ANT_CORE_URI)) {
  716. uri = "";
  717. }
  718. if ("".equals(uri)) {
  719. return true;
  720. }
  721. if (parentUri.equals(ProjectHelper.ANT_CORE_URI)) {
  722. parentUri = "";
  723. }
  724. return uri.equals(parentUri);
  725. }
  726. /**
  727. * Stores a named nested element using a storage method determined
  728. * by the initial introspection. If no appropriate storage method
  729. * is available, this method returns immediately.
  730. *
  731. * @param project Ignored in this implementation.
  732. * May be <code>null</code>.
  733. *
  734. * @param parent Parent instance to store the child in.
  735. * Must not be <code>null</code>.
  736. *
  737. * @param child Child instance to store in the parent.
  738. * Should not be <code>null</code>.
  739. *
  740. * @param elementName Name of the child element to store.
  741. * May be <code>null</code>, in which case
  742. * this method returns immediately.
  743. *
  744. * @exception BuildException if the storage method fails.
  745. */
  746. public void storeElement(Project project, Object parent, Object child,
  747. String elementName) throws BuildException {
  748. if (elementName == null) {
  749. return;
  750. }
  751. NestedCreator ns = (NestedCreator) nestedCreators.get(elementName.toLowerCase(Locale.ENGLISH));
  752. if (ns == null) {
  753. return;
  754. }
  755. try {
  756. ns.store(parent, child);
  757. } catch (IllegalAccessException ie) {
  758. // impossible as getMethods should only return public methods
  759. throw new BuildException(ie);
  760. } catch (InstantiationException ine) {
  761. // impossible as getMethods should only return public methods
  762. throw new BuildException(ine);
  763. } catch (InvocationTargetException ite) {
  764. throw extractBuildException(ite);
  765. }
  766. }
  767. /**
  768. * Helper method to extract the inner fault from an {@link InvocationTargetException}, and turn
  769. * it into a BuildException. If it is already a BuildException, it is type cast and returned; if
  770. * not a new BuildException is created containing the child as nested text.
  771. * @param ite
  772. * @return the nested exception
  773. */
  774. private static BuildException extractBuildException(InvocationTargetException ite) {
  775. Throwable t = ite.getTargetException();
  776. if (t instanceof BuildException) {
  777. return (BuildException) t;
  778. }
  779. return new BuildException(t);
  780. }
  781. /**
  782. * Returns the type of a named nested element.
  783. *
  784. * @param elementName The name of the element to find the type of.
  785. * Must not be <code>null</code>.
  786. *
  787. * @return the type of the nested element with the specified name.
  788. * This will never be <code>null</code>.
  789. *
  790. * @exception BuildException if the introspected class does not
  791. * support the named nested element.
  792. */
  793. public Class getElementType(String elementName) throws BuildException {
  794. Class nt = (Class) nestedTypes.get(elementName);
  795. if (nt == null) {
  796. throw new UnsupportedElementException("Class "
  797. + bean.getName() + " doesn't support the nested \""
  798. + elementName + "\" element.", elementName);
  799. }
  800. return nt;
  801. }
  802. /**
  803. * Returns the type of a named attribute.
  804. *
  805. * @param attributeName The name of the attribute to find the type of.
  806. * Must not be <code>null</code>.
  807. *
  808. * @return the type of the attribute with the specified name.
  809. * This will never be <code>null</code>.
  810. *
  811. * @exception BuildException if the introspected class does not
  812. * support the named attribute.
  813. */
  814. public Class getAttributeType(String attributeName) throws BuildException {
  815. Class at = (Class) attributeTypes.get(attributeName);
  816. if (at == null) {
  817. throw new UnsupportedAttributeException("Class "
  818. + bean.getName() + " doesn't support the \""
  819. + attributeName + "\" attribute.", attributeName);
  820. }
  821. return at;
  822. }
  823. /**
  824. * Returns the addText method when the introspected
  825. * class supports nested text.
  826. *
  827. * @return the method on this introspected class that adds nested text.
  828. * Cannot be <code>null</code>.
  829. * @throws BuildException if the introspected class does not
  830. * support the nested text.
  831. * @since Ant 1.6.3
  832. */
  833. public Method getAddTextMethod() throws BuildException {
  834. if (!supportsCharacters()) {
  835. throw new BuildException("Class " + bean.getName()
  836. + " doesn't support nested text data.");
  837. }
  838. return addText;
  839. }
  840. /**
  841. * Returns the adder or creator method of a named nested element.
  842. *
  843. * @param elementName The name of the attribute to find the setter
  844. * method of. Must not be <code>null</code>.
  845. * @return the method on this introspected class that adds or creates this
  846. * nested element. Can be <code>null</code> when the introspected
  847. * class is a dynamic configurator!
  848. * @throws BuildException if the introspected class does not
  849. * support the named nested element.
  850. * @since Ant 1.6.3
  851. */
  852. public Method getElementMethod(String elementName) throws BuildException {
  853. Object creator = nestedCreators.get(elementName);
  854. if (creator == null) {
  855. throw new UnsupportedElementException("Class "
  856. + bean.getName() + " doesn't support the nested \""
  857. + elementName + "\" element.", elementName);
  858. }
  859. return ((NestedCreator) creator).method;
  860. }
  861. /**
  862. * Returns the setter method of a named attribute.
  863. *
  864. * @param attributeName The name of the attribute to find the setter
  865. * method of. Must not be <code>null</code>.
  866. * @return the method on this introspected class that sets this attribute.
  867. * This will never be <code>null</code>.
  868. * @throws BuildException if the introspected class does not
  869. * support the named attribute.
  870. * @since Ant 1.6.3
  871. */
  872. public Method getAttributeMethod(String attributeName) throws BuildException {
  873. Object setter = attributeSetters.get(attributeName);
  874. if (setter == null) {
  875. throw new UnsupportedAttributeException("Class "
  876. + bean.getName() + " doesn't support the \""
  877. + attributeName + "\" attribute.", attributeName);
  878. }
  879. return ((AttributeSetter) setter).method;
  880. }
  881. /**
  882. * Returns whether or not the introspected class supports PCDATA.
  883. *
  884. * @return whether or not the introspected class supports PCDATA.
  885. */
  886. public boolean supportsCharacters() {
  887. return addText != null;
  888. }
  889. /**
  890. * Returns an enumeration of the names of the attributes supported by the introspected class.
  891. *
  892. * @return an enumeration of the names of the attributes supported by the introspected class.
  893. * @see #getAttributeMap
  894. */
  895. public Enumeration getAttributes() {
  896. return attributeSetters.keys();
  897. }
  898. /**
  899. * Returns a read-only map of attributes supported by the introspected class.
  900. *
  901. * @return an attribute name to attribute <code>Class</code>
  902. * unmodifiable map. Can be empty, but never <code>null</code>.
  903. * @since Ant 1.6.3
  904. */
  905. public Map getAttributeMap() {
  906. return attributeTypes.isEmpty()
  907. ? Collections.EMPTY_MAP : Collections.unmodifiableMap(attributeTypes);
  908. }
  909. /**
  910. * Returns an enumeration of the names of the nested elements supported
  911. * by the introspected class.
  912. *
  913. * @return an enumeration of the names of the nested elements supported
  914. * by the introspected class.
  915. * @see #getNestedElementMap
  916. */
  917. public Enumeration getNestedElements() {
  918. return nestedTypes.keys();
  919. }
  920. /**
  921. * Returns a read-only map of nested elements supported
  922. * by the introspected class.
  923. *
  924. * @return a nested-element name to nested-element <code>Class</code>
  925. * unmodifiable map. Can be empty, but never <code>null</code>.
  926. * @since Ant 1.6.3
  927. */
  928. public Map getNestedElementMap() {
  929. return nestedTypes.isEmpty()
  930. ? Collections.EMPTY_MAP : Collections.unmodifiableMap(nestedTypes);
  931. }
  932. /**
  933. * Returns a read-only list of extension points supported
  934. * by the introspected class.
  935. * <p>
  936. * A task/type or nested element with void methods named <code>add()<code>
  937. * or <code>addConfigured()</code>, taking a single class or interface
  938. * argument, supports extensions point. This method returns the list of
  939. * all these <em>void add[Configured](type)</em> methods.
  940. *
  941. * @return a list of void, single argument add() or addConfigured()
  942. * <code>Method<code>s of all supported extension points.
  943. * These methods are sorted such that if the argument type of a
  944. * method derives from another type also an argument of a method
  945. * of this list, the method with the most derived argument will
  946. * always appear first. Can be empty, but never <code>null</code>.
  947. * @since Ant 1.6.3
  948. */
  949. public List getExtensionPoints() {
  950. return addTypeMethods.isEmpty()
  951. ? Collections.EMPTY_LIST : Collections.unmodifiableList(addTypeMethods);
  952. }
  953. /**
  954. * Creates an implementation of AttributeSetter for the given
  955. * attribute type. Conversions (where necessary) are automatically
  956. * made for the following types:
  957. * <ul>
  958. * <li>String (left as it is)
  959. * <li>Character/char (first character is used)
  960. * <li>Boolean/boolean
  961. * ({@link Project#toBoolean(String) Project.toBoolean(String)} is used)
  962. * <li>Class (Class.forName is used)
  963. * <li>File (resolved relative to the appropriate project)
  964. * <li>Path (resolve relative to the appropriate project)
  965. * <li>Resource (resolved as a FileResource relative to the appropriate project)
  966. * <li>FileProvider (resolved as a FileResource relative to the appropriate project)
  967. * <li>EnumeratedAttribute (uses its own
  968. * {@link EnumeratedAttribute#setValue(String) setValue} method)
  969. * <li>Other primitive types (wrapper classes are used with constructors
  970. * taking String)
  971. * </ul>
  972. *
  973. * If none of the above covers the given parameters, a constructor for the
  974. * appropriate class taking a String parameter is used if it is available.
  975. *
  976. * @param m The method to invoke on the bean when the setter is invoked.
  977. * Must not be <code>null</code>.
  978. * @param arg The type of the single argument of the bean's method.
  979. * Must not be <code>null</code>.
  980. * @param attrName the name of the attribute for which the setter is being
  981. * created.
  982. *
  983. * @return an appropriate AttributeSetter instance, or <code>null</code>
  984. * if no appropriate conversion is available.
  985. */
  986. private AttributeSetter createAttributeSetter(final Method m,
  987. Class arg,
  988. final String attrName) {
  989. // use wrappers for primitive classes, e.g. int and
  990. // Integer are treated identically
  991. final Class reflectedArg = PRIMITIVE_TYPE_MAP.containsKey(arg)
  992. ? (Class) PRIMITIVE_TYPE_MAP.get(arg) : arg;
  993. // Object.class - it gets handled differently by AttributeSetter
  994. if (java.lang.Object.class == reflectedArg) {
  995. return new AttributeSetter(m, arg) {
  996. public void set(Project p, Object parent, String value)
  997. throws InvocationTargetException,
  998. IllegalAccessException {
  999. throw new BuildException(
  1000. "Internal ant problem - this should not get called");
  1001. }
  1002. };
  1003. }
  1004. // simplest case - setAttribute expects String
  1005. if (java.lang.String.class.equals(reflectedArg)) {
  1006. return new AttributeSetter(m, arg) {
  1007. public void set(Project p, Object parent, String value)
  1008. throws InvocationTargetException, IllegalAccessException {
  1009. m.invoke(parent, (Object[]) new String[] {value});
  1010. }
  1011. };
  1012. }
  1013. // char and Character get special treatment - take the first character
  1014. if (java.lang.Character.class.equals(reflectedArg)) {
  1015. return new AttributeSetter(m, arg) {
  1016. public void set(Project p, Object parent, String value)
  1017. throws InvocationTargetException, IllegalAccessException {
  1018. if (value.length() == 0) {
  1019. throw new BuildException("The value \"\" is not a "
  1020. + "legal value for attribute \"" + attrName + "\"");
  1021. }
  1022. m.invoke(parent, (Object[]) new Character[] {new Character(value.charAt(0))});
  1023. }
  1024. };
  1025. }
  1026. // boolean and Boolean get special treatment because we have a nice method in Project
  1027. if (java.lang.Boolean.class.equals(reflectedArg)) {
  1028. return new AttributeSetter(m, arg) {
  1029. public void set(Project p, Object parent, String value)
  1030. throws InvocationTargetException, IllegalAccessException {
  1031. m.invoke(parent, (Object[]) new Boolean[] {
  1032. Project.toBoolean(value) ? Boolean.TRUE : Boolean.FALSE });
  1033. }
  1034. };
  1035. }
  1036. // Class doesn't have a String constructor but a decent factory method
  1037. if (java.lang.Class.class.equals(reflectedArg)) {
  1038. return new AttributeSetter(m, arg) {
  1039. public void set(Project p, Object parent, String value)
  1040. throws InvocationTargetException, IllegalAccessException, BuildException {
  1041. try {
  1042. m.invoke(parent, new Object[] {Class.forName(value)});
  1043. } catch (ClassNotFoundException ce) {
  1044. throw new BuildException(ce);
  1045. }
  1046. }
  1047. };
  1048. }
  1049. // resolve relative paths through Project
  1050. if (java.io.File.class.equals(reflectedArg)) {
  1051. return new AttributeSetter(m, arg) {
  1052. public void set(Project p, Object parent, String value)
  1053. throws InvocationTargetException, IllegalAccessException {
  1054. m.invoke(parent, new Object[] {p.resolveFile(value)});
  1055. }
  1056. };
  1057. }
  1058. // resolve Resources/FileProviders as FileResources relative to Project:
  1059. if (Resource.class.equals(reflectedArg) || FileProvider.class.equals(reflectedArg)) {
  1060. return new AttributeSetter(m, arg) {
  1061. void set(Project p, Object parent, String value) throws InvocationTargetException,
  1062. IllegalAccessException, BuildException {
  1063. m.invoke(parent, new Object[] { new FileResource(p, p.resolveFile(value)) });
  1064. };
  1065. };
  1066. }
  1067. // EnumeratedAttributes have their own helper class
  1068. if (EnumeratedAttribute.class.isAssignableFrom(reflectedArg)) {
  1069. return new AttributeSetter(m, arg) {
  1070. public void set(Project p, Object parent, String value)
  1071. throws InvocationTargetException, IllegalAccessException, BuildException {
  1072. try {
  1073. EnumeratedAttribute ea = (EnumeratedAttribute) reflectedArg.newInstance();
  1074. ea.setValue(value);
  1075. m.invoke(parent, new Object[] {ea});
  1076. } catch (InstantiationException ie) {
  1077. throw new BuildException(ie);
  1078. }
  1079. }
  1080. };
  1081. }
  1082. AttributeSetter setter = getEnumSetter(reflectedArg, m, arg);
  1083. if (setter != null) {
  1084. return setter;
  1085. }
  1086. if (java.lang.Long.class.equals(reflectedArg)) {
  1087. return new AttributeSetter(m, arg) {
  1088. public void set(Project p, Object parent, String value)
  1089. throws InvocationTargetException, IllegalAccessException, BuildException {
  1090. try {
  1091. m.invoke(parent, new Object[] {
  1092. new Long(StringUtils.parseHumanSizes(value)) });
  1093. } catch (NumberFormatException e) {
  1094. throw new BuildException("Can't assign non-numeric"
  1095. + " value '" + value + "' to"
  1096. + " attribute " + attrName);
  1097. } catch (InvocationTargetException e) {
  1098. throw e;
  1099. } catch (IllegalAccessException e) {
  1100. throw e;
  1101. } catch (Exception e) {
  1102. throw new BuildException(e);
  1103. }
  1104. }
  1105. };
  1106. }
  1107. // worst case. look for a public String constructor and use it
  1108. // also supports new Whatever(Project, String) as for Path or Reference
  1109. // This is used (deliberately) for all primitives/wrappers other than
  1110. // char, boolean, and long.
  1111. boolean includeProject;
  1112. Constructor c;
  1113. try {
  1114. // First try with Project.
  1115. c = reflectedArg.getConstructor(new Class[] {Project.class, String.class});
  1116. includeProject = true;
  1117. } catch (NoSuchMethodException nme) {
  1118. // OK, try without.
  1119. try {
  1120. c = reflectedArg.getConstructor(new Class[] {String.class});
  1121. includeProject = false;
  1122. } catch (NoSuchMethodException nme2) {
  1123. // Well, no matching constructor.
  1124. return null;
  1125. }
  1126. }
  1127. final boolean finalIncludeProject = includeProject;
  1128. final Constructor finalConstructor = c;
  1129. return new AttributeSetter(m, arg) {
  1130. public void set(Project p, Object parent, String value)
  1131. throws InvocationTargetException, IllegalAccessException, BuildException {
  1132. try {
  1133. Object[] args = finalIncludeProject
  1134. ? new Object[] {p, value} : new Object[] {value};
  1135. Object attribute = finalConstructor.newInstance(args);
  1136. if (p != null) {
  1137. p.setProjectReference(attribute);
  1138. }
  1139. m.invoke(parent, new Object[] {attribute});
  1140. } catch (InvocationTargetException e) {
  1141. Throwable cause = e.getCause();
  1142. if (cause instanceof IllegalArgumentException) {
  1143. throw new BuildException("Can't assign value '" + value
  1144. + "' to attribute " + attrName
  1145. + ", reason: "
  1146. + cause.getClass()
  1147. + " with message '"
  1148. + cause.getMessage() + "'");
  1149. }
  1150. throw e;
  1151. } catch (InstantiationException ie) {
  1152. throw new BuildException(ie);
  1153. }
  1154. }
  1155. };
  1156. }
  1157. private AttributeSetter getEnumSetter(
  1158. final Class reflectedArg, final Method m, Class arg) {
  1159. Class enumClass = null;
  1160. try {
  1161. enumClass = Class.forName("java.lang.Enum");
  1162. } catch (ClassNotFoundException e) {
  1163. //ignore
  1164. }
  1165. if (enumClass != null && enumClass.isAssignableFrom(reflectedArg)) {
  1166. return new AttributeSetter(m, arg) {
  1167. public void set(Project p, Object parent, String value)
  1168. throws InvocationTargetException, IllegalAccessException,
  1169. BuildException {
  1170. try {
  1171. m.invoke(
  1172. parent, new Object[] {
  1173. reflectedArg.getMethod(
  1174. "valueOf", new Class[] {String.class}).
  1175. invoke(null, new Object[] {value})});
  1176. } catch (InvocationTargetException x) {
  1177. //there is specific logic here for the value
  1178. // being out of the allowed set of enumerations.
  1179. if (x.getTargetException() instanceof IllegalArgumentException) {
  1180. throw new BuildException(
  1181. "'" + value + "' is not a permitted value for "
  1182. + reflectedArg.getName());
  1183. }
  1184. //only if the exception is not an IllegalArgument do we
  1185. // request the
  1186. //BuildException via extractBuildException():
  1187. throw extractBuildException(x);
  1188. } catch (Exception x) {
  1189. //any other failure of invoke() to work.
  1190. throw new BuildException(x);
  1191. }
  1192. }
  1193. };
  1194. }
  1195. return null;
  1196. }
  1197. /**
  1198. * Returns a description of the type of the given element in
  1199. * relation to a given project. This is used for logging purposes
  1200. * when the element is asked to cope with some data it has no way of handling.
  1201. *
  1202. * @param project The project the element is defined in. Must not be <code>null</code>.
  1203. *
  1204. * @param element The element to describe. Must not be <code>null</code>.
  1205. *
  1206. * @return a description of the element type
  1207. */
  1208. private String getElementName(Project project, Object element) {
  1209. return project.getElementName(element);
  1210. }
  1211. /**
  1212. * Extracts the name of a property from a method name by subtracting
  1213. * a given prefix and converting into lower case. It is up to calling
  1214. * code to make sure the method name does actually begin with the
  1215. * specified prefix - no checking is done in this method.
  1216. *
  1217. * @param methodName The name of the method in question. Must not be <code>null</code>.
  1218. * @param prefix The prefix to remove. Must not be <code>null</code>.
  1219. *
  1220. * @return the lower-cased method name with the prefix removed.
  1221. */
  1222. private static String getPropertyName(String methodName, String prefix) {
  1223. return methodName.substring(prefix.length()).toLowerCase(Locale.ENGLISH);
  1224. }
  1225. /**
  1226. * creator - allows use of create/store external
  1227. * to IntrospectionHelper.
  1228. * The class is final as it has a private constructor.
  1229. */
  1230. public static final class Creator {
  1231. private NestedCreator nestedCreator;
  1232. private Object parent;
  1233. private Project project;
  1234. private Object nestedObject;
  1235. private String polyType;
  1236. /**
  1237. * Creates a new Creator instance.
  1238. * This object is given to the UnknownElement to create
  1239. * objects for sub-elements. UnknownElement calls
  1240. * create to create an object, the object then gets
  1241. * configured and then UnknownElement calls store.
  1242. * SetPolyType may be used to override the type used
  1243. * to create the object with. SetPolyType gets called before create.
  1244. *
  1245. * @param project the current project
  1246. * @param parent the parent object to create the object in
  1247. * @param nestedCreator the nested creator object to use
  1248. */
  1249. private Creator(Project project, Object parent, NestedCreator nestedCreator) {
  1250. this.project = project;
  1251. this.parent = parent;
  1252. this.nestedCreator = nestedCreator;
  1253. }
  1254. /**
  1255. * Used to override the class used to create the object.
  1256. *
  1257. * @param polyType a ant component type name
  1258. */
  1259. public void setPolyType(String polyType) {
  1260. this.polyType = polyType;
  1261. }
  1262. /**
  1263. * Create an object using this creator, which is determined by introspection.
  1264. *
  1265. * @return the created object
  1266. */
  1267. public Object create() {
  1268. if (polyType != null) {
  1269. if (!nestedCreator.isPolyMorphic()) {
  1270. throw new BuildException(
  1271. "Not allowed to use the polymorphic form for this element");
  1272. }
  1273. ComponentHelper helper = ComponentHelper.getComponentHelper(project);
  1274. nestedObject = helper.createComponent(polyType);
  1275. if (nestedObject == null) {
  1276. throw new BuildException("Unable to create object of type " + polyType);
  1277. }
  1278. }
  1279. try {
  1280. nestedObject = nestedCreator.create(project, parent, nestedObject);
  1281. if (project != null) {
  1282. project.setProjectReference(nestedObject);
  1283. }
  1284. return nestedObject;
  1285. } catch (IllegalAccessException ex) {
  1286. throw new BuildException(ex);
  1287. } catch (InstantiationException ex) {
  1288. throw new BuildException(ex);
  1289. } catch (IllegalArgumentException ex) {
  1290. if (polyType == null) {
  1291. throw ex;
  1292. }
  1293. throw new BuildException("Invalid type used " + polyType);
  1294. } catch (InvocationTargetException ex) {
  1295. throw extractBuildException(ex);
  1296. }
  1297. }
  1298. /**
  1299. * @return the real object (used currently only for presetdef).
  1300. */
  1301. public Object getRealObject() {
  1302. return nestedCreator.getRealObject();
  1303. }
  1304. /**
  1305. * Stores the nested element object using a storage method determined by introspection.
  1306. *
  1307. */
  1308. public void store() {
  1309. try {
  1310. nestedCreator.store(parent, nestedObject);
  1311. } catch (IllegalAccessException ex) {
  1312. throw new BuildException(ex);
  1313. } catch (InstantiationException ex) {
  1314. throw new BuildException(ex);
  1315. } catch (IllegalArgumentException ex) {
  1316. if (polyType == null) {
  1317. throw ex;
  1318. }
  1319. throw new BuildException("Invalid type used " + polyType);
  1320. } catch (InvocationTargetException ex) {
  1321. throw extractBuildException(ex);
  1322. }
  1323. }
  1324. }
  1325. /**
  1326. * Internal interface used to create nested elements. Not documented
  1327. * in detail for reasons of source code readability.
  1328. */
  1329. private abstract static class NestedCreator {
  1330. private Method method; // the method called to add/create the nested element
  1331. protected NestedCreator(Method m) {
  1332. method = m;
  1333. }
  1334. Method getMethod() {
  1335. return method;
  1336. }
  1337. boolean isPolyMorphic() {
  1338. return false;
  1339. }
  1340. Object getRealObject() {
  1341. return null;
  1342. }
  1343. abstract Object create(Project project, Object parent, Object child)
  1344. throws InvocationTargetException, IllegalAccessException, InstantiationException;
  1345. void store(Object parent, Object child)
  1346. throws InvocationTargetException, IllegalAccessException, InstantiationException {
  1347. // DO NOTHING
  1348. }
  1349. }
  1350. private static class CreateNestedCreator extends NestedCreator {
  1351. CreateNestedCreator(Method m) {
  1352. super(m);
  1353. }
  1354. Object create(Project project, Object parent, Object ignore)
  1355. throws InvocationTargetException, IllegalAccessException {
  1356. return getMethod().invoke(parent, new Object[] {});
  1357. }
  1358. }
  1359. /** Version to use for addXXX and addConfiguredXXX */
  1360. private static class AddNestedCreator extends NestedCreator {
  1361. static final int ADD = 1;
  1362. static final int ADD_CONFIGURED = 2;
  1363. private Constructor constructor;
  1364. private int behavior; // ADD or ADD_CONFIGURED
  1365. AddNestedCreator(Method m, Constructor c, int behavior) {
  1366. super(m);
  1367. this.constructor = c;
  1368. this.behavior = behavior;
  1369. }
  1370. boolean isPolyMorphic() {
  1371. return true;
  1372. }
  1373. Object create(Project project, Object parent, Object child)
  1374. throws InvocationTargetException, IllegalAccessException, InstantiationException {
  1375. if (child == null) {
  1376. child = constructor.newInstance(
  1377. constructor.getParameterTypes().length == 0
  1378. ? new Object[] {} : new Object[] {project});
  1379. }
  1380. if (child instanceof PreSetDef.PreSetDefinition) {
  1381. child = ((PreSetDef.PreSetDefinition) child).createObject(project);
  1382. }
  1383. if (behavior == ADD) {
  1384. istore(parent, child);
  1385. }
  1386. return child;
  1387. }
  1388. void store(Object parent, Object child)
  1389. throws InvocationTargetException, IllegalAccessException, InstantiationException {
  1390. if (behavior == ADD_CONFIGURED) {
  1391. istore(parent, child);
  1392. }
  1393. }
  1394. private void istore(Object parent, Object child)
  1395. throws InvocationTargetException, IllegalAccessException, InstantiationException {
  1396. getMethod().invoke(parent, new Object[] {child});
  1397. }
  1398. }
  1399. /**
  1400. * Internal interface used to setting element attributes. Not documented
  1401. * in detail for reasons of source code readability.
  1402. */
  1403. private abstract static class AttributeSetter {
  1404. private Method method; // the method called to set the attribute
  1405. private Class type;
  1406. protected AttributeSetter(Method m, Class type) {
  1407. method = m;
  1408. this.type = type;
  1409. }
  1410. void setObject(Project p, Object parent, Object value)
  1411. throws InvocationTargetException, IllegalAccessException, BuildException {
  1412. if (type != null) {
  1413. Class useType = type;
  1414. if (type.isPrimitive()) {
  1415. if (value == null) {
  1416. throw new BuildException(
  1417. "Attempt to set primitive "
  1418. + getPropertyName(method.getName(), "set")
  1419. + " to null on " + parent);
  1420. }
  1421. useType = (Class) PRIMITIVE_TYPE_MAP.get(type);
  1422. }
  1423. if (value == null || useType.isInstance(value)) {
  1424. method.invoke(parent, new Object[] {value});
  1425. return;
  1426. }
  1427. }
  1428. set(p, parent, value.toString());
  1429. }
  1430. abstract void set(Project p, Object parent, String value)
  1431. throws InvocationTargetException, IllegalAccessException, BuildException;
  1432. }
  1433. /**
  1434. * Clears the static cache of on build finished.
  1435. */
  1436. public static void clearCache() {
  1437. HELPERS.clear();
  1438. }
  1439. /**
  1440. * Create a NestedCreator for the given element.
  1441. * @param project owning project
  1442. * @param parent Parent object used to create the instance.
  1443. * @param elementName name of the element
  1444. * @return a nested creator, or null if there is no component of the given name, or it
  1445. * has no matching add type methods
  1446. * @throws BuildException
  1447. */
  1448. private NestedCreator createAddTypeCreator(
  1449. Project project, Object parent, String elementName) throws BuildException {
  1450. if (addTypeMethods.size() == 0) {
  1451. return null;
  1452. }
  1453. ComponentHelper helper = ComponentHelper.getComponentHelper(project);
  1454. MethodAndObject restricted = createRestricted(
  1455. helper, elementName, addTypeMethods);
  1456. MethodAndObject topLevel = createTopLevel(
  1457. helper, elementName, addTypeMethods);
  1458. if (restricted == null && topLevel == null) {
  1459. return null;
  1460. }
  1461. if (restricted != null && topLevel != null) {
  1462. throw new BuildException(
  1463. "ambiguous: type and component definitions for "
  1464. + elementName);
  1465. }
  1466. MethodAndObject methodAndObject
  1467. = restricted != null ? restricted : topLevel;
  1468. Object rObject = methodAndObject.object;
  1469. if (methodAndObject.object instanceof PreSetDef.PreSetDefinition) {
  1470. rObject = ((PreSetDef.PreSetDefinition) methodAndObject.object)
  1471. .createObject(project);
  1472. }
  1473. final Object nestedObject = methodAndObject.object;
  1474. final Object realObject = rObject;
  1475. return new NestedCreator(methodAndObject.method) {
  1476. Object create(Project project, Object parent, Object ignore)
  1477. throws InvocationTargetException, IllegalAccessException {
  1478. if (!getMethod().getName().endsWith("Configured")) {
  1479. getMethod().invoke(parent, new Object[] {realObject});
  1480. }
  1481. return nestedObject;
  1482. }
  1483. Object getRealObject() {
  1484. return realObject;
  1485. }
  1486. void store(Object parent, Object child) throws InvocationTargetException,
  1487. IllegalAccessException, InstantiationException {
  1488. if (getMethod().getName().endsWith("Configured")) {
  1489. getMethod().invoke(parent, new Object[] {realObject});
  1490. }
  1491. }
  1492. };
  1493. }
  1494. /**
  1495. * Inserts an add or addConfigured method into
  1496. * the addTypeMethods array. The array is
  1497. * ordered so that the more derived classes are first.
  1498. * If both add and addConfigured are present, the addConfigured will take priority.
  1499. * @param method the <code>Method</code> to insert.
  1500. */
  1501. private void insertAddTypeMethod(Method method) {
  1502. Class argClass = method.getParameterTypes()[0];
  1503. final int size = addTypeMethods.size();
  1504. for (int c = 0; c < size; ++c) {
  1505. Method current = (Method) addTypeMethods.get(c);
  1506. if (current.getParameterTypes()[0].equals(argClass)) {
  1507. if (method.getName().equals("addConfigured")) {
  1508. // add configured replaces the add method
  1509. addTypeMethods.set(c, method);
  1510. }
  1511. return; // Already present
  1512. }
  1513. if (current.getParameterTypes()[0].isAssignableFrom(argClass)) {
  1514. addTypeMethods.add(c, method);
  1515. return; // higher derived
  1516. }
  1517. }
  1518. addTypeMethods.add(method);
  1519. }
  1520. /**
  1521. * Search the list of methods to find the first method
  1522. * that has a parameter that accepts the nested element object.
  1523. * @param paramClass the <code>Class</code> type to search for.
  1524. * @param methods the <code>List</code> of methods to search.
  1525. * @return a matching <code>Method</code>; null if none found.
  1526. */
  1527. private Method findMatchingMethod(Class paramClass, List methods) {
  1528. if (paramClass == null) {
  1529. return null;
  1530. }
  1531. Class matchedClass = null;
  1532. Method matchedMethod = null;
  1533. final int size = methods.size();
  1534. for (int i = 0; i < size; ++i) {
  1535. Method method = (Method) methods.get(i);
  1536. Class methodClass = method.getParameterTypes()[0];
  1537. if (methodClass.isAssignableFrom(paramClass)) {
  1538. if (matchedClass == null) {
  1539. matchedClass = methodClass;
  1540. matchedMethod = method;
  1541. } else if (!methodClass.isAssignableFrom(matchedClass)) {
  1542. throw new BuildException("ambiguous: types " + matchedClass.getName() + " and "
  1543. + methodClass.getName() + " match " + paramClass.getName());
  1544. }
  1545. }
  1546. }
  1547. return matchedMethod;
  1548. }
  1549. private String condenseText(final String text) {
  1550. if (text.length() <= MAX_REPORT_NESTED_TEXT) {
  1551. return text;
  1552. }
  1553. int ends = (MAX_REPORT_NESTED_TEXT - ELLIPSIS.length()) / 2;
  1554. return new StringBuffer(text).replace(ends, text.length() - ends, ELLIPSIS).toString();
  1555. }
  1556. private static class MethodAndObject {
  1557. private Method method;
  1558. private Object object;
  1559. public MethodAndObject(Method method, Object object) {
  1560. this.method = method;
  1561. this.object = object;
  1562. }
  1563. }
  1564. /**
  1565. *
  1566. */
  1567. private AntTypeDefinition findRestrictedDefinition(
  1568. ComponentHelper helper, String componentName, List methods) {
  1569. AntTypeDefinition definition = null;
  1570. Class matchedDefinitionClass = null;
  1571. List definitions = helper.getRestrictedDefinitions(componentName);
  1572. if (definitions == null) {
  1573. return null;
  1574. }
  1575. synchronized (definitions) {
  1576. final int size = definitions.size();
  1577. for (int i = 0; i < size; ++i) {
  1578. AntTypeDefinition d = (AntTypeDefinition) definitions.get(i);
  1579. Class exposedClass = d.getExposedClass(helper.getProject());
  1580. if (exposedClass == null) {
  1581. continue;
  1582. }
  1583. Method method = findMatchingMethod(exposedClass, methods);
  1584. if (method == null) {
  1585. continue;
  1586. }
  1587. if (matchedDefinitionClass != null) {
  1588. throw new BuildException(
  1589. "ambiguous: restricted definitions for "
  1590. + componentName + " "
  1591. + matchedDefinitionClass + " and " + exposedClass);
  1592. }
  1593. matchedDefinitionClass = exposedClass;
  1594. definition = d;
  1595. }
  1596. }
  1597. return definition;
  1598. }
  1599. private MethodAndObject createRestricted(
  1600. ComponentHelper helper, String elementName, List addTypeMethods) {
  1601. Project project = helper.getProject();
  1602. AntTypeDefinition restrictedDefinition =
  1603. findRestrictedDefinition(helper, elementName, addTypeMethods);
  1604. if (restrictedDefinition == null) {
  1605. return null;
  1606. }
  1607. Method addMethod = findMatchingMethod(
  1608. restrictedDefinition.getExposedClass(project), addTypeMethods);
  1609. if (addMethod == null) {
  1610. throw new BuildException(
  1611. "Ant Internal Error - contract mismatch for "
  1612. + elementName);
  1613. }
  1614. Object addedObject = restrictedDefinition.create(project);
  1615. if (addedObject == null) {
  1616. throw new BuildException(
  1617. "Failed to create object " + elementName
  1618. + " of type " + restrictedDefinition.getTypeClass(project));
  1619. }
  1620. return new MethodAndObject(addMethod, addedObject);
  1621. }
  1622. private MethodAndObject createTopLevel(
  1623. ComponentHelper helper, String elementName, List methods) {
  1624. Class clazz = helper.getComponentClass(elementName);
  1625. if (clazz == null) {
  1626. return null;
  1627. }
  1628. Method addMethod = findMatchingMethod(clazz, addTypeMethods);
  1629. if (addMethod == null) {
  1630. return null;
  1631. }
  1632. Object addedObject = helper.createComponent(elementName);
  1633. return new MethodAndObject(addMethod, addedObject);
  1634. }
  1635. }