|
29 | 29 |
|
30 | 30 | package net.imagej.patcher;
|
31 | 31 |
|
| 32 | +import io.github.classgraph.ClassGraph; |
| 33 | +import io.github.classgraph.ScanResult; |
| 34 | + |
32 | 35 | import java.awt.event.KeyEvent;
|
33 | 36 | import java.io.ByteArrayInputStream;
|
34 | 37 | import java.io.File;
|
@@ -590,57 +593,14 @@ public static Collection<File> getClasspathElements(
|
590 | 593 | final ClassLoader fromClassLoader, final StringBuilder errors,
|
591 | 594 | final ClassLoader... excludeClassLoaders)
|
592 | 595 | {
|
593 |
| - final Set<ClassLoader> exclude = |
594 |
| - new HashSet<ClassLoader>(Arrays.asList(excludeClassLoaders)); |
595 |
| - final List<File> result = new ArrayList<File>(); |
596 |
| - for (ClassLoader loader = fromClassLoader; loader != null; loader = |
597 |
| - loader.getParent()) { |
598 |
| - if (exclude.contains(loader)) break; |
599 |
| - |
600 |
| - if (!(loader instanceof URLClassLoader)) { |
601 |
| - errors.append("Cannot add class path from ClassLoader of type ") |
602 |
| - .append(fromClassLoader.getClass().getName()).append("\n"); |
603 |
| - continue; |
604 |
| - } |
| 596 | + try( ScanResult result = new ClassGraph() |
| 597 | +// .verbose() |
| 598 | +// .enableAllInfo() |
| 599 | + .acceptPackages() |
| 600 | + .scan()) { |
605 | 601 |
|
606 |
| - for (final URL url : ((URLClassLoader) loader).getURLs()) { |
607 |
| - if (!"file".equals(url.getProtocol())) { |
608 |
| - errors.append("Not a file URL! ").append(url).append("\n"); |
609 |
| - continue; |
610 |
| - } |
611 |
| - result.add(new File(url.getPath())); |
612 |
| - final String path = url.getPath(); |
613 |
| - if (path.matches(".*/target/surefire/surefirebooter[0-9]*\\.jar")) try { |
614 |
| - final JarFile jar = new JarFile(path); |
615 |
| - final Manifest manifest = jar.getManifest(); |
616 |
| - if (manifest != null) { |
617 |
| - final String classPath = |
618 |
| - manifest.getMainAttributes().getValue(Name.CLASS_PATH); |
619 |
| - if (classPath != null) { |
620 |
| - for (final String element : classPath.split(" +")) |
621 |
| - try { |
622 |
| - final URL url2 = new URL(element); |
623 |
| - if (!"file".equals(url2.getProtocol())) { |
624 |
| - errors.append("Not a file URL! ").append(url2).append("\n"); |
625 |
| - continue; |
626 |
| - } |
627 |
| - result.add(new File(url2.getPath())); |
628 |
| - } |
629 |
| - catch (final MalformedURLException e) { |
630 |
| - e.printStackTrace(); |
631 |
| - } |
632 |
| - } |
633 |
| - } |
634 |
| - } |
635 |
| - catch (final IOException e) { |
636 |
| - System.err |
637 |
| - .println("Warning: could not add plugin class path due to "); |
638 |
| - e.printStackTrace(); |
639 |
| - } |
640 |
| - |
641 |
| - } |
| 602 | + return result.getClasspathFiles(); |
642 | 603 | }
|
643 |
| - return result; |
644 | 604 | }
|
645 | 605 |
|
646 | 606 | /**
|
|
0 commit comments