forked from apache/drill
-
Notifications
You must be signed in to change notification settings - Fork 1
CG Compilation Framework
Paul Rogers edited this page Nov 18, 2016
·
4 revisions
The "JDK compiler" uses the built-in Java compiler (which is, in modern Java, available in the JRE itself.) Java compilation in Java itself is based on the JavaCompiler
class. The javax.tools
provides a dynamic compilation framework. The IBM article provides a sample app that compiles Java classes from in-memory sources.
Drill's implementation is similar to the approach outlined in the IBM article. The DrillJavaFileManager
manages the (virtual) source and class files, DrillJavaFileObject
manages each file.
You can view the generated code in one of three ways:
- Enable debug logging for
AbstractClassCompiler
. The generated code is written to the log file. Set the config optiondrill.exec.compile.debug
totrue
if you want line numbers added to each line. - Uncomment the obvious block of code in
AbstractClassCompiler
to write each generated class to/tmp
. This version is handy as it uses the class name to name each file. - Pass the following to the command line when starting Drill:
-Dorg.codehaus.janino.source_debugging.enable=true -Dorg.codehaus.janino.source_debugging.dir=/tmp
. (See this post for more information.) This version writes all files using generic temporary names, making it hard to find the particular file of interest.
You can gain access to the generated class files by uncommenting the obvious lines near line 256 in MergeAdapter
.