!7 static S v = "x30"; static S sourceID = "#1001638"; static S javaTarget = "1.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 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(); } }