-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Expand file tree
/
Copy pathcode-coverage.gradle
More file actions
100 lines (92 loc) · 3.27 KB
/
code-coverage.gradle
File metadata and controls
100 lines (92 loc) · 3.27 KB
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
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
apply plugin: 'jacoco'
repositories {
mavenCentral()
gradlePluginPortal()
// TODO: Find the way to use the repositories from RepositoriesSetupPlugin
maven {
url = "https://ci.opensearch.org/ci/dbc/snapshots/lucene/"
}
}
allprojects {
plugins.withId('jacoco') {
jacoco.toolVersion = '0.8.13'
}
}
tasks.withType(JacocoReport).configureEach {
group = JavaBasePlugin.VERIFICATION_GROUP
reports {
// Code coverage report in HTML and CSV formats are on demand, in case they take extra disk space.
xml.required = System.getProperty('tests.coverage.report.xml', 'true').toBoolean()
html.required = System.getProperty('tests.coverage.report.html', 'false').toBoolean()
csv.required = System.getProperty('tests.coverage.report.csv', 'false').toBoolean()
}
}
// Enhance jacocoTestReport task to include all test types
allprojects {
plugins.withId('jacoco') {
tasks.matching { it.name == 'jacocoTestReport' }.configureEach {
def executionDataFiles = []
def sourceSetsList = []
if (tasks.findByName('test')) {
executionDataFiles.add("$buildDir/jacoco/test.exec")
sourceSetsList.add(sourceSets.test)
}
if (tasks.findByName('internalClusterTest')) {
executionDataFiles.add("$buildDir/jacoco/internalClusterTest.exec")
sourceSetsList.add(sourceSets.internalClusterTest)
}
if (tasks.findByName('javaRestTest')) {
executionDataFiles.add("$buildDir/jacoco/javaRestTest.exec")
sourceSetsList.add(sourceSets.javaRestTest)
}
if (tasks.findByName('yamlRestTest')) {
executionDataFiles.add("$buildDir/jacoco/yamlRestTest.exec")
sourceSetsList.add(sourceSets.yamlRestTest)
}
if (!executionDataFiles.isEmpty()) {
executionData.setFrom(files(executionDataFiles).filter { it.exists() })
sourceSets(*sourceSetsList)
}
onlyIf {
file("$buildDir/jacoco/test.exec").exists() ||
file("$buildDir/jacoco/internalClusterTest.exec").exists() ||
file("$buildDir/jacoco/javaRestTest.exec").exists() ||
file("$buildDir/jacoco/yamlRestTest.exec").exists()
}
}
}
}
if (System.getProperty("tests.coverage")) {
reporting {
reports {
testCodeCoverageReport(JacocoCoverageReport) {
testSuiteName = "test"
}
testCodeCoverageReportInternalClusterTest(JacocoCoverageReport) {
testSuiteName = "internalClusterTest"
}
testCodeCoverageReportJavaRestTest(JacocoCoverageReport) {
testSuiteName = "javaRestTest"
}
testCodeCoverageReportYamlRestTest(JacocoCoverageReport) {
testSuiteName = "yamlRestTest"
}
}
}
// Attach code coverage report task to Gradle check task
project.getTasks().named(JavaBasePlugin.CHECK_TASK_NAME).configure {
dependsOn(
tasks.named('testCodeCoverageReport', JacocoReport),
tasks.named('testCodeCoverageReportInternalClusterTest', JacocoReport),
tasks.named('testCodeCoverageReportJavaRestTest', JacocoReport),
tasks.named('testCodeCoverageReportYamlRestTest', JacocoReport)
)
}
}