Class TestCompiler
java.lang.Object
org.springframework.aot.test.generator.compile.TestCompiler
Utility that can be used to dynamically compile and test Java source code.
- Since:
- 6.0
- Author:
- Phillip Webb
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Compile content from this instance.void
compile
(SourceFile sourceFile, Consumer<Compiled> compiled) Compile content from this instance along with the additional provided source file.void
compile
(SourceFiles sourceFiles, Consumer<Compiled> compiled) Compile content from this instance along with the additional provided source files.void
compile
(SourceFiles sourceFiles, ResourceFiles resourceFiles, Consumer<Compiled> compiled) Compile content from this instance along with the additional provided source and resource files.void
compile
(WritableContent content, Consumer<Compiled> compiled) Compile content from this instance along with the additional provided content.static TestCompiler
forCompiler
(JavaCompiler javaCompiler) Return a newTestCompiler
backed by the givenJavaCompiler
.static TestCompiler
Return a newTestCompiler
backed by the system java compiler.withResources
(ResourceFile... resourceFiles) Return a newTestCompiler
instance with addition resource files.withResources
(ResourceFiles resourceFiles) Return a newTestCompiler
instance with addition resource files.withSources
(SourceFile... sourceFiles) Return a newTestCompiler
instance with addition source files.withSources
(SourceFiles sourceFiles) Return a newTestCompiler
instance with addition source files.
-
Method Details
-
forSystem
Return a newTestCompiler
backed by the system java compiler.- Returns:
- a new
TestCompiler
instance
-
forCompiler
Return a newTestCompiler
backed by the givenJavaCompiler
.- Parameters:
javaCompiler
- the java compiler to use- Returns:
- a new
TestCompiler
instance
-
withSources
Return a newTestCompiler
instance with addition source files.- Parameters:
sourceFiles
- the additional source files- Returns:
- a new
TestCompiler
instance
-
withSources
Return a newTestCompiler
instance with addition source files.- Parameters:
sourceFiles
- the additional source files- Returns:
- a new
TestCompiler
instance
-
withResources
Return a newTestCompiler
instance with addition resource files.- Parameters:
resourceFiles
- the additional resource files- Returns:
- a new
TestCompiler
instance
-
withResources
Return a newTestCompiler
instance with addition resource files.- Parameters:
resourceFiles
- the additional resource files- Returns:
- a new
TestCompiler
instance
-
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
- a consumed used to further assert the compiled code- Throws:
CompilationException
- if source cannot be compiled
-
compile
Compile content from this instance.- Parameters:
compiled
- a consumed used to further assert the compiled code- Throws:
CompilationException
- if source cannot be compiled
-