-
Notifications
You must be signed in to change notification settings - Fork 8
/
pmd-init.groovy
47 lines (43 loc) · 1.42 KB
/
pmd-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
import org.gradle.api.Project
ext.PMD = 'pmd'
gradle.projectsEvaluated {
ext.applyPmd = {
if (project.hasProperty('android')
&& !project.hasProperty(PMD)) {
setConfig(project)
repositories {
mavenCentral()
}
apply plugin:PMD
//PMD task
task pmd(type:Pmd) {
ruleSets = rootProject.ext.ruleSets
source = ['main', 'androidTest', 'test'].collect {
project.android.sourceSets.findByName(it)
}.find { null != it }.collect { it.java.srcDirs }
exclude '**/*.kt'
ignoreFailures = true // Don't report error if there are bugs found.
}
project.check.dependsOn += [project.tasks.pmd]
}
}
if (rootProject.subprojects.isEmpty()) {
rootProject applyPmd
} else {
rootProject.subprojects applyPmd
}
}
File setConfig(final Project project) {
final String CONFIG_NAME = 'pmd.config'
// Find ruleSets config file
if (rootProject.file(CONFIG_NAME).exists()) {
project.apply from:rootProject.file(CONFIG_NAME)
} else {
for (final File dir : startParameter.initScripts) {
if (new File(dir.parentFile, CONFIG_NAME).exists()) {
project.apply from:new File(dir.parentFile, CONFIG_NAME)
break
}
}
}
}