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 | html { |
17 | // lock lock; // now using SerializeComputations |
18 | |
19 | uri = dropPrefixSlash(uri); |
20 | S snippetID = fsI(uri); |
21 | if (!isSnippetPublic(snippetID)) fail("Snippet not public: " + snippetID); |
22 | S transpiledSrc = getServerTranspiled2(snippetID); |
23 | |
24 | // md5 check (if parameter supplied) |
25 | |
26 | S md5 = params.get('md5); |
27 | S srcMD5 = md5(transpiledSrc); |
28 | if (md5 != null && !eq(md5, srcMD5)) ret "md5 mismatch"; |
29 | bool forceCompilation = eq(params.get("forceCompilation"), "1"); |
30 | |
31 | File jar; |
32 | try { |
33 | jar = computations.get(srcMD5/*, snippetID)*/, -> { |
34 | print("Entering compilation (forceCompilation=" + forceCompilation + ")"); |
35 | new CompilerBot2 bot; |
36 | bot.forceCompilation = forceCompilation; |
37 | bot.compileSrcLib = lambda1 compileSrcLib; |
38 | ret bot.compileSnippet(snippetID); |
39 | }); |
40 | } catch print e { |
41 | // dexcompile.php can't handle code 500 |
42 | ret /*subBot_serve500*/("Error. " + e); |
43 | } |
44 | |
45 | bool forceRepackage = eq("1", params.get("repackage")); |
46 | bool withLibs = eq("1", params.get("withLibs")); |
47 | bool noCompiler = eq("1", params.get("noCompiler")); |
48 | bool withX30 = eq("1", params.get("withX30")); |
49 | bool noSrc = eq("1", params.get("noSrc")); |
50 | bool dynamicObjectOnly = eq("dynamicObjectOnly", params.get("mode")); |
51 | bool uncompressed = eq("1", params.get("uncompressed")); |
52 | |
53 | File jar2 = jar; |
54 | if (withLibs) jar2 = appendToBaseFileName(jar2, ".with-libs"); |
55 | if (noCompiler) jar2 = appendToBaseFileName(jar2, ".no-compiler"); |
56 | if (dynamicObjectOnly) jar2 = appendToBaseFileName(jar2, ".dynamicObjectOnly"); |
57 | if (noSrc) jar2 = appendToBaseFileName(jar2, ".noSrc"); |
58 | if (uncompressed) jar2 = appendToBaseFileName(jar2, ".uncomp"); |
59 | |
60 | bool withSrc = !noSrc; |
61 | |
62 | IPred<S> generalFileFilter = f -> |
63 | (withSrc || !endsWith(f, ".java")) |
64 | && !startsWith(f, "META-INF/versions/"); // see flatlaf jar |
65 | |
66 | if (!eq(jar, jar2)) { |
67 | if (fileLength(jar2) <= 22 || forceRepackage) { |
68 | temp var jarOut = zipOutputStream(jar2); |
69 | if (uncompressed) jarOut.setMethod(ZipOutputStream.STORED); |
70 | new Set<S> entries; |
71 | |
72 | text2zip(jarOut, "source.txt", f2s(jar2)); |
73 | |
74 | zip2zip_collectFiles(jar, jarOut, entries, generalFileFilter); |
75 | |
76 | if (withLibs) { |
77 | Pair<S, LS> srcAndLibs = extractLibsFromTranspilation(transpiledSrc); |
78 | fOr (S libID : srcAndLibs.b) { |
79 | File fixer = compilerBotDestDir("fixer" + psI(libID) + ".jar"); |
80 | |
81 | if (fileExists(fixer)) { |
82 | println("APPLYING FIXER: " + fixer); |
83 | zip2zip_collectFiles(fixer, jarOut, entries); |
84 | } |
85 | |
86 | zip2zip_collectFiles(loadLibraryOrSrcLib(libID, lambda1 compileSrcLib), jarOut, entries, generalFileFilter); |
87 | } |
88 | } |
89 | |
90 | if (withX30) |
91 | zip2zip_collectFiles(pathToJavaxJar(), jarOut, entries); |
92 | else if (noCompiler) |
93 | zip2zip_collectFiles(pathToJavaxJar(), jarOut, entries, name -> ! |
94 | startsWithOneOf(name, "org/eclipse/", "META-INF/")); |
95 | else if (dynamicObjectOnly) |
96 | zip2zip_collectFiles(pathToJavaxJar(), jarOut, entries, name -> contains(name, "DynamicObject")); |
97 | } |
98 | |
99 | jar = jar2; |
100 | } |
101 | |
102 | print("Serving jar for " + snippetID + ": " + renderFileInfo(jar)); |
103 | if (eq(params.get("makeJarOnly"), "1")) |
104 | ret "OK: " + f2s(jar); |
105 | else |
106 | ret subBot_serveFileWithName(jar, psI(snippetID) + ".jar", "application/java-archive"); |
107 | } |
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: | #1033736 |
Snippet name: | Jar Web Bot backup |
Eternal ID of this version: | #1033736/1 |
Text MD5: | 73ee5e9be183bc0d2ce732daa07a4b8b |
Author: | stefan |
Category: | javax / web |
Type: | JavaX module (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-12-31 21:25:28 |
Source code size: | 3932 bytes / 107 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 301 / 494 |
Referenced in: | [show references] |