Class TestCompiler
java.lang.Object
org.springframework.core.test.tools.TestCompiler
Utility that can be used to dynamically compile and test Java source code.
- Since:
- 6.0
- Author:
- Phillip Webb, Scott Frederick, Stephane Nicoll
- 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.Create a newTestCompiler
instance that fails if any warning is encountered.static TestCompiler
forCompiler
(JavaCompiler javaCompiler) Create a newTestCompiler
backed by the givenJavaCompiler
.static TestCompiler
Create a newTestCompiler
backed by the system java compiler.printFiles
(PrintStream printStream) Print the contents of the source and resource files to the specifiedPrintStream
.with
(UnaryOperator<TestCompiler> customizer) Apply customization to this compiler.withClasses
(Iterable<ClassFile> classFiles) Create a newTestCompiler
instance with additional classes.withCompilerOptions
(String... options) Create a newTestCompiler
instance with the additional compiler options.withProcessors
(Iterable<Processor> processors) Create a newTestCompiler
instance with additional annotation processors.withProcessors
(Processor... processors) Create a newTestCompiler
instance with additional annotation processors.withResources
(Iterable<ResourceFile> resourceFiles) Create a newTestCompiler
instance with additional source files.withResources
(ResourceFile... resourceFiles) Create a newTestCompiler
instance with additional resource files.withResources
(ResourceFiles resourceFiles) Create a newTestCompiler
instance with additional resource files.withSources
(Iterable<SourceFile> sourceFiles) Create a newTestCompiler
instance with additional source files.withSources
(SourceFile... sourceFiles) Create a newTestCompiler
instance with additional source files.withSources
(SourceFiles sourceFiles) Create a newTestCompiler
instance with additional source files.
-
Method Details
-
forSystem
Create a newTestCompiler
backed by the system java compiler.- Returns:
- a new
TestCompiler
instance
-
forCompiler
Create a newTestCompiler
backed by the givenJavaCompiler
.- Parameters:
javaCompiler
- the java compiler to use- Returns:
- a new
TestCompiler
instance
-
with
Apply customization to this compiler.- Parameters:
customizer
- the customizer to call- Returns:
- a new
TestCompiler
instance with the customizations applied
-
withSources
Create a newTestCompiler
instance with additional source files.- Parameters:
sourceFiles
- the additional source files- Returns:
- a new
TestCompiler
instance
-
withSources
Create a newTestCompiler
instance with additional source files.- Parameters:
sourceFiles
- the additional source files- Returns:
- a new
TestCompiler
instance
-
withSources
Create a newTestCompiler
instance with additional source files.- Parameters:
sourceFiles
- the additional source files- Returns:
- a new
TestCompiler
instance
-
withResources
Create a newTestCompiler
instance with additional resource files.- Parameters:
resourceFiles
- the additional resource files- Returns:
- a new
TestCompiler
instance
-
withResources
Create a newTestCompiler
instance with additional source files.- Parameters:
resourceFiles
- the additional source files- Returns:
- a new
TestCompiler
instance
-
withResources
Create a newTestCompiler
instance with additional resource files.- Parameters:
resourceFiles
- the additional resource files- Returns:
- a new
TestCompiler
instance
-
withClasses
Create a newTestCompiler
instance with additional classes.- Parameters:
classFiles
- the additional classes- Returns:
- a new
TestCompiler
instance
-
withProcessors
Create a newTestCompiler
instance with additional annotation processors.- Parameters:
processors
- the additional annotation processors- Returns:
- a new
TestCompiler
instance
-
withProcessors
Create a newTestCompiler
instance with additional annotation processors.- Parameters:
processors
- the additional annotation processors- Returns:
- a new
TestCompiler
instance
-
withCompilerOptions
Create a newTestCompiler
instance with the additional compiler options.- Parameters:
options
- the additional compiler options- Returns:
- a new
TestCompiler
instance - Since:
- 6.1
-
failOnWarning
Create a newTestCompiler
instance that fails if any warning is encountered. This sets the-Xlint:all
and-Werror
compiler options.- Returns:
- a new
TestCompiler
instance - Since:
- 6.1
- See Also:
-
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
- aConsumer
used to further assert the compiled code- Throws:
CompilationException
- if source cannot be compiled
-
compile
Compile content from this instance.- Parameters:
compiled
- aConsumer
used 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
-