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