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

64
LINES

< > BotCompany Repo | #1007180 // javaCompileToJar_standard - outdated

JavaX fragment (include)

1  
static File javaCompileToJar_standard(S src, File destJar) {
2  
  ret javaCompileToJar_standard(src, "", destJar);
3  
}
4  
5  
// returns path to jar
6  
static synchronized File javaCompileToJar_standard(S src, S dehlibs, File destJar) {
7  
  S javaTarget = null; // use default target
8  
  
9  
  print("Compiling " + l(src) + " chars");
10  
  S md5 = md5(src);
11  
  File jar = destJar;
12  
13  
  Class j = getJavaX();
14  
  if (javaTarget != null)
15  
    setOpt(j, "javaTarget", javaTarget);
16  
  //setOpt(j, "verbose", true);
17  
  File srcDir = cast call(j, "TempDirMaker_make");
18  
  S className = "main";
19  
  S fileName = className + ".java";
20  
  File mainJava = new File(srcDir, fileName);
21  
  //print("main java: " + mainJava.getAbsolutePath());
22  
  saveTextFile(mainJava, src);
23  
  File classesDir = (File) call(j, "TempDirMaker_make");
24  
  new L<File> libraries;
25  
  
26  
  Matcher m = Pattern.compile("\\d+").matcher(dehlibs);
27  
  while (m.find()) {
28  
    S libID = m.group();
29  
    //print("libID=" + quote(libID));
30  
    assertTrue(isSnippetID(libID));
31  
    libraries.add(loadLibrary(libID));
32  
  }
33  
    
34  
  S compilerOutput;
35  
  try {
36  
    compilerOutput = (S) call(j, "compileJava", srcDir, libraries, classesDir);
37  
  } catch (Throwable e) {
38  
    compilerOutput = (S) get(getJavaX(), "javaCompilerOutput");
39  
    fail("Compile Error. " + compilerOutput + " " + e);
40  
  }
41  
  
42  
  if (nempty(compilerOutput)) {
43  
    print("Compiler said: " + compilerOutput);
44  
    //fail("Compile Error. " + compilerOutput);
45  
  }
46  
47  
  // sanity test
48  
  if (!new File(classesDir, className + ".class").exists())
49  
    fail("No class generated (" + className + ")");
50  
      
51  
  // add sources to .jar
52  
  saveTextFile(new File(classesDir, "main.java"), src);
53  
  
54  
  // add information about libraries to jar
55  
  if (nempty(dehlibs))
56  
    saveTextFile(new File(classesDir, "libraries"), dehlibs);
57  
58  
  //print("Zipping: " + classesDir.getAbsolutePath() + " to " + jar.getAbsolutePath());
59  
  dir2zip_recurse_verbose = false;
60  
  int n = dir2zip_recurse(classesDir, jar); // cache on success only
61  
  //print("Files zipped: " + n);
62  
63  
  return jar;
64  
}

Author comment

Began life as a copy of #1003843

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: #1007180
Snippet name: javaCompileToJar_standard - outdated
Eternal ID of this version: #1007180/4
Text MD5: 090a637be2e00896a4bd2ac1325e2036
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-10-24 05:16:40
Source code size: 2081 bytes / 64 lines
Pitched / IR pitched: No / No
Views / Downloads: 410 / 456
Version history: 3 change(s)
Referenced in: [show references]