OpenSearch/gradle/code-coverage.gradle

51 lines
1.4 KiB
Groovy
Raw Normal View History

Add support to generate code coverage report with JaCoCo (#971) * add jacoco plugin Signed-off-by: Tianli Feng <ftianli@amazon.com> * config aggregated jacoco report Signed-off-by: Tianli Feng <ftianli@amazon.com> * Skip generating report if no test in subproject Signed-off-by: Tianli Feng <ftianli@amazon.com> * Add jacoco plugin into root project Signed-off-by: Tianli Feng <ftianli@amazon.com> * test aggregate code coverage report Signed-off-by: Tianli Feng <ftianli@amazon.com> * Can generate aggregated unit test coverage report Signed-off-by: Tianli Feng <ftianli@amazon.com> * Can generate aggregated test report with source file linked Signed-off-by: Tianli Feng <ftianli@amazon.com> * Some cleanup, but jacocoReport is not dependson Test Signed-off-by: Tianli Feng <ftianli@amazon.com> * cleanup Signed-off-by: Tianli Feng <ftianli@amazon.com> * get unit test code coverage report Signed-off-by: Tianli Feng <ftianli@amazon.com> * change 'enabled == true' to 'enabled' Signed-off-by: Tianli Feng <ftianli@amazon.com> * add a comment for selectedsubprojects Signed-off-by: Tianli Feng <ftianli@amazon.com> * add tasks to generate code coverage report for unit test and integration test Signed-off-by: Tianli Feng <ftianli@amazon.com> * fix typo in variable Signed-off-by: Tianli Feng <ftianli@amazon.com> * Correct the task to get codecoverage for unit test and integtest Signed-off-by: Tianli Feng <ftianli@amazon.com> * Make code coverage report task run after test Signed-off-by: Tianli Feng <ftianli@amazon.com> * apply gradle configuration aciidance api Signed-off-by: Tianli Feng <ftianli@amazon.com> * apply jacoco plugin in BuildPlugin in all case Signed-off-by: Tianli Feng <ftianli@amazon.com> * Put file path list of integration test exec data in a variable Signed-off-by: Tianli Feng <ftianli@amazon.com> * Apply gradle configuration aviodance api to register task instead of create task Signed-off-by: Tianli Feng <ftianli@amazon.com> * merge 2 jacocoreport configurations Signed-off-by: Tianli Feng <ftianli@amazon.com> * Add some comments in gradle script Signed-off-by: Tianli Feng <ftianli@amazon.com> * Attach code coverage report task to gralde check task Signed-off-by: Tianli Feng <ftianli@amazon.com> * add a space Signed-off-by: Tianli Feng <ftianli@amazon.com> * get code coverage report after check task on demand and get report in html format on demand Signed-off-by: Tianli Feng <ftianli@amazon.com>
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()
gradlePluginPortal()
// TODO: Find the way to use the repositories from RepositoriesSetupPlugin
maven {
url = "https://d1nvenhzbhpy0q.cloudfront.net/snapshots/lucene/"
}
Add support to generate code coverage report with JaCoCo (#971) * add jacoco plugin Signed-off-by: Tianli Feng <ftianli@amazon.com> * config aggregated jacoco report Signed-off-by: Tianli Feng <ftianli@amazon.com> * Skip generating report if no test in subproject Signed-off-by: Tianli Feng <ftianli@amazon.com> * Add jacoco plugin into root project Signed-off-by: Tianli Feng <ftianli@amazon.com> * test aggregate code coverage report Signed-off-by: Tianli Feng <ftianli@amazon.com> * Can generate aggregated unit test coverage report Signed-off-by: Tianli Feng <ftianli@amazon.com> * Can generate aggregated test report with source file linked Signed-off-by: Tianli Feng <ftianli@amazon.com> * Some cleanup, but jacocoReport is not dependson Test Signed-off-by: Tianli Feng <ftianli@amazon.com> * cleanup Signed-off-by: Tianli Feng <ftianli@amazon.com> * get unit test code coverage report Signed-off-by: Tianli Feng <ftianli@amazon.com> * change 'enabled == true' to 'enabled' Signed-off-by: Tianli Feng <ftianli@amazon.com> * add a comment for selectedsubprojects Signed-off-by: Tianli Feng <ftianli@amazon.com> * add tasks to generate code coverage report for unit test and integration test Signed-off-by: Tianli Feng <ftianli@amazon.com> * fix typo in variable Signed-off-by: Tianli Feng <ftianli@amazon.com> * Correct the task to get codecoverage for unit test and integtest Signed-off-by: Tianli Feng <ftianli@amazon.com> * Make code coverage report task run after test Signed-off-by: Tianli Feng <ftianli@amazon.com> * apply gradle configuration aciidance api Signed-off-by: Tianli Feng <ftianli@amazon.com> * apply jacoco plugin in BuildPlugin in all case Signed-off-by: Tianli Feng <ftianli@amazon.com> * Put file path list of integration test exec data in a variable Signed-off-by: Tianli Feng <ftianli@amazon.com> * Apply gradle configuration aviodance api to register task instead of create task Signed-off-by: Tianli Feng <ftianli@amazon.com> * merge 2 jacocoreport configurations Signed-off-by: Tianli Feng <ftianli@amazon.com> * Add some comments in gradle script Signed-off-by: Tianli Feng <ftianli@amazon.com> * Attach code coverage report task to gralde check task Signed-off-by: Tianli Feng <ftianli@amazon.com> * add a space Signed-off-by: Tianli Feng <ftianli@amazon.com> * get code coverage report after check task on demand and get report in html format on demand Signed-off-by: Tianli Feng <ftianli@amazon.com>
2021-08-10 10:23:46 -04:00
}
allprojects {
plugins.withId('jacoco') {
jacoco.toolVersion = '0.8.8'
Add support to generate code coverage report with JaCoCo (#971) * add jacoco plugin Signed-off-by: Tianli Feng <ftianli@amazon.com> * config aggregated jacoco report Signed-off-by: Tianli Feng <ftianli@amazon.com> * Skip generating report if no test in subproject Signed-off-by: Tianli Feng <ftianli@amazon.com> * Add jacoco plugin into root project Signed-off-by: Tianli Feng <ftianli@amazon.com> * test aggregate code coverage report Signed-off-by: Tianli Feng <ftianli@amazon.com> * Can generate aggregated unit test coverage report Signed-off-by: Tianli Feng <ftianli@amazon.com> * Can generate aggregated test report with source file linked Signed-off-by: Tianli Feng <ftianli@amazon.com> * Some cleanup, but jacocoReport is not dependson Test Signed-off-by: Tianli Feng <ftianli@amazon.com> * cleanup Signed-off-by: Tianli Feng <ftianli@amazon.com> * get unit test code coverage report Signed-off-by: Tianli Feng <ftianli@amazon.com> * change 'enabled == true' to 'enabled' Signed-off-by: Tianli Feng <ftianli@amazon.com> * add a comment for selectedsubprojects Signed-off-by: Tianli Feng <ftianli@amazon.com> * add tasks to generate code coverage report for unit test and integration test Signed-off-by: Tianli Feng <ftianli@amazon.com> * fix typo in variable Signed-off-by: Tianli Feng <ftianli@amazon.com> * Correct the task to get codecoverage for unit test and integtest Signed-off-by: Tianli Feng <ftianli@amazon.com> * Make code coverage report task run after test Signed-off-by: Tianli Feng <ftianli@amazon.com> * apply gradle configuration aciidance api Signed-off-by: Tianli Feng <ftianli@amazon.com> * apply jacoco plugin in BuildPlugin in all case Signed-off-by: Tianli Feng <ftianli@amazon.com> * Put file path list of integration test exec data in a variable Signed-off-by: Tianli Feng <ftianli@amazon.com> * Apply gradle configuration aviodance api to register task instead of create task Signed-off-by: Tianli Feng <ftianli@amazon.com> * merge 2 jacocoreport configurations Signed-off-by: Tianli Feng <ftianli@amazon.com> * Add some comments in gradle script Signed-off-by: Tianli Feng <ftianli@amazon.com> * Attach code coverage report task to gralde check task Signed-off-by: Tianli Feng <ftianli@amazon.com> * add a space Signed-off-by: Tianli Feng <ftianli@amazon.com> * get code coverage report after check task on demand and get report in html format on demand Signed-off-by: Tianli Feng <ftianli@amazon.com>
2021-08-10 10:23:46 -04:00
}
}
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()
Add support to generate code coverage report with JaCoCo (#971) * add jacoco plugin Signed-off-by: Tianli Feng <ftianli@amazon.com> * config aggregated jacoco report Signed-off-by: Tianli Feng <ftianli@amazon.com> * Skip generating report if no test in subproject Signed-off-by: Tianli Feng <ftianli@amazon.com> * Add jacoco plugin into root project Signed-off-by: Tianli Feng <ftianli@amazon.com> * test aggregate code coverage report Signed-off-by: Tianli Feng <ftianli@amazon.com> * Can generate aggregated unit test coverage report Signed-off-by: Tianli Feng <ftianli@amazon.com> * Can generate aggregated test report with source file linked Signed-off-by: Tianli Feng <ftianli@amazon.com> * Some cleanup, but jacocoReport is not dependson Test Signed-off-by: Tianli Feng <ftianli@amazon.com> * cleanup Signed-off-by: Tianli Feng <ftianli@amazon.com> * get unit test code coverage report Signed-off-by: Tianli Feng <ftianli@amazon.com> * change 'enabled == true' to 'enabled' Signed-off-by: Tianli Feng <ftianli@amazon.com> * add a comment for selectedsubprojects Signed-off-by: Tianli Feng <ftianli@amazon.com> * add tasks to generate code coverage report for unit test and integration test Signed-off-by: Tianli Feng <ftianli@amazon.com> * fix typo in variable Signed-off-by: Tianli Feng <ftianli@amazon.com> * Correct the task to get codecoverage for unit test and integtest Signed-off-by: Tianli Feng <ftianli@amazon.com> * Make code coverage report task run after test Signed-off-by: Tianli Feng <ftianli@amazon.com> * apply gradle configuration aciidance api Signed-off-by: Tianli Feng <ftianli@amazon.com> * apply jacoco plugin in BuildPlugin in all case Signed-off-by: Tianli Feng <ftianli@amazon.com> * Put file path list of integration test exec data in a variable Signed-off-by: Tianli Feng <ftianli@amazon.com> * Apply gradle configuration aviodance api to register task instead of create task Signed-off-by: Tianli Feng <ftianli@amazon.com> * merge 2 jacocoreport configurations Signed-off-by: Tianli Feng <ftianli@amazon.com> * Add some comments in gradle script Signed-off-by: Tianli Feng <ftianli@amazon.com> * Attach code coverage report task to gralde check task Signed-off-by: Tianli Feng <ftianli@amazon.com> * add a space Signed-off-by: Tianli Feng <ftianli@amazon.com> * get code coverage report after check task on demand and get report in html format on demand Signed-off-by: Tianli Feng <ftianli@amazon.com>
2021-08-10 10:23:46 -04:00
}
}
if (System.getProperty("tests.coverage")) {
reporting {
reports {
testCodeCoverageReport(JacocoCoverageReport) {
testType = TestSuiteType.UNIT_TEST
}
}
}
Add support to generate code coverage report with JaCoCo (#971) * add jacoco plugin Signed-off-by: Tianli Feng <ftianli@amazon.com> * config aggregated jacoco report Signed-off-by: Tianli Feng <ftianli@amazon.com> * Skip generating report if no test in subproject Signed-off-by: Tianli Feng <ftianli@amazon.com> * Add jacoco plugin into root project Signed-off-by: Tianli Feng <ftianli@amazon.com> * test aggregate code coverage report Signed-off-by: Tianli Feng <ftianli@amazon.com> * Can generate aggregated unit test coverage report Signed-off-by: Tianli Feng <ftianli@amazon.com> * Can generate aggregated test report with source file linked Signed-off-by: Tianli Feng <ftianli@amazon.com> * Some cleanup, but jacocoReport is not dependson Test Signed-off-by: Tianli Feng <ftianli@amazon.com> * cleanup Signed-off-by: Tianli Feng <ftianli@amazon.com> * get unit test code coverage report Signed-off-by: Tianli Feng <ftianli@amazon.com> * change 'enabled == true' to 'enabled' Signed-off-by: Tianli Feng <ftianli@amazon.com> * add a comment for selectedsubprojects Signed-off-by: Tianli Feng <ftianli@amazon.com> * add tasks to generate code coverage report for unit test and integration test Signed-off-by: Tianli Feng <ftianli@amazon.com> * fix typo in variable Signed-off-by: Tianli Feng <ftianli@amazon.com> * Correct the task to get codecoverage for unit test and integtest Signed-off-by: Tianli Feng <ftianli@amazon.com> * Make code coverage report task run after test Signed-off-by: Tianli Feng <ftianli@amazon.com> * apply gradle configuration aciidance api Signed-off-by: Tianli Feng <ftianli@amazon.com> * apply jacoco plugin in BuildPlugin in all case Signed-off-by: Tianli Feng <ftianli@amazon.com> * Put file path list of integration test exec data in a variable Signed-off-by: Tianli Feng <ftianli@amazon.com> * Apply gradle configuration aviodance api to register task instead of create task Signed-off-by: Tianli Feng <ftianli@amazon.com> * merge 2 jacocoreport configurations Signed-off-by: Tianli Feng <ftianli@amazon.com> * Add some comments in gradle script Signed-off-by: Tianli Feng <ftianli@amazon.com> * Attach code coverage report task to gralde check task Signed-off-by: Tianli Feng <ftianli@amazon.com> * add a space Signed-off-by: Tianli Feng <ftianli@amazon.com> * get code coverage report after check task on demand and get report in html format on demand Signed-off-by: Tianli Feng <ftianli@amazon.com>
2021-08-10 10:23:46 -04:00
// Attach code coverage report task to Gradle check task
project.getTasks().named(JavaBasePlugin.CHECK_TASK_NAME).configure {
dependsOn tasks.named('testCodeCoverageReport', JacocoReport)
Add support to generate code coverage report with JaCoCo (#971) * add jacoco plugin Signed-off-by: Tianli Feng <ftianli@amazon.com> * config aggregated jacoco report Signed-off-by: Tianli Feng <ftianli@amazon.com> * Skip generating report if no test in subproject Signed-off-by: Tianli Feng <ftianli@amazon.com> * Add jacoco plugin into root project Signed-off-by: Tianli Feng <ftianli@amazon.com> * test aggregate code coverage report Signed-off-by: Tianli Feng <ftianli@amazon.com> * Can generate aggregated unit test coverage report Signed-off-by: Tianli Feng <ftianli@amazon.com> * Can generate aggregated test report with source file linked Signed-off-by: Tianli Feng <ftianli@amazon.com> * Some cleanup, but jacocoReport is not dependson Test Signed-off-by: Tianli Feng <ftianli@amazon.com> * cleanup Signed-off-by: Tianli Feng <ftianli@amazon.com> * get unit test code coverage report Signed-off-by: Tianli Feng <ftianli@amazon.com> * change 'enabled == true' to 'enabled' Signed-off-by: Tianli Feng <ftianli@amazon.com> * add a comment for selectedsubprojects Signed-off-by: Tianli Feng <ftianli@amazon.com> * add tasks to generate code coverage report for unit test and integration test Signed-off-by: Tianli Feng <ftianli@amazon.com> * fix typo in variable Signed-off-by: Tianli Feng <ftianli@amazon.com> * Correct the task to get codecoverage for unit test and integtest Signed-off-by: Tianli Feng <ftianli@amazon.com> * Make code coverage report task run after test Signed-off-by: Tianli Feng <ftianli@amazon.com> * apply gradle configuration aciidance api Signed-off-by: Tianli Feng <ftianli@amazon.com> * apply jacoco plugin in BuildPlugin in all case Signed-off-by: Tianli Feng <ftianli@amazon.com> * Put file path list of integration test exec data in a variable Signed-off-by: Tianli Feng <ftianli@amazon.com> * Apply gradle configuration aviodance api to register task instead of create task Signed-off-by: Tianli Feng <ftianli@amazon.com> * merge 2 jacocoreport configurations Signed-off-by: Tianli Feng <ftianli@amazon.com> * Add some comments in gradle script Signed-off-by: Tianli Feng <ftianli@amazon.com> * Attach code coverage report task to gralde check task Signed-off-by: Tianli Feng <ftianli@amazon.com> * add a space Signed-off-by: Tianli Feng <ftianli@amazon.com> * get code coverage report after check task on demand and get report in html format on demand Signed-off-by: Tianli Feng <ftianli@amazon.com>
2021-08-10 10:23:46 -04:00
}
}