-
Notifications
You must be signed in to change notification settings - Fork 3
/
jacoco.gradle
110 lines (96 loc) · 3.21 KB
/
jacoco.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import groovy.lang.Closure;
apply plugin: 'scala'
def jacocoVersion = '0.6.3'
def jacocoAgent = "org.jacoco.agent-${jacocoVersion}.jar"
configurations { jacoco }
dependencies {
jacoco "org.jacoco:org.jacoco.agent:$jacocoVersion"
jacoco "org.jacoco:org.jacoco.ant:$jacocoVersion"
}
def jacocoConvention = new JacocoPluginConvention(project)
project.convention.plugins.jacoco = jacocoConvention
class JacocoPluginConvention {
def reportPath
def coverageFileName
def tmpDir
def includes
def excludes
def exclclassloader
def append
def sessionid
def dumponexit
def output
def address
def port
def jacoco(Closure close) {
close.delegate = this
close.run()
}
JacocoPluginConvention(Project project) {
reportPath = "${project.reporting.baseDir.absolutePath}/jacoco"
tmpDir = "${project.buildDir}/tmp/jacoco"
coverageFileName = "${tmpDir}/jacoco.exec"
includes = []
excludes = []
exclclassloader = []
sessionid = null
append = false
dumponexit = true
output = "file"
address = null
port = null
}
def getParams() {
def params = [:]
params["property"] = "agentvmparam"
params["destfile"] = coverageFileName
if (includes != null && includes.size() > 0) params["includes"] = includes.join(":")
if (excludes != null && excludes.size() > 0) params["excludes"] = excludes.join(":")
if (exclclassloader != null && exclclassloader.size > 0) params["exclclassloader"] = exclclassloader
if (sessionid != null) params["sessionid"] = sessionid
params["append"] = append
params["dumponexit"] = dumponexit
params["output"] = output
if (address != null) params["address"] = address
if (port != null) params["port"] = port
return params
}
}
test {
testLogging.showStandardStreams = true
doFirst {
ant.taskdef(name:'jacocoagent', classname: 'org.jacoco.ant.AgentTask', classpath: configurations.jacoco.asPath)
ant.jacocoagent(jacocoConvention.getParams())
jvmArgs "${ant.properties.agentvmparam}"
}
doLast {
if (!new File(jacocoConvention.coverageFileName).exists()) {
logger.info("Skipping Jacoco report for ${project.name}. The data file is missing. (Maybe no tests ran in this module?)")
logger.info("The data file was expected at ${jacocoConvention.coverageFileName}")
return
}
ant.taskdef(name:'jacocoreport', classname: 'org.jacoco.ant.ReportTask', classpath: configurations.jacoco.asPath)
ant.mkdir dir: "${jacocoConvention.reportPath}"
ant.jacocoreport {
executiondata {
ant.file file: "${jacocoConvention.coverageFileName}"
}
structure(name: project.name) {
classfiles {
fileset dir: "${sourceSets.main.output.classesDir}"
}
sourcefiles {
sourceSets.main.java.srcDirs.each {
// when overriding source sets or syncing projects with empty src dirs from
// certain VCS systems, it can happen that the source directory doesn't exist
if (it.exists()) {
fileset(dir: it.absolutePath)
}
}
}
}
xml destfile: "${jacocoConvention.reportPath}/jacoco.xml"
html destdir: "${jacocoConvention.reportPath}"
}
}
}