public class TestLintTask
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
TestLintTask.ErrorMessageChecker
Interface to implement to configure the lint driver to check all reported error
messages.
|
static interface |
TestLintTask.GradleMockModifier
Interface to implement to modify the Gradle builder model that is mocked
from a
TestFiles.gradle(String) test file. |
static interface |
TestLintTask.LintDriverConfigurator
Interface to implement to configure the lint driver before lint starts
running.
|
Modifier and Type | Field and Description |
---|---|
boolean |
forceSymbolResolutionErrors |
protected ProjectDescription[] |
projects |
java.io.File |
sdkHome |
Constructor and Description |
---|
TestLintTask()
Creates a new lint test task
|
TestLintTask(ProjectDescription[] projects)
Creates a new lint test task
|
Modifier and Type | Method and Description |
---|---|
TestLintTask |
allowCompilationErrors()
Configures the test task to allow compilation errors in the test files (normally not
allowed)
|
TestLintTask |
allowCompilationErrors(boolean allow)
Sets whether the test task should allow compilation errors in the test files
|
TestLintTask |
allowSystemErrors(boolean allow)
Sets whether the test task should silently ignore lint infrastructure errors
(such as missing .class files etc)
|
TestLintTask |
checkMessage(TestLintTask.ErrorMessageChecker checker)
Configures a custom error message checker to invoke on each reported error.
|
TestLintTask |
client(TestLintClient client)
Configures lint to run with a custom lint client instead of the
default one.
|
TestLintTask |
configureDriver(TestLintTask.LintDriverConfigurator configurator)
Registers a hook to initialize the lint driver during test execution
|
java.util.List<com.android.tools.lint.detector.api.Project> |
createProjects(boolean keepFiles)
Creates lint test projects according to the configured project descriptions.
|
TestLintTask |
customRules(java.io.File... customRuleJars)
Configures the test task to look for issues in the given set of custom rule jars
|
TestLintTask |
customScope(java.util.EnumSet<com.android.tools.lint.detector.api.Scope> customScope)
Configures a custom scope to use when lint is run instead of the default one
|
TestLintTask |
detector(com.android.tools.lint.detector.api.Detector detector)
Configures the test task to use the given detector when
determining which issues to run.
|
TestLintTask |
files(TestFile... files)
Configures the test task to check the given test files
|
TestLintTask |
forceSymbolResolutionErrors()
Tells the lint infrastructure to simulate symbol resolution errors.
|
java.util.List<com.android.tools.lint.detector.api.Issue> |
getCheckedIssues()
Returns the list of issues to be checked by this run.
|
TestLintTask |
ignoreUnknownGradleConstructs()
Tells the lint infrastructure to silently ignore any unknown Gradle constructs
it encounters when processing a Gradle file and attempting to build up mocks
for the Gradle builder model
|
TestLintTask |
incremental()
Configures the test task to run incrementally.
|
TestLintTask |
incremental(java.lang.String currentFileName)
Configures the test task to run incrementally, with the given file as
the current file
|
TestLintTask |
issueIds(java.lang.String... ids)
Configures the test task to look for the given set of issue ids.
|
TestLintTask |
issues(com.android.tools.lint.detector.api.Issue... issues)
Configures the test task to look for the given set of issues.
|
static TestLintTask |
lint()
Creates a new lint test task
|
TestLintTask |
listener(com.android.tools.lint.client.api.LintListener listener)
Configures the lint task to notify the given {@link LintListener during
execution.
|
TestLintTask |
modifyGradleMocks(TestLintTask.GradleMockModifier mockModifier)
This method allows you to add a hook which you can run on a mock
builder model to tweak it, such as changing or augmenting the builder model
classes
|
void |
populateProjectDirectory(ProjectDescription project,
java.io.File projectDir,
TestFile... testFiles) |
TestLintTask |
projects(ProjectDescription... projects)
Configures the test task to check the given test projects
|
TestLintResult |
run()
Performs the lint check, returning the results of the lint check.
|
TestLintTask |
sdkHome(java.io.File sdkHomeOverride)
Configures the lint task with a given SDK home to use instead of the
default one.
|
TestLintTask |
skipExtraTokenChecks()
Normally lint will run your detectors twice, first on the
plain source code, and then a second time where it has inserted whitespace
and parentheses pretty much everywhere, to help catch bugs where your detector
is only checking direct parents or siblings rather than properly allowing for
whitespace and parenthesis nodes which can be present for example when using
PSI inside the IDE.
|
TestLintTask |
supportResourceRepository(boolean supportResourceRepository)
Normally resource repositories are only provided in incremental/single-file
lint runs.
|
TestLintTask |
variant(java.lang.String variantName)
Tells lint to select a particular Gradle variant.
|
protected ProjectDescription[] projects
public java.io.File sdkHome
public boolean forceSymbolResolutionErrors
public TestLintTask()
public TestLintTask(@NonNull ProjectDescription[] projects)
@NonNull public static TestLintTask lint()
public TestLintTask projects(@NonNull ProjectDescription... projects)
public TestLintTask files(@NonNull TestFile... files)
public TestLintTask allowCompilationErrors()
public TestLintTask allowCompilationErrors(boolean allow)
public TestLintTask allowSystemErrors(boolean allow)
public TestLintTask incremental(@NonNull java.lang.String currentFileName)
currentFileName
- the relative path to the current filepublic TestLintTask detector(@NonNull com.android.tools.lint.detector.api.Detector detector)
issues(Issue...)
you do not need to call this method,
but for detectors that report a lot of issues, this is more
convenient. (This requires the set of issues produced by a detector
to be static fields in the detector class.)detector
- the detector to use to discover the set of issuespublic TestLintTask issues(@NonNull com.android.tools.lint.detector.api.Issue... issues)
issues
- the set of issues to checkpublic TestLintTask issueIds(@NonNull java.lang.String... ids)
ids
- the set of issues to check@NonNull public TestLintTask customRules(@NonNull java.io.File... customRuleJars)
customRuleJars
- the jar files to look for issues inpublic TestLintTask incremental()
incremental(String)
instead.public TestLintTask listener(@NonNull com.android.tools.lint.client.api.LintListener listener)
listener
- the listener to registerpublic TestLintTask sdkHome(java.io.File sdkHomeOverride)
sdkHomeOverride
- the root directory of a custom SDK to usepublic TestLintTask modifyGradleMocks(@NonNull TestLintTask.GradleMockModifier mockModifier)
public TestLintTask configureDriver(@NonNull TestLintTask.LintDriverConfigurator configurator)
configurator
- the callback to configure the lint driverpublic TestLintTask customScope(@Nullable java.util.EnumSet<com.android.tools.lint.detector.api.Scope> customScope)
customScope
- the scope to configure lint withpublic TestLintTask checkMessage(@NonNull TestLintTask.ErrorMessageChecker checker)
checker
- the checker to invokepublic TestLintTask client(@Nullable TestLintClient client)
client
- the custom client to usepublic TestLintTask variant(java.lang.String variantName)
variantName
- the name of the variant to usepublic TestLintTask skipExtraTokenChecks()
public TestLintTask ignoreUnknownGradleConstructs()
public TestLintTask forceSymbolResolutionErrors()
public TestLintTask supportResourceRepository(boolean supportResourceRepository)
supportResourceRepository
- if true, provide a resource repository to detectors that ask
for it.@NonNull public TestLintResult run()
@NonNull public java.util.List<com.android.tools.lint.detector.api.Project> createProjects(boolean keepFiles)
run()
method is called. This method is intended mainly for testing
the lint infrastructure itself. Most detector tests will just want to
use run()
.keepFiles
- if true, don't delete the generated temporary project source filespublic void populateProjectDirectory(@NonNull ProjectDescription project, @NonNull java.io.File projectDir, @NonNull TestFile... testFiles) throws java.io.IOException
java.io.IOException
@NonNull public java.util.List<com.android.tools.lint.detector.api.Issue> getCheckedIssues()
issues(Issue...)
is called to register issues, this will be the
exact set of issues used, otherwise the issues found as fields in the
detector passed to detector(Detector)
is used.