Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion findbugs-init.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@ gradle.projectsEvaluated {
}
}

//Findbugs task
/**
* Findbugs task.
* @deprecated
* Deprecated in favour of spotbugs, see
* https://github.com/gradle/gradle/issues/7028.
* Will be removed when latest Android Gradle plug-in requires a
* version of Gradle that does not support findbugs.
* @param project Project to which a findbugs task will be added.
*/
@Deprecated
void addFindBugsTask(final Project project) {
project.apply plugin:FINDBUGS
project.tasks.create([name:FINDBUGS,
Expand Down
86 changes: 86 additions & 0 deletions spotbugs-init.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import org.gradle.api.Project
import org.gradle.api.file.FileCollection

ext.SPOTBUGS = 'spotbugs'
rootProject {
buildscript {
repositories {
maven {
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
classpath 'com.github.spotbugs:spotbugs-gradle-plugin:3.0.0'
}
}
}

gradle.projectsEvaluated {
ext.applySpotBugs = {
if (project.hasProperty('android') &&
!project.hasProperty(SPOTBUGS)) {
addSpotBugsTask project
}
}
if (rootProject.subprojects.isEmpty()) {
rootProject applySpotBugs
} else {
rootProject.subprojects applySpotBugs
}
}

//Spotbugs task
void addSpotBugsTask(final Project project) {
project.apply plugin:'com.github.spotbugs'
project.sourceSets {
main {
java.srcDirs = ['main', 'androidTest', 'test'].collect {
project.android.sourceSets.findByName(it)
}.find { null != it }.collect { it.java.srcDirs }
}
}
project.tasks.matching { it.name.startsWith(SPOTBUGS) }.each {
it.with {
// Find excludes filter
final String CONFIG_NAME = 'findbugs-filter.xml'
if (rootProject.file(CONFIG_NAME).exists()) {
excludeFilter rootProject.file(CONFIG_NAME)
} else {
for (final File dir : startParameter.initScripts) {
if (new File(dir.parentFile, CONFIG_NAME).exists()) {
excludeFilter new File(dir.parentFile, CONFIG_NAME)
break
}
}
}
//excludeFilter script.file(CONFIG_NAME)
classes = getDebugSources(project)
classpath = project.configurations.compile + files(project.android.bootClasspath)
effort = 'max'
reportLevel = 'low'
reports {
// html.enabled = true
xml {
// enabled = false
withMessages = true
}
}
ignoreFailures = true // Don't report error if there are bugs found.
}
}
}

FileCollection getDebugSources(final Project project) {
FileCollection classes = project.files()
for (final String variantType : ['applicationVariants', 'libraryVariants', 'testVariants']) {
if (project.android.hasProperty(variantType)) {
project.android."${variantType}".all { variant ->
if (variant.buildType.name == 'debug') {
classes += files("${variant.javaCompileProvider.get().destinationDir}")
}
}
}
}
classes
}

2 changes: 1 addition & 1 deletion static-checker-init.groovy
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apply from:'checkstyle-init.groovy'
apply from:'detekt-init.groovy'
apply from:'findbugs-init.groovy'
apply from:'ktlint-init.groovy'
apply from:'pmd-init.groovy'
apply from:'sonar-init.groovy'
apply from:'spotbugs-init.groovy'