forked from spring-attic/grails-data-mapping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clover.gradle
94 lines (80 loc) · 2.46 KB
/
clover.gradle
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
84
85
86
87
88
89
90
91
92
93
94
apply plugin: "groovy"
def cloverConvention = new CloverPluginConvention(project)
project.convention.plugins.clover = cloverConvention
class CloverPluginConvention {
def classesBackupDir
def licenseFile
def clover(Closure close) {
close.delegate = this
close.run()
}
CloverPluginConvention(Project project) {
classesBackupDir = "${project.sourceSets.main.classesDir}-bak"
licenseFile = "/Developer/grails-dev/core/inconsequential/clover.license"
}
}
dependencies {
testRuntime "com.cenqua.clover:clover:3.0.2"
}
test.doFirst {
if (project.hasProperty("withClover")) {
ant.taskdef(name: 'groovyc', classname:"org.codehaus.groovy.ant.Groovyc", classpath:configurations.testRuntime.asPath)
ant.taskdef(resource:"cloverlib.xml", classpath:configurations.testRuntime.asPath)
ant.property(name:"clover.license.path", value:cloverConvention.licenseFile)
ant."clover-clean"()
ant.'clover-setup'(initString: "${buildDir}/clover/clover.db", tmpDir: "${buildDir}/clover/tmp") {
["java", "groovy"].each { source ->
["main", "test"].each { type ->
sourceSets."$type"."$source".srcDirs.each {
if (it.exists()) {
ant.fileset(dir: it) {
include(name: "**/*.groovy")
include(name: "**/*.java")
}
}
}
}
}
}
//move original classes
ant.move(file:sourceSets.main.classesDir, tofile:cloverConvention.classesBackupDir)
//compile instrumented classes
sourceSets.main.classesDir.mkdirs()
ant.groovyc(
destdir:sourceSets.main.classesDir,
fork: true,
verbose: true
) {
classpath {
pathElement path:configurations.testCompile.asPath
}
javac(source:sourceCompatibility, target: targetCompatibility) {
classpath {
pathElement path:configurations.testRuntime.asPath
}
}
["java", "groovy"].each { source ->
sourceSets.main."$source".srcDirs.each {
if (it.exists()) {
src(path: it)
}
}
}
}
//copy resources
ant.copy(todir:sourceSets.main.classesDir) {
fileset(dir:cloverConvention.classesBackupDir, excludes:"**/*.class")
}
}
}
test.doLast {
if (project.hasProperty("withClover") && new File(cloverConvention.classesBackupDir).exists()) {
// restore original classes
ant.delete(file: sourceSets.main.classesDir)
ant.move(file:cloverConvention.classesBackupDir, tofile:sourceSets.main.classesDir)
ant."clover-report" {
current(outfile:"${reportsDir}/clover/clover.xml")
}
ant."clover-html-report"(outdir:"${reportsDir}/clover/html");
}
}