From e2db09a2bc21e192bd34c2930ea67f78f46f5488 Mon Sep 17 00:00:00 2001 From: Banji Jolaoso Date: Mon, 6 Feb 2023 12:43:07 -0800 Subject: [PATCH] fixed review comments --- jacoco-config.gradle | 20 ------- jacoco.gradle | 132 ------------------------------------------- 2 files changed, 152 deletions(-) delete mode 100644 jacoco-config.gradle delete mode 100644 jacoco.gradle diff --git a/jacoco-config.gradle b/jacoco-config.gradle deleted file mode 100644 index 5f10e02ad0..0000000000 --- a/jacoco-config.gradle +++ /dev/null @@ -1,20 +0,0 @@ -project.ext { - jacocoIgnoreList = [ - 'testutils', - 'testmodels' - ] - - // Exclude file by names, packages or types. Such files will be ignored during test coverage - // calculation - jacocoFileFilter = [ - '**/*App.*', - '**/*Application.*', - '**/*Activity.*', - '**/*Fragment.*', - '**/*View.*', - '**/*ViewGroup.*', - '**/*JsonAdapter.*', - '**/di/**', - '**/*Dagger.*' - ] -} \ No newline at end of file diff --git a/jacoco.gradle b/jacoco.gradle deleted file mode 100644 index 0220e3fca3..0000000000 --- a/jacoco.gradle +++ /dev/null @@ -1,132 +0,0 @@ -apply from: '../jacoco-config.gradle' -apply plugin: 'jacoco' - -jacoco { - toolVersion = "0.8.7" -} - -afterEvaluate { project -> - def ignoreList = jacocoIgnoreList - def projectName = project.name - if (ignoreList.contains(projectName)) { - println "Jacoco: ignoring project ${projectName}" - return false - } - setupTestExistenceValidationTask() - if (isAndroidModule(project)) { - setupAndroidReporting(project) - } else { - setupKotlinReporting() - } -} - -def setupTestExistenceValidationTask() { - task testExistenceValidation(type: TestExistenceValidation) -} - -def setupAndroidReporting(Project currentProject) { - tasks.withType(Test) { - jacoco.includeNoLocationClasses true - jacoco.excludes = ['jdk.internal.*'] - } - task jacocoTestReport( - type: JacocoReport, - dependsOn: [ - 'testExistenceValidation', - 'testDebugUnitTest' - ] - ) { - reports { - csv.enabled false - xml { - enabled true - destination file("${buildDir}/coverage-report/${currentProject.name}.xml") - } - html { - enabled true - destination file("${buildDir}/coverage-report/${currentProject.name}.html") - } - } - - final def coverageSourceDirs = [ - "$projectDir/src/main/java", - "$projectDir/src/main/kotlin" - ] - final def kotlinDebugTree = fileTree( - dir: "$buildDir/tmp/kotlin-classes/debug", - excludes: jacocoFileFilter - ) - - final def javaDebugTree = fileTree( - dir: "$buildDir/intermediates/javac/debug/classes", - excludes: jacocoFileFilter - ) - sourceDirectories.from = files(coverageSourceDirs) - classDirectories.from = files([kotlinDebugTree, javaDebugTree]) - executionData.from = fileTree( - dir: project.buildDir, - includes: ['jacoco/testDebugUnitTest.exec'] - ) - } -} - -def setupKotlinReporting() { - jacocoTestReport { - dependsOn testExistenceValidation - dependsOn test - reports { - csv.enabled false - xml { - enabled true - destination file("${buildDir}/coverage-report/${currentProject.name}.xml") - } - html.enabled false - } - } -} - -private static boolean isAndroidModule(Project project) { - def isAndroidLibrary = project.plugins.hasPlugin('com.android.library') - def isAndroidApp = project.plugins.hasPlugin('com.android.application') - return isAndroidLibrary || isAndroidApp -} - -class TestExistenceValidation extends DefaultTask { - - static final SRC_DIR = 'src' - static final JAVA_DIR = 'java' - static final TEST_DIRS = ['test', 'androidTest'] - - static final IGNORED_NAME_PATTERNS = [ - ~/^sample-.++$/ - ] - - @TaskAction - void execute() { - if (shouldSkip(project)) return - - File srcDir = new File(project.projectDir, SRC_DIR) - FileFilter filter = { it.isDirectory() } - File[] subDirs = srcDir.listFiles(filter) ?: [] - File testsDir = subDirs.find { TEST_DIRS.contains(it.name) } - if (testsDir) { - File javaTestsDir = testsDir - .listFiles(filter) - .find { it.name == JAVA_DIR } - if (javaTestsDir && javaTestsDir.list().length > 0) { - return - } - } - - throw new GradleException( - "${project.name} has no unit tests. " - ) - } - - private static boolean shouldSkip(Project project) { - def name = project.name - return IGNORED_NAME_PATTERNS - .collect { name =~ it } // convert Pattern to Matcher - .any { it.find() } - } -} \ No newline at end of file