Skip to content

Commit

Permalink
Merge pull request #230 from usefulness/updates
Browse files Browse the repository at this point in the history
Use only public AGP apis + fix "ValueError: Operation on closed image"
  • Loading branch information
mateuszkwiecinski authored Mar 11, 2024
2 parents 3055b3d + 863e01e commit 0bcfd00
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 29 deletions.
1 change: 0 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand Down
20 changes: 10 additions & 10 deletions sample/gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion screenshot-testing-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ gradlePlugin {
}

dependencies {
compileOnly(libs.agp.gradle.impl)
compileOnly(libs.agp.gradle.api)

testImplementation(libs.agp.gradle.api)
testImplementation(gradleTestKit())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -77,21 +74,11 @@ class ScreenshotsPlugin : Plugin<Project> {
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 <reified T : ScreenshotTask> Project.registerTask(name: String, variant: AndroidTest) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 0bcfd00

Please sign in to comment.