Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 46 additions & 34 deletions msal/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,44 +50,56 @@ tasks.withType(Test) {
}
}

tasks.register("jacocoTestReport", JacocoReport) {
dependsOn "testLocalDebugUnitTest" // Run Robolectric tests first
// Registers a JaCoCo XML+HTML coverage report task for a given build variant's unit tests.
// PR validation builds the 'local' flavor, so the PR checks invoke jacocoTestReport
// (localDebug) and its behaviour is unchanged. The weekly release pipeline builds the
// 'dist' flavor and invokes jacocoDistTestReport (distDebug), which reuses the .exec
// produced by distDebug<Module>UnitTestCoverageReport rather than re-running tests on a
// variant the weekly infrastructure doesn't build.
def registerJacocoXmlReport = { String taskName, String variant ->
def variantCap = variant.capitalize()
tasks.register(taskName, JacocoReport) {
dependsOn "test${variantCap}UnitTest" // Run Robolectric tests first

reports {
xml.required = true
html.required = true
}

reports {
xml.required = true
html.required = true
def fileFilter = [
'**/R.class', '**/R$*.class', '**/BuildConfig.*',
'**/Manifest*.*', '**/*Test*.*',
'android/**/*.*'
]

def kotlinClasses = fileTree(
dir: "$buildDir/tmp/kotlin-classes/${variant}",
excludes: fileFilter
)

def javaClasses = fileTree(
dir: "$buildDir/intermediates/javac/${variant}/compile${variantCap}JavaWithJavac/classes",
excludes: fileFilter
)

sourceDirectories.setFrom(files([
"$projectDir/src/main/java",
"$projectDir/src/main/kotlin"
]))
classDirectories.setFrom(files([kotlinClasses, javaClasses]))
executionData.setFrom(fileTree(
dir: buildDir,
includes: [
"jacoco/test${variantCap}UnitTest.exec".toString(),
"outputs/unit_test_code_coverage/${variant}UnitTest/test${variantCap}UnitTest.exec".toString()
]
))
}

def fileFilter = [
'**/R.class', '**/R$*.class', '**/BuildConfig.*',
'**/Manifest*.*', '**/*Test*.*',
'android/**/*.*'
]

def kotlinClasses = fileTree(
dir: "$buildDir/tmp/kotlin-classes/localDebug",
excludes: fileFilter
)

def javaClasses = fileTree(
dir: "$buildDir/intermediates/javac/localDebug/compileLocalDebugJavaWithJavac/classes",
excludes: fileFilter
)

sourceDirectories.setFrom(files([
"$projectDir/src/main/java",
"$projectDir/src/main/kotlin"
]))
classDirectories.setFrom(files([kotlinClasses, javaClasses]))
executionData.setFrom(fileTree(
dir: buildDir,
includes: [
"jacoco/testLocalDebugUnitTest.exec",
"outputs/unit_test_code_coverage/localDebugUnitTest/testLocalDebugUnitTest.exec"
]
))
}

registerJacocoXmlReport("jacocoTestReport", "localDebug") // PR validation (local flavor)
registerJacocoXmlReport("jacocoDistTestReport", "distDebug") // weekly release (dist flavor)

def robolectricRepoUsername = System.getenv("ENV_VSTS_MVN_CRED_USERNAME") != null ? System.getenv("ENV_VSTS_MVN_CRED_USERNAME") : project.findProperty("vstsUsername")
def robolectricRepoPassword = System.getenv("ENV_VSTS_MVN_CRED_ACCESSTOKEN") != null ? System.getenv("ENV_VSTS_MVN_CRED_ACCESSTOKEN") : project.findProperty("vstsMavenAccessToken")

Expand Down
Loading