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