forked from linkedin/venice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
665 lines (588 loc) · 22.1 KB
/
build.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
import com.github.spotbugs.snom.SpotBugsTask
import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.internal.logging.text.StyledTextOutput.Style
import org.gradle.internal.logging.text.StyledTextOutputFactory
import java.nio.file.Files
plugins {
id 'idea'
id 'java'
id 'maven-publish'
id 'com.diffplug.spotless' version '6.12.0'
id 'com.dorongold.task-tree' version '2.1.0'
id 'com.github.johnrengelman.shadow' version '6.1.0' apply false
id 'com.github.spotbugs' version '4.8.0' apply false
id 'org.gradle.test-retry' version '1.5.0' apply false
id 'com.form.diff-coverage' version '0.9.5' apply false
id 'me.champeau.jmh' version '0.6.7' apply false
}
apply from: "$rootDir/gradle/helper/git.gradle"
apply from: "$rootDir/gradle/helper/publishing.gradle"
/*
* This snippet allows the Gradle environment to be overridden with custom
* settings. This is useful in environments (such as a private company) where a
* third party wishes to use custom repositories, or inject certain
* functionality into the default Gradle build lifecycle.
*/
if (project.hasProperty('overrideBuildEnvironment')) {
apply from: file(project.overrideBuildEnvironment)
product {
codeQuality {
ignoreFailures = true
}
}
}
def avroVersion = '1.9.2'
def avroUtilVersion = '0.2.150'
def kafkaGroup = 'com.linkedin.kafka'
def kafkaVersion = '2.4.1.65'
def log4j2Version = '2.17.1'
def pegasusVersion = '29.31.0'
def jacksonVersion = '2.13.3'
ext.libraries = [
avro: 'org.apache.avro:avro:' + avroVersion,
avroCompiler: 'org.apache.avro:avro-compiler:' + avroVersion,
avroMapred: 'org.apache.avro:avro-mapred:' + avroVersion,
avroUtilBuilder: 'com.linkedin.avroutil1:builder:' + avroUtilVersion,
avroUtilCompatHelper: 'com.linkedin.avroutil1:helper-all:' + avroUtilVersion,
avroUtilFastserde: 'com.linkedin.avroutil1:avro-fastserde:' + avroUtilVersion,
avroUtilSpotbugsPlugin: 'com.linkedin.avroutil1:spotbugs-plugin:0.2.69',
bouncyCastle: 'org.bouncycastle:bcprov-jdk15on:1.55',
caffeine: 'com.github.ben-manes.caffeine:caffeine:2.8.5',
classgraph: 'io.github.classgraph:classgraph:4.8.60',
commonsCodec: 'commons-codec:commons-codec:1.4',
commonsConfiguration: 'commons-configuration:commons-configuration:1.9',
commonsIo: 'commons-io:commons-io:2.11.0',
commonsCli: 'commons-cli:commons-cli:1.5.0',
commonsLang: 'commons-lang:commons-lang:2.6',
conscrypt: 'org.conscrypt:conscrypt-openjdk-uber:2.4.0',
d2: 'com.linkedin.pegasus:d2:' + pegasusVersion,
failsafe: 'net.jodah:failsafe:2.4.0',
fastUtil: 'it.unimi.dsi:fastutil:8.3.0',
hadoopCommon: 'org.apache.hadoop:hadoop-common:2.3.0',
helix: 'org.apache.helix:helix-core:1.0.4',
httpAsyncClient: 'org.apache.httpcomponents:httpasyncclient:4.1.2',
httpClient5: 'org.apache.httpcomponents.client5:httpclient5:5.2.1',
httpCore5: 'org.apache.httpcomponents.core5:httpcore5:5.2.1',
httpCore5H2: 'org.apache.httpcomponents.core5:httpcore5-h2:5.2.1',
httpClient: 'org.apache.httpcomponents:httpclient:4.5.2',
httpCore: 'org.apache.httpcomponents:httpcore:4.4.5',
jacksonCore: 'com.fasterxml.jackson.core:jackson-core:' + jacksonVersion,
jacksonAnnotations: 'com.fasterxml.jackson.core:jackson-annotations:' + jacksonVersion,
jacksonDatabind: 'com.fasterxml.jackson.core:jackson-databind:' + jacksonVersion,
javax: 'javax.servlet:javax.servlet-api:3.1.0',
javaxActivation: 'com.sun.activation:javax.activation:1.2.0',
jdom: 'org.jdom:jdom:1.1',
jna: 'net.java.dev.jna:jna:4.5.1',
jsr305: 'com.google.code.findbugs:jsr305:3.0.2',
joptSimple: 'net.sf.jopt-simple:jopt-simple:3.2',
kafka: kafkaGroup + ':kafka_2.12:' + kafkaVersion,
kafkaClients: kafkaGroup + ':kafka-clients:' + kafkaVersion,
kafkaClientsTest: kafkaGroup + ':kafka-clients:' + kafkaVersion + ':test',
log4j2api: 'org.apache.logging.log4j:log4j-api:' + log4j2Version,
log4j2core: 'org.apache.logging.log4j:log4j-core:' + log4j2Version,
mail: 'javax.mail:mail:1.4.4',
mapreduceClientCore: 'org.apache.hadoop:hadoop-mapreduce-client-core:2.3.0',
mapreduceClientJobClient: 'org.apache.hadoop:hadoop-mapreduce-client-jobclient:2.3.0',
mockito: 'org.mockito:mockito-core:3.3.3',
netty: 'io.netty:netty-all:4.1.52.Final',
oss: 'org.sonatype.oss:oss-parent:7',
r2: 'com.linkedin.pegasus:r2:' + pegasusVersion,
restliCommon: 'com.linkedin.pegasus:restli-common:' + pegasusVersion,
rocksdbjni: 'org.rocksdb:rocksdbjni:7.9.2',
samzaApi: 'org.apache.samza:samza-api:1.5.1',
snappy: 'org.iq80.snappy:snappy:0.4',
spark: 'com.sparkjava:spark-core:2.9.4',
spotbugs: 'com.github.spotbugs:spotbugs:4.5.2',
tehuti: 'io.tehuti:tehuti:0.10.0',
testng: 'org.testng:testng:6.14.3',
// Resolves java.lang.UnsupportedOperationException: setXIncludeAware is not supported on this JAXP implementation or earlier: class org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
xalan: 'xalan:xalan:2.7.1',
xerces: 'xerces:xercesImpl:2.9.1',
zkclient: 'com.101tec:zkclient:0.7', // For Kafka AdminUtils
zookeeper: 'org.apache.zookeeper:zookeeper:3.5.9',
zstd: 'com.github.luben:zstd-jni:1.5.2-3'
]
group = 'com.linkedin.venice'
publishing {
repositories {
mavenLocal()
maven {
name 'LinkedInJFrog'
url 'https://linkedin.jfrog.io/artifactory/venice'
if (System.getenv('JFROG_USERNAME') != null && System.getenv('JFROG_API_KEY') != null) {
credentials {
username System.getenv('JFROG_USERNAME')
password System.getenv('JFROG_API_KEY')
}
}
}
}
}
def parser = new XmlSlurper()
parser.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false)
parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false)
subprojects {
//apply group and version to all submodules
group = rootProject.group
version = rootProject.version
def isLeafSubModule = project.childProjects.isEmpty()
apply {
plugin 'idea'
plugin 'java-library'
plugin 'com.github.spotbugs'
plugin 'org.gradle.test-retry'
}
if (isLeafSubModule) {
apply {
plugin 'jacoco'
plugin 'com.form.diff-coverage'
}
}
if (JavaVersion.current() >= JavaVersion.VERSION_1_9) {
tasks.withType(JavaCompile) {
options.release = 8
}
}
java {
withSourcesJar()
// TODO: Enable after we have valid javadocs
//withJavadocJar()
}
configurations {
implementation {
// These are global exclusions that will apply to the entire project
exclude group: 'backport-util-concurrent'
exclude group: 'com.intellij.annotations'
exclude group: 'com.linkedin.avro-schemas'
exclude group: 'com.linkedin.container'
exclude group: 'com.linkedin.container-core'
exclude group: 'com.linkedin.security'
exclude group: 'com.linkedin.dds-storage-core'
exclude group: 'com.linkedin.linkedin-kafka-clients'
exclude group: 'com.linkedin.util', module: 'util-sql'
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
exclude module: 'clojure'
exclude module: 'kafka_2.10' // This ends up getting pulled in by a few dependencies, unfortunately :/ ...
exclude module: 'kafka_2.11'
// These various netty modules clash with netty-all, and we transitively pull a different version, which causes NoSuchMethodError
exclude group: 'io.netty', module: 'netty-buffer'
exclude group: 'io.netty', module: 'netty-codec'
exclude group: 'io.netty', module: 'netty-common'
exclude group: 'io.netty', module: 'netty-handler'
exclude group: 'io.netty', module: 'netty-resolver'
exclude group: 'io.netty', module: 'netty-transport'
exclude group: 'io.netty', module: 'netty-transport-native-epoll'
exclude group: 'io.netty', module: 'netty-transport-native-unix-common'
}
compileOnly {
// These dependencies are transitively used at runtime, so we cannot exclude them further than compileOnly
exclude group: 'com.google.guava'
exclude group: 'com.typesafe.scala-logging'
exclude group: 'log4j'
exclude group: 'org.slf4j'
}
all {
resolutionStrategy.force libraries.zookeeper
}
avroCompiler {
}
}
dependencies {
testImplementation libraries.log4j2api
testImplementation libraries.mockito
testImplementation libraries.testng
// Test utils and framework for all unit tests and integration tests.
testImplementation project(':internal:venice-test-common')
spotbugs libraries.spotbugs
spotbugsPlugins libraries.avroUtilSpotbugsPlugin
avroCompiler libraries.avroCompiler
avroCompiler libraries.avroUtilBuilder
avroCompiler 'org.slf4j:slf4j-simple:1.7.32'
}
idea {
module {
downloadJavadoc = true
downloadSources = true
}
}
task compileAvro(type: SourceTask) {
def sourceDir = file('src/main/resources/avro')
def outputDir = file("$buildDir/generated/sources/avro/java/main")
source sourceDir
inputs.files(configurations.avroCompiler).withNormalizer(ClasspathNormalizer)
outputs.dir(outputDir)
outputs.cacheIf { true }
doFirst {
def versionOverrides = [
// project(':internal:venice-common').file('src/main/resources/avro/StoreVersionState/v5', PathValidation.DIRECTORY)
]
def schemaDirs = [sourceDir]
sourceDir.eachDir { typeDir ->
def parseVersionId = { dir ->
(dir in versionOverrides) ? Integer.MAX_VALUE : dir?.name?.substring(1)?.toInteger()
}
def latestVersionDir = null
typeDir.eachDirMatch(~/v-?\d+/) { versionDir ->
if (parseVersionId(versionDir) > parseVersionId(latestVersionDir)) {
latestVersionDir = versionDir
}
}
if (latestVersionDir) {
schemaDirs << latestVersionDir
}
}
copy {
from (schemaDirs) {
include '*.avsc'
}
into temporaryDir
duplicatesStrategy = DuplicatesStrategy.FAIL
eachFile {
println "Copying avro schema ${relativePath(it.file)} ${it.file.parentFile in versionOverrides ? '(OVERRIDE)' : ''}"
}
}
javaexec {
classpath = configurations.avroCompiler
main = 'com.linkedin.avroutil1.builder.SchemaBuilder'
args = [
'--input', temporaryDir,
'--output', outputDir
]
}
}
}
sourceSets.main.java.srcDir(compileAvro)
tasks.withType(SpotBugsTask) {
effort = 'max'
reportLevel = 'low'
includeFilter = file(
project.hasProperty('spotallbugs') ?
"$rootDir/gradle/spotbugs/include-all.xml" :
"$rootDir/gradle/spotbugs/include.xml"
)
excludeFilter = file("$rootDir/gradle/spotbugs/exclude.xml")
ignoreFailures = project.hasProperty('spotbugs.ignoreFailures')
showStackTraces = false
reports ({
xml {
enabled = project.hasProperty('spotbugs.xml')
}
html {
enabled = !reports.getByName('XML').enabled
stylesheet = 'fancy-hist.xsl'
}
})
doFirst {
sourceDirs += sourceSets.getByName(baseName).output.generatedSourcesDirs
def generatedSources = sourceDirs.sum { dir ->
dir.path =~ "^$buildDir/generated/sources/" ?
fileTree(dir: dir, include: '**/*.java').collect { dir.relativePath(it) } : []
}
if (generatedSources) {
def generatedClasses = generatedSources*.replaceFirst('.java$', '').sum {
[ it + '.class', it + '\$*.class' ]
}
classes = classDirs.asFileTree.matching { exclude generatedClasses }
auxClassPaths += classDirs.asFileTree.matching { include generatedClasses }.each {
println "Excluding generated class ${project.relativePath(it)}"
}
}
}
}
def ALPINI_TEST_FILTER = 'com.linkedin.alpini.*'
def ALPINI_NETTY_TEST_FILTER = 'io.netty.*'
def ALPINI_UNIT_TEST_TASK_NAME = 'alpiniUnitTest'
def ALPINI_FUNCTIONAL_TEST_TASK_NAME = 'alpiniFunctionalTest'
tasks.withType(Test) {
mustRunAfter tasks.withType(SpotBugsTask)
if (!project.ext.has("skipAlpnBoot") || !project.ext.skipAlpnBoot) {
// The ALPN version should match the JVM version
if (JavaVersion.current() < JavaVersion.VERSION_11) {
if (Os.isFamily(Os.FAMILY_MAC)) {
jvmArgs '-Xbootclasspath/p:/Library/Java/Boot/1_8_0_172/alpn-boot-8.1.12.v20180117.jar'
} else if (Os.isFamily(Os.FAMILY_UNIX)) {
jvmArgs '-Xbootclasspath/p:/export/apps/jdkboot/1_8_0_172/alpn-boot-8.1.12.v20180117.jar'
} else {
def osName = System.getProperty('os.name').toLowerCase(Locale.ENGLISH)
throw new GradleException("$osName is not supported since ALPN only works for either Mac or Linux right now.")
}
}
}
forkEvery = Integer.valueOf(System.getProperty('forkEvery', '0'))
maxParallelForks = Integer.valueOf(System.getProperty('maxParallelForks', '4'))
minHeapSize = System.getProperty('minHeapSize', '1g')
maxHeapSize = System.getProperty('maxHeapSize', '4g')
systemProperty 'pubSubBrokerFactory', System.getProperty('pubSubBrokerFactory', "com.linkedin.venice.integration.utils.KafkaBrokerFactory")
System.getProperty('jvmArgs')?.eachMatch(/(?:[^\s'"]+|'[^']*'|"[^"]*")+/) { jvmArgs it }
doFirst {
println "forkEvery=$forkEvery"
println "maxParallelForks=$maxParallelForks"
println "jvmArgs=$allJvmArgs"
}
if (name != ALPINI_UNIT_TEST_TASK_NAME && name != ALPINI_FUNCTIONAL_TEST_TASK_NAME) {
filter {
excludeTestsMatching ALPINI_TEST_FILTER
excludeTestsMatching ALPINI_NETTY_TEST_FILTER
failOnNoMatchingTests = false
}
}
useTestNG {
excludeGroups 'flaky'
listeners = ['com.linkedin.venice.testng.VeniceSuiteListener']
}
retry {
maxRetries = 4 // 5 attempts in total
maxFailures = 100
failOnPassedAfterRetry = false
}
testLogging {
events 'started', 'failed', 'skipped' // N.B. we override how 'passed' tests are formatted in afterTest
showStandardStreams = false // to mute the DDS Router's noisy behavior...
exceptionFormat = 'full'
}
afterTest { descriptor, result ->
if (result.resultType == TestResult.ResultType.SUCCESS) {
def totalTime = result.endTime - result.startTime
def prettyTime = totalTime < 1000 ? "$totalTime ms" : "${totalTime / 1000} s"
def out = services.get(StyledTextOutputFactory).create("an-ouput")
out.style(Style.Normal).text("Gradle suite > Gradle test > $descriptor.className > $descriptor.displayName ")
.style(Style.Identifier).text("PASSED ")
.style(Style.Normal).println("($prettyTime)")
}
}
}
if (isLeafSubModule) {
jacocoTestReport {
dependsOn test // tests are required to run before generating the report
reports {
xml.enabled = true
html.enabled = true
}
doLast {
parseJacocoXml("$buildDir/reports/jacoco/test/jacocoTestReport.xml")
}
}
afterEvaluate {
jacocoTestCoverageVerification {
dependsOn jacocoTestReport
violationRules {
rule {
def threshold = project.ext.has('jacocoCoverageThreshold') ? project.ext.jacocoCoverageThreshold : 0.6
limit {
counter = 'BRANCH'
value = 'COVEREDRATIO'
minimum = threshold
}
}
}
}
diffCoverageReport {
diffSource.file = createDiffFile()
// Report locates at <module_name>/build/reports/jacoco/diffCoverage/html/index.html
reports {
html = true
xml = true
}
violationRules {
minBranches = project.ext.has('diffCoverageThreshold') ? project.ext.diffCoverageThreshold : 0.33
failOnViolation = true
}
}
task logDiffCoverage {
doLast {
parseJacocoXml("$buildDir/reports/jacoco/diffCoverage/report.xml")
}
}
diffCoverage.finalizedBy logDiffCoverage
}
}
task flakyTest(type: Test) {
useTestNG {
includeGroups 'flaky'
}
}
task "$ALPINI_UNIT_TEST_TASK_NAME"(type: Test) {
useTestNG() {
includeGroups 'unit'
}
filter {
includeTestsMatching ALPINI_TEST_FILTER
includeTestsMatching ALPINI_NETTY_TEST_FILTER
failOnNoMatchingTests = false
}
}
task "$ALPINI_FUNCTIONAL_TEST_TASK_NAME"(type: Test) {
useTestNG() {
includeGroups 'functional'
}
filter {
includeTestsMatching ALPINI_TEST_FILTER
includeTestsMatching ALPINI_NETTY_TEST_FILTER
failOnNoMatchingTests = false
}
}
tasks.withType(Jar) {
zip64 = true
duplicatesStrategy = DuplicatesStrategy.FAIL
exclude('**/*.xml')
}
task testJar(type: Jar) {
classifier 'tests'
from sourceSets.test.output
}
// Only publish artifacts for projects that are at the leaf level
if (isLeafSubModule) {
publishing.configureArtifactPublishing(project, testJar)
}
}
spotless {
ratchetFrom "${git.getUpstreamRemote()}/main"
java {
importOrder()
removeUnusedImports()
eclipse().configFile("$rootDir/gradle/spotless/eclipse-java-formatter.xml")
target '**/*.java'
targetExclude '**/generated/**'
}
}
task setupWorkspace {
println 'Setting up default git config'
def gitConfig = [
'core.hooksPath' : 'gradle/githooks',
'blame.ignoreRevsFile' : '.git-blame-ignore-revs',
'branch.autoSetupMerge' : 'true', // Only track remote branches
'branch.autoSetupRebase' : 'always',
'pull.rebase' : 'true',
]
gitConfig.each(git.setConfig)
}
task spotbugs {
dependsOn subprojects.tasks*.withType(SpotBugsTask)
}
check.dependsOn(spotbugs)
test {
mustRunAfter spotbugs
dependsOn subprojects.test
afterTest { descriptor, result ->
def totalTime = result.endTime - result.startTime
println "Total time of $descriptor.name was $totalTime"
}
}
assemble {
dependsOn (
setupWorkspace,
testClasses,
'internal:venice-test-common:jmhClasses',
'internal:venice-test-common:integrationTestClasses'
)
}
build {
dependsOn (
'services:venice-router:installDist',
'services:venice-server:installDist',
'services:venice-controller:installDist'
)
}
idea.project.ipr {
withXml { provider ->
provider.node.component
.find { it.@name == 'VcsDirectoryMappings' }
.mapping.@vcs = 'Git'
def inspectionProjectProfileManager = provider.node.component
.find { it.@name == 'InspectionProjectProfileManager' }
def danglingJavaDocInspectionProperties = [
class: "DanglingJavadoc",
enabled: "false",
level: "WARNING",
enabled_by_default: "false"
]
if (inspectionProjectProfileManager == null) {
inspectionProjectProfileManager = provider.node.appendNode(
"component",
[
name: "InspectionProjectProfileManager"
]
)
def profile = inspectionProjectProfileManager.appendNode(
"profile",
[
version: "1.0"
]
)
profile.appendNode(
"option",
[
name: "myName",
value: "Project Default"
]
)
profile.appendNode(
"inspection_tool",
danglingJavaDocInspectionProperties
)
inspectionProjectProfileManager.appendNode(
"version",
[
value: "1.0"
]
)
} else {
def danglingJavaDoc = inspectionProjectProfileManager.profile.inspection_tool
.find { it.@class == 'DanglingJavadoc' }
if (danglingJavaDoc == null) {
inspectionProjectProfileManager.profile.get(0).appendNode(
"inspection_tool",
danglingJavaDocInspectionProperties
)
} else {
danglingJavaDoc.@enabled = false
danglingJavaDoc.@level = "WARNING"
danglingJavaDoc.@enabled_by_default = false
}
}
}
}
// Allow running diffCoverage against uncommitted files
// See https://github.com/form-com/diff-coverage-gradle/issues/73
ext.createDiffFile = { ->
// Files that we don't plan to write unit tests for now. Will be worked in the future
def exclusionFilter = [
':!services/venice-controller/src/main/java/com/linkedin/venice/controller/VeniceHelixAdmin.java',
':!services/venice-controller/src/main/java/com/linkedin/venice/controller/VeniceParentHelixAdmin.java',
':!internal/venice-test-common/*',
':!services/venice-server/src/main/java/com/linkedin/venice/server/VeniceServer.java',
':!internal/venice-common/src/main/java/com/linkedin/venice/controllerapi/ControllerClient.java',
':!services/venice-controller/src/main/java/com/linkedin/venice/controller/VeniceController.java',
':!services/venice-router/src/main/java/com/linkedin/venice/router/RouterServer.java',
':!services/venice-standalone/*', // exclude the entire standalone project
':!clients/venice-client/src/main/java/com/linkedin/venice/fastclient/factory/ClientFactory.java',
// Other files that have tests but are not executed in the regular unit test task
':!internal/alpini/*'
]
def file = Files.createTempFile(URLEncoder.encode(project.name, 'UTF-8'), '.diff').toFile()
def diffBase = "${git.getUpstreamRemote()}/main"
def command = [
'git', 'diff', diffBase, '--no-color', '--minimal', '--', '.'
]
command.addAll(exclusionFilter)
file.withOutputStream { out ->
exec {
commandLine command
standardOutput = out
}
}
return file
}
// for a given xml jacoco report, parse it and print out the branch coverage
ext.parseJacocoXml = { filePath ->
try {
def jacocoReport = parser.parse(filePath).children()
def branchCoverage = jacocoReport.find { it.name() == 'counter' && it.@type == 'BRANCH' }
println "Branch coverage: ${(branchCoverageRatio * 100.0).round(2)}%"
} catch (Exception e) {
// failure to retrieve numbers should not fail the build
project.logger.debug("Branch coverage: N/A. There's either no branch coverage or " +
"the jacoco report is not generated.", e)
}
}