sclass ProgramPackager { File jarFile; S mainProgramID; S mainClassName; Set excludeSnippets; Cl extraSnippets; // setting this to false currently breaks everything because transpilation MD5s are no longer available bool includeSources = true; bool includeBinaries = false; bool includeCompiler = true; VF1 copyAdditionalFiles = voidfunc(ZipOutputStream jar) { file2zip(jar, programFile("gazelle-concepts.zip")); }; *(File *jarFile, S *mainProgramID, S *mainClassName) {} *(File *jarFile, S *mainProgramID) { mainClassName = tok_mainClassNameFromJavaXSnippet(mainProgramID); //assertNotNull("Please set mainClassName in " + mainProgramID, mainClassName); if (mainClassName == null) mainClassName = "main"; } Set snippetIDs; Map> trace; void go ctex { Pair programJarAndSrc = CompilerBot.compileSnippet2(mainProgramID); if (snippetIDs == null) { temp IProgressShower p = tempProgressBar("Collecting dependencies", 100); trace = new Map; snippetIDs = recursivelyCollectSnippetIDsFromTranspiled_multi( itemPlusList(mainProgramID, extraSnippets), trace_out := minimalNotifyingMap(trace, r { p.setValue(l(trace)); }), exclude := excludeSnippets); } temp IProgressShower p = tempProgressBar("JAR", or_nonZeroLong(fileSize(jarFile), megabytes(30))); { temp ZipOutputStream jar = zipOutputStream(jarFile); temp tempShowFileSizeProgress(p, jarFile); makeManifestWithMainClass(jar, mainClassName); zip2zip_exceptManifest2(programJarAndSrc.a, jar, // exclude those: litset("main.java")); zip_addTextFile(jar, "back-references.txt", renderMap_colon_lines(reverseMultiMap_tree(pseudoToRealMultiMap(trace)).data)); SS titles = getSnippetTitles_cached(snippetIDs); zip_addTextFile(jar, "snippet-titles.struct", indentedStruct(titles)); new TreeMap types; for (S snippetID : snippetIDs) { continue if isPseudoSnippetID(snippetID); int type = getSnippetType(snippetID); types.put(snippetID, type); if (type == snippetType_image()) { File img = loadLibrary(snippetID); addFileToZip(jar, img, psI(snippetID) + "." + (isGIF(img) ? "gif" : "png")); } else if (type == snippetType_data()) addFileToZip(jar, loadLibrary(snippetID), psI(snippetID) + ".bin"); else pcall { S text = loadSnippet(snippetID); if (text != null) zip_addTextFile(jar, psI(snippetID) + ".text", text); if (isJavaxCompilableSnippetTypeExceptInclude(type)) { if (includeSources) { S transpilation = getServerTranspiled2(snippetID); zip_addTextFile(jar, psI(snippetID) + ".transpiled", transpilation); } if (includeBinaries && !sameSnippetID(snippetID, mainProgramID)) { File snippetJar = pairA(hotwire_compile(snippetID)); print("Adding binary: " + snippetID + " / " + f2s(snippetJar)); file2zip(jar, snippetJar); } } } } //S typeStruct = indentedStruct(types); S typeStruct = "tm{\n" + mapToLines(types, (snippetID, type) -> " " + quote(snippetID) + "=" + type + ", // " + snippetTypeName(type)) + "}"; zip_addTextFile(jar, "snippet-types.struct", typeStruct); File javaxJar = pathToJavaxJar(); print("Copying: " + javaxJar); if (!includeCompiler) zip2zip_withPredicate(javaxJar, jar, s -> !startsWithOneOf(s, "META-INF/", "org/eclipse/") && !eq(s, "transpilationDate")); else zip2zip_exceptManifest2(javaxJar, jar, litset("transpilationDate")); callF(copyAdditionalFiles, jar); } // jar close makeExecutable(jarFile); fileSavedInfoBox(jarFile); } }