Download Jar. Uses 3310K of libraries. Click here for Pure Java version (18608L/116K).
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 | // jar file => null (not used yet) |
11 | static new SerializeComputations<File, Void> packagingComputations; |
12 | |
13 | static File compileSrcLib(S srcLibID) { |
14 | new CompilerBot2 subBot; |
15 | subBot.dontCompile = true; |
16 | ret assertFileExists(subBot.compileSnippet(srcLibID)); |
17 | } |
18 | |
19 | static Lock lock = lock(); |
20 | |
21 | html { |
22 | // lock lock; // now using SerializeComputations |
23 | |
24 | uri = dropPrefixSlash(uri); |
25 | S snippetID = fsI(uri); |
26 | if (!isSnippetPublic(snippetID)) fail("Snippet not public: " + snippetID); |
27 | S transpiledSrc = getServerTranspiled2(snippetID); |
28 | |
29 | // md5 check (if parameter supplied) |
30 | |
31 | S md5 = params.get('md5); |
32 | S srcMD5 = md5(transpiledSrc); |
33 | if (md5 != null && !eq(md5, srcMD5)) ret "md5 mismatch"; |
34 | bool forceCompilation = eq(params.get("forceCompilation"), "1"); |
35 | S mainClassForManifest = params.get("mainClassForManifest"); |
36 | |
37 | File jar; |
38 | try { |
39 | jar = computations.get(srcMD5/*, snippetID)*/, -> { |
40 | print("Entering compilation (forceCompilation=" + forceCompilation + ")"); |
41 | new CompilerBot2 bot; |
42 | //bot.mainClassForManifest = mainClassForManifest; |
43 | bot.useRenaming = !sameSnippetID(snippetID, #1001638); |
44 | bot.forceCompilation = forceCompilation; |
45 | bot.compileSrcLib = lambda1 compileSrcLib; |
46 | ret bot.compileSnippet(snippetID); |
47 | }); |
48 | } catch print e { |
49 | // dexcompile.php can't handle code 500 |
50 | ret /*subBot_serve500*/("Error. " + e); |
51 | } |
52 | |
53 | bool forceRepackage = eq("1", params.get("repackage")); |
54 | bool withLibs = eq("1", params.get("withLibs")); |
55 | bool noCompiler = eq("1", params.get("noCompiler")); |
56 | bool withX30 = eq("1", params.get("withX30")); |
57 | bool x30UtilOnly = eq("1", params.get("x30UtilOnly")); |
58 | bool noSrc = eq("1", params.get("noSrc")); |
59 | bool dynamicObjectOnly = eq("dynamicObjectOnly", params.get("mode")); |
60 | // currently unsupported |
61 | //bool uncompressed = eq("1", params.get("uncompressed")); |
62 | S nameForDelivery = params.get("name"); |
63 | S fileToExtract = params.get("fileToExtract"); |
64 | |
65 | L<Map> existingFilesJSON = (L) jsonDecode(params.get("existingFiles")); |
66 | S existingFilesComp = params.get("existingFilesComp"); |
67 | if (nempty(existingFilesComp)) |
68 | existingFilesJSON = (L) jsonDecode(gunzipToText(base64decode(existingFilesComp))); |
69 | |
70 | File jar2 = jar; |
71 | if (withLibs) jar2 = appendToBaseFileName(jar2, ".with-libs"); |
72 | if (noCompiler) jar2 = appendToBaseFileName(jar2, ".no-compiler"); |
73 | if (dynamicObjectOnly) jar2 = appendToBaseFileName(jar2, ".dynamicObjectOnly"); |
74 | if (noSrc) jar2 = appendToBaseFileName(jar2, ".noSrc"); |
75 | //if (uncompressed) jar2 = appendToBaseFileName(jar2, ".uncomp"); |
76 | |
77 | bool withSrc = !noSrc; |
78 | |
79 | IPred<S> generalFileFilter = f -> |
80 | (withSrc || !endsWith(f, ".java")) |
81 | && !startsWithOneOf(f, "META-INF/versions/", "META-INF/LICENSE"); // see flatlaf jar |
82 | |
83 | if (!eq(jar, jar2)) { |
84 | lock lock; |
85 | |
86 | print(+jar2); |
87 | |
88 | if (fileLength(jar2) <= 22 || forceRepackage) { |
89 | print("Repackaging."); |
90 | |
91 | for (File f : listFilesStartingWith(fileNameWithoutExtension(jar) + ".", dirOfFile(jar))) { |
92 | if (!eq(f, jar)) |
93 | deleteFileVerbose(f); |
94 | } |
95 | |
96 | File tempZip = createTempFileWithExtension(".zip"); |
97 | { |
98 | temp tempZipOut = zipOutputStream(tempZip); |
99 | text2zip(tempZipOut, "source.txt", |
100 | renderColonProperties( |
101 | jar := f2s(jar2), |
102 | packagingDate := dateWithSecondsUTC())); |
103 | if (nempty(mainClassForManifest)) |
104 | text2zip(tempZipOut, manifestPathInJar(), manifestTextForMainClass(mainClassForManifest)); |
105 | } |
106 | |
107 | temp Zip2Zip_Zip4j z2z = new(jar2); |
108 | |
109 | z2z.inZip = tempZip; |
110 | z2z.run(); |
111 | |
112 | z2z.inZip = jar; |
113 | z2z.predicate = generalFileFilter; |
114 | /*if (uncompressed) z2z.modifyZipEntry = e -> { |
115 | e.setMethod(ZipOutputStream.STORED); |
116 | e.setCompressedSize(e.getSize()); |
117 | };*/ |
118 | z2z.run(); |
119 | |
120 | if (withLibs) { |
121 | Pair<S, LS> srcAndLibs = extractLibsFromTranspilation(transpiledSrc); |
122 | fOr (S libID : srcAndLibs.b) { |
123 | File fixer = compilerBotDestDir("fixer" + psI(libID) + ".jar"); |
124 | |
125 | if (fileExists(fixer)) { |
126 | println("APPLYING FIXER: " + fixer); |
127 | z2z.inZip = fixer; |
128 | z2z.predicate = null; |
129 | z2z.run(); |
130 | } |
131 | |
132 | z2z.inZip = loadLibraryOrSrcLib(libID, lambda1 compileSrcLib); |
133 | z2z.run(); |
134 | } |
135 | } |
136 | |
137 | z2z.inZip = pathToJavaxJar(); |
138 | |
139 | if (withX30) { |
140 | z2z.predicate = null; |
141 | z2z.run(); |
142 | } else if (x30UtilOnly) { |
143 | z2z.predicate = name -> startsWithOneOf(name, "x30_pkg"); |
144 | z2z.run(); |
145 | } else if (noCompiler) { |
146 | z2z.predicate = name -> ! |
147 | startsWithOneOf(name, "org/eclipse/", "META-INF/", "ecj.", "about.html"); |
148 | z2z.run(); |
149 | } else if (dynamicObjectOnly) { |
150 | z2z.predicate = name -> contains(name, "DynamicObject"); |
151 | z2z.run(); |
152 | } |
153 | |
154 | z2z.finish(); |
155 | } |
156 | |
157 | jar = jar2; |
158 | } |
159 | |
160 | if (nempty(existingFilesJSON)) { |
161 | lock lock; |
162 | print(+jar); |
163 | L<Map> newFingerprints = zipFileToJSONFingerprint_md5(jar); |
164 | new SS map; |
165 | for (Map m : existingFilesJSON) |
166 | map.put((S) m.get("name"), (S) m.get("md5")); |
167 | |
168 | jar2 = createTempFile("partial", ".jar"); |
169 | { |
170 | temp ZipOutputStream outJar = zipOutputStream(jar2); |
171 | temp ZipFile jarIn = new ZipFile(jar); |
172 | new LS toKeep; |
173 | for (Map fp : newFingerprints) { |
174 | S name = (S) fp.get("name"); |
175 | S oldMD5 = map.get(name); |
176 | if (!eq(oldMD5, fp.get("md5"))) { |
177 | outJar.putNextEntry(new ZipEntry(name)); |
178 | ZipEntry entry = jarIn.getEntry(name); |
179 | copyStreamAndCloseInput(jarIn.getInputStream(entry), outJar); |
180 | } else |
181 | toKeep.add(name); |
182 | } |
183 | text2zip(outJar, "to-keep", lines_rtrim(toKeep)); |
184 | } |
185 | |
186 | jar = jar2; |
187 | } |
188 | |
189 | if (forceRepackage) |
190 | sendToSnippetUpdatesBot("/transpileOK/" + psI(snippetID)); |
191 | |
192 | print("Serving jar for " + snippetID + ": " + renderFileInfo(jar)); |
193 | if (eq(params.get("makeJarOnly"), "1")) |
194 | ret "OK: " + f2s(jar); |
195 | else if (nempty(fileToExtract)) { |
196 | // serve one file out of jar file |
197 | ret "TODO"; |
198 | } else |
199 | // serve the whole jar file |
200 | ret subBot_serveFileWithName(jar, |
201 | or2(nameForDelivery, psI(snippetID) + ".jar"), |
202 | "application/java-archive"); |
203 | } |
Began life as a copy of #1018308
download show line numbers debug dex old transpilations
Travelled to 9 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1020140 |
Snippet name: | Jar Web Bot [LIVE at botcompany.de/jar] |
Eternal ID of this version: | #1020140/105 |
Text MD5: | fb1f93c60ad367ab74404915e49bf608 |
Transpilation MD5: | 4e1b3f491f8e124067c8a5bdbcc3d41e |
Author: | stefan |
Category: | javax / web |
Type: | JavaX module (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-05-12 18:33:33 |
Source code size: | 6837 bytes / 203 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 953 / 3154 |
Version history: | 104 change(s) |
Referenced in: | [show references] |