Class TestCompiler
java.lang.Object
org.springframework.aot.test.generate.compile.TestCompiler
Utility that can be used to dynamically compile and test Java source code.
- Since:
- 6.0
- Author:
- Phillip Webb, Scott Frederick
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidCompile content from this instance.voidcompile(SourceFile sourceFile, Consumer<Compiled> compiled) Compile content from this instance along with the additional provided source file.voidcompile(SourceFiles sourceFiles, Consumer<Compiled> compiled) Compile content from this instance along with the additional provided source files.voidcompile(SourceFiles sourceFiles, ResourceFiles resourceFiles, Consumer<Compiled> compiled) Compile content from this instance along with the additional provided source and resource files.voidcompile(WritableContent content, Consumer<Compiled> compiled) Compile content from this instance along with the additional provided content.static TestCompilerforCompiler(JavaCompiler javaCompiler) Create a newTestCompilerbacked by the givenJavaCompiler.static TestCompilerCreate a newTestCompilerbacked by the system java compiler.printFiles(PrintStream printStream) Print the contents of the source and resource files to the specifiedPrintStream.withFiles(InMemoryGeneratedFiles generatedFiles) Create a newTestCompilerinstance with additional generated source and resource files.withProcessors(Iterable<Processor> processors) Create a newTestCompilerinstance with additional annotation processors.withProcessors(Processor... processors) Create a newTestCompilerinstance with additional annotation processors.withResources(Iterable<ResourceFile> resourceFiles) Create a newTestCompilerinstance with additional source files.withResources(ResourceFile... resourceFiles) Create a newTestCompilerinstance with additional resource files.withResources(ResourceFiles resourceFiles) Create a newTestCompilerinstance with additional resource files.withSources(Iterable<SourceFile> sourceFiles) Create a newTestCompilerinstance with additional source files.withSources(SourceFile... sourceFiles) Create a newTestCompilerinstance with additional source files.withSources(SourceFiles sourceFiles) Create a newTestCompilerinstance with additional source files.
-
Method Details
-
forSystem
Create a newTestCompilerbacked by the system java compiler.- Returns:
- a new
TestCompilerinstance
-
forCompiler
Create a newTestCompilerbacked by the givenJavaCompiler.- Parameters:
javaCompiler- the java compiler to use- Returns:
- a new
TestCompilerinstance
-
withFiles
Create a newTestCompilerinstance with additional generated source and resource files.- Parameters:
generatedFiles- the generated files to add- Returns:
- a new
TestCompilerinstance
-
withSources
Create a newTestCompilerinstance with additional source files.- Parameters:
sourceFiles- the additional source files- Returns:
- a new
TestCompilerinstance
-
withSources
Create a newTestCompilerinstance with additional source files.- Parameters:
sourceFiles- the additional source files- Returns:
- a new
TestCompilerinstance
-
withSources
Create a newTestCompilerinstance with additional source files.- Parameters:
sourceFiles- the additional source files- Returns:
- a new
TestCompilerinstance
-
withResources
Create a newTestCompilerinstance with additional resource files.- Parameters:
resourceFiles- the additional resource files- Returns:
- a new
TestCompilerinstance
-
withResources
Create a newTestCompilerinstance with additional source files.- Parameters:
resourceFiles- the additional source files- Returns:
- a new
TestCompilerinstance
-
withResources
Create a newTestCompilerinstance with additional resource files.- Parameters:
resourceFiles- the additional resource files- Returns:
- a new
TestCompilerinstance
-
withProcessors
Create a newTestCompilerinstance with additional annotation processors.- Parameters:
processors- the additional annotation processors- Returns:
- a new
TestCompilerinstance
-
withProcessors
Create a newTestCompilerinstance with additional annotation processors.- Parameters:
processors- the additional annotation processors- Returns:
- a new
TestCompilerinstance
-
compile
Compile content from this instance along with the additional provided content.- Parameters:
content- the additional content to compilecompiled- a consumed used to further assert the compiled code- Throws:
CompilationException- if source cannot be compiled
-
compile
Compile content from this instance along with the additional provided source file.- Parameters:
sourceFile- the additional source file to compilecompiled- a consumed used to further assert the compiled code- Throws:
CompilationException- if source cannot be compiled
-
compile
Compile content from this instance along with the additional provided source files.- Parameters:
sourceFiles- the additional source files to compilecompiled- a consumed used to further assert the compiled code- Throws:
CompilationException- if source cannot be compiled
-
compile
public void compile(SourceFiles sourceFiles, ResourceFiles resourceFiles, Consumer<Compiled> compiled) Compile content from this instance along with the additional provided source and resource files.- Parameters:
sourceFiles- the additional source files to compileresourceFiles- the additional resource files to includecompiled- aConsumerused to further assert the compiled code- Throws:
CompilationException- if source cannot be compiled
-
compile
Compile content from this instance.- Parameters:
compiled- aConsumerused to further assert the compiled code- Throws:
CompilationException- if source cannot be compiled
-
printFiles
Print the contents of the source and resource files to the specifiedPrintStream.- Parameters:
printStream- the destination print stream- Returns:
- this instance
-