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

44
LINES

< > BotCompany Repo | #1033530 // JavaCompilation - uses direct ECJ

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

Transpiled version (7002L) is out of date.

1  
sclass JavaCompilation {
2  
  File srcDir;
3  
  L<File> libraries;
4  
  File classesDir;
5  
  bool verbose = true;
6  
  S sourceLevel = "11";
7  
  S moreOptions = "-warn:none";
8  
  
9  
  L<File> sources;
10  
  File optionsFile;
11  
  S compilerOutput;
12  
  
13  
  swappable void invokeJavaCompiler() {
14  
    compilerOutput = invokeEcj_direct(optionsFile);
15  
  }
16  
  
17  
  run {
18  
    // collect sources
19  
20  
    sources = findJavaSourceFiles(srcDir);
21  
    if (sources.isEmpty())
22  
      throw new IOException("No sources found");
23  
24  
    // compile
25  
26  
    optionsFile = File.createTempFile("ecj", "", javaxTempDir());
27  
    try {
28  
      if (verbose) printWithMS("Compiling " + sources.size() + " source(s) to " + classesDir.getPath());
29  
      if (verbose) printWithMS("Libraries: " + libraries);
30  
      
31  
      S options = unnull(moreOptions) + " -source " + sourceLevel + " -target " + sourceLevel;
32  
      options += " -d " + pqO(classesDir.getPath());
33  
      libraries.add(pathToJavaxJar());
34  
      makeOptionsFileForJavaCompiler(optionsFile, sources, libraries, options);
35  
      if (verbose) printWithMS("Options: " + loadTextFile(optionsFile));
36  
      classesDir.mkdirs();
37  
      time "invokeJavaCompiler" {
38  
        invokeJavaCompiler();
39  
      }
40  
    } finally {
41  
      optionsFile.delete();
42  
    }
43  
  }
44  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033530
Snippet name: JavaCompilation - uses direct ECJ
Eternal ID of this version: #1033530/11
Text MD5: 3ba80c361211779607202b6a41b94e32
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-03-06 23:22:06
Source code size: 1275 bytes / 44 lines
Pitched / IR pitched: No / No
Views / Downloads: 161 / 257
Version history: 10 change(s)
Referenced in: [show references]