Class TestConfigurationBuilder
- java.lang.Object
-
- org.checkerframework.framework.test.TestConfigurationBuilder
-
public class TestConfigurationBuilder extends java.lang.Object
Used to create an instance of TestConfiguration. TestConfigurationBuilder is fluent: it returns itself after every call so you can string together configuration methods as follows:new TestConfigurationBuilder() .addOption("-Awarns") .addSourceFile("src1.java") .addDiagnosticFile("src1.out")
- See Also:
TestConfiguration
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
TESTS_OUTPUTDIR
The output directory for tests.
-
Constructor Summary
Constructors Constructor Description TestConfigurationBuilder()
Note: There are static helper methods named buildConfiguration and buildConfigurationBuilder that can be used to create the most common types of configurationsTestConfigurationBuilder(TestConfiguration initialConfig)
Create a builder that has all of the options in initialConfig.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description TestConfigurationBuilder
addDiagnosticFile(java.io.File diagnostics)
Adds the given diagnostics file tothis
.TestConfigurationBuilder
addDiagnosticFiles(java.lang.Iterable<java.io.File> diagnostics)
Adds the given diagnostics files tothis
.TestConfigurationBuilder
adddToPathOption(java.lang.String key, java.lang.String toAppend)
Adds the given path option tothis
.TestConfigurationBuilder
addOption(java.lang.String option)
Adds the given option tothis
.TestConfigurationBuilder
addOption(java.lang.String option, java.lang.String value)
Adds the given option and value tothis
.TestConfigurationBuilder
addOptionIfValueNonEmpty(java.lang.String option, java.lang.String value)
Adds the given option tothis
if the value is non-empty.TestConfigurationBuilder
addOptions(java.lang.Iterable<java.lang.String> newOptions)
Adds the given options tothis
.TestConfigurationBuilder
addOptions(java.util.Map<java.lang.String,@Nullable java.lang.String> options)
Adds the given options tothis
.TestConfigurationBuilder
addProcessor(@BinaryName java.lang.String processor)
Add a processor.TestConfigurationBuilder
addProcessors(java.lang.Iterable<@BinaryName java.lang.String> processors)
Add processors.TestConfigurationBuilder
addSourceFile(java.io.File sourceFile)
Adds the given source file tothis
.TestConfigurationBuilder
addSourceFiles(java.lang.Iterable<java.io.File> sourceFiles)
Adds the given source files tothis
.TestConfiguration
build()
Creates a TestConfiguration using the settings in this builder.static TestConfiguration
buildDefaultConfiguration(java.lang.String testSourcePath, java.io.File testFile, java.lang.Class<?> processor, java.util.List<java.lang.String> options, boolean shouldEmitDebugInfo)
This is the default configuration used by Checker Framework JUnit tests.static TestConfiguration
buildDefaultConfiguration(java.lang.String testSourcePath, java.lang.Iterable<java.io.File> testSourceFiles, java.lang.Iterable<@BinaryName java.lang.String> processors, java.util.List<java.lang.String> options, boolean shouldEmitDebugInfo)
This is the default configuration used by Checker Framework JUnit tests.static TestConfiguration
buildDefaultConfiguration(java.lang.String testSourcePath, java.lang.Iterable<java.io.File> testSourceFiles, java.util.Collection<java.lang.String> classpathExtra, java.lang.Iterable<@BinaryName java.lang.String> processors, java.util.List<java.lang.String> options, boolean shouldEmitDebugInfo)
This is the default configuration used by Checker Framework JUnit tests.TestConfigurationBuilder
dontEmitDebugInfo()
Setsthis
to not output debug info.TestConfigurationBuilder
emitDebugInfo()
Setsthis
to output debug info.java.util.List<java.lang.String>
flatOptions()
Returns the set of Javac options as a flat list.static java.lang.String
getDefaultClassPath()
Determine the default classpath from thetests.classpath
property.static TestConfigurationBuilder
getDefaultConfigurationBuilder(java.lang.String testSourcePath, java.io.File outputClassDirectory, java.lang.String classPath, java.lang.Iterable<java.io.File> testSourceFiles, java.lang.Iterable<@BinaryName java.lang.String> processors, java.util.List<java.lang.String> options, boolean shouldEmitDebugInfo)
This creates a builder for the default configuration used by Checker Framework JUnit tests.static java.io.File
getOutputDirFromProperty()
Determine the output directory from thetests.outputDir
property.protected void
removeConflicts()
Ensures there are no options conflicting with each other.TestConfigurationBuilder
setDiagnosticFiles(java.util.List<java.io.File> diagnosticFiles)
Sets the diagnostics files ofthis
.TestConfigurationBuilder
setOptions(java.util.Map<java.lang.String,@Nullable java.lang.String> options)
Sets the given options onthis
.TestConfigurationBuilder
setProcessors(java.lang.Iterable<@BinaryName java.lang.String> processors)
Set the processors.TestConfigurationBuilder
setShouldEmitDebugInfo(boolean shouldEmitDebugInfo)
Setsthis
to output debug info depending on the parameter.TestConfigurationBuilder
setSourceFiles(java.util.List<java.io.File> sourceFiles)
Sets the source files ofthis
.java.lang.String
toString()
java.util.List<java.lang.String>
validate(boolean requireProcessors)
Ensures that the minimum requirements for running a test are met.TestConfiguration
validateThenBuild(boolean requireProcessors)
Creates a TestConfiguration using the settings in this builder.
-
-
-
Field Detail
-
TESTS_OUTPUTDIR
public static final java.lang.String TESTS_OUTPUTDIR
The output directory for tests.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TestConfigurationBuilder
public TestConfigurationBuilder()
Note: There are static helper methods named buildConfiguration and buildConfigurationBuilder that can be used to create the most common types of configurations
-
TestConfigurationBuilder
public TestConfigurationBuilder(TestConfiguration initialConfig)
Create a builder that has all of the options in initialConfig.- Parameters:
initialConfig
- initial configuration for the newly-created builder
-
-
Method Detail
-
getDefaultConfigurationBuilder
public static TestConfigurationBuilder getDefaultConfigurationBuilder(java.lang.String testSourcePath, java.io.File outputClassDirectory, java.lang.String classPath, java.lang.Iterable<java.io.File> testSourceFiles, java.lang.Iterable<@BinaryName java.lang.String> processors, java.util.List<java.lang.String> options, boolean shouldEmitDebugInfo)
This creates a builder for the default configuration used by Checker Framework JUnit tests.- Parameters:
testSourcePath
- the path to the Checker test file sources, usually this is the directory of Checker's testsoutputClassDirectory
- the directory to place classes compiled for testingclassPath
- the classpath to use for compilationtestSourceFiles
- the Java files that compose the testprocessors
- the checkers or other annotation processors to run over the testSourceFilesoptions
- the options to the compiler/processorsshouldEmitDebugInfo
- whether or not debug information should be emitted- Returns:
- the builder that will create an immutable test configuration
-
buildDefaultConfiguration
public static TestConfiguration buildDefaultConfiguration(java.lang.String testSourcePath, java.io.File testFile, java.lang.Class<?> processor, java.util.List<java.lang.String> options, boolean shouldEmitDebugInfo)
This is the default configuration used by Checker Framework JUnit tests.- Parameters:
testSourcePath
- the path to the Checker test file sources, usually this is the directory of Checker's teststestFile
- a single test Java file to compileprocessor
- a single checker to include in the processors fieldoptions
- the options to the compiler/processorsshouldEmitDebugInfo
- whether or not debug information should be emitted- Returns:
- a TestConfiguration with input parameters added plus the normal default options, compiler, and file manager used by Checker Framework tests
-
buildDefaultConfiguration
public static TestConfiguration buildDefaultConfiguration(java.lang.String testSourcePath, java.lang.Iterable<java.io.File> testSourceFiles, java.lang.Iterable<@BinaryName java.lang.String> processors, java.util.List<java.lang.String> options, boolean shouldEmitDebugInfo)
This is the default configuration used by Checker Framework JUnit tests.- Parameters:
testSourcePath
- the path to the Checker test file sources, usually this is the directory of Checker's teststestSourceFiles
- the Java files that compose the testprocessors
- the checkers or other annotation processors to run over the testSourceFilesoptions
- the options to the compiler/processorsshouldEmitDebugInfo
- whether or not debug information should be emitted- Returns:
- a TestConfiguration with input parameters added plus the normal default options, compiler, and file manager used by Checker Framework tests
-
buildDefaultConfiguration
public static TestConfiguration buildDefaultConfiguration(java.lang.String testSourcePath, java.lang.Iterable<java.io.File> testSourceFiles, java.util.Collection<java.lang.String> classpathExtra, java.lang.Iterable<@BinaryName java.lang.String> processors, java.util.List<java.lang.String> options, boolean shouldEmitDebugInfo)
This is the default configuration used by Checker Framework JUnit tests.- Parameters:
testSourcePath
- the path to the Checker test file sources, usually this is the directory of Checker's teststestSourceFiles
- the Java files that compose the testclasspathExtra
- extra entries for the classpath, needed to compile the source filesprocessors
- the checkers or other annotation processors to run over the testSourceFilesoptions
- the options to the compiler/processorsshouldEmitDebugInfo
- whether or not debug information should be emitted- Returns:
- a TestConfiguration with input parameters added plus the normal default options, compiler, and file manager used by Checker Framework tests
-
validate
public java.util.List<java.lang.String> validate(boolean requireProcessors)
Ensures that the minimum requirements for running a test are met. These requirements are:- There is at least one source file
- There is at least one processor (if requireProcessors has been set to true)
- There is an output directory specified for class files
- There is no
-processor
option in the optionMap (it should be added by addProcessor instead) - There is no option with prefix "-J-" in the optionMap
- Parameters:
requireProcessors
- whether or not to require that there is at least one processor- Returns:
- a list of errors found while validating this configuration
-
removeConflicts
protected void removeConflicts()
Ensures there are no options conflicting with each other.
-
adddToPathOption
public TestConfigurationBuilder adddToPathOption(java.lang.String key, java.lang.String toAppend)
Adds the given path option tothis
.- Parameters:
key
- the key to addtoAppend
- the path to append- Returns:
- the current object
this
-
addDiagnosticFile
public TestConfigurationBuilder addDiagnosticFile(java.io.File diagnostics)
Adds the given diagnostics file tothis
.- Parameters:
diagnostics
- the diagnostics file to add tothis
- Returns:
- the current object
this
-
addDiagnosticFiles
public TestConfigurationBuilder addDiagnosticFiles(java.lang.Iterable<java.io.File> diagnostics)
Adds the given diagnostics files tothis
.- Parameters:
diagnostics
- diagnostics files to add tothis
- Returns:
- the current object
this
-
setDiagnosticFiles
public TestConfigurationBuilder setDiagnosticFiles(java.util.List<java.io.File> diagnosticFiles)
Sets the diagnostics files ofthis
.- Parameters:
diagnosticFiles
- diagnostics files to set onthis
- Returns:
- the current object
this
-
addSourceFile
public TestConfigurationBuilder addSourceFile(java.io.File sourceFile)
Adds the given source file tothis
.- Parameters:
sourceFile
- source file to add tothis
- Returns:
- the current object
this
-
addSourceFiles
public TestConfigurationBuilder addSourceFiles(java.lang.Iterable<java.io.File> sourceFiles)
Adds the given source files tothis
.- Parameters:
sourceFiles
- source files to add tothis
- Returns:
- the current object
this
-
setSourceFiles
public TestConfigurationBuilder setSourceFiles(java.util.List<java.io.File> sourceFiles)
Sets the source files ofthis
.- Parameters:
sourceFiles
- source files to set onthis
- Returns:
- the current object
this
-
setOptions
public TestConfigurationBuilder setOptions(java.util.Map<java.lang.String,@Nullable java.lang.String> options)
Sets the given options onthis
.- Parameters:
options
- options to set onthis
- Returns:
- the current object
this
-
addOption
public TestConfigurationBuilder addOption(java.lang.String option)
Adds the given option tothis
.- Parameters:
option
- option to add tothis
- Returns:
- the current object
this
-
addOption
public TestConfigurationBuilder addOption(java.lang.String option, java.lang.String value)
Adds the given option and value tothis
.- Parameters:
option
- option to add tothis
value
- value to add- Returns:
- the current object
this
-
addOptionIfValueNonEmpty
public TestConfigurationBuilder addOptionIfValueNonEmpty(java.lang.String option, java.lang.String value)
Adds the given option tothis
if the value is non-empty.- Parameters:
option
- option to add tothis
value
- value to add, iff it is non-empty- Returns:
- the current object
this
-
addOptions
@RequiresNonNull("this.options") public TestConfigurationBuilder addOptions(@UnknownInitialization(TestConfigurationBuilder.class) TestConfigurationBuilder this, java.util.Map<java.lang.String,@Nullable java.lang.String> options)
Adds the given options tothis
.- Parameters:
options
- options to add tothis
- Returns:
- the current object
this
-
addOptions
public TestConfigurationBuilder addOptions(java.lang.Iterable<java.lang.String> newOptions)
Adds the given options tothis
.- Parameters:
newOptions
- options to add tothis
- Returns:
- the current object
this
-
setProcessors
public TestConfigurationBuilder setProcessors(java.lang.Iterable<@BinaryName java.lang.String> processors)
Set the processors.- Parameters:
processors
- the processors to run- Returns:
- this
-
addProcessor
public TestConfigurationBuilder addProcessor(@BinaryName java.lang.String processor)
Add a processor.- Parameters:
processor
- a processor to run- Returns:
- this
-
addProcessors
public TestConfigurationBuilder addProcessors(java.lang.Iterable<@BinaryName java.lang.String> processors)
Add processors.- Parameters:
processors
- processors to run- Returns:
- this
-
emitDebugInfo
public TestConfigurationBuilder emitDebugInfo()
Setsthis
to output debug info.- Returns:
- the current object
this
-
dontEmitDebugInfo
public TestConfigurationBuilder dontEmitDebugInfo()
Setsthis
to not output debug info.- Returns:
- the current object
this
-
setShouldEmitDebugInfo
public TestConfigurationBuilder setShouldEmitDebugInfo(boolean shouldEmitDebugInfo)
Setsthis
to output debug info depending on the parameter.- Parameters:
shouldEmitDebugInfo
- whether to emit debug info- Returns:
- the current object
this
-
build
public TestConfiguration build()
Creates a TestConfiguration using the settings in this builder. The settings are NOT validated first.- Returns:
- a TestConfiguration using the settings in this builder
-
validateThenBuild
public TestConfiguration validateThenBuild(boolean requireProcessors)
Creates a TestConfiguration using the settings in this builder. The settings are first validated and a runtime exception is thrown if any errors are found- Parameters:
requireProcessors
- whether or not there should be at least 1 processor specified, see method validate- Returns:
- a TestConfiguration using the settings in this builder
-
flatOptions
public java.util.List<java.lang.String> flatOptions()
Returns the set of Javac options as a flat list.- Returns:
- the set of Javac options as a flat list
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getOutputDirFromProperty
public static java.io.File getOutputDirFromProperty()
Determine the output directory from thetests.outputDir
property.- Returns:
- the output directory
-
getDefaultClassPath
public static java.lang.String getDefaultClassPath()
Determine the default classpath from thetests.classpath
property.- Returns:
- the default classpath
-
-