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).

!7

static S v = "x30";
static S sourceID = "#1001638";
static S javaTarget = "1.8"; // compile JavaX for everyone
static S ecjSnippetID = #1400467; // #1400153; // #1400052; // #1011501; // #1008795; // #1001164; // ecj.zip

static S compilerBotID = "#1001155";
static int compressionLevel = 9; // Zip compression - highest level

set flag hotwire_here.

p {
  loading "Updating JavaX!" {
    sendToAllVMs("prepare for javax upgrade");
    
    File jarFile = new File(programDir(), v + ".jar");
    File deployedFile = new File(userHome(), ".javax/" + jarFile.getName());
    
    S oldMD5 = deployedFile == null ? null : md5(deployedFile);
    if (oldMD5 != null) print("Current md5: " + oldMD5);
    
    S s = loadPage(tb_mainServer() + "/tb-int/get-transpiled.php?id=" + parseSnippetID(sourceID) + "&raw=1&withlibs=1");
    S libs = firstLine(s);
    s = dropFirstLine(s);
    
    s += x30_makeUtilsSource();
    
    saveProgramTextFile("raw.java", s);
    L<S> tok = javaTok(s);
    // TODO: generate & compile DynamicMethods.java
    javax_prepareX30SourceForDeployment(tok);
    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 = format("Please compile this Java text: * for java version *", join(tok), javaTarget);
    print("Question to bot: " + shorten(botQuestion, 200));
    print("..." + takeLast(botQuestion, 200));
    print("Parses? " + match3("Please compile this Java text: * for java version *", botQuestion));
    
    Class compilerBot = hotwireDependent(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?");
    
    long transpilationDate = parseFirstLong(replace(jextract("myTranspilationDate_value = *", tok), "L", ""));
    saveTextFile(new File(classesDir, "transpilationDate"), strOrNull(transpilationDate));

    print("Now making jar.");
    File ecj = loadLibrary(ecjSnippetID);
    
    FileOutputStream fout = new FileOutputStream(jarFile);
    ZipOutputStream zout = new ZipOutputStream(fout);
    zout.setLevel(compressionLevel);
    
    makeManifestWithMainClass(zout, v);
    dir2zip_recurse(new File(classesDir), zout);
    zip2zip_exceptManifest(ecj, zout);
    zout.close();
    fout.close();
    
    print("ok, made " + jarFile.getAbsolutePath() + " (" + jarFile.length() + " bytes)");
    
    copyFile(jarFile, deployedFile);
    print("Deployed to " + deployedFile.getAbsolutePath());
    S newMD5 = md5(deployedFile);
    if (eq(oldMD5, newMD5))
      print("File unchanged.");
    else
      print("File changed. New MD5: " + newMD5);
    
    print();
    setConsoleTitle(infoBoxAndReturn("JavaX successfully updated!"));
  }
  if (isMain() && !headless()) {
    sleepSeconds(5);
    cleanKill();
  }
}

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: 645 / 5430
Version history: 36 change(s)
Referenced in: #1000825 #1001677 #1005033 #1006316 #1006696 #1006722 #1009247 #1009791 #1010517 #1011537 #1013640 #1016058 #1016442 #1016582 #1022688 #1024922 #3000190 #3000195 #3000196 #3000197 #3000198 #3000199 #3000200 #3000201 #3000202 #3000238 #3000382 #3000383

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