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)

  // compile JavaX source, load classes & return main class
  // src can be a snippet ID or actual source code
  
  // requires class _javax
  
  static Class<?> hotwire(String src) {
    try {
      try { _javax.androidContext = get(main.class, "androidContext"); } catch (Exception e) {}
      
      List<File> libraries = new ArrayList<File>();
      File srcDir = _javax.transpileMain(src, libraries);
      
      if (_javax.androidContext != null)
        return _javax.loadx2android(srcDir, src);
        
      File classesDir = _javax.TempDirMaker_make();
      String javacOutput = _javax.compileJava(srcDir, libraries, classesDir);
      System.out.println(javacOutput);
      
      URL[] urls = new URL[libraries.size()+1];
      urls[0] = classesDir.toURI().toURL();
      for (int i = 0; i < libraries.size(); i++)
        urls[i+1] = libraries.get(i).toURI().toURL();

      // make class loader
      URLClassLoader classLoader = new URLClassLoader(urls);
  
      // load & return main class
      Class<?> theClass = classLoader.loadClass("main");
      
      if (isSnippetID(src))
        try {
          set(theClass, "programID", src);
        } catch (Throwable e) {}
      
      return theClass;
    } catch (Exception e) {
      throw e instanceof RuntimeException ? (RuntimeException) e : new RuntimeException(e);
    }
  }

Author comment

Began life as a copy of #1000401

download  show line numbers  debug dex   

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

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: 658 / 1097
Referenced in: [show references]

Formerly at http://tinybrain.de/1000631 & http://1000631.tinybrain.de