-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate and push code coverage to codecov.io in CI
- Loading branch information
1 parent
524eaf4
commit dc3ec91
Showing
3 changed files
with
29 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,37 @@ | ||
apply plugin: 'jacoco' | ||
|
||
jacoco { | ||
toolVersion = pluginVersion.jacoco | ||
} | ||
|
||
android { | ||
testOptions { | ||
unitTests.all { | ||
jacoco { | ||
includeNoLocationClasses = true | ||
} | ||
} | ||
} | ||
} | ||
|
||
project.afterEvaluate { | ||
//Gather build type and product flavor names in a list | ||
// Grab all build types and product flavors | ||
def buildTypes = android.buildTypes.collect { type -> type.name } | ||
def productFlavors = android.productFlavors.collect { flavor -> flavor.name } | ||
if (!productFlavors) productFlavors.add('') | ||
|
||
productFlavors.each { productFlavorName -> | ||
buildTypes.each { buildTypeName -> | ||
|
||
//Define the sourceName and the sourcePath. | ||
def sourceName, sourcePath | ||
if (!productFlavorName) { | ||
sourceName = sourcePath = "${buildTypeName}" | ||
} else { | ||
sourceName = "${productFlavorName}${buildTypeName.capitalize()}" | ||
sourcePath = "${productFlavorName}/${buildTypeName}" | ||
} | ||
|
||
def testTaskName = "test${sourceName.capitalize()}UnitTest" | ||
|
||
//noinspection GroovyAssignabilityCheck | ||
task "create${sourceName.capitalize()}UnitTestCoverageReport"(type: JacocoReport, dependsOn: "$testTaskName") { | ||
buildTypes.each { buildTypeName -> | ||
def sourceName, sourcePath | ||
sourceName = sourcePath = "${buildTypeName}" | ||
def testTaskName = "test${sourceName.capitalize()}UnitTest" | ||
def coverageTaskName = "${testTaskName}Coverage" | ||
|
||
group = "Reporting" | ||
description = | ||
"Generate Jacoco coverage reports on the ${sourceName.capitalize()} build." | ||
// Create coverage task of form 'testFlavorTypeUnitTestCoverage' depending on 'testFlavorTypeUnitTest' | ||
task "${coverageTaskName}"(type: JacocoReport, dependsOn: "$testTaskName") { | ||
group = 'Reporting' | ||
description = "Generate Jacoco coverage reports for the ${sourceName.capitalize()} build." | ||
|
||
//Directory where the compiled class files are | ||
classDirectories = | ||
fileTree(dir: "${project.buildDir}/intermediates/classes/${sourcePath}", | ||
excludes: [ | ||
'**/R.class', | ||
'**/R$*.class', | ||
'**/*$ViewInjector*.*', | ||
'**/*$ViewBinder*.*', | ||
'**/BuildConfig.*', | ||
'**/Manifest*.*', | ||
'**/*$Lambda$*.*', // Jacoco can not handle several "$" in class name. | ||
'**/*_Provide*Factory*.*', | ||
'**/*$*$*.*' // Anonymous classes generated by kotlin | ||
]) | ||
classDirectories = fileTree( | ||
dir: "${project.buildDir}/intermediates/javac/${sourcePath}", | ||
excludes: ['**/R.class', | ||
'**/R$*.class', | ||
'**/BuildConfig.*', | ||
'**/Manifest*.*']) | ||
|
||
sourceDirectories = files(["src/main/java", | ||
"src/$productFlavorName/java", | ||
"src/$buildTypeName/java"]) | ||
sourceDirectories = files(["src/main/java", | ||
"src/$buildTypeName/java"]) | ||
|
||
executionData = files("${project.buildDir}/jacoco/${testTaskName}.exec") | ||
executionData = files("${project.buildDir}/jacoco/${testTaskName}.exec") | ||
|
||
reports { | ||
xml.enabled = true | ||
html.enabled = true | ||
} | ||
} | ||
build.dependsOn "${coverageTaskName}" | ||
} | ||
} | ||
} |