1 /* <lambda>null2 * 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 package androidx.build 18 19 import org.gradle.api.Project 20 import org.gradle.api.provider.Provider 21 import org.gradle.api.services.BuildService 22 import org.gradle.api.services.BuildServiceParameters 23 24 /** Lists projects as specified by settings.gradle */ 25 abstract class ListProjectsService : BuildService<ListProjectsService.Parameters> { 26 interface Parameters : BuildServiceParameters { 27 var settingsFile: Provider<String> 28 } 29 30 // Lists all project paths mentioned in frameworks/support/settings.gradle 31 // Note that this might be more than the full list of projects configured in this build: 32 // a) Configuration-on-demand can disable projects mentioned in settings.gradle 33 // B) Playground builds use their own settings.gradle files 34 val allPossibleProjects: List<IncludedProject> by lazy { 35 SettingsParser.findProjects(parameters.settingsFile.get()) 36 } 37 38 companion object { 39 internal fun registerOrGet(project: Project): Provider<ListProjectsService> { 40 // service that can compute full list of projects in settings.gradle 41 val settings = project.lazyReadFile("settings.gradle") 42 return project.gradle.sharedServices.registerIfAbsent( 43 "listProjectsService", 44 ListProjectsService::class.java 45 ) { spec -> 46 spec.parameters.settingsFile = settings 47 } 48 } 49 } 50 } 51