static File javaCompileToJar_rename(S src, File destJar, S progID) { ret javaCompileToJar_rename(src, "", destJar, progID); } // returns path to jar static synchronized File javaCompileToJar_rename(S src, S dehlibs, File destJar, S progID) { S javaTarget = null; // use default target print("Compiling " + l(src) + " chars"); S dummyClass = dummyMainClassName(progID); src += "\nclass " + dummyClass + "{}"; S md5 = md5(src); File jar = destJar; Class j = getJavaX(); if (javaTarget != null) setOpt(j, "javaTarget", javaTarget); //setOpt(j, "verbose", true); File srcDir = cast call(j, "TempDirMaker_make"); S className = "main"; S fileName = dummyClass + ".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)); } S compilerOutput; try { compilerOutput = (S) call(j, "compileJava", srcDir, libraries, classesDir); } catch (Throwable e) { compilerOutput = (S) get(getJavaX(), "javaCompilerOutput"); fail("Compile Error. " + compilerOutput + " " + e); } if (nempty(compilerOutput)) { print("Compiler said: " + compilerOutput); //fail("Compile Error. " + compilerOutput); } // sanity test if (!new File(classesDir, className + ".class").exists()) fail("No class generated (" + className + ")"); // add sources to .jar saveTextFile(new File(classesDir, "main.java"), src); // add information about libraries to jar if (nempty(dehlibs)) saveTextFile(new File(classesDir, "libraries"), dehlibs); //print("Zipping: " + classesDir.getAbsolutePath() + " to " + jar.getAbsolutePath()); dir2zip_recurse_verbose = false; int n = dir2zip_recurse(classesDir, jar); // cache on success only //print("Files zipped: " + n); return jar; }
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: | 523 / 579 |
Version history: | 4 change(s) |
Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) #1011328 - javaCompileToJar_optionalRename - renames if progID != null |