Class JavaCompilerSupport

java.lang.Object
dev.metaschema.databind.codegen.JavaCompilerSupport

public class JavaCompilerSupport extends Object
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.

  • Constructor Details

    • JavaCompilerSupport

      public JavaCompilerSupport(@NonNull Path classDir)
      Construct a new compiler support instance.
      Parameters:
      classDir - the directory where compiled class files will be written
  • Method Details

    • getClassPath

      public Set<String> getClassPath()
      Get the configured classpath entries.
      Returns:
      the classpath entries
    • getModulePath

      public Set<String> getModulePath()
      Get the configured module path entries.
      Returns:
      the module path entries
    • getRootModuleNames

      public Set<String> getRootModuleNames()
      Get the configured root module names.
      Returns:
      the root module names
    • addToClassPath

      public void addToClassPath(@NonNull String entry)
      Add an entry to the classpath.
      Parameters:
      entry - the classpath entry to add
    • addToModulePath

      public void addToModulePath(@NonNull String entry)
      Add an entry to the module path.
      Parameters:
      entry - the module path entry to add
    • addRootModule

      public void addRootModule(@NonNull String entry)
      Add a root module name.
      Parameters:
      entry - the root module name to add
    • setLogger

      public void setLogger(@NonNull JavaCompilerSupport.Logger logger)
      Set the logger for compilation messages.
      Parameters:
      logger - the logger to use
    • generateCompilerOptions

      @NonNull protected List<String> 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 classes
      IllegalArgumentException - if any of the options are invalid, or if any of the given compilation units are of other kind than JavaFileObject.Kind.SOURCE