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

64
LINES

< > BotCompany Repo | #1001163 // x27.jar maker module (from #1001148)

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

Libraryless. Click here for Pure Java version (923L/8K/23K).

!747

m {
  static S v = "x27";
  static S javaTarget = "1.6"; // compile JavaX for everyone
  
  static int compressionLevel = 9; // Zip compression - highest level
  
  p {
    S s = loadPage("http://tinybrain.de:8080/tb-int/get-transpiled.php?id=1001148&raw=1");
    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));
    }
    S javaFile = v + ".java";
    saveTextFile(javaFile, join(tok));
    print("ok, made " + javaFile);
    
    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("#1001155");
    // 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))
      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.");
    S jarFile = 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 + " (" + new File(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"));
  }
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1001163
Snippet name: x27.jar maker module (from #1001148)
Eternal ID of this version: #1001163/1
Text MD5: b7ae5722da55e69e55127c57dc8afd38
Transpilation MD5: b9089ed5f7b9b222ac6d15d3501a8687
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-09-25 21:35:13
Source code size: 2303 bytes / 64 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 805 / 861
Referenced in: #1001371 - x28.jar maker module (from #1001370)
#3000190 - Answer for stefanreich(>> t 20 questions)
#3000202 - Answer for stefanreich (>> T conversion bot)
#3000238 - Answer for stefanreich (>> t power bot)
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)