Class Compiler

java.lang.Object
com.google.testing.compile.Compiler

public abstract class Compiler extends Object
An object that can compile(JavaFileObject...) Java source files.
  • Constructor Details

    • Compiler

      public Compiler()
  • Method Details

    • javac

      public static Compiler javac()
      Returns the javac compiler.
    • compiler

      public static Compiler compiler(JavaCompiler javaCompiler)
      Returns a Compiler that uses a given JavaCompiler instance.
    • processors

      public abstract com.google.common.collect.ImmutableList<Processor> processors()
      The annotation processors applied during compilation.
    • options

      public abstract com.google.common.collect.ImmutableList<String> options()
      The options passed to the compiler.
    • classPath

      public abstract Optional<com.google.common.collect.ImmutableList<File>> classPath()
      The compilation class path. If not present, the system class path is used.
    • annotationProcessorPath

      public abstract Optional<com.google.common.collect.ImmutableList<File>> annotationProcessorPath()
      The annotation processor path. If not present, the system annotation processor path is used.
    • withProcessors

      public final Compiler withProcessors(Processor... processors)
      Uses annotation processors during compilation. These replace any previously specified.

      Note that most annotation processors cannot be reused for more than one compilation.

      Returns:
      a new instance with the same options and the given processors
    • withProcessors

      public final Compiler withProcessors(Iterable<? extends Processor> processors)
      Uses annotation processors during compilation. These replace any previously specified.

      Note that most annotation processors cannot be reused for more than one compilation.

      Returns:
      a new instance with the same options and the given processors
    • withOptions

      public final Compiler withOptions(Object... options)
      Passes command-line options to the compiler. These replace any previously specified.
      Returns:
      a new instance with the same processors and the given options
    • withOptions

      public final Compiler withOptions(Iterable<? extends Object> options)
      Passes command-line options to the compiler. These replace any previously specified.
      Returns:
      a new instance with the same processors and the given options
    • withClasspathFrom

      @Deprecated public final Compiler withClasspathFrom(ClassLoader classloader)
      Deprecated.
      prefer withClasspath(Iterable). This method only supports URLClassLoader and the default system classloader, and Files are usually a more natural way to expression compilation classpaths than class loaders.
      Uses the classpath from the passed on classloader (and its parents) for the compilation instead of the system classpath.
      Throws:
      IllegalArgumentException - if the given classloader had classpaths which we could not determine or use for compilation.
    • withClasspath

      public final Compiler withClasspath(Iterable<File> classPath)
      Uses the given classpath for the compilation instead of the system classpath.
    • withAnnotationProcessorPath

      public final Compiler withAnnotationProcessorPath(Iterable<File> annotationProcessorPath)
      Uses the given annotation processor path for the compilation instead of the system annotation processor path.
    • compile

      public final Compilation compile(JavaFileObject... files)
      Compiles Java source files.
      Returns:
      the results of the compilation
    • compile

      public final Compilation compile(Iterable<? extends JavaFileObject> files)
      Compiles Java source files.
      Returns:
      the results of the compilation