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

74
LINES

< > BotCompany Repo | #1001601 // x29.jar maker module - deploys into {userhome}/.javax

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

Libraryless. Click here for Pure Java version (1119L/8K/27K).

1  
!747
2  
3  
m {
4  
  static S v = "x29";
5  
  static S sourceID = "#1001600";
6  
  static S javaTarget = "1.6"; // compile JavaX for everyone
7  
  
8  
  static S compilerBotID = "#1001155";
9  
  static int compressionLevel = 9; // Zip compression - highest level
10  
  
11  
  p {
12  
    S s = loadPage("http://tinybrain.de:8080/tb-int/get-transpiled.php?id=" + parseSnippetID(sourceID) + "&raw=1");
13  
    saveProgramTextFile("raw.java", s);
14  
    L<S> tok = javaTok(s);
15  
    renameToken(tok, "StringFunc", "StrF");
16  
    for (L<S> c : allClasses(tok)) {
17  
      S name = getClassDeclarationName(c);
18  
      if (name.equals("main"))
19  
        clearAllTokens(c);
20  
      else if (name.equals(v) && !c.get(1).equals("public"))
21  
        c.set(1, "public " + c.get(1));
22  
    }
23  
    File javaFile = new File(programDir(), v + ".java");
24  
    saveTextFile(javaFile, join(tok));
25  
    print("ok, made " + javaFile.getAbsolutePath());
26  
    
27  
    print("Now compiling. Making a compiler bot just for the occasion.");
28  
    S botQuestion = "Please compile this Java text: " + quote(join(tok)) + " for java version " + quote(javaTarget);
29  
    print("Question to bot: " + shorten(botQuestion, 200));
30  
    //print("Parses? " + match3("Please compile this Java text: *", botQuestion));
31  
    
32  
    Class compilerBot = hotwire(compilerBotID);
33  
    // We should initialize it or so... we're being lazy here. Works for now.
34  
    S answer = cast call(compilerBot, "answer", botQuestion);
35  
    print("Bot said: " + answer);
36  
    if (answer == null) fail();
37  
    new Matches m;
38  
    if (!match3("ok, *", answer, m))
39  
      if (match3("Compile error", answer))
40  
        fail("Compile Error.");
41  
      else
42  
        fail("I don't understand the bot, exiting");
43  
      
44  
    S classesDir = unquote(m.m[0]);
45  
    print("I think the classes dir is: " + classesDir);
46  
    if (!new File(classesDir).isDirectory()) fail("huh?");
47  
48  
    print("Now making jar.");
49  
    File jarFile = new File(programDir(), v + ".jar");
50  
    File ecj = loadLibrary("#1001164"); // ecj.zip
51  
    
52  
    FileOutputStream fout = new FileOutputStream(jarFile);
53  
    ZipOutputStream zout = new ZipOutputStream(fout);
54  
    zout.setLevel(compressionLevel);
55  
    
56  
    makeManifest(zout);
57  
    dir2zip(classesDir, zout);
58  
    zip2zip(ecj, zout);
59  
    zout.close();
60  
    fout.close();
61  
    
62  
    print("ok, made " + jarFile.getAbsolutePath() + " (" + jarFile.length() + " bytes)");
63  
    
64  
    File deployedFile = new File(userHome(), ".javax/" + jarFile.getName());
65  
    copyFile(jarFile, deployedFile);
66  
    print("Deployed to " + deployedFile.getAbsolutePath());
67  
  }
68  
  
69  
  static void makeManifest(ZipOutputStream outZip) ctex {
70  
    outZip.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF"));
71  
    outZip.write(toUtf8("Manifest-Version: 1.0\n" +
72  
      "Main-Class: " + v + "\n\n"));
73  
  }
74  
}

Author comment

Began life as a copy of #1001371

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: #1001601
Snippet name: x29.jar maker module - deploys into {userhome}/.javax
Eternal ID of this version: #1001601/1
Text MD5: 9abcece15d4f6b19e44e41270a39c03d
Transpilation MD5: e4f553d864d7fbd4d600502bd787ad1f
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-10-26 18:06:55
Source code size: 2801 bytes / 74 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 639 / 690
Referenced in: [show references]