Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

34
LINES

< > BotCompany Repo | #1025287 // hotwire_makeClassLoader_stickyAndSrcLibs (backup)

JavaX fragment (include)

// TODO: unload src libs when not used anymore,
// especially: old versions
static Map<File, ClassLoader> hotwire_srcLibsMap = syncMap();

static JavaXClassLoader hotwire_makeClassLoader_stickyAndSrcLibs(L<File> files) {
  new L<File> files2;
  new Map<S, ClassLoader> parents; // key = package/class name
  for (File f : files) {
    S libID = DiskSnippetCache_fileToLibID(f);
    if (libID != null && isStickyLibrary(libID)) {
      if (addLibrary(libID))
        print("Retaining sticky library " + libID);
    } else if (f != first(files) && isMarkedAsSrcLib(libID = isFile(f) ? loadTextFileFromZip(f, "progID") : null)) {
      ClassLoader c = hotwire_srcLibsMap.get(f);
      S jname = dropSuffix(".java", getJavaSrcNameOfSrcLib(libID));
      assertNempty(libID, jname);
      if (c == null) {
        print("Hotwiring src lib " + libID + " / " + f);
        Class cc = hotwireSpecialMainClass(libID, jname.replace("/", ".");
        setCreatorTo(cc, mc());
        c = cc.getClassLoader();
        hotwire_srcLibsMap.put(f, c);
      }
      S pkg = beforeSlash(jname);
      print("Linking src lib " + libID + " as " + pkg);
      parents.put(pkg, c);
    } else
      files2.add(f);
  }

  JavaXClassLoaderWithParents cl = new(null, files2, myClassLoader()); // progID is set later
  putAll(cl.parentMap, parents);
  ret cl;
}

Author comment

Began life as a copy of #1020749

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1025287
Snippet name: hotwire_makeClassLoader_stickyAndSrcLibs (backup)
Eternal ID of this version: #1025287/1
Text MD5: 052ab4a9d7248c748ba73fd41b8d9be7
Author: stefan
Category: javax / class loading
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-09-18 18:29:03
Source code size: 1369 bytes / 34 lines
Pitched / IR pitched: No / No
Views / Downloads: 240 / 253
Referenced in: [show references]