| /* |
| * Copyright 2020 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| /** |
| * This file was created using the `createProject` gradle task (./gradlew createProject) |
| * |
| * Please use the task when creating a new project, rather than copying an existing project and |
| * modifying its settings. |
| */ |
| import org.jetbrains.kotlin.gradle.tasks.KotlinCompile |
| |
| plugins { |
| id("AndroidXPlugin") |
| id("AndroidXComposePlugin") |
| id("com.android.library") |
| } |
| |
| android { |
| compileSdk { version = release(35) } |
| namespace = "androidx.compose.runtime.integrationtests" |
| } |
| |
| dependencies { |
| androidTestImplementation(project(":compose:runtime:runtime")) |
| androidTestImplementation(project(":compose:ui:ui")) |
| androidTestImplementation(project(":compose:material:material")) |
| androidTestImplementation(project(":compose:foundation:foundation-layout")) |
| androidTestImplementation(project(":compose:ui:ui-test-junit4")) |
| androidTestImplementation(libs.kotlinTest) |
| androidTestImplementation(project(":compose:test-utils")) |
| androidTestImplementation("androidx.activity:activity-compose:1.10.1") |
| androidTestImplementation(libs.testExtJunit) |
| androidTestImplementation(libs.testRules) |
| androidTestImplementation(libs.testRunner) |
| androidTestImplementation(libs.truth) |
| } |
| |
| tasks.withType(KotlinCompile).configureEach { |
| compilerOptions { |
| freeCompilerArgs.add("-Xcontext-receivers") |
| } |
| } |
| |
| public File findFile() { |
| project.file("src/androidTest/kotlin/androidx/compose/runtime/GroupSizeTests.kt") |
| } |
| |
| class UpdateExpectedGroupSizes extends DefaultTask { |
| @Internal |
| File source |
| |
| @Internal |
| String sizes |
| |
| @TaskAction |
| def exec() { |
| def newExpected = sizes.split(",") |
| if (newExpected.length != 3) { |
| if (newExpected.length < 3) |
| parameterError("Not enough parameters") |
| parameterError("Too many parameters") |
| } |
| if (!newExpected[1].isInteger()) { |
| parameterError("Groups field is not an integer") |
| } |
| if (!newExpected[1].isInteger()) { |
| parameterError("Slots field is not an integer") |
| } |
| def testName = newExpected[0] |
| def newGroups = newExpected[1] as Integer |
| def newSlots = newExpected[2] as Integer |
| |
| def lines = source.readLines() |
| def modified = false |
| |
| def namePattern = "\"$testName\"" |
| for (int i = 0; i < lines.size(); i++) { |
| String line = lines[i] |
| if (line.contains(namePattern)) { |
| def newGroupsIndex = lines[i + 1].indexOf("noMoreGroupsThan") |
| if (newGroupsIndex < 0) error("Group line not found for test $namePattern") |
| lines[i + 1] = lines[i + 1].replaceFirst(/[0-9]+/, "$newGroups") |
| def newSlotsIndex = lines[i + 2].indexOf("noMoreSlotsThan") |
| if (newSlotsIndex < 0) error("Group line not found for test $namePattern") |
| lines[i + 2] = lines[i + 2].replaceFirst(/[0-9]+/, "$newSlots") |
| modified = true |
| } |
| } |
| if (!modified) error("Could not find test $namePattern") |
| |
| // Update the file |
| def writer = source.newWriter() |
| lines.forEach {line -> |
| writer.write("$line\n") |
| } |
| writer.close() |
| } |
| |
| def parameterError(String message) { |
| error("$message, expected newExpectedGroups to look like " + |
| "<testsName>,<newGroups>,<newSlots>") |
| } |
| |
| def error(String message) { |
| throw new GradleException(message) |
| } |
| } |
| |
| afterEvaluate { |
| tasks.register("updateExpectedGroupSizes", UpdateExpectedGroupSizes) { task -> |
| task.source = findFile() |
| task.sizes = project.findProperty("compose.newExpectedSizes") |
| } |
| } |