java.lang.Object
dev.metaschema.databind.codegen.JavaCompilerSupport
Provides support for compiling Java source files using the system Java
compiler.
This class wraps the JavaCompiler API to provide a
simplified interface for compiling generated Java source files. It supports
configuring the classpath, module path, and output directory.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classContains the result of a compilation operation.static interfaceA logging interface for compilation messages. -
Constructor Summary
ConstructorsConstructorDescriptionJavaCompilerSupport(Path classDir) Construct a new compiler support instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddRootModule(String entry) Add a root module name.voidaddToClassPath(String entry) Add an entry to the classpath.voidaddToModulePath(String entry) Add an entry to the module path.Compile the provided Java source files.Generate the compiler options based on the current configuration.Get the configured classpath entries.Get the configured module path entries.Get the configured root module names.voidsetLogger(JavaCompilerSupport.Logger logger) Set the logger for compilation messages.
-
Constructor Details
-
JavaCompilerSupport
Construct a new compiler support instance.- Parameters:
classDir- the directory where compiled class files will be written
-
-
Method Details
-
getClassPath
Get the configured classpath entries.- Returns:
- the classpath entries
-
getModulePath
Get the configured module path entries.- Returns:
- the module path entries
-
getRootModuleNames
Get the configured root module names.- Returns:
- the root module names
-
addToClassPath
Add an entry to the classpath.- Parameters:
entry- the classpath entry to add
-
addToModulePath
Add an entry to the module path.- Parameters:
entry- the module path entry to add
-
addRootModule
Add a root module name.- Parameters:
entry- the root module name to add
-
setLogger
Set the logger for compilation messages.- Parameters:
logger- the logger to use
-
generateCompilerOptions
Generate the compiler options based on the current configuration.- Returns:
- the list of compiler options
-
compile
public JavaCompilerSupport.CompilationResult compile(@NonNull List<Path> classFiles) throws IOException Compile the provided Java source files.- Parameters:
classFiles- the source files to compile- Returns:
- information about the compilation result
- Throws:
IOException- if an error occurred while compiling the classesIllegalArgumentException- if any of the options are invalid, or if any of the given compilation units are of other kind thanJavaFileObject.Kind.SOURCE
-