Add support for running Android lint on java and android modules.
Add a rule that runs Android lint on each java and android module
and produces reports in xml, html and text formats.
Bug: 153485543
Test: m out/soong/.intermediates/packages/apps/Settings/Settings-core/android_common/lint-report.html
Change-Id: I5a530975b73ba767fef45b257d4f9ec901a19fcb
Merged-In: I5a530975b73ba767fef45b257d4f9ec901a19fcb
(cherry picked from commit 014489c1e6
)
This commit is contained in:
27
java/java.go
27
java/java.go
@@ -475,6 +475,7 @@ type Module struct {
|
||||
|
||||
hiddenAPI
|
||||
dexpreopter
|
||||
linter
|
||||
|
||||
// list of the xref extraction files
|
||||
kytheFiles android.Paths
|
||||
@@ -494,6 +495,7 @@ func (j *Module) addHostAndDeviceProperties() {
|
||||
j.AddProperties(
|
||||
&j.deviceProperties,
|
||||
&j.dexpreoptProperties,
|
||||
&j.linter.properties,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1635,6 +1637,28 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
|
||||
outputFile = implementationAndResourcesJar
|
||||
}
|
||||
|
||||
if ctx.Device() {
|
||||
lintSDKVersionString := func(sdkSpec sdkSpec) string {
|
||||
if v := sdkSpec.version; v.isNumbered() {
|
||||
return v.String()
|
||||
} else {
|
||||
return ctx.Config().DefaultAppTargetSdk()
|
||||
}
|
||||
}
|
||||
|
||||
j.linter.name = ctx.ModuleName()
|
||||
j.linter.srcs = srcFiles
|
||||
j.linter.srcJars = srcJars
|
||||
j.linter.classpath = append(append(android.Paths(nil), flags.bootClasspath...), flags.classpath...)
|
||||
j.linter.classes = j.implementationJarFile
|
||||
j.linter.minSdkVersion = lintSDKVersionString(j.minSdkVersion())
|
||||
j.linter.targetSdkVersion = lintSDKVersionString(j.targetSdkVersion())
|
||||
j.linter.compileSdkVersion = lintSDKVersionString(j.sdkVersion())
|
||||
j.linter.javaLanguageLevel = flags.javaVersion.String()
|
||||
j.linter.kotlinLanguageLevel = "1.3"
|
||||
j.linter.lint(ctx)
|
||||
}
|
||||
|
||||
ctx.CheckbuildFile(outputFile)
|
||||
|
||||
// Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource
|
||||
@@ -2235,6 +2259,7 @@ func TestFactory() android.Module {
|
||||
|
||||
module.Module.properties.Installable = proptools.BoolPtr(true)
|
||||
module.Module.dexpreopter.isTest = true
|
||||
module.Module.linter.test = true
|
||||
|
||||
InitJavaModule(module, android.HostAndDeviceSupported)
|
||||
return module
|
||||
@@ -2249,6 +2274,7 @@ func TestHelperLibraryFactory() android.Module {
|
||||
|
||||
module.Module.properties.Installable = proptools.BoolPtr(true)
|
||||
module.Module.dexpreopter.isTest = true
|
||||
module.Module.linter.test = true
|
||||
|
||||
InitJavaModule(module, android.HostAndDeviceSupported)
|
||||
return module
|
||||
@@ -2823,6 +2849,7 @@ func DefaultsFactory() android.Module {
|
||||
&DexImportProperties{},
|
||||
&android.ApexProperties{},
|
||||
&RuntimeResourceOverlayProperties{},
|
||||
&LintProperties{},
|
||||
)
|
||||
|
||||
android.InitDefaultsModule(module)
|
||||
|
Reference in New Issue
Block a user