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

67
LINES

< > BotCompany Repo | #1016058 // Make Stefan's OS Starter ["Stefans-OS.jar", OK]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Libraryless. Click here for Pure Java version (8323L/57K).

1  
!7
2  
3  
sS mainClassName = "StefansOS";
4  
static S v = "x30";
5  
static S sourceID = #1001638;
6  
static S javaTarget = "1.8"; // compile JavaX for everyone
7  
static S ecjSnippetID = #1400467;
8  
9  
static S compilerBotID = #1001155;
10  
static int compressionLevel = 9; // Zip compression - highest level
11  
12  
p {
13  
  File jarFile = javaxArtifactsDir("Stefans-OS.jar");
14  
15  
  S s = getServerTranspiled(sourceID);
16  
  S libs = firstLine(s);
17  
  s = dropFirstLine(s);
18  
  
19  
  S mainCode = getServerTranspiledWithoutLibs(#1016060);
20  
  mainCode = jreplace(mainCode, "main.class", mainClassName + ".class");
21  
  mainCode = jreplace(mainCode, "class main", "class " + mainClassName);
22  
23  
  s = moveImportsUp(s + "\n" + mainCode);
24  
25  
  s += x30_makeUtilsSource();
26  
  L<S> tok = javaTok(s);
27  
  javax_prepareX30SourceForDeployment(tok);
28  
  jreplace(tok, "public class " + v, "class " + v);
29  
  S src = join(tok);
30  
  
31  
  File javaFile = new File(programDir(), mainClassName + ".java");
32  
  saveTextFile(javaFile, src);
33  
  print("ok, made " + javaFile.getAbsolutePath());
34  
  
35  
  print("Now compiling.");
36  
  S botQuestion = "Please compile this Java text: " + quote(src) + " for java version " + quote(javaTarget);
37  
  print("Question to bot: " + shorten(botQuestion, 200));
38  
39  
  Class compilerBot = hotwire(compilerBotID);
40  
  S answer = cast call(compilerBot, "answer", botQuestion);
41  
  print("Bot said: " + answer);
42  
  if (answer == null) fail();
43  
  new Matches m;
44  
  if (!match3("ok, *", answer, m))
45  
    if (match3("Compile error", answer))
46  
      fail("Compile Error.");
47  
    else
48  
      fail("I don't understand the bot, exiting");
49  
    
50  
  S classesDir = unquote(m.m[0]);
51  
  print("I think the classes dir is: " + classesDir);
52  
  if (!new File(classesDir).isDirectory()) fail("huh?");
53  
54  
  print("Now making jar.");
55  
  File ecj = loadLibrary(ecjSnippetID);
56  
  
57  
  ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(jarFile));
58  
  zout.setLevel(compressionLevel);
59  
  
60  
  makeManifestWithMainClass(zout, mainClassName);
61  
  dir2zip_recurse(new File(classesDir), zout);
62  
  zip2zip_exceptManifest(ecj, zout);
63  
  zout.close();
64  
  makeExecutable(jarFile);
65  
66  
  print("ok, made " + jarFile.getAbsolutePath() + " (" + jarFile.length() + " bytes)");
67  
}

Author comment

Began life as a copy of #1001639

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1016058
Snippet name: Make Stefan's OS Starter ["Stefans-OS.jar", OK]
Eternal ID of this version: #1016058/33
Text MD5: 071f7c46cb61739603f0ae381bf9e299
Transpilation MD5: 86924f087d60ec2e4594db6d97f39a5d
Author: stefan
Category: javax
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-06-20 07:04:16
Source code size: 2224 bytes / 67 lines
Pitched / IR pitched: No / No
Views / Downloads: 720 / 1592
Version history: 32 change(s)
Referenced in: [show references]