@ -24,6 +24,7 @@ import java.util.List;
@@ -24,6 +24,7 @@ import java.util.List;
import java.util.Locale ;
import java.util.function.Consumer ;
import java.util.function.UnaryOperator ;
import java.util.stream.Stream ;
import javax.annotation.processing.Processor ;
import javax.tools.Diagnostic ;
@ -41,6 +42,7 @@ import org.springframework.lang.Nullable;
@@ -41,6 +42,7 @@ import org.springframework.lang.Nullable;
*
* @author Phillip Webb
* @author Scott Frederick
* @author Stephane Nicoll
* @since 6 . 0
* @see # forSystem ( )
* /
@ -59,10 +61,12 @@ public final class TestCompiler {
@@ -59,10 +61,12 @@ public final class TestCompiler {
private final List < Processor > processors ;
private final List < String > compilerOptions ;
private TestCompiler ( @Nullable ClassLoader classLoader , JavaCompiler compiler ,
SourceFiles sourceFiles , ResourceFiles resourceFiles , ClassFiles classFiles ,
List < Processor > processors ) {
List < Processor > processors , List < String > compilerOptions ) {
this . classLoader = classLoader ;
this . compiler = compiler ;
@ -70,6 +74,7 @@ public final class TestCompiler {
@@ -70,6 +74,7 @@ public final class TestCompiler {
this . resourceFiles = resourceFiles ;
this . classFiles = classFiles ;
this . processors = processors ;
this . compilerOptions = compilerOptions ;
}
@ -88,7 +93,7 @@ public final class TestCompiler {
@@ -88,7 +93,7 @@ public final class TestCompiler {
* /
public static TestCompiler forCompiler ( JavaCompiler javaCompiler ) {
return new TestCompiler ( null , javaCompiler , SourceFiles . none ( ) ,
ResourceFiles . none ( ) , ClassFiles . none ( ) , Collections . emptyList ( ) ) ;
ResourceFiles . none ( ) , ClassFiles . none ( ) , Collections . emptyList ( ) , Collections . emptyList ( ) ) ;
}
/ * *
@ -108,7 +113,7 @@ public final class TestCompiler {
@@ -108,7 +113,7 @@ public final class TestCompiler {
public TestCompiler withSources ( SourceFile . . . sourceFiles ) {
return new TestCompiler ( this . classLoader , this . compiler ,
this . sourceFiles . and ( sourceFiles ) , this . resourceFiles ,
this . classFiles , this . processors ) ;
this . classFiles , this . processors , this . compilerOptions ) ;
}
/ * *
@ -119,7 +124,7 @@ public final class TestCompiler {
@@ -119,7 +124,7 @@ public final class TestCompiler {
public TestCompiler withSources ( Iterable < SourceFile > sourceFiles ) {
return new TestCompiler ( this . classLoader , this . compiler ,
this . sourceFiles . and ( sourceFiles ) , this . resourceFiles ,
this . classFiles , this . processors ) ;
this . classFiles , this . processors , this . compilerOptions ) ;
}
/ * *
@ -130,7 +135,7 @@ public final class TestCompiler {
@@ -130,7 +135,7 @@ public final class TestCompiler {
public TestCompiler withSources ( SourceFiles sourceFiles ) {
return new TestCompiler ( this . classLoader , this . compiler ,
this . sourceFiles . and ( sourceFiles ) , this . resourceFiles ,
this . classFiles , this . processors ) ;
this . classFiles , this . processors , this . compilerOptions ) ;
}
/ * *
@ -140,7 +145,8 @@ public final class TestCompiler {
@@ -140,7 +145,8 @@ public final class TestCompiler {
* /
public TestCompiler withResources ( ResourceFile . . . resourceFiles ) {
return new TestCompiler ( this . classLoader , this . compiler , this . sourceFiles ,
this . resourceFiles . and ( resourceFiles ) , this . classFiles , this . processors ) ;
this . resourceFiles . and ( resourceFiles ) , this . classFiles , this . processors ,
this . compilerOptions ) ;
}
/ * *
@ -150,7 +156,8 @@ public final class TestCompiler {
@@ -150,7 +156,8 @@ public final class TestCompiler {
* /
public TestCompiler withResources ( Iterable < ResourceFile > resourceFiles ) {
return new TestCompiler ( this . classLoader , this . compiler , this . sourceFiles ,
this . resourceFiles . and ( resourceFiles ) , this . classFiles , this . processors ) ;
this . resourceFiles . and ( resourceFiles ) , this . classFiles , this . processors ,
this . compilerOptions ) ;
}
/ * *
@ -160,7 +167,8 @@ public final class TestCompiler {
@@ -160,7 +167,8 @@ public final class TestCompiler {
* /
public TestCompiler withResources ( ResourceFiles resourceFiles ) {
return new TestCompiler ( this . classLoader , this . compiler , this . sourceFiles ,
this . resourceFiles . and ( resourceFiles ) , this . classFiles , this . processors ) ;
this . resourceFiles . and ( resourceFiles ) , this . classFiles , this . processors ,
this . compilerOptions ) ;
}
/ * *
@ -170,7 +178,8 @@ public final class TestCompiler {
@@ -170,7 +178,8 @@ public final class TestCompiler {
* /
public TestCompiler withClasses ( Iterable < ClassFile > classFiles ) {
return new TestCompiler ( this . classLoader , this . compiler , this . sourceFiles ,
this . resourceFiles , this . classFiles . and ( classFiles ) , this . processors ) ;
this . resourceFiles , this . classFiles . and ( classFiles ) , this . processors ,
this . compilerOptions ) ;
}
/ * *
@ -182,7 +191,7 @@ public final class TestCompiler {
@@ -182,7 +191,7 @@ public final class TestCompiler {
List < Processor > mergedProcessors = new ArrayList < > ( this . processors ) ;
mergedProcessors . addAll ( Arrays . asList ( processors ) ) ;
return new TestCompiler ( this . classLoader , this . compiler , this . sourceFiles ,
this . resourceFiles , this . classFiles , mergedProcessors ) ;
this . resourceFiles , this . classFiles , mergedProcessors , this . compilerOptions ) ;
}
/ * *
@ -194,7 +203,32 @@ public final class TestCompiler {
@@ -194,7 +203,32 @@ public final class TestCompiler {
List < Processor > mergedProcessors = new ArrayList < > ( this . processors ) ;
processors . forEach ( mergedProcessors : : add ) ;
return new TestCompiler ( this . classLoader , this . compiler , this . sourceFiles ,
this . resourceFiles , this . classFiles , mergedProcessors ) ;
this . resourceFiles , this . classFiles , mergedProcessors , this . compilerOptions ) ;
}
/ * *
* Create a new { @link TestCompiler } instance with the additional compiler options .
* @param options the additional compiler options
* @return a new { @code TestCompiler } instance
* @since 6 . 1
* /
public TestCompiler withCompilerOptions ( String . . . options ) {
List < String > mergedCompilerOptions = Stream . concat ( this . compilerOptions . stream ( ) ,
Arrays . stream ( options ) ) . distinct ( ) . toList ( ) ;
return new TestCompiler ( this . classLoader , this . compiler , this . sourceFiles ,
this . resourceFiles , this . classFiles , this . processors , mergedCompilerOptions ) ;
}
/ * *
* Create a new { @link TestCompiler } instance that fails if any warning is
* encountered . This sets the { @code - Xlint : all } and { @code - Werror } compiler
* options .
* @return a new { @code TestCompiler } instance
* @since 6 . 1
* @see # withCompilerOptions ( String . . . )
* /
public TestCompiler failOnWarning ( ) {
return withCompilerOptions ( "-Xlint:all" , "-Werror" ) ;
}
/ * *
@ -275,8 +309,8 @@ public final class TestCompiler {
@@ -275,8 +309,8 @@ public final class TestCompiler {
standardFileManager , classLoaderToUse , this . classFiles , this . resourceFiles ) ;
if ( ! this . sourceFiles . isEmpty ( ) ) {
Errors errors = new Errors ( ) ;
CompilationTask task = this . compiler . getTask ( null , fileManager , errors , null ,
null , compilationUnits ) ;
CompilationTask task = this . compiler . getTask ( null , fileManager , errors ,
this . compilerOptions , null , compilationUnits ) ;
if ( ! this . processors . isEmpty ( ) ) {
task . setProcessors ( this . processors ) ;
}