Given a folder, return a list of absolute paths to all jar or zip files inside that folder, separated by pathSeparatorChar. This will prepend a colon (or whatever the path separator is) so that it can be directly appended to another path string. As of 0136, this will no longer add the root f
(File folder)
| 537 | * files in the folder or within a subfolder. |
| 538 | */ |
| 539 | static public String contentsToClassPath(File folder) { |
| 540 | if (folder == null) return ""; |
| 541 | |
| 542 | StringBuilder sb = new StringBuilder(); |
| 543 | String sep = System.getProperty("path.separator"); |
| 544 | |
| 545 | try { |
| 546 | String path = folder.getCanonicalPath(); |
| 547 | |
| 548 | // When getting the name of this folder, make sure it has a slash |
| 549 | // after it, so that the names of sub-items can be added. |
| 550 | if (!path.endsWith(File.separator)) { |
| 551 | path += File.separator; |
| 552 | } |
| 553 | |
| 554 | String[] list = folder.list(); |
| 555 | if (list != null) { |
| 556 | for (String item : list) { |
| 557 | // Skip . and ._ files. Prior to 0125p3, .jar files that had |
| 558 | // OS X AppleDouble files associated would cause trouble. |
| 559 | if (!item.startsWith(".")) { |
| 560 | if (item.toLowerCase().endsWith(".jar") || |
| 561 | item.toLowerCase().endsWith(".zip")) { |
| 562 | sb.append(sep); |
| 563 | sb.append(path); |
| 564 | sb.append(item); |
| 565 | } |
| 566 | } |
| 567 | } |
| 568 | } |
| 569 | } catch (IOException e) { |
| 570 | e.printStackTrace(); // this would be odd |
| 571 | } |
| 572 | return sb.toString(); |
| 573 | } |
| 574 | |
| 575 | |
| 576 | /** |
no test coverage detected