Package org.agrona.generation
Class CompilerUtil
java.lang.Object
org.agrona.generation.CompilerUtil
Utilities for compiling Java source files at runtime.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
compile
(DiagnosticCollector<JavaFileObject> diagnostics, JavaCompiler.CompilationTask task) Execute compilation task and report errors if it fails.static Class
<?> compileAndLoad
(String className, DiagnosticCollector<JavaFileObject> diagnostics, JavaFileManager fileManager, JavaCompiler.CompilationTask task) Compile and load a class.static Class
<?> compileInMemory
(String className, Map<String, CharSequence> sources) static Class
<?> compileOnDisk
(String className, Map<String, CharSequence> sources) static Collection
<File> persist
(Map<String, CharSequence> sources) Persist source files to disc.private static Collection
<CharSequenceJavaFileObject> wrap
(Map<String, CharSequence> sources)
-
Field Details
-
TEMP_DIR_NAME
Temporary directory for files.
-
-
Constructor Details
-
CompilerUtil
private CompilerUtil()
-
-
Method Details
-
compileInMemory
public static Class<?> compileInMemory(String className, Map<String, CharSequence> sources) throws ClassNotFoundException- Parameters:
className
- to return after compilation.sources
- to be compiled.- Returns:
- the named class that is the result of the compilation.
- Throws:
ClassNotFoundException
- of the named class cannot be found.
-
compileOnDisk
public static Class<?> compileOnDisk(String className, Map<String, CharSequence> sources) throws ClassNotFoundException, IOException- Parameters:
className
- to return after compilation.sources
- to be compiled.- Returns:
- the named class that is the result of the compilation.
- Throws:
ClassNotFoundException
- of the named class cannot be found.IOException
- if an error occurs when writing to disk.
-
compileAndLoad
public static Class<?> compileAndLoad(String className, DiagnosticCollector<JavaFileObject> diagnostics, JavaFileManager fileManager, JavaCompiler.CompilationTask task) throws ClassNotFoundException Compile and load a class.- Parameters:
className
- name of the class to compile.diagnostics
- attached to the compilation task.fileManager
- to load compiled class from disk.task
- compilation task.- Returns:
Class
for the compiled class ornull
if compilation fails.- Throws:
ClassNotFoundException
- if compiled class was not loaded.
-
compile
public static boolean compile(DiagnosticCollector<JavaFileObject> diagnostics, JavaCompiler.CompilationTask task) Execute compilation task and report errors if it fails.- Parameters:
diagnostics
- attached to the compilation task.task
- compilation to be executed.- Returns:
true
if compilation succeeds.
-
persist
Persist source files to disc.- Parameters:
sources
- to persist.- Returns:
- a collection of
File
objects pointing to the persisted sources. - Throws:
IOException
- in case of I/O errors.
-
wrap
-