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

93
LINES

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

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

Download Jar. Libraryless. Click here for Pure Java version (18173L/119K).

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

Author comment

Began life as a copy of #1001601

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1001639
Snippet name: Update JavaX! [deploys into {userhome}/.javax]
Eternal ID of this version: #1001639/39
Text MD5: c510751dd676e8c09bdaecfc138b5f0d
Transpilation MD5: 05e80ce36d4bcc5d7acb58c1c002d2a6
Author: stefan
Category: javax
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-30 16:54:11
Source code size: 3451 bytes / 93 lines
Pitched / IR pitched: No / No
Views / Downloads: 1082 / 6959
Version history: 38 change(s)
Referenced in: [show references]