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)

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

// returns path to jar
static synchronized File javaCompileToJar_standard(S src, S dehlibs, File destJar) {
  S javaTarget = null; // use default target
  
  print("Compiling " + l(src) + " chars");
  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 = 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));
  }
    
  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;
}

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: 409 / 455
Version history: 3 change(s)
Referenced in: [show references]