Skip to content

Commit

Permalink
Update findbugs config
Browse files Browse the repository at this point in the history
  • Loading branch information
Sloy committed May 17, 2019
1 parent 0f32231 commit 5b295df
Showing 1 changed file with 95 additions and 13 deletions.
108 changes: 95 additions & 13 deletions config/android-quality.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,59 @@ task pmd(type: Pmd) {
}
}

task findbugs(type: FindBugs, dependsOn: assemble) {
description 'Run findbugs'
group 'verification'

classes = fileTree('build/intermediates/classes/')
source = fileTree('src/main/java/')
classpath = files()
includeFilter = file("$rootProject.projectDir/config/findbugs/findbugs-config.xml")
excludeFilter = file("$rootProject.projectDir/config/findbugs/findbugs-excludes.xml")
ignoreFailures = false

reports {
xml.enabled = false
html.enabled = true
// Excludes based on https://github.com/ChaitanyaPramod/findbugs-android
def androidDataBindingExcludes =
['android/databinding/**/*.class',
'**/android/databinding/*Binding.class',
'**/BR.*'].asImmutable()

def Collection<String> androidExcludes =
['**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*.bin'
].asImmutable()

def Collection<String> butterKnifeExcludes =
['**/*$ViewInjector*.*',
'**/*$ViewBinder*.*'].asImmutable()

def Collection<String> dagger2Excludes =
['**/*_MembersInjector.class',
'**/Dagger*Component.class',
'**/Dagger*Component$Builder.class',
'**/*Module_*Factory.class'].asImmutable()

def Collection<String> defaultExcludes =
(androidDataBindingExcludes + androidExcludes + butterKnifeExcludes + dagger2Excludes)
.asImmutable()

getVariants().all { variant ->
task("findbugs${variant.name.capitalize()}", type: FindBugs) {
description "Analyze ${variant.name} code with the findbugs tool"
group "Verification"

source = variant.javaCompile.source
classes = project.fileTree(dir: variant.javaCompile.destinationDir, excludes: defaultExcludes)
classpath = variant.javaCompile.classpath

reports {
xml.enabled = isTravis
html.enabled = !isTravis
}
dependsOn variant.javaCompile
}
}

task findbugs() {
description "Analyze code with the findbugs tool"
group "Verification"

dependsOn tasks.withType(FindBugs)
}

task checkstyle(type: Checkstyle) {
description 'Run checkstyle'
group 'verification'
Expand Down Expand Up @@ -97,4 +133,50 @@ task jacocoTestReport(type: JacocoReport, dependsOn: 'testDebugUnitTest') {
classDirectories = files([debugTree])
executionData = files(["${buildDir}/jacoco/testDebugUnitTest.exec",
"${buildDir}/outputs/code-coverage/connected/coverage.ec"])
}

getVariants()
.matching { it.getBuildType().isDebuggable() }
.all { variant ->
task("jacocoTestReport${variant.name.capitalize()}", type: JacocoReport) {
description "Generate Jacoco coverage reports after running ${variant.name} tests."
group = 'reporting'

def fileFilter = ['**/R.class',
'**/R$*.class',
'**/BR.class',
'**/*Binding.class',
'**/*$ViewInjector*.*',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*Test*.*',
'**/*$InjectAdapter.class',
'**/*$ModuleAdapter.class',
'**/*Module.class',
'**/*Module_*Factory.class',
'**/*Component.class',
'**/AutoValue_*.*',
'**/*$$*',
'android/**/*.*']

def debugTree = fileTree(dir: "$project.buildDir/intermediates/classes/${variant.dirName}", excludes: fileFilter)

sourceDirectories = files([variant.javaCompile.source])
classDirectories = files([debugTree])
executionData = files(["${buildDir}/jacoco/test${variant.name.capitalize()}UnitTest.exec"])

reports {
xml.enabled = isTravis
html.enabled = true
}
dependsOn "test${variant.name.capitalize()}UnitTest"
}
}

private def getVariants() {
if (plugins.findPlugin('com.android.library')) {
project.android.libraryVariants
} else {
project.android.applicationVariants.matching { it.isSigningReady() }
}
}

0 comments on commit 5b295df

Please sign in to comment.