-
Notifications
You must be signed in to change notification settings - Fork 8
/
jdepend-init.groovy
59 lines (53 loc) · 1.8 KB
/
jdepend-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
import org.gradle.api.Project
import org.gradle.api.file.FileCollection
projectsEvaluated {
ext.applyJdepend = {
if (project.hasProperty('android')) {
repositories {
jcenter()
}
addJdependTask project
project.check.dependsOn += [project.tasks.jdepend]
}
}
if (rootProject.subprojects.isEmpty()) {
rootProject applyJdepend
} else {
rootProject.subprojects applyJdepend
}
}
// JDepend task
void addJdependTask(final Project project) {
final String TASK_NAME = 'jdepend'
project.apply plugin:TASK_NAME
project.tasks.create([name:TASK_NAME,
type:JDepend,
dependsOn:[project.assembleRelease],]) {
jdependClasspath = setConfig(jdependClasspath)
for (final String variantType : ['applicationVariants', 'libraryVariants',]) {
if (project.android.hasProperty(variantType)) {
project.android."${variantType}".all { variant ->
if (variant.buildType.name == 'release') {
classesDir file("${variant.javaCompileProvider.get().destinationDir}")
}
}
}
}
}
}
FileCollection setConfig(final FileCollection jdependClasspath) {
final String CONFIG_NAME = 'jdepend.properties'
FileCollection result = jdependClasspath
// Find jdepend properties file
if (rootProject.file(CONFIG_NAME).exists()) {
result = result + files(rootProject.projectDir)
} else {
for (final File dir : startParameter.initScripts) {
if (new File(dir.parentFile, CONFIG_NAME).exists()) {
result = result + files(dir.parentFile)
break
}
}
}
result
}