Class SourceCompiler
java.lang.Object
org.h2.util.SourceCompiler
This class allows to convert source code to a class. It uses one class loader
per class.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classAn in-memory class file manager.private static final classAccess the Groovy compiler using reflection, so that we do not gain a compile-time dependency unnecessarily.(package private) static classAn in-memory java class object.(package private) static classAn in-memory java source file object. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringThe class name to byte code map.(package private) final Map<String, CompiledScript> The class name to compiled scripts map.(package private) static final JavaCompilerThe "com.sun.tools.javac.Main" (if available).private static final Class<?> The class name to source code map.(package private) booleanWhether to use the ToolProvider.getSystemJavaCompiler(). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidcopyInThread(InputStream in, OutputStream out) private static intClass<?> Get the class object for the given name.getCompiledScript(String packageAndClassName) Get the compiled script.(package private) static StringgetCompleteSourceCode(String packageName, String className, String source) Get the complete source code (including package name, imports, and so on).Get the first public static method of the given class.private static voidhandleSyntaxError(String output, int exitStatus) private static booleanisGroovySource(String source) private static booleanisJavascriptSource(String source) static booleanisJavaxScriptSource(String source) Whether the passed source can be compiled usingScriptEngineManager.private static booleanisRubySource(String source) (package private) byte[]javacCompile(String packageName, String className, String source) Compile the given class.private static voidjavacProcess(Path javaFile) private static void(package private) Class<?> javaxToolsJavac(String packageName, String className, String source) Compile using the standard java compiler.voidsetJavaSystemCompiler(boolean enabled) Enable or disable the usage of the Java system compiler.voidSet the source code for the specified class.
-
Field Details
-
JAVA_COMPILER
The "com.sun.tools.javac.Main" (if available). -
JAVAC_SUN
-
COMPILE_DIR
-
sources
-
compiled
-
compiledScripts
The class name to compiled scripts map. -
useJavaSystemCompiler
boolean useJavaSystemCompilerWhether to use the ToolProvider.getSystemJavaCompiler().
-
-
Constructor Details
-
SourceCompiler
public SourceCompiler()
-
-
Method Details
-
setSource
-
setJavaSystemCompiler
public void setJavaSystemCompiler(boolean enabled) Enable or disable the usage of the Java system compiler.- Parameters:
enabled- true to enable
-
getClass
Get the class object for the given name.- Parameters:
packageAndClassName- the class name- Returns:
- the class
- Throws:
ClassNotFoundException- on failure
-
isGroovySource
-
isJavascriptSource
-
isRubySource
-
isJavaxScriptSource
Whether the passed source can be compiled usingScriptEngineManager.- Parameters:
source- the source to test.- Returns:
trueifgetCompiledScript(String)can be called.
-
getCompiledScript
Get the compiled script.- Parameters:
packageAndClassName- the package and class name- Returns:
- the compiled script
- Throws:
ScriptException- on failure
-
getMethod
Get the first public static method of the given class.- Parameters:
className- the class name- Returns:
- the method name
- Throws:
ClassNotFoundException- on failure
-
javacCompile
Compile the given class. This method tries to use the class "com.sun.tools.javac.Main" if available. If not, it tries to run "javac" in a separate process.- Parameters:
packageName- the package nameclassName- the class namesource- the source code- Returns:
- the class file
-
getCompleteSourceCode
Get the complete source code (including package name, imports, and so on).- Parameters:
packageName- the package nameclassName- the class namesource- the (possibly shortened) source code- Returns:
- the full source code
-
javaxToolsJavac
-
javacProcess
-
exec
-
copyInThread
-
javacSun
-
handleSyntaxError
-