1 /* 2 * Copyright 2023 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.wrapper 18 19 import androidx.baselineprofile.gradle.apptarget.BaselineProfileAppTargetPlugin 20 import androidx.baselineprofile.gradle.consumer.BaselineProfileConsumerPlugin 21 import androidx.baselineprofile.gradle.producer.BaselineProfileProducerPlugin 22 import org.gradle.api.Plugin 23 import org.gradle.api.Project 24 25 /** 26 * The wrapper plugin simplifies the developer workflow detecting which android plugin is applied to 27 * the module and applying the correct baseline profile plugin. It uses the following mapping: 28 * `com.android.application` can be both [BaselineProfileConsumerPlugin] and 29 * [BaselineProfileAppTargetPlugin], `com.android.library` can be only 30 * [BaselineProfileConsumerPlugin], `com.android.test` can be only [BaselineProfileProducerPlugin] 31 */ 32 class BaselineProfileWrapperPlugin : Plugin<Project> { 33 applynull34 override fun apply(project: Project) { 35 36 // If this module is an application module 37 project.pluginManager.withPlugin("com.android.application") { 38 39 // Applies profile consumer and app target plugins 40 project.pluginManager.apply(BaselineProfileAppTargetPlugin::class.java) 41 project.pluginManager.apply(BaselineProfileConsumerPlugin::class.java) 42 } 43 44 // If this module is a library module 45 project.pluginManager.withPlugin("com.android.library") { 46 47 // Applies the profile consumer plugin 48 project.pluginManager.apply(BaselineProfileConsumerPlugin::class.java) 49 } 50 51 // If this module is a test module 52 project.pluginManager.withPlugin("com.android.test") { 53 54 // Applies the profile producer plugin 55 project.pluginManager.apply(BaselineProfileProducerPlugin::class.java) 56 } 57 } 58 } 59