diff options
author | wisberg <wisberg> | 2005-06-08 23:33:01 +0000 |
---|---|---|
committer | wisberg <wisberg> | 2005-06-08 23:33:01 +0000 |
commit | d851660694dc1ee5d44d0ffb3bf2381559e8ceb4 (patch) | |
tree | 1eaff217ffca1bd9a9d07c7662d7ece3bada610b /util/src | |
parent | ec99a1f3fed8237f2df73a5063d7039d762afa8d (diff) | |
download | aspectj-d851660694dc1ee5d44d0ffb3bf2381559e8ceb4.tar.gz aspectj-d851660694dc1ee5d44d0ffb3bf2381559e8ceb4.zip |
getBestFile(String[])
Diffstat (limited to 'util/src')
-rw-r--r-- | util/src/org/aspectj/util/FileUtil.java | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/util/src/org/aspectj/util/FileUtil.java b/util/src/org/aspectj/util/FileUtil.java index ddaeedb43..a0f0a9021 100644 --- a/util/src/org/aspectj/util/FileUtil.java +++ b/util/src/org/aspectj/util/FileUtil.java @@ -339,6 +339,64 @@ public class FileUtil { } /** + * Get best File for the first-readable path in input paths, + * treating entries prefixed "sp:" as system property keys. + * Safe to call in static initializers. + * @param paths the String[] of paths to check. + * @return null if not found, or valid File otherwise + */ + public static File getBestFile(String[] paths) { + if (null == paths) { + return null; + } + File result = null; + for (int i = 0; (null == result) && (i < paths.length); i++) { + String path = paths[i]; + if (null == path) { + continue; + } + if (path.startsWith("sp:")) { + try { + path = System.getProperty(path.substring(3)); + } catch (Throwable t) { + path = null; + } + if (null == path) { + continue; + } + } + try { + File f = new File(path); + if (f.exists() && f.canRead()) { + result = FileUtil.getBestFile(f); + } + } catch (Throwable t) { + // swallow + } + } + return result; + } + + /** + * Render as best file, canonical or absolute. + * @param file the File to get the best File for (not null) + * @return File of the best-available path + * @throws IllegalArgumentException if file is null + */ + public static File getBestFile(File file) { + LangUtil.throwIaxIfNull(file, "file"); + if (file.exists()) { + try { + return file.getCanonicalFile(); + } catch (IOException e) { + return file.getAbsoluteFile(); + } + } else { + return file; + } + } + + /** * Render as best path, canonical or absolute. * @param file the File to get the path for (not null) * @return String of the best-available path |