@@ -3,6 +3,7 @@ package conventions
3
3
import org.gradle.api.Plugin
4
4
import org.gradle.api.Project
5
5
import org.gradle.api.artifacts.VersionCatalogsExtension
6
+ import org.gradle.api.file.FileTree
6
7
import org.gradle.configurationcache.extensions.capitalized
7
8
import org.gradle.kotlin.dsl.extra
8
9
import org.gradle.kotlin.dsl.getByType
@@ -18,47 +19,47 @@ import ytemplate.android.jacoco.jacoco
18
19
*
19
20
* @constructor Create empty Library jacoco convention plugin
20
21
*/
22
+ @Suppress(" UNCHECKED_CAST" )
21
23
class ProjectJacocoConventionPlugin : Plugin <Project > {
22
- private val project_level_limits = mutableMapOf (
23
- " instruction" to 0.0 ,
24
- " branch" to 0.0 ,
25
- " line" to 0.0 ,
26
- " complexity" to 0.0 ,
27
- " method" to 0.0 ,
28
- " class" to 0.0
29
- )
30
-
31
-
32
- fun Project.setProjectTestCoverageLimits (projectLimits : Map <String , Double >? = null) {
33
- if (projectLimits != null ) {
34
- extra.set(" limits" , projectLimits)
35
- } else {
36
- extra.set(" limits" , project_level_limits)
37
- }
38
- }
39
-
40
24
override fun apply (target : Project ) {
41
25
with (target) {
42
- val libs = extensions.getByType<VersionCatalogsExtension >().named(" versionCatalogLibs" )
43
26
with (pluginManager) {
44
27
apply (" jacoco" )
45
28
}
46
- tasks.register<JacocoReport >(" MergeHTMLJacocoReports" ) {
29
+
30
+ tasks.register<JacocoReport >(" createMergedJacocoReport" ) {
47
31
val jacocoReport = this
48
32
group = " Reporting"
49
- description = " Merge all generated JacocoReport "
33
+ description = " create Project Jacoco Report for debug builds for all submodules with jacoco plugin "
50
34
logger.quiet(" ======Merging HTML Reports=========" )
51
- val javaClasses: MutableCollection <String > = mutableListOf ()
52
- val kotlinClasses: MutableCollection <String > = mutableListOf ()
35
+ val javaClasses: MutableCollection <FileTree > = mutableListOf ()
36
+ val kotlinClasses: MutableCollection <FileTree > = mutableListOf ()
53
37
val sourceDir: MutableCollection <String > = mutableListOf ()
54
38
val coverageFiles: MutableCollection <String > = mutableListOf ()
39
+
55
40
subprojects {
56
41
val subProject = this
57
42
subProject.plugins.withType<JacocoPlugin >().configureEach {
58
43
val moduleTask = tasks.findByName(" createDemoDebugJacocoReport" )
59
44
jacocoReport.dependsOn(moduleTask)
60
- javaClasses.add(" ${subProject.buildDir} /intermediates/javac/demoDebug/classes" )
61
- kotlinClasses.add(" ${subProject.buildDir} /tmp/kotlin-classes/demoDebug" )
45
+ }
46
+ if (subProject.plugins.findPlugin(JacocoPlugin ::class .java)!= null ) {
47
+ val excludedFiles: MutableCollection <String > = mutableListOf ()
48
+ if (subProject.extra.has(" excludes" )) {
49
+ excludedFiles.addAll(subProject.extra.get(" excludes" ) as List <String >)
50
+ }
51
+ javaClasses.add(fileTree(" ${subProject.buildDir} /intermediates/javac/demoDebug/classes" ) {
52
+ if (excludedFiles.isNotEmpty()) {
53
+ exclude(excludedFiles)
54
+ }
55
+
56
+ }.asFileTree)
57
+ kotlinClasses.add(fileTree(" ${subProject.buildDir} /tmp/kotlin-classes/demoDebug" ) {
58
+ if (excludedFiles.isNotEmpty()) {
59
+ exclude(excludedFiles)
60
+ }
61
+ }.asFileTree)
62
+
62
63
sourceDir.add(" ${subProject.projectDir} /src/main/java" )
63
64
sourceDir.add(" ${subProject.projectDir} /src/main/kotlin" )
64
65
sourceDir.add(" ${subProject.projectDir} /src/demoDebug/java" )
0 commit comments