From: Andy Clement Date: Tue, 19 Feb 2019 16:58:30 +0000 (-0800) Subject: extra util for finding suitable files with mustBeJar option X-Git-Tag: V1_9_3RC1~10 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=044ddbb7f93e7234cc849e3092454e9f3d9ac3c3;p=aspectj.git extra util for finding suitable files with mustBeJar option --- diff --git a/util/src/main/java/org/aspectj/util/FileUtil.java b/util/src/main/java/org/aspectj/util/FileUtil.java index f3db2bda7..fef580e83 100644 --- a/util/src/main/java/org/aspectj/util/FileUtil.java +++ b/util/src/main/java/org/aspectj/util/FileUtil.java @@ -408,6 +408,41 @@ public class FileUtil { return result; } + public static File getBestFile(String[] paths, boolean mustBeJar) { + 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()) { + if (mustBeJar && !f.isDirectory()) { + result = FileUtil.getBestFile(f); + } + } + } catch (Throwable t) { + // swallow + } + } + return result; + } + /** * Render as best file, canonical or absolute. *