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 com.google.common.truth.Truth.assertThat 20 import java.io.File 21 import java.util.Properties 22 import net.saff.checkmark.Checkmark.Companion.check 23 import org.gradle.api.plugins.ExtraPropertiesExtension 24 import org.gradle.api.provider.Provider 25 import org.gradle.testfixtures.ProjectBuilder 26 import org.jetbrains.kotlin.gradle.dsl.KotlinVersion 27 import org.junit.Test 28 29 class SdkResourceGeneratorTest { 30 @Test 31 fun `All SDK properties are resolved`() { 32 val project = ProjectBuilder.builder().build() 33 project.extensions.create( 34 "androidXConfiguration", 35 AndroidXConfigImpl::class.java, 36 project.provider { KotlinVersion.KOTLIN_1_8 }, 37 project.provider { "1.8.21" }, 38 ) 39 40 project.setSupportRootFolder(File("files/support")) 41 val extension = project.rootProject.property("ext") as ExtraPropertiesExtension 42 extension.set("prebuiltsRoot", project.projectDir.resolve("relative/prebuilts")) 43 extension.set("androidx.compileSdk", 33) 44 extension.set("outDir", project.layout.buildDirectory.dir("out").get().asFile) 45 46 val taskProvider = 47 SdkResourceGenerator.registerSdkResourceGeneratorTask( 48 project, 49 kspVersion = "1.2.3", 50 agpVersion = "4.5.6", 51 kgpVersion = "1.7.10", 52 ) 53 val tasks = project.getTasksByName(SdkResourceGenerator.TASK_NAME, false) 54 val generator = tasks.first() as SdkResourceGenerator 55 generator.prebuiltsRelativePath.check { it == "relative/prebuilts" } 56 57 val task = taskProvider.get() 58 val propsFile = task.outputDir.file("sdk.prop").get().asFile 59 propsFile.parentFile.mkdirs() 60 propsFile.createNewFile() 61 task.generateFile() 62 63 val stream = propsFile.inputStream() 64 val properties = Properties() 65 properties.load(stream) 66 67 // All properties must be resolved. 68 properties.values.forEach { propertyValue -> 69 assertThat(propertyValue.toString()).doesNotMatch("task '.+?' property '.+?'") 70 } 71 } 72 73 internal open class AndroidXConfigImpl( 74 override val kotlinApiVersion: Provider<KotlinVersion>, 75 override val kotlinBomVersion: Provider<String>, 76 ) : AndroidXConfiguration 77 } 78