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

92
LINES

< > BotCompany Repo | #1001639 - Update JavaX! [deploys into {userhome}/.javax]

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

Libraryless. Click here for Pure Java version (13459L/94K).

1  
!7
2  
3  
static S v = "x30";
4  
static S sourceID = "#1001638";
5  
static S javaTarget = "1.8"; // compile JavaX for everyone
6  
static S ecjSnippetID = #1400467; // #1400153; // #1400052; // #1011501; // #1008795; // #1001164; // ecj.zip
7  
8  
static S compilerBotID = "#1001155";
9  
static int compressionLevel = 9; // Zip compression - highest level
10  
11  
set flag hotwire_here.
12  
13  
p {
14  
  loading "Updating JavaX!" {
15  
    sendToAllVMs("prepare for javax upgrade");
16  
    
17  
    File jarFile = new File(programDir(), v + ".jar");
18  
    File deployedFile = new File(userHome(), ".javax/" + jarFile.getName());
19  
    
20  
    S oldMD5 = deployedFile == null ? null : md5(deployedFile);
21  
    if (oldMD5 != null) print("Current md5: " + oldMD5);
22  
    
23  
    S s = loadPage(tb_mainServer() + "/tb-int/get-transpiled.php?id=" + parseSnippetID(sourceID) + "&raw=1&withlibs=1");
24  
    S libs = firstLine(s);
25  
    s = dropFirstLine(s);
26  
    
27  
    s += x30_makeUtilsSource();
28  
    
29  
    saveProgramTextFile("raw.java", s);
30  
    L<S> tok = javaTok(s);
31  
    // TODO: generate & compile DynamicMethods.java
32  
    javax_prepareX30SourceForDeployment(tok);
33  
    File javaFile = new File(programDir(), v + ".java");
34  
    saveTextFile(javaFile, join(tok));
35  
    print("ok, made " + javaFile.getAbsolutePath());
36  
    
37  
    print("Now compiling. Making a compiler bot just for the occasion.");
38  
    S botQuestion = format("Please compile this Java text: * for java version *", join(tok), javaTarget);
39  
    print("Question to bot: " + shorten(botQuestion, 200));
40  
    print("..." + takeLast(botQuestion, 200));
41  
    print("Parses? " + match3("Please compile this Java text: * for java version *", botQuestion));
42  
    
43  
    Class compilerBot = hotwireDependent(compilerBotID);
44  
    // We should initialize it or so... we're being lazy here. Works for now.
45  
    S answer = cast call(compilerBot, "answer", botQuestion);
46  
    print("Bot said: " + answer);
47  
    if (answer == null) fail();
48  
    new Matches m;
49  
    if (!match3("ok, *", answer, m))
50  
      if (match3("Compile error", answer))
51  
        fail("Compile Error.");
52  
      else
53  
        fail("I don't understand the bot, exiting");
54  
      
55  
    S classesDir = unquote(m.m[0]);
56  
    print("I think the classes dir is: " + classesDir);
57  
    if (!new File(classesDir).isDirectory()) fail("huh?");
58  
    
59  
    long transpilationDate = parseFirstLong(replace(jextract("myTranspilationDate_value = *", tok), "L", ""));
60  
    saveTextFile(new File(classesDir, "transpilationDate"), strOrNull(transpilationDate));
61  
62  
    print("Now making jar.");
63  
    File ecj = loadLibrary(ecjSnippetID);
64  
    
65  
    FileOutputStream fout = new FileOutputStream(jarFile);
66  
    ZipOutputStream zout = new ZipOutputStream(fout);
67  
    zout.setLevel(compressionLevel);
68  
    
69  
    makeManifestWithMainClass(zout, v);
70  
    dir2zip_recurse(new File(classesDir), zout);
71  
    zip2zip_exceptManifest(ecj, zout);
72  
    zout.close();
73  
    fout.close();
74  
    
75  
    print("ok, made " + jarFile.getAbsolutePath() + " (" + jarFile.length() + " bytes)");
76  
    
77  
    copyFile(jarFile, deployedFile);
78  
    print("Deployed to " + deployedFile.getAbsolutePath());
79  
    S newMD5 = md5(deployedFile);
80  
    if (eq(oldMD5, newMD5))
81  
      print("File unchanged.");
82  
    else
83  
      print("File changed. New MD5: " + newMD5);
84  
    
85  
    print();
86  
    setConsoleTitle(infoBoxAndReturn("JavaX successfully updated!"));
87  
  }
88  
  if (isMain() && !headless()) {
89  
    sleepSeconds(5);
90  
    cleanKill();
91  
  }
92  
}

Author comment

Began life as a copy of #1001601

download  show line numbers  debug dex  old transpilations   

Travelled to 36 computer(s): aoiabmzegqzx, aqvamacmveew, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, dhtvkmknsjym, djztyncnmsck, ekrmjmnbrukm, etmzoiygucik, gwrvuhgaqvyk, hpgrupgrauku, hszllmzzlmie, imzmzdywqqli, irmadwmeruwu, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, nzrhlmtlsyqh, onxytkatvevr, ppjhyzlbdabe, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, snaazhdonpnp, teubizvjbppd, triorysbatvj, tslmcundralx, tvejysmllsmz, vdyxwxlmubrt, vouqrxazstgt, vpdwwinrgdga, wtqryiryparv, ychswryhhvyu, ymdyxumozjwr

No comments. add comment

Snippet ID: #1001639
Snippet name: Update JavaX! [deploys into {userhome}/.javax]
Eternal ID of this version: #1001639/37
Text MD5: a5689664fb8bf7cfc290887bff6f9241
Transpilation MD5: fa252fd561b75ccd5b10162ea3c50bb9
Author: stefan
Category: javax
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-04-30 15:36:19
Source code size: 3460 bytes / 92 lines
Pitched / IR pitched: No / No
Views / Downloads: 646 / 5432
Version history: 36 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1001639 & http://1001639.tinybrain.de