1 /*
2  * Copyright 2024 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 package androidx.baselineprofile.gradle.utils
18 
19 import org.gradle.api.plugins.ExtensionContainer
20 
21 /** Extensions to enable/disable each warnings separately. */
22 abstract class WarningsExtension : Warnings() {
23 
24     companion object {
25         private const val EXTENSION_NAME = "warnings"
26 
registernull27         internal fun register(extensions: ExtensionContainer): Warnings {
28             return extensions.findByType(Warnings::class.java)
29                 ?: extensions.create(EXTENSION_NAME, Warnings::class.java)
30         }
31     }
32 }
33 
34 open class Warnings {
35 
36     /** Controls all the warnings printed by the baseline profile gradle plugin. */
setAllnull37     fun setAll(value: Boolean) {
38         this.maxAgpVersion = value
39         this.disabledVariants = value
40         this.multipleBuildTypesWithAgp80 = value
41         this.noBaselineProfileRulesGenerated = value
42         this.noStartupProfileRulesGenerated = value
43     }
44 
45     /**
46      * Controls the warning for when the Android Gradle Plugin version is higher than the max tested
47      * one.
48      */
49     var maxAgpVersion = true
50 
51     /** Controls the warning for when a benchmark or baseline profile variant has been disabled. */
52     var disabledVariants = true
53 
54     /**
55      * Controls the warning printed when invoking `generateBaselineProfile` with AGP 8.0, that does
56      * not support running instrumentation tests for multiple build types at once.
57      */
58     var multipleBuildTypesWithAgp80 = true
59 
60     /**
61      * Controls the warning printed when no baseline profile are generated after running the
62      * generate baseline profile command.
63      */
64     var noBaselineProfileRulesGenerated = true
65 
66     /**
67      * Controls the warning printed when no startup profile are generated after running the generate
68      * baseline profile command.
69      */
70     var noStartupProfileRulesGenerated = true
71 
72     /**
73      * Controls the warning printed when a variant has no baseline profile dependency set, either
74      * globally or a specific one.
75      */
76     var variantHasNoBaselineProfileDependency = true
77 }
78