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

!7

static S v = "x30";
static S sourceID = "#1001638";
static S javaTarget = "11"; // now using Java 11 for "var" keyword
static S ecjSnippetID = #1400533;  // ecj compiler to be bundled into x30.jar
  // #1400467

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 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: 899 / 6643
Version history: 38 change(s)
Referenced in: #1000825 - JavaX Starter - Runnables search, v3 (CURRENT)
#1001638 - x30.java (JavaX) - packaged by #1001639
#1001677 - startMultiPort
#1005033 - Find all inner classes of main in running program
#1006316 - JavaX Starter - Runnables search (dev.)
#1006696 - myClasses - get names of all classes declared in running program (even those not loaded yet)
#1006722 - Transpiler Translator for #759
#1009247 - upgradeJavaX
#1009791 - infoBox_pleaseUpgradeJavaX
#1010517 - replaceConsoleInputWithAutoComboBox - experimental
#1011537 - upgradeJavaXAndRestart
#1013640 - upgradeJavaXAndContinue
#1016058 - Make Stefan's OS Starter ["Stefans-OS.jar", OK]
#1016442 - System Version
#1016582 - Global Utils (stuff in here gets moved to x30_pkg.x30_util.*)
#1022688 - Package Dialog Kit
#1024922 - programPackager_standardExcludedSnippets
#1032684 - #759 transpilation backup
#1033636 - Gazelle 22 Standalone [stable version]
#3000190 - Answer for stefanreich(>> t 20 questions)
#3000195 - Answer for stefanreich (>> y)
#3000196 - Answer for stefanreich (>> y)
#3000197 - Answer for stefanreich (>> program data sizes)
#3000198 - Answer for stefanreich (>> program data sizes)
#3000199 - Answer for stefanreich (>> program data sizes)
#3000200 - Answer for stefanreich (>> program data sizes)
#3000201 - Answer for stefanreich (>> list all files)
#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)