2021-08-10 10:23:46 -04:00
|
|
|
/*
|
|
|
|
* 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()
|
|
|
|
}
|
|
|
|
|
|
|
|
allprojects {
|
|
|
|
plugins.withId('jacoco') {
|
|
|
|
// The default JaCoCo version in Gradle 6.6.1 is 0.8.5, but at least version 0.8.6 officially supports Java 14
|
|
|
|
jacoco.toolVersion = '0.8.7'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def codeCoverageReportTask = tasks.register("codeCoverageReport", JacocoReport) {
|
|
|
|
description = 'Generates aggregate report from all subprojects.'
|
|
|
|
executionData.setFrom fileTree(dir: '.', include: '**/build/jacoco/*.exec')
|
2021-11-29 14:34:06 -05:00
|
|
|
dependsOn subprojects.findAll(s -> s.tasks.findByName('check') != null).check
|
2021-08-10 10:23:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
tasks.register("codeCoverageReportForUnitTest", JacocoReport) {
|
|
|
|
description = 'Generates aggregate report from all subprojects for unit test.'
|
|
|
|
executionData.setFrom fileTree(dir: '.', include: '**/build/jacoco/test.exec')
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.register("codeCoverageReportForIntegrationTest", JacocoReport) {
|
|
|
|
description = 'Generates aggregate report from all subprojects for integration test.'
|
|
|
|
// These kinds of tests are integration test, and the tests can be ran by Gradle tasks with the same name
|
|
|
|
def integrationTestExecPathList = ['**/build/jacoco/integTest.exec',
|
|
|
|
'**/build/jacoco/internalClusterTest.exec',
|
|
|
|
'**/build/jacoco/javaRestTest.exec',
|
|
|
|
'**/build/jacoco/yamlRestTest.exec' ]
|
|
|
|
executionData.setFrom fileTree(dir: '.', include: integrationTestExecPathList)
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.withType(JacocoReport).configureEach {
|
|
|
|
group = JavaBasePlugin.VERIFICATION_GROUP
|
|
|
|
|
|
|
|
// Select projects with corresponding tests in order to run proper tests and select proper classes to generate the report
|
|
|
|
def projectsWithJavaPlugin = subprojects.findAll { it.pluginManager.hasPlugin('java') }
|
|
|
|
def projectsWithUnitTest = projectsWithJavaPlugin.findAll { it.tasks.findByName('test').enabled }
|
|
|
|
def projectsWithIntegTest = projectsWithJavaPlugin.findAll {it.tasks.findByName('integTest')}
|
2021-11-29 14:34:06 -05:00
|
|
|
def projectsWithAsyncIntegTest = projectsWithJavaPlugin.findAll {it.tasks.findByName('asyncIntegTest')}
|
2021-08-10 10:23:46 -04:00
|
|
|
def projectsWithInternalClusterTest = projectsWithJavaPlugin.findAll {it.tasks.findByName('internalClusterTest')}
|
2021-11-29 14:34:06 -05:00
|
|
|
def projectsWithPooledInternalClusterTest = projectsWithJavaPlugin.findAll {it.tasks.findByName('pooledInternalClusterTest')}
|
2021-08-10 10:23:46 -04:00
|
|
|
def projectsWithJavaRestTest = projectsWithJavaPlugin.findAll {it.tasks.findByName('javaRestTest')}
|
|
|
|
def projectsWithYamlRestTest = projectsWithJavaPlugin.findAll {it.tasks.findByName('yamlRestTest')}
|
2021-11-29 14:34:06 -05:00
|
|
|
def projectsWithIntegrationTest = projectsWithIntegTest + projectsWithAsyncIntegTest + projectsWithInternalClusterTest + projectsWithPooledInternalClusterTest + projectsWithJavaRestTest + projectsWithYamlRestTest
|
2021-08-10 10:23:46 -04:00
|
|
|
def projectsWithTest = projectsWithUnitTest + projectsWithIntegrationTest
|
|
|
|
|
|
|
|
def selectedProjects
|
|
|
|
switch (name) {
|
|
|
|
case "codeCoverageReportForUnitTest":
|
|
|
|
dependsOn projectsWithUnitTest.test
|
|
|
|
selectedProjects = projectsWithUnitTest
|
|
|
|
break
|
|
|
|
case "codeCoverageReportForIntegrationTest":
|
|
|
|
dependsOn projectsWithIntegTest.integTest
|
2021-11-29 14:34:06 -05:00
|
|
|
dependsOn projectsWithAsyncIntegTest.asyncIntegTest
|
2021-08-10 10:23:46 -04:00
|
|
|
dependsOn projectsWithInternalClusterTest.internalClusterTest
|
2021-11-29 14:34:06 -05:00
|
|
|
dependsOn projectsWithPooledInternalClusterTest.pooledInternalClusterTest
|
2021-08-10 10:23:46 -04:00
|
|
|
dependsOn projectsWithJavaRestTest.javaRestTest
|
|
|
|
dependsOn projectsWithYamlRestTest.yamlRestTest
|
|
|
|
selectedProjects = projectsWithIntegrationTest
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
dependsOn projectsWithUnitTest.test
|
|
|
|
dependsOn projectsWithIntegTest.integTest
|
2021-11-29 14:34:06 -05:00
|
|
|
dependsOn projectsWithAsyncIntegTest.asyncIntegTest
|
2021-08-10 10:23:46 -04:00
|
|
|
dependsOn projectsWithInternalClusterTest.internalClusterTest
|
2021-11-29 14:34:06 -05:00
|
|
|
dependsOn projectsWithPooledInternalClusterTest.pooledInternalClusterTest
|
2021-08-10 10:23:46 -04:00
|
|
|
dependsOn projectsWithJavaRestTest.javaRestTest
|
|
|
|
dependsOn projectsWithYamlRestTest.yamlRestTest
|
2021-11-29 14:34:06 -05:00
|
|
|
selectedProjects = projectsWithJavaPlugin
|
2021-08-10 10:23:46 -04:00
|
|
|
break
|
|
|
|
}
|
2021-11-29 14:34:06 -05:00
|
|
|
|
2021-08-10 10:23:46 -04:00
|
|
|
sourceDirectories.setFrom files(selectedProjects.sourceSets.main.allSource.srcDirs)
|
|
|
|
classDirectories.setFrom files(selectedProjects.sourceSets.main.output)
|
|
|
|
|
|
|
|
reports {
|
2021-09-13 13:56:11 -04:00
|
|
|
// Code coverage report in HTML and CSV formats are on demand, in case they take extra disk space.
|
2021-11-29 14:34:06 -05:00
|
|
|
xml.getRequired().set(System.getProperty('tests.coverage.report.xml', 'true').toBoolean())
|
|
|
|
html.getRequired().set(System.getProperty('tests.coverage.report.html', 'false').toBoolean())
|
|
|
|
csv.getRequired().set(System.getProperty('tests.coverage.report.csv', 'false').toBoolean())
|
2021-08-10 10:23:46 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (System.getProperty("tests.coverage")) {
|
|
|
|
// Attach code coverage report task to Gradle check task
|
|
|
|
project.getTasks().named(JavaBasePlugin.CHECK_TASK_NAME).configure {
|
|
|
|
dependsOn codeCoverageReportTask
|
|
|
|
}
|
|
|
|
}
|