]> source.dussan.org Git - aspectj.git/commitdiff
extra util for finding suitable files with mustBeJar option
authorAndy Clement <aclement@pivotal.io>
Tue, 19 Feb 2019 16:58:30 +0000 (08:58 -0800)
committerAndy Clement <aclement@pivotal.io>
Tue, 19 Feb 2019 16:58:30 +0000 (08:58 -0800)
util/src/main/java/org/aspectj/util/FileUtil.java

index f3db2bda7c43e5b531f4373e4c58e460882843df..fef580e83777a4b9c18abc0e543c7c8e1852d0e7 100644 (file)
@@ -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.
         *