Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

92
LINES

< > BotCompany Repo | #1033537 // Jar Web Bot [backup]

JavaX module (desktop) [tags: use-pretranspiled]

Download Jar. Libraryless. Click here for Pure Java version (12427L/76K).

1  
!7
2  
3  
sS defaultJavaTarget = "1.11";
4  
5  
sS standardCredentials() { ret ""; } // public snippets only
6  
7  
// (transpilation md5, snippetID) => jar file
8  
//static new SerializeComputations<PairS, File> computations;
9  
// transpilation md5 => jar file
10  
static new SerializeComputations<S, File> computations;
11  
12  
html {
13  
  // lock lock; // now using SerializeComputations
14  
  
15  
  uri = dropPrefixSlash(uri);
16  
  S snippetID = fsI(uri);
17  
  if (!isSnippetPublic(snippetID)) fail("Snippet not public: " + snippetID);
18  
  S transpiledSrc = getServerTranspiled2(snippetID);
19  
  
20  
  // md5 check (if parameter supplied)
21  
  
22  
  S md5 = params.get('md5);
23  
  S srcMD5 = md5(transpiledSrc);
24  
  if (md5 != null && !eq(md5, srcMD5)) ret "md5 mismatch";
25  
  
26  
  File jar = computations.get(srcMD5/*, snippetID)*/, -> {
27  
    remutable transpiledSrc;
28  
    int i = transpiledSrc.indexOf('\n');
29  
    S libs = transpiledSrc.substring(0, Math.max(0, i));
30  
    printVars(+snippetID, +libs);
31  
    transpiledSrc = transpiledSrc.substring(i+1);
32  
    S javaTarget = or(params.get('javaTarget), defaultJavaTarget);    
33  
    CompilerBot.verbose = true;
34  
    ret CompilerBot.compile(transpiledSrc, libs, javaTarget, snippetID);
35  
  });
36  
  
37  
  bool forceRepackage = eq("1", params.get("repackage"));
38  
  bool withLibs = eq("1", params.get("withLibs"));
39  
  bool noCompiler = eq("1", params.get("noCompiler"));
40  
  bool withX30 = eq("1", params.get("withX30"));
41  
  bool noSrc = eq("1", params.get("noSrc"));
42  
  bool dynamicObjectOnly = eq("dynamicObjectOnly", params.get("mode"));
43  
  
44  
  File jar2 = jar;
45  
  if (withLibs) jar2 = appendToBaseFileName(jar2, ".with-libs"); 
46  
  if (noCompiler) jar2 = appendToBaseFileName(jar2, ".no-compiler"); 
47  
  if (dynamicObjectOnly) jar2 = appendToBaseFileName(jar2, ".dynamicObjectOnly"); 
48  
  if (noSrc) jar2 = appendToBaseFileName(jar2, ".noSrc"); 
49  
  
50  
  if (!eq(jar, jar2)) {
51  
    if (fileLength(jar2) <= 22 || forceRepackage) {
52  
      temp var jarOut = zipOutputStream(jar2);
53  
      new Set<S> entries;
54  
      
55  
      text2zip(jarOut, "source.txt", f2s(jar2));
56  
      
57  
      bool withSrc = !noSrc;
58  
      
59  
      zip2zip_collectFiles(jar, jarOut, entries, name -> withSrc || !endsWith(name, ".java"));
60  
      
61  
      if (withLibs) {
62  
        Pair<S, LS> srcAndLibs = extractLibsFromTranspilation(transpiledSrc);
63  
        fOr (S libID : srcAndLibs.b) {
64  
          File fixer = compilerBotDestDir("fixer" + psI(libID) + ".jar");
65  
  
66  
          if (fileExists(fixer)) {
67  
            println("APPLYING FIXER: " + fixer);
68  
            zip2zip_collectFiles(fixer, jarOut, entries);
69  
          }
70  
            
71  
          zip2zip_collectFiles(loadLibraryOrSrcLib(libID), jarOut, entries);
72  
          /*if (withSrc && isSrcLib(libID))
73  
            text2zip(jarOut, "lib" + libID + ".java", getServerTranspiledWithoutLibs(libID)); // TODO: use actual package and main class
74  
          */
75  
        }
76  
      }
77  
      
78  
      if (withX30)
79  
        zip2zip_collectFiles(pathToJavaxJar(), jarOut, entries);
80  
      else if (noCompiler)
81  
        zip2zip_collectFiles(pathToJavaxJar(), jarOut, entries, name -> !
82  
          startsWithOneOf(name, "org/eclipse/", "META-INF/"));
83  
      else if (dynamicObjectOnly)
84  
        zip2zip_collectFiles(pathToJavaxJar(), jarOut, entries, name -> contains(name, "DynamicObject"));
85  
    }
86  
    
87  
    jar = jar2;
88  
  }
89  
90  
  print("Serving jar for " + snippetID + ": " + renderFileInfo(jar));
91  
  ret subBot_serveFileWithName(jar, psI(snippetID) + ".jar", "application/java-archive");
92  
}

Author comment

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: #1033537
Snippet name: Jar Web Bot [backup]
Eternal ID of this version: #1033537/2
Text MD5: 9b6ab0ad27c8c8d98faaabb22c9c11e9
Transpilation MD5: 810b62b98a178b1d9fca207b4317a8da
Author: stefan
Category: javax / web
Type: JavaX module (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-11-01 20:55:03
Source code size: 3502 bytes / 92 lines
Pitched / IR pitched: No / No
Views / Downloads: 97 / 528
Version history: 1 change(s)
Referenced in: [show references]