From 044ddbb7f93e7234cc849e3092454e9f3d9ac3c3 Mon Sep 17 00:00:00 2001 From: Andy Clement Date: Tue, 19 Feb 2019 08:58:30 -0800 Subject: [PATCH] extra util for finding suitable files with mustBeJar option --- .../main/java/org/aspectj/util/FileUtil.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) 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. * -- 2.39.5