From 8a1baf5013f2607eaed752e737f1f8b8dba455a7 Mon Sep 17 00:00:00 2001 From: Michael Oliveira Date: Mon, 26 Aug 2024 10:05:49 +0200 Subject: [PATCH 1/2] Add boolean property to allow webp format export --- .../gradle/MultiplatformResourcesPluginExtension.kt | 2 ++ .../gradle/generator/factory/ImageGeneratorFactory.kt | 7 ++++++- .../gradle/tasks/GenerateMultiplatformResourcesTask.kt | 6 +++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPluginExtension.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPluginExtension.kt index 959bae57..7b138996 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPluginExtension.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPluginExtension.kt @@ -19,6 +19,7 @@ abstract class MultiplatformResourcesPluginExtension { abstract val resourcesVisibility: Property abstract val iosMinimalDeploymentTarget: Property abstract val resourcesSourceSets: NamedDomainObjectContainer + abstract val allowWebpImageFormat: Property fun Project.configureCopyXCFrameworkResources(xcFrameworkName: String = name) { NativeBuildType.values() @@ -35,4 +36,5 @@ internal fun MultiplatformResourcesPluginExtension.setupConvention(project: Proj iosBaseLocalizationRegion.convention("en") resourcesVisibility.convention(MRVisibility.Public) iosMinimalDeploymentTarget.convention("9.0") + allowWebpImageFormat.convention(false) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/ImageGeneratorFactory.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/ImageGeneratorFactory.kt index 69204611..b6bc653f 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/ImageGeneratorFactory.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/ImageGeneratorFactory.kt @@ -31,6 +31,7 @@ internal class ImageGeneratorFactory( private val outputAssetsDir: File, private val kotlinPlatformType: KotlinPlatformType, private val kotlinKonanTarget: () -> KonanTarget, + private val allowWebpImageFormat: Boolean, private val androidRClassPackage: () -> String, private val logger: Logger ) { @@ -44,7 +45,11 @@ internal class ImageGeneratorFactory( generator = ImageResourceGenerator(), platformResourceGenerator = createPlatformImageGenerator(), filter = { - include("images/**/*.png", "images/**/*.jpg", "images/**/*.svg") + val formats = mutableListOf("images/**/*.png", "images/**/*.jpg", "images/**/*.svg") + if (allowWebpImageFormat) { + formats.add("images/**/*.webp") + } + include(formats) } ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/GenerateMultiplatformResourcesTask.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/GenerateMultiplatformResourcesTask.kt index 2eb52b14..0da87562 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/GenerateMultiplatformResourcesTask.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/GenerateMultiplatformResourcesTask.kt @@ -99,6 +99,9 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { @get:Input abstract val strictLineBreaks: Property + @get:Input + abstract val allowWebpImageFormat: Property + @get:Optional @get:PathSensitive(PathSensitivity.RELATIVE) @get:InputFiles @@ -229,8 +232,9 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { outputAssetsDir = outputAssetsDir.get().asFile, kotlinPlatformType = kotlinPlatformType, kotlinKonanTarget = ::kotlinKonanTarget, + allowWebpImageFormat = allowWebpImageFormat.get(), androidRClassPackage = androidRClassPackage::get, - logger = logger + logger = logger, ).create(), ColorGeneratorFactory( resourcesVisibility = resourcesVisibility.get(), From dd81d53a2ebb6357fda75b953a3220cc650f312f Mon Sep 17 00:00:00 2001 From: Michael Oliveira Date: Mon, 26 Aug 2024 14:16:07 +0200 Subject: [PATCH 2/2] Put the prperty optional --- .../icerock/gradle/tasks/GenerateMultiplatformResourcesTask.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/GenerateMultiplatformResourcesTask.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/GenerateMultiplatformResourcesTask.kt index 0da87562..40c24132 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/GenerateMultiplatformResourcesTask.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/GenerateMultiplatformResourcesTask.kt @@ -99,6 +99,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { @get:Input abstract val strictLineBreaks: Property + @get:Optional @get:Input abstract val allowWebpImageFormat: Property