-
Notifications
You must be signed in to change notification settings - Fork 8
/
findbugs-init.groovy
84 lines (80 loc) · 2.93 KB
/
findbugs-init.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import org.gradle.api.Project
import org.gradle.api.file.FileCollection
ext.FINDBUGS = 'findbugs'
gradle.projectsEvaluated {
ext.applyFindBugs = {
if (project.hasProperty('android')) {
repositories {
mavenCentral()
}
if (!project.hasProperty(FINDBUGS)) {
addFindBugsTask project
}
}
}
if (rootProject.subprojects.isEmpty()) {
rootProject applyFindBugs
} else {
rootProject.subprojects applyFindBugs
}
}
//Findbugs task
void addFindBugsTask(final Project project) {
project.apply plugin:FINDBUGS
project.tasks.create([name:FINDBUGS,
type:FindBugs,
dependsOn:[project.assembleRelease],]) {
// 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)
source = ['main', 'androidTest', 'test'].collect {
project.android.sourceSets.findByName(it)
}.find { null != it }.collect { it.java.srcDirs }
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.
}
// Flavourless projects need assembleDebugAndroidTest
// Flavoured projects need assembleAndroidTest
for (final String taskProperty : ['assembleDebugAndroidTest',
'assembleAndroidTest',
'assembleDebugUnitTest',
'assembleUnitTest',]) {
if (project.hasProperty(taskProperty)) {
project.tasks.findbugs.dependsOn += [taskProperty]
}
}
project.check.dependsOn += [project.tasks.findbugs]
}
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
}