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

46
LINES

< > BotCompany Repo | #1003840 // javaCompile - compile to classes dir

JavaX fragment (include)

static File javaCompile(S src) {
  ret javaCompile(src, "");
}

// returns path to classes dir
static synchronized File javaCompile(S src, S dehlibs) {
  S javaTarget = null; // use default target
  
  //print("Compiling " + l(src) + " chars");

  Class j = getJavaX();
  if (javaTarget != null)
    setOpt(j, "javaTarget", javaTarget);
  //setOpt(j, "verbose", true);
  File srcDir = cast call(j, "TempDirMaker_make");
  S className = getNameOfPublicClass(javaTok(src));
  S fileName = className + ".java";
  File mainJava = new File(srcDir, fileName);
  //print("main java: " + mainJava.getAbsolutePath());
  saveTextFile(mainJava, src);
  File classesDir = (File) call(j, "TempDirMaker_make");
  new L<File> libraries;
  
  Matcher m = Pattern.compile("\\d+").matcher(dehlibs);
  while (m.find()) {
    S libID = m.group();
    //print("libID=" + quote(libID));
    assertTrue(isSnippetID(libID));
    libraries.add(loadLibrary(libID));
  }
    
  try {
     // This seems to be empty in case of success with Eclipse compiler.
     S compilerOutput = cast call(j, "compileJava", srcDir, libraries, classesDir);
     if (nempty(compilerOutput)) print("Compiler said: " + quote(compilerOutput));
      
      // sanity test
      if (!new File(classesDir, className + ".class").exists())
        fail("No class generated (" + className + ")");
  } catch (Exception e) {
    //e.printStackTrace();
    fail("Compile Error\n" + getOpt(j, "javaCompilerOutput"));
  }
  
  ret classesDir;
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1003840
Snippet name: javaCompile - compile to classes dir
Eternal ID of this version: #1003840/1
Text MD5: de5f364a8c46ecab9841fd10ce2fe1f4
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-08-07 18:21:39
Source code size: 1534 bytes / 46 lines
Pitched / IR pitched: No / No
Views / Downloads: 617 / 647
Referenced in: [show references]