From 83e3fd36be28adfe9739f917ae7b0cf5fa616819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Kwiecin=CC=81ski?= Date: Mon, 11 Mar 2024 22:49:45 +0700 Subject: [PATCH 1/2] Use only public AGP apis --- gradle/libs.versions.toml | 1 - sample/gradlew.bat | 20 +++++++++---------- screenshot-testing-plugin/build.gradle | 2 +- .../screenshot/build/ScreenshotsPlugin.kt | 19 +++--------------- 4 files changed, 14 insertions(+), 28 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 789e7bc6..4eb977cd 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -18,7 +18,6 @@ google-material = "1.11.0" google-coordinatorlayout = "1.2.0" [libraries] -agp-gradle-impl = { module = "com.android.tools.build:gradle", version.ref = "google-agp" } agp-gradle-api = { module = "com.android.tools.build:gradle-api", version.ref = "google-agp" } kotlin-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "maven-kotlin" } diff --git a/sample/gradlew.bat b/sample/gradlew.bat index 6689b85b..7101f8e4 100644 --- a/sample/gradlew.bat +++ b/sample/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/screenshot-testing-plugin/build.gradle b/screenshot-testing-plugin/build.gradle index 002ca583..c2ccba2a 100644 --- a/screenshot-testing-plugin/build.gradle +++ b/screenshot-testing-plugin/build.gradle @@ -78,7 +78,7 @@ gradlePlugin { } dependencies { - compileOnly(libs.agp.gradle.impl) + compileOnly(libs.agp.gradle.api) testImplementation(libs.agp.gradle.api) testImplementation(gradleTestKit()) diff --git a/screenshot-testing-plugin/src/main/kotlin/com/facebook/testing/screenshot/build/ScreenshotsPlugin.kt b/screenshot-testing-plugin/src/main/kotlin/com/facebook/testing/screenshot/build/ScreenshotsPlugin.kt index 56b30ab4..46c73cd3 100644 --- a/screenshot-testing-plugin/src/main/kotlin/com/facebook/testing/screenshot/build/ScreenshotsPlugin.kt +++ b/screenshot-testing-plugin/src/main/kotlin/com/facebook/testing/screenshot/build/ScreenshotsPlugin.kt @@ -19,9 +19,6 @@ package com.facebook.testing.screenshot.build import com.android.build.api.variant.AndroidComponentsExtension import com.android.build.api.variant.AndroidTest import com.android.build.api.variant.HasAndroidTest -import com.android.build.gradle.AppExtension -import com.android.build.gradle.LibraryExtension -import com.android.build.gradle.TestedExtension import com.usefulness.testing.screenshot.build.ScreenshotTask import io.github.usefulness.testing.screenshot.generated.ScreenshotTestBuildConfig import org.gradle.api.Plugin @@ -77,21 +74,11 @@ class ScreenshotsPlugin : Plugin { val androidTest = (variant as? HasAndroidTest)?.androidTest if (androidTest != null) { generateTasksFor(androidTest) + androidTest.instrumentationRunner + androidTest.instrumentationRunner.set(TEST_RUNNER_CLASS) + androidTest.instrumentationRunnerArguments.put("SCREENSHOT_TESTS_RUN_ID", SCREENSHOT_TESTS_RUN_ID) } } - val androidExtension = getProjectExtension(this) - androidExtension.defaultConfig.testInstrumentationRunner = TEST_RUNNER_CLASS - androidExtension.defaultConfig.testInstrumentationRunnerArguments["SCREENSHOT_TESTS_RUN_ID"] = SCREENSHOT_TESTS_RUN_ID - } - - private fun getProjectExtension(project: Project): TestedExtension { - val extensions = project.extensions - val plugins = project.plugins - return when { - plugins.hasPlugin("com.android.application") -> extensions.findByType(AppExtension::class.java)!! - plugins.hasPlugin("com.android.library") -> extensions.findByType(LibraryExtension::class.java)!! - else -> throw IllegalArgumentException("Screenshot Test plugin requires Android's plugin") - } } private inline fun Project.registerTask(name: String, variant: AndroidTest) = From 863e01e8f1d304f53e4ab556e64cddaa4e7831af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Kwiecin=CC=81ski?= Date: Mon, 11 Mar 2024 22:58:49 +0700 Subject: [PATCH 2/2] Fix `ValueError: Operation on closed image` --- .../src/py/android_screenshot_tests/recorder.py | 1 - 1 file changed, 1 deletion(-) diff --git a/screenshot-testing-plugin/src/py/android_screenshot_tests/recorder.py b/screenshot-testing-plugin/src/py/android_screenshot_tests/recorder.py index 4b1affa1..2db58d52 100644 --- a/screenshot-testing-plugin/src/py/android_screenshot_tests/recorder.py +++ b/screenshot-testing-plugin/src/py/android_screenshot_tests/recorder.py @@ -67,7 +67,6 @@ def _copy(self, name, w, h): input_file = common.get_image_file_name(name, i, j) with Image.open(join(self._input, input_file)) as input_image: im.paste(input_image, (i * tilewidth, j * tileheight)) - input_image.close() im.save(join(self._output, name + ".png")) im.close()