Эх сурвалжийг харах

build.gradle: Refactor spotbugs setup

 - 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 <alvaro.brey@nextcloud.com>
Álvaro Brey Vilas 3 жил өмнө
parent
commit
14c1e8d718

+ 24 - 21
build.gradle

@@ -21,7 +21,7 @@ buildscript {
     dependencies {
     dependencies {
         classpath 'com.android.tools.build:gradle:7.0.3'
         classpath 'com.android.tools.build:gradle:7.0.3'
         classpath 'com.hiya:jacoco-android:0.2'
         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 "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
         classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.18.1"
         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
         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'
     check.dependsOn 'checkstyle', 'spotbugsGplayDebugReport', 'pmd', 'lint', 'ktlint', 'detekt'
 
 
     buildFeatures {
     buildFeatures {
@@ -472,3 +452,26 @@ shot {
 jacoco {
 jacoco {
     toolVersion = "$jacoco_version"
     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")
+        }
+    }
+}

+ 1 - 10
scripts/analysis/findbugs-up.rb

@@ -47,16 +47,7 @@ require 'xmlsimple'
 
 
 # run FindBugs
 # run FindBugs
 puts "running 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
 # find FindBugs report file
 findbugs_reports = Dir.glob(FINDBUGS_REPORT_FILE)
 findbugs_reports = Dir.glob(FINDBUGS_REPORT_FILE)