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

70
LINES

< > BotCompany Repo | #1001371 // x28.jar maker module (from #1001370)

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (995L/8K/25K).

!747

m {
  static S v = "x28";
  static S sourceID = "#1001370";
  static S javaTarget = "1.6"; // compile JavaX for everyone
  
  static S compilerBotID = "#1001155";
  static int compressionLevel = 9; // Zip compression - highest level
  
  p {
    S s = loadPage("http://tinybrain.de:8080/tb-int/get-transpiled.php?id=" + parseSnippetID(sourceID) + "&raw=1");
    saveProgramTextFile("raw.java", s);
    L<S> tok = javaTok(s);
    renameToken(tok, "StringFunc", "StrF");
    for (L<S> c : allClasses(tok)) {
      S name = getClassDeclarationName(c);
      if (name.equals("main"))
        clearAllTokens(c);
      else if (name.equals(v) && !c.get(1).equals("public"))
        c.set(1, "public " + c.get(1));
    }
    File javaFile = new File(programDir(), v + ".java");
    saveTextFile(javaFile, join(tok));
    print("ok, made " + javaFile.getAbsolutePath());
    
    print("Now compiling. Making a compiler bot just for the occasion.");
    S botQuestion = "Please compile this Java text: " + quote(join(tok)) + " for java version " + quote(javaTarget);
    print("Question to bot: " + shorten(botQuestion, 200));
    //print("Parses? " + match3("Please compile this Java text: *", botQuestion));
    
    Class compilerBot = hotwire(compilerBotID);
    // We should initialize it or so... we're being lazy here. Works for now.
    S answer = cast call(compilerBot, "answer", botQuestion);
    print("Bot said: " + answer);
    if (answer == null) fail();
    new Matches m;
    if (!match3("ok, *", answer, m))
      if (match3("Compile error", answer))
        fail("Compile Error.");
      else
        fail("I don't understand the bot, exiting");
      
    S classesDir = unquote(m.m[0]);
    print("I think the classes dir is: " + classesDir);
    if (!new File(classesDir).isDirectory()) fail("huh?");

    print("Now making jar.");
    File jarFile = new File(programDir(), v + ".jar");
    File ecj = loadLibrary("#1001164"); // ecj.zip
    
    FileOutputStream fout = new FileOutputStream(jarFile);
    ZipOutputStream zout = new ZipOutputStream(fout);
    zout.setLevel(compressionLevel);
    
    makeManifest(zout);
    dir2zip(classesDir, zout);
    zip2zip(ecj, zout);
    zout.close();
    fout.close();
    
    print("ok, made " + jarFile.getAbsolutePath() + " (" + jarFile.length() + " bytes)");
  }
  
  static void makeManifest(ZipOutputStream outZip) ctex {
    outZip.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF"));
    outZip.write(toUtf8("Manifest-Version: 1.0\n" +
      "Main-Class: " + v + "\n\n"));
  }
}

Author comment

Began life as a copy of #1001163

download  show line numbers  debug dex  old transpilations   

Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, dhtvkmknsjym, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1001371
Snippet name: x28.jar maker module (from #1001370)
Eternal ID of this version: #1001371/1
Text MD5: b56dec87253cd88ef4949a7b7fe06624
Transpilation MD5: a6f843aeadd34845dc91fd6edf80598c
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-10-13 20:25:12
Source code size: 2618 bytes / 70 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 650 / 838
Referenced in: [show references]