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

113
LINES

< > BotCompany Repo | #1022682 // ProgramPackager

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (13374L) is out of date.

sclass ProgramPackager {
  File jarFile;
  S mainProgramID;
  S mainClassName;
  Set<S> excludeSnippets;
  Cl<S> extraSnippets;
  
  // setting this to false currently breaks everything because transpilation MD5s are no longer available
  bool includeSources = true;
  
  bool includeBinaries = false;
  bool includeCompiler = true;
  
  VF1<ZipOutputStream> copyAdditionalFiles = voidfunc(ZipOutputStream jar) {
    file2zip(jar, programFile("gazelle-concepts.zip"));
  };
  
  *(File *jarFile, S *mainProgramID, S *mainClassName) {}
  
  *(File *jarFile, S *mainProgramID) {
    mainClassName = tok_mainClassNameFromJavaXSnippet(mainProgramID);
    //assertNotNull("Please set mainClassName in " + mainProgramID, mainClassName);
    if (mainClassName == null) mainClassName = "main";
  }
  
  Set<S> snippetIDs;
  Map<S, Collection<S>> trace;

  void go ctex {
    Pair<File, S> programJarAndSrc = CompilerBot.compileSnippet2(mainProgramID);
    
    if (snippetIDs == null) {
      temp IProgressShower p = tempProgressBar("Collecting dependencies", 100);
      
      trace = new Map;
      snippetIDs = recursivelyCollectSnippetIDsFromTranspiled_multi(
        itemPlusList(mainProgramID, extraSnippets),
        trace_out := minimalNotifyingMap(trace, r {
          p.setValue(l(trace));
        }),
        exclude := excludeSnippets);
    }
    
    temp IProgressShower p = tempProgressBar("JAR", or_nonZeroLong(fileSize(jarFile), megabytes(30)));
    {
      temp ZipOutputStream jar = zipOutputStream(jarFile);
      temp tempShowFileSizeProgress(p, jarFile);
      
      makeManifestWithMainClass(jar, mainClassName);
      
      zip2zip_exceptManifest2(programJarAndSrc.a, jar,
        // exclude those:
        litset("main.java"));
      
      zip_addTextFile(jar, "back-references.txt", 
        renderMap_colon_lines(reverseMultiMap_tree(pseudoToRealMultiMap(trace)).data));
        
      SS titles = getSnippetTitles_cached(snippetIDs);
      zip_addTextFile(jar, "snippet-titles.struct", indentedStruct(titles));
      new TreeMap<S, Int> types;
    
      for (S snippetID : snippetIDs) {
        continue if isPseudoSnippetID(snippetID);
        int type = getSnippetType(snippetID);
        types.put(snippetID, type);
        if (type == snippetType_image()) {
          File img = loadLibrary(snippetID);
          addFileToZip(jar, img, psI(snippetID) + "." + (isGIF(img) ? "gif" : "png"));
        } else if (type == snippetType_data())
          addFileToZip(jar, loadLibrary(snippetID), psI(snippetID) + ".bin");
        else pcall {
          S text = loadSnippet(snippetID);
          if (text != null)
            zip_addTextFile(jar, psI(snippetID) + ".text", text);
          if (isJavaxCompilableSnippetTypeExceptInclude(type)) {
            if (includeSources) {
              S transpilation = getServerTranspiled2(snippetID);
              zip_addTextFile(jar, psI(snippetID) + ".transpiled", transpilation);
            }
            if (includeBinaries && !sameSnippetID(snippetID, mainProgramID)) {
              File snippetJar = pairA(hotwire_compile(snippetID));
              print("Adding binary: " + snippetID + " / " + f2s(snippetJar));
              file2zip(jar, snippetJar);
            }
          }
        }
      }
      
      //S typeStruct = indentedStruct(types);
      
      S typeStruct = "tm{\n" +
        mapToLines(types,
          (snippetID, type) -> "  " + quote(snippetID) + "=" + type + ", // " + snippetTypeName(type))
      + "}";

      zip_addTextFile(jar, "snippet-types.struct", typeStruct);
      
      File javaxJar = pathToJavaxJar();
      print("Copying: " + javaxJar);
      if (!includeCompiler)
        zip2zip_withPredicate(javaxJar, jar, s ->
          !startsWithOneOf(s, "META-INF/", "org/eclipse/")
          && !eq(s, "transpilationDate"));
      else
        zip2zip_exceptManifest2(javaxJar, jar, litset("transpilationDate"));
      
      callF(copyAdditionalFiles, jar);
    } // jar close
    
    makeExecutable(jarFile);
    fileSavedInfoBox(jarFile);
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1022682
Snippet name: ProgramPackager
Eternal ID of this version: #1022682/32
Text MD5: 05bde36cf6d2c902647cba8a5e69d078
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-05-24 19:53:37
Source code size: 4172 bytes / 113 lines
Pitched / IR pitched: No / No
Views / Downloads: 350 / 918
Version history: 31 change(s)
Referenced in: [show references]