Using modern Java compiler default
authorJan Lahoda <jlahoda@netbeans.org>
Tue, 24 Jan 2017 04:27:23 +0100
changeset 143ff7a893a7ce
parent 13 334128dc6441
child 15 cdb47e644581
Using modern Java compiler
src/main/java/xelfi/compiler/XelfiCompilerMain.java
     1.1 --- a/src/main/java/xelfi/compiler/XelfiCompilerMain.java	Tue Jan 24 04:23:08 2017 +0100
     1.2 +++ b/src/main/java/xelfi/compiler/XelfiCompilerMain.java	Tue Jan 24 04:27:23 2017 +0100
     1.3 @@ -8,6 +8,10 @@
     1.4  import sun.tools.javac.*;
     1.5  import sun.tools.java.*;
     1.6  import java.io.*;
     1.7 +import java.util.Arrays;
     1.8 +import javax.tools.JavaCompiler;
     1.9 +import javax.tools.StandardJavaFileManager;
    1.10 +import javax.tools.ToolProvider;
    1.11  
    1.12  
    1.13  class XelfiCompilerMain extends Main implements MainCompiler
    1.14 @@ -37,7 +41,17 @@
    1.15        args[0] = file.toString();
    1.16        output("Compiling: " + args[0]);
    1.17      }
    1.18 -    compile(args);
    1.19 +    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    1.20 +    StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
    1.21 +    try {
    1.22 +      compiler.getTask(new OutputStreamWriter(out), fm, null, Arrays.asList(args).subList(0, args.length - 1), null, fm.getJavaFileObjects(args[args.length - 1])).call();
    1.23 +    } finally {
    1.24 +      try {
    1.25 +        fm.close();
    1.26 +      } catch (IOException ex) {
    1.27 +         ex.printStackTrace();
    1.28 +      }
    1.29 +    }
    1.30      output("\n");
    1.31    }
    1.32