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

39
LINES

< > BotCompany Repo | #1020749 // hotwire_makeClassLoader_stickyAndSrcLibs

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (11166L/68K).

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

srecord hotwire_srcLibsMap_Cached(ClassLoader classLoader, S jname) {}

sbool hotwire_verboseLinking;

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)) {
      hotwire_srcLibsMap_Cached cached = hotwire_srcLibsMap.get(f);
      if (cached == null) {
        print("Hotwiring src lib " + libID + " / " + f);
        S jname = dropSuffix(".java", getJavaSrcNameOfSrcLib(libID));
        assertNempty(libID, jname);
        Class cc = hotwireSpecialMainClass(libID, jname.replace("/", ".");
        setCreatorTo(cc, mc());
        cached = hotwire_srcLibsMap_Cached(cc.getClassLoader(), jname);
        hotwire_srcLibsMap.put(f, cached);
      }
      S pkg = beforeSlash(cached.jname);
      if (hotwire_verboseLinking)
        print("Linking src lib " + libID + " as " + pkg);
      parents.put(pkg, cached.classLoader);
    } 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 #1016216

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1020749
Snippet name: hotwire_makeClassLoader_stickyAndSrcLibs
Eternal ID of this version: #1020749/11
Text MD5: d2caf73eec8c3b7435a6c99d735fffd3
Transpilation MD5: b4959c1469644b2895d1fc61e8711c15
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-23 23:43:47
Source code size: 1623 bytes / 39 lines
Pitched / IR pitched: No / No
Views / Downloads: 238 / 328
Version history: 10 change(s)
Referenced in: [show references]