// progID is just for information static class JavaXClassLoader extends URLClassLoader { S progID; Set files = syncLinkedHashSet(); Set libraryIDs = syncLinkedHashSet(); Set triedToLoad = synchroSet(); Set loadedClasses = synchroSet(); bool retired; O retiredMarker; IF1 findClass_extension; S mainClassName; bool verbose; *(S progID, L files) { this(progID, files, getSystemClassLoader()); } *(S progID, L files, ClassLoader parent) { // sadly can't see this constructor //super(progID, new URL[0], parent, vm_globalACC()); super(new URL[0], parent); this.progID = progID; fOr (File f : files) addFile(f); // TODO: how to get around this fixACCInClassLoader(this); } Class super_findClass(S name) throws ClassNotFoundException { ret super.findClass(name); } protected Class findClass(S name) throws ClassNotFoundException { if (verbose) System.out.println(this + " findClass: " + name); if (findClass_extension != null) { Class c = findClass_extension.get(name); if (verbose) System.out.println("extension returned: " + c); if (c != null) ret c; } bool triedBefore = !triedToLoad.add(name); try { Class c = super.findClass(name); if (verbose) System.out.println("super.findClass returned: " + c); loadedClasses.add(c); if (eq(name, mainClassName())) callOpt(javax(), 'registerAMainClass, c); ret c; } catch (ClassNotFoundException e) { if (verbose) System.out.println(getStackTrace(e)); throw new ClassNotFoundException("Class " + name + " not found in " + joinWithComma(map f2s(files)) + " (progID=" + progID + ")" + (triedBefore ? ", tried to load before" : ""), e); } } toString { ret shortClassName(this) + "[" + systemHashCodeHex(this) + "] - " + progID; } S mainClassName() { if (mainClassName == null) { mainClassName = "main"; pcall { mainClassName = or2(trim(loadTextFileResource(this, "main-class")), mainClassName); } } ret mainClassName; } bool addFile(File f, S libraryID) { if (nempty(libraryID)) if (!libraryIDs.add(libraryID)) false; ret addFile(f); } bool addFile(File f) ctex { if (!files.add(f)) false; addURL(f.toURI().toURL()); mainClassName(); // calculate early. no good loading text files later true; } Set libraryIDs() { ret libraryIDs; } bool hasLibraryID(S libraryID) { ret libraryIDs.contains(libraryID); } protected swappable S findLibrary(S libname) { ret super.findLibrary(libname); } // make public public void addURL(URL url) { super.addURL(url); } }