提交 1fffb340 编写于 作者: K Kohsuke Kawaguchi

added a method to find a nearest job name (with a proper consideration to jobs in a hierarchy)

上级 189e95d2
...@@ -1912,13 +1912,22 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A ...@@ -1912,13 +1912,22 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
* Finds a {@link AbstractProject} that has the name closest to the given name. * Finds a {@link AbstractProject} that has the name closest to the given name.
*/ */
public static AbstractProject findNearest(String name) { public static AbstractProject findNearest(String name) {
List<AbstractProject> projects = Hudson.getInstance().getItems(AbstractProject.class); return findNearest(name,Hudson.getInstance());
}
/**
* Finds a {@link AbstractProject} whose name (when referenced from the specified context) is closest to the given name.
*
* @since 1.419
*/
public static AbstractProject findNearest(String name, ItemGroup context) {
List<AbstractProject> projects = Hudson.getInstance().getAllItems(AbstractProject.class);
String[] names = new String[projects.size()]; String[] names = new String[projects.size()];
for( int i=0; i<projects.size(); i++ ) for( int i=0; i<projects.size(); i++ )
names[i] = projects.get(i).getName(); names[i] = projects.get(i).getRelativeNameFrom(context);
String nearest = EditDistance.findNearest(name, names); String nearest = EditDistance.findNearest(name, names);
return (AbstractProject)Hudson.getInstance().getItem(nearest); return (AbstractProject)Hudson.getInstance().getItem(nearest,context);
} }
private static final Comparator<Integer> REVERSE_INTEGER_COMPARATOR = new Comparator<Integer>() { private static final Comparator<Integer> REVERSE_INTEGER_COMPARATOR = new Comparator<Integer>() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册