Add SpotBugs CI check

This commit is contained in:
ByteHamster 2021-03-27 16:17:14 +01:00
parent 0d1241be66
commit 3946f986d7
3 changed files with 55 additions and 0 deletions

View File

@ -90,3 +90,12 @@ workflows:
- run: - run:
name: Lint name: Lint
command: ./gradlew lintPlayRelease command: ./gradlew lintPlayRelease
- build:
name: SpotBugs
build-steps:
- run:
name: SpotBugs (Modules with Play flavour)
command: ./gradlew spotbugsPlayDebug | grep "\[SpotBugs\]"
- run:
name: SpotBugs (Modules without Play flavour)
command: ./gradlew spotbugsDebug | grep "\[SpotBugs\]"

View File

@ -9,6 +9,7 @@ buildscript {
classpath 'com.android.tools.build:gradle:3.6.3' classpath 'com.android.tools.build:gradle:3.6.3'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:1.0.2' classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:1.0.2'
classpath 'de.timfreiheit.resourceplaceholders:placeholders:0.3' classpath 'de.timfreiheit.resourceplaceholders:placeholders:0.3'
classpath "gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.7.0"
} }
} }
@ -25,6 +26,38 @@ allprojects {
options.compilerArgs << "-Xlint" options.compilerArgs << "-Xlint"
} }
} }
apply plugin: 'com.github.spotbugs'
spotbugs {
effort = 'max'
reportLevel = 'high' // for now
excludeFilter = rootProject.file('config/spotbugs/exclude.xml')
ignoreFailures = true // Handled by printing task
}
gradle.taskGraph.beforeTask { task ->
if (task.name.toLowerCase().contains('spotbugs')) {
task.doLast {
def reportFile = task.project.file("build/reports/spotbugs/playDebug.xml")
if (!reportFile.exists()) return
def slurped = new XmlSlurper().parse(reportFile)
def foundErrors = false
slurped['BugInstance'].each { bug ->
logger.error "[SpotBugs] ${bug['LongMessage']} [${bug.@'type'}]"
bug['SourceLine'].each { line ->
logger.error "[SpotBugs] ${line['Message']}"
foundErrors = true
}
}
if (foundErrors) {
throw new TaskExecutionException(task,
new Exception("SpotBugs violations were found. See output above for details."))
}
}
}
}
} }
// Disable predex if requested (we can"t predex in Circle CI // Disable predex if requested (we can"t predex in Circle CI

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
<Match>
<Bug pattern="v WEAK_MESSAGE_DIGEST_MD5"/>
</Match>
<Match>
<Bug pattern="v LI_LAZY_INIT_UPDATE_STATIC"/>
</Match>
<Match>
<Bug pattern="NM_SAME_SIMPLE_NAME_AS_SUPERCLASS"/>
<Class name="de.danoeh.antennapod.menuhandler.MenuItemUtils"/>
</Match>
</FindBugsFilter>