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).

1  
// TODO: unload src libs when not used anymore,
2  
// especially: old versions
3  
static Map<File, hotwire_srcLibsMap_Cached> hotwire_srcLibsMap = syncMap();
4  
5  
srecord hotwire_srcLibsMap_Cached(ClassLoader classLoader, S jname) {}
6  
7  
sbool hotwire_verboseLinking;
8  
9  
static JavaXClassLoader hotwire_makeClassLoader_stickyAndSrcLibs(L<File> files) {
10  
  new L<File> files2;
11  
  new Map<S, ClassLoader> parents; // key = package/class name
12  
  for (File f : files) {
13  
    S libID = DiskSnippetCache_fileToLibID(f);
14  
    if (libID != null && isStickyLibrary(libID)) {
15  
      if (addLibrary(libID))
16  
        print("Retaining sticky library " + libID);
17  
    } else if (f != first(files) && isMarkedAsSrcLib(libID = isFile(f) ? loadTextFileFromZip(f, "progID") : null)) {
18  
      hotwire_srcLibsMap_Cached cached = hotwire_srcLibsMap.get(f);
19  
      if (cached == null) {
20  
        print("Hotwiring src lib " + libID + " / " + f);
21  
        S jname = dropSuffix(".java", getJavaSrcNameOfSrcLib(libID));
22  
        assertNempty(libID, jname);
23  
        Class cc = hotwireSpecialMainClass(libID, jname.replace("/", ".");
24  
        setCreatorTo(cc, mc());
25  
        cached = hotwire_srcLibsMap_Cached(cc.getClassLoader(), jname);
26  
        hotwire_srcLibsMap.put(f, cached);
27  
      }
28  
      S pkg = beforeSlash(cached.jname);
29  
      if (hotwire_verboseLinking)
30  
        print("Linking src lib " + libID + " as " + pkg);
31  
      parents.put(pkg, cached.classLoader);
32  
    } else
33  
      files2.add(f);
34  
  }
35  
36  
  JavaXClassLoaderWithParents cl = new(null, files2, myClassLoader()); // progID is set later
37  
  putAll(cl.parentMap, parents);
38  
  ret cl;
39  
}

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: 252 / 346
Version history: 10 change(s)
Referenced in: [show references]