diff --git a/src/main/org/apache/tools/ant/IntrospectionHelper.java b/src/main/org/apache/tools/ant/IntrospectionHelper.java index a4dec726f..8ef8da741 100644 --- a/src/main/org/apache/tools/ant/IntrospectionHelper.java +++ b/src/main/org/apache/tools/ant/IntrospectionHelper.java @@ -385,6 +385,30 @@ public class IntrospectionHelper implements BuildListener { return ih; } + /** + * Returns a helper for the given class, either from the cache + * or by creating a new instance. + * + * The method will make sure the helper will be cleaned up at the end of + * the project, and only one instance will be created for each class. + * + * @param c The class for which a helper is required. + * Must not be null. + * + * @return a helper for the specified class + */ + public static synchronized IntrospectionHelper getHelper(Project p, Class c) + { + IntrospectionHelper ih = (IntrospectionHelper) helpers.get(c); + if (ih == null) { + ih = new IntrospectionHelper(c); + helpers.put(c, ih); + // Cleanup at end of project + p.addBuildListener(ih); + } + return ih; + } + /** * Sets the named attribute in the given element, which is part of the * given project.