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.

1  
sclass ProgramPackager {
2  
  File jarFile;
3  
  S mainProgramID;
4  
  S mainClassName;
5  
  Set<S> excludeSnippets;
6  
  Cl<S> extraSnippets;
7  
  
8  
  // setting this to false currently breaks everything because transpilation MD5s are no longer available
9  
  bool includeSources = true;
10  
  
11  
  bool includeBinaries = false;
12  
  bool includeCompiler = true;
13  
  
14  
  VF1<ZipOutputStream> copyAdditionalFiles = voidfunc(ZipOutputStream jar) {
15  
    file2zip(jar, programFile("gazelle-concepts.zip"));
16  
  };
17  
  
18  
  *(File *jarFile, S *mainProgramID, S *mainClassName) {}
19  
  
20  
  *(File *jarFile, S *mainProgramID) {
21  
    mainClassName = tok_mainClassNameFromJavaXSnippet(mainProgramID);
22  
    //assertNotNull("Please set mainClassName in " + mainProgramID, mainClassName);
23  
    if (mainClassName == null) mainClassName = "main";
24  
  }
25  
  
26  
  Set<S> snippetIDs;
27  
  Map<S, Collection<S>> trace;
28  
29  
  void go ctex {
30  
    Pair<File, S> programJarAndSrc = CompilerBot.compileSnippet2(mainProgramID);
31  
    
32  
    if (snippetIDs == null) {
33  
      temp IProgressShower p = tempProgressBar("Collecting dependencies", 100);
34  
      
35  
      trace = new Map;
36  
      snippetIDs = recursivelyCollectSnippetIDsFromTranspiled_multi(
37  
        itemPlusList(mainProgramID, extraSnippets),
38  
        trace_out := minimalNotifyingMap(trace, r {
39  
          p.setValue(l(trace));
40  
        }),
41  
        exclude := excludeSnippets);
42  
    }
43  
    
44  
    temp IProgressShower p = tempProgressBar("JAR", or_nonZeroLong(fileSize(jarFile), megabytes(30)));
45  
    {
46  
      temp ZipOutputStream jar = zipOutputStream(jarFile);
47  
      temp tempShowFileSizeProgress(p, jarFile);
48  
      
49  
      makeManifestWithMainClass(jar, mainClassName);
50  
      
51  
      zip2zip_exceptManifest2(programJarAndSrc.a, jar,
52  
        // exclude those:
53  
        litset("main.java"));
54  
      
55  
      zip_addTextFile(jar, "back-references.txt", 
56  
        renderMap_colon_lines(reverseMultiMap_tree(pseudoToRealMultiMap(trace)).data));
57  
        
58  
      SS titles = getSnippetTitles_cached(snippetIDs);
59  
      zip_addTextFile(jar, "snippet-titles.struct", indentedStruct(titles));
60  
      new TreeMap<S, Int> types;
61  
    
62  
      for (S snippetID : snippetIDs) {
63  
        continue if isPseudoSnippetID(snippetID);
64  
        int type = getSnippetType(snippetID);
65  
        types.put(snippetID, type);
66  
        if (type == snippetType_image()) {
67  
          File img = loadLibrary(snippetID);
68  
          addFileToZip(jar, img, psI(snippetID) + "." + (isGIF(img) ? "gif" : "png"));
69  
        } else if (type == snippetType_data())
70  
          addFileToZip(jar, loadLibrary(snippetID), psI(snippetID) + ".bin");
71  
        else pcall {
72  
          S text = loadSnippet(snippetID);
73  
          if (text != null)
74  
            zip_addTextFile(jar, psI(snippetID) + ".text", text);
75  
          if (isJavaxCompilableSnippetTypeExceptInclude(type)) {
76  
            if (includeSources) {
77  
              S transpilation = getServerTranspiled2(snippetID);
78  
              zip_addTextFile(jar, psI(snippetID) + ".transpiled", transpilation);
79  
            }
80  
            if (includeBinaries && !sameSnippetID(snippetID, mainProgramID)) {
81  
              File snippetJar = pairA(hotwire_compile(snippetID));
82  
              print("Adding binary: " + snippetID + " / " + f2s(snippetJar));
83  
              file2zip(jar, snippetJar);
84  
            }
85  
          }
86  
        }
87  
      }
88  
      
89  
      //S typeStruct = indentedStruct(types);
90  
      
91  
      S typeStruct = "tm{\n" +
92  
        mapToLines(types,
93  
          (snippetID, type) -> "  " + quote(snippetID) + "=" + type + ", // " + snippetTypeName(type))
94  
      + "}";
95  
96  
      zip_addTextFile(jar, "snippet-types.struct", typeStruct);
97  
      
98  
      File javaxJar = pathToJavaxJar();
99  
      print("Copying: " + javaxJar);
100  
      if (!includeCompiler)
101  
        zip2zip_withPredicate(javaxJar, jar, s ->
102  
          !startsWithOneOf(s, "META-INF/", "org/eclipse/")
103  
          && !eq(s, "transpilationDate"));
104  
      else
105  
        zip2zip_exceptManifest2(javaxJar, jar, litset("transpilationDate"));
106  
      
107  
      callF(copyAdditionalFiles, jar);
108  
    } // jar close
109  
    
110  
    makeExecutable(jarFile);
111  
    fileSavedInfoBox(jarFile);
112  
  }
113  
}

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: 358 / 930
Version history: 31 change(s)
Referenced in: [show references]