Refactor search for a file within a PATH

Change-Id: I785ab6bf1823d174394b1d2b25c5bb202535e943
This commit is contained in:
Robin Rosenberg 2010-12-28 17:15:08 +01:00 committed by Shawn O. Pearce
parent 558879d820
commit 14b358a6fb
2 changed files with 15 additions and 8 deletions

View File

@ -199,4 +199,15 @@ public String run() {
return null;
return new File(home).getAbsoluteFile();
}
static File searchPath(final String path, final String... lookFor) {
for (final String p : path.split(File.pathSeparator)) {
for (String command : lookFor) {
final File e = new File(p, command);
if (e.isFile())
return e.getAbsoluteFile();
}
}
return null;
}
}

View File

@ -62,14 +62,10 @@ public String run() {
});
if (path == null)
return false;
for (final String p : path.split(";")) {
final File e = new File(p, "cygpath.exe");
if (e.isFile()) {
cygpath = e.getAbsolutePath();
return true;
}
}
return false;
File found = FS.searchPath(path, "cygpath.exe");
if (found != null)
cygpath = found.getPath();
return cygpath != null;
}
public File resolve(final File dir, final String pn) {