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

40
LINES

< > BotCompany Repo | #1000631 // hotwire for x19+ (_javax)

JavaX fragment (include)

1  
  // compile JavaX source, load classes & return main class
2  
  // src can be a snippet ID or actual source code
3  
  
4  
  // requires class _javax
5  
  
6  
  static Class<?> hotwire(String src) {
7  
    try {
8  
      try { _javax.androidContext = get(main.class, "androidContext"); } catch (Exception e) {}
9  
      
10  
      List<File> libraries = new ArrayList<File>();
11  
      File srcDir = _javax.transpileMain(src, libraries);
12  
      
13  
      if (_javax.androidContext != null)
14  
        return _javax.loadx2android(srcDir, src);
15  
        
16  
      File classesDir = _javax.TempDirMaker_make();
17  
      String javacOutput = _javax.compileJava(srcDir, libraries, classesDir);
18  
      System.out.println(javacOutput);
19  
      
20  
      URL[] urls = new URL[libraries.size()+1];
21  
      urls[0] = classesDir.toURI().toURL();
22  
      for (int i = 0; i < libraries.size(); i++)
23  
        urls[i+1] = libraries.get(i).toURI().toURL();
24  
25  
      // make class loader
26  
      URLClassLoader classLoader = new URLClassLoader(urls);
27  
  
28  
      // load & return main class
29  
      Class<?> theClass = classLoader.loadClass("main");
30  
      
31  
      if (isSnippetID(src))
32  
        try {
33  
          set(theClass, "programID", src);
34  
        } catch (Throwable e) {}
35  
      
36  
      return theClass;
37  
    } catch (Exception e) {
38  
      throw e instanceof RuntimeException ? (RuntimeException) e : new RuntimeException(e);
39  
    }
40  
  }

Author comment

Began life as a copy of #1000401

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

Comments [hide]

ID Author/Program Comment Date
799 #1000604 (pitcher) 2015-08-20 15:28:24

add comment

Snippet ID: #1000631
Snippet name: hotwire for x19+ (_javax)
Eternal ID of this version: #1000631/1
Text MD5: 00fdc42c488ada28d9546c6a3b8bc9f6
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-09-03 23:42:54
Source code size: 1391 bytes / 40 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 933 / 1395
Referenced in: [show references]