Download Jar. Uses 3106K of libraries. Click here for Pure Java version (14240L/87K).
1 | !7 |
2 | |
3 | sS standardCredentials() { ret ""; } // public snippets only |
4 | |
5 | // (transpilation md5, snippetID) => jar file |
6 | //static new SerializeComputations<PairS, File> computations; |
7 | // transpilation md5 => jar file |
8 | static new SerializeComputations<S, File> computations; |
9 | |
10 | static File compileSrcLib(S srcLibID) { |
11 | new CompilerBot2 subBot; |
12 | subBot.dontCompile = true; |
13 | ret assertFileExists(subBot.compileSnippet(srcLibID)); |
14 | } |
15 | |
16 | static Lock lock = lock(); |
17 | |
18 | html { |
19 | // lock lock; // now using SerializeComputations |
20 | |
21 | uri = dropPrefixSlash(uri); |
22 | S snippetID = fsI(uri); |
23 | if (!isSnippetPublic(snippetID)) fail("Snippet not public: " + snippetID); |
24 | S transpiledSrc = getServerTranspiled2(snippetID); |
25 | |
26 | // md5 check (if parameter supplied) |
27 | |
28 | S md5 = params.get('md5); |
29 | S srcMD5 = md5(transpiledSrc); |
30 | if (md5 != null && !eq(md5, srcMD5)) ret "md5 mismatch"; |
31 | bool forceCompilation = eq(params.get("forceCompilation"), "1"); |
32 | |
33 | File jar; |
34 | try { |
35 | jar = computations.get(srcMD5/*, snippetID)*/, -> { |
36 | print("Entering compilation (forceCompilation=" + forceCompilation + ")"); |
37 | new CompilerBot2 bot; |
38 | bot.useRenaming = !sameSnippetID(snippetID, #1001638); |
39 | bot.forceCompilation = forceCompilation; |
40 | bot.compileSrcLib = lambda1 compileSrcLib; |
41 | ret bot.compileSnippet(snippetID); |
42 | }); |
43 | } catch print e { |
44 | // dexcompile.php can't handle code 500 |
45 | ret /*subBot_serve500*/("Error. " + e); |
46 | } |
47 | |
48 | bool forceRepackage = eq("1", params.get("repackage")); |
49 | bool withLibs = eq("1", params.get("withLibs")); |
50 | bool noCompiler = eq("1", params.get("noCompiler")); |
51 | bool withX30 = eq("1", params.get("withX30")); |
52 | bool x30UtilOnly = eq("1", params.get("x30UtilOnly")); |
53 | bool noSrc = eq("1", params.get("noSrc")); |
54 | bool dynamicObjectOnly = eq("dynamicObjectOnly", params.get("mode")); |
55 | bool uncompressed = eq("1", params.get("uncompressed")); |
56 | S nameForDelivery = params.get("name"); |
57 | |
58 | L<Map> existingFilesJSON = (L) jsonDecode(params.get("existingFiles")); |
59 | S existingFilesComp = params.get("existingFilesComp"); |
60 | if (nempty(existingFilesComp)) |
61 | existingFilesJSON = (L) jsonDecode(gunzipToText(base64decode(existingFilesComp))); |
62 | |
63 | File jar2 = jar; |
64 | if (withLibs) jar2 = appendToBaseFileName(jar2, ".with-libs"); |
65 | if (noCompiler) jar2 = appendToBaseFileName(jar2, ".no-compiler"); |
66 | if (dynamicObjectOnly) jar2 = appendToBaseFileName(jar2, ".dynamicObjectOnly"); |
67 | if (noSrc) jar2 = appendToBaseFileName(jar2, ".noSrc"); |
68 | if (uncompressed) jar2 = appendToBaseFileName(jar2, ".uncomp"); |
69 | |
70 | bool withSrc = !noSrc; |
71 | |
72 | IPred<S> generalFileFilter = f -> |
73 | (withSrc || !endsWith(f, ".java")) |
74 | && !startsWithOneOf(f, "META-INF/versions/", "META-INF/LICENSE"); // see flatlaf jar |
75 | |
76 | if (!eq(jar, jar2)) { |
77 | lock lock; |
78 | |
79 | if (fileLength(jar2) <= 22 || forceRepackage) { |
80 | temp var jarOut = zipOutputStream(jar2); |
81 | new Set<S> entries; |
82 | |
83 | text2zip(jarOut, "source.txt", |
84 | renderColonProperties( |
85 | jar := f2s(jar2), |
86 | packagingDate := dateWithSecondsUTC())); |
87 | |
88 | Zip2Zip_b z2z = new(jar, jarOut, entries); |
89 | z2z.predicate = generalFileFilter; |
90 | if (uncompressed) z2z.modifyZipEntry = e -> { |
91 | e.setMethod(ZipOutputStream.STORED); |
92 | e.setCompressedSize(e.getSize()); |
93 | }; |
94 | z2z.run(); |
95 | |
96 | if (withLibs) { |
97 | Pair<S, LS> srcAndLibs = extractLibsFromTranspilation(transpiledSrc); |
98 | fOr (S libID : srcAndLibs.b) { |
99 | File fixer = compilerBotDestDir("fixer" + psI(libID) + ".jar"); |
100 | |
101 | if (fileExists(fixer)) { |
102 | println("APPLYING FIXER: " + fixer); |
103 | z2z.inZip = fixer; |
104 | z2z.predicate = null; |
105 | z2z.run(); |
106 | } |
107 | |
108 | z2z.inZip = loadLibraryOrSrcLib(libID, lambda1 compileSrcLib); |
109 | z2z.run(); |
110 | } |
111 | } |
112 | |
113 | z2z.inZip = pathToJavaxJar(); |
114 | |
115 | if (withX30) { |
116 | z2z.predicate = null; |
117 | z2z.run(); |
118 | } else if (x30UtilOnly) { |
119 | z2z.predicate = name -> startsWithOneOf(name, "x30_pkg"); |
120 | z2z.run(); |
121 | } else if (noCompiler) { |
122 | z2z.predicate = name -> ! |
123 | startsWithOneOf(name, "org/eclipse/", "META-INF/", "ecj.", "about.html"); |
124 | z2z.run(); |
125 | } else if (dynamicObjectOnly) { |
126 | z2z.predicate = name -> contains(name, "DynamicObject"); |
127 | z2z.run(); |
128 | } |
129 | } |
130 | |
131 | jar = jar2; |
132 | } |
133 | |
134 | if (nempty(existingFilesJSON)) { |
135 | L<Map> newFingerprints = zipFileToJSONFingerprint_md5(jar); |
136 | new SS map; |
137 | for (Map m : existingFilesJSON) |
138 | map.put((S) m.get("name"), (S) m.get("md5")); |
139 | |
140 | jar2 = createTempFile("partial", ".jar"); |
141 | { |
142 | temp ZipOutputStream outJar = zipOutputStream(jar2); |
143 | temp ZipFile jarIn = new ZipFile(jar); |
144 | new LS toKeep; |
145 | for (Map fp : newFingerprints) { |
146 | S name = (S) fp.get("name"); |
147 | S oldMD5 = map.get(name); |
148 | if (!eq(oldMD5, fp.get("md5"))) { |
149 | outJar.putNextEntry(new ZipEntry(name)); |
150 | ZipEntry entry = jarIn.getEntry(name); |
151 | copyStreamAndCloseInput(jarIn.getInputStream(entry), outJar); |
152 | } else |
153 | toKeep.add(name); |
154 | } |
155 | text2zip(outJar, "to-keep", lines_rtrim(toKeep)); |
156 | } |
157 | |
158 | jar = jar2; |
159 | } |
160 | |
161 | if (forceRepackage) |
162 | sendToSnippetUpdatesBot("/transpileOK/" + psI(snippetID)); |
163 | |
164 | print("Serving jar for " + snippetID + ": " + renderFileInfo(jar)); |
165 | if (eq(params.get("makeJarOnly"), "1")) |
166 | ret "OK: " + f2s(jar); |
167 | else |
168 | ret subBot_serveFileWithName(jar, |
169 | or2(nameForDelivery, psI(snippetID) + ".jar"), |
170 | "application/java-archive"); |
171 | } |
Began life as a copy of #1020140
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): bhatertpkbcr, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1034361 |
Snippet name: | Jar Web Bot [backup before zip4j] |
Eternal ID of this version: | #1034361/1 |
Text MD5: | a3899d06413ccf321ff278ab4810c48f |
Transpilation MD5: | 83e26c6d190068cd737c0e75aa574091 |
Author: | stefan |
Category: | javax / web |
Type: | JavaX module (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-02-03 07:07:50 |
Source code size: | 5816 bytes / 171 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 240 / 701 |
Referenced in: | [show references] |