diff --git a/src/main/org/apache/tools/ant/ComponentHelper.java b/src/main/org/apache/tools/ant/ComponentHelper.java index 355e11aa2..8588c918b 100644 --- a/src/main/org/apache/tools/ant/ComponentHelper.java +++ b/src/main/org/apache/tools/ant/ComponentHelper.java @@ -579,7 +579,7 @@ public class ComponentHelper { */ public static String getElementName(Project p, Object o, boolean brief) { if (p == null) { - p = getProject(o); + p = Project.getProject(o); } return p == null ? getUnmappedElementName(o.getClass(), brief) : getComponentHelper(p).getElementName(o, brief); @@ -593,21 +593,6 @@ public class ComponentHelper { return c.toString(); } - private static Project getProject(Object o) { - if (o instanceof ProjectComponent) { - return ((ProjectComponent) o).getProject(); - } - try { - Method m = o.getClass().getMethod("getProject", (Class[]) null); - if (Project.class == m.getReturnType()) { - return (Project) m.invoke(o, (Object[]) null); - } - } catch (Exception e) { - //too bad - } - return null; - } - /** * Check if definition is a valid definition--it may be a * definition of an optional task that does not exist. diff --git a/src/main/org/apache/tools/ant/Project.java b/src/main/org/apache/tools/ant/Project.java index b8c256728..d56f36d15 100644 --- a/src/main/org/apache/tools/ant/Project.java +++ b/src/main/org/apache/tools/ant/Project.java @@ -1651,6 +1651,26 @@ public class Project implements ResourceFactory { || "yes".equalsIgnoreCase(s)); } + /** + * Get the Project instance associated with the specified object. + * @return Project instance, if any. + * @since Ant 1.7.1 + */ + public static Project getProject(Object o) { + if (o instanceof ProjectComponent) { + return ((ProjectComponent) o).getProject(); + } + try { + Method m = o.getClass().getMethod("getProject", (Class[]) null); + if (Project.class == m.getReturnType()) { + return (Project) m.invoke(o, (Object[]) null); + } + } catch (Exception e) { + //too bad + } + return null; + } + /** * Topologically sort a set of targets. Equivalent to calling * topoSort(new String[] {root}, targets, true).