Browse Source

move and publish public static Project getProject(Object)

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@494952 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 18 years ago
parent
commit
d44807f593
2 changed files with 21 additions and 16 deletions
  1. +1
    -16
      src/main/org/apache/tools/ant/ComponentHelper.java
  2. +20
    -0
      src/main/org/apache/tools/ant/Project.java

+ 1
- 16
src/main/org/apache/tools/ant/ComponentHelper.java View File

@@ -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.


+ 20
- 0
src/main/org/apache/tools/ant/Project.java View File

@@ -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
* <code>topoSort(new String[] {root}, targets, true)</code>.


Loading…
Cancel
Save