+ public static class LibClassLoader extends ClassLoader {
+ private final ClassLoader[] classpath;
+
+ public LibClassLoader(ClassLoader parent, Collection<ClassLoader> classpath) {
+ super(parent);
+ this.classpath = classpath.toArray(new ClassLoader[0]);
+ }
+
+ public Class<?> findClass(String name) throws ClassNotFoundException {
+ for(ClassLoader lib : classpath) {
+ try {
+ return(lib.loadClass(name));
+ } catch(ClassNotFoundException e) {}
+ }
+ throw(new ClassNotFoundException("Could not find " + name + " in any of " + Arrays.asList(classpath).toString()));
+ }
+ }
+
+ public ClassLoader libloader(Path p) {
+ synchronized(libs) {
+ ClassLoader ret = libs.get(p);
+ if(ret == null) {
+ try {
+ libs.put(p, ret = new URLClassLoader(new URL[] {p.toUri().toURL()}));
+ } catch(MalformedURLException e) {
+ throw(new RuntimeException(e));
+ }
+ }
+ return(ret);
+ }
+ }
+
+ private Path findlib(String nm) {
+ for(Path dir : searchpath) {
+ Path jar = dir.resolve(nm + ".jar");
+ if(Files.isRegularFile(jar))
+ return(jar);
+ }
+ return(null);
+ }
+
+ private static final Pattern classpat = Pattern.compile("^((public|abstract)\\s+)*(class|interface)\\s+(\\S+)");
+ private static final Pattern libpat = Pattern.compile("\\$use\\s*:\\s*(\\S+)");
+ public class Module {