1 /*
2  * Copyright 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 plugins {
18     alias(libs.plugins.android.library)
19     alias(libs.plugins.kotlin.android)
20     jacoco
21 }
22 
23 val jetpackComposeVersion: String? by extra
24 
25 android {
26     namespace = "com.android.settingslib.spa"
27 
28     defaultConfig {
29         testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
30     }
31 
32     sourceSets {
33         sourceSets.getByName("main") {
34             kotlin.setSrcDirs(listOf("src"))
35             res.setSrcDirs(listOf("res"))
36             manifest.srcFile("AndroidManifest.xml")
37         }
38         sourceSets.getByName("androidTest") {
39             kotlin.setSrcDirs(listOf("../tests/src"))
40             res.setSrcDirs(listOf("../tests/res"))
41             manifest.srcFile("../tests/AndroidManifest.xml")
42         }
43     }
44     buildFeatures {
45         compose = true
46     }
47     buildTypes {
48         getByName("debug") {
49             enableAndroidTestCoverage = true
50         }
51     }
52 }
53 
54 dependencies {
55     api("androidx.appcompat:appcompat:1.7.0-alpha02")
56     api("androidx.slice:slice-builders:1.1.0-alpha02")
57     api("androidx.slice:slice-core:1.1.0-alpha02")
58     api("androidx.slice:slice-view:1.1.0-alpha02")
59     api("androidx.compose.material3:material3:1.2.0-alpha03")
60     api("androidx.compose.material:material-icons-extended:$jetpackComposeVersion")
61     api("androidx.compose.runtime:runtime-livedata:$jetpackComposeVersion")
62     api("androidx.compose.ui:ui-tooling-preview:$jetpackComposeVersion")
63     api("androidx.lifecycle:lifecycle-livedata-ktx")
64     api("androidx.lifecycle:lifecycle-runtime-compose")
65     api("androidx.navigation:navigation-compose:2.7.0-beta01")
66     api("com.github.PhilJay:MPAndroidChart:v3.1.0-alpha")
67     api("com.google.android.material:material:1.7.0-alpha03")
68     debugApi("androidx.compose.ui:ui-tooling:$jetpackComposeVersion")
69     implementation("com.airbnb.android:lottie-compose:5.2.0")
70 
71     androidTestImplementation(project(":testutils"))
72     androidTestImplementation(libs.dexmaker.mockito)
73 }
74 
75 tasks.register<JacocoReport>("coverageReport") {
76     group = "Reporting"
77     description = "Generate Jacoco coverage reports after running tests."
78     dependsOn("connectedDebugAndroidTest")
79     sourceDirectories.setFrom(files("src"))
80     classDirectories.setFrom(
81         fileTree(layout.buildDirectory.dir("tmp/kotlin-classes/debug")) {
82             setExcludes(
83                 listOf(
84                     "com/android/settingslib/spa/debug/**",
85 
86                     // Excludes files forked from AndroidX.
87                     "com/android/settingslib/spa/widget/scaffold/CustomizedAppBar*",
88                     "com/android/settingslib/spa/widget/scaffold/TopAppBarColors*",
89 
90                     // Excludes files forked from Accompanist.
91                     "com/android/settingslib/spa/framework/compose/DrawablePainter*",
92 
93                     // Excludes inline functions, which is not covered in Jacoco reports.
94                     "com/android/settingslib/spa/framework/util/Collections*",
95                     "com/android/settingslib/spa/framework/util/Flows*",
96 
97                     // Excludes debug functions
98                     "com/android/settingslib/spa/framework/compose/TimeMeasurer*",
99 
100                     // Excludes slice demo presenter & provider
101                     "com/android/settingslib/spa/slice/presenter/Demo*",
102                     "com/android/settingslib/spa/slice/provider/Demo*",
103                 )
104             )
105         }
106     )
107     executionData.setFrom(
108         fileTree(layout.buildDirectory.dir("outputs/code_coverage/debugAndroidTest/connected"))
109     )
110 }
111