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

66
LINES

< > BotCompany Repo | #1008752 // javaCompileToJar_rename - renames source file to make stack traces more informative; outdated

JavaX fragment (include)

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

Author comment

Began life as a copy of #1007180

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: #1008752
Snippet name: javaCompileToJar_rename - renames source file to make stack traces more informative; outdated
Eternal ID of this version: #1008752/5
Text MD5: 351cc0b025bf863fecb7ea7c2a6950a9
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:52
Source code size: 2192 bytes / 66 lines
Pitched / IR pitched: No / No
Views / Downloads: 522 / 579
Version history: 4 change(s)
Referenced in: [show references]