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).

!7

sS defaultJavaTarget = "1.11";

sS standardCredentials() { ret ""; } // public snippets only

// (transpilation md5, snippetID) => jar file
//static new SerializeComputations<PairS, File> computations;
// transpilation md5 => jar file
static new SerializeComputations<S, File> computations;

html {
  // lock lock; // now using SerializeComputations
  
  uri = dropPrefixSlash(uri);
  S snippetID = fsI(uri);
  if (!isSnippetPublic(snippetID)) fail("Snippet not public: " + snippetID);
  S transpiledSrc = getServerTranspiled2(snippetID);
  
  // md5 check (if parameter supplied)
  
  S md5 = params.get('md5);
  S srcMD5 = md5(transpiledSrc);
  if (md5 != null && !eq(md5, srcMD5)) ret "md5 mismatch";
  
  File jar = computations.get(srcMD5/*, snippetID)*/, -> {
    remutable transpiledSrc;
    int i = transpiledSrc.indexOf('\n');
    S libs = transpiledSrc.substring(0, Math.max(0, i));
    printVars(+snippetID, +libs);
    transpiledSrc = transpiledSrc.substring(i+1);
    S javaTarget = or(params.get('javaTarget), defaultJavaTarget);    
    CompilerBot.verbose = true;
    ret CompilerBot.compile(transpiledSrc, libs, javaTarget, snippetID);
  });
  
  bool forceRepackage = eq("1", params.get("repackage"));
  bool withLibs = eq("1", params.get("withLibs"));
  bool noCompiler = eq("1", params.get("noCompiler"));
  bool withX30 = eq("1", params.get("withX30"));
  bool noSrc = eq("1", params.get("noSrc"));
  bool dynamicObjectOnly = eq("dynamicObjectOnly", params.get("mode"));
  
  File jar2 = jar;
  if (withLibs) jar2 = appendToBaseFileName(jar2, ".with-libs"); 
  if (noCompiler) jar2 = appendToBaseFileName(jar2, ".no-compiler"); 
  if (dynamicObjectOnly) jar2 = appendToBaseFileName(jar2, ".dynamicObjectOnly"); 
  if (noSrc) jar2 = appendToBaseFileName(jar2, ".noSrc"); 
  
  if (!eq(jar, jar2)) {
    if (fileLength(jar2) <= 22 || forceRepackage) {
      temp var jarOut = zipOutputStream(jar2);
      new Set<S> entries;
      
      text2zip(jarOut, "source.txt", f2s(jar2));
      
      bool withSrc = !noSrc;
      
      zip2zip_collectFiles(jar, jarOut, entries, name -> withSrc || !endsWith(name, ".java"));
      
      if (withLibs) {
        Pair<S, LS> srcAndLibs = extractLibsFromTranspilation(transpiledSrc);
        fOr (S libID : srcAndLibs.b) {
          File fixer = compilerBotDestDir("fixer" + psI(libID) + ".jar");
  
          if (fileExists(fixer)) {
            println("APPLYING FIXER: " + fixer);
            zip2zip_collectFiles(fixer, jarOut, entries);
          }
            
          zip2zip_collectFiles(loadLibraryOrSrcLib(libID), jarOut, entries);
          /*if (withSrc && isSrcLib(libID))
            text2zip(jarOut, "lib" + libID + ".java", getServerTranspiledWithoutLibs(libID)); // TODO: use actual package and main class
          */
        }
      }
      
      if (withX30)
        zip2zip_collectFiles(pathToJavaxJar(), jarOut, entries);
      else if (noCompiler)
        zip2zip_collectFiles(pathToJavaxJar(), jarOut, entries, name -> !
          startsWithOneOf(name, "org/eclipse/", "META-INF/"));
      else if (dynamicObjectOnly)
        zip2zip_collectFiles(pathToJavaxJar(), jarOut, entries, name -> contains(name, "DynamicObject"));
    }
    
    jar = jar2;
  }

  print("Serving jar for " + snippetID + ": " + renderFileInfo(jar));
  ret subBot_serveFileWithName(jar, psI(snippetID) + ".jar", "application/java-archive");
}

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: 212 / 831
Version history: 1 change(s)
Referenced in: [show references]