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

49
LINES

< > BotCompany Repo | #1005811 // BACKUP of hotwire using outer JavaX

JavaX fragment (include)

1  
  // compile JavaX source, load classes & return main class
2  
  // src can be a snippet ID or path to sources dir
3  
  // TODO: record injection?
4  
  
5  
  static Class<?> hotwire(String src) {
6  
    try {
7  
      Class j = getJavaX();
8  
      
9  
      synchronized(j) { // hopefully this goes well...
10  
        List<File> libraries = new ArrayList<File>();
11  
        File srcDir = (File) call(j, "transpileMain", src, libraries);
12  
        if (srcDir == null)
13  
          fail("transpileMain returned null (src=" + quote(src) + ")");
14  
        
15  
        Object androidContext = get(j, "androidContext");
16  
        if (androidContext != null)
17  
          return (Class) call(j, "loadx2android", srcDir, src);
18  
          
19  
        File classesDir = (File) call(j, "TempDirMaker_make");
20  
        String javacOutput = (String) call(j, "compileJava", srcDir, libraries, classesDir);
21  
        System.out.println(javacOutput);
22  
        
23  
        URL[] urls = new URL[libraries.size()+1];
24  
        urls[0] = classesDir.toURI().toURL();
25  
        for (int i = 0; i < libraries.size(); i++)
26  
          urls[i+1] = libraries.get(i).toURI().toURL();
27  
  
28  
        // make class loader
29  
        URLClassLoader classLoader = new URLClassLoader(urls);
30  
    
31  
        // load & return main class
32  
        Class<?> theClass = classLoader.loadClass("main");
33  
        
34  
        callOpt(j, "registerSourceCode", theClass, loadTextFile(new File(srcDir, "main.java")));
35  
36  
        call(j, "setVars", theClass, isSnippetID(src) ? src : null);
37  
        
38  
        if (isSnippetID(src))
39  
          callOpt(j, "addInstance", src, theClass);
40  
          
41  
        if (!_inCore())
42  
          hotwire_copyOver(theClass);
43  
  
44  
        return theClass;
45  
      }
46  
    } catch (Exception e) {
47  
      throw e instanceof RuntimeException ? (RuntimeException) e : new RuntimeException(e);
48  
    }
49  
  }

Author comment

Began life as a copy of #1000963

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1005811
Snippet name: BACKUP of hotwire using outer JavaX
Eternal ID of this version: #1005811/1
Text MD5: b9ddfcc5638c50a6c3acb12af169154f
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-12-09 14:40:26
Source code size: 1844 bytes / 49 lines
Pitched / IR pitched: No / No
Views / Downloads: 462 / 447
Referenced in: [show references]