From 14c1e8d7187820d5cf4fc2aeb33b83ce71d48ba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Brey=20Vilas?= Date: Fri, 5 Nov 2021 16:09:33 +0100 Subject: [PATCH 1/3] build.gradle: Refactor spotbugs setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Don't duplicate tasks. Use the ones that spotbugs provides and link them to their sourcesets - Add dependencies to compileSources to the spotbugs tasks - Update spotbugs plugin This results in a much higher amount of issues. They were probably not being properly scanned earlier. Signed-off-by: Álvaro Brey Vilas --- build.gradle | 45 ++++++++++++++++++--------------- scripts/analysis/findbugs-up.rb | 11 +------- 2 files changed, 25 insertions(+), 31 deletions(-) diff --git a/build.gradle b/build.gradle index a5dae74936..d4f9db9140 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:7.0.3' classpath 'com.hiya:jacoco-android:0.2' - classpath 'gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.7.5' + classpath 'com.github.spotbugs.snom:spotbugs-gradle-plugin:4.7.9' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.18.1" classpath "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2 @@ -224,26 +224,6 @@ android { } } - android.applicationVariants.all { variant -> - String variantName = variant.name - String capVariantName = variantName.substring(0, 1).toUpperCase() + variantName.substring(1) - tasks.register("spotbugs${capVariantName}Report", SpotBugsTask) { - ignoreFailures = true // should continue checking - effort = "max" - reportLevel = "medium" - classes = fileTree("$project.buildDir/intermediates/javac/${variantName}/classes/") - excludeFilter = file("${project.rootDir}/spotbugs-filter.xml") - - reports { - xml.enabled = false - html { - enabled = true - destination = file("$project.buildDir/reports/spotbugs/spotbugs.html") - } - } - } - } - check.dependsOn 'checkstyle', 'spotbugsGplayDebugReport', 'pmd', 'lint', 'ktlint', 'detekt' buildFeatures { @@ -472,3 +452,26 @@ shot { jacoco { toolVersion = "$jacoco_version" } + +spotbugs { + ignoreFailures = true // should continue checking + effort = "max" + reportLevel = "medium" +} + +tasks.withType(SpotBugsTask){task -> + String variantNameCap = task.name.replace("spotbugs", "") + String variantName = variantNameCap.substring(0, 1).toLowerCase() + variantNameCap.substring(1) + + dependsOn "compile${variantNameCap}Sources" + + excludeFilter = file("${project.rootDir}/spotbugs-filter.xml") + classes = files("$project.buildDir/intermediates/javac/${variantName}") + reports { + xml.enabled = false + html { + enabled = true + destination = file("$project.buildDir/reports/spotbugs/spotbugs.html") + } + } +} diff --git a/scripts/analysis/findbugs-up.rb b/scripts/analysis/findbugs-up.rb index 0e22755f0e..e66583ac16 100644 --- a/scripts/analysis/findbugs-up.rb +++ b/scripts/analysis/findbugs-up.rb @@ -47,16 +47,7 @@ require 'xmlsimple' # run FindBugs puts "running FindBugs..." -system './gradlew assembleGplayDebug 1>/dev/null' - -# confirm that assemble ran w/out error -result = $?.to_i -if result != 0 - puts "FAIL: failed to run ./gradlew assembleGplayDebug" - exit 1 -end - -system './gradlew spotbugsGplayDebugReport 1>/dev/null 2>&1' +system './gradlew spotbugsGplayDebug 1>/dev/null 2>&1' # find FindBugs report file findbugs_reports = Dir.glob(FINDBUGS_REPORT_FILE) From 9eb2fcc6c1aae48528e24df2ffe098bddb57f33f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Brey=20Vilas?= Date: Mon, 8 Nov 2021 10:37:42 +0100 Subject: [PATCH 2/3] spotbugs: Show list of scanned files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Brey Vilas --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index d4f9db9140..bdd662932e 100644 --- a/build.gradle +++ b/build.gradle @@ -466,7 +466,7 @@ tasks.withType(SpotBugsTask){task -> dependsOn "compile${variantNameCap}Sources" excludeFilter = file("${project.rootDir}/spotbugs-filter.xml") - classes = files("$project.buildDir/intermediates/javac/${variantName}") + classes = fileTree("$project.buildDir/intermediates/javac/${variantName}/classes/") reports { xml.enabled = false html { From be54fa0bcefe98f953d18c9dc563ef009723e054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Brey=20Vilas?= Date: Mon, 8 Nov 2021 13:56:04 +0100 Subject: [PATCH 3/3] Update spotbugs results MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Brey Vilas --- scripts/analysis/findbugs-results.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/analysis/findbugs-results.txt b/scripts/analysis/findbugs-results.txt index 1caed7b767..231a7d578e 100644 --- a/scripts/analysis/findbugs-results.txt +++ b/scripts/analysis/findbugs-results.txt @@ -1 +1 @@ -351 +638