!7 static S v = "x30"; static S sourceID = "#1001638"; static S javaTarget = "1.6"; // compile JavaX for everyone static S ecjSnippetID = #1011501; // #1008795; // #1001164; // ecj.zip static S compilerBotID = "#1001155"; static int compressionLevel = 9; // Zip compression - highest level 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("http://tinybrain.de:8080/tb-int/get-transpiled.php?id=" + parseSnippetID(sourceID) + "&raw=1&withlibs=1"); S libs = firstLine(s); s = dropFirstLine(s); saveProgramTextFile("raw.java", s); L tok = javaTok(s); renameToken(tok, "StringFunc", "StrF"); for (L c : allClasses(tok)) { S name = getClassDeclarationName(c); if (name.equals("main")) clearAllTokens(c); else if (name.equals(v) && !c.get(1).equals("public")) c.set(1, "public " + c.get(1)); } 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 = "Please compile this Java text: " + quote(join(tok)) + " for java version " + quote(javaTarget); print("Question to bot: " + shorten(botQuestion, 200)); //print("Parses? " + match3("Please compile this Java text: *", botQuestion)); Class compilerBot = hotwire(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?"); print("Now making jar."); File ecj = loadLibrary(ecjSnippetID); FileOutputStream fout = new FileOutputStream(jarFile); ZipOutputStream zout = new ZipOutputStream(fout); zout.setLevel(compressionLevel); makeManifest(zout); dir2zip(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(print("JavaX successfully updated!")); }} static void makeManifest(ZipOutputStream outZip) ctex { outZip.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF")); outZip.write(toUtf8("Manifest-Version: 1.0\n" + "Main-Class: " + v + "\n\n")); }