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 null;
return new File(home).getAbsoluteFile(); 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) if (path == null)
return false; return false;
for (final String p : path.split(";")) { File found = FS.searchPath(path, "cygpath.exe");
final File e = new File(p, "cygpath.exe"); if (found != null)
if (e.isFile()) { cygpath = found.getPath();
cygpath = e.getAbsolutePath(); return cygpath != null;
return true;
}
}
return false;
} }
public File resolve(final File dir, final String pn) { public File resolve(final File dir, final String pn) {