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)

1  
static File javaCompile(S src) {
2  
  ret javaCompile(src, "");
3  
}
4  
5  
// returns path to classes dir
6  
static synchronized File javaCompile(S src, S dehlibs) {
7  
  S javaTarget = null; // use default target
8  
  
9  
  //print("Compiling " + l(src) + " chars");
10  
11  
  Class j = getJavaX();
12  
  if (javaTarget != null)
13  
    setOpt(j, "javaTarget", javaTarget);
14  
  //setOpt(j, "verbose", true);
15  
  File srcDir = cast call(j, "TempDirMaker_make");
16  
  S className = getNameOfPublicClass(javaTok(src));
17  
  S fileName = className + ".java";
18  
  File mainJava = new File(srcDir, fileName);
19  
  //print("main java: " + mainJava.getAbsolutePath());
20  
  saveTextFile(mainJava, src);
21  
  File classesDir = (File) call(j, "TempDirMaker_make");
22  
  new L<File> libraries;
23  
  
24  
  Matcher m = Pattern.compile("\\d+").matcher(dehlibs);
25  
  while (m.find()) {
26  
    S libID = m.group();
27  
    //print("libID=" + quote(libID));
28  
    assertTrue(isSnippetID(libID));
29  
    libraries.add(loadLibrary(libID));
30  
  }
31  
    
32  
  try {
33  
     // This seems to be empty in case of success with Eclipse compiler.
34  
     S compilerOutput = cast call(j, "compileJava", srcDir, libraries, classesDir);
35  
     if (nempty(compilerOutput)) print("Compiler said: " + quote(compilerOutput));
36  
      
37  
      // sanity test
38  
      if (!new File(classesDir, className + ".class").exists())
39  
        fail("No class generated (" + className + ")");
40  
  } catch (Exception e) {
41  
    //e.printStackTrace();
42  
    fail("Compile Error\n" + getOpt(j, "javaCompilerOutput"));
43  
  }
44  
  
45  
  ret classesDir;
46  
}

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