From f47bb5bc05dfa55961f6bc16747f8f192d3e9ff7 Mon Sep 17 00:00:00 2001 From: Colin Lee Date: Mon, 1 May 2023 16:08:08 -0500 Subject: [PATCH 001/352] Fix #118: Fill in missing string translations with base translation --- .../resources/desc/PluralFormattedStringDesc.kt | 5 +++++ .../dev/icerock/moko/resources/desc/Utils.kt | 15 +++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/resources/src/appleMain/kotlin/dev/icerock/moko/resources/desc/PluralFormattedStringDesc.kt b/resources/src/appleMain/kotlin/dev/icerock/moko/resources/desc/PluralFormattedStringDesc.kt index 774b7c659..2a18bcec5 100644 --- a/resources/src/appleMain/kotlin/dev/icerock/moko/resources/desc/PluralFormattedStringDesc.kt +++ b/resources/src/appleMain/kotlin/dev/icerock/moko/resources/desc/PluralFormattedStringDesc.kt @@ -5,6 +5,7 @@ package dev.icerock.moko.resources.desc import dev.icerock.moko.resources.PluralsResource +import dev.icerock.moko.resources.desc.Utils.FALLBACK_FALLBACK_LOCALE import platform.Foundation.NSBundle import platform.Foundation.NSLocale import platform.Foundation.NSString @@ -37,10 +38,13 @@ internal fun pluralizedString( resourceId: String, number: Int ): String { + val fallbackLocale = bundle.developmentLocalization ?: FALLBACK_FALLBACK_LOCALE val localized = bundle .localizedStringForKey(resourceId, null, null) .takeUnless { it == resourceId } ?: baseBundle.localizedStringForKey(resourceId, null, null) + .takeUnless { it == resourceId } ?: StringDesc.LocaleType.Custom(fallbackLocale) + .getLocaleBundle(bundle).localizedStringForKey(resourceId, null, null) @Suppress("CAST_NEVER_SUCCEEDS") return NSString.create( format = localized, @@ -48,3 +52,4 @@ internal fun pluralizedString( args = arrayOf(number) ) as String } + diff --git a/resources/src/appleMain/kotlin/dev/icerock/moko/resources/desc/Utils.kt b/resources/src/appleMain/kotlin/dev/icerock/moko/resources/desc/Utils.kt index b52e5675b..6420ebf5d 100644 --- a/resources/src/appleMain/kotlin/dev/icerock/moko/resources/desc/Utils.kt +++ b/resources/src/appleMain/kotlin/dev/icerock/moko/resources/desc/Utils.kt @@ -9,16 +9,23 @@ import platform.Foundation.NSString import platform.Foundation.stringWithFormat object Utils { + const val FALLBACK_FALLBACK_LOCALE = "en" + fun processArgs(args: List): Array { return args.map { (it as? StringDesc)?.localized() ?: it }.toTypedArray() } fun localizedString(stringRes: StringResource): String { val bundle = StringDesc.localeType.getLocaleBundle(stringRes.bundle) - val string = bundle.localizedStringForKey(stringRes.resourceId, null, null) - return if (string == stringRes.resourceId) { - stringRes.bundle.localizedStringForKey(stringRes.resourceId, null, null) - } else string + val stringInCurrentLocale = bundle.localizedStringForKey(stringRes.resourceId, null, null) + return if (stringInCurrentLocale == stringRes.resourceId) { + val stringInDefaultBundle = stringRes.bundle.localizedStringForKey(stringRes.resourceId, null, null) + if (stringInDefaultBundle == stringRes.resourceId) { + val fallbackLocale = stringRes.bundle.developmentLocalization ?: FALLBACK_FALLBACK_LOCALE + val fallbackLocaleBundle = StringDesc.LocaleType.Custom(fallbackLocale).getLocaleBundle(bundle) + fallbackLocaleBundle.localizedStringForKey(stringRes.resourceId, null, null) + } else stringInDefaultBundle + } else stringInCurrentLocale } fun stringWithFormat(format: String, args: Array): String { From 6881efc90404d3dfd7efee85c4257857d6cda50b Mon Sep 17 00:00:00 2001 From: Lucchetto Date: Sat, 1 Jul 2023 23:13:38 +0200 Subject: [PATCH 002/352] Add fallback for plural when string of quantity not defined on JVM Signed-off-by: Lucchetto --- .../kotlin/dev/icerock/moko/resources/PluralsResource.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/resources/src/jvmMain/kotlin/dev/icerock/moko/resources/PluralsResource.kt b/resources/src/jvmMain/kotlin/dev/icerock/moko/resources/PluralsResource.kt index 53c9cab56..0b87b1370 100644 --- a/resources/src/jvmMain/kotlin/dev/icerock/moko/resources/PluralsResource.kt +++ b/resources/src/jvmMain/kotlin/dev/icerock/moko/resources/PluralsResource.kt @@ -4,7 +4,6 @@ package dev.icerock.moko.resources -import com.ibm.icu.text.MessageFormat import com.ibm.icu.text.PluralRules import com.ibm.icu.util.ULocale import java.util.* @@ -22,7 +21,11 @@ actual class PluralsResource( val selectedVariant = pluralRules.select(quantity.toDouble()) val keyWithQuantity = "$key.$selectedVariant" - return resourceBundle.getString(keyWithQuantity) + return if (resourceBundle.containsKey(keyWithQuantity)) { + resourceBundle.getString(keyWithQuantity) + } else { + resourceBundle.getString("$key.${PluralRules.KEYWORD_OTHER}") + } } fun localized(locale: Locale = Locale.getDefault(), quantity: Int): String = From 047f1f4060d010e7f9f81e9a47991d4faa5087dc Mon Sep 17 00:00:00 2001 From: Lucchetto Date: Sun, 2 Jul 2023 10:23:59 +0200 Subject: [PATCH 003/352] Add tests for plural fallback Signed-off-by: Lucchetto --- .../commonMain/resources/MR/base/plurals-test.xml | 4 ++++ .../commonMain/resources/MR/ru/plurals-test.xml | 4 ++++ .../com/icerock/library/PluralResourceEnTests.kt | 12 ++++++++++++ .../com/icerock/library/PluralResourceRuTests.kt | 14 ++++++++++++-- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/base/plurals-test.xml b/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/base/plurals-test.xml index ab64371c1..3443d601c 100644 --- a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/base/plurals-test.xml +++ b/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/base/plurals-test.xml @@ -25,4 +25,8 @@ plurals-interop: two plurals-interop: other + + one + other + diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/ru/plurals-test.xml b/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/ru/plurals-test.xml index 9430468c6..69351a7d9 100644 --- a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/ru/plurals-test.xml +++ b/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/ru/plurals-test.xml @@ -33,4 +33,8 @@ %s two %s other + + один + другое + diff --git a/samples/resources-gallery/mpp-library/src/commonTest/kotlin/com/icerock/library/PluralResourceEnTests.kt b/samples/resources-gallery/mpp-library/src/commonTest/kotlin/com/icerock/library/PluralResourceEnTests.kt index 5946a6e36..934d5436b 100644 --- a/samples/resources-gallery/mpp-library/src/commonTest/kotlin/com/icerock/library/PluralResourceEnTests.kt +++ b/samples/resources-gallery/mpp-library/src/commonTest/kotlin/com/icerock/library/PluralResourceEnTests.kt @@ -50,6 +50,18 @@ class PluralResourceEnTests : BaseStringResourceTests("en") { actual = MR.plurals.test_plural.desc(22) ) + @Test + fun checkPluralFallback1() = pluralTest( + expected = "one", + actual = MR.plurals.test_plural_fallback.desc(1) + ) + + @Test + fun checkPluralFallback2() = pluralTest( + expected = "other", + actual = MR.plurals.test_plural_fallback.desc(2) + ) + @Test fun checkVariantsPlurals() = pluralTest( expected = """ diff --git a/samples/resources-gallery/mpp-library/src/commonTest/kotlin/com/icerock/library/PluralResourceRuTests.kt b/samples/resources-gallery/mpp-library/src/commonTest/kotlin/com/icerock/library/PluralResourceRuTests.kt index 01c2b9537..27c8d15b1 100644 --- a/samples/resources-gallery/mpp-library/src/commonTest/kotlin/com/icerock/library/PluralResourceRuTests.kt +++ b/samples/resources-gallery/mpp-library/src/commonTest/kotlin/com/icerock/library/PluralResourceRuTests.kt @@ -6,9 +6,7 @@ package com.icerock.library import com.icerockdev.library.MR import com.icerockdev.library.Testing -import dev.icerock.moko.resources.desc.StringDesc import dev.icerock.moko.resources.desc.desc -import kotlin.test.BeforeTest import kotlin.test.Ignore import kotlin.test.Test @@ -52,6 +50,18 @@ class PluralResourceRuTests : BaseStringResourceTests("ru") { actual = MR.plurals.test_plural.desc(22) ) + @Test + fun checkPluralFallback1() = pluralTest( + expected = "один", + actual = MR.plurals.test_plural_fallback.desc(1) + ) + + @Test + fun checkPluralFallback2() = pluralTest( + expected = "другое", + actual = MR.plurals.test_plural_fallback.desc(2) + ) + @Test fun checkVariantsPlurals() = pluralTest( expected = """ From 14c388681e2f5d6651e0d0adbae4d6108ded6a6f Mon Sep 17 00:00:00 2001 From: viktor kuzmin Date: Tue, 25 Jul 2023 11:12:22 +0300 Subject: [PATCH 004/352] #510 update kotlin version --- gradle/libs.versions.toml | 6 +- kotlin-js-store/yarn.lock | 768 ++++++------------ .../main/kotlin/detekt-convention.gradle.kts | 2 +- ...form-android-publish-convention.gradle.kts | 2 +- ...ultiplatform-library-convention.gradle.kts | 2 +- resources-compose/build.gradle.kts | 2 +- .../compose/internal/CGImageRef+Skia.kt | 2 + .../resources/compose/internal/NSDataExt.kt | 2 + .../moko/resources/compose/ColorResource.kt | 2 + .../moko/resources/compose/ImageResource.kt | 2 + .../moko/resources/compose/StringDescExt.kt | 2 + .../moko/resources/compose/ImageResource.kt | 2 + resources-generator/build.gradle.kts | 2 +- .../gradle/generator/FontsGenerator.kt | 3 +- .../generator/apple/AppleMRGenerator.kt | 2 +- .../icerock/moko/resources/FileResource.kt | 2 + .../icerock/moko/resources/FontResource.kt | 2 + .../icerock/moko/resources/FontResource.kt | 2 + samples/android-mpp-app/app/build.gradle.kts | 2 +- samples/android-mpp-app/build.gradle.kts | 2 +- samples/auto-manifest/build.gradle.kts | 2 +- .../mpp-library/build.gradle.kts | 2 +- samples/compose-jvm-app/build.gradle.kts | 2 +- .../androidApp/build.gradle.kts | 2 +- .../gradle.properties | 2 +- .../shared/build.gradle.kts | 2 +- .../ios-static-xcframework/build.gradle.kts | 2 +- samples/kotlin-ios-app/build.gradle.kts | 2 +- samples/resources-gallery/build.gradle.kts | 4 +- .../mpp-library/build.gradle.kts | 2 +- 30 files changed, 275 insertions(+), 558 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2295eb5a8..99af28b28 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -kotlinVersion = "1.8.20" +kotlinVersion = "1.9.0" androidGradleVersion = "7.4.2" androidSdkCommonVersion = "31.0.0" @@ -12,11 +12,11 @@ constraintLayoutVersion = "2.1.4" androidAppCompatVersion = "1.6.1" # android compose -composeVersion = "1.4.2" +composeVersion = "1.4.3" composeActivityVersion = "1.7.1" # jetbrains compose -composeJetbrainsVersion = "1.4.0" +composeJetbrainsVersion = "1.5.0-dev1114" # jvm apacheCommonsTextVersion = "1.10.0" diff --git a/kotlin-js-store/yarn.lock b/kotlin-js-store/yarn.lock index 75930f9a6..678dd3428 100644 --- a/kotlin-js-store/yarn.lock +++ b/kotlin-js-store/yarn.lock @@ -2,27 +2,6 @@ # yarn lockfile v1 -"@babel/code-frame@^7.10.4": - version "7.21.4" - resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.21.4.tgz#d0fa9e4413aca81f2b23b9442797bda1826edb39" - integrity sha512-LYvhNKfwWSPpocw8GI7gpK2nq3HSDuEPC/uSYaALSJu9xjsalaaYFOq0Pwt5KmVqwEbZlDu81aLXwBOmD/Fv9g== - dependencies: - "@babel/highlight" "^7.18.6" - -"@babel/helper-validator-identifier@^7.18.6": - version "7.19.1" - resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.19.1.tgz#7eea834cf32901ffdc1a7ee555e2f9c27e249ca2" - integrity sha512-awrNfaMtnHUr653GgGEs++LlAvW6w+DcPrOliSMXWCKo597CwL5Acf/wWdNkf/tfEQE3mjkeD1YOVZOUV/od1w== - -"@babel/highlight@^7.18.6": - version "7.18.6" - resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.18.6.tgz#81158601e93e2563795adcbfbdf5d64be3f2ecdf" - integrity sha512-u7stbOuYjaPezCuLj29hNW1v64M2Md2qupEKP1fHc7WdOA3DgLh37suiSrZYY7haUB7iBeQZ9P1uiRF359do3g== - dependencies: - "@babel/helper-validator-identifier" "^7.18.6" - chalk "^2.0.0" - js-tokens "^4.0.0" - "@colors/colors@1.5.0": version "1.5.0" resolved "https://registry.yarnpkg.com/@colors/colors/-/colors-1.5.0.tgz#bb504579c1cae923e6576a4f5da43d25f97bdbd9" @@ -70,7 +49,7 @@ resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz#d7c6e6755c78567a951e04ab52ef0fd26de59f32" integrity sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg== -"@jridgewell/trace-mapping@^0.3.9": +"@jridgewell/trace-mapping@^0.3.17", "@jridgewell/trace-mapping@^0.3.9": version "0.3.18" resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.18.tgz#25783b2086daf6ff1dcb53c9249ae480e4dd4cd6" integrity sha512-w+niJYzMHdd7USdiH2U6869nqhD2nbfZXND5Yp93qIbEmnDNk7PD48o+YchRVpzMU7M6jVCbenTR7PA1FLQ9pA== @@ -114,48 +93,6 @@ dependencies: make-plural "^7.0.0" -"@rollup/plugin-commonjs@^21.0.1": - version "21.1.0" - resolved "https://registry.yarnpkg.com/@rollup/plugin-commonjs/-/plugin-commonjs-21.1.0.tgz#45576d7b47609af2db87f55a6d4b46e44fc3a553" - integrity sha512-6ZtHx3VHIp2ReNNDxHjuUml6ur+WcQ28N1yHgCQwsbNkQg2suhxGMDQGJOn/KuDxKtd1xuZP5xSTwBA4GQ8hbA== - dependencies: - "@rollup/pluginutils" "^3.1.0" - commondir "^1.0.1" - estree-walker "^2.0.1" - glob "^7.1.6" - is-reference "^1.2.1" - magic-string "^0.25.7" - resolve "^1.17.0" - -"@rollup/plugin-node-resolve@^13.1.3": - version "13.3.0" - resolved "https://registry.yarnpkg.com/@rollup/plugin-node-resolve/-/plugin-node-resolve-13.3.0.tgz#da1c5c5ce8316cef96a2f823d111c1e4e498801c" - integrity sha512-Lus8rbUo1eEcnS4yTFKLZrVumLPY+YayBdWXgFSHYhTT2iJbMhoaaBL3xl5NCdeRytErGr8tZ0L71BMRmnlwSw== - dependencies: - "@rollup/pluginutils" "^3.1.0" - "@types/resolve" "1.17.1" - deepmerge "^4.2.2" - is-builtin-module "^3.1.0" - is-module "^1.0.0" - resolve "^1.19.0" - -"@rollup/plugin-typescript@^8.3.0": - version "8.5.0" - resolved "https://registry.yarnpkg.com/@rollup/plugin-typescript/-/plugin-typescript-8.5.0.tgz#7ea11599a15b0a30fa7ea69ce3b791d41b862515" - integrity sha512-wMv1/scv0m/rXx21wD2IsBbJFba8wGF3ErJIr6IKRfRj49S85Lszbxb4DCo8iILpluTjk2GAAu9CoZt4G3ppgQ== - dependencies: - "@rollup/pluginutils" "^3.1.0" - resolve "^1.17.0" - -"@rollup/pluginutils@^3.0.9", "@rollup/pluginutils@^3.1.0": - version "3.1.0" - resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-3.1.0.tgz#706b4524ee6dc8b103b3c995533e5ad680c02b9b" - integrity sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg== - dependencies: - "@types/estree" "0.0.39" - estree-walker "^1.0.1" - picomatch "^2.2.2" - "@socket.io/component-emitter@~3.1.0": version "3.1.0" resolved "https://registry.yarnpkg.com/@socket.io/component-emitter/-/component-emitter-3.1.0.tgz#96116f2a912e0c02817345b3c10751069920d553" @@ -194,15 +131,10 @@ resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.50.tgz#1e0caa9364d3fccd2931c3ed96fdbeaa5d4cca83" integrity sha512-C6N5s2ZFtuZRj54k2/zyRhNDjJwwcViAM3Nbm8zjBpbqAdZ00mr0CFxvSKeO8Y/e03WVFLpQMdHYVfUd6SB+Hw== -"@types/estree@0.0.39": - version "0.0.39" - resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f" - integrity sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw== - -"@types/estree@^0.0.51": - version "0.0.51" - resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.51.tgz#cfd70924a25a3fd32b218e5e420e6897e1ac4f40" - integrity sha512-CuPgU6f3eT/XgKKPqKd/gLZV1Xmvf1a2R5POBOGQa6uv82xpls89HU5zKeVoyR8XzHd1RGNOlQlvUe3CFkjWNQ== +"@types/estree@^1.0.0": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.1.tgz#aa22750962f3bf0e79d753d3cc067f010c95f194" + integrity sha512-LG4opVs2ANWZ1TJoKc937iMmNstM/d0ae1vNbnBvBhqCSezgVUOzcLCqbI5elV8Vy6WKwKjaqR+zO9VKirBBCA== "@types/json-schema@*", "@types/json-schema@^7.0.8": version "7.0.9" @@ -219,160 +151,141 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.13.tgz#5ed7ed7c662948335fcad6c412bb42d99ea754e3" integrity sha512-Y86MAxASe25hNzlDbsviXl8jQHb0RDvKt4c40ZJQ1Don0AAL0STLZSs4N+6gLEO55pedy7r2cLwS+ZDxPm/2Bw== -"@types/node@^12.12.14": - version "12.20.55" - resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.55.tgz#c329cbd434c42164f846b909bd6f85b5537f6240" - integrity sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ== - -"@types/resolve@1.17.1": - version "1.17.1" - resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-1.17.1.tgz#3afd6ad8967c77e4376c598a82ddd58f46ec45d6" - integrity sha512-yy7HuzQhj0dhGpD8RLXSZWEkLsV9ibvxvi6EiJ3bkqLAO1RGo0WbkWQiwpRlSFymTJRz0d3k5LM3kkx8ArDbLw== +"@webassemblyjs/ast@1.11.6", "@webassemblyjs/ast@^1.11.5": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.11.6.tgz#db046555d3c413f8966ca50a95176a0e2c642e24" + integrity sha512-IN1xI7PwOvLPgjcf180gC1bqn3q/QaOCwYUahIOhbYUu8KA/3tw2RT/T0Gidi1l7Hhj5D/INhJxiICObqpMu4Q== dependencies: - "@types/node" "*" + "@webassemblyjs/helper-numbers" "1.11.6" + "@webassemblyjs/helper-wasm-bytecode" "1.11.6" -"@ungap/promise-all-settled@1.1.2": - version "1.1.2" - resolved "https://registry.yarnpkg.com/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz#aa58042711d6e3275dd37dc597e5d31e8c290a44" - integrity sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q== - -"@webassemblyjs/ast@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.11.1.tgz#2bfd767eae1a6996f432ff7e8d7fc75679c0b6a7" - integrity sha512-ukBh14qFLjxTQNTXocdyksN5QdM28S1CxHt2rdskFyL+xFV7VremuBLVbmCePj+URalXBENx/9Lm7lnhihtCSw== - dependencies: - "@webassemblyjs/helper-numbers" "1.11.1" - "@webassemblyjs/helper-wasm-bytecode" "1.11.1" - -"@webassemblyjs/floating-point-hex-parser@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.11.1.tgz#f6c61a705f0fd7a6aecaa4e8198f23d9dc179e4f" - integrity sha512-iGRfyc5Bq+NnNuX8b5hwBrRjzf0ocrJPI6GWFodBFzmFnyvrQ83SHKhmilCU/8Jv67i4GJZBMhEzltxzcNagtQ== - -"@webassemblyjs/helper-api-error@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-api-error/-/helper-api-error-1.11.1.tgz#1a63192d8788e5c012800ba6a7a46c705288fd16" - integrity sha512-RlhS8CBCXfRUR/cwo2ho9bkheSXG0+NwooXcc3PAILALf2QLdFyj7KGsKRbVc95hZnhnERon4kW/D3SZpp6Tcg== - -"@webassemblyjs/helper-buffer@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.11.1.tgz#832a900eb444884cde9a7cad467f81500f5e5ab5" - integrity sha512-gwikF65aDNeeXa8JxXa2BAk+REjSyhrNC9ZwdT0f8jc4dQQeDQ7G4m0f2QCLPJiMTTO6wfDmRmj/pW0PsUvIcA== - -"@webassemblyjs/helper-numbers@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-numbers/-/helper-numbers-1.11.1.tgz#64d81da219fbbba1e3bd1bfc74f6e8c4e10a62ae" - integrity sha512-vDkbxiB8zfnPdNK9Rajcey5C0w+QJugEglN0of+kmO8l7lDb77AnlKYQF7aarZuCrv+l0UvqL+68gSDr3k9LPQ== - dependencies: - "@webassemblyjs/floating-point-hex-parser" "1.11.1" - "@webassemblyjs/helper-api-error" "1.11.1" +"@webassemblyjs/floating-point-hex-parser@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.11.6.tgz#dacbcb95aff135c8260f77fa3b4c5fea600a6431" + integrity sha512-ejAj9hfRJ2XMsNHk/v6Fu2dGS+i4UaXBXGemOfQ/JfQ6mdQg/WXtwleQRLLS4OvfDhv8rYnVwH27YJLMyYsxhw== + +"@webassemblyjs/helper-api-error@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-api-error/-/helper-api-error-1.11.6.tgz#6132f68c4acd59dcd141c44b18cbebbd9f2fa768" + integrity sha512-o0YkoP4pVu4rN8aTJgAyj9hC2Sv5UlkzCHhxqWj8butaLvnpdc2jOwh4ewE6CX0txSfLn/UYaV/pheS2Txg//Q== + +"@webassemblyjs/helper-buffer@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.11.6.tgz#b66d73c43e296fd5e88006f18524feb0f2c7c093" + integrity sha512-z3nFzdcp1mb8nEOFFk8DrYLpHvhKC3grJD2ardfKOzmbmJvEf/tPIqCY+sNcwZIY8ZD7IkB2l7/pqhUhqm7hLA== + +"@webassemblyjs/helper-numbers@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-numbers/-/helper-numbers-1.11.6.tgz#cbce5e7e0c1bd32cf4905ae444ef64cea919f1b5" + integrity sha512-vUIhZ8LZoIWHBohiEObxVm6hwP034jwmc9kuq5GdHZH0wiLVLIPcMCdpJzG4C11cHoQ25TFIQj9kaVADVX7N3g== + dependencies: + "@webassemblyjs/floating-point-hex-parser" "1.11.6" + "@webassemblyjs/helper-api-error" "1.11.6" "@xtuc/long" "4.2.2" -"@webassemblyjs/helper-wasm-bytecode@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.11.1.tgz#f328241e41e7b199d0b20c18e88429c4433295e1" - integrity sha512-PvpoOGiJwXeTrSf/qfudJhwlvDQxFgelbMqtq52WWiXC6Xgg1IREdngmPN3bs4RoO83PnL/nFrxucXj1+BX62Q== +"@webassemblyjs/helper-wasm-bytecode@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.11.6.tgz#bb2ebdb3b83aa26d9baad4c46d4315283acd51e9" + integrity sha512-sFFHKwcmBprO9e7Icf0+gddyWYDViL8bpPjJJl0WHxCdETktXdmtWLGVzoHbqUcY4Be1LkNfwTmXOJUFZYSJdA== -"@webassemblyjs/helper-wasm-section@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.11.1.tgz#21ee065a7b635f319e738f0dd73bfbda281c097a" - integrity sha512-10P9No29rYX1j7F3EVPX3JvGPQPae+AomuSTPiF9eBQeChHI6iqjMIwR9JmOJXwpnn/oVGDk7I5IlskuMwU/pg== +"@webassemblyjs/helper-wasm-section@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.11.6.tgz#ff97f3863c55ee7f580fd5c41a381e9def4aa577" + integrity sha512-LPpZbSOwTpEC2cgn4hTydySy1Ke+XEu+ETXuoyvuyezHO3Kjdu90KK95Sh9xTbmjrCsUwvWwCOQQNta37VrS9g== dependencies: - "@webassemblyjs/ast" "1.11.1" - "@webassemblyjs/helper-buffer" "1.11.1" - "@webassemblyjs/helper-wasm-bytecode" "1.11.1" - "@webassemblyjs/wasm-gen" "1.11.1" + "@webassemblyjs/ast" "1.11.6" + "@webassemblyjs/helper-buffer" "1.11.6" + "@webassemblyjs/helper-wasm-bytecode" "1.11.6" + "@webassemblyjs/wasm-gen" "1.11.6" -"@webassemblyjs/ieee754@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/ieee754/-/ieee754-1.11.1.tgz#963929e9bbd05709e7e12243a099180812992614" - integrity sha512-hJ87QIPtAMKbFq6CGTkZYJivEwZDbQUgYd3qKSadTNOhVY7p+gfP6Sr0lLRVTaG1JjFj+r3YchoqRYxNH3M0GQ== +"@webassemblyjs/ieee754@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/ieee754/-/ieee754-1.11.6.tgz#bb665c91d0b14fffceb0e38298c329af043c6e3a" + integrity sha512-LM4p2csPNvbij6U1f19v6WR56QZ8JcHg3QIJTlSwzFcmx6WSORicYj6I63f9yU1kEUtrpG+kjkiIAkevHpDXrg== dependencies: "@xtuc/ieee754" "^1.2.0" -"@webassemblyjs/leb128@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/leb128/-/leb128-1.11.1.tgz#ce814b45574e93d76bae1fb2644ab9cdd9527aa5" - integrity sha512-BJ2P0hNZ0u+Th1YZXJpzW6miwqQUGcIHT1G/sf72gLVD9DZ5AdYTqPNbHZh6K1M5VmKvFXwGSWZADz+qBWxeRw== +"@webassemblyjs/leb128@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/leb128/-/leb128-1.11.6.tgz#70e60e5e82f9ac81118bc25381a0b283893240d7" + integrity sha512-m7a0FhE67DQXgouf1tbN5XQcdWoNgaAuoULHIfGFIEVKA6tu/edls6XnIlkmS6FrXAquJRPni3ZZKjw6FSPjPQ== dependencies: "@xtuc/long" "4.2.2" -"@webassemblyjs/utf8@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/utf8/-/utf8-1.11.1.tgz#d1f8b764369e7c6e6bae350e854dec9a59f0a3ff" - integrity sha512-9kqcxAEdMhiwQkHpkNiorZzqpGrodQQ2IGrHHxCy+Ozng0ofyMA0lTqiLkVs1uzTRejX+/O0EOT7KxqVPuXosQ== - -"@webassemblyjs/wasm-edit@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-edit/-/wasm-edit-1.11.1.tgz#ad206ebf4bf95a058ce9880a8c092c5dec8193d6" - integrity sha512-g+RsupUC1aTHfR8CDgnsVRVZFJqdkFHpsHMfJuWQzWU3tvnLC07UqHICfP+4XyL2tnr1amvl1Sdp06TnYCmVkA== - dependencies: - "@webassemblyjs/ast" "1.11.1" - "@webassemblyjs/helper-buffer" "1.11.1" - "@webassemblyjs/helper-wasm-bytecode" "1.11.1" - "@webassemblyjs/helper-wasm-section" "1.11.1" - "@webassemblyjs/wasm-gen" "1.11.1" - "@webassemblyjs/wasm-opt" "1.11.1" - "@webassemblyjs/wasm-parser" "1.11.1" - "@webassemblyjs/wast-printer" "1.11.1" - -"@webassemblyjs/wasm-gen@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-gen/-/wasm-gen-1.11.1.tgz#86c5ea304849759b7d88c47a32f4f039ae3c8f76" - integrity sha512-F7QqKXwwNlMmsulj6+O7r4mmtAlCWfO/0HdgOxSklZfQcDu0TpLiD1mRt/zF25Bk59FIjEuGAIyn5ei4yMfLhA== - dependencies: - "@webassemblyjs/ast" "1.11.1" - "@webassemblyjs/helper-wasm-bytecode" "1.11.1" - "@webassemblyjs/ieee754" "1.11.1" - "@webassemblyjs/leb128" "1.11.1" - "@webassemblyjs/utf8" "1.11.1" - -"@webassemblyjs/wasm-opt@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-opt/-/wasm-opt-1.11.1.tgz#657b4c2202f4cf3b345f8a4c6461c8c2418985f2" - integrity sha512-VqnkNqnZlU5EB64pp1l7hdm3hmQw7Vgqa0KF/KCNO9sIpI6Fk6brDEiX+iCOYrvMuBWDws0NkTOxYEb85XQHHw== - dependencies: - "@webassemblyjs/ast" "1.11.1" - "@webassemblyjs/helper-buffer" "1.11.1" - "@webassemblyjs/wasm-gen" "1.11.1" - "@webassemblyjs/wasm-parser" "1.11.1" - -"@webassemblyjs/wasm-parser@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.11.1.tgz#86ca734534f417e9bd3c67c7a1c75d8be41fb199" - integrity sha512-rrBujw+dJu32gYB7/Lup6UhdkPx9S9SnobZzRVL7VcBH9Bt9bCBLEuX/YXOOtBsOZ4NQrRykKhffRWHvigQvOA== - dependencies: - "@webassemblyjs/ast" "1.11.1" - "@webassemblyjs/helper-api-error" "1.11.1" - "@webassemblyjs/helper-wasm-bytecode" "1.11.1" - "@webassemblyjs/ieee754" "1.11.1" - "@webassemblyjs/leb128" "1.11.1" - "@webassemblyjs/utf8" "1.11.1" - -"@webassemblyjs/wast-printer@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-printer/-/wast-printer-1.11.1.tgz#d0c73beda8eec5426f10ae8ef55cee5e7084c2f0" - integrity sha512-IQboUWM4eKzWW+N/jij2sRatKMh99QEelo3Eb2q0qXkvPRISAj8Qxtmw5itwqK+TTkBuUIE45AxYPToqPtL5gg== - dependencies: - "@webassemblyjs/ast" "1.11.1" +"@webassemblyjs/utf8@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/utf8/-/utf8-1.11.6.tgz#90f8bc34c561595fe156603be7253cdbcd0fab5a" + integrity sha512-vtXf2wTQ3+up9Zsg8sa2yWiQpzSsMyXj0qViVP6xKGCUT8p8YJ6HqI7l5eCnWx1T/FYdsv07HQs2wTFbbof/RA== + +"@webassemblyjs/wasm-edit@^1.11.5": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-edit/-/wasm-edit-1.11.6.tgz#c72fa8220524c9b416249f3d94c2958dfe70ceab" + integrity sha512-Ybn2I6fnfIGuCR+Faaz7YcvtBKxvoLV3Lebn1tM4o/IAJzmi9AWYIPWpyBfU8cC+JxAO57bk4+zdsTjJR+VTOw== + dependencies: + "@webassemblyjs/ast" "1.11.6" + "@webassemblyjs/helper-buffer" "1.11.6" + "@webassemblyjs/helper-wasm-bytecode" "1.11.6" + "@webassemblyjs/helper-wasm-section" "1.11.6" + "@webassemblyjs/wasm-gen" "1.11.6" + "@webassemblyjs/wasm-opt" "1.11.6" + "@webassemblyjs/wasm-parser" "1.11.6" + "@webassemblyjs/wast-printer" "1.11.6" + +"@webassemblyjs/wasm-gen@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-gen/-/wasm-gen-1.11.6.tgz#fb5283e0e8b4551cc4e9c3c0d7184a65faf7c268" + integrity sha512-3XOqkZP/y6B4F0PBAXvI1/bky7GryoogUtfwExeP/v7Nzwo1QLcq5oQmpKlftZLbT+ERUOAZVQjuNVak6UXjPA== + dependencies: + "@webassemblyjs/ast" "1.11.6" + "@webassemblyjs/helper-wasm-bytecode" "1.11.6" + "@webassemblyjs/ieee754" "1.11.6" + "@webassemblyjs/leb128" "1.11.6" + "@webassemblyjs/utf8" "1.11.6" + +"@webassemblyjs/wasm-opt@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-opt/-/wasm-opt-1.11.6.tgz#d9a22d651248422ca498b09aa3232a81041487c2" + integrity sha512-cOrKuLRE7PCe6AsOVl7WasYf3wbSo4CeOk6PkrjS7g57MFfVUF9u6ysQBBODX0LdgSvQqRiGz3CXvIDKcPNy4g== + dependencies: + "@webassemblyjs/ast" "1.11.6" + "@webassemblyjs/helper-buffer" "1.11.6" + "@webassemblyjs/wasm-gen" "1.11.6" + "@webassemblyjs/wasm-parser" "1.11.6" + +"@webassemblyjs/wasm-parser@1.11.6", "@webassemblyjs/wasm-parser@^1.11.5": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.11.6.tgz#bb85378c527df824004812bbdb784eea539174a1" + integrity sha512-6ZwPeGzMJM3Dqp3hCsLgESxBGtT/OeCvCZ4TA1JUPYgmhAx38tTPR9JaKy0S5H3evQpO/h2uWs2j6Yc/fjkpTQ== + dependencies: + "@webassemblyjs/ast" "1.11.6" + "@webassemblyjs/helper-api-error" "1.11.6" + "@webassemblyjs/helper-wasm-bytecode" "1.11.6" + "@webassemblyjs/ieee754" "1.11.6" + "@webassemblyjs/leb128" "1.11.6" + "@webassemblyjs/utf8" "1.11.6" + +"@webassemblyjs/wast-printer@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-printer/-/wast-printer-1.11.6.tgz#a7bf8dd7e362aeb1668ff43f35cb849f188eff20" + integrity sha512-JM7AhRcE+yW2GWYaKeHL5vt4xqee5N2WcezptmgyhNS+ScggqcT1OtXykhAb13Sn5Yas0j2uv9tHgrjwvzAP4A== + dependencies: + "@webassemblyjs/ast" "1.11.6" "@xtuc/long" "4.2.2" -"@webpack-cli/configtest@^1.2.0": - version "1.2.0" - resolved "https://registry.yarnpkg.com/@webpack-cli/configtest/-/configtest-1.2.0.tgz#7b20ce1c12533912c3b217ea68262365fa29a6f5" - integrity sha512-4FB8Tj6xyVkyqjj1OaTqCjXYULB9FMkqQ8yGrZjRDrYh0nOE+7Lhs45WioWQQMV+ceFlE368Ukhe6xdvJM9Egg== +"@webpack-cli/configtest@^2.1.0": + version "2.1.1" + resolved "https://registry.yarnpkg.com/@webpack-cli/configtest/-/configtest-2.1.1.tgz#3b2f852e91dac6e3b85fb2a314fb8bef46d94646" + integrity sha512-wy0mglZpDSiSS0XHrVR+BAdId2+yxPSoJW8fsna3ZpYSlufjvxnP4YbKTCBZnNIcGN4r6ZPXV55X4mYExOfLmw== -"@webpack-cli/info@^1.5.0": - version "1.5.0" - resolved "https://registry.yarnpkg.com/@webpack-cli/info/-/info-1.5.0.tgz#6c78c13c5874852d6e2dd17f08a41f3fe4c261b1" - integrity sha512-e8tSXZpw2hPl2uMJY6fsMswaok5FdlGNRTktvFk2sD8RjH0hE2+XistawJx1vmKteh4NmGmNUrp+Tb2w+udPcQ== - dependencies: - envinfo "^7.7.3" +"@webpack-cli/info@^2.0.1": + version "2.0.2" + resolved "https://registry.yarnpkg.com/@webpack-cli/info/-/info-2.0.2.tgz#cc3fbf22efeb88ff62310cf885c5b09f44ae0fdd" + integrity sha512-zLHQdI/Qs1UyT5UBdWNqsARasIA+AaF8t+4u2aS2nEpBQh2mWIVb8qAklq0eUENnC5mOItrIB4LiS9xMtph18A== -"@webpack-cli/serve@^1.7.0": - version "1.7.0" - resolved "https://registry.yarnpkg.com/@webpack-cli/serve/-/serve-1.7.0.tgz#e1993689ac42d2b16e9194376cfb6753f6254db1" - integrity sha512-oxnCNGj88fL+xzV+dacXs44HcDwf1ovs3AuEzvP7mqXw7fQntqIhQ1BRmynh4qEKQSSSRSWVyXRjmTbZIX9V2Q== +"@webpack-cli/serve@^2.0.3": + version "2.0.5" + resolved "https://registry.yarnpkg.com/@webpack-cli/serve/-/serve-2.0.5.tgz#325db42395cd49fe6c14057f9a900e427df8810e" + integrity sha512-lqaoKnRYBdo1UgDX8uF24AfGMifWK19TxPmM5FHc2vAGxrJ/qtyUyFBWoY1tISZdelsQ5fBcOusifo5o5wSJxQ== "@xtuc/ieee754@^1.2.0": version "1.2.0" @@ -456,13 +369,6 @@ ansi-regex@^5.0.1: resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304" integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ== -ansi-styles@^3.2.1: - version "3.2.1" - resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d" - integrity sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA== - dependencies: - color-convert "^1.9.0" - ansi-styles@^4.0.0, ansi-styles@^4.1.0: version "4.3.0" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.3.0.tgz#edd803628ae71c04c85ae7a0906edad34b648937" @@ -483,11 +389,6 @@ argparse@^2.0.1: resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38" integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q== -atob@^2.1.2: - version "2.1.2" - resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9" - integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg== - balanced-match@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" @@ -571,11 +472,6 @@ buffer-from@^1.0.0: resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.2.tgz#2b146a6fd72e80b4f55d255f35ed59a3a9a41bd5" integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ== -builtin-modules@^3.3.0: - version "3.3.0" - resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-3.3.0.tgz#cae62812b89801e9656336e46223e030386be7b6" - integrity sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw== - bytes@3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.1.tgz#3f018291cb4cbad9accb6e6970bca9c8889e879a" @@ -591,15 +487,6 @@ caniuse-lite@^1.0.30001286: resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001303.tgz#9b168e4f43ccfc372b86f4bc5a551d9b909c95c9" integrity sha512-/Mqc1oESndUNszJP0kx0UaQU9kEv9nNtJ7Kn8AdA0mNnH8eR1cj0kG+NbNuC1Wq/b21eA8prhKRA3bbkjONegQ== -chalk@^2.0.0: - version "2.4.2" - resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" - integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== - dependencies: - ansi-styles "^3.2.1" - escape-string-regexp "^1.0.5" - supports-color "^5.3.0" - chalk@^4.1.0: version "4.1.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01" @@ -646,13 +533,6 @@ clone-deep@^4.0.1: kind-of "^6.0.2" shallow-clone "^3.0.0" -color-convert@^1.9.0: - version "1.9.3" - resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8" - integrity sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg== - dependencies: - color-name "1.1.3" - color-convert@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3" @@ -660,11 +540,6 @@ color-convert@^2.0.1: dependencies: color-name "~1.1.4" -color-name@1.1.3: - version "1.1.3" - resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25" - integrity sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw== - color-name@~1.1.4: version "1.1.4" resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" @@ -675,21 +550,16 @@ colorette@^2.0.14: resolved "https://registry.yarnpkg.com/colorette/-/colorette-2.0.16.tgz#713b9af84fdb000139f04546bd4a93f62a5085da" integrity sha512-hUewv7oMjCp+wkBv5Rm0v87eJhq4woh5rSR+42YSQJKecCqgIqNkZ6lAlQms/BwHPJA5NKMRlpxPRv0n8HQW6g== +commander@^10.0.1: + version "10.0.1" + resolved "https://registry.yarnpkg.com/commander/-/commander-10.0.1.tgz#881ee46b4f77d1c1dccc5823433aa39b022cbe06" + integrity sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug== + commander@^2.20.0: version "2.20.3" resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ== -commander@^7.0.0: - version "7.2.0" - resolved "https://registry.yarnpkg.com/commander/-/commander-7.2.0.tgz#a36cb57d0b501ce108e4d20559a150a391d97ab7" - integrity sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw== - -commondir@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b" - integrity sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg== - concat-map@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" @@ -787,16 +657,6 @@ decamelize@^4.0.0: resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-4.0.0.tgz#aa472d7bf660eb15f3494efd531cab7f2a709837" integrity sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ== -decode-uri-component@^0.2.0: - version "0.2.2" - resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.2.tgz#e69dbe25d37941171dd540e024c444cd5188e1e9" - integrity sha512-FqUYQ+8o158GyGTrMFJms9qh3CqTKvAqgqsTnkLI8sKu0028orqBhxNMFkFen0zGyg6epACD32pjVk58ngIErQ== - -deepmerge@^4.2.2: - version "4.3.1" - resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-4.3.1.tgz#44b5f2147cd3b00d4b56137685966f26fd25dd4a" - integrity sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A== - depd@~1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.2.tgz#9bcd52e14c097763e749b274c4346ed2e560b5a9" @@ -863,10 +723,10 @@ engine.io@~6.4.1: engine.io-parser "~5.0.3" ws "~8.11.0" -enhanced-resolve@^5.10.0: - version "5.12.0" - resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.12.0.tgz#300e1c90228f5b570c4d35babf263f6da7155634" - integrity sha512-QHTXI/sZQmko1cbDoNAa3mJ5qhWUUNAq3vR0/YiD379fWQrcfuoX1+HW2S0MTt7XmoPLapdaDKUtelUSPic7hQ== +enhanced-resolve@^5.13.0: + version "5.15.0" + resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.15.0.tgz#1af946c7d93603eb88e9896cee4904dc012e9c35" + integrity sha512-LXYT42KJ7lpIKECr2mAXIaMldcNCh/7E0KBKOu4KSfkHmP+mZmSs+8V5gBAqisWBy0OO4W5Oyys0GO1Y8KtdKg== dependencies: graceful-fs "^4.2.4" tapable "^2.2.0" @@ -881,10 +741,10 @@ envinfo@^7.7.3: resolved "https://registry.yarnpkg.com/envinfo/-/envinfo-7.8.1.tgz#06377e3e5f4d379fea7ac592d5ad8927e0c4d475" integrity sha512-/o+BXHmB7ocbHEAs6F2EnG0ogybVVUdkRunTT2glZU9XAaGmhqskrvKwqXuDfNjEO0LZKWdejEEpnq8aM0tOaw== -es-module-lexer@^0.9.0: - version "0.9.3" - resolved "https://registry.yarnpkg.com/es-module-lexer/-/es-module-lexer-0.9.3.tgz#6f13db00cc38417137daf74366f535c8eb438f19" - integrity sha512-1HQ2M2sPtxwnvOvT1ZClHyQDiggdNjURWpY2we6aMKCQiUVxTmVs2UYPLIrD84sS+kMdUwfBSylbJPwNnBrnHQ== +es-module-lexer@^1.2.1: + version "1.3.0" + resolved "https://registry.yarnpkg.com/es-module-lexer/-/es-module-lexer-1.3.0.tgz#6be9c9e0b4543a60cd166ff6f8b4e9dae0b0c16f" + integrity sha512-vZK7T0N2CBmBOixhmjdqx2gWVbFZ4DXZ/NyRMZVlJXPa7CyFS+/a4QQsDGDQy9ZfEzxFuNEsMLeQJnKP2p5/JA== escalade@^3.1.1: version "3.1.1" @@ -901,11 +761,6 @@ escape-string-regexp@4.0.0: resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34" integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA== -escape-string-regexp@^1.0.5: - version "1.0.5" - resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" - integrity sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg== - eslint-scope@5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c" @@ -931,16 +786,6 @@ estraverse@^5.2.0: resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-5.3.0.tgz#2eea5290702f26ab8fe5370370ff86c965d21123" integrity sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA== -estree-walker@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-1.0.1.tgz#31bc5d612c96b704106b477e6dd5d8aa138cb700" - integrity sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg== - -estree-walker@^2.0.1: - version "2.0.2" - resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-2.0.2.tgz#52f010178c2a4c117a7757cfe942adb7d2da4cac" - integrity sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w== - eventemitter3@^4.0.0: version "4.0.7" resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f" @@ -1022,7 +867,7 @@ follow-redirects@^1.0.0: resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.7.tgz#2004c02eb9436eee9a21446a6477debf17e81685" integrity sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ== -format-util@1.0.5, format-util@^1.0.5: +format-util@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/format-util/-/format-util-1.0.5.tgz#1ffb450c8a03e7bccffe40643180918cc297d271" integrity sha512-varLbTj0e0yVyRpqQhuWV+8hlePAgaoFRhNFj50BNjEIrw1/DphHSObtqwskVCPWNgzwPoQrZAbfa/SBiicNeg== @@ -1080,33 +925,21 @@ glob@7.2.0, glob@^7.1.3, glob@^7.1.7: once "^1.3.0" path-is-absolute "^1.0.0" -glob@^7.1.6: - version "7.2.3" - resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.3.tgz#b8df0fb802bbfa8e89bd1d938b4e16578ed44f2b" - integrity sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q== - dependencies: - fs.realpath "^1.0.0" - inflight "^1.0.4" - inherits "2" - minimatch "^3.1.1" - once "^1.3.0" - path-is-absolute "^1.0.0" - graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.4, graceful-fs@^4.2.6: version "4.2.9" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.9.tgz#041b05df45755e587a24942279b9d113146e1c96" integrity sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ== +graceful-fs@^4.2.10: + version "4.2.11" + resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3" + integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ== + graceful-fs@^4.2.9: version "4.2.10" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.10.tgz#147d3a006da4ca3ce14728c7aefc287c367d7a6c" integrity sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA== -has-flag@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd" - integrity sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw== - has-flag@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b" @@ -1184,10 +1017,10 @@ inherits@2, inherits@2.0.4: resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== -interpret@^2.2.0: - version "2.2.0" - resolved "https://registry.yarnpkg.com/interpret/-/interpret-2.2.0.tgz#1a78a0b5965c40a5416d007ad6f50ad27c417df9" - integrity sha512-Ju0Bz/cEia55xDwUWEa8+olFpCiQoypjnQySseKtmjNrnps3P+xfpUmGr90T7yjlVJmOtybRvPXhKMbHr+fWnw== +interpret@^3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/interpret/-/interpret-3.1.1.tgz#5be0ceed67ca79c6c4bc5cf0d7ee843dcea110c4" + integrity sha512-6xwYfHbajpoF0xLW+iwLkhwgvLoZDfjYfoFNu8ftMoXINzwuymNLd9u/KmwtdT2GbR+/Cz66otEGEVVUHX9QLQ== is-alphabetical@^2.0.0: version "2.0.1" @@ -1209,13 +1042,6 @@ is-binary-path@~2.1.0: dependencies: binary-extensions "^2.0.0" -is-builtin-module@^3.1.0: - version "3.2.1" - resolved "https://registry.yarnpkg.com/is-builtin-module/-/is-builtin-module-3.2.1.tgz#f03271717d8654cfcaf07ab0463faa3571581169" - integrity sha512-BSLE3HnV2syZ0FK0iMA/yUGplUeMmNz4AW5fnTunbCIqZi4vG3WjJT9FHMy5D69xmAYBHXQhJdALdpwVxV501A== - dependencies: - builtin-modules "^3.3.0" - is-core-module@^2.11.0: version "2.12.1" resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.12.1.tgz#0c0b6885b6f80011c71541ce15c8d66cf5a4f9fd" @@ -1223,23 +1049,11 @@ is-core-module@^2.11.0: dependencies: has "^1.0.3" -is-core-module@^2.8.1: - version "2.8.1" - resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.8.1.tgz#f59fdfca701d5879d0a6b100a40aa1560ce27211" - integrity sha512-SdNCUs284hr40hFTFP6l0IfZ/RSrMXF3qgoRHd3/79unUTvrFO/JoXwkGm+5J/Oe3E/b5GsnG330uUNgRpu1PA== - dependencies: - has "^1.0.3" - is-decimal@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/is-decimal/-/is-decimal-2.0.1.tgz#9469d2dc190d0214fd87d78b78caecc0cc14eef7" integrity sha512-AAB9hiomQs5DXWcRB1rqsxGUstbRroFOPPVAomNk/3XHR5JyEZChOyTWe2oayKnsSsr/kcGqF+z6yuH6HHpN0A== -is-docker@^2.0.0: - version "2.2.1" - resolved "https://registry.yarnpkg.com/is-docker/-/is-docker-2.2.1.tgz#33eeabe23cfe86f14bde4408a02c0cfb853acdaa" - integrity sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ== - is-extglob@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2" @@ -1257,11 +1071,6 @@ is-glob@^4.0.1, is-glob@~4.0.1: dependencies: is-extglob "^2.1.1" -is-module@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/is-module/-/is-module-1.0.0.tgz#3258fb69f78c14d5b815d664336b4cffb6441591" - integrity sha512-51ypPSPCoTEIN9dy5Oy+h4pShgJmPCygKfyRCISBI+JoWT/2oJvK8QPxmwv7b/p239jXrm9M1mlQbyKJ5A152g== - is-number@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/is-number/-/is-number-7.0.0.tgz#7535345b896734d5f80c4d06c50955527a14f12b" @@ -1279,25 +1088,11 @@ is-plain-object@^2.0.4: dependencies: isobject "^3.0.1" -is-reference@^1.2.1: - version "1.2.1" - resolved "https://registry.yarnpkg.com/is-reference/-/is-reference-1.2.1.tgz#8b2dac0b371f4bc994fdeaba9eb542d03002d0b7" - integrity sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ== - dependencies: - "@types/estree" "*" - is-unicode-supported@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz#3f26c76a809593b52bfa2ecb5710ed2779b522a7" integrity sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw== -is-wsl@^2.2.0: - version "2.2.0" - resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-2.2.0.tgz#74a4c76e77ca9fd3f932f290c17ea326cd157271" - integrity sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww== - dependencies: - is-docker "^2.0.0" - isbinaryfile@^4.0.8: version "4.0.8" resolved "https://registry.yarnpkg.com/isbinaryfile/-/isbinaryfile-4.0.8.tgz#5d34b94865bd4946633ecc78a026fc76c5b11fcf" @@ -1313,29 +1108,15 @@ isobject@^3.0.1: resolved "https://registry.yarnpkg.com/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df" integrity sha1-TkMekrEalzFjaqH5yNHMvP2reN8= -jest-worker@^26.2.1: - version "26.6.2" - resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-26.6.2.tgz#7f72cbc4d643c365e27b9fd775f9d0eaa9c7a8ed" - integrity sha512-KWYVV1c4i+jbMpaBC+U++4Va0cp8OisU185o73T1vo99hqi7w8tSJfUXYswwqqrjzwxa6KpRK54WhPvwf5w6PQ== - dependencies: - "@types/node" "*" - merge-stream "^2.0.0" - supports-color "^7.0.0" - -jest-worker@^27.4.1: - version "27.4.6" - resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-27.4.6.tgz#5d2d93db419566cb680752ca0792780e71b3273e" - integrity sha512-gHWJF/6Xi5CTG5QCvROr6GcmpIqNYpDJyc8A1h/DyXqH1tD6SnRCM0d3U5msV31D2LB/U+E0M+W4oyvKV44oNw== +jest-worker@^27.4.5: + version "27.5.1" + resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-27.5.1.tgz#8d146f0900e8973b106b6f73cc1e9a8cb86f8db0" + integrity sha512-7vuh85V5cdDofPyxn58nrPjBktZo0u9x1g8WtjQol+jZDaE+fhN+cIvTj11GndBnMnyfrUOG1sZQxCdjKh+DKg== dependencies: "@types/node" "*" merge-stream "^2.0.0" supports-color "^8.0.0" -js-tokens@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" - integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ== - js-yaml@4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.0.tgz#c1fb65f8f5017901cdd2c951864ba18458a10602" @@ -1365,10 +1146,10 @@ jsonfile@^4.0.0: optionalDependencies: graceful-fs "^4.1.6" -karma-chrome-launcher@3.1.1: - version "3.1.1" - resolved "https://registry.yarnpkg.com/karma-chrome-launcher/-/karma-chrome-launcher-3.1.1.tgz#baca9cc071b1562a1db241827257bfe5cab597ea" - integrity sha512-hsIglcq1vtboGPAN+DGCISCFOxW+ZVnIqhDQcCMqqCp+4dmJ0Qpq5QAjkbA0X2L9Mi6OBkHi2Srrbmm7pUKkzQ== +karma-chrome-launcher@3.2.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/karma-chrome-launcher/-/karma-chrome-launcher-3.2.0.tgz#eb9c95024f2d6dfbb3748d3415ac9b381906b9a9" + integrity sha512-rE9RkUPI7I9mAxByQWkGJFXfFD6lE4gC5nPuZdobf/QdTEJI6EU4yIay/cfU/xV4ZxlM5JiTv7zWYgA64NpS5Q== dependencies: which "^1.2.1" @@ -1379,12 +1160,12 @@ karma-mocha@2.0.1: dependencies: minimist "^1.2.3" -karma-sourcemap-loader@0.3.8: - version "0.3.8" - resolved "https://registry.yarnpkg.com/karma-sourcemap-loader/-/karma-sourcemap-loader-0.3.8.tgz#d4bae72fb7a8397328a62b75013d2df937bdcf9c" - integrity sha512-zorxyAakYZuBcHRJE+vbrK2o2JXLFWK8VVjiT/6P+ltLBUGUvqTEkUiQ119MGdOrK7mrmxXHZF1/pfT6GgIZ6g== +karma-sourcemap-loader@0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/karma-sourcemap-loader/-/karma-sourcemap-loader-0.4.0.tgz#b01d73f8f688f533bcc8f5d273d43458e13b5488" + integrity sha512-xCRL3/pmhAYF3I6qOrcn0uhbQevitc2DERMPH82FMnG+4WReoGcGFZb1pURf2a5apyrOHRdvD+O6K7NljqKHyA== dependencies: - graceful-fs "^4.1.2" + graceful-fs "^4.2.10" karma-webpack@5.0.0: version "5.0.0" @@ -1395,10 +1176,10 @@ karma-webpack@5.0.0: minimatch "^3.0.4" webpack-merge "^4.1.5" -karma@6.4.0: - version "6.4.0" - resolved "https://registry.yarnpkg.com/karma/-/karma-6.4.0.tgz#82652dfecdd853ec227b74ed718a997028a99508" - integrity sha512-s8m7z0IF5g/bS5ONT7wsOavhW4i4aFkzD4u4wgzAQWT4HGUeWI3i21cK2Yz6jndMAeHETp5XuNsRoyGJZXVd4w== +karma@6.4.2: + version "6.4.2" + resolved "https://registry.yarnpkg.com/karma/-/karma-6.4.2.tgz#a983f874cee6f35990c4b2dcc3d274653714de8e" + integrity sha512-C6SU/53LB31BEgRg+omznBEMY4SjHU3ricV6zBcAe1EeILKkeScr+fZXtaI5WyDbkVowJxxAI6h73NcFPmXolQ== dependencies: "@colors/colors" "1.5.0" body-parser "^1.19.0" @@ -1480,13 +1261,6 @@ lru-cache@^6.0.0: dependencies: yallist "^4.0.0" -magic-string@^0.25.7: - version "0.25.9" - resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.25.9.tgz#de7f9faf91ef8a1c91d02c2e5314c8277dbcdd1c" - integrity sha512-RmF0AsMzgt25qzqqLc1+MbHmhdx0ojF2Fvs4XnOqz2ZOBXzzkEwc/dJQZCYHAn7v1jbVOjAZfK8msRn4BxO4VQ== - dependencies: - sourcemap-codec "^1.4.8" - make-plural@^7.0.0: version "7.2.0" resolved "https://registry.yarnpkg.com/make-plural/-/make-plural-7.2.0.tgz#93174b1419672a48a2340db6c1d3fb217530c684" @@ -1540,13 +1314,6 @@ minimatch@^3.0.4: dependencies: brace-expansion "^1.1.7" -minimatch@^3.1.1: - version "3.1.2" - resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b" - integrity sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw== - dependencies: - brace-expansion "^1.1.7" - minimist@^1.2.3: version "1.2.5" resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602" @@ -1564,12 +1331,11 @@ mkdirp@^0.5.5: dependencies: minimist "^1.2.6" -mocha@10.0.0: - version "10.0.0" - resolved "https://registry.yarnpkg.com/mocha/-/mocha-10.0.0.tgz#205447d8993ec755335c4b13deba3d3a13c4def9" - integrity sha512-0Wl+elVUD43Y0BqPZBzZt8Tnkw9CMUdNYnUsTfOM1vuhJVZL+kiesFYsqwBkEEuEixaiPe5ZQdqDgX2jddhmoA== +mocha@10.2.0: + version "10.2.0" + resolved "https://registry.yarnpkg.com/mocha/-/mocha-10.2.0.tgz#1fd4a7c32ba5ac372e03a17eef435bd00e5c68b8" + integrity sha512-IDY7fl/BecMwFHzoqF2sg/SHHANeBoMMXFlS9r0OXKDssYE1M5O43wUY/9BVPeIvfH2zmEbBfseqN9gBQZzXkg== dependencies: - "@ungap/promise-all-settled" "1.1.2" ansi-colors "4.1.1" browser-stdout "1.3.1" chokidar "3.5.3" @@ -1724,7 +1490,7 @@ picocolors@^1.0.0: resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c" integrity sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ== -picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.2.2: +picomatch@^2.0.4, picomatch@^2.2.1: version "2.3.1" resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42" integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA== @@ -1830,12 +1596,12 @@ readdirp@~3.6.0: dependencies: picomatch "^2.2.1" -rechoir@^0.7.0: - version "0.7.1" - resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.7.1.tgz#9478a96a1ca135b5e88fc027f03ee92d6c645686" - integrity sha512-/njmZ8s1wVeR6pjTZ+0nCnv8SpZNRMT2D1RLOJQESlYFDBvwpTA4KWJpZ+sBJ4+vhjILRcK7JIFdGCdxEAAitg== +rechoir@^0.8.0: + version "0.8.0" + resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.8.0.tgz#49f866e0d32146142da3ad8f0eff352b3215ff22" + integrity sha512-/vxpCXddiX8NGfGO/mTafwjq4aFa/71pvamip0++IQk3zG8cbCj0fifNPrjjF1XMXUne91jL9OoxmdykoEtifQ== dependencies: - resolve "^1.9.0" + resolve "^1.20.0" require-directory@^2.1.1: version "2.1.1" @@ -1864,7 +1630,7 @@ resolve-from@^5.0.0: resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-5.0.0.tgz#c35225843df8f776df21c57557bc087e9dfdfc69" integrity sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw== -resolve@^1.17.0, resolve@^1.19.0: +resolve@^1.20.0: version "1.22.2" resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.2.tgz#0ed0943d4e301867955766c9f3e1ae6d01c6845f" integrity sha512-Sb+mjNHOULsBv818T40qSPeRiuWLyaGMa5ewydRLFimneixmVy2zdivRl+AF6jaYPC8ERxGDmFSiqui6SfPd+g== @@ -1873,15 +1639,6 @@ resolve@^1.17.0, resolve@^1.19.0: path-parse "^1.0.7" supports-preserve-symlinks-flag "^1.0.0" -resolve@^1.9.0: - version "1.22.0" - resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.0.tgz#5e0b8c67c15df57a89bdbabe603a002f21731198" - integrity sha512-Hhtrw0nLeSrFQ7phPp4OOcVjLPIeMnRlr5mcnVuMe7M/7eBn98A3hmFRLoFo3DLZkivSYwhRUJTyPyWAk56WLw== - dependencies: - is-core-module "^2.8.1" - path-parse "^1.0.7" - supports-preserve-symlinks-flag "^1.0.0" - rfdc@^1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/rfdc/-/rfdc-1.3.0.tgz#d0b7c441ab2720d05dc4cf26e01c89631d9da08b" @@ -1894,31 +1651,6 @@ rimraf@^3.0.0, rimraf@^3.0.2: dependencies: glob "^7.1.3" -rollup-plugin-sourcemaps@^0.6.3: - version "0.6.3" - resolved "https://registry.yarnpkg.com/rollup-plugin-sourcemaps/-/rollup-plugin-sourcemaps-0.6.3.tgz#bf93913ffe056e414419607f1d02780d7ece84ed" - integrity sha512-paFu+nT1xvuO1tPFYXGe+XnQvg4Hjqv/eIhG8i5EspfYYPBKL57X7iVbfv55aNVASg3dzWvES9dmWsL2KhfByw== - dependencies: - "@rollup/pluginutils" "^3.0.9" - source-map-resolve "^0.6.0" - -rollup-plugin-terser@^7.0.2: - version "7.0.2" - resolved "https://registry.yarnpkg.com/rollup-plugin-terser/-/rollup-plugin-terser-7.0.2.tgz#e8fbba4869981b2dc35ae7e8a502d5c6c04d324d" - integrity sha512-w3iIaU4OxcF52UUXiZNsNeuXIMDvFrr+ZXK6bFZ0Q60qyVfq4uLptoS4bbq3paG3x216eQllFZX7zt6TIImguQ== - dependencies: - "@babel/code-frame" "^7.10.4" - jest-worker "^26.2.1" - serialize-javascript "^4.0.0" - terser "^5.0.0" - -rollup@^2.68.0: - version "2.79.1" - resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.79.1.tgz#bedee8faef7c9f93a2647ac0108748f497f081c7" - integrity sha512-uKxbd0IhMZOhjAiD5oAFp7BqvkA4Dv47qpOCtaNvng4HBwdbWtdOh8f5nZNuk2rp51PMGk3bzfWu5oayNEuYnw== - optionalDependencies: - fsevents "~2.3.2" - safe-buffer@^5.1.0: version "5.2.1" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6" @@ -1934,7 +1666,7 @@ safe-identifier@^0.4.1: resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== -schema-utils@^3.1.0, schema-utils@^3.1.1: +schema-utils@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-3.1.1.tgz#bc74c4b6b6995c1d88f76a8b77bea7219e0c8281" integrity sha512-Y5PQxS4ITlC+EahLuXaY86TXfR7Dc5lw294alXOq86JAHCihAIZfqv8nNCWvaEJvaC51uN9hbLGeV0cFBdH+Fw== @@ -1943,6 +1675,15 @@ schema-utils@^3.1.0, schema-utils@^3.1.1: ajv "^6.12.5" ajv-keywords "^3.5.2" +schema-utils@^3.1.2: + version "3.3.0" + resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-3.3.0.tgz#f50a88877c3c01652a15b622ae9e9795df7a60fe" + integrity sha512-pN/yOAvcC+5rQ5nERGuwrjLlYvLTbCibnZ1I7B1LaiAz9BRBlE9GMgE/eqV30P7aJQUf7Ddimy/RsbYO/GrVGg== + dependencies: + "@types/json-schema" "^7.0.8" + ajv "^6.12.5" + ajv-keywords "^3.5.2" + schema-utils@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-4.0.0.tgz#60331e9e3ae78ec5d16353c467c34b3a0a1d3df7" @@ -1960,17 +1701,17 @@ semver@^7.3.8: dependencies: lru-cache "^6.0.0" -serialize-javascript@6.0.0, serialize-javascript@^6.0.0: +serialize-javascript@6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-6.0.0.tgz#efae5d88f45d7924141da8b5c3a7a7e663fefeb8" integrity sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag== dependencies: randombytes "^2.1.0" -serialize-javascript@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-4.0.0.tgz#b525e1238489a5ecfc42afacc3fe99e666f4b1aa" - integrity sha512-GaNA54380uFefWghODBWEGisLZFj00nS5ACs6yHa9nLqlLpVLO8ChDGeKRjZnV4Nh4n0Qi7nhYZD/9fCPzEqkw== +serialize-javascript@^6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-6.0.1.tgz#b206efb27c3da0b0ab6b52f48d170b7996458e5c" + integrity sha512-owoXEFjWRllis8/M1Q+Cw5k8ZH40e3zhp/ovX+Xr/vi1qj6QesbyXXViFbpNvWvPNAD62SutwEXavefrLJWj7w== dependencies: randombytes "^2.1.0" @@ -2030,23 +1771,15 @@ source-map-js@^1.0.2: resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.0.2.tgz#adbc361d9c62df380125e7f161f71c826f1e490c" integrity sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw== -source-map-loader@4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/source-map-loader/-/source-map-loader-4.0.0.tgz#bdc6b118bc6c87ee4d8d851f2d4efcc5abdb2ef5" - integrity sha512-i3KVgM3+QPAHNbGavK+VBq03YoJl24m9JWNbLgsjTj8aJzXG9M61bantBTNBt7CNwY2FYf+RJRYJ3pzalKjIrw== +source-map-loader@4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/source-map-loader/-/source-map-loader-4.0.1.tgz#72f00d05f5d1f90f80974eda781cbd7107c125f2" + integrity sha512-oqXpzDIByKONVY8g1NUPOTQhe0UTU5bWUl32GSkqK2LjJj0HmwTMVKxcUip0RgAYhY1mqgOxjbQM48a0mmeNfA== dependencies: abab "^2.0.6" iconv-lite "^0.6.3" source-map-js "^1.0.2" -source-map-resolve@^0.6.0: - version "0.6.0" - resolved "https://registry.yarnpkg.com/source-map-resolve/-/source-map-resolve-0.6.0.tgz#3d9df87e236b53f16d01e58150fc7711138e5ed2" - integrity sha512-KXBr9d/fO/bWo97NXsPIAW1bFSBOuCnjbNTBMO7N59hsv5i9yzRDfcYwwt0l04+VqnKC+EwzvJZIP/qkuMgR/w== - dependencies: - atob "^2.1.2" - decode-uri-component "^0.2.0" - source-map-support@~0.5.20: version "0.5.21" resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f" @@ -2060,16 +1793,6 @@ source-map@^0.6.0, source-map@^0.6.1: resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== -source-map@~0.7.2: - version "0.7.3" - resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383" - integrity sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ== - -sourcemap-codec@^1.4.8: - version "1.4.8" - resolved "https://registry.yarnpkg.com/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz#ea804bd94857402e6992d05a38ef1ae35a9ab4c4" - integrity sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA== - "statuses@>= 1.5.0 < 2", statuses@~1.5.0: version "1.5.0" resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c" @@ -2117,14 +1840,7 @@ supports-color@8.1.1, supports-color@^8.0.0: dependencies: has-flag "^4.0.0" -supports-color@^5.3.0: - version "5.5.0" - resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f" - integrity sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow== - dependencies: - has-flag "^3.0.0" - -supports-color@^7.0.0, supports-color@^7.1.0: +supports-color@^7.1.0: version "7.2.0" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da" integrity sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw== @@ -2141,36 +1857,27 @@ tapable@^2.1.1, tapable@^2.2.0: resolved "https://registry.yarnpkg.com/tapable/-/tapable-2.2.1.tgz#1967a73ef4060a82f12ab96af86d52fdb76eeca0" integrity sha512-GNzQvQTOIP6RyTfE2Qxb8ZVlNmw0n88vp1szwWRimP02mnTsx3Wtn5qRdqY9w2XduFNUgvOwhNnQsjwCp+kqaQ== -terser-webpack-plugin@^5.1.3: - version "5.3.0" - resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-5.3.0.tgz#21641326486ecf91d8054161c816e464435bae9f" - integrity sha512-LPIisi3Ol4chwAaPP8toUJ3L4qCM1G0wao7L3qNv57Drezxj6+VEyySpPw4B1HSO2Eg/hDY/MNF5XihCAoqnsQ== +terser-webpack-plugin@^5.3.7: + version "5.3.9" + resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-5.3.9.tgz#832536999c51b46d468067f9e37662a3b96adfe1" + integrity sha512-ZuXsqE07EcggTWQjXUj+Aot/OMcD0bMKGgF63f7UxYcu5/AJF53aIpK1YoP5xR9l6s/Hy2b+t1AM0bLNPRuhwA== dependencies: - jest-worker "^27.4.1" + "@jridgewell/trace-mapping" "^0.3.17" + jest-worker "^27.4.5" schema-utils "^3.1.1" - serialize-javascript "^6.0.0" - source-map "^0.6.1" - terser "^5.7.2" + serialize-javascript "^6.0.1" + terser "^5.16.8" -terser@^5.0.0: - version "5.17.7" - resolved "https://registry.yarnpkg.com/terser/-/terser-5.17.7.tgz#2a8b134826fe179b711969fd9d9a0c2479b2a8c3" - integrity sha512-/bi0Zm2C6VAexlGgLlVxA0P2lru/sdLyfCVaRMfKVo9nWxbmz7f/sD8VPybPeSUJaJcwmCJis9pBIhcVcG1QcQ== +terser@^5.16.8: + version "5.19.2" + resolved "https://registry.yarnpkg.com/terser/-/terser-5.19.2.tgz#bdb8017a9a4a8de4663a7983f45c506534f9234e" + integrity sha512-qC5+dmecKJA4cpYxRa5aVkKehYsQKc+AHeKl0Oe62aYjBL8ZA33tTljktDHJSaxxMnbI5ZYw+o/S2DxxLu8OfA== dependencies: "@jridgewell/source-map" "^0.3.3" acorn "^8.8.2" commander "^2.20.0" source-map-support "~0.5.20" -terser@^5.7.2: - version "5.10.0" - resolved "https://registry.yarnpkg.com/terser/-/terser-5.10.0.tgz#b86390809c0389105eb0a0b62397563096ddafcc" - integrity sha512-AMmF99DMfEDiRJfxfY5jj5wNH/bYO09cniSqhfoyxc8sFoYIgkJy86G04UoZU5VjlpnplVu0K6Tx6E9b5+DlHA== - dependencies: - commander "^2.20.0" - source-map "~0.7.2" - source-map-support "~0.5.20" - tmp@^0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.2.1.tgz#8457fc3037dcf4719c251367a1af6500ee1ccf14" @@ -2190,11 +1897,6 @@ toidentifier@1.0.1: resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.1.tgz#3be34321a88a820ed1bd80dfaa33e479fbb8dd35" integrity sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA== -tslib@^2.3.1: - version "2.5.3" - resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.3.tgz#24944ba2d990940e6e982c4bea147aba80209913" - integrity sha512-mSxlJJwl3BMEQCUNnxXBU9jP4JBktcEGhURcPR6VQVlnP0FdDEsIaz0C35dXNGLyRfrATNofF0F5p2KPxQgB+w== - type-is@~1.6.18: version "1.6.18" resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.18.tgz#4e552cd05df09467dcbc4ef739de89f2cf37c131" @@ -2203,15 +1905,10 @@ type-is@~1.6.18: media-typer "0.3.0" mime-types "~2.1.24" -typescript@4.7.4: - version "4.7.4" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.4.tgz#1a88596d1cf47d59507a1bcdfb5b9dfe4d488235" - integrity sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ== - -typescript@^3.7.2: - version "3.9.10" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.10.tgz#70f3910ac7a51ed6bef79da7800690b19bf778b8" - integrity sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q== +typescript@5.0.4: + version "5.0.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.0.4.tgz#b217fd20119bd61a94d4011274e0ab369058da3b" + integrity sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw== ua-parser-js@^0.7.30: version "0.7.34" @@ -2263,22 +1960,23 @@ watchpack@^2.4.0: glob-to-regexp "^0.4.1" graceful-fs "^4.1.2" -webpack-cli@4.10.0: - version "4.10.0" - resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-4.10.0.tgz#37c1d69c8d85214c5a65e589378f53aec64dab31" - integrity sha512-NLhDfH/h4O6UOy+0LSso42xvYypClINuMNBVVzX4vX98TmTaTUxwRbXdhucbFMd2qLaCTcLq/PdYrvi8onw90w== +webpack-cli@5.1.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-5.1.0.tgz#abc4b1f44b50250f2632d8b8b536cfe2f6257891" + integrity sha512-a7KRJnCxejFoDpYTOwzm5o21ZXMaNqtRlvS183XzGDUPRdVEzJNImcQokqYZ8BNTnk9DkKiuWxw75+DCCoZ26w== dependencies: "@discoveryjs/json-ext" "^0.5.0" - "@webpack-cli/configtest" "^1.2.0" - "@webpack-cli/info" "^1.5.0" - "@webpack-cli/serve" "^1.7.0" + "@webpack-cli/configtest" "^2.1.0" + "@webpack-cli/info" "^2.0.1" + "@webpack-cli/serve" "^2.0.3" colorette "^2.0.14" - commander "^7.0.0" + commander "^10.0.1" cross-spawn "^7.0.3" + envinfo "^7.7.3" fastest-levenshtein "^1.0.12" import-local "^3.0.2" - interpret "^2.2.0" - rechoir "^0.7.0" + interpret "^3.1.1" + rechoir "^0.8.0" webpack-merge "^5.7.3" webpack-merge@^4.1.5: @@ -2301,22 +1999,22 @@ webpack-sources@^3.2.3: resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.2.3.tgz#2d4daab8451fd4b240cc27055ff6a0c2ccea0cde" integrity sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w== -webpack@5.74.0: - version "5.74.0" - resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.74.0.tgz#02a5dac19a17e0bb47093f2be67c695102a55980" - integrity sha512-A2InDwnhhGN4LYctJj6M1JEaGL7Luj6LOmyBHjcI8529cm5p6VXiTIW2sn6ffvEAKmveLzvu4jrihwXtPojlAA== +webpack@5.82.0: + version "5.82.0" + resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.82.0.tgz#3c0d074dec79401db026b4ba0fb23d6333f88e7d" + integrity sha512-iGNA2fHhnDcV1bONdUu554eZx+XeldsaeQ8T67H6KKHl2nUSwX8Zm7cmzOA46ox/X1ARxf7Bjv8wQ/HsB5fxBg== dependencies: "@types/eslint-scope" "^3.7.3" - "@types/estree" "^0.0.51" - "@webassemblyjs/ast" "1.11.1" - "@webassemblyjs/wasm-edit" "1.11.1" - "@webassemblyjs/wasm-parser" "1.11.1" + "@types/estree" "^1.0.0" + "@webassemblyjs/ast" "^1.11.5" + "@webassemblyjs/wasm-edit" "^1.11.5" + "@webassemblyjs/wasm-parser" "^1.11.5" acorn "^8.7.1" acorn-import-assertions "^1.7.6" browserslist "^4.14.5" chrome-trace-event "^1.0.2" - enhanced-resolve "^5.10.0" - es-module-lexer "^0.9.0" + enhanced-resolve "^5.13.0" + es-module-lexer "^1.2.1" eslint-scope "5.1.1" events "^3.2.0" glob-to-regexp "^0.4.1" @@ -2325,9 +2023,9 @@ webpack@5.74.0: loader-runner "^4.2.0" mime-types "^2.1.27" neo-async "^2.6.2" - schema-utils "^3.1.0" + schema-utils "^3.1.2" tapable "^2.1.1" - terser-webpack-plugin "^5.1.3" + terser-webpack-plugin "^5.3.7" watchpack "^2.4.0" webpack-sources "^3.2.3" diff --git a/resources-build-logic/src/main/kotlin/detekt-convention.gradle.kts b/resources-build-logic/src/main/kotlin/detekt-convention.gradle.kts index 9503616f7..83389bafa 100644 --- a/resources-build-logic/src/main/kotlin/detekt-convention.gradle.kts +++ b/resources-build-logic/src/main/kotlin/detekt-convention.gradle.kts @@ -7,7 +7,7 @@ plugins { } detekt { - input.setFrom( + source.setFrom( "src/commonMain/kotlin", "src/androidMain/kotlin", "src/iosMain/kotlin", diff --git a/resources-build-logic/src/main/kotlin/multiplatform-android-publish-convention.gradle.kts b/resources-build-logic/src/main/kotlin/multiplatform-android-publish-convention.gradle.kts index 02acce7ff..b95dfb63a 100644 --- a/resources-build-logic/src/main/kotlin/multiplatform-android-publish-convention.gradle.kts +++ b/resources-build-logic/src/main/kotlin/multiplatform-android-publish-convention.gradle.kts @@ -7,7 +7,7 @@ plugins { } kotlin { - android { + androidTarget() { publishAllLibraryVariants() publishLibraryVariantsGroupedByFlavor = true } diff --git a/resources-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts b/resources-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts index 199914a05..bdd895ef4 100644 --- a/resources-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts +++ b/resources-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts @@ -14,7 +14,7 @@ plugins { kotlin { jvm() - android() + androidTarget() ios() iosSimulatorArm64() macosX64() diff --git a/resources-compose/build.gradle.kts b/resources-compose/build.gradle.kts index 08069a0c8..58e14593e 100644 --- a/resources-compose/build.gradle.kts +++ b/resources-compose/build.gradle.kts @@ -25,7 +25,7 @@ android { kotlin { jvm() - android() + androidTarget() ios() iosSimulatorArm64() macosX64() diff --git a/resources-compose/src/appleMain/kotlin/dev/icerock/moko/resources/compose/internal/CGImageRef+Skia.kt b/resources-compose/src/appleMain/kotlin/dev/icerock/moko/resources/compose/internal/CGImageRef+Skia.kt index 98e730277..88c92a125 100644 --- a/resources-compose/src/appleMain/kotlin/dev/icerock/moko/resources/compose/internal/CGImageRef+Skia.kt +++ b/resources-compose/src/appleMain/kotlin/dev/icerock/moko/resources/compose/internal/CGImageRef+Skia.kt @@ -9,6 +9,7 @@ import cnames.structs.CGImage import kotlinx.cinterop.CPointed import kotlinx.cinterop.CPointer import kotlinx.cinterop.CValue +import kotlinx.cinterop.ExperimentalForeignApi import kotlinx.cinterop.readBytes import org.jetbrains.skia.ColorAlphaType import org.jetbrains.skia.ColorType @@ -31,6 +32,7 @@ import platform.posix.malloc import platform.posix.size_t import platform.posix.uint32_t +@OptIn(ExperimentalForeignApi::class) internal fun CGImageRef.toSkiaImage(): Image { val cgImage: CPointer = this val width: size_t = CGImageGetWidth(cgImage) diff --git a/resources-compose/src/appleMain/kotlin/dev/icerock/moko/resources/compose/internal/NSDataExt.kt b/resources-compose/src/appleMain/kotlin/dev/icerock/moko/resources/compose/internal/NSDataExt.kt index 259dfe55c..554440fde 100644 --- a/resources-compose/src/appleMain/kotlin/dev/icerock/moko/resources/compose/internal/NSDataExt.kt +++ b/resources-compose/src/appleMain/kotlin/dev/icerock/moko/resources/compose/internal/NSDataExt.kt @@ -4,12 +4,14 @@ package dev.icerock.moko.resources.compose.internal +import kotlinx.cinterop.ExperimentalForeignApi import kotlinx.cinterop.addressOf import kotlinx.cinterop.usePinned import platform.Foundation.NSData import platform.posix.memcpy +@OptIn(ExperimentalForeignApi::class) internal fun NSData.toByteArray(): ByteArray { return ByteArray(this@toByteArray.length.toInt()).apply { usePinned { pinned -> diff --git a/resources-compose/src/iosMain/kotlin/dev/icerock/moko/resources/compose/ColorResource.kt b/resources-compose/src/iosMain/kotlin/dev/icerock/moko/resources/compose/ColorResource.kt index 6b64ceeaf..94ce6a5e1 100644 --- a/resources-compose/src/iosMain/kotlin/dev/icerock/moko/resources/compose/ColorResource.kt +++ b/resources-compose/src/iosMain/kotlin/dev/icerock/moko/resources/compose/ColorResource.kt @@ -11,6 +11,7 @@ import androidx.compose.ui.graphics.Color import dev.icerock.moko.resources.ColorResource import dev.icerock.moko.resources.getUIColor import kotlinx.cinterop.DoubleVarOf +import kotlinx.cinterop.ExperimentalForeignApi import kotlinx.cinterop.alloc import kotlinx.cinterop.memScoped import kotlinx.cinterop.ptr @@ -18,6 +19,7 @@ import kotlinx.cinterop.value import platform.CoreGraphics.CGFloat import platform.UIKit.UIColor +@OptIn(ExperimentalForeignApi::class) @Composable actual fun colorResource(resource: ColorResource): Color { // TODO https://github.com/icerockdev/moko-resources/issues/443 diff --git a/resources-compose/src/iosMain/kotlin/dev/icerock/moko/resources/compose/ImageResource.kt b/resources-compose/src/iosMain/kotlin/dev/icerock/moko/resources/compose/ImageResource.kt index 9d7f01b89..c9a269ff5 100644 --- a/resources-compose/src/iosMain/kotlin/dev/icerock/moko/resources/compose/ImageResource.kt +++ b/resources-compose/src/iosMain/kotlin/dev/icerock/moko/resources/compose/ImageResource.kt @@ -11,10 +11,12 @@ import androidx.compose.ui.graphics.painter.Painter import androidx.compose.ui.graphics.toComposeImageBitmap import dev.icerock.moko.resources.ImageResource import dev.icerock.moko.resources.compose.internal.toSkiaImage +import kotlinx.cinterop.ExperimentalForeignApi import org.jetbrains.skia.Image import platform.CoreGraphics.CGImageRef import platform.UIKit.UIImage +@OptIn(ExperimentalForeignApi::class) @Composable actual fun painterResource(imageResource: ImageResource): Painter { return remember(imageResource) { diff --git a/resources-compose/src/jvmMain/kotlin/dev/icerock/moko/resources/compose/StringDescExt.kt b/resources-compose/src/jvmMain/kotlin/dev/icerock/moko/resources/compose/StringDescExt.kt index 7ad6226d4..2e295c182 100644 --- a/resources-compose/src/jvmMain/kotlin/dev/icerock/moko/resources/compose/StringDescExt.kt +++ b/resources-compose/src/jvmMain/kotlin/dev/icerock/moko/resources/compose/StringDescExt.kt @@ -4,9 +4,11 @@ package dev.icerock.moko.resources.compose +import androidx.compose.runtime.Composable import dev.icerock.moko.resources.desc.StringDesc @Suppress("EXTENSION_SHADOWED_BY_MEMBER") +@Composable actual fun StringDesc.localized(): String { return this.localized() } diff --git a/resources-compose/src/macosMain/kotlin/dev/icerock/moko/resources/compose/ImageResource.kt b/resources-compose/src/macosMain/kotlin/dev/icerock/moko/resources/compose/ImageResource.kt index 17ee2f53d..08beeb63a 100644 --- a/resources-compose/src/macosMain/kotlin/dev/icerock/moko/resources/compose/ImageResource.kt +++ b/resources-compose/src/macosMain/kotlin/dev/icerock/moko/resources/compose/ImageResource.kt @@ -11,11 +11,13 @@ import androidx.compose.ui.graphics.painter.Painter import androidx.compose.ui.graphics.toComposeImageBitmap import dev.icerock.moko.resources.ImageResource import dev.icerock.moko.resources.compose.internal.toSkiaImage +import kotlinx.cinterop.ExperimentalForeignApi import org.jetbrains.skia.Image import platform.AppKit.NSImage import platform.CoreGraphics.CGImageRef import platform.CoreGraphics.CGImageRelease +@OptIn(ExperimentalForeignApi::class) @Composable actual fun painterResource(imageResource: ImageResource): Painter { return remember(imageResource) { diff --git a/resources-generator/build.gradle.kts b/resources-generator/build.gradle.kts index eaad63837..4835925fa 100644 --- a/resources-generator/build.gradle.kts +++ b/resources-generator/build.gradle.kts @@ -3,7 +3,7 @@ */ plugins { - id("org.jetbrains.kotlin.jvm") version ("1.8.10") + id("org.jetbrains.kotlin.jvm") version ("1.9.0") id("detekt-convention") id("publication-convention") id("com.gradle.plugin-publish") version ("1.2.0") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt index 7bb961fd5..f92b81ea2 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt @@ -16,6 +16,7 @@ import dev.icerock.gradle.generator.js.JsFontsGenerator import dev.icerock.gradle.generator.jvm.JvmFontsGenerator import org.gradle.api.file.FileTree import java.io.File +import java.util.Locale abstract class FontsGenerator( private val inputFileTree: FileTree @@ -92,7 +93,7 @@ abstract class FontsGenerator( fontStyleFiles .forEach { (styleName, file) -> val styleProperty = PropertySpec - .builder(styleName.decapitalize(), resourceClassName) + .builder(styleName.replaceFirstChar { it.lowercase(Locale.ROOT) }, resourceClassName) .addModifiers(*getPropertyModifiers()) getPropertyInitializer(file)?.let { codeBlock -> styleProperty.initializer(codeBlock) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt index 0c473706a..713f06d90 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt @@ -110,7 +110,7 @@ class AppleMRGenerator( } private fun setupKLibResources(generationTask: Task) { - val compileTask: KotlinNativeCompile = compilation.compileKotlinTask + val compileTask: KotlinNativeCompile = compilation.compileTaskProvider.get() compileTask.dependsOn(generationTask) // tasks like compileIosMainKotlinMetadata when only one target enabled diff --git a/resources/src/appleMain/kotlin/dev/icerock/moko/resources/FileResource.kt b/resources/src/appleMain/kotlin/dev/icerock/moko/resources/FileResource.kt index 375543eab..82e0211c9 100644 --- a/resources/src/appleMain/kotlin/dev/icerock/moko/resources/FileResource.kt +++ b/resources/src/appleMain/kotlin/dev/icerock/moko/resources/FileResource.kt @@ -4,6 +4,7 @@ package dev.icerock.moko.resources +import kotlinx.cinterop.ExperimentalForeignApi import kotlinx.cinterop.ObjCObjectVar import kotlinx.cinterop.alloc import kotlinx.cinterop.memScoped @@ -34,6 +35,7 @@ actual open class FileResource( subdirectory = "files" )!! + @OptIn(ExperimentalForeignApi::class) fun readText(): String { val filePath = path val (result: String?, error: NSError?) = memScoped { diff --git a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/FontResource.kt b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/FontResource.kt index 9aadec8f8..db3128d98 100644 --- a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/FontResource.kt +++ b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/FontResource.kt @@ -8,6 +8,7 @@ import cnames.structs.CGDataProvider import cnames.structs.__CFData import cnames.structs.__CTFont import kotlinx.cinterop.CPointer +import kotlinx.cinterop.ExperimentalForeignApi import platform.CoreFoundation.CFDataCreate import platform.CoreFoundation.kCFAllocatorDefault import platform.CoreGraphics.CGDataProviderCreateWithCFData @@ -21,6 +22,7 @@ import platform.Foundation.create import platform.UIKit.UIFont import platform.darwin.UInt8Var +@OptIn(ExperimentalForeignApi::class) actual class FontResource( val fontName: String, val bundle: NSBundle = NSBundle.mainBundle diff --git a/resources/src/macosMain/kotlin/dev/icerock/moko/resources/FontResource.kt b/resources/src/macosMain/kotlin/dev/icerock/moko/resources/FontResource.kt index 0014765aa..da7747453 100644 --- a/resources/src/macosMain/kotlin/dev/icerock/moko/resources/FontResource.kt +++ b/resources/src/macosMain/kotlin/dev/icerock/moko/resources/FontResource.kt @@ -8,6 +8,7 @@ import cnames.structs.CGDataProvider import cnames.structs.__CFData import cnames.structs.__CTFont import kotlinx.cinterop.CPointer +import kotlinx.cinterop.ExperimentalForeignApi import platform.AppKit.NSFont import platform.CoreFoundation.CFDataCreate import platform.CoreFoundation.kCFAllocatorDefault @@ -21,6 +22,7 @@ import platform.Foundation.NSData import platform.Foundation.create import platform.darwin.UInt8Var +@OptIn(ExperimentalForeignApi::class) actual class FontResource( val fontName: String, val bundle: NSBundle = NSBundle.mainBundle diff --git a/samples/android-mpp-app/app/build.gradle.kts b/samples/android-mpp-app/app/build.gradle.kts index f3c923231..14cc6998a 100644 --- a/samples/android-mpp-app/app/build.gradle.kts +++ b/samples/android-mpp-app/app/build.gradle.kts @@ -33,7 +33,7 @@ android { } kotlin { - android() + androidTarget() ios() } diff --git a/samples/android-mpp-app/build.gradle.kts b/samples/android-mpp-app/build.gradle.kts index 696f2d88c..e2ad3fa1d 100644 --- a/samples/android-mpp-app/build.gradle.kts +++ b/samples/android-mpp-app/build.gradle.kts @@ -11,7 +11,7 @@ buildscript { } dependencies { classpath(moko.resourcesGradlePlugin) - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0") classpath("com.android.tools.build:gradle:8.0.1") } } diff --git a/samples/auto-manifest/build.gradle.kts b/samples/auto-manifest/build.gradle.kts index 0a558aec2..a4bbb97ab 100644 --- a/samples/auto-manifest/build.gradle.kts +++ b/samples/auto-manifest/build.gradle.kts @@ -11,7 +11,7 @@ buildscript { } dependencies { classpath(moko.resourcesGradlePlugin) - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0") classpath("com.android.tools.build:gradle:8.0.1") classpath("com.gradleup:auto-manifest-plugin:2.0") } diff --git a/samples/auto-manifest/mpp-library/build.gradle.kts b/samples/auto-manifest/mpp-library/build.gradle.kts index e1fc28d87..365bd55ad 100644 --- a/samples/auto-manifest/mpp-library/build.gradle.kts +++ b/samples/auto-manifest/mpp-library/build.gradle.kts @@ -18,7 +18,7 @@ android { } kotlin { - android() + androidTarget() } dependencies { diff --git a/samples/compose-jvm-app/build.gradle.kts b/samples/compose-jvm-app/build.gradle.kts index ef52564f1..7ecb9f62f 100644 --- a/samples/compose-jvm-app/build.gradle.kts +++ b/samples/compose-jvm-app/build.gradle.kts @@ -7,7 +7,7 @@ buildscript { } dependencies { classpath(moko.resourcesGradlePlugin) - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0") classpath("org.jetbrains.compose:compose-gradle-plugin:1.4.0") } } diff --git a/samples/compose-resources-gallery/androidApp/build.gradle.kts b/samples/compose-resources-gallery/androidApp/build.gradle.kts index a12bdab8c..168b66b61 100644 --- a/samples/compose-resources-gallery/androidApp/build.gradle.kts +++ b/samples/compose-resources-gallery/androidApp/build.gradle.kts @@ -5,7 +5,7 @@ plugins { } kotlin { - android() + androidTarget() @Suppress("UNUSED_VARIABLE") sourceSets { diff --git a/samples/compose-resources-gallery/gradle.properties b/samples/compose-resources-gallery/gradle.properties index 227dfebe6..52e7715b8 100644 --- a/samples/compose-resources-gallery/gradle.properties +++ b/samples/compose-resources-gallery/gradle.properties @@ -16,4 +16,4 @@ kotlin.mpp.androidGradlePluginCompatibility.nowarn=true kotlin.native.binary.memoryModel=experimental kotlin.version=1.8.20 agp.version=8.0.1 -compose.version=1.4.0 +compose.version=1.5.0 diff --git a/samples/compose-resources-gallery/shared/build.gradle.kts b/samples/compose-resources-gallery/shared/build.gradle.kts index 987c70f16..2f96c3584 100644 --- a/samples/compose-resources-gallery/shared/build.gradle.kts +++ b/samples/compose-resources-gallery/shared/build.gradle.kts @@ -11,7 +11,7 @@ plugins { version = "1.0-SNAPSHOT" kotlin { - android() + androidTarget() jvm("desktop") diff --git a/samples/ios-static-xcframework/build.gradle.kts b/samples/ios-static-xcframework/build.gradle.kts index 77d5c8bb9..7eada2742 100644 --- a/samples/ios-static-xcframework/build.gradle.kts +++ b/samples/ios-static-xcframework/build.gradle.kts @@ -11,6 +11,6 @@ buildscript { } dependencies { classpath(moko.resourcesGradlePlugin) - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0") } } diff --git a/samples/kotlin-ios-app/build.gradle.kts b/samples/kotlin-ios-app/build.gradle.kts index 77d5c8bb9..7eada2742 100644 --- a/samples/kotlin-ios-app/build.gradle.kts +++ b/samples/kotlin-ios-app/build.gradle.kts @@ -11,6 +11,6 @@ buildscript { } dependencies { classpath(moko.resourcesGradlePlugin) - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0") } } diff --git a/samples/resources-gallery/build.gradle.kts b/samples/resources-gallery/build.gradle.kts index ce7afffe5..20874508f 100644 --- a/samples/resources-gallery/build.gradle.kts +++ b/samples/resources-gallery/build.gradle.kts @@ -13,9 +13,9 @@ buildscript { } dependencies { classpath(moko.resourcesGradlePlugin) - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0") classpath("com.android.tools.build:gradle:7.4.2") - classpath("org.jetbrains.compose:compose-gradle-plugin:1.4.0") + classpath("org.jetbrains.compose:compose-gradle-plugin:1.5.0-dev1114") } } diff --git a/samples/resources-gallery/mpp-library/build.gradle.kts b/samples/resources-gallery/mpp-library/build.gradle.kts index a55ce94a5..6589f1fdc 100644 --- a/samples/resources-gallery/mpp-library/build.gradle.kts +++ b/samples/resources-gallery/mpp-library/build.gradle.kts @@ -12,7 +12,7 @@ plugins { allprojects { plugins.withId("org.jetbrains.kotlin.multiplatform") { kotlin { - android() + androidTarget() ios() iosSimulatorArm64() jvm() From 7c52c31ce859020b5f874284e72811cf9fdec33b Mon Sep 17 00:00:00 2001 From: viktor kuzmin Date: Thu, 27 Jul 2023 19:38:44 +0300 Subject: [PATCH 005/352] #510 update composeJetbrainsVersion --- gradle/libs.versions.toml | 4 ++-- samples/resources-gallery/build.gradle.kts | 2 +- samples/resources-gallery/web-app/build.gradle.kts | 8 ++++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 99af28b28..9475bee84 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -12,11 +12,11 @@ constraintLayoutVersion = "2.1.4" androidAppCompatVersion = "1.6.1" # android compose -composeVersion = "1.4.3" +composeVersion = "1.5.0-rc01" composeActivityVersion = "1.7.1" # jetbrains compose -composeJetbrainsVersion = "1.5.0-dev1114" +composeJetbrainsVersion = "1.5.0-dev1122" # jvm apacheCommonsTextVersion = "1.10.0" diff --git a/samples/resources-gallery/build.gradle.kts b/samples/resources-gallery/build.gradle.kts index 20874508f..66d3b63f5 100644 --- a/samples/resources-gallery/build.gradle.kts +++ b/samples/resources-gallery/build.gradle.kts @@ -15,7 +15,7 @@ buildscript { classpath(moko.resourcesGradlePlugin) classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0") classpath("com.android.tools.build:gradle:7.4.2") - classpath("org.jetbrains.compose:compose-gradle-plugin:1.5.0-dev1114") + classpath("org.jetbrains.compose:compose-gradle-plugin:1.5.0-dev1122") } } diff --git a/samples/resources-gallery/web-app/build.gradle.kts b/samples/resources-gallery/web-app/build.gradle.kts index 2d227128b..e96a3d916 100644 --- a/samples/resources-gallery/web-app/build.gradle.kts +++ b/samples/resources-gallery/web-app/build.gradle.kts @@ -15,8 +15,12 @@ kotlin { implementation(moko.resources) implementation(project(":mpp-library")) - implementation(compose.html.core) - implementation(compose.runtime) + // TODO() + // implementation(compose.html.core) + // implementation(compose.runtime) + implementation("org.jetbrains.compose.web:web-core:1.4.0") + runtimeOnly("org.jetbrains.compose.runtime:runtime:1.4.0") + } } } From 69cec0dfec117497d2b18b106ddfba774d06b19c Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Mon, 31 Jul 2023 19:38:10 +0700 Subject: [PATCH 006/352] #530 update detekt convention --- .../src/main/kotlin/detekt-convention.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources-build-logic/src/main/kotlin/detekt-convention.gradle.kts b/resources-build-logic/src/main/kotlin/detekt-convention.gradle.kts index 9503616f7..9345c920d 100644 --- a/resources-build-logic/src/main/kotlin/detekt-convention.gradle.kts +++ b/resources-build-logic/src/main/kotlin/detekt-convention.gradle.kts @@ -17,5 +17,5 @@ detekt { } dependencies { - "detektPlugins"("io.gitlab.arturbosch.detekt:detekt-formatting:1.22.0") + detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.22.0") } From 506c5ef12c767e6ae1aa60d9714f4dd56a755f55 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Mon, 31 Jul 2023 19:41:44 +0700 Subject: [PATCH 007/352] #530 update libs, gradle, agp --- gradle/libs.versions.toml | 10 +++++----- gradle/moko.versions.toml | 2 +- gradle/wrapper/gradle-wrapper.properties | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2295eb5a8..df826a182 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,10 +1,10 @@ [versions] -kotlinVersion = "1.8.20" -androidGradleVersion = "7.4.2" -androidSdkCommonVersion = "31.0.0" +kotlinVersion = "1.8.21" +androidGradleVersion = "8.0.2" +androidSdkCommonVersion = "31.1.0" # kotlinx -kotlinxSerializationVersion = "1.5.0" +kotlinxSerializationVersion = "1.5.1" kotlinxCoroutinesVersion = "1.6.4" # android @@ -16,7 +16,7 @@ composeVersion = "1.4.2" composeActivityVersion = "1.7.1" # jetbrains compose -composeJetbrainsVersion = "1.4.0" +composeJetbrainsVersion = "1.4.3" # jvm apacheCommonsTextVersion = "1.10.0" diff --git a/gradle/moko.versions.toml b/gradle/moko.versions.toml index 8aea45de7..22271f2a0 100644 --- a/gradle/moko.versions.toml +++ b/gradle/moko.versions.toml @@ -1,5 +1,5 @@ [versions] -resourcesVersion = "0.23.0" +resourcesVersion = "0.24.0" [libraries] resources = { module = "dev.icerock.moko:resources", version.ref = "resourcesVersion" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 37aef8d3f..d99d8671b 100755 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ +#Tue Jul 25 10:40:31 NOVT 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From d2407b72118721b7e71ffa9473056b92a693e957 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Mon, 31 Jul 2023 19:42:20 +0700 Subject: [PATCH 008/352] #530 generator update, replaced resource dir, remove MR package --- resources-generator/build.gradle.kts | 2 +- .../gradle/MultiplatformResourcesPlugin.kt | 23 +++++++++++++------ .../gradle/generator/AssetsGenerator.kt | 6 ++--- .../gradle/generator/ColorsGenerator.kt | 2 +- .../gradle/generator/FilesGenerator.kt | 2 +- .../gradle/generator/FontsGenerator.kt | 2 +- .../gradle/generator/ImagesGenerator.kt | 2 +- .../gradle/generator/PluralsGenerator.kt | 2 +- .../gradle/generator/StringsGenerator.kt | 2 +- 9 files changed, 25 insertions(+), 18 deletions(-) diff --git a/resources-generator/build.gradle.kts b/resources-generator/build.gradle.kts index eaad63837..ed039e0ea 100644 --- a/resources-generator/build.gradle.kts +++ b/resources-generator/build.gradle.kts @@ -3,7 +3,7 @@ */ plugins { - id("org.jetbrains.kotlin.jvm") version ("1.8.10") + id("org.jetbrains.kotlin.jvm") version ("1.8.21") id("detekt-convention") id("publication-convention") id("com.gradle.plugin-publish") version ("1.2.0") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index d9691de5a..c8d30c2cd 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -25,6 +25,8 @@ import dev.icerock.gradle.utils.getDependedFrom import dev.icerock.gradle.utils.isDependsOn import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.file.SourceDirectorySet +import org.gradle.api.model.ObjectFactory import org.gradle.api.tasks.SourceSet import org.gradle.kotlin.dsl.create import org.gradle.kotlin.dsl.getByType @@ -41,10 +43,14 @@ import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget import org.jetbrains.kotlin.konan.target.HostManager import java.io.File +import javax.inject.Inject import javax.xml.parsers.DocumentBuilderFactory @Suppress("TooManyFunctions") -class MultiplatformResourcesPlugin : Plugin { +abstract class MultiplatformResourcesPlugin : Plugin { + @Inject + protected abstract fun getObjectFactory(): ObjectFactory + override fun apply(target: Project) { val mrExtension: MultiplatformResourcesPluginExtension = target.extensions.create( "multiplatformResources", @@ -72,10 +78,12 @@ class MultiplatformResourcesPlugin : Plugin { mrExtension: MultiplatformResourcesPluginExtension, multiplatformExtension: KotlinMultiplatformExtension ) { - val commonSourceSet = multiplatformExtension.sourceSets.getByName(mrExtension.sourceSetName) - val commonResources = commonSourceSet.resources + val commonSourceSet: KotlinSourceSet = multiplatformExtension.sourceSets.getByName(mrExtension.sourceSetName) + val commonResources: SourceDirectorySet = getObjectFactory() + .sourceDirectorySet("moko-resources", "moko-resources") + commonResources.srcDir("${target.projectDir}/src/${commonSourceSet.name}/moko-resources") - val generatedDir = File(target.buildDir, "generated/moko") + val generatedDir = File(target.buildDir, "generated/moko-resources") val mrClassPackage: String = requireNotNull(mrExtension.multiplatformResourcesPackage) { buildString { appendLine("multiplatformResources.multiplatformResourcesPackage is required!") @@ -88,9 +96,9 @@ class MultiplatformResourcesPlugin : Plugin { visibility = mrExtension.multiplatformResourcesVisibility ) val sourceInfo = SourceInfo( - generatedDir, - commonResources, - mrExtension.multiplatformResourcesPackage!! + generatedDir = generatedDir, + commonResources = commonResources, + mrClassPackage = mrExtension.multiplatformResourcesPackage!! ) val strictLineBreaks: Boolean = target @@ -223,6 +231,7 @@ class MultiplatformResourcesPlugin : Plugin { target: Project ): GenerateMultiplatformResourcesTask { val commonGeneratorSourceSet: MRGenerator.SourceSet = createSourceSet(commonSourceSet) + return CommonMRGenerator( generatedDir, commonGeneratorSourceSet, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt index 9f00e8523..08e821117 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt @@ -26,7 +26,7 @@ abstract class AssetsGenerator( override val resourceClassName = ClassName("dev.icerock.moko.resources", "AssetResource") private fun getBaseDir(file: File): String { - val relativePathToAssets = file.path.substringAfterLast(RES_ROOT) + val relativePathToAssets = file.path.substringAfterLast(ASSETS_DIR_NAME) val fixedRelativePath = File(relativePathToAssets).path val result: String = if (fixedRelativePath.startsWith(File.separatorChar)) { @@ -74,7 +74,7 @@ abstract class AssetsGenerator( ): List { val contentOfRootDir = mutableListOf() resFolders.forEach { - val assets = File(it, RES_ROOT) + val assets = File(it, ASSETS_DIR_NAME) val content = assets.listFiles() if (content != null) { @@ -203,7 +203,5 @@ abstract class AssetsGenerator( don't support it like apple. */ const val PATH_DELIMITER = '+' - - private val RES_ROOT = "MR${File.separatorChar}$ASSETS_DIR_NAME" } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt index 3c9ed7050..c56f73e4d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt @@ -140,7 +140,7 @@ abstract class ColorsGenerator( ) : ResourceGeneratorFeature { private val colorsFileTree = - info.commonResources.matching { it.include("MR/**/colors*.xml") } + info.commonResources.matching { it.include("colors/colors*.xml") } override fun createCommonGenerator() = CommonColorsGenerator(colorsFileTree) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt index 4d96f4194..14a1abd66 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt @@ -98,7 +98,7 @@ abstract class FilesGenerator( ) : ResourceGeneratorFeature { private val fileTree = info.commonResources.matching { - it.include("MR/files/**") + it.include("files/**") } override fun createCommonGenerator() = CommonFilesGenerator(fileTree) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt index 7bb961fd5..dd1b782bf 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt @@ -126,7 +126,7 @@ abstract class FontsGenerator( private val mrSettings: MRGenerator.MRSettings ) : ResourceGeneratorFeature { private val stringsFileTree = info.commonResources.matching { - it.include("MR/fonts/**.ttf", "MR/fonts/**.otf") + it.include("fonts/**.ttf", "fonts/**.otf") } override fun createCommonGenerator() = CommonFontsGenerator(stringsFileTree) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt index 289baf5ec..2ec94e511 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt @@ -103,7 +103,7 @@ abstract class ImagesGenerator( private val logger: Logger ) : ResourceGeneratorFeature { private val stringsFileTree = info.commonResources.matching { - it.include("MR/images/**/*.png", "MR/images/**/*.jpg", "MR/images/**/*.svg") + it.include("images/**/*.png", "images/**/*.jpg", "images/**/*.svg") } override fun createCommonGenerator() = diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt index 3f71c1b9f..0ea050d41 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt @@ -99,7 +99,7 @@ abstract class PluralsGenerator( private val mrSettings: MRGenerator.MRSettings ) : ResourceGeneratorFeature { private val stringsFileTree = - info.commonResources.matching { it.include("MR/**/plurals*.xml") } + info.commonResources.matching { it.include("**/plurals*.xml") } override fun createCommonGenerator(): PluralsGenerator = CommonPluralsGenerator(stringsFileTree, strictLineBreaks) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt index 4d9892cb8..67642615d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt @@ -79,7 +79,7 @@ abstract class StringsGenerator( private val mrSettings: MRGenerator.MRSettings ) : ResourceGeneratorFeature { private val stringsFileTree = - info.commonResources.matching { it.include("MR/**/strings*.xml") } + info.commonResources.matching { it.include("**/strings*.xml") } override fun createCommonGenerator() = CommonStringsGenerator(stringsFileTree, strictLineBreaks) From 2bdd8a04883d462c6fc74781587b4e117d1b63e3 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Mon, 31 Jul 2023 19:42:37 +0700 Subject: [PATCH 009/352] #530 update samples --- .../MR => moko-resources}/base/strings.xml | 0 .../MR => moko-resources}/base/strings.xml | 0 samples/compose-jvm-app/build.gradle.kts | 4 ++-- .../MR => moko-resources}/base/strings.xml | 0 .../compose-resources-gallery/.run/iosApp.run.xml | 2 +- samples/compose-resources-gallery/gradle.properties | 4 ++-- .../shared/src/commonMain/kotlin/App.kt | 1 - .../MR => moko-resources}/assets/some_asset.txt | 0 .../MR => moko-resources}/base/plurals.xml | 0 .../MR => moko-resources}/base/strings.xml | 0 .../MR => moko-resources}/colors/colors.xml | 0 .../MR => moko-resources}/files/some_file.txt | 0 .../fonts/cormorant-italic.otf | Bin .../MR => moko-resources}/images/car_black.svg | 0 .../MR => moko-resources}/images/moko_logo@1x.png | Bin .../MR => moko-resources}/images/moko_logo@2x.png | Bin .../MR => moko-resources}/images/moko_logo@3x.png | Bin .../{resources/MR => moko-resources}/ru/plurals.xml | 0 .../{resources/MR => moko-resources}/ru/strings.xml | 0 samples/ios-static-xcframework/build.gradle.kts | 2 +- .../MR => moko-resources}/base/strings.xml | 0 samples/kotlin-ios-app/build.gradle.kts | 2 +- samples/resources-gallery/build.gradle.kts | 4 ++-- .../mpp-library/test-utils/build.gradle.kts | 8 ++++---- 24 files changed, 13 insertions(+), 14 deletions(-) rename samples/android-mpp-app/app/src/commonMain/{resources/MR => moko-resources}/base/strings.xml (100%) rename samples/auto-manifest/mpp-library/src/commonMain/{resources/MR => moko-resources}/base/strings.xml (100%) rename samples/compose-jvm-app/common/src/commonMain/{resources/MR => moko-resources}/base/strings.xml (100%) rename samples/compose-resources-gallery/shared/src/commonMain/{resources/MR => moko-resources}/assets/some_asset.txt (100%) rename samples/compose-resources-gallery/shared/src/commonMain/{resources/MR => moko-resources}/base/plurals.xml (100%) rename samples/compose-resources-gallery/shared/src/commonMain/{resources/MR => moko-resources}/base/strings.xml (100%) rename samples/compose-resources-gallery/shared/src/commonMain/{resources/MR => moko-resources}/colors/colors.xml (100%) rename samples/compose-resources-gallery/shared/src/commonMain/{resources/MR => moko-resources}/files/some_file.txt (100%) rename samples/compose-resources-gallery/shared/src/commonMain/{resources/MR => moko-resources}/fonts/cormorant-italic.otf (100%) rename samples/compose-resources-gallery/shared/src/commonMain/{resources/MR => moko-resources}/images/car_black.svg (100%) rename samples/compose-resources-gallery/shared/src/commonMain/{resources/MR => moko-resources}/images/moko_logo@1x.png (100%) rename samples/compose-resources-gallery/shared/src/commonMain/{resources/MR => moko-resources}/images/moko_logo@2x.png (100%) rename samples/compose-resources-gallery/shared/src/commonMain/{resources/MR => moko-resources}/images/moko_logo@3x.png (100%) rename samples/compose-resources-gallery/shared/src/commonMain/{resources/MR => moko-resources}/ru/plurals.xml (100%) rename samples/compose-resources-gallery/shared/src/commonMain/{resources/MR => moko-resources}/ru/strings.xml (100%) rename samples/ios-static-xcframework/mpp-library/src/commonMain/{resources/MR => moko-resources}/base/strings.xml (100%) diff --git a/samples/android-mpp-app/app/src/commonMain/resources/MR/base/strings.xml b/samples/android-mpp-app/app/src/commonMain/moko-resources/base/strings.xml similarity index 100% rename from samples/android-mpp-app/app/src/commonMain/resources/MR/base/strings.xml rename to samples/android-mpp-app/app/src/commonMain/moko-resources/base/strings.xml diff --git a/samples/auto-manifest/mpp-library/src/commonMain/resources/MR/base/strings.xml b/samples/auto-manifest/mpp-library/src/commonMain/moko-resources/base/strings.xml similarity index 100% rename from samples/auto-manifest/mpp-library/src/commonMain/resources/MR/base/strings.xml rename to samples/auto-manifest/mpp-library/src/commonMain/moko-resources/base/strings.xml diff --git a/samples/compose-jvm-app/build.gradle.kts b/samples/compose-jvm-app/build.gradle.kts index ef52564f1..c0e56a292 100644 --- a/samples/compose-jvm-app/build.gradle.kts +++ b/samples/compose-jvm-app/build.gradle.kts @@ -7,7 +7,7 @@ buildscript { } dependencies { classpath(moko.resourcesGradlePlugin) - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10") - classpath("org.jetbrains.compose:compose-gradle-plugin:1.4.0") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.21") + classpath("org.jetbrains.compose:compose-gradle-plugin:1.4.3") } } diff --git a/samples/compose-jvm-app/common/src/commonMain/resources/MR/base/strings.xml b/samples/compose-jvm-app/common/src/commonMain/moko-resources/base/strings.xml similarity index 100% rename from samples/compose-jvm-app/common/src/commonMain/resources/MR/base/strings.xml rename to samples/compose-jvm-app/common/src/commonMain/moko-resources/base/strings.xml diff --git a/samples/compose-resources-gallery/.run/iosApp.run.xml b/samples/compose-resources-gallery/.run/iosApp.run.xml index a4c331d05..778f6afeb 100644 --- a/samples/compose-resources-gallery/.run/iosApp.run.xml +++ b/samples/compose-resources-gallery/.run/iosApp.run.xml @@ -1,5 +1,5 @@ - + diff --git a/samples/compose-resources-gallery/gradle.properties b/samples/compose-resources-gallery/gradle.properties index 227dfebe6..fc559bd79 100644 --- a/samples/compose-resources-gallery/gradle.properties +++ b/samples/compose-resources-gallery/gradle.properties @@ -14,6 +14,6 @@ kotlin.mpp.androidSourceSetLayoutVersion=2 kotlin.mpp.androidGradlePluginCompatibility.nowarn=true # Enable kotlin/native experimental memory model kotlin.native.binary.memoryModel=experimental -kotlin.version=1.8.20 +kotlin.version=1.8.21 agp.version=8.0.1 -compose.version=1.4.0 +compose.version=1.4.3 diff --git a/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt b/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt index 0f9591b61..8609d7379 100644 --- a/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt +++ b/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt @@ -6,7 +6,6 @@ import androidx.compose.material.* import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.unit.dp import com.icerockdev.library.MR diff --git a/samples/compose-resources-gallery/shared/src/commonMain/resources/MR/assets/some_asset.txt b/samples/compose-resources-gallery/shared/src/commonMain/moko-resources/assets/some_asset.txt similarity index 100% rename from samples/compose-resources-gallery/shared/src/commonMain/resources/MR/assets/some_asset.txt rename to samples/compose-resources-gallery/shared/src/commonMain/moko-resources/assets/some_asset.txt diff --git a/samples/compose-resources-gallery/shared/src/commonMain/resources/MR/base/plurals.xml b/samples/compose-resources-gallery/shared/src/commonMain/moko-resources/base/plurals.xml similarity index 100% rename from samples/compose-resources-gallery/shared/src/commonMain/resources/MR/base/plurals.xml rename to samples/compose-resources-gallery/shared/src/commonMain/moko-resources/base/plurals.xml diff --git a/samples/compose-resources-gallery/shared/src/commonMain/resources/MR/base/strings.xml b/samples/compose-resources-gallery/shared/src/commonMain/moko-resources/base/strings.xml similarity index 100% rename from samples/compose-resources-gallery/shared/src/commonMain/resources/MR/base/strings.xml rename to samples/compose-resources-gallery/shared/src/commonMain/moko-resources/base/strings.xml diff --git a/samples/compose-resources-gallery/shared/src/commonMain/resources/MR/colors/colors.xml b/samples/compose-resources-gallery/shared/src/commonMain/moko-resources/colors/colors.xml similarity index 100% rename from samples/compose-resources-gallery/shared/src/commonMain/resources/MR/colors/colors.xml rename to samples/compose-resources-gallery/shared/src/commonMain/moko-resources/colors/colors.xml diff --git a/samples/compose-resources-gallery/shared/src/commonMain/resources/MR/files/some_file.txt b/samples/compose-resources-gallery/shared/src/commonMain/moko-resources/files/some_file.txt similarity index 100% rename from samples/compose-resources-gallery/shared/src/commonMain/resources/MR/files/some_file.txt rename to samples/compose-resources-gallery/shared/src/commonMain/moko-resources/files/some_file.txt diff --git a/samples/compose-resources-gallery/shared/src/commonMain/resources/MR/fonts/cormorant-italic.otf b/samples/compose-resources-gallery/shared/src/commonMain/moko-resources/fonts/cormorant-italic.otf similarity index 100% rename from samples/compose-resources-gallery/shared/src/commonMain/resources/MR/fonts/cormorant-italic.otf rename to samples/compose-resources-gallery/shared/src/commonMain/moko-resources/fonts/cormorant-italic.otf diff --git a/samples/compose-resources-gallery/shared/src/commonMain/resources/MR/images/car_black.svg b/samples/compose-resources-gallery/shared/src/commonMain/moko-resources/images/car_black.svg similarity index 100% rename from samples/compose-resources-gallery/shared/src/commonMain/resources/MR/images/car_black.svg rename to samples/compose-resources-gallery/shared/src/commonMain/moko-resources/images/car_black.svg diff --git a/samples/compose-resources-gallery/shared/src/commonMain/resources/MR/images/moko_logo@1x.png b/samples/compose-resources-gallery/shared/src/commonMain/moko-resources/images/moko_logo@1x.png similarity index 100% rename from samples/compose-resources-gallery/shared/src/commonMain/resources/MR/images/moko_logo@1x.png rename to samples/compose-resources-gallery/shared/src/commonMain/moko-resources/images/moko_logo@1x.png diff --git a/samples/compose-resources-gallery/shared/src/commonMain/resources/MR/images/moko_logo@2x.png b/samples/compose-resources-gallery/shared/src/commonMain/moko-resources/images/moko_logo@2x.png similarity index 100% rename from samples/compose-resources-gallery/shared/src/commonMain/resources/MR/images/moko_logo@2x.png rename to samples/compose-resources-gallery/shared/src/commonMain/moko-resources/images/moko_logo@2x.png diff --git a/samples/compose-resources-gallery/shared/src/commonMain/resources/MR/images/moko_logo@3x.png b/samples/compose-resources-gallery/shared/src/commonMain/moko-resources/images/moko_logo@3x.png similarity index 100% rename from samples/compose-resources-gallery/shared/src/commonMain/resources/MR/images/moko_logo@3x.png rename to samples/compose-resources-gallery/shared/src/commonMain/moko-resources/images/moko_logo@3x.png diff --git a/samples/compose-resources-gallery/shared/src/commonMain/resources/MR/ru/plurals.xml b/samples/compose-resources-gallery/shared/src/commonMain/moko-resources/ru/plurals.xml similarity index 100% rename from samples/compose-resources-gallery/shared/src/commonMain/resources/MR/ru/plurals.xml rename to samples/compose-resources-gallery/shared/src/commonMain/moko-resources/ru/plurals.xml diff --git a/samples/compose-resources-gallery/shared/src/commonMain/resources/MR/ru/strings.xml b/samples/compose-resources-gallery/shared/src/commonMain/moko-resources/ru/strings.xml similarity index 100% rename from samples/compose-resources-gallery/shared/src/commonMain/resources/MR/ru/strings.xml rename to samples/compose-resources-gallery/shared/src/commonMain/moko-resources/ru/strings.xml diff --git a/samples/ios-static-xcframework/build.gradle.kts b/samples/ios-static-xcframework/build.gradle.kts index 77d5c8bb9..e7d4a7812 100644 --- a/samples/ios-static-xcframework/build.gradle.kts +++ b/samples/ios-static-xcframework/build.gradle.kts @@ -11,6 +11,6 @@ buildscript { } dependencies { classpath(moko.resourcesGradlePlugin) - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.21") } } diff --git a/samples/ios-static-xcframework/mpp-library/src/commonMain/resources/MR/base/strings.xml b/samples/ios-static-xcframework/mpp-library/src/commonMain/moko-resources/base/strings.xml similarity index 100% rename from samples/ios-static-xcframework/mpp-library/src/commonMain/resources/MR/base/strings.xml rename to samples/ios-static-xcframework/mpp-library/src/commonMain/moko-resources/base/strings.xml diff --git a/samples/kotlin-ios-app/build.gradle.kts b/samples/kotlin-ios-app/build.gradle.kts index 77d5c8bb9..e7d4a7812 100644 --- a/samples/kotlin-ios-app/build.gradle.kts +++ b/samples/kotlin-ios-app/build.gradle.kts @@ -11,6 +11,6 @@ buildscript { } dependencies { classpath(moko.resourcesGradlePlugin) - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.21") } } diff --git a/samples/resources-gallery/build.gradle.kts b/samples/resources-gallery/build.gradle.kts index ce7afffe5..dfaaa02e4 100644 --- a/samples/resources-gallery/build.gradle.kts +++ b/samples/resources-gallery/build.gradle.kts @@ -13,9 +13,9 @@ buildscript { } dependencies { classpath(moko.resourcesGradlePlugin) - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.21") classpath("com.android.tools.build:gradle:7.4.2") - classpath("org.jetbrains.compose:compose-gradle-plugin:1.4.0") + classpath("org.jetbrains.compose:compose-gradle-plugin:1.4.3") } } diff --git a/samples/resources-gallery/mpp-library/test-utils/build.gradle.kts b/samples/resources-gallery/mpp-library/test-utils/build.gradle.kts index 281d4e1c7..1dbab27e7 100644 --- a/samples/resources-gallery/mpp-library/test-utils/build.gradle.kts +++ b/samples/resources-gallery/mpp-library/test-utils/build.gradle.kts @@ -18,8 +18,8 @@ kotlin { sourceSets { val commonMain by getting { dependencies { - api("org.jetbrains.kotlin:kotlin-test:1.8.10") - api("org.jetbrains.kotlin:kotlin-test-annotations-common:1.8.10") + api("org.jetbrains.kotlin:kotlin-test:1.8.21") + api("org.jetbrains.kotlin:kotlin-test-annotations-common:1.8.21") api("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4") api(moko.resourcesTest) } @@ -27,13 +27,13 @@ kotlin { val jvmMain by getting { dependencies { - api("org.jetbrains.kotlin:kotlin-test-junit:1.8.10") + api("org.jetbrains.kotlin:kotlin-test-junit:1.8.21") } } val androidMain by getting { dependencies { - api("org.jetbrains.kotlin:kotlin-test-junit:1.8.10") + api("org.jetbrains.kotlin:kotlin-test-junit:1.8.21") api("androidx.test:core:1.5.0") api("org.robolectric:robolectric:4.10.3") api("junit:junit:4.13.2") From c0e25644f93f3e6c8681082e36677fc98612d443 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Mon, 31 Jul 2023 19:47:09 +0700 Subject: [PATCH 010/352] #530 fix imports --- .../resources/compose/internal/CGImageRef+Skia.kt | 11 +++++++++-- .../moko/resources/compose/internal/NSDataExt.kt | 1 - 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/resources-compose/src/appleMain/kotlin/dev/icerock/moko/resources/compose/internal/CGImageRef+Skia.kt b/resources-compose/src/appleMain/kotlin/dev/icerock/moko/resources/compose/internal/CGImageRef+Skia.kt index 924dd7c43..2db53b2a3 100644 --- a/resources-compose/src/appleMain/kotlin/dev/icerock/moko/resources/compose/internal/CGImageRef+Skia.kt +++ b/resources-compose/src/appleMain/kotlin/dev/icerock/moko/resources/compose/internal/CGImageRef+Skia.kt @@ -6,7 +6,10 @@ package dev.icerock.moko.resources.compose.internal import cnames.structs.CGColorSpace import cnames.structs.CGImage -import kotlinx.cinterop.* +import kotlinx.cinterop.CPointed +import kotlinx.cinterop.CPointer +import kotlinx.cinterop.CValue +import kotlinx.cinterop.refTo import org.jetbrains.skia.ColorAlphaType import org.jetbrains.skia.ColorType import org.jetbrains.skia.Image @@ -23,7 +26,11 @@ import platform.CoreGraphics.CGImageGetWidth import platform.CoreGraphics.CGImageRef import platform.CoreGraphics.CGRect import platform.CoreGraphics.CGRectMake -import platform.posix.* +import platform.posix.free +import platform.posix.malloc +import platform.posix.memcpy +import platform.posix.size_t +import platform.posix.uint32_t internal fun CGImageRef.toSkiaImage(): Image { val cgImage: CPointer = this diff --git a/resources-compose/src/appleMain/kotlin/dev/icerock/moko/resources/compose/internal/NSDataExt.kt b/resources-compose/src/appleMain/kotlin/dev/icerock/moko/resources/compose/internal/NSDataExt.kt index 259dfe55c..7a891f551 100644 --- a/resources-compose/src/appleMain/kotlin/dev/icerock/moko/resources/compose/internal/NSDataExt.kt +++ b/resources-compose/src/appleMain/kotlin/dev/icerock/moko/resources/compose/internal/NSDataExt.kt @@ -9,7 +9,6 @@ import kotlinx.cinterop.usePinned import platform.Foundation.NSData import platform.posix.memcpy - internal fun NSData.toByteArray(): ByteArray { return ByteArray(this@toByteArray.length.toInt()).apply { usePinned { pinned -> From 49af2d26c884dbd8c5d42f3611a753929330a4b9 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Mon, 31 Jul 2023 19:50:06 +0700 Subject: [PATCH 011/352] #530 update readme --- README.md | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index dc335052c..b18183304 100755 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ buildscript { } dependencies { - classpath "dev.icerock.moko:resources-generator:0.23.0" + classpath "dev.icerock.moko:resources-generator:0.24.0" } } @@ -80,10 +80,10 @@ project build.gradle apply plugin: "dev.icerock.mobile.multiplatform-resources" dependencies { - commonMainApi("dev.icerock.moko:resources:0.23.0") - commonMainApi("dev.icerock.moko:resources-compose:0.23.0") // for compose multiplatform + commonMainApi("dev.icerock.moko:resources:0.24.0") + commonMainApi("dev.icerock.moko:resources-compose:0.24.0") // for compose multiplatform - commonTestImplementation("dev.icerock.moko:resources-test:0.23.0") + commonTestImplementation("dev.icerock.moko:resources-test:0.24.0") } multiplatformResources { @@ -102,7 +102,7 @@ should [add `export` declarations](https://kotlinlang.org/docs/multiplatform-bui ``` framework { - export("dev.icerock.moko:resources:0.23.0") + export("dev.icerock.moko:resources:0.24.0") export("dev.icerock.moko:graphics:0.9.0") // toUIColor here } ``` @@ -226,7 +226,7 @@ Details you can check in sample `samples/ios-static-xcframework`. ### Example 1 - simple localization string -The first step is a create a file `strings.xml` in `commonMain/resources/MR/base` with the following +The first step is a create a file `strings.xml` in `commonMain/moko-resources/base` with the following content: ```xml @@ -237,8 +237,8 @@ content: ``` Next - create a file `strings.xml` with localized strings -in `commonMain/resource/MR/`. Here's an example of -creating `commonMain/resource/MR/ru` for a Russian localization: +in `commonMain/moko-resources/`. Here's an example of +creating `commonMain/moko-resources/ru` for a Russian localization: ```xml @@ -332,7 +332,7 @@ Note: more info in issue [#126](https://github.com/icerockdev/moko-resources/iss ### Example 2 - formatted localization string -In `commonMain/resources/MR/base/strings.xml` add: +In `commonMain/moko-resources/base/strings.xml` add: ```xml @@ -377,7 +377,7 @@ different behaviour on different platforms. Stick to one style for each string. ### Example 3 - plural string -The first step is to create a file `plurals.xml` in `commonMain/resources/MR/base` with the +The first step is to create a file `plurals.xml` in `commonMain/moko-resources/base` with the following content: ```xml @@ -418,7 +418,7 @@ let string = getMyPluralDesc(quantity: 10).localized() ### Example 4 - plural formatted string -The first step is to create file `plurals.xml` in `commonMain/resources/MR/base` with the following +The first step is to create file `plurals.xml` in `commonMain/moko-resources/base` with the following content: ```xml @@ -513,7 +513,7 @@ StringDesc.localeType = StringDesc.LocaleType.System ### Example 7 - Shared Images -Place images in the `commonMain/resources/MR/images` directory. Nested directories are also supported. +Place images in the `commonMain/moko-resources/images` directory. Nested directories are also supported. #### png and jpg @@ -526,7 +526,7 @@ Image names should end with one of: - `@3x` - android xxhdpi, ios 3x; - `@4x` - android xxxhdpi. -If we add the following files to `commonMain/resources/MR/images`: +If we add the following files to `commonMain/moko-resources/images`: - `home_black_18@1x.png` - `home_black_18@2x.png` @@ -540,7 +540,7 @@ Then we get an autogenerated `MR.images.home_black_18` `ImageResource` in code. The Image generator also supports `svg` files. -If we add the following file to `commonMain/resources/MR/images`: +If we add the following file to `commonMain/moko-resources/images`: - `car_black.svg` @@ -600,7 +600,7 @@ Image(resource: \.home_black_18) ### Example 8 - pass font -Fonts resources directory is `commonMain/resources/MR/fonts`. +Fonts resources directory is `commonMain/moko-resources/fonts`. Font name should be this pattern: `-` like: - `Raleway-Bold.ttf` @@ -608,7 +608,7 @@ Font name should be this pattern: `-` like: - `Raleway-Italic.ttf` Supports `ttf` and `otf` resources. -If we add to `commonMain/resources/MR/fonts` files: +If we add to `commonMain/moko-resources/fonts` files: - `Raleway-Bold.ttf` - `Raleway-Regular.ttf` @@ -640,7 +640,7 @@ val font: Font = MR.fonts.Raleway.italic.asFont( ### Example 9 - pass colors -Colors resources directory is `commonMain/resources/MR/colors`. +Colors resources directory is `commonMain/moko-resources/colors`. Colors files is `xml` with format: ```xml @@ -740,7 +740,7 @@ val color: Color = colorResource(MR.colors.valueColor) ### Example 10 - plain file resource access The first step is a create a resource file `test.txt` for example, -in `commonMain/resources/MR/files` +in `commonMain/moko-resources/files` After gradle sync we can get file by id `MR.files.test` Moko-resources has out of box implementation function for read text files from common code - `readText()` @@ -770,7 +770,7 @@ val fileContent: String? by MR.files.test.readTextAsState() ### Example 11 - assets access Assets allow you save directories hierarchy (in files structure is plain). Locate files -to `commonMain/resources/MR/assets` and access to it by `MR.assets.*` +to `commonMain/moko-resources/assets` and access to it by `MR.assets.*` #### Compose Multiplatform From c98137b032cb20ff6976f6f076ed3f395fa3c76b Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Wed, 2 Aug 2023 12:45:13 +0700 Subject: [PATCH 012/352] #530 reformat --- .../src/main/kotlin/apple-main-convention.gradle.kts | 4 ++-- .../src/main/kotlin/detekt-convention.gradle.kts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/resources-build-logic/src/main/kotlin/apple-main-convention.gradle.kts b/resources-build-logic/src/main/kotlin/apple-main-convention.gradle.kts index 8d1d8e508..b03697149 100644 --- a/resources-build-logic/src/main/kotlin/apple-main-convention.gradle.kts +++ b/resources-build-logic/src/main/kotlin/apple-main-convention.gradle.kts @@ -8,7 +8,7 @@ plugins { kotlin { sourceSets { - val commonMain by getting {} + val commonMain by getting val appleMain by creating { dependsOn(commonMain) @@ -20,7 +20,7 @@ kotlin { dependsOn(appleMain) } - val commonTest by getting {} + val commonTest by getting val appleTest by creating { dependsOn(commonTest) } diff --git a/resources-build-logic/src/main/kotlin/detekt-convention.gradle.kts b/resources-build-logic/src/main/kotlin/detekt-convention.gradle.kts index 9345c920d..9ae55c5ee 100644 --- a/resources-build-logic/src/main/kotlin/detekt-convention.gradle.kts +++ b/resources-build-logic/src/main/kotlin/detekt-convention.gradle.kts @@ -7,7 +7,7 @@ plugins { } detekt { - input.setFrom( + source.setFrom( "src/commonMain/kotlin", "src/androidMain/kotlin", "src/iosMain/kotlin", From 9fcfb7976d9ff4ab843338e0889377903f2058cc Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Wed, 2 Aug 2023 17:33:56 +0700 Subject: [PATCH 013/352] #530 update sample --- .../gradle.properties | 2 +- .../src/commonMain/kotlin/Main.macos.kt | 2 ++ .../shared/build.gradle.kts | 5 ++--- .../shared/src/commonMain/kotlin/App.kt | 20 ++++++++++++++++--- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/samples/compose-resources-gallery/gradle.properties b/samples/compose-resources-gallery/gradle.properties index fc559bd79..fab8ca620 100644 --- a/samples/compose-resources-gallery/gradle.properties +++ b/samples/compose-resources-gallery/gradle.properties @@ -14,6 +14,6 @@ kotlin.mpp.androidSourceSetLayoutVersion=2 kotlin.mpp.androidGradlePluginCompatibility.nowarn=true # Enable kotlin/native experimental memory model kotlin.native.binary.memoryModel=experimental -kotlin.version=1.8.21 +kotlin.version=1.9.0 agp.version=8.0.1 compose.version=1.4.3 diff --git a/samples/compose-resources-gallery/macosApp/src/commonMain/kotlin/Main.macos.kt b/samples/compose-resources-gallery/macosApp/src/commonMain/kotlin/Main.macos.kt index 83f54f088..8e19e8e6d 100644 --- a/samples/compose-resources-gallery/macosApp/src/commonMain/kotlin/Main.macos.kt +++ b/samples/compose-resources-gallery/macosApp/src/commonMain/kotlin/Main.macos.kt @@ -1,6 +1,7 @@ import androidx.compose.ui.window.Window import com.icerockdev.library.MR import dev.icerock.moko.resources.desc.desc +import kotlinx.cinterop.ExperimentalForeignApi import kotlinx.cinterop.staticCFunction import platform.AppKit.NSApplication import platform.AppKit.NSApplicationActivationPolicy @@ -8,6 +9,7 @@ import platform.AppKit.NSApplicationDelegateProtocol import platform.darwin.NSObject import platform.objc.objc_setUncaughtExceptionHandler +@OptIn(ExperimentalForeignApi::class) @Suppress("UNUSED_PARAMETER") fun main(args: Array) { setUnhandledExceptionHook { diff --git a/samples/compose-resources-gallery/shared/build.gradle.kts b/samples/compose-resources-gallery/shared/build.gradle.kts index 987c70f16..4f0d6179d 100644 --- a/samples/compose-resources-gallery/shared/build.gradle.kts +++ b/samples/compose-resources-gallery/shared/build.gradle.kts @@ -51,9 +51,9 @@ kotlin { } val androidMain by getting { dependencies { - api("androidx.activity:activity-compose:1.7.1") + api("androidx.activity:activity-compose:1.7.2") api("androidx.appcompat:appcompat:1.6.1") - api("androidx.core:core-ktx:1.10.0") + api("androidx.core:core-ktx:1.10.1") } } val iosMain by getting @@ -85,7 +85,6 @@ kotlin { android { compileSdk = 33 sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml") - sourceSets["main"].res.srcDirs("src/androidMain/res") defaultConfig { minSdk = 26 diff --git a/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt b/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt index 8609d7379..8ebd2b219 100644 --- a/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt +++ b/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt @@ -1,9 +1,23 @@ import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.isSystemInDarkTheme -import androidx.compose.foundation.layout.* -import androidx.compose.material.* -import androidx.compose.runtime.* +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.material.Button +import androidx.compose.material.MaterialTheme +import androidx.compose.material.OutlinedTextField +import androidx.compose.material.Text +import androidx.compose.material.TextFieldDefaults +import androidx.compose.material.darkColors +import androidx.compose.material.lightColors +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.ColorFilter From 4611270b1d80c28229ff5490ac9f1903d8b3cf19 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Wed, 2 Aug 2023 17:35:30 +0700 Subject: [PATCH 014/352] #530 change package for resource, add kotlin folder --- .../main/kotlin/dev/icerock/gradle/AndroidPluginLogic.kt | 8 ++++++-- .../dev/icerock/gradle/MultiplatformResourcesPlugin.kt | 2 +- .../kotlin/dev/icerock/gradle/generator/MRGenerator.kt | 2 +- .../dev/icerock/gradle/utils/ProcessResourcesUtils.kt | 4 ++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/AndroidPluginLogic.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/AndroidPluginLogic.kt index 2e75c16c0..f22363cd9 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/AndroidPluginLogic.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/AndroidPluginLogic.kt @@ -10,6 +10,8 @@ import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.ResourceGeneratorFeature import dev.icerock.gradle.generator.android.AndroidMRGenerator import dev.icerock.gradle.utils.isDependsOn +import java.io.File +import java.util.Locale import org.gradle.api.Action import org.gradle.api.Project import org.gradle.api.Task @@ -17,7 +19,6 @@ import org.gradle.kotlin.dsl.getByType import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import org.jetbrains.kotlin.gradle.plugin.KotlinTarget import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget -import java.io.File internal class AndroidPluginLogic( private val commonSourceSet: KotlinSourceSet, @@ -72,9 +73,12 @@ internal class AndroidPluginLogic( ): MRGenerator.SourceSet { return object : MRGenerator.SourceSet { override val name: String - get() = "android${androidSourceSet.name.capitalize()}" + get() = "android${androidSourceSet.name.replaceFirstChar { + if (it.isLowerCase()) it.titlecase(Locale.ROOT) else it.toString() } + }" override fun addSourceDir(directory: File) { + androidSourceSet.kotlin.srcDirs(directory) kotlinSourceSets.forEach { it.kotlin.srcDir(directory) } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index c8d30c2cd..091bc1929 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -81,7 +81,7 @@ abstract class MultiplatformResourcesPlugin : Plugin { val commonSourceSet: KotlinSourceSet = multiplatformExtension.sourceSets.getByName(mrExtension.sourceSetName) val commonResources: SourceDirectorySet = getObjectFactory() .sourceDirectorySet("moko-resources", "moko-resources") - commonResources.srcDir("${target.projectDir}/src/${commonSourceSet.name}/moko-resources") + commonResources.srcDirs(File(target.projectDir,"/src/${commonSourceSet.name}/moko-resources")) val generatedDir = File(target.buildDir, "generated/moko-resources") val mrClassPackage: String = requireNotNull(mrExtension.multiplatformResourcesPackage) { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt index f708194b7..0f91bf549 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt @@ -23,7 +23,7 @@ abstract class MRGenerator( internal val generators: List ) { - internal val outputDir = File(generatedDir, sourceSet.name) + internal val outputDir = File(generatedDir, "${sourceSet.name}/kotlin") protected open val sourcesGenerationDir get() = File(outputDir, "src") protected open val resourcesGenerationDir diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProcessResourcesUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProcessResourcesUtils.kt index 19bf13c63..5aacc247a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProcessResourcesUtils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProcessResourcesUtils.kt @@ -22,8 +22,8 @@ fun dependsOnProcessResources( .configureEach { processResourcesTask -> processResourcesTask.exclude { val path: String = it.file.absolutePath - if (shouldExcludeGenerated && path.contains("generated/moko")) return@exclude true - if (path.contains("resources/MR")) return@exclude true + if (shouldExcludeGenerated && path.contains("generated/moko-resources")) return@exclude true + if (path.contains("moko-resources")) return@exclude true false } processResourcesTask.dependsOn(task) From 9dbc81daf8dea7e38cc120d0b3e36dc6dd870baa Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Thu, 3 Aug 2023 12:14:08 +0700 Subject: [PATCH 015/352] #530 fix android sourceSet --- .../kotlin/dev/icerock/gradle/AndroidPluginLogic.kt | 1 + .../dev/icerock/gradle/MultiplatformResourcesPlugin.kt | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/AndroidPluginLogic.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/AndroidPluginLogic.kt index f22363cd9..5a24933ea 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/AndroidPluginLogic.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/AndroidPluginLogic.kt @@ -79,6 +79,7 @@ internal class AndroidPluginLogic( override fun addSourceDir(directory: File) { androidSourceSet.kotlin.srcDirs(directory) + androidSourceSet.java.srcDirs(directory) kotlinSourceSets.forEach { it.kotlin.srcDir(directory) } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 091bc1929..503f7427b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -233,9 +233,9 @@ abstract class MultiplatformResourcesPlugin : Plugin { val commonGeneratorSourceSet: MRGenerator.SourceSet = createSourceSet(commonSourceSet) return CommonMRGenerator( - generatedDir, - commonGeneratorSourceSet, - mrSettings, + generatedDir = generatedDir, + sourceSet = commonGeneratorSourceSet, + mrSettings = mrSettings, generators = features.map { it.createCommonGenerator() } ).apply(target) } @@ -283,8 +283,8 @@ abstract class MultiplatformResourcesPlugin : Plugin { kotlinSourceSets.forEach { (compilation, kotlinSourceSet) -> JsMRGenerator( - generatedDir, - createSourceSet(kotlinSourceSet), + generatedDir = generatedDir, + sourceSet = createSourceSet(kotlinSourceSet), mrSettings = mrSettings, generators = features.map { it.createJsGenerator() }, compilation = compilation From ea54a40cb4694c955a8d4422e866d854c51c51ca Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Thu, 3 Aug 2023 20:05:24 +0700 Subject: [PATCH 016/352] #530 fixed desktop, js targets, fixes after review --- gradle/libs.versions.toml | 2 +- resources-generator/build.gradle.kts | 2 +- .../dev/icerock/gradle/AndroidPluginLogic.kt | 20 ++++--------------- .../gradle/generator/ColorsGenerator.kt | 2 +- .../icerock/gradle/generator/MRGenerator.kt | 2 +- .../generator/apple/AppleMRGenerator.kt | 7 ------- .../gradle/generator/js/JsMRGenerator.kt | 1 - .../gradle/generator/jvm/JvmMRGenerator.kt | 2 -- .../gradle/utils/ProcessResourcesUtils.kt | 7 ------- samples/compose-jvm-app/build.gradle.kts | 2 +- .../shared/src/commonMain/kotlin/App.kt | 6 +++++- 11 files changed, 14 insertions(+), 39 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index df826a182..e01a26419 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -kotlinVersion = "1.8.21" +kotlinVersion = "1.8.22" androidGradleVersion = "8.0.2" androidSdkCommonVersion = "31.1.0" diff --git a/resources-generator/build.gradle.kts b/resources-generator/build.gradle.kts index ed039e0ea..2a9e6f14c 100644 --- a/resources-generator/build.gradle.kts +++ b/resources-generator/build.gradle.kts @@ -3,7 +3,7 @@ */ plugins { - id("org.jetbrains.kotlin.jvm") version ("1.8.21") + id("org.jetbrains.kotlin.jvm") version ("1.8.22") id("detekt-convention") id("publication-convention") id("com.gradle.plugin-publish") version ("1.2.0") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/AndroidPluginLogic.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/AndroidPluginLogic.kt index 5a24933ea..4c5143291 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/AndroidPluginLogic.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/AndroidPluginLogic.kt @@ -26,19 +26,10 @@ internal class AndroidPluginLogic( private val generatedDir: File, private val mrSettings: MRGenerator.MRSettings, private val features: List>, - private val project: Project + private val project: Project, ) { fun setup(androidMainSourceSet: AndroidSourceSet) { - val kotlinSourceSets: List = targets - .filterIsInstance() - .flatMap { it.compilations } - .filter { compilation -> - compilation.kotlinSourceSets.any { it.isDependsOn(commonSourceSet) } - } - .map { it.defaultSourceSet } - - val androidSourceSet: MRGenerator.SourceSet = - createSourceSet(androidMainSourceSet, kotlinSourceSets) + val androidSourceSet: MRGenerator.SourceSet = createSourceSet(androidMainSourceSet) setAssetsDirsRefresh() @@ -69,18 +60,15 @@ internal class AndroidPluginLogic( private fun createSourceSet( androidSourceSet: AndroidSourceSet, - kotlinSourceSets: List ): MRGenerator.SourceSet { return object : MRGenerator.SourceSet { override val name: String - get() = "android${androidSourceSet.name.replaceFirstChar { - if (it.isLowerCase()) it.titlecase(Locale.ROOT) else it.toString() } + get() = "android${ + androidSourceSet.name.replaceFirstChar { it.uppercase() } }" override fun addSourceDir(directory: File) { - androidSourceSet.kotlin.srcDirs(directory) androidSourceSet.java.srcDirs(directory) - kotlinSourceSets.forEach { it.kotlin.srcDir(directory) } } override fun addResourcesDir(directory: File) { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt index c56f73e4d..701f68450 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt @@ -140,7 +140,7 @@ abstract class ColorsGenerator( ) : ResourceGeneratorFeature { private val colorsFileTree = - info.commonResources.matching { it.include("colors/colors*.xml") } + info.commonResources.matching { it.include("**/colors*.xml") } override fun createCommonGenerator() = CommonColorsGenerator(colorsFileTree) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt index 0f91bf549..f708194b7 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt @@ -23,7 +23,7 @@ abstract class MRGenerator( internal val generators: List ) { - internal val outputDir = File(generatedDir, "${sourceSet.name}/kotlin") + internal val outputDir = File(generatedDir, sourceSet.name) protected open val sourcesGenerationDir get() = File(outputDir, "src") protected open val resourcesGenerationDir diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt index 0c473706a..d00eeb9d9 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt @@ -96,13 +96,6 @@ class AppleMRGenerator( setupFrameworkResources() setupTestsResources() setupFatFrameworkTasks() - - dependsOnProcessResources( - project = project, - sourceSet = sourceSet, - task = generationTask, - shouldExcludeGenerated = true - ) } override fun beforeMRGeneration() { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt index adbc3f986..3c796c2f8 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt @@ -99,7 +99,6 @@ class JsMRGenerator( project = project, sourceSet = sourceSet, task = generationTask, - shouldExcludeGenerated = true ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt index 1a53704c0..0a7c697b9 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt @@ -76,14 +76,12 @@ class JvmMRGenerator( it.dependsOn(generationTask) } project.tasks.withType().configureEach { - it.exclude("MR/**") it.dependsOn(generationTask) } dependsOnProcessResources( project = project, sourceSet = sourceSet, task = generationTask, - shouldExcludeGenerated = false ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProcessResourcesUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProcessResourcesUtils.kt index 5aacc247a..d05c63153 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProcessResourcesUtils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProcessResourcesUtils.kt @@ -14,18 +14,11 @@ fun dependsOnProcessResources( project: Project, sourceSet: MRGenerator.SourceSet, task: Task, - shouldExcludeGenerated: Boolean ) { project.tasks .matching { it.name == sourceSet.name.removeSuffix("Main") + "ProcessResources" } .withType() .configureEach { processResourcesTask -> - processResourcesTask.exclude { - val path: String = it.file.absolutePath - if (shouldExcludeGenerated && path.contains("generated/moko-resources")) return@exclude true - if (path.contains("moko-resources")) return@exclude true - false - } processResourcesTask.dependsOn(task) } } diff --git a/samples/compose-jvm-app/build.gradle.kts b/samples/compose-jvm-app/build.gradle.kts index c0e56a292..113c074b7 100644 --- a/samples/compose-jvm-app/build.gradle.kts +++ b/samples/compose-jvm-app/build.gradle.kts @@ -7,7 +7,7 @@ buildscript { } dependencies { classpath(moko.resourcesGradlePlugin) - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.21") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.22") classpath("org.jetbrains.compose:compose-gradle-plugin:1.4.3") } } diff --git a/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt b/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt index 8ebd2b219..34854f96c 100644 --- a/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt +++ b/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt @@ -23,7 +23,11 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.unit.dp import com.icerockdev.library.MR -import dev.icerock.moko.resources.compose.* +import dev.icerock.moko.resources.compose.colorResource +import dev.icerock.moko.resources.compose.fontFamilyResource +import dev.icerock.moko.resources.compose.painterResource +import dev.icerock.moko.resources.compose.readTextAsState +import dev.icerock.moko.resources.compose.stringResource @Composable internal fun App() { From 36d7582404a5e3c7b14ca0bd34b92c8ef4609ca9 Mon Sep 17 00:00:00 2001 From: viktor kuzmin Date: Thu, 3 Aug 2023 17:50:53 +0300 Subject: [PATCH 017/352] refactoring --- gradle/libs.versions.toml | 2 +- samples/compose-jvm-app/build.gradle.kts | 2 +- samples/resources-gallery/build.gradle.kts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 9475bee84..5c65378c5 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -16,7 +16,7 @@ composeVersion = "1.5.0-rc01" composeActivityVersion = "1.7.1" # jetbrains compose -composeJetbrainsVersion = "1.5.0-dev1122" +composeJetbrainsVersion = "1.5.0-beta01" # jvm apacheCommonsTextVersion = "1.10.0" diff --git a/samples/compose-jvm-app/build.gradle.kts b/samples/compose-jvm-app/build.gradle.kts index 7ecb9f62f..34e7e08a1 100644 --- a/samples/compose-jvm-app/build.gradle.kts +++ b/samples/compose-jvm-app/build.gradle.kts @@ -8,6 +8,6 @@ buildscript { dependencies { classpath(moko.resourcesGradlePlugin) classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0") - classpath("org.jetbrains.compose:compose-gradle-plugin:1.4.0") + classpath("org.jetbrains.compose:compose-gradle-plugin:1.5.0-beta01") } } diff --git a/samples/resources-gallery/build.gradle.kts b/samples/resources-gallery/build.gradle.kts index 66d3b63f5..9130ddc21 100644 --- a/samples/resources-gallery/build.gradle.kts +++ b/samples/resources-gallery/build.gradle.kts @@ -15,7 +15,7 @@ buildscript { classpath(moko.resourcesGradlePlugin) classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0") classpath("com.android.tools.build:gradle:7.4.2") - classpath("org.jetbrains.compose:compose-gradle-plugin:1.5.0-dev1122") + classpath("org.jetbrains.compose:compose-gradle-plugin:1.5.0-beta01") } } From 6321baa16b96c1f7e04659f7ea113a5fac4b8f1d Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Tue, 8 Aug 2023 11:30:09 +0700 Subject: [PATCH 018/352] #530 rework generation logic --- .../kotlin/android-base-convention.gradle.kts | 4 +- ...ultiplatform-library-convention.gradle.kts | 2 +- resources-generator/build.gradle.kts | 2 +- .../gradle/MultiplatformResourcesPlugin.kt | 91 ++++++++++++++----- .../desktopApp/build.gradle.kts | 2 +- .../shared/build.gradle.kts | 11 +-- 6 files changed, 79 insertions(+), 33 deletions(-) diff --git a/resources-build-logic/src/main/kotlin/android-base-convention.gradle.kts b/resources-build-logic/src/main/kotlin/android-base-convention.gradle.kts index d6f8fa3e9..2d4650668 100644 --- a/resources-build-logic/src/main/kotlin/android-base-convention.gradle.kts +++ b/resources-build-logic/src/main/kotlin/android-base-convention.gradle.kts @@ -13,7 +13,7 @@ configure { } compileOptions { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } } diff --git a/resources-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts b/resources-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts index 199914a05..72b78da91 100644 --- a/resources-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts +++ b/resources-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts @@ -52,7 +52,7 @@ kotlin { jsTest.dependsOn(commonTest) } - jvmToolchain(11) + jvmToolchain(17) } tasks.withType { diff --git a/resources-generator/build.gradle.kts b/resources-generator/build.gradle.kts index 2a9e6f14c..42a5fadef 100644 --- a/resources-generator/build.gradle.kts +++ b/resources-generator/build.gradle.kts @@ -31,7 +31,7 @@ java { } kotlin { - jvmToolchain(11) + jvmToolchain(17) } gradlePlugin { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 503f7427b..d14053923 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -32,6 +32,7 @@ import org.gradle.kotlin.dsl.create import org.gradle.kotlin.dsl.getByType import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import org.jetbrains.kotlin.gradle.dsl.kotlinExtension import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation import org.jetbrains.kotlin.gradle.plugin.KotlinMultiplatformPluginWrapper import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet @@ -45,6 +46,12 @@ import org.jetbrains.kotlin.konan.target.HostManager import java.io.File import javax.inject.Inject import javax.xml.parsers.DocumentBuilderFactory +import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension +import org.jetbrains.kotlin.gradle.plugin.extraProperties +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation +import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.targets +import org.jetbrains.kotlin.gradle.targets.native.tasks.artifact.kotlinArtifactsExtension +import org.jetbrains.kotlin.gradle.utils.ObservableSet @Suppress("TooManyFunctions") abstract class MultiplatformResourcesPlugin : Plugin { @@ -58,17 +65,37 @@ abstract class MultiplatformResourcesPlugin : Plugin { ) mrExtension.multiplatformResourcesPackage = "${target.group}.${target.name}" - target.plugins.withType(KotlinMultiplatformPluginWrapper::class) { - val multiplatformExtension = - target.extensions.getByType(KotlinMultiplatformExtension::class) + target.plugins.withType(KotlinMultiplatformPluginWrapper::class) { _ -> + val multiplatformExtension = target.extensions.getByType( + type = KotlinMultiplatformExtension::class + ) - target.afterEvaluate { - configureGenerators( - target = target, - mrExtension = mrExtension, - multiplatformExtension = multiplatformExtension - ) + target.kotlinExtension.targets.forEach {kotlinTarget -> + kotlinTarget.compilations.configureEach { compilation -> + compilation.kotlinSourceSetsObservable.whenObjectAdded { + configureGenerators( + target = target, + mrExtension = mrExtension, + multiplatformExtension = multiplatformExtension + ) + } + } } +// target.kotlinExtension.sourceSets.configureEach { +// configureGenerators( +// target = target, +// mrExtension = mrExtension, +// multiplatformExtension = multiplatformExtension +// ) +// } + +// target.afterEvaluate { +// configureGenerators( +// target = target, +// mrExtension = mrExtension, +// multiplatformExtension = multiplatformExtension +// ) +// } } } @@ -76,12 +103,23 @@ abstract class MultiplatformResourcesPlugin : Plugin { private fun configureGenerators( target: Project, mrExtension: MultiplatformResourcesPluginExtension, - multiplatformExtension: KotlinMultiplatformExtension + multiplatformExtension: KotlinMultiplatformExtension, ) { val commonSourceSet: KotlinSourceSet = multiplatformExtension.sourceSets.getByName(mrExtension.sourceSetName) - val commonResources: SourceDirectorySet = getObjectFactory() - .sourceDirectorySet("moko-resources", "moko-resources") - commonResources.srcDirs(File(target.projectDir,"/src/${commonSourceSet.name}/moko-resources")) + val commonResources: SourceDirectorySet = getObjectFactory().sourceDirectorySet( + "moko-resources", + "moko-resources" + ) + commonResources.srcDirs( + File( + target.projectDir, + buildString { + append("/src/") + append(commonSourceSet.name) + append("/moko-resources") + } + ) + ) val generatedDir = File(target.buildDir, "generated/moko-resources") val mrClassPackage: String = requireNotNull(mrExtension.multiplatformResourcesPackage) { @@ -137,7 +175,10 @@ abstract class MultiplatformResourcesPlugin : Plugin { target = target ) - listOf("com.android.library", "com.android.application").forEach { id -> + listOf( + "com.android.library", + "com.android.application" + ).forEach { id -> target.plugins.withId(id) { setupAndroidGenerator( target = target, @@ -196,7 +237,7 @@ abstract class MultiplatformResourcesPlugin : Plugin { generatedDir: File, mrSettings: MRGenerator.MRSettings, features: List>, - sourceInfo: SourceInfo + sourceInfo: SourceInfo, ) { val androidExtension = target.extensions.getByType(BaseExtension::class) @@ -228,7 +269,7 @@ abstract class MultiplatformResourcesPlugin : Plugin { generatedDir: File, mrSettings: MRGenerator.MRSettings, features: List>, - target: Project + target: Project, ): GenerateMultiplatformResourcesTask { val commonGeneratorSourceSet: MRGenerator.SourceSet = createSourceSet(commonSourceSet) @@ -247,7 +288,7 @@ abstract class MultiplatformResourcesPlugin : Plugin { generatedDir: File, mrSettings: MRGenerator.MRSettings, features: List>, - target: Project + target: Project, ) { val kotlinSourceSets: List = targets .filterIsInstance() @@ -272,7 +313,7 @@ abstract class MultiplatformResourcesPlugin : Plugin { generatedDir: File, mrSettings: MRGenerator.MRSettings, features: List>, - target: Project + target: Project, ) { val kotlinSourceSets: List> = targets .filterIsInstance() @@ -300,9 +341,9 @@ abstract class MultiplatformResourcesPlugin : Plugin { mrSettings: MRGenerator.MRSettings, features: List>, target: Project, - iosLocalizationRegion: String + iosLocalizationRegion: String, ) { - val compilations = targets + val compilations: List = targets .filterIsInstance() .filter { it.konanTarget.family.isAppleFamily } .map { kotlinNativeTarget -> @@ -310,13 +351,13 @@ abstract class MultiplatformResourcesPlugin : Plugin { .getByName(KotlinCompilation.MAIN_COMPILATION_NAME) } - val defSourceSets = compilations.map { it.defaultSourceSet } + val defSourceSets: List = compilations.map { it.defaultSourceSet } .filter { it.isDependsOn(commonSourceSet) } compilations.forEach { compilation -> val kss = compilation.defaultSourceSet val depend = kss.getDependedFrom(defSourceSets) - val sourceSet = createSourceSet(depend ?: kss) + val sourceSet: MRGenerator.SourceSet = createSourceSet(depend ?: kss) AppleMRGenerator( generatedDir = generatedDir, sourceSet = sourceSet, @@ -379,3 +420,9 @@ abstract class MultiplatformResourcesPlugin : Plugin { return manifest.attributes.getNamedItem("package").textContent } } + +internal val KotlinCompilation<*>.allKotlinSourceSetsObservable + get() = this.allKotlinSourceSets as ObservableSet + +internal val KotlinCompilation<*>.kotlinSourceSetsObservable + get() = this.kotlinSourceSets as ObservableSet \ No newline at end of file diff --git a/samples/compose-resources-gallery/desktopApp/build.gradle.kts b/samples/compose-resources-gallery/desktopApp/build.gradle.kts index 49733564d..ced437d22 100644 --- a/samples/compose-resources-gallery/desktopApp/build.gradle.kts +++ b/samples/compose-resources-gallery/desktopApp/build.gradle.kts @@ -7,7 +7,7 @@ plugins { } kotlin { - jvm {} + jvm() sourceSets { val jvmMain by getting { dependencies { diff --git a/samples/compose-resources-gallery/shared/build.gradle.kts b/samples/compose-resources-gallery/shared/build.gradle.kts index 4f0d6179d..e0197ddb3 100644 --- a/samples/compose-resources-gallery/shared/build.gradle.kts +++ b/samples/compose-resources-gallery/shared/build.gradle.kts @@ -11,20 +11,19 @@ plugins { version = "1.0-SNAPSHOT" kotlin { - android() - - jvm("desktop") + androidTarget() ios() iosSimulatorArm64() + macosArm64() + macosX64() + + jvm("desktop") js(IR) { browser() } - macosArm64() - macosX64() - cocoapods { summary = "Some description for the Shared Module" homepage = "Link to the Shared Module homepage" From 852b970b0671d8b2823181a09e2929fcc94a8e8e Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Thu, 10 Aug 2023 16:06:14 +0700 Subject: [PATCH 019/352] #530 fixes after review --- .../moko/resources/compose/StringDescExt.kt | 1 - .../dev/icerock/gradle/AndroidPluginLogic.kt | 5 ++--- .../icerock/gradle/generator/FontsGenerator.kt | 3 ++- .../kotlin/dev/icerock/gradle/utils/StringExt.kt | 16 ++++++++++++++-- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/resources-compose/src/jvmMain/kotlin/dev/icerock/moko/resources/compose/StringDescExt.kt b/resources-compose/src/jvmMain/kotlin/dev/icerock/moko/resources/compose/StringDescExt.kt index 2e295c182..a6d5f02bf 100644 --- a/resources-compose/src/jvmMain/kotlin/dev/icerock/moko/resources/compose/StringDescExt.kt +++ b/resources-compose/src/jvmMain/kotlin/dev/icerock/moko/resources/compose/StringDescExt.kt @@ -8,7 +8,6 @@ import androidx.compose.runtime.Composable import dev.icerock.moko.resources.desc.StringDesc @Suppress("EXTENSION_SHADOWED_BY_MEMBER") -@Composable actual fun StringDesc.localized(): String { return this.localized() } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/AndroidPluginLogic.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/AndroidPluginLogic.kt index 4c5143291..7c3b48f83 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/AndroidPluginLogic.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/AndroidPluginLogic.kt @@ -9,6 +9,7 @@ import com.android.build.gradle.BaseExtension import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.ResourceGeneratorFeature import dev.icerock.gradle.generator.android.AndroidMRGenerator +import dev.icerock.gradle.utils.capitalize import dev.icerock.gradle.utils.isDependsOn import java.io.File import java.util.Locale @@ -63,9 +64,7 @@ internal class AndroidPluginLogic( ): MRGenerator.SourceSet { return object : MRGenerator.SourceSet { override val name: String - get() = "android${ - androidSourceSet.name.replaceFirstChar { it.uppercase() } - }" + get() = "android${androidSourceSet.name.capitalize()}" override fun addSourceDir(directory: File) { androidSourceSet.java.srcDirs(directory) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt index 9aa5a0af3..15c87d0cd 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt @@ -14,6 +14,7 @@ import dev.icerock.gradle.generator.apple.AppleFontsGenerator import dev.icerock.gradle.generator.common.CommonFontsGenerator import dev.icerock.gradle.generator.js.JsFontsGenerator import dev.icerock.gradle.generator.jvm.JvmFontsGenerator +import dev.icerock.gradle.utils.decapitalize import org.gradle.api.file.FileTree import java.io.File import java.util.Locale @@ -93,7 +94,7 @@ abstract class FontsGenerator( fontStyleFiles .forEach { (styleName, file) -> val styleProperty = PropertySpec - .builder(styleName.replaceFirstChar { it.lowercase(Locale.ROOT) }, resourceClassName) + .builder(styleName.decapitalize(), resourceClassName) .addModifiers(*getPropertyModifiers()) getPropertyInitializer(file)?.let { codeBlock -> styleProperty.initializer(codeBlock) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/StringExt.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/StringExt.kt index a07f5a10e..c10a9b78e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/StringExt.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/StringExt.kt @@ -4,6 +4,8 @@ package dev.icerock.gradle.utils +import java.util.Locale + /** * Replace all new lines including space characters before and after. * This is required to remove the IDE indentation. @@ -12,5 +14,15 @@ internal fun String.removeLineWraps(): String { return replace(Regex("\\s*\n\\s*"), " ") } -internal val String.withoutScale get() = - substringBefore("@") +internal val String.withoutScale + get() = substringBefore("@") + +internal fun String.capitalize(): String { + return replaceFirstChar { char -> + if (char.isLowerCase()) char.titlecase(Locale.ROOT) else char.toString() + } +} + +internal fun String.decapitalize(): String { + return replaceFirstChar { it.lowercase(Locale.ROOT) } +} From 8b0af74e1d4bdd07e36a3861fe2fdc2dcb1e415a Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Thu, 10 Aug 2023 16:24:36 +0700 Subject: [PATCH 020/352] #530 compose 1.5.0, fix annotation for localize --- gradle/libs.versions.toml | 6 +++--- .../dev/icerock/moko/resources/compose/StringDescExt.kt | 1 + samples/compose-jvm-app/build.gradle.kts | 2 +- samples/resources-gallery/build.gradle.kts | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a60fee1ca..94d2677e3 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -12,8 +12,8 @@ constraintLayoutVersion = "2.1.4" androidAppCompatVersion = "1.6.1" # android compose -composeVersion = "1.5.0-rc01" -composeActivityVersion = "1.7.1" +composeVersion = "1.5.0" +composeActivityVersion = "1.7.2" # jetbrains compose composeJetbrainsVersion = "1.4.3" @@ -36,7 +36,7 @@ robolectricVersion = "4.8.1" # moko mokoGraphicsVersion = "0.9.0" -mokoParcelizeVersion = "0.8.0" +mokoParcelizeVersion = "0.9.0" mokoTestVersion = "0.6.1" mokoMultiplatformPluginVersion = "0.14.2" diff --git a/resources-compose/src/jvmMain/kotlin/dev/icerock/moko/resources/compose/StringDescExt.kt b/resources-compose/src/jvmMain/kotlin/dev/icerock/moko/resources/compose/StringDescExt.kt index a6d5f02bf..2e295c182 100644 --- a/resources-compose/src/jvmMain/kotlin/dev/icerock/moko/resources/compose/StringDescExt.kt +++ b/resources-compose/src/jvmMain/kotlin/dev/icerock/moko/resources/compose/StringDescExt.kt @@ -8,6 +8,7 @@ import androidx.compose.runtime.Composable import dev.icerock.moko.resources.desc.StringDesc @Suppress("EXTENSION_SHADOWED_BY_MEMBER") +@Composable actual fun StringDesc.localized(): String { return this.localized() } diff --git a/samples/compose-jvm-app/build.gradle.kts b/samples/compose-jvm-app/build.gradle.kts index f603992ec..791cf2917 100644 --- a/samples/compose-jvm-app/build.gradle.kts +++ b/samples/compose-jvm-app/build.gradle.kts @@ -8,6 +8,6 @@ buildscript { dependencies { classpath(moko.resourcesGradlePlugin) classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0") - classpath("org.jetbrains.compose:compose-gradle-plugin:1.4.3") + classpath("org.jetbrains.compose:compose-gradle-plugin:1.5.0") } } diff --git a/samples/resources-gallery/build.gradle.kts b/samples/resources-gallery/build.gradle.kts index cefad9d10..ee68b4250 100644 --- a/samples/resources-gallery/build.gradle.kts +++ b/samples/resources-gallery/build.gradle.kts @@ -14,7 +14,7 @@ buildscript { dependencies { classpath(moko.resourcesGradlePlugin) classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0") - classpath("org.jetbrains.compose:compose-gradle-plugin:1.4.3") + classpath("org.jetbrains.compose:compose-gradle-plugin:1.5.0") classpath("com.android.tools.build:gradle:7.4.2") } } From adf98e542c2cb0b884b3628b687fe164f72588b9 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Thu, 10 Aug 2023 16:48:47 +0700 Subject: [PATCH 021/352] #530 rework beforeGeneration task dependencies --- .../generator/apple/AppleMRGenerator.kt | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt index c178eada8..bbb421490 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt @@ -4,6 +4,7 @@ package dev.icerock.gradle.generator.apple +import com.android.build.gradle.internal.tasks.factory.dependsOn import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier @@ -24,6 +25,7 @@ import org.gradle.api.Action import org.gradle.api.Project import org.gradle.api.Task import org.gradle.api.plugins.ExtensionAware +import org.gradle.api.tasks.TaskProvider import org.gradle.kotlin.dsl.findByType import org.gradle.kotlin.dsl.getByType import org.gradle.kotlin.dsl.maybeCreate @@ -103,8 +105,11 @@ class AppleMRGenerator( } private fun setupKLibResources(generationTask: Task) { - val compileTask: KotlinNativeCompile = compilation.compileTaskProvider.get() - compileTask.dependsOn(generationTask) + val compileTask: TaskProvider = compilation.compileTaskProvider + + compileTask.configure { + it.dependsOn(generationTask) + } // tasks like compileIosMainKotlinMetadata when only one target enabled generationTask.project.tasks @@ -112,14 +117,16 @@ class AppleMRGenerator( .matching { it.name.contains(sourceSet.name, ignoreCase = true) } .configureEach { it.dependsOn(generationTask) } - compileTask.doLast( - PackResourcesToKLibAction( - baseLocalizationRegion = baseLocalizationRegion, - bundleIdentifier = bundleIdentifier, - assetsDirectory = assetsDirectory, - resourcesGenerationDir = resourcesGenerationDir, - ) - ) + compileTask.configure { + it.doLast { + PackResourcesToKLibAction( + baseLocalizationRegion = baseLocalizationRegion, + bundleIdentifier = bundleIdentifier, + assetsDirectory = assetsDirectory, + resourcesGenerationDir = resourcesGenerationDir, + ) + } + } } private fun setupFrameworkResources() { From b805e79a35caa96b50afeb120e46eda1d90a8c02 Mon Sep 17 00:00:00 2001 From: Alexey Illarionov Date: Mon, 31 Jul 2023 21:00:07 +0300 Subject: [PATCH 022/352] Configure plugin more lazily --- .../dev/icerock/gradle/AndroidPluginLogic.kt | 73 +++-- .../gradle/MultiplatformResourcesPlugin.kt | 260 ++++++++---------- .../gradle/generator/FilesGenerator.kt | 2 +- .../gradle/generator/FontsGenerator.kt | 2 +- .../gradle/generator/ImagesGenerator.kt | 2 +- .../icerock/gradle/generator/MRGenerator.kt | 70 +++-- .../gradle/generator/PluralsGenerator.kt | 2 +- .../icerock/gradle/generator/SourceInfo.kt | 12 +- .../gradle/generator/StringsGenerator.kt | 2 +- .../android/AndroidFilesGenerator.kt | 5 +- .../android/AndroidFontsGenerator.kt | 5 +- .../android/AndroidImagesGenerator.kt | 5 +- .../generator/android/AndroidMRGenerator.kt | 5 +- .../android/AndroidPluralsGenerator.kt | 5 +- .../android/AndroidStringsGenerator.kt | 5 +- .../generator/apple/AppleMRGenerator.kt | 58 ++-- .../apple/action/PackResourcesToKLibAction.kt | 13 +- .../generator/common/CommonMRGenerator.kt | 5 +- .../gradle/generator/js/JsFontsGenerator.kt | 12 +- .../gradle/generator/js/JsMRGenerator.kt | 36 ++- .../gradle/generator/js/JsPluralsGenerator.kt | 11 +- .../gradle/generator/js/JsStringsGenerator.kt | 11 +- .../generator/jvm/ClassLoaderExtender.kt | 5 +- .../gradle/generator/jvm/JvmMRGenerator.kt | 21 +- .../generator/jvm/JvmPluralsGenerator.kt | 6 +- .../generator/jvm/JvmStringsGenerator.kt | 6 +- .../tasks/CopyExecutableResourcesToApp.kt | 9 +- .../GenerateMultiplatformResourcesTask.kt | 2 +- .../gradle/utils/KotlinSourceSetExt.kt | 28 +- .../icerock/gradle/utils/TasksContainer.kt | 21 ++ 30 files changed, 386 insertions(+), 313 deletions(-) create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/utils/TasksContainer.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/AndroidPluginLogic.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/AndroidPluginLogic.kt index 2e75c16c0..c75fa326a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/AndroidPluginLogic.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/AndroidPluginLogic.kt @@ -8,36 +8,48 @@ import com.android.build.api.dsl.AndroidSourceSet import com.android.build.gradle.BaseExtension import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.ResourceGeneratorFeature +import dev.icerock.gradle.generator.SourceInfo import dev.icerock.gradle.generator.android.AndroidMRGenerator import dev.icerock.gradle.utils.isDependsOn import org.gradle.api.Action +import org.gradle.api.DomainObjectCollection import org.gradle.api.Project import org.gradle.api.Task +import org.gradle.api.file.Directory +import org.gradle.api.provider.Provider +import org.gradle.api.tasks.SourceSet import org.gradle.kotlin.dsl.getByType import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet -import org.jetbrains.kotlin.gradle.plugin.KotlinTarget import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget import java.io.File +import javax.xml.parsers.DocumentBuilderFactory +@Suppress("LongParameterList") internal class AndroidPluginLogic( private val commonSourceSet: KotlinSourceSet, - private val targets: List, - private val generatedDir: File, + private val targets: DomainObjectCollection, + private val generatedDir: Provider, private val mrSettings: MRGenerator.MRSettings, private val features: List>, - private val project: Project + private val sourceInfo: SourceInfo, + private val project: Project, ) { - fun setup(androidMainSourceSet: AndroidSourceSet) { - val kotlinSourceSets: List = targets - .filterIsInstance() - .flatMap { it.compilations } - .filter { compilation -> - compilation.kotlinSourceSets.any { it.isDependsOn(commonSourceSet) } - } - .map { it.defaultSourceSet } + fun setup() { + val androidExtension: BaseExtension = project.extensions.getByType(BaseExtension::class) - val androidSourceSet: MRGenerator.SourceSet = - createSourceSet(androidMainSourceSet, kotlinSourceSets) + val androidMainSourceSet = androidExtension.sourceSets + .getByName(SourceSet.MAIN_SOURCE_SET_NAME) + + sourceInfo.androidRClassPackageProvider = project.provider { + val namespace: String? = androidExtension.namespace + if (namespace != null) { + namespace + } else { + val manifestFile = androidMainSourceSet.manifest.srcFile + getAndroidPackage(manifestFile) + } + } + val androidSourceSet: MRGenerator.SourceSet = createSourceSet(androidMainSourceSet) setAssetsDirsRefresh() @@ -68,23 +80,46 @@ internal class AndroidPluginLogic( private fun createSourceSet( androidSourceSet: AndroidSourceSet, - kotlinSourceSets: List ): MRGenerator.SourceSet { return object : MRGenerator.SourceSet { override val name: String get() = "android${androidSourceSet.name.capitalize()}" - override fun addSourceDir(directory: File) { - kotlinSourceSets.forEach { it.kotlin.srcDir(directory) } + override fun addSourceDir(directory: Provider) { + targets.configureEach { target -> + target.compilations.configureEach { compilation -> + val lazyDirectory = { + directory.takeIf { + compilation.kotlinSourceSets.any { compilationSourceSet -> + compilationSourceSet.isDependsOn(commonSourceSet) + } + } + } + compilation.defaultSourceSet.kotlin.srcDir(lazyDirectory) + } + } } - override fun addResourcesDir(directory: File) { + override fun addResourcesDir(directory: Provider) { androidSourceSet.res.srcDir(directory) } - override fun addAssetsDir(directory: File) { + override fun addAssetsDir(directory: Provider) { androidSourceSet.assets.srcDir(directory) } } } + + private companion object { + private fun getAndroidPackage(manifestFile: File): String { + val dbFactory = DocumentBuilderFactory.newInstance() + val dBuilder = dbFactory.newDocumentBuilder() + val doc = dBuilder.parse(manifestFile) + + val manifestNodes = doc.getElementsByTagName("manifest") + val manifest = manifestNodes.item(0) + + return manifest.attributes.getNamedItem("package").textContent + } + } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index d9691de5a..84e974e4d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -4,7 +4,6 @@ package dev.icerock.gradle -import com.android.build.gradle.BaseExtension import dev.icerock.gradle.generator.AssetsGenerator import dev.icerock.gradle.generator.ColorsGenerator import dev.icerock.gradle.generator.FilesGenerator @@ -21,11 +20,16 @@ import dev.icerock.gradle.generator.js.JsMRGenerator import dev.icerock.gradle.generator.jvm.JvmMRGenerator import dev.icerock.gradle.tasks.CopyXCFrameworkResourcesToApp import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask -import dev.icerock.gradle.utils.getDependedFrom -import dev.icerock.gradle.utils.isDependsOn +import dev.icerock.gradle.utils.ifDependsOn +import org.gradle.api.DomainObjectCollection +import org.gradle.api.NamedDomainObjectCollection import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.api.tasks.SourceSet +import org.gradle.api.file.Directory +import org.gradle.api.file.ProjectLayout +import org.gradle.api.file.SourceDirectorySet +import org.gradle.api.provider.Provider +import org.gradle.api.provider.ProviderFactory import org.gradle.kotlin.dsl.create import org.gradle.kotlin.dsl.getByType import org.gradle.kotlin.dsl.withType @@ -34,14 +38,13 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation import org.jetbrains.kotlin.gradle.plugin.KotlinMultiplatformPluginWrapper import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import org.jetbrains.kotlin.gradle.plugin.KotlinTarget +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFrameworkTask import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilation import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget import org.jetbrains.kotlin.konan.target.HostManager -import java.io.File -import javax.xml.parsers.DocumentBuilderFactory @Suppress("TooManyFunctions") class MultiplatformResourcesPlugin : Plugin { @@ -50,48 +53,63 @@ class MultiplatformResourcesPlugin : Plugin { "multiplatformResources", MultiplatformResourcesPluginExtension::class ) - mrExtension.multiplatformResourcesPackage = "${target.group}.${target.name}" - target.plugins.withType(KotlinMultiplatformPluginWrapper::class) { - val multiplatformExtension = - target.extensions.getByType(KotlinMultiplatformExtension::class) - target.afterEvaluate { configureGenerators( target = target, + resourcesSourceSetName = mrExtension.sourceSetName, mrExtension = mrExtension, - multiplatformExtension = multiplatformExtension + multiplatformExtension = target.extensions.getByType(KotlinMultiplatformExtension::class) ) } } } + private fun configureGenerators( + target: Project, + resourcesSourceSetName: String, + mrExtension: MultiplatformResourcesPluginExtension, + multiplatformExtension: KotlinMultiplatformExtension, + ) { + multiplatformExtension.sourceSets + .matching { it.name == resourcesSourceSetName } + .all { commonSourceSet -> + configureGenerators( + target = target, + mrExtension = mrExtension, + multiplatformExtension = multiplatformExtension, + commonSourceSet = commonSourceSet, + ) + } + } + @Suppress("LongMethod") private fun configureGenerators( target: Project, mrExtension: MultiplatformResourcesPluginExtension, - multiplatformExtension: KotlinMultiplatformExtension + multiplatformExtension: KotlinMultiplatformExtension, + commonSourceSet: KotlinSourceSet, ) { - val commonSourceSet = multiplatformExtension.sourceSets.getByName(mrExtension.sourceSetName) + val projectLayout: ProjectLayout = target.layout + val providerFactory: ProviderFactory = target.providers val commonResources = commonSourceSet.resources - val generatedDir = File(target.buildDir, "generated/moko") - val mrClassPackage: String = requireNotNull(mrExtension.multiplatformResourcesPackage) { - buildString { - appendLine("multiplatformResources.multiplatformResourcesPackage is required!") - append("Please configure moko-resources plugin correctly.") - } + val generatedDir = projectLayout.buildDirectory.dir("generated/moko") + val mrClassPackage = providerFactory.provider { mrExtension.multiplatformResourcesPackage } + .orElse(providerFactory.provider { "${target.group}.${target.name}" }) + + val mrSettings = object : MRGenerator.MRSettings { + override val packageName = mrClassPackage + override val className = providerFactory.provider(mrExtension::multiplatformResourcesClassName) + override val visibility = providerFactory.provider(mrExtension::multiplatformResourcesVisibility) + } + + val sourceInfo = object : SourceInfo { + override val commonResources: SourceDirectorySet + get() = commonResources + override val mrClassPackage = mrClassPackage + override var androidRClassPackageProvider: Provider? = null } - val mrSettings = MRGenerator.MRSettings( - packageName = mrClassPackage, - className = mrExtension.multiplatformResourcesClassName, - visibility = mrExtension.multiplatformResourcesVisibility - ) - val sourceInfo = SourceInfo( - generatedDir, - commonResources, - mrExtension.multiplatformResourcesPackage!! - ) val strictLineBreaks: Boolean = target .findProperty("moko.resources.strictLineBreaks") @@ -119,7 +137,7 @@ class MultiplatformResourcesPlugin : Plugin { ColorsGenerator.Feature(sourceInfo, mrSettings), AssetsGenerator.Feature(sourceInfo, mrSettings) ) - val targets: List = multiplatformExtension.targets.toList() + val targets: NamedDomainObjectCollection = multiplatformExtension.targets val commonGenerationTask = setupCommonGenerator( commonSourceSet = commonSourceSet, @@ -131,15 +149,15 @@ class MultiplatformResourcesPlugin : Plugin { listOf("com.android.library", "com.android.application").forEach { id -> target.plugins.withId(id) { - setupAndroidGenerator( - target = target, + AndroidPluginLogic( commonSourceSet = commonSourceSet, - targets = targets, + targets = targets.withType(), generatedDir = generatedDir, mrSettings = mrSettings, features = features, - sourceInfo = sourceInfo - ) + sourceInfo = sourceInfo, + project = target + ).setup() } } @@ -180,44 +198,9 @@ class MultiplatformResourcesPlugin : Plugin { .configureEach { it.dependsOn(commonGenerationTask) } } - @Suppress("LongParameterList") - private fun setupAndroidGenerator( - target: Project, - commonSourceSet: KotlinSourceSet, - targets: List, - generatedDir: File, - mrSettings: MRGenerator.MRSettings, - features: List>, - sourceInfo: SourceInfo - ) { - val androidExtension = target.extensions.getByType(BaseExtension::class) - - val androidLogic = AndroidPluginLogic( - commonSourceSet = commonSourceSet, - targets = targets, - generatedDir = generatedDir, - mrSettings = mrSettings, - features = features, - project = target - ) - - val androidMainSourceSet = androidExtension.sourceSets - .getByName(SourceSet.MAIN_SOURCE_SET_NAME) - - sourceInfo.getAndroidRClassPackage = lambda@{ - val namespace: String? = androidExtension.namespace - if (namespace != null) return@lambda namespace - - val manifestFile = androidMainSourceSet.manifest.srcFile - getAndroidPackage(manifestFile) - } - - androidLogic.setup(androidMainSourceSet) - } - private fun setupCommonGenerator( commonSourceSet: KotlinSourceSet, - generatedDir: File, + generatedDir: Provider, mrSettings: MRGenerator.MRSettings, features: List>, target: Project @@ -234,90 +217,86 @@ class MultiplatformResourcesPlugin : Plugin { @Suppress("LongParameterList") private fun setupJvmGenerator( commonSourceSet: KotlinSourceSet, - targets: List, - generatedDir: File, + targets: DomainObjectCollection, + generatedDir: Provider, mrSettings: MRGenerator.MRSettings, features: List>, target: Project ) { - val kotlinSourceSets: List = targets - .filterIsInstance() - .flatMap { it.compilations } - .map { it.defaultSourceSet } - .filter { it.isDependsOn(commonSourceSet) } - - kotlinSourceSets.forEach { kotlinSourceSet -> - JvmMRGenerator( - generatedDir = generatedDir, - sourceSet = createSourceSet(kotlinSourceSet), - mrSettings = mrSettings, - generators = features.map { it.createJvmGenerator() } - ).apply(target) - } + targets + .withType() + .configureEach { kotlinJvmTarget -> + kotlinJvmTarget.compilations + .configureEach { compilation -> + compilation.defaultSourceSet.ifDependsOn(commonSourceSet) { + JvmMRGenerator( + generatedDir = generatedDir, + sourceSet = createSourceSet(compilation.defaultSourceSet), + mrSettings = mrSettings, + generators = features.map { it.createJvmGenerator() } + ).apply(project = target) + } + } + } } @Suppress("LongParameterList") private fun setupJsGenerator( commonSourceSet: KotlinSourceSet, - targets: List, - generatedDir: File, + targets: DomainObjectCollection, + generatedDir: Provider, mrSettings: MRGenerator.MRSettings, features: List>, target: Project ) { - val kotlinSourceSets: List> = targets - .filterIsInstance() - .flatMap { it.compilations } - .filterIsInstance() - .map { it to it.defaultSourceSet } - .filter { it.second.isDependsOn(commonSourceSet) } - - kotlinSourceSets.forEach { (compilation, kotlinSourceSet) -> - JsMRGenerator( - generatedDir, - createSourceSet(kotlinSourceSet), - mrSettings = mrSettings, - generators = features.map { it.createJsGenerator() }, - compilation = compilation - ).apply(target) - } + targets + .withType() + .configureEach { kotlinJsIrTarget -> + kotlinJsIrTarget.compilations + .withType() + .all { compilation -> + compilation.defaultSourceSet.ifDependsOn(commonSourceSet) { + JsMRGenerator( + generatedDir, + createSourceSet(compilation.defaultSourceSet), + mrSettings = mrSettings, + generators = features.map { it.createJsGenerator() }, + compilation = compilation, + ).apply(project = target) + } + } + } } @Suppress("LongParameterList") private fun setupAppleGenerator( commonSourceSet: KotlinSourceSet, - targets: List, - generatedDir: File, + targets: DomainObjectCollection, + generatedDir: Provider, mrSettings: MRGenerator.MRSettings, features: List>, target: Project, iosLocalizationRegion: String ) { - val compilations = targets - .filterIsInstance() - .filter { it.konanTarget.family.isAppleFamily } - .map { kotlinNativeTarget -> - kotlinNativeTarget.compilations - .getByName(KotlinCompilation.MAIN_COMPILATION_NAME) + targets + .withType() + .matching { it.konanTarget.family.isAppleFamily } + .configureEach { appleFamilyTarget -> + appleFamilyTarget.compilations + .matching { it.name == KotlinCompilation.MAIN_COMPILATION_NAME } + .all { compilation -> + compilation.defaultSourceSet.ifDependsOn(commonSourceSet) { + AppleMRGenerator( + generatedDir = generatedDir, + sourceSet = createSourceSet(compilation.defaultSourceSet), + mrSettings = mrSettings, + generators = features.map { it.createIosGenerator() }, + compilation = compilation, + baseLocalizationRegion = iosLocalizationRegion, + ).apply(project = target) + } + } } - - val defSourceSets = compilations.map { it.defaultSourceSet } - .filter { it.isDependsOn(commonSourceSet) } - compilations.forEach { compilation -> - val kss = compilation.defaultSourceSet - val depend = kss.getDependedFrom(defSourceSets) - - val sourceSet = createSourceSet(depend ?: kss) - AppleMRGenerator( - generatedDir = generatedDir, - sourceSet = sourceSet, - mrSettings = mrSettings, - generators = features.map { it.createIosGenerator() }, - compilation = compilation, - baseLocalizationRegion = iosLocalizationRegion - ).apply(target) - } - setupCopyXCFrameworkResourcesTask(target) } @@ -345,28 +324,17 @@ class MultiplatformResourcesPlugin : Plugin { override val name: String get() = kotlinSourceSet.name - override fun addSourceDir(directory: File) { + override fun addSourceDir(directory: Provider) { kotlinSourceSet.kotlin.srcDir(directory) } - override fun addResourcesDir(directory: File) { + override fun addResourcesDir(directory: Provider) { kotlinSourceSet.resources.srcDir(directory) } - override fun addAssetsDir(directory: File) { + override fun addAssetsDir(directory: Provider) { // nothing } } } - - private fun getAndroidPackage(manifestFile: File): String { - val dbFactory = DocumentBuilderFactory.newInstance() - val dBuilder = dbFactory.newDocumentBuilder() - val doc = dBuilder.parse(manifestFile) - - val manifestNodes = doc.getElementsByTagName("manifest") - val manifest = manifestNodes.item(0) - - return manifest.attributes.getNamedItem("package").textContent - } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt index 4d96f4194..077f36662 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt @@ -107,7 +107,7 @@ abstract class FilesGenerator( override fun createAndroidGenerator() = AndroidFilesGenerator( inputFileTree = fileTree, - getAndroidRClassPackage = requireNotNull(info.getAndroidRClassPackage) + androidRClassPackageProvider = requireNotNull(info.androidRClassPackageProvider), ) override fun createJsGenerator(): FilesGenerator = JsFilesGenerator(fileTree) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt index 7bb961fd5..052ea4041 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt @@ -135,7 +135,7 @@ abstract class FontsGenerator( override fun createAndroidGenerator() = AndroidFontsGenerator( inputFileTree = stringsFileTree, - getAndroidRClassPackage = requireNotNull(info.getAndroidRClassPackage) + androidRClassPackageProvider = requireNotNull(info.androidRClassPackageProvider) ) override fun createJsGenerator(): FontsGenerator = JsFontsGenerator( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt index 289baf5ec..885e84628 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt @@ -113,7 +113,7 @@ abstract class ImagesGenerator( override fun createAndroidGenerator() = AndroidImagesGenerator( inputFileTree = stringsFileTree, - getAndroidRClassPackage = requireNotNull(info.getAndroidRClassPackage), + androidRClassPackageProvider = requireNotNull(info.androidRClassPackageProvider), logger = logger ) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt index f708194b7..4afd881a9 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt @@ -14,40 +14,28 @@ import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.toModifier import org.gradle.api.Project import org.gradle.api.Task +import org.gradle.api.file.Directory +import org.gradle.api.provider.Provider import java.io.File abstract class MRGenerator( - generatedDir: File, + generatedDir: Provider, protected val sourceSet: SourceSet, protected val mrSettings: MRSettings, internal val generators: List ) { - - internal val outputDir = File(generatedDir, sourceSet.name) - protected open val sourcesGenerationDir - get() = File(outputDir, "src") - protected open val resourcesGenerationDir - get() = File(outputDir, "res") - - protected open val assetsGenerationDir: File - get() = File(outputDir, AssetsGenerator.ASSETS_DIR_NAME) - - init { - setupGenerationDirs() - } - - private fun setupGenerationDirs() { - sourcesGenerationDir.mkdirs() - sourceSet.addSourceDir(sourcesGenerationDir) - - resourcesGenerationDir.mkdirs() - sourceSet.addResourcesDir(resourcesGenerationDir) - - assetsGenerationDir.mkdirs() - sourceSet.addAssetsDir(assetsGenerationDir) + internal val outputDir: Provider = generatedDir.map { it.dir(sourceSet.name) } + protected open val sourcesGenerationDir: Provider = outputDir.map { it.dir("src") } + protected open val resourcesGenerationDir: Provider = outputDir.map { it.dir("res") } + protected open val assetsGenerationDir: Provider = outputDir.map { + it.dir(AssetsGenerator.ASSETS_DIR_NAME) } internal fun generate() { + val sourcesGenerationDir = sourcesGenerationDir.get().asFile + val assetsGenerationDir = assetsGenerationDir.get().asFile + val resourcesGenerationDir = resourcesGenerationDir.get().asFile + sourcesGenerationDir.deleteRecursively() resourcesGenerationDir.deleteRecursively() assetsGenerationDir.deleteRecursively() @@ -55,13 +43,13 @@ abstract class MRGenerator( beforeMRGeneration() @Suppress("SpreadOperator") - val mrClassSpec = TypeSpec.objectBuilder(mrSettings.className) + val mrClassSpec = TypeSpec.objectBuilder(mrSettings.className.get()) .addModifiers(*getMRClassModifiers()) - .addModifiers(mrSettings.visibility.toModifier()) + .addModifiers(mrSettings.visibility.get().toModifier()) generators.forEach { generator -> val builder = TypeSpec.objectBuilder(generator.mrObjectName) - .addModifiers(mrSettings.visibility.toModifier()) + .addModifiers(mrSettings.visibility.get().toModifier()) val fileResourceInterfaceClassName = ClassName("dev.icerock.moko.resources", "ResourceContainer") @@ -80,7 +68,7 @@ abstract class MRGenerator( val mrClass = mrClassSpec.build() - val fileSpec = FileSpec.builder(mrSettings.packageName, mrSettings.className) + val fileSpec = FileSpec.builder(mrSettings.packageName.get(), mrSettings.className.get()) .addType(mrClass) generators @@ -97,6 +85,7 @@ abstract class MRGenerator( fun apply(project: Project): GenerateMultiplatformResourcesTask { val name = sourceSet.name val genTaskName = "generateMR$name" + setupGenerationDirs() val genTask = runCatching { project.tasks.getByName(genTaskName) as GenerateMultiplatformResourcesTask }.getOrNull() ?: project.tasks.create( @@ -104,6 +93,9 @@ abstract class MRGenerator( GenerateMultiplatformResourcesTask::class.java ) { it.generator = this + it.inputs.property("mokoSettingsPackageName", mrSettings.packageName) + it.inputs.property("mokoSettingsClassName", mrSettings.className) + it.inputs.property("mokoSettingsVisibility", mrSettings.visibility) } apply(generationTask = genTask, project = project) @@ -120,6 +112,12 @@ abstract class MRGenerator( protected open fun processMRClass(mrClass: TypeSpec.Builder) {} protected open fun getImports(): List = emptyList() + private fun setupGenerationDirs() { + sourceSet.addSourceDir(sourcesGenerationDir) + sourceSet.addResourcesDir(resourcesGenerationDir) + sourceSet.addAssetsDir(assetsGenerationDir) + } + interface Generator : ObjectBodyExtendable { val mrObjectName: String val resourceClassName: ClassName @@ -137,14 +135,14 @@ abstract class MRGenerator( interface SourceSet { val name: String - fun addSourceDir(directory: File) - fun addResourcesDir(directory: File) - fun addAssetsDir(directory: File) + fun addSourceDir(directory: Provider) + fun addResourcesDir(directory: Provider) + fun addAssetsDir(directory: Provider) } - data class MRSettings( - val packageName: String, - val className: String, - val visibility: MRVisibility - ) + interface MRSettings { + val packageName: Provider + val className: Provider + val visibility: Provider + } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt index 3f71c1b9f..82a93b327 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt @@ -111,7 +111,7 @@ abstract class PluralsGenerator( AndroidPluralsGenerator( pluralsFileTree = stringsFileTree, strictLineBreaks = strictLineBreaks, - getAndroidRClassPackage = requireNotNull(info.getAndroidRClassPackage) + androidRClassPackageProvider = requireNotNull(info.androidRClassPackageProvider), ) override fun createJvmGenerator() = diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/SourceInfo.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/SourceInfo.kt index 791086506..fdf5ea4ae 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/SourceInfo.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/SourceInfo.kt @@ -5,12 +5,10 @@ package dev.icerock.gradle.generator import org.gradle.api.file.SourceDirectorySet -import java.io.File +import org.gradle.api.provider.Provider -data class SourceInfo( - val generatedDir: File, - val commonResources: SourceDirectorySet, - val mrClassPackage: String -) { - var getAndroidRClassPackage: (() -> String)? = null +interface SourceInfo { + val commonResources: SourceDirectorySet + val mrClassPackage: Provider + var androidRClassPackageProvider: Provider? } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt index 4d9892cb8..5703ed9cc 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt @@ -91,7 +91,7 @@ abstract class StringsGenerator( AndroidStringsGenerator( stringsFileTree = stringsFileTree, strictLineBreaks = strictLineBreaks, - getAndroidRClassPackage = requireNotNull(info.getAndroidRClassPackage) + androidRClassPackageProvider = requireNotNull(info.androidRClassPackageProvider) ) override fun createJsGenerator(): StringsGenerator = diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt index 2201f4d91..989c88004 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt @@ -11,12 +11,13 @@ import dev.icerock.gradle.generator.FilesGenerator import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable import org.gradle.api.file.FileTree +import org.gradle.api.provider.Provider import java.io.File import java.util.Locale class AndroidFilesGenerator( inputFileTree: FileTree, - private val getAndroidRClassPackage: () -> String + private val androidRClassPackageProvider: Provider, ) : FilesGenerator(inputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -26,7 +27,7 @@ class AndroidFilesGenerator( CodeBlock.of("FileResource(rawResId = R.raw.%L)", keyToResourceId(fileSpec.key)) override fun getImports() = listOf( - ClassName(getAndroidRClassPackage(), "R") + ClassName(androidRClassPackageProvider.get(), "R") ) override fun generateResources( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFontsGenerator.kt index e7f0ddbd1..9325f89b0 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFontsGenerator.kt @@ -11,12 +11,13 @@ import dev.icerock.gradle.generator.FontsGenerator import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable import org.gradle.api.file.FileTree +import org.gradle.api.provider.Provider import java.io.File import java.util.Locale class AndroidFontsGenerator( inputFileTree: FileTree, - private val getAndroidRClassPackage: () -> String + private val androidRClassPackageProvider: Provider, ) : FontsGenerator(inputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -27,7 +28,7 @@ class AndroidFontsGenerator( } override fun getImports(): List = listOf( - ClassName(getAndroidRClassPackage(), "R") + ClassName(androidRClassPackageProvider.get(), "R") ) override fun generateResources( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt index f84f8f46a..ccfcdffb0 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt @@ -14,6 +14,7 @@ import dev.icerock.gradle.generator.ObjectBodyExtendable import dev.icerock.gradle.utils.svg import org.gradle.api.file.FileTree import org.gradle.api.logging.Logger +import org.gradle.api.provider.Provider import java.io.File import java.io.FileOutputStream import java.io.IOException @@ -23,7 +24,7 @@ import kotlin.reflect.full.functions class AndroidImagesGenerator( inputFileTree: FileTree, - private val getAndroidRClassPackage: () -> String, + private val androidRClassPackageProvider: Provider, private val logger: Logger ) : ImagesGenerator(inputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -36,7 +37,7 @@ class AndroidImagesGenerator( } override fun getImports(): List = listOf( - ClassName(getAndroidRClassPackage(), "R") + ClassName(androidRClassPackageProvider.get(), "R") ) override fun generateResources( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt index cd27456c3..e302eff10 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt @@ -10,11 +10,12 @@ import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.MRGenerator import org.gradle.api.Project import org.gradle.api.Task +import org.gradle.api.file.Directory +import org.gradle.api.provider.Provider import org.gradle.kotlin.dsl.withType -import java.io.File class AndroidMRGenerator( - generatedDir: File, + generatedDir: Provider, sourceSet: SourceSet, mrSettings: MRSettings, generators: List diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt index b3a633644..e136414b0 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt @@ -15,12 +15,13 @@ import dev.icerock.gradle.generator.PluralMap import dev.icerock.gradle.generator.PluralsGenerator import org.apache.commons.lang3.StringEscapeUtils import org.gradle.api.file.FileTree +import org.gradle.api.provider.Provider import java.io.File class AndroidPluralsGenerator( pluralsFileTree: FileTree, strictLineBreaks: Boolean, - private val getAndroidRClassPackage: () -> String + private val androidRClassPackageProvider: Provider, ) : PluralsGenerator(pluralsFileTree, strictLineBreaks), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -31,7 +32,7 @@ class AndroidPluralsGenerator( CodeBlock.of("PluralsResource(R.plurals.%L)", processKey(key)) override fun getImports(): List = listOf( - ClassName(getAndroidRClassPackage(), "R") + ClassName(androidRClassPackageProvider.get(), "R") ) override fun generateResources( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt index 33d686a57..0c4730004 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt @@ -14,12 +14,13 @@ import dev.icerock.gradle.generator.ObjectBodyExtendable import dev.icerock.gradle.generator.StringsGenerator import org.apache.commons.text.StringEscapeUtils import org.gradle.api.file.FileTree +import org.gradle.api.provider.Provider import java.io.File class AndroidStringsGenerator( stringsFileTree: FileTree, strictLineBreaks: Boolean, - private val getAndroidRClassPackage: () -> String + private val androidRClassPackageProvider: Provider, ) : StringsGenerator(stringsFileTree, strictLineBreaks), ObjectBodyExtendable by NOPObjectBodyExtendable() { @@ -31,7 +32,7 @@ class AndroidStringsGenerator( CodeBlock.of("StringResource(R.string.%L)", processKey(key)) override fun getImports(): List = listOf( - ClassName(getAndroidRClassPackage(), "R") + ClassName(androidRClassPackageProvider.get(), "R") ) override fun generateResources( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt index 0c473706a..0fc374e3b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt @@ -20,13 +20,16 @@ import dev.icerock.gradle.tasks.CopyFrameworkResourcesToAppEntryPointTask import dev.icerock.gradle.tasks.CopyFrameworkResourcesToAppTask import dev.icerock.gradle.utils.calculateResourcesHash import dev.icerock.gradle.utils.dependsOnProcessResources +import dev.icerock.gradle.utils.klibs +import dev.icerock.gradle.utils.maybeRegister import org.gradle.api.Action import org.gradle.api.Project import org.gradle.api.Task +import org.gradle.api.file.Directory import org.gradle.api.plugins.ExtensionAware +import org.gradle.api.provider.Provider import org.gradle.kotlin.dsl.findByType import org.gradle.kotlin.dsl.getByType -import org.gradle.kotlin.dsl.maybeCreate import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompile import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension @@ -38,14 +41,13 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask import org.jetbrains.kotlin.gradle.tasks.FrameworkDescriptor -import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink import java.io.File import kotlin.reflect.full.memberProperties @Suppress("TooManyFunctions") class AppleMRGenerator( - generatedDir: File, + generatedDir: Provider, sourceSet: SourceSet, mrSettings: MRSettings, generators: List, @@ -59,9 +61,9 @@ class AppleMRGenerator( ) { private val bundleClassName = ClassName("platform.Foundation", "NSBundle") - private val bundleIdentifier = "${mrSettings.packageName}.MR" + private val bundleIdentifierProvider = mrSettings.packageName.map { "$it.MR" } - private val assetsDirectory: File get() = File(resourcesGenerationDir, ASSETS_DIR_NAME) + private val assetsDirectory: Provider = resourcesGenerationDir.map { it.dir(ASSETS_DIR_NAME) } override fun getMRClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -74,13 +76,13 @@ class AppleMRGenerator( bundleClassName, KModifier.PRIVATE ) - .delegate(CodeBlock.of("lazy { NSBundle.loadableBundle(\"$bundleIdentifier\") }")) + .delegate(CodeBlock.of("lazy { NSBundle.loadableBundle(\"${bundleIdentifierProvider.get()}\") }")) .build() ) mrClass.addProperty( PropertySpec.builder("contentHash", STRING, KModifier.PRIVATE) - .initializer("%S", resourcesGenerationDir.calculateResourcesHash()) + .initializer("%S", resourcesGenerationDir.get().asFile.calculateResourcesHash()) .build() ) } @@ -106,27 +108,27 @@ class AppleMRGenerator( } override fun beforeMRGeneration() { - assetsDirectory.mkdirs() + assetsDirectory.get().asFile.mkdirs() } private fun setupKLibResources(generationTask: Task) { - val compileTask: KotlinNativeCompile = compilation.compileKotlinTask - compileTask.dependsOn(generationTask) - // tasks like compileIosMainKotlinMetadata when only one target enabled generationTask.project.tasks .withType() .matching { it.name.contains(sourceSet.name, ignoreCase = true) } .configureEach { it.dependsOn(generationTask) } - compileTask.doLast( - PackResourcesToKLibAction( - baseLocalizationRegion = baseLocalizationRegion, - bundleIdentifier = bundleIdentifier, - assetsDirectory = assetsDirectory, - resourcesGenerationDir = resourcesGenerationDir, + compilation.compileTaskProvider.configure { + it.doLast( + PackResourcesToKLibAction( + baseLocalizationRegion = baseLocalizationRegion, + bundleIdentifierProvider = bundleIdentifierProvider, + assetsDirectoryProvider = assetsDirectory, + resourcesGenerationDirProvider = resourcesGenerationDir, + ) ) - ) + it.dependsOn(generationTask) + } } private fun setupFrameworkResources() { @@ -157,18 +159,18 @@ $linkTask produces static framework, Xcode should have Build Phase with copyFram } } - private fun createCopyResourcesToAppTask(project: Project) { + private fun createCopyResourcesToAppTask(project: Project) = project.afterEvaluate { project.tasks.withType() .matching { it.binary is AbstractExecutable } .all { linkTask -> val copyTaskName = linkTask.name.replace("link", "copyResources") - project.tasks - .maybeCreate(copyTaskName, CopyExecutableResourcesToApp::class) - .apply { - this.linkTask = linkTask - this.dependsOn(linkTask) - } + project.tasks.maybeRegister(copyTaskName) { + this.klibs.from( + linkTask.klibs.filter { it.path.endsWith(".klib") && it.exists() } + ) + this.dependsOn(linkTask) + } } } @@ -206,9 +208,9 @@ $linkTask produces static framework, Xcode should have Build Phase with copyFram .matching { it is TestExecutable && it.compilation.associateWith.contains(compilation) } .configureEach { val executable = it as TestExecutable - val linkTask = executable.linkTask - - linkTask.doLast(CopyResourcesFromKLibsToExecutableAction()) + executable.linkTaskProvider.configure { + it.doLast(CopyResourcesFromKLibsToExecutableAction()) + } } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/PackResourcesToKLibAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/PackResourcesToKLibAction.kt index 811c1e796..6c2e126b7 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/PackResourcesToKLibAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/PackResourcesToKLibAction.kt @@ -8,6 +8,8 @@ import dev.icerock.gradle.generator.apple.LoadableBundle import dev.icerock.gradle.utils.unzipTo import org.gradle.api.Action import org.gradle.api.Task +import org.gradle.api.file.Directory +import org.gradle.api.provider.Provider import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile import org.jetbrains.kotlin.konan.file.zipDirAs import java.io.File @@ -15,9 +17,9 @@ import java.util.Properties internal class PackResourcesToKLibAction( private val baseLocalizationRegion: String, - private val bundleIdentifier: String, - private val assetsDirectory: File, - private val resourcesGenerationDir: File + private val bundleIdentifierProvider: Provider, + private val assetsDirectoryProvider: Provider, + private val resourcesGenerationDirProvider: Provider, ) : Action { override fun execute(task: Task) { task as KotlinNativeCompile @@ -26,7 +28,10 @@ internal class PackResourcesToKLibAction( val repackDir = File(klibFile.parent, klibFile.nameWithoutExtension) val defaultDir = File(repackDir, "default") val resRepackDir = File(defaultDir, "resources") + val assetsDirectory = assetsDirectoryProvider.get().asFile + val resourcesGenerationDir = resourcesGenerationDirProvider.get().asFile + task.logger.info("Adding resources to klib file `{}`", klibFile) unzipTo(zipFile = klibFile, outputDirectory = repackDir) val manifestFile = File(defaultDir, "manifest") @@ -39,7 +44,7 @@ internal class PackResourcesToKLibAction( directory = resRepackDir, bundleName = uniqueName, developmentRegion = baseLocalizationRegion, - identifier = bundleIdentifier + identifier = bundleIdentifierProvider.get() ) loadableBundle.write() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index bee89720d..44861e6de 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -8,12 +8,13 @@ import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.MRGenerator import org.gradle.api.Project import org.gradle.api.Task +import org.gradle.api.file.Directory +import org.gradle.api.provider.Provider import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.dsl.KotlinCompile -import java.io.File class CommonMRGenerator( - generatedDir: File, + generatedDir: Provider, sourceSet: SourceSet, mrSettings: MRSettings, generators: List diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFontsGenerator.kt index 246c372f5..72ef79997 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFontsGenerator.kt @@ -14,15 +14,17 @@ import dev.icerock.gradle.generator.FontsGenerator import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable import org.gradle.api.file.FileTree +import org.gradle.api.provider.Provider +import org.gradle.kotlin.dsl.provideDelegate import java.io.File class JsFontsGenerator( inputFileTree: FileTree, - mrClassPackage: String, + mrClassPackage: Provider, ) : FontsGenerator(inputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { - private val flattenPackage: String = mrClassPackage.replace(".", "") - private val cssDeclarationsFileName: String = "$flattenPackage-generated-declarations.css" + private val flattenPackage: Provider = mrClassPackage.map { it.replace(".", "") } + private val cssDeclarationsFileName: Provider = flattenPackage.map { "$it-generated-declarations.css" } override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -62,7 +64,7 @@ class JsFontsGenerator( FunSpec.builder("addFontsToPage") .addCode( "js(%S)", - """require("$FONTS_DIR/$cssDeclarationsFileName")""" + """require("$FONTS_DIR/${cssDeclarationsFileName.get()}")""" ).build() ) } @@ -74,7 +76,7 @@ class JsFontsGenerator( file.copyTo(File(fontsDir, file.name)) } - val cssDeclarationsFile = File(fontsDir, cssDeclarationsFileName) + val cssDeclarationsFile = File(fontsDir, cssDeclarationsFileName.get()) val declarations = files .takeIf(List<*>::isNotEmpty) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt index adbc3f986..53827899a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt @@ -16,6 +16,8 @@ import dev.icerock.gradle.utils.klibs import org.gradle.api.Action import org.gradle.api.Project import org.gradle.api.Task +import org.gradle.api.file.Directory +import org.gradle.api.provider.Provider import org.gradle.jvm.tasks.Jar import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilation @@ -25,25 +27,28 @@ import org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl import java.io.File class JsMRGenerator( - generatedDir: File, + generatedDir: Provider, sourceSet: SourceSet, mrSettings: MRSettings, generators: List, - private val compilation: KotlinJsIrCompilation + private val compilation: KotlinJsIrCompilation, ) : MRGenerator( generatedDir = generatedDir, sourceSet = sourceSet, mrSettings = mrSettings, generators = generators ) { - private val flattenClassName: String get() = mrSettings.packageName.replace(".", "") - - override val resourcesGenerationDir: File - get() = outputDir.resolve("$flattenClassName/res") + private val flattenClassName: Provider = mrSettings.packageName + .map { it.replace(".", "") } + override val resourcesGenerationDir: Provider = outputDir.zip(flattenClassName) { outputDir, className -> + outputDir.dir(className).dir("res") + } override fun getMRClassModifiers(): Array = arrayOf(KModifier.ACTUAL) override fun processMRClass(mrClass: TypeSpec.Builder) { + val resourcesGenerationDir = resourcesGenerationDir.get().asFile + mrClass.addProperty( PropertySpec.builder("contentHash", STRING, KModifier.PRIVATE) .initializer("%S", resourcesGenerationDir.calculateResourcesHash()) @@ -117,7 +122,7 @@ class JsMRGenerator( val kotlinTarget: KotlinJsIrTarget = compilation.target as KotlinJsIrTarget kotlinTarget.compilations - .configureEach { compilation -> + .all { compilation -> compilation.compileTaskProvider.configure { compileTask -> val action = CopyResourcesToExecutableAction(resourcesGenerationDir) @Suppress("UNCHECKED_CAST") @@ -126,7 +131,9 @@ class JsMRGenerator( } } - class CopyResourcesToKLibAction(private val resourcesDir: File) : Action { + class CopyResourcesToKLibAction( + private val resourcesDirProvider: Provider, + ) : Action { override fun execute(task: Kotlin2JsCompile) { val unpackedKLibDir: File = task.destinationDirectory.asFile.get() val defaultDir = File(unpackedKLibDir, "default") @@ -134,7 +141,7 @@ class JsMRGenerator( if (resRepackDir.exists().not()) return val resDir = File(resRepackDir, "moko-resources-js") - resourcesDir.copyRecursively( + resourcesDirProvider.get().asFile.copyRecursively( resDir, overwrite = true ) @@ -142,10 +149,11 @@ class JsMRGenerator( } class CopyResourcesToExecutableAction( - private val resourcesGeneratedDir: File + private val resourcesGeneratedDirProvider: Provider, ) : Action { override fun execute(task: Kotlin2JsCompile) { val project: Project = task.project + val resourcesGeneratedDir = resourcesGeneratedDirProvider.get().asFile task.klibs.forEach { dependency -> copyResourcesFromLibraries( @@ -230,10 +238,14 @@ class JsMRGenerator( const output = { path: require("os").tmpdir() + '/' + '_karma_webpack_' + Math.floor(Math.random() * 1000000), } - + + const optimization = { + runtimeChunk: true + } + config.set( { - webpack: {... createWebpackConfig(), output}, + webpack: {... createWebpackConfig(), output, optimization}, files: config.files.concat([{ pattern: $pattern, watched: false, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsPluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsPluralsGenerator.kt index 06decabaf..8df2eda5e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsPluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsPluralsGenerator.kt @@ -19,16 +19,17 @@ import dev.icerock.gradle.generator.PluralsGenerator import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.put import org.gradle.api.file.FileTree +import org.gradle.api.provider.Provider import java.io.File class JsPluralsGenerator( pluralsFileTree: FileTree, - mrClassPackage: String, + mrClassPackage: Provider, strictLineBreaks: Boolean ) : PluralsGenerator(pluralsFileTree, strictLineBreaks), ObjectBodyExtendable by NOPObjectBodyExtendable() { - private val flattenClassPackage = mrClassPackage.replace(".", "") + private val flattenClassPackage = mrClassPackage.map { it.replace(".", "") } override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -46,10 +47,10 @@ class JsPluralsGenerator( languages = languageMap.keys.toList(), folder = JsMRGenerator.LOCALIZATION_DIR, fallbackFilePropertyName = JsMRGenerator.PLURALS_FALLBACK_FILE_URL_PROPERTY_NAME, - fallbackFile = "${flattenClassPackage}_${JsMRGenerator.PLURALS_JSON_NAME}.json", + fallbackFile = "${flattenClassPackage.get()}_${JsMRGenerator.PLURALS_JSON_NAME}.json", supportedLocalesPropertyName = JsMRGenerator.SUPPORTED_LOCALES_PROPERTY_NAME, getFileNameForLanguage = { language -> - "${flattenClassPackage}_${JsMRGenerator.PLURALS_JSON_NAME}${language.jsResourcesSuffix}.json" + "${flattenClassPackage.get()}_${JsMRGenerator.PLURALS_JSON_NAME}${language.jsResourcesSuffix}.json" } ) val languageKeys = languageMap[LanguageType.Base].orEmpty().keys @@ -73,7 +74,7 @@ class JsPluralsGenerator( strings: Map ) { val fileDirName = - "${flattenClassPackage}_${JsMRGenerator.PLURALS_JSON_NAME}${language.jsResourcesSuffix}" + "${flattenClassPackage.get()}_${JsMRGenerator.PLURALS_JSON_NAME}${language.jsResourcesSuffix}" val localizationDir = File(resourcesGenerationDir, JsMRGenerator.LOCALIZATION_DIR).apply { mkdirs() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt index a78fec14a..becfefcdf 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt @@ -20,16 +20,17 @@ import dev.icerock.gradle.generator.js.JsMRGenerator.Companion.SUPPORTED_LOCALES import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.put import org.gradle.api.file.FileTree +import org.gradle.api.provider.Provider import java.io.File class JsStringsGenerator( stringsFileTree: FileTree, - mrClassPackage: String, + mrClassPackage: Provider, strictLineBreaks: Boolean ) : StringsGenerator(stringsFileTree, strictLineBreaks), ObjectBodyExtendable by NOPObjectBodyExtendable() { - private val flattenClassPackage = mrClassPackage.replace(".", "") + private val flattenClassPackage = mrClassPackage.map { it.replace(".", "") } override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -47,10 +48,10 @@ class JsStringsGenerator( languages = languageMap.keys.toList(), folder = JsMRGenerator.LOCALIZATION_DIR, fallbackFilePropertyName = STRINGS_FALLBACK_FILE_URL_PROPERTY_NAME, - fallbackFile = "${flattenClassPackage}_${JsMRGenerator.STRINGS_JSON_NAME}.json", + fallbackFile = "${flattenClassPackage.get()}_${JsMRGenerator.STRINGS_JSON_NAME}.json", supportedLocalesPropertyName = SUPPORTED_LOCALES_PROPERTY_NAME, getFileNameForLanguage = { language -> - "${flattenClassPackage}_${JsMRGenerator.STRINGS_JSON_NAME}${language.jsResourcesSuffix}.json" + "${flattenClassPackage.get()}_${JsMRGenerator.STRINGS_JSON_NAME}${language.jsResourcesSuffix}.json" } ) val languageKeys = languageMap[LanguageType.Base].orEmpty().keys @@ -74,7 +75,7 @@ class JsStringsGenerator( strings: Map ) { val fileDirName = - "${flattenClassPackage}_${JsMRGenerator.STRINGS_JSON_NAME}${language.jsResourcesSuffix}" + "${flattenClassPackage.get()}_${JsMRGenerator.STRINGS_JSON_NAME}${language.jsResourcesSuffix}" val localizationDir = File(resourcesGenerationDir, JsMRGenerator.LOCALIZATION_DIR).apply { mkdirs() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/ClassLoaderExtender.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/ClassLoaderExtender.kt index 5d20b4a29..1f130e7b3 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/ClassLoaderExtender.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/ClassLoaderExtender.kt @@ -10,8 +10,9 @@ import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.ObjectBodyExtendable +import org.gradle.api.provider.Provider -class ClassLoaderExtender(private val mrClassName: String) : ObjectBodyExtendable { +class ClassLoaderExtender(private val mrClassName: Provider) : ObjectBodyExtendable { override fun extendObjectBodyAtStart(classBuilder: TypeSpec.Builder) { classBuilder.addProperty( PropertySpec.builder( @@ -19,7 +20,7 @@ class ClassLoaderExtender(private val mrClassName: String) : ObjectBodyExtendabl ClassName("java.lang", "ClassLoader"), KModifier.OVERRIDE ) - .initializer(CodeBlock.of("$mrClassName::class.java.classLoader")) + .initializer(CodeBlock.of("${mrClassName.get()}::class.java.classLoader")) .build() ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt index 1a53704c0..af28955a9 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt @@ -13,13 +13,14 @@ import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.utils.dependsOnProcessResources import org.gradle.api.Project import org.gradle.api.Task +import org.gradle.api.file.Directory +import org.gradle.api.provider.Provider import org.gradle.jvm.tasks.Jar import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -import java.io.File class JvmMRGenerator( - generatedDir: File, + generatedDir: Provider, sourceSet: SourceSet, mrSettings: MRSettings, generators: List @@ -29,13 +30,11 @@ class JvmMRGenerator( mrSettings = mrSettings, generators = generators ) { - private val flattenClassName: String get() = mrSettings.packageName.replace(".", "") - - override val resourcesGenerationDir: File - get() = File( - outputDir, - "$flattenClassName/res" - ) + private val flattenClassNameProvider: Provider = mrSettings.packageName + .map { it.replace(".", "") } + override val resourcesGenerationDir: Provider = outputDir.map { + it.dir(flattenClassNameProvider.get()).dir("res") + } override fun getMRClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -51,7 +50,7 @@ class JvmMRGenerator( CodeBlock.of( "\"%L/%L\"", LOCALIZATION_DIR, - "${flattenClassName}_$STRINGS_BUNDLE_NAME" + "${flattenClassNameProvider.get()}_$STRINGS_BUNDLE_NAME" ) ).build() ) @@ -65,7 +64,7 @@ class JvmMRGenerator( CodeBlock.of( "\"%L/%L\"", LOCALIZATION_DIR, - "${flattenClassName}_$PLURALS_BUNDLE_NAME" + "${flattenClassNameProvider.get()}_$PLURALS_BUNDLE_NAME" ) ).build() ) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmPluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmPluralsGenerator.kt index 2328a20c1..50da2b8ba 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmPluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmPluralsGenerator.kt @@ -13,6 +13,7 @@ import dev.icerock.gradle.generator.ObjectBodyExtendable import dev.icerock.gradle.generator.PluralMap import dev.icerock.gradle.generator.PluralsGenerator import org.gradle.api.file.FileTree +import org.gradle.api.provider.Provider import java.io.File class JvmPluralsGenerator( @@ -22,7 +23,8 @@ class JvmPluralsGenerator( ) : PluralsGenerator(pluralsFileTree, strictLineBreaks), ObjectBodyExtendable by ClassLoaderExtender(mrSettings.className) { - private val flattenClassPackage = mrSettings.packageName.replace(".", "") + private val flattenClassPackage: Provider = mrSettings.packageName + .map { it.replace(".", "") } override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -41,7 +43,7 @@ class JvmPluralsGenerator( strings: Map ) { val fileDirName = - "${flattenClassPackage}_${JvmMRGenerator.PLURALS_BUNDLE_NAME}${language.jvmResourcesSuffix}" + "${flattenClassPackage.get()}_${JvmMRGenerator.PLURALS_BUNDLE_NAME}${language.jvmResourcesSuffix}" val localizationDir = File(resourcesGenerationDir, JvmMRGenerator.LOCALIZATION_DIR).apply { mkdirs() } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt index 1fd33926d..a10f6902d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt @@ -12,6 +12,7 @@ import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.ObjectBodyExtendable import dev.icerock.gradle.generator.StringsGenerator import org.gradle.api.file.FileTree +import org.gradle.api.provider.Provider import java.io.File class JvmStringsGenerator( @@ -21,7 +22,8 @@ class JvmStringsGenerator( ) : StringsGenerator(stringsFileTree, strictLineBreaks), ObjectBodyExtendable by ClassLoaderExtender(mrSettings.className) { - private val flattenClassPackage = mrSettings.packageName.replace(".", "") + private val flattenClassPackage: Provider = mrSettings.packageName + .map { it.replace(".", "") } override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -40,7 +42,7 @@ class JvmStringsGenerator( strings: Map ) { val fileDirName = - "${flattenClassPackage}_${JvmMRGenerator.STRINGS_BUNDLE_NAME}${language.jvmResourcesSuffix}" + "${flattenClassPackage.get()}_${JvmMRGenerator.STRINGS_BUNDLE_NAME}${language.jvmResourcesSuffix}" val localizationDir = File(resourcesGenerationDir, JvmMRGenerator.LOCALIZATION_DIR).apply { mkdirs() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt index c60913637..3fe34f393 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt @@ -4,18 +4,17 @@ package dev.icerock.gradle.tasks -import dev.icerock.gradle.utils.klibs import org.gradle.api.DefaultTask +import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.tasks.Internal import org.gradle.api.tasks.TaskAction -import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink import org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl import java.io.File import java.io.FileFilter -open class CopyExecutableResourcesToApp : DefaultTask() { +abstract class CopyExecutableResourcesToApp : DefaultTask() { @get:Internal - lateinit var linkTask: KotlinNativeLink + abstract val klibs: ConfigurableFileCollection init { group = "moko-resources" @@ -30,7 +29,7 @@ open class CopyExecutableResourcesToApp : DefaultTask() { val outputDir = File(buildProductsDir, contentsFolderPath) - linkTask.klibs + klibs .filter { library -> library.extension == "klib" } .filter(File::exists) .forEach { inputFile -> 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 e87f2677b..9cee84537 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 @@ -23,7 +23,7 @@ open class GenerateMultiplatformResourcesTask : DefaultTask() { @get:OutputDirectory val outputDirectory: File - get() = generator.outputDir + get() = generator.outputDir.get().asFile init { group = "moko-resources" diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/KotlinSourceSetExt.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/KotlinSourceSetExt.kt index 322b045d3..26ae3d627 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/KotlinSourceSetExt.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/KotlinSourceSetExt.kt @@ -5,6 +5,11 @@ package dev.icerock.gradle.utils import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet +import org.jetbrains.kotlin.gradle.utils.ObservableSet +import java.util.concurrent.atomic.AtomicBoolean + +internal val KotlinSourceSet.dependsOnObservable + get() = this.dependsOn as ObservableSet @Suppress("ReturnCount") internal fun KotlinSourceSet.isDependsOn(sourceSet: KotlinSourceSet): Boolean { @@ -15,8 +20,23 @@ internal fun KotlinSourceSet.isDependsOn(sourceSet: KotlinSourceSet): Boolean { return false } -internal fun KotlinSourceSet.getDependedFrom(sourceSets: Collection): KotlinSourceSet? { - return sourceSets.firstOrNull { this.dependsOn.contains(it) } ?: this.dependsOn - .mapNotNull { it.getDependedFrom(sourceSets) } - .firstOrNull() +internal fun KotlinSourceSet.ifDependsOn( + sourceSet: KotlinSourceSet, + block: () -> Unit +) = ifDependsOn(sourceSet, AtomicBoolean(false), block) + +private fun KotlinSourceSet.ifDependsOn( + sourceSet: KotlinSourceSet, + sourceSetFound: AtomicBoolean, + block: () -> Unit +) { + if (this == sourceSet) { + if (sourceSetFound.compareAndSet(false, true)) { + block() + } + } else { + dependsOnObservable.forAll { parent -> + parent.ifDependsOn(sourceSet, sourceSetFound, block) + } + } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/TasksContainer.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/TasksContainer.kt new file mode 100644 index 000000000..483c0a621 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/TasksContainer.kt @@ -0,0 +1,21 @@ +/* + * Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.utils + +import org.gradle.api.Task +import org.gradle.api.UnknownTaskException +import org.gradle.api.tasks.TaskContainer +import org.gradle.api.tasks.TaskProvider +import org.gradle.kotlin.dsl.named +import org.gradle.kotlin.dsl.register + +inline fun TaskContainer.maybeRegister( + taskName: String, + noinline configuration: T.() -> Unit +): TaskProvider = try { + named(taskName) +} catch (@Suppress("SwallowedException") ex: UnknownTaskException) { + register(taskName, configuration) +} From e74063d79ea69b3c07c69d1633f9e72a09d09682 Mon Sep 17 00:00:00 2001 From: Luca Spinazzola Date: Mon, 14 Aug 2023 13:54:36 -0400 Subject: [PATCH 023/352] apple: fix getAssetByFilePath for files with no extension `substringAfterLast` returns `missingDelimiterValue` which defaults to the original string. `missingDelimiterValue` should be an empty string when there is no file extension --- .../kotlin/dev/icerock/moko/resources/ResourceContainerExt.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/src/appleMain/kotlin/dev/icerock/moko/resources/ResourceContainerExt.kt b/resources/src/appleMain/kotlin/dev/icerock/moko/resources/ResourceContainerExt.kt index 08ac9ee8b..21c114689 100644 --- a/resources/src/appleMain/kotlin/dev/icerock/moko/resources/ResourceContainerExt.kt +++ b/resources/src/appleMain/kotlin/dev/icerock/moko/resources/ResourceContainerExt.kt @@ -6,7 +6,7 @@ package dev.icerock.moko.resources actual fun ResourceContainer.getAssetByFilePath(filePath: String): AssetResource? { //get name without extension and extension - val ext = filePath.substringAfterLast('.') + val ext = filePath.substringAfterLast('.', "") val name = filePath.substringBeforeLast('.') .replace('/', '+') From 7d4ab7050a734400dfe9cf77e02131270f7d39fd Mon Sep 17 00:00:00 2001 From: maksimgordienko Date: Thu, 31 Aug 2023 20:18:05 +0300 Subject: [PATCH 024/352] Fix #546 and #549 --- .../kotlin/dev/icerock/moko/resources/ImageResource.kt | 2 +- .../kotlin/dev/icerock/moko/resources/ImageResource.kt | 4 +++- .../dev/icerock/moko/resources/desc/image/ImageDesc.kt | 2 +- .../icerock/moko/resources/desc/image/ImageDescResource.kt | 4 +++- .../dev/icerock/moko/resources/desc/image/ImageDescUrl.kt | 5 ++++- .../kotlin/dev/icerock/moko/resources/ImageResource.kt | 5 +++-- .../kotlin/dev/icerock/moko/resources/ImageResource.kt | 4 +++- .../kotlin/dev/icerock/moko/resources/ImageResource.kt | 5 +++-- .../kotlin/dev/icerock/moko/resources/ImageResource.kt | 5 +++-- 9 files changed, 24 insertions(+), 12 deletions(-) diff --git a/resources/src/androidMain/kotlin/dev/icerock/moko/resources/ImageResource.kt b/resources/src/androidMain/kotlin/dev/icerock/moko/resources/ImageResource.kt index 649913603..06db99aba 100644 --- a/resources/src/androidMain/kotlin/dev/icerock/moko/resources/ImageResource.kt +++ b/resources/src/androidMain/kotlin/dev/icerock/moko/resources/ImageResource.kt @@ -12,7 +12,7 @@ import androidx.core.content.ContextCompat import kotlinx.parcelize.Parcelize @Parcelize -actual class ImageResource( +actual data class ImageResource( @DrawableRes val drawableResId: Int ) : Parcelable { diff --git a/resources/src/commonMain/kotlin/dev/icerock/moko/resources/ImageResource.kt b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/ImageResource.kt index 7bc6cd2f4..6265d4019 100644 --- a/resources/src/commonMain/kotlin/dev/icerock/moko/resources/ImageResource.kt +++ b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/ImageResource.kt @@ -4,4 +4,6 @@ package dev.icerock.moko.resources -expect class ImageResource +import dev.icerock.moko.parcelize.Parcelable + +expect class ImageResource : Parcelable diff --git a/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/image/ImageDesc.kt b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/image/ImageDesc.kt index a4199690a..826560775 100644 --- a/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/image/ImageDesc.kt +++ b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/image/ImageDesc.kt @@ -4,6 +4,6 @@ package dev.icerock.moko.resources.desc.image -interface ImageDesc { +interface ImageDesc : Parcelable { companion object } diff --git a/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/image/ImageDescResource.kt b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/image/ImageDescResource.kt index 26b65b2b4..3deb896a8 100644 --- a/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/image/ImageDescResource.kt +++ b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/image/ImageDescResource.kt @@ -4,9 +4,11 @@ package dev.icerock.moko.resources.desc.image +import dev.icerock.moko.parcelize.Parcelize import dev.icerock.moko.resources.ImageResource -class ImageDescResource(val resource: ImageResource) : ImageDesc +@Parcelize +data class ImageDescResource(val resource: ImageResource) : ImageDesc @Suppress("FunctionName") fun ImageDesc.Companion.Resource(resource: ImageResource): ImageDesc = ImageDescResource(resource) diff --git a/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/image/ImageDescUrl.kt b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/image/ImageDescUrl.kt index 687a78678..ef2bcee69 100644 --- a/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/image/ImageDescUrl.kt +++ b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/image/ImageDescUrl.kt @@ -4,7 +4,10 @@ package dev.icerock.moko.resources.desc.image -class ImageDescUrl(val url: String) : ImageDesc +import dev.icerock.moko.parcelize.Parcelize + +@Parcelize +data class ImageDescUrl(val url: String) : ImageDesc @Suppress("FunctionName") fun ImageDesc.Companion.Url(url: String): ImageDesc = ImageDescUrl(url) diff --git a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/ImageResource.kt b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/ImageResource.kt index 7f703176f..7d4c1e54e 100644 --- a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/ImageResource.kt +++ b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/ImageResource.kt @@ -4,13 +4,14 @@ package dev.icerock.moko.resources +import dev.icerock.moko.parcelize.Parcelable import platform.Foundation.NSBundle import platform.UIKit.UIImage -actual class ImageResource( +actual data class ImageResource( val assetImageName: String, val bundle: NSBundle = NSBundle.mainBundle -) { +) : Parcelable { fun toUIImage(): UIImage? { return UIImage.imageNamed( name = assetImageName, diff --git a/resources/src/jsMain/kotlin/dev/icerock/moko/resources/ImageResource.kt b/resources/src/jsMain/kotlin/dev/icerock/moko/resources/ImageResource.kt index 9dd736344..0d2d70fd8 100644 --- a/resources/src/jsMain/kotlin/dev/icerock/moko/resources/ImageResource.kt +++ b/resources/src/jsMain/kotlin/dev/icerock/moko/resources/ImageResource.kt @@ -4,4 +4,6 @@ package dev.icerock.moko.resources -actual class ImageResource(val fileName: String, val fileUrl: String) +import dev.icerock.moko.parcelize.Parcelable + +actual data class ImageResource(val fileName: String, val fileUrl: String) : Parcelable diff --git a/resources/src/jvmMain/kotlin/dev/icerock/moko/resources/ImageResource.kt b/resources/src/jvmMain/kotlin/dev/icerock/moko/resources/ImageResource.kt index 41d81eb9f..2d3a90bb8 100644 --- a/resources/src/jvmMain/kotlin/dev/icerock/moko/resources/ImageResource.kt +++ b/resources/src/jvmMain/kotlin/dev/icerock/moko/resources/ImageResource.kt @@ -4,6 +4,7 @@ package dev.icerock.moko.resources +import dev.icerock.moko.parcelize.Parcelable import org.apache.batik.transcoder.Transcoder import org.apache.batik.transcoder.TranscoderInput import org.apache.batik.transcoder.TranscoderOutput @@ -15,10 +16,10 @@ import java.io.PipedInputStream import java.io.PipedOutputStream import javax.imageio.ImageIO -actual class ImageResource( +actual data class ImageResource( val resourcesClassLoader: ClassLoader, val filePath: String -) { +) : Parcelable { val image: BufferedImage by lazy { val stream = resourcesClassLoader.getResourceAsStream(filePath) ?: throw FileNotFoundException("Couldn't open resource as stream at: $filePath") diff --git a/resources/src/macosMain/kotlin/dev/icerock/moko/resources/ImageResource.kt b/resources/src/macosMain/kotlin/dev/icerock/moko/resources/ImageResource.kt index bc02191c6..8d17f3457 100644 --- a/resources/src/macosMain/kotlin/dev/icerock/moko/resources/ImageResource.kt +++ b/resources/src/macosMain/kotlin/dev/icerock/moko/resources/ImageResource.kt @@ -4,14 +4,15 @@ package dev.icerock.moko.resources +import dev.icerock.moko.parcelize.Parcelable import platform.AppKit.NSImage import platform.AppKit.imageForResource import platform.Foundation.NSBundle -actual class ImageResource( +actual data class ImageResource( val assetImageName: String, val bundle: NSBundle = NSBundle.mainBundle -) { +) : Parcelable { fun toNSImage(): NSImage? = NSImage.imageNamed(assetImageName) ?: bundle.imageForResource(assetImageName) } From 045fe89327f6efcd821cf8f1017dc2022c20bd3d Mon Sep 17 00:00:00 2001 From: maksimgordienko Date: Thu, 31 Aug 2023 20:24:01 +0300 Subject: [PATCH 025/352] Fix #546 and #549 --- .../kotlin/dev/icerock/moko/resources/desc/image/ImageDesc.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/image/ImageDesc.kt b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/image/ImageDesc.kt index 826560775..0aee58381 100644 --- a/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/image/ImageDesc.kt +++ b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/image/ImageDesc.kt @@ -4,6 +4,8 @@ package dev.icerock.moko.resources.desc.image +import dev.icerock.moko.parcelize.Parcelable + interface ImageDesc : Parcelable { companion object } From a279e1918a5f04f1de6cfcded17494a98405c831 Mon Sep 17 00:00:00 2001 From: maksimgordienko Date: Fri, 1 Sep 2023 19:54:36 +0300 Subject: [PATCH 026/352] * Refactoring MultiplatformResourcesPluginExtension: changed to abstract class and fields replaced with Gradle's Property instances. Removed redundant multipaltform prefix for move convenient reading. Extension methods to access default values --- .../gradle/MultiplatformResourcesPlugin.kt | 14 ++++---- .../MultiplatformResourcesPluginExtension.kt | 34 +++++++++++++------ .../generator/apple/AppleMRGenerator.kt | 3 +- 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index d9691de5a..48ab194b3 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -50,8 +50,6 @@ class MultiplatformResourcesPlugin : Plugin { "multiplatformResources", MultiplatformResourcesPluginExtension::class ) - mrExtension.multiplatformResourcesPackage = "${target.group}.${target.name}" - target.plugins.withType(KotlinMultiplatformPluginWrapper::class) { val multiplatformExtension = target.extensions.getByType(KotlinMultiplatformExtension::class) @@ -72,11 +70,11 @@ class MultiplatformResourcesPlugin : Plugin { mrExtension: MultiplatformResourcesPluginExtension, multiplatformExtension: KotlinMultiplatformExtension ) { - val commonSourceSet = multiplatformExtension.sourceSets.getByName(mrExtension.sourceSetName) + val commonSourceSet = multiplatformExtension.sourceSets.getByName(mrExtension.resourcesSourceSetValue) val commonResources = commonSourceSet.resources val generatedDir = File(target.buildDir, "generated/moko") - val mrClassPackage: String = requireNotNull(mrExtension.multiplatformResourcesPackage) { + val mrClassPackage: String = requireNotNull(mrExtension.resourcesPackageValue(target)) { buildString { appendLine("multiplatformResources.multiplatformResourcesPackage is required!") append("Please configure moko-resources plugin correctly.") @@ -84,13 +82,13 @@ class MultiplatformResourcesPlugin : Plugin { } val mrSettings = MRGenerator.MRSettings( packageName = mrClassPackage, - className = mrExtension.multiplatformResourcesClassName, - visibility = mrExtension.multiplatformResourcesVisibility + className = mrExtension.resourcesClassNameValue, + visibility = mrExtension.resourcesVisibilityValue ) val sourceInfo = SourceInfo( generatedDir, commonResources, - mrExtension.multiplatformResourcesPackage!! + mrExtension.resourcesPackageValue(target) ) val strictLineBreaks: Boolean = target @@ -99,7 +97,7 @@ class MultiplatformResourcesPlugin : Plugin { ?.toBoolean() ?: false - val iosLocalizationRegion = mrExtension.iosBaseLocalizationRegion + val iosLocalizationRegion = mrExtension.iosBaseLocalizationRegionValue val features = listOf( StringsGenerator.Feature( info = sourceInfo, 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 dd79293d4..c993ce620 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPluginExtension.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPluginExtension.kt @@ -4,15 +4,29 @@ package dev.icerock.gradle -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet +import org.gradle.api.Project +import org.gradle.api.provider.Property -open class MultiplatformResourcesPluginExtension { - var multiplatformResourcesPackage: String? = null - var multiplatformResourcesClassName: String = "MR" - var multiplatformResourcesSourceSet: String? = null - var iosBaseLocalizationRegion: String = "en" - val sourceSetName: String - get() = multiplatformResourcesSourceSet ?: KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME - var disableStaticFrameworkWarning = false - var multiplatformResourcesVisibility: MRVisibility = MRVisibility.Public +abstract class MultiplatformResourcesPluginExtension { + abstract val resourcesPackage: Property + abstract val resourcesClassName: Property + abstract val resourcesSourceSet: Property + abstract val iosBaseLocalizationRegion: Property + abstract val staticFrameworkWarningEnabled: Property + abstract val resourcesVisibility: Property } + +internal fun MultiplatformResourcesPluginExtension.resourcesPackageValue(project : Project): String { + return resourcesPackage.getOrElse("${project.group}.${project.name}") +} + +internal val MultiplatformResourcesPluginExtension.resourcesClassNameValue : String + get() = resourcesClassName.getOrElse("MR") +internal val MultiplatformResourcesPluginExtension.resourcesSourceSetValue : String + get() = resourcesSourceSet.getOrElse("commonMain") +internal val MultiplatformResourcesPluginExtension.iosBaseLocalizationRegionValue : String + get() = iosBaseLocalizationRegion.getOrElse("en") +internal val MultiplatformResourcesPluginExtension.isStaticFrameworkWarningEnabledValue : Boolean + get() = staticFrameworkWarningEnabled.getOrElse(true) +internal val MultiplatformResourcesPluginExtension.resourcesVisibilityValue : MRVisibility + get() = resourcesVisibility.getOrElse(MRVisibility.Public) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt index 0c473706a..cb9970578 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt @@ -15,6 +15,7 @@ import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.apple.action.CopyResourcesFromKLibsToExecutableAction import dev.icerock.gradle.generator.apple.action.CopyResourcesFromKLibsToFrameworkAction import dev.icerock.gradle.generator.apple.action.PackResourcesToKLibAction +import dev.icerock.gradle.isStaticFrameworkWarningEnabledValue import dev.icerock.gradle.tasks.CopyExecutableResourcesToApp import dev.icerock.gradle.tasks.CopyFrameworkResourcesToAppEntryPointTask import dev.icerock.gradle.tasks.CopyFrameworkResourcesToAppTask @@ -145,7 +146,7 @@ class AppleMRGenerator( if (framework.isStatic) { val resourcesExtension = project.extensions.getByType() - if (resourcesExtension.disableStaticFrameworkWarning.not()) { + if (resourcesExtension.isStaticFrameworkWarningEnabledValue) { project.logger.warn( """ $linkTask produces static framework, Xcode should have Build Phase with copyFrameworkResourcesToApp gradle task call. Please read readme on https://github.com/icerockdev/moko-resources From b7f6ffa82b40a785576fb8f0dd4ed650b7aa2d9d Mon Sep 17 00:00:00 2001 From: maksimgordienko Date: Fri, 1 Sep 2023 19:57:26 +0300 Subject: [PATCH 027/352] * Removed default value with Project reference for resourcesPackage field, because it's actually not correct by default. Users should configure package names for their projects due to their requirements --- .../kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt | 4 ++-- .../icerock/gradle/MultiplatformResourcesPluginExtension.kt | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 48ab194b3..4751e1ac8 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -74,7 +74,7 @@ class MultiplatformResourcesPlugin : Plugin { val commonResources = commonSourceSet.resources val generatedDir = File(target.buildDir, "generated/moko") - val mrClassPackage: String = requireNotNull(mrExtension.resourcesPackageValue(target)) { + val mrClassPackage: String = requireNotNull(mrExtension.resourcesPackage.orNull) { buildString { appendLine("multiplatformResources.multiplatformResourcesPackage is required!") append("Please configure moko-resources plugin correctly.") @@ -88,7 +88,7 @@ class MultiplatformResourcesPlugin : Plugin { val sourceInfo = SourceInfo( generatedDir, commonResources, - mrExtension.resourcesPackageValue(target) + mrClassPackage ) val strictLineBreaks: Boolean = target 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 c993ce620..7ffabf59a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPluginExtension.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPluginExtension.kt @@ -16,10 +16,6 @@ abstract class MultiplatformResourcesPluginExtension { abstract val resourcesVisibility: Property } -internal fun MultiplatformResourcesPluginExtension.resourcesPackageValue(project : Project): String { - return resourcesPackage.getOrElse("${project.group}.${project.name}") -} - internal val MultiplatformResourcesPluginExtension.resourcesClassNameValue : String get() = resourcesClassName.getOrElse("MR") internal val MultiplatformResourcesPluginExtension.resourcesSourceSetValue : String From a1512a3627925fdc99262f7a5c9e92da5c5ede6a Mon Sep 17 00:00:00 2001 From: maksimgordienko Date: Fri, 1 Sep 2023 19:57:46 +0300 Subject: [PATCH 028/352] * Removed default value with Project reference for resourcesPackage field, because it's actually not correct by default. Users should configure package names for their projects due to their requirements --- .../kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 4751e1ac8..0c82c4d2b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -76,7 +76,7 @@ class MultiplatformResourcesPlugin : Plugin { val generatedDir = File(target.buildDir, "generated/moko") val mrClassPackage: String = requireNotNull(mrExtension.resourcesPackage.orNull) { buildString { - appendLine("multiplatformResources.multiplatformResourcesPackage is required!") + appendLine("multiplatformResources.resourcesPackage is required!") append("Please configure moko-resources plugin correctly.") } } From df53eda939f384e9940de22b6da665662593dc88 Mon Sep 17 00:00:00 2001 From: maksimgordienko Date: Fri, 1 Sep 2023 21:50:25 +0300 Subject: [PATCH 029/352] * Actual #535 fix --- .../gradle/MultiplatformResourcesPlugin.kt | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 0c82c4d2b..fe0f8d6c4 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -5,6 +5,7 @@ package dev.icerock.gradle import com.android.build.gradle.BaseExtension +import com.android.build.gradle.internal.tasks.factory.dependsOn import dev.icerock.gradle.generator.AssetsGenerator import dev.icerock.gradle.generator.ColorsGenerator import dev.icerock.gradle.generator.FilesGenerator @@ -74,7 +75,7 @@ class MultiplatformResourcesPlugin : Plugin { val commonResources = commonSourceSet.resources val generatedDir = File(target.buildDir, "generated/moko") - val mrClassPackage: String = requireNotNull(mrExtension.resourcesPackage.orNull) { + val mrClassPackage: String = requireNotNull(mrExtension.resourcesPackage.orNull.orEmpty()) { buildString { appendLine("multiplatformResources.resourcesPackage is required!") append("Please configure moko-resources plugin correctly.") @@ -320,21 +321,16 @@ class MultiplatformResourcesPlugin : Plugin { } private fun setupCopyXCFrameworkResourcesTask(project: Project) { - // can't use here configureEach because we will add new task when found xcframeworktask - project.afterEvaluate { - project.tasks.filterIsInstance() - .forEach { task -> - val copyTaskName: String = - task.name.replace("assemble", "copyResources").plus("ToApp") - - val copyTask = project.tasks.create( - copyTaskName, - CopyXCFrameworkResourcesToApp::class.java - ) { - it.xcFrameworkDir = task.outputDir - } - copyTask.dependsOn(task) - } + //Seems that there were problem with this block in the past with mystic task adding. Need more info + //Now, that works perfectly, I've tested on the real project with Kotlin 1.9.10 and KSP enabled + //Suppose that on that moment there were no lazy register method for task container + project.tasks.withType(XCFrameworkTask::class).configureEach { task -> + val copyTaskName: String = + task.name.replace("assemble", "copyResources").plus("ToApp") + project.tasks.register(copyTaskName, CopyXCFrameworkResourcesToApp::class.java) { + it.xcFrameworkDir = task.outputDir + it.dependsOn(task) + } } } From 316f2a66559e510f2be8302a87331437bc9238b5 Mon Sep 17 00:00:00 2001 From: maksimgordienko Date: Mon, 4 Sep 2023 10:02:54 +0300 Subject: [PATCH 030/352] * Detekt problems fix --- .../gradle/MultiplatformResourcesPlugin.kt | 8 +++--- .../MultiplatformResourcesPluginExtension.kt | 25 +++++++++---------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index fe0f8d6c4..2eb8f3340 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -75,7 +75,7 @@ class MultiplatformResourcesPlugin : Plugin { val commonResources = commonSourceSet.resources val generatedDir = File(target.buildDir, "generated/moko") - val mrClassPackage: String = requireNotNull(mrExtension.resourcesPackage.orNull.orEmpty()) { + val mrClassPackage: String = requireNotNull(mrExtension.resourcesPackage.orNull) { buildString { appendLine("multiplatformResources.resourcesPackage is required!") append("Please configure moko-resources plugin correctly.") @@ -321,9 +321,9 @@ class MultiplatformResourcesPlugin : Plugin { } private fun setupCopyXCFrameworkResourcesTask(project: Project) { - //Seems that there were problem with this block in the past with mystic task adding. Need more info - //Now, that works perfectly, I've tested on the real project with Kotlin 1.9.10 and KSP enabled - //Suppose that on that moment there were no lazy register method for task container + // Seems that there were problem with this block in the past with mystic task adding. Need more info + // Now, that works perfectly, I've tested on the real project with Kotlin 1.9.10 and KSP enabled + // Suppose that on that moment there were no lazy register method for task container project.tasks.withType(XCFrameworkTask::class).configureEach { task -> val copyTaskName: String = task.name.replace("assemble", "copyResources").plus("ToApp") 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 7ffabf59a..aee8a5927 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPluginExtension.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPluginExtension.kt @@ -4,25 +4,24 @@ package dev.icerock.gradle -import org.gradle.api.Project import org.gradle.api.provider.Property -abstract class MultiplatformResourcesPluginExtension { - abstract val resourcesPackage: Property - abstract val resourcesClassName: Property - abstract val resourcesSourceSet: Property - abstract val iosBaseLocalizationRegion: Property - abstract val staticFrameworkWarningEnabled: Property - abstract val resourcesVisibility: Property +interface MultiplatformResourcesPluginExtension { + val resourcesPackage: Property + val resourcesClassName: Property + val resourcesSourceSet: Property + val iosBaseLocalizationRegion: Property + val staticFrameworkWarningEnabled: Property + val resourcesVisibility: Property } -internal val MultiplatformResourcesPluginExtension.resourcesClassNameValue : String +internal val MultiplatformResourcesPluginExtension.resourcesClassNameValue: String get() = resourcesClassName.getOrElse("MR") -internal val MultiplatformResourcesPluginExtension.resourcesSourceSetValue : String +internal val MultiplatformResourcesPluginExtension.resourcesSourceSetValue: String get() = resourcesSourceSet.getOrElse("commonMain") -internal val MultiplatformResourcesPluginExtension.iosBaseLocalizationRegionValue : String +internal val MultiplatformResourcesPluginExtension.iosBaseLocalizationRegionValue: String get() = iosBaseLocalizationRegion.getOrElse("en") -internal val MultiplatformResourcesPluginExtension.isStaticFrameworkWarningEnabledValue : Boolean +internal val MultiplatformResourcesPluginExtension.isStaticFrameworkWarningEnabledValue: Boolean get() = staticFrameworkWarningEnabled.getOrElse(true) -internal val MultiplatformResourcesPluginExtension.resourcesVisibilityValue : MRVisibility +internal val MultiplatformResourcesPluginExtension.resourcesVisibilityValue: MRVisibility get() = resourcesVisibility.getOrElse(MRVisibility.Public) From ec8a08d9bb39fc3ed7bea82ae5a002d630826207 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 10 Sep 2023 00:37:19 +0700 Subject: [PATCH 031/352] #535 rework apple app resources task registration --- .../gradle/MultiplatformResourcesPlugin.kt | 3 ++ .../gradle/configuration/AppleTargets.kt | 33 +++++++++++++++++-- .../generator/apple/AppleMRGenerator.kt | 20 ----------- samples/android-mpp-app/app/build.gradle.kts | 2 +- 4 files changed, 35 insertions(+), 23 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 0eb2c7078..0070530ff 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -10,6 +10,7 @@ import dev.icerock.gradle.configuration.configureCommonTargetGenerator import dev.icerock.gradle.configuration.configureJsTargetGenerator import dev.icerock.gradle.configuration.configureJvmTargetGenerator import dev.icerock.gradle.configuration.getAndroidRClassPackage +import dev.icerock.gradle.configuration.setupProjectForApple import dev.icerock.gradle.generator.AssetsGenerator import dev.icerock.gradle.generator.ColorsGenerator import dev.icerock.gradle.generator.FilesGenerator @@ -99,6 +100,8 @@ open class MultiplatformResourcesPlugin : Plugin { settings = settings ) } + + setupProjectForApple(project) } private fun configureKotlinTargetGenerator( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt index 5d1ac84c5..3237fd184 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt @@ -7,13 +7,18 @@ package dev.icerock.gradle.configuration import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.ResourceGeneratorFeature import dev.icerock.gradle.generator.apple.AppleMRGenerator +import dev.icerock.gradle.tasks.CopyExecutableResourcesToApp import dev.icerock.gradle.tasks.CopyXCFrameworkResourcesToApp +import dev.icerock.gradle.utils.klibs import org.gradle.api.Project +import org.gradle.kotlin.dsl.register import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation +import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractExecutable import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFrameworkTask +import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink import org.jetbrains.kotlin.konan.target.HostManager internal fun configureAppleTargetGenerator( @@ -37,15 +42,23 @@ internal fun configureAppleTargetGenerator( compilation = mainCompilation, baseLocalizationRegion = settings.iosLocalizationRegion ).apply(target.project) +} + +internal fun setupProjectForApple(project: Project) { + if (HostManager.hostIsMac.not()) { + project.logger.warn("MR file generation for Apple is not supported on your system!") + return + } - setupCopyXCFrameworkResourcesTask(project = target.project) + setupCopyXCFrameworkResourcesTask(project) + createCopyResourcesToAppTask(project) } private fun setupCopyXCFrameworkResourcesTask(project: Project) { // Seems that there were problem with this block in the past with mystic task adding. Need more info // Now, that works perfectly, I've tested on the real project with Kotlin 1.9.10 and KSP enabled // Suppose that on that moment there were no lazy register method for task container - project.tasks.withType(XCFrameworkTask::class).configureEach { task -> + project.tasks.withType(XCFrameworkTask::class).all { task -> val copyTaskName: String = task.name .replace("assemble", "copyResources").plus("ToApp") @@ -55,3 +68,19 @@ private fun setupCopyXCFrameworkResourcesTask(project: Project) { } } } + +private fun createCopyResourcesToAppTask(project: Project) { + project.tasks + .withType() + .matching { it.binary is AbstractExecutable } + .all { linkTask -> + val copyTaskName: String = linkTask.name.replace("link", "copyResources") + + project.tasks.register(copyTaskName) { + this.klibs.from( + linkTask.klibs.filter { it.path.endsWith(".klib") && it.exists() } + ) + this.dependsOn(linkTask) + } + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt index d87442c1d..71bf3fb85 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt @@ -16,12 +16,9 @@ import dev.icerock.gradle.generator.apple.action.CopyResourcesFromKLibsToExecuta import dev.icerock.gradle.generator.apple.action.CopyResourcesFromKLibsToFrameworkAction import dev.icerock.gradle.generator.apple.action.PackResourcesToKLibAction import dev.icerock.gradle.getIsStaticFrameworkWarningEnabled -import dev.icerock.gradle.tasks.CopyExecutableResourcesToApp import dev.icerock.gradle.tasks.CopyFrameworkResourcesToAppEntryPointTask import dev.icerock.gradle.tasks.CopyFrameworkResourcesToAppTask import dev.icerock.gradle.utils.calculateResourcesHash -import dev.icerock.gradle.utils.klibs -import dev.icerock.gradle.utils.maybeRegister import org.gradle.api.Action import org.gradle.api.Project import org.gradle.api.Task @@ -34,7 +31,6 @@ import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompile import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension -import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractExecutable import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractKotlinNativeCompilation import org.jetbrains.kotlin.gradle.plugin.mpp.Framework import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget @@ -92,7 +88,6 @@ class AppleMRGenerator( ) override fun apply(generationTask: Task, project: Project) { - createCopyResourcesToAppTask(project) setupKLibResources(generationTask) setupFrameworkResources() setupTestsResources() @@ -157,21 +152,6 @@ $linkTask produces static framework, Xcode should have Build Phase with copyFram } } - private fun createCopyResourcesToAppTask(project: Project) = project.afterEvaluate { - project.tasks.withType() - .matching { it.binary is AbstractExecutable } - .all { linkTask -> - val copyTaskName = linkTask.name.replace("link", "copyResources") - - project.tasks.maybeRegister(copyTaskName) { - this.klibs.from( - linkTask.klibs.filter { it.path.endsWith(".klib") && it.exists() } - ) - this.dependsOn(linkTask) - } - } - } - private fun createCopyFrameworkResourcesTask(linkTask: KotlinNativeLink) { val framework = linkTask.binary as Framework val project = linkTask.project diff --git a/samples/android-mpp-app/app/build.gradle.kts b/samples/android-mpp-app/app/build.gradle.kts index 14cc6998a..faa2d5b9c 100644 --- a/samples/android-mpp-app/app/build.gradle.kts +++ b/samples/android-mpp-app/app/build.gradle.kts @@ -44,5 +44,5 @@ dependencies { } multiplatformResources { - multiplatformResourcesPackage = "com.icerockdev.library" + resourcesPackage.set("com.icerockdev.library") } From b9857290ea3ad2cff13c17e4897a7e72a54791e8 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 10 Sep 2023 23:07:32 +0700 Subject: [PATCH 032/352] #535 fix some errors in samples check --- .../gradle/configuration/AppleTargets.kt | 21 ++++++++-------- .../icerock/gradle/configuration/JvmTarget.kt | 24 +++++++++++-------- .../icerock/gradle/generator/MRGenerator.kt | 6 +++-- .../generator/android/AndroidMRGenerator.kt | 4 ++-- .../generator/apple/AppleMRGenerator.kt | 16 +++++++++---- .../generator/common/CommonMRGenerator.kt | 3 ++- .../gradle/generator/js/JsMRGenerator.kt | 3 ++- .../gradle/generator/jvm/JvmMRGenerator.kt | 3 ++- .../tasks/CopyExecutableResourcesToApp.kt | 6 +++-- .../mpp-library/build.gradle.kts | 2 +- .../compose-jvm-app/common/build.gradle.kts | 2 +- .../ios-static-xcframework/build.gradle.kts | 2 +- .../mpp-library/build.gradle.kts | 2 +- .../ios-kotlin-app/build.gradle.kts | 4 ++-- .../mpp-library/build.gradle.kts | 4 ++-- 15 files changed, 60 insertions(+), 42 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt index 3237fd184..87d318233 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt @@ -9,7 +9,6 @@ import dev.icerock.gradle.generator.ResourceGeneratorFeature import dev.icerock.gradle.generator.apple.AppleMRGenerator import dev.icerock.gradle.tasks.CopyExecutableResourcesToApp import dev.icerock.gradle.tasks.CopyXCFrameworkResourcesToApp -import dev.icerock.gradle.utils.klibs import org.gradle.api.Project import org.gradle.kotlin.dsl.register import org.gradle.kotlin.dsl.withType @@ -50,8 +49,12 @@ internal fun setupProjectForApple(project: Project) { return } - setupCopyXCFrameworkResourcesTask(project) - createCopyResourcesToAppTask(project) + // without this afterEvaluate in ios-static-xcframework sample we got + // configuration iosArm64DebugFrameworkExport not found error + project.afterEvaluate { + setupCopyXCFrameworkResourcesTask(project) + createCopyResourcesToAppTask(project) + } } private fun setupCopyXCFrameworkResourcesTask(project: Project) { @@ -62,9 +65,9 @@ private fun setupCopyXCFrameworkResourcesTask(project: Project) { val copyTaskName: String = task.name .replace("assemble", "copyResources").plus("ToApp") - project.tasks.register(copyTaskName, CopyXCFrameworkResourcesToApp::class.java) { - it.xcFrameworkDir = task.outputDir - it.dependsOn(task) + project.tasks.register(copyTaskName) { + xcFrameworkDir = task.outputDir + dependsOn(task) } } } @@ -77,10 +80,8 @@ private fun createCopyResourcesToAppTask(project: Project) { val copyTaskName: String = linkTask.name.replace("link", "copyResources") project.tasks.register(copyTaskName) { - this.klibs.from( - linkTask.klibs.filter { it.path.endsWith(".klib") && it.exists() } - ) - this.dependsOn(linkTask) + this.linkTask = linkTask + dependsOn(linkTask) } } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JvmTarget.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JvmTarget.kt index 84d893091..c70f3a64c 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JvmTarget.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JvmTarget.kt @@ -7,6 +7,7 @@ package dev.icerock.gradle.configuration import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.ResourceGeneratorFeature import dev.icerock.gradle.generator.jvm.JvmMRGenerator +import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation import org.jetbrains.kotlin.gradle.plugin.KotlinTarget internal fun configureJvmTargetGenerator( @@ -14,16 +15,19 @@ internal fun configureJvmTargetGenerator( settings: MRGenerator.Settings, features: List> ) { - target.compilations - .configureEach { compilation -> - // TODO fix depends on + val mainCompilation: KotlinCompilation<*> = target.compilations + .getByName(KotlinCompilation.MAIN_COMPILATION_NAME) + + JvmMRGenerator( + generatedDir = settings.generatedDir, + sourceSet = target.project.provider { createSourceSet(mainCompilation.defaultSourceSet) }, + settings = settings, + generators = features.map { it.createJvmGenerator() } + ).apply(project = target.project) + + + // TODO fix depends on // compilation.defaultSourceSet.ifDependsOn(commonSourceSet) { - JvmMRGenerator( - generatedDir = settings.generatedDir, - sourceSet = target.project.provider { createSourceSet(compilation.defaultSourceSet) }, - settings = settings, - generators = features.map { it.createJvmGenerator() } - ).apply(project = target.project) + // } - } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt index 1b945746d..226bff760 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt @@ -13,7 +13,6 @@ import dev.icerock.gradle.MRVisibility import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.toModifier import org.gradle.api.Project -import org.gradle.api.Task import org.gradle.api.file.SourceDirectorySet import org.gradle.api.provider.Provider import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet @@ -114,7 +113,10 @@ abstract class MRGenerator( protected open fun afterMRGeneration() = Unit protected abstract fun getMRClassModifiers(): Array - protected abstract fun apply(generationTask: Task, project: Project) + protected abstract fun apply( + generationTask: GenerateMultiplatformResourcesTask, + project: Project + ) protected open fun processMRClass(mrClass: TypeSpec.Builder) {} protected open fun getImports(): List = emptyList() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt index 5b61b189b..19dcb1eb0 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt @@ -8,8 +8,8 @@ import com.android.build.gradle.tasks.GenerateResValues import com.android.build.gradle.tasks.MergeSourceSetFolders import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.MRGenerator +import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import org.gradle.api.Project -import org.gradle.api.Task import org.gradle.api.provider.Provider import org.gradle.kotlin.dsl.withType import java.io.File @@ -27,7 +27,7 @@ class AndroidMRGenerator( ) { override fun getMRClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - override fun apply(generationTask: Task, project: Project) { + override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { project.tasks.withType().configureEach { it.dependsOn(generationTask) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt index 71bf3fb85..ca24b0e06 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt @@ -18,7 +18,9 @@ import dev.icerock.gradle.generator.apple.action.PackResourcesToKLibAction import dev.icerock.gradle.getIsStaticFrameworkWarningEnabled import dev.icerock.gradle.tasks.CopyFrameworkResourcesToAppEntryPointTask import dev.icerock.gradle.tasks.CopyFrameworkResourcesToAppTask +import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.utils.calculateResourcesHash +import dev.icerock.gradle.utils.dependsOnProcessResources import org.gradle.api.Action import org.gradle.api.Project import org.gradle.api.Task @@ -87,7 +89,7 @@ class AppleMRGenerator( ClassName("dev.icerock.moko.resources.utils", "loadableBundle") ) - override fun apply(generationTask: Task, project: Project) { + override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { setupKLibResources(generationTask) setupFrameworkResources() setupTestsResources() @@ -98,12 +100,10 @@ class AppleMRGenerator( assetsGenerationDir.get().mkdirs() } - private fun setupKLibResources(generationTask: Task) { + private fun setupKLibResources(generationTask: GenerateMultiplatformResourcesTask) { val compileTask: TaskProvider = compilation.compileTaskProvider - compileTask.configure { - it.dependsOn(generationTask) - } + compileTask.configure { it.dependsOn(generationTask) } // tasks like compileIosMainKotlinMetadata when only one target enabled generationTask.project.tasks @@ -122,6 +122,12 @@ class AppleMRGenerator( } it.dependsOn(generationTask) } + + dependsOnProcessResources( + project = generationTask.project, + sourceSet = sourceSet, + task = generationTask, + ) } private fun setupFrameworkResources() { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index 328753c3a..101912446 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -6,6 +6,7 @@ package dev.icerock.gradle.generator.common import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.MRGenerator +import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import org.gradle.api.Project import org.gradle.api.Task import org.gradle.api.provider.Provider @@ -27,7 +28,7 @@ class CommonMRGenerator( override fun getMRClassModifiers(): Array = arrayOf(KModifier.EXPECT) - override fun apply(generationTask: Task, project: Project) { + override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { project.tasks .withType>() // .matching { it.name.contains(sourceSet.name, ignoreCase = true) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt index 8498d2880..a2f738a1c 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt @@ -10,6 +10,7 @@ import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.STRING import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.MRGenerator +import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.utils.calculateResourcesHash import dev.icerock.gradle.utils.dependsOnProcessResources import dev.icerock.gradle.utils.klibs @@ -88,7 +89,7 @@ class JsMRGenerator( } } - override fun apply(generationTask: Task, project: Project) { + override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { project.tasks.withType().configureEach { it.dependsOn(generationTask) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt index 5e5fb1c52..c3b18f735 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt @@ -10,6 +10,7 @@ import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.STRING import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.MRGenerator +import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.utils.dependsOnProcessResources import org.gradle.api.Project import org.gradle.api.Task @@ -71,7 +72,7 @@ class JvmMRGenerator( ) } - override fun apply(generationTask: Task, project: Project) { + override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { project.tasks.withType().configureEach { it.dependsOn(generationTask) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt index 3fe34f393..f3a738606 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt @@ -4,17 +4,19 @@ package dev.icerock.gradle.tasks +import dev.icerock.gradle.utils.klibs import org.gradle.api.DefaultTask import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.tasks.Internal import org.gradle.api.tasks.TaskAction +import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink import org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl import java.io.File import java.io.FileFilter abstract class CopyExecutableResourcesToApp : DefaultTask() { @get:Internal - abstract val klibs: ConfigurableFileCollection + abstract var linkTask: KotlinNativeLink init { group = "moko-resources" @@ -29,7 +31,7 @@ abstract class CopyExecutableResourcesToApp : DefaultTask() { val outputDir = File(buildProductsDir, contentsFolderPath) - klibs + linkTask.klibs .filter { library -> library.extension == "klib" } .filter(File::exists) .forEach { inputFile -> diff --git a/samples/auto-manifest/mpp-library/build.gradle.kts b/samples/auto-manifest/mpp-library/build.gradle.kts index 365bd55ad..e503fa240 100644 --- a/samples/auto-manifest/mpp-library/build.gradle.kts +++ b/samples/auto-manifest/mpp-library/build.gradle.kts @@ -26,7 +26,7 @@ dependencies { } multiplatformResources { - multiplatformResourcesPackage = "com.icerockdev.library" + resourcesPackage.set("com.icerockdev.library") } autoManifest { diff --git a/samples/compose-jvm-app/common/build.gradle.kts b/samples/compose-jvm-app/common/build.gradle.kts index 4b2ba4cfb..f70abfede 100644 --- a/samples/compose-jvm-app/common/build.gradle.kts +++ b/samples/compose-jvm-app/common/build.gradle.kts @@ -39,7 +39,7 @@ kotlin { } multiplatformResources { - multiplatformResourcesPackage = "com.icerockdev.app" + resourcesPackage.set("com.icerockdev.app") } compose { diff --git a/samples/ios-static-xcframework/build.gradle.kts b/samples/ios-static-xcframework/build.gradle.kts index 7eada2742..37e7cc5c5 100644 --- a/samples/ios-static-xcframework/build.gradle.kts +++ b/samples/ios-static-xcframework/build.gradle.kts @@ -11,6 +11,6 @@ buildscript { } dependencies { classpath(moko.resourcesGradlePlugin) - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.10") } } diff --git a/samples/ios-static-xcframework/mpp-library/build.gradle.kts b/samples/ios-static-xcframework/mpp-library/build.gradle.kts index de96d7b96..13cb9ff75 100644 --- a/samples/ios-static-xcframework/mpp-library/build.gradle.kts +++ b/samples/ios-static-xcframework/mpp-library/build.gradle.kts @@ -52,5 +52,5 @@ dependencies { } multiplatformResources { - multiplatformResourcesPackage = "com.icerockdev.library" + resourcesPackage.set("com.icerockdev.library") } diff --git a/samples/kotlin-ios-app/ios-kotlin-app/build.gradle.kts b/samples/kotlin-ios-app/ios-kotlin-app/build.gradle.kts index 13c58f9af..56581743c 100644 --- a/samples/kotlin-ios-app/ios-kotlin-app/build.gradle.kts +++ b/samples/kotlin-ios-app/ios-kotlin-app/build.gradle.kts @@ -40,6 +40,6 @@ kotlin { } multiplatformResources { - multiplatformResourcesPackage = "com.icerockdev.app" - multiplatformResourcesSourceSet = "iosMain" + resourcesPackage.set("com.icerockdev.app") + resourcesSourceSet.set("iosMain") } diff --git a/samples/kotlin-ios-app/mpp-library/build.gradle.kts b/samples/kotlin-ios-app/mpp-library/build.gradle.kts index f30f41fb9..df75722d7 100644 --- a/samples/kotlin-ios-app/mpp-library/build.gradle.kts +++ b/samples/kotlin-ios-app/mpp-library/build.gradle.kts @@ -24,6 +24,6 @@ kotlin { } multiplatformResources { - multiplatformResourcesPackage = "com.icerockdev.library" - multiplatformResourcesSourceSet = "iosMain" + resourcesPackage.set("com.icerockdev.library") + resourcesSourceSet.set("iosMain") } From eefde0497f90e7cfbd77b511b5a2e17139847700 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 11 Sep 2023 14:56:13 +0700 Subject: [PATCH 033/352] #535 another fixes --- .../gradle/generator/apple/AppleMRGenerator.kt | 4 +++- .../icerock/gradle/generator/js/JsMRGenerator.kt | 15 +++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt index ca24b0e06..f86fa648d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt @@ -103,7 +103,9 @@ class AppleMRGenerator( private fun setupKLibResources(generationTask: GenerateMultiplatformResourcesTask) { val compileTask: TaskProvider = compilation.compileTaskProvider - compileTask.configure { it.dependsOn(generationTask) } + compileTask.configure { task -> + task.dependsOn(generationTask) + } // tasks like compileIosMainKotlinMetadata when only one target enabled generationTask.project.tasks diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt index a2f738a1c..47613ce58 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt @@ -119,16 +119,11 @@ class JsMRGenerator( } private fun setupResources() { - val kotlinTarget: KotlinJsIrTarget = compilation.target as KotlinJsIrTarget - - kotlinTarget.compilations - .all { compilation -> - compilation.compileTaskProvider.configure { compileTask -> - val action = CopyResourcesToExecutableAction(resourcesGenerationDir) - @Suppress("UNCHECKED_CAST") - compileTask.doLast(action as Action) - } - } + compilation.compileTaskProvider.configure { compileTask -> + val action = CopyResourcesToExecutableAction(resourcesGenerationDir) + @Suppress("UNCHECKED_CAST") + compileTask.doLast(action as Action) + } } class CopyResourcesToKLibAction( From 0a2db556f49e777fd87dfdf3aa63c81e2e6c0468 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 11 Sep 2023 16:54:56 +0700 Subject: [PATCH 034/352] #535 detekt fixes --- resources-build-logic/settings.gradle.kts | 2 ++ resources-generator/settings.gradle.kts | 2 ++ .../main/kotlin/dev/icerock/gradle/configuration/JvmTarget.kt | 4 ---- .../dev/icerock/gradle/generator/common/CommonMRGenerator.kt | 1 - .../kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt | 1 - .../kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt | 1 - .../dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt | 1 - settings.gradle.kts | 2 ++ 8 files changed, 6 insertions(+), 8 deletions(-) diff --git a/resources-build-logic/settings.gradle.kts b/resources-build-logic/settings.gradle.kts index 795110937..8b07b43f8 100644 --- a/resources-build-logic/settings.gradle.kts +++ b/resources-build-logic/settings.gradle.kts @@ -2,6 +2,8 @@ * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ +rootProject.name = "resources-build-logic" + dependencyResolutionManagement { repositories { mavenCentral() diff --git a/resources-generator/settings.gradle.kts b/resources-generator/settings.gradle.kts index 991a300b4..88e3d8482 100644 --- a/resources-generator/settings.gradle.kts +++ b/resources-generator/settings.gradle.kts @@ -2,6 +2,8 @@ * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ +rootProject.name = "resources-generator" + pluginManagement { repositories { mavenCentral() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JvmTarget.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JvmTarget.kt index c70f3a64c..8cada5fba 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JvmTarget.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JvmTarget.kt @@ -24,10 +24,6 @@ internal fun configureJvmTargetGenerator( settings = settings, generators = features.map { it.createJvmGenerator() } ).apply(project = target.project) - - // TODO fix depends on // compilation.defaultSourceSet.ifDependsOn(commonSourceSet) { - -// } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index 101912446..dd3bfd4b0 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -8,7 +8,6 @@ import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import org.gradle.api.Project -import org.gradle.api.Task import org.gradle.api.provider.Provider import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.dsl.KotlinCompile diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt index 47613ce58..523925018 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt @@ -21,7 +21,6 @@ import org.gradle.api.provider.Provider import org.gradle.jvm.tasks.Jar import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilation -import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile import org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl import java.io.File diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt index c3b18f735..3138c07b1 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt @@ -13,7 +13,6 @@ import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.utils.dependsOnProcessResources import org.gradle.api.Project -import org.gradle.api.Task import org.gradle.api.provider.Provider import org.gradle.jvm.tasks.Jar import org.gradle.kotlin.dsl.withType diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt index f3a738606..795d43981 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt @@ -6,7 +6,6 @@ package dev.icerock.gradle.tasks import dev.icerock.gradle.utils.klibs import org.gradle.api.DefaultTask -import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.tasks.Internal import org.gradle.api.tasks.TaskAction import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink diff --git a/settings.gradle.kts b/settings.gradle.kts index 3a4f3354b..3a69af4dc 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -2,6 +2,8 @@ * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ +rootProject.name = "moko-resources" + enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") dependencyResolutionManagement { From 1768988e8d6dfbbf1df76eb91727007ffacc52c6 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 11 Sep 2023 19:04:04 +0700 Subject: [PATCH 035/352] #535 configuration fixes --- README.md | 10 +++++----- .../desktopApp/build.gradle.kts | 2 +- .../macosApp/build.gradle.kts | 2 +- .../compose-resources-gallery/shared/build.gradle.kts | 2 +- samples/resources-gallery/jvm-app/build.gradle.kts | 2 +- samples/resources-gallery/mpp-library/build.gradle.kts | 2 +- .../mpp-library/nested-module/build.gradle.kts | 6 +++--- samples/resources-gallery/web-app/build.gradle.kts | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index cf43b0dec..232c4b4cf 100755 --- a/README.md +++ b/README.md @@ -87,11 +87,11 @@ dependencies { } multiplatformResources { - multiplatformResourcesPackage = "org.example.library" // required - multiplatformResourcesClassName = "SharedRes" // optional, default MR - multiplatformResourcesVisibility = MRVisibility.Internal // optional, default Public - iosBaseLocalizationRegion = "en" // optional, default "en" - multiplatformResourcesSourceSet = "commonClientMain" // optional, default "commonMain" + resourcesPackage.set("org.example.library") // required + resourcesClassName.set("SharedRes") // optional, default MR + resourcesVisibility.set(MRVisibility.Internal) // optional, default Public + iosBaseLocalizationRegion.set("en") // optional, default "en" + resourcesSourceSet.set("commonClientMain") // optional, default "commonMain" } ``` diff --git a/samples/compose-resources-gallery/desktopApp/build.gradle.kts b/samples/compose-resources-gallery/desktopApp/build.gradle.kts index ced437d22..5fc2af307 100644 --- a/samples/compose-resources-gallery/desktopApp/build.gradle.kts +++ b/samples/compose-resources-gallery/desktopApp/build.gradle.kts @@ -31,5 +31,5 @@ compose.desktop { } multiplatformResources { - multiplatformResourcesPackage = "com.icerockdev.app" + resourcesPackage.set("com.icerockdev.app") } diff --git a/samples/compose-resources-gallery/macosApp/build.gradle.kts b/samples/compose-resources-gallery/macosApp/build.gradle.kts index b5ab143d7..804eaea02 100644 --- a/samples/compose-resources-gallery/macosApp/build.gradle.kts +++ b/samples/compose-resources-gallery/macosApp/build.gradle.kts @@ -62,7 +62,7 @@ kotlin { } multiplatformResources { - multiplatformResourcesPackage = "dev.icerock.moko.resources.sample" + resourcesPackage.set("dev.icerock.moko.resources.sample") } // TODO move to moko-resources gradle plugin diff --git a/samples/compose-resources-gallery/shared/build.gradle.kts b/samples/compose-resources-gallery/shared/build.gradle.kts index e0197ddb3..7f8838933 100644 --- a/samples/compose-resources-gallery/shared/build.gradle.kts +++ b/samples/compose-resources-gallery/shared/build.gradle.kts @@ -97,7 +97,7 @@ android { } multiplatformResources { - multiplatformResourcesPackage = "com.icerockdev.library" + resourcesPackage.set("com.icerockdev.library") } // TODO move to gradle plugin diff --git a/samples/resources-gallery/jvm-app/build.gradle.kts b/samples/resources-gallery/jvm-app/build.gradle.kts index 4f3da5ef4..ca3829eb4 100644 --- a/samples/resources-gallery/jvm-app/build.gradle.kts +++ b/samples/resources-gallery/jvm-app/build.gradle.kts @@ -39,5 +39,5 @@ compose { } multiplatformResources { - multiplatformResourcesPackage = "com.icerockdev.app" + resourcesPackage.set("com.icerockdev.app") } diff --git a/samples/resources-gallery/mpp-library/build.gradle.kts b/samples/resources-gallery/mpp-library/build.gradle.kts index 6589f1fdc..c47c9d5db 100644 --- a/samples/resources-gallery/mpp-library/build.gradle.kts +++ b/samples/resources-gallery/mpp-library/build.gradle.kts @@ -75,5 +75,5 @@ dependencies { } multiplatformResources { - multiplatformResourcesPackage = "com.icerockdev.library" + resourcesPackage.set("com.icerockdev.library") } diff --git a/samples/resources-gallery/mpp-library/nested-module/build.gradle.kts b/samples/resources-gallery/mpp-library/nested-module/build.gradle.kts index df4135eb8..1f408483c 100644 --- a/samples/resources-gallery/mpp-library/nested-module/build.gradle.kts +++ b/samples/resources-gallery/mpp-library/nested-module/build.gradle.kts @@ -19,7 +19,7 @@ dependencies { } multiplatformResources { - multiplatformResourcesPackage = "com.icerockdev.library.nested" - multiplatformResourcesClassName = "NestedMR" - multiplatformResourcesVisibility = MRVisibility.Internal + resourcesPackage.set("com.icerockdev.library.nested") + resourcesClassName.set("NestedMR") + resourcesVisibility.set(MRVisibility.Internal) } diff --git a/samples/resources-gallery/web-app/build.gradle.kts b/samples/resources-gallery/web-app/build.gradle.kts index e96a3d916..a87e4c56b 100644 --- a/samples/resources-gallery/web-app/build.gradle.kts +++ b/samples/resources-gallery/web-app/build.gradle.kts @@ -27,5 +27,5 @@ kotlin { } multiplatformResources { - multiplatformResourcesPackage = "com.icerockdev.app" + resourcesPackage.set("com.icerockdev.app") } From b95186136a98ec4e30d1ee9d422ba1851fc4bea8 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 11 Sep 2023 22:27:47 +0700 Subject: [PATCH 036/352] #535 rollback jvm target to 11 --- gradle/libs.versions.toml | 42 +++---------------- .../kotlin/android-base-convention.gradle.kts | 4 +- ...form-android-publish-convention.gradle.kts | 2 +- ...ultiplatform-library-convention.gradle.kts | 2 +- resources-generator/build.gradle.kts | 2 +- .../gradle/MultiplatformResourcesPlugin.kt | 2 - .../webApp/build.gradle.kts | 2 +- 7 files changed, 11 insertions(+), 45 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 94d2677e3..2114a37af 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,22 +1,20 @@ [versions] kotlinVersion = "1.9.0" -androidGradleVersion = "8.0.2" -androidSdkCommonVersion = "31.1.0" +androidGradleVersion = "7.4.2" +androidSdkCommonVersion = "31.0.0" # kotlinx kotlinxSerializationVersion = "1.5.1" kotlinxCoroutinesVersion = "1.6.4" # android -constraintLayoutVersion = "2.1.4" androidAppCompatVersion = "1.6.1" # android compose -composeVersion = "1.5.0" -composeActivityVersion = "1.7.2" +composeUiVersion = "1.5.1" # jetbrains compose -composeJetbrainsVersion = "1.4.3" +composeJetbrainsVersion = "1.5.0" # jvm apacheCommonsTextVersion = "1.10.0" @@ -26,14 +24,6 @@ icu4jVersion = "73.1" commonsCodecVersion = "1.15" batikVersion = "1.16" -# tests -espressoCoreVersion = "3.5.1" -testRunnerVersion = "1.5.2" -testRulesVersion = "1.5.0" -testExtJunitVersion = "1.1.5" -testCoreVersion = "1.5.0" -robolectricVersion = "4.8.1" - # moko mokoGraphicsVersion = "0.9.0" mokoParcelizeVersion = "0.9.0" @@ -44,7 +34,6 @@ mokoMultiplatformPluginVersion = "0.14.2" # kotlinx kotlinxSerialization = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationVersion" } kotlinxCoroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinxCoroutinesVersion" } -coroutinesTest = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinxCoroutinesVersion" } # moko mokoParcelize = { module = "dev.icerock.moko:parcelize", version.ref = "mokoParcelizeVersion" } @@ -53,19 +42,9 @@ mokoTestCore = { module = "dev.icerock.moko:test-core", version.ref = "mokoTestV # android appCompat = { module = "androidx.appcompat:appcompat", version.ref = "androidAppCompatVersion" } -constraintLayout = { module = "androidx.constraintlayout:constraintlayout", version.ref = "constraintLayoutVersion" } # android compose -composeUi = { module = "androidx.compose.ui:ui", version.ref = "composeVersion" } -composeUiTooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "composeVersion" } -composeUiToolingPreview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "composeVersion" } -composeRuntime = { module = "androidx.compose.runtime:runtime", version.ref = "composeVersion" } -composeMaterial = { module = "androidx.compose.material:material", version.ref = "composeVersion" } -composeFoundation = { module = "androidx.compose.foundation:foundation", version.ref = "composeVersion" } -composeActivity = { module = "androidx.activity:activity-compose", version.ref = "composeActivityVersion" } - -# jetbrains compose -composeGradlePlugin = { module = "org.jetbrains.compose:compose-gradle-plugin", version.ref = "composeJetbrainsVersion" } +composeUi = { module = "androidx.compose.ui:ui", version.ref = "composeUiVersion" } # jvm kotlinPoet = { module = "com.squareup:kotlinpoet", version.ref = "kotlinPoetVersion" } @@ -75,17 +54,6 @@ batikTranscoder = { module = "org.apache.xmlgraphics:batik-transcoder", version. commonsCodec = { module = "commons-codec:commons-codec", version.ref = "commonsCodecVersion" } icu4j = { module = "com.ibm.icu:icu4j", version.ref = "icu4jVersion" } -# tests -espressoCore = { module = "androidx.test.espresso:espresso-core", version.ref = "espressoCoreVersion" } -kotlinTestJUnit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlinVersion" } -testCore = { module = "androidx.test:core", version.ref = "testCoreVersion" } -robolectric = { module = "org.robolectric:robolectric", version.ref = "robolectricVersion" } -testRunner = { module = "androidx.test:runner", version.ref = "testRunnerVersion" } -testRules = { module = "androidx.test:rules", version.ref = "testRulesVersion" } -testExtJunit = { module = "androidx.test.ext:junit", version.ref = "testExtJunitVersion" } -kotlinTest = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlinVersion" } -kotlinTestAnnotations = { module = "org.jetbrains.kotlin:kotlin-test-annotations-common", version.ref = "kotlinVersion" } - # gradle kotlinGradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlinVersion" } androidGradlePlugin = { module = "com.android.tools.build:gradle", version.ref = "androidGradleVersion" } diff --git a/resources-build-logic/src/main/kotlin/android-base-convention.gradle.kts b/resources-build-logic/src/main/kotlin/android-base-convention.gradle.kts index 2d4650668..d6f8fa3e9 100644 --- a/resources-build-logic/src/main/kotlin/android-base-convention.gradle.kts +++ b/resources-build-logic/src/main/kotlin/android-base-convention.gradle.kts @@ -13,7 +13,7 @@ configure { } compileOptions { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 } } diff --git a/resources-build-logic/src/main/kotlin/multiplatform-android-publish-convention.gradle.kts b/resources-build-logic/src/main/kotlin/multiplatform-android-publish-convention.gradle.kts index b95dfb63a..cd1d48b68 100644 --- a/resources-build-logic/src/main/kotlin/multiplatform-android-publish-convention.gradle.kts +++ b/resources-build-logic/src/main/kotlin/multiplatform-android-publish-convention.gradle.kts @@ -7,7 +7,7 @@ plugins { } kotlin { - androidTarget() { + androidTarget { publishAllLibraryVariants() publishLibraryVariantsGroupedByFlavor = true } diff --git a/resources-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts b/resources-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts index 38a0055c1..bdd895ef4 100644 --- a/resources-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts +++ b/resources-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts @@ -52,7 +52,7 @@ kotlin { jsTest.dependsOn(commonTest) } - jvmToolchain(17) + jvmToolchain(11) } tasks.withType { diff --git a/resources-generator/build.gradle.kts b/resources-generator/build.gradle.kts index 78675884e..4835925fa 100644 --- a/resources-generator/build.gradle.kts +++ b/resources-generator/build.gradle.kts @@ -31,7 +31,7 @@ java { } kotlin { - jvmToolchain(17) + jvmToolchain(11) } gradlePlugin { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 0070530ff..e53e31bf8 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -45,8 +45,6 @@ open class MultiplatformResourcesPlugin : Plugin { type = MultiplatformResourcesPluginExtension::class ) - mrExtension.resourcesPackage.set("${project.group}.${project.name}") - project.plugins.withType(KotlinMultiplatformPluginWrapper::class) { val kmpExtension: KotlinMultiplatformExtension = project.extensions.getByType() diff --git a/samples/compose-resources-gallery/webApp/build.gradle.kts b/samples/compose-resources-gallery/webApp/build.gradle.kts index a16f32e2f..3e171f4af 100644 --- a/samples/compose-resources-gallery/webApp/build.gradle.kts +++ b/samples/compose-resources-gallery/webApp/build.gradle.kts @@ -29,5 +29,5 @@ compose.experimental { } multiplatformResources { - multiplatformResourcesPackage = "com.icerockdev.app" + resourcesPackage.set("com.icerockdev.app") } From cfde18ced72001cef840ebbdd565b0dfff64beb4 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 11 Sep 2023 22:37:37 +0700 Subject: [PATCH 037/352] #535 review fixes --- gradle.properties | 1 + samples/compose-resources-gallery/gradle.properties | 6 +++--- samples/resources-gallery/build.gradle.kts | 4 ++-- samples/resources-gallery/web-app/build.gradle.kts | 8 ++------ 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/gradle.properties b/gradle.properties index 9f9a44a59..de47c7e24 100755 --- a/gradle.properties +++ b/gradle.properties @@ -13,5 +13,6 @@ org.jetbrains.compose.experimental.uikit.enabled=true org.jetbrains.compose.experimental.macos.enabled=true android.useAndroidX=true +android.disableAutomaticComponentCreation=true mobile.multiplatform.iosTargetWarning=false diff --git a/samples/compose-resources-gallery/gradle.properties b/samples/compose-resources-gallery/gradle.properties index fab8ca620..3d755dbae 100644 --- a/samples/compose-resources-gallery/gradle.properties +++ b/samples/compose-resources-gallery/gradle.properties @@ -14,6 +14,6 @@ kotlin.mpp.androidSourceSetLayoutVersion=2 kotlin.mpp.androidGradlePluginCompatibility.nowarn=true # Enable kotlin/native experimental memory model kotlin.native.binary.memoryModel=experimental -kotlin.version=1.9.0 -agp.version=8.0.1 -compose.version=1.4.3 +kotlin.version=1.9.10 +agp.version=8.0.2 +compose.version=1.5.1 diff --git a/samples/resources-gallery/build.gradle.kts b/samples/resources-gallery/build.gradle.kts index ee68b4250..6aa8a156d 100644 --- a/samples/resources-gallery/build.gradle.kts +++ b/samples/resources-gallery/build.gradle.kts @@ -13,8 +13,8 @@ buildscript { } dependencies { classpath(moko.resourcesGradlePlugin) - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0") - classpath("org.jetbrains.compose:compose-gradle-plugin:1.5.0") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10") + classpath("org.jetbrains.compose:compose-gradle-plugin:1.4.0") classpath("com.android.tools.build:gradle:7.4.2") } } diff --git a/samples/resources-gallery/web-app/build.gradle.kts b/samples/resources-gallery/web-app/build.gradle.kts index a87e4c56b..594c15c65 100644 --- a/samples/resources-gallery/web-app/build.gradle.kts +++ b/samples/resources-gallery/web-app/build.gradle.kts @@ -15,12 +15,8 @@ kotlin { implementation(moko.resources) implementation(project(":mpp-library")) - // TODO() - // implementation(compose.html.core) - // implementation(compose.runtime) - implementation("org.jetbrains.compose.web:web-core:1.4.0") - runtimeOnly("org.jetbrains.compose.runtime:runtime:1.4.0") - + implementation(compose.html.core) + implementation(compose.runtime) } } } From bcc4ab8ba7b03d259365bc4ad58887882ffaeff9 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 17 Sep 2023 20:16:47 +0700 Subject: [PATCH 038/352] #535 rework logic of configuration stage --- .../gradle/MultiplatformResourcesPlugin.kt | 135 +++++++++++++----- .../MultiplatformResourcesPluginExtension.kt | 39 ++--- .../gradle/configuration/CommonTarget.kt | 6 +- .../gradle/generator/AssetsGenerator.kt | 2 +- .../icerock/gradle/generator/MRGenerator.kt | 4 +- .../generator/apple/AppleMRGenerator.kt | 21 ++- .../GenerateMultiplatformResourcesTask.kt | 73 +++++++--- .../gradle/utils/ProcessResourcesUtils.kt | 5 +- .../ios-kotlin-app/build.gradle.kts | 2 +- .../mpp-library/build.gradle.kts | 2 +- 10 files changed, 187 insertions(+), 102 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index e53e31bf8..d022d219c 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -9,8 +9,6 @@ import dev.icerock.gradle.configuration.configureAppleTargetGenerator import dev.icerock.gradle.configuration.configureCommonTargetGenerator import dev.icerock.gradle.configuration.configureJsTargetGenerator import dev.icerock.gradle.configuration.configureJvmTargetGenerator -import dev.icerock.gradle.configuration.getAndroidRClassPackage -import dev.icerock.gradle.configuration.setupProjectForApple import dev.icerock.gradle.generator.AssetsGenerator import dev.icerock.gradle.generator.ColorsGenerator import dev.icerock.gradle.generator.FilesGenerator @@ -20,11 +18,11 @@ import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.PluralsGenerator import dev.icerock.gradle.generator.ResourceGeneratorFeature import dev.icerock.gradle.generator.StringsGenerator -import dev.icerock.gradle.utils.isStrictLineBreaks +import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask +import dev.icerock.gradle.utils.dependsOnObservable import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.file.SourceDirectorySet -import org.gradle.api.provider.Provider import org.gradle.kotlin.dsl.create import org.gradle.kotlin.dsl.getByType import org.gradle.kotlin.dsl.withType @@ -35,6 +33,7 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import org.jetbrains.kotlin.gradle.plugin.KotlinTarget import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.konan.target.KonanTarget +import org.jetbrains.kotlin.tooling.core.extrasKeyOf import java.io.File open class MultiplatformResourcesPlugin : Plugin { @@ -43,7 +42,7 @@ open class MultiplatformResourcesPlugin : Plugin { val mrExtension: MultiplatformResourcesPluginExtension = project.extensions.create( name = "multiplatformResources", type = MultiplatformResourcesPluginExtension::class - ) + ).apply { setupConvention(project) } project.plugins.withType(KotlinMultiplatformPluginWrapper::class) { val kmpExtension: KotlinMultiplatformExtension = project.extensions.getByType() @@ -61,45 +60,89 @@ open class MultiplatformResourcesPlugin : Plugin { mrExtension: MultiplatformResourcesPluginExtension, kmpExtension: KotlinMultiplatformExtension ) { - val resourcesSourceDirectory: SourceDirectorySet = project.objects.sourceDirectorySet( - "moko-resources", - "moko-resources" - ) - - val resourcesSourceSet: Provider = mrExtension - .getResourcesSourceSetName() - .map { kmpExtension.sourceSets.getByName(it) } - - resourcesSourceDirectory.srcDirs( - resourcesSourceSet.map { sourceSet -> + kmpExtension.sourceSets + .configureEach { kotlinSourceSet -> val sources = File(project.projectDir, "src") - val resourceSourceSetDir = File(sources, sourceSet.name) - File(resourceSourceSetDir, "moko-resources") + val resourceSourceSetDir = File(sources, kotlinSourceSet.name) + val mokoResourcesDir = File(resourceSourceSetDir, "moko-resources") + + val resourcesSourceDirectory: SourceDirectorySet = + project.objects.sourceDirectorySet( + kotlinSourceSet.name + "MokoResources", + "moko-resources for ${kotlinSourceSet.name} sourceSet" + ) + resourcesSourceDirectory.srcDirs(mokoResourcesDir) + + kotlinSourceSet.extras[mokoResourcesSourceDirectoryKey()] = resourcesSourceDirectory + + project.logger.warn("created source directory set $resourcesSourceDirectory") + + val generateTaskName: String = "generateMR" + kotlinSourceSet.name + val task = project.tasks.register( + generateTaskName, + GenerateMultiplatformResourcesTask::class.java + ) { + it.kotlinSourceSet.set(kotlinSourceSet) + } } - ) - val generatedDir = File(project.buildDir, "generated/moko-resources") - - val settings = MRGenerator.Settings( - packageName = mrExtension.getResourcesPackage(project), - className = mrExtension.getResourcesClassName(), - visibility = mrExtension.getResourcesVisibility(), - generatedDir = generatedDir, - isStrictLineBreaks = project.isStrictLineBreaks, - iosLocalizationRegion = mrExtension.getIosBaseLocalizationRegion(), - resourcesSourceDirectory = resourcesSourceDirectory, - resourcesSourceSet = resourcesSourceSet, - androidRClassPackage = project.getAndroidRClassPackage() - ) - - kmpExtension.targets.configureEach { kotlinTarget -> - configureKotlinTargetGenerator( - target = kotlinTarget, - settings = settings - ) + kmpExtension.targets.configureEach { target -> + target.compilations.configureEach { compilation -> + project.logger.warn("target $target with $compilation found") + } } - setupProjectForApple(project) + +// val resourcesSourceDirectory: SourceDirectorySet = project.objects.sourceDirectorySet( +// "moko-resources", +// "moko-resources" +// ) +// +// val ss = mrExtension.resourcesSourceSet +// project.logger.warn("source set $ss") +// +// kmpExtension.sourceSets +// .matching { it.name == mrExtension.resourcesSourceSet } +// .configureEach { kotlinSourceSet -> +// val sources = File(project.projectDir, "src") +// val resourceSourceSetDir = File(sources, kotlinSourceSet.name) +// val mokoResourcesDir = File(resourceSourceSetDir, "moko-resources") +// +// resourcesSourceDirectory.srcDirs(mokoResourcesDir) +// } +// +// val generatedDir = File(project.buildDir, "generated/moko-resources") +// +// val settings = MRGenerator.Settings( +// packageName = mrExtension.resourcesPackage, +// className = mrExtension.resourcesClassName, +// visibility = mrExtension.resourcesVisibility, +// generatedDir = generatedDir, +// isStrictLineBreaks = project.isStrictLineBreaks, +// iosLocalizationRegion = mrExtension.iosBaseLocalizationRegion, +// resourcesSourceDirectory = resourcesSourceDirectory, +// androidRClassPackage = project.getAndroidRClassPackage() +// ) +// +// kmpExtension.targets.configureEach { kotlinTarget -> +// var found = false +// +// kotlinTarget.compilations.configureEach { compilation -> +// compilation.kotlinSourceSetsObservable.forAll { kotlinSourceSet -> +// kotlinSourceSet.whenDependsOn(mrExtension.resourcesSourceSet) { +// if(found) return@whenDependsOn +// +// found = true +// configureKotlinTargetGenerator( +// target = kotlinTarget, +// settings = settings +// ) +// } +// } +// } +// } +// +// setupProjectForApple(project) } private fun configureKotlinTargetGenerator( @@ -173,3 +216,17 @@ open class MultiplatformResourcesPlugin : Plugin { } } } + +private fun KotlinSourceSet.whenDependsOn(sourceSetName: String, action: () -> Unit) { + if (this.name == sourceSetName) { + action() + } + + dependsOnObservable.forAll { dependencySourceSet -> + if (dependencySourceSet.name == sourceSetName) action() + else dependencySourceSet.whenDependsOn(sourceSetName, action) + } +} + +fun mokoResourcesSourceDirectoryKey() = + extrasKeyOf("moko-resources-source-directory") 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 ad657c4b1..55edb85d5 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPluginExtension.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPluginExtension.kt @@ -6,32 +6,19 @@ package dev.icerock.gradle import org.gradle.api.Project import org.gradle.api.provider.Property -import org.gradle.api.provider.Provider -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet -interface MultiplatformResourcesPluginExtension { - val resourcesPackage: Property - val resourcesClassName: Property - val resourcesSourceSet: Property - val iosBaseLocalizationRegion: Property - val staticFrameworkWarningEnabled: Property - val resourcesVisibility: Property +abstract class MultiplatformResourcesPluginExtension { + abstract val resourcesPackage: Property + abstract val resourcesClassName: Property + abstract val iosBaseLocalizationRegion: Property + abstract val staticFrameworkWarningEnabled: Property + abstract val resourcesVisibility: Property } -internal fun MultiplatformResourcesPluginExtension.getResourcesPackage(project: Project): Provider = - resourcesPackage.orElse(project.provider { "${project.group}.${project.name}" }) - -internal fun MultiplatformResourcesPluginExtension.getResourcesClassName(): Provider = - resourcesClassName.orElse("MR") - -internal fun MultiplatformResourcesPluginExtension.getResourcesSourceSetName(): Provider = - resourcesSourceSet.orElse(KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME) - -internal fun MultiplatformResourcesPluginExtension.getIosBaseLocalizationRegion(): Provider = - iosBaseLocalizationRegion.orElse("en") - -internal fun MultiplatformResourcesPluginExtension.getIsStaticFrameworkWarningEnabled(): Provider = - staticFrameworkWarningEnabled.orElse(true) - -internal fun MultiplatformResourcesPluginExtension.getResourcesVisibility(): Provider = - resourcesVisibility.orElse(MRVisibility.Public) +internal fun MultiplatformResourcesPluginExtension.setupConvention(project: Project) { + resourcesPackage.convention(project.provider { "${project.group}.${project.name}" }) + resourcesClassName.convention("MR") + iosBaseLocalizationRegion.convention("en") + staticFrameworkWarningEnabled.convention(true) + resourcesVisibility.convention(MRVisibility.Public) +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/CommonTarget.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/CommonTarget.kt index 9a2e7f586..02302ec19 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/CommonTarget.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/CommonTarget.kt @@ -9,6 +9,7 @@ import dev.icerock.gradle.generator.ResourceGeneratorFeature import dev.icerock.gradle.generator.common.CommonMRGenerator import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import org.gradle.kotlin.dsl.withType +import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation import org.jetbrains.kotlin.gradle.plugin.KotlinTarget internal fun configureCommonTargetGenerator( @@ -18,7 +19,10 @@ internal fun configureCommonTargetGenerator( ) { val generationTask: GenerateMultiplatformResourcesTask = CommonMRGenerator( generatedDir = settings.generatedDir, - sourceSet = settings.resourcesSourceSet.map { createSourceSet(it) }, + sourceSet = target.project.provider { + val compilation = target.compilations.getByName(KotlinCompilation.MAIN_COMPILATION_NAME) + createSourceSet(compilation.defaultSourceSet) + }, settings = settings, generators = features.map { it.createCommonGenerator() } ).apply(project = target.project) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt index 33f77bcc9..9a093c919 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt @@ -21,7 +21,7 @@ import java.io.File abstract class AssetsGenerator( private val sourceDirectorySet: SourceDirectorySet ) : MRGenerator.Generator { - override val inputFiles: Iterable = sourceDirectorySet.files + override val inputFiles: Iterable get() = sourceDirectorySet.files override val mrObjectName: String = ASSETS_DIR_NAME override val resourceClassName = ClassName("dev.icerock.moko.resources", "AssetResource") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt index 226bff760..b48494e63 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt @@ -15,7 +15,6 @@ import dev.icerock.gradle.toModifier import org.gradle.api.Project import org.gradle.api.file.SourceDirectorySet import org.gradle.api.provider.Provider -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import java.io.File abstract class MRGenerator( @@ -98,7 +97,7 @@ abstract class MRGenerator( "generateMR$name", GenerateMultiplatformResourcesTask::class.java ) { - it.generator = this +// it.generator = this it.inputs.property("mokoSettingsPackageName", settings.packageName) it.inputs.property("mokoSettingsClassName", settings.className) it.inputs.property("mokoSettingsVisibility", settings.visibility) @@ -159,7 +158,6 @@ abstract class MRGenerator( val isStrictLineBreaks: Boolean, val iosLocalizationRegion: Provider, val resourcesSourceDirectory: SourceDirectorySet, - val resourcesSourceSet: Provider, val androidRClassPackage: Provider ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt index f86fa648d..eabd0713a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt @@ -15,7 +15,6 @@ import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.apple.action.CopyResourcesFromKLibsToExecutableAction import dev.icerock.gradle.generator.apple.action.CopyResourcesFromKLibsToFrameworkAction import dev.icerock.gradle.generator.apple.action.PackResourcesToKLibAction -import dev.icerock.gradle.getIsStaticFrameworkWarningEnabled import dev.icerock.gradle.tasks.CopyFrameworkResourcesToAppEntryPointTask import dev.icerock.gradle.tasks.CopyFrameworkResourcesToAppTask import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask @@ -30,7 +29,6 @@ import org.gradle.api.tasks.TaskProvider import org.gradle.kotlin.dsl.findByType import org.gradle.kotlin.dsl.getByType import org.gradle.kotlin.dsl.withType -import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompile import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractKotlinNativeCompilation @@ -105,16 +103,8 @@ class AppleMRGenerator( compileTask.configure { task -> task.dependsOn(generationTask) - } - - // tasks like compileIosMainKotlinMetadata when only one target enabled - generationTask.project.tasks - .withType() -// .matching { it.name.contains(sourceSet.name, ignoreCase = true) } - .configureEach { it.dependsOn(generationTask) } - compileTask.configure { - it.doLast { + task.doLast { PackResourcesToKLibAction( baseLocalizationRegion = baseLocalizationRegion, bundleIdentifierProvider = bundleIdentifierProvider, @@ -122,9 +112,14 @@ class AppleMRGenerator( resourcesGenerationDirProvider = resourcesGenerationDir, ) } - it.dependsOn(generationTask) } + // tasks like compileIosMainKotlinMetadata when only one target enabled +// generationTask.project.tasks +// .withType() +// .matching { it.name.contains(sourceSet.name, ignoreCase = true) } +// .configureEach { it.dependsOn(generationTask) } + dependsOnProcessResources( project = generationTask.project, sourceSet = sourceSet, @@ -148,7 +143,7 @@ class AppleMRGenerator( if (framework.isStatic) { val resourcesExtension: MultiplatformResourcesPluginExtension = project.extensions.getByType() - if (resourcesExtension.getIsStaticFrameworkWarningEnabled().get()) { + if (resourcesExtension.staticFrameworkWarningEnabled.get()) { project.logger.warn( """ $linkTask produces static framework, Xcode should have Build Phase with copyFrameworkResourcesToApp gradle task call. Please read readme on https://github.com/icerockdev/moko-resources 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 e31c754a5..d5b4ddaca 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 @@ -4,26 +4,35 @@ package dev.icerock.gradle.tasks -import dev.icerock.gradle.generator.MRGenerator +import dev.icerock.gradle.mokoResourcesSourceDirectoryKey import org.gradle.api.DefaultTask -import org.gradle.api.tasks.InputFiles -import org.gradle.api.tasks.Internal -import org.gradle.api.tasks.OutputDirectory +import org.gradle.api.file.SourceDirectorySet +import org.gradle.api.model.ObjectFactory +import org.gradle.api.provider.Property +import org.gradle.api.tasks.CacheableTask +import org.gradle.api.tasks.Input import org.gradle.api.tasks.TaskAction -import java.io.File +import org.gradle.kotlin.dsl.getByType +import org.gradle.kotlin.dsl.property +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet +import javax.inject.Inject -open class GenerateMultiplatformResourcesTask : DefaultTask() { +@CacheableTask +abstract class GenerateMultiplatformResourcesTask @Inject constructor( + objectFactory: ObjectFactory, +) : DefaultTask() { - @get:Internal - internal lateinit var generator: MRGenerator + @get:Input + val kotlinSourceSet: Property = objectFactory.property() - @get:InputFiles - val inputFiles: Iterable - get() = generator.generators.flatMap { it.inputFiles } - - @get:OutputDirectory - val outputDirectory: File - get() = generator.outputDir.get() +// @get:InputFiles +// val inputFiles: Iterable +// get() = generator.generators.flatMap { it.inputFiles } +// +// @get:OutputDirectory +// val outputDirectory: File +// get() = generator.outputDir.get() init { group = "moko-resources" @@ -31,6 +40,38 @@ open class GenerateMultiplatformResourcesTask : DefaultTask() { @TaskAction fun generate() { - generator.generate() + val kmpExtension: KotlinMultiplatformExtension = project.extensions.getByType() + val sourceSet: KotlinSourceSet = kotlinSourceSet.get() + val ownSourceDirectory: SourceDirectorySet = + sourceSet.extras[mokoResourcesSourceDirectoryKey()] + ?: error("can't find source directory!") + + val allSourceDirectories = sourceSet.allSourceSets() + .map { it.extras[mokoResourcesSourceDirectoryKey()] } + .onEach { project.logger.warn("found mrs $it") } + .filterNotNull() + + val (target, compilation) = kmpExtension.targets + .onEach { project.logger.warn("found target $it") } + .flatMap { target -> + target.compilations.map { target to it } + } + .onEach { (target, compilation) -> + project.logger.warn("found $target $compilation with ${compilation.defaultSourceSet} ${compilation.kotlinSourceSets}") + } + .filter { (target, compilation) -> + compilation.defaultSourceSet == sourceSet + } + .onEach { project.logger.warn("found with default $it") } + .first() + + project.logger.warn("${this.name} from $compilation ${compilation?.target}") + + project.logger.warn("ownSourceDirectory $ownSourceDirectory") + project.logger.warn("allSourceDirectories $allSourceDirectories") + } + + private fun KotlinSourceSet.allSourceSets(): Set { + return setOf(this) + dependsOn.flatMap { it.allSourceSets() } } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProcessResourcesUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProcessResourcesUtils.kt index 4881eb471..03a22f9eb 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProcessResourcesUtils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProcessResourcesUtils.kt @@ -16,8 +16,11 @@ fun dependsOnProcessResources( @Suppress("UNUSED_PARAMETER") sourceSet: Provider, task: Task, ) { + val sourceSet: MRGenerator.SourceSet = sourceSet.get() + project.logger.warn("source set name is ${sourceSet.name}") + project.tasks -// .matching { it.name == sourceSet.name.removeSuffix("Main") + "ProcessResources" } + .matching { it.name == sourceSet.name.removeSuffix("Main") + "ProcessResources" } .withType() .configureEach { processResourcesTask -> processResourcesTask.dependsOn(task) diff --git a/samples/kotlin-ios-app/ios-kotlin-app/build.gradle.kts b/samples/kotlin-ios-app/ios-kotlin-app/build.gradle.kts index 56581743c..7a3d9e31e 100644 --- a/samples/kotlin-ios-app/ios-kotlin-app/build.gradle.kts +++ b/samples/kotlin-ios-app/ios-kotlin-app/build.gradle.kts @@ -41,5 +41,5 @@ kotlin { multiplatformResources { resourcesPackage.set("com.icerockdev.app") - resourcesSourceSet.set("iosMain") + resourcesSourceSet = "iosMain" } diff --git a/samples/kotlin-ios-app/mpp-library/build.gradle.kts b/samples/kotlin-ios-app/mpp-library/build.gradle.kts index df75722d7..ee5f1e100 100644 --- a/samples/kotlin-ios-app/mpp-library/build.gradle.kts +++ b/samples/kotlin-ios-app/mpp-library/build.gradle.kts @@ -25,5 +25,5 @@ kotlin { multiplatformResources { resourcesPackage.set("com.icerockdev.library") - resourcesSourceSet.set("iosMain") + resourcesSourceSet = "iosMain" } From cc4d8cade37ca86a9b0932158f8ef73d078dc272 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 8 Oct 2023 00:42:42 +0700 Subject: [PATCH 039/352] #535 allow plugin usage with old kotlin --- resources-generator/build.gradle.kts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/resources-generator/build.gradle.kts b/resources-generator/build.gradle.kts index 4835925fa..3e7cbdc01 100644 --- a/resources-generator/build.gradle.kts +++ b/resources-generator/build.gradle.kts @@ -1,3 +1,6 @@ +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.dsl.KotlinVersion + /* * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ @@ -26,6 +29,9 @@ dependencies { } java { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + withJavadocJar() withSourcesJar() } @@ -34,6 +40,12 @@ kotlin { jvmToolchain(11) } +tasks.withType() + .configureEach { + compilerOptions.jvmTarget.set(JvmTarget.JVM_11) + compilerOptions.languageVersion.set(KotlinVersion.KOTLIN_1_8) + } + gradlePlugin { plugins { create("multiplatform-resources") { From 7f17344430cfb207ecd3b2f7301c044174a564a5 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 8 Oct 2023 00:43:49 +0700 Subject: [PATCH 040/352] #535 configure generate tasks lazy and complete info --- .../gradle/MultiplatformResourcesPlugin.kt | 150 +++++++++++++++--- .../GenerateMultiplatformResourcesTask.kt | 93 ++++++----- samples/resources-gallery/build.gradle.kts | 4 +- 3 files changed, 188 insertions(+), 59 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index d022d219c..d1fea44ed 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -23,6 +23,7 @@ import dev.icerock.gradle.utils.dependsOnObservable import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.file.SourceDirectorySet +import org.gradle.api.tasks.TaskProvider import org.gradle.kotlin.dsl.create import org.gradle.kotlin.dsl.getByType import org.gradle.kotlin.dsl.withType @@ -62,33 +63,44 @@ open class MultiplatformResourcesPlugin : Plugin { ) { kmpExtension.sourceSets .configureEach { kotlinSourceSet -> - val sources = File(project.projectDir, "src") - val resourceSourceSetDir = File(sources, kotlinSourceSet.name) - val mokoResourcesDir = File(resourceSourceSetDir, "moko-resources") - - val resourcesSourceDirectory: SourceDirectorySet = - project.objects.sourceDirectorySet( - kotlinSourceSet.name + "MokoResources", - "moko-resources for ${kotlinSourceSet.name} sourceSet" + val resourcesSourceDirectory: SourceDirectorySet = createMokoResourcesSourceSet( + project = project, + kotlinSourceSet = kotlinSourceSet + ) + + val genTask: TaskProvider = + registerGenerateTask( + kotlinSourceSet = kotlinSourceSet, + project = project, + resourcesSourceDirectory = resourcesSourceDirectory ) - resourcesSourceDirectory.srcDirs(mokoResourcesDir) - kotlinSourceSet.extras[mokoResourcesSourceDirectoryKey()] = resourcesSourceDirectory + configureLowerDependencies( + kotlinSourceSet = kotlinSourceSet, + genTask = genTask + ) - project.logger.warn("created source directory set $resourcesSourceDirectory") + configureUpperDependencies( + kotlinSourceSet = kotlinSourceSet, + resourcesSourceDirectory = resourcesSourceDirectory + ) - val generateTaskName: String = "generateMR" + kotlinSourceSet.name - val task = project.tasks.register( - generateTaskName, - GenerateMultiplatformResourcesTask::class.java - ) { - it.kotlinSourceSet.set(kotlinSourceSet) - } + configureTaskDependencies( + kotlinSourceSet = kotlinSourceSet, + genTask = genTask + ) } kmpExtension.targets.configureEach { target -> target.compilations.configureEach { compilation -> - project.logger.warn("target $target with $compilation found") + val sourceSet: KotlinSourceSet = compilation.defaultSourceSet + val genTask: TaskProvider = requireNotNull( + sourceSet.extras[mokoResourcesGenTaskKey()] + ) + + genTask.configure { + it.kotlinTarget.set(target.targetName) + } } } @@ -145,6 +157,101 @@ open class MultiplatformResourcesPlugin : Plugin { // setupProjectForApple(project) } + private fun createMokoResourcesSourceSet( + project: Project, + kotlinSourceSet: KotlinSourceSet + ): SourceDirectorySet { + val sources = File(project.projectDir, "src") + val resourceSourceSetDir = File(sources, kotlinSourceSet.name) + val mokoResourcesDir = File(resourceSourceSetDir, "moko-resources") + + val resourcesSourceDirectory: SourceDirectorySet = project.objects.sourceDirectorySet( + kotlinSourceSet.name + "MokoResources", + "moko-resources for ${kotlinSourceSet.name} sourceSet" + ) + resourcesSourceDirectory.srcDirs(mokoResourcesDir) + + kotlinSourceSet.extras[mokoResourcesSourceDirectoryKey()] = resourcesSourceDirectory + + return resourcesSourceDirectory + } + + private fun registerGenerateTask( + kotlinSourceSet: KotlinSourceSet, + project: Project, + resourcesSourceDirectory: SourceDirectorySet + ): TaskProvider { + val generateTaskName: String = "generateMR" + kotlinSourceSet.name + val taskProvider: TaskProvider = project.tasks.register( + generateTaskName, + GenerateMultiplatformResourcesTask::class.java + ) { + val files: Set = resourcesSourceDirectory.srcDirs + it.ownResources.setFrom(files) + } + + kotlinSourceSet.extras[mokoResourcesGenTaskKey()] = taskProvider + + return taskProvider + } + + private fun configureLowerDependencies( + kotlinSourceSet: KotlinSourceSet, + genTask: TaskProvider + ) { + kotlinSourceSet.dependsOnObservable.forAll { dependsSourceSet -> + val resourcesDir: SourceDirectorySet = requireNotNull( + dependsSourceSet.extras[mokoResourcesSourceDirectoryKey()] + ) + + genTask.configure { + val files: Set = resourcesDir.srcDirs + it.lowerResources.from(files) + } + + configureLowerDependencies( + kotlinSourceSet = dependsSourceSet, + genTask = genTask + ) + } + } + + private fun configureUpperDependencies( + kotlinSourceSet: KotlinSourceSet, + resourcesSourceDirectory: SourceDirectorySet, + ) { + kotlinSourceSet.dependsOnObservable.forAll { dependsSourceSet -> + val dependsGenTask: TaskProvider = requireNotNull( + dependsSourceSet.extras[mokoResourcesGenTaskKey()] + ) + + dependsGenTask.configure { + val files: Set = resourcesSourceDirectory.srcDirs + it.upperResources.from(files) + } + + configureUpperDependencies( + kotlinSourceSet = dependsSourceSet, + resourcesSourceDirectory = resourcesSourceDirectory + ) + } + } + + private fun configureTaskDependencies( + kotlinSourceSet: KotlinSourceSet, + genTask: TaskProvider, + ) { + kotlinSourceSet.dependsOnObservable.forAll { dependsSourceSet -> + val dependsGenTask: TaskProvider = requireNotNull( + dependsSourceSet.extras[mokoResourcesGenTaskKey()] + ) + + genTask.configure { + it.dependsOn(dependsGenTask) + } + } + } + private fun configureKotlinTargetGenerator( target: KotlinTarget, settings: MRGenerator.Settings @@ -228,5 +335,8 @@ private fun KotlinSourceSet.whenDependsOn(sourceSetName: String, action: () -> U } } -fun mokoResourcesSourceDirectoryKey() = +internal fun mokoResourcesSourceDirectoryKey() = extrasKeyOf("moko-resources-source-directory") + +internal fun mokoResourcesGenTaskKey() = + extrasKeyOf>("moko-resources-generate-task") 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 d5b4ddaca..d3ff707e9 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 @@ -4,27 +4,36 @@ package dev.icerock.gradle.tasks -import dev.icerock.gradle.mokoResourcesSourceDirectoryKey import org.gradle.api.DefaultTask -import org.gradle.api.file.SourceDirectorySet -import org.gradle.api.model.ObjectFactory +import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.provider.Property import org.gradle.api.tasks.CacheableTask +import org.gradle.api.tasks.Classpath import org.gradle.api.tasks.Input +import org.gradle.api.tasks.InputFiles import org.gradle.api.tasks.TaskAction -import org.gradle.kotlin.dsl.getByType -import org.gradle.kotlin.dsl.property -import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet -import javax.inject.Inject @CacheableTask -abstract class GenerateMultiplatformResourcesTask @Inject constructor( - objectFactory: ObjectFactory, -) : DefaultTask() { +abstract class GenerateMultiplatformResourcesTask : DefaultTask() { + + @get:InputFiles + @get:Classpath + abstract val ownResources: ConfigurableFileCollection + + @get:InputFiles + @get:Classpath + abstract val lowerResources: ConfigurableFileCollection + + @get:InputFiles + @get:Classpath + abstract val upperResources: ConfigurableFileCollection @get:Input - val kotlinSourceSet: Property = objectFactory.property() + abstract val kotlinTarget: Property + +// @get:Input +// val kotlinSourceSet: Property = objectFactory.property() // @get:InputFiles // val inputFiles: Iterable @@ -36,39 +45,49 @@ abstract class GenerateMultiplatformResourcesTask @Inject constructor( init { group = "moko-resources" + kotlinTarget.convention("kotlinMetadata") } @TaskAction fun generate() { - val kmpExtension: KotlinMultiplatformExtension = project.extensions.getByType() - val sourceSet: KotlinSourceSet = kotlinSourceSet.get() - val ownSourceDirectory: SourceDirectorySet = - sourceSet.extras[mokoResourcesSourceDirectoryKey()] - ?: error("can't find source directory!") - - val allSourceDirectories = sourceSet.allSourceSets() - .map { it.extras[mokoResourcesSourceDirectoryKey()] } - .onEach { project.logger.warn("found mrs $it") } - .filterNotNull() + logger.warn("i $name have ownResources ${ownResources.from}") + logger.warn("i $name have lowerResources ${lowerResources.from}") + logger.warn("i $name have upperResources ${upperResources.from}") + logger.warn("i $name have kotlinTarget ${kotlinTarget.get()}") - val (target, compilation) = kmpExtension.targets - .onEach { project.logger.warn("found target $it") } - .flatMap { target -> - target.compilations.map { target to it } - } - .onEach { (target, compilation) -> - project.logger.warn("found $target $compilation with ${compilation.defaultSourceSet} ${compilation.kotlinSourceSets}") - } - .filter { (target, compilation) -> - compilation.defaultSourceSet == sourceSet - } - .onEach { project.logger.warn("found with default $it") } - .first() +// val kmpExtension: KotlinMultiplatformExtension = project.extensions.getByType() +// val sourceSet: KotlinSourceSet = kotlinSourceSet.get() +// val ownSourceDirectory: SourceDirectorySet = +// sourceSet.extras[mokoResourcesSourceDirectoryKey()] +// ?: error("can't find source directory!") +// +// val allSourceDirectories = sourceSet.allSourceSets() +// .map { it.extras[mokoResourcesSourceDirectoryKey()] } +// .onEach { project.logger.warn("found mrs $it") } +// .filterNotNull() +// +// val (target, compilation) = kmpExtension.targets +// .onEach { project.logger.warn("found target $it") } +// .flatMap { target -> +// target.compilations.map { target to it } +// } +// .onEach { (target, compilation) -> +// project.logger.warn("found $target $compilation with ${compilation.defaultSourceSet} ${compilation.kotlinSourceSets}") +// } +// .filter { (target, compilation) -> +// compilation.defaultSourceSet == sourceSet +// } +// .onEach { project.logger.warn("found with default $it") } +// .first() +// +// project.logger.warn("${this.name} from $compilation ${compilation?.target}") +// +// project.logger.warn("ownSourceDirectory $ownSourceDirectory") +// project.logger.warn("allSourceDirectories $allSourceDirectories") - project.logger.warn("${this.name} from $compilation ${compilation?.target}") + // TODO when task executed we should detect which generator should be used by check source + // sets hierarhy - project.logger.warn("ownSourceDirectory $ownSourceDirectory") - project.logger.warn("allSourceDirectories $allSourceDirectories") } private fun KotlinSourceSet.allSourceSets(): Set { diff --git a/samples/resources-gallery/build.gradle.kts b/samples/resources-gallery/build.gradle.kts index 6aa8a156d..43c022ae7 100644 --- a/samples/resources-gallery/build.gradle.kts +++ b/samples/resources-gallery/build.gradle.kts @@ -13,8 +13,8 @@ buildscript { } dependencies { classpath(moko.resourcesGradlePlugin) - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10") - classpath("org.jetbrains.compose:compose-gradle-plugin:1.4.0") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0") + classpath("org.jetbrains.compose:compose-gradle-plugin:1.5.1") classpath("com.android.tools.build:gradle:7.4.2") } } From a96cdabec2745b69d2d33f40dae2a0135cab9721 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 8 Oct 2023 00:47:32 +0700 Subject: [PATCH 041/352] #535 configure compile task dependencies --- .../kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index d1fea44ed..67e0d9a1b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -101,6 +101,10 @@ open class MultiplatformResourcesPlugin : Plugin { genTask.configure { it.kotlinTarget.set(target.targetName) } + + compilation.compileTaskProvider.configure { + it.dependsOn(genTask) + } } } From 87078545c4373a6b0a11baf4ce33a5d760dba499 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 8 Oct 2023 00:48:11 +0700 Subject: [PATCH 042/352] #535 reformat --- .../gradle/MultiplatformResourcesPlugin.kt | 47 +++++++++---------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 67e0d9a1b..085bb69f0 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -61,35 +61,34 @@ open class MultiplatformResourcesPlugin : Plugin { mrExtension: MultiplatformResourcesPluginExtension, kmpExtension: KotlinMultiplatformExtension ) { - kmpExtension.sourceSets - .configureEach { kotlinSourceSet -> - val resourcesSourceDirectory: SourceDirectorySet = createMokoResourcesSourceSet( - project = project, - kotlinSourceSet = kotlinSourceSet - ) - - val genTask: TaskProvider = - registerGenerateTask( - kotlinSourceSet = kotlinSourceSet, - project = project, - resourcesSourceDirectory = resourcesSourceDirectory - ) - - configureLowerDependencies( - kotlinSourceSet = kotlinSourceSet, - genTask = genTask - ) + kmpExtension.sourceSets.configureEach { kotlinSourceSet -> + val resourcesSourceDirectory: SourceDirectorySet = createMokoResourcesSourceSet( + project = project, + kotlinSourceSet = kotlinSourceSet + ) - configureUpperDependencies( + val genTask: TaskProvider = + registerGenerateTask( kotlinSourceSet = kotlinSourceSet, + project = project, resourcesSourceDirectory = resourcesSourceDirectory ) - configureTaskDependencies( - kotlinSourceSet = kotlinSourceSet, - genTask = genTask - ) - } + configureLowerDependencies( + kotlinSourceSet = kotlinSourceSet, + genTask = genTask + ) + + configureUpperDependencies( + kotlinSourceSet = kotlinSourceSet, + resourcesSourceDirectory = resourcesSourceDirectory + ) + + configureTaskDependencies( + kotlinSourceSet = kotlinSourceSet, + genTask = genTask + ) + } kmpExtension.targets.configureEach { target -> target.compilations.configureEach { compilation -> From 85206d86912c694800a10a5ef44737025f1ed515 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 9 Oct 2023 00:20:39 +0700 Subject: [PATCH 043/352] #535 part of gen task new configuration --- .../gradle/MultiplatformResourcesPlugin.kt | 5 +- .../icerock/gradle/generator/MRGenerator.kt | 92 +++++----- .../GenerateMultiplatformResourcesTask.kt | 171 +++++++++++++----- 3 files changed, 169 insertions(+), 99 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 085bb69f0..c82b6ac1c 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -98,7 +98,10 @@ open class MultiplatformResourcesPlugin : Plugin { ) genTask.configure { - it.kotlinTarget.set(target.targetName) + it.platformType.set(target.platformType.name) + if (target is KotlinNativeTarget) { + it.konanTarget.set(target.konanTarget.name) + } } compilation.compileTaskProvider.configure { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt index b48494e63..a87c19295 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt @@ -13,38 +13,32 @@ import dev.icerock.gradle.MRVisibility import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.toModifier import org.gradle.api.Project +import org.gradle.api.file.Directory import org.gradle.api.file.SourceDirectorySet import org.gradle.api.provider.Provider import java.io.File abstract class MRGenerator( - generatedDir: File, protected val sourceSet: Provider, protected val settings: Settings, internal val generators: List ) { - internal val outputDir: Provider = sourceSet.map { File(generatedDir, it.name) } - protected open val sourcesGenerationDir: Provider = outputDir.map { File(it, "src") } - protected open val resourcesGenerationDir: Provider = outputDir.map { File(it, "res") } - protected open val assetsGenerationDir: Provider = outputDir.map { - File(it, AssetsGenerator.ASSETS_DIR_NAME) - } + internal val outputDir: File = settings.generatedDir.asFile + protected open val sourcesGenerationDir: File = File(outputDir, "src") + protected open val resourcesGenerationDir: File = File(outputDir, "res") + protected open val assetsGenerationDir: File = File(outputDir, AssetsGenerator.ASSETS_DIR_NAME) internal fun generate() { - val sourcesGenerationDir: File = sourcesGenerationDir.get() - val assetsGenerationDir: File = assetsGenerationDir.get() - val resourcesGenerationDir: File = resourcesGenerationDir.get() - sourcesGenerationDir.deleteRecursively() resourcesGenerationDir.deleteRecursively() assetsGenerationDir.deleteRecursively() beforeMRGeneration() - val visibilityModifier: KModifier = settings.visibility.get().toModifier() + val visibilityModifier: KModifier = settings.visibility.toModifier() @Suppress("SpreadOperator") - val mrClassSpec = TypeSpec.objectBuilder(settings.className.get()) + val mrClassSpec = TypeSpec.objectBuilder(settings.className) .addModifiers(*getMRClassModifiers()) .addModifiers(visibilityModifier) @@ -74,8 +68,8 @@ abstract class MRGenerator( val mrClass = mrClassSpec.build() val fileSpec = FileSpec.builder( - packageName = settings.packageName.get(), - fileName = settings.className.get() + packageName = settings.packageName, + fileName = settings.className ).addType(mrClass) generators @@ -89,44 +83,44 @@ abstract class MRGenerator( afterMRGeneration() } - fun apply(project: Project): GenerateMultiplatformResourcesTask { - setupGenerationDirs() - - val name: String = sourceSet.get().name - val genTask = project.tasks.create( - "generateMR$name", - GenerateMultiplatformResourcesTask::class.java - ) { -// it.generator = this - it.inputs.property("mokoSettingsPackageName", settings.packageName) - it.inputs.property("mokoSettingsClassName", settings.className) - it.inputs.property("mokoSettingsVisibility", settings.visibility) - } - - apply(generationTask = genTask, project = project) - - return genTask - } +// fun apply(project: Project): GenerateMultiplatformResourcesTask { +// setupGenerationDirs() +// +// val name: String = sourceSet.get().name +// val genTask = project.tasks.create( +// "generateMR$name", +// GenerateMultiplatformResourcesTask::class.java +// ) { +//// it.generator = this +// it.inputs.property("mokoSettingsPackageName", settings.packageName) +// it.inputs.property("mokoSettingsClassName", settings.className) +// it.inputs.property("mokoSettingsVisibility", settings.visibility) +// } +// +// apply(generationTask = genTask, project = project) +// +// return genTask +// } protected open fun beforeMRGeneration() = Unit protected open fun afterMRGeneration() = Unit protected abstract fun getMRClassModifiers(): Array - protected abstract fun apply( - generationTask: GenerateMultiplatformResourcesTask, - project: Project - ) +// protected abstract fun apply( +// generationTask: GenerateMultiplatformResourcesTask, +// project: Project +// ) protected open fun processMRClass(mrClass: TypeSpec.Builder) {} protected open fun getImports(): List = emptyList() - private fun setupGenerationDirs() { - with(sourceSet.get()) { - addSourceDir(sourcesGenerationDir) - addResourcesDir(resourcesGenerationDir) - addAssetsDir(assetsGenerationDir) - } - } +// private fun setupGenerationDirs() { +// with(sourceSet.get()) { +// addSourceDir(sourcesGenerationDir) +// addResourcesDir(resourcesGenerationDir) +// addAssetsDir(assetsGenerationDir) +// } +// } interface Generator : ObjectBodyExtendable { val mrObjectName: String @@ -151,13 +145,11 @@ abstract class MRGenerator( } data class Settings( - val packageName: Provider, - val className: Provider, - val visibility: Provider, - val generatedDir: File, + val packageName: String, + val className: String, + val visibility: MRVisibility, + val generatedDir: Directory, val isStrictLineBreaks: Boolean, - val iosLocalizationRegion: Provider, val resourcesSourceDirectory: SourceDirectorySet, - val androidRClassPackage: Provider ) } 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 d3ff707e9..e544ffa0d 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 @@ -4,15 +4,35 @@ package dev.icerock.gradle.tasks +import dev.icerock.gradle.MRVisibility +import dev.icerock.gradle.generator.AssetsGenerator +import dev.icerock.gradle.generator.ColorsGenerator +import dev.icerock.gradle.generator.FilesGenerator +import dev.icerock.gradle.generator.FontsGenerator +import dev.icerock.gradle.generator.ImagesGenerator +import dev.icerock.gradle.generator.MRGenerator +import dev.icerock.gradle.generator.PluralsGenerator +import dev.icerock.gradle.generator.ResourceGeneratorFeature +import dev.icerock.gradle.generator.StringsGenerator +import dev.icerock.gradle.generator.android.AndroidMRGenerator +import dev.icerock.gradle.generator.apple.AppleMRGenerator +import dev.icerock.gradle.generator.common.CommonMRGenerator +import dev.icerock.gradle.generator.js.JsMRGenerator +import dev.icerock.gradle.generator.jvm.JvmMRGenerator import org.gradle.api.DefaultTask import org.gradle.api.file.ConfigurableFileCollection +import org.gradle.api.file.DirectoryProperty +import org.gradle.api.file.RegularFileProperty import org.gradle.api.provider.Property import org.gradle.api.tasks.CacheableTask import org.gradle.api.tasks.Classpath import org.gradle.api.tasks.Input import org.gradle.api.tasks.InputFiles +import org.gradle.api.tasks.OutputDirectory +import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.TaskAction -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType +import org.jetbrains.kotlin.konan.target.KonanTarget @CacheableTask abstract class GenerateMultiplatformResourcesTask : DefaultTask() { @@ -30,22 +50,28 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { abstract val upperResources: ConfigurableFileCollection @get:Input - abstract val kotlinTarget: Property + abstract val platformType: Property -// @get:Input -// val kotlinSourceSet: Property = objectFactory.property() + @get:Input + abstract val konanTarget: Property + + @get:Input + abstract val resourcesPackageName: Property + + @get:Input + abstract val resourcesClassName: Property + + @get:Input + abstract val resourcesVisibility: Property + + @get:OutputFile + abstract val generationReport: RegularFileProperty -// @get:InputFiles -// val inputFiles: Iterable -// get() = generator.generators.flatMap { it.inputFiles } -// -// @get:OutputDirectory -// val outputDirectory: File -// get() = generator.outputDir.get() + @get:OutputDirectory + abstract val outputDirectory: DirectoryProperty init { group = "moko-resources" - kotlinTarget.convention("kotlinMetadata") } @TaskAction @@ -53,44 +79,93 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { logger.warn("i $name have ownResources ${ownResources.from}") logger.warn("i $name have lowerResources ${lowerResources.from}") logger.warn("i $name have upperResources ${upperResources.from}") - logger.warn("i $name have kotlinTarget ${kotlinTarget.get()}") - -// val kmpExtension: KotlinMultiplatformExtension = project.extensions.getByType() -// val sourceSet: KotlinSourceSet = kotlinSourceSet.get() -// val ownSourceDirectory: SourceDirectorySet = -// sourceSet.extras[mokoResourcesSourceDirectoryKey()] -// ?: error("can't find source directory!") -// -// val allSourceDirectories = sourceSet.allSourceSets() -// .map { it.extras[mokoResourcesSourceDirectoryKey()] } -// .onEach { project.logger.warn("found mrs $it") } -// .filterNotNull() -// -// val (target, compilation) = kmpExtension.targets -// .onEach { project.logger.warn("found target $it") } -// .flatMap { target -> -// target.compilations.map { target to it } -// } -// .onEach { (target, compilation) -> -// project.logger.warn("found $target $compilation with ${compilation.defaultSourceSet} ${compilation.kotlinSourceSets}") -// } -// .filter { (target, compilation) -> -// compilation.defaultSourceSet == sourceSet -// } -// .onEach { project.logger.warn("found with default $it") } -// .first() -// -// project.logger.warn("${this.name} from $compilation ${compilation?.target}") -// -// project.logger.warn("ownSourceDirectory $ownSourceDirectory") -// project.logger.warn("allSourceDirectories $allSourceDirectories") - - // TODO when task executed we should detect which generator should be used by check source - // sets hierarhy + val generator: MRGenerator = resolveGenerator() + generator.generate() + } + + private fun resolveGenerator(): MRGenerator { + return when (KotlinPlatformType.valueOf(platformType.get())) { + KotlinPlatformType.common -> createCommonGenerator() + KotlinPlatformType.jvm -> createJvmGenerator() + KotlinPlatformType.js -> createJsGenerator() + KotlinPlatformType.androidJvm -> createAndroidJvmGenerator() + KotlinPlatformType.native -> createNativeGenerator() + KotlinPlatformType.wasm -> error("moko-resources not support wasm target now") + } + } + + private fun createGeneratorFeatures(): List> { + val settings = MRGenerator.Settings( + packageName = resourcesPackageName.get(), + className = resourcesClassName.get(), + visibility = resourcesVisibility.get(), + generatedDir = outputDirectory.get(), + isStrictLineBreaks = project.isStrictLineBreaks, + iosLocalizationRegion = mrExtension.iosBaseLocalizationRegion, + resourcesSourceDirectory = resourcesSourceDirectory, + androidRClassPackage = project.getAndroidRClassPackage() + ) + + return listOf( + StringsGenerator.Feature(settings), + PluralsGenerator.Feature(settings), + ImagesGenerator.Feature(settings, logger), + FontsGenerator.Feature(settings), + FilesGenerator.Feature(settings), + ColorsGenerator.Feature(settings), + AssetsGenerator.Feature(settings) + ) + } + + private fun createCommonGenerator(): CommonMRGenerator { + return CommonMRGenerator( + + ) + } + + private fun createJvmGenerator(): JvmMRGenerator { + TODO() + } + + private fun createJsGenerator(): JsMRGenerator { + TODO() + } + + private fun createAndroidJvmGenerator(): AndroidMRGenerator { + TODO() + } + + private fun createNativeGenerator(): MRGenerator { + val konanTargetName: String = konanTarget.get() + val konanTarget: KonanTarget = KonanTarget.predefinedTargets[konanTargetName] + ?: error("can't find $konanTargetName in KonanTarget") + + return when (konanTarget) { + KonanTarget.IOS_ARM32, + KonanTarget.IOS_ARM64, + KonanTarget.IOS_SIMULATOR_ARM64, + KonanTarget.IOS_X64, + + KonanTarget.MACOS_ARM64, + KonanTarget.MACOS_X64, + + KonanTarget.TVOS_ARM64, + KonanTarget.TVOS_SIMULATOR_ARM64, + KonanTarget.TVOS_X64, + + KonanTarget.WATCHOS_ARM32, + KonanTarget.WATCHOS_ARM64, + KonanTarget.WATCHOS_DEVICE_ARM64, + KonanTarget.WATCHOS_SIMULATOR_ARM64, + KonanTarget.WATCHOS_X64, + KonanTarget.WATCHOS_X86 -> createAppleGenerator() + + else -> error("$konanTarget is not supported by moko-resources now!") + } } - private fun KotlinSourceSet.allSourceSets(): Set { - return setOf(this) + dependsOn.flatMap { it.allSourceSets() } + private fun createAppleGenerator(): AppleMRGenerator { + TODO() } } From b546ac64cc1cc6db068b37cc295df251596b309a Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Thu, 2 Nov 2023 18:53:57 +0700 Subject: [PATCH 044/352] #535 add hierarchy of resources in settings, removed property and provide, --- .../gradle/generator/AssetsGenerator.kt | 27 ++++----- .../gradle/generator/ColorsGenerator.kt | 2 +- .../gradle/generator/FilesGenerator.kt | 4 +- .../gradle/generator/FontsGenerator.kt | 4 +- .../gradle/generator/ImagesGenerator.kt | 2 +- .../icerock/gradle/generator/MRGenerator.kt | 10 ++-- .../gradle/generator/PluralsGenerator.kt | 4 +- .../gradle/generator/StringsGenerator.kt | 4 +- .../android/AndroidAssetsGenerator.kt | 5 +- .../android/AndroidFilesGenerator.kt | 5 +- .../android/AndroidFontsGenerator.kt | 4 +- .../android/AndroidImagesGenerator.kt | 4 +- .../generator/android/AndroidMRGenerator.kt | 2 - .../android/AndroidPluralsGenerator.kt | 6 +- .../android/AndroidStringsGenerator.kt | 4 +- .../generator/apple/AppleAssetsGenerator.kt | 5 +- .../generator/apple/AppleMRGenerator.kt | 19 +++---- .../generator/apple/ApplePluralsGenerator.kt | 5 +- .../generator/apple/AppleStringsGenerator.kt | 2 +- .../apple/action/PackResourcesToKLibAction.kt | 17 +++--- .../generator/common/CommonAssetsGenerator.kt | 5 +- .../generator/common/CommonMRGenerator.kt | 2 - .../gradle/generator/js/JsAssetsGenerator.kt | 5 +- .../gradle/generator/js/JsFontsGenerator.kt | 11 ++-- .../gradle/generator/js/JsMRGenerator.kt | 20 ++----- .../gradle/generator/js/JsPluralsGenerator.kt | 11 ++-- .../gradle/generator/js/JsStringsGenerator.kt | 11 ++-- .../generator/jvm/ClassLoaderExtender.kt | 4 +- .../generator/jvm/JvmAssetsGenerator.kt | 5 +- .../gradle/generator/jvm/JvmMRGenerator.kt | 16 ++---- .../generator/jvm/JvmPluralsGenerator.kt | 6 +- .../generator/jvm/JvmStringsGenerator.kt | 7 ++- .../GenerateMultiplatformResourcesTask.kt | 56 ++++++++++++++----- .../dev/icerock/gradle/utils/StringExt.kt | 11 ++++ 34 files changed, 166 insertions(+), 139 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt index 9a093c919..9f3e273ce 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt @@ -14,14 +14,15 @@ import dev.icerock.gradle.generator.apple.AppleAssetsGenerator import dev.icerock.gradle.generator.common.CommonAssetsGenerator import dev.icerock.gradle.generator.js.JsAssetsGenerator import dev.icerock.gradle.generator.jvm.JvmAssetsGenerator -import org.gradle.api.file.SourceDirectorySet +import org.gradle.api.file.FileTree import java.io.File @Suppress("TooManyFunctions") abstract class AssetsGenerator( - private val sourceDirectorySet: SourceDirectorySet + private val fileTree: FileTree ) : MRGenerator.Generator { - override val inputFiles: Iterable get() = sourceDirectorySet.files + override val inputFiles: Iterable + get() = fileTree.files override val mrObjectName: String = ASSETS_DIR_NAME override val resourceClassName = ClassName("dev.icerock.moko.resources", "AssetResource") @@ -89,7 +90,7 @@ abstract class AssetsGenerator( resourcesGenerationDir: File, objectBuilder: TypeSpec.Builder ): TypeSpec { - val rootContent = parseRootContent(sourceDirectorySet.sourceDirectories.files) + val rootContent = parseRootContent(fileTree.files) beforeGenerate(objectBuilder, rootContent) @@ -158,15 +159,15 @@ abstract class AssetsGenerator( abstract fun getPropertyInitializer(fileSpec: AssetSpecFile): CodeBlock? - /* - * @param pathRelativeToBase used to copy necessary resources in AssetsGenerator - * @param newFilePath is a new name a of copied resource for systems which do not support path with / symbol - */ sealed class AssetSpec class AssetSpecDirectory(val name: String, val assets: List) : AssetSpec() + /** + * @param pathRelativeToBase used to copy necessary resources in AssetsGenerator + * @param file is a new name a of copied resource for systems which do not support path with / symbol + */ class AssetSpecFile( val pathRelativeToBase: String, val file: File @@ -177,24 +178,24 @@ abstract class AssetsGenerator( ) : ResourceGeneratorFeature { override fun createCommonGenerator(): AssetsGenerator = CommonAssetsGenerator( - sourceDirectorySet = settings.resourcesSourceDirectory + fileTree = settings.ownResourcesFileTree ) override fun createIosGenerator(): AssetsGenerator = AppleAssetsGenerator( - sourceDirectorySet = settings.resourcesSourceDirectory + fileTree = settings.ownResourcesFileTree ) override fun createAndroidGenerator(): AssetsGenerator = AndroidAssetsGenerator( - sourceDirectorySet = settings.resourcesSourceDirectory + fileTree = settings.ownResourcesFileTree ) override fun createJvmGenerator(): AssetsGenerator = JvmAssetsGenerator( - sourceDirectorySet = settings.resourcesSourceDirectory, + fileTree = settings.ownResourcesFileTree, settings = settings ) override fun createJsGenerator(): AssetsGenerator = JsAssetsGenerator( - sourceDirectorySet = settings.resourcesSourceDirectory + fileTree = settings.ownResourcesFileTree ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt index 4d8bbc938..fc9069893 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt @@ -137,7 +137,7 @@ abstract class ColorsGenerator( class Feature( private val settings: MRGenerator.Settings ) : ResourceGeneratorFeature { - private val fileTree: FileTree = settings.resourcesSourceDirectory + private val fileTree: FileTree = settings.ownResourcesFileTree .matching { it.include("**/colors*.xml") } override fun createCommonGenerator() = CommonColorsGenerator(fileTree) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt index 19144fdbe..dda52a5ad 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt @@ -96,7 +96,7 @@ abstract class FilesGenerator( private val settings: MRGenerator.Settings ) : ResourceGeneratorFeature { - private val fileTree: FileTree = settings.resourcesSourceDirectory + private val fileTree: FileTree = settings.ownResourcesFileTree .matching { it.include("files/**") } override fun createCommonGenerator(): FilesGenerator = CommonFilesGenerator( @@ -109,7 +109,7 @@ abstract class FilesGenerator( override fun createAndroidGenerator(): FilesGenerator = AndroidFilesGenerator( inputFileTree = fileTree, - androidRClassPackageProvider = settings.androidRClassPackage, + androidRClassPackage = settings.androidRClassPackage, ) override fun createJsGenerator(): FilesGenerator = JsFilesGenerator( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt index 6827d56f0..e9f0aae0f 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt @@ -125,7 +125,7 @@ abstract class FontsGenerator( class Feature( private val settings: MRGenerator.Settings ) : ResourceGeneratorFeature { - private val stringsFileTree: FileTree = settings.resourcesSourceDirectory + private val stringsFileTree: FileTree = settings.ownResourcesFileTree .matching { it.include("fonts/**.ttf", "fonts/**.otf") } override fun createCommonGenerator(): FontsGenerator = CommonFontsGenerator( @@ -138,7 +138,7 @@ abstract class FontsGenerator( override fun createAndroidGenerator(): FontsGenerator = AndroidFontsGenerator( inputFileTree = stringsFileTree, - androidRClassPackageProvider = settings.androidRClassPackage + androidRClassPackage = settings.androidRClassPackage ) override fun createJsGenerator(): FontsGenerator = JsFontsGenerator( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt index 6aedd071d..8170eb15f 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt @@ -101,7 +101,7 @@ abstract class ImagesGenerator( private val settings: MRGenerator.Settings, private val logger: Logger ) : ResourceGeneratorFeature { - private val fileTree: FileTree = settings.resourcesSourceDirectory + private val fileTree: FileTree = settings.ownResourcesFileTree .matching { it.include("images/**/*.png", "images/**/*.jpg", "images/**/*.svg") } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt index a87c19295..9cda08ce3 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt @@ -10,11 +10,9 @@ import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.MRVisibility -import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.toModifier -import org.gradle.api.Project import org.gradle.api.file.Directory -import org.gradle.api.file.SourceDirectorySet +import org.gradle.api.file.FileTree import org.gradle.api.provider.Provider import java.io.File @@ -150,6 +148,10 @@ abstract class MRGenerator( val visibility: MRVisibility, val generatedDir: Directory, val isStrictLineBreaks: Boolean, - val resourcesSourceDirectory: SourceDirectorySet, + val iosLocalizationRegion: String, + val ownResourcesFileTree: FileTree, + val lowerResourcesFileTree: FileTree, + val upperResourcesFileTree: FileTree, + val androidRClassPackage: String ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt index 5d3137851..f1f40ae7a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt @@ -95,7 +95,7 @@ abstract class PluralsGenerator( class Feature( private val settings: MRGenerator.Settings ) : ResourceGeneratorFeature { - private val fileTree: FileTree = settings.resourcesSourceDirectory + private val fileTree: FileTree = settings.ownResourcesFileTree .matching { it.include("**/plurals*.xml") } override fun createCommonGenerator(): PluralsGenerator = CommonPluralsGenerator( @@ -112,7 +112,7 @@ abstract class PluralsGenerator( override fun createAndroidGenerator(): PluralsGenerator = AndroidPluralsGenerator( pluralsFileTree = fileTree, strictLineBreaks = settings.isStrictLineBreaks, - androidRClassPackageProvider = settings.androidRClassPackage, + androidRClassPackage = settings.androidRClassPackage, ) override fun createJvmGenerator(): PluralsGenerator = JvmPluralsGenerator( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt index 69ce87fb9..5b5b46481 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt @@ -75,7 +75,7 @@ abstract class StringsGenerator( class Feature( private val settings: MRGenerator.Settings ) : ResourceGeneratorFeature { - private val fileTree: FileTree = settings.resourcesSourceDirectory + private val fileTree: FileTree = settings.ownResourcesFileTree .matching { it.include("**/strings*.xml") } override fun createCommonGenerator(): StringsGenerator = CommonStringsGenerator( @@ -92,7 +92,7 @@ abstract class StringsGenerator( override fun createAndroidGenerator(): StringsGenerator = AndroidStringsGenerator( stringsFileTree = fileTree, strictLineBreaks = settings.isStrictLineBreaks, - androidRClassPackageProvider = settings.androidRClassPackage + androidRClassPackage = settings.androidRClassPackage ) override fun createJsGenerator(): StringsGenerator = JsStringsGenerator( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidAssetsGenerator.kt index 4e47e66a2..c45a2aef3 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidAssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidAssetsGenerator.kt @@ -9,12 +9,13 @@ import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.AssetsGenerator import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable +import org.gradle.api.file.FileTree import org.gradle.api.file.SourceDirectorySet import java.io.File class AndroidAssetsGenerator( - sourceDirectorySet: SourceDirectorySet -) : AssetsGenerator(sourceDirectorySet), ObjectBodyExtendable by NOPObjectBodyExtendable() { + fileTree: FileTree +) : AssetsGenerator(fileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun generateResources( assetsGenerationDir: File, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt index 989c88004..876315eb4 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt @@ -11,13 +11,12 @@ import dev.icerock.gradle.generator.FilesGenerator import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable import org.gradle.api.file.FileTree -import org.gradle.api.provider.Provider import java.io.File import java.util.Locale class AndroidFilesGenerator( inputFileTree: FileTree, - private val androidRClassPackageProvider: Provider, + private val androidRClassPackage: String, ) : FilesGenerator(inputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -27,7 +26,7 @@ class AndroidFilesGenerator( CodeBlock.of("FileResource(rawResId = R.raw.%L)", keyToResourceId(fileSpec.key)) override fun getImports() = listOf( - ClassName(androidRClassPackageProvider.get(), "R") + ClassName(androidRClassPackage, "R") ) override fun generateResources( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFontsGenerator.kt index 9325f89b0..9c268ce1d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFontsGenerator.kt @@ -17,7 +17,7 @@ import java.util.Locale class AndroidFontsGenerator( inputFileTree: FileTree, - private val androidRClassPackageProvider: Provider, + private val androidRClassPackage: String, ) : FontsGenerator(inputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -28,7 +28,7 @@ class AndroidFontsGenerator( } override fun getImports(): List = listOf( - ClassName(androidRClassPackageProvider.get(), "R") + ClassName(androidRClassPackage, "R") ) override fun generateResources( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt index 2f8fd89a2..d15864bee 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt @@ -24,7 +24,7 @@ import kotlin.reflect.full.functions class AndroidImagesGenerator( inputFileTree: FileTree, - private val androidRClassPackageProvider: Provider, + private val androidRClassPackageProvider: String, private val logger: Logger ) : ImagesGenerator(inputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -37,7 +37,7 @@ class AndroidImagesGenerator( } override fun getImports(): List = listOf( - ClassName(androidRClassPackageProvider.get(), "R") + ClassName(androidRClassPackageProvider, "R") ) override fun generateResources( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt index 19dcb1eb0..d93679311 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt @@ -15,12 +15,10 @@ import org.gradle.kotlin.dsl.withType import java.io.File class AndroidMRGenerator( - generatedDir: File, sourceSet: Provider, settings: Settings, generators: List, ) : MRGenerator( - generatedDir = generatedDir, sourceSet = sourceSet, settings = settings, generators = generators diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt index e136414b0..5f4342324 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt @@ -21,7 +21,7 @@ import java.io.File class AndroidPluralsGenerator( pluralsFileTree: FileTree, strictLineBreaks: Boolean, - private val androidRClassPackageProvider: Provider, + private val androidRClassPackage: String, ) : PluralsGenerator(pluralsFileTree, strictLineBreaks), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -32,13 +32,13 @@ class AndroidPluralsGenerator( CodeBlock.of("PluralsResource(R.plurals.%L)", processKey(key)) override fun getImports(): List = listOf( - ClassName(androidRClassPackageProvider.get(), "R") + ClassName(androidRClassPackage, "R") ) override fun generateResources( resourcesGenerationDir: File, language: LanguageType, - strings: Map + strings: Map, ) { val valuesDir = File(resourcesGenerationDir, language.androidResourcesDir) val stringsFile = File(valuesDir, "multiplatform_plurals.xml") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt index 0c4730004..14cb8ab65 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt @@ -20,7 +20,7 @@ import java.io.File class AndroidStringsGenerator( stringsFileTree: FileTree, strictLineBreaks: Boolean, - private val androidRClassPackageProvider: Provider, + private val androidRClassPackage: String, ) : StringsGenerator(stringsFileTree, strictLineBreaks), ObjectBodyExtendable by NOPObjectBodyExtendable() { @@ -32,7 +32,7 @@ class AndroidStringsGenerator( CodeBlock.of("StringResource(R.string.%L)", processKey(key)) override fun getImports(): List = listOf( - ClassName(androidRClassPackageProvider.get(), "R") + ClassName(androidRClassPackage, "R") ) override fun generateResources( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleAssetsGenerator.kt index 9821b442c..c16d0a0e7 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleAssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleAssetsGenerator.kt @@ -8,12 +8,13 @@ import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.AssetsGenerator import dev.icerock.gradle.generator.ObjectBodyExtendable +import org.gradle.api.file.FileTree import org.gradle.api.file.SourceDirectorySet import java.io.File class AppleAssetsGenerator( - sourceDirectorySet: SourceDirectorySet -) : AssetsGenerator(sourceDirectorySet), ObjectBodyExtendable by AppleGeneratorHelper() { + fileTree: FileTree +) : AssetsGenerator(fileTree), ObjectBodyExtendable by AppleGeneratorHelper() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt index eabd0713a..471209a8c 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt @@ -44,21 +44,19 @@ import kotlin.reflect.full.memberProperties @Suppress("TooManyFunctions") class AppleMRGenerator( - generatedDir: File, sourceSet: Provider, settings: Settings, generators: List, private val compilation: AbstractKotlinNativeCompilation, - private val baseLocalizationRegion: Provider, + private val baseLocalizationRegion: String, ) : MRGenerator( - generatedDir = generatedDir, sourceSet = sourceSet, settings = settings, generators = generators ) { private val bundleClassName = ClassName("platform.Foundation", "NSBundle") - private val bundleIdentifierProvider = settings.packageName.map { "$it.MR" } + private val bundleIdentifier = "${settings.packageName}.MR" override fun getMRClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -71,13 +69,13 @@ class AppleMRGenerator( bundleClassName, KModifier.PRIVATE ) - .delegate(CodeBlock.of("lazy { NSBundle.loadableBundle(\"${bundleIdentifierProvider.get()}\") }")) + .delegate(CodeBlock.of("lazy { NSBundle.loadableBundle(\"${bundleIdentifier}\") }")) .build() ) mrClass.addProperty( PropertySpec.builder("contentHash", STRING, KModifier.PRIVATE) - .initializer("%S", resourcesGenerationDir.get().calculateResourcesHash()) + .initializer("%S", resourcesGenerationDir.calculateResourcesHash()) .build() ) } @@ -95,7 +93,7 @@ class AppleMRGenerator( } override fun beforeMRGeneration() { - assetsGenerationDir.get().mkdirs() + assetsGenerationDir.mkdirs() } private fun setupKLibResources(generationTask: GenerateMultiplatformResourcesTask) { @@ -107,9 +105,9 @@ class AppleMRGenerator( task.doLast { PackResourcesToKLibAction( baseLocalizationRegion = baseLocalizationRegion, - bundleIdentifierProvider = bundleIdentifierProvider, - assetsDirectoryProvider = assetsGenerationDir, - resourcesGenerationDirProvider = resourcesGenerationDir, + bundleIdentifier = bundleIdentifier, + assetsDirectory = assetsGenerationDir, + resourcesGenerationDir = resourcesGenerationDir, ) } } @@ -199,7 +197,6 @@ $linkTask produces static framework, Xcode should have Build Phase with copyFram val kotlinNativeTarget = compilation.target as KotlinNativeTarget val project = kotlinNativeTarget.project - @Suppress("ObjectLiteralToLambda") val fatAction: Action = object : Action { override fun execute(task: Task) { val fatTask: FatFrameworkTask = task as FatFrameworkTask diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/ApplePluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/ApplePluralsGenerator.kt index df38cbc4a..2b1de865d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/ApplePluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/ApplePluralsGenerator.kt @@ -12,13 +12,12 @@ import dev.icerock.gradle.generator.ObjectBodyExtendable import dev.icerock.gradle.generator.PluralMap import dev.icerock.gradle.generator.PluralsGenerator import org.gradle.api.file.FileTree -import org.gradle.api.provider.Provider import java.io.File class ApplePluralsGenerator( pluralsFileTree: FileTree, strictLineBreaks: Boolean, - private val baseLocalizationRegion: Provider + private val baseLocalizationRegion: String ) : PluralsGenerator(pluralsFileTree, strictLineBreaks), ObjectBodyExtendable by AppleGeneratorHelper() { @@ -84,7 +83,7 @@ class ApplePluralsGenerator( writeStringsFile(localizableFile, strings) if (language == LanguageType.Base) { - val localRegion: String = baseLocalizationRegion.get() + val localRegion: String = baseLocalizationRegion val regionDir = File(resourcesGenerationDir, "$localRegion.lproj") regionDir.mkdirs() val regionFile = File(regionDir, "Localizable.stringsdict") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleStringsGenerator.kt index 4f212eb3f..d8c39ccd6 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleStringsGenerator.kt @@ -19,7 +19,7 @@ import java.io.File class AppleStringsGenerator( stringsFileTree: FileTree, strictLineBreaks: Boolean, - private val baseLocalizationRegion: Provider + private val baseLocalizationRegion: String ) : StringsGenerator(stringsFileTree, strictLineBreaks), ObjectBodyExtendable by AppleGeneratorHelper() { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/PackResourcesToKLibAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/PackResourcesToKLibAction.kt index ffde1dbc8..cc3829acd 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/PackResourcesToKLibAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/PackResourcesToKLibAction.kt @@ -8,17 +8,16 @@ import dev.icerock.gradle.generator.apple.LoadableBundle import dev.icerock.gradle.utils.unzipTo import org.gradle.api.Action import org.gradle.api.Task -import org.gradle.api.provider.Provider import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile import org.jetbrains.kotlin.konan.file.zipDirAs import java.io.File import java.util.Properties internal class PackResourcesToKLibAction( - private val baseLocalizationRegion: Provider, - private val bundleIdentifierProvider: Provider, - private val assetsDirectoryProvider: Provider, - private val resourcesGenerationDirProvider: Provider, + private val baseLocalizationRegion: String, + private val bundleIdentifier: String, + private val assetsDirectory: File, + private val resourcesGenerationDir: File, ) : Action { override fun execute(task: Task) { task as KotlinNativeCompile @@ -27,8 +26,8 @@ internal class PackResourcesToKLibAction( val repackDir = File(klibFile.parent, klibFile.nameWithoutExtension) val defaultDir = File(repackDir, "default") val resRepackDir = File(defaultDir, "resources") - val assetsDirectory: File = assetsDirectoryProvider.get() - val resourcesGenerationDir: File = resourcesGenerationDirProvider.get() + val assetsDirectory: File = assetsDirectory + val resourcesGenerationDir: File = resourcesGenerationDir task.logger.info("Adding resources to klib file `{}`", klibFile) unzipTo(zipFile = klibFile, outputDirectory = repackDir) @@ -42,8 +41,8 @@ internal class PackResourcesToKLibAction( val loadableBundle = LoadableBundle( directory = resRepackDir, bundleName = uniqueName, - developmentRegion = baseLocalizationRegion.get(), - identifier = bundleIdentifierProvider.get() + developmentRegion = baseLocalizationRegion, + identifier = bundleIdentifier ) loadableBundle.write() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonAssetsGenerator.kt index b5b06a335..a89394d58 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonAssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonAssetsGenerator.kt @@ -9,11 +9,12 @@ import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.AssetsGenerator import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable +import org.gradle.api.file.FileTree import org.gradle.api.file.SourceDirectorySet class CommonAssetsGenerator( - sourceDirectorySet: SourceDirectorySet -) : AssetsGenerator(sourceDirectorySet), ObjectBodyExtendable by NOPObjectBodyExtendable() { + fileTree: FileTree +) : AssetsGenerator(fileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = emptyArray() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index dd3bfd4b0..45a97c5bd 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -14,12 +14,10 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinCompile import java.io.File class CommonMRGenerator( - generatedDir: File, sourceSet: Provider, settings: Settings, generators: List ) : MRGenerator( - generatedDir = generatedDir, sourceSet = sourceSet, settings = settings, generators = generators diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsAssetsGenerator.kt index f76541b1c..5755e9115 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsAssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsAssetsGenerator.kt @@ -13,12 +13,13 @@ import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.AssetsGenerator import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable +import org.gradle.api.file.FileTree import org.gradle.api.file.SourceDirectorySet import java.io.File class JsAssetsGenerator( - sourceDirectorySet: SourceDirectorySet -) : AssetsGenerator(sourceDirectorySet), ObjectBodyExtendable by NOPObjectBodyExtendable() { + fileTree: FileTree +) : AssetsGenerator(fileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFontsGenerator.kt index 72ef79997..646b2fb61 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFontsGenerator.kt @@ -13,6 +13,7 @@ import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.FontsGenerator import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable +import dev.icerock.gradle.utils.flatName import org.gradle.api.file.FileTree import org.gradle.api.provider.Provider import org.gradle.kotlin.dsl.provideDelegate @@ -20,11 +21,11 @@ import java.io.File class JsFontsGenerator( inputFileTree: FileTree, - mrClassPackage: Provider, + mrClassPackage: String, ) : FontsGenerator(inputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { - private val flattenPackage: Provider = mrClassPackage.map { it.replace(".", "") } - private val cssDeclarationsFileName: Provider = flattenPackage.map { "$it-generated-declarations.css" } + private val flattenPackage: String = mrClassPackage.flatName + private val cssDeclarationsFileName: String = "$flattenPackage-generated-declarations.css" override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -64,7 +65,7 @@ class JsFontsGenerator( FunSpec.builder("addFontsToPage") .addCode( "js(%S)", - """require("$FONTS_DIR/${cssDeclarationsFileName.get()}")""" + """require("$FONTS_DIR/${cssDeclarationsFileName}")""" ).build() ) } @@ -76,7 +77,7 @@ class JsFontsGenerator( file.copyTo(File(fontsDir, file.name)) } - val cssDeclarationsFile = File(fontsDir, cssDeclarationsFileName.get()) + val cssDeclarationsFile = File(fontsDir, cssDeclarationsFileName) val declarations = files .takeIf(List<*>::isNotEmpty) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt index 523925018..754288820 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt @@ -13,6 +13,7 @@ import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.utils.calculateResourcesHash import dev.icerock.gradle.utils.dependsOnProcessResources +import dev.icerock.gradle.utils.flatName import dev.icerock.gradle.utils.klibs import org.gradle.api.Action import org.gradle.api.Project @@ -26,29 +27,21 @@ import org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl import java.io.File class JsMRGenerator( - generatedDir: File, sourceSet: Provider, settings: Settings, generators: List, private val compilation: KotlinJsIrCompilation, ) : MRGenerator( - generatedDir = generatedDir, sourceSet = sourceSet, settings = settings, generators = generators ) { - private val flattenClassName: Provider = settings.packageName - .map { it.replace(".", "") } - override val resourcesGenerationDir: Provider = - outputDir.zip(flattenClassName) { outputDir, className -> - File(File(outputDir, className), "res") - } + private val flattenClassName: String = settings.packageName.flatName + override val resourcesGenerationDir: File = File(File(outputDir, flattenClassName), "res") override fun getMRClassModifiers(): Array = arrayOf(KModifier.ACTUAL) override fun processMRClass(mrClass: TypeSpec.Builder) { - val resourcesGenerationDir: File = resourcesGenerationDir.get() - mrClass.addProperty( PropertySpec.builder("contentHash", STRING, KModifier.PRIVATE) .initializer("%S", resourcesGenerationDir.calculateResourcesHash()) @@ -126,7 +119,7 @@ class JsMRGenerator( } class CopyResourcesToKLibAction( - private val resourcesDirProvider: Provider, + private val resourcesDirProvider: File, ) : Action { override fun execute(task: Kotlin2JsCompile) { val unpackedKLibDir: File = task.destinationDirectory.asFile.get() @@ -135,7 +128,7 @@ class JsMRGenerator( if (resRepackDir.exists().not()) return val resDir = File(resRepackDir, "moko-resources-js") - resourcesDirProvider.get().copyRecursively( + resourcesDirProvider.copyRecursively( resDir, overwrite = true ) @@ -143,11 +136,10 @@ class JsMRGenerator( } class CopyResourcesToExecutableAction( - private val resourcesGeneratedDirProvider: Provider, + private val resourcesGeneratedDir: File, ) : Action { override fun execute(task: Kotlin2JsCompile) { val project: Project = task.project - val resourcesGeneratedDir: File = resourcesGeneratedDirProvider.get() task.klibs.forEach { dependency -> copyResourcesFromLibraries( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsPluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsPluralsGenerator.kt index 8df2eda5e..5d5d59807 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsPluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsPluralsGenerator.kt @@ -16,6 +16,7 @@ import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable import dev.icerock.gradle.generator.PluralMap import dev.icerock.gradle.generator.PluralsGenerator +import dev.icerock.gradle.utils.flatName import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.put import org.gradle.api.file.FileTree @@ -24,12 +25,12 @@ import java.io.File class JsPluralsGenerator( pluralsFileTree: FileTree, - mrClassPackage: Provider, + mrClassPackage: String, strictLineBreaks: Boolean ) : PluralsGenerator(pluralsFileTree, strictLineBreaks), ObjectBodyExtendable by NOPObjectBodyExtendable() { - private val flattenClassPackage = mrClassPackage.map { it.replace(".", "") } + private val flattenClassPackage = mrClassPackage.flatName override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -47,10 +48,10 @@ class JsPluralsGenerator( languages = languageMap.keys.toList(), folder = JsMRGenerator.LOCALIZATION_DIR, fallbackFilePropertyName = JsMRGenerator.PLURALS_FALLBACK_FILE_URL_PROPERTY_NAME, - fallbackFile = "${flattenClassPackage.get()}_${JsMRGenerator.PLURALS_JSON_NAME}.json", + fallbackFile = "${flattenClassPackage}_${JsMRGenerator.PLURALS_JSON_NAME}.json", supportedLocalesPropertyName = JsMRGenerator.SUPPORTED_LOCALES_PROPERTY_NAME, getFileNameForLanguage = { language -> - "${flattenClassPackage.get()}_${JsMRGenerator.PLURALS_JSON_NAME}${language.jsResourcesSuffix}.json" + "${flattenClassPackage}_${JsMRGenerator.PLURALS_JSON_NAME}${language.jsResourcesSuffix}.json" } ) val languageKeys = languageMap[LanguageType.Base].orEmpty().keys @@ -74,7 +75,7 @@ class JsPluralsGenerator( strings: Map ) { val fileDirName = - "${flattenClassPackage.get()}_${JsMRGenerator.PLURALS_JSON_NAME}${language.jsResourcesSuffix}" + "${flattenClassPackage}_${JsMRGenerator.PLURALS_JSON_NAME}${language.jsResourcesSuffix}" val localizationDir = File(resourcesGenerationDir, JsMRGenerator.LOCALIZATION_DIR).apply { mkdirs() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt index becfefcdf..7b366386c 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt @@ -17,6 +17,7 @@ import dev.icerock.gradle.generator.ObjectBodyExtendable import dev.icerock.gradle.generator.StringsGenerator import dev.icerock.gradle.generator.js.JsMRGenerator.Companion.STRINGS_FALLBACK_FILE_URL_PROPERTY_NAME import dev.icerock.gradle.generator.js.JsMRGenerator.Companion.SUPPORTED_LOCALES_PROPERTY_NAME +import dev.icerock.gradle.utils.flatName import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.put import org.gradle.api.file.FileTree @@ -25,12 +26,12 @@ import java.io.File class JsStringsGenerator( stringsFileTree: FileTree, - mrClassPackage: Provider, + mrClassPackage: String, strictLineBreaks: Boolean ) : StringsGenerator(stringsFileTree, strictLineBreaks), ObjectBodyExtendable by NOPObjectBodyExtendable() { - private val flattenClassPackage = mrClassPackage.map { it.replace(".", "") } + private val flattenClassPackage = mrClassPackage.flatName override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -48,10 +49,10 @@ class JsStringsGenerator( languages = languageMap.keys.toList(), folder = JsMRGenerator.LOCALIZATION_DIR, fallbackFilePropertyName = STRINGS_FALLBACK_FILE_URL_PROPERTY_NAME, - fallbackFile = "${flattenClassPackage.get()}_${JsMRGenerator.STRINGS_JSON_NAME}.json", + fallbackFile = "${flattenClassPackage}_${JsMRGenerator.STRINGS_JSON_NAME}.json", supportedLocalesPropertyName = SUPPORTED_LOCALES_PROPERTY_NAME, getFileNameForLanguage = { language -> - "${flattenClassPackage.get()}_${JsMRGenerator.STRINGS_JSON_NAME}${language.jsResourcesSuffix}.json" + "${flattenClassPackage}_${JsMRGenerator.STRINGS_JSON_NAME}${language.jsResourcesSuffix}.json" } ) val languageKeys = languageMap[LanguageType.Base].orEmpty().keys @@ -75,7 +76,7 @@ class JsStringsGenerator( strings: Map ) { val fileDirName = - "${flattenClassPackage.get()}_${JsMRGenerator.STRINGS_JSON_NAME}${language.jsResourcesSuffix}" + "${flattenClassPackage}_${JsMRGenerator.STRINGS_JSON_NAME}${language.jsResourcesSuffix}" val localizationDir = File(resourcesGenerationDir, JsMRGenerator.LOCALIZATION_DIR).apply { mkdirs() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/ClassLoaderExtender.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/ClassLoaderExtender.kt index 1f130e7b3..1dfc5ed9e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/ClassLoaderExtender.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/ClassLoaderExtender.kt @@ -12,7 +12,7 @@ import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.ObjectBodyExtendable import org.gradle.api.provider.Provider -class ClassLoaderExtender(private val mrClassName: Provider) : ObjectBodyExtendable { +class ClassLoaderExtender(private val mrClassName: String) : ObjectBodyExtendable { override fun extendObjectBodyAtStart(classBuilder: TypeSpec.Builder) { classBuilder.addProperty( PropertySpec.builder( @@ -20,7 +20,7 @@ class ClassLoaderExtender(private val mrClassName: Provider) : ObjectBod ClassName("java.lang", "ClassLoader"), KModifier.OVERRIDE ) - .initializer(CodeBlock.of("${mrClassName.get()}::class.java.classLoader")) + .initializer(CodeBlock.of("${mrClassName}::class.java.classLoader")) .build() ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmAssetsGenerator.kt index 4aea098f9..d393a3e9c 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmAssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmAssetsGenerator.kt @@ -9,13 +9,14 @@ import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.AssetsGenerator import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.ObjectBodyExtendable +import org.gradle.api.file.FileTree import org.gradle.api.file.SourceDirectorySet import java.io.File class JvmAssetsGenerator( - sourceDirectorySet: SourceDirectorySet, + fileTree: FileTree, settings: MRGenerator.Settings -) : AssetsGenerator(sourceDirectorySet), +) : AssetsGenerator(fileTree), ObjectBodyExtendable by ClassLoaderExtender(settings.className) { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt index 3138c07b1..e46100515 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt @@ -12,6 +12,7 @@ import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.utils.dependsOnProcessResources +import dev.icerock.gradle.utils.flatName import org.gradle.api.Project import org.gradle.api.provider.Provider import org.gradle.jvm.tasks.Jar @@ -20,22 +21,17 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import java.io.File class JvmMRGenerator( - generatedDir: File, sourceSet: Provider, settings: Settings, generators: List ) : MRGenerator( - generatedDir = generatedDir, sourceSet = sourceSet, settings = settings, generators = generators ) { - private val flattenClassNameProvider: Provider = settings.packageName - .map { it.replace(".", "") } - override val resourcesGenerationDir: Provider = outputDir - .zip(flattenClassNameProvider) { dir, className -> - File(File(dir, className), "res") - } + private val flattenClassName: String = settings.packageName.flatName + + override val resourcesGenerationDir: File = File(File(outputDir, flattenClassName), "res") override fun getMRClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -51,7 +47,7 @@ class JvmMRGenerator( CodeBlock.of( "\"%L/%L\"", LOCALIZATION_DIR, - "${flattenClassNameProvider.get()}_$STRINGS_BUNDLE_NAME" + "${flattenClassName}_$STRINGS_BUNDLE_NAME" ) ).build() ) @@ -65,7 +61,7 @@ class JvmMRGenerator( CodeBlock.of( "\"%L/%L\"", LOCALIZATION_DIR, - "${flattenClassNameProvider.get()}_$PLURALS_BUNDLE_NAME" + "${flattenClassName}_$PLURALS_BUNDLE_NAME" ) ).build() ) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmPluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmPluralsGenerator.kt index 94d79f2ca..f87d001a2 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmPluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmPluralsGenerator.kt @@ -12,6 +12,7 @@ import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.ObjectBodyExtendable import dev.icerock.gradle.generator.PluralMap import dev.icerock.gradle.generator.PluralsGenerator +import dev.icerock.gradle.utils.remove import org.gradle.api.file.FileTree import org.gradle.api.provider.Provider import java.io.File @@ -23,8 +24,7 @@ class JvmPluralsGenerator( ) : PluralsGenerator(pluralsFileTree, strictLineBreaks), ObjectBodyExtendable by ClassLoaderExtender(settings.className) { - private val flattenClassPackage: Provider = settings.packageName - .map { it.replace(".", "") } + private val flattenClassPackage: String = settings.packageName.remove('.') override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -43,7 +43,7 @@ class JvmPluralsGenerator( strings: Map ) { val fileDirName = - "${flattenClassPackage.get()}_${JvmMRGenerator.PLURALS_BUNDLE_NAME}${language.jvmResourcesSuffix}" + "${flattenClassPackage}_${JvmMRGenerator.PLURALS_BUNDLE_NAME}${language.jvmResourcesSuffix}" val localizationDir = File(resourcesGenerationDir, JvmMRGenerator.LOCALIZATION_DIR).apply { mkdirs() } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt index e4ec9a0ec..15c42b037 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt @@ -11,6 +11,8 @@ import dev.icerock.gradle.generator.LanguageType import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.ObjectBodyExtendable import dev.icerock.gradle.generator.StringsGenerator +import dev.icerock.gradle.utils.flatName +import dev.icerock.gradle.utils.remove import org.gradle.api.file.FileTree import org.gradle.api.provider.Provider import java.io.File @@ -22,8 +24,7 @@ class JvmStringsGenerator( ) : StringsGenerator(stringsFileTree, strictLineBreaks), ObjectBodyExtendable by ClassLoaderExtender(settings.className) { - private val flattenClassPackage: Provider = settings.packageName - .map { it.replace(".", "") } + private val flattenClassPackage = settings.packageName.flatName override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -42,7 +43,7 @@ class JvmStringsGenerator( strings: Map ) { val fileDirName = - "${flattenClassPackage.get()}_${JvmMRGenerator.STRINGS_BUNDLE_NAME}${language.jvmResourcesSuffix}" + "${flattenClassPackage}_${JvmMRGenerator.STRINGS_BUNDLE_NAME}${language.jvmResourcesSuffix}" val localizationDir = File(resourcesGenerationDir, JvmMRGenerator.LOCALIZATION_DIR).apply { mkdirs() 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 e544ffa0d..408da25d5 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 @@ -5,20 +5,24 @@ package dev.icerock.gradle.tasks import dev.icerock.gradle.MRVisibility +import dev.icerock.gradle.configuration.getAndroidRClassPackage import dev.icerock.gradle.generator.AssetsGenerator import dev.icerock.gradle.generator.ColorsGenerator import dev.icerock.gradle.generator.FilesGenerator import dev.icerock.gradle.generator.FontsGenerator import dev.icerock.gradle.generator.ImagesGenerator import dev.icerock.gradle.generator.MRGenerator +import dev.icerock.gradle.generator.MRGenerator.Settings import dev.icerock.gradle.generator.PluralsGenerator import dev.icerock.gradle.generator.ResourceGeneratorFeature import dev.icerock.gradle.generator.StringsGenerator +import dev.icerock.gradle.generator.StringsGenerator.Feature import dev.icerock.gradle.generator.android.AndroidMRGenerator import dev.icerock.gradle.generator.apple.AppleMRGenerator import dev.icerock.gradle.generator.common.CommonMRGenerator import dev.icerock.gradle.generator.js.JsMRGenerator import dev.icerock.gradle.generator.jvm.JvmMRGenerator +import dev.icerock.gradle.utils.isStrictLineBreaks import org.gradle.api.DefaultTask import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.DirectoryProperty @@ -61,6 +65,9 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { @get:Input abstract val resourcesClassName: Property + @get:Input + abstract val iosBaseLocalizationRegion: Property + @get:Input abstract val resourcesVisibility: Property @@ -80,13 +87,19 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { logger.warn("i $name have lowerResources ${lowerResources.from}") logger.warn("i $name have upperResources ${upperResources.from}") - val generator: MRGenerator = resolveGenerator() - generator.generate() + val settings: Settings = createGeneratorSettings() + val features: List> = createGeneratorFeatures(settings) + val generator: MRGenerator = resolveGenerator(settings, generators = features) + logger.warn("i generator type: ${generator::class.java.simpleName}") +// generator.generate() } - private fun resolveGenerator(): MRGenerator { + private fun resolveGenerator( + settings: MRGenerator.Settings, + generators: List> + ): MRGenerator { return when (KotlinPlatformType.valueOf(platformType.get())) { - KotlinPlatformType.common -> createCommonGenerator() + KotlinPlatformType.common -> createCommonGenerator(settings, generators) KotlinPlatformType.jvm -> createJvmGenerator() KotlinPlatformType.js -> createJsGenerator() KotlinPlatformType.androidJvm -> createAndroidJvmGenerator() @@ -95,18 +108,24 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { } } - private fun createGeneratorFeatures(): List> { - val settings = MRGenerator.Settings( + private fun createGeneratorSettings(): MRGenerator.Settings { + return MRGenerator.Settings( packageName = resourcesPackageName.get(), className = resourcesClassName.get(), - visibility = resourcesVisibility.get(), + ownResourcesFileTree = ownResources.asFileTree, + lowerResourcesFileTree = lowerResources.asFileTree, + upperResourcesFileTree = upperResources.asFileTree, generatedDir = outputDirectory.get(), isStrictLineBreaks = project.isStrictLineBreaks, - iosLocalizationRegion = mrExtension.iosBaseLocalizationRegion, - resourcesSourceDirectory = resourcesSourceDirectory, - androidRClassPackage = project.getAndroidRClassPackage() + visibility = resourcesVisibility.get(), + androidRClassPackage = project.getAndroidRClassPackage().get(), + iosLocalizationRegion = iosBaseLocalizationRegion.get(), ) + } + private fun createGeneratorFeatures( + settings: MRGenerator.Settings + ): List> { return listOf( StringsGenerator.Feature(settings), PluralsGenerator.Feature(settings), @@ -118,21 +137,27 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { ) } - private fun createCommonGenerator(): CommonMRGenerator { + private fun createCommonGenerator( + settings: MRGenerator.Settings, + generators: List> + ): CommonMRGenerator { return CommonMRGenerator( + sourceSet =, + settings = createGeneratorSettings(), + generators = generators ) } - private fun createJvmGenerator(): JvmMRGenerator { + private fun createAndroidJvmGenerator(): AndroidMRGenerator { TODO() } - private fun createJsGenerator(): JsMRGenerator { + private fun createJvmGenerator(): JvmMRGenerator { TODO() } - private fun createAndroidJvmGenerator(): AndroidMRGenerator { + private fun createJsGenerator(): JsMRGenerator { TODO() } @@ -159,7 +184,8 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { KonanTarget.WATCHOS_DEVICE_ARM64, KonanTarget.WATCHOS_SIMULATOR_ARM64, KonanTarget.WATCHOS_X64, - KonanTarget.WATCHOS_X86 -> createAppleGenerator() + KonanTarget.WATCHOS_X86, + -> createAppleGenerator() else -> error("$konanTarget is not supported by moko-resources now!") } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/StringExt.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/StringExt.kt index c10a9b78e..434cdc4d6 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/StringExt.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/StringExt.kt @@ -26,3 +26,14 @@ internal fun String.capitalize(): String { internal fun String.decapitalize(): String { return replaceFirstChar { it.lowercase(Locale.ROOT) } } + +internal fun String.remove(char: Char): String { + return this.remove(char.toString()) +} + +internal fun String.remove(char: String): String { + return this.replace(char, "") +} + +internal val String.flatName: String + get() = this.remove('.') From e4503117fbb697f5fbcb365040d3d8c61f6a65e0 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Tue, 14 Nov 2023 12:58:56 +0700 Subject: [PATCH 045/352] #535 removed sourceSets from generators, add settings fields, started rework strings generator --- gradle/libs.versions.toml | 6 +- .../gradle/MultiplatformResourcesPlugin.kt | 136 +++++++++++++++--- .../gradle/configuration/AndroidTarget.kt | 5 - .../gradle/configuration/AppleTargets.kt | 2 - .../gradle/configuration/CommonTarget.kt | 11 +- .../icerock/gradle/configuration/JsTarget.kt | 2 - .../icerock/gradle/configuration/JvmTarget.kt | 5 - .../dev/icerock/gradle/configuration/Utils.kt | 12 +- .../gradle/generator/AssetsGenerator.kt | 15 +- .../gradle/generator/ColorsGenerator.kt | 43 ++++-- .../gradle/generator/FilesGenerator.kt | 19 ++- .../gradle/generator/FontsGenerator.kt | 19 ++- .../gradle/generator/ImagesGenerator.kt | 19 ++- .../icerock/gradle/generator/MRGenerator.kt | 117 +++++---------- .../gradle/generator/PluralsGenerator.kt | 15 +- .../gradle/generator/StringsGenerator.kt | 40 ++++-- .../gradle/generator/TargetMRGenerator.kt | 69 +++++++++ .../android/AndroidAssetsGenerator.kt | 6 +- .../android/AndroidColorsGenerator.kt | 5 +- .../android/AndroidFilesGenerator.kt | 5 +- .../android/AndroidFontsGenerator.kt | 6 +- .../android/AndroidImagesGenerator.kt | 6 +- .../generator/android/AndroidMRGenerator.kt | 8 +- .../android/AndroidPluralsGenerator.kt | 6 +- .../android/AndroidStringsGenerator.kt | 35 ++++- .../generator/apple/AppleAssetsGenerator.kt | 6 +- .../generator/apple/AppleColorsGenerator.kt | 5 +- .../generator/apple/AppleFilesGenerator.kt | 7 +- .../generator/apple/AppleFontsGenerator.kt | 5 +- .../generator/apple/AppleImagesGenerator.kt | 5 +- .../generator/apple/AppleMRGenerator.kt | 27 ++-- .../generator/apple/ApplePluralsGenerator.kt | 5 +- .../generator/apple/AppleStringsGenerator.kt | 10 +- .../generator/common/CommonAssetsGenerator.kt | 6 +- .../generator/common/CommonColorsGenerator.kt | 5 +- .../generator/common/CommonFilesGenerator.kt | 5 +- .../generator/common/CommonFontsGenerator.kt | 5 +- .../generator/common/CommonImagesGenerator.kt | 5 +- .../generator/common/CommonMRGenerator.kt | 109 +++++++++++++- .../common/CommonPluralsGenerator.kt | 5 +- .../common/CommonStringsGenerator.kt | 11 +- .../gradle/generator/js/JsAssetsGenerator.kt | 6 +- .../gradle/generator/js/JsColorsGenerator.kt | 5 +- .../gradle/generator/js/JsFilesGenerator.kt | 5 +- .../gradle/generator/js/JsFontsGenerator.kt | 5 +- .../gradle/generator/js/JsImagesGenerator.kt | 5 +- .../gradle/generator/js/JsMRGenerator.kt | 18 +-- .../gradle/generator/js/JsPluralsGenerator.kt | 6 +- .../gradle/generator/js/JsStringsGenerator.kt | 10 +- .../generator/jvm/JvmAssetsGenerator.kt | 6 +- .../generator/jvm/JvmColorsGenerator.kt | 5 +- .../gradle/generator/jvm/JvmFilesGenerator.kt | 5 +- .../gradle/generator/jvm/JvmFontsGenerator.kt | 5 +- .../generator/jvm/JvmImagesGenerator.kt | 5 +- .../gradle/generator/jvm/JvmMRGenerator.kt | 18 +-- .../generator/jvm/JvmPluralsGenerator.kt | 6 +- .../generator/jvm/JvmStringsGenerator.kt | 15 +- .../GenerateMultiplatformResourcesTask.kt | 110 ++++++++------ .../dev/icerock/gradle/utils/FileExt.kt | 3 + 59 files changed, 706 insertions(+), 365 deletions(-) create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2114a37af..ecb1fe5cc 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,7 +1,7 @@ [versions] -kotlinVersion = "1.9.0" +kotlinVersion = "1.9.10" androidGradleVersion = "7.4.2" -androidSdkCommonVersion = "31.0.0" +androidSdkCommonVersion = "31.1.2" # kotlinx kotlinxSerializationVersion = "1.5.1" @@ -14,7 +14,7 @@ androidAppCompatVersion = "1.6.1" composeUiVersion = "1.5.1" # jetbrains compose -composeJetbrainsVersion = "1.5.0" +composeJetbrainsVersion = "1.5.1" # jvm apacheCommonsTextVersion = "1.10.0" diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index c82b6ac1c..779e61fe5 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -4,6 +4,8 @@ package dev.icerock.gradle +import com.android.build.api.dsl.AndroidSourceSet +import com.android.build.gradle.BaseExtension import dev.icerock.gradle.configuration.configureAndroidTargetGenerator import dev.icerock.gradle.configuration.configureAppleTargetGenerator import dev.icerock.gradle.configuration.configureCommonTargetGenerator @@ -23,11 +25,13 @@ import dev.icerock.gradle.utils.dependsOnObservable import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.file.SourceDirectorySet +import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.TaskProvider import org.gradle.kotlin.dsl.create import org.gradle.kotlin.dsl.getByType import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension import org.jetbrains.kotlin.gradle.plugin.KotlinMultiplatformPluginWrapper import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet @@ -53,26 +57,29 @@ open class MultiplatformResourcesPlugin : Plugin { mrExtension = mrExtension, kmpExtension = kmpExtension ) + + //TODO add configuration for generated resources + setupResourcesSourceSet(project, kmpExtension) } } private fun configureKotlinTargetGenerator( project: Project, mrExtension: MultiplatformResourcesPluginExtension, - kmpExtension: KotlinMultiplatformExtension + kmpExtension: KotlinMultiplatformExtension, ) { - kmpExtension.sourceSets.configureEach { kotlinSourceSet -> + kmpExtension.sourceSets.configureEach { kotlinSourceSet: KotlinSourceSet -> val resourcesSourceDirectory: SourceDirectorySet = createMokoResourcesSourceSet( project = project, kotlinSourceSet = kotlinSourceSet ) - val genTask: TaskProvider = - registerGenerateTask( - kotlinSourceSet = kotlinSourceSet, - project = project, - resourcesSourceDirectory = resourcesSourceDirectory - ) + val genTask: TaskProvider = registerGenerateTask( + kotlinSourceSet = kotlinSourceSet, + project = project, + resourcesSourceDirectory = resourcesSourceDirectory, + mrExtension = mrExtension + ) configureLowerDependencies( kotlinSourceSet = kotlinSourceSet, @@ -91,6 +98,8 @@ open class MultiplatformResourcesPlugin : Plugin { } kmpExtension.targets.configureEach { target -> + project.logger.warn("i target ${target.targetName}") + target.compilations.configureEach { compilation -> val sourceSet: KotlinSourceSet = compilation.defaultSourceSet val genTask: TaskProvider = requireNotNull( @@ -98,7 +107,10 @@ open class MultiplatformResourcesPlugin : Plugin { ) genTask.configure { + project.logger.warn("i configure platformName ${target.platformType.name}") + it.platformType.set(target.platformType.name) + if (target is KotlinNativeTarget) { it.konanTarget.set(target.konanTarget.name) } @@ -163,9 +175,90 @@ open class MultiplatformResourcesPlugin : Plugin { // setupProjectForApple(project) } + private fun setupResourcesSourceSet( + project: Project, + kmpExtension: KotlinMultiplatformExtension, + ) { + val kotlinExtension: KotlinProjectExtension = project.extensions.getByType( + KotlinProjectExtension::class.java + ) + val commonSourceSet: KotlinSourceSet? = kotlinExtension.sourceSets.findByName( + KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME + ) + val androidExtension: BaseExtension? = + project.extensions.findByName("android") as BaseExtension? + val androidSourceSet: com.android.build.gradle.api.AndroidSourceSet? = + androidExtension?.sourceSets?.getByName(SourceSet.MAIN_SOURCE_SET_NAME) + + when { + commonSourceSet != null -> { + setupKotlinSourceSet( + project = project, + kotlinSourceSet = commonSourceSet, + ) + } + androidSourceSet != null -> { + setupAndroidSourceSet( + project = project, + androidSourceSet = androidSourceSet + ) + } + else -> { + kmpExtension.sourceSets.configureEach { kotlinSourceSet -> + setupKotlinSourceSet( + project = project, + kotlinSourceSet = kotlinSourceSet, + ) + } + } + } + } + + private fun setupKotlinSourceSet( + project: Project, + kotlinSourceSet: KotlinSourceSet, + ) { + val mokoResourcesDir = getGeneratedResourcesDir( + project = project, + sourceSetName = kotlinSourceSet.name + ) + + val sourcesGenerationDir = File(mokoResourcesDir, "src") + val resourcesGenerationDir = File(mokoResourcesDir, "res") + + kotlinSourceSet.kotlin.srcDir(sourcesGenerationDir) + kotlinSourceSet.resources.srcDir(resourcesGenerationDir) + } + + private fun setupAndroidSourceSet( + project: Project, + androidSourceSet: AndroidSourceSet, + ) { + val mokoResourcesDir = getGeneratedResourcesDir( + project = project, + sourceSetName = androidSourceSet.name + ) + + val sourcesGenerationDir = File(mokoResourcesDir, "src") + val resourcesGenerationDir = File(mokoResourcesDir, "res") + val assetsGenerationDir = File(mokoResourcesDir, AssetsGenerator.ASSETS_DIR_NAME) + + androidSourceSet.assets.srcDir(assetsGenerationDir) + androidSourceSet.java.srcDir(sourcesGenerationDir) + androidSourceSet.resources.srcDir(resourcesGenerationDir) + } + + private fun getGeneratedResourcesDir( + project: Project, + sourceSetName: String, + ): File { + val generatedDir = File(project.buildDir, "generated/moko-resources") + return File(generatedDir, sourceSetName) + } + private fun createMokoResourcesSourceSet( project: Project, - kotlinSourceSet: KotlinSourceSet + kotlinSourceSet: KotlinSourceSet, ): SourceDirectorySet { val sources = File(project.projectDir, "src") val resourceSourceSetDir = File(sources, kotlinSourceSet.name) @@ -185,15 +278,25 @@ open class MultiplatformResourcesPlugin : Plugin { private fun registerGenerateTask( kotlinSourceSet: KotlinSourceSet, project: Project, - resourcesSourceDirectory: SourceDirectorySet + resourcesSourceDirectory: SourceDirectorySet, + mrExtension: MultiplatformResourcesPluginExtension, ): TaskProvider { val generateTaskName: String = "generateMR" + kotlinSourceSet.name val taskProvider: TaskProvider = project.tasks.register( generateTaskName, GenerateMultiplatformResourcesTask::class.java - ) { + ) { generateTask -> val files: Set = resourcesSourceDirectory.srcDirs - it.ownResources.setFrom(files) + generateTask.ownResources.setFrom(files) + + generateTask.iosBaseLocalizationRegion.set(mrExtension.iosBaseLocalizationRegion) + generateTask.resourcesClassName.set(mrExtension.resourcesClassName) + generateTask.resourcesPackageName.set(mrExtension.resourcesPackage) + generateTask.resourcesVisibility.set(mrExtension.resourcesVisibility) + + generateTask.outputDirectory.set( + File(File(project.buildDir, "generated/moko-resources"), kotlinSourceSet.name) + ) } kotlinSourceSet.extras[mokoResourcesGenTaskKey()] = taskProvider @@ -203,7 +306,7 @@ open class MultiplatformResourcesPlugin : Plugin { private fun configureLowerDependencies( kotlinSourceSet: KotlinSourceSet, - genTask: TaskProvider + genTask: TaskProvider, ) { kotlinSourceSet.dependsOnObservable.forAll { dependsSourceSet -> val resourcesDir: SourceDirectorySet = requireNotNull( @@ -260,7 +363,7 @@ open class MultiplatformResourcesPlugin : Plugin { private fun configureKotlinTargetGenerator( target: KotlinTarget, - settings: MRGenerator.Settings + settings: MRGenerator.Settings, ) { val features = listOf( StringsGenerator.Feature(settings), @@ -297,7 +400,7 @@ open class MultiplatformResourcesPlugin : Plugin { private fun configureNativeTargetGenerator( target: KotlinNativeTarget, settings: MRGenerator.Settings, - features: List> + features: List>, ) { when (target.konanTarget) { KonanTarget.IOS_ARM32, @@ -317,7 +420,8 @@ open class MultiplatformResourcesPlugin : Plugin { KonanTarget.WATCHOS_DEVICE_ARM64, KonanTarget.WATCHOS_SIMULATOR_ARM64, KonanTarget.WATCHOS_X64, - KonanTarget.WATCHOS_X86 -> configureAppleTargetGenerator( + KonanTarget.WATCHOS_X86, + -> configureAppleTargetGenerator( target = target, settings = settings, features = features diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AndroidTarget.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AndroidTarget.kt index bf798d1fa..8fa984604 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AndroidTarget.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AndroidTarget.kt @@ -58,14 +58,9 @@ private fun setupAndroidGenerator( settings: MRGenerator.Settings, features: List>, ) { - val androidExtension: BaseExtension = project.extensions.getByType(BaseExtension::class) - val androidMainSourceSet: AndroidSourceSet = androidExtension.mainSourceSet - setAssetsDirsRefresh(project) AndroidMRGenerator( - generatedDir = settings.generatedDir, - sourceSet = project.provider { createSourceSet(androidMainSourceSet) }, settings = settings, generators = features.map { it.createAndroidGenerator() }, ).apply(project) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt index 87d318233..ae3f640b3 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt @@ -34,8 +34,6 @@ internal fun configureAppleTargetGenerator( .getByName(KotlinCompilation.MAIN_COMPILATION_NAME) AppleMRGenerator( - generatedDir = settings.generatedDir, - sourceSet = target.project.provider { createSourceSet(mainCompilation.defaultSourceSet) }, settings = settings, generators = features.map { it.createIosGenerator() }, compilation = mainCompilation, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/CommonTarget.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/CommonTarget.kt index 02302ec19..34a8eca3b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/CommonTarget.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/CommonTarget.kt @@ -9,23 +9,18 @@ import dev.icerock.gradle.generator.ResourceGeneratorFeature import dev.icerock.gradle.generator.common.CommonMRGenerator import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import org.gradle.kotlin.dsl.withType -import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation import org.jetbrains.kotlin.gradle.plugin.KotlinTarget internal fun configureCommonTargetGenerator( target: KotlinTarget, settings: MRGenerator.Settings, - features: List> + features: List>, ) { val generationTask: GenerateMultiplatformResourcesTask = CommonMRGenerator( - generatedDir = settings.generatedDir, - sourceSet = target.project.provider { - val compilation = target.compilations.getByName(KotlinCompilation.MAIN_COMPILATION_NAME) - createSourceSet(compilation.defaultSourceSet) - }, + project = target.project, settings = settings, generators = features.map { it.createCommonGenerator() } - ).apply(project = target.project) + ).apply(project = target.project,) target.project.tasks .withType() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JsTarget.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JsTarget.kt index 63e081b83..8d4bf1503 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JsTarget.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JsTarget.kt @@ -27,8 +27,6 @@ internal fun configureJsTargetGenerator( // TODO rollback ifDepends // compilation.defaultSourceSet.ifDependsOn(commonSourceSet) { JsMRGenerator( - generatedDir = settings.generatedDir, - sourceSet = project.provider { createSourceSet(compilation.defaultSourceSet) }, settings = settings, generators = features.map { it.createJsGenerator() }, compilation = compilation, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JvmTarget.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JvmTarget.kt index 8cada5fba..ddce584dc 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JvmTarget.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JvmTarget.kt @@ -15,12 +15,7 @@ internal fun configureJvmTargetGenerator( settings: MRGenerator.Settings, features: List> ) { - val mainCompilation: KotlinCompilation<*> = target.compilations - .getByName(KotlinCompilation.MAIN_COMPILATION_NAME) - JvmMRGenerator( - generatedDir = settings.generatedDir, - sourceSet = target.project.provider { createSourceSet(mainCompilation.defaultSourceSet) }, settings = settings, generators = features.map { it.createJvmGenerator() } ).apply(project = target.project) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/Utils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/Utils.kt index edaa39fb3..1f71cd533 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/Utils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/Utils.kt @@ -16,15 +16,15 @@ internal fun createSourceSet(kotlinSourceSet: KotlinSourceSet): MRGenerator.Sour override val name: String get() = kotlinSourceSet.name - override fun addSourceDir(directory: Provider) { + override fun addSourceDir(directory: File) { kotlinSourceSet.kotlin.srcDir(directory) } - override fun addResourcesDir(directory: Provider) { + override fun addResourcesDir(directory: File) { kotlinSourceSet.resources.srcDir(directory) } - override fun addAssetsDir(directory: Provider) { + override fun addAssetsDir(directory: File) { // nothing } } @@ -37,7 +37,7 @@ internal fun createSourceSet( override val name: String get() = "android${androidSourceSet.name.capitalize()}" - override fun addSourceDir(directory: Provider) { + override fun addSourceDir(directory: File) { androidSourceSet.java.srcDirs(directory) // targets.configureEach { target -> // target.compilations.configureEach { compilation -> @@ -53,11 +53,11 @@ internal fun createSourceSet( // } } - override fun addResourcesDir(directory: Provider) { + override fun addResourcesDir(directory: File) { androidSourceSet.res.srcDir(directory) } - override fun addAssetsDir(directory: Provider) { + override fun addAssetsDir(directory: File) { androidSourceSet.assets.srcDir(directory) } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt index 9f3e273ce..f10c17edb 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt @@ -178,24 +178,29 @@ abstract class AssetsGenerator( ) : ResourceGeneratorFeature { override fun createCommonGenerator(): AssetsGenerator = CommonAssetsGenerator( - fileTree = settings.ownResourcesFileTree + ownResourcesFileTree = settings.ownResourcesFileTree, + upperResourcesFileTree = settings.upperResourcesFileTree, ) override fun createIosGenerator(): AssetsGenerator = AppleAssetsGenerator( - fileTree = settings.ownResourcesFileTree + ownResourcesFileTree = settings.ownResourcesFileTree, + lowerResourcesFileTree = settings.lowerResourcesFileTree, ) override fun createAndroidGenerator(): AssetsGenerator = AndroidAssetsGenerator( - fileTree = settings.ownResourcesFileTree + ownResourcesFileTree = settings.ownResourcesFileTree, + lowerResourcesFileTree = settings.lowerResourcesFileTree, ) override fun createJvmGenerator(): AssetsGenerator = JvmAssetsGenerator( - fileTree = settings.ownResourcesFileTree, + ownResourcesFileTree = settings.ownResourcesFileTree, + lowerResourcesFileTree = settings.lowerResourcesFileTree, settings = settings ) override fun createJsGenerator(): AssetsGenerator = JsAssetsGenerator( - fileTree = settings.ownResourcesFileTree + ownResourcesFileTree = settings.ownResourcesFileTree, + lowerResourcesFileTree = settings.lowerResourcesFileTree, ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt index fc9069893..a3b4b7d16 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt @@ -21,7 +21,7 @@ import java.io.File import javax.xml.parsers.DocumentBuilderFactory abstract class ColorsGenerator( - private val colorsFileTree: FileTree + private val colorsFileTree: FileTree, ) : MRGenerator.Generator { override val inputFiles: Iterable get() = colorsFileTree.files @@ -38,7 +38,7 @@ abstract class ColorsGenerator( override fun generate( assetsGenerationDir: File, resourcesGenerationDir: File, - objectBuilder: TypeSpec.Builder + objectBuilder: TypeSpec.Builder, ): TypeSpec { objectBuilder.addModifiers(*getClassModifiers()) extendObjectBodyAtStart(objectBuilder) @@ -68,7 +68,7 @@ abstract class ColorsGenerator( protected open fun generateResources( resourcesGenerationDir: File, - colors: List + colors: List, ) = Unit private fun parseColors(): List { @@ -135,20 +135,35 @@ abstract class ColorsGenerator( } class Feature( - private val settings: MRGenerator.Settings + private val settings: MRGenerator.Settings, ) : ResourceGeneratorFeature { private val fileTree: FileTree = settings.ownResourcesFileTree .matching { it.include("**/colors*.xml") } - override fun createCommonGenerator() = CommonColorsGenerator(fileTree) - - override fun createIosGenerator() = AppleColorsGenerator(fileTree) - - override fun createAndroidGenerator() = AndroidColorsGenerator(fileTree) - - override fun createJsGenerator(): ColorsGenerator = JsColorsGenerator(fileTree) - - override fun createJvmGenerator() = JvmColorsGenerator(fileTree, settings) + override fun createCommonGenerator() = CommonColorsGenerator( + ownColorsFileTree = settings.ownResourcesFileTree, + upperColorsFileTree = settings.upperResourcesFileTree + ) + + override fun createIosGenerator() = AppleColorsGenerator( + ownColorsFileTree = settings.ownResourcesFileTree, + lowerColorsFileTree = settings.lowerResourcesFileTree + ) + + override fun createAndroidGenerator() = AndroidColorsGenerator( + ownColorsFileTree = settings.ownResourcesFileTree, + lowerColorsFileTree = settings.lowerResourcesFileTree + ) + + override fun createJsGenerator(): ColorsGenerator = JsColorsGenerator( + ownColorsFileTree = settings.ownResourcesFileTree, + lowerColorsFileTree = settings.lowerResourcesFileTree + ) + + override fun createJvmGenerator() = JvmColorsGenerator( + ownColorsFileTree = settings.ownResourcesFileTree, + lowerColorsFileTree = settings.lowerResourcesFileTree, settings + ) } protected fun replaceColorAlpha(color: String?): String? { @@ -182,7 +197,7 @@ data class ColorNode( val name: String, val lightColor: String?, // as rgba val darkColor: String?, // as rgba - val singleColor: String? // as rgba + val singleColor: String?, // as rgba ) { fun isThemed(): Boolean = lightColor != null && darkColor != null } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt index dda52a5ad..08031f2a0 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt @@ -96,28 +96,33 @@ abstract class FilesGenerator( private val settings: MRGenerator.Settings ) : ResourceGeneratorFeature { - private val fileTree: FileTree = settings.ownResourcesFileTree - .matching { it.include("files/**") } +// private val fileTree: FileTree = settings.ownResourcesFileTree +// .matching { it.include("files/**") } override fun createCommonGenerator(): FilesGenerator = CommonFilesGenerator( - inputFileTree = fileTree + ownInputFileTree = settings.ownResourcesFileTree, + upperInputFileTree = settings.upperResourcesFileTree ) override fun createIosGenerator(): FilesGenerator = AppleFilesGenerator( - inputFileTree = fileTree + ownInputFileTree = settings.ownResourcesFileTree, + lowerInputFileTree = settings.lowerResourcesFileTree ) override fun createAndroidGenerator(): FilesGenerator = AndroidFilesGenerator( - inputFileTree = fileTree, + ownInputFileTree = settings.ownResourcesFileTree, + lowerInputFileTree = settings.lowerResourcesFileTree, androidRClassPackage = settings.androidRClassPackage, ) override fun createJsGenerator(): FilesGenerator = JsFilesGenerator( - inputFileTree = fileTree + ownInputFileTree = settings.ownResourcesFileTree, + lowerInputFileTree = settings.lowerResourcesFileTree ) override fun createJvmGenerator(): FilesGenerator = JvmFilesGenerator( - inputFileTree = fileTree, + ownInputFileTree = settings.ownResourcesFileTree, + lowerInputFileTree = settings.lowerResourcesFileTree, settings = settings ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt index e9f0aae0f..62caa8f4d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt @@ -125,29 +125,34 @@ abstract class FontsGenerator( class Feature( private val settings: MRGenerator.Settings ) : ResourceGeneratorFeature { - private val stringsFileTree: FileTree = settings.ownResourcesFileTree - .matching { it.include("fonts/**.ttf", "fonts/**.otf") } +// private val stringsFileTree: FileTree = settings.ownResourcesFileTree +// .matching { it.include("fonts/**.ttf", "fonts/**.otf") } override fun createCommonGenerator(): FontsGenerator = CommonFontsGenerator( - inputFileTree = stringsFileTree + ownInputFileTree = settings.ownResourcesFileTree, + upperInputFileTree = settings.upperResourcesFileTree ) override fun createIosGenerator(): FontsGenerator = AppleFontsGenerator( - inputFileTree = stringsFileTree + ownInputFileTree = settings.ownResourcesFileTree, + lowerInputFileTree = settings.lowerResourcesFileTree ) override fun createAndroidGenerator(): FontsGenerator = AndroidFontsGenerator( - inputFileTree = stringsFileTree, + ownInputFileTree = settings.ownResourcesFileTree, + lowerInputFileTree = settings.lowerResourcesFileTree, androidRClassPackage = settings.androidRClassPackage ) override fun createJsGenerator(): FontsGenerator = JsFontsGenerator( - inputFileTree = stringsFileTree, + ownInputFileTree = settings.ownResourcesFileTree, + lowerInputFileTree = settings.lowerResourcesFileTree, mrClassPackage = settings.packageName ) override fun createJvmGenerator(): FontsGenerator = JvmFontsGenerator( - inputFileTree = stringsFileTree, + ownInputFileTree = settings.ownResourcesFileTree, + lowerInputFileTree = settings.lowerResourcesFileTree, settings = settings ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt index 8170eb15f..814aa73ec 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt @@ -23,7 +23,9 @@ abstract class ImagesGenerator( private val inputFileTree: FileTree ) : MRGenerator.Generator { - override val inputFiles: Iterable get() = inputFileTree.files + override val inputFiles: Iterable + get() = inputFileTree.files + override val resourceClassName = ClassName("dev.icerock.moko.resources", "ImageResource") override val mrObjectName: String = "images" @@ -107,25 +109,30 @@ abstract class ImagesGenerator( } override fun createCommonGenerator(): ImagesGenerator = CommonImagesGenerator( - inputFileTree = fileTree + ownInputFileTree = settings.ownResourcesFileTree, + upperInputFileTree = settings.upperResourcesFileTree ) override fun createIosGenerator(): ImagesGenerator = AppleImagesGenerator( - inputFileTree = fileTree + ownInputFileTree = settings.ownResourcesFileTree, + lowerInputFileTree = settings.lowerResourcesFileTree, ) override fun createAndroidGenerator(): ImagesGenerator = AndroidImagesGenerator( - inputFileTree = fileTree, + ownInputFileTree = settings.ownResourcesFileTree, + lowerInputFileTree = settings.lowerResourcesFileTree, androidRClassPackageProvider = settings.androidRClassPackage, logger = logger ) override fun createJsGenerator(): ImagesGenerator = JsImagesGenerator( - inputFileTree = fileTree + ownInputFileTree = settings.ownResourcesFileTree, + lowerInputFileTree = settings.lowerResourcesFileTree, ) override fun createJvmGenerator(): ImagesGenerator = JvmImagesGenerator( - inputFileTree = fileTree, + ownInputFileTree = settings.ownResourcesFileTree, + lowerInputFileTree = settings.lowerResourcesFileTree, settings = settings ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt index 9cda08ce3..f562f7db1 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt @@ -7,25 +7,24 @@ package dev.icerock.gradle.generator import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.FileSpec import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.MRVisibility -import dev.icerock.gradle.toModifier +import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask +import org.gradle.api.Project import org.gradle.api.file.Directory import org.gradle.api.file.FileTree -import org.gradle.api.provider.Provider import java.io.File abstract class MRGenerator( - protected val sourceSet: Provider, protected val settings: Settings, - internal val generators: List + internal val generators: List, ) { internal val outputDir: File = settings.generatedDir.asFile protected open val sourcesGenerationDir: File = File(outputDir, "src") protected open val resourcesGenerationDir: File = File(outputDir, "res") protected open val assetsGenerationDir: File = File(outputDir, AssetsGenerator.ASSETS_DIR_NAME) + internal fun generate() { sourcesGenerationDir.deleteRecursively() resourcesGenerationDir.deleteRecursively() @@ -33,93 +32,49 @@ abstract class MRGenerator( beforeMRGeneration() - val visibilityModifier: KModifier = settings.visibility.toModifier() - - @Suppress("SpreadOperator") - val mrClassSpec = TypeSpec.objectBuilder(settings.className) - .addModifiers(*getMRClassModifiers()) - .addModifiers(visibilityModifier) + val file = generateFileSpec() + file?.writeTo(sourcesGenerationDir) - generators.forEach { generator -> - val builder = TypeSpec.objectBuilder(generator.mrObjectName) - .addModifiers(visibilityModifier) - - val fileResourceInterfaceClassName = ClassName( - packageName = "dev.icerock.moko.resources", - "ResourceContainer" - ) - builder.addSuperinterface( - fileResourceInterfaceClassName.parameterizedBy(generator.resourceClassName) - ) + afterMRGeneration() + } - mrClassSpec.addType( - generator.generate( - assetsGenerationDir, - resourcesGenerationDir, - builder - ) + abstract fun generateFileSpec(): FileSpec? + + fun apply(project: Project): GenerateMultiplatformResourcesTask { + //TODO add sourceSetName + val name: String = project.displayName + + val genTask = project.tasks.create( + "generateMR$name", + GenerateMultiplatformResourcesTask::class.java + ) { +// it.generator = this + it.inputs.property("mokoSettingsPackageName", settings.packageName) + it.inputs.property("mokoSettingsClassName", settings.className) + it.inputs.property("mokoSettingsVisibility", settings.visibility) + it.inputs.property( + "mokoSettingsIosLocalizationRegion", + settings.iosLocalizationRegion ) } - processMRClass(mrClassSpec) - - val mrClass = mrClassSpec.build() + apply(generationTask = genTask, project = project) - val fileSpec = FileSpec.builder( - packageName = settings.packageName, - fileName = settings.className - ).addType(mrClass) - - generators - .flatMap { it.getImports() } - .plus(getImports()) - .forEach { fileSpec.addImport(it.packageName, it.simpleName) } - - val file = fileSpec.build() - file.writeTo(sourcesGenerationDir) - - afterMRGeneration() + return genTask } -// fun apply(project: Project): GenerateMultiplatformResourcesTask { -// setupGenerationDirs() -// -// val name: String = sourceSet.get().name -// val genTask = project.tasks.create( -// "generateMR$name", -// GenerateMultiplatformResourcesTask::class.java -// ) { -//// it.generator = this -// it.inputs.property("mokoSettingsPackageName", settings.packageName) -// it.inputs.property("mokoSettingsClassName", settings.className) -// it.inputs.property("mokoSettingsVisibility", settings.visibility) -// } -// -// apply(generationTask = genTask, project = project) -// -// return genTask -// } - protected open fun beforeMRGeneration() = Unit protected open fun afterMRGeneration() = Unit protected abstract fun getMRClassModifiers(): Array -// protected abstract fun apply( -// generationTask: GenerateMultiplatformResourcesTask, -// project: Project -// ) + protected abstract fun apply( + generationTask: GenerateMultiplatformResourcesTask, + project: Project, + ) protected open fun processMRClass(mrClass: TypeSpec.Builder) {} protected open fun getImports(): List = emptyList() -// private fun setupGenerationDirs() { -// with(sourceSet.get()) { -// addSourceDir(sourcesGenerationDir) -// addResourcesDir(resourcesGenerationDir) -// addAssetsDir(assetsGenerationDir) -// } -// } - interface Generator : ObjectBodyExtendable { val mrObjectName: String val resourceClassName: ClassName @@ -128,7 +83,7 @@ abstract class MRGenerator( fun generate( assetsGenerationDir: File, resourcesGenerationDir: File, - objectBuilder: TypeSpec.Builder + objectBuilder: TypeSpec.Builder, ): TypeSpec fun getImports(): List @@ -137,9 +92,9 @@ abstract class MRGenerator( interface SourceSet { val name: String - fun addSourceDir(directory: Provider) - fun addResourcesDir(directory: Provider) - fun addAssetsDir(directory: Provider) + fun addSourceDir(directory: File) + fun addResourcesDir(directory: File) + fun addAssetsDir(directory: File) } data class Settings( @@ -152,6 +107,6 @@ abstract class MRGenerator( val ownResourcesFileTree: FileTree, val lowerResourcesFileTree: FileTree, val upperResourcesFileTree: FileTree, - val androidRClassPackage: String + val androidRClassPackage: String, ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt index f1f40ae7a..9e53cbfa0 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt @@ -99,30 +99,35 @@ abstract class PluralsGenerator( .matching { it.include("**/plurals*.xml") } override fun createCommonGenerator(): PluralsGenerator = CommonPluralsGenerator( - pluralsFileTree = fileTree, + ownPluralsFileTree = settings.ownResourcesFileTree, + upperPluralsFileTree = settings.upperResourcesFileTree, strictLineBreaks = settings.isStrictLineBreaks ) override fun createIosGenerator(): PluralsGenerator = ApplePluralsGenerator( - pluralsFileTree = fileTree, + ownPluralsFileTree = settings.ownResourcesFileTree, + lowerPluralsFileTree = settings.lowerResourcesFileTree, strictLineBreaks = settings.isStrictLineBreaks, baseLocalizationRegion = settings.iosLocalizationRegion ) override fun createAndroidGenerator(): PluralsGenerator = AndroidPluralsGenerator( - pluralsFileTree = fileTree, + ownPluralsFileTree = settings.ownResourcesFileTree, + lowerPluralsFileTree = settings.lowerResourcesFileTree, strictLineBreaks = settings.isStrictLineBreaks, androidRClassPackage = settings.androidRClassPackage, ) override fun createJvmGenerator(): PluralsGenerator = JvmPluralsGenerator( - pluralsFileTree = fileTree, + ownPluralsFileTree = settings.ownResourcesFileTree, + lowerPluralsFileTree = settings.lowerResourcesFileTree, strictLineBreaks = settings.isStrictLineBreaks, settings = settings ) override fun createJsGenerator(): PluralsGenerator = JsPluralsGenerator( - pluralsFileTree = fileTree, + ownPluralsFileTree = settings.ownResourcesFileTree, + lowerPluralsFileTree = settings.lowerResourcesFileTree, mrClassPackage = settings.packageName, strictLineBreaks = settings.isStrictLineBreaks ) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt index 5b5b46481..71dbcbbc1 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt @@ -18,16 +18,22 @@ import javax.xml.parsers.DocumentBuilderFactory typealias KeyType = String abstract class StringsGenerator( - private val stringsFileTree: FileTree, - private val strictLineBreaks: Boolean + private val lowerStringsFileTree: FileTree, + private val ownStringsFileTree: FileTree, + private val upperStringsFileTree: FileTree? = null, + private val strictLineBreaks: Boolean, ) : BaseGenerator() { - override val inputFiles: Iterable get() = stringsFileTree.files + override val inputFiles: Iterable + get() = ownStringsFileTree.matching { + it.include(STRINGS_MASK) + }.files + override val resourceClassName = ClassName("dev.icerock.moko.resources", "StringResource") override val mrObjectName: String = "strings" override fun loadLanguageMap(): Map> { - return stringsFileTree.map { file -> + return inputFiles.map { file -> val language: LanguageType = LanguageType.fromFileName(file.parentFile.name) val strings: Map = loadLanguageStrings(file) language to strings @@ -63,6 +69,7 @@ abstract class StringsGenerator( .filter { it.key == it.value } .keys .toList() + if (incorrectKeys.isNotEmpty()) { throw EqualStringKeysException(incorrectKeys) } @@ -73,38 +80,45 @@ abstract class StringsGenerator( override fun getImports(): List = emptyList() class Feature( - private val settings: MRGenerator.Settings + private val settings: MRGenerator.Settings, ) : ResourceGeneratorFeature { - private val fileTree: FileTree = settings.ownResourcesFileTree - .matching { it.include("**/strings*.xml") } - override fun createCommonGenerator(): StringsGenerator = CommonStringsGenerator( - stringsFileTree = fileTree, + lowerStringsFileTree = settings.lowerResourcesFileTree, + ownStringsFileTree = settings.ownResourcesFileTree, + upperStringsFileTree = settings.upperResourcesFileTree, strictLineBreaks = settings.isStrictLineBreaks ) override fun createIosGenerator(): StringsGenerator = AppleStringsGenerator( - stringsFileTree = fileTree, + ownStringsFileTree = settings.ownResourcesFileTree, + lowerStringsFileTree = settings.lowerResourcesFileTree, strictLineBreaks = settings.isStrictLineBreaks, baseLocalizationRegion = settings.iosLocalizationRegion ) override fun createAndroidGenerator(): StringsGenerator = AndroidStringsGenerator( - stringsFileTree = fileTree, + ownStringsFileTree = settings.ownResourcesFileTree, + lowerStringsFileTree = settings.lowerResourcesFileTree, strictLineBreaks = settings.isStrictLineBreaks, androidRClassPackage = settings.androidRClassPackage ) override fun createJsGenerator(): StringsGenerator = JsStringsGenerator( - stringsFileTree = fileTree, + ownStringsFileTree = settings.ownResourcesFileTree, + lowerStringsFileTree = settings.lowerResourcesFileTree, mrClassPackage = settings.packageName, strictLineBreaks = settings.isStrictLineBreaks ) override fun createJvmGenerator(): StringsGenerator = JvmStringsGenerator( - stringsFileTree = fileTree, + ownStringsFileTree = settings.ownResourcesFileTree, + lowerStringsFileTree = settings.lowerResourcesFileTree, strictLineBreaks = settings.isStrictLineBreaks, settings = settings ) } + + companion object { + const val STRINGS_MASK = "**/strings*.xml" + } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt new file mode 100644 index 000000000..4d710d349 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt @@ -0,0 +1,69 @@ +package dev.icerock.gradle.generator + +import com.squareup.kotlinpoet.FileSpec +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask +import dev.icerock.gradle.toModifier +import org.gradle.api.Project + +abstract class TargetMRGenerator( + settings: Settings, + generators: List, +) : MRGenerator( + settings = settings, + generators = generators +) { + override fun generateFileSpec(): FileSpec? { + val visibilityModifier: KModifier = settings.visibility.toModifier() + + @Suppress("SpreadOperator") + val mrClassSpec = TypeSpec.objectBuilder(settings.className) + .addModifiers(*getMRClassModifiers()) + .addModifiers(visibilityModifier) + + generators.forEach { generator -> + val builder = TypeSpec.objectBuilder(generator.mrObjectName) + .addModifiers(visibilityModifier) + +// val fileResourceInterfaceClassName = ClassName( +// packageName = "dev.icerock.moko.resources", +// "ResourceContainer" +// ) +// builder.addSuperinterface( +// fileResourceInterfaceClassName.parameterizedBy(generator.resourceClassName) +// ) + + mrClassSpec.addType( + generator.generate( + assetsGenerationDir, + resourcesGenerationDir, + builder + ) + ) + } + + processMRClass(mrClassSpec) + + val mrClass = mrClassSpec.build() + + val fileSpec = FileSpec.builder( + packageName = settings.packageName, + fileName = settings.className + ).addType(mrClass) + + generators + .flatMap { it.getImports() } + .plus(getImports()) + .forEach { fileSpec.addImport(it.packageName, it.simpleName) } + + return fileSpec.build() + } + + override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { + + } + + override fun getMRClassModifiers(): Array = arrayOf(KModifier.ACTUAL) + +} \ No newline at end of file diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidAssetsGenerator.kt index c45a2aef3..cd4607f28 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidAssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidAssetsGenerator.kt @@ -10,12 +10,12 @@ import dev.icerock.gradle.generator.AssetsGenerator import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable import org.gradle.api.file.FileTree -import org.gradle.api.file.SourceDirectorySet import java.io.File class AndroidAssetsGenerator( - fileTree: FileTree -) : AssetsGenerator(fileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { + ownResourcesFileTree: FileTree, + lowerResourcesFileTree: FileTree, +) : AssetsGenerator(ownResourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun generateResources( assetsGenerationDir: File, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt index 74ccad169..0f6e6a708 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt @@ -15,8 +15,9 @@ import org.gradle.api.file.FileTree import java.io.File class AndroidColorsGenerator( - colorsFileTree: FileTree -) : ColorsGenerator(colorsFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { + ownColorsFileTree: FileTree, + lowerColorsFileTree: FileTree, +) : ColorsGenerator(ownColorsFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getImports() = listOf( ClassName("dev.icerock.moko.graphics", "Color") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt index 876315eb4..c1d29f78a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt @@ -15,9 +15,10 @@ import java.io.File import java.util.Locale class AndroidFilesGenerator( - inputFileTree: FileTree, + ownInputFileTree: FileTree, + lowerInputFileTree: FileTree, private val androidRClassPackage: String, -) : FilesGenerator(inputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { +) : FilesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFontsGenerator.kt index 9c268ce1d..9a20fe16b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFontsGenerator.kt @@ -11,14 +11,14 @@ import dev.icerock.gradle.generator.FontsGenerator import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable import org.gradle.api.file.FileTree -import org.gradle.api.provider.Provider import java.io.File import java.util.Locale class AndroidFontsGenerator( - inputFileTree: FileTree, + ownInputFileTree: FileTree, + lowerInputFileTree: FileTree, private val androidRClassPackage: String, -) : FontsGenerator(inputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { +) : FontsGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt index d15864bee..2ecb6ff1c 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt @@ -14,7 +14,6 @@ import dev.icerock.gradle.generator.ObjectBodyExtendable import dev.icerock.gradle.utils.svg import org.gradle.api.file.FileTree import org.gradle.api.logging.Logger -import org.gradle.api.provider.Provider import java.io.File import java.io.FileOutputStream import java.io.IOException @@ -23,10 +22,11 @@ import java.nio.file.Path import kotlin.reflect.full.functions class AndroidImagesGenerator( - inputFileTree: FileTree, + ownInputFileTree: FileTree, + lowerInputFileTree: FileTree, private val androidRClassPackageProvider: String, private val logger: Logger -) : ImagesGenerator(inputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { +) : ImagesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt index d93679311..270a26f03 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt @@ -7,19 +7,15 @@ package dev.icerock.gradle.generator.android import com.android.build.gradle.tasks.GenerateResValues import com.android.build.gradle.tasks.MergeSourceSetFolders import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.MRGenerator +import dev.icerock.gradle.generator.TargetMRGenerator import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import org.gradle.api.Project -import org.gradle.api.provider.Provider import org.gradle.kotlin.dsl.withType -import java.io.File class AndroidMRGenerator( - sourceSet: Provider, settings: Settings, generators: List, -) : MRGenerator( - sourceSet = sourceSet, +) : TargetMRGenerator( settings = settings, generators = generators ) { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt index 5f4342324..92bbd05a2 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt @@ -15,14 +15,14 @@ import dev.icerock.gradle.generator.PluralMap import dev.icerock.gradle.generator.PluralsGenerator import org.apache.commons.lang3.StringEscapeUtils import org.gradle.api.file.FileTree -import org.gradle.api.provider.Provider import java.io.File class AndroidPluralsGenerator( - pluralsFileTree: FileTree, + ownPluralsFileTree: FileTree, + lowerPluralsFileTree: FileTree, strictLineBreaks: Boolean, private val androidRClassPackage: String, -) : PluralsGenerator(pluralsFileTree, strictLineBreaks), +) : PluralsGenerator(ownPluralsFileTree, strictLineBreaks), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt index 14cb8ab65..835ead60b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt @@ -14,19 +14,42 @@ import dev.icerock.gradle.generator.ObjectBodyExtendable import dev.icerock.gradle.generator.StringsGenerator import org.apache.commons.text.StringEscapeUtils import org.gradle.api.file.FileTree -import org.gradle.api.provider.Provider import java.io.File class AndroidStringsGenerator( - stringsFileTree: FileTree, + private val ownStringsFileTree: FileTree, + private val lowerStringsFileTree: FileTree, strictLineBreaks: Boolean, private val androidRClassPackage: String, -) : StringsGenerator(stringsFileTree, strictLineBreaks), - ObjectBodyExtendable by NOPObjectBodyExtendable() { +) : StringsGenerator( + lowerStringsFileTree = lowerStringsFileTree, + ownStringsFileTree = ownStringsFileTree, + strictLineBreaks = strictLineBreaks +), ObjectBodyExtendable by NOPObjectBodyExtendable() { - override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) + override fun getClassModifiers(): Array { + val ownIsEmpty = ownStringsFileTree.matching { + it.include(STRINGS_MASK) + }.isEmpty - override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) + val lowerIsEmpty = lowerStringsFileTree.matching { + it.include(STRINGS_MASK) + }.isEmpty + + return arrayOf(KModifier.ACTUAL) + } + + override fun getPropertyModifiers(): Array { + val ownIsEmpty = ownStringsFileTree.matching { + it.include(STRINGS_MASK) + }.isEmpty + + val lowerIsEmpty = lowerStringsFileTree.matching { + it.include(STRINGS_MASK) + }.isEmpty + + return arrayOf(KModifier.ACTUAL) + } override fun getPropertyInitializer(key: String) = CodeBlock.of("StringResource(R.string.%L)", processKey(key)) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleAssetsGenerator.kt index c16d0a0e7..2f42a225c 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleAssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleAssetsGenerator.kt @@ -9,12 +9,12 @@ import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.AssetsGenerator import dev.icerock.gradle.generator.ObjectBodyExtendable import org.gradle.api.file.FileTree -import org.gradle.api.file.SourceDirectorySet import java.io.File class AppleAssetsGenerator( - fileTree: FileTree -) : AssetsGenerator(fileTree), ObjectBodyExtendable by AppleGeneratorHelper() { + ownResourcesFileTree: FileTree, + lowerResourcesFileTree: FileTree, +) : AssetsGenerator(ownResourcesFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt index 2515c8a5e..c17e00449 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt @@ -21,8 +21,9 @@ import org.gradle.api.file.FileTree import java.io.File class AppleColorsGenerator( - colorsFileTree: FileTree -) : ColorsGenerator(colorsFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { + ownColorsFileTree: FileTree, + lowerColorsFileTree: FileTree, +) : ColorsGenerator(ownColorsFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { override fun getImports(): List { return listOf( ClassName("dev.icerock.moko.graphics", "Color") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFilesGenerator.kt index 269a1d603..e281c325c 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFilesGenerator.kt @@ -12,8 +12,9 @@ import org.gradle.api.file.FileTree import java.io.File class AppleFilesGenerator( - inputFileTree: FileTree -) : FilesGenerator(inputFileTree = inputFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { + ownInputFileTree: FileTree, + lowerInputFileTree: FileTree, +) : FilesGenerator(inputFileTree = ownInputFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -27,7 +28,7 @@ class AppleFilesGenerator( override fun generateResources( resourcesGenerationDir: File, - files: List + files: List, ) { val targetDir = File(resourcesGenerationDir, "files") targetDir.mkdirs() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFontsGenerator.kt index a267192e3..36935662e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFontsGenerator.kt @@ -12,8 +12,9 @@ import org.gradle.api.file.FileTree import java.io.File class AppleFontsGenerator( - inputFileTree: FileTree -) : FontsGenerator(inputFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { + ownInputFileTree: FileTree, + lowerInputFileTree: FileTree, +) : FontsGenerator(ownInputFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleImagesGenerator.kt index 9ff7ff1d1..d574a05c4 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleImagesGenerator.kt @@ -19,8 +19,9 @@ import org.gradle.api.file.FileTree import java.io.File class AppleImagesGenerator( - inputFileTree: FileTree -) : ImagesGenerator(inputFileTree = inputFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { + ownInputFileTree: FileTree, + lowerInputFileTree: FileTree, +) : ImagesGenerator(inputFileTree = ownInputFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt index 471209a8c..59bbfa583 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt @@ -11,7 +11,7 @@ import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.STRING import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.MultiplatformResourcesPluginExtension -import dev.icerock.gradle.generator.MRGenerator +import dev.icerock.gradle.generator.TargetMRGenerator import dev.icerock.gradle.generator.apple.action.CopyResourcesFromKLibsToExecutableAction import dev.icerock.gradle.generator.apple.action.CopyResourcesFromKLibsToFrameworkAction import dev.icerock.gradle.generator.apple.action.PackResourcesToKLibAction @@ -19,12 +19,10 @@ import dev.icerock.gradle.tasks.CopyFrameworkResourcesToAppEntryPointTask import dev.icerock.gradle.tasks.CopyFrameworkResourcesToAppTask import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.utils.calculateResourcesHash -import dev.icerock.gradle.utils.dependsOnProcessResources import org.gradle.api.Action import org.gradle.api.Project import org.gradle.api.Task import org.gradle.api.plugins.ExtensionAware -import org.gradle.api.provider.Provider import org.gradle.api.tasks.TaskProvider import org.gradle.kotlin.dsl.findByType import org.gradle.kotlin.dsl.getByType @@ -44,13 +42,11 @@ import kotlin.reflect.full.memberProperties @Suppress("TooManyFunctions") class AppleMRGenerator( - sourceSet: Provider, settings: Settings, generators: List, private val compilation: AbstractKotlinNativeCompilation, private val baseLocalizationRegion: String, -) : MRGenerator( - sourceSet = sourceSet, +) : TargetMRGenerator( settings = settings, generators = generators ) { @@ -118,11 +114,12 @@ class AppleMRGenerator( // .matching { it.name.contains(sourceSet.name, ignoreCase = true) } // .configureEach { it.dependsOn(generationTask) } - dependsOnProcessResources( - project = generationTask.project, - sourceSet = sourceSet, - task = generationTask, - ) + //TODO fix usage of sourceSet +// dependsOnProcessResources( +// project = generationTask.project, +// sourceSet = sourceSet, +// task = generationTask, +// ) } private fun setupFrameworkResources() { @@ -185,10 +182,10 @@ $linkTask produces static framework, Xcode should have Build Phase with copyFram kotlinNativeTarget.binaries .matching { it is TestExecutable && it.compilation.associateWith.contains(compilation) } - .configureEach { - val executable = it as TestExecutable - executable.linkTaskProvider.configure { - it.doLast(CopyResourcesFromKLibsToExecutableAction()) + .configureEach { binary -> + val executable = binary as TestExecutable + executable.linkTaskProvider.configure { link -> + link.doLast(CopyResourcesFromKLibsToExecutableAction()) } } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/ApplePluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/ApplePluralsGenerator.kt index 2b1de865d..42623e536 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/ApplePluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/ApplePluralsGenerator.kt @@ -15,10 +15,11 @@ import org.gradle.api.file.FileTree import java.io.File class ApplePluralsGenerator( - pluralsFileTree: FileTree, + ownPluralsFileTree: FileTree, + lowerPluralsFileTree: FileTree, strictLineBreaks: Boolean, private val baseLocalizationRegion: String -) : PluralsGenerator(pluralsFileTree, strictLineBreaks), +) : PluralsGenerator(ownPluralsFileTree, strictLineBreaks), ObjectBodyExtendable by AppleGeneratorHelper() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleStringsGenerator.kt index d8c39ccd6..e43ee7fe1 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleStringsGenerator.kt @@ -13,14 +13,18 @@ import dev.icerock.gradle.generator.StringsGenerator import dev.icerock.gradle.generator.apple.AppleMRGenerator.Companion.BUNDLE_PROPERTY_NAME import org.apache.commons.text.StringEscapeUtils import org.gradle.api.file.FileTree -import org.gradle.api.provider.Provider import java.io.File class AppleStringsGenerator( - stringsFileTree: FileTree, + ownStringsFileTree: FileTree, + lowerStringsFileTree: FileTree, strictLineBreaks: Boolean, private val baseLocalizationRegion: String -) : StringsGenerator(stringsFileTree, strictLineBreaks), +) : StringsGenerator( + lowerStringsFileTree = lowerStringsFileTree, + ownStringsFileTree = ownStringsFileTree, + strictLineBreaks = strictLineBreaks +), ObjectBodyExtendable by AppleGeneratorHelper() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonAssetsGenerator.kt index a89394d58..b8f449b57 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonAssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonAssetsGenerator.kt @@ -10,11 +10,11 @@ import dev.icerock.gradle.generator.AssetsGenerator import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable import org.gradle.api.file.FileTree -import org.gradle.api.file.SourceDirectorySet class CommonAssetsGenerator( - fileTree: FileTree -) : AssetsGenerator(fileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { + ownResourcesFileTree: FileTree, + upperResourcesFileTree: FileTree, +) : AssetsGenerator(ownResourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = emptyArray() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonColorsGenerator.kt index 79bd11eae..a8f2de5b8 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonColorsGenerator.kt @@ -13,8 +13,9 @@ import dev.icerock.gradle.generator.ObjectBodyExtendable import org.gradle.api.file.FileTree class CommonColorsGenerator( - colorsFileTree: FileTree -) : ColorsGenerator(colorsFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { + ownColorsFileTree: FileTree, + upperColorsFileTree: FileTree, +) : ColorsGenerator(ownColorsFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getImports(): List { return emptyList() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt index cd96666e7..35d0f9afd 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt @@ -12,8 +12,9 @@ import dev.icerock.gradle.generator.ObjectBodyExtendable import org.gradle.api.file.FileTree class CommonFilesGenerator( - inputFileTree: FileTree -) : FilesGenerator(inputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { + ownInputFileTree: FileTree, + upperInputFileTree: FileTree, +) : FilesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = emptyArray() override fun getPropertyModifiers(): Array = emptyArray() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFontsGenerator.kt index baf01b9ac..9b797eea2 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFontsGenerator.kt @@ -13,8 +13,9 @@ import org.gradle.api.file.FileTree import java.io.File class CommonFontsGenerator( - inputFileTree: FileTree -) : FontsGenerator(inputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { + ownInputFileTree: FileTree, + upperInputFileTree: FileTree, +) : FontsGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = emptyArray() override fun getPropertyModifiers(): Array = emptyArray() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonImagesGenerator.kt index 6fea2c40a..fa4c29418 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonImagesGenerator.kt @@ -12,8 +12,9 @@ import dev.icerock.gradle.generator.ObjectBodyExtendable import org.gradle.api.file.FileTree class CommonImagesGenerator( - inputFileTree: FileTree -) : ImagesGenerator(inputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { + ownInputFileTree: FileTree, + upperInputFileTree: FileTree, +) : ImagesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = emptyArray() override fun getPropertyModifiers(): Array = emptyArray() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index 45a97c5bd..47f78be84 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -4,24 +4,125 @@ package dev.icerock.gradle.generator.common +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.DelicateKotlinPoetApi +import com.squareup.kotlinpoet.FileSpec +import com.squareup.kotlinpoet.FileSpec.Builder import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.TypeName +import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask +import dev.icerock.gradle.toModifier +import dev.icerock.gradle.utils.targetName import org.gradle.api.Project -import org.gradle.api.provider.Provider +import org.gradle.api.file.FileCollection import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.dsl.KotlinCompile import java.io.File class CommonMRGenerator( - sourceSet: Provider, + project: Project, settings: Settings, - generators: List + generators: List, ) : MRGenerator( - sourceSet = sourceSet, settings = settings, generators = generators ) { + val logger = project.logger + + @OptIn(DelicateKotlinPoetApi::class) + override fun generateFileSpec(): FileSpec? { + val visibilityModifier: KModifier = settings.visibility.toModifier() + + @Suppress("SpreadOperator") + // generated MR class structure: + val mrClassSpec: TypeSpec.Builder = + TypeSpec.objectBuilder(settings.className) // default: object MR + .addModifiers(*getMRClassModifiers()) // expect/actual + .addModifiers(visibilityModifier) // public/internal + + val ownIsEmpty: Boolean = settings.ownResourcesFileTree.files.isEmpty() + + if (ownIsEmpty) return null + + val fileSpec: Builder = FileSpec.builder( + packageName = settings.packageName, + fileName = settings.className + ) + + val lowerIsEmpty = settings.lowerResourcesFileTree.files.isEmpty() + + if (lowerIsEmpty) { + // Check upper directories on files with resources + val upperDirectoryWithResources: FileCollection = settings.upperResourcesFileTree +// .filter { it.isDirectory } +// .filter { file: File -> +// file.listFiles()?.isNotEmpty() ?: false +// } + + val lowerResourcesInterfaceList = mutableListOf>() + if (!upperDirectoryWithResources.isEmpty) { + + // If upper directory has files of resources, need to generate + // expect interface for sourceSet + upperDirectoryWithResources.forEach { file: File -> + logger.warn("i file - $file") + + val sourceSetName: String = file.targetName + + logger.warn("i sourceSetName - $sourceSetName") + + val resourcesInterface: TypeSpec = TypeSpec.interfaceBuilder(sourceSetName) + .addModifiers(visibilityModifier) + .addModifiers(KModifier.EXPECT) + .build() + + lowerResourcesInterfaceList.add(Pair(resourcesInterface.superclass, resourcesInterface.initializerBlock)) + fileSpec.addType(resourcesInterface) + } + } + + // When lower resources is empty, should generate expect MR object + generators.forEach { generator -> + + val builder: TypeSpec.Builder = TypeSpec + .objectBuilder(generator.mrObjectName) // resource name: example strings + .addModifiers(visibilityModifier) // public/internal + + lowerResourcesInterfaceList.forEach { + builder.addSuperinterface(it.first, it.second) + } + + mrClassSpec.addType( + generator.generate( + assetsGenerationDir, + resourcesGenerationDir, + builder + ) + ) + } + + processMRClass(mrClassSpec) + + val mrClass = mrClassSpec.build() + fileSpec.addType(mrClass) + + } else { + // If lower resources has files, when on lower level has expect object and + // need to generate actual interface with fields + + //TODO actual + // Добавить генерацию actual интерфейсов в которых будут поля + } + + generators + .flatMap { it.getImports() } + .plus(getImports()) + .forEach { fileSpec.addImport(it.packageName, it.simpleName) } + + return fileSpec.build() + } override fun getMRClassModifiers(): Array = arrayOf(KModifier.EXPECT) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonPluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonPluralsGenerator.kt index 3cb61abb9..1369259d9 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonPluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonPluralsGenerator.kt @@ -11,9 +11,10 @@ import dev.icerock.gradle.generator.PluralsGenerator import org.gradle.api.file.FileTree class CommonPluralsGenerator( - pluralsFileTree: FileTree, + ownPluralsFileTree: FileTree, + upperPluralsFileTree: FileTree, strictLineBreaks: Boolean, -) : PluralsGenerator(pluralsFileTree, strictLineBreaks), +) : PluralsGenerator(ownPluralsFileTree, strictLineBreaks), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getPropertyInitializer( key: String diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonStringsGenerator.kt index 542ec84af..70707e8a4 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonStringsGenerator.kt @@ -11,8 +11,15 @@ import dev.icerock.gradle.generator.StringsGenerator import org.gradle.api.file.FileTree class CommonStringsGenerator( - stringsFileTree: FileTree, + lowerStringsFileTree: FileTree, + ownStringsFileTree: FileTree, + upperStringsFileTree: FileTree, strictLineBreaks: Boolean -) : StringsGenerator(stringsFileTree, strictLineBreaks), ObjectBodyExtendable by NOPObjectBodyExtendable() { +) : StringsGenerator( + lowerStringsFileTree = lowerStringsFileTree, + ownStringsFileTree = ownStringsFileTree, + upperStringsFileTree = upperStringsFileTree, + strictLineBreaks = strictLineBreaks +), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getPropertyInitializer(key: String): CodeBlock? = null } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsAssetsGenerator.kt index 5755e9115..0154cc9b2 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsAssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsAssetsGenerator.kt @@ -14,12 +14,12 @@ import dev.icerock.gradle.generator.AssetsGenerator import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable import org.gradle.api.file.FileTree -import org.gradle.api.file.SourceDirectorySet import java.io.File class JsAssetsGenerator( - fileTree: FileTree -) : AssetsGenerator(fileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { + ownResourcesFileTree: FileTree, + lowerResourcesFileTree: FileTree, +) : AssetsGenerator(ownResourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsColorsGenerator.kt index 8aacfccb8..a80356bca 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsColorsGenerator.kt @@ -18,8 +18,9 @@ import dev.icerock.gradle.generator.jsJvmCommon.createColorResourceInitializer import org.gradle.api.file.FileTree class JsColorsGenerator( - colorsFileTree: FileTree -) : ColorsGenerator(colorsFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { + ownColorsFileTree: FileTree, + lowerColorsFileTree: FileTree, +) : ColorsGenerator(ownColorsFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFilesGenerator.kt index 1c0cbfd09..95e169c8d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFilesGenerator.kt @@ -17,8 +17,9 @@ import org.gradle.api.file.FileTree import java.io.File class JsFilesGenerator( - inputFileTree: FileTree -) : FilesGenerator(inputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { + ownInputFileTree: FileTree, + lowerInputFileTree: FileTree, +) : FilesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFontsGenerator.kt index 646b2fb61..920fd829b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFontsGenerator.kt @@ -20,9 +20,10 @@ import org.gradle.kotlin.dsl.provideDelegate import java.io.File class JsFontsGenerator( - inputFileTree: FileTree, + ownInputFileTree: FileTree, + lowerInputFileTree: FileTree, mrClassPackage: String, -) : FontsGenerator(inputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { +) : FontsGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { private val flattenPackage: String = mrClassPackage.flatName private val cssDeclarationsFileName: String = "$flattenPackage-generated-declarations.css" diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsImagesGenerator.kt index 15348af4b..939904161 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsImagesGenerator.kt @@ -18,8 +18,9 @@ import org.gradle.api.file.FileTree import java.io.File class JsImagesGenerator( - inputFileTree: FileTree -) : ImagesGenerator(inputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { + ownInputFileTree: FileTree, + lowerInputFileTree: FileTree, +) : ImagesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt index 754288820..c2ac9fb26 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt @@ -9,16 +9,14 @@ import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.STRING import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.MRGenerator +import dev.icerock.gradle.generator.TargetMRGenerator import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.utils.calculateResourcesHash -import dev.icerock.gradle.utils.dependsOnProcessResources import dev.icerock.gradle.utils.flatName import dev.icerock.gradle.utils.klibs import org.gradle.api.Action import org.gradle.api.Project import org.gradle.api.Task -import org.gradle.api.provider.Provider import org.gradle.jvm.tasks.Jar import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilation @@ -27,12 +25,10 @@ import org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl import java.io.File class JsMRGenerator( - sourceSet: Provider, settings: Settings, generators: List, private val compilation: KotlinJsIrCompilation, -) : MRGenerator( - sourceSet = sourceSet, +) : TargetMRGenerator( settings = settings, generators = generators ) { @@ -93,11 +89,11 @@ class JsMRGenerator( it.dependsOn(generationTask) } - dependsOnProcessResources( - project = project, - sourceSet = sourceSet, - task = generationTask, - ) +// dependsOnProcessResources( +// project = project, +// sourceSet = sourceSet, +// task = generationTask, +// ) } private fun setupKLibResources(generationTask: Task) { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsPluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsPluralsGenerator.kt index 5d5d59807..5ceab3b79 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsPluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsPluralsGenerator.kt @@ -20,14 +20,14 @@ import dev.icerock.gradle.utils.flatName import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.put import org.gradle.api.file.FileTree -import org.gradle.api.provider.Provider import java.io.File class JsPluralsGenerator( - pluralsFileTree: FileTree, + ownPluralsFileTree: FileTree, + lowerPluralsFileTree: FileTree, mrClassPackage: String, strictLineBreaks: Boolean -) : PluralsGenerator(pluralsFileTree, strictLineBreaks), +) : PluralsGenerator(ownPluralsFileTree, strictLineBreaks), ObjectBodyExtendable by NOPObjectBodyExtendable() { private val flattenClassPackage = mrClassPackage.flatName diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt index 7b366386c..d0cef2715 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt @@ -21,14 +21,18 @@ import dev.icerock.gradle.utils.flatName import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.put import org.gradle.api.file.FileTree -import org.gradle.api.provider.Provider import java.io.File class JsStringsGenerator( - stringsFileTree: FileTree, + ownStringsFileTree: FileTree, + lowerStringsFileTree: FileTree, mrClassPackage: String, strictLineBreaks: Boolean -) : StringsGenerator(stringsFileTree, strictLineBreaks), +) : StringsGenerator( + lowerStringsFileTree = lowerStringsFileTree, + ownStringsFileTree = ownStringsFileTree, + strictLineBreaks = strictLineBreaks +), ObjectBodyExtendable by NOPObjectBodyExtendable() { private val flattenClassPackage = mrClassPackage.flatName diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmAssetsGenerator.kt index d393a3e9c..0e71f0a64 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmAssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmAssetsGenerator.kt @@ -10,13 +10,13 @@ import dev.icerock.gradle.generator.AssetsGenerator import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.ObjectBodyExtendable import org.gradle.api.file.FileTree -import org.gradle.api.file.SourceDirectorySet import java.io.File class JvmAssetsGenerator( - fileTree: FileTree, + ownResourcesFileTree: FileTree, + lowerResourcesFileTree: FileTree, settings: MRGenerator.Settings -) : AssetsGenerator(fileTree), +) : AssetsGenerator(ownResourcesFileTree), ObjectBodyExtendable by ClassLoaderExtender(settings.className) { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmColorsGenerator.kt index 9d3aff834..d691344de 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmColorsGenerator.kt @@ -15,9 +15,10 @@ import dev.icerock.gradle.generator.jsJvmCommon.createColorResourceInitializer import org.gradle.api.file.FileTree class JvmColorsGenerator( - colorsFileTree: FileTree, + ownColorsFileTree: FileTree, + lowerColorsFileTree: FileTree, settings: MRGenerator.Settings -) : ColorsGenerator(colorsFileTree), +) : ColorsGenerator(ownColorsFileTree), ObjectBodyExtendable by ClassLoaderExtender(settings.className) { override fun getImports() = listOf( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFilesGenerator.kt index 98b31dce0..7cd2752c1 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFilesGenerator.kt @@ -13,9 +13,10 @@ import org.gradle.api.file.FileTree import java.io.File class JvmFilesGenerator( - inputFileTree: FileTree, + ownInputFileTree: FileTree, + lowerInputFileTree: FileTree, settings: MRGenerator.Settings -) : FilesGenerator(inputFileTree), +) : FilesGenerator(ownInputFileTree), ObjectBodyExtendable by ClassLoaderExtender(settings.className) { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFontsGenerator.kt index fa158e17b..86bb2866e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFontsGenerator.kt @@ -13,9 +13,10 @@ import org.gradle.api.file.FileTree import java.io.File class JvmFontsGenerator( - inputFileTree: FileTree, + ownInputFileTree: FileTree, + lowerInputFileTree: FileTree, settings: MRGenerator.Settings -) : FontsGenerator(inputFileTree), +) : FontsGenerator(ownInputFileTree), ObjectBodyExtendable by ClassLoaderExtender(settings.className) { override fun getClassModifiers() = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmImagesGenerator.kt index 5e2739879..11515e1b1 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmImagesGenerator.kt @@ -14,9 +14,10 @@ import org.gradle.api.file.FileTree import java.io.File class JvmImagesGenerator( - inputFileTree: FileTree, + ownInputFileTree: FileTree, + lowerInputFileTree: FileTree, settings: MRGenerator.Settings -) : ImagesGenerator(inputFileTree), +) : ImagesGenerator(ownInputFileTree), ObjectBodyExtendable by ClassLoaderExtender(settings.className) { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt index e46100515..4f2799b52 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt @@ -9,23 +9,19 @@ import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.STRING import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.MRGenerator +import dev.icerock.gradle.generator.TargetMRGenerator import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask -import dev.icerock.gradle.utils.dependsOnProcessResources import dev.icerock.gradle.utils.flatName import org.gradle.api.Project -import org.gradle.api.provider.Provider import org.gradle.jvm.tasks.Jar import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import java.io.File class JvmMRGenerator( - sourceSet: Provider, settings: Settings, generators: List -) : MRGenerator( - sourceSet = sourceSet, +) : TargetMRGenerator( settings = settings, generators = generators ) { @@ -74,11 +70,11 @@ class JvmMRGenerator( project.tasks.withType().configureEach { it.dependsOn(generationTask) } - dependsOnProcessResources( - project = project, - sourceSet = sourceSet, - task = generationTask, - ) +// dependsOnProcessResources( +// project = project, +// sourceSet = sourceSet, +// task = generationTask, +// ) } companion object { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmPluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmPluralsGenerator.kt index f87d001a2..bd0a314e6 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmPluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmPluralsGenerator.kt @@ -14,14 +14,14 @@ import dev.icerock.gradle.generator.PluralMap import dev.icerock.gradle.generator.PluralsGenerator import dev.icerock.gradle.utils.remove import org.gradle.api.file.FileTree -import org.gradle.api.provider.Provider import java.io.File class JvmPluralsGenerator( - pluralsFileTree: FileTree, + ownPluralsFileTree: FileTree, + lowerPluralsFileTree: FileTree, strictLineBreaks: Boolean, settings: MRGenerator.Settings -) : PluralsGenerator(pluralsFileTree, strictLineBreaks), +) : PluralsGenerator(ownPluralsFileTree, strictLineBreaks), ObjectBodyExtendable by ClassLoaderExtender(settings.className) { private val flattenClassPackage: String = settings.packageName.remove('.') diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt index 15c42b037..c90b4e3e0 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt @@ -12,16 +12,19 @@ import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.ObjectBodyExtendable import dev.icerock.gradle.generator.StringsGenerator import dev.icerock.gradle.utils.flatName -import dev.icerock.gradle.utils.remove import org.gradle.api.file.FileTree -import org.gradle.api.provider.Provider import java.io.File class JvmStringsGenerator( - stringsFileTree: FileTree, + ownStringsFileTree: FileTree, + lowerStringsFileTree: FileTree, strictLineBreaks: Boolean, - settings: MRGenerator.Settings -) : StringsGenerator(stringsFileTree, strictLineBreaks), + settings: MRGenerator.Settings, +) : StringsGenerator( + lowerStringsFileTree = lowerStringsFileTree, + ownStringsFileTree = ownStringsFileTree, + strictLineBreaks = strictLineBreaks +), ObjectBodyExtendable by ClassLoaderExtender(settings.className) { private val flattenClassPackage = settings.packageName.flatName @@ -40,7 +43,7 @@ class JvmStringsGenerator( override fun generateResources( resourcesGenerationDir: File, language: LanguageType, - strings: Map + strings: Map, ) { val fileDirName = "${flattenClassPackage}_${JvmMRGenerator.STRINGS_BUNDLE_NAME}${language.jvmResourcesSuffix}" 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 408da25d5..e62344e65 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 @@ -6,17 +6,9 @@ package dev.icerock.gradle.tasks import dev.icerock.gradle.MRVisibility import dev.icerock.gradle.configuration.getAndroidRClassPackage -import dev.icerock.gradle.generator.AssetsGenerator -import dev.icerock.gradle.generator.ColorsGenerator -import dev.icerock.gradle.generator.FilesGenerator -import dev.icerock.gradle.generator.FontsGenerator -import dev.icerock.gradle.generator.ImagesGenerator import dev.icerock.gradle.generator.MRGenerator -import dev.icerock.gradle.generator.MRGenerator.Settings -import dev.icerock.gradle.generator.PluralsGenerator import dev.icerock.gradle.generator.ResourceGeneratorFeature import dev.icerock.gradle.generator.StringsGenerator -import dev.icerock.gradle.generator.StringsGenerator.Feature import dev.icerock.gradle.generator.android.AndroidMRGenerator import dev.icerock.gradle.generator.apple.AppleMRGenerator import dev.icerock.gradle.generator.common.CommonMRGenerator @@ -26,14 +18,13 @@ import dev.icerock.gradle.utils.isStrictLineBreaks import org.gradle.api.DefaultTask import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.DirectoryProperty -import org.gradle.api.file.RegularFileProperty import org.gradle.api.provider.Property import org.gradle.api.tasks.CacheableTask import org.gradle.api.tasks.Classpath import org.gradle.api.tasks.Input import org.gradle.api.tasks.InputFiles +import org.gradle.api.tasks.Optional import org.gradle.api.tasks.OutputDirectory -import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.TaskAction import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import org.jetbrains.kotlin.konan.target.KonanTarget @@ -53,9 +44,11 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { @get:Classpath abstract val upperResources: ConfigurableFileCollection + @get:Optional @get:Input abstract val platformType: Property + @get:Optional @get:Input abstract val konanTarget: Property @@ -71,8 +64,9 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { @get:Input abstract val resourcesVisibility: Property - @get:OutputFile - abstract val generationReport: RegularFileProperty + //TODO Realise +// @get:OutputFile +// abstract val generationReport: RegularFileProperty @get:OutputDirectory abstract val outputDirectory: DirectoryProperty @@ -87,23 +81,24 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { logger.warn("i $name have lowerResources ${lowerResources.from}") logger.warn("i $name have upperResources ${upperResources.from}") - val settings: Settings = createGeneratorSettings() + val settings: MRGenerator.Settings = createGeneratorSettings() val features: List> = createGeneratorFeatures(settings) - val generator: MRGenerator = resolveGenerator(settings, generators = features) - logger.warn("i generator type: ${generator::class.java.simpleName}") -// generator.generate() + val mrGenerator: MRGenerator = resolveGenerator(settings, features) + + logger.warn("i ${platformType.get()} generator type: ${mrGenerator::class.java.simpleName}") + mrGenerator.generate() } private fun resolveGenerator( settings: MRGenerator.Settings, - generators: List> + generators: List>, ): MRGenerator { return when (KotlinPlatformType.valueOf(platformType.get())) { KotlinPlatformType.common -> createCommonGenerator(settings, generators) - KotlinPlatformType.jvm -> createJvmGenerator() - KotlinPlatformType.js -> createJsGenerator() - KotlinPlatformType.androidJvm -> createAndroidJvmGenerator() - KotlinPlatformType.native -> createNativeGenerator() + KotlinPlatformType.jvm -> createJvmGenerator(settings, generators) + KotlinPlatformType.js -> createJsGenerator(settings, generators) + KotlinPlatformType.androidJvm -> createAndroidJvmGenerator(settings, generators) + KotlinPlatformType.native -> createNativeGenerator(settings, generators) KotlinPlatformType.wasm -> error("moko-resources not support wasm target now") } } @@ -112,10 +107,10 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { return MRGenerator.Settings( packageName = resourcesPackageName.get(), className = resourcesClassName.get(), + generatedDir = outputDirectory.get(), ownResourcesFileTree = ownResources.asFileTree, lowerResourcesFileTree = lowerResources.asFileTree, upperResourcesFileTree = upperResources.asFileTree, - generatedDir = outputDirectory.get(), isStrictLineBreaks = project.isStrictLineBreaks, visibility = resourcesVisibility.get(), androidRClassPackage = project.getAndroidRClassPackage().get(), @@ -124,44 +119,72 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { } private fun createGeneratorFeatures( - settings: MRGenerator.Settings + settings: MRGenerator.Settings, ): List> { return listOf( StringsGenerator.Feature(settings), - PluralsGenerator.Feature(settings), - ImagesGenerator.Feature(settings, logger), - FontsGenerator.Feature(settings), - FilesGenerator.Feature(settings), - ColorsGenerator.Feature(settings), - AssetsGenerator.Feature(settings) +// PluralsGenerator.Feature(settings), +// ImagesGenerator.Feature(settings, logger), +// FontsGenerator.Feature(settings), +// FilesGenerator.Feature(settings), +// ColorsGenerator.Feature(settings), +// AssetsGenerator.Feature(settings) ) } private fun createCommonGenerator( settings: MRGenerator.Settings, - generators: List> + generators: List>, ): CommonMRGenerator { return CommonMRGenerator( - sourceSet =, - settings = createGeneratorSettings(), - generators = generators - + project = project, + settings = settings, + generators = generators.map { + it.createCommonGenerator() + } ) } - private fun createAndroidJvmGenerator(): AndroidMRGenerator { - TODO() + private fun createAndroidJvmGenerator( + settings: MRGenerator.Settings, + generators: List>, + ): AndroidMRGenerator { + return AndroidMRGenerator( + settings = settings, + generators = generators.map { + it.createAndroidGenerator() + } + ) } - private fun createJvmGenerator(): JvmMRGenerator { - TODO() + private fun createJvmGenerator( + settings: MRGenerator.Settings, + generators: List>, + ): JvmMRGenerator { + return JvmMRGenerator( + settings = settings, generators = generators.map { + it.createJvmGenerator() + } + ) } - private fun createJsGenerator(): JsMRGenerator { + private fun createJsGenerator( + settings: MRGenerator.Settings, + generators: List>, + ): JsMRGenerator { TODO() +// return JsMRGenerator( +// settings = settings, +// generators = generators.map { +// it.createJsGenerator() +// } +// ) } - private fun createNativeGenerator(): MRGenerator { + private fun createNativeGenerator( + settings: MRGenerator.Settings, + generators: List>, + ): MRGenerator { val konanTargetName: String = konanTarget.get() val konanTarget: KonanTarget = KonanTarget.predefinedTargets[konanTargetName] ?: error("can't find $konanTargetName in KonanTarget") @@ -185,13 +208,16 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { KonanTarget.WATCHOS_SIMULATOR_ARM64, KonanTarget.WATCHOS_X64, KonanTarget.WATCHOS_X86, - -> createAppleGenerator() + -> createAppleGenerator(settings, generators) else -> error("$konanTarget is not supported by moko-resources now!") } } - private fun createAppleGenerator(): AppleMRGenerator { + private fun createAppleGenerator( + settings: MRGenerator.Settings, + generators: List>, + ): AppleMRGenerator { TODO() } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/FileExt.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/FileExt.kt index acc11d7df..0af32a742 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/FileExt.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/FileExt.kt @@ -14,3 +14,6 @@ internal val File.scale: String get() = internal val File.nameWithoutScale: String get() = nameWithoutExtension.withoutScale + +internal val File.targetName: String + get() = parentFile.parentFile.parentFile.name \ No newline at end of file From ccb32d126d91e9e47a3af54e22674e012fae0478 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Tue, 21 Nov 2023 16:36:47 +0700 Subject: [PATCH 046/352] #535 add generation expect interface and implementation for MR --- .../generator/common/CommonMRGenerator.kt | 132 +++++++++++++----- .../GenerateMultiplatformResourcesTask.kt | 4 +- .../moko-resources/base/strings.xml | 4 + .../iosMain/moko-resources/base/strings.xml | 4 + 4 files changed, 108 insertions(+), 36 deletions(-) create mode 100644 samples/compose-resources-gallery/shared/src/androidMain/moko-resources/base/strings.xml create mode 100644 samples/compose-resources-gallery/shared/src/iosMain/moko-resources/base/strings.xml diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index 47f78be84..7bff34350 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -4,17 +4,20 @@ package dev.icerock.gradle.generator.common -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.DelicateKotlinPoetApi +import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.FileSpec import com.squareup.kotlinpoet.FileSpec.Builder import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.TypeName import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.MRGenerator +import dev.icerock.gradle.generator.common.GeneratedObject.GeneratedFileModifier +import dev.icerock.gradle.generator.common.GeneratedObject.GeneratedFileModifier.Companion.toGeneratedModifier +import dev.icerock.gradle.generator.common.GeneratedObject.GeneratedObjectType import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.toModifier +import dev.icerock.gradle.utils.capitalize import dev.icerock.gradle.utils.targetName +import org.gradle.api.GradleException import org.gradle.api.Project import org.gradle.api.file.FileCollection import org.gradle.kotlin.dsl.withType @@ -31,9 +34,11 @@ class CommonMRGenerator( ) { val logger = project.logger - @OptIn(DelicateKotlinPoetApi::class) override fun generateFileSpec(): FileSpec? { val visibilityModifier: KModifier = settings.visibility.toModifier() + val generatedFiles = mutableListOf() + + if (settings.ownResourcesFileTree.files.isEmpty()) return null @Suppress("SpreadOperator") // generated MR class structure: @@ -42,56 +47,74 @@ class CommonMRGenerator( .addModifiers(*getMRClassModifiers()) // expect/actual .addModifiers(visibilityModifier) // public/internal - val ownIsEmpty: Boolean = settings.ownResourcesFileTree.files.isEmpty() - - if (ownIsEmpty) return null + generatedFiles.add( + GeneratedObject( + type = GeneratedObjectType.OBJECT, + name = settings.className, + modifier = KModifier.EXPECT.toGeneratedModifier() + ) + ) val fileSpec: Builder = FileSpec.builder( packageName = settings.packageName, fileName = settings.className ) - val lowerIsEmpty = settings.lowerResourcesFileTree.files.isEmpty() + val lowerResourcesIsEmpty = settings.lowerResourcesFileTree.files.isEmpty() + + if (lowerResourcesIsEmpty) { + // When lower resources is empty, should generate expect MR object + generators.forEach { generator -> + + val builder: TypeSpec.Builder = TypeSpec + .objectBuilder(generator.mrObjectName) // resource name: example strings + .addModifiers(visibilityModifier) // public/internal - if (lowerIsEmpty) { - // Check upper directories on files with resources - val upperDirectoryWithResources: FileCollection = settings.upperResourcesFileTree + // Check upper directories on files with resources + //TODO: Спискок ресурсов содержит только файлы, без "пустых" директорий + val upperDirectoryWithResources: FileCollection = settings.upperResourcesFileTree // .filter { it.isDirectory } // .filter { file: File -> // file.listFiles()?.isNotEmpty() ?: false // } - val lowerResourcesInterfaceList = mutableListOf>() - if (!upperDirectoryWithResources.isEmpty) { - - // If upper directory has files of resources, need to generate - // expect interface for sourceSet - upperDirectoryWithResources.forEach { file: File -> - logger.warn("i file - $file") + val lowerResourcesInterfacesList = mutableListOf() - val sourceSetName: String = file.targetName + if (!upperDirectoryWithResources.isEmpty) { - logger.warn("i sourceSetName - $sourceSetName") + // If upper directory has files of resources, need to generate + // expect interface for sourceSet + upperDirectoryWithResources.forEach { file: File -> + val sourceSetName: String = file.targetName - val resourcesInterface: TypeSpec = TypeSpec.interfaceBuilder(sourceSetName) - .addModifiers(visibilityModifier) - .addModifiers(KModifier.EXPECT) - .build() + val interfaceName = + sourceSetName.capitalize() + generator.mrObjectName.capitalize() + val resourcesInterface: TypeSpec = + TypeSpec.interfaceBuilder(interfaceName) + .addModifiers(visibilityModifier) + .addModifiers(KModifier.EXPECT) + .build() - lowerResourcesInterfaceList.add(Pair(resourcesInterface.superclass, resourcesInterface.initializerBlock)) - fileSpec.addType(resourcesInterface) + lowerResourcesInterfacesList.add("${resourcesInterface.name}") + fileSpec.addType(resourcesInterface) + } } - } - // When lower resources is empty, should generate expect MR object - generators.forEach { generator -> - - val builder: TypeSpec.Builder = TypeSpec - .objectBuilder(generator.mrObjectName) // resource name: example strings - .addModifiers(visibilityModifier) // public/internal + lowerResourcesInterfacesList.forEach { interfaceName -> + builder.addSuperinterface( + ClassName( + packageName = "dev.icerock.moko.resources", + interfaceName + ) + ) - lowerResourcesInterfaceList.forEach { - builder.addSuperinterface(it.first, it.second) + generatedFiles.add( + GeneratedObject( + type = GeneratedObjectType.INTERFACE, + name = interfaceName, + modifier = GeneratedFileModifier.EXPECT + ) + ) } mrClassSpec.addType( @@ -105,6 +128,12 @@ class CommonMRGenerator( processMRClass(mrClassSpec) + generatedFiles.forEach { + logger.warn( + it.objectSpec + ) + } + val mrClass = mrClassSpec.build() fileSpec.addType(mrClass) @@ -114,6 +143,10 @@ class CommonMRGenerator( //TODO actual // Добавить генерацию actual интерфейсов в которых будут поля + + val builder: TypeSpec.Builder = TypeSpec + .objectBuilder(generator.mrObjectName) // resource name: example strings + .addModifiers(visibilityModifier) // public/internal } generators @@ -145,3 +178,32 @@ class CommonMRGenerator( } } } + +data class GeneratedObject( + val type: GeneratedObjectType, + val name: String, + val modifier: GeneratedFileModifier, +) { + val objectSpec: String + get() = "${modifier.name.lowercase()} ${type.name.lowercase()} $name" + + enum class GeneratedObjectType { + OBJECT, + INTERFACE + } + + enum class GeneratedFileModifier { + EXPECT, + ACTUAL; + + companion object { + fun KModifier.toGeneratedModifier(): GeneratedFileModifier { + return when (this) { + KModifier.EXPECT -> EXPECT + KModifier.ACTUAL -> ACTUAL + else -> throw GradleException("Invalid object modifier") + } + } + } + } +} 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 e62344e65..7803323fd 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 @@ -7,6 +7,7 @@ package dev.icerock.gradle.tasks import dev.icerock.gradle.MRVisibility import dev.icerock.gradle.configuration.getAndroidRClassPackage import dev.icerock.gradle.generator.MRGenerator +import dev.icerock.gradle.generator.PluralsGenerator import dev.icerock.gradle.generator.ResourceGeneratorFeature import dev.icerock.gradle.generator.StringsGenerator import dev.icerock.gradle.generator.android.AndroidMRGenerator @@ -162,7 +163,8 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { generators: List>, ): JvmMRGenerator { return JvmMRGenerator( - settings = settings, generators = generators.map { + settings = settings, + generators = generators.map { it.createJvmGenerator() } ) diff --git a/samples/compose-resources-gallery/shared/src/androidMain/moko-resources/base/strings.xml b/samples/compose-resources-gallery/shared/src/androidMain/moko-resources/base/strings.xml new file mode 100644 index 000000000..301021b76 --- /dev/null +++ b/samples/compose-resources-gallery/shared/src/androidMain/moko-resources/base/strings.xml @@ -0,0 +1,4 @@ + + + Hello moko-resources Android World + diff --git a/samples/compose-resources-gallery/shared/src/iosMain/moko-resources/base/strings.xml b/samples/compose-resources-gallery/shared/src/iosMain/moko-resources/base/strings.xml new file mode 100644 index 000000000..e289acab0 --- /dev/null +++ b/samples/compose-resources-gallery/shared/src/iosMain/moko-resources/base/strings.xml @@ -0,0 +1,4 @@ + + + Hello moko-resources iOS World + From f1637f4f19ee7959014522416aea1c41461303a7 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Wed, 22 Nov 2023 01:05:00 +0700 Subject: [PATCH 047/352] =?UTF-8?q?=E2=84=96535=20decided=20expect=20logic?= =?UTF-8?q?=20in=20private=20function,=20inverted=20logic=20for=20test=20g?= =?UTF-8?q?eneration=20of=20actual=20interfaces=20in=20commonMain?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../generator/common/CommonMRGenerator.kt | 232 +++++++++++------- .../moko-resources/base/strings.xml | 3 +- 2 files changed, 142 insertions(+), 93 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index 7bff34350..5d27dcdbf 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -10,8 +10,8 @@ import com.squareup.kotlinpoet.FileSpec.Builder import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.MRGenerator -import dev.icerock.gradle.generator.common.GeneratedObject.GeneratedFileModifier -import dev.icerock.gradle.generator.common.GeneratedObject.GeneratedFileModifier.Companion.toGeneratedModifier +import dev.icerock.gradle.generator.common.GeneratedObject.GeneratedObjectModifier +import dev.icerock.gradle.generator.common.GeneratedObject.GeneratedObjectModifier.Companion.asGeneratedModifier import dev.icerock.gradle.generator.common.GeneratedObject.GeneratedObjectType import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.toModifier @@ -35,25 +35,10 @@ class CommonMRGenerator( val logger = project.logger override fun generateFileSpec(): FileSpec? { - val visibilityModifier: KModifier = settings.visibility.toModifier() - val generatedFiles = mutableListOf() - if (settings.ownResourcesFileTree.files.isEmpty()) return null - @Suppress("SpreadOperator") - // generated MR class structure: - val mrClassSpec: TypeSpec.Builder = - TypeSpec.objectBuilder(settings.className) // default: object MR - .addModifiers(*getMRClassModifiers()) // expect/actual - .addModifiers(visibilityModifier) // public/internal - - generatedFiles.add( - GeneratedObject( - type = GeneratedObjectType.OBJECT, - name = settings.className, - modifier = KModifier.EXPECT.toGeneratedModifier() - ) - ) + val visibilityModifier: KModifier = settings.visibility.toModifier() + val generatedObjectsList = mutableListOf() val fileSpec: Builder = FileSpec.builder( packageName = settings.packageName, @@ -62,99 +47,162 @@ class CommonMRGenerator( val lowerResourcesIsEmpty = settings.lowerResourcesFileTree.files.isEmpty() - if (lowerResourcesIsEmpty) { - // When lower resources is empty, should generate expect MR object - generators.forEach { generator -> + if (!lowerResourcesIsEmpty) { + generateExpectMRObjectFileSpec( + visibilityModifier = visibilityModifier, + generatedObjectsList = generatedObjectsList, + fileSpec = fileSpec + ) + } else { + // If lower resources has files, when on lower level has expect object and + // need to generate actual interface with fields - val builder: TypeSpec.Builder = TypeSpec - .objectBuilder(generator.mrObjectName) // resource name: example strings - .addModifiers(visibilityModifier) // public/internal - - // Check upper directories on files with resources - //TODO: Спискок ресурсов содержит только файлы, без "пустых" директорий - val upperDirectoryWithResources: FileCollection = settings.upperResourcesFileTree -// .filter { it.isDirectory } -// .filter { file: File -> -// file.listFiles()?.isNotEmpty() ?: false -// } - - val lowerResourcesInterfacesList = mutableListOf() - - if (!upperDirectoryWithResources.isEmpty) { - - // If upper directory has files of resources, need to generate - // expect interface for sourceSet - upperDirectoryWithResources.forEach { file: File -> - val sourceSetName: String = file.targetName - - val interfaceName = - sourceSetName.capitalize() + generator.mrObjectName.capitalize() - val resourcesInterface: TypeSpec = - TypeSpec.interfaceBuilder(interfaceName) - .addModifiers(visibilityModifier) - .addModifiers(KModifier.EXPECT) - .build() - - lowerResourcesInterfacesList.add("${resourcesInterface.name}") - fileSpec.addType(resourcesInterface) - } - } + //TODO actual + // Добавить генерацию actual интерфейсов в которых будут поля - lowerResourcesInterfacesList.forEach { interfaceName -> - builder.addSuperinterface( - ClassName( - packageName = "dev.icerock.moko.resources", - interfaceName - ) - ) + // generated MR class structure: +// val mrClassSpec: TypeSpec.Builder = TypeSpec.classBuilder(settings.className) // default: object MR + + val ownDirectoryWithResources: FileCollection = settings.ownResourcesFileTree + + ownDirectoryWithResources.forEach { + logger.warn("ownDirectoryWithResources: ${it.absoluteFile}") + } + + generators.forEach { generator -> + ownDirectoryWithResources.forEach { file: File -> + val sourceSetName: String = file.targetName + + val interfaceName = + sourceSetName.capitalize() + generator.mrObjectName.capitalize() + val resourcesInterfaceBuilder: TypeSpec.Builder = + TypeSpec.interfaceBuilder("${interfaceName}${generator.resourceClassName.simpleName}") + .addModifiers(visibilityModifier) + .addModifiers(KModifier.ACTUAL) - generatedFiles.add( + generatedObjectsList.add( GeneratedObject( type = GeneratedObjectType.INTERFACE, name = interfaceName, - modifier = GeneratedFileModifier.EXPECT + modifier = GeneratedObjectModifier.ACTUAL ) ) - } - mrClassSpec.addType( - generator.generate( - assetsGenerationDir, - resourcesGenerationDir, - builder + resourcesInterfaceBuilder.addType( + generator.generate( + assetsGenerationDir, + resourcesGenerationDir, + resourcesInterfaceBuilder + ) ) - ) + processMRClass(resourcesInterfaceBuilder) + + val mrClass: TypeSpec = resourcesInterfaceBuilder.build() + fileSpec.addType(mrClass) + } } - processMRClass(mrClassSpec) +// processMRClass(mrClassSpec) +// +// val mrClass: TypeSpec = mrClassSpec.build() +// fileSpec.addType(mrClass) + } - generatedFiles.forEach { - logger.warn( - it.objectSpec - ) - } + generators + .flatMap { it.getImports() } + .plus(getImports()) + .forEach { fileSpec.addImport(it.packageName, it.simpleName) } - val mrClass = mrClassSpec.build() - fileSpec.addType(mrClass) + return fileSpec.build() + } - } else { - // If lower resources has files, when on lower level has expect object and - // need to generate actual interface with fields + private fun generateExpectMRObjectFileSpec( + visibilityModifier: KModifier, + generatedObjectsList: MutableList, + fileSpec: Builder, + ) { + // generated MR class structure: + val mrClassSpec: TypeSpec.Builder = + TypeSpec.objectBuilder(settings.className) // default: object MR + .addModifiers(KModifier.EXPECT) // expect/actual + .addModifiers(visibilityModifier) // public/internal - //TODO actual - // Добавить генерацию actual интерфейсов в которых будут поля + generatedObjectsList.add( + GeneratedObject( + type = GeneratedObjectType.OBJECT, + name = settings.className, + modifier = KModifier.EXPECT.asGeneratedModifier() + ) + ) + + // When lower resources is empty, should generate expect MR object + generators.forEach { generator -> val builder: TypeSpec.Builder = TypeSpec .objectBuilder(generator.mrObjectName) // resource name: example strings .addModifiers(visibilityModifier) // public/internal + + // Check upper directories on files with resources + //TODO: Спискок ресурсов содержит только файлы, без "пустых" директорий + val upperDirectoryWithResources: FileCollection = settings.upperResourcesFileTree + // .filter { it.isDirectory } + // .filter { file: File -> + // file.listFiles()?.isNotEmpty() ?: false + // } + + val generatedInterfaces: List = if (!upperDirectoryWithResources.isEmpty) { + val expectInterfacesList = mutableListOf() + + // If upper directory has files of resources, need to generate + // expect interface for sourceSet + upperDirectoryWithResources.forEach { file: File -> + val sourceSetName: String = file.targetName + + val interfaceName = + sourceSetName.capitalize() + generator.mrObjectName.capitalize() + val resourcesInterface: TypeSpec = + TypeSpec.interfaceBuilder(interfaceName) + .addModifiers(visibilityModifier) + .addModifiers(KModifier.EXPECT) + .build() + + expectInterfacesList.add("${resourcesInterface.name}") + fileSpec.addType(resourcesInterface) + } + + expectInterfacesList + } else emptyList() + + generatedInterfaces.forEach { interfaceName -> + builder.addSuperinterface( + ClassName( + packageName = "dev.icerock.moko.resources", + interfaceName + ) + ) + + generatedObjectsList.add( + GeneratedObject( + type = GeneratedObjectType.INTERFACE, + name = interfaceName, + modifier = GeneratedObjectModifier.EXPECT + ) + ) + } + + mrClassSpec.addType( + generator.generate( + assetsGenerationDir, + resourcesGenerationDir, + builder + ) + ) } - generators - .flatMap { it.getImports() } - .plus(getImports()) - .forEach { fileSpec.addImport(it.packageName, it.simpleName) } + processMRClass(mrClassSpec) - return fileSpec.build() + val mrClass: TypeSpec = mrClassSpec.build() + fileSpec.addType(mrClass) } override fun getMRClassModifiers(): Array = arrayOf(KModifier.EXPECT) @@ -182,7 +230,7 @@ class CommonMRGenerator( data class GeneratedObject( val type: GeneratedObjectType, val name: String, - val modifier: GeneratedFileModifier, + val modifier: GeneratedObjectModifier, ) { val objectSpec: String get() = "${modifier.name.lowercase()} ${type.name.lowercase()} $name" @@ -192,12 +240,12 @@ data class GeneratedObject( INTERFACE } - enum class GeneratedFileModifier { + enum class GeneratedObjectModifier { EXPECT, ACTUAL; companion object { - fun KModifier.toGeneratedModifier(): GeneratedFileModifier { + fun KModifier.asGeneratedModifier(): GeneratedObjectModifier { return when (this) { KModifier.EXPECT -> EXPECT KModifier.ACTUAL -> ACTUAL diff --git a/samples/compose-resources-gallery/shared/src/androidMain/moko-resources/base/strings.xml b/samples/compose-resources-gallery/shared/src/androidMain/moko-resources/base/strings.xml index 301021b76..46167e256 100644 --- a/samples/compose-resources-gallery/shared/src/androidMain/moko-resources/base/strings.xml +++ b/samples/compose-resources-gallery/shared/src/androidMain/moko-resources/base/strings.xml @@ -1,4 +1,5 @@ - Hello moko-resources Android World + Android, Hello World + Hello moko-resources Android World From 2d650332aeaa931579dfa1117380da97dcd94237 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Thu, 23 Nov 2023 10:49:11 +0700 Subject: [PATCH 048/352] #535 add generation of actual interfaces on commonMRgenerator level --- .../generator/common/CommonMRGenerator.kt | 151 +++++++++--------- 1 file changed, 79 insertions(+), 72 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index 5d27dcdbf..c8c44e827 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -8,8 +8,10 @@ import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.FileSpec import com.squareup.kotlinpoet.FileSpec.Builder import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.KModifier.ACTUAL import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.MRGenerator +import dev.icerock.gradle.generator.MRGenerator.Generator import dev.icerock.gradle.generator.common.GeneratedObject.GeneratedObjectModifier import dev.icerock.gradle.generator.common.GeneratedObject.GeneratedObjectModifier.Companion.asGeneratedModifier import dev.icerock.gradle.generator.common.GeneratedObject.GeneratedObjectType @@ -34,6 +36,27 @@ class CommonMRGenerator( ) { val logger = project.logger + override fun getMRClassModifiers(): Array = arrayOf(KModifier.EXPECT) + + override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { + project.tasks + .withType>() +// .matching { it.name.contains(sourceSet.name, ignoreCase = true) } + .configureEach { it.dependsOn(generationTask) } + + project.rootProject.tasks.matching { + it.name.contains("prepareKotlinBuildScriptModel") + }.configureEach { + it.dependsOn(generationTask) + } + + project.tasks + .matching { it.name.startsWith("metadata") && it.name.endsWith("ProcessResources") } + .configureEach { + it.dependsOn(generationTask) + } + } + override fun generateFileSpec(): FileSpec? { if (settings.ownResourcesFileTree.files.isEmpty()) return null @@ -47,7 +70,7 @@ class CommonMRGenerator( val lowerResourcesIsEmpty = settings.lowerResourcesFileTree.files.isEmpty() - if (!lowerResourcesIsEmpty) { + if (lowerResourcesIsEmpty) { generateExpectMRObjectFileSpec( visibilityModifier = visibilityModifier, generatedObjectsList = generatedObjectsList, @@ -56,62 +79,21 @@ class CommonMRGenerator( } else { // If lower resources has files, when on lower level has expect object and // need to generate actual interface with fields - - //TODO actual - // Добавить генерацию actual интерфейсов в которых будут поля - - // generated MR class structure: -// val mrClassSpec: TypeSpec.Builder = TypeSpec.classBuilder(settings.className) // default: object MR - - val ownDirectoryWithResources: FileCollection = settings.ownResourcesFileTree - - ownDirectoryWithResources.forEach { - logger.warn("ownDirectoryWithResources: ${it.absoluteFile}") - } - - generators.forEach { generator -> - ownDirectoryWithResources.forEach { file: File -> - val sourceSetName: String = file.targetName - - val interfaceName = - sourceSetName.capitalize() + generator.mrObjectName.capitalize() - val resourcesInterfaceBuilder: TypeSpec.Builder = - TypeSpec.interfaceBuilder("${interfaceName}${generator.resourceClassName.simpleName}") - .addModifiers(visibilityModifier) - .addModifiers(KModifier.ACTUAL) - - generatedObjectsList.add( - GeneratedObject( - type = GeneratedObjectType.INTERFACE, - name = interfaceName, - modifier = GeneratedObjectModifier.ACTUAL - ) - ) - - resourcesInterfaceBuilder.addType( - generator.generate( - assetsGenerationDir, - resourcesGenerationDir, - resourcesInterfaceBuilder - ) - ) - processMRClass(resourcesInterfaceBuilder) - - val mrClass: TypeSpec = resourcesInterfaceBuilder.build() - fileSpec.addType(mrClass) - } - } - -// processMRClass(mrClassSpec) -// -// val mrClass: TypeSpec = mrClassSpec.build() -// fileSpec.addType(mrClass) + generateActualInterfacesFileSpec( + visibilityModifier = visibilityModifier, + generatedObjectsList = generatedObjectsList, + fileSpec = fileSpec + ) } generators .flatMap { it.getImports() } .plus(getImports()) - .forEach { fileSpec.addImport(it.packageName, it.simpleName) } + .forEach { + logger.warn("Imports: ${it.packageName}, ${it.simpleName}") + + fileSpec.addImport(it.packageName, it.simpleName) + } return fileSpec.build() } @@ -143,7 +125,6 @@ class CommonMRGenerator( .addModifiers(visibilityModifier) // public/internal // Check upper directories on files with resources - //TODO: Спискок ресурсов содержит только файлы, без "пустых" директорий val upperDirectoryWithResources: FileCollection = settings.upperResourcesFileTree // .filter { it.isDirectory } // .filter { file: File -> @@ -156,10 +137,11 @@ class CommonMRGenerator( // If upper directory has files of resources, need to generate // expect interface for sourceSet upperDirectoryWithResources.forEach { file: File -> - val sourceSetName: String = file.targetName + val interfaceName = getInterfaceName( + targetName = file.targetName, + generator = generator + ) - val interfaceName = - sourceSetName.capitalize() + generator.mrObjectName.capitalize() val resourcesInterface: TypeSpec = TypeSpec.interfaceBuilder(interfaceName) .addModifiers(visibilityModifier) @@ -173,6 +155,7 @@ class CommonMRGenerator( expectInterfacesList } else emptyList() + //Implement interfaces for generated expect object generatedInterfaces.forEach { interfaceName -> builder.addSuperinterface( ClassName( @@ -183,8 +166,8 @@ class CommonMRGenerator( generatedObjectsList.add( GeneratedObject( - type = GeneratedObjectType.INTERFACE, name = interfaceName, + type = GeneratedObjectType.INTERFACE, modifier = GeneratedObjectModifier.EXPECT ) ) @@ -205,28 +188,52 @@ class CommonMRGenerator( fileSpec.addType(mrClass) } - override fun getMRClassModifiers(): Array = arrayOf(KModifier.EXPECT) - override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { - project.tasks - .withType>() -// .matching { it.name.contains(sourceSet.name, ignoreCase = true) } - .configureEach { it.dependsOn(generationTask) } + private fun generateActualInterfacesFileSpec( + visibilityModifier: KModifier, + generatedObjectsList: MutableList, + fileSpec: Builder, + ) { + val targetName = settings.ownResourcesFileTree.files.first().targetName - project.rootProject.tasks.matching { - it.name.contains("prepareKotlinBuildScriptModel") - }.configureEach { - it.dependsOn(generationTask) + settings.ownResourcesFileTree.forEach { + logger.warn("ownDirectoryWithResources: ${it.absoluteFile}") } - project.tasks - .matching { it.name.startsWith("metadata") && it.name.endsWith("ProcessResources") } - .configureEach { - it.dependsOn(generationTask) - } + generators.forEach { generator -> + val interfaceName = getInterfaceName( + targetName = targetName, + generator = generator + ) + + val resourcesInterfaceBuilder: TypeSpec.Builder = + TypeSpec.interfaceBuilder(interfaceName) + .addModifiers(visibilityModifier) + .addModifiers(ACTUAL) + + generatedObjectsList.add( + GeneratedObject( + name = interfaceName, + type = GeneratedObjectType.INTERFACE, + modifier = GeneratedObjectModifier.ACTUAL + ) + ) + + fileSpec.addType( + generator.generate( + assetsGenerationDir, + resourcesGenerationDir, + resourcesInterfaceBuilder + ) + ) + } } } +private fun getInterfaceName(targetName: String, generator: Generator): String{ + return targetName.capitalize() + generator.mrObjectName.capitalize() +} + data class GeneratedObject( val type: GeneratedObjectType, val name: String, From b4345d092784beb7877a48457e34bc2f86c3df6f Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Thu, 23 Nov 2023 12:09:47 +0700 Subject: [PATCH 049/352] #535 fix imports of implemented interfaces, rework targets with resources list --- .../generator/common/CommonMRGenerator.kt | 49 ++++++++----------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index c8c44e827..a055af82a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -8,12 +8,10 @@ import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.FileSpec import com.squareup.kotlinpoet.FileSpec.Builder import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.KModifier.ACTUAL import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.MRGenerator.Generator import dev.icerock.gradle.generator.common.GeneratedObject.GeneratedObjectModifier -import dev.icerock.gradle.generator.common.GeneratedObject.GeneratedObjectModifier.Companion.asGeneratedModifier import dev.icerock.gradle.generator.common.GeneratedObject.GeneratedObjectType import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.toModifier @@ -21,10 +19,8 @@ import dev.icerock.gradle.utils.capitalize import dev.icerock.gradle.utils.targetName import org.gradle.api.GradleException import org.gradle.api.Project -import org.gradle.api.file.FileCollection import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.dsl.KotlinCompile -import java.io.File class CommonMRGenerator( project: Project, @@ -68,10 +64,10 @@ class CommonMRGenerator( fileName = settings.className ) - val lowerResourcesIsEmpty = settings.lowerResourcesFileTree.files.isEmpty() - - if (lowerResourcesIsEmpty) { + if (settings.lowerResourcesFileTree.files.isEmpty()) { + // When lower resources is empty, should generate expect MR object generateExpectMRObjectFileSpec( + resourcePackage = settings.packageName, visibilityModifier = visibilityModifier, generatedObjectsList = generatedObjectsList, fileSpec = fileSpec @@ -87,18 +83,17 @@ class CommonMRGenerator( } generators - .flatMap { it.getImports() } + .flatMap { generator -> generator.getImports() } .plus(getImports()) - .forEach { - logger.warn("Imports: ${it.packageName}, ${it.simpleName}") - - fileSpec.addImport(it.packageName, it.simpleName) + .forEach { className -> + fileSpec.addImport(className.packageName, className.simpleName) } return fileSpec.build() } private fun generateExpectMRObjectFileSpec( + resourcePackage: String, visibilityModifier: KModifier, generatedObjectsList: MutableList, fileSpec: Builder, @@ -113,32 +108,32 @@ class CommonMRGenerator( GeneratedObject( type = GeneratedObjectType.OBJECT, name = settings.className, - modifier = KModifier.EXPECT.asGeneratedModifier() + modifier = GeneratedObjectModifier.EXPECT ) ) - // When lower resources is empty, should generate expect MR object generators.forEach { generator -> - val builder: TypeSpec.Builder = TypeSpec .objectBuilder(generator.mrObjectName) // resource name: example strings .addModifiers(visibilityModifier) // public/internal // Check upper directories on files with resources - val upperDirectoryWithResources: FileCollection = settings.upperResourcesFileTree + val targetsWithResources: List = settings.upperResourcesFileTree.map { + it.targetName + }.distinct() // .filter { it.isDirectory } // .filter { file: File -> // file.listFiles()?.isNotEmpty() ?: false // } - val generatedInterfaces: List = if (!upperDirectoryWithResources.isEmpty) { + val generatedInterfaces: List = if (targetsWithResources.isNotEmpty()) { val expectInterfacesList = mutableListOf() // If upper directory has files of resources, need to generate // expect interface for sourceSet - upperDirectoryWithResources.forEach { file: File -> + targetsWithResources.forEach { targetName -> val interfaceName = getInterfaceName( - targetName = file.targetName, + targetName = targetName, generator = generator ) @@ -159,7 +154,7 @@ class CommonMRGenerator( generatedInterfaces.forEach { interfaceName -> builder.addSuperinterface( ClassName( - packageName = "dev.icerock.moko.resources", + packageName = resourcePackage, interfaceName ) ) @@ -175,9 +170,9 @@ class CommonMRGenerator( mrClassSpec.addType( generator.generate( - assetsGenerationDir, - resourcesGenerationDir, - builder + assetsGenerationDir = assetsGenerationDir, + resourcesGenerationDir = resourcesGenerationDir, + objectBuilder = builder ) ) } @@ -196,10 +191,6 @@ class CommonMRGenerator( ) { val targetName = settings.ownResourcesFileTree.files.first().targetName - settings.ownResourcesFileTree.forEach { - logger.warn("ownDirectoryWithResources: ${it.absoluteFile}") - } - generators.forEach { generator -> val interfaceName = getInterfaceName( targetName = targetName, @@ -209,7 +200,7 @@ class CommonMRGenerator( val resourcesInterfaceBuilder: TypeSpec.Builder = TypeSpec.interfaceBuilder(interfaceName) .addModifiers(visibilityModifier) - .addModifiers(ACTUAL) + .addModifiers(KModifier.ACTUAL) generatedObjectsList.add( GeneratedObject( @@ -230,7 +221,7 @@ class CommonMRGenerator( } } -private fun getInterfaceName(targetName: String, generator: Generator): String{ +private fun getInterfaceName(targetName: String, generator: Generator): String { return targetName.capitalize() + generator.mrObjectName.capitalize() } From dc8613ad7e6cb3eff0210745facf700958a1c823 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Fri, 24 Nov 2023 13:40:19 +0700 Subject: [PATCH 050/352] #535 add output metadata for generated objects in commonMRGenerator --- .../generator/common/CommonMRGenerator.kt | 92 ++++++++++--------- .../gradle/metadata/GeneratedObject.kt | 55 +++++++++++ .../metadata/GeneratedObjectModifier.kt | 14 +++ .../gradle/metadata/GeneratedObjectType.kt | 14 +++ .../gradle/metadata/GeneratedVariables.kt | 32 +++++++ .../dev/icerock/gradle/metadata/Metadata.kt | 48 ++++++++++ 6 files changed, 212 insertions(+), 43 deletions(-) create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObjectModifier.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObjectType.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedVariables.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index a055af82a..8702459ef 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -8,22 +8,25 @@ import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.FileSpec import com.squareup.kotlinpoet.FileSpec.Builder import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.MRGenerator.Generator -import dev.icerock.gradle.generator.common.GeneratedObject.GeneratedObjectModifier -import dev.icerock.gradle.generator.common.GeneratedObject.GeneratedObjectType +import dev.icerock.gradle.metadata.GeneratedObject +import dev.icerock.gradle.metadata.GeneratedObjectModifier +import dev.icerock.gradle.metadata.GeneratedObjectType +import dev.icerock.gradle.metadata.GeneratedVariables +import dev.icerock.gradle.metadata.Metadata.createOutputMetadata import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.toModifier import dev.icerock.gradle.utils.capitalize import dev.icerock.gradle.utils.targetName -import org.gradle.api.GradleException import org.gradle.api.Project import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.dsl.KotlinCompile class CommonMRGenerator( - project: Project, + private val project: Project, settings: Settings, generators: List, ) : MRGenerator( @@ -89,6 +92,12 @@ class CommonMRGenerator( fileSpec.addImport(className.packageName, className.simpleName) } + createOutputMetadata( + buildDir = project.buildDir, + sourceSetName = settings.ownResourcesFileTree.first().targetName, + generatedObjects = generatedObjectsList + ) + return fileSpec.build() } @@ -108,7 +117,8 @@ class CommonMRGenerator( GeneratedObject( type = GeneratedObjectType.OBJECT, name = settings.className, - modifier = GeneratedObjectModifier.EXPECT + modifier = GeneratedObjectModifier.EXPECT, + variables = emptyList() ) ) @@ -163,18 +173,28 @@ class CommonMRGenerator( GeneratedObject( name = interfaceName, type = GeneratedObjectType.INTERFACE, - modifier = GeneratedObjectModifier.EXPECT + modifier = GeneratedObjectModifier.EXPECT, + variables = emptyList() ) ) } - mrClassSpec.addType( - generator.generate( - assetsGenerationDir = assetsGenerationDir, - resourcesGenerationDir = resourcesGenerationDir, - objectBuilder = builder + val generatedResources = generator.generate( + assetsGenerationDir = assetsGenerationDir, + resourcesGenerationDir = resourcesGenerationDir, + objectBuilder = builder + ) + + generatedObjectsList.add( + GeneratedObject( + name = generator.mrObjectName, + type = GeneratedObjectType.OBJECT, + modifier = GeneratedObjectModifier.EXPECT, + variables = generatedResources.propertySpecs.toGeneratedVariables(), ) ) + + mrClassSpec.addType(generatedResources) } processMRClass(mrClassSpec) @@ -183,7 +203,6 @@ class CommonMRGenerator( fileSpec.addType(mrClass) } - private fun generateActualInterfacesFileSpec( visibilityModifier: KModifier, generatedObjectsList: MutableList, @@ -202,20 +221,23 @@ class CommonMRGenerator( .addModifiers(visibilityModifier) .addModifiers(KModifier.ACTUAL) + val generatedResources: TypeSpec = generator.generate( + assetsGenerationDir, + resourcesGenerationDir, + resourcesInterfaceBuilder + ) + generatedObjectsList.add( GeneratedObject( name = interfaceName, type = GeneratedObjectType.INTERFACE, - modifier = GeneratedObjectModifier.ACTUAL + modifier = GeneratedObjectModifier.ACTUAL, + variables = generatedResources.propertySpecs.toGeneratedVariables() ) ) fileSpec.addType( - generator.generate( - assetsGenerationDir, - resourcesGenerationDir, - resourcesInterfaceBuilder - ) + generatedResources ) } } @@ -225,31 +247,15 @@ private fun getInterfaceName(targetName: String, generator: Generator): String { return targetName.capitalize() + generator.mrObjectName.capitalize() } -data class GeneratedObject( - val type: GeneratedObjectType, - val name: String, - val modifier: GeneratedObjectModifier, -) { - val objectSpec: String - get() = "${modifier.name.lowercase()} ${type.name.lowercase()} $name" - - enum class GeneratedObjectType { - OBJECT, - INTERFACE - } - - enum class GeneratedObjectModifier { - EXPECT, - ACTUAL; - - companion object { - fun KModifier.asGeneratedModifier(): GeneratedObjectModifier { - return when (this) { - KModifier.EXPECT -> EXPECT - KModifier.ACTUAL -> ACTUAL - else -> throw GradleException("Invalid object modifier") - } +private fun List.toGeneratedVariables() : List { + return map { + GeneratedVariables( + name = it.name, + modifier = if (it.modifiers.contains(KModifier.ACTUAL)) { + GeneratedObjectModifier.ACTUAL + } else { + GeneratedObjectModifier.EXPECT } - } + ) } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt new file mode 100644 index 000000000..79dfac2ca --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt @@ -0,0 +1,55 @@ +package dev.icerock.gradle.metadata + +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.buildJsonArray +import kotlinx.serialization.json.buildJsonObject +import kotlinx.serialization.json.put +import org.jetbrains.kotlin.com.google.gson.annotations.SerializedName + +data class GeneratedObject( + val type: GeneratedObjectType, + val name: String, + val modifier: GeneratedObjectModifier, + val variables: List, +) { + val objectSpec: String + get() = "${modifier.value} ${type.value} $name" + + val asJsonObject: JsonObject + get() = buildJsonObject { + put(key = "name", value = name) + put(key = "type", value = type.value) + put(key = "modifier", value = modifier.value) + put( + key = "variables", + element = buildJsonArray { + variables.forEach { + add(it.asJsonObject) + } + } + ) + } +} + +data class GeneratedObjectMetadata( + @SerializedName("type") + val type: String, + @SerializedName("name") + val name: String, + @SerializedName("modifier") + val modifier: String, + @SerializedName("variables") + val variables: List, +) { + val asGeneratedObject: GeneratedObject + get() { + return GeneratedObject( + type = GeneratedObjectType.getByValue(type), + name = name, + modifier = GeneratedObjectModifier.getByValue(modifier), + variables = variables.map { + it.asGeneratedVariables + } + ) + } +} \ No newline at end of file diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObjectModifier.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObjectModifier.kt new file mode 100644 index 000000000..7b547d11b --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObjectModifier.kt @@ -0,0 +1,14 @@ +package dev.icerock.gradle.metadata + +enum class GeneratedObjectModifier(val value: String) { + EXPECT("expect"), + ACTUAL("actual"); + + companion object { + private val VALUES = values() + fun getByValue(value: String): GeneratedObjectModifier { + return VALUES.firstOrNull { it.value.lowercase() == value.lowercase() } + ?: throw Exception("Invalid modifier value") + } + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObjectType.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObjectType.kt new file mode 100644 index 000000000..b11bf3c10 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObjectType.kt @@ -0,0 +1,14 @@ +package dev.icerock.gradle.metadata + +enum class GeneratedObjectType(val value: String) { + OBJECT("object"), + INTERFACE("interface"); + + companion object { + private val VALUES = values() + fun getByValue(value: String): GeneratedObjectType { + return VALUES.firstOrNull { it.value.lowercase() == value.lowercase() } + ?: throw Exception("Invalid object type") + } + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedVariables.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedVariables.kt new file mode 100644 index 000000000..f2a5ed4a7 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedVariables.kt @@ -0,0 +1,32 @@ +package dev.icerock.gradle.metadata + +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.buildJsonObject +import kotlinx.serialization.json.put +import org.jetbrains.kotlin.com.google.gson.annotations.SerializedName + +data class GeneratedVariables( + val name: String, + val modifier: GeneratedObjectModifier, +) { + val asJsonObject: JsonObject + get() = buildJsonObject { + put("name", name) + put("modifier", modifier.value) + } +} + +data class GeneratedVariablesMetadata( + @SerializedName("name") + val name: String, + @SerializedName("modifier") + val modifier: String, +) { + val asGeneratedVariables: GeneratedVariables + get() { + return GeneratedVariables( + name = name, + modifier = GeneratedObjectModifier.getByValue(modifier) + ) + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt new file mode 100644 index 000000000..d7c8983b6 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt @@ -0,0 +1,48 @@ +package dev.icerock.gradle.metadata + +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonArray +import kotlinx.serialization.json.buildJsonArray +import java.io.BufferedReader +import java.io.File + +object Metadata { + private const val DIRECTORY = "generated/moko-resources/metadata" + + fun createOutputMetadata( + buildDir: File, + sourceSetName: String, + generatedObjects: List, + ) { + val metadataDir = File(buildDir, DIRECTORY).apply { + mkdirs() + } + val metadataFile = File(metadataDir, "$sourceSetName-metadata.json") + metadataFile.createNewFile() + + + val generatedJson: JsonArray = buildJsonArray { + generatedObjects.forEach { generatedObject -> + add(generatedObject.asJsonObject) + } + } + + metadataFile.writeText(generatedJson.toString()) + } + + fun readInputMetadata( + buildDir: File, + sourceSetName: String, + ): List { + val metadataDir = File(buildDir, DIRECTORY).apply { + mkdirs() + } + val inputMetadata = File(metadataDir, "$sourceSetName-metadata.json") + val bufferedReader: BufferedReader = File(inputMetadata.toURI()).bufferedReader() + val inputString = bufferedReader.use { it.readText() } + + return Json.decodeFromString>(inputString).map { + it.asGeneratedObject + } + } +} From 9357484217c32e8481f3b038a3adacf8f14db01b Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Fri, 24 Nov 2023 20:40:24 +0700 Subject: [PATCH 051/352] #535 started targetMRGenerator, input metadata for targetGenerator --- .../gradle/configuration/AndroidTarget.kt | 1 + .../gradle/configuration/AppleTargets.kt | 1 + .../icerock/gradle/configuration/JsTarget.kt | 1 + .../icerock/gradle/configuration/JvmTarget.kt | 2 +- .../gradle/generator/TargetMRGenerator.kt | 66 ++++++++++++++++--- .../generator/android/AndroidMRGenerator.kt | 2 + .../generator/apple/AppleMRGenerator.kt | 2 + .../generator/common/CommonMRGenerator.kt | 7 +- .../gradle/generator/js/JsMRGenerator.kt | 2 + .../gradle/generator/jvm/JvmMRGenerator.kt | 2 + .../gradle/metadata/GeneratedObject.kt | 24 ------- .../gradle/metadata/GeneratedVariables.kt | 16 ----- .../dev/icerock/gradle/metadata/Metadata.kt | 50 ++++++++++++-- .../icerock/gradle/metadata/MetadataUtils.kt | 8 +++ .../GenerateMultiplatformResourcesTask.kt | 3 +- 15 files changed, 123 insertions(+), 64 deletions(-) create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataUtils.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AndroidTarget.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AndroidTarget.kt index 8fa984604..8b4356abd 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AndroidTarget.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AndroidTarget.kt @@ -61,6 +61,7 @@ private fun setupAndroidGenerator( setAssetsDirsRefresh(project) AndroidMRGenerator( + project = project, settings = settings, generators = features.map { it.createAndroidGenerator() }, ).apply(project) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt index ae3f640b3..aa0d04bfc 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt @@ -34,6 +34,7 @@ internal fun configureAppleTargetGenerator( .getByName(KotlinCompilation.MAIN_COMPILATION_NAME) AppleMRGenerator( + project = target.project, settings = settings, generators = features.map { it.createIosGenerator() }, compilation = mainCompilation, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JsTarget.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JsTarget.kt index 8d4bf1503..62f015e0d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JsTarget.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JsTarget.kt @@ -27,6 +27,7 @@ internal fun configureJsTargetGenerator( // TODO rollback ifDepends // compilation.defaultSourceSet.ifDependsOn(commonSourceSet) { JsMRGenerator( + project = project, settings = settings, generators = features.map { it.createJsGenerator() }, compilation = compilation, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JvmTarget.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JvmTarget.kt index ddce584dc..2c1d128cc 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JvmTarget.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JvmTarget.kt @@ -7,7 +7,6 @@ package dev.icerock.gradle.configuration import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.ResourceGeneratorFeature import dev.icerock.gradle.generator.jvm.JvmMRGenerator -import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation import org.jetbrains.kotlin.gradle.plugin.KotlinTarget internal fun configureJvmTargetGenerator( @@ -16,6 +15,7 @@ internal fun configureJvmTargetGenerator( features: List> ) { JvmMRGenerator( + project = target.project, settings = settings, generators = features.map { it.createJvmGenerator() } ).apply(project = target.project) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt index 4d710d349..ad8f5e9a8 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt @@ -1,38 +1,65 @@ package dev.icerock.gradle.generator +import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.FileSpec import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.TypeSpec +import com.squareup.kotlinpoet.TypeSpec.Builder +import dev.icerock.gradle.metadata.GeneratedObject +import dev.icerock.gradle.metadata.GeneratedObjectModifier +import dev.icerock.gradle.metadata.GeneratedObjectType +import dev.icerock.gradle.metadata.Metadata.readInputMetadata import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.toModifier +import dev.icerock.gradle.utils.targetName import org.gradle.api.Project abstract class TargetMRGenerator( + private val project: Project, settings: Settings, generators: List, ) : MRGenerator( settings = settings, generators = generators ) { + val logger = project.logger + override fun generateFileSpec(): FileSpec? { val visibilityModifier: KModifier = settings.visibility.toModifier() + val inputMetadata: List = readInputMetadata( + buildDir = project.buildDir, + sourceSetName = settings.lowerResourcesFileTree.files.first().targetName + ) + val generatedObjects = mutableListOf() + + inputMetadata.forEach { + logger.warn("i prev: $it") + + } + @Suppress("SpreadOperator") val mrClassSpec = TypeSpec.objectBuilder(settings.className) .addModifiers(*getMRClassModifiers()) .addModifiers(visibilityModifier) + val targetName = settings.ownResourcesFileTree.first().targetName + generators.forEach { generator -> - val builder = TypeSpec.objectBuilder(generator.mrObjectName) + val builder: Builder = TypeSpec + .objectBuilder(generator.mrObjectName) .addModifiers(visibilityModifier) -// val fileResourceInterfaceClassName = ClassName( -// packageName = "dev.icerock.moko.resources", -// "ResourceContainer" -// ) -// builder.addSuperinterface( -// fileResourceInterfaceClassName.parameterizedBy(generator.resourceClassName) -// ) + inputMetadata.distinctBy { + it.type == GeneratedObjectType.INTERFACE && it.modifier == GeneratedObjectModifier.EXPECT + }.forEach { generatedObject: GeneratedObject -> + builder.addSuperinterface( + ClassName( + packageName = settings.packageName, + generatedObject.name + ) + ) + } mrClassSpec.addType( generator.generate( @@ -52,6 +79,16 @@ abstract class TargetMRGenerator( fileName = settings.className ).addType(mrClass) + logger.warn("i fileSpec") + +// createOutputMetadata( +// buildDir = project.buildDir, +// sourceSetName = settings.ownResourcesFileTree.files.first().targetName, +// generatedObjects = generatedObjects +// ) + + logger.warn("i fileSpec.addImport") + generators .flatMap { it.getImports() } .plus(getImports()) @@ -61,9 +98,20 @@ abstract class TargetMRGenerator( } override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { + val name = settings.ownResourcesFileTree.first().targetName + val genTaskName = "generateMR$name" + val genTask = runCatching { + project.tasks.getByName(genTaskName) as GenerateMultiplatformResourcesTask + }.getOrNull() ?: project.tasks.create( + genTaskName, + GenerateMultiplatformResourcesTask::class.java + ) { + it.generate() + } + + apply(generationTask = genTask, project = project) } override fun getMRClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - } \ No newline at end of file diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt index 270a26f03..7ebe90532 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt @@ -13,9 +13,11 @@ import org.gradle.api.Project import org.gradle.kotlin.dsl.withType class AndroidMRGenerator( + project: Project, settings: Settings, generators: List, ) : TargetMRGenerator( + project = project, settings = settings, generators = generators ) { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt index 59bbfa583..4ff5d0174 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt @@ -42,11 +42,13 @@ import kotlin.reflect.full.memberProperties @Suppress("TooManyFunctions") class AppleMRGenerator( + project: Project, settings: Settings, generators: List, private val compilation: AbstractKotlinNativeCompilation, private val baseLocalizationRegion: String, ) : TargetMRGenerator( + project = project, settings = settings, generators = generators ) { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index 8702459ef..e442aaeb8 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -11,15 +11,14 @@ import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.MRGenerator -import dev.icerock.gradle.generator.MRGenerator.Generator import dev.icerock.gradle.metadata.GeneratedObject import dev.icerock.gradle.metadata.GeneratedObjectModifier import dev.icerock.gradle.metadata.GeneratedObjectType import dev.icerock.gradle.metadata.GeneratedVariables import dev.icerock.gradle.metadata.Metadata.createOutputMetadata +import dev.icerock.gradle.metadata.getInterfaceName import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.toModifier -import dev.icerock.gradle.utils.capitalize import dev.icerock.gradle.utils.targetName import org.gradle.api.Project import org.gradle.kotlin.dsl.withType @@ -243,10 +242,6 @@ class CommonMRGenerator( } } -private fun getInterfaceName(targetName: String, generator: Generator): String { - return targetName.capitalize() + generator.mrObjectName.capitalize() -} - private fun List.toGeneratedVariables() : List { return map { GeneratedVariables( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt index c2ac9fb26..08143b1e3 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt @@ -25,10 +25,12 @@ import org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl import java.io.File class JsMRGenerator( + project: Project, settings: Settings, generators: List, private val compilation: KotlinJsIrCompilation, ) : TargetMRGenerator( + project = project, settings = settings, generators = generators ) { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt index 4f2799b52..81f038f19 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt @@ -19,9 +19,11 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import java.io.File class JvmMRGenerator( + project: Project, settings: Settings, generators: List ) : TargetMRGenerator( + project = project, settings = settings, generators = generators ) { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt index 79dfac2ca..942e04132 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt @@ -4,7 +4,6 @@ import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.buildJsonArray import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.put -import org.jetbrains.kotlin.com.google.gson.annotations.SerializedName data class GeneratedObject( val type: GeneratedObjectType, @@ -30,26 +29,3 @@ data class GeneratedObject( ) } } - -data class GeneratedObjectMetadata( - @SerializedName("type") - val type: String, - @SerializedName("name") - val name: String, - @SerializedName("modifier") - val modifier: String, - @SerializedName("variables") - val variables: List, -) { - val asGeneratedObject: GeneratedObject - get() { - return GeneratedObject( - type = GeneratedObjectType.getByValue(type), - name = name, - modifier = GeneratedObjectModifier.getByValue(modifier), - variables = variables.map { - it.asGeneratedVariables - } - ) - } -} \ No newline at end of file diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedVariables.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedVariables.kt index f2a5ed4a7..3269eefcb 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedVariables.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedVariables.kt @@ -3,7 +3,6 @@ package dev.icerock.gradle.metadata import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.put -import org.jetbrains.kotlin.com.google.gson.annotations.SerializedName data class GeneratedVariables( val name: String, @@ -15,18 +14,3 @@ data class GeneratedVariables( put("modifier", modifier.value) } } - -data class GeneratedVariablesMetadata( - @SerializedName("name") - val name: String, - @SerializedName("modifier") - val modifier: String, -) { - val asGeneratedVariables: GeneratedVariables - get() { - return GeneratedVariables( - name = name, - modifier = GeneratedObjectModifier.getByValue(modifier) - ) - } -} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt index d7c8983b6..1426d88dd 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt @@ -2,7 +2,11 @@ package dev.icerock.gradle.metadata import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonArray +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.buildJsonArray +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject import java.io.BufferedReader import java.io.File @@ -14,13 +18,14 @@ object Metadata { sourceSetName: String, generatedObjects: List, ) { + if (generatedObjects.isEmpty()) return + val metadataDir = File(buildDir, DIRECTORY).apply { mkdirs() } val metadataFile = File(metadataDir, "$sourceSetName-metadata.json") metadataFile.createNewFile() - val generatedJson: JsonArray = buildJsonArray { generatedObjects.forEach { generatedObject -> add(generatedObject.asJsonObject) @@ -34,15 +39,46 @@ object Metadata { buildDir: File, sourceSetName: String, ): List { - val metadataDir = File(buildDir, DIRECTORY).apply { - mkdirs() - } + val metadataDir = File(buildDir, DIRECTORY) val inputMetadata = File(metadataDir, "$sourceSetName-metadata.json") val bufferedReader: BufferedReader = File(inputMetadata.toURI()).bufferedReader() - val inputString = bufferedReader.use { it.readText() } + val inputString: String = bufferedReader.use { it.readText() } + + val generatedObjects = mutableListOf() + + val parsedArray: JsonArray = Json.parseToJsonElement(inputString).jsonArray - return Json.decodeFromString>(inputString).map { - it.asGeneratedObject + parsedArray.forEach { generatedObjectJson: JsonElement -> + val element: JsonObject = generatedObjectJson.jsonObject + val name: String = element["name"].cleanValue() + val type: String = element["type"].cleanValue() + val modifier: String = element["modifier"].cleanValue() + val variables: JsonArray? = element["variables"]?.jsonArray + + generatedObjects.add( + GeneratedObject( + name = name, + type = GeneratedObjectType.getByValue(type), + modifier = GeneratedObjectModifier.getByValue(modifier), + variables = variables?.map { variableJson -> + val variableElement: JsonObject = variableJson.jsonObject + val variableName: String = variableElement["name"].cleanValue() + val variableModifier: String = variableElement["modifier"].cleanValue() + + GeneratedVariables( + name = variableName, + modifier = GeneratedObjectModifier.getByValue(variableModifier) + + ) + } ?: emptyList() + ) + ) } + + return generatedObjects + } + + private fun JsonElement?.cleanValue():String { + return this.toString().replace("\"", "") } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataUtils.kt new file mode 100644 index 000000000..b12eb6903 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataUtils.kt @@ -0,0 +1,8 @@ +package dev.icerock.gradle.metadata + +import dev.icerock.gradle.generator.MRGenerator.Generator +import dev.icerock.gradle.utils.capitalize + +internal fun getInterfaceName(targetName: String, generator: Generator): String { + return targetName.capitalize() + generator.mrObjectName.capitalize() +} 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 7803323fd..68215ae70 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 @@ -7,7 +7,6 @@ package dev.icerock.gradle.tasks import dev.icerock.gradle.MRVisibility import dev.icerock.gradle.configuration.getAndroidRClassPackage import dev.icerock.gradle.generator.MRGenerator -import dev.icerock.gradle.generator.PluralsGenerator import dev.icerock.gradle.generator.ResourceGeneratorFeature import dev.icerock.gradle.generator.StringsGenerator import dev.icerock.gradle.generator.android.AndroidMRGenerator @@ -151,6 +150,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { generators: List>, ): AndroidMRGenerator { return AndroidMRGenerator( + project = project, settings = settings, generators = generators.map { it.createAndroidGenerator() @@ -163,6 +163,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { generators: List>, ): JvmMRGenerator { return JvmMRGenerator( + project = project, settings = settings, generators = generators.map { it.createJvmGenerator() From f057f6ce3dcaa799b8764d848050c703d21c2aed Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Sun, 26 Nov 2023 20:37:11 +0700 Subject: [PATCH 052/352] #535 generation actual interface for target, fix metadata generation, removed baseLocalization from appleGenerator --- .../gradle/MultiplatformResourcesPlugin.kt | 44 +++--- .../gradle/configuration/AppleTargets.kt | 1 - .../icerock/gradle/generator/MRGenerator.kt | 1 - .../gradle/generator/StringsGenerator.kt | 2 +- .../gradle/generator/TargetMRGenerator.kt | 146 +++++++++++++++--- .../generator/android/AndroidMRGenerator.kt | 1 + .../android/AndroidStringsGenerator.kt | 26 +--- .../generator/apple/AppleMRGenerator.kt | 3 +- .../generator/common/CommonMRGenerator.kt | 18 +-- .../gradle/metadata/GeneratedObject.kt | 19 ++- ...tedVariables.kt => GeneratedProperties.kt} | 11 +- .../dev/icerock/gradle/metadata/Metadata.kt | 27 ++-- .../metadata/{MetadataUtils.kt => Utils.kt} | 0 .../GenerateMultiplatformResourcesTask.kt | 10 ++ .../moko-resources/base/strings.xml | 1 - .../moko-resources/base/strings.xml | 4 + 16 files changed, 210 insertions(+), 104 deletions(-) rename resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/{GeneratedVariables.kt => GeneratedProperties.kt} (56%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/{MetadataUtils.kt => Utils.kt} (100%) create mode 100644 samples/compose-resources-gallery/shared/src/desktopMain/moko-resources/base/strings.xml diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 779e61fe5..9e898c4c4 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -111,6 +111,8 @@ open class MultiplatformResourcesPlugin : Plugin { it.platformType.set(target.platformType.name) + project.logger.warn("i configure it.platformType = ${it.platformType.get()}") + if (target is KotlinNativeTarget) { it.konanTarget.set(target.konanTarget.name) } @@ -190,27 +192,25 @@ open class MultiplatformResourcesPlugin : Plugin { val androidSourceSet: com.android.build.gradle.api.AndroidSourceSet? = androidExtension?.sourceSets?.getByName(SourceSet.MAIN_SOURCE_SET_NAME) - when { - commonSourceSet != null -> { - setupKotlinSourceSet( - project = project, - kotlinSourceSet = commonSourceSet, - ) - } - androidSourceSet != null -> { - setupAndroidSourceSet( - project = project, - androidSourceSet = androidSourceSet - ) - } - else -> { - kmpExtension.sourceSets.configureEach { kotlinSourceSet -> - setupKotlinSourceSet( - project = project, - kotlinSourceSet = kotlinSourceSet, - ) - } - } + if (commonSourceSet != null) { + setupKotlinSourceSet( + project = project, + kotlinSourceSet = commonSourceSet, + ) + } + + if (androidSourceSet != null) { + setupAndroidSourceSet( + project = project, + androidSourceSet = androidSourceSet + ) + } + + kmpExtension.sourceSets.configureEach { kotlinSourceSet -> + setupKotlinSourceSet( + project = project, + kotlinSourceSet = kotlinSourceSet, + ) } } @@ -234,6 +234,8 @@ open class MultiplatformResourcesPlugin : Plugin { project: Project, androidSourceSet: AndroidSourceSet, ) { + project.logger.warn("i android sourceSets: ${androidSourceSet.name}") + val mokoResourcesDir = getGeneratedResourcesDir( project = project, sourceSetName = androidSourceSet.name diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt index aa0d04bfc..59e64bb2d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt @@ -38,7 +38,6 @@ internal fun configureAppleTargetGenerator( settings = settings, generators = features.map { it.createIosGenerator() }, compilation = mainCompilation, - baseLocalizationRegion = settings.iosLocalizationRegion ).apply(target.project) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt index f562f7db1..8433991f4 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt @@ -48,7 +48,6 @@ abstract class MRGenerator( "generateMR$name", GenerateMultiplatformResourcesTask::class.java ) { -// it.generator = this it.inputs.property("mokoSettingsPackageName", settings.packageName) it.inputs.property("mokoSettingsClassName", settings.className) it.inputs.property("mokoSettingsVisibility", settings.visibility) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt index 71dbcbbc1..fcb84fe8b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt @@ -25,7 +25,7 @@ abstract class StringsGenerator( ) : BaseGenerator() { override val inputFiles: Iterable - get() = ownStringsFileTree.matching { + get() = (lowerStringsFileTree + ownStringsFileTree).matching { it.include(STRINGS_MASK) }.files diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt index ad8f5e9a8..fd4eec3b9 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt @@ -4,11 +4,13 @@ import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.FileSpec import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.TypeSpec -import com.squareup.kotlinpoet.TypeSpec.Builder +import dev.icerock.gradle.generator.common.toGeneratedVariables import dev.icerock.gradle.metadata.GeneratedObject import dev.icerock.gradle.metadata.GeneratedObjectModifier import dev.icerock.gradle.metadata.GeneratedObjectType +import dev.icerock.gradle.metadata.Metadata.createOutputMetadata import dev.icerock.gradle.metadata.Metadata.readInputMetadata +import dev.icerock.gradle.metadata.getInterfaceName import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.toModifier import dev.icerock.gradle.utils.targetName @@ -27,32 +29,86 @@ abstract class TargetMRGenerator( override fun generateFileSpec(): FileSpec? { val visibilityModifier: KModifier = settings.visibility.toModifier() + //Read list of generated resources on previous level val inputMetadata: List = readInputMetadata( buildDir = project.buildDir, sourceSetName = settings.lowerResourcesFileTree.files.first().targetName ) +// TODO: Check need of this for empty resources targets +// if (hasNoResourcesForGenerator(inputMetadata)) return null + + val fileSpec: FileSpec.Builder = FileSpec.builder( + packageName = settings.packageName, + fileName = settings.className + ) + val generatedObjects = mutableListOf() inputMetadata.forEach { logger.warn("i prev: $it") - } + logger.warn("i mrClassSpec") + @Suppress("SpreadOperator") - val mrClassSpec = TypeSpec.objectBuilder(settings.className) - .addModifiers(*getMRClassModifiers()) - .addModifiers(visibilityModifier) + val mrClassSpec = TypeSpec.objectBuilder(settings.className) // default: object MR + .addModifiers(KModifier.ACTUAL) + .addModifiers(visibilityModifier) // public/internal + + generatedObjects.add( + GeneratedObject( + type = GeneratedObjectType.OBJECT, + name = settings.className, + modifier = GeneratedObjectModifier.ACTUAL, + properties = emptyList() + ) + ) - val targetName = settings.ownResourcesFileTree.first().targetName + val expectInterfacesList: List = inputMetadata.filter { + it.type == GeneratedObjectType.INTERFACE && + it.modifier == GeneratedObjectModifier.EXPECT + } + + //Add actual implementation of expect interfaces from previous level + generateActualInterface( + visibilityModifier = settings.visibility.toModifier(), + generatedObjectsList = generatedObjects, + fileSpec = fileSpec + ) + + generatedObjects.forEach { + logger.warn("i generated objects item: ${it.name}") + } + + //Implementation not realised expect interfaces + expectInterfacesList.forEach { expectInterface -> + val hasInGeneratedActualObjects = generatedObjects.firstOrNull { + it.name == expectInterface.name + } != null + + logger.warn("i has in generatedObjects: $hasInGeneratedActualObjects") + + if (hasInGeneratedActualObjects) return@forEach + + val resourcesInterface: TypeSpec = + TypeSpec.interfaceBuilder(expectInterface.name) + .addModifiers(visibilityModifier) + .addModifiers(KModifier.ACTUAL) + .build() + + fileSpec.addType(resourcesInterface) + } + + expectInterfacesList.forEach { + logger.warn("i expectInterfacesList item: $it") + } generators.forEach { generator -> - val builder: Builder = TypeSpec + val builder: TypeSpec.Builder = TypeSpec .objectBuilder(generator.mrObjectName) .addModifiers(visibilityModifier) - inputMetadata.distinctBy { - it.type == GeneratedObjectType.INTERFACE && it.modifier == GeneratedObjectModifier.EXPECT - }.forEach { generatedObject: GeneratedObject -> + expectInterfacesList.forEach { generatedObject: GeneratedObject -> builder.addSuperinterface( ClassName( packageName = settings.packageName, @@ -73,21 +129,13 @@ abstract class TargetMRGenerator( processMRClass(mrClassSpec) val mrClass = mrClassSpec.build() + fileSpec.addType(mrClass) - val fileSpec = FileSpec.builder( - packageName = settings.packageName, - fileName = settings.className - ).addType(mrClass) - - logger.warn("i fileSpec") - -// createOutputMetadata( -// buildDir = project.buildDir, -// sourceSetName = settings.ownResourcesFileTree.files.first().targetName, -// generatedObjects = generatedObjects -// ) - - logger.warn("i fileSpec.addImport") + createOutputMetadata( + buildDir = project.buildDir, + sourceSetName = settings.ownResourcesFileTree.first().targetName, + generatedObjects = generatedObjects + ) generators .flatMap { it.getImports() } @@ -97,6 +145,56 @@ abstract class TargetMRGenerator( return fileSpec.build() } + private fun generateActualInterface( + visibilityModifier: KModifier, + generatedObjectsList: MutableList, + fileSpec: FileSpec.Builder, + ) { + logger.warn("i res") + settings.lowerResourcesFileTree.forEach { + logger.warn("i lowerResourcesFileTree file: $it") + } + settings.upperResourcesFileTree.forEach { + logger.warn("i upperResourcesFileTree file: $it") + } + settings.ownResourcesFileTree.forEach { + logger.warn("i ownResourcesFileTree file: $it") + } + val targetName = + settings.ownResourcesFileTree.files.firstOrNull()?.targetName ?: "androidMain" + + generators.forEach { generator -> + val interfaceName = getInterfaceName( + targetName = targetName, + generator = generator + ) + + val resourcesInterfaceBuilder: TypeSpec.Builder = + TypeSpec.interfaceBuilder(interfaceName) + .addModifiers(visibilityModifier) + + val generatedResources: TypeSpec = generator.generate( + assetsGenerationDir, + resourcesGenerationDir, + resourcesInterfaceBuilder + ) + + generatedObjectsList.add( + GeneratedObject( + name = interfaceName, + type = GeneratedObjectType.INTERFACE, + modifier = GeneratedObjectModifier.ACTUAL, + properties = generatedResources.propertySpecs.toGeneratedVariables() + ) + ) + + fileSpec.addType(generatedResources) + } + } + + private fun hasNoResourcesForGenerator(inputMetadata: List) = + inputMetadata.isEmpty() && settings.ownResourcesFileTree.isEmpty + override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { val name = settings.ownResourcesFileTree.first().targetName val genTaskName = "generateMR$name" diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt index 7ebe90532..ca3d67f19 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt @@ -24,6 +24,7 @@ class AndroidMRGenerator( override fun getMRClassModifiers(): Array = arrayOf(KModifier.ACTUAL) override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { + project.tasks.withType().configureEach { it.dependsOn(generationTask) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt index 835ead60b..1591fa1c5 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt @@ -17,8 +17,8 @@ import org.gradle.api.file.FileTree import java.io.File class AndroidStringsGenerator( - private val ownStringsFileTree: FileTree, private val lowerStringsFileTree: FileTree, + private val ownStringsFileTree: FileTree, strictLineBreaks: Boolean, private val androidRClassPackage: String, ) : StringsGenerator( @@ -27,29 +27,9 @@ class AndroidStringsGenerator( strictLineBreaks = strictLineBreaks ), ObjectBodyExtendable by NOPObjectBodyExtendable() { - override fun getClassModifiers(): Array { - val ownIsEmpty = ownStringsFileTree.matching { - it.include(STRINGS_MASK) - }.isEmpty - - val lowerIsEmpty = lowerStringsFileTree.matching { - it.include(STRINGS_MASK) - }.isEmpty - - return arrayOf(KModifier.ACTUAL) - } - - override fun getPropertyModifiers(): Array { - val ownIsEmpty = ownStringsFileTree.matching { - it.include(STRINGS_MASK) - }.isEmpty + override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - val lowerIsEmpty = lowerStringsFileTree.matching { - it.include(STRINGS_MASK) - }.isEmpty - - return arrayOf(KModifier.ACTUAL) - } + override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) override fun getPropertyInitializer(key: String) = CodeBlock.of("StringResource(R.string.%L)", processKey(key)) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt index 4ff5d0174..3c545ef6b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt @@ -46,7 +46,6 @@ class AppleMRGenerator( settings: Settings, generators: List, private val compilation: AbstractKotlinNativeCompilation, - private val baseLocalizationRegion: String, ) : TargetMRGenerator( project = project, settings = settings, @@ -102,7 +101,7 @@ class AppleMRGenerator( task.doLast { PackResourcesToKLibAction( - baseLocalizationRegion = baseLocalizationRegion, + baseLocalizationRegion = settings.iosLocalizationRegion, bundleIdentifier = bundleIdentifier, assetsDirectory = assetsGenerationDir, resourcesGenerationDir = resourcesGenerationDir, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index e442aaeb8..3ab00d875 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -14,7 +14,7 @@ import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.metadata.GeneratedObject import dev.icerock.gradle.metadata.GeneratedObjectModifier import dev.icerock.gradle.metadata.GeneratedObjectType -import dev.icerock.gradle.metadata.GeneratedVariables +import dev.icerock.gradle.metadata.GeneratedProperties import dev.icerock.gradle.metadata.Metadata.createOutputMetadata import dev.icerock.gradle.metadata.getInterfaceName import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask @@ -117,7 +117,7 @@ class CommonMRGenerator( type = GeneratedObjectType.OBJECT, name = settings.className, modifier = GeneratedObjectModifier.EXPECT, - variables = emptyList() + properties = emptyList() ) ) @@ -173,7 +173,7 @@ class CommonMRGenerator( name = interfaceName, type = GeneratedObjectType.INTERFACE, modifier = GeneratedObjectModifier.EXPECT, - variables = emptyList() + properties = emptyList() ) ) } @@ -189,7 +189,7 @@ class CommonMRGenerator( name = generator.mrObjectName, type = GeneratedObjectType.OBJECT, modifier = GeneratedObjectModifier.EXPECT, - variables = generatedResources.propertySpecs.toGeneratedVariables(), + properties = generatedResources.propertySpecs.toGeneratedVariables(), ) ) @@ -231,20 +231,18 @@ class CommonMRGenerator( name = interfaceName, type = GeneratedObjectType.INTERFACE, modifier = GeneratedObjectModifier.ACTUAL, - variables = generatedResources.propertySpecs.toGeneratedVariables() + properties = generatedResources.propertySpecs.toGeneratedVariables() ) ) - fileSpec.addType( - generatedResources - ) + fileSpec.addType(generatedResources) } } } -private fun List.toGeneratedVariables() : List { +fun List.toGeneratedVariables() : List { return map { - GeneratedVariables( + GeneratedProperties( name = it.name, modifier = if (it.modifiers.contains(KModifier.ACTUAL)) { GeneratedObjectModifier.ACTUAL diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt index 942e04132..93bf7c134 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt @@ -9,23 +9,30 @@ data class GeneratedObject( val type: GeneratedObjectType, val name: String, val modifier: GeneratedObjectModifier, - val variables: List, + val properties: List, ) { val objectSpec: String get() = "${modifier.value} ${type.value} $name" val asJsonObject: JsonObject get() = buildJsonObject { - put(key = "name", value = name) - put(key = "type", value = type.value) - put(key = "modifier", value = modifier.value) + put(key = KEY_NAME, value = name) + put(key = KEY_TYPE, value = type.value) + put(key = KEY_MODIFIER, value = modifier.value) put( - key = "variables", + key = KEY_PROPERTIES, element = buildJsonArray { - variables.forEach { + properties.forEach { add(it.asJsonObject) } } ) } + + companion object { + const val KEY_NAME = "name" + const val KEY_TYPE = "type" + const val KEY_MODIFIER = "modifier" + const val KEY_PROPERTIES = "properties" + } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedVariables.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperties.kt similarity index 56% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedVariables.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperties.kt index 3269eefcb..aa6bf366f 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedVariables.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperties.kt @@ -4,13 +4,18 @@ import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.put -data class GeneratedVariables( +data class GeneratedProperties( val name: String, val modifier: GeneratedObjectModifier, ) { val asJsonObject: JsonObject get() = buildJsonObject { - put("name", name) - put("modifier", modifier.value) + put(key = KEY_NAME, value = name) + put(key = KEY_MODIFIER, value = modifier.value) } + + companion object { + const val KEY_NAME = "name" + const val KEY_MODIFIER = "modifier" + } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt index 1426d88dd..b13a7593b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt @@ -7,6 +7,7 @@ import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.buildJsonArray import kotlinx.serialization.json.jsonArray import kotlinx.serialization.json.jsonObject +import kotlinx.serialization.json.jsonPrimitive import java.io.BufferedReader import java.io.File @@ -50,27 +51,31 @@ object Metadata { parsedArray.forEach { generatedObjectJson: JsonElement -> val element: JsonObject = generatedObjectJson.jsonObject - val name: String = element["name"].cleanValue() - val type: String = element["type"].cleanValue() - val modifier: String = element["modifier"].cleanValue() - val variables: JsonArray? = element["variables"]?.jsonArray + val name: String = element.getValue(GeneratedObject.KEY_NAME) + val type: String = element.getValue(GeneratedObject.KEY_TYPE) + val modifier: String = element.getValue(GeneratedObject.KEY_MODIFIER) + val variables: JsonArray? = element[GeneratedObject.KEY_PROPERTIES]?.jsonArray generatedObjects.add( GeneratedObject( name = name, type = GeneratedObjectType.getByValue(type), modifier = GeneratedObjectModifier.getByValue(modifier), - variables = variables?.map { variableJson -> + properties = variables?.map { variableJson -> val variableElement: JsonObject = variableJson.jsonObject - val variableName: String = variableElement["name"].cleanValue() - val variableModifier: String = variableElement["modifier"].cleanValue() + val variableName: String = variableElement.getValue( + key = GeneratedProperties.KEY_NAME + ) + val variableModifier: String = variableElement.getValue( + key = GeneratedProperties.KEY_MODIFIER + ) - GeneratedVariables( + GeneratedProperties( name = variableName, modifier = GeneratedObjectModifier.getByValue(variableModifier) ) - } ?: emptyList() + }.orEmpty() ) ) } @@ -78,7 +83,7 @@ object Metadata { return generatedObjects } - private fun JsonElement?.cleanValue():String { - return this.toString().replace("\"", "") + private fun JsonObject.getValue(key: String): String { + return this[key]?.jsonPrimitive?.content ?: "" } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Utils.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataUtils.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Utils.kt 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 68215ae70..06c4ce401 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 @@ -177,7 +177,9 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { ): JsMRGenerator { TODO() // return JsMRGenerator( +// project = project, // settings = settings, +// compilation = , //TODO: Research implementation // generators = generators.map { // it.createJsGenerator() // } @@ -222,5 +224,13 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { generators: List>, ): AppleMRGenerator { TODO() +// return AppleMRGenerator( +// project = project, +// settings = settings, +// generators = generators.map { +// it.createIosGenerator() +// }, +// compilation = , +// ) } } diff --git a/samples/compose-resources-gallery/shared/src/androidMain/moko-resources/base/strings.xml b/samples/compose-resources-gallery/shared/src/androidMain/moko-resources/base/strings.xml index 46167e256..d88d92a7e 100644 --- a/samples/compose-resources-gallery/shared/src/androidMain/moko-resources/base/strings.xml +++ b/samples/compose-resources-gallery/shared/src/androidMain/moko-resources/base/strings.xml @@ -1,5 +1,4 @@ Android, Hello World - Hello moko-resources Android World diff --git a/samples/compose-resources-gallery/shared/src/desktopMain/moko-resources/base/strings.xml b/samples/compose-resources-gallery/shared/src/desktopMain/moko-resources/base/strings.xml new file mode 100644 index 000000000..8d49ab2ba --- /dev/null +++ b/samples/compose-resources-gallery/shared/src/desktopMain/moko-resources/base/strings.xml @@ -0,0 +1,4 @@ + + + Desktop, Hello World + From b512ac879530ea50a33476a14ea3c439ddbb6baf Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Wed, 29 Nov 2023 00:02:10 +0700 Subject: [PATCH 053/352] #535 add kotlinx serialization plugin for with metadata --- resources-generator/build.gradle.kts | 1 + .../gradle/metadata/GeneratedObject.kt | 28 +-------- .../gradle/metadata/GeneratedProperties.kt | 18 +----- .../dev/icerock/gradle/metadata/Metadata.kt | 57 ++----------------- 4 files changed, 10 insertions(+), 94 deletions(-) diff --git a/resources-generator/build.gradle.kts b/resources-generator/build.gradle.kts index 3e7cbdc01..b300c4deb 100644 --- a/resources-generator/build.gradle.kts +++ b/resources-generator/build.gradle.kts @@ -11,6 +11,7 @@ plugins { id("publication-convention") id("com.gradle.plugin-publish") version ("1.2.0") id("java-gradle-plugin") + kotlin("plugin.serialization") version ("1.9.0") } group = "dev.icerock.moko" diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt index 93bf7c134..189fb56e8 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt @@ -1,10 +1,8 @@ package dev.icerock.gradle.metadata -import kotlinx.serialization.json.JsonObject -import kotlinx.serialization.json.buildJsonArray -import kotlinx.serialization.json.buildJsonObject -import kotlinx.serialization.json.put +import kotlinx.serialization.Serializable +@Serializable data class GeneratedObject( val type: GeneratedObjectType, val name: String, @@ -13,26 +11,4 @@ data class GeneratedObject( ) { val objectSpec: String get() = "${modifier.value} ${type.value} $name" - - val asJsonObject: JsonObject - get() = buildJsonObject { - put(key = KEY_NAME, value = name) - put(key = KEY_TYPE, value = type.value) - put(key = KEY_MODIFIER, value = modifier.value) - put( - key = KEY_PROPERTIES, - element = buildJsonArray { - properties.forEach { - add(it.asJsonObject) - } - } - ) - } - - companion object { - const val KEY_NAME = "name" - const val KEY_TYPE = "type" - const val KEY_MODIFIER = "modifier" - const val KEY_PROPERTIES = "properties" - } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperties.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperties.kt index aa6bf366f..fe18bfe31 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperties.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperties.kt @@ -1,21 +1,9 @@ package dev.icerock.gradle.metadata -import kotlinx.serialization.json.JsonObject -import kotlinx.serialization.json.buildJsonObject -import kotlinx.serialization.json.put +import kotlinx.serialization.Serializable +@Serializable data class GeneratedProperties( val name: String, val modifier: GeneratedObjectModifier, -) { - val asJsonObject: JsonObject - get() = buildJsonObject { - put(key = KEY_NAME, value = name) - put(key = KEY_MODIFIER, value = modifier.value) - } - - companion object { - const val KEY_NAME = "name" - const val KEY_MODIFIER = "modifier" - } -} +) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt index b13a7593b..6795a20c6 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt @@ -1,13 +1,7 @@ package dev.icerock.gradle.metadata +import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json -import kotlinx.serialization.json.JsonArray -import kotlinx.serialization.json.JsonElement -import kotlinx.serialization.json.JsonObject -import kotlinx.serialization.json.buildJsonArray -import kotlinx.serialization.json.jsonArray -import kotlinx.serialization.json.jsonObject -import kotlinx.serialization.json.jsonPrimitive import java.io.BufferedReader import java.io.File @@ -27,13 +21,9 @@ object Metadata { val metadataFile = File(metadataDir, "$sourceSetName-metadata.json") metadataFile.createNewFile() - val generatedJson: JsonArray = buildJsonArray { - generatedObjects.forEach { generatedObject -> - add(generatedObject.asJsonObject) - } - } + val generatedJson: String = Json.encodeToString(generatedObjects) - metadataFile.writeText(generatedJson.toString()) + metadataFile.writeText(generatedJson) } fun readInputMetadata( @@ -45,45 +35,6 @@ object Metadata { val bufferedReader: BufferedReader = File(inputMetadata.toURI()).bufferedReader() val inputString: String = bufferedReader.use { it.readText() } - val generatedObjects = mutableListOf() - - val parsedArray: JsonArray = Json.parseToJsonElement(inputString).jsonArray - - parsedArray.forEach { generatedObjectJson: JsonElement -> - val element: JsonObject = generatedObjectJson.jsonObject - val name: String = element.getValue(GeneratedObject.KEY_NAME) - val type: String = element.getValue(GeneratedObject.KEY_TYPE) - val modifier: String = element.getValue(GeneratedObject.KEY_MODIFIER) - val variables: JsonArray? = element[GeneratedObject.KEY_PROPERTIES]?.jsonArray - - generatedObjects.add( - GeneratedObject( - name = name, - type = GeneratedObjectType.getByValue(type), - modifier = GeneratedObjectModifier.getByValue(modifier), - properties = variables?.map { variableJson -> - val variableElement: JsonObject = variableJson.jsonObject - val variableName: String = variableElement.getValue( - key = GeneratedProperties.KEY_NAME - ) - val variableModifier: String = variableElement.getValue( - key = GeneratedProperties.KEY_MODIFIER - ) - - GeneratedProperties( - name = variableName, - modifier = GeneratedObjectModifier.getByValue(variableModifier) - - ) - }.orEmpty() - ) - ) - } - - return generatedObjects - } - - private fun JsonObject.getValue(key: String): String { - return this[key]?.jsonPrimitive?.content ?: "" + return Json.decodeFromString(inputString) } } From 4fe55fa1f555c020de3a09d3d0e2716c481eebbb Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Wed, 29 Nov 2023 00:04:12 +0700 Subject: [PATCH 054/352] #535 highlight js and apple generator problem --- .../dev/icerock/gradle/generator/apple/AppleMRGenerator.kt | 1 + .../kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt | 1 + .../gradle/tasks/GenerateMultiplatformResourcesTask.kt | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt index 3c545ef6b..64d863651 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt @@ -93,6 +93,7 @@ class AppleMRGenerator( assetsGenerationDir.mkdirs() } + //TODO: Вынести на этап конфигурации private fun setupKLibResources(generationTask: GenerateMultiplatformResourcesTask) { val compileTask: TaskProvider = compilation.compileTaskProvider diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt index 08143b1e3..cc015ab94 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt @@ -98,6 +98,7 @@ class JsMRGenerator( // ) } + //TODO: Вынести на этап конфигурации private fun setupKLibResources(generationTask: Task) { val taskProvider = compilation.compileTaskProvider taskProvider.configure { compileTask -> 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 06c4ce401..91aabd890 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 @@ -179,7 +179,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { // return JsMRGenerator( // project = project, // settings = settings, -// compilation = , //TODO: Research implementation +// compilation = compilationJs.get(), // generators = generators.map { // it.createJsGenerator() // } @@ -230,7 +230,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { // generators = generators.map { // it.createIosGenerator() // }, -// compilation = , +// compilation = compilationApple.get(), // ) } } From 819ac49eab2e15ed15c36ad38f1ff4707542cdf0 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Wed, 29 Nov 2023 00:57:28 +0700 Subject: [PATCH 055/352] #535 add input/output metadata property, started work on generate with metadata --- .../gradle/MultiplatformResourcesPlugin.kt | 40 ++++--- .../gradle/generator/AssetsGenerator.kt | 3 + .../icerock/gradle/generator/BaseGenerator.kt | 57 +++++++-- .../gradle/generator/ColorsGenerator.kt | 3 + .../gradle/generator/FilesGenerator.kt | 3 + .../gradle/generator/FontsGenerator.kt | 3 + .../gradle/generator/ImagesGenerator.kt | 3 + .../icerock/gradle/generator/LanguageType.kt | 2 +- .../icerock/gradle/generator/MRGenerator.kt | 3 + .../gradle/generator/StringsGenerator.kt | 2 +- .../gradle/generator/TargetMRGenerator.kt | 112 +++++++++--------- .../generator/common/CommonMRGenerator.kt | 48 ++++++-- .../gradle/metadata/GeneratedObject.kt | 2 +- .../gradle/metadata/GeneratedProperties.kt | 2 +- .../dev/icerock/gradle/metadata/Metadata.kt | 8 +- .../GenerateMultiplatformResourcesTask.kt | 14 +++ 16 files changed, 207 insertions(+), 98 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 9e898c4c4..6fec0b475 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -22,6 +22,7 @@ import dev.icerock.gradle.generator.ResourceGeneratorFeature import dev.icerock.gradle.generator.StringsGenerator import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.utils.dependsOnObservable +import dev.icerock.gradle.utils.kotlinSourceSetsObservable import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.file.SourceDirectorySet @@ -68,7 +69,10 @@ open class MultiplatformResourcesPlugin : Plugin { mrExtension: MultiplatformResourcesPluginExtension, kmpExtension: KotlinMultiplatformExtension, ) { + kmpExtension.sourceSets.configureEach { kotlinSourceSet: KotlinSourceSet -> + project.logger.warn("i kmpExtension.sourceSets: ${kotlinSourceSet.name}") + val resourcesSourceDirectory: SourceDirectorySet = createMokoResourcesSourceSet( project = project, kotlinSourceSet = kotlinSourceSet @@ -101,25 +105,25 @@ open class MultiplatformResourcesPlugin : Plugin { project.logger.warn("i target ${target.targetName}") target.compilations.configureEach { compilation -> - val sourceSet: KotlinSourceSet = compilation.defaultSourceSet - val genTask: TaskProvider = requireNotNull( - sourceSet.extras[mokoResourcesGenTaskKey()] - ) - genTask.configure { - project.logger.warn("i configure platformName ${target.platformType.name}") + compilation.kotlinSourceSetsObservable.forAll { sourceSet -> + project.logger.warn("i compilation kotlinSourceSets: $sourceSet") - it.platformType.set(target.platformType.name) + project.logger.warn(("i compilationSourceSet: $sourceSet")) - project.logger.warn("i configure it.platformType = ${it.platformType.get()}") + val genTask: TaskProvider = requireNotNull( + sourceSet.extras[mokoResourcesGenTaskKey()] + ) - if (target is KotlinNativeTarget) { - it.konanTarget.set(target.konanTarget.name) + genTask.configure { + project.logger.warn("i configure platformName ${target.platformType.name}") + + it.platformType.set(target.platformType.name) } - } - compilation.compileTaskProvider.configure { - it.dependsOn(genTask) + compilation.compileTaskProvider.configure { + it.dependsOn(genTask) + } } } } @@ -357,8 +361,14 @@ open class MultiplatformResourcesPlugin : Plugin { dependsSourceSet.extras[mokoResourcesGenTaskKey()] ) - genTask.configure { - it.dependsOn(dependsGenTask) + genTask.configure { resourceTask -> + resourceTask.dependsOn(dependsGenTask) //TODO: Убрать после реализации связи через метадату + + resourceTask.inputMetadataFile.set( + dependsGenTask.flatMap { + it.outputMetadataFile + } + ) } } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt index f10c17edb..6e7ee244a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt @@ -14,6 +14,7 @@ import dev.icerock.gradle.generator.apple.AppleAssetsGenerator import dev.icerock.gradle.generator.common.CommonAssetsGenerator import dev.icerock.gradle.generator.js.JsAssetsGenerator import dev.icerock.gradle.generator.jvm.JvmAssetsGenerator +import dev.icerock.gradle.metadata.GeneratedObject import org.gradle.api.file.FileTree import java.io.File @@ -86,6 +87,8 @@ abstract class AssetsGenerator( } override fun generate( + metadata: List, + typeSpecIsInterface: Boolean, assetsGenerationDir: File, resourcesGenerationDir: File, objectBuilder: TypeSpec.Builder diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt index a1389c4f6..5a016ed99 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt @@ -7,15 +7,19 @@ package dev.icerock.gradle.generator import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.PropertySpec +import com.squareup.kotlinpoet.PropertySpec.Builder import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.metadata.GeneratedObject import java.io.File abstract class BaseGenerator : MRGenerator.Generator { override fun generate( + metadata: List, + typeSpecIsInterface: Boolean, assetsGenerationDir: File, resourcesGenerationDir: File, - objectBuilder: TypeSpec.Builder + objectBuilder: TypeSpec.Builder, ): TypeSpec { // language - key - value val languageMap: Map> = loadLanguageMap() @@ -23,7 +27,12 @@ abstract class BaseGenerator : MRGenerator.Generator { beforeGenerateResources(objectBuilder, languageMap) - val stringsClass = createTypeSpec(languageKeyValues.keys.toList(), objectBuilder) + val stringsClass = createTypeSpec( + metadata = metadata, + typeSpecIsInterface = typeSpecIsInterface, + keys = languageKeyValues.keys.toList(), + objectBuilder = objectBuilder + ) languageMap.forEach { (language, strings) -> generateResources(resourcesGenerationDir, language, strings) @@ -33,19 +42,31 @@ abstract class BaseGenerator : MRGenerator.Generator { } @Suppress("SpreadOperator") - private fun createTypeSpec(keys: List, objectBuilder: TypeSpec.Builder): TypeSpec { + private fun createTypeSpec( + metadata: List = emptyList(), + typeSpecIsInterface: Boolean, + keys: List, + objectBuilder: TypeSpec.Builder, + ): TypeSpec { objectBuilder.addModifiers(*getClassModifiers()) extendObjectBodyAtStart(objectBuilder) keys.forEach { key -> val name = key.replace(".", "_") - val property = - PropertySpec.builder(name, resourceClassName) - property.addModifiers(*getPropertyModifiers()) - getPropertyInitializer( - key - )?.let { property.initializer(it) } + val property: Builder = PropertySpec.builder(name, resourceClassName) + + if (!typeSpecIsInterface) { + property + .addModifiers(*getPropertyModifiers()) + + addOverrideModifier(property, metadata) + + getPropertyInitializer( + key + )?.let { property.initializer(it) } + } + objectBuilder.addProperty(property.build()) } @@ -53,6 +74,17 @@ abstract class BaseGenerator : MRGenerator.Generator { return objectBuilder.build() } + private fun addActualOverrideModifier( + property: PropertySpec.Builder, + metadata: List, + ) { + + + property + .addModifiers(KModifier.OVERRIDE) + + } + protected abstract fun loadLanguageMap(): Map> protected abstract fun getPropertyInitializer(key: String): CodeBlock? @@ -61,15 +93,14 @@ abstract class BaseGenerator : MRGenerator.Generator { protected open fun beforeGenerateResources( objectBuilder: TypeSpec.Builder, - languageMap: Map> + languageMap: Map>, ) = Unit protected open fun generateResources( resourcesGenerationDir: File, language: LanguageType, - strings: Map - ) { - } + strings: Map, + ) = Unit protected companion object { const val BASE_LANGUAGE = "base" diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt index a3b4b7d16..ba026d751 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt @@ -14,6 +14,7 @@ import dev.icerock.gradle.generator.apple.AppleColorsGenerator import dev.icerock.gradle.generator.common.CommonColorsGenerator import dev.icerock.gradle.generator.js.JsColorsGenerator import dev.icerock.gradle.generator.jvm.JvmColorsGenerator +import dev.icerock.gradle.metadata.GeneratedObject import org.gradle.api.file.FileTree import org.w3c.dom.Node import org.w3c.dom.NodeList @@ -36,6 +37,8 @@ abstract class ColorsGenerator( @Suppress("SpreadOperator") override fun generate( + metadata: List, + typeSpecIsInterface: Boolean, assetsGenerationDir: File, resourcesGenerationDir: File, objectBuilder: TypeSpec.Builder, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt index 08031f2a0..68a3a8e4d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt @@ -14,6 +14,7 @@ import dev.icerock.gradle.generator.apple.AppleFilesGenerator import dev.icerock.gradle.generator.common.CommonFilesGenerator import dev.icerock.gradle.generator.js.JsFilesGenerator import dev.icerock.gradle.generator.jvm.JvmFilesGenerator +import dev.icerock.gradle.metadata.GeneratedObject import org.gradle.api.file.FileTree import java.io.File @@ -26,6 +27,8 @@ abstract class FilesGenerator( override val mrObjectName: String = "files" override fun generate( + metadata: List, + typeSpecIsInterface: Boolean, assetsGenerationDir: File, resourcesGenerationDir: File, objectBuilder: TypeSpec.Builder diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt index 62caa8f4d..88422287e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt @@ -14,6 +14,7 @@ import dev.icerock.gradle.generator.apple.AppleFontsGenerator import dev.icerock.gradle.generator.common.CommonFontsGenerator import dev.icerock.gradle.generator.js.JsFontsGenerator import dev.icerock.gradle.generator.jvm.JvmFontsGenerator +import dev.icerock.gradle.metadata.GeneratedObject import dev.icerock.gradle.utils.decapitalize import org.gradle.api.file.FileTree import java.io.File @@ -27,6 +28,8 @@ abstract class FontsGenerator( override val mrObjectName: String = "fonts" override fun generate( + metadata: List, + typeSpecIsInterface: Boolean, assetsGenerationDir: File, resourcesGenerationDir: File, objectBuilder: TypeSpec.Builder diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt index 814aa73ec..614f2200e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt @@ -14,6 +14,7 @@ import dev.icerock.gradle.generator.apple.AppleImagesGenerator import dev.icerock.gradle.generator.common.CommonImagesGenerator import dev.icerock.gradle.generator.js.JsImagesGenerator import dev.icerock.gradle.generator.jvm.JvmImagesGenerator +import dev.icerock.gradle.metadata.GeneratedObject import dev.icerock.gradle.utils.withoutScale import org.gradle.api.file.FileTree import org.gradle.api.logging.Logger @@ -30,6 +31,8 @@ abstract class ImagesGenerator( override val mrObjectName: String = "images" override fun generate( + metadata: List, + typeSpecIsInterface: Boolean, assetsGenerationDir: File, resourcesGenerationDir: File, objectBuilder: TypeSpec.Builder diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/LanguageType.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/LanguageType.kt index 9b70945f5..30d75eabe 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/LanguageType.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/LanguageType.kt @@ -45,7 +45,7 @@ sealed interface LanguageType { override val jvmResourcesSuffix: String = "_${toLocaleString()}" /** - * Throw an error here so that we safeguard ourselves from implcitly calling `Local.toString`. + * Throw an error here so that we safeguard ourselves from implicitly calling `Local.toString`. * You should always use the more explicit methods defined above. */ override fun toString(): String = TODO("Use toLocaleString or toBcpString instead!") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt index 8433991f4..d2e7cbf77 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt @@ -9,6 +9,7 @@ import com.squareup.kotlinpoet.FileSpec import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.MRVisibility +import dev.icerock.gradle.metadata.GeneratedObject import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import org.gradle.api.Project import org.gradle.api.file.Directory @@ -80,6 +81,8 @@ abstract class MRGenerator( val inputFiles: Iterable fun generate( + metadata: List = emptyList(), + typeSpecIsInterface: Boolean = false, assetsGenerationDir: File, resourcesGenerationDir: File, objectBuilder: TypeSpec.Builder, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt index fcb84fe8b..71dbcbbc1 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt @@ -25,7 +25,7 @@ abstract class StringsGenerator( ) : BaseGenerator() { override val inputFiles: Iterable - get() = (lowerStringsFileTree + ownStringsFileTree).matching { + get() = ownStringsFileTree.matching { it.include(STRINGS_MASK) }.files diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt index fd4eec3b9..54e8a6e06 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt @@ -28,14 +28,25 @@ abstract class TargetMRGenerator( override fun generateFileSpec(): FileSpec? { val visibilityModifier: KModifier = settings.visibility.toModifier() + val inputMetadata: MutableList = mutableListOf() //Read list of generated resources on previous level - val inputMetadata: List = readInputMetadata( - buildDir = project.buildDir, - sourceSetName = settings.lowerResourcesFileTree.files.first().targetName - ) -// TODO: Check need of this for empty resources targets -// if (hasNoResourcesForGenerator(inputMetadata)) return null + if (settings.lowerResourcesFileTree.files.isNotEmpty()) { + inputMetadata.addAll( + readInputMetadata( + inputMetadataFile = project.buildDir, + sourceSetName = settings.lowerResourcesFileTree.files.firstOrNull()?.targetName + ?: throw Exception("Lower resources is empty") + ) + ) + } + + inputMetadata.forEach { + logger.warn("i prev: $it") + } + + // TODO: Check need of this for empty resources targets + // if (hasNoResourcesForGenerator(inputMetadata)) return null val fileSpec: FileSpec.Builder = FileSpec.builder( packageName = settings.packageName, @@ -44,12 +55,6 @@ abstract class TargetMRGenerator( val generatedObjects = mutableListOf() - inputMetadata.forEach { - logger.warn("i prev: $it") - } - - logger.warn("i mrClassSpec") - @Suppress("SpreadOperator") val mrClassSpec = TypeSpec.objectBuilder(settings.className) // default: object MR .addModifiers(KModifier.ACTUAL) @@ -69,38 +74,30 @@ abstract class TargetMRGenerator( it.modifier == GeneratedObjectModifier.EXPECT } - //Add actual implementation of expect interfaces from previous level - generateActualInterface( - visibilityModifier = settings.visibility.toModifier(), - generatedObjectsList = generatedObjects, - fileSpec = fileSpec - ) - - generatedObjects.forEach { - logger.warn("i generated objects item: ${it.name}") - } - - //Implementation not realised expect interfaces - expectInterfacesList.forEach { expectInterface -> - val hasInGeneratedActualObjects = generatedObjects.firstOrNull { - it.name == expectInterface.name - } != null - - logger.warn("i has in generatedObjects: $hasInGeneratedActualObjects") + // Add actual implementation of expect interfaces from previous levels + if (inputMetadata.isNotEmpty()) { + generateActualInterface( + visibilityModifier = settings.visibility.toModifier(), + generatedObjectsList = generatedObjects, + fileSpec = fileSpec + ) - if (hasInGeneratedActualObjects) return@forEach + // Generation of actual interfaces not realised on current level + expectInterfacesList.forEach { expectInterface -> + val hasInGeneratedActualObjects = generatedObjects.firstOrNull { + it.name == expectInterface.name + } != null - val resourcesInterface: TypeSpec = - TypeSpec.interfaceBuilder(expectInterface.name) - .addModifiers(visibilityModifier) - .addModifiers(KModifier.ACTUAL) - .build() + if (hasInGeneratedActualObjects) return@forEach - fileSpec.addType(resourcesInterface) - } + val resourcesInterface: TypeSpec = + TypeSpec.interfaceBuilder(expectInterface.name) + .addModifiers(visibilityModifier) + .addModifiers(KModifier.ACTUAL) + .build() - expectInterfacesList.forEach { - logger.warn("i expectInterfacesList item: $it") + fileSpec.addType(resourcesInterface) + } } generators.forEach { generator -> @@ -108,6 +105,8 @@ abstract class TargetMRGenerator( .objectBuilder(generator.mrObjectName) .addModifiers(visibilityModifier) + // Implement to object expect interfaces from previous + // levels of resources expectInterfacesList.forEach { generatedObject: GeneratedObject -> builder.addSuperinterface( ClassName( @@ -119,9 +118,9 @@ abstract class TargetMRGenerator( mrClassSpec.addType( generator.generate( - assetsGenerationDir, - resourcesGenerationDir, - builder + assetsGenerationDir = assetsGenerationDir, + resourcesGenerationDir = resourcesGenerationDir, + objectBuilder = builder, ) ) } @@ -132,8 +131,9 @@ abstract class TargetMRGenerator( fileSpec.addType(mrClass) createOutputMetadata( - buildDir = project.buildDir, - sourceSetName = settings.ownResourcesFileTree.first().targetName, + outputMetadataFile = project.buildDir, + sourceSetName = settings.ownResourcesFileTree.firstOrNull()?.targetName + ?: "unknownTarget", generatedObjects = generatedObjects ) @@ -150,18 +150,20 @@ abstract class TargetMRGenerator( generatedObjectsList: MutableList, fileSpec: FileSpec.Builder, ) { - logger.warn("i res") settings.lowerResourcesFileTree.forEach { - logger.warn("i lowerResourcesFileTree file: $it") + logger.warn("i generateActualInterface lowerResourcesFileTree file: $it") } settings.upperResourcesFileTree.forEach { - logger.warn("i upperResourcesFileTree file: $it") + logger.warn("i generateActualInterface upperResourcesFileTree file: $it") } settings.ownResourcesFileTree.forEach { - logger.warn("i ownResourcesFileTree file: $it") + logger.warn("i generateActualInterface ownResourcesFileTree file: $it") } - val targetName = - settings.ownResourcesFileTree.files.firstOrNull()?.targetName ?: "androidMain" + + if (settings.ownResourcesFileTree.files.isEmpty()) return + + val targetName: String = + settings.ownResourcesFileTree.files.firstOrNull()?.targetName ?: return generators.forEach { generator -> val interfaceName = getInterfaceName( @@ -174,9 +176,11 @@ abstract class TargetMRGenerator( .addModifiers(visibilityModifier) val generatedResources: TypeSpec = generator.generate( - assetsGenerationDir, - resourcesGenerationDir, - resourcesInterfaceBuilder + metadata = generatedObjectsList, + typeSpecIsInterface = true, + assetsGenerationDir = assetsGenerationDir, + resourcesGenerationDir = resourcesGenerationDir, + objectBuilder = resourcesInterfaceBuilder ) generatedObjectsList.add( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index 3ab00d875..65e9ea248 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -15,6 +15,7 @@ import dev.icerock.gradle.metadata.GeneratedObject import dev.icerock.gradle.metadata.GeneratedObjectModifier import dev.icerock.gradle.metadata.GeneratedObjectType import dev.icerock.gradle.metadata.GeneratedProperties +import dev.icerock.gradle.metadata.Metadata import dev.icerock.gradle.metadata.Metadata.createOutputMetadata import dev.icerock.gradle.metadata.getInterfaceName import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask @@ -58,6 +59,23 @@ class CommonMRGenerator( override fun generateFileSpec(): FileSpec? { if (settings.ownResourcesFileTree.files.isEmpty()) return null + val inputMetadata: MutableList = mutableListOf() + + //Read list of generated resources on previous level + if (settings.lowerResourcesFileTree.files.isNotEmpty()) { + inputMetadata.addAll( + Metadata.readInputMetadata( + inputMetadataFile = project.buildDir, + sourceSetName = settings.lowerResourcesFileTree.files.firstOrNull()?.targetName + ?: throw Exception("Lower resources is empty") + ) + ) + } + + inputMetadata.forEach { + logger.warn("i prev: $it") + } + val visibilityModifier: KModifier = settings.visibility.toModifier() val generatedObjectsList = mutableListOf() @@ -79,7 +97,8 @@ class CommonMRGenerator( // need to generate actual interface with fields generateActualInterfacesFileSpec( visibilityModifier = visibilityModifier, - generatedObjectsList = generatedObjectsList, + generatedObjects = generatedObjectsList, + inputMetadata = inputMetadata, fileSpec = fileSpec ) } @@ -92,7 +111,7 @@ class CommonMRGenerator( } createOutputMetadata( - buildDir = project.buildDir, + outputMetadataFile = project.buildDir, sourceSetName = settings.ownResourcesFileTree.first().targetName, generatedObjects = generatedObjectsList ) @@ -204,7 +223,8 @@ class CommonMRGenerator( private fun generateActualInterfacesFileSpec( visibilityModifier: KModifier, - generatedObjectsList: MutableList, + inputMetadata: MutableList, + generatedObjects: MutableList, fileSpec: Builder, ) { val targetName = settings.ownResourcesFileTree.files.first().targetName @@ -221,12 +241,14 @@ class CommonMRGenerator( .addModifiers(KModifier.ACTUAL) val generatedResources: TypeSpec = generator.generate( - assetsGenerationDir, - resourcesGenerationDir, - resourcesInterfaceBuilder + metadata = generatedObjects, + typeSpecIsInterface = true, + assetsGenerationDir = assetsGenerationDir, + resourcesGenerationDir = resourcesGenerationDir, + objectBuilder = resourcesInterfaceBuilder, ) - generatedObjectsList.add( + generatedObjects.add( GeneratedObject( name = interfaceName, type = GeneratedObjectType.INTERFACE, @@ -237,10 +259,20 @@ class CommonMRGenerator( fileSpec.addType(generatedResources) } + + inputMetadata.forEach { metadata -> + val hasInGeneratedActual = generatedObjects.firstOrNull { actualMetadata -> + metadata.name == actualMetadata.name + } != null + + if (!hasInGeneratedActual) { + generatedObjects.add(metadata) + } + } } } -fun List.toGeneratedVariables() : List { +fun List.toGeneratedVariables(): List { return map { GeneratedProperties( name = it.name, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt index 189fb56e8..5a10af9e0 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt @@ -4,9 +4,9 @@ import kotlinx.serialization.Serializable @Serializable data class GeneratedObject( + val modifier: GeneratedObjectModifier, val type: GeneratedObjectType, val name: String, - val modifier: GeneratedObjectModifier, val properties: List, ) { val objectSpec: String diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperties.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperties.kt index fe18bfe31..fb1156606 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperties.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperties.kt @@ -4,6 +4,6 @@ import kotlinx.serialization.Serializable @Serializable data class GeneratedProperties( - val name: String, val modifier: GeneratedObjectModifier, + val name: String, ) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt index 6795a20c6..093048663 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt @@ -9,13 +9,13 @@ object Metadata { private const val DIRECTORY = "generated/moko-resources/metadata" fun createOutputMetadata( - buildDir: File, + outputMetadataFile: File, sourceSetName: String, generatedObjects: List, ) { if (generatedObjects.isEmpty()) return - val metadataDir = File(buildDir, DIRECTORY).apply { + val metadataDir = File(outputMetadataFile, DIRECTORY).apply { mkdirs() } val metadataFile = File(metadataDir, "$sourceSetName-metadata.json") @@ -27,10 +27,10 @@ object Metadata { } fun readInputMetadata( - buildDir: File, + inputMetadataFile: File, sourceSetName: String, ): List { - val metadataDir = File(buildDir, DIRECTORY) + val metadataDir = File(inputMetadataFile, DIRECTORY) val inputMetadata = File(metadataDir, "$sourceSetName-metadata.json") val bufferedReader: BufferedReader = File(inputMetadata.toURI()).bufferedReader() val inputString: String = bufferedReader.use { it.readText() } 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 91aabd890..184c0e209 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 @@ -18,13 +18,18 @@ import dev.icerock.gradle.utils.isStrictLineBreaks import org.gradle.api.DefaultTask import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.DirectoryProperty +import org.gradle.api.file.RegularFileProperty import org.gradle.api.provider.Property import org.gradle.api.tasks.CacheableTask import org.gradle.api.tasks.Classpath import org.gradle.api.tasks.Input +import org.gradle.api.tasks.InputFile import org.gradle.api.tasks.InputFiles import org.gradle.api.tasks.Optional import org.gradle.api.tasks.OutputDirectory +import org.gradle.api.tasks.OutputFile +import org.gradle.api.tasks.PathSensitive +import org.gradle.api.tasks.PathSensitivity import org.gradle.api.tasks.TaskAction import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import org.jetbrains.kotlin.konan.target.KonanTarget @@ -64,6 +69,15 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { @get:Input abstract val resourcesVisibility: Property + @get:OutputFile + @get:Optional + abstract val outputMetadataFile: RegularFileProperty + + @get:PathSensitive(PathSensitivity.ABSOLUTE) + @get:InputFile + @get:Optional + abstract val inputMetadataFile: RegularFileProperty + //TODO Realise // @get:OutputFile // abstract val generationReport: RegularFileProperty From 66cb9b3d43eae1d1d10626fe72063e2f7629a0a7 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Tue, 5 Dec 2023 08:10:22 +0700 Subject: [PATCH 056/352] #535 add generator type in metadata, input/output tasks result, started rework generate task --- .../gradle/MultiplatformResourcesPlugin.kt | 50 +++--- .../gradle/generator/AssetsGenerator.kt | 12 +- .../icerock/gradle/generator/BaseGenerator.kt | 99 +++++++++-- .../gradle/generator/ColorsGenerator.kt | 12 +- .../gradle/generator/FilesGenerator.kt | 12 +- .../gradle/generator/FontsGenerator.kt | 12 +- .../gradle/generator/ImagesGenerator.kt | 12 +- .../icerock/gradle/generator/MRGenerator.kt | 12 +- .../gradle/generator/PluralsGenerator.kt | 7 +- .../gradle/generator/StringsGenerator.kt | 7 +- .../gradle/generator/TargetMRGenerator.kt | 154 ++++++++++-------- .../generator/common/CommonColorsGenerator.kt | 1 + .../generator/common/CommonFilesGenerator.kt | 1 + .../generator/common/CommonFontsGenerator.kt | 2 +- .../generator/common/CommonMRGenerator.kt | 126 +++++++------- .../gradle/metadata/GeneratedObject.kt | 10 +- .../metadata/GeneratedObjectModifier.kt | 5 +- .../gradle/metadata/GeneratedObjectType.kt | 4 +- .../gradle/metadata/GeneratedProperties.kt | 1 + .../icerock/gradle/metadata/GeneratorType.kt | 12 ++ .../dev/icerock/gradle/metadata/Metadata.kt | 35 ++-- .../GenerateMultiplatformResourcesTask.kt | 10 +- 22 files changed, 367 insertions(+), 229 deletions(-) create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratorType.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 6fec0b475..258a4c2cf 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -23,6 +23,7 @@ import dev.icerock.gradle.generator.StringsGenerator import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.utils.dependsOnObservable import dev.icerock.gradle.utils.kotlinSourceSetsObservable +import java.io.File import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.file.SourceDirectorySet @@ -40,7 +41,6 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinTarget import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.konan.target.KonanTarget import org.jetbrains.kotlin.tooling.core.extrasKeyOf -import java.io.File open class MultiplatformResourcesPlugin : Plugin { @@ -196,25 +196,25 @@ open class MultiplatformResourcesPlugin : Plugin { val androidSourceSet: com.android.build.gradle.api.AndroidSourceSet? = androidExtension?.sourceSets?.getByName(SourceSet.MAIN_SOURCE_SET_NAME) - if (commonSourceSet != null) { - setupKotlinSourceSet( - project = project, - kotlinSourceSet = commonSourceSet, - ) - } - - if (androidSourceSet != null) { - setupAndroidSourceSet( - project = project, - androidSourceSet = androidSourceSet - ) - } - - kmpExtension.sourceSets.configureEach { kotlinSourceSet -> - setupKotlinSourceSet( - project = project, - kotlinSourceSet = kotlinSourceSet, - ) + when { + commonSourceSet != null -> { + setupKotlinSourceSet( + project = project, + kotlinSourceSet = commonSourceSet, + ) + } + androidSourceSet != null -> { + setupAndroidSourceSet( + project = project, + androidSourceSet = androidSourceSet + ) + } + else -> kmpExtension.sourceSets.configureEach { kotlinSourceSet -> + setupKotlinSourceSet( + project = project, + kotlinSourceSet = kotlinSourceSet, + ) + } } } @@ -299,7 +299,12 @@ open class MultiplatformResourcesPlugin : Plugin { generateTask.resourcesClassName.set(mrExtension.resourcesClassName) generateTask.resourcesPackageName.set(mrExtension.resourcesPackage) generateTask.resourcesVisibility.set(mrExtension.resourcesVisibility) - + generateTask.outputMetadataFile.set( + File( + File(project.buildDir, "generated/moko-resources/metadata"), + "${kotlinSourceSet.name}-metadata.json" + ) + ) generateTask.outputDirectory.set( File(File(project.buildDir, "generated/moko-resources"), kotlinSourceSet.name) ) @@ -364,7 +369,8 @@ open class MultiplatformResourcesPlugin : Plugin { genTask.configure { resourceTask -> resourceTask.dependsOn(dependsGenTask) //TODO: Убрать после реализации связи через метадату - resourceTask.inputMetadataFile.set( + // Заменить на список файлов + resourceTask.inputMetadataFiles.setFrom( dependsGenTask.flatMap { it.outputMetadataFile } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt index 6e7ee244a..7fb95ac20 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt @@ -15,8 +15,9 @@ import dev.icerock.gradle.generator.common.CommonAssetsGenerator import dev.icerock.gradle.generator.js.JsAssetsGenerator import dev.icerock.gradle.generator.jvm.JvmAssetsGenerator import dev.icerock.gradle.metadata.GeneratedObject -import org.gradle.api.file.FileTree +import dev.icerock.gradle.metadata.GeneratorType import java.io.File +import org.gradle.api.file.FileTree @Suppress("TooManyFunctions") abstract class AssetsGenerator( @@ -27,6 +28,8 @@ abstract class AssetsGenerator( override val mrObjectName: String = ASSETS_DIR_NAME override val resourceClassName = ClassName("dev.icerock.moko.resources", "AssetResource") + override val type: GeneratorType = GeneratorType.Assets + private fun getBaseDir(file: File): String { val relativePathToAssets = file.path.substringAfterLast(ASSETS_DIR_NAME) val fixedRelativePath = File(relativePathToAssets).path @@ -87,11 +90,12 @@ abstract class AssetsGenerator( } override fun generate( - metadata: List, - typeSpecIsInterface: Boolean, + inputMetadata: MutableList, + generatedObjects: MutableList, + targetObject: GeneratedObject, assetsGenerationDir: File, resourcesGenerationDir: File, - objectBuilder: TypeSpec.Builder + objectBuilder: TypeSpec.Builder, ): TypeSpec { val rootContent = parseRootContent(fileTree.files) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt index 5a016ed99..ea3e143a1 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt @@ -10,13 +10,19 @@ import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.PropertySpec.Builder import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.metadata.GeneratedObject +import dev.icerock.gradle.metadata.GeneratedObjectModifier.Actual +import dev.icerock.gradle.metadata.GeneratedObjectModifier.Expect +import dev.icerock.gradle.metadata.GeneratedObjectModifier.None +import dev.icerock.gradle.metadata.GeneratedObjectType +import dev.icerock.gradle.metadata.GeneratedProperties import java.io.File abstract class BaseGenerator : MRGenerator.Generator { override fun generate( - metadata: List, - typeSpecIsInterface: Boolean, + inputMetadata: MutableList, + generatedObjects: MutableList, + targetObject: GeneratedObject, assetsGenerationDir: File, resourcesGenerationDir: File, objectBuilder: TypeSpec.Builder, @@ -25,11 +31,15 @@ abstract class BaseGenerator : MRGenerator.Generator { val languageMap: Map> = loadLanguageMap() val languageKeyValues = languageMap[LanguageType.Base].orEmpty() + // Добавить входящие ресурсы из метаданных + // + чтение своих ресурсов отдельно, как было + beforeGenerateResources(objectBuilder, languageMap) val stringsClass = createTypeSpec( - metadata = metadata, - typeSpecIsInterface = typeSpecIsInterface, + inputMetadata = inputMetadata, + generatedObjects = generatedObjects, + targetObject = targetObject, keys = languageKeyValues.keys.toList(), objectBuilder = objectBuilder ) @@ -43,8 +53,9 @@ abstract class BaseGenerator : MRGenerator.Generator { @Suppress("SpreadOperator") private fun createTypeSpec( - metadata: List = emptyList(), - typeSpecIsInterface: Boolean, + inputMetadata: MutableList, + generatedObjects: MutableList, + targetObject: GeneratedObject, keys: List, objectBuilder: TypeSpec.Builder, ): TypeSpec { @@ -52,37 +63,91 @@ abstract class BaseGenerator : MRGenerator.Generator { extendObjectBodyAtStart(objectBuilder) + val generatedProperties = mutableListOf() + keys.forEach { key -> val name = key.replace(".", "_") - val property: Builder = PropertySpec.builder(name, resourceClassName) - if (!typeSpecIsInterface) { - property - .addModifiers(*getPropertyModifiers()) + var generatedProperty = GeneratedProperties( + modifier = None, + name = name, + data = "" + ) - addOverrideModifier(property, metadata) + val property: Builder = PropertySpec.builder(name, resourceClassName) - getPropertyInitializer( - key - )?.let { property.initializer(it) } + if (targetObject.type == GeneratedObjectType.Object) { + generatedProperty = generatedProperty.copy( + modifier = if (getPropertyModifiers().contains(KModifier.ACTUAL)) { + Actual + } else { + Expect + } + ) + + addActualOverrideModifier( + propertyName = name, + property = property, + inputMetadata = inputMetadata, + targetObject = targetObject + ) + + getPropertyInitializer(key)?.let { + property.initializer(it) + } } objectBuilder.addProperty(property.build()) + + generatedProperties.add(generatedProperty) } extendObjectBodyAtEnd(objectBuilder) + + generatedObjects.add( + targetObject.copy( + properties = generatedProperties + ) + ) + return objectBuilder.build() } private fun addActualOverrideModifier( + propertyName: String, property: PropertySpec.Builder, - metadata: List, + inputMetadata: List, + targetObject: GeneratedObject ) { + val actualInterfaces = (inputMetadata).filter { + it.type == GeneratedObjectType.Interface + && it.modifier == Actual + && it.generatorType == targetObject.generatorType + } + var containsInActualInterfaces = false - property - .addModifiers(KModifier.OVERRIDE) + actualInterfaces.forEach { genInterface -> + val hasInInterface = genInterface.properties.any { + it.name == propertyName + } + if (hasInInterface) { + containsInActualInterfaces = true + } + } + + if (targetObject.type == GeneratedObjectType.Object) { + if (containsInActualInterfaces) { + property.addModifiers(KModifier.OVERRIDE) + } else { + when (targetObject.modifier) { + Expect -> property.addModifiers(KModifier.EXPECT) + Actual -> property.addModifiers(KModifier.ACTUAL) + None -> Unit + } + } + } } protected abstract fun loadLanguageMap(): Map> diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt index ba026d751..9f80a5fae 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt @@ -15,11 +15,12 @@ import dev.icerock.gradle.generator.common.CommonColorsGenerator import dev.icerock.gradle.generator.js.JsColorsGenerator import dev.icerock.gradle.generator.jvm.JvmColorsGenerator import dev.icerock.gradle.metadata.GeneratedObject +import dev.icerock.gradle.metadata.GeneratorType +import java.io.File +import javax.xml.parsers.DocumentBuilderFactory import org.gradle.api.file.FileTree import org.w3c.dom.Node import org.w3c.dom.NodeList -import java.io.File -import javax.xml.parsers.DocumentBuilderFactory abstract class ColorsGenerator( private val colorsFileTree: FileTree, @@ -33,12 +34,15 @@ abstract class ColorsGenerator( private val colorClassName = ClassName("dev.icerock.moko.resources", "ColorResource") + override val type: GeneratorType = GeneratorType.Colors + open fun beforeGenerate(objectBuilder: TypeSpec.Builder, keys: List) {} @Suppress("SpreadOperator") override fun generate( - metadata: List, - typeSpecIsInterface: Boolean, + inputMetadata: MutableList, + generatedObjects: MutableList, + targetObject: GeneratedObject, assetsGenerationDir: File, resourcesGenerationDir: File, objectBuilder: TypeSpec.Builder, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt index 68a3a8e4d..0be0d5cba 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt @@ -15,8 +15,9 @@ import dev.icerock.gradle.generator.common.CommonFilesGenerator import dev.icerock.gradle.generator.js.JsFilesGenerator import dev.icerock.gradle.generator.jvm.JvmFilesGenerator import dev.icerock.gradle.metadata.GeneratedObject -import org.gradle.api.file.FileTree +import dev.icerock.gradle.metadata.GeneratorType import java.io.File +import org.gradle.api.file.FileTree abstract class FilesGenerator( private val inputFileTree: FileTree @@ -26,12 +27,15 @@ abstract class FilesGenerator( override val resourceClassName = ClassName("dev.icerock.moko.resources", "FileResource") override val mrObjectName: String = "files" + override val type: GeneratorType = GeneratorType.Files + override fun generate( - metadata: List, - typeSpecIsInterface: Boolean, + inputMetadata: MutableList, + generatedObjects: MutableList, + targetObject: GeneratedObject, assetsGenerationDir: File, resourcesGenerationDir: File, - objectBuilder: TypeSpec.Builder + objectBuilder: TypeSpec.Builder, ): TypeSpec { val fileSpecs = inputFileTree.map { file -> FileSpec( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt index 88422287e..5b28213fe 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt @@ -15,9 +15,10 @@ import dev.icerock.gradle.generator.common.CommonFontsGenerator import dev.icerock.gradle.generator.js.JsFontsGenerator import dev.icerock.gradle.generator.jvm.JvmFontsGenerator import dev.icerock.gradle.metadata.GeneratedObject +import dev.icerock.gradle.metadata.GeneratorType import dev.icerock.gradle.utils.decapitalize -import org.gradle.api.file.FileTree import java.io.File +import org.gradle.api.file.FileTree abstract class FontsGenerator( private val inputFileTree: FileTree @@ -27,12 +28,15 @@ abstract class FontsGenerator( override val resourceClassName = ClassName("dev.icerock.moko.resources", "FontResource") override val mrObjectName: String = "fonts" + override val type: GeneratorType = GeneratorType.Fonts + override fun generate( - metadata: List, - typeSpecIsInterface: Boolean, + inputMetadata: MutableList, + generatedObjects: MutableList, + targetObject: GeneratedObject, assetsGenerationDir: File, resourcesGenerationDir: File, - objectBuilder: TypeSpec.Builder + objectBuilder: TypeSpec.Builder, ): TypeSpec { val fontFiles = inputFileTree.map { FontFile( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt index 614f2200e..f32fcaede 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt @@ -15,10 +15,11 @@ import dev.icerock.gradle.generator.common.CommonImagesGenerator import dev.icerock.gradle.generator.js.JsImagesGenerator import dev.icerock.gradle.generator.jvm.JvmImagesGenerator import dev.icerock.gradle.metadata.GeneratedObject +import dev.icerock.gradle.metadata.GeneratorType import dev.icerock.gradle.utils.withoutScale +import java.io.File import org.gradle.api.file.FileTree import org.gradle.api.logging.Logger -import java.io.File abstract class ImagesGenerator( private val inputFileTree: FileTree @@ -30,12 +31,15 @@ abstract class ImagesGenerator( override val resourceClassName = ClassName("dev.icerock.moko.resources", "ImageResource") override val mrObjectName: String = "images" + override val type: GeneratorType = GeneratorType.Images + override fun generate( - metadata: List, - typeSpecIsInterface: Boolean, + inputMetadata: MutableList, + generatedObjects: MutableList, + targetObject: GeneratedObject, assetsGenerationDir: File, resourcesGenerationDir: File, - objectBuilder: TypeSpec.Builder + objectBuilder: TypeSpec.Builder, ): TypeSpec { val fileMap = inputFileTree.groupBy { file -> // SVGs do not have scale suffixes, so we need to remove the extension first diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt index d2e7cbf77..ed8c59d25 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt @@ -10,11 +10,12 @@ import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.MRVisibility import dev.icerock.gradle.metadata.GeneratedObject +import dev.icerock.gradle.metadata.GeneratorType import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask +import java.io.File import org.gradle.api.Project import org.gradle.api.file.Directory import org.gradle.api.file.FileTree -import java.io.File abstract class MRGenerator( protected val settings: Settings, @@ -80,9 +81,12 @@ abstract class MRGenerator( val resourceClassName: ClassName val inputFiles: Iterable + val type: GeneratorType + fun generate( - metadata: List = emptyList(), - typeSpecIsInterface: Boolean = false, + inputMetadata: MutableList, + generatedObjects: MutableList, //TODO: Remove emptyList() after complete realisation + targetObject: GeneratedObject, assetsGenerationDir: File, resourcesGenerationDir: File, objectBuilder: TypeSpec.Builder, @@ -100,6 +104,8 @@ abstract class MRGenerator( } data class Settings( + val inputMetadataFiles: FileTree, + val outputMetadataFile: File, val packageName: String, val className: String, val visibility: MRVisibility, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt index 9e53cbfa0..486076454 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt @@ -10,12 +10,13 @@ import dev.icerock.gradle.generator.apple.ApplePluralsGenerator import dev.icerock.gradle.generator.common.CommonPluralsGenerator import dev.icerock.gradle.generator.js.JsPluralsGenerator import dev.icerock.gradle.generator.jvm.JvmPluralsGenerator +import dev.icerock.gradle.metadata.GeneratorType import dev.icerock.gradle.utils.removeLineWraps +import java.io.File +import javax.xml.parsers.DocumentBuilderFactory import org.gradle.api.file.FileTree import org.w3c.dom.Document import org.w3c.dom.Element -import java.io.File -import javax.xml.parsers.DocumentBuilderFactory typealias PluralMap = Map @@ -36,6 +37,8 @@ abstract class PluralsGenerator( override val resourceClassName = ClassName("dev.icerock.moko.resources", "PluralsResource") override val mrObjectName: String = "plurals" + override val type: GeneratorType = GeneratorType.Plurals + override fun loadLanguageMap(): Map> { return pluralsFileTree.map { file -> val language: LanguageType = LanguageType.fromFileName(file.parentFile.name) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt index 71dbcbbc1..d7363d221 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt @@ -10,10 +10,11 @@ import dev.icerock.gradle.generator.apple.AppleStringsGenerator import dev.icerock.gradle.generator.common.CommonStringsGenerator import dev.icerock.gradle.generator.js.JsStringsGenerator import dev.icerock.gradle.generator.jvm.JvmStringsGenerator +import dev.icerock.gradle.metadata.GeneratorType import dev.icerock.gradle.utils.removeLineWraps -import org.gradle.api.file.FileTree import java.io.File import javax.xml.parsers.DocumentBuilderFactory +import org.gradle.api.file.FileTree typealias KeyType = String @@ -25,13 +26,15 @@ abstract class StringsGenerator( ) : BaseGenerator() { override val inputFiles: Iterable - get() = ownStringsFileTree.matching { + get() = (ownStringsFileTree).matching { it.include(STRINGS_MASK) }.files override val resourceClassName = ClassName("dev.icerock.moko.resources", "StringResource") override val mrObjectName: String = "strings" + override val type: GeneratorType = GeneratorType.Strings + override fun loadLanguageMap(): Map> { return inputFiles.map { file -> val language: LanguageType = LanguageType.fromFileName(file.parentFile.name) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt index 54e8a6e06..7163c7102 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt @@ -4,10 +4,10 @@ import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.FileSpec import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.common.toGeneratedVariables import dev.icerock.gradle.metadata.GeneratedObject import dev.icerock.gradle.metadata.GeneratedObjectModifier import dev.icerock.gradle.metadata.GeneratedObjectType +import dev.icerock.gradle.metadata.GeneratorType import dev.icerock.gradle.metadata.Metadata.createOutputMetadata import dev.icerock.gradle.metadata.Metadata.readInputMetadata import dev.icerock.gradle.metadata.getInterfaceName @@ -26,69 +26,71 @@ abstract class TargetMRGenerator( ) { val logger = project.logger + override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { + val name = settings.ownResourcesFileTree.first().targetName + val genTaskName = "generateMR$name" + + val genTask = runCatching { + project.tasks.getByName(genTaskName) as GenerateMultiplatformResourcesTask + }.getOrNull() ?: project.tasks.create( + genTaskName, + GenerateMultiplatformResourcesTask::class.java + ) { + it.generate() + } + + apply(generationTask = genTask, project = project) + } + + override fun getMRClassModifiers(): Array = arrayOf(KModifier.ACTUAL) + override fun generateFileSpec(): FileSpec? { val visibilityModifier: KModifier = settings.visibility.toModifier() val inputMetadata: MutableList = mutableListOf() //Read list of generated resources on previous level - if (settings.lowerResourcesFileTree.files.isNotEmpty()) { - inputMetadata.addAll( - readInputMetadata( - inputMetadataFile = project.buildDir, - sourceSetName = settings.lowerResourcesFileTree.files.firstOrNull()?.targetName - ?: throw Exception("Lower resources is empty") - ) + inputMetadata.addAll( + readInputMetadata( + inputMetadataFiles = settings.inputMetadataFiles ) - } + ) inputMetadata.forEach { logger.warn("i prev: $it") } - // TODO: Check need of this for empty resources targets - // if (hasNoResourcesForGenerator(inputMetadata)) return null - val fileSpec: FileSpec.Builder = FileSpec.builder( packageName = settings.packageName, fileName = settings.className ) - val generatedObjects = mutableListOf() - @Suppress("SpreadOperator") val mrClassSpec = TypeSpec.objectBuilder(settings.className) // default: object MR .addModifiers(KModifier.ACTUAL) .addModifiers(visibilityModifier) // public/internal - generatedObjects.add( - GeneratedObject( - type = GeneratedObjectType.OBJECT, - name = settings.className, - modifier = GeneratedObjectModifier.ACTUAL, - properties = emptyList() - ) - ) - val expectInterfacesList: List = inputMetadata.filter { - it.type == GeneratedObjectType.INTERFACE && - it.modifier == GeneratedObjectModifier.EXPECT + it.type == GeneratedObjectType.Interface && + it.modifier == GeneratedObjectModifier.Expect } // Add actual implementation of expect interfaces from previous levels if (inputMetadata.isNotEmpty()) { generateActualInterface( + inputMetadata = inputMetadata, visibilityModifier = settings.visibility.toModifier(), - generatedObjectsList = generatedObjects, fileSpec = fileSpec ) // Generation of actual interfaces not realised on current level expectInterfacesList.forEach { expectInterface -> - val hasInGeneratedActualObjects = generatedObjects.firstOrNull { + val hasInGeneratedActualInterfaces = inputMetadata.firstOrNull { it.name == expectInterface.name + && it.type == GeneratedObjectType.Interface + && it.modifier == GeneratedObjectModifier.Actual } != null - if (hasInGeneratedActualObjects) return@forEach + if (hasInGeneratedActualInterfaces) return@forEach val resourcesInterface: TypeSpec = TypeSpec.interfaceBuilder(expectInterface.name) @@ -99,6 +101,7 @@ abstract class TargetMRGenerator( fileSpec.addType(resourcesInterface) } } + val generatedActualObjects = mutableListOf() generators.forEach { generator -> val builder: TypeSpec.Builder = TypeSpec @@ -118,6 +121,19 @@ abstract class TargetMRGenerator( mrClassSpec.addType( generator.generate( + inputMetadata = inputMetadata, + generatedObjects = generatedActualObjects, + targetObject = GeneratedObject( + generatorType = generator.type, + modifier = GeneratedObjectModifier.Actual, + type = GeneratedObjectType.Object, + name = generator.mrObjectName, + interfaces = getObjectInterfaces( + generatorType = generator.type, + objectName = generator.mrObjectName, + inputMetadata = inputMetadata + ) + ), assetsGenerationDir = assetsGenerationDir, resourcesGenerationDir = resourcesGenerationDir, objectBuilder = builder, @@ -125,16 +141,24 @@ abstract class TargetMRGenerator( ) } + inputMetadata.add( + GeneratedObject( + generatorType = GeneratorType.None, + type = GeneratedObjectType.Object, + name = settings.className, + modifier = GeneratedObjectModifier.Actual, + objects = generatedActualObjects + ) + ) + processMRClass(mrClassSpec) val mrClass = mrClassSpec.build() fileSpec.addType(mrClass) createOutputMetadata( - outputMetadataFile = project.buildDir, - sourceSetName = settings.ownResourcesFileTree.firstOrNull()?.targetName - ?: "unknownTarget", - generatedObjects = generatedObjects + outputMetadataFile = settings.outputMetadataFile, + generatedObjects = inputMetadata ) generators @@ -146,20 +170,10 @@ abstract class TargetMRGenerator( } private fun generateActualInterface( + inputMetadata: MutableList, visibilityModifier: KModifier, - generatedObjectsList: MutableList, fileSpec: FileSpec.Builder, ) { - settings.lowerResourcesFileTree.forEach { - logger.warn("i generateActualInterface lowerResourcesFileTree file: $it") - } - settings.upperResourcesFileTree.forEach { - logger.warn("i generateActualInterface upperResourcesFileTree file: $it") - } - settings.ownResourcesFileTree.forEach { - logger.warn("i generateActualInterface ownResourcesFileTree file: $it") - } - if (settings.ownResourcesFileTree.files.isEmpty()) return val targetName: String = @@ -176,44 +190,44 @@ abstract class TargetMRGenerator( .addModifiers(visibilityModifier) val generatedResources: TypeSpec = generator.generate( - metadata = generatedObjectsList, - typeSpecIsInterface = true, + inputMetadata = inputMetadata, + generatedObjects = inputMetadata, + targetObject = GeneratedObject( + generatorType = generator.type, + modifier = GeneratedObjectModifier.Actual, + type = GeneratedObjectType.Interface, + name = interfaceName + ), assetsGenerationDir = assetsGenerationDir, resourcesGenerationDir = resourcesGenerationDir, objectBuilder = resourcesInterfaceBuilder ) - generatedObjectsList.add( - GeneratedObject( - name = interfaceName, - type = GeneratedObjectType.INTERFACE, - modifier = GeneratedObjectModifier.ACTUAL, - properties = generatedResources.propertySpecs.toGeneratedVariables() - ) - ) - fileSpec.addType(generatedResources) } } - private fun hasNoResourcesForGenerator(inputMetadata: List) = - inputMetadata.isEmpty() && settings.ownResourcesFileTree.isEmpty - - override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { - val name = settings.ownResourcesFileTree.first().targetName - val genTaskName = "generateMR$name" + private fun getObjectInterfaces( + generatorType: GeneratorType, + objectName: String, + inputMetadata: List + ): List { + val interfaces = mutableListOf() + + val mrObjects: List = inputMetadata.filter { + it.type == GeneratedObjectType.Object + && it.generatorType == GeneratorType.None + && it.modifier == GeneratedObjectModifier.Expect + } - val genTask = runCatching { - project.tasks.getByName(genTaskName) as GenerateMultiplatformResourcesTask - }.getOrNull() ?: project.tasks.create( - genTaskName, - GenerateMultiplatformResourcesTask::class.java - ) { - it.generate() + mrObjects.forEach { mrObject -> + mrObject.objects.forEach { + if (it.generatorType == generatorType && it.name == objectName) { + interfaces.addAll(it.interfaces) + } + } } - apply(generationTask = genTask, project = project) + return interfaces.distinct() } - - override fun getMRClassModifiers(): Array = arrayOf(KModifier.ACTUAL) } \ No newline at end of file diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonColorsGenerator.kt index a8f2de5b8..89dffc8a1 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonColorsGenerator.kt @@ -10,6 +10,7 @@ import dev.icerock.gradle.generator.ColorNode import dev.icerock.gradle.generator.ColorsGenerator import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable +import dev.icerock.gradle.metadata.GeneratorType import org.gradle.api.file.FileTree class CommonColorsGenerator( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt index 35d0f9afd..b8698caa2 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt @@ -9,6 +9,7 @@ import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.FilesGenerator import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable +import dev.icerock.gradle.metadata.GeneratorType import org.gradle.api.file.FileTree class CommonFilesGenerator( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFontsGenerator.kt index 9b797eea2..e03c7afff 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFontsGenerator.kt @@ -9,8 +9,8 @@ import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.FontsGenerator import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable -import org.gradle.api.file.FileTree import java.io.File +import org.gradle.api.file.FileTree class CommonFontsGenerator( ownInputFileTree: FileTree, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index 65e9ea248..f53645573 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -8,13 +8,12 @@ import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.FileSpec import com.squareup.kotlinpoet.FileSpec.Builder import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.metadata.GeneratedObject import dev.icerock.gradle.metadata.GeneratedObjectModifier import dev.icerock.gradle.metadata.GeneratedObjectType -import dev.icerock.gradle.metadata.GeneratedProperties +import dev.icerock.gradle.metadata.GeneratorType.None import dev.icerock.gradle.metadata.Metadata import dev.icerock.gradle.metadata.Metadata.createOutputMetadata import dev.icerock.gradle.metadata.getInterfaceName @@ -65,9 +64,7 @@ class CommonMRGenerator( if (settings.lowerResourcesFileTree.files.isNotEmpty()) { inputMetadata.addAll( Metadata.readInputMetadata( - inputMetadataFile = project.buildDir, - sourceSetName = settings.lowerResourcesFileTree.files.firstOrNull()?.targetName - ?: throw Exception("Lower resources is empty") + inputMetadataFiles = settings.inputMetadataFiles ) ) } @@ -77,7 +74,7 @@ class CommonMRGenerator( } val visibilityModifier: KModifier = settings.visibility.toModifier() - val generatedObjectsList = mutableListOf() + val generatedObjects = mutableListOf() val fileSpec: Builder = FileSpec.builder( packageName = settings.packageName, @@ -87,9 +84,10 @@ class CommonMRGenerator( if (settings.lowerResourcesFileTree.files.isEmpty()) { // When lower resources is empty, should generate expect MR object generateExpectMRObjectFileSpec( + inputMetadata = inputMetadata, + generatedObjects = generatedObjects, resourcePackage = settings.packageName, visibilityModifier = visibilityModifier, - generatedObjectsList = generatedObjectsList, fileSpec = fileSpec ) } else { @@ -97,7 +95,7 @@ class CommonMRGenerator( // need to generate actual interface with fields generateActualInterfacesFileSpec( visibilityModifier = visibilityModifier, - generatedObjects = generatedObjectsList, + generatedObjects = generatedObjects, inputMetadata = inputMetadata, fileSpec = fileSpec ) @@ -111,18 +109,18 @@ class CommonMRGenerator( } createOutputMetadata( - outputMetadataFile = project.buildDir, - sourceSetName = settings.ownResourcesFileTree.first().targetName, - generatedObjects = generatedObjectsList + outputMetadataFile = settings.outputMetadataFile, + generatedObjects = generatedObjects ) return fileSpec.build() } private fun generateExpectMRObjectFileSpec( + inputMetadata: MutableList, + generatedObjects: MutableList, resourcePackage: String, visibilityModifier: KModifier, - generatedObjectsList: MutableList, fileSpec: Builder, ) { // generated MR class structure: @@ -131,16 +129,19 @@ class CommonMRGenerator( .addModifiers(KModifier.EXPECT) // expect/actual .addModifiers(visibilityModifier) // public/internal - generatedObjectsList.add( - GeneratedObject( - type = GeneratedObjectType.OBJECT, - name = settings.className, - modifier = GeneratedObjectModifier.EXPECT, - properties = emptyList() - ) + + var expectMRObject: GeneratedObject = GeneratedObject( + generatorType = None, + type = GeneratedObjectType.Object, + name = settings.className, + modifier = GeneratedObjectModifier.Expect, + properties = emptyList(), + objects = emptyList() ) + val generatedExpectInterfaces = mutableListOf() + val generatedExpectObjects = mutableListOf() - generators.forEach { generator -> + generators.forEach { generator: Generator -> val builder: TypeSpec.Builder = TypeSpec .objectBuilder(generator.mrObjectName) // resource name: example strings .addModifiers(visibilityModifier) // public/internal @@ -187,34 +188,55 @@ class CommonMRGenerator( ) ) - generatedObjectsList.add( + generatedExpectInterfaces.add( GeneratedObject( + generatorType = generator.type, name = interfaceName, - type = GeneratedObjectType.INTERFACE, - modifier = GeneratedObjectModifier.EXPECT, - properties = emptyList() + type = GeneratedObjectType.Interface, + modifier = GeneratedObjectModifier.Expect, ) ) } - val generatedResources = generator.generate( + val generatedResourcesTypeSpec = generator.generate( + inputMetadata = inputMetadata, + generatedObjects = generatedExpectObjects, + targetObject = GeneratedObject( + generatorType = generator.type, + modifier = GeneratedObjectModifier.Expect, + type = GeneratedObjectType.Object, + name = generator.mrObjectName, + interfaces = generatedInterfaces + ), assetsGenerationDir = assetsGenerationDir, resourcesGenerationDir = resourcesGenerationDir, objectBuilder = builder ) - generatedObjectsList.add( - GeneratedObject( - name = generator.mrObjectName, - type = GeneratedObjectType.OBJECT, - modifier = GeneratedObjectModifier.EXPECT, - properties = generatedResources.propertySpecs.toGeneratedVariables(), - ) - ) - - mrClassSpec.addType(generatedResources) +// expectMRObject = expectMRObject.copy( +// objects = expectMRObject.objects + listOf( +// GeneratedObject( +// generatorType = generator.type, +// name = generator.mrObjectName, +// type = GeneratedObjectType.Object, +// modifier = GeneratedObjectModifier.Expect, +// interfaces = generatedInterfaces, +// properties = generatedResources.propertySpecs.toGeneratedVariables(), +// ) +// ) +// ) + + mrClassSpec.addType(generatedResourcesTypeSpec) } + // Add generated objects in MR + generatedObjects.add( + expectMRObject.copy( + objects = generatedExpectObjects + ) + ) + generatedObjects.addAll(generatedExpectInterfaces) + processMRClass(mrClassSpec) val mrClass: TypeSpec = mrClassSpec.build() @@ -222,9 +244,9 @@ class CommonMRGenerator( } private fun generateActualInterfacesFileSpec( - visibilityModifier: KModifier, inputMetadata: MutableList, generatedObjects: MutableList, + visibilityModifier: KModifier, fileSpec: Builder, ) { val targetName = settings.ownResourcesFileTree.files.first().targetName @@ -241,22 +263,19 @@ class CommonMRGenerator( .addModifiers(KModifier.ACTUAL) val generatedResources: TypeSpec = generator.generate( - metadata = generatedObjects, - typeSpecIsInterface = true, + targetObject = GeneratedObject( + generatorType = generator.type, + name = interfaceName, + type = GeneratedObjectType.Interface, + modifier = GeneratedObjectModifier.Actual, + ), + inputMetadata = inputMetadata, + generatedObjects = generatedObjects, assetsGenerationDir = assetsGenerationDir, resourcesGenerationDir = resourcesGenerationDir, objectBuilder = resourcesInterfaceBuilder, ) - generatedObjects.add( - GeneratedObject( - name = interfaceName, - type = GeneratedObjectType.INTERFACE, - modifier = GeneratedObjectModifier.ACTUAL, - properties = generatedResources.propertySpecs.toGeneratedVariables() - ) - ) - fileSpec.addType(generatedResources) } @@ -271,16 +290,3 @@ class CommonMRGenerator( } } } - -fun List.toGeneratedVariables(): List { - return map { - GeneratedProperties( - name = it.name, - modifier = if (it.modifiers.contains(KModifier.ACTUAL)) { - GeneratedObjectModifier.ACTUAL - } else { - GeneratedObjectModifier.EXPECT - } - ) - } -} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt index 5a10af9e0..651cc9e86 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt @@ -4,11 +4,11 @@ import kotlinx.serialization.Serializable @Serializable data class GeneratedObject( + val generatorType: GeneratorType, val modifier: GeneratedObjectModifier, val type: GeneratedObjectType, val name: String, - val properties: List, -) { - val objectSpec: String - get() = "${modifier.value} ${type.value} $name" -} + val interfaces: List = emptyList(), + val properties: List = emptyList(), + val objects: List = emptyList() +) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObjectModifier.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObjectModifier.kt index 7b547d11b..79e2450f1 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObjectModifier.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObjectModifier.kt @@ -1,8 +1,9 @@ package dev.icerock.gradle.metadata enum class GeneratedObjectModifier(val value: String) { - EXPECT("expect"), - ACTUAL("actual"); + Expect("expect"), + Actual("actual"), + None("none"); companion object { private val VALUES = values() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObjectType.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObjectType.kt index b11bf3c10..d24d44628 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObjectType.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObjectType.kt @@ -1,8 +1,8 @@ package dev.icerock.gradle.metadata enum class GeneratedObjectType(val value: String) { - OBJECT("object"), - INTERFACE("interface"); + Object("object"), + Interface("interface"); companion object { private val VALUES = values() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperties.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperties.kt index fb1156606..9a5c843d0 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperties.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperties.kt @@ -6,4 +6,5 @@ import kotlinx.serialization.Serializable data class GeneratedProperties( val modifier: GeneratedObjectModifier, val name: String, + val data: String // Can contain data with dependencies from generator type ) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratorType.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratorType.kt new file mode 100644 index 000000000..e7d92f628 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratorType.kt @@ -0,0 +1,12 @@ +package dev.icerock.gradle.metadata + +enum class GeneratorType { + Strings, + Plurals, + Assets, + Colors, + Images, + Files, + Fonts, + None +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt index 093048663..39a9dc7eb 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt @@ -1,40 +1,39 @@ package dev.icerock.gradle.metadata -import kotlinx.serialization.encodeToString -import kotlinx.serialization.json.Json import java.io.BufferedReader import java.io.File +import kotlinx.serialization.encodeToString +import kotlinx.serialization.json.Json +import org.gradle.api.file.FileTree object Metadata { - private const val DIRECTORY = "generated/moko-resources/metadata" - fun createOutputMetadata( outputMetadataFile: File, - sourceSetName: String, generatedObjects: List, ) { if (generatedObjects.isEmpty()) return - val metadataDir = File(outputMetadataFile, DIRECTORY).apply { - mkdirs() - } - val metadataFile = File(metadataDir, "$sourceSetName-metadata.json") - metadataFile.createNewFile() + outputMetadataFile.createNewFile() val generatedJson: String = Json.encodeToString(generatedObjects) - metadataFile.writeText(generatedJson) + outputMetadataFile.writeText(generatedJson) } fun readInputMetadata( - inputMetadataFile: File, - sourceSetName: String, + inputMetadataFiles: FileTree, ): List { - val metadataDir = File(inputMetadataFile, DIRECTORY) - val inputMetadata = File(metadataDir, "$sourceSetName-metadata.json") - val bufferedReader: BufferedReader = File(inputMetadata.toURI()).bufferedReader() - val inputString: String = bufferedReader.use { it.readText() } + val generatedObjects = mutableListOf() + + inputMetadataFiles.forEach { inputFile -> + if(inputFile.isDirectory) return@forEach + + val bufferedReader: BufferedReader = File(inputFile.toURI()).bufferedReader() + val inputString: String = bufferedReader.use { it.readText() } + val inputMetadata: List = Json.decodeFromString(inputString) + generatedObjects.addAll(inputMetadata) + } - return Json.decodeFromString(inputString) + return generatedObjects } } 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 184c0e209..a2610b098 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 @@ -23,7 +23,6 @@ import org.gradle.api.provider.Property import org.gradle.api.tasks.CacheableTask import org.gradle.api.tasks.Classpath import org.gradle.api.tasks.Input -import org.gradle.api.tasks.InputFile import org.gradle.api.tasks.InputFiles import org.gradle.api.tasks.Optional import org.gradle.api.tasks.OutputDirectory @@ -70,13 +69,12 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { abstract val resourcesVisibility: Property @get:OutputFile - @get:Optional abstract val outputMetadataFile: RegularFileProperty - @get:PathSensitive(PathSensitivity.ABSOLUTE) - @get:InputFile @get:Optional - abstract val inputMetadataFile: RegularFileProperty + @get:PathSensitive(PathSensitivity.ABSOLUTE) + @get:InputFiles + abstract val inputMetadataFiles: ConfigurableFileCollection //TODO Realise // @get:OutputFile @@ -119,6 +117,8 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { private fun createGeneratorSettings(): MRGenerator.Settings { return MRGenerator.Settings( + inputMetadataFiles = inputMetadataFiles.asFileTree, + outputMetadataFile = outputMetadataFile.asFile.get(), packageName = resourcesPackageName.get(), className = resourcesClassName.get(), generatedDir = outputDirectory.get(), From 0f034c80e9478b323b745e4dc39642aa33874eb6 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Tue, 5 Dec 2023 18:18:04 +0700 Subject: [PATCH 057/352] #535 add addActual() for metadata logic, correction of output metadata --- .../icerock/gradle/generator/BaseGenerator.kt | 3 +- .../gradle/generator/TargetMRGenerator.kt | 31 +++++++++++++++---- .../icerock/gradle/metadata/MetadataExt.kt | 15 +++++++++ 3 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt index ea3e143a1..d4adef0d8 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt @@ -15,6 +15,7 @@ import dev.icerock.gradle.metadata.GeneratedObjectModifier.Expect import dev.icerock.gradle.metadata.GeneratedObjectModifier.None import dev.icerock.gradle.metadata.GeneratedObjectType import dev.icerock.gradle.metadata.GeneratedProperties +import dev.icerock.gradle.metadata.addActual import java.io.File abstract class BaseGenerator : MRGenerator.Generator { @@ -104,7 +105,7 @@ abstract class BaseGenerator : MRGenerator.Generator { extendObjectBodyAtEnd(objectBuilder) - generatedObjects.add( + generatedObjects.addActual( targetObject.copy( properties = generatedProperties ) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt index 7163c7102..1ed24d491 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt @@ -10,6 +10,7 @@ import dev.icerock.gradle.metadata.GeneratedObjectType import dev.icerock.gradle.metadata.GeneratorType import dev.icerock.gradle.metadata.Metadata.createOutputMetadata import dev.icerock.gradle.metadata.Metadata.readInputMetadata +import dev.icerock.gradle.metadata.addActual import dev.icerock.gradle.metadata.getInterfaceName import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.toModifier @@ -84,11 +85,9 @@ abstract class TargetMRGenerator( // Generation of actual interfaces not realised on current level expectInterfacesList.forEach { expectInterface -> - val hasInGeneratedActualInterfaces = inputMetadata.firstOrNull { - it.name == expectInterface.name - && it.type == GeneratedObjectType.Interface - && it.modifier == GeneratedObjectModifier.Actual - } != null + val hasInGeneratedActualInterfaces = inputMetadata.hasInActualInterfaces( + interfaceName = expectInterface.name + ) if (hasInGeneratedActualInterfaces) return@forEach @@ -98,6 +97,16 @@ abstract class TargetMRGenerator( .addModifiers(KModifier.ACTUAL) .build() + // TODO: add logic with add extract interface type + inputMetadata.addActual( + GeneratedObject( + generatorType = GeneratorType.Strings, + modifier = GeneratedObjectModifier.Actual, + type = GeneratedObjectType.Interface, + name = expectInterface.name, + ) + ) + fileSpec.addType(resourcesInterface) } } @@ -141,7 +150,7 @@ abstract class TargetMRGenerator( ) } - inputMetadata.add( + inputMetadata.addActual( GeneratedObject( generatorType = GeneratorType.None, type = GeneratedObjectType.Object, @@ -230,4 +239,14 @@ abstract class TargetMRGenerator( return interfaces.distinct() } + + private fun List.hasInActualInterfaces( + interfaceName: String + ): Boolean { + return this.firstOrNull { + it.name == interfaceName + && it.type == GeneratedObjectType.Interface + && it.modifier == GeneratedObjectModifier.Actual + } != null + } } \ No newline at end of file diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt new file mode 100644 index 000000000..59b7148cc --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt @@ -0,0 +1,15 @@ +package dev.icerock.gradle.metadata + +fun MutableList.addActual(actualObject: GeneratedObject){ + val expect: GeneratedObject? = firstOrNull { + it.name == actualObject.name + && it.generatorType == actualObject.generatorType + && it.type == actualObject.type + } + + if (expect != null){ + remove(expect) + } + + add(actualObject) +} \ No newline at end of file From d003e0b1ed679202f7d1e5a4e5af98f96d9d50d1 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Tue, 5 Dec 2023 20:22:32 +0700 Subject: [PATCH 058/352] #535 correct property modifier, data of properties --- .../gradle/MultiplatformResourcesPlugin.kt | 6 +- .../gradle/generator/AssetsGenerator.kt | 4 +- .../icerock/gradle/generator/BaseGenerator.kt | 75 ++++++++++++------- .../gradle/generator/ColorsGenerator.kt | 13 +++- .../gradle/generator/FilesGenerator.kt | 11 ++- .../gradle/generator/FontsGenerator.kt | 4 +- .../gradle/generator/ImagesGenerator.kt | 4 +- .../icerock/gradle/generator/LanguageType.kt | 8 +- .../icerock/gradle/generator/MRGenerator.kt | 3 +- .../gradle/generator/StringsGenerator.kt | 2 +- .../gradle/generator/TargetMRGenerator.kt | 36 +++------ .../android/AndroidColorsGenerator.kt | 4 +- .../android/AndroidFilesGenerator.kt | 4 +- .../generator/apple/AppleColorsGenerator.kt | 4 +- .../generator/apple/AppleFilesGenerator.kt | 4 +- .../generator/common/CommonColorsGenerator.kt | 5 +- .../generator/common/CommonFilesGenerator.kt | 5 +- .../generator/common/CommonMRGenerator.kt | 30 ++------ .../gradle/generator/js/JsColorsGenerator.kt | 4 +- .../gradle/generator/js/JsFilesGenerator.kt | 4 +- .../generator/jvm/JvmColorsGenerator.kt | 4 +- .../gradle/generator/jvm/JvmFilesGenerator.kt | 4 +- .../metadata/GeneratedObjectModifier.kt | 17 ++--- .../icerock/gradle/metadata/MetadataExt.kt | 9 ++- 24 files changed, 154 insertions(+), 110 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 258a4c2cf..d57b44d0b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -23,7 +23,6 @@ import dev.icerock.gradle.generator.StringsGenerator import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.utils.dependsOnObservable import dev.icerock.gradle.utils.kotlinSourceSetsObservable -import java.io.File import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.file.SourceDirectorySet @@ -41,6 +40,7 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinTarget import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.konan.target.KonanTarget import org.jetbrains.kotlin.tooling.core.extrasKeyOf +import java.io.File open class MultiplatformResourcesPlugin : Plugin { @@ -388,8 +388,8 @@ open class MultiplatformResourcesPlugin : Plugin { PluralsGenerator.Feature(settings), ImagesGenerator.Feature(settings, target.project.logger), FontsGenerator.Feature(settings), - FilesGenerator.Feature(settings), - ColorsGenerator.Feature(settings), + FilesGenerator.Feature(target.project, settings), + ColorsGenerator.Feature(target.project, settings), AssetsGenerator.Feature(settings) ) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt index 7fb95ac20..b1a9e5e0e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt @@ -16,8 +16,9 @@ import dev.icerock.gradle.generator.js.JsAssetsGenerator import dev.icerock.gradle.generator.jvm.JvmAssetsGenerator import dev.icerock.gradle.metadata.GeneratedObject import dev.icerock.gradle.metadata.GeneratorType -import java.io.File +import org.gradle.api.Project import org.gradle.api.file.FileTree +import java.io.File @Suppress("TooManyFunctions") abstract class AssetsGenerator( @@ -90,6 +91,7 @@ abstract class AssetsGenerator( } override fun generate( + project: Project, inputMetadata: MutableList, generatedObjects: MutableList, targetObject: GeneratedObject, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt index d4adef0d8..e453a40cc 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt @@ -10,17 +10,19 @@ import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.PropertySpec.Builder import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.metadata.GeneratedObject -import dev.icerock.gradle.metadata.GeneratedObjectModifier.Actual -import dev.icerock.gradle.metadata.GeneratedObjectModifier.Expect -import dev.icerock.gradle.metadata.GeneratedObjectModifier.None +import dev.icerock.gradle.metadata.GeneratedObjectModifier import dev.icerock.gradle.metadata.GeneratedObjectType import dev.icerock.gradle.metadata.GeneratedProperties import dev.icerock.gradle.metadata.addActual +import kotlinx.serialization.encodeToString +import kotlinx.serialization.json.Json +import org.gradle.api.Project import java.io.File abstract class BaseGenerator : MRGenerator.Generator { override fun generate( + project: Project, inputMetadata: MutableList, generatedObjects: MutableList, targetObject: GeneratedObject, @@ -42,10 +44,16 @@ abstract class BaseGenerator : MRGenerator.Generator { generatedObjects = generatedObjects, targetObject = targetObject, keys = languageKeyValues.keys.toList(), + languageMap = languageMap, objectBuilder = objectBuilder ) - languageMap.forEach { (language, strings) -> + languageMap.forEach { (language: LanguageType, strings: Map) -> + project.logger.warn("i: language ${language.language()}") + strings.forEach { (k, v) -> + project.logger.warn("i: strings $k $v") + + } generateResources(resourcesGenerationDir, language, strings) } @@ -58,6 +66,7 @@ abstract class BaseGenerator : MRGenerator.Generator { generatedObjects: MutableList, targetObject: GeneratedObject, keys: List, + languageMap: Map>, objectBuilder: TypeSpec.Builder, ): TypeSpec { objectBuilder.addModifiers(*getClassModifiers()) @@ -69,28 +78,33 @@ abstract class BaseGenerator : MRGenerator.Generator { keys.forEach { key -> val name = key.replace(".", "_") + val values = mutableMapOf() + + languageMap.forEach { (language, strings) -> + strings.forEach { (stringKey, value) -> + if (stringKey == key) { + values[language.language()] = value as String + } + } + } + var generatedProperty = GeneratedProperties( - modifier = None, + modifier = GeneratedObjectModifier.None, name = name, - data = "" + data = Json.encodeToString(values.toList()) ) val property: Builder = PropertySpec.builder(name, resourceClassName) if (targetObject.type == GeneratedObjectType.Object) { + // Add modifier for property and setup metadata generatedProperty = generatedProperty.copy( - modifier = if (getPropertyModifiers().contains(KModifier.ACTUAL)) { - Actual - } else { - Expect - } - ) - - addActualOverrideModifier( - propertyName = name, - property = property, - inputMetadata = inputMetadata, - targetObject = targetObject + modifier = addActualOverrideModifier( + propertyName = name, + property = property, + inputMetadata = inputMetadata, + targetObject = targetObject + ) ) getPropertyInitializer(key)?.let { @@ -118,11 +132,11 @@ abstract class BaseGenerator : MRGenerator.Generator { propertyName: String, property: PropertySpec.Builder, inputMetadata: List, - targetObject: GeneratedObject - ) { + targetObject: GeneratedObject, + ): GeneratedObjectModifier { val actualInterfaces = (inputMetadata).filter { it.type == GeneratedObjectType.Interface - && it.modifier == Actual + && it.modifier == GeneratedObjectModifier.Actual && it.generatorType == targetObject.generatorType } @@ -138,16 +152,27 @@ abstract class BaseGenerator : MRGenerator.Generator { } } - if (targetObject.type == GeneratedObjectType.Object) { + return if (targetObject.type == GeneratedObjectType.Object) { if (containsInActualInterfaces) { property.addModifiers(KModifier.OVERRIDE) + GeneratedObjectModifier.Override } else { when (targetObject.modifier) { - Expect -> property.addModifiers(KModifier.EXPECT) - Actual -> property.addModifiers(KModifier.ACTUAL) - None -> Unit + GeneratedObjectModifier.Expect -> { + property.addModifiers(KModifier.EXPECT) + GeneratedObjectModifier.Expect + } + GeneratedObjectModifier.Actual -> { + property.addModifiers(KModifier.ACTUAL) + GeneratedObjectModifier.Actual + } + else -> { + GeneratedObjectModifier.None + } } } + } else { + GeneratedObjectModifier.None } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt index 9f80a5fae..8918c02af 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt @@ -16,13 +16,15 @@ import dev.icerock.gradle.generator.js.JsColorsGenerator import dev.icerock.gradle.generator.jvm.JvmColorsGenerator import dev.icerock.gradle.metadata.GeneratedObject import dev.icerock.gradle.metadata.GeneratorType -import java.io.File -import javax.xml.parsers.DocumentBuilderFactory +import org.gradle.api.Project import org.gradle.api.file.FileTree import org.w3c.dom.Node import org.w3c.dom.NodeList +import java.io.File +import javax.xml.parsers.DocumentBuilderFactory abstract class ColorsGenerator( + val project: Project, private val colorsFileTree: FileTree, ) : MRGenerator.Generator { @@ -40,6 +42,7 @@ abstract class ColorsGenerator( @Suppress("SpreadOperator") override fun generate( + project: Project, inputMetadata: MutableList, generatedObjects: MutableList, targetObject: GeneratedObject, @@ -142,32 +145,38 @@ abstract class ColorsGenerator( } class Feature( + val project: Project, private val settings: MRGenerator.Settings, ) : ResourceGeneratorFeature { private val fileTree: FileTree = settings.ownResourcesFileTree .matching { it.include("**/colors*.xml") } override fun createCommonGenerator() = CommonColorsGenerator( + project = project, ownColorsFileTree = settings.ownResourcesFileTree, upperColorsFileTree = settings.upperResourcesFileTree ) override fun createIosGenerator() = AppleColorsGenerator( + project = project, ownColorsFileTree = settings.ownResourcesFileTree, lowerColorsFileTree = settings.lowerResourcesFileTree ) override fun createAndroidGenerator() = AndroidColorsGenerator( + project = project, ownColorsFileTree = settings.ownResourcesFileTree, lowerColorsFileTree = settings.lowerResourcesFileTree ) override fun createJsGenerator(): ColorsGenerator = JsColorsGenerator( + project = project, ownColorsFileTree = settings.ownResourcesFileTree, lowerColorsFileTree = settings.lowerResourcesFileTree ) override fun createJvmGenerator() = JvmColorsGenerator( + project = project, ownColorsFileTree = settings.ownResourcesFileTree, lowerColorsFileTree = settings.lowerResourcesFileTree, settings ) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt index 0be0d5cba..68d1f4d2e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt @@ -16,10 +16,12 @@ import dev.icerock.gradle.generator.js.JsFilesGenerator import dev.icerock.gradle.generator.jvm.JvmFilesGenerator import dev.icerock.gradle.metadata.GeneratedObject import dev.icerock.gradle.metadata.GeneratorType -import java.io.File +import org.gradle.api.Project import org.gradle.api.file.FileTree +import java.io.File abstract class FilesGenerator( + project: Project, private val inputFileTree: FileTree ) : MRGenerator.Generator { @@ -30,6 +32,7 @@ abstract class FilesGenerator( override val type: GeneratorType = GeneratorType.Files override fun generate( + project: Project, inputMetadata: MutableList, generatedObjects: MutableList, targetObject: GeneratedObject, @@ -100,6 +103,7 @@ abstract class FilesGenerator( ) class Feature( + val project: Project, private val settings: MRGenerator.Settings ) : ResourceGeneratorFeature { @@ -107,27 +111,32 @@ abstract class FilesGenerator( // .matching { it.include("files/**") } override fun createCommonGenerator(): FilesGenerator = CommonFilesGenerator( + project = project, ownInputFileTree = settings.ownResourcesFileTree, upperInputFileTree = settings.upperResourcesFileTree ) override fun createIosGenerator(): FilesGenerator = AppleFilesGenerator( + project = project, ownInputFileTree = settings.ownResourcesFileTree, lowerInputFileTree = settings.lowerResourcesFileTree ) override fun createAndroidGenerator(): FilesGenerator = AndroidFilesGenerator( + project = project, ownInputFileTree = settings.ownResourcesFileTree, lowerInputFileTree = settings.lowerResourcesFileTree, androidRClassPackage = settings.androidRClassPackage, ) override fun createJsGenerator(): FilesGenerator = JsFilesGenerator( + project = project, ownInputFileTree = settings.ownResourcesFileTree, lowerInputFileTree = settings.lowerResourcesFileTree ) override fun createJvmGenerator(): FilesGenerator = JvmFilesGenerator( + project = project, ownInputFileTree = settings.ownResourcesFileTree, lowerInputFileTree = settings.lowerResourcesFileTree, settings = settings diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt index 5b28213fe..2611453b7 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt @@ -17,8 +17,9 @@ import dev.icerock.gradle.generator.jvm.JvmFontsGenerator import dev.icerock.gradle.metadata.GeneratedObject import dev.icerock.gradle.metadata.GeneratorType import dev.icerock.gradle.utils.decapitalize -import java.io.File +import org.gradle.api.Project import org.gradle.api.file.FileTree +import java.io.File abstract class FontsGenerator( private val inputFileTree: FileTree @@ -31,6 +32,7 @@ abstract class FontsGenerator( override val type: GeneratorType = GeneratorType.Fonts override fun generate( + project: Project, inputMetadata: MutableList, generatedObjects: MutableList, targetObject: GeneratedObject, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt index f32fcaede..8ff7e45e9 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt @@ -17,9 +17,10 @@ import dev.icerock.gradle.generator.jvm.JvmImagesGenerator import dev.icerock.gradle.metadata.GeneratedObject import dev.icerock.gradle.metadata.GeneratorType import dev.icerock.gradle.utils.withoutScale -import java.io.File +import org.gradle.api.Project import org.gradle.api.file.FileTree import org.gradle.api.logging.Logger +import java.io.File abstract class ImagesGenerator( private val inputFileTree: FileTree @@ -34,6 +35,7 @@ abstract class ImagesGenerator( override val type: GeneratorType = GeneratorType.Images override fun generate( + project: Project, inputMetadata: MutableList, generatedObjects: MutableList, targetObject: GeneratedObject, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/LanguageType.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/LanguageType.kt index 30d75eabe..347c7fa58 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/LanguageType.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/LanguageType.kt @@ -13,17 +13,23 @@ sealed interface LanguageType { val jsResourcesSuffix: String val jvmResourcesSuffix: String + fun language(): String + object Base : LanguageType { override val androidResourcesDir: String = "values" override val appleResourcesDir: String = "Base.lproj" override val jsResourcesSuffix: String = "" override val jvmResourcesSuffix: String = "" + + override fun language(): String = BASE } - class Locale(languageTag: String) : LanguageType { + class Locale(private val languageTag: String) : LanguageType { private val jvmLocale: JvmLocale = JvmLocale.forLanguageTag(languageTag) + override fun language(): String = languageTag + fun toBcpString(): String = jvmLocale.toLanguageTag() private fun toLocaleString(): String = jvmLocale.toString() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt index ed8c59d25..237c117b9 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt @@ -12,10 +12,10 @@ import dev.icerock.gradle.MRVisibility import dev.icerock.gradle.metadata.GeneratedObject import dev.icerock.gradle.metadata.GeneratorType import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask -import java.io.File import org.gradle.api.Project import org.gradle.api.file.Directory import org.gradle.api.file.FileTree +import java.io.File abstract class MRGenerator( protected val settings: Settings, @@ -84,6 +84,7 @@ abstract class MRGenerator( val type: GeneratorType fun generate( + project: Project, inputMetadata: MutableList, generatedObjects: MutableList, //TODO: Remove emptyList() after complete realisation targetObject: GeneratedObject, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt index d7363d221..54f890581 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt @@ -12,9 +12,9 @@ import dev.icerock.gradle.generator.js.JsStringsGenerator import dev.icerock.gradle.generator.jvm.JvmStringsGenerator import dev.icerock.gradle.metadata.GeneratorType import dev.icerock.gradle.utils.removeLineWraps +import org.gradle.api.file.FileTree import java.io.File import javax.xml.parsers.DocumentBuilderFactory -import org.gradle.api.file.FileTree typealias KeyType = String diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt index 1ed24d491..db21ebc2d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt @@ -11,6 +11,7 @@ import dev.icerock.gradle.metadata.GeneratorType import dev.icerock.gradle.metadata.Metadata.createOutputMetadata import dev.icerock.gradle.metadata.Metadata.readInputMetadata import dev.icerock.gradle.metadata.addActual +import dev.icerock.gradle.metadata.getExpectInterfaces import dev.icerock.gradle.metadata.getInterfaceName import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.toModifier @@ -84,32 +85,23 @@ abstract class TargetMRGenerator( ) // Generation of actual interfaces not realised on current level - expectInterfacesList.forEach { expectInterface -> - val hasInGeneratedActualInterfaces = inputMetadata.hasInActualInterfaces( - interfaceName = expectInterface.name - ) - - if (hasInGeneratedActualInterfaces) return@forEach + val expectInterfaces = inputMetadata.getExpectInterfaces() + expectInterfaces.forEach { expectInterface -> val resourcesInterface: TypeSpec = TypeSpec.interfaceBuilder(expectInterface.name) .addModifiers(visibilityModifier) .addModifiers(KModifier.ACTUAL) .build() - // TODO: add logic with add extract interface type inputMetadata.addActual( - GeneratedObject( - generatorType = GeneratorType.Strings, - modifier = GeneratedObjectModifier.Actual, - type = GeneratedObjectType.Interface, - name = expectInterface.name, - ) + expectInterface.copy(modifier = GeneratedObjectModifier.Actual) ) fileSpec.addType(resourcesInterface) } } + val generatedActualObjects = mutableListOf() generators.forEach { generator -> @@ -130,6 +122,7 @@ abstract class TargetMRGenerator( mrClassSpec.addType( generator.generate( + project = project, inputMetadata = inputMetadata, generatedObjects = generatedActualObjects, targetObject = GeneratedObject( @@ -185,8 +178,8 @@ abstract class TargetMRGenerator( ) { if (settings.ownResourcesFileTree.files.isEmpty()) return - val targetName: String = - settings.ownResourcesFileTree.files.firstOrNull()?.targetName ?: return + val targetName: String = settings.ownResourcesFileTree.files + .firstOrNull()?.targetName ?: return generators.forEach { generator -> val interfaceName = getInterfaceName( @@ -199,6 +192,7 @@ abstract class TargetMRGenerator( .addModifiers(visibilityModifier) val generatedResources: TypeSpec = generator.generate( + project = project, inputMetadata = inputMetadata, generatedObjects = inputMetadata, targetObject = GeneratedObject( @@ -219,7 +213,7 @@ abstract class TargetMRGenerator( private fun getObjectInterfaces( generatorType: GeneratorType, objectName: String, - inputMetadata: List + inputMetadata: List, ): List { val interfaces = mutableListOf() @@ -239,14 +233,4 @@ abstract class TargetMRGenerator( return interfaces.distinct() } - - private fun List.hasInActualInterfaces( - interfaceName: String - ): Boolean { - return this.firstOrNull { - it.name == interfaceName - && it.type == GeneratedObjectType.Interface - && it.modifier == GeneratedObjectModifier.Actual - } != null - } } \ No newline at end of file diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt index 0f6e6a708..1ff31e4bb 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt @@ -11,13 +11,15 @@ import dev.icerock.gradle.generator.ColorNode import dev.icerock.gradle.generator.ColorsGenerator import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable +import org.gradle.api.Project import org.gradle.api.file.FileTree import java.io.File class AndroidColorsGenerator( + project: Project, ownColorsFileTree: FileTree, lowerColorsFileTree: FileTree, -) : ColorsGenerator(ownColorsFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { +) : ColorsGenerator(project, ownColorsFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getImports() = listOf( ClassName("dev.icerock.moko.graphics", "Color") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt index c1d29f78a..6cf16ef3f 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt @@ -10,15 +10,17 @@ import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.FilesGenerator import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable +import org.gradle.api.Project import org.gradle.api.file.FileTree import java.io.File import java.util.Locale class AndroidFilesGenerator( + project: Project, ownInputFileTree: FileTree, lowerInputFileTree: FileTree, private val androidRClassPackage: String, -) : FilesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { +) : FilesGenerator(project, ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt index c17e00449..51d9764a9 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt @@ -17,13 +17,15 @@ import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.buildJsonArray import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.put +import org.gradle.api.Project import org.gradle.api.file.FileTree import java.io.File class AppleColorsGenerator( + project: Project, ownColorsFileTree: FileTree, lowerColorsFileTree: FileTree, -) : ColorsGenerator(ownColorsFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { +) : ColorsGenerator(project, ownColorsFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { override fun getImports(): List { return listOf( ClassName("dev.icerock.moko.graphics", "Color") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFilesGenerator.kt index e281c325c..82804b802 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFilesGenerator.kt @@ -8,13 +8,15 @@ import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.FilesGenerator import dev.icerock.gradle.generator.ObjectBodyExtendable +import org.gradle.api.Project import org.gradle.api.file.FileTree import java.io.File class AppleFilesGenerator( + project: Project, ownInputFileTree: FileTree, lowerInputFileTree: FileTree, -) : FilesGenerator(inputFileTree = ownInputFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { +) : FilesGenerator(project, inputFileTree = ownInputFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonColorsGenerator.kt index 89dffc8a1..46241de4d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonColorsGenerator.kt @@ -10,13 +10,14 @@ import dev.icerock.gradle.generator.ColorNode import dev.icerock.gradle.generator.ColorsGenerator import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable -import dev.icerock.gradle.metadata.GeneratorType +import org.gradle.api.Project import org.gradle.api.file.FileTree class CommonColorsGenerator( + project: Project, ownColorsFileTree: FileTree, upperColorsFileTree: FileTree, -) : ColorsGenerator(ownColorsFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { +) : ColorsGenerator(project, ownColorsFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getImports(): List { return emptyList() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt index b8698caa2..5dae268f4 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt @@ -9,13 +9,14 @@ import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.FilesGenerator import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable -import dev.icerock.gradle.metadata.GeneratorType +import org.gradle.api.Project import org.gradle.api.file.FileTree class CommonFilesGenerator( + project: Project, ownInputFileTree: FileTree, upperInputFileTree: FileTree, -) : FilesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { +) : FilesGenerator(project, ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = emptyArray() override fun getPropertyModifiers(): Array = emptyArray() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index f53645573..ce4edd463 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -130,14 +130,6 @@ class CommonMRGenerator( .addModifiers(visibilityModifier) // public/internal - var expectMRObject: GeneratedObject = GeneratedObject( - generatorType = None, - type = GeneratedObjectType.Object, - name = settings.className, - modifier = GeneratedObjectModifier.Expect, - properties = emptyList(), - objects = emptyList() - ) val generatedExpectInterfaces = mutableListOf() val generatedExpectObjects = mutableListOf() @@ -199,6 +191,7 @@ class CommonMRGenerator( } val generatedResourcesTypeSpec = generator.generate( + project = project, inputMetadata = inputMetadata, generatedObjects = generatedExpectObjects, targetObject = GeneratedObject( @@ -213,25 +206,17 @@ class CommonMRGenerator( objectBuilder = builder ) -// expectMRObject = expectMRObject.copy( -// objects = expectMRObject.objects + listOf( -// GeneratedObject( -// generatorType = generator.type, -// name = generator.mrObjectName, -// type = GeneratedObjectType.Object, -// modifier = GeneratedObjectModifier.Expect, -// interfaces = generatedInterfaces, -// properties = generatedResources.propertySpecs.toGeneratedVariables(), -// ) -// ) -// ) - mrClassSpec.addType(generatedResourcesTypeSpec) } // Add generated objects in MR generatedObjects.add( - expectMRObject.copy( + GeneratedObject( + generatorType = None, + type = GeneratedObjectType.Object, + name = settings.className, + modifier = GeneratedObjectModifier.Expect, + properties = emptyList(), objects = generatedExpectObjects ) ) @@ -263,6 +248,7 @@ class CommonMRGenerator( .addModifiers(KModifier.ACTUAL) val generatedResources: TypeSpec = generator.generate( + project = project, targetObject = GeneratedObject( generatorType = generator.type, name = interfaceName, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsColorsGenerator.kt index a80356bca..eda8794d0 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsColorsGenerator.kt @@ -15,12 +15,14 @@ import dev.icerock.gradle.generator.ColorsGenerator import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable import dev.icerock.gradle.generator.jsJvmCommon.createColorResourceInitializer +import org.gradle.api.Project import org.gradle.api.file.FileTree class JsColorsGenerator( + project: Project, ownColorsFileTree: FileTree, lowerColorsFileTree: FileTree, -) : ColorsGenerator(ownColorsFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { +) : ColorsGenerator(project, ownColorsFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFilesGenerator.kt index 95e169c8d..d813f8112 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFilesGenerator.kt @@ -13,13 +13,15 @@ import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.FilesGenerator import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable +import org.gradle.api.Project import org.gradle.api.file.FileTree import java.io.File class JsFilesGenerator( + project: Project, ownInputFileTree: FileTree, lowerInputFileTree: FileTree, -) : FilesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { +) : FilesGenerator(project,ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmColorsGenerator.kt index d691344de..b26029677 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmColorsGenerator.kt @@ -12,13 +12,15 @@ import dev.icerock.gradle.generator.ColorsGenerator import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.ObjectBodyExtendable import dev.icerock.gradle.generator.jsJvmCommon.createColorResourceInitializer +import org.gradle.api.Project import org.gradle.api.file.FileTree class JvmColorsGenerator( + project: Project, ownColorsFileTree: FileTree, lowerColorsFileTree: FileTree, settings: MRGenerator.Settings -) : ColorsGenerator(ownColorsFileTree), +) : ColorsGenerator(project, ownColorsFileTree), ObjectBodyExtendable by ClassLoaderExtender(settings.className) { override fun getImports() = listOf( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFilesGenerator.kt index 7cd2752c1..ed348579a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFilesGenerator.kt @@ -9,14 +9,16 @@ import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.FilesGenerator import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.ObjectBodyExtendable +import org.gradle.api.Project import org.gradle.api.file.FileTree import java.io.File class JvmFilesGenerator( + project: Project, ownInputFileTree: FileTree, lowerInputFileTree: FileTree, settings: MRGenerator.Settings -) : FilesGenerator(ownInputFileTree), +) : FilesGenerator(project, ownInputFileTree), ObjectBodyExtendable by ClassLoaderExtender(settings.className) { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObjectModifier.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObjectModifier.kt index 79e2450f1..bd3c40794 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObjectModifier.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObjectModifier.kt @@ -1,15 +1,8 @@ package dev.icerock.gradle.metadata -enum class GeneratedObjectModifier(val value: String) { - Expect("expect"), - Actual("actual"), - None("none"); - - companion object { - private val VALUES = values() - fun getByValue(value: String): GeneratedObjectModifier { - return VALUES.firstOrNull { it.value.lowercase() == value.lowercase() } - ?: throw Exception("Invalid modifier value") - } - } +enum class GeneratedObjectModifier { + Expect, + Actual, + Override, + None; } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt index 59b7148cc..f1b81b5be 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt @@ -12,4 +12,11 @@ fun MutableList.addActual(actualObject: GeneratedObject){ } add(actualObject) -} \ No newline at end of file +} + +fun List.getExpectInterfaces(): List { + return filter { + it.type == GeneratedObjectType.Interface + && it.modifier == GeneratedObjectModifier.Expect + } +} From b1a614d169e40ebfeed0c82028f695e14ee2a37e Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Thu, 7 Dec 2023 13:37:55 +0700 Subject: [PATCH 059/352] #535 remove lowerResources from strings generator, correct generation strings for androidTarget --- .../icerock/gradle/generator/BaseGenerator.kt | 114 +-------- .../gradle/generator/StringsGenerator.kt | 235 +++++++++++++++++- .../android/AndroidStringsGenerator.kt | 4 +- .../generator/apple/AppleStringsGenerator.kt | 4 +- .../common/CommonStringsGenerator.kt | 4 - .../gradle/generator/js/JsStringsGenerator.kt | 4 +- .../generator/jvm/JvmStringsGenerator.kt | 4 +- .../icerock/gradle/metadata/MetadataExt.kt | 21 ++ .../moko-resources/base/strings.xml | 1 + 9 files changed, 255 insertions(+), 136 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt index e453a40cc..906574019 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt @@ -10,14 +10,8 @@ import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.PropertySpec.Builder import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.metadata.GeneratedObject -import dev.icerock.gradle.metadata.GeneratedObjectModifier -import dev.icerock.gradle.metadata.GeneratedObjectType -import dev.icerock.gradle.metadata.GeneratedProperties -import dev.icerock.gradle.metadata.addActual -import kotlinx.serialization.encodeToString -import kotlinx.serialization.json.Json -import org.gradle.api.Project import java.io.File +import org.gradle.api.Project abstract class BaseGenerator : MRGenerator.Generator { @@ -34,26 +28,14 @@ abstract class BaseGenerator : MRGenerator.Generator { val languageMap: Map> = loadLanguageMap() val languageKeyValues = languageMap[LanguageType.Base].orEmpty() - // Добавить входящие ресурсы из метаданных - // + чтение своих ресурсов отдельно, как было - beforeGenerateResources(objectBuilder, languageMap) val stringsClass = createTypeSpec( - inputMetadata = inputMetadata, - generatedObjects = generatedObjects, - targetObject = targetObject, keys = languageKeyValues.keys.toList(), - languageMap = languageMap, objectBuilder = objectBuilder ) languageMap.forEach { (language: LanguageType, strings: Map) -> - project.logger.warn("i: language ${language.language()}") - strings.forEach { (k, v) -> - project.logger.warn("i: strings $k $v") - - } generateResources(resourcesGenerationDir, language, strings) } @@ -62,120 +44,30 @@ abstract class BaseGenerator : MRGenerator.Generator { @Suppress("SpreadOperator") private fun createTypeSpec( - inputMetadata: MutableList, - generatedObjects: MutableList, - targetObject: GeneratedObject, keys: List, - languageMap: Map>, objectBuilder: TypeSpec.Builder, ): TypeSpec { objectBuilder.addModifiers(*getClassModifiers()) extendObjectBodyAtStart(objectBuilder) - val generatedProperties = mutableListOf() - keys.forEach { key -> val name = key.replace(".", "_") - val values = mutableMapOf() - - languageMap.forEach { (language, strings) -> - strings.forEach { (stringKey, value) -> - if (stringKey == key) { - values[language.language()] = value as String - } - } - } - - var generatedProperty = GeneratedProperties( - modifier = GeneratedObjectModifier.None, - name = name, - data = Json.encodeToString(values.toList()) - ) - val property: Builder = PropertySpec.builder(name, resourceClassName) - if (targetObject.type == GeneratedObjectType.Object) { - // Add modifier for property and setup metadata - generatedProperty = generatedProperty.copy( - modifier = addActualOverrideModifier( - propertyName = name, - property = property, - inputMetadata = inputMetadata, - targetObject = targetObject - ) - ) - - getPropertyInitializer(key)?.let { - property.initializer(it) - } + getPropertyInitializer(key)?.let { + property.initializer(it) } objectBuilder.addProperty(property.build()) - - generatedProperties.add(generatedProperty) } extendObjectBodyAtEnd(objectBuilder) - generatedObjects.addActual( - targetObject.copy( - properties = generatedProperties - ) - ) - return objectBuilder.build() } - private fun addActualOverrideModifier( - propertyName: String, - property: PropertySpec.Builder, - inputMetadata: List, - targetObject: GeneratedObject, - ): GeneratedObjectModifier { - val actualInterfaces = (inputMetadata).filter { - it.type == GeneratedObjectType.Interface - && it.modifier == GeneratedObjectModifier.Actual - && it.generatorType == targetObject.generatorType - } - - var containsInActualInterfaces = false - - actualInterfaces.forEach { genInterface -> - val hasInInterface = genInterface.properties.any { - it.name == propertyName - } - - if (hasInInterface) { - containsInActualInterfaces = true - } - } - - return if (targetObject.type == GeneratedObjectType.Object) { - if (containsInActualInterfaces) { - property.addModifiers(KModifier.OVERRIDE) - GeneratedObjectModifier.Override - } else { - when (targetObject.modifier) { - GeneratedObjectModifier.Expect -> { - property.addModifiers(KModifier.EXPECT) - GeneratedObjectModifier.Expect - } - GeneratedObjectModifier.Actual -> { - property.addModifiers(KModifier.ACTUAL) - GeneratedObjectModifier.Actual - } - else -> { - GeneratedObjectModifier.None - } - } - } - } else { - GeneratedObjectModifier.None - } - } - protected abstract fun loadLanguageMap(): Map> protected abstract fun getPropertyInitializer(key: String): CodeBlock? diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt index 54f890581..5058373e8 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt @@ -5,26 +5,249 @@ package dev.icerock.gradle.generator import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.PropertySpec +import com.squareup.kotlinpoet.PropertySpec.Builder +import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.android.AndroidStringsGenerator import dev.icerock.gradle.generator.apple.AppleStringsGenerator import dev.icerock.gradle.generator.common.CommonStringsGenerator import dev.icerock.gradle.generator.js.JsStringsGenerator import dev.icerock.gradle.generator.jvm.JvmStringsGenerator +import dev.icerock.gradle.metadata.GeneratedObject +import dev.icerock.gradle.metadata.GeneratedObjectModifier +import dev.icerock.gradle.metadata.GeneratedObjectModifier.None +import dev.icerock.gradle.metadata.GeneratedObjectType +import dev.icerock.gradle.metadata.GeneratedProperties import dev.icerock.gradle.metadata.GeneratorType +import dev.icerock.gradle.metadata.addActual +import dev.icerock.gradle.metadata.objectsWithProperties import dev.icerock.gradle.utils.removeLineWraps -import org.gradle.api.file.FileTree import java.io.File import javax.xml.parsers.DocumentBuilderFactory +import kotlinx.serialization.encodeToString +import kotlinx.serialization.json.Json +import org.gradle.api.Project +import org.gradle.api.file.FileTree typealias KeyType = String abstract class StringsGenerator( - private val lowerStringsFileTree: FileTree, private val ownStringsFileTree: FileTree, - private val upperStringsFileTree: FileTree? = null, private val strictLineBreaks: Boolean, ) : BaseGenerator() { + override fun generate( + project: Project, + inputMetadata: MutableList, + generatedObjects: MutableList, + targetObject: GeneratedObject, + assetsGenerationDir: File, + resourcesGenerationDir: File, + objectBuilder: TypeSpec.Builder, + ): TypeSpec { + + val previousLanguagesMap: Map> = getPreviousLanguagesMap( + inputMetadata = inputMetadata, + targetObject = targetObject + ) + + // language - key - value + val languageMap: Map> = loadLanguageMap() + val languagesAllMaps = getLanguagesAllMaps(previousLanguagesMap, languageMap) + val languageKeyValues = languagesAllMaps[LanguageType.Base].orEmpty() + + beforeGenerateResources(objectBuilder, languagesAllMaps) + + val stringsClass = createTypeSpec( + inputMetadata = inputMetadata, + generatedObjects = generatedObjects, + targetObject = targetObject, + keys = languageKeyValues.keys.toList(), + languageMap = languagesAllMaps, + objectBuilder = objectBuilder + ) + + languagesAllMaps.forEach { (language: LanguageType, strings: Map) -> + generateResources(resourcesGenerationDir, language, strings) + } + + return stringsClass + } + + private fun getLanguagesAllMaps( + previousLanguageMaps: Map>, + languageMap: Map> + ): Map> { + val resultLanguageMap: MutableMap> = mutableMapOf() + + resultLanguageMap.putAll(previousLanguageMaps) + + languageMap.forEach { (languageType: LanguageType, value: Map) -> + + val currentMap: MutableMap = + previousLanguageMaps[languageType]?.toMutableMap() ?: mutableMapOf() + + value.forEach { (key, value) -> currentMap[key] = value } + + resultLanguageMap[languageType] = currentMap + } + + return resultLanguageMap + } + + private fun getPreviousLanguagesMap( + inputMetadata: List, + targetObject: GeneratedObject, + ): Map> { + if (targetObject.type != GeneratedObjectType.Object + || targetObject.modifier != GeneratedObjectModifier.Actual + ) return emptyMap() + + val objectsWithProperties: List = inputMetadata.objectsWithProperties(targetObject) + + val languagesMaps = mutableMapOf>() + + objectsWithProperties.forEach { generatedObject -> + generatedObject.properties.forEach { property -> + val data = Json.decodeFromString>>(property.data) + + data.forEach { (languageTag, value) -> + val languageType: LanguageType = if (languageTag == BASE_LANGUAGE) { + LanguageType.Base + } else { + LanguageType.Locale(languageTag) + } + + val currentMap: MutableMap = + languagesMaps[languageType]?.toMutableMap() ?: mutableMapOf() + + currentMap[property.name] = value + + languagesMaps[languageType] = currentMap + } + } + } + + return languagesMaps + } + + @Suppress("SpreadOperator") + private fun createTypeSpec( + inputMetadata: MutableList, + generatedObjects: MutableList, + targetObject: GeneratedObject, + keys: List, + languageMap: Map>, + objectBuilder: TypeSpec.Builder, + ): TypeSpec { + objectBuilder.addModifiers(*getClassModifiers()) + + extendObjectBodyAtStart(objectBuilder) + + val generatedProperties = mutableListOf() + + keys.forEach { key -> + val name = key.replace(".", "_") + + val values = mutableMapOf() + + languageMap.forEach { (languageType, strings) -> + strings.forEach { (stringKey, value) -> + if (stringKey == key) { + values[languageType.language()] = value + } + } + } + + var generatedProperty = GeneratedProperties( + modifier = None, + name = name, + data = Json.encodeToString(values.toList()) + ) + + val property: Builder = PropertySpec.builder(name, resourceClassName) + + if (targetObject.type == GeneratedObjectType.Object) { + // Add modifier for property and setup metadata + generatedProperty = generatedProperty.copy( + modifier = addActualOverrideModifier( + propertyName = name, + property = property, + inputMetadata = inputMetadata, + targetObject = targetObject + ) + ) + + getPropertyInitializer(key)?.let { + property.initializer(it) + } + } + + objectBuilder.addProperty(property.build()) + + generatedProperties.add(generatedProperty) + } + + extendObjectBodyAtEnd(objectBuilder) + + generatedObjects.addActual( + targetObject.copy(properties = generatedProperties) + ) + + return objectBuilder.build() + } + + private fun addActualOverrideModifier( + propertyName: String, + property: PropertySpec.Builder, + inputMetadata: List, + targetObject: GeneratedObject, + ): GeneratedObjectModifier { + val actualInterfaces = (inputMetadata).filter { + it.type == GeneratedObjectType.Interface + && it.modifier == GeneratedObjectModifier.Actual + && it.generatorType == targetObject.generatorType + } + + var containsInActualInterfaces = false + + actualInterfaces.forEach { genInterface -> + val hasInInterface = genInterface.properties.any { + it.name == propertyName + } + + if (hasInInterface) { + containsInActualInterfaces = true + } + } + + return if (targetObject.type == GeneratedObjectType.Object) { + if (containsInActualInterfaces) { + property.addModifiers(KModifier.OVERRIDE) + GeneratedObjectModifier.Override + } else { + when (targetObject.modifier) { + GeneratedObjectModifier.Expect -> { + property.addModifiers(KModifier.EXPECT) + GeneratedObjectModifier.Expect + } + + GeneratedObjectModifier.Actual -> { + property.addModifiers(KModifier.ACTUAL) + GeneratedObjectModifier.Actual + } + + else -> { + GeneratedObjectModifier.None + } + } + } + } else { + GeneratedObjectModifier.None + } + } + override val inputFiles: Iterable get() = (ownStringsFileTree).matching { it.include(STRINGS_MASK) @@ -86,36 +309,30 @@ abstract class StringsGenerator( private val settings: MRGenerator.Settings, ) : ResourceGeneratorFeature { override fun createCommonGenerator(): StringsGenerator = CommonStringsGenerator( - lowerStringsFileTree = settings.lowerResourcesFileTree, ownStringsFileTree = settings.ownResourcesFileTree, - upperStringsFileTree = settings.upperResourcesFileTree, strictLineBreaks = settings.isStrictLineBreaks ) override fun createIosGenerator(): StringsGenerator = AppleStringsGenerator( ownStringsFileTree = settings.ownResourcesFileTree, - lowerStringsFileTree = settings.lowerResourcesFileTree, strictLineBreaks = settings.isStrictLineBreaks, baseLocalizationRegion = settings.iosLocalizationRegion ) override fun createAndroidGenerator(): StringsGenerator = AndroidStringsGenerator( ownStringsFileTree = settings.ownResourcesFileTree, - lowerStringsFileTree = settings.lowerResourcesFileTree, strictLineBreaks = settings.isStrictLineBreaks, androidRClassPackage = settings.androidRClassPackage ) override fun createJsGenerator(): StringsGenerator = JsStringsGenerator( ownStringsFileTree = settings.ownResourcesFileTree, - lowerStringsFileTree = settings.lowerResourcesFileTree, mrClassPackage = settings.packageName, strictLineBreaks = settings.isStrictLineBreaks ) override fun createJvmGenerator(): StringsGenerator = JvmStringsGenerator( ownStringsFileTree = settings.ownResourcesFileTree, - lowerStringsFileTree = settings.lowerResourcesFileTree, strictLineBreaks = settings.isStrictLineBreaks, settings = settings ) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt index 1591fa1c5..7b422cd54 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt @@ -12,17 +12,15 @@ import dev.icerock.gradle.generator.LanguageType import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable import dev.icerock.gradle.generator.StringsGenerator +import java.io.File import org.apache.commons.text.StringEscapeUtils import org.gradle.api.file.FileTree -import java.io.File class AndroidStringsGenerator( - private val lowerStringsFileTree: FileTree, private val ownStringsFileTree: FileTree, strictLineBreaks: Boolean, private val androidRClassPackage: String, ) : StringsGenerator( - lowerStringsFileTree = lowerStringsFileTree, ownStringsFileTree = ownStringsFileTree, strictLineBreaks = strictLineBreaks ), ObjectBodyExtendable by NOPObjectBodyExtendable() { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleStringsGenerator.kt index e43ee7fe1..a632eca50 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleStringsGenerator.kt @@ -11,17 +11,15 @@ import dev.icerock.gradle.generator.LanguageType import dev.icerock.gradle.generator.ObjectBodyExtendable import dev.icerock.gradle.generator.StringsGenerator import dev.icerock.gradle.generator.apple.AppleMRGenerator.Companion.BUNDLE_PROPERTY_NAME +import java.io.File import org.apache.commons.text.StringEscapeUtils import org.gradle.api.file.FileTree -import java.io.File class AppleStringsGenerator( ownStringsFileTree: FileTree, - lowerStringsFileTree: FileTree, strictLineBreaks: Boolean, private val baseLocalizationRegion: String ) : StringsGenerator( - lowerStringsFileTree = lowerStringsFileTree, ownStringsFileTree = ownStringsFileTree, strictLineBreaks = strictLineBreaks ), diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonStringsGenerator.kt index 70707e8a4..64b942753 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonStringsGenerator.kt @@ -11,14 +11,10 @@ import dev.icerock.gradle.generator.StringsGenerator import org.gradle.api.file.FileTree class CommonStringsGenerator( - lowerStringsFileTree: FileTree, ownStringsFileTree: FileTree, - upperStringsFileTree: FileTree, strictLineBreaks: Boolean ) : StringsGenerator( - lowerStringsFileTree = lowerStringsFileTree, ownStringsFileTree = ownStringsFileTree, - upperStringsFileTree = upperStringsFileTree, strictLineBreaks = strictLineBreaks ), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getPropertyInitializer(key: String): CodeBlock? = null diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt index d0cef2715..9b3995d45 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt @@ -18,18 +18,16 @@ import dev.icerock.gradle.generator.StringsGenerator import dev.icerock.gradle.generator.js.JsMRGenerator.Companion.STRINGS_FALLBACK_FILE_URL_PROPERTY_NAME import dev.icerock.gradle.generator.js.JsMRGenerator.Companion.SUPPORTED_LOCALES_PROPERTY_NAME import dev.icerock.gradle.utils.flatName +import java.io.File import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.put import org.gradle.api.file.FileTree -import java.io.File class JsStringsGenerator( ownStringsFileTree: FileTree, - lowerStringsFileTree: FileTree, mrClassPackage: String, strictLineBreaks: Boolean ) : StringsGenerator( - lowerStringsFileTree = lowerStringsFileTree, ownStringsFileTree = ownStringsFileTree, strictLineBreaks = strictLineBreaks ), diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt index c90b4e3e0..e255a5fd9 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt @@ -12,16 +12,14 @@ import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.ObjectBodyExtendable import dev.icerock.gradle.generator.StringsGenerator import dev.icerock.gradle.utils.flatName -import org.gradle.api.file.FileTree import java.io.File +import org.gradle.api.file.FileTree class JvmStringsGenerator( ownStringsFileTree: FileTree, - lowerStringsFileTree: FileTree, strictLineBreaks: Boolean, settings: MRGenerator.Settings, ) : StringsGenerator( - lowerStringsFileTree = lowerStringsFileTree, ownStringsFileTree = ownStringsFileTree, strictLineBreaks = strictLineBreaks ), diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt index f1b81b5be..b562b4f7a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt @@ -20,3 +20,24 @@ fun List.getExpectInterfaces(): List { && it.modifier == GeneratedObjectModifier.Expect } } + +fun List.objectsWithProperties( + targetObject: GeneratedObject, +): List { + val objectsWithProperties = mutableListOf() + + this.forEach { genObject -> + if (genObject.generatorType == targetObject.generatorType && genObject.properties.isNotEmpty()) { + objectsWithProperties.add(genObject) + } + + genObject.objects.forEach { innerObject -> + if (innerObject.generatorType == targetObject.generatorType && innerObject.properties.isNotEmpty()) { + objectsWithProperties.add(innerObject) + } + } + } + + return objectsWithProperties +} + diff --git a/samples/compose-resources-gallery/shared/src/commonMain/moko-resources/base/strings.xml b/samples/compose-resources-gallery/shared/src/commonMain/moko-resources/base/strings.xml index 6c15aa117..9db4ff73f 100644 --- a/samples/compose-resources-gallery/shared/src/commonMain/moko-resources/base/strings.xml +++ b/samples/compose-resources-gallery/shared/src/commonMain/moko-resources/base/strings.xml @@ -1,4 +1,5 @@ Hello moko-resources World + Second value for Test From 399bd102b88d18850c1a285b73d24b72791a0b09 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Thu, 7 Dec 2023 15:59:53 +0700 Subject: [PATCH 060/352] #535 correction of metadata properties, optimization of read own resources in generator --- .../gradle/generator/StringsGenerator.kt | 23 +++++++++++++------ .../gradle/metadata/GeneratedProperties.kt | 3 ++- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt index 5058373e8..356e38aae 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt @@ -25,8 +25,10 @@ import dev.icerock.gradle.metadata.objectsWithProperties import dev.icerock.gradle.utils.removeLineWraps import java.io.File import javax.xml.parsers.DocumentBuilderFactory -import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.JsonPrimitive +import kotlinx.serialization.json.decodeFromJsonElement import org.gradle.api.Project import org.gradle.api.file.FileTree @@ -53,7 +55,14 @@ abstract class StringsGenerator( ) // language - key - value - val languageMap: Map> = loadLanguageMap() + val languageMap: Map> = if ( + targetObject.type == GeneratedObjectType.Object && targetObject.modifier == GeneratedObjectModifier.Actual + ) { + emptyMap() + } else { + loadLanguageMap() + } + val languagesAllMaps = getLanguagesAllMaps(previousLanguagesMap, languageMap) val languageKeyValues = languagesAllMaps[LanguageType.Base].orEmpty() @@ -110,7 +119,7 @@ abstract class StringsGenerator( objectsWithProperties.forEach { generatedObject -> generatedObject.properties.forEach { property -> - val data = Json.decodeFromString>>(property.data) + val data = Json.decodeFromJsonElement>(property.data) data.forEach { (languageTag, value) -> val languageType: LanguageType = if (languageTag == BASE_LANGUAGE) { @@ -122,7 +131,7 @@ abstract class StringsGenerator( val currentMap: MutableMap = languagesMaps[languageType]?.toMutableMap() ?: mutableMapOf() - currentMap[property.name] = value + currentMap[property.name] = value.content languagesMaps[languageType] = currentMap } @@ -150,12 +159,12 @@ abstract class StringsGenerator( keys.forEach { key -> val name = key.replace(".", "_") - val values = mutableMapOf() + val values = mutableMapOf() languageMap.forEach { (languageType, strings) -> strings.forEach { (stringKey, value) -> if (stringKey == key) { - values[languageType.language()] = value + values[languageType.language()] = JsonPrimitive(value) } } } @@ -163,7 +172,7 @@ abstract class StringsGenerator( var generatedProperty = GeneratedProperties( modifier = None, name = name, - data = Json.encodeToString(values.toList()) + data = JsonObject(values) ) val property: Builder = PropertySpec.builder(name, resourceClassName) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperties.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperties.kt index 9a5c843d0..a2d2ad3b0 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperties.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperties.kt @@ -1,10 +1,11 @@ package dev.icerock.gradle.metadata import kotlinx.serialization.Serializable +import kotlinx.serialization.json.JsonElement @Serializable data class GeneratedProperties( val modifier: GeneratedObjectModifier, val name: String, - val data: String // Can contain data with dependencies from generator type + val data: JsonElement // Can contain data with dependencies from generator type ) From 0351741ce1f0ae4a77e041368bd8f64893f1c06e Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Fri, 8 Dec 2023 02:11:42 +0700 Subject: [PATCH 061/352] #535 add generated object state properties --- .../gradle/generator/StringsGenerator.kt | 26 +++++++------------ .../gradle/generator/TargetMRGenerator.kt | 10 ++----- .../generator/common/CommonMRGenerator.kt | 1 - .../gradle/metadata/GeneratedObject.kt | 26 ++++++++++++++++++- .../icerock/gradle/metadata/MetadataExt.kt | 7 +++-- 5 files changed, 41 insertions(+), 29 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt index 356e38aae..0ce01cca3 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt @@ -16,11 +16,11 @@ import dev.icerock.gradle.generator.js.JsStringsGenerator import dev.icerock.gradle.generator.jvm.JvmStringsGenerator import dev.icerock.gradle.metadata.GeneratedObject import dev.icerock.gradle.metadata.GeneratedObjectModifier -import dev.icerock.gradle.metadata.GeneratedObjectModifier.None import dev.icerock.gradle.metadata.GeneratedObjectType import dev.icerock.gradle.metadata.GeneratedProperties import dev.icerock.gradle.metadata.GeneratorType import dev.icerock.gradle.metadata.addActual +import dev.icerock.gradle.metadata.getActualInterfaces import dev.icerock.gradle.metadata.objectsWithProperties import dev.icerock.gradle.utils.removeLineWraps import java.io.File @@ -55,9 +55,7 @@ abstract class StringsGenerator( ) // language - key - value - val languageMap: Map> = if ( - targetObject.type == GeneratedObjectType.Object && targetObject.modifier == GeneratedObjectModifier.Actual - ) { + val languageMap: Map> = if (targetObject.isActualObject) { emptyMap() } else { loadLanguageMap() @@ -109,9 +107,7 @@ abstract class StringsGenerator( inputMetadata: List, targetObject: GeneratedObject, ): Map> { - if (targetObject.type != GeneratedObjectType.Object - || targetObject.modifier != GeneratedObjectModifier.Actual - ) return emptyMap() + if (!targetObject.isObject || !targetObject.isActual) return emptyMap() val objectsWithProperties: List = inputMetadata.objectsWithProperties(targetObject) @@ -170,14 +166,14 @@ abstract class StringsGenerator( } var generatedProperty = GeneratedProperties( - modifier = None, + modifier = GeneratedObjectModifier.None, name = name, data = JsonObject(values) ) val property: Builder = PropertySpec.builder(name, resourceClassName) - if (targetObject.type == GeneratedObjectType.Object) { + if (targetObject.isObject) { // Add modifier for property and setup metadata generatedProperty = generatedProperty.copy( modifier = addActualOverrideModifier( @@ -213,11 +209,9 @@ abstract class StringsGenerator( inputMetadata: List, targetObject: GeneratedObject, ): GeneratedObjectModifier { - val actualInterfaces = (inputMetadata).filter { - it.type == GeneratedObjectType.Interface - && it.modifier == GeneratedObjectModifier.Actual - && it.generatorType == targetObject.generatorType - } + val actualInterfaces = inputMetadata.getActualInterfaces( + generatorType = targetObject.generatorType + ) var containsInActualInterfaces = false @@ -258,9 +252,7 @@ abstract class StringsGenerator( } override val inputFiles: Iterable - get() = (ownStringsFileTree).matching { - it.include(STRINGS_MASK) - }.files + get() = (ownStringsFileTree).matching { it.include(STRINGS_MASK) }.files override val resourceClassName = ClassName("dev.icerock.moko.resources", "StringResource") override val mrObjectName: String = "strings" diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt index db21ebc2d..eb618d6ad 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt @@ -71,11 +71,6 @@ abstract class TargetMRGenerator( .addModifiers(KModifier.ACTUAL) .addModifiers(visibilityModifier) // public/internal - val expectInterfacesList: List = inputMetadata.filter { - it.type == GeneratedObjectType.Interface && - it.modifier == GeneratedObjectModifier.Expect - } - // Add actual implementation of expect interfaces from previous levels if (inputMetadata.isNotEmpty()) { generateActualInterface( @@ -102,6 +97,7 @@ abstract class TargetMRGenerator( } } + val expectInterfacesList: List = inputMetadata.getExpectInterfaces() val generatedActualObjects = mutableListOf() generators.forEach { generator -> @@ -218,9 +214,7 @@ abstract class TargetMRGenerator( val interfaces = mutableListOf() val mrObjects: List = inputMetadata.filter { - it.type == GeneratedObjectType.Object - && it.generatorType == GeneratorType.None - && it.modifier == GeneratedObjectModifier.Expect + it.isExpectObject && it.generatorType == GeneratorType.None } mrObjects.forEach { mrObject -> diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index ce4edd463..000ce34ea 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -216,7 +216,6 @@ class CommonMRGenerator( type = GeneratedObjectType.Object, name = settings.className, modifier = GeneratedObjectModifier.Expect, - properties = emptyList(), objects = generatedExpectObjects ) ) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt index 651cc9e86..10a652b5a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt @@ -11,4 +11,28 @@ data class GeneratedObject( val interfaces: List = emptyList(), val properties: List = emptyList(), val objects: List = emptyList() -) +) { + val isExpect: Boolean + get() = modifier == GeneratedObjectModifier.Expect + + val isActual: Boolean + get() = modifier == GeneratedObjectModifier.Actual + + val isObject: Boolean + get() = type == GeneratedObjectType.Object + + val isInterface: Boolean + get() = type == GeneratedObjectType.Interface + + val isExpectObject + get() = isObject && isExpect + + val isActualObject: Boolean + get() = isObject && isActual + + val isExpectInterface + get() = isInterface && isExpect + + val isActualInterface: Boolean + get() = isInterface && isActual +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt index b562b4f7a..b3d36c301 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt @@ -15,9 +15,12 @@ fun MutableList.addActual(actualObject: GeneratedObject){ } fun List.getExpectInterfaces(): List { + return filter { it.isExpectInterface } +} + +fun List.getActualInterfaces(generatorType: GeneratorType): List { return filter { - it.type == GeneratedObjectType.Interface - && it.modifier == GeneratedObjectModifier.Expect + it.isActualInterface && it.generatorType == generatorType } } From d8c5bc2feb71b3f3e849ffada7df0dec5d12ad58 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Fri, 8 Dec 2023 02:41:25 +0700 Subject: [PATCH 062/352] #535 remove useless override --- .../icerock/gradle/generator/android/AndroidMRGenerator.kt | 3 --- .../dev/icerock/gradle/generator/apple/AppleMRGenerator.kt | 6 ++---- .../icerock/gradle/generator/common/CommonMRGenerator.kt | 6 +++--- .../kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt | 4 +--- .../dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt | 4 +--- 5 files changed, 7 insertions(+), 16 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt index ca3d67f19..0b5c33462 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt @@ -6,7 +6,6 @@ package dev.icerock.gradle.generator.android import com.android.build.gradle.tasks.GenerateResValues import com.android.build.gradle.tasks.MergeSourceSetFolders -import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.TargetMRGenerator import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import org.gradle.api.Project @@ -21,8 +20,6 @@ class AndroidMRGenerator( settings = settings, generators = generators ) { - override fun getMRClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { project.tasks.withType().configureEach { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt index 64d863651..7ded1772a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt @@ -19,6 +19,8 @@ import dev.icerock.gradle.tasks.CopyFrameworkResourcesToAppEntryPointTask import dev.icerock.gradle.tasks.CopyFrameworkResourcesToAppTask import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.utils.calculateResourcesHash +import java.io.File +import kotlin.reflect.full.memberProperties import org.gradle.api.Action import org.gradle.api.Project import org.gradle.api.Task @@ -37,8 +39,6 @@ import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask import org.jetbrains.kotlin.gradle.tasks.FrameworkDescriptor import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink -import java.io.File -import kotlin.reflect.full.memberProperties @Suppress("TooManyFunctions") class AppleMRGenerator( @@ -55,8 +55,6 @@ class AppleMRGenerator( ClassName("platform.Foundation", "NSBundle") private val bundleIdentifier = "${settings.packageName}.MR" - override fun getMRClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - override fun processMRClass(mrClass: TypeSpec.Builder) { super.processMRClass(mrClass) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index 000ce34ea..a3588d171 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -73,14 +73,14 @@ class CommonMRGenerator( logger.warn("i prev: $it") } - val visibilityModifier: KModifier = settings.visibility.toModifier() - val generatedObjects = mutableListOf() - val fileSpec: Builder = FileSpec.builder( packageName = settings.packageName, fileName = settings.className ) + val visibilityModifier: KModifier = settings.visibility.toModifier() + val generatedObjects = mutableListOf() + if (settings.lowerResourcesFileTree.files.isEmpty()) { // When lower resources is empty, should generate expect MR object generateExpectMRObjectFileSpec( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt index cc015ab94..bb8fbd880 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt @@ -14,6 +14,7 @@ import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.utils.calculateResourcesHash import dev.icerock.gradle.utils.flatName import dev.icerock.gradle.utils.klibs +import java.io.File import org.gradle.api.Action import org.gradle.api.Project import org.gradle.api.Task @@ -22,7 +23,6 @@ import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilation import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile import org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl -import java.io.File class JsMRGenerator( project: Project, @@ -37,8 +37,6 @@ class JsMRGenerator( private val flattenClassName: String = settings.packageName.flatName override val resourcesGenerationDir: File = File(File(outputDir, flattenClassName), "res") - override fun getMRClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - override fun processMRClass(mrClass: TypeSpec.Builder) { mrClass.addProperty( PropertySpec.builder("contentHash", STRING, KModifier.PRIVATE) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt index 81f038f19..4e11ae2b2 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt @@ -12,11 +12,11 @@ import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.TargetMRGenerator import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.utils.flatName +import java.io.File import org.gradle.api.Project import org.gradle.jvm.tasks.Jar import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -import java.io.File class JvmMRGenerator( project: Project, @@ -31,8 +31,6 @@ class JvmMRGenerator( override val resourcesGenerationDir: File = File(File(outputDir, flattenClassName), "res") - override fun getMRClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - override fun processMRClass(mrClass: TypeSpec.Builder) { super.processMRClass(mrClass) From 0b67af926eeadf80366f247db8eb7ea03fb71bc3 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Fri, 8 Dec 2023 02:52:47 +0700 Subject: [PATCH 063/352] #535 remove configure depends task, replaced on input/output files --- .../icerock/gradle/MultiplatformResourcesPlugin.kt | 5 +---- .../tasks/GenerateMultiplatformResourcesTask.kt | 12 +++--------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index d57b44d0b..6ce95873a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -23,6 +23,7 @@ import dev.icerock.gradle.generator.StringsGenerator import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.utils.dependsOnObservable import dev.icerock.gradle.utils.kotlinSourceSetsObservable +import java.io.File import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.file.SourceDirectorySet @@ -40,7 +41,6 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinTarget import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.konan.target.KonanTarget import org.jetbrains.kotlin.tooling.core.extrasKeyOf -import java.io.File open class MultiplatformResourcesPlugin : Plugin { @@ -367,9 +367,6 @@ open class MultiplatformResourcesPlugin : Plugin { ) genTask.configure { resourceTask -> - resourceTask.dependsOn(dependsGenTask) //TODO: Убрать после реализации связи через метадату - - // Заменить на список файлов resourceTask.inputMetadataFiles.setFrom( dependsGenTask.flatMap { it.outputMetadataFile 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 a2610b098..ad2dad7ef 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 @@ -153,9 +153,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { return CommonMRGenerator( project = project, settings = settings, - generators = generators.map { - it.createCommonGenerator() - } + generators = generators.map { it.createCommonGenerator() } ) } @@ -166,9 +164,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { return AndroidMRGenerator( project = project, settings = settings, - generators = generators.map { - it.createAndroidGenerator() - } + generators = generators.map { it.createAndroidGenerator() } ) } @@ -179,9 +175,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { return JvmMRGenerator( project = project, settings = settings, - generators = generators.map { - it.createJvmGenerator() - } + generators = generators.map { it.createJvmGenerator() } ) } From 64c4291bb571217e5c57a36b121f7769d3c70041 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Sun, 10 Dec 2023 13:51:53 +0700 Subject: [PATCH 064/352] #535 add plurals generator, correct expect properties generation, rework expect interfaces generation --- .../icerock/gradle/generator/BaseGenerator.kt | 151 ++++++++++++- .../icerock/gradle/generator/MRGenerator.kt | 2 +- .../gradle/generator/PluralsGenerator.kt | 115 ++++++++-- .../gradle/generator/StringsGenerator.kt | 203 +++--------------- .../gradle/generator/TargetMRGenerator.kt | 4 +- .../android/AndroidPluralsGenerator.kt | 5 +- .../android/AndroidStringsGenerator.kt | 6 +- .../generator/apple/ApplePluralsGenerator.kt | 5 +- .../generator/apple/AppleStringsGenerator.kt | 4 +- .../generator/common/CommonMRGenerator.kt | 138 +++++++----- .../common/CommonPluralsGenerator.kt | 5 +- .../common/CommonStringsGenerator.kt | 4 +- .../gradle/generator/js/JsPluralsGenerator.kt | 5 +- .../gradle/generator/js/JsStringsGenerator.kt | 6 +- .../generator/jvm/JvmPluralsGenerator.kt | 5 +- .../generator/jvm/JvmStringsGenerator.kt | 6 +- .../dev/icerock/gradle/metadata/Utils.kt | 4 + .../GenerateMultiplatformResourcesTask.kt | 3 +- .../moko-resources/base/plurals.xml | 9 + 19 files changed, 394 insertions(+), 286 deletions(-) create mode 100644 samples/compose-resources-gallery/shared/src/androidMain/moko-resources/base/plurals.xml diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt index 906574019..c3cb0efe1 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt @@ -10,11 +10,16 @@ import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.PropertySpec.Builder import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.metadata.GeneratedObject -import java.io.File +import dev.icerock.gradle.metadata.GeneratedObjectModifier +import dev.icerock.gradle.metadata.GeneratedProperties +import dev.icerock.gradle.metadata.addActual +import dev.icerock.gradle.metadata.getActualInterfaces +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonObject import org.gradle.api.Project +import java.io.File abstract class BaseGenerator : MRGenerator.Generator { - override fun generate( project: Project, inputMetadata: MutableList, @@ -24,50 +29,174 @@ abstract class BaseGenerator : MRGenerator.Generator { resourcesGenerationDir: File, objectBuilder: TypeSpec.Builder, ): TypeSpec { - // language - key - value - val languageMap: Map> = loadLanguageMap() - val languageKeyValues = languageMap[LanguageType.Base].orEmpty() + // Read previous languages map from metadata + // if target object is expect object or interface return emptyMap() + val previousLanguagesMap: Map> = getPreviousLanguagesMap( + inputMetadata = inputMetadata, + targetObject = targetObject + ) - beforeGenerateResources(objectBuilder, languageMap) + // Read actual resources of target + // If target object is actual object: skip read files again + // + // Structure: language - key - value + val languageMap: Map> = if (targetObject.isActualObject) { + emptyMap() + } else { + loadLanguageMap() + } - val stringsClass = createTypeSpec( + // Sum of previous and target language fields + val languagesAllMaps: Map> = getLanguagesAllMaps( + previousLanguageMaps = previousLanguagesMap, + languageMap = languageMap + ) + val languageKeyValues: Map = languagesAllMaps[LanguageType.Base].orEmpty() + + beforeGenerateResources(objectBuilder, languagesAllMaps) + + val stringsClass: TypeSpec = createTypeSpec( + inputMetadata = inputMetadata, + generatedObjects = generatedObjects, + targetObject = targetObject, keys = languageKeyValues.keys.toList(), + languageMap = languagesAllMaps, objectBuilder = objectBuilder ) - languageMap.forEach { (language: LanguageType, strings: Map) -> + languagesAllMaps.forEach { (language: LanguageType, strings: Map) -> generateResources(resourcesGenerationDir, language, strings) } return stringsClass } - @Suppress("SpreadOperator") private fun createTypeSpec( + inputMetadata: MutableList, + generatedObjects: MutableList, + targetObject: GeneratedObject, keys: List, + languageMap: Map>, objectBuilder: TypeSpec.Builder, ): TypeSpec { objectBuilder.addModifiers(*getClassModifiers()) extendObjectBodyAtStart(objectBuilder) + val generatedProperties = mutableListOf() + keys.forEach { key -> val name = key.replace(".", "_") + //Create metadata property + var generatedProperty = GeneratedProperties( + modifier = GeneratedObjectModifier.None, + name = name, + data = JsonObject( + content = getPropertyMetadata( + key = key, + languageMap = languageMap + ) + ) + ) + val property: Builder = PropertySpec.builder(name, resourceClassName) - getPropertyInitializer(key)?.let { - property.initializer(it) + if (targetObject.isObject) { + // Add modifier for property and setup metadata + generatedProperty = generatedProperty.copy( + modifier = addActualOverrideModifier( + propertyName = name, + property = property, + inputMetadata = inputMetadata, + targetObject = targetObject + ) + ) + + getPropertyInitializer(key)?.let { + property.initializer(it) + } } objectBuilder.addProperty(property.build()) + generatedProperties.add(generatedProperty) } extendObjectBodyAtEnd(objectBuilder) + // Add object in metadata with remove expect realisation + generatedObjects.addActual( + targetObject.copy(properties = generatedProperties) + ) + return objectBuilder.build() } + abstract fun getPropertyMetadata( + key: KeyType, + languageMap: Map>, + ): Map + + private fun addActualOverrideModifier( + propertyName: String, + property: PropertySpec.Builder, + inputMetadata: List, + targetObject: GeneratedObject, + ): GeneratedObjectModifier { + // Read actual interfaces of target object generator type + val actualInterfaces: List = inputMetadata.getActualInterfaces( + generatorType = targetObject.generatorType + ) + + var containsInActualInterfaces = false + + // Search property in actual interfaces + actualInterfaces.forEach { genInterface -> + val hasInInterface = genInterface.properties.any { + it.name == propertyName + } + + if (hasInInterface) { + containsInActualInterfaces = true + } + } + + return if (targetObject.isObject) { + if (containsInActualInterfaces) { + property.addModifiers(KModifier.OVERRIDE) + GeneratedObjectModifier.Override + } else { + when (targetObject.modifier) { +// GeneratedObjectModifier.Expect -> { +// property.addModifiers(KModifier.EXPECT) +// GeneratedObjectModifier.Expect +// } + + GeneratedObjectModifier.Actual -> { + property.addModifiers(KModifier.ACTUAL) + GeneratedObjectModifier.Actual + } + + else -> { + GeneratedObjectModifier.None + } + } + } + } else { + GeneratedObjectModifier.None + } + } + + abstract fun getLanguagesAllMaps( + previousLanguageMaps: Map>, + languageMap: Map> + ): Map> + + abstract fun getPreviousLanguagesMap( + inputMetadata: List, + targetObject: GeneratedObject, + ): Map> + protected abstract fun loadLanguageMap(): Map> protected abstract fun getPropertyInitializer(key: String): CodeBlock? diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt index 237c117b9..7978ad592 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt @@ -86,7 +86,7 @@ abstract class MRGenerator( fun generate( project: Project, inputMetadata: MutableList, - generatedObjects: MutableList, //TODO: Remove emptyList() after complete realisation + generatedObjects: MutableList, targetObject: GeneratedObject, assetsGenerationDir: File, resourcesGenerationDir: File, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt index 486076454..0f98eac98 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt @@ -10,13 +10,20 @@ import dev.icerock.gradle.generator.apple.ApplePluralsGenerator import dev.icerock.gradle.generator.common.CommonPluralsGenerator import dev.icerock.gradle.generator.js.JsPluralsGenerator import dev.icerock.gradle.generator.jvm.JvmPluralsGenerator +import dev.icerock.gradle.metadata.GeneratedObject import dev.icerock.gradle.metadata.GeneratorType +import dev.icerock.gradle.metadata.objectsWithProperties import dev.icerock.gradle.utils.removeLineWraps -import java.io.File -import javax.xml.parsers.DocumentBuilderFactory +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.JsonPrimitive +import kotlinx.serialization.json.decodeFromJsonElement import org.gradle.api.file.FileTree import org.w3c.dom.Document import org.w3c.dom.Element +import java.io.File +import javax.xml.parsers.DocumentBuilderFactory typealias PluralMap = Map @@ -29,18 +36,93 @@ typealias PluralMap = Map private val SOURCE_PLURAL_NODE_NAMES = listOf("plural", "plurals") abstract class PluralsGenerator( - private val pluralsFileTree: FileTree, + private val ownResourcesFileTree: FileTree, private val strictLineBreaks: Boolean ) : BaseGenerator() { - override val inputFiles: Iterable get() = pluralsFileTree.files + override val inputFiles: Iterable + get() = ownResourcesFileTree.matching { it.include(PLURALS_MASK) }.files + override val resourceClassName = ClassName("dev.icerock.moko.resources", "PluralsResource") override val mrObjectName: String = "plurals" override val type: GeneratorType = GeneratorType.Plurals + override fun getLanguagesAllMaps( + previousLanguageMaps: Map>, + languageMap: Map> + ): Map> { + val resultLanguageMap: MutableMap> = mutableMapOf() + + resultLanguageMap.putAll(previousLanguageMaps) + + languageMap.forEach { (languageType: LanguageType, value: Map) -> + + val currentMap: MutableMap = + previousLanguageMaps[languageType]?.toMutableMap() ?: mutableMapOf() + + value.forEach { (key, value) -> currentMap[key] = value } + + resultLanguageMap[languageType] = currentMap + } + + return resultLanguageMap + } + + override fun getPreviousLanguagesMap( + inputMetadata: List, + targetObject: GeneratedObject, + ): Map> { + if (!targetObject.isObject || !targetObject.isActual) return emptyMap() + val json = Json + val objectsWithProperties: List = inputMetadata.objectsWithProperties(targetObject) + + val languagesMaps = mutableMapOf>() + + objectsWithProperties.forEach { generatedObject -> + generatedObject.properties.forEach { property -> + val data = json.decodeFromJsonElement>(property.data) + + data.forEach { (languageTag, value) -> + val languageType: LanguageType = if (languageTag == BASE_LANGUAGE) { + LanguageType.Base + } else { + LanguageType.Locale(languageTag) + } + + val currentMap: MutableMap = + languagesMaps[languageType]?.toMutableMap() ?: mutableMapOf() + currentMap[property.name] = value + + languagesMaps[languageType] = currentMap + } + } + } + + return languagesMaps + } + + override fun getPropertyMetadata( + key: KeyType, + languageMap: Map> + ): Map { + val values = mutableMapOf() + + languageMap.forEach { (languageType, plurals) -> + plurals.forEach { (pluralKey: KeyType, value: Map) -> + if (pluralKey == key) { + values[languageType.language()] = JsonObject(content = value.mapValues { + JsonPrimitive(it.value) + }) + } + } + } + + return values + } + override fun loadLanguageMap(): Map> { - return pluralsFileTree.map { file -> + return inputFiles.map { file -> val language: LanguageType = LanguageType.fromFileName(file.parentFile.name) val strings: Map = loadLanguagePlurals(file) language to strings @@ -98,41 +180,38 @@ abstract class PluralsGenerator( class Feature( private val settings: MRGenerator.Settings ) : ResourceGeneratorFeature { - private val fileTree: FileTree = settings.ownResourcesFileTree - .matching { it.include("**/plurals*.xml") } - override fun createCommonGenerator(): PluralsGenerator = CommonPluralsGenerator( - ownPluralsFileTree = settings.ownResourcesFileTree, - upperPluralsFileTree = settings.upperResourcesFileTree, + ownResourcesFileTree = settings.ownResourcesFileTree, strictLineBreaks = settings.isStrictLineBreaks ) override fun createIosGenerator(): PluralsGenerator = ApplePluralsGenerator( - ownPluralsFileTree = settings.ownResourcesFileTree, - lowerPluralsFileTree = settings.lowerResourcesFileTree, + ownResourcesFileTree = settings.ownResourcesFileTree, strictLineBreaks = settings.isStrictLineBreaks, baseLocalizationRegion = settings.iosLocalizationRegion ) override fun createAndroidGenerator(): PluralsGenerator = AndroidPluralsGenerator( - ownPluralsFileTree = settings.ownResourcesFileTree, - lowerPluralsFileTree = settings.lowerResourcesFileTree, + ownResourcesFileTree = settings.ownResourcesFileTree, strictLineBreaks = settings.isStrictLineBreaks, androidRClassPackage = settings.androidRClassPackage, ) override fun createJvmGenerator(): PluralsGenerator = JvmPluralsGenerator( - ownPluralsFileTree = settings.ownResourcesFileTree, - lowerPluralsFileTree = settings.lowerResourcesFileTree, + ownResourcesFileTree = settings.ownResourcesFileTree, strictLineBreaks = settings.isStrictLineBreaks, settings = settings ) override fun createJsGenerator(): PluralsGenerator = JsPluralsGenerator( - ownPluralsFileTree = settings.ownResourcesFileTree, - lowerPluralsFileTree = settings.lowerResourcesFileTree, + ownResourcesFileTree = settings.ownResourcesFileTree, mrClassPackage = settings.packageName, strictLineBreaks = settings.isStrictLineBreaks ) } + + + companion object { + const val PLURALS_MASK = "**/plurals*.xml" + } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt index 0ce01cca3..d46510ed8 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt @@ -5,84 +5,39 @@ package dev.icerock.gradle.generator import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.PropertySpec -import com.squareup.kotlinpoet.PropertySpec.Builder -import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.android.AndroidStringsGenerator import dev.icerock.gradle.generator.apple.AppleStringsGenerator import dev.icerock.gradle.generator.common.CommonStringsGenerator import dev.icerock.gradle.generator.js.JsStringsGenerator import dev.icerock.gradle.generator.jvm.JvmStringsGenerator import dev.icerock.gradle.metadata.GeneratedObject -import dev.icerock.gradle.metadata.GeneratedObjectModifier -import dev.icerock.gradle.metadata.GeneratedObjectType -import dev.icerock.gradle.metadata.GeneratedProperties import dev.icerock.gradle.metadata.GeneratorType -import dev.icerock.gradle.metadata.addActual -import dev.icerock.gradle.metadata.getActualInterfaces import dev.icerock.gradle.metadata.objectsWithProperties import dev.icerock.gradle.utils.removeLineWraps -import java.io.File -import javax.xml.parsers.DocumentBuilderFactory import kotlinx.serialization.json.Json -import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonPrimitive import kotlinx.serialization.json.decodeFromJsonElement -import org.gradle.api.Project import org.gradle.api.file.FileTree +import java.io.File +import javax.xml.parsers.DocumentBuilderFactory typealias KeyType = String abstract class StringsGenerator( - private val ownStringsFileTree: FileTree, + private val resourcesFileTree: FileTree, private val strictLineBreaks: Boolean, ) : BaseGenerator() { - override fun generate( - project: Project, - inputMetadata: MutableList, - generatedObjects: MutableList, - targetObject: GeneratedObject, - assetsGenerationDir: File, - resourcesGenerationDir: File, - objectBuilder: TypeSpec.Builder, - ): TypeSpec { - - val previousLanguagesMap: Map> = getPreviousLanguagesMap( - inputMetadata = inputMetadata, - targetObject = targetObject - ) - - // language - key - value - val languageMap: Map> = if (targetObject.isActualObject) { - emptyMap() - } else { - loadLanguageMap() - } - - val languagesAllMaps = getLanguagesAllMaps(previousLanguagesMap, languageMap) - val languageKeyValues = languagesAllMaps[LanguageType.Base].orEmpty() - - beforeGenerateResources(objectBuilder, languagesAllMaps) - - val stringsClass = createTypeSpec( - inputMetadata = inputMetadata, - generatedObjects = generatedObjects, - targetObject = targetObject, - keys = languageKeyValues.keys.toList(), - languageMap = languagesAllMaps, - objectBuilder = objectBuilder - ) + override val inputFiles: Iterable + get() = resourcesFileTree.matching { it.include(STRINGS_MASK) }.files - languagesAllMaps.forEach { (language: LanguageType, strings: Map) -> - generateResources(resourcesGenerationDir, language, strings) - } + override val resourceClassName = ClassName("dev.icerock.moko.resources", "StringResource") + override val mrObjectName: String = "strings" - return stringsClass - } + override val type: GeneratorType = GeneratorType.Strings - private fun getLanguagesAllMaps( + override fun getLanguagesAllMaps( previousLanguageMaps: Map>, languageMap: Map> ): Map> { @@ -103,19 +58,19 @@ abstract class StringsGenerator( return resultLanguageMap } - private fun getPreviousLanguagesMap( + override fun getPreviousLanguagesMap( inputMetadata: List, targetObject: GeneratedObject, ): Map> { if (!targetObject.isObject || !targetObject.isActual) return emptyMap() - + val json = Json val objectsWithProperties: List = inputMetadata.objectsWithProperties(targetObject) val languagesMaps = mutableMapOf>() objectsWithProperties.forEach { generatedObject -> generatedObject.properties.forEach { property -> - val data = Json.decodeFromJsonElement>(property.data) + val data = json.decodeFromJsonElement>(property.data) data.forEach { (languageTag, value) -> val languageType: LanguageType = if (languageTag == BASE_LANGUAGE) { @@ -137,127 +92,23 @@ abstract class StringsGenerator( return languagesMaps } - @Suppress("SpreadOperator") - private fun createTypeSpec( - inputMetadata: MutableList, - generatedObjects: MutableList, - targetObject: GeneratedObject, - keys: List, + override fun getPropertyMetadata( + key: KeyType, languageMap: Map>, - objectBuilder: TypeSpec.Builder, - ): TypeSpec { - objectBuilder.addModifiers(*getClassModifiers()) - - extendObjectBodyAtStart(objectBuilder) - - val generatedProperties = mutableListOf() - - keys.forEach { key -> - val name = key.replace(".", "_") + ): Map { + val values = mutableMapOf() - val values = mutableMapOf() - - languageMap.forEach { (languageType, strings) -> - strings.forEach { (stringKey, value) -> - if (stringKey == key) { - values[languageType.language()] = JsonPrimitive(value) - } + languageMap.forEach { (languageType, strings) -> + strings.forEach { (stringKey, value) -> + if (stringKey == key) { + values[languageType.language()] = JsonPrimitive(value) } } - - var generatedProperty = GeneratedProperties( - modifier = GeneratedObjectModifier.None, - name = name, - data = JsonObject(values) - ) - - val property: Builder = PropertySpec.builder(name, resourceClassName) - - if (targetObject.isObject) { - // Add modifier for property and setup metadata - generatedProperty = generatedProperty.copy( - modifier = addActualOverrideModifier( - propertyName = name, - property = property, - inputMetadata = inputMetadata, - targetObject = targetObject - ) - ) - - getPropertyInitializer(key)?.let { - property.initializer(it) - } - } - - objectBuilder.addProperty(property.build()) - - generatedProperties.add(generatedProperty) } - extendObjectBodyAtEnd(objectBuilder) - - generatedObjects.addActual( - targetObject.copy(properties = generatedProperties) - ) - - return objectBuilder.build() + return values } - private fun addActualOverrideModifier( - propertyName: String, - property: PropertySpec.Builder, - inputMetadata: List, - targetObject: GeneratedObject, - ): GeneratedObjectModifier { - val actualInterfaces = inputMetadata.getActualInterfaces( - generatorType = targetObject.generatorType - ) - - var containsInActualInterfaces = false - - actualInterfaces.forEach { genInterface -> - val hasInInterface = genInterface.properties.any { - it.name == propertyName - } - - if (hasInInterface) { - containsInActualInterfaces = true - } - } - - return if (targetObject.type == GeneratedObjectType.Object) { - if (containsInActualInterfaces) { - property.addModifiers(KModifier.OVERRIDE) - GeneratedObjectModifier.Override - } else { - when (targetObject.modifier) { - GeneratedObjectModifier.Expect -> { - property.addModifiers(KModifier.EXPECT) - GeneratedObjectModifier.Expect - } - - GeneratedObjectModifier.Actual -> { - property.addModifiers(KModifier.ACTUAL) - GeneratedObjectModifier.Actual - } - - else -> { - GeneratedObjectModifier.None - } - } - } - } else { - GeneratedObjectModifier.None - } - } - - override val inputFiles: Iterable - get() = (ownStringsFileTree).matching { it.include(STRINGS_MASK) }.files - - override val resourceClassName = ClassName("dev.icerock.moko.resources", "StringResource") - override val mrObjectName: String = "strings" - - override val type: GeneratorType = GeneratorType.Strings override fun loadLanguageMap(): Map> { return inputFiles.map { file -> @@ -310,30 +161,30 @@ abstract class StringsGenerator( private val settings: MRGenerator.Settings, ) : ResourceGeneratorFeature { override fun createCommonGenerator(): StringsGenerator = CommonStringsGenerator( - ownStringsFileTree = settings.ownResourcesFileTree, + resourcesFileTree = settings.ownResourcesFileTree, strictLineBreaks = settings.isStrictLineBreaks ) override fun createIosGenerator(): StringsGenerator = AppleStringsGenerator( - ownStringsFileTree = settings.ownResourcesFileTree, + resourcesFileTree = settings.ownResourcesFileTree, strictLineBreaks = settings.isStrictLineBreaks, baseLocalizationRegion = settings.iosLocalizationRegion ) override fun createAndroidGenerator(): StringsGenerator = AndroidStringsGenerator( - ownStringsFileTree = settings.ownResourcesFileTree, + resourcesFileTree = settings.ownResourcesFileTree, strictLineBreaks = settings.isStrictLineBreaks, androidRClassPackage = settings.androidRClassPackage ) override fun createJsGenerator(): StringsGenerator = JsStringsGenerator( - ownStringsFileTree = settings.ownResourcesFileTree, + resourcesFileTree = settings.ownResourcesFileTree, mrClassPackage = settings.packageName, strictLineBreaks = settings.isStrictLineBreaks ) override fun createJvmGenerator(): StringsGenerator = JvmStringsGenerator( - ownStringsFileTree = settings.ownResourcesFileTree, + resourcesFileTree = settings.ownResourcesFileTree, strictLineBreaks = settings.isStrictLineBreaks, settings = settings ) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt index eb618d6ad..a2b8656d7 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt @@ -11,6 +11,7 @@ import dev.icerock.gradle.metadata.GeneratorType import dev.icerock.gradle.metadata.Metadata.createOutputMetadata import dev.icerock.gradle.metadata.Metadata.readInputMetadata import dev.icerock.gradle.metadata.addActual +import dev.icerock.gradle.metadata.getActualInterfaces import dev.icerock.gradle.metadata.getExpectInterfaces import dev.icerock.gradle.metadata.getInterfaceName import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask @@ -97,7 +98,6 @@ abstract class TargetMRGenerator( } } - val expectInterfacesList: List = inputMetadata.getExpectInterfaces() val generatedActualObjects = mutableListOf() generators.forEach { generator -> @@ -107,7 +107,7 @@ abstract class TargetMRGenerator( // Implement to object expect interfaces from previous // levels of resources - expectInterfacesList.forEach { generatedObject: GeneratedObject -> + inputMetadata.getActualInterfaces(generator.type).forEach { generatedObject: GeneratedObject -> builder.addSuperinterface( ClassName( packageName = settings.packageName, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt index 92bbd05a2..990bce113 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt @@ -18,11 +18,10 @@ import org.gradle.api.file.FileTree import java.io.File class AndroidPluralsGenerator( - ownPluralsFileTree: FileTree, - lowerPluralsFileTree: FileTree, + ownResourcesFileTree: FileTree, strictLineBreaks: Boolean, private val androidRClassPackage: String, -) : PluralsGenerator(ownPluralsFileTree, strictLineBreaks), +) : PluralsGenerator(ownResourcesFileTree, strictLineBreaks), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt index 7b422cd54..af6e8f6a3 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt @@ -12,16 +12,16 @@ import dev.icerock.gradle.generator.LanguageType import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable import dev.icerock.gradle.generator.StringsGenerator -import java.io.File import org.apache.commons.text.StringEscapeUtils import org.gradle.api.file.FileTree +import java.io.File class AndroidStringsGenerator( - private val ownStringsFileTree: FileTree, + resourcesFileTree: FileTree, strictLineBreaks: Boolean, private val androidRClassPackage: String, ) : StringsGenerator( - ownStringsFileTree = ownStringsFileTree, + resourcesFileTree = resourcesFileTree, strictLineBreaks = strictLineBreaks ), ObjectBodyExtendable by NOPObjectBodyExtendable() { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/ApplePluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/ApplePluralsGenerator.kt index 42623e536..3d789cf10 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/ApplePluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/ApplePluralsGenerator.kt @@ -15,11 +15,10 @@ import org.gradle.api.file.FileTree import java.io.File class ApplePluralsGenerator( - ownPluralsFileTree: FileTree, - lowerPluralsFileTree: FileTree, + ownResourcesFileTree: FileTree, strictLineBreaks: Boolean, private val baseLocalizationRegion: String -) : PluralsGenerator(ownPluralsFileTree, strictLineBreaks), +) : PluralsGenerator(ownResourcesFileTree, strictLineBreaks), ObjectBodyExtendable by AppleGeneratorHelper() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleStringsGenerator.kt index a632eca50..953fa26a1 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleStringsGenerator.kt @@ -16,11 +16,11 @@ import org.apache.commons.text.StringEscapeUtils import org.gradle.api.file.FileTree class AppleStringsGenerator( - ownStringsFileTree: FileTree, + resourcesFileTree: FileTree, strictLineBreaks: Boolean, private val baseLocalizationRegion: String ) : StringsGenerator( - ownStringsFileTree = ownStringsFileTree, + resourcesFileTree = resourcesFileTree, strictLineBreaks = strictLineBreaks ), ObjectBodyExtendable by AppleGeneratorHelper() { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index a3588d171..6c8b9171b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -13,14 +13,16 @@ import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.metadata.GeneratedObject import dev.icerock.gradle.metadata.GeneratedObjectModifier import dev.icerock.gradle.metadata.GeneratedObjectType +import dev.icerock.gradle.metadata.GeneratorType import dev.icerock.gradle.metadata.GeneratorType.None -import dev.icerock.gradle.metadata.Metadata import dev.icerock.gradle.metadata.Metadata.createOutputMetadata +import dev.icerock.gradle.metadata.Metadata.readInputMetadata import dev.icerock.gradle.metadata.getInterfaceName import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.toModifier import dev.icerock.gradle.utils.targetName import org.gradle.api.Project +import org.gradle.api.file.FileTree import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.dsl.KotlinCompile @@ -63,7 +65,7 @@ class CommonMRGenerator( //Read list of generated resources on previous level if (settings.lowerResourcesFileTree.files.isNotEmpty()) { inputMetadata.addAll( - Metadata.readInputMetadata( + readInputMetadata( inputMetadataFiles = settings.inputMetadataFiles ) ) @@ -129,63 +131,30 @@ class CommonMRGenerator( .addModifiers(KModifier.EXPECT) // expect/actual .addModifiers(visibilityModifier) // public/internal - - val generatedExpectInterfaces = mutableListOf() val generatedExpectObjects = mutableListOf() + generateExpectInterfaces( + visibilityModifier = visibilityModifier, + upperResourcesFileTree = settings.upperResourcesFileTree, + generatedObjects = generatedObjects, + fileSpec = fileSpec + ) + generators.forEach { generator: Generator -> val builder: TypeSpec.Builder = TypeSpec .objectBuilder(generator.mrObjectName) // resource name: example strings .addModifiers(visibilityModifier) // public/internal - // Check upper directories on files with resources - val targetsWithResources: List = settings.upperResourcesFileTree.map { - it.targetName - }.distinct() - // .filter { it.isDirectory } - // .filter { file: File -> - // file.listFiles()?.isNotEmpty() ?: false - // } - - val generatedInterfaces: List = if (targetsWithResources.isNotEmpty()) { - val expectInterfacesList = mutableListOf() - - // If upper directory has files of resources, need to generate - // expect interface for sourceSet - targetsWithResources.forEach { targetName -> - val interfaceName = getInterfaceName( - targetName = targetName, - generator = generator - ) - - val resourcesInterface: TypeSpec = - TypeSpec.interfaceBuilder(interfaceName) - .addModifiers(visibilityModifier) - .addModifiers(KModifier.EXPECT) - .build() - - expectInterfacesList.add("${resourcesInterface.name}") - fileSpec.addType(resourcesInterface) - } - - expectInterfacesList - } else emptyList() + val expectInterfaces: List = generatedObjects.filter { + it.generatorType == generator.type && it.isExpectInterface + } //Implement interfaces for generated expect object - generatedInterfaces.forEach { interfaceName -> + expectInterfaces.forEach { expectInterface -> builder.addSuperinterface( ClassName( packageName = resourcePackage, - interfaceName - ) - ) - - generatedExpectInterfaces.add( - GeneratedObject( - generatorType = generator.type, - name = interfaceName, - type = GeneratedObjectType.Interface, - modifier = GeneratedObjectModifier.Expect, + expectInterface.name ) ) } @@ -199,7 +168,7 @@ class CommonMRGenerator( modifier = GeneratedObjectModifier.Expect, type = GeneratedObjectType.Object, name = generator.mrObjectName, - interfaces = generatedInterfaces + interfaces = expectInterfaces.map { it.name } ), assetsGenerationDir = assetsGenerationDir, resourcesGenerationDir = resourcesGenerationDir, @@ -219,7 +188,6 @@ class CommonMRGenerator( objects = generatedExpectObjects ) ) - generatedObjects.addAll(generatedExpectInterfaces) processMRClass(mrClassSpec) @@ -227,6 +195,78 @@ class CommonMRGenerator( fileSpec.addType(mrClass) } + private fun generateExpectInterfaces( + visibilityModifier: KModifier, + upperResourcesFileTree: FileTree, + generatedObjects: MutableList, + fileSpec: Builder, + ) { + val expectInterfaces = mutableListOf() + + upperResourcesFileTree.forEach { + logger.warn("parentFile 1 = ${it.parentFile.name}") // need for images,colors, files, fonts, assets + + if (it.path.matches("^.*/strings.*.xml".toRegex())) { + val generatorType: GeneratorType = GeneratorType.Strings + val interfaceName: String = getInterfaceName( + targetName = it.targetName, + generatorType = generatorType + ) + + expectInterfaces.add( + GeneratedObject( + generatorType = generatorType, + type = GeneratedObjectType.Interface, + modifier = GeneratedObjectModifier.Expect, + name = interfaceName + ) + ) + } else if (it.path.matches("^.*/plurals.*.xml".toRegex())) { + val generatorType: GeneratorType = GeneratorType.Plurals + val interfaceName: String = getInterfaceName( + targetName = it.targetName, + generatorType = generatorType + ) + + expectInterfaces.add( + GeneratedObject( + generatorType = generatorType, + type = GeneratedObjectType.Interface, + modifier = GeneratedObjectModifier.Expect, + name = interfaceName + ) + ) + } + } + + expectInterfaces.distinctBy { + it.name + }.forEach { expectInterface -> + val resourcesInterface: TypeSpec = + TypeSpec.interfaceBuilder(expectInterface.name) + .addModifiers(visibilityModifier) + .addModifiers(KModifier.EXPECT) + .build() + + fileSpec.addType(resourcesInterface) + + generatedObjects.add(expectInterface) + } + + + logger.warn("i") + logger.warn("i") + logger.warn("i") + + generatedObjects.forEach { + logger.warn("metadata : $it") + } + + logger.warn("i") + logger.warn("i") + logger.warn("i") + } + private fun generateActualInterfacesFileSpec( inputMetadata: MutableList, generatedObjects: MutableList, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonPluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonPluralsGenerator.kt index 1369259d9..67d387dda 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonPluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonPluralsGenerator.kt @@ -11,10 +11,9 @@ import dev.icerock.gradle.generator.PluralsGenerator import org.gradle.api.file.FileTree class CommonPluralsGenerator( - ownPluralsFileTree: FileTree, - upperPluralsFileTree: FileTree, + ownResourcesFileTree: FileTree, strictLineBreaks: Boolean, -) : PluralsGenerator(ownPluralsFileTree, strictLineBreaks), +) : PluralsGenerator(ownResourcesFileTree, strictLineBreaks), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getPropertyInitializer( key: String diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonStringsGenerator.kt index 64b942753..e06f12aaf 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonStringsGenerator.kt @@ -11,10 +11,10 @@ import dev.icerock.gradle.generator.StringsGenerator import org.gradle.api.file.FileTree class CommonStringsGenerator( - ownStringsFileTree: FileTree, + resourcesFileTree: FileTree, strictLineBreaks: Boolean ) : StringsGenerator( - ownStringsFileTree = ownStringsFileTree, + resourcesFileTree = resourcesFileTree, strictLineBreaks = strictLineBreaks ), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getPropertyInitializer(key: String): CodeBlock? = null diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsPluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsPluralsGenerator.kt index 5ceab3b79..f4a68fc4f 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsPluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsPluralsGenerator.kt @@ -23,11 +23,10 @@ import org.gradle.api.file.FileTree import java.io.File class JsPluralsGenerator( - ownPluralsFileTree: FileTree, - lowerPluralsFileTree: FileTree, + ownResourcesFileTree: FileTree, mrClassPackage: String, strictLineBreaks: Boolean -) : PluralsGenerator(ownPluralsFileTree, strictLineBreaks), +) : PluralsGenerator(ownResourcesFileTree, strictLineBreaks), ObjectBodyExtendable by NOPObjectBodyExtendable() { private val flattenClassPackage = mrClassPackage.flatName diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt index 9b3995d45..58bf6523d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt @@ -18,17 +18,17 @@ import dev.icerock.gradle.generator.StringsGenerator import dev.icerock.gradle.generator.js.JsMRGenerator.Companion.STRINGS_FALLBACK_FILE_URL_PROPERTY_NAME import dev.icerock.gradle.generator.js.JsMRGenerator.Companion.SUPPORTED_LOCALES_PROPERTY_NAME import dev.icerock.gradle.utils.flatName -import java.io.File import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.put import org.gradle.api.file.FileTree +import java.io.File class JsStringsGenerator( - ownStringsFileTree: FileTree, + resourcesFileTree: FileTree, mrClassPackage: String, strictLineBreaks: Boolean ) : StringsGenerator( - ownStringsFileTree = ownStringsFileTree, + resourcesFileTree = resourcesFileTree, strictLineBreaks = strictLineBreaks ), ObjectBodyExtendable by NOPObjectBodyExtendable() { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmPluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmPluralsGenerator.kt index bd0a314e6..693de797d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmPluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmPluralsGenerator.kt @@ -17,11 +17,10 @@ import org.gradle.api.file.FileTree import java.io.File class JvmPluralsGenerator( - ownPluralsFileTree: FileTree, - lowerPluralsFileTree: FileTree, + ownResourcesFileTree: FileTree, strictLineBreaks: Boolean, settings: MRGenerator.Settings -) : PluralsGenerator(ownPluralsFileTree, strictLineBreaks), +) : PluralsGenerator(ownResourcesFileTree, strictLineBreaks), ObjectBodyExtendable by ClassLoaderExtender(settings.className) { private val flattenClassPackage: String = settings.packageName.remove('.') diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt index e255a5fd9..d47d83a7c 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt @@ -12,15 +12,15 @@ import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.ObjectBodyExtendable import dev.icerock.gradle.generator.StringsGenerator import dev.icerock.gradle.utils.flatName -import java.io.File import org.gradle.api.file.FileTree +import java.io.File class JvmStringsGenerator( - ownStringsFileTree: FileTree, + resourcesFileTree: FileTree, strictLineBreaks: Boolean, settings: MRGenerator.Settings, ) : StringsGenerator( - ownStringsFileTree = ownStringsFileTree, + resourcesFileTree = resourcesFileTree, strictLineBreaks = strictLineBreaks ), ObjectBodyExtendable by ClassLoaderExtender(settings.className) { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Utils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Utils.kt index b12eb6903..dbc0c2c06 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Utils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Utils.kt @@ -6,3 +6,7 @@ import dev.icerock.gradle.utils.capitalize internal fun getInterfaceName(targetName: String, generator: Generator): String { return targetName.capitalize() + generator.mrObjectName.capitalize() } + +internal fun getInterfaceName(targetName: String, generatorType: GeneratorType): String { + return targetName.capitalize() + generatorType.name.capitalize() +} 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 ad2dad7ef..f2330f440 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 @@ -7,6 +7,7 @@ package dev.icerock.gradle.tasks import dev.icerock.gradle.MRVisibility import dev.icerock.gradle.configuration.getAndroidRClassPackage import dev.icerock.gradle.generator.MRGenerator +import dev.icerock.gradle.generator.PluralsGenerator import dev.icerock.gradle.generator.ResourceGeneratorFeature import dev.icerock.gradle.generator.StringsGenerator import dev.icerock.gradle.generator.android.AndroidMRGenerator @@ -137,7 +138,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { ): List> { return listOf( StringsGenerator.Feature(settings), -// PluralsGenerator.Feature(settings), + PluralsGenerator.Feature(settings), // ImagesGenerator.Feature(settings, logger), // FontsGenerator.Feature(settings), // FilesGenerator.Feature(settings), diff --git a/samples/compose-resources-gallery/shared/src/androidMain/moko-resources/base/plurals.xml b/samples/compose-resources-gallery/shared/src/androidMain/moko-resources/base/plurals.xml new file mode 100644 index 000000000..90e223e1c --- /dev/null +++ b/samples/compose-resources-gallery/shared/src/androidMain/moko-resources/base/plurals.xml @@ -0,0 +1,9 @@ + + + + zero chars, android + %d char, android + %d chars, android + %d chars, android + + \ No newline at end of file From bb8cc366b986704952590bb9f85b25ce28bfda22 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Sun, 10 Dec 2023 15:24:33 +0700 Subject: [PATCH 065/352] #535 add expect interfaces types, fix jvm target generation --- .../gradle/MultiplatformResourcesPlugin.kt | 32 ++++--- .../icerock/gradle/generator/BaseGenerator.kt | 4 +- .../gradle/generator/ColorsGenerator.kt | 2 + .../gradle/generator/ImagesGenerator.kt | 16 ++-- .../gradle/generator/PluralsGenerator.kt | 1 + .../gradle/generator/StringsGenerator.kt | 1 + .../android/AndroidImagesGenerator.kt | 1 - .../generator/apple/AppleImagesGenerator.kt | 2 +- .../generator/common/CommonMRGenerator.kt | 87 +++++++------------ .../gradle/generator/js/JsImagesGenerator.kt | 1 - .../generator/jvm/ClassLoaderExtender.kt | 3 - .../generator/jvm/JvmImagesGenerator.kt | 1 - .../generator/jvm/JvmStringsGenerator.kt | 3 +- .../moko-resources/images/car_white.svg | 30 +++++++ 14 files changed, 98 insertions(+), 86 deletions(-) create mode 100644 samples/compose-resources-gallery/shared/src/androidMain/moko-resources/images/car_white.svg diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 6ce95873a..f4e67a28b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -23,7 +23,6 @@ import dev.icerock.gradle.generator.StringsGenerator import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.utils.dependsOnObservable import dev.icerock.gradle.utils.kotlinSourceSetsObservable -import java.io.File import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.file.SourceDirectorySet @@ -41,6 +40,7 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinTarget import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.konan.target.KonanTarget import org.jetbrains.kotlin.tooling.core.extrasKeyOf +import java.io.File open class MultiplatformResourcesPlugin : Plugin { @@ -391,19 +391,31 @@ open class MultiplatformResourcesPlugin : Plugin { ) when (target.platformType) { - KotlinPlatformType.common -> configureCommonTargetGenerator(target, settings, features) - KotlinPlatformType.jvm -> configureJvmTargetGenerator(target, settings, features) - KotlinPlatformType.js -> configureJsTargetGenerator(target, settings, features) + KotlinPlatformType.common -> configureCommonTargetGenerator( + target = target, + settings = settings, + features = features + ) + KotlinPlatformType.jvm -> configureJvmTargetGenerator( + target = target, + settings = settings, + features = features + ) + KotlinPlatformType.js -> configureJsTargetGenerator( + target = target, + settings = settings, + features = features + ) KotlinPlatformType.androidJvm -> configureAndroidTargetGenerator( - target, - settings, - features + target = target, + settings = settings, + features = features ) KotlinPlatformType.native -> configureNativeTargetGenerator( - target as KotlinNativeTarget, - settings, - features + target = target as KotlinNativeTarget, + settings = settings, + features = features ) KotlinPlatformType.wasm -> { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt index c3cb0efe1..853e8af19 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt @@ -81,7 +81,9 @@ abstract class BaseGenerator : MRGenerator.Generator { ): TypeSpec { objectBuilder.addModifiers(*getClassModifiers()) - extendObjectBodyAtStart(objectBuilder) + if (targetObject.isActualObject) { + extendObjectBodyAtStart(objectBuilder) + } val generatedProperties = mutableListOf() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt index 8918c02af..049ac30dc 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt @@ -206,6 +206,8 @@ abstract class ColorsGenerator( internal const val XmlColorReferencePrefix = "@color/" internal const val RgbFormatLength = 6 internal const val DefaultAlpha = "FF" + + val COLORS_REGEX: Regex = "^.*/colors.*.xml".toRegex() } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt index 8ff7e45e9..b6f30b271 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt @@ -23,11 +23,13 @@ import org.gradle.api.logging.Logger import java.io.File abstract class ImagesGenerator( - private val inputFileTree: FileTree + private val resourcesFileTree: FileTree ) : MRGenerator.Generator { override val inputFiles: Iterable - get() = inputFileTree.files + get() = resourcesFileTree.matching { + it.include("images/**/*.png", "images/**/*.jpg", "images/**/*.svg") + } override val resourceClassName = ClassName("dev.icerock.moko.resources", "ImageResource") override val mrObjectName: String = "images" @@ -43,7 +45,7 @@ abstract class ImagesGenerator( resourcesGenerationDir: File, objectBuilder: TypeSpec.Builder, ): TypeSpec { - val fileMap = inputFileTree.groupBy { file -> + val fileMap: Map> = inputFiles.groupBy { file -> // SVGs do not have scale suffixes, so we need to remove the extension first val key = file .nameWithoutExtension @@ -112,11 +114,6 @@ abstract class ImagesGenerator( private val settings: MRGenerator.Settings, private val logger: Logger ) : ResourceGeneratorFeature { - private val fileTree: FileTree = settings.ownResourcesFileTree - .matching { - it.include("images/**/*.png", "images/**/*.jpg", "images/**/*.svg") - } - override fun createCommonGenerator(): ImagesGenerator = CommonImagesGenerator( ownInputFileTree = settings.ownResourcesFileTree, upperInputFileTree = settings.upperResourcesFileTree @@ -129,19 +126,16 @@ abstract class ImagesGenerator( override fun createAndroidGenerator(): ImagesGenerator = AndroidImagesGenerator( ownInputFileTree = settings.ownResourcesFileTree, - lowerInputFileTree = settings.lowerResourcesFileTree, androidRClassPackageProvider = settings.androidRClassPackage, logger = logger ) override fun createJsGenerator(): ImagesGenerator = JsImagesGenerator( ownInputFileTree = settings.ownResourcesFileTree, - lowerInputFileTree = settings.lowerResourcesFileTree, ) override fun createJvmGenerator(): ImagesGenerator = JvmImagesGenerator( ownInputFileTree = settings.ownResourcesFileTree, - lowerInputFileTree = settings.lowerResourcesFileTree, settings = settings ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt index 0f98eac98..1a550b2b3 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt @@ -213,5 +213,6 @@ abstract class PluralsGenerator( companion object { const val PLURALS_MASK = "**/plurals*.xml" + val PLURALS_REGEX: Regex = "^.*/plurals.*.xml".toRegex() } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt index d46510ed8..897bd10f5 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt @@ -192,5 +192,6 @@ abstract class StringsGenerator( companion object { const val STRINGS_MASK = "**/strings*.xml" + val STRINGS_REGEX: Regex = "^.*/strings.*.xml".toRegex() } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt index 2ecb6ff1c..3df2dde60 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt @@ -23,7 +23,6 @@ import kotlin.reflect.full.functions class AndroidImagesGenerator( ownInputFileTree: FileTree, - lowerInputFileTree: FileTree, private val androidRClassPackageProvider: String, private val logger: Logger ) : ImagesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleImagesGenerator.kt index d574a05c4..2d84cee0f 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleImagesGenerator.kt @@ -21,7 +21,7 @@ import java.io.File class AppleImagesGenerator( ownInputFileTree: FileTree, lowerInputFileTree: FileTree, -) : ImagesGenerator(inputFileTree = ownInputFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { +) : ImagesGenerator(resourcesFileTree = ownInputFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index 6c8b9171b..8fb1a9a74 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -9,7 +9,10 @@ import com.squareup.kotlinpoet.FileSpec import com.squareup.kotlinpoet.FileSpec.Builder import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.generator.ColorsGenerator import dev.icerock.gradle.generator.MRGenerator +import dev.icerock.gradle.generator.PluralsGenerator +import dev.icerock.gradle.generator.StringsGenerator import dev.icerock.gradle.metadata.GeneratedObject import dev.icerock.gradle.metadata.GeneratedObjectModifier import dev.icerock.gradle.metadata.GeneratedObjectType @@ -71,10 +74,6 @@ class CommonMRGenerator( ) } - inputMetadata.forEach { - logger.warn("i prev: $it") - } - val fileSpec: Builder = FileSpec.builder( packageName = settings.packageName, fileName = settings.className @@ -152,10 +151,7 @@ class CommonMRGenerator( //Implement interfaces for generated expect object expectInterfaces.forEach { expectInterface -> builder.addSuperinterface( - ClassName( - packageName = resourcePackage, - expectInterface.name - ) + ClassName(packageName = resourcePackage, expectInterface.name) ) } @@ -204,44 +200,38 @@ class CommonMRGenerator( val expectInterfaces = mutableListOf() upperResourcesFileTree.forEach { - logger.warn("parentFile 1 = ${it.parentFile.name}") // need for images,colors, files, fonts, assets - - if (it.path.matches("^.*/strings.*.xml".toRegex())) { - val generatorType: GeneratorType = GeneratorType.Strings - val interfaceName: String = getInterfaceName( - targetName = it.targetName, - generatorType = generatorType - ) - - expectInterfaces.add( - GeneratedObject( - generatorType = generatorType, - type = GeneratedObjectType.Interface, - modifier = GeneratedObjectModifier.Expect, - name = interfaceName - ) - ) - } else if (it.path.matches("^.*/plurals.*.xml".toRegex())) { - val generatorType: GeneratorType = GeneratorType.Plurals - val interfaceName: String = getInterfaceName( - targetName = it.targetName, - generatorType = generatorType - ) + val generatorType: GeneratorType = if (it.path.matches(StringsGenerator.STRINGS_REGEX)) { + GeneratorType.Strings + } else if (it.path.matches(PluralsGenerator.PLURALS_REGEX)) { + GeneratorType.Plurals + } else if (it.path.matches(ColorsGenerator.COLORS_REGEX)) { + GeneratorType.Colors + } else if (it.parentFile.name == "images") { + GeneratorType.Images + } else if (it.parentFile.name == "files") { + GeneratorType.Files + } else if (it.parentFile.name == "assets") { + GeneratorType.Assets + } else if (it.parentFile.name == "fonts") { + GeneratorType.Fonts + } else { + GeneratorType.None + } - expectInterfaces.add( - GeneratedObject( - generatorType = generatorType, - type = GeneratedObjectType.Interface, - modifier = GeneratedObjectModifier.Expect, - name = interfaceName + expectInterfaces.add( + GeneratedObject( + generatorType = generatorType, + type = GeneratedObjectType.Interface, + modifier = GeneratedObjectModifier.Expect, + name = getInterfaceName( + targetName = it.targetName, + generatorType = generatorType ) ) - } + ) } - expectInterfaces.distinctBy { - it.name - }.forEach { expectInterface -> + expectInterfaces.distinctBy { it.name }.forEach { expectInterface -> val resourcesInterface: TypeSpec = TypeSpec.interfaceBuilder(expectInterface.name) .addModifiers(visibilityModifier) @@ -252,19 +242,6 @@ class CommonMRGenerator( generatedObjects.add(expectInterface) } - - - logger.warn("i") - logger.warn("i") - logger.warn("i") - - generatedObjects.forEach { - logger.warn("metadata : $it") - } - - logger.warn("i") - logger.warn("i") - logger.warn("i") } private fun generateActualInterfacesFileSpec( @@ -273,7 +250,7 @@ class CommonMRGenerator( visibilityModifier: KModifier, fileSpec: Builder, ) { - val targetName = settings.ownResourcesFileTree.files.first().targetName + val targetName: String = settings.ownResourcesFileTree.files.first().targetName generators.forEach { generator -> val interfaceName = getInterfaceName( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsImagesGenerator.kt index 939904161..5828fe4dd 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsImagesGenerator.kt @@ -19,7 +19,6 @@ import java.io.File class JsImagesGenerator( ownInputFileTree: FileTree, - lowerInputFileTree: FileTree, ) : ImagesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/ClassLoaderExtender.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/ClassLoaderExtender.kt index 1dfc5ed9e..5a86c6bc6 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/ClassLoaderExtender.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/ClassLoaderExtender.kt @@ -6,11 +6,9 @@ package dev.icerock.gradle.generator.jvm import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.ObjectBodyExtendable -import org.gradle.api.provider.Provider class ClassLoaderExtender(private val mrClassName: String) : ObjectBodyExtendable { override fun extendObjectBodyAtStart(classBuilder: TypeSpec.Builder) { @@ -18,7 +16,6 @@ class ClassLoaderExtender(private val mrClassName: String) : ObjectBodyExtendabl PropertySpec.builder( "resourcesClassLoader", ClassName("java.lang", "ClassLoader"), - KModifier.OVERRIDE ) .initializer(CodeBlock.of("${mrClassName}::class.java.classLoader")) .build() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmImagesGenerator.kt index 11515e1b1..96e8c48dd 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmImagesGenerator.kt @@ -15,7 +15,6 @@ import java.io.File class JvmImagesGenerator( ownInputFileTree: FileTree, - lowerInputFileTree: FileTree, settings: MRGenerator.Settings ) : ImagesGenerator(ownInputFileTree), ObjectBodyExtendable by ClassLoaderExtender(settings.className) { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt index d47d83a7c..2f0f89270 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt @@ -22,8 +22,7 @@ class JvmStringsGenerator( ) : StringsGenerator( resourcesFileTree = resourcesFileTree, strictLineBreaks = strictLineBreaks -), - ObjectBodyExtendable by ClassLoaderExtender(settings.className) { +), ObjectBodyExtendable by ClassLoaderExtender(settings.className) { private val flattenClassPackage = settings.packageName.flatName diff --git a/samples/compose-resources-gallery/shared/src/androidMain/moko-resources/images/car_white.svg b/samples/compose-resources-gallery/shared/src/androidMain/moko-resources/images/car_white.svg new file mode 100644 index 000000000..831b6e7f5 --- /dev/null +++ b/samples/compose-resources-gallery/shared/src/androidMain/moko-resources/images/car_white.svg @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + From 20f0cad21bd2cd04f6cafdd02d1bb27a42f73811 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Sun, 10 Dec 2023 15:43:13 +0700 Subject: [PATCH 066/352] #535 remove upper resources from colors generator, fix files filter --- .../gradle/generator/ColorsGenerator.kt | 27 +++++++------------ .../android/AndroidColorsGenerator.kt | 5 ++-- .../generator/apple/AppleColorsGenerator.kt | 5 ++-- .../generator/common/CommonColorsGenerator.kt | 5 ++-- .../gradle/generator/js/JsColorsGenerator.kt | 5 ++-- .../generator/jvm/JvmColorsGenerator.kt | 10 +++---- 6 files changed, 22 insertions(+), 35 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt index 049ac30dc..a69b4f0c3 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt @@ -24,11 +24,11 @@ import java.io.File import javax.xml.parsers.DocumentBuilderFactory abstract class ColorsGenerator( - val project: Project, - private val colorsFileTree: FileTree, + private val resourcesFileTree: FileTree, ) : MRGenerator.Generator { - override val inputFiles: Iterable get() = colorsFileTree.files + override val inputFiles: Iterable + get() = resourcesFileTree.matching { it.include("**/colors*.xml") } override val resourceClassName: ClassName = ClassName("dev.icerock.moko.resources", "ColorResource") override val mrObjectName: String = "colors" @@ -96,7 +96,7 @@ abstract class ColorsGenerator( } } - colorsFileTree.map { file -> + inputFiles.map { file -> val dbFactory = DocumentBuilderFactory.newInstance() val dBuilder = dbFactory.newDocumentBuilder() val doc = dBuilder.parse(file) @@ -148,37 +148,30 @@ abstract class ColorsGenerator( val project: Project, private val settings: MRGenerator.Settings, ) : ResourceGeneratorFeature { - private val fileTree: FileTree = settings.ownResourcesFileTree - .matching { it.include("**/colors*.xml") } - override fun createCommonGenerator() = CommonColorsGenerator( project = project, - ownColorsFileTree = settings.ownResourcesFileTree, - upperColorsFileTree = settings.upperResourcesFileTree + resourcesFileTree = settings.ownResourcesFileTree, ) override fun createIosGenerator() = AppleColorsGenerator( project = project, - ownColorsFileTree = settings.ownResourcesFileTree, - lowerColorsFileTree = settings.lowerResourcesFileTree + resourcesFileTree = settings.ownResourcesFileTree, ) override fun createAndroidGenerator() = AndroidColorsGenerator( project = project, - ownColorsFileTree = settings.ownResourcesFileTree, - lowerColorsFileTree = settings.lowerResourcesFileTree + resourcesFileTree = settings.ownResourcesFileTree, ) override fun createJsGenerator(): ColorsGenerator = JsColorsGenerator( project = project, - ownColorsFileTree = settings.ownResourcesFileTree, - lowerColorsFileTree = settings.lowerResourcesFileTree + resourcesFileTree = settings.ownResourcesFileTree, ) override fun createJvmGenerator() = JvmColorsGenerator( project = project, - ownColorsFileTree = settings.ownResourcesFileTree, - lowerColorsFileTree = settings.lowerResourcesFileTree, settings + resourcesFileTree = settings.ownResourcesFileTree, + mrClassName = settings.className ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt index 1ff31e4bb..4ab3df75a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt @@ -17,9 +17,8 @@ import java.io.File class AndroidColorsGenerator( project: Project, - ownColorsFileTree: FileTree, - lowerColorsFileTree: FileTree, -) : ColorsGenerator(project, ownColorsFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { + resourcesFileTree: FileTree, +) : ColorsGenerator(resourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getImports() = listOf( ClassName("dev.icerock.moko.graphics", "Color") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt index 51d9764a9..29b474cdb 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt @@ -23,9 +23,8 @@ import java.io.File class AppleColorsGenerator( project: Project, - ownColorsFileTree: FileTree, - lowerColorsFileTree: FileTree, -) : ColorsGenerator(project, ownColorsFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { + resourcesFileTree: FileTree, +) : ColorsGenerator(resourcesFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { override fun getImports(): List { return listOf( ClassName("dev.icerock.moko.graphics", "Color") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonColorsGenerator.kt index 46241de4d..831742a67 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonColorsGenerator.kt @@ -15,9 +15,8 @@ import org.gradle.api.file.FileTree class CommonColorsGenerator( project: Project, - ownColorsFileTree: FileTree, - upperColorsFileTree: FileTree, -) : ColorsGenerator(project, ownColorsFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { + resourcesFileTree: FileTree, +) : ColorsGenerator(resourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getImports(): List { return emptyList() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsColorsGenerator.kt index eda8794d0..00830fa73 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsColorsGenerator.kt @@ -20,9 +20,8 @@ import org.gradle.api.file.FileTree class JsColorsGenerator( project: Project, - ownColorsFileTree: FileTree, - lowerColorsFileTree: FileTree, -) : ColorsGenerator(project, ownColorsFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { + resourcesFileTree: FileTree, +) : ColorsGenerator(resourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmColorsGenerator.kt index b26029677..59e1e3ab8 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmColorsGenerator.kt @@ -9,7 +9,6 @@ import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.ColorNode import dev.icerock.gradle.generator.ColorsGenerator -import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.ObjectBodyExtendable import dev.icerock.gradle.generator.jsJvmCommon.createColorResourceInitializer import org.gradle.api.Project @@ -17,11 +16,10 @@ import org.gradle.api.file.FileTree class JvmColorsGenerator( project: Project, - ownColorsFileTree: FileTree, - lowerColorsFileTree: FileTree, - settings: MRGenerator.Settings -) : ColorsGenerator(project, ownColorsFileTree), - ObjectBodyExtendable by ClassLoaderExtender(settings.className) { + resourcesFileTree: FileTree, + mrClassName: String, +) : ColorsGenerator(resourcesFileTree), + ObjectBodyExtendable by ClassLoaderExtender(mrClassName) { override fun getImports() = listOf( ClassName("dev.icerock.moko.graphics", "Color") From ffb8b9a81f5560857cc46c59c6013951c7bd1e67 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Mon, 11 Dec 2023 11:38:16 +0700 Subject: [PATCH 067/352] #535 js action separated from js generator --- .../icerock/gradle/generator/js/JsAction.kt | 160 ++++++++++++++++++ .../gradle/generator/js/JsMRGenerator.kt | 156 ----------------- .../gradle/generator/js/JsPluralsGenerator.kt | 13 +- .../gradle/generator/js/JsStringsGenerator.kt | 12 +- 4 files changed, 177 insertions(+), 164 deletions(-) create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsAction.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsAction.kt new file mode 100644 index 000000000..b5907eeb3 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsAction.kt @@ -0,0 +1,160 @@ +package dev.icerock.gradle.generator.js + +import dev.icerock.gradle.utils.klibs +import org.gradle.api.Action +import org.gradle.api.Project +import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile +import org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl +import java.io.File + +class CopyResourcesToKLibAction( + private val resourcesDirProvider: File, +) : Action { + override fun execute(task: Kotlin2JsCompile) { + val unpackedKLibDir: File = task.destinationDirectory.asFile.get() + val defaultDir = File(unpackedKLibDir, "default") + val resRepackDir = File(defaultDir, "resources") + if (resRepackDir.exists().not()) return + + val resDir = File(resRepackDir, "moko-resources-js") + resourcesDirProvider.copyRecursively( + resDir, + overwrite = true + ) + } +} + +class CopyResourcesToExecutableAction( + private val resourcesGeneratedDir: File, +) : Action { + override fun execute(task: Kotlin2JsCompile) { + val project: Project = task.project + + task.klibs.forEach { dependency -> + copyResourcesFromLibraries( + inputFile = dependency, + project = project, + outputDir = resourcesGeneratedDir + ) + } + + generateWebpackConfig(project, resourcesGeneratedDir) + generateKarmaConfig(project) + } + + private fun generateWebpackConfig(project: Project, resourcesOutput: File) { + val webpackDir = File(project.projectDir, "webpack.config.d") + webpackDir.mkdirs() + + val webpackConfig = File(webpackDir, "moko-resources-generated.js") + val webpackResourcesDir: String = resourcesOutput.absolutePath + .replace("\\", "\\\\") + + webpackConfig.writeText( + // language=js + """ +// noinspection JSUnnecessarySemicolon +;(function(config) { + const path = require('path'); + const MiniCssExtractPlugin = require('mini-css-extract-plugin'); + + const mokoResourcePath = path.resolve("$webpackResourcesDir"); + + config.module.rules.push( + { + test: /\.(.*)/, + resource: [ + path.resolve(mokoResourcePath, "files"), + path.resolve(mokoResourcePath, "images"), + path.resolve(mokoResourcePath, "localization"), + ], + type: 'asset/resource' + } + ); + + config.plugins.push(new MiniCssExtractPlugin()) + config.module.rules.push( + { + test: /\.css${'$'}/, + resource: [ + path.resolve(mokoResourcePath, "fonts"), + ], + use: ['style-loader', 'css-loader'] + } + ) + + config.module.rules.push( + { + test: /\.(otf|ttf)?${'$'}/, + resource: [ + path.resolve(mokoResourcePath, "fonts"), + ], + type: 'asset/resource', + } + ) + + config.resolve.modules.push(mokoResourcePath); +})(config); + """.trimIndent() + ) + } + + private fun generateKarmaConfig(project: Project) { + val webpackDir = File(project.projectDir, "karma.config.d") + webpackDir.mkdirs() + + val webpackTestConfig = File(webpackDir, "moko-resources-generated.js") + val pattern = "`\${output.path}/**/*`" + webpackTestConfig.writeText( + // language=js + """ + // workaround from https://github.com/ryanclark/karma-webpack/issues/498#issuecomment-790040818 + + const output = { + path: require("os").tmpdir() + '/' + '_karma_webpack_' + Math.floor(Math.random() * 1000000), + } + + const optimization = { + runtimeChunk: true + } + + config.set( + { + webpack: {... createWebpackConfig(), output, optimization}, + files: config.files.concat([{ + pattern: $pattern, + watched: false, + included: false, + }] + ) + } + ) + """.trimIndent() + ) + } + + private fun copyResourcesFromLibraries( + inputFile: File, + project: Project, + outputDir: File + ) { + if (inputFile.extension != "klib") return + if (inputFile.exists().not()) return + + project.logger.info("copy resources from $inputFile into $outputDir") + val klibKonan = org.jetbrains.kotlin.konan.file.File(inputFile.path) + val klib = KotlinLibraryLayoutImpl(klib = klibKonan, component = "default") + val layout = klib.extractingToTemp + + try { + File(layout.resourcesDir.path, "moko-resources-js").copyRecursively( + target = outputDir, + overwrite = true + ) + } catch (@Suppress("SwallowedException") exc: kotlin.io.NoSuchFileException) { + project.logger.info("resources in $inputFile not found") + } catch (@Suppress("SwallowedException") exc: java.nio.file.NoSuchFileException) { + project.logger.info("resources in $inputFile not found (empty lib)") + } + } +} \ No newline at end of file diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt index bb8fbd880..483fe1643 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt @@ -115,165 +115,9 @@ class JsMRGenerator( } } - class CopyResourcesToKLibAction( - private val resourcesDirProvider: File, - ) : Action { - override fun execute(task: Kotlin2JsCompile) { - val unpackedKLibDir: File = task.destinationDirectory.asFile.get() - val defaultDir = File(unpackedKLibDir, "default") - val resRepackDir = File(defaultDir, "resources") - if (resRepackDir.exists().not()) return - - val resDir = File(resRepackDir, "moko-resources-js") - resourcesDirProvider.copyRecursively( - resDir, - overwrite = true - ) - } - } - - class CopyResourcesToExecutableAction( - private val resourcesGeneratedDir: File, - ) : Action { - override fun execute(task: Kotlin2JsCompile) { - val project: Project = task.project - - task.klibs.forEach { dependency -> - copyResourcesFromLibraries( - inputFile = dependency, - project = project, - outputDir = resourcesGeneratedDir - ) - } - - generateWebpackConfig(project, resourcesGeneratedDir) - generateKarmaConfig(project) - } - - private fun generateWebpackConfig(project: Project, resourcesOutput: File) { - val webpackDir = File(project.projectDir, "webpack.config.d") - webpackDir.mkdirs() - - val webpackConfig = File(webpackDir, "moko-resources-generated.js") - val webpackResourcesDir: String = resourcesOutput.absolutePath - .replace("\\", "\\\\") - - webpackConfig.writeText( - // language=js - """ -// noinspection JSUnnecessarySemicolon -;(function(config) { - const path = require('path'); - const MiniCssExtractPlugin = require('mini-css-extract-plugin'); - - const mokoResourcePath = path.resolve("$webpackResourcesDir"); - - config.module.rules.push( - { - test: /\.(.*)/, - resource: [ - path.resolve(mokoResourcePath, "files"), - path.resolve(mokoResourcePath, "images"), - path.resolve(mokoResourcePath, "localization"), - ], - type: 'asset/resource' - } - ); - - config.plugins.push(new MiniCssExtractPlugin()) - config.module.rules.push( - { - test: /\.css${'$'}/, - resource: [ - path.resolve(mokoResourcePath, "fonts"), - ], - use: ['style-loader', 'css-loader'] - } - ) - - config.module.rules.push( - { - test: /\.(otf|ttf)?${'$'}/, - resource: [ - path.resolve(mokoResourcePath, "fonts"), - ], - type: 'asset/resource', - } - ) - - config.resolve.modules.push(mokoResourcePath); -})(config); - """.trimIndent() - ) - } - - private fun generateKarmaConfig(project: Project) { - val webpackDir = File(project.projectDir, "karma.config.d") - webpackDir.mkdirs() - - val webpackTestConfig = File(webpackDir, "moko-resources-generated.js") - val pattern = "`\${output.path}/**/*`" - webpackTestConfig.writeText( - // language=js - """ - // workaround from https://github.com/ryanclark/karma-webpack/issues/498#issuecomment-790040818 - - const output = { - path: require("os").tmpdir() + '/' + '_karma_webpack_' + Math.floor(Math.random() * 1000000), - } - - const optimization = { - runtimeChunk: true - } - - config.set( - { - webpack: {... createWebpackConfig(), output, optimization}, - files: config.files.concat([{ - pattern: $pattern, - watched: false, - included: false, - }] - ) - } - ) - """.trimIndent() - ) - } - - private fun copyResourcesFromLibraries( - inputFile: File, - project: Project, - outputDir: File - ) { - if (inputFile.extension != "klib") return - if (inputFile.exists().not()) return - - project.logger.info("copy resources from $inputFile into $outputDir") - val klibKonan = org.jetbrains.kotlin.konan.file.File(inputFile.path) - val klib = KotlinLibraryLayoutImpl(klib = klibKonan, component = "default") - val layout = klib.extractingToTemp - - try { - File(layout.resourcesDir.path, "moko-resources-js").copyRecursively( - target = outputDir, - overwrite = true - ) - } catch (@Suppress("SwallowedException") exc: kotlin.io.NoSuchFileException) { - project.logger.info("resources in $inputFile not found") - } catch (@Suppress("SwallowedException") exc: java.nio.file.NoSuchFileException) { - project.logger.info("resources in $inputFile not found (empty lib)") - } - } - } companion object { - const val STRINGS_JSON_NAME = "stringsJson" - const val PLURALS_JSON_NAME = "pluralsJson" - const val SUPPORTED_LOCALES_PROPERTY_NAME = "supportedLocales" - const val STRINGS_FALLBACK_FILE_URL_PROPERTY_NAME = "stringsFallbackFileUrl" - const val PLURALS_FALLBACK_FILE_URL_PROPERTY_NAME = "stringsFallbackFileUrl" const val LOCALIZATION_DIR = "localization" } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsPluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsPluralsGenerator.kt index f4a68fc4f..ad8ea3cb1 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsPluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsPluralsGenerator.kt @@ -46,11 +46,11 @@ class JsPluralsGenerator( objectBuilder.generateFallbackAndSupportedLanguageProperties( languages = languageMap.keys.toList(), folder = JsMRGenerator.LOCALIZATION_DIR, - fallbackFilePropertyName = JsMRGenerator.PLURALS_FALLBACK_FILE_URL_PROPERTY_NAME, - fallbackFile = "${flattenClassPackage}_${JsMRGenerator.PLURALS_JSON_NAME}.json", + fallbackFilePropertyName = PLURALS_FALLBACK_FILE_URL_PROPERTY_NAME, + fallbackFile = "${flattenClassPackage}_${PLURALS_JSON_NAME}.json", supportedLocalesPropertyName = JsMRGenerator.SUPPORTED_LOCALES_PROPERTY_NAME, getFileNameForLanguage = { language -> - "${flattenClassPackage}_${JsMRGenerator.PLURALS_JSON_NAME}${language.jsResourcesSuffix}.json" + "${flattenClassPackage}_${PLURALS_JSON_NAME}${language.jsResourcesSuffix}.json" } ) val languageKeys = languageMap[LanguageType.Base].orEmpty().keys @@ -74,7 +74,7 @@ class JsPluralsGenerator( strings: Map ) { val fileDirName = - "${flattenClassPackage}_${JsMRGenerator.PLURALS_JSON_NAME}${language.jsResourcesSuffix}" + "${flattenClassPackage}_${PLURALS_JSON_NAME}${language.jsResourcesSuffix}" val localizationDir = File(resourcesGenerationDir, JsMRGenerator.LOCALIZATION_DIR).apply { mkdirs() @@ -110,4 +110,9 @@ class JsPluralsGenerator( pluralsFile.writeText(content) } + + companion object { + const val PLURALS_JSON_NAME = "pluralsJson" + const val PLURALS_FALLBACK_FILE_URL_PROPERTY_NAME = "stringsFallbackFileUrl" + } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt index 58bf6523d..3e5e9163d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt @@ -15,7 +15,6 @@ import dev.icerock.gradle.generator.LanguageType import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable import dev.icerock.gradle.generator.StringsGenerator -import dev.icerock.gradle.generator.js.JsMRGenerator.Companion.STRINGS_FALLBACK_FILE_URL_PROPERTY_NAME import dev.icerock.gradle.generator.js.JsMRGenerator.Companion.SUPPORTED_LOCALES_PROPERTY_NAME import dev.icerock.gradle.utils.flatName import kotlinx.serialization.json.buildJsonObject @@ -51,10 +50,10 @@ class JsStringsGenerator( languages = languageMap.keys.toList(), folder = JsMRGenerator.LOCALIZATION_DIR, fallbackFilePropertyName = STRINGS_FALLBACK_FILE_URL_PROPERTY_NAME, - fallbackFile = "${flattenClassPackage}_${JsMRGenerator.STRINGS_JSON_NAME}.json", + fallbackFile = "${flattenClassPackage}_${STRINGS_JSON_NAME}.json", supportedLocalesPropertyName = SUPPORTED_LOCALES_PROPERTY_NAME, getFileNameForLanguage = { language -> - "${flattenClassPackage}_${JsMRGenerator.STRINGS_JSON_NAME}${language.jsResourcesSuffix}.json" + "${flattenClassPackage}_${STRINGS_JSON_NAME}${language.jsResourcesSuffix}.json" } ) val languageKeys = languageMap[LanguageType.Base].orEmpty().keys @@ -78,7 +77,7 @@ class JsStringsGenerator( strings: Map ) { val fileDirName = - "${flattenClassPackage}_${JsMRGenerator.STRINGS_JSON_NAME}${language.jsResourcesSuffix}" + "${flattenClassPackage}_${STRINGS_JSON_NAME}${language.jsResourcesSuffix}" val localizationDir = File(resourcesGenerationDir, JsMRGenerator.LOCALIZATION_DIR).apply { mkdirs() @@ -94,4 +93,9 @@ class JsStringsGenerator( stringsFile.writeText(content) } + + companion object { + const val STRINGS_JSON_NAME = "stringsJson" + const val STRINGS_FALLBACK_FILE_URL_PROPERTY_NAME = "stringsFallbackFileUrl" + } } From b108786ecde901777a7cfb0da464c99c7e03b5ca Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Mon, 11 Dec 2023 12:43:04 +0700 Subject: [PATCH 068/352] #535 setup JsMRGenerator --- .../gradle/MultiplatformResourcesPlugin.kt | 19 +++++++++-- .../icerock/gradle/configuration/JsTarget.kt | 1 - .../gradle/generator/js/JsMRGenerator.kt | 32 ++----------------- ...droidParamsHelper.kt => JsParamsHelper.kt} | 0 .../gradle/generator/js/JsSetupUtils.kt | 26 +++++++++++++++ .../CopyResourcesToExecutableAction.kt} | 19 +---------- .../js/action/CopyResourcesToKLibAction.kt | 22 +++++++++++++ .../GenerateMultiplatformResourcesTask.kt | 14 +++----- 8 files changed, 74 insertions(+), 59 deletions(-) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/{AndroidParamsHelper.kt => JsParamsHelper.kt} (100%) create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsSetupUtils.kt rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/{JsAction.kt => action/CopyResourcesToExecutableAction.kt} (88%) create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/action/CopyResourcesToKLibAction.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index f4e67a28b..c96d0a1a3 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -121,8 +121,23 @@ open class MultiplatformResourcesPlugin : Plugin { it.platformType.set(target.platformType.name) } - compilation.compileTaskProvider.configure { - it.dependsOn(genTask) + compilation.compileTaskProvider.configure { compileTask: KotlinCompilationTask<*> -> + compileTask.dependsOn(genTask) + + if ( + target.platformType == KotlinPlatformType.js + && compilation as? KotlinJsIrCompilation != null + && compileTask as? Kotlin2JsCompile != null + ) { + setupJsResources( + compileTask = compileTask, + resourcesGenerationDir = genTask.get().outputDirectory.asFile.get() + ) + setupJsKLibResources( + compileTask = compileTask, + resourcesGenerationDir = genTask.get().outputDirectory.asFile.get() + ) + } } } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JsTarget.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JsTarget.kt index 62f015e0d..247f45d4e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JsTarget.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JsTarget.kt @@ -30,7 +30,6 @@ internal fun configureJsTargetGenerator( project = project, settings = settings, generators = features.map { it.createJsGenerator() }, - compilation = compilation, ).apply(project = project) // } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt index 483fe1643..fc48ee7ca 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt @@ -13,22 +13,16 @@ import dev.icerock.gradle.generator.TargetMRGenerator import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.utils.calculateResourcesHash import dev.icerock.gradle.utils.flatName -import dev.icerock.gradle.utils.klibs -import java.io.File -import org.gradle.api.Action import org.gradle.api.Project -import org.gradle.api.Task import org.gradle.jvm.tasks.Jar import org.gradle.kotlin.dsl.withType -import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilation import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile -import org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl +import java.io.File class JsMRGenerator( project: Project, settings: Settings, generators: List, - private val compilation: KotlinJsIrCompilation, ) : TargetMRGenerator( project = project, settings = settings, @@ -81,8 +75,8 @@ class JsMRGenerator( project.tasks.withType().configureEach { it.dependsOn(generationTask) } - setupKLibResources(generationTask) - setupResources() +// setupKLibResources(generationTask) +// setupResources() // Declare task ':web-app:generateMRcommonMain' as an input of ':web-app:jsSourcesJar'. project.tasks.withType().configureEach { @@ -96,26 +90,6 @@ class JsMRGenerator( // ) } - //TODO: Вынести на этап конфигурации - private fun setupKLibResources(generationTask: Task) { - val taskProvider = compilation.compileTaskProvider - taskProvider.configure { compileTask -> - compileTask.dependsOn(generationTask) - val action = CopyResourcesToKLibAction(resourcesGenerationDir) - @Suppress("UNCHECKED_CAST") - compileTask.doLast(action as Action) - } - } - - private fun setupResources() { - compilation.compileTaskProvider.configure { compileTask -> - val action = CopyResourcesToExecutableAction(resourcesGenerationDir) - @Suppress("UNCHECKED_CAST") - compileTask.doLast(action as Action) - } - } - - companion object { const val SUPPORTED_LOCALES_PROPERTY_NAME = "supportedLocales" const val LOCALIZATION_DIR = "localization" diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/AndroidParamsHelper.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsParamsHelper.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/AndroidParamsHelper.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsParamsHelper.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsSetupUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsSetupUtils.kt new file mode 100644 index 000000000..473bae08e --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsSetupUtils.kt @@ -0,0 +1,26 @@ +package dev.icerock.gradle.generator.js + +import dev.icerock.gradle.generator.js.action.CopyResourcesToExecutableAction +import dev.icerock.gradle.generator.js.action.CopyResourcesToKLibAction +import org.gradle.api.Action +import org.gradle.api.Task +import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile +import java.io.File + +fun setupJsKLibResources( + compileTask: Kotlin2JsCompile, + resourcesGenerationDir: File +) { + val copyResourcesToKLibAction = CopyResourcesToKLibAction(resourcesGenerationDir) + @Suppress("UNCHECKED_CAST") + compileTask.doLast(copyResourcesToKLibAction as Action) +} + +fun setupJsResources( + compileTask: Kotlin2JsCompile, + resourcesGenerationDir: File +) { + val copyResourcesAction = CopyResourcesToExecutableAction(resourcesGenerationDir) + @Suppress("UNCHECKED_CAST") + compileTask.doLast(copyResourcesAction as Action) +} \ No newline at end of file diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/action/CopyResourcesToExecutableAction.kt similarity index 88% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsAction.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/action/CopyResourcesToExecutableAction.kt index b5907eeb3..60d6cdbff 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/action/CopyResourcesToExecutableAction.kt @@ -1,4 +1,4 @@ -package dev.icerock.gradle.generator.js +package dev.icerock.gradle.generator.js.action import dev.icerock.gradle.utils.klibs import org.gradle.api.Action @@ -7,23 +7,6 @@ import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile import org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl import java.io.File -class CopyResourcesToKLibAction( - private val resourcesDirProvider: File, -) : Action { - override fun execute(task: Kotlin2JsCompile) { - val unpackedKLibDir: File = task.destinationDirectory.asFile.get() - val defaultDir = File(unpackedKLibDir, "default") - val resRepackDir = File(defaultDir, "resources") - if (resRepackDir.exists().not()) return - - val resDir = File(resRepackDir, "moko-resources-js") - resourcesDirProvider.copyRecursively( - resDir, - overwrite = true - ) - } -} - class CopyResourcesToExecutableAction( private val resourcesGeneratedDir: File, ) : Action { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/action/CopyResourcesToKLibAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/action/CopyResourcesToKLibAction.kt new file mode 100644 index 000000000..6a32088ff --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/action/CopyResourcesToKLibAction.kt @@ -0,0 +1,22 @@ +package dev.icerock.gradle.generator.js.action + +import org.gradle.api.Action +import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile +import java.io.File + +class CopyResourcesToKLibAction( + private val resourcesDirProvider: File, +) : Action { + override fun execute(task: Kotlin2JsCompile) { + val unpackedKLibDir: File = task.destinationDirectory.asFile.get() + val defaultDir = File(unpackedKLibDir, "default") + val resRepackDir = File(defaultDir, "resources") + if (resRepackDir.exists().not()) return + + val resDir = File(resRepackDir, "moko-resources-js") + resourcesDirProvider.copyRecursively( + target = resDir, + overwrite = true + ) + } +} 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 f2330f440..2b96d8980 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 @@ -184,15 +184,11 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { settings: MRGenerator.Settings, generators: List>, ): JsMRGenerator { - TODO() -// return JsMRGenerator( -// project = project, -// settings = settings, -// compilation = compilationJs.get(), -// generators = generators.map { -// it.createJsGenerator() -// } -// ) + return JsMRGenerator( + project = project, + settings = settings, + generators = generators.map { it.createJsGenerator() } + ) } private fun createNativeGenerator( From d473e3d30c2332567c1ce6d927d43a9307f3fa29 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Fri, 15 Dec 2023 13:18:09 +0700 Subject: [PATCH 069/352] #535 add resourceContainter implementation, fix actual interface generation, --- gradle/libs.versions.toml | 2 +- .../gradle/MultiplatformResourcesPlugin.kt | 315 ++++++------------ .../gradle/configuration/AppleTargets.kt | 3 +- .../gradle/generator/AssetsGenerator.kt | 2 +- .../icerock/gradle/generator/BaseGenerator.kt | 14 +- .../gradle/generator/ColorsGenerator.kt | 2 +- .../gradle/generator/FilesGenerator.kt | 2 +- .../gradle/generator/FontsGenerator.kt | 22 +- .../gradle/generator/ImagesGenerator.kt | 4 +- .../icerock/gradle/generator/MRGenerator.kt | 48 ++- .../gradle/generator/PluralsGenerator.kt | 2 +- .../generator/ResourceGeneratorFeature.kt | 2 +- .../gradle/generator/StringsGenerator.kt | 2 +- .../gradle/generator/TargetMRGenerator.kt | 37 +- .../android/AndroidFilesGenerator.kt | 5 +- .../android/AndroidFontsGenerator.kt | 5 +- .../android/AndroidImagesGenerator.kt | 5 +- .../android/AndroidPluralsGenerator.kt | 5 +- .../android/AndroidStringsGenerator.kt | 5 +- .../generator/apple/AppleMRGenerator.kt | 182 +--------- .../generator/apple/ApplePluralsGenerator.kt | 5 +- .../generator/apple/AppleStringsGenerator.kt | 7 +- .../gradle/generator/apple/SetupAppleUtils.kt | 160 +++++++++ .../apple/action/PackResourcesToKLibAction.kt | 19 +- .../generator/common/CommonMRGenerator.kt | 37 +- .../gradle/generator/js/JsMRGenerator.kt | 2 +- .../gradle/generator/js/JsParamsHelper.kt | 3 +- .../gradle/generator/js/JsSetupUtils.kt | 5 +- .../action/CopyResourcesToExecutableAction.kt | 8 +- .../js/action/CopyResourcesToKLibAction.kt | 6 +- .../generator/jvm/ClassLoaderExtender.kt | 2 + .../gradle/generator/jvm/JvmMRGenerator.kt | 4 +- .../icerock/gradle/metadata/MetadataExt.kt | 2 +- .../GenerateMultiplatformResourcesTask.kt | 39 ++- 34 files changed, 464 insertions(+), 499 deletions(-) create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/SetupAppleUtils.kt diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ecb1fe5cc..743901711 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -4,7 +4,7 @@ androidGradleVersion = "7.4.2" androidSdkCommonVersion = "31.1.2" # kotlinx -kotlinxSerializationVersion = "1.5.1" +kotlinxSerializationVersion = "1.6.1" kotlinxCoroutinesVersion = "1.6.4" # android diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index c96d0a1a3..bc00698d5 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -4,41 +4,36 @@ package dev.icerock.gradle -import com.android.build.api.dsl.AndroidSourceSet import com.android.build.gradle.BaseExtension -import dev.icerock.gradle.configuration.configureAndroidTargetGenerator -import dev.icerock.gradle.configuration.configureAppleTargetGenerator -import dev.icerock.gradle.configuration.configureCommonTargetGenerator -import dev.icerock.gradle.configuration.configureJsTargetGenerator -import dev.icerock.gradle.configuration.configureJvmTargetGenerator -import dev.icerock.gradle.generator.AssetsGenerator -import dev.icerock.gradle.generator.ColorsGenerator -import dev.icerock.gradle.generator.FilesGenerator -import dev.icerock.gradle.generator.FontsGenerator -import dev.icerock.gradle.generator.ImagesGenerator -import dev.icerock.gradle.generator.MRGenerator -import dev.icerock.gradle.generator.PluralsGenerator -import dev.icerock.gradle.generator.ResourceGeneratorFeature -import dev.icerock.gradle.generator.StringsGenerator +import dev.icerock.gradle.generator.apple.setupAppleKLibResources +import dev.icerock.gradle.generator.js.setupJsKLibResources +import dev.icerock.gradle.generator.js.setupJsResources import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.utils.dependsOnObservable import dev.icerock.gradle.utils.kotlinSourceSetsObservable import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.file.SourceDirectorySet -import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.TaskProvider import org.gradle.kotlin.dsl.create import org.gradle.kotlin.dsl.getByType import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension -import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension import org.jetbrains.kotlin.gradle.plugin.KotlinMultiplatformPluginWrapper import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.androidJvm +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.common +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.js +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.jvm +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.native +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.wasm import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import org.jetbrains.kotlin.gradle.plugin.KotlinTarget +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget -import org.jetbrains.kotlin.konan.target.KonanTarget +import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile +import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask +import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile import org.jetbrains.kotlin.tooling.core.extrasKeyOf import java.io.File @@ -58,9 +53,6 @@ open class MultiplatformResourcesPlugin : Plugin { mrExtension = mrExtension, kmpExtension = kmpExtension ) - - //TODO add configuration for generated resources - setupResourcesSourceSet(project, kmpExtension) } } @@ -102,42 +94,74 @@ open class MultiplatformResourcesPlugin : Plugin { } kmpExtension.targets.configureEach { target -> - project.logger.warn("i target ${target.targetName}") - target.compilations.configureEach { compilation -> + compilation.kotlinSourceSetsObservable.forAll { sourceSet: KotlinSourceSet -> + val genTaskProvider: TaskProvider = + requireNotNull( + sourceSet.extras[mokoResourcesGenTaskKey()] + ) - compilation.kotlinSourceSetsObservable.forAll { sourceSet -> - project.logger.warn("i compilation kotlinSourceSets: $sourceSet") + genTaskProvider.configure { + it.platformType.set(target.platformType.name) - project.logger.warn(("i compilationSourceSet: $sourceSet")) + if (target.platformType == KotlinPlatformType.native) { + it.konanTarget.set((target as KotlinNativeTarget).konanTarget.name) + } + } - val genTask: TaskProvider = requireNotNull( - sourceSet.extras[mokoResourcesGenTaskKey()] + // Setup generated sourceSets, assets, resources as sourceSet of target + setupSourceSets( + project, + target = target, + sourceSet = sourceSet, + genTaskProvider = genTaskProvider, ) - genTask.configure { - project.logger.warn("i configure platformName ${target.platformType.name}") - - it.platformType.set(target.platformType.name) - } - compilation.compileTaskProvider.configure { compileTask: KotlinCompilationTask<*> -> - compileTask.dependsOn(genTask) + compileTask.dependsOn(genTaskProvider) + + if (target.platformType == KotlinPlatformType.js) { + compileTask as Kotlin2JsCompile - if ( - target.platformType == KotlinPlatformType.js - && compilation as? KotlinJsIrCompilation != null - && compileTask as? Kotlin2JsCompile != null - ) { setupJsResources( compileTask = compileTask, - resourcesGenerationDir = genTask.get().outputDirectory.asFile.get() + resourcesGenerationDir = genTaskProvider.flatMap { + it.outputResourcesDir.asFile + } ) setupJsKLibResources( compileTask = compileTask, - resourcesGenerationDir = genTask.get().outputDirectory.asFile.get() + resourcesGenerationDir = genTaskProvider.flatMap { + it.outputResourcesDir.asFile + } ) } + + if (target.platformType == KotlinPlatformType.native) { + target as KotlinNativeTarget + compilation as KotlinNativeCompilation + compileTask as KotlinNativeCompile + + setupAppleKLibResources( + compileTask = compileTask, + assetsDirectory = genTaskProvider.flatMap { + it.outputAssetsDir.asFile + }, + resourcesGenerationDir = genTaskProvider.flatMap { + it.outputResourcesDir.asFile + }, + iosLocalizationRegion = genTaskProvider.flatMap { + it.iosBaseLocalizationRegion + }, + resourcePackageName = genTaskProvider.flatMap { + it.resourcesPackageName + } + ) + //TODO: Realize Apple setup: now crashed +// setupFrameworkResources(compilation = compilation) +// setupTestsResources(compilation = compilation) +// setupFatFrameworkTasks(compilation = compilation) + } } } } @@ -196,85 +220,48 @@ open class MultiplatformResourcesPlugin : Plugin { // setupProjectForApple(project) } - private fun setupResourcesSourceSet( - project: Project, - kmpExtension: KotlinMultiplatformExtension, - ) { - val kotlinExtension: KotlinProjectExtension = project.extensions.getByType( - KotlinProjectExtension::class.java - ) - val commonSourceSet: KotlinSourceSet? = kotlinExtension.sourceSets.findByName( - KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME - ) - val androidExtension: BaseExtension? = - project.extensions.findByName("android") as BaseExtension? - val androidSourceSet: com.android.build.gradle.api.AndroidSourceSet? = - androidExtension?.sourceSets?.getByName(SourceSet.MAIN_SOURCE_SET_NAME) - - when { - commonSourceSet != null -> { - setupKotlinSourceSet( - project = project, - kotlinSourceSet = commonSourceSet, - ) - } - androidSourceSet != null -> { - setupAndroidSourceSet( - project = project, - androidSourceSet = androidSourceSet - ) - } - else -> kmpExtension.sourceSets.configureEach { kotlinSourceSet -> - setupKotlinSourceSet( - project = project, - kotlinSourceSet = kotlinSourceSet, - ) - } - } - } - - private fun setupKotlinSourceSet( - project: Project, - kotlinSourceSet: KotlinSourceSet, - ) { - val mokoResourcesDir = getGeneratedResourcesDir( - project = project, - sourceSetName = kotlinSourceSet.name - ) - - val sourcesGenerationDir = File(mokoResourcesDir, "src") - val resourcesGenerationDir = File(mokoResourcesDir, "res") - - kotlinSourceSet.kotlin.srcDir(sourcesGenerationDir) - kotlinSourceSet.resources.srcDir(resourcesGenerationDir) - } - - private fun setupAndroidSourceSet( + private fun setupSourceSets( project: Project, - androidSourceSet: AndroidSourceSet, + target: KotlinTarget, + sourceSet: KotlinSourceSet, + genTaskProvider: TaskProvider, ) { - project.logger.warn("i android sourceSets: ${androidSourceSet.name}") - - val mokoResourcesDir = getGeneratedResourcesDir( - project = project, - sourceSetName = androidSourceSet.name - ) + sourceSet.kotlin.srcDir(genTaskProvider.map { it.outputSourcesDir }) - val sourcesGenerationDir = File(mokoResourcesDir, "src") - val resourcesGenerationDir = File(mokoResourcesDir, "res") - val assetsGenerationDir = File(mokoResourcesDir, AssetsGenerator.ASSETS_DIR_NAME) + when (target.platformType) { + jvm, js -> { + sourceSet.resources.srcDir(genTaskProvider.map { it.outputResourcesDir }) + sourceSet.resources.srcDir(genTaskProvider.map { it.outputAssetsDir }) + } - androidSourceSet.assets.srcDir(assetsGenerationDir) - androidSourceSet.java.srcDir(sourcesGenerationDir) - androidSourceSet.resources.srcDir(resourcesGenerationDir) - } + androidJvm -> { + val androidExtension: BaseExtension = target.project.extensions.getByType() + + // Remove android name from kotlinSourceSet name, because androidSourceSet + // doesn't have prefix 'android' + val kotlinSourceSetName: String = sourceSet.name + .replace("android", "") + .lowercase() + + //TODO: Need correction of filter for setup test sourceSets + // maybe should do logic implementation with + // https://kotlinlang.org/docs/multiplatform-android-layout.html#move-source-files + + androidExtension.sourceSets.filter { + it.name == kotlinSourceSetName + }.forEach { androidSourceSet -> + project.logger.warn("SETUP ANDROID SOURCESETS: ${sourceSet.name} androidSS: ${androidSourceSet.name}") + project.logger.warn("SETUP ANDROID SOURCESETS: genTaskProvider: $genTaskProvider") + + // Setup source for release/debug + androidSourceSet.kotlin.srcDir(genTaskProvider.map { it.outputSourcesDir }) + androidSourceSet.res.srcDir(genTaskProvider.map { it.outputResourcesDir }) + androidSourceSet.assets.srcDir(genTaskProvider.map { it.outputAssetsDir }) + } + } - private fun getGeneratedResourcesDir( - project: Project, - sourceSetName: String, - ): File { - val generatedDir = File(project.buildDir, "generated/moko-resources") - return File(generatedDir, sourceSetName) + common, native, wasm -> Unit + } } private fun createMokoResourcesSourceSet( @@ -303,6 +290,8 @@ open class MultiplatformResourcesPlugin : Plugin { mrExtension: MultiplatformResourcesPluginExtension, ): TaskProvider { val generateTaskName: String = "generateMR" + kotlinSourceSet.name + val generatedMokoResourcesDir = File(project.buildDir, "generated/moko-resources") + val taskProvider: TaskProvider = project.tasks.register( generateTaskName, GenerateMultiplatformResourcesTask::class.java @@ -316,13 +305,15 @@ open class MultiplatformResourcesPlugin : Plugin { generateTask.resourcesVisibility.set(mrExtension.resourcesVisibility) generateTask.outputMetadataFile.set( File( - File(project.buildDir, "generated/moko-resources/metadata"), + File(generatedMokoResourcesDir, "metadata"), "${kotlinSourceSet.name}-metadata.json" ) ) - generateTask.outputDirectory.set( - File(File(project.buildDir, "generated/moko-resources"), kotlinSourceSet.name) - ) + val sourceSetResourceDir = File(generatedMokoResourcesDir, kotlinSourceSet.name) + generateTask.outputGeneratedResourcesDir.set(sourceSetResourceDir) + generateTask.outputAssetsDir.set(File(sourceSetResourceDir, "assets")) + generateTask.outputResourcesDir.set(File(sourceSetResourceDir, "res")) + generateTask.outputSourcesDir.set(File(sourceSetResourceDir, "src")) } kotlinSourceSet.extras[mokoResourcesGenTaskKey()] = taskProvider @@ -390,90 +381,6 @@ open class MultiplatformResourcesPlugin : Plugin { } } } - - private fun configureKotlinTargetGenerator( - target: KotlinTarget, - settings: MRGenerator.Settings, - ) { - val features = listOf( - StringsGenerator.Feature(settings), - PluralsGenerator.Feature(settings), - ImagesGenerator.Feature(settings, target.project.logger), - FontsGenerator.Feature(settings), - FilesGenerator.Feature(target.project, settings), - ColorsGenerator.Feature(target.project, settings), - AssetsGenerator.Feature(settings) - ) - - when (target.platformType) { - KotlinPlatformType.common -> configureCommonTargetGenerator( - target = target, - settings = settings, - features = features - ) - KotlinPlatformType.jvm -> configureJvmTargetGenerator( - target = target, - settings = settings, - features = features - ) - KotlinPlatformType.js -> configureJsTargetGenerator( - target = target, - settings = settings, - features = features - ) - KotlinPlatformType.androidJvm -> configureAndroidTargetGenerator( - target = target, - settings = settings, - features = features - ) - - KotlinPlatformType.native -> configureNativeTargetGenerator( - target = target as KotlinNativeTarget, - settings = settings, - features = features - ) - - KotlinPlatformType.wasm -> { - target.project.logger.warn("wasm target not supported by MOKO Resources now") - } - } - } - - private fun configureNativeTargetGenerator( - target: KotlinNativeTarget, - settings: MRGenerator.Settings, - features: List>, - ) { - when (target.konanTarget) { - KonanTarget.IOS_ARM32, - KonanTarget.IOS_ARM64, - KonanTarget.IOS_SIMULATOR_ARM64, - KonanTarget.IOS_X64, - - KonanTarget.MACOS_ARM64, - KonanTarget.MACOS_X64, - - KonanTarget.TVOS_ARM64, - KonanTarget.TVOS_SIMULATOR_ARM64, - KonanTarget.TVOS_X64, - - KonanTarget.WATCHOS_ARM32, - KonanTarget.WATCHOS_ARM64, - KonanTarget.WATCHOS_DEVICE_ARM64, - KonanTarget.WATCHOS_SIMULATOR_ARM64, - KonanTarget.WATCHOS_X64, - KonanTarget.WATCHOS_X86, - -> configureAppleTargetGenerator( - target = target, - settings = settings, - features = features - ) - - else -> { - target.project.logger.warn("$target is not supported by MOKO Resources at now") - } - } - } } private fun KotlinSourceSet.whenDependsOn(sourceSetName: String, action: () -> Unit) { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt index 59e64bb2d..699b19115 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt @@ -36,8 +36,7 @@ internal fun configureAppleTargetGenerator( AppleMRGenerator( project = target.project, settings = settings, - generators = features.map { it.createIosGenerator() }, - compilation = mainCompilation, + generators = features.map { it.createAppleGenerator() }, ).apply(target.project) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt index b1a9e5e0e..7304f03f6 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt @@ -191,7 +191,7 @@ abstract class AssetsGenerator( upperResourcesFileTree = settings.upperResourcesFileTree, ) - override fun createIosGenerator(): AssetsGenerator = AppleAssetsGenerator( + override fun createAppleGenerator(): AssetsGenerator = AppleAssetsGenerator( ownResourcesFileTree = settings.ownResourcesFileTree, lowerResourcesFileTree = settings.lowerResourcesFileTree, ) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt index 853e8af19..cf9d0e124 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt @@ -56,6 +56,7 @@ abstract class BaseGenerator : MRGenerator.Generator { beforeGenerateResources(objectBuilder, languagesAllMaps) val stringsClass: TypeSpec = createTypeSpec( + project, inputMetadata = inputMetadata, generatedObjects = generatedObjects, targetObject = targetObject, @@ -72,6 +73,7 @@ abstract class BaseGenerator : MRGenerator.Generator { } private fun createTypeSpec( + project: Project, inputMetadata: MutableList, generatedObjects: MutableList, targetObject: GeneratedObject, @@ -126,10 +128,14 @@ abstract class BaseGenerator : MRGenerator.Generator { extendObjectBodyAtEnd(objectBuilder) - // Add object in metadata with remove expect realisation - generatedObjects.addActual( - targetObject.copy(properties = generatedProperties) - ) + project.logger.warn("generatedObjects actual: $targetObject \n + $generatedProperties") + + if (generatedProperties.isNotEmpty()) { + // Add object in metadata with remove expect realisation + generatedObjects.addActual( + targetObject.copy(properties = generatedProperties) + ) + } return objectBuilder.build() } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt index a69b4f0c3..6a453efc3 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt @@ -153,7 +153,7 @@ abstract class ColorsGenerator( resourcesFileTree = settings.ownResourcesFileTree, ) - override fun createIosGenerator() = AppleColorsGenerator( + override fun createAppleGenerator() = AppleColorsGenerator( project = project, resourcesFileTree = settings.ownResourcesFileTree, ) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt index 68d1f4d2e..49e701b7d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt @@ -116,7 +116,7 @@ abstract class FilesGenerator( upperInputFileTree = settings.upperResourcesFileTree ) - override fun createIosGenerator(): FilesGenerator = AppleFilesGenerator( + override fun createAppleGenerator(): FilesGenerator = AppleFilesGenerator( project = project, ownInputFileTree = settings.ownResourcesFileTree, lowerInputFileTree = settings.lowerResourcesFileTree diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt index 2611453b7..2ff303586 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt @@ -22,10 +22,13 @@ import org.gradle.api.file.FileTree import java.io.File abstract class FontsGenerator( - private val inputFileTree: FileTree + private val inputFileTree: FileTree, ) : MRGenerator.Generator { - override val inputFiles: Iterable get() = inputFileTree.files + override val inputFiles: Iterable + get() = inputFileTree.matching { + it.include("fonts/**.ttf", "fonts/**.otf") + } override val resourceClassName = ClassName("dev.icerock.moko.resources", "FontResource") override val mrObjectName: String = "fonts" @@ -74,7 +77,7 @@ abstract class FontsGenerator( familyGroups.forEach { group -> // TODO Make pairs: "style name" - "font file" - val stylePairs = group + val stylePairs: List> = group .value .map { it.nameWithoutExtension.substringAfter("-") to it } @@ -94,7 +97,7 @@ abstract class FontsGenerator( @Suppress("SpreadOperator") private fun generateFontFamilySpec( familyName: String, - fontStyleFiles: List> + fontStyleFiles: List>, ): TypeSpec { val spec = TypeSpec .objectBuilder(familyName) @@ -114,7 +117,7 @@ abstract class FontsGenerator( protected open fun generateResources( resourcesGenerationDir: File, - files: List + files: List, ) { } @@ -128,21 +131,18 @@ abstract class FontsGenerator( data class FontFile( val key: String, - val file: File + val file: File, ) class Feature( - private val settings: MRGenerator.Settings + private val settings: MRGenerator.Settings, ) : ResourceGeneratorFeature { -// private val stringsFileTree: FileTree = settings.ownResourcesFileTree -// .matching { it.include("fonts/**.ttf", "fonts/**.otf") } - override fun createCommonGenerator(): FontsGenerator = CommonFontsGenerator( ownInputFileTree = settings.ownResourcesFileTree, upperInputFileTree = settings.upperResourcesFileTree ) - override fun createIosGenerator(): FontsGenerator = AppleFontsGenerator( + override fun createAppleGenerator(): FontsGenerator = AppleFontsGenerator( ownInputFileTree = settings.ownResourcesFileTree, lowerInputFileTree = settings.lowerResourcesFileTree ) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt index b6f30b271..087309aaf 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt @@ -119,14 +119,14 @@ abstract class ImagesGenerator( upperInputFileTree = settings.upperResourcesFileTree ) - override fun createIosGenerator(): ImagesGenerator = AppleImagesGenerator( + override fun createAppleGenerator(): ImagesGenerator = AppleImagesGenerator( ownInputFileTree = settings.ownResourcesFileTree, lowerInputFileTree = settings.lowerResourcesFileTree, ) override fun createAndroidGenerator(): ImagesGenerator = AndroidImagesGenerator( ownInputFileTree = settings.ownResourcesFileTree, - androidRClassPackageProvider = settings.androidRClassPackage, + androidRClassPackage = settings.androidRClassPackage, logger = logger ) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt index 7978ad592..8ad80938d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt @@ -15,23 +15,50 @@ import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import org.gradle.api.Project import org.gradle.api.file.Directory import org.gradle.api.file.FileTree +import org.gradle.api.provider.Provider import java.io.File abstract class MRGenerator( protected val settings: Settings, internal val generators: List, ) { - internal val outputDir: File = settings.generatedDir.asFile - protected open val sourcesGenerationDir: File = File(outputDir, "src") - protected open val resourcesGenerationDir: File = File(outputDir, "res") - protected open val assetsGenerationDir: File = File(outputDir, AssetsGenerator.ASSETS_DIR_NAME) + protected open val sourcesGenerationDir: File = settings.sourceSetDir.asFile + protected open val resourcesGenerationDir: File = settings.resourcesDir.asFile + protected open val assetsGenerationDir: File = settings.assetsDir.asFile - internal fun generate() { + internal fun generate(project: Project) { + + project.logger.warn("GENERATE: BEFORE DELETE") + + sourcesGenerationDir.listFiles()?.forEach {file -> + project.logger.warn("GENERATE: sourcesGenerationDir $file") + } + resourcesGenerationDir.listFiles()?.forEach {file -> + project.logger.warn("GENERATE: resourcesGenerationDir$file") + } + assetsGenerationDir.listFiles()?.forEach {file -> + project.logger.warn("GENERATE: assetsGenerationDir $file") + } + + // Не работает рекурсивное удаление + // лог директорий, что удалено sourcesGenerationDir.deleteRecursively() resourcesGenerationDir.deleteRecursively() assetsGenerationDir.deleteRecursively() + project.logger.warn("GENERATE: AFTER DELETE") + + sourcesGenerationDir.listFiles()?.forEach {file -> + project.logger.warn("GENERATE: sourcesGenerationDir $file") + } + resourcesGenerationDir.listFiles()?.forEach {file -> + project.logger.warn("GENERATE: resourcesGenerationDir$file") + } + assetsGenerationDir.listFiles()?.forEach {file -> + project.logger.warn("GENERATE: assetsGenerationDir $file") + } + beforeMRGeneration() val file = generateFileSpec() @@ -78,6 +105,8 @@ abstract class MRGenerator( interface Generator : ObjectBodyExtendable { val mrObjectName: String + val resourceContainerClass: ClassName + get() = ClassName("dev.icerock.moko.resources", "ResourceContainer") val resourceClassName: ClassName val inputFiles: Iterable @@ -110,12 +139,15 @@ abstract class MRGenerator( val packageName: String, val className: String, val visibility: MRVisibility, - val generatedDir: Directory, + val outputDirectory: Directory, + val assetsDir: Directory, + val sourceSetDir: Directory, + val resourcesDir: Directory, val isStrictLineBreaks: Boolean, - val iosLocalizationRegion: String, val ownResourcesFileTree: FileTree, val lowerResourcesFileTree: FileTree, val upperResourcesFileTree: FileTree, - val androidRClassPackage: String, + val iosLocalizationRegion: Provider, + val androidRClassPackage: Provider, ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt index 1a550b2b3..0a64f6bc3 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt @@ -185,7 +185,7 @@ abstract class PluralsGenerator( strictLineBreaks = settings.isStrictLineBreaks ) - override fun createIosGenerator(): PluralsGenerator = ApplePluralsGenerator( + override fun createAppleGenerator(): PluralsGenerator = ApplePluralsGenerator( ownResourcesFileTree = settings.ownResourcesFileTree, strictLineBreaks = settings.isStrictLineBreaks, baseLocalizationRegion = settings.iosLocalizationRegion diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceGeneratorFeature.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceGeneratorFeature.kt index 87d5a433e..99178802f 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceGeneratorFeature.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceGeneratorFeature.kt @@ -6,7 +6,7 @@ package dev.icerock.gradle.generator interface ResourceGeneratorFeature { fun createCommonGenerator(): T - fun createIosGenerator(): T + fun createAppleGenerator(): T fun createAndroidGenerator(): T fun createJvmGenerator(): T fun createJsGenerator(): T diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt index 897bd10f5..4f3e5debe 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt @@ -165,7 +165,7 @@ abstract class StringsGenerator( strictLineBreaks = settings.isStrictLineBreaks ) - override fun createIosGenerator(): StringsGenerator = AppleStringsGenerator( + override fun createAppleGenerator(): StringsGenerator = AppleStringsGenerator( resourcesFileTree = settings.ownResourcesFileTree, strictLineBreaks = settings.isStrictLineBreaks, baseLocalizationRegion = settings.iosLocalizationRegion diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt index a2b8656d7..026145f40 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt @@ -3,6 +3,7 @@ package dev.icerock.gradle.generator import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.FileSpec import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.metadata.GeneratedObject import dev.icerock.gradle.metadata.GeneratedObjectModifier @@ -48,7 +49,6 @@ abstract class TargetMRGenerator( override fun getMRClassModifiers(): Array = arrayOf(KModifier.ACTUAL) override fun generateFileSpec(): FileSpec? { - val visibilityModifier: KModifier = settings.visibility.toModifier() val inputMetadata: MutableList = mutableListOf() //Read list of generated resources on previous level @@ -58,6 +58,15 @@ abstract class TargetMRGenerator( ) ) + if ( + inputMetadata.isEmpty() + && settings.ownResourcesFileTree.files.none { + it.isFile + } + ) return null + + val visibilityModifier: KModifier = settings.visibility.toModifier() + inputMetadata.forEach { logger.warn("i prev: $it") } @@ -91,7 +100,7 @@ abstract class TargetMRGenerator( .build() inputMetadata.addActual( - expectInterface.copy(modifier = GeneratedObjectModifier.Actual) + actualObject = expectInterface.copy(modifier = GeneratedObjectModifier.Actual) ) fileSpec.addType(resourcesInterface) @@ -100,21 +109,23 @@ abstract class TargetMRGenerator( val generatedActualObjects = mutableListOf() - generators.forEach { generator -> + generators.forEach { generator: Generator -> val builder: TypeSpec.Builder = TypeSpec .objectBuilder(generator.mrObjectName) .addModifiers(visibilityModifier) + .addSuperinterface(generator.resourceContainerClass.parameterizedBy(generator.resourceClassName)) // Implement to object expect interfaces from previous // levels of resources - inputMetadata.getActualInterfaces(generator.type).forEach { generatedObject: GeneratedObject -> - builder.addSuperinterface( - ClassName( - packageName = settings.packageName, - generatedObject.name + inputMetadata.getActualInterfaces(generator.type) + .forEach { generatedObject: GeneratedObject -> + builder.addSuperinterface( + ClassName( + packageName = settings.packageName, + generatedObject.name + ) ) - ) - } + } mrClassSpec.addType( generator.generate( @@ -140,7 +151,7 @@ abstract class TargetMRGenerator( } inputMetadata.addActual( - GeneratedObject( + actualObject = GeneratedObject( generatorType = GeneratorType.None, type = GeneratedObjectType.Object, name = settings.className, @@ -202,7 +213,9 @@ abstract class TargetMRGenerator( objectBuilder = resourcesInterfaceBuilder ) - fileSpec.addType(generatedResources) + if (generatedResources.propertySpecs.isNotEmpty()) { + fileSpec.addType(generatedResources) + } } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt index 6cf16ef3f..a67c6a99a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt @@ -12,6 +12,7 @@ import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable import org.gradle.api.Project import org.gradle.api.file.FileTree +import org.gradle.api.provider.Provider import java.io.File import java.util.Locale @@ -19,7 +20,7 @@ class AndroidFilesGenerator( project: Project, ownInputFileTree: FileTree, lowerInputFileTree: FileTree, - private val androidRClassPackage: String, + private val androidRClassPackage: Provider, ) : FilesGenerator(project, ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -29,7 +30,7 @@ class AndroidFilesGenerator( CodeBlock.of("FileResource(rawResId = R.raw.%L)", keyToResourceId(fileSpec.key)) override fun getImports() = listOf( - ClassName(androidRClassPackage, "R") + ClassName(androidRClassPackage.get(), "R") ) override fun generateResources( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFontsGenerator.kt index 9a20fe16b..fe34f4821 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFontsGenerator.kt @@ -11,13 +11,14 @@ import dev.icerock.gradle.generator.FontsGenerator import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable import org.gradle.api.file.FileTree +import org.gradle.api.provider.Provider import java.io.File import java.util.Locale class AndroidFontsGenerator( ownInputFileTree: FileTree, lowerInputFileTree: FileTree, - private val androidRClassPackage: String, + private val androidRClassPackage: Provider, ) : FontsGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -28,7 +29,7 @@ class AndroidFontsGenerator( } override fun getImports(): List = listOf( - ClassName(androidRClassPackage, "R") + ClassName(androidRClassPackage.get(), "R") ) override fun generateResources( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt index 3df2dde60..c30abdfb3 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt @@ -14,6 +14,7 @@ import dev.icerock.gradle.generator.ObjectBodyExtendable import dev.icerock.gradle.utils.svg import org.gradle.api.file.FileTree import org.gradle.api.logging.Logger +import org.gradle.api.provider.Provider import java.io.File import java.io.FileOutputStream import java.io.IOException @@ -23,7 +24,7 @@ import kotlin.reflect.full.functions class AndroidImagesGenerator( ownInputFileTree: FileTree, - private val androidRClassPackageProvider: String, + private val androidRClassPackage: Provider, private val logger: Logger ) : ImagesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -36,7 +37,7 @@ class AndroidImagesGenerator( } override fun getImports(): List = listOf( - ClassName(androidRClassPackageProvider, "R") + ClassName(androidRClassPackage.get(), "R") ) override fun generateResources( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt index 990bce113..1e8e512ab 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt @@ -15,12 +15,13 @@ import dev.icerock.gradle.generator.PluralMap import dev.icerock.gradle.generator.PluralsGenerator import org.apache.commons.lang3.StringEscapeUtils import org.gradle.api.file.FileTree +import org.gradle.api.provider.Provider import java.io.File class AndroidPluralsGenerator( ownResourcesFileTree: FileTree, strictLineBreaks: Boolean, - private val androidRClassPackage: String, + private val androidRClassPackage: Provider, ) : PluralsGenerator(ownResourcesFileTree, strictLineBreaks), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -31,7 +32,7 @@ class AndroidPluralsGenerator( CodeBlock.of("PluralsResource(R.plurals.%L)", processKey(key)) override fun getImports(): List = listOf( - ClassName(androidRClassPackage, "R") + ClassName(androidRClassPackage.get(), "R") ) override fun generateResources( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt index af6e8f6a3..dc838dbce 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt @@ -14,12 +14,13 @@ import dev.icerock.gradle.generator.ObjectBodyExtendable import dev.icerock.gradle.generator.StringsGenerator import org.apache.commons.text.StringEscapeUtils import org.gradle.api.file.FileTree +import org.gradle.api.provider.Provider import java.io.File class AndroidStringsGenerator( resourcesFileTree: FileTree, strictLineBreaks: Boolean, - private val androidRClassPackage: String, + private val androidRClassPackage: Provider, ) : StringsGenerator( resourcesFileTree = resourcesFileTree, strictLineBreaks = strictLineBreaks @@ -33,7 +34,7 @@ class AndroidStringsGenerator( CodeBlock.of("StringResource(R.string.%L)", processKey(key)) override fun getImports(): List = listOf( - ClassName(androidRClassPackage, "R") + ClassName(androidRClassPackage.get(), "R") ) override fun generateResources( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt index 7ded1772a..f27038eba 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt @@ -10,49 +10,21 @@ import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.STRING import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.MultiplatformResourcesPluginExtension import dev.icerock.gradle.generator.TargetMRGenerator -import dev.icerock.gradle.generator.apple.action.CopyResourcesFromKLibsToExecutableAction -import dev.icerock.gradle.generator.apple.action.CopyResourcesFromKLibsToFrameworkAction -import dev.icerock.gradle.generator.apple.action.PackResourcesToKLibAction -import dev.icerock.gradle.tasks.CopyFrameworkResourcesToAppEntryPointTask -import dev.icerock.gradle.tasks.CopyFrameworkResourcesToAppTask -import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.utils.calculateResourcesHash -import java.io.File -import kotlin.reflect.full.memberProperties -import org.gradle.api.Action import org.gradle.api.Project -import org.gradle.api.Task -import org.gradle.api.plugins.ExtensionAware -import org.gradle.api.tasks.TaskProvider -import org.gradle.kotlin.dsl.findByType -import org.gradle.kotlin.dsl.getByType -import org.gradle.kotlin.dsl.withType -import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension -import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension -import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractKotlinNativeCompilation -import org.jetbrains.kotlin.gradle.plugin.mpp.Framework -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget -import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable -import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask -import org.jetbrains.kotlin.gradle.tasks.FrameworkDescriptor -import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile -import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink @Suppress("TooManyFunctions") class AppleMRGenerator( project: Project, settings: Settings, generators: List, - private val compilation: AbstractKotlinNativeCompilation, ) : TargetMRGenerator( project = project, settings = settings, generators = generators ) { - private val bundleClassName = - ClassName("platform.Foundation", "NSBundle") + private val bundleClassName = ClassName("platform.Foundation", "NSBundle") private val bundleIdentifier = "${settings.packageName}.MR" override fun processMRClass(mrClass: TypeSpec.Builder) { @@ -80,162 +52,10 @@ class AppleMRGenerator( ClassName("dev.icerock.moko.resources.utils", "loadableBundle") ) - override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { - setupKLibResources(generationTask) - setupFrameworkResources() - setupTestsResources() - setupFatFrameworkTasks() - } - override fun beforeMRGeneration() { assetsGenerationDir.mkdirs() } - //TODO: Вынести на этап конфигурации - private fun setupKLibResources(generationTask: GenerateMultiplatformResourcesTask) { - val compileTask: TaskProvider = compilation.compileTaskProvider - - compileTask.configure { task -> - task.dependsOn(generationTask) - - task.doLast { - PackResourcesToKLibAction( - baseLocalizationRegion = settings.iosLocalizationRegion, - bundleIdentifier = bundleIdentifier, - assetsDirectory = assetsGenerationDir, - resourcesGenerationDir = resourcesGenerationDir, - ) - } - } - - // tasks like compileIosMainKotlinMetadata when only one target enabled -// generationTask.project.tasks -// .withType() -// .matching { it.name.contains(sourceSet.name, ignoreCase = true) } -// .configureEach { it.dependsOn(generationTask) } - - //TODO fix usage of sourceSet -// dependsOnProcessResources( -// project = generationTask.project, -// sourceSet = sourceSet, -// task = generationTask, -// ) - } - - private fun setupFrameworkResources() { - val kotlinNativeTarget = compilation.target as KotlinNativeTarget - val project = kotlinNativeTarget.project - - kotlinNativeTarget.binaries - .matching { it is Framework && it.compilation == compilation } - .configureEach { binary -> - val framework = binary as Framework - - val linkTask = framework.linkTask - - linkTask.doLast(CopyResourcesFromKLibsToFrameworkAction()) - - if (framework.isStatic) { - val resourcesExtension: MultiplatformResourcesPluginExtension = - project.extensions.getByType() - if (resourcesExtension.staticFrameworkWarningEnabled.get()) { - project.logger.warn( - """ -$linkTask produces static framework, Xcode should have Build Phase with copyFrameworkResourcesToApp gradle task call. Please read readme on https://github.com/icerockdev/moko-resources -""" - ) - } - createCopyFrameworkResourcesTask(linkTask) - } - } - } - - private fun createCopyFrameworkResourcesTask(linkTask: KotlinNativeLink) { - val framework = linkTask.binary as Framework - val project = linkTask.project - val taskName = linkTask.name.replace("link", "copyResources") - - val copyTask = project.tasks.create(taskName, CopyFrameworkResourcesToAppTask::class.java) { - it.framework = framework - } - copyTask.dependsOn(linkTask) - - val xcodeTask = project.tasks.maybeCreate( - "copyFrameworkResourcesToApp", - CopyFrameworkResourcesToAppEntryPointTask::class.java - ) - val multiplatformExtension = project.extensions.getByType() - xcodeTask.configurationMapper = (multiplatformExtension as? ExtensionAware)?.extensions - ?.findByType() - ?.xcodeConfigurationToNativeBuildType - ?: emptyMap() - - if (framework.target.konanTarget == xcodeTask.konanTarget && - framework.buildType.getName() == xcodeTask.configuration?.lowercase() - ) { - xcodeTask.dependsOn(copyTask) - } - } - - private fun setupTestsResources() { - val kotlinNativeTarget = compilation.target as KotlinNativeTarget - - kotlinNativeTarget.binaries - .matching { it is TestExecutable && it.compilation.associateWith.contains(compilation) } - .configureEach { binary -> - val executable = binary as TestExecutable - executable.linkTaskProvider.configure { link -> - link.doLast(CopyResourcesFromKLibsToExecutableAction()) - } - } - } - - private fun setupFatFrameworkTasks() { - val kotlinNativeTarget = compilation.target as KotlinNativeTarget - val project = kotlinNativeTarget.project - - val fatAction: Action = object : Action { - override fun execute(task: Task) { - val fatTask: FatFrameworkTask = task as FatFrameworkTask - - // compatibility of this api was changed - // from 1.6.10 to 1.6.20, so reflection was - // used here. - val fatFrameworkDir: File = FatFrameworkTask::class - .memberProperties - .run { - find { it.name == "fatFrameworkDir" } - ?: find { it.name == "fatFramework" } - }?.invoke(fatTask) as File - - val frameworkFile = when (val any: Any = fatTask.frameworks.first()) { - is Framework -> any.outputFile - is FrameworkDescriptor -> any.files.rootDir - else -> error("Unsupported type of $any") - } - - executeWithFramework(fatFrameworkDir, frameworkFile) - } - - private fun executeWithFramework( - fatFrameworkDir: File, - frameworkFile: File, - ) = frameworkFile - .listFiles() - ?.asSequence() - ?.filter { it.name.contains(".bundle") } - ?.forEach { bundleFile -> - project.copy { - it.from(bundleFile) - it.into(File(fatFrameworkDir, bundleFile.name)) - } - } - } - - project.tasks.withType(FatFrameworkTask::class) - .configureEach { it.doLast(fatAction) } - } - companion object { const val BUNDLE_PROPERTY_NAME = "bundle" const val ASSETS_DIR_NAME = "Assets.xcassets" diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/ApplePluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/ApplePluralsGenerator.kt index 3d789cf10..b7e402c1b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/ApplePluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/ApplePluralsGenerator.kt @@ -12,12 +12,13 @@ import dev.icerock.gradle.generator.ObjectBodyExtendable import dev.icerock.gradle.generator.PluralMap import dev.icerock.gradle.generator.PluralsGenerator import org.gradle.api.file.FileTree +import org.gradle.api.provider.Provider import java.io.File class ApplePluralsGenerator( ownResourcesFileTree: FileTree, strictLineBreaks: Boolean, - private val baseLocalizationRegion: String + private val baseLocalizationRegion: Provider ) : PluralsGenerator(ownResourcesFileTree, strictLineBreaks), ObjectBodyExtendable by AppleGeneratorHelper() { @@ -83,7 +84,7 @@ class ApplePluralsGenerator( writeStringsFile(localizableFile, strings) if (language == LanguageType.Base) { - val localRegion: String = baseLocalizationRegion + val localRegion: String = baseLocalizationRegion.get() val regionDir = File(resourcesGenerationDir, "$localRegion.lproj") regionDir.mkdirs() val regionFile = File(regionDir, "Localizable.stringsdict") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleStringsGenerator.kt index 953fa26a1..91c219450 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleStringsGenerator.kt @@ -11,14 +11,15 @@ import dev.icerock.gradle.generator.LanguageType import dev.icerock.gradle.generator.ObjectBodyExtendable import dev.icerock.gradle.generator.StringsGenerator import dev.icerock.gradle.generator.apple.AppleMRGenerator.Companion.BUNDLE_PROPERTY_NAME -import java.io.File import org.apache.commons.text.StringEscapeUtils import org.gradle.api.file.FileTree +import org.gradle.api.provider.Provider +import java.io.File class AppleStringsGenerator( resourcesFileTree: FileTree, strictLineBreaks: Boolean, - private val baseLocalizationRegion: String + private val baseLocalizationRegion: Provider ) : StringsGenerator( resourcesFileTree = resourcesFileTree, strictLineBreaks = strictLineBreaks @@ -49,7 +50,7 @@ class AppleStringsGenerator( localizableFile.writeText(content) if (language == LanguageType.Base) { - val regionDir = File(resourcesGenerationDir, "$baseLocalizationRegion.lproj") + val regionDir = File(resourcesGenerationDir, "${baseLocalizationRegion.get()}.lproj") regionDir.mkdirs() val regionFile = File(regionDir, "Localizable.strings") regionFile.writeText(content) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/SetupAppleUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/SetupAppleUtils.kt new file mode 100644 index 000000000..a606d010f --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/SetupAppleUtils.kt @@ -0,0 +1,160 @@ +package dev.icerock.gradle.generator.apple + +import dev.icerock.gradle.MultiplatformResourcesPluginExtension +import dev.icerock.gradle.generator.apple.action.CopyResourcesFromKLibsToExecutableAction +import dev.icerock.gradle.generator.apple.action.CopyResourcesFromKLibsToFrameworkAction +import dev.icerock.gradle.generator.apple.action.PackResourcesToKLibAction +import dev.icerock.gradle.tasks.CopyFrameworkResourcesToAppEntryPointTask +import dev.icerock.gradle.tasks.CopyFrameworkResourcesToAppTask +import org.gradle.api.Action +import org.gradle.api.Project +import org.gradle.api.Task +import org.gradle.api.plugins.ExtensionAware +import org.gradle.api.provider.Provider +import org.gradle.kotlin.dsl.findByType +import org.gradle.kotlin.dsl.getByType +import org.gradle.kotlin.dsl.withType +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension +import org.jetbrains.kotlin.gradle.plugin.mpp.Framework +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation +import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable +import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask +import org.jetbrains.kotlin.gradle.tasks.FrameworkDescriptor +import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile +import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink +import java.io.File +import kotlin.reflect.full.memberProperties + +fun setupAppleKLibResources( + compileTask: KotlinNativeCompile, + assetsDirectory: Provider, + resourcesGenerationDir: Provider, + iosLocalizationRegion: Provider, + resourcePackageName: Provider, +) { + compileTask.doLast { + PackResourcesToKLibAction( + baseLocalizationRegion = iosLocalizationRegion, + resourcePackageName = resourcePackageName, + assetsDirectory = assetsDirectory, + resourcesGenerationDir = resourcesGenerationDir, + ) + } + + // tasks like compileIosMainKotlinMetadata when only one target enabled +// generationTask.project.tasks +// .withType() +// .matching { it.name.contains(sourceSet.name, ignoreCase = true) } +// .configureEach { it.dependsOn(generationTask) } + + //TODO fix usage of sourceSet +// dependsOnProcessResources( +// project = generationTask.project, +// sourceSet = sourceSet, +// task = generationTask, +// ) +} + +fun setupFrameworkResources(compilation: KotlinNativeCompilation) { + compilation.target.binaries.withType().configureEach { framework -> + framework.linkTaskProvider.configure { linkTask -> + linkTask.doLast(CopyResourcesFromKLibsToFrameworkAction()) + + if (framework.isStatic) { + val project: Project = linkTask.project + val resourcesExtension: MultiplatformResourcesPluginExtension = + project.extensions.getByType() + if (resourcesExtension.staticFrameworkWarningEnabled.get()) { + project.logger.warn( + """ +$linkTask produces static framework, Xcode should have Build Phase with copyFrameworkResourcesToApp gradle task call. Please read readme on https://github.com/icerockdev/moko-resources +""" + ) + } + createCopyFrameworkResourcesTask(linkTask) + } + } + } +} + +fun createCopyFrameworkResourcesTask(linkTask: KotlinNativeLink) { + val framework = linkTask.binary as Framework + val project = linkTask.project + val taskName = linkTask.name.replace("link", "copyResources") + + val copyTask = project.tasks.create(taskName, CopyFrameworkResourcesToAppTask::class.java) { + it.framework = framework + } + copyTask.dependsOn(linkTask) + + val xcodeTask = project.tasks.maybeCreate( + "copyFrameworkResourcesToApp", + CopyFrameworkResourcesToAppEntryPointTask::class.java + ) + val multiplatformExtension = project.extensions.getByType() + xcodeTask.configurationMapper = (multiplatformExtension as? ExtensionAware)?.extensions + ?.findByType() + ?.xcodeConfigurationToNativeBuildType + ?: emptyMap() + + if (framework.target.konanTarget == xcodeTask.konanTarget && + framework.buildType.getName() == xcodeTask.configuration?.lowercase() + ) { + xcodeTask.dependsOn(copyTask) + } +} + +fun setupTestsResources(compilation: KotlinNativeCompilation) { + compilation.target.binaries.withType().configureEach {executable -> + executable.linkTaskProvider.configure { link -> + link.doLast(CopyResourcesFromKLibsToExecutableAction()) + } + } +} + +fun setupFatFrameworkTasks(compilation: KotlinNativeCompilation) { + val project = compilation.project + + val fatAction: Action = object : Action { + override fun execute(task: Task) { + val fatTask: FatFrameworkTask = task as FatFrameworkTask + + // compatibility of this api was changed + // from 1.6.10 to 1.6.20, so reflection was + // used here. + val fatFrameworkDir: File = FatFrameworkTask::class + .memberProperties + .run { + find { it.name == "fatFrameworkDir" } + ?: find { it.name == "fatFramework" } + }?.invoke(fatTask) as File + + val frameworkFile = when (val any: Any = fatTask.frameworks.first()) { + is Framework -> any.outputFile + is FrameworkDescriptor -> any.files.rootDir + else -> error("Unsupported type of $any") + } + + executeWithFramework(fatFrameworkDir, frameworkFile) + } + + private fun executeWithFramework( + fatFrameworkDir: File, + frameworkFile: File, + ) = frameworkFile + .listFiles() + ?.asSequence() + ?.filter { it.name.contains(".bundle") } + ?.forEach { bundleFile -> + project.copy { + it.from(bundleFile) + it.into(File(fatFrameworkDir, bundleFile.name)) + } + } + } + + project.tasks.withType().configureEach { + it.doLast(fatAction) + } +} \ No newline at end of file diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/PackResourcesToKLibAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/PackResourcesToKLibAction.kt index cc3829acd..75fe03d68 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/PackResourcesToKLibAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/PackResourcesToKLibAction.kt @@ -8,26 +8,27 @@ import dev.icerock.gradle.generator.apple.LoadableBundle import dev.icerock.gradle.utils.unzipTo import org.gradle.api.Action import org.gradle.api.Task +import org.gradle.api.provider.Provider import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile import org.jetbrains.kotlin.konan.file.zipDirAs import java.io.File import java.util.Properties internal class PackResourcesToKLibAction( - private val baseLocalizationRegion: String, - private val bundleIdentifier: String, - private val assetsDirectory: File, - private val resourcesGenerationDir: File, + private val assetsDirectory: Provider, + private val baseLocalizationRegion: Provider, + private val resourcePackageName: Provider, + private val resourcesGenerationDir: Provider, ) : Action { override fun execute(task: Task) { task as KotlinNativeCompile - val klibFile = task.outputFile.get() + val klibFile: File = task.outputFile.get() val repackDir = File(klibFile.parent, klibFile.nameWithoutExtension) val defaultDir = File(repackDir, "default") val resRepackDir = File(defaultDir, "resources") - val assetsDirectory: File = assetsDirectory - val resourcesGenerationDir: File = resourcesGenerationDir + val assetsDirectory: File = assetsDirectory.get() + val resourcesGenerationDir: File = resourcesGenerationDir.get() task.logger.info("Adding resources to klib file `{}`", klibFile) unzipTo(zipFile = klibFile, outputDirectory = repackDir) @@ -41,8 +42,8 @@ internal class PackResourcesToKLibAction( val loadableBundle = LoadableBundle( directory = resRepackDir, bundleName = uniqueName, - developmentRegion = baseLocalizationRegion, - identifier = bundleIdentifier + developmentRegion = baseLocalizationRegion.get(), + identifier = "${resourcePackageName.get()}.MR" ) loadableBundle.write() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index 8fb1a9a74..61556987b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -8,8 +8,8 @@ import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.FileSpec import com.squareup.kotlinpoet.FileSpec.Builder import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.ColorsGenerator import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.PluralsGenerator import dev.icerock.gradle.generator.StringsGenerator @@ -61,7 +61,7 @@ class CommonMRGenerator( } override fun generateFileSpec(): FileSpec? { - if (settings.ownResourcesFileTree.files.isEmpty()) return null +// if (settings.ownResourcesFileTree.files.isEmpty()) return null val inputMetadata: MutableList = mutableListOf() @@ -143,6 +143,7 @@ class CommonMRGenerator( val builder: TypeSpec.Builder = TypeSpec .objectBuilder(generator.mrObjectName) // resource name: example strings .addModifiers(visibilityModifier) // public/internal + .addSuperinterface(generator.resourceContainerClass.parameterizedBy(generator.resourceClassName)) val expectInterfaces: List = generatedObjects.filter { it.generatorType == generator.type && it.isExpectInterface @@ -204,19 +205,21 @@ class CommonMRGenerator( GeneratorType.Strings } else if (it.path.matches(PluralsGenerator.PLURALS_REGEX)) { GeneratorType.Plurals - } else if (it.path.matches(ColorsGenerator.COLORS_REGEX)) { - GeneratorType.Colors - } else if (it.parentFile.name == "images") { - GeneratorType.Images - } else if (it.parentFile.name == "files") { - GeneratorType.Files - } else if (it.parentFile.name == "assets") { - GeneratorType.Assets - } else if (it.parentFile.name == "fonts") { - GeneratorType.Fonts - } else { - GeneratorType.None - } + } else return@forEach + //TODO: Implement with generator +// else if (it.path.matches(ColorsGenerator.COLORS_REGEX)) { +// GeneratorType.Colors +// } else if (it.parentFile.name == "images") { +// GeneratorType.Images +// } else if (it.parentFile.name == "files") { +// GeneratorType.Files +// } else if (it.parentFile.name == "assets") { +// GeneratorType.Assets +// } else if (it.parentFile.name == "fonts") { +// GeneratorType.Fonts +// } else { +// GeneratorType.None +// } expectInterfaces.add( GeneratedObject( @@ -278,7 +281,9 @@ class CommonMRGenerator( objectBuilder = resourcesInterfaceBuilder, ) - fileSpec.addType(generatedResources) + if (generatedResources.propertySpecs.isNotEmpty()){ + fileSpec.addType(generatedResources) + } } inputMetadata.forEach { metadata -> diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt index fc48ee7ca..3d6d40bc1 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt @@ -29,7 +29,7 @@ class JsMRGenerator( generators = generators ) { private val flattenClassName: String = settings.packageName.flatName - override val resourcesGenerationDir: File = File(File(outputDir, flattenClassName), "res") + override val resourcesGenerationDir: File = settings.resourcesDir.asFile override fun processMRClass(mrClass: TypeSpec.Builder) { mrClass.addProperty( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsParamsHelper.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsParamsHelper.kt index c49576a50..fcb245246 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsParamsHelper.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsParamsHelper.kt @@ -7,8 +7,7 @@ package dev.icerock.gradle.generator.js private val messageFormatRegex = "%(.)(?:\\\$(.))?".toRegex() fun String.convertToMessageFormat(): String { - val allMatches = messageFormatRegex - .findAll(this) + val allMatches = messageFormatRegex.findAll(this) if (allMatches.count() == 0) return this diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsSetupUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsSetupUtils.kt index 473bae08e..5c67d5043 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsSetupUtils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsSetupUtils.kt @@ -4,12 +4,13 @@ import dev.icerock.gradle.generator.js.action.CopyResourcesToExecutableAction import dev.icerock.gradle.generator.js.action.CopyResourcesToKLibAction import org.gradle.api.Action import org.gradle.api.Task +import org.gradle.api.provider.Provider import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile import java.io.File fun setupJsKLibResources( compileTask: Kotlin2JsCompile, - resourcesGenerationDir: File + resourcesGenerationDir: Provider ) { val copyResourcesToKLibAction = CopyResourcesToKLibAction(resourcesGenerationDir) @Suppress("UNCHECKED_CAST") @@ -18,7 +19,7 @@ fun setupJsKLibResources( fun setupJsResources( compileTask: Kotlin2JsCompile, - resourcesGenerationDir: File + resourcesGenerationDir: Provider ) { val copyResourcesAction = CopyResourcesToExecutableAction(resourcesGenerationDir) @Suppress("UNCHECKED_CAST") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/action/CopyResourcesToExecutableAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/action/CopyResourcesToExecutableAction.kt index 60d6cdbff..a28ed0fdf 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/action/CopyResourcesToExecutableAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/action/CopyResourcesToExecutableAction.kt @@ -3,25 +3,27 @@ package dev.icerock.gradle.generator.js.action import dev.icerock.gradle.utils.klibs import org.gradle.api.Action import org.gradle.api.Project +import org.gradle.api.provider.Provider import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile import org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl import java.io.File class CopyResourcesToExecutableAction( - private val resourcesGeneratedDir: File, + private val resourcesGeneratedDir: Provider, ) : Action { override fun execute(task: Kotlin2JsCompile) { val project: Project = task.project + val resourceDir = resourcesGeneratedDir.get() task.klibs.forEach { dependency -> copyResourcesFromLibraries( inputFile = dependency, project = project, - outputDir = resourcesGeneratedDir + outputDir = resourceDir ) } - generateWebpackConfig(project, resourcesGeneratedDir) + generateWebpackConfig(project, resourceDir) generateKarmaConfig(project) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/action/CopyResourcesToKLibAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/action/CopyResourcesToKLibAction.kt index 6a32088ff..d02f095a2 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/action/CopyResourcesToKLibAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/action/CopyResourcesToKLibAction.kt @@ -1,11 +1,12 @@ package dev.icerock.gradle.generator.js.action import org.gradle.api.Action +import org.gradle.api.provider.Provider import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile import java.io.File class CopyResourcesToKLibAction( - private val resourcesDirProvider: File, + private val resourcesDirProvider: Provider, ) : Action { override fun execute(task: Kotlin2JsCompile) { val unpackedKLibDir: File = task.destinationDirectory.asFile.get() @@ -14,7 +15,8 @@ class CopyResourcesToKLibAction( if (resRepackDir.exists().not()) return val resDir = File(resRepackDir, "moko-resources-js") - resourcesDirProvider.copyRecursively( + + resourcesDirProvider.get().copyRecursively( target = resDir, overwrite = true ) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/ClassLoaderExtender.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/ClassLoaderExtender.kt index 5a86c6bc6..1d50bc5f5 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/ClassLoaderExtender.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/ClassLoaderExtender.kt @@ -6,6 +6,7 @@ package dev.icerock.gradle.generator.jvm import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.ObjectBodyExtendable @@ -16,6 +17,7 @@ class ClassLoaderExtender(private val mrClassName: String) : ObjectBodyExtendabl PropertySpec.builder( "resourcesClassLoader", ClassName("java.lang", "ClassLoader"), + KModifier.OVERRIDE ) .initializer(CodeBlock.of("${mrClassName}::class.java.classLoader")) .build() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt index 4e11ae2b2..3b48114aa 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt @@ -12,11 +12,11 @@ import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.TargetMRGenerator import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.utils.flatName -import java.io.File import org.gradle.api.Project import org.gradle.jvm.tasks.Jar import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import java.io.File class JvmMRGenerator( project: Project, @@ -29,7 +29,7 @@ class JvmMRGenerator( ) { private val flattenClassName: String = settings.packageName.flatName - override val resourcesGenerationDir: File = File(File(outputDir, flattenClassName), "res") + override val resourcesGenerationDir: File = settings.resourcesDir.asFile override fun processMRClass(mrClass: TypeSpec.Builder) { super.processMRClass(mrClass) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt index b3d36c301..b7eed4e9b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt @@ -7,7 +7,7 @@ fun MutableList.addActual(actualObject: GeneratedObject){ && it.type == actualObject.type } - if (expect != null){ + if (expect != null) { remove(expect) } 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 2b96d8980..c4410e8de 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 @@ -73,7 +73,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { abstract val outputMetadataFile: RegularFileProperty @get:Optional - @get:PathSensitive(PathSensitivity.ABSOLUTE) + @get:PathSensitive(PathSensitivity.NAME_ONLY) @get:InputFiles abstract val inputMetadataFiles: ConfigurableFileCollection @@ -82,7 +82,17 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { // abstract val generationReport: RegularFileProperty @get:OutputDirectory - abstract val outputDirectory: DirectoryProperty + abstract val outputGeneratedResourcesDir: DirectoryProperty + + @get:OutputDirectory + abstract val outputResourcesDir: DirectoryProperty + + @get:OutputDirectory + abstract val outputSourcesDir: DirectoryProperty + + @get:OutputDirectory + abstract val outputAssetsDir: DirectoryProperty + init { group = "moko-resources" @@ -99,7 +109,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { val mrGenerator: MRGenerator = resolveGenerator(settings, features) logger.warn("i ${platformType.get()} generator type: ${mrGenerator::class.java.simpleName}") - mrGenerator.generate() + mrGenerator.generate(project) } private fun resolveGenerator( @@ -122,14 +132,17 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { outputMetadataFile = outputMetadataFile.asFile.get(), packageName = resourcesPackageName.get(), className = resourcesClassName.get(), - generatedDir = outputDirectory.get(), + outputDirectory = outputGeneratedResourcesDir.get(), + assetsDir = outputAssetsDir.get(), + sourceSetDir = outputSourcesDir.get(), + resourcesDir = outputResourcesDir.get(), ownResourcesFileTree = ownResources.asFileTree, lowerResourcesFileTree = lowerResources.asFileTree, upperResourcesFileTree = upperResources.asFileTree, isStrictLineBreaks = project.isStrictLineBreaks, visibility = resourcesVisibility.get(), - androidRClassPackage = project.getAndroidRClassPackage().get(), - iosLocalizationRegion = iosBaseLocalizationRegion.get(), + androidRClassPackage = project.getAndroidRClassPackage(), + iosLocalizationRegion = iosBaseLocalizationRegion, ) } @@ -228,14 +241,10 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { settings: MRGenerator.Settings, generators: List>, ): AppleMRGenerator { - TODO() -// return AppleMRGenerator( -// project = project, -// settings = settings, -// generators = generators.map { -// it.createIosGenerator() -// }, -// compilation = compilationApple.get(), -// ) + return AppleMRGenerator( + project = project, + settings = settings, + generators = generators.map { it.createAppleGenerator() }, + ) } } From cf20b2f47be4eeb0d1bc1b4438a7c03ae0b9e4dc Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Fri, 15 Dec 2023 13:24:11 +0700 Subject: [PATCH 070/352] #535 remove unused fields --- .../gradle/generator/AssetsGenerator.kt | 1 - .../gradle/generator/ColorsGenerator.kt | 1 - .../gradle/generator/FilesGenerator.kt | 29 +++++-------------- .../gradle/generator/FontsGenerator.kt | 1 - .../android/AndroidFilesGenerator.kt | 5 +--- .../generator/apple/AppleFilesGenerator.kt | 5 +--- .../generator/common/CommonFilesGenerator.kt | 5 +--- .../gradle/generator/js/JsAssetsGenerator.kt | 1 - .../gradle/generator/js/JsColorsGenerator.kt | 2 -- .../gradle/generator/js/JsFilesGenerator.kt | 7 ++--- .../gradle/generator/js/JsFontsGenerator.kt | 1 - .../gradle/generator/jvm/JvmFilesGenerator.kt | 9 ++---- 12 files changed, 17 insertions(+), 50 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt index 7304f03f6..0bbdeff84 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt @@ -209,7 +209,6 @@ abstract class AssetsGenerator( override fun createJsGenerator(): AssetsGenerator = JsAssetsGenerator( ownResourcesFileTree = settings.ownResourcesFileTree, - lowerResourcesFileTree = settings.lowerResourcesFileTree, ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt index 6a453efc3..86109263b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt @@ -164,7 +164,6 @@ abstract class ColorsGenerator( ) override fun createJsGenerator(): ColorsGenerator = JsColorsGenerator( - project = project, resourcesFileTree = settings.ownResourcesFileTree, ) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt index 49e701b7d..440c825da 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt @@ -21,11 +21,11 @@ import org.gradle.api.file.FileTree import java.io.File abstract class FilesGenerator( - project: Project, - private val inputFileTree: FileTree + private val inputFileTree: FileTree, ) : MRGenerator.Generator { - override val inputFiles: Iterable get() = inputFileTree.files + override val inputFiles: Iterable + get() = inputFileTree.matching { it.include("files/**") } override val resourceClassName = ClassName("dev.icerock.moko.resources", "FileResource") override val mrObjectName: String = "files" @@ -66,7 +66,7 @@ abstract class FilesGenerator( override fun getImports(): List = emptyList() private fun generateFileProperty( - fileSpec: FileSpec + fileSpec: FileSpec, ): PropertySpec { @Suppress("SpreadOperator") return PropertySpec.builder(fileSpec.key, resourceClassName) @@ -79,12 +79,12 @@ abstract class FilesGenerator( protected open fun beforeGenerate( objectBuilder: TypeSpec.Builder, - files: List + files: List, ) = Unit protected open fun generateResources( resourcesGenerationDir: File, - files: List + files: List, ) = Unit private fun processKey(key: String): String { @@ -99,46 +99,33 @@ abstract class FilesGenerator( data class FileSpec( val key: String, - val file: File + val file: File, ) class Feature( val project: Project, - private val settings: MRGenerator.Settings + private val settings: MRGenerator.Settings, ) : ResourceGeneratorFeature { -// private val fileTree: FileTree = settings.ownResourcesFileTree -// .matching { it.include("files/**") } - override fun createCommonGenerator(): FilesGenerator = CommonFilesGenerator( - project = project, ownInputFileTree = settings.ownResourcesFileTree, - upperInputFileTree = settings.upperResourcesFileTree ) override fun createAppleGenerator(): FilesGenerator = AppleFilesGenerator( - project = project, ownInputFileTree = settings.ownResourcesFileTree, - lowerInputFileTree = settings.lowerResourcesFileTree ) override fun createAndroidGenerator(): FilesGenerator = AndroidFilesGenerator( - project = project, ownInputFileTree = settings.ownResourcesFileTree, - lowerInputFileTree = settings.lowerResourcesFileTree, androidRClassPackage = settings.androidRClassPackage, ) override fun createJsGenerator(): FilesGenerator = JsFilesGenerator( - project = project, ownInputFileTree = settings.ownResourcesFileTree, - lowerInputFileTree = settings.lowerResourcesFileTree ) override fun createJvmGenerator(): FilesGenerator = JvmFilesGenerator( - project = project, ownInputFileTree = settings.ownResourcesFileTree, - lowerInputFileTree = settings.lowerResourcesFileTree, settings = settings ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt index 2ff303586..232b0243c 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt @@ -155,7 +155,6 @@ abstract class FontsGenerator( override fun createJsGenerator(): FontsGenerator = JsFontsGenerator( ownInputFileTree = settings.ownResourcesFileTree, - lowerInputFileTree = settings.lowerResourcesFileTree, mrClassPackage = settings.packageName ) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt index a67c6a99a..d7167a024 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt @@ -10,18 +10,15 @@ import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.FilesGenerator import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable -import org.gradle.api.Project import org.gradle.api.file.FileTree import org.gradle.api.provider.Provider import java.io.File import java.util.Locale class AndroidFilesGenerator( - project: Project, ownInputFileTree: FileTree, - lowerInputFileTree: FileTree, private val androidRClassPackage: Provider, -) : FilesGenerator(project, ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { +) : FilesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFilesGenerator.kt index 82804b802..831394d8d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFilesGenerator.kt @@ -8,15 +8,12 @@ import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.FilesGenerator import dev.icerock.gradle.generator.ObjectBodyExtendable -import org.gradle.api.Project import org.gradle.api.file.FileTree import java.io.File class AppleFilesGenerator( - project: Project, ownInputFileTree: FileTree, - lowerInputFileTree: FileTree, -) : FilesGenerator(project, inputFileTree = ownInputFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { +) : FilesGenerator(inputFileTree = ownInputFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt index 5dae268f4..e9f4e1792 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt @@ -9,14 +9,11 @@ import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.FilesGenerator import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable -import org.gradle.api.Project import org.gradle.api.file.FileTree class CommonFilesGenerator( - project: Project, ownInputFileTree: FileTree, - upperInputFileTree: FileTree, -) : FilesGenerator(project, ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { +) : FilesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = emptyArray() override fun getPropertyModifiers(): Array = emptyArray() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsAssetsGenerator.kt index 0154cc9b2..25780b85b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsAssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsAssetsGenerator.kt @@ -18,7 +18,6 @@ import java.io.File class JsAssetsGenerator( ownResourcesFileTree: FileTree, - lowerResourcesFileTree: FileTree, ) : AssetsGenerator(ownResourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsColorsGenerator.kt index 00830fa73..63103664b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsColorsGenerator.kt @@ -15,11 +15,9 @@ import dev.icerock.gradle.generator.ColorsGenerator import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable import dev.icerock.gradle.generator.jsJvmCommon.createColorResourceInitializer -import org.gradle.api.Project import org.gradle.api.file.FileTree class JsColorsGenerator( - project: Project, resourcesFileTree: FileTree, ) : ColorsGenerator(resourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFilesGenerator.kt index d813f8112..00ddc47e7 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFilesGenerator.kt @@ -13,15 +13,14 @@ import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.FilesGenerator import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable -import org.gradle.api.Project import org.gradle.api.file.FileTree import java.io.File class JsFilesGenerator( - project: Project, ownInputFileTree: FileTree, - lowerInputFileTree: FileTree, -) : FilesGenerator(project,ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { +) : FilesGenerator( + inputFileTree = ownInputFileTree +), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFontsGenerator.kt index 920fd829b..26c60d6e1 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFontsGenerator.kt @@ -21,7 +21,6 @@ import java.io.File class JsFontsGenerator( ownInputFileTree: FileTree, - lowerInputFileTree: FileTree, mrClassPackage: String, ) : FontsGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFilesGenerator.kt index ed348579a..da546e728 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFilesGenerator.kt @@ -9,16 +9,13 @@ import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.FilesGenerator import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.ObjectBodyExtendable -import org.gradle.api.Project import org.gradle.api.file.FileTree import java.io.File class JvmFilesGenerator( - project: Project, ownInputFileTree: FileTree, - lowerInputFileTree: FileTree, - settings: MRGenerator.Settings -) : FilesGenerator(project, ownInputFileTree), + settings: MRGenerator.Settings, +) : FilesGenerator(ownInputFileTree), ObjectBodyExtendable by ClassLoaderExtender(settings.className) { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -32,7 +29,7 @@ class JvmFilesGenerator( override fun generateResources( resourcesGenerationDir: File, - files: List + files: List, ) { val fileResDir = File(resourcesGenerationDir, FILES_DIR).apply { mkdirs() } files.forEach { fileSpec -> From 83eda1518a96c9bb93cb6ed66ee600442e676e37 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Fri, 15 Dec 2023 13:41:21 +0700 Subject: [PATCH 071/352] #535 remove unused task property --- .../gradle/MultiplatformResourcesPlugin.kt | 1 - .../gradle/generator/AssetsGenerator.kt | 1 - .../gradle/generator/FontsGenerator.kt | 1 - .../icerock/gradle/generator/MRGenerator.kt | 30 +------------------ .../generator/jvm/JvmAssetsGenerator.kt | 1 - .../gradle/generator/jvm/JvmFontsGenerator.kt | 1 - .../GenerateMultiplatformResourcesTask.kt | 9 ++---- 7 files changed, 3 insertions(+), 41 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index bc00698d5..176866fa7 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -310,7 +310,6 @@ open class MultiplatformResourcesPlugin : Plugin { ) ) val sourceSetResourceDir = File(generatedMokoResourcesDir, kotlinSourceSet.name) - generateTask.outputGeneratedResourcesDir.set(sourceSetResourceDir) generateTask.outputAssetsDir.set(File(sourceSetResourceDir, "assets")) generateTask.outputResourcesDir.set(File(sourceSetResourceDir, "res")) generateTask.outputSourcesDir.set(File(sourceSetResourceDir, "src")) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt index 0bbdeff84..0e0176f62 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt @@ -203,7 +203,6 @@ abstract class AssetsGenerator( override fun createJvmGenerator(): AssetsGenerator = JvmAssetsGenerator( ownResourcesFileTree = settings.ownResourcesFileTree, - lowerResourcesFileTree = settings.lowerResourcesFileTree, settings = settings ) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt index 232b0243c..249177b64 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt @@ -160,7 +160,6 @@ abstract class FontsGenerator( override fun createJvmGenerator(): FontsGenerator = JvmFontsGenerator( ownInputFileTree = settings.ownResourcesFileTree, - lowerInputFileTree = settings.lowerResourcesFileTree, settings = settings ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt index 8ad80938d..2d230d0d8 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt @@ -27,38 +27,11 @@ abstract class MRGenerator( protected open val assetsGenerationDir: File = settings.assetsDir.asFile - internal fun generate(project: Project) { - - project.logger.warn("GENERATE: BEFORE DELETE") - - sourcesGenerationDir.listFiles()?.forEach {file -> - project.logger.warn("GENERATE: sourcesGenerationDir $file") - } - resourcesGenerationDir.listFiles()?.forEach {file -> - project.logger.warn("GENERATE: resourcesGenerationDir$file") - } - assetsGenerationDir.listFiles()?.forEach {file -> - project.logger.warn("GENERATE: assetsGenerationDir $file") - } - - // Не работает рекурсивное удаление - // лог директорий, что удалено + internal fun generate() { sourcesGenerationDir.deleteRecursively() resourcesGenerationDir.deleteRecursively() assetsGenerationDir.deleteRecursively() - project.logger.warn("GENERATE: AFTER DELETE") - - sourcesGenerationDir.listFiles()?.forEach {file -> - project.logger.warn("GENERATE: sourcesGenerationDir $file") - } - resourcesGenerationDir.listFiles()?.forEach {file -> - project.logger.warn("GENERATE: resourcesGenerationDir$file") - } - assetsGenerationDir.listFiles()?.forEach {file -> - project.logger.warn("GENERATE: assetsGenerationDir $file") - } - beforeMRGeneration() val file = generateFileSpec() @@ -139,7 +112,6 @@ abstract class MRGenerator( val packageName: String, val className: String, val visibility: MRVisibility, - val outputDirectory: Directory, val assetsDir: Directory, val sourceSetDir: Directory, val resourcesDir: Directory, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmAssetsGenerator.kt index 0e71f0a64..3187cbd22 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmAssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmAssetsGenerator.kt @@ -14,7 +14,6 @@ import java.io.File class JvmAssetsGenerator( ownResourcesFileTree: FileTree, - lowerResourcesFileTree: FileTree, settings: MRGenerator.Settings ) : AssetsGenerator(ownResourcesFileTree), ObjectBodyExtendable by ClassLoaderExtender(settings.className) { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFontsGenerator.kt index 86bb2866e..190d53720 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFontsGenerator.kt @@ -14,7 +14,6 @@ import java.io.File class JvmFontsGenerator( ownInputFileTree: FileTree, - lowerInputFileTree: FileTree, settings: MRGenerator.Settings ) : FontsGenerator(ownInputFileTree), ObjectBodyExtendable by ClassLoaderExtender(settings.className) { 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 c4410e8de..80b6d7e04 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 @@ -73,7 +73,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { abstract val outputMetadataFile: RegularFileProperty @get:Optional - @get:PathSensitive(PathSensitivity.NAME_ONLY) + @get:PathSensitive(PathSensitivity.ABSOLUTE) @get:InputFiles abstract val inputMetadataFiles: ConfigurableFileCollection @@ -81,9 +81,6 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { // @get:OutputFile // abstract val generationReport: RegularFileProperty - @get:OutputDirectory - abstract val outputGeneratedResourcesDir: DirectoryProperty - @get:OutputDirectory abstract val outputResourcesDir: DirectoryProperty @@ -93,7 +90,6 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { @get:OutputDirectory abstract val outputAssetsDir: DirectoryProperty - init { group = "moko-resources" } @@ -109,7 +105,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { val mrGenerator: MRGenerator = resolveGenerator(settings, features) logger.warn("i ${platformType.get()} generator type: ${mrGenerator::class.java.simpleName}") - mrGenerator.generate(project) + mrGenerator.generate() } private fun resolveGenerator( @@ -132,7 +128,6 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { outputMetadataFile = outputMetadataFile.asFile.get(), packageName = resourcesPackageName.get(), className = resourcesClassName.get(), - outputDirectory = outputGeneratedResourcesDir.get(), assetsDir = outputAssetsDir.get(), sourceSetDir = outputSourcesDir.get(), resourcesDir = outputResourcesDir.get(), From 7909639643e8cd88ecb7760a2913ecfce56733c5 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 17 Dec 2023 23:28:36 +0700 Subject: [PATCH 072/352] #535 configure valid android generation --- .../gradle/MultiplatformResourcesPlugin.kt | 112 +++++++++++------- .../GenerateMultiplatformResourcesTask.kt | 12 ++ 2 files changed, 79 insertions(+), 45 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 176866fa7..01c0de324 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -4,13 +4,15 @@ package dev.icerock.gradle -import com.android.build.gradle.BaseExtension +import com.android.build.api.dsl.AndroidSourceSet +import com.android.build.gradle.api.BaseVariant import dev.icerock.gradle.generator.apple.setupAppleKLibResources import dev.icerock.gradle.generator.js.setupJsKLibResources import dev.icerock.gradle.generator.js.setupJsResources import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.utils.dependsOnObservable import dev.icerock.gradle.utils.kotlinSourceSetsObservable +import org.gradle.api.GradleException import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.file.SourceDirectorySet @@ -18,19 +20,18 @@ import org.gradle.api.tasks.TaskProvider import org.gradle.kotlin.dsl.create import org.gradle.kotlin.dsl.getByType import org.gradle.kotlin.dsl.withType +import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation import org.jetbrains.kotlin.gradle.plugin.KotlinMultiplatformPluginWrapper import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType -import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.androidJvm -import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.common -import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.js -import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.jvm -import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.native -import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.wasm import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import org.jetbrains.kotlin.gradle.plugin.KotlinTarget +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmAndroidCompilation import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget +import org.jetbrains.kotlin.gradle.plugin.sources.android.findAndroidSourceSet import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile @@ -97,32 +98,36 @@ open class MultiplatformResourcesPlugin : Plugin { target.compilations.configureEach { compilation -> compilation.kotlinSourceSetsObservable.forAll { sourceSet: KotlinSourceSet -> val genTaskProvider: TaskProvider = - requireNotNull( - sourceSet.extras[mokoResourcesGenTaskKey()] - ) + requireNotNull(sourceSet.extras[mokoResourcesGenTaskKey()]) genTaskProvider.configure { it.platformType.set(target.platformType.name) - if (target.platformType == KotlinPlatformType.native) { - it.konanTarget.set((target as KotlinNativeTarget).konanTarget.name) + if (target is KotlinNativeTarget) { + it.konanTarget.set(target.konanTarget.name) } } // Setup generated sourceSets, assets, resources as sourceSet of target setupSourceSets( - project, target = target, sourceSet = sourceSet, genTaskProvider = genTaskProvider, + compilation = compilation + ) + + // Setup android specific tasks + setupAndroidTasks( + target = target, + sourceSet = sourceSet, + genTaskProvider = genTaskProvider, + compilation = compilation ) compilation.compileTaskProvider.configure { compileTask: KotlinCompilationTask<*> -> compileTask.dependsOn(genTaskProvider) - if (target.platformType == KotlinPlatformType.js) { - compileTask as Kotlin2JsCompile - + if (compileTask is Kotlin2JsCompile) { setupJsResources( compileTask = compileTask, resourcesGenerationDir = genTaskProvider.flatMap { @@ -137,8 +142,7 @@ open class MultiplatformResourcesPlugin : Plugin { ) } - if (target.platformType == KotlinPlatformType.native) { - target as KotlinNativeTarget + if (target is KotlinNativeTarget) { compilation as KotlinNativeCompilation compileTask as KotlinNativeCompile @@ -220,50 +224,68 @@ open class MultiplatformResourcesPlugin : Plugin { // setupProjectForApple(project) } + @OptIn(ExperimentalKotlinGradlePluginApi::class) private fun setupSourceSets( - project: Project, target: KotlinTarget, sourceSet: KotlinSourceSet, genTaskProvider: TaskProvider, + compilation: KotlinCompilation<*>, ) { + val project: Project = target.project + sourceSet.kotlin.srcDir(genTaskProvider.map { it.outputSourcesDir }) when (target.platformType) { - jvm, js -> { + KotlinPlatformType.jvm, KotlinPlatformType.js -> { sourceSet.resources.srcDir(genTaskProvider.map { it.outputResourcesDir }) sourceSet.resources.srcDir(genTaskProvider.map { it.outputAssetsDir }) } - androidJvm -> { - val androidExtension: BaseExtension = target.project.extensions.getByType() - - // Remove android name from kotlinSourceSet name, because androidSourceSet - // doesn't have prefix 'android' - val kotlinSourceSetName: String = sourceSet.name - .replace("android", "") - .lowercase() - - //TODO: Need correction of filter for setup test sourceSets - // maybe should do logic implementation with - // https://kotlinlang.org/docs/multiplatform-android-layout.html#move-source-files - - androidExtension.sourceSets.filter { - it.name == kotlinSourceSetName - }.forEach { androidSourceSet -> - project.logger.warn("SETUP ANDROID SOURCESETS: ${sourceSet.name} androidSS: ${androidSourceSet.name}") - project.logger.warn("SETUP ANDROID SOURCESETS: genTaskProvider: $genTaskProvider") - - // Setup source for release/debug - androidSourceSet.kotlin.srcDir(genTaskProvider.map { it.outputSourcesDir }) - androidSourceSet.res.srcDir(genTaskProvider.map { it.outputResourcesDir }) - androidSourceSet.assets.srcDir(genTaskProvider.map { it.outputAssetsDir }) - } + KotlinPlatformType.androidJvm -> { + target as KotlinAndroidTarget + compilation as KotlinJvmAndroidCompilation + + val androidSourceSet: AndroidSourceSet = project.findAndroidSourceSet(sourceSet) + ?: throw GradleException("can't find android source set for $sourceSet") + + @Suppress("UnstableApiUsage") + androidSourceSet.kotlin.srcDir(genTaskProvider.map { it.outputSourcesDir }) + @Suppress("UnstableApiUsage") + androidSourceSet.res.srcDir(genTaskProvider.map { it.outputResourcesDir }) + @Suppress("UnstableApiUsage") + androidSourceSet.assets.srcDir(genTaskProvider.map { it.outputAssetsDir }) } - common, native, wasm -> Unit + KotlinPlatformType.common, KotlinPlatformType.native, KotlinPlatformType.wasm -> Unit } } + @OptIn(ExperimentalKotlinGradlePluginApi::class) + private fun setupAndroidTasks( + target: KotlinTarget, + sourceSet: KotlinSourceSet, + genTaskProvider: TaskProvider, + compilation: KotlinCompilation<*> + ) { + if (target !is KotlinAndroidTarget) return + + compilation as KotlinJvmAndroidCompilation + + val project: Project = target.project + + val androidSourceSet: AndroidSourceSet = project.findAndroidSourceSet(sourceSet) + ?: throw GradleException("can't find android source set for $sourceSet") + + // save android sourceSet name to skip build type specific tasks + @Suppress("UnstableApiUsage") + genTaskProvider.configure { it.androidSourceSetName.set(androidSourceSet.name) } + + // connect generateMR task with android preBuild + @Suppress("DEPRECATION") + val androidVariant: BaseVariant = compilation.androidVariant + androidVariant.preBuildProvider.configure { it.dependsOn(genTaskProvider) } + } + private fun createMokoResourcesSourceSet( project: Project, kotlinSourceSet: KotlinSourceSet, 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 80b6d7e04..8c74238d8 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 @@ -63,6 +63,10 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { @get:Input abstract val resourcesClassName: Property + @get:Optional + @get:Input + abstract val androidSourceSetName: Property + @get:Input abstract val iosBaseLocalizationRegion: Property @@ -92,6 +96,14 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { init { group = "moko-resources" + + onlyIf("generation on Android supported only for main flavor") { + val platform: String = platformType.get() + if (platform != KotlinPlatformType.androidJvm.name) return@onlyIf true + + val flavor: String = androidSourceSetName.get() + flavor in listOf("main", "test", "androidTest") + } } @TaskAction From 669f75df38c9e3bb713bf950980da37164a53f97 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 17 Dec 2023 23:29:56 +0700 Subject: [PATCH 073/352] #535 comment unused code (will be removed later) --- .../gradle/configuration/AndroidTarget.kt | 101 +++++++-------- .../gradle/configuration/AppleTargets.kt | 119 +++++++++--------- .../gradle/configuration/CommonTarget.kt | 33 ++--- .../icerock/gradle/configuration/JsTarget.kt | 47 +++---- .../icerock/gradle/configuration/JvmTarget.kt | 27 ++-- .../icerock/gradle/generator/MRGenerator.kt | 52 ++++---- .../gradle/generator/TargetMRGenerator.kt | 31 ++--- .../generator/android/AndroidMRGenerator.kt | 19 +-- .../generator/common/CommonMRGenerator.kt | 37 +++--- .../gradle/generator/js/JsMRGenerator.kt | 37 +++--- .../gradle/generator/jvm/JvmMRGenerator.kt | 27 ++-- 11 files changed, 271 insertions(+), 259 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AndroidTarget.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AndroidTarget.kt index 8b4356abd..d3a2e4824 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AndroidTarget.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AndroidTarget.kt @@ -24,26 +24,27 @@ import java.io.File import javax.xml.parsers.DocumentBuilder import javax.xml.parsers.DocumentBuilderFactory -internal fun configureAndroidTargetGenerator( - target: KotlinTarget, - settings: MRGenerator.Settings, - features: List> -) { - val project: Project = target.project - - listOf( - "com.android.library", - "com.android.application" - ).forEach { id -> - project.plugins.withId(id) { - setupAndroidGenerator( - settings = settings, - features = features, - project = project - ) - } - } -} +// TODO not used. remove after complete migration of task configuration to Plugin configuration time +//internal fun configureAndroidTargetGenerator( +// target: KotlinTarget, +// settings: MRGenerator.Settings, +// features: List> +//) { +// val project: Project = target.project +// +// listOf( +// "com.android.library", +// "com.android.application" +// ).forEach { id -> +// project.plugins.withId(id) { +// setupAndroidGenerator( +// settings = settings, +// features = features, +// project = project +// ) +// } +// } +//} internal fun Project.getAndroidRClassPackage(): Provider { return provider { @@ -52,37 +53,37 @@ internal fun Project.getAndroidRClassPackage(): Provider { } } -@Suppress("LongParameterList") -private fun setupAndroidGenerator( - project: Project, - settings: MRGenerator.Settings, - features: List>, -) { - setAssetsDirsRefresh(project) +//@Suppress("LongParameterList") +//private fun setupAndroidGenerator( +// project: Project, +// settings: MRGenerator.Settings, +// features: List>, +//) { +// setAssetsDirsRefresh(project) +// +// AndroidMRGenerator( +// project = project, +// settings = settings, +// generators = features.map { it.createAndroidGenerator() }, +// ).apply(project) +//} - AndroidMRGenerator( - project = project, - settings = settings, - generators = features.map { it.createAndroidGenerator() }, - ).apply(project) -} - -private fun setAssetsDirsRefresh(project: Project) { - // without this code Android Gradle Plugin not copy assets to aar - project.tasks - .matching { it.name.startsWith("package") && it.name.endsWith("Assets") } - .configureEach { task -> - // for gradle optimizations we should use anonymous object - @Suppress("ObjectLiteralToLambda") - task.doFirst(object : Action { - override fun execute(t: Task) { - val android: BaseExtension = project.extensions.getByType() - val assets: AndroidSourceDirectorySet = android.mainSourceSet.assets - assets.setSrcDirs(assets.srcDirs) - } - }) - } -} +//private fun setAssetsDirsRefresh(project: Project) { +// // without this code Android Gradle Plugin not copy assets to aar +// project.tasks +// .matching { it.name.startsWith("package") && it.name.endsWith("Assets") } +// .configureEach { task -> +// // for gradle optimizations we should use anonymous object +// @Suppress("ObjectLiteralToLambda") +// task.doFirst(object : Action { +// override fun execute(t: Task) { +// val android: BaseExtension = project.extensions.getByType() +// val assets: AndroidSourceDirectorySet = android.mainSourceSet.assets +// assets.setSrcDirs(assets.srcDirs) +// } +// }) +// } +//} private fun getAndroidPackage(manifestFile: File): String { val dbFactory: DocumentBuilderFactory = DocumentBuilderFactory.newInstance() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt index 699b19115..0be15960a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt @@ -20,65 +20,66 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFrameworkTask import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink import org.jetbrains.kotlin.konan.target.HostManager -internal fun configureAppleTargetGenerator( - target: KotlinNativeTarget, - settings: MRGenerator.Settings, - features: List> -) { - if (HostManager.hostIsMac.not()) { - target.project.logger.warn("MR file generation for Apple is not supported on your system!") - return - } +// TODO not used. remove after complete migration of task configuration to Plugin configuration time +//internal fun configureAppleTargetGenerator( +// target: KotlinNativeTarget, +// settings: MRGenerator.Settings, +// features: List> +//) { +// if (HostManager.hostIsMac.not()) { +// target.project.logger.warn("MR file generation for Apple is not supported on your system!") +// return +// } +// +// val mainCompilation: KotlinNativeCompilation = target.compilations +// .getByName(KotlinCompilation.MAIN_COMPILATION_NAME) +// +// AppleMRGenerator( +// project = target.project, +// settings = settings, +// generators = features.map { it.createAppleGenerator() }, +// ).apply(target.project) +//} - val mainCompilation: KotlinNativeCompilation = target.compilations - .getByName(KotlinCompilation.MAIN_COMPILATION_NAME) +//internal fun setupProjectForApple(project: Project) { +// if (HostManager.hostIsMac.not()) { +// project.logger.warn("MR file generation for Apple is not supported on your system!") +// return +// } +// +// // without this afterEvaluate in ios-static-xcframework sample we got +// // configuration iosArm64DebugFrameworkExport not found error +// project.afterEvaluate { +// setupCopyXCFrameworkResourcesTask(project) +// createCopyResourcesToAppTask(project) +// } +//} - AppleMRGenerator( - project = target.project, - settings = settings, - generators = features.map { it.createAppleGenerator() }, - ).apply(target.project) -} +//private fun setupCopyXCFrameworkResourcesTask(project: Project) { +// // Seems that there were problem with this block in the past with mystic task adding. Need more info +// // Now, that works perfectly, I've tested on the real project with Kotlin 1.9.10 and KSP enabled +// // Suppose that on that moment there were no lazy register method for task container +// project.tasks.withType(XCFrameworkTask::class).all { task -> +// val copyTaskName: String = task.name +// .replace("assemble", "copyResources").plus("ToApp") +// +// project.tasks.register(copyTaskName) { +// xcFrameworkDir = task.outputDir +// dependsOn(task) +// } +// } +//} -internal fun setupProjectForApple(project: Project) { - if (HostManager.hostIsMac.not()) { - project.logger.warn("MR file generation for Apple is not supported on your system!") - return - } - - // without this afterEvaluate in ios-static-xcframework sample we got - // configuration iosArm64DebugFrameworkExport not found error - project.afterEvaluate { - setupCopyXCFrameworkResourcesTask(project) - createCopyResourcesToAppTask(project) - } -} - -private fun setupCopyXCFrameworkResourcesTask(project: Project) { - // Seems that there were problem with this block in the past with mystic task adding. Need more info - // Now, that works perfectly, I've tested on the real project with Kotlin 1.9.10 and KSP enabled - // Suppose that on that moment there were no lazy register method for task container - project.tasks.withType(XCFrameworkTask::class).all { task -> - val copyTaskName: String = task.name - .replace("assemble", "copyResources").plus("ToApp") - - project.tasks.register(copyTaskName) { - xcFrameworkDir = task.outputDir - dependsOn(task) - } - } -} - -private fun createCopyResourcesToAppTask(project: Project) { - project.tasks - .withType() - .matching { it.binary is AbstractExecutable } - .all { linkTask -> - val copyTaskName: String = linkTask.name.replace("link", "copyResources") - - project.tasks.register(copyTaskName) { - this.linkTask = linkTask - dependsOn(linkTask) - } - } -} +//private fun createCopyResourcesToAppTask(project: Project) { +// project.tasks +// .withType() +// .matching { it.binary is AbstractExecutable } +// .all { linkTask -> +// val copyTaskName: String = linkTask.name.replace("link", "copyResources") +// +// project.tasks.register(copyTaskName) { +// this.linkTask = linkTask +// dependsOn(linkTask) +// } +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/CommonTarget.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/CommonTarget.kt index 34a8eca3b..08e643675 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/CommonTarget.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/CommonTarget.kt @@ -11,19 +11,20 @@ import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.plugin.KotlinTarget -internal fun configureCommonTargetGenerator( - target: KotlinTarget, - settings: MRGenerator.Settings, - features: List>, -) { - val generationTask: GenerateMultiplatformResourcesTask = CommonMRGenerator( - project = target.project, - settings = settings, - generators = features.map { it.createCommonGenerator() } - ).apply(project = target.project,) - - target.project.tasks - .withType() - .matching { it != generationTask } - .configureEach { it.dependsOn(generationTask) } -} +// TODO not used. remove after complete migration of task configuration to Plugin configuration time +//internal fun configureCommonTargetGenerator( +// target: KotlinTarget, +// settings: MRGenerator.Settings, +// features: List>, +//) { +// val generationTask: GenerateMultiplatformResourcesTask = CommonMRGenerator( +// project = target.project, +// settings = settings, +// generators = features.map { it.createCommonGenerator() } +// ).apply(project = target.project,) +// +// target.project.tasks +// .withType() +// .matching { it != generationTask } +// .configureEach { it.dependsOn(generationTask) } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JsTarget.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JsTarget.kt index 247f45d4e..e9f8d2943 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JsTarget.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JsTarget.kt @@ -11,26 +11,27 @@ import org.gradle.api.Project import org.jetbrains.kotlin.gradle.plugin.KotlinTarget import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget -internal fun configureJsTargetGenerator( - target: KotlinTarget, - settings: MRGenerator.Settings, - features: List> -) { - val project: Project = target.project - val jsTarget: KotlinJsIrTarget? = target as? KotlinJsIrTarget - if (jsTarget == null) { - project.logger.warn("$target is not supported by MOKO Resources") - return - } - - jsTarget.compilations.configureEach { compilation -> - // TODO rollback ifDepends -// compilation.defaultSourceSet.ifDependsOn(commonSourceSet) { - JsMRGenerator( - project = project, - settings = settings, - generators = features.map { it.createJsGenerator() }, - ).apply(project = project) -// } - } -} +// TODO not used. remove after complete migration of task configuration to Plugin configuration time +//internal fun configureJsTargetGenerator( +// target: KotlinTarget, +// settings: MRGenerator.Settings, +// features: List> +//) { +// val project: Project = target.project +// val jsTarget: KotlinJsIrTarget? = target as? KotlinJsIrTarget +// if (jsTarget == null) { +// project.logger.warn("$target is not supported by MOKO Resources") +// return +// } +// +// jsTarget.compilations.configureEach { compilation -> +// // TODO rollback ifDepends +//// compilation.defaultSourceSet.ifDependsOn(commonSourceSet) { +// JsMRGenerator( +// project = project, +// settings = settings, +// generators = features.map { it.createJsGenerator() }, +// ).apply(project = project) +//// } +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JvmTarget.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JvmTarget.kt index 2c1d128cc..8845bf4a9 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JvmTarget.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JvmTarget.kt @@ -9,16 +9,17 @@ import dev.icerock.gradle.generator.ResourceGeneratorFeature import dev.icerock.gradle.generator.jvm.JvmMRGenerator import org.jetbrains.kotlin.gradle.plugin.KotlinTarget -internal fun configureJvmTargetGenerator( - target: KotlinTarget, - settings: MRGenerator.Settings, - features: List> -) { - JvmMRGenerator( - project = target.project, - settings = settings, - generators = features.map { it.createJvmGenerator() } - ).apply(project = target.project) - // TODO fix depends on -// compilation.defaultSourceSet.ifDependsOn(commonSourceSet) { -} +// TODO not used. remove after complete migration of task configuration to Plugin configuration time +//internal fun configureJvmTargetGenerator( +// target: KotlinTarget, +// settings: MRGenerator.Settings, +// features: List> +//) { +// JvmMRGenerator( +// project = target.project, +// settings = settings, +// generators = features.map { it.createJvmGenerator() } +// ).apply(project = target.project) +// // TODO fix depends on +//// compilation.defaultSourceSet.ifDependsOn(commonSourceSet) { +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt index 2d230d0d8..5541f9877 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt @@ -42,36 +42,38 @@ abstract class MRGenerator( abstract fun generateFileSpec(): FileSpec? - fun apply(project: Project): GenerateMultiplatformResourcesTask { - //TODO add sourceSetName - val name: String = project.displayName - - val genTask = project.tasks.create( - "generateMR$name", - GenerateMultiplatformResourcesTask::class.java - ) { - it.inputs.property("mokoSettingsPackageName", settings.packageName) - it.inputs.property("mokoSettingsClassName", settings.className) - it.inputs.property("mokoSettingsVisibility", settings.visibility) - it.inputs.property( - "mokoSettingsIosLocalizationRegion", - settings.iosLocalizationRegion - ) - } - - apply(generationTask = genTask, project = project) - - return genTask - } + // TODO not used. remove after complete migration of task configuration to Plugin configuration time +// fun apply(project: Project): GenerateMultiplatformResourcesTask { +// //TODO add sourceSetName +// val name: String = project.displayName +// +// val genTask = project.tasks.create( +// "generateMR$name", +// GenerateMultiplatformResourcesTask::class.java +// ) { +// it.inputs.property("mokoSettingsPackageName", settings.packageName) +// it.inputs.property("mokoSettingsClassName", settings.className) +// it.inputs.property("mokoSettingsVisibility", settings.visibility) +// it.inputs.property( +// "mokoSettingsIosLocalizationRegion", +// settings.iosLocalizationRegion +// ) +// } +// +// apply(generationTask = genTask, project = project) +// +// return genTask +// } protected open fun beforeMRGeneration() = Unit protected open fun afterMRGeneration() = Unit protected abstract fun getMRClassModifiers(): Array - protected abstract fun apply( - generationTask: GenerateMultiplatformResourcesTask, - project: Project, - ) + +// protected abstract fun apply( +// generationTask: GenerateMultiplatformResourcesTask, +// project: Project, +// ) protected open fun processMRClass(mrClass: TypeSpec.Builder) {} protected open fun getImports(): List = emptyList() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt index 026145f40..86a180836 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt @@ -30,21 +30,22 @@ abstract class TargetMRGenerator( ) { val logger = project.logger - override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { - val name = settings.ownResourcesFileTree.first().targetName - val genTaskName = "generateMR$name" - - val genTask = runCatching { - project.tasks.getByName(genTaskName) as GenerateMultiplatformResourcesTask - }.getOrNull() ?: project.tasks.create( - genTaskName, - GenerateMultiplatformResourcesTask::class.java - ) { - it.generate() - } - - apply(generationTask = genTask, project = project) - } + // TODO not used. remove after complete migration of task configuration to Plugin configuration time +// override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { +// val name = settings.ownResourcesFileTree.first().targetName +// val genTaskName = "generateMR$name" +// +// val genTask = runCatching { +// project.tasks.getByName(genTaskName) as GenerateMultiplatformResourcesTask +// }.getOrNull() ?: project.tasks.create( +// genTaskName, +// GenerateMultiplatformResourcesTask::class.java +// ) { +// it.generate() +// } +// +// apply(generationTask = genTask, project = project) +// } override fun getMRClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt index 0b5c33462..29efd4e2d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt @@ -20,13 +20,14 @@ class AndroidMRGenerator( settings = settings, generators = generators ) { - override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { - - project.tasks.withType().configureEach { - it.dependsOn(generationTask) - } - project.tasks.withType().configureEach { - it.dependsOn(generationTask) - } - } + // TODO not used. remove after complete migration of task configuration to Plugin configuration time +// override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { +// +// project.tasks.withType().configureEach { +// it.dependsOn(generationTask) +// } +// project.tasks.withType().configureEach { +// it.dependsOn(generationTask) +// } +// } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index 61556987b..b6df1fb03 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -41,24 +41,25 @@ class CommonMRGenerator( override fun getMRClassModifiers(): Array = arrayOf(KModifier.EXPECT) - override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { - project.tasks - .withType>() -// .matching { it.name.contains(sourceSet.name, ignoreCase = true) } - .configureEach { it.dependsOn(generationTask) } - - project.rootProject.tasks.matching { - it.name.contains("prepareKotlinBuildScriptModel") - }.configureEach { - it.dependsOn(generationTask) - } - - project.tasks - .matching { it.name.startsWith("metadata") && it.name.endsWith("ProcessResources") } - .configureEach { - it.dependsOn(generationTask) - } - } + // TODO not used. remove after complete migration of task configuration to Plugin configuration time +// override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { +// project.tasks +// .withType>() +//// .matching { it.name.contains(sourceSet.name, ignoreCase = true) } +// .configureEach { it.dependsOn(generationTask) } +// +// project.rootProject.tasks.matching { +// it.name.contains("prepareKotlinBuildScriptModel") +// }.configureEach { +// it.dependsOn(generationTask) +// } +// +// project.tasks +// .matching { it.name.startsWith("metadata") && it.name.endsWith("ProcessResources") } +// .configureEach { +// it.dependsOn(generationTask) +// } +// } override fun generateFileSpec(): FileSpec? { // if (settings.ownResourcesFileTree.files.isEmpty()) return null diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt index 3d6d40bc1..21d01584f 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt @@ -71,24 +71,25 @@ class JsMRGenerator( } } - override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { - project.tasks.withType().configureEach { - it.dependsOn(generationTask) - } -// setupKLibResources(generationTask) -// setupResources() - - // Declare task ':web-app:generateMRcommonMain' as an input of ':web-app:jsSourcesJar'. - project.tasks.withType().configureEach { - it.dependsOn(generationTask) - } - -// dependsOnProcessResources( -// project = project, -// sourceSet = sourceSet, -// task = generationTask, -// ) - } + // TODO not used. remove after complete migration of task configuration to Plugin configuration time +// override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { +// project.tasks.withType().configureEach { +// it.dependsOn(generationTask) +// } +//// setupKLibResources(generationTask) +//// setupResources() +// +// // Declare task ':web-app:generateMRcommonMain' as an input of ':web-app:jsSourcesJar'. +// project.tasks.withType().configureEach { +// it.dependsOn(generationTask) +// } +// +//// dependsOnProcessResources( +//// project = project, +//// sourceSet = sourceSet, +//// task = generationTask, +//// ) +// } companion object { const val SUPPORTED_LOCALES_PROPERTY_NAME = "supportedLocales" diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt index 3b48114aa..0e187d02a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt @@ -63,19 +63,20 @@ class JvmMRGenerator( ) } - override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { - project.tasks.withType().configureEach { - it.dependsOn(generationTask) - } - project.tasks.withType().configureEach { - it.dependsOn(generationTask) - } -// dependsOnProcessResources( -// project = project, -// sourceSet = sourceSet, -// task = generationTask, -// ) - } + // TODO not used. remove after complete migration of task configuration to Plugin configuration time +// override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { +// project.tasks.withType().configureEach { +// it.dependsOn(generationTask) +// } +// project.tasks.withType().configureEach { +// it.dependsOn(generationTask) +// } +//// dependsOnProcessResources( +//// project = project, +//// sourceSet = sourceSet, +//// task = generationTask, +//// ) +// } companion object { const val STRINGS_BUNDLE_PROPERTY_NAME = "stringsBundle" From a8335ef12745dd35318cf8c24b870ef1dd93685b Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Mon, 18 Dec 2023 12:27:25 +0700 Subject: [PATCH 074/352] #535 fix generation of resources objects, divide resource logic for target generator --- .../gradle/MultiplatformResourcesPlugin.kt | 21 ++- .../gradle/generator/AssetsGenerator.kt | 2 +- .../icerock/gradle/generator/BaseGenerator.kt | 22 ++- .../gradle/generator/ColorsGenerator.kt | 2 +- .../gradle/generator/FilesGenerator.kt | 2 +- .../gradle/generator/FontsGenerator.kt | 3 +- .../gradle/generator/ImagesGenerator.kt | 2 +- .../icerock/gradle/generator/MRGenerator.kt | 8 +- .../gradle/generator/TargetMRGenerator.kt | 144 +++++++++++------- .../generator/apple/AppleMRGenerator.kt | 3 + .../gradle/generator/apple/SetupAppleUtils.kt | 39 ++--- .../generator/common/CommonMRGenerator.kt | 95 +++++++----- .../generator/jvm/JvmPluralsGenerator.kt | 4 +- .../gradle/metadata/GeneratedObject.kt | 6 + .../icerock/gradle/metadata/MetadataExt.kt | 26 +++- .../dev/icerock/gradle/metadata/Utils.kt | 14 +- .../jvmMain/moko-resources/base/strings.xml | 4 + .../src/commonMain/kotlin/Main.macos.kt | 3 +- .../src/androidMain/kotlin/main.android.kt | 2 +- .../moko-resources/images/car_white.svg | 10 +- .../webApp/build.gradle.kts | 2 - 21 files changed, 261 insertions(+), 153 deletions(-) create mode 100644 samples/compose-resources-gallery/desktopApp/src/jvmMain/moko-resources/base/strings.xml diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 01c0de324..6f77567d2 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -7,6 +7,9 @@ package dev.icerock.gradle import com.android.build.api.dsl.AndroidSourceSet import com.android.build.gradle.api.BaseVariant import dev.icerock.gradle.generator.apple.setupAppleKLibResources +import dev.icerock.gradle.generator.apple.setupFatFrameworkTasks +import dev.icerock.gradle.generator.apple.setupFrameworkResources +import dev.icerock.gradle.generator.apple.setupTestsResources import dev.icerock.gradle.generator.js.setupJsKLibResources import dev.icerock.gradle.generator.js.setupJsResources import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask @@ -94,6 +97,20 @@ open class MultiplatformResourcesPlugin : Plugin { ) } + // If use configureEach, we get exception of task context in project, on configuration step + kmpExtension.targets.matching { + it.platformType == KotlinPlatformType.native + }.configureEach { target -> + target.compilations.configureEach { compilation -> + + compilation as KotlinNativeCompilation + + setupFrameworkResources(compilation = compilation) + setupTestsResources(compilation = compilation) + setupFatFrameworkTasks(compilation = compilation) + } + } + kmpExtension.targets.configureEach { target -> target.compilations.configureEach { compilation -> compilation.kotlinSourceSetsObservable.forAll { sourceSet: KotlinSourceSet -> @@ -161,10 +178,6 @@ open class MultiplatformResourcesPlugin : Plugin { it.resourcesPackageName } ) - //TODO: Realize Apple setup: now crashed -// setupFrameworkResources(compilation = compilation) -// setupTestsResources(compilation = compilation) -// setupFatFrameworkTasks(compilation = compilation) } } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt index 0e0176f62..6a071286c 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt @@ -98,7 +98,7 @@ abstract class AssetsGenerator( assetsGenerationDir: File, resourcesGenerationDir: File, objectBuilder: TypeSpec.Builder, - ): TypeSpec { + ): TypeSpec? { val rootContent = parseRootContent(fileTree.files) beforeGenerate(objectBuilder, rootContent) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt index cf9d0e124..f99660fe7 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt @@ -28,7 +28,7 @@ abstract class BaseGenerator : MRGenerator.Generator { assetsGenerationDir: File, resourcesGenerationDir: File, objectBuilder: TypeSpec.Builder, - ): TypeSpec { + ): TypeSpec? { // Read previous languages map from metadata // if target object is expect object or interface return emptyMap() val previousLanguagesMap: Map> = getPreviousLanguagesMap( @@ -55,7 +55,7 @@ abstract class BaseGenerator : MRGenerator.Generator { beforeGenerateResources(objectBuilder, languagesAllMaps) - val stringsClass: TypeSpec = createTypeSpec( + val stringsClass = createTypeSpec( project, inputMetadata = inputMetadata, generatedObjects = generatedObjects, @@ -80,10 +80,12 @@ abstract class BaseGenerator : MRGenerator.Generator { keys: List, languageMap: Map>, objectBuilder: TypeSpec.Builder, - ): TypeSpec { - objectBuilder.addModifiers(*getClassModifiers()) + ): TypeSpec? { + if (targetObject.isActual) { + objectBuilder.addModifiers(*getClassModifiers()) + } - if (targetObject.isActualObject) { + if (targetObject.isActualObject || targetObject.isTargetObject) { extendObjectBodyAtStart(objectBuilder) } @@ -130,14 +132,18 @@ abstract class BaseGenerator : MRGenerator.Generator { project.logger.warn("generatedObjects actual: $targetObject \n + $generatedProperties") - if (generatedProperties.isNotEmpty()) { + + + return if (generatedProperties.isNotEmpty()) { // Add object in metadata with remove expect realisation generatedObjects.addActual( targetObject.copy(properties = generatedProperties) ) - } - return objectBuilder.build() + objectBuilder.build() + } else { + null + } } abstract fun getPropertyMetadata( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt index 86109263b..8b9d19cef 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt @@ -49,7 +49,7 @@ abstract class ColorsGenerator( assetsGenerationDir: File, resourcesGenerationDir: File, objectBuilder: TypeSpec.Builder, - ): TypeSpec { + ): TypeSpec? { objectBuilder.addModifiers(*getClassModifiers()) extendObjectBodyAtStart(objectBuilder) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt index 440c825da..2f4713b5f 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt @@ -39,7 +39,7 @@ abstract class FilesGenerator( assetsGenerationDir: File, resourcesGenerationDir: File, objectBuilder: TypeSpec.Builder, - ): TypeSpec { + ): TypeSpec? { val fileSpecs = inputFileTree.map { file -> FileSpec( key = processKey(file.nameWithoutExtension), diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt index 249177b64..338aa1bb5 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt @@ -42,7 +42,7 @@ abstract class FontsGenerator( assetsGenerationDir: File, resourcesGenerationDir: File, objectBuilder: TypeSpec.Builder, - ): TypeSpec { + ): TypeSpec? { val fontFiles = inputFileTree.map { FontFile( key = it.nameWithoutExtension, @@ -53,6 +53,7 @@ abstract class FontsGenerator( beforeGenerateResources(objectBuilder, fontFiles) val typeSpec = createTypeSpec(inputFileTree.sortedBy { it.name }, objectBuilder) generateResources(resourcesGenerationDir, fontFiles) + return typeSpec } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt index 087309aaf..2419f826d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt @@ -44,7 +44,7 @@ abstract class ImagesGenerator( assetsGenerationDir: File, resourcesGenerationDir: File, objectBuilder: TypeSpec.Builder, - ): TypeSpec { + ): TypeSpec? { val fileMap: Map> = inputFiles.groupBy { file -> // SVGs do not have scale suffixes, so we need to remove the extension first val key = file diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt index 5541f9877..764250738 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt @@ -11,7 +11,6 @@ import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.MRVisibility import dev.icerock.gradle.metadata.GeneratedObject import dev.icerock.gradle.metadata.GeneratorType -import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import org.gradle.api.Project import org.gradle.api.file.Directory import org.gradle.api.file.FileTree @@ -95,11 +94,16 @@ abstract class MRGenerator( assetsGenerationDir: File, resourcesGenerationDir: File, objectBuilder: TypeSpec.Builder, - ): TypeSpec + ): TypeSpec? fun getImports(): List } + data class GenerationResult( + val typeSpec: TypeSpec, + val hasResourceProperty: Boolean = false + ) + interface SourceSet { val name: String diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt index 86a180836..64a8318b5 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt @@ -12,10 +12,11 @@ import dev.icerock.gradle.metadata.GeneratorType import dev.icerock.gradle.metadata.Metadata.createOutputMetadata import dev.icerock.gradle.metadata.Metadata.readInputMetadata import dev.icerock.gradle.metadata.addActual -import dev.icerock.gradle.metadata.getActualInterfaces import dev.icerock.gradle.metadata.getExpectInterfaces +import dev.icerock.gradle.metadata.getGeneratorInterfaces import dev.icerock.gradle.metadata.getInterfaceName -import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask +import dev.icerock.gradle.metadata.isNotEmptyMetadata +import dev.icerock.gradle.metadata.resourcesIsEmpty import dev.icerock.gradle.toModifier import dev.icerock.gradle.utils.targetName import org.gradle.api.Project @@ -52,19 +53,24 @@ abstract class TargetMRGenerator( override fun generateFileSpec(): FileSpec? { val inputMetadata: MutableList = mutableListOf() - //Read list of generated resources on previous level + //Read list of generated resources on previous level's inputMetadata.addAll( readInputMetadata( inputMetadataFiles = settings.inputMetadataFiles ) ) - if ( - inputMetadata.isEmpty() - && settings.ownResourcesFileTree.files.none { - it.isFile - } - ) return null + // Check resources for generation: if lower resources is empty + // and own resources has no files - skip step + if (resourcesIsEmpty(inputMetadata, settings)) return null + + //TODO: Добавить обработку кейса, когда данные есть только в таргете, т.е. генерация MR объекта + // Если есть свои ресурсы, но нет нижестоящих - просто MR + // Если есть нижестоящие - actual MR + // [checked] Нет своих и нет нижестоящих - ничего не генерировать + + // If previous levels has resources, need generate actual objects + val needGenerateActual: Boolean = inputMetadata.isNotEmptyMetadata() val visibilityModifier: KModifier = settings.visibility.toModifier() @@ -79,14 +85,18 @@ abstract class TargetMRGenerator( @Suppress("SpreadOperator") val mrClassSpec = TypeSpec.objectBuilder(settings.className) // default: object MR - .addModifiers(KModifier.ACTUAL) .addModifiers(visibilityModifier) // public/internal + if (needGenerateActual) { + mrClassSpec.addModifiers(KModifier.ACTUAL) + } + // Add actual implementation of expect interfaces from previous levels if (inputMetadata.isNotEmpty()) { - generateActualInterface( + generateTargetInterfaces( inputMetadata = inputMetadata, visibilityModifier = settings.visibility.toModifier(), + generateActualObject = needGenerateActual, fileSpec = fileSpec ) @@ -94,33 +104,36 @@ abstract class TargetMRGenerator( val expectInterfaces = inputMetadata.getExpectInterfaces() expectInterfaces.forEach { expectInterface -> - val resourcesInterface: TypeSpec = + val actualInterfaceTypeSpec: TypeSpec = TypeSpec.interfaceBuilder(expectInterface.name) .addModifiers(visibilityModifier) .addModifiers(KModifier.ACTUAL) .build() + fileSpec.addType(actualInterfaceTypeSpec) inputMetadata.addActual( actualObject = expectInterface.copy(modifier = GeneratedObjectModifier.Actual) ) - - fileSpec.addType(resourcesInterface) } } val generatedActualObjects = mutableListOf() generators.forEach { generator: Generator -> - val builder: TypeSpec.Builder = TypeSpec + val objectBuilder: TypeSpec.Builder = TypeSpec .objectBuilder(generator.mrObjectName) .addModifiers(visibilityModifier) - .addSuperinterface(generator.resourceContainerClass.parameterizedBy(generator.resourceClassName)) + .addSuperinterface( + superinterface = generator.resourceContainerClass.parameterizedBy( + generator.resourceClassName + ) + ) // Implement to object expect interfaces from previous // levels of resources - inputMetadata.getActualInterfaces(generator.type) + inputMetadata.getGeneratorInterfaces(generator.type) .forEach { generatedObject: GeneratedObject -> - builder.addSuperinterface( + objectBuilder.addSuperinterface( ClassName( packageName = settings.packageName, generatedObject.name @@ -128,60 +141,69 @@ abstract class TargetMRGenerator( ) } - mrClassSpec.addType( - generator.generate( - project = project, - inputMetadata = inputMetadata, - generatedObjects = generatedActualObjects, - targetObject = GeneratedObject( + val generatedResourceObjectTypeSpec: TypeSpec? = generator.generate( + project = project, + inputMetadata = inputMetadata, + generatedObjects = generatedActualObjects, + targetObject = GeneratedObject( + generatorType = generator.type, + modifier = if (needGenerateActual) { + GeneratedObjectModifier.Actual + } else { + GeneratedObjectModifier.None + }, + type = GeneratedObjectType.Object, + name = generator.mrObjectName, + interfaces = getObjectInterfaces( generatorType = generator.type, - modifier = GeneratedObjectModifier.Actual, - type = GeneratedObjectType.Object, - name = generator.mrObjectName, - interfaces = getObjectInterfaces( - generatorType = generator.type, - objectName = generator.mrObjectName, - inputMetadata = inputMetadata - ) - ), - assetsGenerationDir = assetsGenerationDir, - resourcesGenerationDir = resourcesGenerationDir, - objectBuilder = builder, - ) + objectName = generator.mrObjectName, + inputMetadata = inputMetadata + ) + ), + assetsGenerationDir = assetsGenerationDir, + resourcesGenerationDir = resourcesGenerationDir, + objectBuilder = objectBuilder, ) - } - inputMetadata.addActual( - actualObject = GeneratedObject( - generatorType = GeneratorType.None, - type = GeneratedObjectType.Object, - name = settings.className, - modifier = GeneratedObjectModifier.Actual, - objects = generatedActualObjects - ) - ) + if (generatedResourceObjectTypeSpec != null) { + mrClassSpec.addType(generatedResourceObjectTypeSpec) + } + } processMRClass(mrClassSpec) - val mrClass = mrClassSpec.build() - fileSpec.addType(mrClass) + if (generatedActualObjects.isNotEmpty()){ + val mrClass = mrClassSpec.build() + fileSpec.addType(mrClass) - createOutputMetadata( - outputMetadataFile = settings.outputMetadataFile, - generatedObjects = inputMetadata - ) + inputMetadata.addActual( + actualObject = GeneratedObject( + generatorType = GeneratorType.None, + type = GeneratedObjectType.Object, + name = settings.className, + modifier = GeneratedObjectModifier.Actual, + objects = generatedActualObjects + ) + ) + } generators .flatMap { it.getImports() } .plus(getImports()) .forEach { fileSpec.addImport(it.packageName, it.simpleName) } + createOutputMetadata( + outputMetadataFile = settings.outputMetadataFile, + generatedObjects = inputMetadata + ) + return fileSpec.build() } - private fun generateActualInterface( + private fun generateTargetInterfaces( inputMetadata: MutableList, visibilityModifier: KModifier, + generateActualObject: Boolean, fileSpec: FileSpec.Builder, ) { if (settings.ownResourcesFileTree.files.isEmpty()) return @@ -192,20 +214,24 @@ abstract class TargetMRGenerator( generators.forEach { generator -> val interfaceName = getInterfaceName( targetName = targetName, - generator = generator + generatorType = generator.type ) val resourcesInterfaceBuilder: TypeSpec.Builder = TypeSpec.interfaceBuilder(interfaceName) .addModifiers(visibilityModifier) - val generatedResources: TypeSpec = generator.generate( + val generatedResourcesTypeSpec: TypeSpec? = generator.generate( project = project, inputMetadata = inputMetadata, generatedObjects = inputMetadata, targetObject = GeneratedObject( generatorType = generator.type, - modifier = GeneratedObjectModifier.Actual, + modifier = if (generateActualObject) { + GeneratedObjectModifier.Actual + } else { + GeneratedObjectModifier.None + }, type = GeneratedObjectType.Interface, name = interfaceName ), @@ -214,8 +240,8 @@ abstract class TargetMRGenerator( objectBuilder = resourcesInterfaceBuilder ) - if (generatedResources.propertySpecs.isNotEmpty()) { - fileSpec.addType(generatedResources) + if (generatedResourcesTypeSpec != null) { + fileSpec.addType(generatedResourcesTypeSpec) } } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt index f27038eba..a7137833a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt @@ -13,6 +13,7 @@ import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.TargetMRGenerator import dev.icerock.gradle.utils.calculateResourcesHash import org.gradle.api.Project +import java.io.File @Suppress("TooManyFunctions") class AppleMRGenerator( @@ -24,6 +25,8 @@ class AppleMRGenerator( settings = settings, generators = generators ) { + override val resourcesGenerationDir: File = settings.resourcesDir.asFile + private val bundleClassName = ClassName("platform.Foundation", "NSBundle") private val bundleIdentifier = "${settings.packageName}.MR" diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/SetupAppleUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/SetupAppleUtils.kt index a606d010f..45be9f40a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/SetupAppleUtils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/SetupAppleUtils.kt @@ -1,5 +1,6 @@ package dev.icerock.gradle.generator.apple +import com.android.build.gradle.internal.tasks.factory.dependsOn import dev.icerock.gradle.MultiplatformResourcesPluginExtension import dev.icerock.gradle.generator.apple.action.CopyResourcesFromKLibsToExecutableAction import dev.icerock.gradle.generator.apple.action.CopyResourcesFromKLibsToFrameworkAction @@ -22,7 +23,6 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask import org.jetbrains.kotlin.gradle.tasks.FrameworkDescriptor import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile -import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink import java.io.File import kotlin.reflect.full.memberProperties @@ -61,33 +61,34 @@ fun setupFrameworkResources(compilation: KotlinNativeCompilation) { framework.linkTaskProvider.configure { linkTask -> linkTask.doLast(CopyResourcesFromKLibsToFrameworkAction()) - if (framework.isStatic) { - val project: Project = linkTask.project - val resourcesExtension: MultiplatformResourcesPluginExtension = - project.extensions.getByType() - if (resourcesExtension.staticFrameworkWarningEnabled.get()) { - project.logger.warn( - """ -$linkTask produces static framework, Xcode should have Build Phase with copyFrameworkResourcesToApp gradle task call. Please read readme on https://github.com/icerockdev/moko-resources + } + + if (framework.isStatic) { + val project: Project = framework.project + val resourcesExtension: MultiplatformResourcesPluginExtension = + project.extensions.getByType() + if (resourcesExtension.staticFrameworkWarningEnabled.get()) { + project.logger.warn( + """ +${framework.linkTaskName} produces static framework, Xcode should have Build Phase with copyFrameworkResourcesToApp gradle task call. Please read readme on https://github.com/icerockdev/moko-resources """ - ) - } - createCopyFrameworkResourcesTask(linkTask) + ) } + createCopyFrameworkResourcesTask(framework) } } } -fun createCopyFrameworkResourcesTask(linkTask: KotlinNativeLink) { - val framework = linkTask.binary as Framework - val project = linkTask.project - val taskName = linkTask.name.replace("link", "copyResources") +fun createCopyFrameworkResourcesTask(framework: Framework) { + val project = framework.project + val taskName = framework.linkTaskName.replace("link", "copyResources") - val copyTask = project.tasks.create(taskName, CopyFrameworkResourcesToAppTask::class.java) { + val copyTask = project.tasks.register(taskName, CopyFrameworkResourcesToAppTask::class.java) { it.framework = framework } - copyTask.dependsOn(linkTask) + copyTask.dependsOn(framework.linkTaskProvider) + //TODO: Вынести в отдельную таску, должно создаваться один раз val xcodeTask = project.tasks.maybeCreate( "copyFrameworkResourcesToApp", CopyFrameworkResourcesToAppEntryPointTask::class.java @@ -106,7 +107,7 @@ fun createCopyFrameworkResourcesTask(linkTask: KotlinNativeLink) { } fun setupTestsResources(compilation: KotlinNativeCompilation) { - compilation.target.binaries.withType().configureEach {executable -> + compilation.target.binaries.withType().configureEach { executable -> executable.linkTaskProvider.configure { link -> link.doLast(CopyResourcesFromKLibsToExecutableAction()) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index b6df1fb03..49c430897 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -17,17 +17,15 @@ import dev.icerock.gradle.metadata.GeneratedObject import dev.icerock.gradle.metadata.GeneratedObjectModifier import dev.icerock.gradle.metadata.GeneratedObjectType import dev.icerock.gradle.metadata.GeneratorType -import dev.icerock.gradle.metadata.GeneratorType.None import dev.icerock.gradle.metadata.Metadata.createOutputMetadata import dev.icerock.gradle.metadata.Metadata.readInputMetadata +import dev.icerock.gradle.metadata.addActual import dev.icerock.gradle.metadata.getInterfaceName -import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask +import dev.icerock.gradle.metadata.resourcesIsEmpty import dev.icerock.gradle.toModifier import dev.icerock.gradle.utils.targetName import org.gradle.api.Project import org.gradle.api.file.FileTree -import org.gradle.kotlin.dsl.withType -import org.jetbrains.kotlin.gradle.dsl.KotlinCompile class CommonMRGenerator( private val project: Project, @@ -62,12 +60,10 @@ class CommonMRGenerator( // } override fun generateFileSpec(): FileSpec? { -// if (settings.ownResourcesFileTree.files.isEmpty()) return null - val inputMetadata: MutableList = mutableListOf() //Read list of generated resources on previous level - if (settings.lowerResourcesFileTree.files.isNotEmpty()) { + if (settings.lowerResourcesFileTree.files.any { it.isFile }) { inputMetadata.addAll( readInputMetadata( inputMetadataFiles = settings.inputMetadataFiles @@ -75,6 +71,10 @@ class CommonMRGenerator( ) } + // If previous level's doesn't has resources for generation + // and target resource has no files - skip step + if (resourcesIsEmpty(inputMetadata, settings)) return null + val fileSpec: Builder = FileSpec.builder( packageName = settings.packageName, fileName = settings.className @@ -83,9 +83,9 @@ class CommonMRGenerator( val visibilityModifier: KModifier = settings.visibility.toModifier() val generatedObjects = mutableListOf() - if (settings.lowerResourcesFileTree.files.isEmpty()) { + if (settings.lowerResourcesFileTree.files.none { it.isFile }) { // When lower resources is empty, should generate expect MR object - generateExpectMRObjectFileSpec( + generateExpectMRObjects( inputMetadata = inputMetadata, generatedObjects = generatedObjects, resourcePackage = settings.packageName, @@ -93,6 +93,8 @@ class CommonMRGenerator( fileSpec = fileSpec ) } else { + generatedObjects.addAll(inputMetadata) + // If lower resources has files, when on lower level has expect object and // need to generate actual interface with fields generateActualInterfacesFileSpec( @@ -101,6 +103,11 @@ class CommonMRGenerator( inputMetadata = inputMetadata, fileSpec = fileSpec ) + + createOutputMetadata( + outputMetadataFile = settings.outputMetadataFile, + generatedObjects = generatedObjects + ) } generators @@ -110,15 +117,17 @@ class CommonMRGenerator( fileSpec.addImport(className.packageName, className.simpleName) } + createOutputMetadata( outputMetadataFile = settings.outputMetadataFile, generatedObjects = generatedObjects ) + project.logger.warn("OUTPUT METADATA: ${settings.outputMetadataFile}") return fileSpec.build() } - private fun generateExpectMRObjectFileSpec( + private fun generateExpectMRObjects( inputMetadata: MutableList, generatedObjects: MutableList, resourcePackage: String, @@ -157,7 +166,7 @@ class CommonMRGenerator( ) } - val generatedResourcesTypeSpec = generator.generate( + val generatedResourcesTypeSpec: TypeSpec? = generator.generate( project = project, inputMetadata = inputMetadata, generatedObjects = generatedExpectObjects, @@ -173,24 +182,29 @@ class CommonMRGenerator( objectBuilder = builder ) - mrClassSpec.addType(generatedResourcesTypeSpec) + if (generatedResourcesTypeSpec != null) { + mrClassSpec.addType(generatedResourcesTypeSpec) + } } - // Add generated objects in MR - generatedObjects.add( - GeneratedObject( - generatorType = None, - type = GeneratedObjectType.Object, - name = settings.className, - modifier = GeneratedObjectModifier.Expect, - objects = generatedExpectObjects - ) - ) - processMRClass(mrClassSpec) - val mrClass: TypeSpec = mrClassSpec.build() - fileSpec.addType(mrClass) + //Create file only if generated expect objects has expect MR object + if (generatedExpectObjects.isNotEmpty()){ + val mrClass: TypeSpec = mrClassSpec.build() + fileSpec.addType(mrClass) + + // Metadata: Add generated objects in MR + generatedObjects.add( + GeneratedObject( + generatorType = GeneratorType.None, + type = GeneratedObjectType.Object, + name = settings.className, + modifier = GeneratedObjectModifier.Expect, + objects = generatedExpectObjects + ) + ) + } } private fun generateExpectInterfaces( @@ -202,11 +216,12 @@ class CommonMRGenerator( val expectInterfaces = mutableListOf() upperResourcesFileTree.forEach { - val generatorType: GeneratorType = if (it.path.matches(StringsGenerator.STRINGS_REGEX)) { - GeneratorType.Strings - } else if (it.path.matches(PluralsGenerator.PLURALS_REGEX)) { - GeneratorType.Plurals - } else return@forEach + val generatorType: GeneratorType = + if (it.path.matches(StringsGenerator.STRINGS_REGEX)) { + GeneratorType.Strings + } else if (it.path.matches(PluralsGenerator.PLURALS_REGEX)) { + GeneratorType.Plurals + } else return@forEach //TODO: Implement with generator // else if (it.path.matches(ColorsGenerator.COLORS_REGEX)) { // GeneratorType.Colors @@ -254,12 +269,13 @@ class CommonMRGenerator( visibilityModifier: KModifier, fileSpec: Builder, ) { - val targetName: String = settings.ownResourcesFileTree.files.first().targetName + val targetName: String = + settings.ownResourcesFileTree.files.firstOrNull()?.targetName ?: return generators.forEach { generator -> val interfaceName = getInterfaceName( targetName = targetName, - generator = generator + generatorType = generator.type ) val resourcesInterfaceBuilder: TypeSpec.Builder = @@ -267,7 +283,7 @@ class CommonMRGenerator( .addModifiers(visibilityModifier) .addModifiers(KModifier.ACTUAL) - val generatedResources: TypeSpec = generator.generate( + val generatedResourcesTypeSpec: TypeSpec? = generator.generate( project = project, targetObject = GeneratedObject( generatorType = generator.type, @@ -282,19 +298,26 @@ class CommonMRGenerator( objectBuilder = resourcesInterfaceBuilder, ) - if (generatedResources.propertySpecs.isNotEmpty()){ - fileSpec.addType(generatedResources) + if (generatedResourcesTypeSpec != null) { + fileSpec.addType(generatedResourcesTypeSpec) } } + // Collect generated actual interfaces and replaced expect in metadata + val generatedActualInterfaces: MutableList = mutableListOf() + inputMetadata.forEach { metadata -> val hasInGeneratedActual = generatedObjects.firstOrNull { actualMetadata -> metadata.name == actualMetadata.name } != null if (!hasInGeneratedActual) { - generatedObjects.add(metadata) + generatedActualInterfaces.add(metadata) } } + + generatedActualInterfaces.forEach { actualInterface -> + inputMetadata.addActual(actualInterface) + } } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmPluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmPluralsGenerator.kt index 693de797d..884b07d78 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmPluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmPluralsGenerator.kt @@ -12,7 +12,7 @@ import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.ObjectBodyExtendable import dev.icerock.gradle.generator.PluralMap import dev.icerock.gradle.generator.PluralsGenerator -import dev.icerock.gradle.utils.remove +import dev.icerock.gradle.utils.flatName import org.gradle.api.file.FileTree import java.io.File @@ -23,7 +23,7 @@ class JvmPluralsGenerator( ) : PluralsGenerator(ownResourcesFileTree, strictLineBreaks), ObjectBodyExtendable by ClassLoaderExtender(settings.className) { - private val flattenClassPackage: String = settings.packageName.remove('.') + private val flattenClassPackage: String = settings.packageName.flatName override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt index 10a652b5a..68733a6f6 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt @@ -35,4 +35,10 @@ data class GeneratedObject( val isActualInterface: Boolean get() = isInterface && isActual + + val isTargetObject: Boolean + get() = isObject && modifier == GeneratedObjectModifier.None + + val isTargetInterface: Boolean + get() = isInterface && modifier == GeneratedObjectModifier.None } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt index b7eed4e9b..f16a56258 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt @@ -1,6 +1,6 @@ package dev.icerock.gradle.metadata -fun MutableList.addActual(actualObject: GeneratedObject){ +fun MutableList.addActual(actualObject: GeneratedObject) { val expect: GeneratedObject? = firstOrNull { it.name == actualObject.name && it.generatorType == actualObject.generatorType @@ -20,7 +20,29 @@ fun List.getExpectInterfaces(): List { fun List.getActualInterfaces(generatorType: GeneratorType): List { return filter { - it.isActualInterface && it.generatorType == generatorType + (it.isActualInterface || it.isTargetInterface) && it.generatorType == generatorType + } +} + +fun List.getGeneratorInterfaces(generatorType: GeneratorType): List { + return filter { + it.isInterface && it.generatorType == generatorType + } +} + +fun List.isEmptyMetadata(): Boolean { + if (this.isEmpty()) return true + + return this.none { it.isObject } +} + +fun List.isNotEmptyMetadata(): Boolean { + return !this.isEmptyMetadata() +} + +fun List.hasActualInterfacesOrExpectObject(): Boolean { + return this.any { + it.isActualInterface || it.isExpectObject } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Utils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Utils.kt index dbc0c2c06..2ea477c7f 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Utils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Utils.kt @@ -1,12 +1,16 @@ package dev.icerock.gradle.metadata -import dev.icerock.gradle.generator.MRGenerator.Generator +import dev.icerock.gradle.generator.MRGenerator.Settings import dev.icerock.gradle.utils.capitalize -internal fun getInterfaceName(targetName: String, generator: Generator): String { - return targetName.capitalize() + generator.mrObjectName.capitalize() -} - internal fun getInterfaceName(targetName: String, generatorType: GeneratorType): String { return targetName.capitalize() + generatorType.name.capitalize() } + +internal fun resourcesIsEmpty( + inputMetadata: MutableList, + settings: Settings, +): Boolean { + return inputMetadata.isEmptyMetadata() + && settings.ownResourcesFileTree.files.none { it.isFile } +} \ No newline at end of file diff --git a/samples/compose-resources-gallery/desktopApp/src/jvmMain/moko-resources/base/strings.xml b/samples/compose-resources-gallery/desktopApp/src/jvmMain/moko-resources/base/strings.xml new file mode 100644 index 000000000..31d10f0a5 --- /dev/null +++ b/samples/compose-resources-gallery/desktopApp/src/jvmMain/moko-resources/base/strings.xml @@ -0,0 +1,4 @@ + + + JVM, Hello World + diff --git a/samples/compose-resources-gallery/macosApp/src/commonMain/kotlin/Main.macos.kt b/samples/compose-resources-gallery/macosApp/src/commonMain/kotlin/Main.macos.kt index 8e19e8e6d..2a1c746aa 100644 --- a/samples/compose-resources-gallery/macosApp/src/commonMain/kotlin/Main.macos.kt +++ b/samples/compose-resources-gallery/macosApp/src/commonMain/kotlin/Main.macos.kt @@ -8,8 +8,9 @@ import platform.AppKit.NSApplicationActivationPolicy import platform.AppKit.NSApplicationDelegateProtocol import platform.darwin.NSObject import platform.objc.objc_setUncaughtExceptionHandler +import kotlin.experimental.ExperimentalNativeApi -@OptIn(ExperimentalForeignApi::class) +@OptIn(ExperimentalForeignApi::class, ExperimentalNativeApi::class) @Suppress("UNUSED_PARAMETER") fun main(args: Array) { setUnhandledExceptionHook { diff --git a/samples/compose-resources-gallery/shared/src/androidMain/kotlin/main.android.kt b/samples/compose-resources-gallery/shared/src/androidMain/kotlin/main.android.kt index d5723a238..fb7c38384 100644 --- a/samples/compose-resources-gallery/shared/src/androidMain/kotlin/main.android.kt +++ b/samples/compose-resources-gallery/shared/src/androidMain/kotlin/main.android.kt @@ -2,4 +2,4 @@ import androidx.compose.runtime.Composable actual fun getPlatformName(): String = "Android" -@Composable fun MainView() = App() +@Composable fun MainView() = App() \ No newline at end of file diff --git a/samples/compose-resources-gallery/shared/src/androidMain/moko-resources/images/car_white.svg b/samples/compose-resources-gallery/shared/src/androidMain/moko-resources/images/car_white.svg index 831b6e7f5..eb41b6115 100644 --- a/samples/compose-resources-gallery/shared/src/androidMain/moko-resources/images/car_white.svg +++ b/samples/compose-resources-gallery/shared/src/androidMain/moko-resources/images/car_white.svg @@ -9,13 +9,9 @@ - - - - + - + diff --git a/samples/compose-resources-gallery/webApp/build.gradle.kts b/samples/compose-resources-gallery/webApp/build.gradle.kts index 3e171f4af..8668d5d03 100644 --- a/samples/compose-resources-gallery/webApp/build.gradle.kts +++ b/samples/compose-resources-gallery/webApp/build.gradle.kts @@ -1,5 +1,3 @@ -import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension - plugins { kotlin("multiplatform") id("org.jetbrains.compose") From bd60350a4b15c55d7b20931f5a82b54d78d80937 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Mon, 18 Dec 2023 13:50:43 +0700 Subject: [PATCH 075/352] #535 fix apple target generation --- .../gradle/MultiplatformResourcesPlugin.kt | 36 ++++++++++--------- .../icerock/gradle/generator/BaseGenerator.kt | 6 +++- .../generator/apple/AppleMRGenerator.kt | 3 -- .../gradle/generator/apple/SetupAppleUtils.kt | 4 +-- .../apple/action/PackResourcesToKLibAction.kt | 8 +++++ 5 files changed, 35 insertions(+), 22 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 6f77567d2..655fc4e86 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -97,20 +97,6 @@ open class MultiplatformResourcesPlugin : Plugin { ) } - // If use configureEach, we get exception of task context in project, on configuration step - kmpExtension.targets.matching { - it.platformType == KotlinPlatformType.native - }.configureEach { target -> - target.compilations.configureEach { compilation -> - - compilation as KotlinNativeCompilation - - setupFrameworkResources(compilation = compilation) - setupTestsResources(compilation = compilation) - setupFatFrameworkTasks(compilation = compilation) - } - } - kmpExtension.targets.configureEach { target -> target.compilations.configureEach { compilation -> compilation.kotlinSourceSetsObservable.forAll { sourceSet: KotlinSourceSet -> @@ -141,6 +127,12 @@ open class MultiplatformResourcesPlugin : Plugin { compilation = compilation ) + // Setup apple specific tasks + setupAppleTasks( + target = target, + compilation = compilation + ) + compilation.compileTaskProvider.configure { compileTask: KotlinCompilationTask<*> -> compileTask.dependsOn(genTaskProvider) @@ -160,7 +152,6 @@ open class MultiplatformResourcesPlugin : Plugin { } if (target is KotlinNativeTarget) { - compilation as KotlinNativeCompilation compileTask as KotlinNativeCompile setupAppleKLibResources( @@ -278,7 +269,7 @@ open class MultiplatformResourcesPlugin : Plugin { target: KotlinTarget, sourceSet: KotlinSourceSet, genTaskProvider: TaskProvider, - compilation: KotlinCompilation<*> + compilation: KotlinCompilation<*>, ) { if (target !is KotlinAndroidTarget) return @@ -299,6 +290,19 @@ open class MultiplatformResourcesPlugin : Plugin { androidVariant.preBuildProvider.configure { it.dependsOn(genTaskProvider) } } + private fun setupAppleTasks( + target: KotlinTarget, + compilation: KotlinCompilation<*>, + ) { + if (target !is KotlinNativeTarget) return + + compilation as KotlinNativeCompilation + + setupFrameworkResources(compilation = compilation) + setupTestsResources(compilation = compilation) + setupFatFrameworkTasks(compilation = compilation) + } + private fun createMokoResourcesSourceSet( project: Project, kotlinSourceSet: KotlinSourceSet, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt index f99660fe7..8f6407cb8 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt @@ -66,7 +66,11 @@ abstract class BaseGenerator : MRGenerator.Generator { ) languagesAllMaps.forEach { (language: LanguageType, strings: Map) -> - generateResources(resourcesGenerationDir, language, strings) + generateResources( + resourcesGenerationDir = resourcesGenerationDir, + language = language, + strings = strings + ) } return stringsClass diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt index a7137833a..f27038eba 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt @@ -13,7 +13,6 @@ import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.TargetMRGenerator import dev.icerock.gradle.utils.calculateResourcesHash import org.gradle.api.Project -import java.io.File @Suppress("TooManyFunctions") class AppleMRGenerator( @@ -25,8 +24,6 @@ class AppleMRGenerator( settings = settings, generators = generators ) { - override val resourcesGenerationDir: File = settings.resourcesDir.asFile - private val bundleClassName = ClassName("platform.Foundation", "NSBundle") private val bundleIdentifier = "${settings.packageName}.MR" diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/SetupAppleUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/SetupAppleUtils.kt index 45be9f40a..7ebc5c5db 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/SetupAppleUtils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/SetupAppleUtils.kt @@ -33,14 +33,14 @@ fun setupAppleKLibResources( iosLocalizationRegion: Provider, resourcePackageName: Provider, ) { - compileTask.doLast { + compileTask.doLast ( PackResourcesToKLibAction( baseLocalizationRegion = iosLocalizationRegion, resourcePackageName = resourcePackageName, assetsDirectory = assetsDirectory, resourcesGenerationDir = resourcesGenerationDir, ) - } + ) // tasks like compileIosMainKotlinMetadata when only one target enabled // generationTask.project.tasks diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/PackResourcesToKLibAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/PackResourcesToKLibAction.kt index 75fe03d68..de026d746 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/PackResourcesToKLibAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/PackResourcesToKLibAction.kt @@ -30,6 +30,13 @@ internal class PackResourcesToKLibAction( val assetsDirectory: File = assetsDirectory.get() val resourcesGenerationDir: File = resourcesGenerationDir.get() + if (resourcesGenerationDir.exists().not() + || resourcesGenerationDir.listFiles()?.isEmpty() != false + ) { + task.logger.info("Resources not found. Skip klib repack action.") + return + } + task.logger.info("Adding resources to klib file `{}`", klibFile) unzipTo(zipFile = klibFile, outputDirectory = repackDir) @@ -45,6 +52,7 @@ internal class PackResourcesToKLibAction( developmentRegion = baseLocalizationRegion.get(), identifier = "${resourcePackageName.get()}.MR" ) + loadableBundle.write() val process: Process = Runtime.getRuntime().exec( From 810777875c16f590b360b872c0c139d2cac04e42 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Mon, 18 Dec 2023 20:49:44 +0700 Subject: [PATCH 076/352] #535 add color generator with metadata w/o AppleColorGenerator --- .../icerock/gradle/generator/BaseGenerator.kt | 55 -------- .../gradle/generator/ColorsGenerator.kt | 117 +++++++++++++++--- .../icerock/gradle/generator/MRGenerator.kt | 52 +++++++- .../android/AndroidColorsGenerator.kt | 15 ++- .../generator/apple/AppleColorsGenerator.kt | 8 +- .../generator/common/CommonColorsGenerator.kt | 2 - .../generator/common/CommonMRGenerator.kt | 10 +- .../gradle/generator/js/JsColorsGenerator.kt | 2 - .../generator/jvm/JvmColorsGenerator.kt | 4 - .../GenerateMultiplatformResourcesTask.kt | 3 +- 10 files changed, 168 insertions(+), 100 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt index 8f6407cb8..a0531c24b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt @@ -13,7 +13,6 @@ import dev.icerock.gradle.metadata.GeneratedObject import dev.icerock.gradle.metadata.GeneratedObjectModifier import dev.icerock.gradle.metadata.GeneratedProperties import dev.icerock.gradle.metadata.addActual -import dev.icerock.gradle.metadata.getActualInterfaces import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonObject import org.gradle.api.Project @@ -134,10 +133,6 @@ abstract class BaseGenerator : MRGenerator.Generator { extendObjectBodyAtEnd(objectBuilder) - project.logger.warn("generatedObjects actual: $targetObject \n + $generatedProperties") - - - return if (generatedProperties.isNotEmpty()) { // Add object in metadata with remove expect realisation generatedObjects.addActual( @@ -155,56 +150,6 @@ abstract class BaseGenerator : MRGenerator.Generator { languageMap: Map>, ): Map - private fun addActualOverrideModifier( - propertyName: String, - property: PropertySpec.Builder, - inputMetadata: List, - targetObject: GeneratedObject, - ): GeneratedObjectModifier { - // Read actual interfaces of target object generator type - val actualInterfaces: List = inputMetadata.getActualInterfaces( - generatorType = targetObject.generatorType - ) - - var containsInActualInterfaces = false - - // Search property in actual interfaces - actualInterfaces.forEach { genInterface -> - val hasInInterface = genInterface.properties.any { - it.name == propertyName - } - - if (hasInInterface) { - containsInActualInterfaces = true - } - } - - return if (targetObject.isObject) { - if (containsInActualInterfaces) { - property.addModifiers(KModifier.OVERRIDE) - GeneratedObjectModifier.Override - } else { - when (targetObject.modifier) { -// GeneratedObjectModifier.Expect -> { -// property.addModifiers(KModifier.EXPECT) -// GeneratedObjectModifier.Expect -// } - - GeneratedObjectModifier.Actual -> { - property.addModifiers(KModifier.ACTUAL) - GeneratedObjectModifier.Actual - } - - else -> { - GeneratedObjectModifier.None - } - } - } - } else { - GeneratedObjectModifier.None - } - } - abstract fun getLanguagesAllMaps( previousLanguageMaps: Map>, languageMap: Map> diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt index 8b9d19cef..eeabbaed0 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt @@ -15,7 +15,16 @@ import dev.icerock.gradle.generator.common.CommonColorsGenerator import dev.icerock.gradle.generator.js.JsColorsGenerator import dev.icerock.gradle.generator.jvm.JvmColorsGenerator import dev.icerock.gradle.metadata.GeneratedObject +import dev.icerock.gradle.metadata.GeneratedObjectModifier +import dev.icerock.gradle.metadata.GeneratedProperties import dev.icerock.gradle.metadata.GeneratorType +import dev.icerock.gradle.metadata.addActual +import dev.icerock.gradle.metadata.objectsWithProperties +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.decodeFromJsonElement +import kotlinx.serialization.json.encodeToJsonElement import org.gradle.api.Project import org.gradle.api.file.FileTree import org.w3c.dom.Node @@ -33,9 +42,6 @@ abstract class ColorsGenerator( ClassName("dev.icerock.moko.resources", "ColorResource") override val mrObjectName: String = "colors" - private val colorClassName = - ClassName("dev.icerock.moko.resources", "ColorResource") - override val type: GeneratorType = GeneratorType.Colors open fun beforeGenerate(objectBuilder: TypeSpec.Builder, keys: List) {} @@ -50,33 +56,104 @@ abstract class ColorsGenerator( resourcesGenerationDir: File, objectBuilder: TypeSpec.Builder, ): TypeSpec? { - objectBuilder.addModifiers(*getClassModifiers()) - extendObjectBodyAtStart(objectBuilder) + if (targetObject.isActual) { + objectBuilder.addModifiers(KModifier.ACTUAL) + } + + if (targetObject.isActualObject || targetObject.isTargetObject) { + extendObjectBodyAtStart(objectBuilder) + } + + // Read colors from previous levels, if target interface or expect + // return emptyList() + val previousColors: List = getPreviousColors( + inputMetadata = inputMetadata, + targetObject = targetObject + ) - val colors = parseColors() + // Read target colors + val targetColors: List = parseColors() + val allColors: List = (previousColors + targetColors).distinct() + val generatedProperties: MutableList = mutableListOf() + + beforeGenerate(objectBuilder, allColors.map { it.name }) + + val json = Json + + allColors.forEach { colorNode -> + val property = PropertySpec.builder(colorNode.name, resourceClassName) + + // Create metadata property + var generatedProperty = GeneratedProperties( + modifier = GeneratedObjectModifier.None, + name = colorNode.name, + data = json.encodeToJsonElement(colorNode) + ) + + if (targetObject.isObject) { + // Setup property modifier and correction metadata info + generatedProperty = generatedProperty.copy( + modifier = addActualOverrideModifier( + propertyName = colorNode.name, + property = property, + inputMetadata = inputMetadata, + targetObject = targetObject + ) + ) - beforeGenerate(objectBuilder, colors.map { it.name }) + getPropertyInitializer(colorNode)?.let { + property.initializer(it) + } + } - colors.forEach { colorNode -> - val property = PropertySpec.builder(colorNode.name, colorClassName) - property.addModifiers(*getPropertyModifiers()) - getPropertyInitializer(colorNode)?.let { property.initializer(it) } objectBuilder.addProperty(property.build()) + generatedProperties.add(generatedProperty) } - generateResources(resourcesGenerationDir, colors) - + generateResources(project, resourcesGenerationDir, allColors) extendObjectBodyAtEnd(objectBuilder) - return objectBuilder.build() + return if (generatedProperties.isNotEmpty()) { + generatedObjects.addActual( + targetObject.copy(properties = generatedProperties) + ) + + objectBuilder.build() + } else { + null + } + } + + private fun getPreviousColors( + inputMetadata: MutableList, + targetObject: GeneratedObject, + ): List { + if (!targetObject.isObject || !targetObject.isActual) return emptyList() + + val json = Json + val objectsWithProperties: List = inputMetadata.objectsWithProperties( + targetObject = targetObject + ) + + val colors = mutableListOf() + + objectsWithProperties.forEach { generatedObject -> + generatedObject.properties.forEach { property -> + val colorNode = json.decodeFromJsonElement(property.data) + + colors.add(colorNode) + } + } + + return colors } protected open fun getClassModifiers(): Array = emptyArray() - protected open fun getPropertyModifiers(): Array = emptyArray() abstract fun getPropertyInitializer(color: ColorNode): CodeBlock? protected open fun generateResources( + project: Project, resourcesGenerationDir: File, colors: List, ) = Unit @@ -145,21 +222,17 @@ abstract class ColorsGenerator( } class Feature( - val project: Project, private val settings: MRGenerator.Settings, ) : ResourceGeneratorFeature { override fun createCommonGenerator() = CommonColorsGenerator( - project = project, resourcesFileTree = settings.ownResourcesFileTree, ) override fun createAppleGenerator() = AppleColorsGenerator( - project = project, resourcesFileTree = settings.ownResourcesFileTree, ) override fun createAndroidGenerator() = AndroidColorsGenerator( - project = project, resourcesFileTree = settings.ownResourcesFileTree, ) @@ -168,7 +241,6 @@ abstract class ColorsGenerator( ) override fun createJvmGenerator() = JvmColorsGenerator( - project = project, resourcesFileTree = settings.ownResourcesFileTree, mrClassName = settings.className ) @@ -203,10 +275,15 @@ abstract class ColorsGenerator( } } +@Serializable data class ColorNode( + @SerialName("name") val name: String, + @SerialName("lightColor") val lightColor: String?, // as rgba + @SerialName("darkColor") val darkColor: String?, // as rgba + @SerialName("singleColor") val singleColor: String?, // as rgba ) { fun isThemed(): Boolean = lightColor != null && darkColor != null diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt index 764250738..5b4e82bd8 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt @@ -7,10 +7,13 @@ package dev.icerock.gradle.generator import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.FileSpec import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.MRVisibility import dev.icerock.gradle.metadata.GeneratedObject +import dev.icerock.gradle.metadata.GeneratedObjectModifier import dev.icerock.gradle.metadata.GeneratorType +import dev.icerock.gradle.metadata.getActualInterfaces import org.gradle.api.Project import org.gradle.api.file.Directory import org.gradle.api.file.FileTree @@ -97,12 +100,51 @@ abstract class MRGenerator( ): TypeSpec? fun getImports(): List - } - data class GenerationResult( - val typeSpec: TypeSpec, - val hasResourceProperty: Boolean = false - ) + fun addActualOverrideModifier( + propertyName: String, + property: PropertySpec.Builder, + inputMetadata: List, + targetObject: GeneratedObject, + ): GeneratedObjectModifier { + // Read actual interfaces of target object generator type + val actualInterfaces: List = inputMetadata.getActualInterfaces( + generatorType = targetObject.generatorType + ) + + var containsInActualInterfaces = false + + // Search property in actual interfaces + actualInterfaces.forEach { genInterface -> + val hasInInterface = genInterface.properties.any { + it.name == propertyName + } + + if (hasInInterface) { + containsInActualInterfaces = true + } + } + + return if (targetObject.isObject) { + if (containsInActualInterfaces) { + property.addModifiers(KModifier.OVERRIDE) + GeneratedObjectModifier.Override + } else { + when (targetObject.modifier) { + GeneratedObjectModifier.Actual -> { + property.addModifiers(KModifier.ACTUAL) + GeneratedObjectModifier.Actual + } + else -> { + GeneratedObjectModifier.None + } + } + } + } else { + GeneratedObjectModifier.None + } + } + } interface SourceSet { val name: String diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt index 4ab3df75a..9c22d3751 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt @@ -16,7 +16,6 @@ import org.gradle.api.file.FileTree import java.io.File class AndroidColorsGenerator( - project: Project, resourcesFileTree: FileTree, ) : ColorsGenerator(resourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { @@ -26,9 +25,11 @@ class AndroidColorsGenerator( override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun generateResources(resourcesGenerationDir: File, colors: List) { + override fun generateResources( + project: Project, + resourcesGenerationDir: File, + colors: List + ) { val valuesDir = File(resourcesGenerationDir, "values") val defaultStringsFile = File(valuesDir, COLORS_XML_FILE_NAME) valuesDir.mkdirs() @@ -48,6 +49,12 @@ class AndroidColorsGenerator( """.trimIndent() + project.logger.warn("ANDROID COLORS GENERATOR") + + colors.forEach { + project.logger.warn("ANDROID COLORS: value: $it") + } + val defaultContent = colors.joinToString("\n") { colorNode -> if (colorNode.isThemed()) { buildColorString(colorNode.name, replaceColorAlpha(colorNode.lightColor)) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt index 29b474cdb..6fe15e961 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt @@ -22,7 +22,6 @@ import org.gradle.api.file.FileTree import java.io.File class AppleColorsGenerator( - project: Project, resourcesFileTree: FileTree, ) : ColorsGenerator(resourcesFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { override fun getImports(): List { @@ -32,9 +31,12 @@ class AppleColorsGenerator( } override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - override fun generateResources(resourcesGenerationDir: File, colors: List) { + override fun generateResources( + project: Project, + resourcesGenerationDir: File, + colors: List + ) { val assetsDirectory = File(resourcesGenerationDir, ASSETS_DIR_NAME) colors.forEach { colorNode -> diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonColorsGenerator.kt index 831742a67..19524211e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonColorsGenerator.kt @@ -10,11 +10,9 @@ import dev.icerock.gradle.generator.ColorNode import dev.icerock.gradle.generator.ColorsGenerator import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable -import org.gradle.api.Project import org.gradle.api.file.FileTree class CommonColorsGenerator( - project: Project, resourcesFileTree: FileTree, ) : ColorsGenerator(resourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index 49c430897..cbeff8c14 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -10,6 +10,7 @@ import com.squareup.kotlinpoet.FileSpec.Builder import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.generator.ColorsGenerator import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.PluralsGenerator import dev.icerock.gradle.generator.StringsGenerator @@ -221,11 +222,12 @@ class CommonMRGenerator( GeneratorType.Strings } else if (it.path.matches(PluralsGenerator.PLURALS_REGEX)) { GeneratorType.Plurals - } else return@forEach + } else if (it.path.matches(ColorsGenerator.COLORS_REGEX)) { + GeneratorType.Colors + } else return@forEach + //TODO: Implement with generator -// else if (it.path.matches(ColorsGenerator.COLORS_REGEX)) { -// GeneratorType.Colors -// } else if (it.parentFile.name == "images") { +// else if (it.parentFile.name == "images") { // GeneratorType.Images // } else if (it.parentFile.name == "files") { // GeneratorType.Files diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsColorsGenerator.kt index 63103664b..d4eb657a6 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsColorsGenerator.kt @@ -23,8 +23,6 @@ class JsColorsGenerator( override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - override fun getImports() = listOf( ClassName("dev.icerock.moko.graphics", "Color") ) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmColorsGenerator.kt index 59e1e3ab8..fc7ac6746 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmColorsGenerator.kt @@ -11,11 +11,9 @@ import dev.icerock.gradle.generator.ColorNode import dev.icerock.gradle.generator.ColorsGenerator import dev.icerock.gradle.generator.ObjectBodyExtendable import dev.icerock.gradle.generator.jsJvmCommon.createColorResourceInitializer -import org.gradle.api.Project import org.gradle.api.file.FileTree class JvmColorsGenerator( - project: Project, resourcesFileTree: FileTree, mrClassName: String, ) : ColorsGenerator(resourcesFileTree), @@ -27,8 +25,6 @@ class JvmColorsGenerator( override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - override fun getPropertyInitializer(color: ColorNode): CodeBlock { return createColorResourceInitializer(color) } 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 8c74238d8..4aa20652d 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 @@ -6,6 +6,7 @@ package dev.icerock.gradle.tasks import dev.icerock.gradle.MRVisibility import dev.icerock.gradle.configuration.getAndroidRClassPackage +import dev.icerock.gradle.generator.ColorsGenerator import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.PluralsGenerator import dev.icerock.gradle.generator.ResourceGeneratorFeature @@ -159,10 +160,10 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { return listOf( StringsGenerator.Feature(settings), PluralsGenerator.Feature(settings), + ColorsGenerator.Feature(settings), // ImagesGenerator.Feature(settings, logger), // FontsGenerator.Feature(settings), // FilesGenerator.Feature(settings), -// ColorsGenerator.Feature(settings), // AssetsGenerator.Feature(settings) ) } From de2e6edb27fbcefa493bdeddb4e442c3174606b5 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Tue, 19 Dec 2023 13:17:09 +0700 Subject: [PATCH 077/352] #535 image generator, changed metadata property name --- .../icerock/gradle/generator/BaseGenerator.kt | 14 +- .../gradle/generator/ColorsGenerator.kt | 10 +- .../gradle/generator/ImagesGenerator.kt | 180 ++++++++++++++++-- .../gradle/generator/StringsGenerator.kt | 1 + .../generator/common/CommonMRGenerator.kt | 19 +- .../gradle/metadata/GeneratedObject.kt | 2 +- ...atedProperties.kt => GeneratedProperty.kt} | 2 +- .../GenerateMultiplatformResourcesTask.kt | 3 +- 8 files changed, 186 insertions(+), 45 deletions(-) rename resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/{GeneratedProperties.kt => GeneratedProperty.kt} (90%) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt index a0531c24b..8cf4e746f 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt @@ -11,7 +11,7 @@ import com.squareup.kotlinpoet.PropertySpec.Builder import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.metadata.GeneratedObject import dev.icerock.gradle.metadata.GeneratedObjectModifier -import dev.icerock.gradle.metadata.GeneratedProperties +import dev.icerock.gradle.metadata.GeneratedProperty import dev.icerock.gradle.metadata.addActual import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonObject @@ -39,7 +39,7 @@ abstract class BaseGenerator : MRGenerator.Generator { // If target object is actual object: skip read files again // // Structure: language - key - value - val languageMap: Map> = if (targetObject.isActualObject) { + val languageMap: Map> = if (targetObject.isActualObject || targetObject.isTargetObject) { emptyMap() } else { loadLanguageMap() @@ -55,7 +55,6 @@ abstract class BaseGenerator : MRGenerator.Generator { beforeGenerateResources(objectBuilder, languagesAllMaps) val stringsClass = createTypeSpec( - project, inputMetadata = inputMetadata, generatedObjects = generatedObjects, targetObject = targetObject, @@ -76,7 +75,6 @@ abstract class BaseGenerator : MRGenerator.Generator { } private fun createTypeSpec( - project: Project, inputMetadata: MutableList, generatedObjects: MutableList, targetObject: GeneratedObject, @@ -85,20 +83,20 @@ abstract class BaseGenerator : MRGenerator.Generator { objectBuilder: TypeSpec.Builder, ): TypeSpec? { if (targetObject.isActual) { - objectBuilder.addModifiers(*getClassModifiers()) + objectBuilder.addModifiers(KModifier.ACTUAL) } if (targetObject.isActualObject || targetObject.isTargetObject) { extendObjectBodyAtStart(objectBuilder) } - val generatedProperties = mutableListOf() + val generatedProperties = mutableListOf() keys.forEach { key -> val name = key.replace(".", "_") //Create metadata property - var generatedProperty = GeneratedProperties( + var generatedProperty = GeneratedProperty( modifier = GeneratedObjectModifier.None, name = name, data = JsonObject( @@ -111,7 +109,7 @@ abstract class BaseGenerator : MRGenerator.Generator { val property: Builder = PropertySpec.builder(name, resourceClassName) - if (targetObject.isObject) { + if (targetObject.isActualObject || targetObject.isTargetObject) { // Add modifier for property and setup metadata generatedProperty = generatedProperty.copy( modifier = addActualOverrideModifier( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt index eeabbaed0..cb6f13a6e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt @@ -16,7 +16,7 @@ import dev.icerock.gradle.generator.js.JsColorsGenerator import dev.icerock.gradle.generator.jvm.JvmColorsGenerator import dev.icerock.gradle.metadata.GeneratedObject import dev.icerock.gradle.metadata.GeneratedObjectModifier -import dev.icerock.gradle.metadata.GeneratedProperties +import dev.icerock.gradle.metadata.GeneratedProperty import dev.icerock.gradle.metadata.GeneratorType import dev.icerock.gradle.metadata.addActual import dev.icerock.gradle.metadata.objectsWithProperties @@ -44,7 +44,7 @@ abstract class ColorsGenerator( override val type: GeneratorType = GeneratorType.Colors - open fun beforeGenerate(objectBuilder: TypeSpec.Builder, keys: List) {} + open fun beforeGenerate(objectBuilder: TypeSpec.Builder, keys: List) = Unit @Suppress("SpreadOperator") override fun generate( @@ -74,7 +74,7 @@ abstract class ColorsGenerator( // Read target colors val targetColors: List = parseColors() val allColors: List = (previousColors + targetColors).distinct() - val generatedProperties: MutableList = mutableListOf() + val generatedProperties: MutableList = mutableListOf() beforeGenerate(objectBuilder, allColors.map { it.name }) @@ -84,13 +84,13 @@ abstract class ColorsGenerator( val property = PropertySpec.builder(colorNode.name, resourceClassName) // Create metadata property - var generatedProperty = GeneratedProperties( + var generatedProperty = GeneratedProperty( modifier = GeneratedObjectModifier.None, name = colorNode.name, data = json.encodeToJsonElement(colorNode) ) - if (targetObject.isObject) { + if (targetObject.isActualObject || targetObject.isTargetObject) { // Setup property modifier and correction metadata info generatedProperty = generatedProperty.copy( modifier = addActualOverrideModifier( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt index 2419f826d..dfef4437e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt @@ -15,15 +15,24 @@ import dev.icerock.gradle.generator.common.CommonImagesGenerator import dev.icerock.gradle.generator.js.JsImagesGenerator import dev.icerock.gradle.generator.jvm.JvmImagesGenerator import dev.icerock.gradle.metadata.GeneratedObject +import dev.icerock.gradle.metadata.GeneratedObjectModifier +import dev.icerock.gradle.metadata.GeneratedProperty import dev.icerock.gradle.metadata.GeneratorType +import dev.icerock.gradle.metadata.addActual +import dev.icerock.gradle.metadata.objectsWithProperties import dev.icerock.gradle.utils.withoutScale +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.JsonPrimitive +import kotlinx.serialization.json.decodeFromJsonElement import org.gradle.api.Project import org.gradle.api.file.FileTree import org.gradle.api.logging.Logger import java.io.File abstract class ImagesGenerator( - private val resourcesFileTree: FileTree + private val resourcesFileTree: FileTree, ) : MRGenerator.Generator { override val inputFiles: Iterable @@ -45,22 +54,36 @@ abstract class ImagesGenerator( resourcesGenerationDir: File, objectBuilder: TypeSpec.Builder, ): TypeSpec? { - val fileMap: Map> = inputFiles.groupBy { file -> - // SVGs do not have scale suffixes, so we need to remove the extension first - val key = file - .nameWithoutExtension - .withoutScale + val previousFilesMap: Map> = getPreviousImageFilesMap( + inputMetadata = inputMetadata, + targetObject = targetObject + ) - "$key.${file.extension}" + val imageFileMap: Map> = if ( + targetObject.isActualObject || targetObject.isTargetObject + ) { + emptyMap() + } else { + inputFiles.getImageMap() } - beforeGenerateResources(objectBuilder, fileMap.keys.sorted()) - val typeSpec = createTypeSpec(fileMap.keys.sorted(), objectBuilder) + val allImagesMap: Map> = getAllImagesMap(previousFilesMap, imageFileMap) + + beforeGenerateResources(objectBuilder, allImagesMap.keys.sorted()) + + val typeSpec: TypeSpec? = createTypeSpec( + inputMetadata = inputMetadata, + generatedObjects = generatedObjects, + targetObject = targetObject, + fileNames = allImagesMap.keys.sorted(), + allImagesMap = allImagesMap, + objectBuilder = objectBuilder + ) generateResources( resourcesGenerationDir = resourcesGenerationDir, - keyFileMap = fileMap.mapKeys { (key, _) -> + keyFileMap = allImagesMap.mapKeys { (key, _) -> key.substringBeforeLast(".") // Remove file extension from keys } ) @@ -68,39 +91,154 @@ abstract class ImagesGenerator( return typeSpec } - @Suppress("SpreadOperator") - private fun createTypeSpec(fileNames: List, objectBuilder: TypeSpec.Builder): TypeSpec { - objectBuilder.addModifiers(*getClassModifiers()) + private fun createTypeSpec( + inputMetadata: MutableList, + generatedObjects: MutableList, + targetObject: GeneratedObject, + fileNames: List, + allImagesMap: Map>, + objectBuilder: TypeSpec.Builder, + ): TypeSpec? { + if (targetObject.isActual) { + objectBuilder.addModifiers(KModifier.ACTUAL) + } + + if (targetObject.isActualObject || targetObject.isTargetObject) { + extendObjectBodyAtStart(objectBuilder) + } - extendObjectBodyAtStart(objectBuilder) + val generatedProperties = mutableListOf() - fileNames.forEach { fileName -> + fileNames.forEach { fileName: String -> val updatedFileName = fileName.substringBeforeLast(".") .replace(".", "_") + ".${fileName.substringAfterLast(".")}" val propertyName = updatedFileName.substringBeforeLast(".") val property = PropertySpec.builder(propertyName, resourceClassName) - property.addModifiers(*getPropertyModifiers()) - getPropertyInitializer(updatedFileName)?.let { property.initializer(it) } + var generatedProperty = GeneratedProperty( + modifier = GeneratedObjectModifier.None, + name = propertyName, + data = JsonObject( + content = getPropertyMetadata( + fileName = fileName, + allImagesMap = allImagesMap + ) + ) + ) + + if (targetObject.isActualObject || targetObject.isTargetObject) { + // Add modifier for property and setup metadata + generatedProperty = generatedProperty.copy( + modifier = addActualOverrideModifier( + propertyName = propertyName, + property = property, + inputMetadata = inputMetadata, + targetObject = targetObject + ) + ) + + getPropertyInitializer(updatedFileName)?.let { + property.initializer(it) + } + } + objectBuilder.addProperty(property.build()) + generatedProperties.add(generatedProperty) } extendObjectBodyAtEnd(objectBuilder) - return objectBuilder.build() + return if (generatedProperties.isNotEmpty()) { + // Add object in metadata with remove expect realisation + generatedObjects.addActual( + targetObject.copy(properties = generatedProperties) + ) + + objectBuilder.build() + } else { + null + } + } + + private fun getPropertyMetadata( + fileName: String, + allImagesMap: Map>, + ): Map { + //Structure: FileName, Path + val resultMap = mutableMapOf() + + allImagesMap[fileName]?.forEach { + resultMap[it.name] = JsonPrimitive(it.path) + } + + return resultMap + } + + private fun getPreviousImageFilesMap( + inputMetadata: List, + targetObject: GeneratedObject, + ): Map> { + if (!targetObject.isObject || !targetObject.isActual) return emptyMap() + + val json = Json + val objectsWithProperties: List = inputMetadata.objectsWithProperties( + targetObject = targetObject + ) + + val fileImage = mutableListOf() + + objectsWithProperties.forEach { generatedObject -> + generatedObject.properties.forEach { property -> + val data = json.decodeFromJsonElement>(property.data) + + data.forEach { + fileImage.add(File(it.value.content)) + } + } + } + + return fileImage.getImageMap() + } + + private fun Iterable.getImageMap(): Map> { + return this.groupBy { file -> + // SVGs do not have scale suffixes, so we need to remove the extension first + val key = file + .nameWithoutExtension + .withoutScale + + "$key.${file.extension}" + } + } + + private fun getAllImagesMap( + previousFilesMap: Map>, + imageFileMap: Map>, + ): Map> { + val resultMap = mutableMapOf>() + + previousFilesMap.forEach { map -> + resultMap[map.key] = map.value + } + + imageFileMap.forEach { map -> + resultMap[map.key] = map.value + } + + return resultMap } override fun getImports(): List = emptyList() protected open fun beforeGenerateResources( objectBuilder: TypeSpec.Builder, - keys: List + keys: List, ) { } protected open fun generateResources( resourcesGenerationDir: File, - keyFileMap: Map> + keyFileMap: Map>, ) { } @@ -112,7 +250,7 @@ abstract class ImagesGenerator( class Feature( private val settings: MRGenerator.Settings, - private val logger: Logger + private val logger: Logger, ) : ResourceGeneratorFeature { override fun createCommonGenerator(): ImagesGenerator = CommonImagesGenerator( ownInputFileTree = settings.ownResourcesFileTree, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt index 4f3e5debe..874697d4b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt @@ -63,6 +63,7 @@ abstract class StringsGenerator( targetObject: GeneratedObject, ): Map> { if (!targetObject.isObject || !targetObject.isActual) return emptyMap() + val json = Json val objectsWithProperties: List = inputMetadata.objectsWithProperties(targetObject) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index cbeff8c14..9f8f772a6 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -191,7 +191,7 @@ class CommonMRGenerator( processMRClass(mrClassSpec) //Create file only if generated expect objects has expect MR object - if (generatedExpectObjects.isNotEmpty()){ + if (generatedExpectObjects.isNotEmpty()) { val mrClass: TypeSpec = mrClassSpec.build() fileSpec.addType(mrClass) @@ -220,16 +220,19 @@ class CommonMRGenerator( val generatorType: GeneratorType = if (it.path.matches(StringsGenerator.STRINGS_REGEX)) { GeneratorType.Strings - } else if (it.path.matches(PluralsGenerator.PLURALS_REGEX)) { + } + else if (it.path.matches(PluralsGenerator.PLURALS_REGEX)) { GeneratorType.Plurals - } else if (it.path.matches(ColorsGenerator.COLORS_REGEX)) { - GeneratorType.Colors - } else return@forEach + } + else if (it.path.matches(ColorsGenerator.COLORS_REGEX)) { + GeneratorType.Colors + } + else if (it.parentFile.name == "images") { + GeneratorType.Images + } else return@forEach //TODO: Implement with generator -// else if (it.parentFile.name == "images") { -// GeneratorType.Images -// } else if (it.parentFile.name == "files") { +// else if (it.parentFile.name == "files") { // GeneratorType.Files // } else if (it.parentFile.name == "assets") { // GeneratorType.Assets diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt index 68733a6f6..f36adb48d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt @@ -9,7 +9,7 @@ data class GeneratedObject( val type: GeneratedObjectType, val name: String, val interfaces: List = emptyList(), - val properties: List = emptyList(), + val properties: List = emptyList(), val objects: List = emptyList() ) { val isExpect: Boolean diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperties.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperty.kt similarity index 90% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperties.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperty.kt index a2d2ad3b0..2968f6f58 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperties.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperty.kt @@ -4,7 +4,7 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.json.JsonElement @Serializable -data class GeneratedProperties( +data class GeneratedProperty( val modifier: GeneratedObjectModifier, val name: String, val data: JsonElement // Can contain data with dependencies from generator type 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 4aa20652d..251e1d18e 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 @@ -7,6 +7,7 @@ package dev.icerock.gradle.tasks import dev.icerock.gradle.MRVisibility import dev.icerock.gradle.configuration.getAndroidRClassPackage import dev.icerock.gradle.generator.ColorsGenerator +import dev.icerock.gradle.generator.ImagesGenerator import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.PluralsGenerator import dev.icerock.gradle.generator.ResourceGeneratorFeature @@ -161,7 +162,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { StringsGenerator.Feature(settings), PluralsGenerator.Feature(settings), ColorsGenerator.Feature(settings), -// ImagesGenerator.Feature(settings, logger), + ImagesGenerator.Feature(settings, logger), // FontsGenerator.Feature(settings), // FilesGenerator.Feature(settings), // AssetsGenerator.Feature(settings) From 0a6cdd41587233bcc2169d4a07768a9a7027ba3e Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Tue, 19 Dec 2023 15:43:08 +0700 Subject: [PATCH 078/352] #535 add files generator --- .../gradle/generator/FilesGenerator.kt | 148 +++++++++++++++--- .../generator/apple/AppleFilesGenerator.kt | 2 +- .../generator/common/CommonMRGenerator.kt | 16 +- .../gradle/generator/js/JsFilesGenerator.kt | 2 +- .../GenerateMultiplatformResourcesTask.kt | 3 +- 5 files changed, 134 insertions(+), 37 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt index 2f4713b5f..84991a7e6 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt @@ -15,17 +15,24 @@ import dev.icerock.gradle.generator.common.CommonFilesGenerator import dev.icerock.gradle.generator.js.JsFilesGenerator import dev.icerock.gradle.generator.jvm.JvmFilesGenerator import dev.icerock.gradle.metadata.GeneratedObject +import dev.icerock.gradle.metadata.GeneratedObjectModifier +import dev.icerock.gradle.metadata.GeneratedProperty import dev.icerock.gradle.metadata.GeneratorType +import dev.icerock.gradle.metadata.addActual +import dev.icerock.gradle.metadata.objectsWithProperties +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonPrimitive +import kotlinx.serialization.json.decodeFromJsonElement import org.gradle.api.Project import org.gradle.api.file.FileTree import java.io.File abstract class FilesGenerator( - private val inputFileTree: FileTree, + private val resourceFiles: FileTree, ) : MRGenerator.Generator { override val inputFiles: Iterable - get() = inputFileTree.matching { it.include("files/**") } + get() = resourceFiles.matching { it.include("files/**") } override val resourceClassName = ClassName("dev.icerock.moko.resources", "FileResource") override val mrObjectName: String = "files" @@ -40,43 +47,135 @@ abstract class FilesGenerator( resourcesGenerationDir: File, objectBuilder: TypeSpec.Builder, ): TypeSpec? { - val fileSpecs = inputFileTree.map { file -> + val previousFilesSpec: List = getPreviousFiles( + inputMetadata = inputMetadata, + targetObject = targetObject + ) + + val targetFilesSpecs: List = if ( + targetObject.isActualObject || targetObject.isTargetObject + ) { + emptyList() + } else { + inputFiles.getFileSpecList() + } + + val allFilesSpecs = (previousFilesSpec + targetFilesSpecs).distinctBy { it.key } + + beforeGenerate(objectBuilder, allFilesSpecs) + + val typeSpec: TypeSpec? = createTypeSpec( + inputMetadata = inputMetadata, + generatedObjects = generatedObjects, + targetObject = targetObject, + keys = allFilesSpecs, + objectBuilder = objectBuilder + ) + + generateResources( + resourcesGenerationDir = resourcesGenerationDir, + files = allFilesSpecs + ) + + return typeSpec + } + + private fun Iterable.getFileSpecList(): List { + return this.map { file -> FileSpec( key = processKey(file.nameWithoutExtension), file = file ) }.sortedBy { it.key } - beforeGenerate(objectBuilder, fileSpecs) - val typeSpec = createTypeSpec(fileSpecs, objectBuilder) - generateResources(resourcesGenerationDir, fileSpecs) - return typeSpec } - private fun createTypeSpec(keys: List, objectBuilder: TypeSpec.Builder): TypeSpec { - @Suppress("SpreadOperator") - objectBuilder.addModifiers(*getClassModifiers()) + private fun getPreviousFiles( + inputMetadata: List, + targetObject: GeneratedObject, + ): List { + if (!targetObject.isObject || !targetObject.isActual) return emptyList() - extendObjectBodyAtStart(objectBuilder) + val json = Json + val objectsWithProperties: List = inputMetadata.objectsWithProperties( + targetObject = targetObject + ) - keys.forEach { objectBuilder.addProperty(generateFileProperty(it)) } - extendObjectBodyAtEnd(objectBuilder) - return objectBuilder.build() + val files = mutableListOf() + + objectsWithProperties.forEach { generatedObject -> + generatedObject.properties.forEach { property -> + val data = json.decodeFromJsonElement(property.data) + files.add( + File(data.content) + ) + } + } + + return files.getFileSpecList() } - override fun getImports(): List = emptyList() + private fun createTypeSpec( + inputMetadata: MutableList, + generatedObjects: MutableList, + targetObject: GeneratedObject, + keys: List, + objectBuilder: TypeSpec.Builder, + ): TypeSpec? { + if (targetObject.isActual) { + objectBuilder.addModifiers(KModifier.ACTUAL) + } + + if (targetObject.isActualObject || targetObject.isTargetObject) { + extendObjectBodyAtStart(objectBuilder) + } + + val generatedProperties = mutableListOf() - private fun generateFileProperty( - fileSpec: FileSpec, - ): PropertySpec { - @Suppress("SpreadOperator") - return PropertySpec.builder(fileSpec.key, resourceClassName) - .addModifiers(*getPropertyModifiers()) - .apply { - getPropertyInitializer(fileSpec)?.let { initializer(it) } + keys.forEach { fileSpec -> + val property = PropertySpec.builder(fileSpec.key, resourceClassName) + + var generatedProperty = GeneratedProperty( + modifier = GeneratedObjectModifier.None, + name = fileSpec.key, + data = JsonPrimitive(fileSpec.file.path) + ) + + if (targetObject.isActualObject || targetObject.isTargetObject) { + // Add modifier for property and setup metadata + generatedProperty = generatedProperty.copy( + modifier = addActualOverrideModifier( + propertyName = fileSpec.key, + property = property, + inputMetadata = inputMetadata, + targetObject = targetObject + ) + ) + + getPropertyInitializer(fileSpec)?.let { + property.initializer(it) + } } - .build() + + objectBuilder.addProperty(property.build()) + generatedProperties.add(generatedProperty) + } + + extendObjectBodyAtEnd(objectBuilder) + + return if (generatedProperties.isNotEmpty()) { + // Add object in metadata with remove expect realisation + generatedObjects.addActual( + targetObject.copy(properties = generatedProperties) + ) + + objectBuilder.build() + } else { + null + } } + override fun getImports(): List = emptyList() + protected open fun beforeGenerate( objectBuilder: TypeSpec.Builder, files: List, @@ -103,7 +202,6 @@ abstract class FilesGenerator( ) class Feature( - val project: Project, private val settings: MRGenerator.Settings, ) : ResourceGeneratorFeature { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFilesGenerator.kt index 831394d8d..3f200155a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFilesGenerator.kt @@ -13,7 +13,7 @@ import java.io.File class AppleFilesGenerator( ownInputFileTree: FileTree, -) : FilesGenerator(inputFileTree = ownInputFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { +) : FilesGenerator(resourceFiles = ownInputFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index 9f8f772a6..5b92c3b5b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -220,21 +220,19 @@ class CommonMRGenerator( val generatorType: GeneratorType = if (it.path.matches(StringsGenerator.STRINGS_REGEX)) { GeneratorType.Strings - } - else if (it.path.matches(PluralsGenerator.PLURALS_REGEX)) { + } else if (it.path.matches(PluralsGenerator.PLURALS_REGEX)) { GeneratorType.Plurals - } - else if (it.path.matches(ColorsGenerator.COLORS_REGEX)) { + } else if (it.path.matches(ColorsGenerator.COLORS_REGEX)) { GeneratorType.Colors - } - else if (it.parentFile.name == "images") { + } else if (it.parentFile.name == "images") { GeneratorType.Images + } else if (it.parentFile.name == "files") { + GeneratorType.Files } else return@forEach //TODO: Implement with generator -// else if (it.parentFile.name == "files") { -// GeneratorType.Files -// } else if (it.parentFile.name == "assets") { + +// else if (it.parentFile.name == "assets") { // GeneratorType.Assets // } else if (it.parentFile.name == "fonts") { // GeneratorType.Fonts diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFilesGenerator.kt index 00ddc47e7..8850bc42b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFilesGenerator.kt @@ -19,7 +19,7 @@ import java.io.File class JsFilesGenerator( ownInputFileTree: FileTree, ) : FilesGenerator( - inputFileTree = ownInputFileTree + resourceFiles = ownInputFileTree ), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) 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 251e1d18e..b97d1c10f 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 @@ -7,6 +7,7 @@ package dev.icerock.gradle.tasks import dev.icerock.gradle.MRVisibility import dev.icerock.gradle.configuration.getAndroidRClassPackage import dev.icerock.gradle.generator.ColorsGenerator +import dev.icerock.gradle.generator.FilesGenerator import dev.icerock.gradle.generator.ImagesGenerator import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.PluralsGenerator @@ -164,7 +165,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { ColorsGenerator.Feature(settings), ImagesGenerator.Feature(settings, logger), // FontsGenerator.Feature(settings), -// FilesGenerator.Feature(settings), + FilesGenerator.Feature(settings), // AssetsGenerator.Feature(settings) ) } From ec6de523b8d4b51ceb37769358e8f8b2ba199f3a Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Thu, 21 Dec 2023 11:16:16 +0700 Subject: [PATCH 079/352] #535 add fonts generator, remove unused fileTree from generators --- .../gradle/MultiplatformResourcesPlugin.kt | 52 ---- .../gradle/generator/AssetsGenerator.kt | 106 ++++---- .../gradle/generator/FontsGenerator.kt | 234 ++++++++++++++---- .../icerock/gradle/generator/SourceInfo.kt | 14 -- .../gradle/generator/TargetMRGenerator.kt | 10 - .../android/AndroidAssetsGenerator.kt | 3 +- .../android/AndroidFontsGenerator.kt | 1 - .../generator/apple/AppleAssetsGenerator.kt | 3 +- .../generator/apple/AppleColorsGenerator.kt | 2 +- .../generator/apple/AppleFontsGenerator.kt | 1 - .../generator/common/CommonAssetsGenerator.kt | 2 +- .../generator/common/CommonFontsGenerator.kt | 3 +- .../generator/common/CommonMRGenerator.kt | 6 +- .../gradle/generator/js/JsAssetsGenerator.kt | 8 +- .../generator/jvm/JvmAssetsGenerator.kt | 2 + .../gradle/metadata/GeneratedProperty.kt | 6 +- .../GenerateMultiplatformResourcesTask.kt | 3 +- 17 files changed, 269 insertions(+), 187 deletions(-) delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/SourceInfo.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 655fc4e86..c51a955a0 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -174,58 +174,6 @@ open class MultiplatformResourcesPlugin : Plugin { } } } - - -// val resourcesSourceDirectory: SourceDirectorySet = project.objects.sourceDirectorySet( -// "moko-resources", -// "moko-resources" -// ) -// -// val ss = mrExtension.resourcesSourceSet -// project.logger.warn("source set $ss") -// -// kmpExtension.sourceSets -// .matching { it.name == mrExtension.resourcesSourceSet } -// .configureEach { kotlinSourceSet -> -// val sources = File(project.projectDir, "src") -// val resourceSourceSetDir = File(sources, kotlinSourceSet.name) -// val mokoResourcesDir = File(resourceSourceSetDir, "moko-resources") -// -// resourcesSourceDirectory.srcDirs(mokoResourcesDir) -// } -// -// val generatedDir = File(project.buildDir, "generated/moko-resources") -// -// val settings = MRGenerator.Settings( -// packageName = mrExtension.resourcesPackage, -// className = mrExtension.resourcesClassName, -// visibility = mrExtension.resourcesVisibility, -// generatedDir = generatedDir, -// isStrictLineBreaks = project.isStrictLineBreaks, -// iosLocalizationRegion = mrExtension.iosBaseLocalizationRegion, -// resourcesSourceDirectory = resourcesSourceDirectory, -// androidRClassPackage = project.getAndroidRClassPackage() -// ) -// -// kmpExtension.targets.configureEach { kotlinTarget -> -// var found = false -// -// kotlinTarget.compilations.configureEach { compilation -> -// compilation.kotlinSourceSetsObservable.forAll { kotlinSourceSet -> -// kotlinSourceSet.whenDependsOn(mrExtension.resourcesSourceSet) { -// if(found) return@whenDependsOn -// -// found = true -// configureKotlinTargetGenerator( -// target = kotlinTarget, -// settings = settings -// ) -// } -// } -// } -// } -// -// setupProjectForApple(project) } @OptIn(ExperimentalKotlinGradlePluginApi::class) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt index 6a071286c..2de904ab7 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt @@ -9,6 +9,8 @@ import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecDirectory +import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecFile import dev.icerock.gradle.generator.android.AndroidAssetsGenerator import dev.icerock.gradle.generator.apple.AppleAssetsGenerator import dev.icerock.gradle.generator.common.CommonAssetsGenerator @@ -22,15 +24,50 @@ import java.io.File @Suppress("TooManyFunctions") abstract class AssetsGenerator( - private val fileTree: FileTree + private val resourcesFileTree: FileTree ) : MRGenerator.Generator { override val inputFiles: Iterable - get() = fileTree.files + get() = resourcesFileTree.matching { + it.include("assets/**") + } override val mrObjectName: String = ASSETS_DIR_NAME override val resourceClassName = ClassName("dev.icerock.moko.resources", "AssetResource") override val type: GeneratorType = GeneratorType.Assets + override fun generate( + project: Project, + inputMetadata: MutableList, + generatedObjects: MutableList, + targetObject: GeneratedObject, + assetsGenerationDir: File, + resourcesGenerationDir: File, + objectBuilder: TypeSpec.Builder, + ): TypeSpec? { + val rootContent: List = parseRootContent(inputFiles) + + beforeGenerate(objectBuilder, rootContent) + + val typeSpec = createTypeSpec(rootContent, objectBuilder) + + generateResources(assetsGenerationDir, resourcesGenerationDir, rootContent) + + return typeSpec + } + + private fun createTypeSpec(keys: List, objectBuilder: TypeSpec.Builder): TypeSpec { + @Suppress("SpreadOperator") + objectBuilder.addModifiers(*getClassModifiers()) + + extendObjectBodyAtStart(objectBuilder) + + createInnerTypeSpec(keys, objectBuilder) + + extendObjectBodyAtEnd(objectBuilder) + + return objectBuilder.build() + } + private fun getBaseDir(file: File): String { val relativePathToAssets = file.path.substringAfterLast(ASSETS_DIR_NAME) val fixedRelativePath = File(relativePathToAssets).path @@ -76,7 +113,7 @@ abstract class AssetsGenerator( } private fun parseRootContent( - resFolders: Set + resFolders: Iterable ): List { val contentOfRootDir = mutableListOf() resFolders.forEach { @@ -90,39 +127,6 @@ abstract class AssetsGenerator( return parseRootContentInner(contentOfRootDir.toTypedArray()) } - override fun generate( - project: Project, - inputMetadata: MutableList, - generatedObjects: MutableList, - targetObject: GeneratedObject, - assetsGenerationDir: File, - resourcesGenerationDir: File, - objectBuilder: TypeSpec.Builder, - ): TypeSpec? { - val rootContent = parseRootContent(fileTree.files) - - beforeGenerate(objectBuilder, rootContent) - - val typeSpec = createTypeSpec(rootContent, objectBuilder) - - generateResources(assetsGenerationDir, resourcesGenerationDir, rootContent) - - return typeSpec - } - - private fun createTypeSpec(keys: List, objectBuilder: TypeSpec.Builder): TypeSpec { - @Suppress("SpreadOperator") - objectBuilder.addModifiers(*getClassModifiers()) - - extendObjectBodyAtStart(objectBuilder) - - createInnerTypeSpec(keys, objectBuilder) - - extendObjectBodyAtEnd(objectBuilder) - - return objectBuilder.build() - } - @Suppress("SpreadOperator") private fun createInnerTypeSpec(keys: List, objectBuilder: TypeSpec.Builder) { for (specs in keys) { @@ -169,18 +173,21 @@ abstract class AssetsGenerator( abstract fun getPropertyInitializer(fileSpec: AssetSpecFile): CodeBlock? - sealed class AssetSpec - - class AssetSpecDirectory(val name: String, val assets: List) : AssetSpec() - - /** - * @param pathRelativeToBase used to copy necessary resources in AssetsGenerator - * @param file is a new name a of copied resource for systems which do not support path with / symbol - */ - class AssetSpecFile( - val pathRelativeToBase: String, - val file: File - ) : AssetSpec() + sealed class AssetSpec { + class AssetSpecDirectory( + val name: String, + val assets: List, + ) : AssetSpec() + + /** + * @param pathRelativeToBase used to copy necessary resources in AssetsGenerator + * @param file is a new name a of copied resource for systems which do not support path with / symbol + */ + class AssetSpecFile( + val pathRelativeToBase: String, + val file: File + ) : AssetSpec() + } class Feature( private val settings: MRGenerator.Settings @@ -188,17 +195,14 @@ abstract class AssetsGenerator( override fun createCommonGenerator(): AssetsGenerator = CommonAssetsGenerator( ownResourcesFileTree = settings.ownResourcesFileTree, - upperResourcesFileTree = settings.upperResourcesFileTree, ) override fun createAppleGenerator(): AssetsGenerator = AppleAssetsGenerator( ownResourcesFileTree = settings.ownResourcesFileTree, - lowerResourcesFileTree = settings.lowerResourcesFileTree, ) override fun createAndroidGenerator(): AssetsGenerator = AndroidAssetsGenerator( ownResourcesFileTree = settings.ownResourcesFileTree, - lowerResourcesFileTree = settings.lowerResourcesFileTree, ) override fun createJvmGenerator(): AssetsGenerator = JvmAssetsGenerator( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt index 338aa1bb5..e0b6609d3 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt @@ -15,18 +15,27 @@ import dev.icerock.gradle.generator.common.CommonFontsGenerator import dev.icerock.gradle.generator.js.JsFontsGenerator import dev.icerock.gradle.generator.jvm.JvmFontsGenerator import dev.icerock.gradle.metadata.GeneratedObject +import dev.icerock.gradle.metadata.GeneratedObjectModifier +import dev.icerock.gradle.metadata.GeneratedProperty import dev.icerock.gradle.metadata.GeneratorType +import dev.icerock.gradle.metadata.addActual +import dev.icerock.gradle.metadata.getActualInterfaces +import dev.icerock.gradle.metadata.objectsWithProperties import dev.icerock.gradle.utils.decapitalize +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.JsonPrimitive +import kotlinx.serialization.json.decodeFromJsonElement import org.gradle.api.Project import org.gradle.api.file.FileTree import java.io.File abstract class FontsGenerator( - private val inputFileTree: FileTree, + private val resourcesFileTree: FileTree, ) : MRGenerator.Generator { override val inputFiles: Iterable - get() = inputFileTree.matching { + get() = resourcesFileTree.matching { it.include("fonts/**.ttf", "fonts/**.otf") } override val resourceClassName = ClassName("dev.icerock.moko.resources", "FontResource") @@ -43,28 +52,91 @@ abstract class FontsGenerator( resourcesGenerationDir: File, objectBuilder: TypeSpec.Builder, ): TypeSpec? { - val fontFiles = inputFileTree.map { + val previousFontFiles: List = getPreviousFontFiles( + inputMetadata = inputMetadata, + targetObject = targetObject + ) + + val fontFiles: List = if ( + targetObject.isActualObject || targetObject.isTargetObject + ) { + emptyList() + } else { + inputFiles.getFontFiles() + } + + // Sum of all fonts files and filter his on unical fonts + val allFontFiles: List = (previousFontFiles + fontFiles).distinctBy { it.key } + + beforeGenerateResources(objectBuilder, allFontFiles) + + val typeSpec = createTypeSpec( + project = project, + inputMetadata = inputMetadata, + generatedObjects = generatedObjects, + targetObject = targetObject, + filesSpec = allFontFiles.sortedBy { it.key }, + objectBuilder = objectBuilder + ) + + generateResources(resourcesGenerationDir, allFontFiles) + + return typeSpec + } + + private fun getPreviousFontFiles( + inputMetadata: List, + targetObject: GeneratedObject, + ): List { + if (!targetObject.isObject || !targetObject.isActual) return emptyList() + + val json = Json + val objectsWithProperties: List = inputMetadata.objectsWithProperties( + targetObject = targetObject + ) + + val fontFiles: MutableList = mutableListOf() + + objectsWithProperties.forEach { generatedObject -> + generatedObject.properties.forEach { property -> + val data = json.decodeFromJsonElement>(property.data) + + data.forEach { + fontFiles.add(File(it.value.content)) + } + } + } + + return fontFiles.getFontFiles() + } + + private fun Iterable.getFontFiles(): List { + return this.map { FontFile( key = it.nameWithoutExtension, file = it ) } - - beforeGenerateResources(objectBuilder, fontFiles) - val typeSpec = createTypeSpec(inputFileTree.sortedBy { it.name }, objectBuilder) - generateResources(resourcesGenerationDir, fontFiles) - - return typeSpec } /* @param keys: names of files like anastasia-regular.ttf */ - private fun createTypeSpec(files: List, objectBuilder: TypeSpec.Builder): TypeSpec { - @Suppress("SpreadOperator") - objectBuilder.addModifiers(*getClassModifiers()) + private fun createTypeSpec( + project: Project, + inputMetadata: MutableList, + generatedObjects: MutableList, + targetObject: GeneratedObject, + filesSpec: List, + objectBuilder: TypeSpec.Builder, + ): TypeSpec? { + if (targetObject.isActual) { + objectBuilder.addModifiers(KModifier.ACTUAL) + } - extendObjectBodyAtStart(objectBuilder) + if (targetObject.isActualObject || targetObject.isTargetObject) { + extendObjectBodyAtStart(objectBuilder) + } /* * 1. Group fileNames by family name (split('-').first()) @@ -72,50 +144,125 @@ abstract class FontsGenerator( * 3. Generate properties in family subtype for each font style * */ - val familyGroups = files.groupBy { file -> - file.nameWithoutExtension.substringBefore("-") + val familyGroups: Map> = filesSpec.groupBy { fileSpec -> + fileSpec.file.nameWithoutExtension.substringBefore("-") } + val generatedProperties = mutableListOf() + familyGroups.forEach { group -> - // TODO Make pairs: "style name" - "font file" - val stylePairs: List> = group + // Make pairs: "style name" - "font file" + val stylePairs: List> = group .value - .map { it.nameWithoutExtension.substringAfter("-") to it } + .map { it.file.nameWithoutExtension.substringAfter("-") to it } - objectBuilder.addType( - generateFontFamilySpec( - familyName = group.key, - fontStyleFiles = stylePairs - ) + val propertyName: String = group.key + val property: TypeSpec.Builder = TypeSpec.objectBuilder(propertyName) + + var generatedProperty = GeneratedProperty( + modifier = addObjectActualOverrideModifier( + project = project, + propertyName = propertyName, + property = property, + inputMetadata = inputMetadata, + targetObject = targetObject + ), + name = propertyName, + data = JsonPrimitive("") ) + + val fontsProperty: MutableMap = mutableMapOf() + + stylePairs.map { + Pair(it.first, it.second.file) + }.forEach { (styleName, file) -> + val styleProperty: PropertySpec.Builder = PropertySpec + .builder(styleName.decapitalize(), resourceClassName) + + if (generatedProperty.isActualProperty){ + styleProperty.addModifiers(KModifier.ACTUAL) + } + + if (targetObject.isActualObject || targetObject.isTargetObject) { + getPropertyInitializer(file)?.let { codeBlock -> + styleProperty.initializer(codeBlock) + } + } + + fontsProperty[styleName] = JsonPrimitive(file.path) + + property.addProperty(styleProperty.build()) + generatedProperty = generatedProperty.copy( + data = JsonObject(fontsProperty) + ) + } + + objectBuilder.addType(property.build()) + generatedProperties.add(generatedProperty) } + extendObjectBodyAtEnd(objectBuilder) - return objectBuilder.build() + + return if (generatedProperties.isNotEmpty()) { + // Add object in metadata with remove expect realisation + generatedObjects.addActual( + targetObject.copy(properties = generatedProperties) + ) + + objectBuilder.build() + } else { + null + } } - override fun getImports(): List = emptyList() + private fun addObjectActualOverrideModifier( + project: Project, + propertyName: String, + property: TypeSpec.Builder, + inputMetadata: List, + targetObject: GeneratedObject, + ): GeneratedObjectModifier { + // Read actual interfaces of target object generator type + val actualInterfaces: List = inputMetadata.getActualInterfaces( + generatorType = targetObject.generatorType + ) - @Suppress("SpreadOperator") - private fun generateFontFamilySpec( - familyName: String, - fontStyleFiles: List>, - ): TypeSpec { - val spec = TypeSpec - .objectBuilder(familyName) - .addModifiers(*getClassModifiers()) - fontStyleFiles - .forEach { (styleName, file) -> - val styleProperty = PropertySpec - .builder(styleName.decapitalize(), resourceClassName) - .addModifiers(*getPropertyModifiers()) - getPropertyInitializer(file)?.let { codeBlock -> - styleProperty.initializer(codeBlock) + var containsInActualInterfaces = false + + // Search property in actual interfaces + actualInterfaces.forEach { genInterface -> + val hasInInterface = genInterface.properties.any { + it.name == propertyName + } + + if (hasInInterface) { + containsInActualInterfaces = true + } + } + + return if (targetObject.isObject) { + if (containsInActualInterfaces) { + property.addModifiers(KModifier.OVERRIDE) + GeneratedObjectModifier.Override + } else { + when (targetObject.modifier) { + GeneratedObjectModifier.Actual -> { + property.addModifiers(KModifier.ACTUAL) + GeneratedObjectModifier.Actual + } + else -> { + GeneratedObjectModifier.None + } } - spec.addProperty(styleProperty.build()) } - return spec.build() + } else { + GeneratedObjectModifier.None + } + } + override fun getImports(): List = emptyList() + protected open fun generateResources( resourcesGenerationDir: File, files: List, @@ -140,17 +287,14 @@ abstract class FontsGenerator( ) : ResourceGeneratorFeature { override fun createCommonGenerator(): FontsGenerator = CommonFontsGenerator( ownInputFileTree = settings.ownResourcesFileTree, - upperInputFileTree = settings.upperResourcesFileTree ) override fun createAppleGenerator(): FontsGenerator = AppleFontsGenerator( ownInputFileTree = settings.ownResourcesFileTree, - lowerInputFileTree = settings.lowerResourcesFileTree ) override fun createAndroidGenerator(): FontsGenerator = AndroidFontsGenerator( ownInputFileTree = settings.ownResourcesFileTree, - lowerInputFileTree = settings.lowerResourcesFileTree, androidRClassPackage = settings.androidRClassPackage ) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/SourceInfo.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/SourceInfo.kt deleted file mode 100644 index fdf5ea4ae..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/SourceInfo.kt +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator - -import org.gradle.api.file.SourceDirectorySet -import org.gradle.api.provider.Provider - -interface SourceInfo { - val commonResources: SourceDirectorySet - val mrClassPackage: Provider - var androidRClassPackageProvider: Provider? -} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt index 64a8318b5..e08b855e6 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt @@ -29,7 +29,6 @@ abstract class TargetMRGenerator( settings = settings, generators = generators ) { - val logger = project.logger // TODO not used. remove after complete migration of task configuration to Plugin configuration time // override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { @@ -64,20 +63,11 @@ abstract class TargetMRGenerator( // and own resources has no files - skip step if (resourcesIsEmpty(inputMetadata, settings)) return null - //TODO: Добавить обработку кейса, когда данные есть только в таргете, т.е. генерация MR объекта - // Если есть свои ресурсы, но нет нижестоящих - просто MR - // Если есть нижестоящие - actual MR - // [checked] Нет своих и нет нижестоящих - ничего не генерировать - // If previous levels has resources, need generate actual objects val needGenerateActual: Boolean = inputMetadata.isNotEmptyMetadata() val visibilityModifier: KModifier = settings.visibility.toModifier() - inputMetadata.forEach { - logger.warn("i prev: $it") - } - val fileSpec: FileSpec.Builder = FileSpec.builder( packageName = settings.packageName, fileName = settings.className diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidAssetsGenerator.kt index cd4607f28..faadd2344 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidAssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidAssetsGenerator.kt @@ -7,6 +7,8 @@ package dev.icerock.gradle.generator.android import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.AssetsGenerator +import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecDirectory +import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecFile import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable import org.gradle.api.file.FileTree @@ -14,7 +16,6 @@ import java.io.File class AndroidAssetsGenerator( ownResourcesFileTree: FileTree, - lowerResourcesFileTree: FileTree, ) : AssetsGenerator(ownResourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun generateResources( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFontsGenerator.kt index fe34f4821..058562a98 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFontsGenerator.kt @@ -17,7 +17,6 @@ import java.util.Locale class AndroidFontsGenerator( ownInputFileTree: FileTree, - lowerInputFileTree: FileTree, private val androidRClassPackage: Provider, ) : FontsGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleAssetsGenerator.kt index 2f42a225c..5a1433272 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleAssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleAssetsGenerator.kt @@ -7,13 +7,14 @@ package dev.icerock.gradle.generator.apple import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.AssetsGenerator +import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecDirectory +import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecFile import dev.icerock.gradle.generator.ObjectBodyExtendable import org.gradle.api.file.FileTree import java.io.File class AppleAssetsGenerator( ownResourcesFileTree: FileTree, - lowerResourcesFileTree: FileTree, ) : AssetsGenerator(ownResourcesFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt index 6fe15e961..465ddc136 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt @@ -41,7 +41,7 @@ class AppleColorsGenerator( colors.forEach { colorNode -> val assetDir = File(assetsDirectory, "${colorNode.name}.colorset") - assetDir.mkdir() + assetDir.mkdirs() val contentsFile = File(assetDir, "Contents.json") contentsFile.createNewFile() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFontsGenerator.kt index 36935662e..4dd1172bb 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFontsGenerator.kt @@ -13,7 +13,6 @@ import java.io.File class AppleFontsGenerator( ownInputFileTree: FileTree, - lowerInputFileTree: FileTree, ) : FontsGenerator(ownInputFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonAssetsGenerator.kt index b8f449b57..9bfc84a54 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonAssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonAssetsGenerator.kt @@ -7,13 +7,13 @@ package dev.icerock.gradle.generator.common import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.AssetsGenerator +import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecFile import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable import org.gradle.api.file.FileTree class CommonAssetsGenerator( ownResourcesFileTree: FileTree, - upperResourcesFileTree: FileTree, ) : AssetsGenerator(ownResourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = emptyArray() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFontsGenerator.kt index e03c7afff..eaad16af2 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFontsGenerator.kt @@ -9,12 +9,11 @@ import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.FontsGenerator import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable -import java.io.File import org.gradle.api.file.FileTree +import java.io.File class CommonFontsGenerator( ownInputFileTree: FileTree, - upperInputFileTree: FileTree, ) : FontsGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = emptyArray() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index 5b92c3b5b..1431fcfc9 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -228,15 +228,15 @@ class CommonMRGenerator( GeneratorType.Images } else if (it.parentFile.name == "files") { GeneratorType.Files + } else if (it.parentFile.name == "fonts") { + GeneratorType.Fonts } else return@forEach //TODO: Implement with generator // else if (it.parentFile.name == "assets") { // GeneratorType.Assets -// } else if (it.parentFile.name == "fonts") { -// GeneratorType.Fonts -// } else { +// } else { // GeneratorType.None // } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsAssetsGenerator.kt index 25780b85b..b6578488b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsAssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsAssetsGenerator.kt @@ -11,6 +11,8 @@ import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.AssetsGenerator +import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecDirectory +import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecFile import dev.icerock.gradle.generator.NOPObjectBodyExtendable import dev.icerock.gradle.generator.ObjectBodyExtendable import org.gradle.api.file.FileTree @@ -86,11 +88,13 @@ class JsAssetsGenerator( private fun generateResourcesInner(files: List, fileResDir: File) { files.forEach { assetSpec -> when (assetSpec) { - is AssetSpecDirectory -> + is AssetSpecDirectory -> { generateResourcesInner(assetSpec.assets, fileResDir) + } - is AssetSpecFile -> + is AssetSpecFile -> { assetSpec.file.copyTo(File(fileResDir, assetSpec.pathRelativeToBase)) + } } } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmAssetsGenerator.kt index 3187cbd22..8fc119d51 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmAssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmAssetsGenerator.kt @@ -7,6 +7,8 @@ package dev.icerock.gradle.generator.jvm import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.AssetsGenerator +import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecDirectory +import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecFile import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.ObjectBodyExtendable import org.gradle.api.file.FileTree diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperty.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperty.kt index 2968f6f58..1a73240fd 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperty.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperty.kt @@ -1,5 +1,6 @@ package dev.icerock.gradle.metadata +import dev.icerock.gradle.metadata.GeneratedObjectModifier.Actual import kotlinx.serialization.Serializable import kotlinx.serialization.json.JsonElement @@ -8,4 +9,7 @@ data class GeneratedProperty( val modifier: GeneratedObjectModifier, val name: String, val data: JsonElement // Can contain data with dependencies from generator type -) +){ + val isActualProperty: Boolean + get() = modifier == Actual +} 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 b97d1c10f..21731ce9a 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 @@ -8,6 +8,7 @@ import dev.icerock.gradle.MRVisibility import dev.icerock.gradle.configuration.getAndroidRClassPackage import dev.icerock.gradle.generator.ColorsGenerator import dev.icerock.gradle.generator.FilesGenerator +import dev.icerock.gradle.generator.FontsGenerator import dev.icerock.gradle.generator.ImagesGenerator import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.PluralsGenerator @@ -164,7 +165,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { PluralsGenerator.Feature(settings), ColorsGenerator.Feature(settings), ImagesGenerator.Feature(settings, logger), -// FontsGenerator.Feature(settings), + FontsGenerator.Feature(settings), FilesGenerator.Feature(settings), // AssetsGenerator.Feature(settings) ) From 3239efc3f3ea3423425c549b1cc6efab4de5c522 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Thu, 21 Dec 2023 12:50:45 +0700 Subject: [PATCH 080/352] #535 fix apple targets for colors and image generators --- .../dev/icerock/gradle/generator/ColorsGenerator.kt | 9 ++++++++- .../dev/icerock/gradle/generator/FontsGenerator.kt | 4 ---- .../dev/icerock/gradle/generator/ImagesGenerator.kt | 10 ++++------ .../gradle/generator/android/AndroidColorsGenerator.kt | 1 + .../gradle/generator/android/AndroidImagesGenerator.kt | 1 + .../gradle/generator/apple/AppleColorsGenerator.kt | 3 ++- .../gradle/generator/apple/AppleImagesGenerator.kt | 4 ++-- .../apple/action/PackResourcesToKLibAction.kt | 2 ++ .../gradle/generator/common/CommonImagesGenerator.kt | 1 - .../icerock/gradle/generator/js/JsImagesGenerator.kt | 1 + .../icerock/gradle/generator/jvm/JvmImagesGenerator.kt | 1 + 11 files changed, 22 insertions(+), 15 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt index cb6f13a6e..63e9efac0 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt @@ -110,7 +110,13 @@ abstract class ColorsGenerator( generatedProperties.add(generatedProperty) } - generateResources(project, resourcesGenerationDir, allColors) + generateResources( + project = project, + assetsGenerationDir = assetsGenerationDir, + resourcesGenerationDir = resourcesGenerationDir, + colors = allColors + ) + extendObjectBodyAtEnd(objectBuilder) return if (generatedProperties.isNotEmpty()) { @@ -154,6 +160,7 @@ abstract class ColorsGenerator( protected open fun generateResources( project: Project, + assetsGenerationDir: File, resourcesGenerationDir: File, colors: List, ) = Unit diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt index e0b6609d3..5f384d5a4 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt @@ -71,7 +71,6 @@ abstract class FontsGenerator( beforeGenerateResources(objectBuilder, allFontFiles) val typeSpec = createTypeSpec( - project = project, inputMetadata = inputMetadata, generatedObjects = generatedObjects, targetObject = targetObject, @@ -123,7 +122,6 @@ abstract class FontsGenerator( @param keys: names of files like anastasia-regular.ttf */ private fun createTypeSpec( - project: Project, inputMetadata: MutableList, generatedObjects: MutableList, targetObject: GeneratedObject, @@ -161,7 +159,6 @@ abstract class FontsGenerator( var generatedProperty = GeneratedProperty( modifier = addObjectActualOverrideModifier( - project = project, propertyName = propertyName, property = property, inputMetadata = inputMetadata, @@ -216,7 +213,6 @@ abstract class FontsGenerator( } private fun addObjectActualOverrideModifier( - project: Project, propertyName: String, property: TypeSpec.Builder, inputMetadata: List, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt index dfef4437e..ba5f86aed 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt @@ -82,6 +82,7 @@ abstract class ImagesGenerator( ) generateResources( + assetsGenerationDir = assetsGenerationDir, resourcesGenerationDir = resourcesGenerationDir, keyFileMap = allImagesMap.mapKeys { (key, _) -> key.substringBeforeLast(".") // Remove file extension from keys @@ -233,14 +234,13 @@ abstract class ImagesGenerator( protected open fun beforeGenerateResources( objectBuilder: TypeSpec.Builder, keys: List, - ) { - } + ) = Unit protected open fun generateResources( + assetsGenerationDir: File, resourcesGenerationDir: File, keyFileMap: Map>, - ) { - } + ) = Unit abstract fun getClassModifiers(): Array @@ -254,12 +254,10 @@ abstract class ImagesGenerator( ) : ResourceGeneratorFeature { override fun createCommonGenerator(): ImagesGenerator = CommonImagesGenerator( ownInputFileTree = settings.ownResourcesFileTree, - upperInputFileTree = settings.upperResourcesFileTree ) override fun createAppleGenerator(): ImagesGenerator = AppleImagesGenerator( ownInputFileTree = settings.ownResourcesFileTree, - lowerInputFileTree = settings.lowerResourcesFileTree, ) override fun createAndroidGenerator(): ImagesGenerator = AndroidImagesGenerator( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt index 9c22d3751..413ae3323 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt @@ -27,6 +27,7 @@ class AndroidColorsGenerator( override fun generateResources( project: Project, + assetsGenerationDir: File, resourcesGenerationDir: File, colors: List ) { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt index c30abdfb3..bb162fae9 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt @@ -41,6 +41,7 @@ class AndroidImagesGenerator( ) override fun generateResources( + assetsGenerationDir: File, resourcesGenerationDir: File, keyFileMap: Map> ) { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt index 465ddc136..a6839d6d6 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt @@ -34,10 +34,11 @@ class AppleColorsGenerator( override fun generateResources( project: Project, + assetsGenerationDir: File, resourcesGenerationDir: File, colors: List ) { - val assetsDirectory = File(resourcesGenerationDir, ASSETS_DIR_NAME) + val assetsDirectory = File(assetsGenerationDir, ASSETS_DIR_NAME) colors.forEach { colorNode -> val assetDir = File(assetsDirectory, "${colorNode.name}.colorset") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleImagesGenerator.kt index 2d84cee0f..c99c3d8a9 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleImagesGenerator.kt @@ -20,7 +20,6 @@ import java.io.File class AppleImagesGenerator( ownInputFileTree: FileTree, - lowerInputFileTree: FileTree, ) : ImagesGenerator(resourcesFileTree = ownInputFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -35,10 +34,11 @@ class AppleImagesGenerator( } override fun generateResources( + assetsGenerationDir: File, resourcesGenerationDir: File, keyFileMap: Map> ) { - val assetsDirectory = File(resourcesGenerationDir, ASSETS_DIR_NAME) + val assetsDirectory = File(assetsGenerationDir, ASSETS_DIR_NAME) keyFileMap.forEach { (key, files) -> val assetDir = File(assetsDirectory, "$key.imageset") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/PackResourcesToKLibAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/PackResourcesToKLibAction.kt index de026d746..9678c5176 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/PackResourcesToKLibAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/PackResourcesToKLibAction.kt @@ -7,6 +7,7 @@ package dev.icerock.gradle.generator.apple.action import dev.icerock.gradle.generator.apple.LoadableBundle import dev.icerock.gradle.utils.unzipTo import org.gradle.api.Action +import org.gradle.api.GradleException import org.gradle.api.Task import org.gradle.api.provider.Provider import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile @@ -67,6 +68,7 @@ internal class PackResourcesToKLibAction( task.logger.error("can't compile assets - $result") task.logger.info(input) task.logger.error(errors) + throw GradleException("Assets compilation failed: $errors") } else { task.logger.info("assets compiled") assetsDirectory.deleteRecursively() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonImagesGenerator.kt index fa4c29418..808513ef6 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonImagesGenerator.kt @@ -13,7 +13,6 @@ import org.gradle.api.file.FileTree class CommonImagesGenerator( ownInputFileTree: FileTree, - upperInputFileTree: FileTree, ) : ImagesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { override fun getClassModifiers(): Array = emptyArray() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsImagesGenerator.kt index 5828fe4dd..a3c4eb1e0 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsImagesGenerator.kt @@ -51,6 +51,7 @@ class JsImagesGenerator( } override fun generateResources( + assetsGenerationDir: File, resourcesGenerationDir: File, keyFileMap: Map> ) { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmImagesGenerator.kt index 96e8c48dd..93e1f60b1 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmImagesGenerator.kt @@ -30,6 +30,7 @@ class JvmImagesGenerator( ) override fun generateResources( + assetsGenerationDir: File, resourcesGenerationDir: File, keyFileMap: Map> ) { From 9b62b312e78b2a675cf604872ae403c6231bb07d Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Thu, 21 Dec 2023 16:27:04 +0700 Subject: [PATCH 081/352] #535 add assets generator --- .../gradle/generator/AssetsGenerator.kt | 201 +++++++++++++----- .../icerock/gradle/generator/BaseGenerator.kt | 6 +- .../gradle/generator/ColorsGenerator.kt | 8 +- .../gradle/generator/FilesGenerator.kt | 8 +- .../gradle/generator/FontsGenerator.kt | 8 +- .../gradle/generator/ImagesGenerator.kt | 8 +- .../icerock/gradle/generator/MRGenerator.kt | 6 +- .../gradle/generator/PluralsGenerator.kt | 4 +- .../gradle/generator/StringsGenerator.kt | 4 +- .../gradle/generator/TargetMRGenerator.kt | 27 +-- .../android/AndroidColorsGenerator.kt | 6 - .../generator/common/CommonMRGenerator.kt | 45 ++-- .../dev/icerock/gradle/metadata/Metadata.kt | 5 +- .../icerock/gradle/metadata/MetadataExt.kt | 3 + .../dev/icerock/gradle/metadata/Utils.kt | 2 + .../gradle/metadata/model/AssetsMetadata.kt | 19 ++ .../metadata/{ => model}/GeneratedObject.kt | 19 +- .../{ => model}/GeneratedObjectModifier.kt | 2 +- .../{ => model}/GeneratedObjectType.kt | 2 +- .../metadata/{ => model}/GeneratedProperty.kt | 4 +- .../metadata/{ => model}/GeneratorType.kt | 2 +- .../GenerateMultiplatformResourcesTask.kt | 3 +- .../additionalDir/second_inner_text_file.txt | 1 + 23 files changed, 260 insertions(+), 133 deletions(-) create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/AssetsMetadata.kt rename resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/{ => model}/GeneratedObject.kt (57%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/{ => model}/GeneratedObjectModifier.kt (67%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/{ => model}/GeneratedObjectType.kt (90%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/{ => model}/GeneratedProperty.kt (75%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/{ => model}/GeneratorType.kt (74%) create mode 100644 samples/compose-resources-gallery/shared/src/commonMain/moko-resources/assets/additionalDir/second_inner_text_file.txt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt index 2de904ab7..14fb36491 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt @@ -16,15 +16,22 @@ import dev.icerock.gradle.generator.apple.AppleAssetsGenerator import dev.icerock.gradle.generator.common.CommonAssetsGenerator import dev.icerock.gradle.generator.js.JsAssetsGenerator import dev.icerock.gradle.generator.jvm.JvmAssetsGenerator -import dev.icerock.gradle.metadata.GeneratedObject -import dev.icerock.gradle.metadata.GeneratorType +import dev.icerock.gradle.metadata.addActual +import dev.icerock.gradle.metadata.model.GeneratedObject +import dev.icerock.gradle.metadata.model.GeneratedObjectModifier +import dev.icerock.gradle.metadata.model.GeneratedProperty +import dev.icerock.gradle.metadata.model.GeneratorType +import dev.icerock.gradle.metadata.objectsWithProperties +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonPrimitive +import kotlinx.serialization.json.decodeFromJsonElement import org.gradle.api.Project import org.gradle.api.file.FileTree import java.io.File @Suppress("TooManyFunctions") abstract class AssetsGenerator( - private val resourcesFileTree: FileTree + private val resourcesFileTree: FileTree, ) : MRGenerator.Generator { override val inputFiles: Iterable get() = resourcesFileTree.matching { @@ -44,28 +51,70 @@ abstract class AssetsGenerator( resourcesGenerationDir: File, objectBuilder: TypeSpec.Builder, ): TypeSpec? { - val rootContent: List = parseRootContent(inputFiles) - beforeGenerate(objectBuilder, rootContent) + val previousAssetsFiles: List = getPreviousAssets( + inputMetadata = inputMetadata, + targetObject = targetObject + ) + + val previousAssets: List = parseRootContentInner(previousAssetsFiles) + val targetAssets: List = parseRootContentInner(inputFiles) + val allAssets: List = (previousAssets + targetAssets) - val typeSpec = createTypeSpec(rootContent, objectBuilder) + beforeGenerate(objectBuilder, allAssets) + + val typeSpec: TypeSpec? = createTypeSpec( + project, + inputMetadata = inputMetadata, + generatedObjects = generatedObjects, + targetObject = targetObject, + keys = allAssets, + objectBuilder = objectBuilder + ) - generateResources(assetsGenerationDir, resourcesGenerationDir, rootContent) + generateResources(assetsGenerationDir, resourcesGenerationDir, allAssets) return typeSpec } - private fun createTypeSpec(keys: List, objectBuilder: TypeSpec.Builder): TypeSpec { - @Suppress("SpreadOperator") - objectBuilder.addModifiers(*getClassModifiers()) + private fun createTypeSpec( + project: Project, + inputMetadata: MutableList, + generatedObjects: MutableList, + targetObject: GeneratedObject, + keys: List, objectBuilder: TypeSpec.Builder, + ): TypeSpec? { + if (targetObject.isActual) { + objectBuilder.addModifiers(KModifier.ACTUAL) + } - extendObjectBodyAtStart(objectBuilder) + if (targetObject.isActualObject || targetObject.isTargetObject) { + extendObjectBodyAtStart(objectBuilder) + } + + val generatedProperties = mutableListOf() - createInnerTypeSpec(keys, objectBuilder) + createInnerTypeSpec( + project, + inputMetadata = inputMetadata, + generatedProperties = generatedProperties, + targetObject = targetObject, + keys = keys, + objectBuilder = objectBuilder + ) extendObjectBodyAtEnd(objectBuilder) - return objectBuilder.build() + return if (generatedProperties.isNotEmpty()) { + // Add object in metadata with remove expect realisation + generatedObjects.addActual( + targetObject.copy(properties = generatedProperties) + ) + + objectBuilder.build() + } else { + null + } } private fun getBaseDir(file: File): String { @@ -81,13 +130,20 @@ abstract class AssetsGenerator( return if (File.separatorChar == '/') result else result.replace(File.separatorChar, '/') } - private fun parseRootContentInner(folders: Array): List { + private fun parseRootContentInner(folders: Iterable): List { val res = mutableListOf() + for (it in folders) { if (it.isDirectory) { val files = it.listFiles() + if (!files.isNullOrEmpty()) { - res.add(AssetSpecDirectory(it.name, parseRootContentInner(files))) + res.add( + AssetSpecDirectory( + name = it.name, + assets = parseRootContentInner(files.toList()) + ) + ) } } else { // skip empty files, like .DS_Store @@ -109,62 +165,107 @@ abstract class AssetsGenerator( ) } } + return res } - private fun parseRootContent( - resFolders: Iterable - ): List { - val contentOfRootDir = mutableListOf() - resFolders.forEach { - val assets = File(it, ASSETS_DIR_NAME) + @Suppress("SpreadOperator") + private fun createInnerTypeSpec( + project: Project, + inputMetadata: MutableList, + generatedProperties: MutableList, + targetObject: GeneratedObject, + keys: List, + objectBuilder: TypeSpec.Builder, + ) { + for (specs: AssetSpec in keys) { + if (specs is AssetSpecDirectory) { + val spec = TypeSpec.objectBuilder(specs.name.replace('-', '_')) + + if (targetObject.isActualObject) { + spec.addModifiers(KModifier.ACTUAL) + } - val content = assets.listFiles() - if (content != null) { - contentOfRootDir.addAll(content) + createInnerTypeSpec( + project, + inputMetadata = inputMetadata, + generatedProperties = generatedProperties, + targetObject = targetObject, + keys = specs.assets, + objectBuilder = spec + ) + + objectBuilder.addType(spec.build()) + } else if (specs is AssetSpecFile) { + val fileName = specs.file.nameWithoutExtension.replace('-', '_') + val styleProperty = PropertySpec.builder(fileName, resourceClassName) + + var generatedProperty = GeneratedProperty( + modifier = GeneratedObjectModifier.None, + name = fileName, + data = JsonPrimitive(specs.file.path) + ) + + if (targetObject.isActualObject || targetObject.isTargetObject) { + // Add modifier for property and setup metadata + generatedProperty = generatedProperty.copy( + modifier = addActualOverrideModifier( + propertyName = fileName, + property = styleProperty, + inputMetadata = inputMetadata, + targetObject = targetObject + ) + ) + + getPropertyInitializer(specs)?.let { codeBlock -> + styleProperty.initializer(codeBlock) + } + } + + generatedProperties.add(generatedProperty) + objectBuilder.addProperty(styleProperty.build()) } } - return parseRootContentInner(contentOfRootDir.toTypedArray()) } - @Suppress("SpreadOperator") - private fun createInnerTypeSpec(keys: List, objectBuilder: TypeSpec.Builder) { - for (specs in keys) { - if (specs is AssetSpecFile) { - val styleProperty = PropertySpec - .builder(specs.file.nameWithoutExtension.replace('-', '_'), resourceClassName) - .addModifiers(*getPropertyModifiers()) - - getPropertyInitializer(specs)?.let { codeBlock -> - styleProperty.initializer(codeBlock) - } - objectBuilder.addProperty(styleProperty.build()) - } else if (specs is AssetSpecDirectory) { - val spec = TypeSpec - .objectBuilder(specs.name.replace('-', '_')) - .addModifiers(*getClassModifiers()) + private fun getPreviousAssets( + inputMetadata: List, + targetObject: GeneratedObject, + ): List { + if (!targetObject.isObject || !targetObject.isActual) return emptyList() - createInnerTypeSpec(specs.assets, spec) + val json = Json + val objectsWithProperties: List = inputMetadata.objectsWithProperties( + targetObject = targetObject + ) - objectBuilder.addType(spec.build()) + val files = mutableListOf() + + objectsWithProperties.forEach { generatedObject -> + generatedObject.properties.forEach { property -> + val data = json.decodeFromJsonElement(property.data) + files.add( + File(data.content) + ) } } + + return files } override fun getImports(): List = emptyList() protected open fun beforeGenerate( objectBuilder: TypeSpec.Builder, - files: List + files: List, ) { } protected open fun generateResources( assetsGenerationDir: File, resourcesGenerationDir: File, - files: List - ) { - } + files: List, + ) = Unit abstract fun getClassModifiers(): Array @@ -185,12 +286,12 @@ abstract class AssetsGenerator( */ class AssetSpecFile( val pathRelativeToBase: String, - val file: File + val file: File, ) : AssetSpec() } class Feature( - private val settings: MRGenerator.Settings + private val settings: MRGenerator.Settings, ) : ResourceGeneratorFeature { override fun createCommonGenerator(): AssetsGenerator = CommonAssetsGenerator( @@ -223,5 +324,7 @@ abstract class AssetsGenerator( don't support it like apple. */ const val PATH_DELIMITER = '+' + + val ASSETS_REGEX: Regex = "^.*/assets/.*".toRegex() } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt index 8cf4e746f..f6ee86a42 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt @@ -9,9 +9,9 @@ import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.PropertySpec.Builder import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.metadata.GeneratedObject -import dev.icerock.gradle.metadata.GeneratedObjectModifier -import dev.icerock.gradle.metadata.GeneratedProperty +import dev.icerock.gradle.metadata.model.GeneratedObject +import dev.icerock.gradle.metadata.model.GeneratedObjectModifier +import dev.icerock.gradle.metadata.model.GeneratedProperty import dev.icerock.gradle.metadata.addActual import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonObject diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt index 63e9efac0..b252c3668 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt @@ -14,11 +14,11 @@ import dev.icerock.gradle.generator.apple.AppleColorsGenerator import dev.icerock.gradle.generator.common.CommonColorsGenerator import dev.icerock.gradle.generator.js.JsColorsGenerator import dev.icerock.gradle.generator.jvm.JvmColorsGenerator -import dev.icerock.gradle.metadata.GeneratedObject -import dev.icerock.gradle.metadata.GeneratedObjectModifier -import dev.icerock.gradle.metadata.GeneratedProperty -import dev.icerock.gradle.metadata.GeneratorType import dev.icerock.gradle.metadata.addActual +import dev.icerock.gradle.metadata.model.GeneratedObject +import dev.icerock.gradle.metadata.model.GeneratedObjectModifier +import dev.icerock.gradle.metadata.model.GeneratedProperty +import dev.icerock.gradle.metadata.model.GeneratorType import dev.icerock.gradle.metadata.objectsWithProperties import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt index 84991a7e6..3c9da8f03 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt @@ -14,10 +14,10 @@ import dev.icerock.gradle.generator.apple.AppleFilesGenerator import dev.icerock.gradle.generator.common.CommonFilesGenerator import dev.icerock.gradle.generator.js.JsFilesGenerator import dev.icerock.gradle.generator.jvm.JvmFilesGenerator -import dev.icerock.gradle.metadata.GeneratedObject -import dev.icerock.gradle.metadata.GeneratedObjectModifier -import dev.icerock.gradle.metadata.GeneratedProperty -import dev.icerock.gradle.metadata.GeneratorType +import dev.icerock.gradle.metadata.model.GeneratedObject +import dev.icerock.gradle.metadata.model.GeneratedObjectModifier +import dev.icerock.gradle.metadata.model.GeneratedProperty +import dev.icerock.gradle.metadata.model.GeneratorType import dev.icerock.gradle.metadata.addActual import dev.icerock.gradle.metadata.objectsWithProperties import kotlinx.serialization.json.Json diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt index 5f384d5a4..713552ad3 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt @@ -14,10 +14,10 @@ import dev.icerock.gradle.generator.apple.AppleFontsGenerator import dev.icerock.gradle.generator.common.CommonFontsGenerator import dev.icerock.gradle.generator.js.JsFontsGenerator import dev.icerock.gradle.generator.jvm.JvmFontsGenerator -import dev.icerock.gradle.metadata.GeneratedObject -import dev.icerock.gradle.metadata.GeneratedObjectModifier -import dev.icerock.gradle.metadata.GeneratedProperty -import dev.icerock.gradle.metadata.GeneratorType +import dev.icerock.gradle.metadata.model.GeneratedObject +import dev.icerock.gradle.metadata.model.GeneratedObjectModifier +import dev.icerock.gradle.metadata.model.GeneratedProperty +import dev.icerock.gradle.metadata.model.GeneratorType import dev.icerock.gradle.metadata.addActual import dev.icerock.gradle.metadata.getActualInterfaces import dev.icerock.gradle.metadata.objectsWithProperties diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt index ba5f86aed..430bcc729 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt @@ -14,11 +14,11 @@ import dev.icerock.gradle.generator.apple.AppleImagesGenerator import dev.icerock.gradle.generator.common.CommonImagesGenerator import dev.icerock.gradle.generator.js.JsImagesGenerator import dev.icerock.gradle.generator.jvm.JvmImagesGenerator -import dev.icerock.gradle.metadata.GeneratedObject -import dev.icerock.gradle.metadata.GeneratedObjectModifier -import dev.icerock.gradle.metadata.GeneratedProperty -import dev.icerock.gradle.metadata.GeneratorType import dev.icerock.gradle.metadata.addActual +import dev.icerock.gradle.metadata.model.GeneratedObject +import dev.icerock.gradle.metadata.model.GeneratedObjectModifier +import dev.icerock.gradle.metadata.model.GeneratedProperty +import dev.icerock.gradle.metadata.model.GeneratorType import dev.icerock.gradle.metadata.objectsWithProperties import dev.icerock.gradle.utils.withoutScale import kotlinx.serialization.json.Json diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt index 5b4e82bd8..5d3ce3b34 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt @@ -10,9 +10,9 @@ import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.MRVisibility -import dev.icerock.gradle.metadata.GeneratedObject -import dev.icerock.gradle.metadata.GeneratedObjectModifier -import dev.icerock.gradle.metadata.GeneratorType +import dev.icerock.gradle.metadata.model.GeneratedObject +import dev.icerock.gradle.metadata.model.GeneratedObjectModifier +import dev.icerock.gradle.metadata.model.GeneratorType import dev.icerock.gradle.metadata.getActualInterfaces import org.gradle.api.Project import org.gradle.api.file.Directory diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt index 0a64f6bc3..0db27949b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt @@ -10,8 +10,8 @@ import dev.icerock.gradle.generator.apple.ApplePluralsGenerator import dev.icerock.gradle.generator.common.CommonPluralsGenerator import dev.icerock.gradle.generator.js.JsPluralsGenerator import dev.icerock.gradle.generator.jvm.JvmPluralsGenerator -import dev.icerock.gradle.metadata.GeneratedObject -import dev.icerock.gradle.metadata.GeneratorType +import dev.icerock.gradle.metadata.model.GeneratedObject +import dev.icerock.gradle.metadata.model.GeneratorType import dev.icerock.gradle.metadata.objectsWithProperties import dev.icerock.gradle.utils.removeLineWraps import kotlinx.serialization.json.Json diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt index 874697d4b..29bd16642 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt @@ -10,8 +10,8 @@ import dev.icerock.gradle.generator.apple.AppleStringsGenerator import dev.icerock.gradle.generator.common.CommonStringsGenerator import dev.icerock.gradle.generator.js.JsStringsGenerator import dev.icerock.gradle.generator.jvm.JvmStringsGenerator -import dev.icerock.gradle.metadata.GeneratedObject -import dev.icerock.gradle.metadata.GeneratorType +import dev.icerock.gradle.metadata.model.GeneratedObject +import dev.icerock.gradle.metadata.model.GeneratorType import dev.icerock.gradle.metadata.objectsWithProperties import dev.icerock.gradle.utils.removeLineWraps import kotlinx.serialization.json.Json diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt index e08b855e6..a22048f78 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt @@ -5,10 +5,9 @@ import com.squareup.kotlinpoet.FileSpec import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.metadata.GeneratedObject -import dev.icerock.gradle.metadata.GeneratedObjectModifier -import dev.icerock.gradle.metadata.GeneratedObjectType -import dev.icerock.gradle.metadata.GeneratorType +import dev.icerock.gradle.metadata.model.GeneratedObject +import dev.icerock.gradle.metadata.model.GeneratedObjectModifier +import dev.icerock.gradle.metadata.model.GeneratorType import dev.icerock.gradle.metadata.Metadata.createOutputMetadata import dev.icerock.gradle.metadata.Metadata.readInputMetadata import dev.icerock.gradle.metadata.addActual @@ -16,6 +15,10 @@ import dev.icerock.gradle.metadata.getExpectInterfaces import dev.icerock.gradle.metadata.getGeneratorInterfaces import dev.icerock.gradle.metadata.getInterfaceName import dev.icerock.gradle.metadata.isNotEmptyMetadata +import dev.icerock.gradle.metadata.model.GeneratedObjectModifier.Actual +import dev.icerock.gradle.metadata.model.GeneratedObjectModifier.None +import dev.icerock.gradle.metadata.model.GeneratedObjectType.Interface +import dev.icerock.gradle.metadata.model.GeneratedObjectType.Object import dev.icerock.gradle.metadata.resourcesIsEmpty import dev.icerock.gradle.toModifier import dev.icerock.gradle.utils.targetName @@ -138,11 +141,11 @@ abstract class TargetMRGenerator( targetObject = GeneratedObject( generatorType = generator.type, modifier = if (needGenerateActual) { - GeneratedObjectModifier.Actual + Actual } else { - GeneratedObjectModifier.None + None }, - type = GeneratedObjectType.Object, + type = Object, name = generator.mrObjectName, interfaces = getObjectInterfaces( generatorType = generator.type, @@ -169,9 +172,9 @@ abstract class TargetMRGenerator( inputMetadata.addActual( actualObject = GeneratedObject( generatorType = GeneratorType.None, - type = GeneratedObjectType.Object, + type = Object, name = settings.className, - modifier = GeneratedObjectModifier.Actual, + modifier = Actual, objects = generatedActualObjects ) ) @@ -218,11 +221,11 @@ abstract class TargetMRGenerator( targetObject = GeneratedObject( generatorType = generator.type, modifier = if (generateActualObject) { - GeneratedObjectModifier.Actual + Actual } else { - GeneratedObjectModifier.None + None }, - type = GeneratedObjectType.Interface, + type = Interface, name = interfaceName ), assetsGenerationDir = assetsGenerationDir, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt index 413ae3323..d5f3b6969 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt @@ -50,12 +50,6 @@ class AndroidColorsGenerator( """.trimIndent() - project.logger.warn("ANDROID COLORS GENERATOR") - - colors.forEach { - project.logger.warn("ANDROID COLORS: value: $it") - } - val defaultContent = colors.joinToString("\n") { colorNode -> if (colorNode.isThemed()) { buildColorString(colorNode.name, replaceColorAlpha(colorNode.lightColor)) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index 1431fcfc9..d26552b6a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -10,18 +10,22 @@ import com.squareup.kotlinpoet.FileSpec.Builder import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.generator.AssetsGenerator import dev.icerock.gradle.generator.ColorsGenerator import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.PluralsGenerator import dev.icerock.gradle.generator.StringsGenerator -import dev.icerock.gradle.metadata.GeneratedObject -import dev.icerock.gradle.metadata.GeneratedObjectModifier -import dev.icerock.gradle.metadata.GeneratedObjectType -import dev.icerock.gradle.metadata.GeneratorType import dev.icerock.gradle.metadata.Metadata.createOutputMetadata import dev.icerock.gradle.metadata.Metadata.readInputMetadata import dev.icerock.gradle.metadata.addActual import dev.icerock.gradle.metadata.getInterfaceName +import dev.icerock.gradle.metadata.model.GeneratedObject +import dev.icerock.gradle.metadata.model.GeneratedObjectModifier.Actual +import dev.icerock.gradle.metadata.model.GeneratedObjectModifier.Expect +import dev.icerock.gradle.metadata.model.GeneratedObjectType.Interface +import dev.icerock.gradle.metadata.model.GeneratedObjectType.Object +import dev.icerock.gradle.metadata.model.GeneratorType +import dev.icerock.gradle.metadata.model.GeneratorType.None import dev.icerock.gradle.metadata.resourcesIsEmpty import dev.icerock.gradle.toModifier import dev.icerock.gradle.utils.targetName @@ -36,8 +40,6 @@ class CommonMRGenerator( settings = settings, generators = generators ) { - val logger = project.logger - override fun getMRClassModifiers(): Array = arrayOf(KModifier.EXPECT) // TODO not used. remove after complete migration of task configuration to Plugin configuration time @@ -123,7 +125,6 @@ class CommonMRGenerator( outputMetadataFile = settings.outputMetadataFile, generatedObjects = generatedObjects ) - project.logger.warn("OUTPUT METADATA: ${settings.outputMetadataFile}") return fileSpec.build() } @@ -138,7 +139,7 @@ class CommonMRGenerator( // generated MR class structure: val mrClassSpec: TypeSpec.Builder = TypeSpec.objectBuilder(settings.className) // default: object MR - .addModifiers(KModifier.EXPECT) // expect/actual + .addModifiers(KModifier.EXPECT) .addModifiers(visibilityModifier) // public/internal val generatedExpectObjects = mutableListOf() @@ -173,8 +174,8 @@ class CommonMRGenerator( generatedObjects = generatedExpectObjects, targetObject = GeneratedObject( generatorType = generator.type, - modifier = GeneratedObjectModifier.Expect, - type = GeneratedObjectType.Object, + modifier = Expect, + type = Object, name = generator.mrObjectName, interfaces = expectInterfaces.map { it.name } ), @@ -198,10 +199,10 @@ class CommonMRGenerator( // Metadata: Add generated objects in MR generatedObjects.add( GeneratedObject( - generatorType = GeneratorType.None, - type = GeneratedObjectType.Object, + generatorType = None, + type = Object, name = settings.className, - modifier = GeneratedObjectModifier.Expect, + modifier = Expect, objects = generatedExpectObjects ) ) @@ -230,21 +231,15 @@ class CommonMRGenerator( GeneratorType.Files } else if (it.parentFile.name == "fonts") { GeneratorType.Fonts + } else if (it.path.matches(AssetsGenerator.ASSETS_REGEX)) { + GeneratorType.Assets } else return@forEach - //TODO: Implement with generator - -// else if (it.parentFile.name == "assets") { -// GeneratorType.Assets -// } else { -// GeneratorType.None -// } - expectInterfaces.add( GeneratedObject( generatorType = generatorType, - type = GeneratedObjectType.Interface, - modifier = GeneratedObjectModifier.Expect, + type = Interface, + modifier = Expect, name = getInterfaceName( targetName = it.targetName, generatorType = generatorType @@ -291,8 +286,8 @@ class CommonMRGenerator( targetObject = GeneratedObject( generatorType = generator.type, name = interfaceName, - type = GeneratedObjectType.Interface, - modifier = GeneratedObjectModifier.Actual, + type = Interface, + modifier = Actual, ), inputMetadata = inputMetadata, generatedObjects = generatedObjects, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt index 39a9dc7eb..63f99ff28 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt @@ -1,10 +1,11 @@ package dev.icerock.gradle.metadata -import java.io.BufferedReader -import java.io.File +import dev.icerock.gradle.metadata.model.GeneratedObject import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import org.gradle.api.file.FileTree +import java.io.BufferedReader +import java.io.File object Metadata { fun createOutputMetadata( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt index f16a56258..7d60c6a5e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt @@ -1,5 +1,8 @@ package dev.icerock.gradle.metadata +import dev.icerock.gradle.metadata.model.GeneratedObject +import dev.icerock.gradle.metadata.model.GeneratorType + fun MutableList.addActual(actualObject: GeneratedObject) { val expect: GeneratedObject? = firstOrNull { it.name == actualObject.name diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Utils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Utils.kt index 2ea477c7f..49c5d80b9 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Utils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Utils.kt @@ -1,6 +1,8 @@ package dev.icerock.gradle.metadata import dev.icerock.gradle.generator.MRGenerator.Settings +import dev.icerock.gradle.metadata.model.GeneratedObject +import dev.icerock.gradle.metadata.model.GeneratorType import dev.icerock.gradle.utils.capitalize internal fun getInterfaceName(targetName: String, generatorType: GeneratorType): String { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/AssetsMetadata.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/AssetsMetadata.kt new file mode 100644 index 000000000..6edcc55f8 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/AssetsMetadata.kt @@ -0,0 +1,19 @@ +package dev.icerock.gradle.metadata.model + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class AssetsMetadata( + @SerialName("type") + val type: AssetsType, + val name: String, + val path: String?, + val files: List?, + val assets: List?, +) + +enum class AssetsType { + File, + Directory +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObject.kt similarity index 57% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObject.kt index f36adb48d..35b05d9d9 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObject.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObject.kt @@ -1,5 +1,10 @@ -package dev.icerock.gradle.metadata +package dev.icerock.gradle.metadata.model +import dev.icerock.gradle.metadata.model.GeneratedObjectModifier.Actual +import dev.icerock.gradle.metadata.model.GeneratedObjectModifier.Expect +import dev.icerock.gradle.metadata.model.GeneratedObjectModifier.None +import dev.icerock.gradle.metadata.model.GeneratedObjectType.Interface +import dev.icerock.gradle.metadata.model.GeneratedObjectType.Object import kotlinx.serialization.Serializable @Serializable @@ -13,16 +18,16 @@ data class GeneratedObject( val objects: List = emptyList() ) { val isExpect: Boolean - get() = modifier == GeneratedObjectModifier.Expect + get() = modifier == Expect val isActual: Boolean - get() = modifier == GeneratedObjectModifier.Actual + get() = modifier == Actual val isObject: Boolean - get() = type == GeneratedObjectType.Object + get() = type == Object val isInterface: Boolean - get() = type == GeneratedObjectType.Interface + get() = type == Interface val isExpectObject get() = isObject && isExpect @@ -37,8 +42,8 @@ data class GeneratedObject( get() = isInterface && isActual val isTargetObject: Boolean - get() = isObject && modifier == GeneratedObjectModifier.None + get() = isObject && modifier == None val isTargetInterface: Boolean - get() = isInterface && modifier == GeneratedObjectModifier.None + get() = isInterface && modifier == None } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObjectModifier.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObjectModifier.kt similarity index 67% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObjectModifier.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObjectModifier.kt index bd3c40794..382ba4e77 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObjectModifier.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObjectModifier.kt @@ -1,4 +1,4 @@ -package dev.icerock.gradle.metadata +package dev.icerock.gradle.metadata.model enum class GeneratedObjectModifier { Expect, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObjectType.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObjectType.kt similarity index 90% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObjectType.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObjectType.kt index d24d44628..14ea45a10 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedObjectType.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObjectType.kt @@ -1,4 +1,4 @@ -package dev.icerock.gradle.metadata +package dev.icerock.gradle.metadata.model enum class GeneratedObjectType(val value: String) { Object("object"), diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperty.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedProperty.kt similarity index 75% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperty.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedProperty.kt index 1a73240fd..25d28bd47 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratedProperty.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedProperty.kt @@ -1,6 +1,6 @@ -package dev.icerock.gradle.metadata +package dev.icerock.gradle.metadata.model -import dev.icerock.gradle.metadata.GeneratedObjectModifier.Actual +import dev.icerock.gradle.metadata.model.GeneratedObjectModifier.Actual import kotlinx.serialization.Serializable import kotlinx.serialization.json.JsonElement diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratorType.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratorType.kt similarity index 74% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratorType.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratorType.kt index e7d92f628..788df5962 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/GeneratorType.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratorType.kt @@ -1,4 +1,4 @@ -package dev.icerock.gradle.metadata +package dev.icerock.gradle.metadata.model enum class GeneratorType { Strings, 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 21731ce9a..6eed3f745 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 @@ -6,6 +6,7 @@ package dev.icerock.gradle.tasks import dev.icerock.gradle.MRVisibility import dev.icerock.gradle.configuration.getAndroidRClassPackage +import dev.icerock.gradle.generator.AssetsGenerator import dev.icerock.gradle.generator.ColorsGenerator import dev.icerock.gradle.generator.FilesGenerator import dev.icerock.gradle.generator.FontsGenerator @@ -167,7 +168,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { ImagesGenerator.Feature(settings, logger), FontsGenerator.Feature(settings), FilesGenerator.Feature(settings), -// AssetsGenerator.Feature(settings) + AssetsGenerator.Feature(settings) ) } diff --git a/samples/compose-resources-gallery/shared/src/commonMain/moko-resources/assets/additionalDir/second_inner_text_file.txt b/samples/compose-resources-gallery/shared/src/commonMain/moko-resources/assets/additionalDir/second_inner_text_file.txt new file mode 100644 index 000000000..82dc87c63 --- /dev/null +++ b/samples/compose-resources-gallery/shared/src/commonMain/moko-resources/assets/additionalDir/second_inner_text_file.txt @@ -0,0 +1 @@ +Text from asset resource. \ No newline at end of file From 315a34bfdd445c4e518d92df344e07bf287ec921 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Wed, 3 Jan 2024 15:40:56 +0700 Subject: [PATCH 082/352] #535 refactoring remove mutablelists, pass output metadata as result --- .../gradle/MultiplatformResourcesPlugin.kt | 18 +- .../gradle/generator/AssetsGenerator.kt | 48 ++-- .../gradle/generator/ColorsGenerator.kt | 33 ++- .../gradle/generator/FilesGenerator.kt | 42 ++-- .../gradle/generator/FontsGenerator.kt | 55 ++--- .../gradle/generator/ImagesGenerator.kt | 42 ++-- ...eGenerator.kt => LocalizationGenerator.kt} | 52 ++-- .../icerock/gradle/generator/MRGenerator.kt | 44 +--- .../gradle/generator/PluralsGenerator.kt | 2 +- .../gradle/generator/StringsGenerator.kt | 2 +- .../gradle/generator/TargetMRGenerator.kt | 94 +++----- .../generator/common/CommonMRGenerator.kt | 222 +++++++----------- .../dev/icerock/gradle/metadata/Metadata.kt | 25 +- .../dev/icerock/gradle/metadata/Utils.kt | 6 +- .../GenerateMultiplatformResourcesTask.kt | 21 +- 15 files changed, 280 insertions(+), 426 deletions(-) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{BaseGenerator.kt => LocalizationGenerator.kt} (82%) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index c51a955a0..cf2db1431 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -65,10 +65,7 @@ open class MultiplatformResourcesPlugin : Plugin { mrExtension: MultiplatformResourcesPluginExtension, kmpExtension: KotlinMultiplatformExtension, ) { - kmpExtension.sourceSets.configureEach { kotlinSourceSet: KotlinSourceSet -> - project.logger.warn("i kmpExtension.sourceSets: ${kotlinSourceSet.name}") - val resourcesSourceDirectory: SourceDirectorySet = createMokoResourcesSourceSet( project = project, kotlinSourceSet = kotlinSourceSet @@ -283,6 +280,8 @@ open class MultiplatformResourcesPlugin : Plugin { generateTaskName, GenerateMultiplatformResourcesTask::class.java ) { generateTask -> + generateTask.sourceSetName.set(kotlinSourceSet.name) + val files: Set = resourcesSourceDirectory.srcDirs generateTask.ownResources.setFrom(files) @@ -300,6 +299,19 @@ open class MultiplatformResourcesPlugin : Plugin { generateTask.outputAssetsDir.set(File(sourceSetResourceDir, "assets")) generateTask.outputResourcesDir.set(File(sourceSetResourceDir, "res")) generateTask.outputSourcesDir.set(File(sourceSetResourceDir, "src")) + + // by default source set will be common + generateTask.platformType.set(KotlinPlatformType.common.name) + + generateTask.onlyIf("generation on Android supported only for main flavor") { task -> + task as GenerateMultiplatformResourcesTask + + val platform: String = task.platformType.get() + if (platform != KotlinPlatformType.androidJvm.name) return@onlyIf true + + val flavor: String = task.androidSourceSetName.get() + flavor in listOf("main", "test", "androidTest") + } } kotlinSourceSet.extras[mokoResourcesGenTaskKey()] = taskProvider diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt index 14fb36491..a0215b093 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt @@ -16,7 +16,6 @@ import dev.icerock.gradle.generator.apple.AppleAssetsGenerator import dev.icerock.gradle.generator.common.CommonAssetsGenerator import dev.icerock.gradle.generator.js.JsAssetsGenerator import dev.icerock.gradle.generator.jvm.JvmAssetsGenerator -import dev.icerock.gradle.metadata.addActual import dev.icerock.gradle.metadata.model.GeneratedObject import dev.icerock.gradle.metadata.model.GeneratedObjectModifier import dev.icerock.gradle.metadata.model.GeneratedProperty @@ -44,17 +43,15 @@ abstract class AssetsGenerator( override fun generate( project: Project, - inputMetadata: MutableList, - generatedObjects: MutableList, - targetObject: GeneratedObject, + inputMetadata: List, + outputMetadata: GeneratedObject, assetsGenerationDir: File, resourcesGenerationDir: File, - objectBuilder: TypeSpec.Builder, - ): TypeSpec? { - + objectBuilder: TypeSpec.Builder + ): MRGenerator.GenerationResult? { val previousAssetsFiles: List = getPreviousAssets( inputMetadata = inputMetadata, - targetObject = targetObject + targetObject = outputMetadata ) val previousAssets: List = parseRootContentInner(previousAssetsFiles) @@ -63,27 +60,26 @@ abstract class AssetsGenerator( beforeGenerate(objectBuilder, allAssets) - val typeSpec: TypeSpec? = createTypeSpec( - project, + val result: MRGenerator.GenerationResult = createTypeSpec( + project = project, inputMetadata = inputMetadata, - generatedObjects = generatedObjects, - targetObject = targetObject, + targetObject = outputMetadata, keys = allAssets, objectBuilder = objectBuilder - ) + ) ?: return null generateResources(assetsGenerationDir, resourcesGenerationDir, allAssets) - return typeSpec + return result } private fun createTypeSpec( project: Project, - inputMetadata: MutableList, - generatedObjects: MutableList, + inputMetadata: List, targetObject: GeneratedObject, - keys: List, objectBuilder: TypeSpec.Builder, - ): TypeSpec? { + keys: List, + objectBuilder: TypeSpec.Builder, + ): MRGenerator.GenerationResult? { if (targetObject.isActual) { objectBuilder.addModifiers(KModifier.ACTUAL) } @@ -105,16 +101,12 @@ abstract class AssetsGenerator( extendObjectBodyAtEnd(objectBuilder) - return if (generatedProperties.isNotEmpty()) { - // Add object in metadata with remove expect realisation - generatedObjects.addActual( - targetObject.copy(properties = generatedProperties) - ) + if (generatedProperties.isEmpty()) return null - objectBuilder.build() - } else { - null - } + return MRGenerator.GenerationResult( + typeSpec = objectBuilder.build(), + metadata = targetObject.copy(properties = generatedProperties) + ) } private fun getBaseDir(file: File): String { @@ -172,7 +164,7 @@ abstract class AssetsGenerator( @Suppress("SpreadOperator") private fun createInnerTypeSpec( project: Project, - inputMetadata: MutableList, + inputMetadata: List, generatedProperties: MutableList, targetObject: GeneratedObject, keys: List, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt index b252c3668..126210b0b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt @@ -14,7 +14,6 @@ import dev.icerock.gradle.generator.apple.AppleColorsGenerator import dev.icerock.gradle.generator.common.CommonColorsGenerator import dev.icerock.gradle.generator.js.JsColorsGenerator import dev.icerock.gradle.generator.jvm.JvmColorsGenerator -import dev.icerock.gradle.metadata.addActual import dev.icerock.gradle.metadata.model.GeneratedObject import dev.icerock.gradle.metadata.model.GeneratedObjectModifier import dev.icerock.gradle.metadata.model.GeneratedProperty @@ -49,18 +48,17 @@ abstract class ColorsGenerator( @Suppress("SpreadOperator") override fun generate( project: Project, - inputMetadata: MutableList, - generatedObjects: MutableList, - targetObject: GeneratedObject, + inputMetadata: List, + outputMetadata: GeneratedObject, assetsGenerationDir: File, resourcesGenerationDir: File, objectBuilder: TypeSpec.Builder, - ): TypeSpec? { - if (targetObject.isActual) { + ): MRGenerator.GenerationResult? { + if (outputMetadata.isActual) { objectBuilder.addModifiers(KModifier.ACTUAL) } - if (targetObject.isActualObject || targetObject.isTargetObject) { + if (outputMetadata.isActualObject || outputMetadata.isTargetObject) { extendObjectBodyAtStart(objectBuilder) } @@ -68,7 +66,7 @@ abstract class ColorsGenerator( // return emptyList() val previousColors: List = getPreviousColors( inputMetadata = inputMetadata, - targetObject = targetObject + targetObject = outputMetadata ) // Read target colors @@ -90,14 +88,14 @@ abstract class ColorsGenerator( data = json.encodeToJsonElement(colorNode) ) - if (targetObject.isActualObject || targetObject.isTargetObject) { + if (outputMetadata.isActualObject || outputMetadata.isTargetObject) { // Setup property modifier and correction metadata info generatedProperty = generatedProperty.copy( modifier = addActualOverrideModifier( propertyName = colorNode.name, property = property, inputMetadata = inputMetadata, - targetObject = targetObject + targetObject = outputMetadata ) ) @@ -119,19 +117,16 @@ abstract class ColorsGenerator( extendObjectBodyAtEnd(objectBuilder) - return if (generatedProperties.isNotEmpty()) { - generatedObjects.addActual( - targetObject.copy(properties = generatedProperties) - ) + if (generatedProperties.isEmpty()) return null - objectBuilder.build() - } else { - null - } + return MRGenerator.GenerationResult( + typeSpec = objectBuilder.build(), + metadata = outputMetadata.copy(properties = generatedProperties) + ) } private fun getPreviousColors( - inputMetadata: MutableList, + inputMetadata: List, targetObject: GeneratedObject, ): List { if (!targetObject.isObject || !targetObject.isActual) return emptyList() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt index 3c9da8f03..adb366e29 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt @@ -18,7 +18,6 @@ import dev.icerock.gradle.metadata.model.GeneratedObject import dev.icerock.gradle.metadata.model.GeneratedObjectModifier import dev.icerock.gradle.metadata.model.GeneratedProperty import dev.icerock.gradle.metadata.model.GeneratorType -import dev.icerock.gradle.metadata.addActual import dev.icerock.gradle.metadata.objectsWithProperties import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonPrimitive @@ -40,20 +39,19 @@ abstract class FilesGenerator( override fun generate( project: Project, - inputMetadata: MutableList, - generatedObjects: MutableList, - targetObject: GeneratedObject, + inputMetadata: List, + outputMetadata: GeneratedObject, assetsGenerationDir: File, resourcesGenerationDir: File, - objectBuilder: TypeSpec.Builder, - ): TypeSpec? { + objectBuilder: TypeSpec.Builder + ): MRGenerator.GenerationResult? { val previousFilesSpec: List = getPreviousFiles( inputMetadata = inputMetadata, - targetObject = targetObject + targetObject = outputMetadata ) val targetFilesSpecs: List = if ( - targetObject.isActualObject || targetObject.isTargetObject + outputMetadata.isActualObject || outputMetadata.isTargetObject ) { emptyList() } else { @@ -64,20 +62,19 @@ abstract class FilesGenerator( beforeGenerate(objectBuilder, allFilesSpecs) - val typeSpec: TypeSpec? = createTypeSpec( + val result: MRGenerator.GenerationResult = createTypeSpec( inputMetadata = inputMetadata, - generatedObjects = generatedObjects, - targetObject = targetObject, + targetObject = outputMetadata, keys = allFilesSpecs, objectBuilder = objectBuilder - ) + ) ?: return null generateResources( resourcesGenerationDir = resourcesGenerationDir, files = allFilesSpecs ) - return typeSpec + return result } private fun Iterable.getFileSpecList(): List { @@ -115,12 +112,11 @@ abstract class FilesGenerator( } private fun createTypeSpec( - inputMetadata: MutableList, - generatedObjects: MutableList, + inputMetadata: List, targetObject: GeneratedObject, keys: List, objectBuilder: TypeSpec.Builder, - ): TypeSpec? { + ): MRGenerator.GenerationResult? { if (targetObject.isActual) { objectBuilder.addModifiers(KModifier.ACTUAL) } @@ -162,16 +158,12 @@ abstract class FilesGenerator( extendObjectBodyAtEnd(objectBuilder) - return if (generatedProperties.isNotEmpty()) { - // Add object in metadata with remove expect realisation - generatedObjects.addActual( - targetObject.copy(properties = generatedProperties) - ) + if (generatedProperties.isEmpty()) return null - objectBuilder.build() - } else { - null - } + return MRGenerator.GenerationResult( + typeSpec = objectBuilder.build(), + metadata = targetObject.copy(properties = generatedProperties) + ) } override fun getImports(): List = emptyList() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt index 713552ad3..a349ba221 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt @@ -14,12 +14,11 @@ import dev.icerock.gradle.generator.apple.AppleFontsGenerator import dev.icerock.gradle.generator.common.CommonFontsGenerator import dev.icerock.gradle.generator.js.JsFontsGenerator import dev.icerock.gradle.generator.jvm.JvmFontsGenerator +import dev.icerock.gradle.metadata.getActualInterfaces import dev.icerock.gradle.metadata.model.GeneratedObject import dev.icerock.gradle.metadata.model.GeneratedObjectModifier import dev.icerock.gradle.metadata.model.GeneratedProperty import dev.icerock.gradle.metadata.model.GeneratorType -import dev.icerock.gradle.metadata.addActual -import dev.icerock.gradle.metadata.getActualInterfaces import dev.icerock.gradle.metadata.objectsWithProperties import dev.icerock.gradle.utils.decapitalize import kotlinx.serialization.json.Json @@ -45,20 +44,19 @@ abstract class FontsGenerator( override fun generate( project: Project, - inputMetadata: MutableList, - generatedObjects: MutableList, - targetObject: GeneratedObject, + inputMetadata: List, + outputMetadata: GeneratedObject, assetsGenerationDir: File, resourcesGenerationDir: File, - objectBuilder: TypeSpec.Builder, - ): TypeSpec? { + objectBuilder: TypeSpec.Builder + ): MRGenerator.GenerationResult? { val previousFontFiles: List = getPreviousFontFiles( inputMetadata = inputMetadata, - targetObject = targetObject + targetObject = outputMetadata ) val fontFiles: List = if ( - targetObject.isActualObject || targetObject.isTargetObject + outputMetadata.isActualObject || outputMetadata.isTargetObject ) { emptyList() } else { @@ -70,13 +68,12 @@ abstract class FontsGenerator( beforeGenerateResources(objectBuilder, allFontFiles) - val typeSpec = createTypeSpec( + val typeSpec: MRGenerator.GenerationResult = createTypeSpec( inputMetadata = inputMetadata, - generatedObjects = generatedObjects, - targetObject = targetObject, + outputMetadata = outputMetadata, filesSpec = allFontFiles.sortedBy { it.key }, objectBuilder = objectBuilder - ) + ) ?: return null generateResources(resourcesGenerationDir, allFontFiles) @@ -122,17 +119,16 @@ abstract class FontsGenerator( @param keys: names of files like anastasia-regular.ttf */ private fun createTypeSpec( - inputMetadata: MutableList, - generatedObjects: MutableList, - targetObject: GeneratedObject, + inputMetadata: List, + outputMetadata: GeneratedObject, filesSpec: List, objectBuilder: TypeSpec.Builder, - ): TypeSpec? { - if (targetObject.isActual) { + ): MRGenerator.GenerationResult? { + if (outputMetadata.isActual) { objectBuilder.addModifiers(KModifier.ACTUAL) } - if (targetObject.isActualObject || targetObject.isTargetObject) { + if (outputMetadata.isActualObject || outputMetadata.isTargetObject) { extendObjectBodyAtStart(objectBuilder) } @@ -162,7 +158,7 @@ abstract class FontsGenerator( propertyName = propertyName, property = property, inputMetadata = inputMetadata, - targetObject = targetObject + targetObject = outputMetadata ), name = propertyName, data = JsonPrimitive("") @@ -176,11 +172,11 @@ abstract class FontsGenerator( val styleProperty: PropertySpec.Builder = PropertySpec .builder(styleName.decapitalize(), resourceClassName) - if (generatedProperty.isActualProperty){ + if (generatedProperty.isActualProperty) { styleProperty.addModifiers(KModifier.ACTUAL) } - if (targetObject.isActualObject || targetObject.isTargetObject) { + if (outputMetadata.isActualObject || outputMetadata.isTargetObject) { getPropertyInitializer(file)?.let { codeBlock -> styleProperty.initializer(codeBlock) } @@ -200,16 +196,12 @@ abstract class FontsGenerator( extendObjectBodyAtEnd(objectBuilder) - return if (generatedProperties.isNotEmpty()) { - // Add object in metadata with remove expect realisation - generatedObjects.addActual( - targetObject.copy(properties = generatedProperties) - ) + if (generatedProperties.isEmpty()) return null - objectBuilder.build() - } else { - null - } + return MRGenerator.GenerationResult( + typeSpec = objectBuilder.build(), + metadata = outputMetadata.copy(properties = generatedProperties) + ) } private fun addObjectActualOverrideModifier( @@ -246,6 +238,7 @@ abstract class FontsGenerator( property.addModifiers(KModifier.ACTUAL) GeneratedObjectModifier.Actual } + else -> { GeneratedObjectModifier.None } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt index 430bcc729..1107ee424 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt @@ -14,7 +14,6 @@ import dev.icerock.gradle.generator.apple.AppleImagesGenerator import dev.icerock.gradle.generator.common.CommonImagesGenerator import dev.icerock.gradle.generator.js.JsImagesGenerator import dev.icerock.gradle.generator.jvm.JvmImagesGenerator -import dev.icerock.gradle.metadata.addActual import dev.icerock.gradle.metadata.model.GeneratedObject import dev.icerock.gradle.metadata.model.GeneratedObjectModifier import dev.icerock.gradle.metadata.model.GeneratedProperty @@ -47,20 +46,19 @@ abstract class ImagesGenerator( override fun generate( project: Project, - inputMetadata: MutableList, - generatedObjects: MutableList, - targetObject: GeneratedObject, + inputMetadata: List, + outputMetadata: GeneratedObject, assetsGenerationDir: File, resourcesGenerationDir: File, - objectBuilder: TypeSpec.Builder, - ): TypeSpec? { + objectBuilder: TypeSpec.Builder + ): MRGenerator.GenerationResult? { val previousFilesMap: Map> = getPreviousImageFilesMap( inputMetadata = inputMetadata, - targetObject = targetObject + targetObject = outputMetadata ) val imageFileMap: Map> = if ( - targetObject.isActualObject || targetObject.isTargetObject + outputMetadata.isActualObject || outputMetadata.isTargetObject ) { emptyMap() } else { @@ -72,14 +70,13 @@ abstract class ImagesGenerator( beforeGenerateResources(objectBuilder, allImagesMap.keys.sorted()) - val typeSpec: TypeSpec? = createTypeSpec( + val result: MRGenerator.GenerationResult = createTypeSpec( inputMetadata = inputMetadata, - generatedObjects = generatedObjects, - targetObject = targetObject, + targetObject = outputMetadata, fileNames = allImagesMap.keys.sorted(), allImagesMap = allImagesMap, objectBuilder = objectBuilder - ) + ) ?: return null generateResources( assetsGenerationDir = assetsGenerationDir, @@ -89,17 +86,16 @@ abstract class ImagesGenerator( } ) - return typeSpec + return result } private fun createTypeSpec( - inputMetadata: MutableList, - generatedObjects: MutableList, + inputMetadata: List, targetObject: GeneratedObject, fileNames: List, allImagesMap: Map>, objectBuilder: TypeSpec.Builder, - ): TypeSpec? { + ): MRGenerator.GenerationResult? { if (targetObject.isActual) { objectBuilder.addModifiers(KModifier.ACTUAL) } @@ -149,16 +145,12 @@ abstract class ImagesGenerator( extendObjectBodyAtEnd(objectBuilder) - return if (generatedProperties.isNotEmpty()) { - // Add object in metadata with remove expect realisation - generatedObjects.addActual( - targetObject.copy(properties = generatedProperties) - ) + if (generatedProperties.isEmpty()) return null - objectBuilder.build() - } else { - null - } + return MRGenerator.GenerationResult( + typeSpec = objectBuilder.build(), + metadata = targetObject.copy(properties = generatedProperties) + ) } private fun getPropertyMetadata( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/LocalizationGenerator.kt similarity index 82% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/LocalizationGenerator.kt index f6ee86a42..2d4290513 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/LocalizationGenerator.kt @@ -12,38 +12,37 @@ import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.metadata.model.GeneratedObject import dev.icerock.gradle.metadata.model.GeneratedObjectModifier import dev.icerock.gradle.metadata.model.GeneratedProperty -import dev.icerock.gradle.metadata.addActual import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonObject import org.gradle.api.Project import java.io.File -abstract class BaseGenerator : MRGenerator.Generator { +abstract class LocalizationGenerator : MRGenerator.Generator { override fun generate( project: Project, - inputMetadata: MutableList, - generatedObjects: MutableList, - targetObject: GeneratedObject, + inputMetadata: List, + outputMetadata: GeneratedObject, assetsGenerationDir: File, resourcesGenerationDir: File, objectBuilder: TypeSpec.Builder, - ): TypeSpec? { + ): MRGenerator.GenerationResult? { // Read previous languages map from metadata // if target object is expect object or interface return emptyMap() val previousLanguagesMap: Map> = getPreviousLanguagesMap( inputMetadata = inputMetadata, - targetObject = targetObject + targetObject = outputMetadata ) // Read actual resources of target // If target object is actual object: skip read files again // // Structure: language - key - value - val languageMap: Map> = if (targetObject.isActualObject || targetObject.isTargetObject) { - emptyMap() - } else { - loadLanguageMap() - } + val languageMap: Map> = + if (outputMetadata.isActualObject || outputMetadata.isTargetObject) { + emptyMap() + } else { + loadLanguageMap() + } // Sum of previous and target language fields val languagesAllMaps: Map> = getLanguagesAllMaps( @@ -54,14 +53,13 @@ abstract class BaseGenerator : MRGenerator.Generator { beforeGenerateResources(objectBuilder, languagesAllMaps) - val stringsClass = createTypeSpec( + val result: MRGenerator.GenerationResult = createTypeSpec( inputMetadata = inputMetadata, - generatedObjects = generatedObjects, - targetObject = targetObject, + targetObject = outputMetadata, keys = languageKeyValues.keys.toList(), languageMap = languagesAllMaps, objectBuilder = objectBuilder - ) + ) ?: return null languagesAllMaps.forEach { (language: LanguageType, strings: Map) -> generateResources( @@ -71,17 +69,16 @@ abstract class BaseGenerator : MRGenerator.Generator { ) } - return stringsClass + return result } private fun createTypeSpec( - inputMetadata: MutableList, - generatedObjects: MutableList, + inputMetadata: List, targetObject: GeneratedObject, keys: List, languageMap: Map>, objectBuilder: TypeSpec.Builder, - ): TypeSpec? { + ): MRGenerator.GenerationResult? { if (targetObject.isActual) { objectBuilder.addModifiers(KModifier.ACTUAL) } @@ -131,16 +128,13 @@ abstract class BaseGenerator : MRGenerator.Generator { extendObjectBodyAtEnd(objectBuilder) - return if (generatedProperties.isNotEmpty()) { - // Add object in metadata with remove expect realisation - generatedObjects.addActual( - targetObject.copy(properties = generatedProperties) - ) + if (generatedProperties.isEmpty()) return null - objectBuilder.build() - } else { - null - } + // Add object in metadata with remove expect realisation + return MRGenerator.GenerationResult( + typeSpec = objectBuilder.build(), + metadata = targetObject.copy(properties = generatedProperties) + ) } abstract fun getPropertyMetadata( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt index 5d3ce3b34..3c0f539a3 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt @@ -10,10 +10,10 @@ import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.MRVisibility +import dev.icerock.gradle.metadata.getActualInterfaces import dev.icerock.gradle.metadata.model.GeneratedObject import dev.icerock.gradle.metadata.model.GeneratedObjectModifier import dev.icerock.gradle.metadata.model.GeneratorType -import dev.icerock.gradle.metadata.getActualInterfaces import org.gradle.api.Project import org.gradle.api.file.Directory import org.gradle.api.file.FileTree @@ -28,7 +28,6 @@ abstract class MRGenerator( protected open val resourcesGenerationDir: File = settings.resourcesDir.asFile protected open val assetsGenerationDir: File = settings.assetsDir.asFile - internal fun generate() { sourcesGenerationDir.deleteRecursively() resourcesGenerationDir.deleteRecursively() @@ -44,39 +43,11 @@ abstract class MRGenerator( abstract fun generateFileSpec(): FileSpec? - // TODO not used. remove after complete migration of task configuration to Plugin configuration time -// fun apply(project: Project): GenerateMultiplatformResourcesTask { -// //TODO add sourceSetName -// val name: String = project.displayName -// -// val genTask = project.tasks.create( -// "generateMR$name", -// GenerateMultiplatformResourcesTask::class.java -// ) { -// it.inputs.property("mokoSettingsPackageName", settings.packageName) -// it.inputs.property("mokoSettingsClassName", settings.className) -// it.inputs.property("mokoSettingsVisibility", settings.visibility) -// it.inputs.property( -// "mokoSettingsIosLocalizationRegion", -// settings.iosLocalizationRegion -// ) -// } -// -// apply(generationTask = genTask, project = project) -// -// return genTask -// } - protected open fun beforeMRGeneration() = Unit protected open fun afterMRGeneration() = Unit protected abstract fun getMRClassModifiers(): Array -// protected abstract fun apply( -// generationTask: GenerateMultiplatformResourcesTask, -// project: Project, -// ) - protected open fun processMRClass(mrClass: TypeSpec.Builder) {} protected open fun getImports(): List = emptyList() @@ -91,13 +62,12 @@ abstract class MRGenerator( fun generate( project: Project, - inputMetadata: MutableList, - generatedObjects: MutableList, - targetObject: GeneratedObject, + inputMetadata: List, + outputMetadata: GeneratedObject, assetsGenerationDir: File, resourcesGenerationDir: File, objectBuilder: TypeSpec.Builder, - ): TypeSpec? + ): GenerationResult? fun getImports(): List @@ -135,6 +105,7 @@ abstract class MRGenerator( property.addModifiers(KModifier.ACTUAL) GeneratedObjectModifier.Actual } + else -> { GeneratedObjectModifier.None } @@ -146,6 +117,11 @@ abstract class MRGenerator( } } + data class GenerationResult( + val typeSpec: TypeSpec, + val metadata: GeneratedObject + ) + interface SourceSet { val name: String diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt index 0db27949b..47c1d070d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt @@ -38,7 +38,7 @@ private val SOURCE_PLURAL_NODE_NAMES = listOf("plural", "plurals") abstract class PluralsGenerator( private val ownResourcesFileTree: FileTree, private val strictLineBreaks: Boolean -) : BaseGenerator() { +) : LocalizationGenerator() { override val inputFiles: Iterable get() = ownResourcesFileTree.matching { it.include(PLURALS_MASK) }.files diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt index 29bd16642..f3ee6606f 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt @@ -27,7 +27,7 @@ typealias KeyType = String abstract class StringsGenerator( private val resourcesFileTree: FileTree, private val strictLineBreaks: Boolean, -) : BaseGenerator() { +) : LocalizationGenerator() { override val inputFiles: Iterable get() = resourcesFileTree.matching { it.include(STRINGS_MASK) }.files diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt index a22048f78..f1e925730 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt @@ -5,20 +5,16 @@ import com.squareup.kotlinpoet.FileSpec import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.metadata.model.GeneratedObject -import dev.icerock.gradle.metadata.model.GeneratedObjectModifier -import dev.icerock.gradle.metadata.model.GeneratorType import dev.icerock.gradle.metadata.Metadata.createOutputMetadata import dev.icerock.gradle.metadata.Metadata.readInputMetadata -import dev.icerock.gradle.metadata.addActual import dev.icerock.gradle.metadata.getExpectInterfaces import dev.icerock.gradle.metadata.getGeneratorInterfaces import dev.icerock.gradle.metadata.getInterfaceName import dev.icerock.gradle.metadata.isNotEmptyMetadata -import dev.icerock.gradle.metadata.model.GeneratedObjectModifier.Actual -import dev.icerock.gradle.metadata.model.GeneratedObjectModifier.None -import dev.icerock.gradle.metadata.model.GeneratedObjectType.Interface -import dev.icerock.gradle.metadata.model.GeneratedObjectType.Object +import dev.icerock.gradle.metadata.model.GeneratedObject +import dev.icerock.gradle.metadata.model.GeneratedObjectModifier +import dev.icerock.gradle.metadata.model.GeneratedObjectType +import dev.icerock.gradle.metadata.model.GeneratorType import dev.icerock.gradle.metadata.resourcesIsEmpty import dev.icerock.gradle.toModifier import dev.icerock.gradle.utils.targetName @@ -33,39 +29,20 @@ abstract class TargetMRGenerator( generators = generators ) { - // TODO not used. remove after complete migration of task configuration to Plugin configuration time -// override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { -// val name = settings.ownResourcesFileTree.first().targetName -// val genTaskName = "generateMR$name" -// -// val genTask = runCatching { -// project.tasks.getByName(genTaskName) as GenerateMultiplatformResourcesTask -// }.getOrNull() ?: project.tasks.create( -// genTaskName, -// GenerateMultiplatformResourcesTask::class.java -// ) { -// it.generate() -// } -// -// apply(generationTask = genTask, project = project) -// } - override fun getMRClassModifiers(): Array = arrayOf(KModifier.ACTUAL) override fun generateFileSpec(): FileSpec? { - val inputMetadata: MutableList = mutableListOf() - //Read list of generated resources on previous level's - inputMetadata.addAll( - readInputMetadata( - inputMetadataFiles = settings.inputMetadataFiles - ) + val inputMetadata: List = readInputMetadata( + inputMetadataFiles = settings.inputMetadataFiles ) // Check resources for generation: if lower resources is empty // and own resources has no files - skip step if (resourcesIsEmpty(inputMetadata, settings)) return null + val outputMetadata: MutableList = mutableListOf() + // If previous levels has resources, need generate actual objects val needGenerateActual: Boolean = inputMetadata.isNotEmptyMetadata() @@ -88,13 +65,14 @@ abstract class TargetMRGenerator( if (inputMetadata.isNotEmpty()) { generateTargetInterfaces( inputMetadata = inputMetadata, + outputMetadata = outputMetadata, visibilityModifier = settings.visibility.toModifier(), generateActualObject = needGenerateActual, fileSpec = fileSpec ) // Generation of actual interfaces not realised on current level - val expectInterfaces = inputMetadata.getExpectInterfaces() + val expectInterfaces: List = inputMetadata.getExpectInterfaces() expectInterfaces.forEach { expectInterface -> val actualInterfaceTypeSpec: TypeSpec = @@ -104,9 +82,7 @@ abstract class TargetMRGenerator( .build() fileSpec.addType(actualInterfaceTypeSpec) - inputMetadata.addActual( - actualObject = expectInterface.copy(modifier = GeneratedObjectModifier.Actual) - ) + outputMetadata.add(expectInterface.copy(modifier = GeneratedObjectModifier.Actual)) } } @@ -134,18 +110,17 @@ abstract class TargetMRGenerator( ) } - val generatedResourceObjectTypeSpec: TypeSpec? = generator.generate( + val result: GenerationResult? = generator.generate( project = project, inputMetadata = inputMetadata, - generatedObjects = generatedActualObjects, - targetObject = GeneratedObject( + outputMetadata = GeneratedObject( generatorType = generator.type, modifier = if (needGenerateActual) { - Actual + GeneratedObjectModifier.Actual } else { - None + GeneratedObjectModifier.None }, - type = Object, + type = GeneratedObjectType.Object, name = generator.mrObjectName, interfaces = getObjectInterfaces( generatorType = generator.type, @@ -158,23 +133,25 @@ abstract class TargetMRGenerator( objectBuilder = objectBuilder, ) - if (generatedResourceObjectTypeSpec != null) { - mrClassSpec.addType(generatedResourceObjectTypeSpec) + if (result != null) { + mrClassSpec.addType(result.typeSpec) + outputMetadata.add(result.metadata) + generatedActualObjects.add(result.metadata) } } processMRClass(mrClassSpec) - if (generatedActualObjects.isNotEmpty()){ + if (generatedActualObjects.isNotEmpty()) { val mrClass = mrClassSpec.build() fileSpec.addType(mrClass) - inputMetadata.addActual( - actualObject = GeneratedObject( + outputMetadata.add( + GeneratedObject( generatorType = GeneratorType.None, - type = Object, + type = GeneratedObjectType.Object, name = settings.className, - modifier = Actual, + modifier = GeneratedObjectModifier.Actual, objects = generatedActualObjects ) ) @@ -194,7 +171,8 @@ abstract class TargetMRGenerator( } private fun generateTargetInterfaces( - inputMetadata: MutableList, + inputMetadata: List, + outputMetadata: MutableList, visibilityModifier: KModifier, generateActualObject: Boolean, fileSpec: FileSpec.Builder, @@ -206,7 +184,7 @@ abstract class TargetMRGenerator( generators.forEach { generator -> val interfaceName = getInterfaceName( - targetName = targetName, + sourceSetName = targetName, generatorType = generator.type ) @@ -214,18 +192,17 @@ abstract class TargetMRGenerator( TypeSpec.interfaceBuilder(interfaceName) .addModifiers(visibilityModifier) - val generatedResourcesTypeSpec: TypeSpec? = generator.generate( + val result: GenerationResult? = generator.generate( project = project, inputMetadata = inputMetadata, - generatedObjects = inputMetadata, - targetObject = GeneratedObject( + outputMetadata = GeneratedObject( generatorType = generator.type, modifier = if (generateActualObject) { - Actual + GeneratedObjectModifier.Actual } else { - None + GeneratedObjectModifier.None }, - type = Interface, + type = GeneratedObjectType.Interface, name = interfaceName ), assetsGenerationDir = assetsGenerationDir, @@ -233,8 +210,9 @@ abstract class TargetMRGenerator( objectBuilder = resourcesInterfaceBuilder ) - if (generatedResourcesTypeSpec != null) { - fileSpec.addType(generatedResourcesTypeSpec) + if (result != null) { + fileSpec.addType(result.typeSpec) + outputMetadata.add(result.metadata) } } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index d26552b6a..fb1151615 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -17,15 +17,11 @@ import dev.icerock.gradle.generator.PluralsGenerator import dev.icerock.gradle.generator.StringsGenerator import dev.icerock.gradle.metadata.Metadata.createOutputMetadata import dev.icerock.gradle.metadata.Metadata.readInputMetadata -import dev.icerock.gradle.metadata.addActual import dev.icerock.gradle.metadata.getInterfaceName import dev.icerock.gradle.metadata.model.GeneratedObject -import dev.icerock.gradle.metadata.model.GeneratedObjectModifier.Actual -import dev.icerock.gradle.metadata.model.GeneratedObjectModifier.Expect -import dev.icerock.gradle.metadata.model.GeneratedObjectType.Interface -import dev.icerock.gradle.metadata.model.GeneratedObjectType.Object +import dev.icerock.gradle.metadata.model.GeneratedObjectModifier +import dev.icerock.gradle.metadata.model.GeneratedObjectType import dev.icerock.gradle.metadata.model.GeneratorType -import dev.icerock.gradle.metadata.model.GeneratorType.None import dev.icerock.gradle.metadata.resourcesIsEmpty import dev.icerock.gradle.toModifier import dev.icerock.gradle.utils.targetName @@ -34,6 +30,7 @@ import org.gradle.api.file.FileTree class CommonMRGenerator( private val project: Project, + private val sourceSetName: String, settings: Settings, generators: List, ) : MRGenerator( @@ -63,16 +60,9 @@ class CommonMRGenerator( // } override fun generateFileSpec(): FileSpec? { - val inputMetadata: MutableList = mutableListOf() - - //Read list of generated resources on previous level - if (settings.lowerResourcesFileTree.files.any { it.isFile }) { - inputMetadata.addAll( - readInputMetadata( - inputMetadataFiles = settings.inputMetadataFiles - ) - ) - } + val inputMetadata: List = readInputMetadata( + inputMetadataFiles = settings.inputMetadataFiles + ) // If previous level's doesn't has resources for generation // and target resource has no files - skip step @@ -84,35 +74,28 @@ class CommonMRGenerator( ) val visibilityModifier: KModifier = settings.visibility.toModifier() - val generatedObjects = mutableListOf() - if (settings.lowerResourcesFileTree.files.none { it.isFile }) { + val isShouldGenerateExpectObject: Boolean = settings.lowerResourcesFileTree.files + .none { it.isFile } + + val results: List = if (isShouldGenerateExpectObject) { // When lower resources is empty, should generate expect MR object generateExpectMRObjects( inputMetadata = inputMetadata, - generatedObjects = generatedObjects, resourcePackage = settings.packageName, visibilityModifier = visibilityModifier, - fileSpec = fileSpec ) } else { - generatedObjects.addAll(inputMetadata) - // If lower resources has files, when on lower level has expect object and // need to generate actual interface with fields generateActualInterfacesFileSpec( visibilityModifier = visibilityModifier, - generatedObjects = generatedObjects, inputMetadata = inputMetadata, - fileSpec = fileSpec - ) - - createOutputMetadata( - outputMetadataFile = settings.outputMetadataFile, - generatedObjects = generatedObjects ) } + if (results.isEmpty()) return null + generators .flatMap { generator -> generator.getImports() } .plus(getImports()) @@ -120,36 +103,32 @@ class CommonMRGenerator( fileSpec.addImport(className.packageName, className.simpleName) } + results.forEach { fileSpec.addType(it.typeSpec) } createOutputMetadata( outputMetadataFile = settings.outputMetadataFile, - generatedObjects = generatedObjects + generatedObjects = results.map { it.metadata } ) return fileSpec.build() } private fun generateExpectMRObjects( - inputMetadata: MutableList, - generatedObjects: MutableList, + inputMetadata: List, resourcePackage: String, visibilityModifier: KModifier, - fileSpec: Builder, - ) { + ): List { // generated MR class structure: val mrClassSpec: TypeSpec.Builder = TypeSpec.objectBuilder(settings.className) // default: object MR .addModifiers(KModifier.EXPECT) .addModifiers(visibilityModifier) // public/internal - val generatedExpectObjects = mutableListOf() - - generateExpectInterfaces( + val expectInterfaceResults: List = generateExpectInterfaces( visibilityModifier = visibilityModifier, - upperResourcesFileTree = settings.upperResourcesFileTree, - generatedObjects = generatedObjects, - fileSpec = fileSpec + upperResourcesFileTree = settings.upperResourcesFileTree ) + val generatedObjects: MutableList = mutableListOf() generators.forEach { generator: Generator -> val builder: TypeSpec.Builder = TypeSpec @@ -157,25 +136,25 @@ class CommonMRGenerator( .addModifiers(visibilityModifier) // public/internal .addSuperinterface(generator.resourceContainerClass.parameterizedBy(generator.resourceClassName)) - val expectInterfaces: List = generatedObjects.filter { - it.generatorType == generator.type && it.isExpectInterface - } + val expectInterfaces: List = expectInterfaceResults + .filter { it.metadata.generatorType == generator.type } + .map { it.metadata } //Implement interfaces for generated expect object - expectInterfaces.forEach { expectInterface -> - builder.addSuperinterface( - ClassName(packageName = resourcePackage, expectInterface.name) - ) - } + expectInterfaces + .forEach { + builder.addSuperinterface( + ClassName(packageName = resourcePackage, it.name) + ) + } - val generatedResourcesTypeSpec: TypeSpec? = generator.generate( + val result: GenerationResult? = generator.generate( project = project, inputMetadata = inputMetadata, - generatedObjects = generatedExpectObjects, - targetObject = GeneratedObject( + outputMetadata = GeneratedObject( generatorType = generator.type, - modifier = Expect, - type = Object, + modifier = GeneratedObjectModifier.Expect, + type = GeneratedObjectType.Object, name = generator.mrObjectName, interfaces = expectInterfaces.map { it.name } ), @@ -184,95 +163,80 @@ class CommonMRGenerator( objectBuilder = builder ) - if (generatedResourcesTypeSpec != null) { - mrClassSpec.addType(generatedResourcesTypeSpec) + if (result != null) { + mrClassSpec.addType(result.typeSpec) + generatedObjects.add(result.metadata) } } processMRClass(mrClassSpec) - //Create file only if generated expect objects has expect MR object - if (generatedExpectObjects.isNotEmpty()) { - val mrClass: TypeSpec = mrClassSpec.build() - fileSpec.addType(mrClass) + if (generatedObjects.isEmpty()) return expectInterfaceResults + return expectInterfaceResults + GenerationResult( + typeSpec = mrClassSpec.build(), // Metadata: Add generated objects in MR - generatedObjects.add( - GeneratedObject( - generatorType = None, - type = Object, - name = settings.className, - modifier = Expect, - objects = generatedExpectObjects - ) + metadata = GeneratedObject( + generatorType = GeneratorType.None, + type = GeneratedObjectType.Object, + name = settings.className, + modifier = GeneratedObjectModifier.Expect, + objects = generatedObjects ) - } + ) } private fun generateExpectInterfaces( visibilityModifier: KModifier, upperResourcesFileTree: FileTree, - generatedObjects: MutableList, - fileSpec: Builder, - ) { - val expectInterfaces = mutableListOf() - - upperResourcesFileTree.forEach { + ): List { + return upperResourcesFileTree.mapNotNull { file -> val generatorType: GeneratorType = - if (it.path.matches(StringsGenerator.STRINGS_REGEX)) { + if (file.path.matches(StringsGenerator.STRINGS_REGEX)) { GeneratorType.Strings - } else if (it.path.matches(PluralsGenerator.PLURALS_REGEX)) { + } else if (file.path.matches(PluralsGenerator.PLURALS_REGEX)) { GeneratorType.Plurals - } else if (it.path.matches(ColorsGenerator.COLORS_REGEX)) { + } else if (file.path.matches(ColorsGenerator.COLORS_REGEX)) { GeneratorType.Colors - } else if (it.parentFile.name == "images") { + } else if (file.parentFile.name == "images") { GeneratorType.Images - } else if (it.parentFile.name == "files") { + } else if (file.parentFile.name == "files") { GeneratorType.Files - } else if (it.parentFile.name == "fonts") { + } else if (file.parentFile.name == "fonts") { GeneratorType.Fonts - } else if (it.path.matches(AssetsGenerator.ASSETS_REGEX)) { + } else if (file.path.matches(AssetsGenerator.ASSETS_REGEX)) { GeneratorType.Assets - } else return@forEach - - expectInterfaces.add( - GeneratedObject( - generatorType = generatorType, - type = Interface, - modifier = Expect, - name = getInterfaceName( - targetName = it.targetName, - generatorType = generatorType - ) + } else return@mapNotNull null + + GeneratedObject( + generatorType = generatorType, + type = GeneratedObjectType.Interface, + modifier = GeneratedObjectModifier.Expect, + name = getInterfaceName( + sourceSetName = file.targetName, + generatorType = generatorType ) ) - } - - expectInterfaces.distinctBy { it.name }.forEach { expectInterface -> - val resourcesInterface: TypeSpec = - TypeSpec.interfaceBuilder(expectInterface.name) - .addModifiers(visibilityModifier) - .addModifiers(KModifier.EXPECT) - .build() - - fileSpec.addType(resourcesInterface) + }.distinctBy { it.name }.map { expectInterface -> + val resourcesInterface: TypeSpec = TypeSpec.interfaceBuilder(expectInterface.name) + .addModifiers(visibilityModifier) + .addModifiers(KModifier.EXPECT) + .build() - generatedObjects.add(expectInterface) + GenerationResult( + typeSpec = resourcesInterface, + metadata = expectInterface + ) } } private fun generateActualInterfacesFileSpec( - inputMetadata: MutableList, - generatedObjects: MutableList, + inputMetadata: List, visibilityModifier: KModifier, - fileSpec: Builder, - ) { - val targetName: String = - settings.ownResourcesFileTree.files.firstOrNull()?.targetName ?: return - - generators.forEach { generator -> - val interfaceName = getInterfaceName( - targetName = targetName, + ): List { + return generators.mapNotNull { generator -> + val interfaceName: String = getInterfaceName( + sourceSetName = sourceSetName, generatorType = generator.type ) @@ -281,41 +245,19 @@ class CommonMRGenerator( .addModifiers(visibilityModifier) .addModifiers(KModifier.ACTUAL) - val generatedResourcesTypeSpec: TypeSpec? = generator.generate( + generator.generate( project = project, - targetObject = GeneratedObject( + inputMetadata = inputMetadata, + outputMetadata = GeneratedObject( generatorType = generator.type, name = interfaceName, - type = Interface, - modifier = Actual, + type = GeneratedObjectType.Interface, + modifier = GeneratedObjectModifier.Actual, ), - inputMetadata = inputMetadata, - generatedObjects = generatedObjects, assetsGenerationDir = assetsGenerationDir, resourcesGenerationDir = resourcesGenerationDir, objectBuilder = resourcesInterfaceBuilder, ) - - if (generatedResourcesTypeSpec != null) { - fileSpec.addType(generatedResourcesTypeSpec) - } - } - - // Collect generated actual interfaces and replaced expect in metadata - val generatedActualInterfaces: MutableList = mutableListOf() - - inputMetadata.forEach { metadata -> - val hasInGeneratedActual = generatedObjects.firstOrNull { actualMetadata -> - metadata.name == actualMetadata.name - } != null - - if (!hasInGeneratedActual) { - generatedActualInterfaces.add(metadata) - } - } - - generatedActualInterfaces.forEach { actualInterface -> - inputMetadata.addActual(actualInterface) } } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt index 63f99ff28..f42fe4f31 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt @@ -1,10 +1,9 @@ package dev.icerock.gradle.metadata import dev.icerock.gradle.metadata.model.GeneratedObject -import kotlinx.serialization.encodeToString +import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.json.Json import org.gradle.api.file.FileTree -import java.io.BufferedReader import java.io.File object Metadata { @@ -16,7 +15,10 @@ object Metadata { outputMetadataFile.createNewFile() - val generatedJson: String = Json.encodeToString(generatedObjects) + val generatedJson: String = Json.encodeToString( + serializer = ListSerializer(GeneratedObject.serializer()), + value = generatedObjects + ) outputMetadataFile.writeText(generatedJson) } @@ -24,17 +26,12 @@ object Metadata { fun readInputMetadata( inputMetadataFiles: FileTree, ): List { - val generatedObjects = mutableListOf() - - inputMetadataFiles.forEach { inputFile -> - if(inputFile.isDirectory) return@forEach - - val bufferedReader: BufferedReader = File(inputFile.toURI()).bufferedReader() - val inputString: String = bufferedReader.use { it.readText() } - val inputMetadata: List = Json.decodeFromString(inputString) - generatedObjects.addAll(inputMetadata) + return inputMetadataFiles.filter { it.isFile }.flatMap { inputFile -> + val inputString: String = inputFile.readText() + Json.decodeFromString( + deserializer = ListSerializer(GeneratedObject.serializer()), + string = inputString + ) } - - return generatedObjects } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Utils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Utils.kt index 49c5d80b9..9a80f7326 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Utils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Utils.kt @@ -5,12 +5,12 @@ import dev.icerock.gradle.metadata.model.GeneratedObject import dev.icerock.gradle.metadata.model.GeneratorType import dev.icerock.gradle.utils.capitalize -internal fun getInterfaceName(targetName: String, generatorType: GeneratorType): String { - return targetName.capitalize() + generatorType.name.capitalize() +internal fun getInterfaceName(sourceSetName: String, generatorType: GeneratorType): String { + return sourceSetName.capitalize() + generatorType.name.capitalize() } internal fun resourcesIsEmpty( - inputMetadata: MutableList, + inputMetadata: List, settings: Settings, ): Boolean { return inputMetadata.isEmptyMetadata() 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 6eed3f745..ace54d2c1 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 @@ -22,6 +22,7 @@ import dev.icerock.gradle.generator.js.JsMRGenerator import dev.icerock.gradle.generator.jvm.JvmMRGenerator import dev.icerock.gradle.utils.isStrictLineBreaks import org.gradle.api.DefaultTask +import org.gradle.api.GradleException import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.DirectoryProperty import org.gradle.api.file.RegularFileProperty @@ -42,6 +43,9 @@ import org.jetbrains.kotlin.konan.target.KonanTarget @CacheableTask abstract class GenerateMultiplatformResourcesTask : DefaultTask() { + @get:Input + abstract val sourceSetName: Property + @get:InputFiles @get:Classpath abstract val ownResources: ConfigurableFileCollection @@ -101,27 +105,13 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { init { group = "moko-resources" - - onlyIf("generation on Android supported only for main flavor") { - val platform: String = platformType.get() - if (platform != KotlinPlatformType.androidJvm.name) return@onlyIf true - - val flavor: String = androidSourceSetName.get() - flavor in listOf("main", "test", "androidTest") - } } @TaskAction fun generate() { - logger.warn("i $name have ownResources ${ownResources.from}") - logger.warn("i $name have lowerResources ${lowerResources.from}") - logger.warn("i $name have upperResources ${upperResources.from}") - val settings: MRGenerator.Settings = createGeneratorSettings() val features: List> = createGeneratorFeatures(settings) val mrGenerator: MRGenerator = resolveGenerator(settings, features) - - logger.warn("i ${platformType.get()} generator type: ${mrGenerator::class.java.simpleName}") mrGenerator.generate() } @@ -135,7 +125,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { KotlinPlatformType.js -> createJsGenerator(settings, generators) KotlinPlatformType.androidJvm -> createAndroidJvmGenerator(settings, generators) KotlinPlatformType.native -> createNativeGenerator(settings, generators) - KotlinPlatformType.wasm -> error("moko-resources not support wasm target now") + KotlinPlatformType.wasm -> throw GradleException("moko-resources not support wasm target now") } } @@ -178,6 +168,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { ): CommonMRGenerator { return CommonMRGenerator( project = project, + sourceSetName = sourceSetName.get(), settings = settings, generators = generators.map { it.createCommonGenerator() } ) From f955c5c612389618f0cf79c3bdfceaaac6723aed Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Fri, 5 Jan 2024 21:33:00 +0700 Subject: [PATCH 083/352] #535 successful simplified generator with strings --- resources-generator/build.gradle.kts | 8 +- .../gradle/MultiplatformResourcesPlugin.kt | 47 +- .../gradle/configuration/AndroidTarget.kt | 6 +- .../gradle/configuration/AppleTargets.kt | 30 +- .../gradle/configuration/CommonTarget.kt | 58 +- .../icerock/gradle/configuration/JsTarget.kt | 72 +- .../icerock/gradle/configuration/JvmTarget.kt | 50 +- .../dev/icerock/gradle/configuration/Utils.kt | 128 ++-- .../gradle/generator/AssetsGenerator.kt | 644 +++++++++--------- .../gradle/generator/ColorsGenerator.kt | 584 ++++++++-------- .../gradle/generator/FilesGenerator.kt | 444 ++++++------ .../gradle/generator/FontsGenerator.kt | 600 ++++++++-------- .../gradle/generator/ImagesGenerator.kt | 540 +++++++-------- .../icerock/gradle/generator/LanguageType.kt | 5 + .../gradle/generator/LocalizationGenerator.kt | 444 +++++++----- .../icerock/gradle/generator/MRGenerator.kt | 320 +++++---- .../generator/NOPObjectBodyExtendable.kt | 26 +- .../gradle/generator/ObjectBodyExtendable.kt | 24 +- .../gradle/generator/PluralsGenerator.kt | 436 ++++++------ .../generator/ResourceGeneratorFeature.kt | 26 +- .../gradle/generator/StringsGenerator.kt | 396 +++++------ .../gradle/generator/TargetMRGenerator.kt | 482 ++++++------- .../android/AndroidAssetsGenerator.kt | 84 +-- .../android/AndroidColorsGenerator.kt | 170 ++--- .../android/AndroidFilesGenerator.kt | 94 +-- .../android/AndroidFontsGenerator.kt | 100 +-- .../android/AndroidImagesGenerator.kt | 244 +++---- .../generator/android/AndroidMRGenerator.kt | 64 +- .../android/AndroidPluralsGenerator.kt | 156 ++--- .../android/AndroidStringsGenerator.kt | 160 ++--- .../generator/apple/AppleAssetsGenerator.kt | 116 ++-- .../generator/apple/AppleColorsGenerator.kt | 266 ++++---- .../generator/apple/AppleFilesGenerator.kt | 78 +-- .../generator/apple/AppleFontsGenerator.kt | 74 +- .../generator/apple/AppleGeneratorHelper.kt | 56 +- .../generator/apple/AppleImagesGenerator.kt | 212 +++--- .../generator/apple/AppleMRGenerator.kt | 126 ++-- .../generator/apple/ApplePluralsGenerator.kt | 196 +++--- .../generator/apple/AppleStringsGenerator.kt | 130 ++-- .../generator/common/CommonAssetsGenerator.kt | 48 +- .../generator/common/CommonColorsGenerator.kt | 48 +- .../generator/common/CommonFilesGenerator.kt | 44 +- .../generator/common/CommonFontsGenerator.kt | 46 +- .../generator/common/CommonImagesGenerator.kt | 44 +- .../generator/common/CommonMRGenerator.kt | 516 +++++++------- .../common/CommonPluralsGenerator.kt | 42 +- .../common/CommonStringsGenerator.kt | 42 +- .../gradle/generator/js/JsAssetsGenerator.kt | 210 +++--- .../gradle/generator/js/JsColorsGenerator.kt | 96 +-- .../gradle/generator/js/JsFilesGenerator.kt | 124 ++-- .../gradle/generator/js/JsFontsGenerator.kt | 200 +++--- .../gradle/generator/js/JsImagesGenerator.kt | 128 ++-- .../gradle/generator/js/JsMRGenerator.kt | 188 ++--- .../gradle/generator/js/JsPluralsGenerator.kt | 236 +++---- .../gradle/generator/js/JsStringsGenerator.kt | 202 +++--- .../js/StringPluralPropertyGenerator.kt | 184 ++--- .../jsJvmCommon/ColorResourceUtils.kt | 32 +- .../jsJvmCommon/GenerateImageUtil.kt | 44 +- .../generator/jvm/ClassLoaderExtender.kt | 56 +- .../generator/jvm/JvmAssetsGenerator.kt | 114 ++-- .../generator/jvm/JvmColorsGenerator.kt | 62 +- .../gradle/generator/jvm/JvmFilesGenerator.kt | 86 +-- .../gradle/generator/jvm/JvmFontsGenerator.kt | 80 +-- .../generator/jvm/JvmImagesGenerator.kt | 86 +-- .../gradle/generator/jvm/JvmMRGenerator.kt | 174 ++--- .../generator/jvm/JvmPluralsGenerator.kt | 126 ++-- .../gradle/generator/jvm/JvmStringUtils.kt | 26 +- .../generator/jvm/JvmStringsGenerator.kt | 118 ++-- .../dev/icerock/gradle/metadata/Metadata.kt | 74 +- .../icerock/gradle/metadata/MetadataExt.kt | 142 ++-- .../dev/icerock/gradle/metadata/Utils.kt | 36 +- .../gradle/metadata/model/AssetsMetadata.kt | 38 +- .../gradle/metadata/model/GeneratedObject.kt | 98 +-- .../metadata/model/GeneratedObjectModifier.kt | 16 +- .../metadata/model/GeneratedObjectType.kt | 28 +- .../metadata/model/GeneratedProperty.kt | 30 +- .../gradle/metadata/model/GeneratorType.kt | 24 +- .../icerock/gradle/rework/GenerationResult.kt | 13 + .../gradle/rework/PlatformGenerator.kt | 16 + .../gradle/rework/ResourceGenerator.kt | 15 + .../gradle/rework/ResourceTypeGenerator.kt | 183 +++++ .../icerock/gradle/rework/ResourcesFiles.kt | 25 + .../gradle/rework/ResourcesGenerator.kt | 193 ++++++ .../metadata/container/ContainerMetadata.kt | 40 ++ .../metadata/resource/ResourceMetadata.kt | 114 ++++ .../rework/serialization/FileSerializer.kt | 28 + .../string/AndroidStringResourceGenerator.kt | 74 ++ .../string/AppleStringResourceGenerator.kt | 65 ++ .../string/JsStringResourceGenerator.kt | 72 ++ .../string/JvmStringResourceGenerator.kt | 73 ++ .../string/NOPStringResourceGenerator.kt | 24 + .../rework/string/StringResourceGenerator.kt | 90 +++ .../dev/icerock/gradle/rework/string/Utils.kt | 18 + .../GenerateMultiplatformResourcesTask.kt | 312 +++++---- .../gradle/utils/ProcessResourcesUtils.kt | 56 +- .../container/ContainerMetadataTest.kt | 40 ++ .../.run/iosApp.run.xml | 7 - .../gradle.properties | 5 +- .../gradle/wrapper/gradle-wrapper.jar | Bin 62076 -> 63721 bytes .../gradle/wrapper/gradle-wrapper.properties | 3 +- samples/compose-resources-gallery/gradlew | 22 +- .../macosApp/build.gradle.kts | 72 +- .../shared/build.gradle.kts | 36 +- 103 files changed, 7192 insertions(+), 5988 deletions(-) create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/rework/GenerationResult.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/rework/PlatformGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourceTypeGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourcesFiles.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourcesGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/rework/metadata/container/ContainerMetadata.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/rework/metadata/resource/ResourceMetadata.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/rework/serialization/FileSerializer.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/AndroidStringResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/AppleStringResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JsStringResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JvmStringResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/NOPStringResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/StringResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/Utils.kt create mode 100644 resources-generator/src/test/kotlin/dev/icerock/gradle/rework/metadata/container/ContainerMetadataTest.kt delete mode 100644 samples/compose-resources-gallery/.run/iosApp.run.xml diff --git a/resources-generator/build.gradle.kts b/resources-generator/build.gradle.kts index b300c4deb..aad721bc9 100644 --- a/resources-generator/build.gradle.kts +++ b/resources-generator/build.gradle.kts @@ -1,10 +1,10 @@ -import org.jetbrains.kotlin.gradle.dsl.JvmTarget -import org.jetbrains.kotlin.gradle.dsl.KotlinVersion - /* * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.dsl.KotlinVersion + plugins { id("org.jetbrains.kotlin.jvm") version ("1.9.0") id("detekt-convention") @@ -27,6 +27,8 @@ dependencies { implementation(libs.kotlinxSerialization) implementation(libs.apacheCommonsText) implementation(libs.commonsCodec) + + testImplementation(kotlin("test-junit")) } java { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index cf2db1431..f384ed197 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -78,13 +78,9 @@ open class MultiplatformResourcesPlugin : Plugin { mrExtension = mrExtension ) - configureLowerDependencies( - kotlinSourceSet = kotlinSourceSet, - genTask = genTask - ) - configureUpperDependencies( kotlinSourceSet = kotlinSourceSet, + resourcesSourceSetName = kotlinSourceSet.name, resourcesSourceDirectory = resourcesSourceDirectory ) @@ -171,6 +167,11 @@ open class MultiplatformResourcesPlugin : Plugin { } } } + + project.tasks.register("generateMR") { + it.group = "moko-resources" + it.dependsOn(project.tasks.withType()) + } } @OptIn(ExperimentalKotlinGradlePluginApi::class) @@ -274,7 +275,10 @@ open class MultiplatformResourcesPlugin : Plugin { mrExtension: MultiplatformResourcesPluginExtension, ): TaskProvider { val generateTaskName: String = "generateMR" + kotlinSourceSet.name - val generatedMokoResourcesDir = File(project.buildDir, "generated/moko-resources") + val generatedMokoResourcesDir = File( + project.layout.buildDirectory.get().asFile, + "generated/moko-resources" + ) val taskProvider: TaskProvider = project.tasks.register( generateTaskName, @@ -319,29 +323,9 @@ open class MultiplatformResourcesPlugin : Plugin { return taskProvider } - private fun configureLowerDependencies( - kotlinSourceSet: KotlinSourceSet, - genTask: TaskProvider, - ) { - kotlinSourceSet.dependsOnObservable.forAll { dependsSourceSet -> - val resourcesDir: SourceDirectorySet = requireNotNull( - dependsSourceSet.extras[mokoResourcesSourceDirectoryKey()] - ) - - genTask.configure { - val files: Set = resourcesDir.srcDirs - it.lowerResources.from(files) - } - - configureLowerDependencies( - kotlinSourceSet = dependsSourceSet, - genTask = genTask - ) - } - } - private fun configureUpperDependencies( kotlinSourceSet: KotlinSourceSet, + resourcesSourceSetName: String, resourcesSourceDirectory: SourceDirectorySet, ) { kotlinSourceSet.dependsOnObservable.forAll { dependsSourceSet -> @@ -351,11 +335,12 @@ open class MultiplatformResourcesPlugin : Plugin { dependsGenTask.configure { val files: Set = resourcesSourceDirectory.srcDirs - it.upperResources.from(files) + it.upperSourceSets.put(resourcesSourceSetName, kotlinSourceSet.project.files(files)) } configureUpperDependencies( kotlinSourceSet = dependsSourceSet, + resourcesSourceSetName = resourcesSourceSetName, resourcesSourceDirectory = resourcesSourceDirectory ) } @@ -371,11 +356,7 @@ open class MultiplatformResourcesPlugin : Plugin { ) genTask.configure { resourceTask -> - resourceTask.inputMetadataFiles.setFrom( - dependsGenTask.flatMap { - it.outputMetadataFile - } - ) + resourceTask.inputMetadataFiles.from(dependsGenTask.flatMap { it.outputMetadataFile }) } } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AndroidTarget.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AndroidTarget.kt index d3a2e4824..1a15d989b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AndroidTarget.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AndroidTarget.kt @@ -7,9 +7,9 @@ package dev.icerock.gradle.configuration import com.android.build.gradle.BaseExtension import com.android.build.gradle.api.AndroidSourceDirectorySet import com.android.build.gradle.api.AndroidSourceSet -import dev.icerock.gradle.generator.MRGenerator -import dev.icerock.gradle.generator.ResourceGeneratorFeature -import dev.icerock.gradle.generator.android.AndroidMRGenerator +//import dev.icerock.gradle.generator.MRGenerator +//import dev.icerock.gradle.generator.ResourceGeneratorFeature +//import dev.icerock.gradle.generator.android.AndroidMRGenerator import org.gradle.api.Action import org.gradle.api.Project import org.gradle.api.Task diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt index 0be15960a..04ab23616 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt @@ -4,21 +4,21 @@ package dev.icerock.gradle.configuration -import dev.icerock.gradle.generator.MRGenerator -import dev.icerock.gradle.generator.ResourceGeneratorFeature -import dev.icerock.gradle.generator.apple.AppleMRGenerator -import dev.icerock.gradle.tasks.CopyExecutableResourcesToApp -import dev.icerock.gradle.tasks.CopyXCFrameworkResourcesToApp -import org.gradle.api.Project -import org.gradle.kotlin.dsl.register -import org.gradle.kotlin.dsl.withType -import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation -import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractExecutable -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget -import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFrameworkTask -import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink -import org.jetbrains.kotlin.konan.target.HostManager +//import dev.icerock.gradle.generator.MRGenerator +//import dev.icerock.gradle.generator.ResourceGeneratorFeature +//import dev.icerock.gradle.generator.apple.AppleMRGenerator +//import dev.icerock.gradle.tasks.CopyExecutableResourcesToApp +//import dev.icerock.gradle.tasks.CopyXCFrameworkResourcesToApp +//import org.gradle.api.Project +//import org.gradle.kotlin.dsl.register +//import org.gradle.kotlin.dsl.withType +//import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation +//import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractExecutable +//import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation +//import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget +//import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFrameworkTask +//import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink +//import org.jetbrains.kotlin.konan.target.HostManager // TODO not used. remove after complete migration of task configuration to Plugin configuration time //internal fun configureAppleTargetGenerator( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/CommonTarget.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/CommonTarget.kt index 08e643675..18ccadca9 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/CommonTarget.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/CommonTarget.kt @@ -1,30 +1,30 @@ -/* - * Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.configuration - -import dev.icerock.gradle.generator.MRGenerator -import dev.icerock.gradle.generator.ResourceGeneratorFeature -import dev.icerock.gradle.generator.common.CommonMRGenerator -import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask -import org.gradle.kotlin.dsl.withType -import org.jetbrains.kotlin.gradle.plugin.KotlinTarget - -// TODO not used. remove after complete migration of task configuration to Plugin configuration time -//internal fun configureCommonTargetGenerator( -// target: KotlinTarget, -// settings: MRGenerator.Settings, -// features: List>, -//) { -// val generationTask: GenerateMultiplatformResourcesTask = CommonMRGenerator( -// project = target.project, -// settings = settings, -// generators = features.map { it.createCommonGenerator() } -// ).apply(project = target.project,) +///* +// * Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ // -// target.project.tasks -// .withType() -// .matching { it != generationTask } -// .configureEach { it.dependsOn(generationTask) } -//} +//package dev.icerock.gradle.configuration +// +//import dev.icerock.gradle.generator.MRGenerator +//import dev.icerock.gradle.generator.ResourceGeneratorFeature +//import dev.icerock.gradle.generator.common.CommonMRGenerator +//import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask +//import org.gradle.kotlin.dsl.withType +//import org.jetbrains.kotlin.gradle.plugin.KotlinTarget +// +//// TODO not used. remove after complete migration of task configuration to Plugin configuration time +////internal fun configureCommonTargetGenerator( +//// target: KotlinTarget, +//// settings: MRGenerator.Settings, +//// features: List>, +////) { +//// val generationTask: GenerateMultiplatformResourcesTask = CommonMRGenerator( +//// project = target.project, +//// settings = settings, +//// generators = features.map { it.createCommonGenerator() } +//// ).apply(project = target.project,) +//// +//// target.project.tasks +//// .withType() +//// .matching { it != generationTask } +//// .configureEach { it.dependsOn(generationTask) } +////} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JsTarget.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JsTarget.kt index e9f8d2943..6c2a14fbf 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JsTarget.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JsTarget.kt @@ -1,37 +1,37 @@ -/* - * Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.configuration - -import dev.icerock.gradle.generator.MRGenerator -import dev.icerock.gradle.generator.ResourceGeneratorFeature -import dev.icerock.gradle.generator.js.JsMRGenerator -import org.gradle.api.Project -import org.jetbrains.kotlin.gradle.plugin.KotlinTarget -import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget - -// TODO not used. remove after complete migration of task configuration to Plugin configuration time -//internal fun configureJsTargetGenerator( -// target: KotlinTarget, -// settings: MRGenerator.Settings, -// features: List> -//) { -// val project: Project = target.project -// val jsTarget: KotlinJsIrTarget? = target as? KotlinJsIrTarget -// if (jsTarget == null) { -// project.logger.warn("$target is not supported by MOKO Resources") -// return -// } +///* +// * Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ // -// jsTarget.compilations.configureEach { compilation -> -// // TODO rollback ifDepends -//// compilation.defaultSourceSet.ifDependsOn(commonSourceSet) { -// JsMRGenerator( -// project = project, -// settings = settings, -// generators = features.map { it.createJsGenerator() }, -// ).apply(project = project) -//// } -// } -//} +//package dev.icerock.gradle.configuration +// +//import dev.icerock.gradle.generator.MRGenerator +//import dev.icerock.gradle.generator.ResourceGeneratorFeature +//import dev.icerock.gradle.generator.js.JsMRGenerator +//import org.gradle.api.Project +//import org.jetbrains.kotlin.gradle.plugin.KotlinTarget +//import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget +// +//// TODO not used. remove after complete migration of task configuration to Plugin configuration time +////internal fun configureJsTargetGenerator( +//// target: KotlinTarget, +//// settings: MRGenerator.Settings, +//// features: List> +////) { +//// val project: Project = target.project +//// val jsTarget: KotlinJsIrTarget? = target as? KotlinJsIrTarget +//// if (jsTarget == null) { +//// project.logger.warn("$target is not supported by MOKO Resources") +//// return +//// } +//// +//// jsTarget.compilations.configureEach { compilation -> +//// // TODO rollback ifDepends +////// compilation.defaultSourceSet.ifDependsOn(commonSourceSet) { +//// JsMRGenerator( +//// project = project, +//// settings = settings, +//// generators = features.map { it.createJsGenerator() }, +//// ).apply(project = project) +////// } +//// } +////} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JvmTarget.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JvmTarget.kt index 8845bf4a9..a73c56cfd 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JvmTarget.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JvmTarget.kt @@ -1,25 +1,25 @@ -/* - * Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.configuration - -import dev.icerock.gradle.generator.MRGenerator -import dev.icerock.gradle.generator.ResourceGeneratorFeature -import dev.icerock.gradle.generator.jvm.JvmMRGenerator -import org.jetbrains.kotlin.gradle.plugin.KotlinTarget - -// TODO not used. remove after complete migration of task configuration to Plugin configuration time -//internal fun configureJvmTargetGenerator( -// target: KotlinTarget, -// settings: MRGenerator.Settings, -// features: List> -//) { -// JvmMRGenerator( -// project = target.project, -// settings = settings, -// generators = features.map { it.createJvmGenerator() } -// ).apply(project = target.project) -// // TODO fix depends on -//// compilation.defaultSourceSet.ifDependsOn(commonSourceSet) { -//} +///* +// * Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.configuration +// +//import dev.icerock.gradle.generator.MRGenerator +//import dev.icerock.gradle.generator.ResourceGeneratorFeature +//import dev.icerock.gradle.generator.jvm.JvmMRGenerator +//import org.jetbrains.kotlin.gradle.plugin.KotlinTarget +// +//// TODO not used. remove after complete migration of task configuration to Plugin configuration time +////internal fun configureJvmTargetGenerator( +//// target: KotlinTarget, +//// settings: MRGenerator.Settings, +//// features: List> +////) { +//// JvmMRGenerator( +//// project = target.project, +//// settings = settings, +//// generators = features.map { it.createJvmGenerator() } +//// ).apply(project = target.project) +//// // TODO fix depends on +////// compilation.defaultSourceSet.ifDependsOn(commonSourceSet) { +////} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/Utils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/Utils.kt index 1f71cd533..14b35db78 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/Utils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/Utils.kt @@ -1,64 +1,64 @@ -/* - * Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.configuration - -import com.android.build.api.dsl.AndroidSourceSet -import dev.icerock.gradle.generator.MRGenerator -import dev.icerock.gradle.utils.capitalize -import org.gradle.api.provider.Provider -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet -import java.io.File - -internal fun createSourceSet(kotlinSourceSet: KotlinSourceSet): MRGenerator.SourceSet { - return object : MRGenerator.SourceSet { - override val name: String - get() = kotlinSourceSet.name - - override fun addSourceDir(directory: File) { - kotlinSourceSet.kotlin.srcDir(directory) - } - - override fun addResourcesDir(directory: File) { - kotlinSourceSet.resources.srcDir(directory) - } - - override fun addAssetsDir(directory: File) { - // nothing - } - } -} - -internal fun createSourceSet( - androidSourceSet: AndroidSourceSet, -): MRGenerator.SourceSet { - return object : MRGenerator.SourceSet { - override val name: String - get() = "android${androidSourceSet.name.capitalize()}" - - override fun addSourceDir(directory: File) { - androidSourceSet.java.srcDirs(directory) -// targets.configureEach { target -> -// target.compilations.configureEach { compilation -> -// val lazyDirectory = { -// directory.takeIf { -// compilation.kotlinSourceSets.any { compilationSourceSet -> -// compilationSourceSet.isDependsOn(commonSourceSet) -// } -// } -// } -// compilation.defaultSourceSet.kotlin.srcDir(lazyDirectory) -// } -// } - } - - override fun addResourcesDir(directory: File) { - androidSourceSet.res.srcDir(directory) - } - - override fun addAssetsDir(directory: File) { - androidSourceSet.assets.srcDir(directory) - } - } -} +///* +// * Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.configuration +// +//import com.android.build.api.dsl.AndroidSourceSet +//import dev.icerock.gradle.generator.MRGenerator +//import dev.icerock.gradle.utils.capitalize +//import org.gradle.api.provider.Provider +//import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet +//import java.io.File +// +//internal fun createSourceSet(kotlinSourceSet: KotlinSourceSet): MRGenerator.SourceSet { +// return object : MRGenerator.SourceSet { +// override val name: String +// get() = kotlinSourceSet.name +// +// override fun addSourceDir(directory: File) { +// kotlinSourceSet.kotlin.srcDir(directory) +// } +// +// override fun addResourcesDir(directory: File) { +// kotlinSourceSet.resources.srcDir(directory) +// } +// +// override fun addAssetsDir(directory: File) { +// // nothing +// } +// } +//} +// +//internal fun createSourceSet( +// androidSourceSet: AndroidSourceSet, +//): MRGenerator.SourceSet { +// return object : MRGenerator.SourceSet { +// override val name: String +// get() = "android${androidSourceSet.name.capitalize()}" +// +// override fun addSourceDir(directory: File) { +// androidSourceSet.java.srcDirs(directory) +//// targets.configureEach { target -> +//// target.compilations.configureEach { compilation -> +//// val lazyDirectory = { +//// directory.takeIf { +//// compilation.kotlinSourceSets.any { compilationSourceSet -> +//// compilationSourceSet.isDependsOn(commonSourceSet) +//// } +//// } +//// } +//// compilation.defaultSourceSet.kotlin.srcDir(lazyDirectory) +//// } +//// } +// } +// +// override fun addResourcesDir(directory: File) { +// androidSourceSet.res.srcDir(directory) +// } +// +// override fun addAssetsDir(directory: File) { +// androidSourceSet.assets.srcDir(directory) +// } +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt index a0215b093..512ee03c0 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt @@ -1,322 +1,322 @@ -/* - * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.PropertySpec -import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecDirectory -import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecFile -import dev.icerock.gradle.generator.android.AndroidAssetsGenerator -import dev.icerock.gradle.generator.apple.AppleAssetsGenerator -import dev.icerock.gradle.generator.common.CommonAssetsGenerator -import dev.icerock.gradle.generator.js.JsAssetsGenerator -import dev.icerock.gradle.generator.jvm.JvmAssetsGenerator -import dev.icerock.gradle.metadata.model.GeneratedObject -import dev.icerock.gradle.metadata.model.GeneratedObjectModifier -import dev.icerock.gradle.metadata.model.GeneratedProperty -import dev.icerock.gradle.metadata.model.GeneratorType -import dev.icerock.gradle.metadata.objectsWithProperties -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.JsonPrimitive -import kotlinx.serialization.json.decodeFromJsonElement -import org.gradle.api.Project -import org.gradle.api.file.FileTree -import java.io.File - -@Suppress("TooManyFunctions") -abstract class AssetsGenerator( - private val resourcesFileTree: FileTree, -) : MRGenerator.Generator { - override val inputFiles: Iterable - get() = resourcesFileTree.matching { - it.include("assets/**") - } - override val mrObjectName: String = ASSETS_DIR_NAME - override val resourceClassName = ClassName("dev.icerock.moko.resources", "AssetResource") - - override val type: GeneratorType = GeneratorType.Assets - - override fun generate( - project: Project, - inputMetadata: List, - outputMetadata: GeneratedObject, - assetsGenerationDir: File, - resourcesGenerationDir: File, - objectBuilder: TypeSpec.Builder - ): MRGenerator.GenerationResult? { - val previousAssetsFiles: List = getPreviousAssets( - inputMetadata = inputMetadata, - targetObject = outputMetadata - ) - - val previousAssets: List = parseRootContentInner(previousAssetsFiles) - val targetAssets: List = parseRootContentInner(inputFiles) - val allAssets: List = (previousAssets + targetAssets) - - beforeGenerate(objectBuilder, allAssets) - - val result: MRGenerator.GenerationResult = createTypeSpec( - project = project, - inputMetadata = inputMetadata, - targetObject = outputMetadata, - keys = allAssets, - objectBuilder = objectBuilder - ) ?: return null - - generateResources(assetsGenerationDir, resourcesGenerationDir, allAssets) - - return result - } - - private fun createTypeSpec( - project: Project, - inputMetadata: List, - targetObject: GeneratedObject, - keys: List, - objectBuilder: TypeSpec.Builder, - ): MRGenerator.GenerationResult? { - if (targetObject.isActual) { - objectBuilder.addModifiers(KModifier.ACTUAL) - } - - if (targetObject.isActualObject || targetObject.isTargetObject) { - extendObjectBodyAtStart(objectBuilder) - } - - val generatedProperties = mutableListOf() - - createInnerTypeSpec( - project, - inputMetadata = inputMetadata, - generatedProperties = generatedProperties, - targetObject = targetObject, - keys = keys, - objectBuilder = objectBuilder - ) - - extendObjectBodyAtEnd(objectBuilder) - - if (generatedProperties.isEmpty()) return null - - return MRGenerator.GenerationResult( - typeSpec = objectBuilder.build(), - metadata = targetObject.copy(properties = generatedProperties) - ) - } - - private fun getBaseDir(file: File): String { - val relativePathToAssets = file.path.substringAfterLast(ASSETS_DIR_NAME) - val fixedRelativePath = File(relativePathToAssets).path - - val result: String = if (fixedRelativePath.startsWith(File.separatorChar)) { - fixedRelativePath.substring(1) - } else { - fixedRelativePath - } - - return if (File.separatorChar == '/') result else result.replace(File.separatorChar, '/') - } - - private fun parseRootContentInner(folders: Iterable): List { - val res = mutableListOf() - - for (it in folders) { - if (it.isDirectory) { - val files = it.listFiles() - - if (!files.isNullOrEmpty()) { - res.add( - AssetSpecDirectory( - name = it.name, - assets = parseRootContentInner(files.toList()) - ) - ) - } - } else { - // skip empty files, like .DS_Store - if (it.nameWithoutExtension.isEmpty()) { - continue - } - - val pathRelativeToBase = getBaseDir(it) - - if (pathRelativeToBase.contains(PATH_DELIMITER)) { - error("file path can't have this symbol $PATH_DELIMITER. We use them as separators.") - } - - res.add( - AssetSpecFile( - pathRelativeToBase = pathRelativeToBase, - file = it - ) - ) - } - } - - return res - } - - @Suppress("SpreadOperator") - private fun createInnerTypeSpec( - project: Project, - inputMetadata: List, - generatedProperties: MutableList, - targetObject: GeneratedObject, - keys: List, - objectBuilder: TypeSpec.Builder, - ) { - for (specs: AssetSpec in keys) { - if (specs is AssetSpecDirectory) { - val spec = TypeSpec.objectBuilder(specs.name.replace('-', '_')) - - if (targetObject.isActualObject) { - spec.addModifiers(KModifier.ACTUAL) - } - - createInnerTypeSpec( - project, - inputMetadata = inputMetadata, - generatedProperties = generatedProperties, - targetObject = targetObject, - keys = specs.assets, - objectBuilder = spec - ) - - objectBuilder.addType(spec.build()) - } else if (specs is AssetSpecFile) { - val fileName = specs.file.nameWithoutExtension.replace('-', '_') - val styleProperty = PropertySpec.builder(fileName, resourceClassName) - - var generatedProperty = GeneratedProperty( - modifier = GeneratedObjectModifier.None, - name = fileName, - data = JsonPrimitive(specs.file.path) - ) - - if (targetObject.isActualObject || targetObject.isTargetObject) { - // Add modifier for property and setup metadata - generatedProperty = generatedProperty.copy( - modifier = addActualOverrideModifier( - propertyName = fileName, - property = styleProperty, - inputMetadata = inputMetadata, - targetObject = targetObject - ) - ) - - getPropertyInitializer(specs)?.let { codeBlock -> - styleProperty.initializer(codeBlock) - } - } - - generatedProperties.add(generatedProperty) - objectBuilder.addProperty(styleProperty.build()) - } - } - } - - private fun getPreviousAssets( - inputMetadata: List, - targetObject: GeneratedObject, - ): List { - if (!targetObject.isObject || !targetObject.isActual) return emptyList() - - val json = Json - val objectsWithProperties: List = inputMetadata.objectsWithProperties( - targetObject = targetObject - ) - - val files = mutableListOf() - - objectsWithProperties.forEach { generatedObject -> - generatedObject.properties.forEach { property -> - val data = json.decodeFromJsonElement(property.data) - files.add( - File(data.content) - ) - } - } - - return files - } - - override fun getImports(): List = emptyList() - - protected open fun beforeGenerate( - objectBuilder: TypeSpec.Builder, - files: List, - ) { - } - - protected open fun generateResources( - assetsGenerationDir: File, - resourcesGenerationDir: File, - files: List, - ) = Unit - - abstract fun getClassModifiers(): Array - - abstract fun getPropertyModifiers(): Array - - abstract fun getPropertyInitializer(fileSpec: AssetSpecFile): CodeBlock? - - - sealed class AssetSpec { - class AssetSpecDirectory( - val name: String, - val assets: List, - ) : AssetSpec() - - /** - * @param pathRelativeToBase used to copy necessary resources in AssetsGenerator - * @param file is a new name a of copied resource for systems which do not support path with / symbol - */ - class AssetSpecFile( - val pathRelativeToBase: String, - val file: File, - ) : AssetSpec() - } - - class Feature( - private val settings: MRGenerator.Settings, - ) : ResourceGeneratorFeature { - - override fun createCommonGenerator(): AssetsGenerator = CommonAssetsGenerator( - ownResourcesFileTree = settings.ownResourcesFileTree, - ) - - override fun createAppleGenerator(): AssetsGenerator = AppleAssetsGenerator( - ownResourcesFileTree = settings.ownResourcesFileTree, - ) - - override fun createAndroidGenerator(): AssetsGenerator = AndroidAssetsGenerator( - ownResourcesFileTree = settings.ownResourcesFileTree, - ) - - override fun createJvmGenerator(): AssetsGenerator = JvmAssetsGenerator( - ownResourcesFileTree = settings.ownResourcesFileTree, - settings = settings - ) - - override fun createJsGenerator(): AssetsGenerator = JsAssetsGenerator( - ownResourcesFileTree = settings.ownResourcesFileTree, - ) - } - - companion object { - const val ASSETS_DIR_NAME: String = "assets" - - /* - This is used for property name in MR class as well as a replacement of / for platforms which - don't support it like apple. - */ - const val PATH_DELIMITER = '+' - - val ASSETS_REGEX: Regex = "^.*/assets/.*".toRegex() - } -} +///* +// * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator +// +//import com.squareup.kotlinpoet.ClassName +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import com.squareup.kotlinpoet.PropertySpec +//import com.squareup.kotlinpoet.TypeSpec +//import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecDirectory +//import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecFile +//import dev.icerock.gradle.generator.android.AndroidAssetsGenerator +//import dev.icerock.gradle.generator.apple.AppleAssetsGenerator +//import dev.icerock.gradle.generator.common.CommonAssetsGenerator +//import dev.icerock.gradle.generator.js.JsAssetsGenerator +//import dev.icerock.gradle.generator.jvm.JvmAssetsGenerator +//import dev.icerock.gradle.metadata.model.GeneratedObject +//import dev.icerock.gradle.metadata.model.GeneratedObjectModifier +//import dev.icerock.gradle.metadata.model.GeneratedProperty +//import dev.icerock.gradle.metadata.model.GeneratorType +//import dev.icerock.gradle.metadata.objectsWithProperties +//import kotlinx.serialization.json.Json +//import kotlinx.serialization.json.JsonPrimitive +//import kotlinx.serialization.json.decodeFromJsonElement +//import org.gradle.api.Project +//import org.gradle.api.file.FileTree +//import java.io.File +// +//@Suppress("TooManyFunctions") +//abstract class AssetsGenerator( +// private val resourcesFileTree: FileTree, +//) : MRGenerator.Generator { +// override val inputFiles: Iterable +// get() = resourcesFileTree.matching { +// it.include("assets/**") +// } +// override val mrObjectName: String = ASSETS_DIR_NAME +// override val resourceClassName = ClassName("dev.icerock.moko.resources", "AssetResource") +// +// override val type: GeneratorType = GeneratorType.Assets +// +// override fun generateObject( +// project: Project, +// inputMetadata: List, +// outputMetadata: GeneratedObject, +// assetsGenerationDir: File, +// resourcesGenerationDir: File, +// objectBuilder: TypeSpec.Builder +// ): MRGenerator.GenerationResult? { +// val previousAssetsFiles: List = getPreviousAssets( +// inputMetadata = inputMetadata, +// targetObject = outputMetadata +// ) +// +// val previousAssets: List = parseRootContentInner(previousAssetsFiles) +// val targetAssets: List = parseRootContentInner(inputFiles) +// val allAssets: List = (previousAssets + targetAssets) +// +// beforeGenerate(objectBuilder, allAssets) +// +// val result: MRGenerator.GenerationResult = createTypeSpec( +// project = project, +// inputMetadata = inputMetadata, +// targetObject = outputMetadata, +// keys = allAssets, +// objectBuilder = objectBuilder +// ) ?: return null +// +// generateResources(assetsGenerationDir, resourcesGenerationDir, allAssets) +// +// return result +// } +// +// private fun createTypeSpec( +// project: Project, +// inputMetadata: List, +// targetObject: GeneratedObject, +// keys: List, +// objectBuilder: TypeSpec.Builder, +// ): MRGenerator.GenerationResult? { +// if (targetObject.isActual) { +// objectBuilder.addModifiers(KModifier.ACTUAL) +// } +// +// if (targetObject.isActualObject || targetObject.isTargetObject) { +// extendObjectBodyAtStart(objectBuilder) +// } +// +// val generatedProperties = mutableListOf() +// +// createInnerTypeSpec( +// project, +// inputMetadata = inputMetadata, +// generatedProperties = generatedProperties, +// targetObject = targetObject, +// keys = keys, +// objectBuilder = objectBuilder +// ) +// +// extendObjectBodyAtEnd(objectBuilder) +// +// if (generatedProperties.isEmpty()) return null +// +// return MRGenerator.GenerationResult( +// typeSpec = objectBuilder.build(), +// metadata = targetObject.copy(properties = generatedProperties) +// ) +// } +// +// private fun getBaseDir(file: File): String { +// val relativePathToAssets = file.path.substringAfterLast(ASSETS_DIR_NAME) +// val fixedRelativePath = File(relativePathToAssets).path +// +// val result: String = if (fixedRelativePath.startsWith(File.separatorChar)) { +// fixedRelativePath.substring(1) +// } else { +// fixedRelativePath +// } +// +// return if (File.separatorChar == '/') result else result.replace(File.separatorChar, '/') +// } +// +// private fun parseRootContentInner(folders: Iterable): List { +// val res = mutableListOf() +// +// for (it in folders) { +// if (it.isDirectory) { +// val files = it.listFiles() +// +// if (!files.isNullOrEmpty()) { +// res.add( +// AssetSpecDirectory( +// name = it.name, +// assets = parseRootContentInner(files.toList()) +// ) +// ) +// } +// } else { +// // skip empty files, like .DS_Store +// if (it.nameWithoutExtension.isEmpty()) { +// continue +// } +// +// val pathRelativeToBase = getBaseDir(it) +// +// if (pathRelativeToBase.contains(PATH_DELIMITER)) { +// error("file path can't have this symbol $PATH_DELIMITER. We use them as separators.") +// } +// +// res.add( +// AssetSpecFile( +// pathRelativeToBase = pathRelativeToBase, +// file = it +// ) +// ) +// } +// } +// +// return res +// } +// +// @Suppress("SpreadOperator") +// private fun createInnerTypeSpec( +// project: Project, +// inputMetadata: List, +// generatedProperties: MutableList, +// targetObject: GeneratedObject, +// keys: List, +// objectBuilder: TypeSpec.Builder, +// ) { +// for (specs: AssetSpec in keys) { +// if (specs is AssetSpecDirectory) { +// val spec = TypeSpec.objectBuilder(specs.name.replace('-', '_')) +// +// if (targetObject.isActualObject) { +// spec.addModifiers(KModifier.ACTUAL) +// } +// +// createInnerTypeSpec( +// project, +// inputMetadata = inputMetadata, +// generatedProperties = generatedProperties, +// targetObject = targetObject, +// keys = specs.assets, +// objectBuilder = spec +// ) +// +// objectBuilder.addType(spec.build()) +// } else if (specs is AssetSpecFile) { +// val fileName = specs.file.nameWithoutExtension.replace('-', '_') +// val styleProperty = PropertySpec.builder(fileName, resourceClassName) +// +// var generatedProperty = GeneratedProperty( +// modifier = GeneratedObjectModifier.None, +// name = fileName, +// data = JsonPrimitive(specs.file.path) +// ) +// +// if (targetObject.isActualObject || targetObject.isTargetObject) { +// // Add modifier for property and setup metadata +// generatedProperty = generatedProperty.copy( +// modifier = addActualOverrideModifier( +// propertyName = fileName, +// property = styleProperty, +// inputMetadata = inputMetadata, +// targetObject = targetObject +// ) +// ) +// +// getPropertyInitializer(specs)?.let { codeBlock -> +// styleProperty.initializer(codeBlock) +// } +// } +// +// generatedProperties.add(generatedProperty) +// objectBuilder.addProperty(styleProperty.build()) +// } +// } +// } +// +// private fun getPreviousAssets( +// inputMetadata: List, +// targetObject: GeneratedObject, +// ): List { +// if (!targetObject.isObject || !targetObject.isActual) return emptyList() +// +// val json = Json +// val objectsWithProperties: List = inputMetadata.objectsWithProperties( +// targetObject = targetObject +// ) +// +// val files = mutableListOf() +// +// objectsWithProperties.forEach { generatedObject -> +// generatedObject.properties.forEach { property -> +// val data = json.decodeFromJsonElement(property.data) +// files.add( +// File(data.content) +// ) +// } +// } +// +// return files +// } +// +// override fun getImports(): List = emptyList() +// +// protected open fun beforeGenerate( +// objectBuilder: TypeSpec.Builder, +// files: List, +// ) { +// } +// +// protected open fun generateResources( +// assetsGenerationDir: File, +// resourcesGenerationDir: File, +// files: List, +// ) = Unit +// +// abstract fun getClassModifiers(): Array +// +// abstract fun getPropertyModifiers(): Array +// +// abstract fun getPropertyInitializer(fileSpec: AssetSpecFile): CodeBlock? +// +// +// sealed class AssetSpec { +// class AssetSpecDirectory( +// val name: String, +// val assets: List, +// ) : AssetSpec() +// +// /** +// * @param pathRelativeToBase used to copy necessary resources in AssetsGenerator +// * @param file is a new name a of copied resource for systems which do not support path with / symbol +// */ +// class AssetSpecFile( +// val pathRelativeToBase: String, +// val file: File, +// ) : AssetSpec() +// } +// +// class Feature( +// private val settings: MRGenerator.Settings, +// ) : ResourceGeneratorFeature { +// +// override fun createCommonGenerator(): AssetsGenerator = CommonAssetsGenerator( +// ownResourcesFileTree = settings.ownResourcesFileTree, +// ) +// +// override fun createAppleGenerator(): AssetsGenerator = AppleAssetsGenerator( +// ownResourcesFileTree = settings.ownResourcesFileTree, +// ) +// +// override fun createAndroidGenerator(): AssetsGenerator = AndroidAssetsGenerator( +// ownResourcesFileTree = settings.ownResourcesFileTree, +// ) +// +// override fun createJvmGenerator(): AssetsGenerator = JvmAssetsGenerator( +// ownResourcesFileTree = settings.ownResourcesFileTree, +// settings = settings +// ) +// +// override fun createJsGenerator(): AssetsGenerator = JsAssetsGenerator( +// ownResourcesFileTree = settings.ownResourcesFileTree, +// ) +// } +// +// companion object { +// const val ASSETS_DIR_NAME: String = "assets" +// +// /* +// This is used for property name in MR class as well as a replacement of / for platforms which +// don't support it like apple. +// */ +// const val PATH_DELIMITER = '+' +// +// val ASSETS_REGEX: Regex = "^.*/assets/.*".toRegex() +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt index 126210b0b..61545b94b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt @@ -1,292 +1,292 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.PropertySpec -import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.android.AndroidColorsGenerator -import dev.icerock.gradle.generator.apple.AppleColorsGenerator -import dev.icerock.gradle.generator.common.CommonColorsGenerator -import dev.icerock.gradle.generator.js.JsColorsGenerator -import dev.icerock.gradle.generator.jvm.JvmColorsGenerator -import dev.icerock.gradle.metadata.model.GeneratedObject -import dev.icerock.gradle.metadata.model.GeneratedObjectModifier -import dev.icerock.gradle.metadata.model.GeneratedProperty -import dev.icerock.gradle.metadata.model.GeneratorType -import dev.icerock.gradle.metadata.objectsWithProperties -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.decodeFromJsonElement -import kotlinx.serialization.json.encodeToJsonElement -import org.gradle.api.Project -import org.gradle.api.file.FileTree -import org.w3c.dom.Node -import org.w3c.dom.NodeList -import java.io.File -import javax.xml.parsers.DocumentBuilderFactory - -abstract class ColorsGenerator( - private val resourcesFileTree: FileTree, -) : MRGenerator.Generator { - - override val inputFiles: Iterable - get() = resourcesFileTree.matching { it.include("**/colors*.xml") } - override val resourceClassName: ClassName = - ClassName("dev.icerock.moko.resources", "ColorResource") - override val mrObjectName: String = "colors" - - override val type: GeneratorType = GeneratorType.Colors - - open fun beforeGenerate(objectBuilder: TypeSpec.Builder, keys: List) = Unit - - @Suppress("SpreadOperator") - override fun generate( - project: Project, - inputMetadata: List, - outputMetadata: GeneratedObject, - assetsGenerationDir: File, - resourcesGenerationDir: File, - objectBuilder: TypeSpec.Builder, - ): MRGenerator.GenerationResult? { - if (outputMetadata.isActual) { - objectBuilder.addModifiers(KModifier.ACTUAL) - } - - if (outputMetadata.isActualObject || outputMetadata.isTargetObject) { - extendObjectBodyAtStart(objectBuilder) - } - - // Read colors from previous levels, if target interface or expect - // return emptyList() - val previousColors: List = getPreviousColors( - inputMetadata = inputMetadata, - targetObject = outputMetadata - ) - - // Read target colors - val targetColors: List = parseColors() - val allColors: List = (previousColors + targetColors).distinct() - val generatedProperties: MutableList = mutableListOf() - - beforeGenerate(objectBuilder, allColors.map { it.name }) - - val json = Json - - allColors.forEach { colorNode -> - val property = PropertySpec.builder(colorNode.name, resourceClassName) - - // Create metadata property - var generatedProperty = GeneratedProperty( - modifier = GeneratedObjectModifier.None, - name = colorNode.name, - data = json.encodeToJsonElement(colorNode) - ) - - if (outputMetadata.isActualObject || outputMetadata.isTargetObject) { - // Setup property modifier and correction metadata info - generatedProperty = generatedProperty.copy( - modifier = addActualOverrideModifier( - propertyName = colorNode.name, - property = property, - inputMetadata = inputMetadata, - targetObject = outputMetadata - ) - ) - - getPropertyInitializer(colorNode)?.let { - property.initializer(it) - } - } - - objectBuilder.addProperty(property.build()) - generatedProperties.add(generatedProperty) - } - - generateResources( - project = project, - assetsGenerationDir = assetsGenerationDir, - resourcesGenerationDir = resourcesGenerationDir, - colors = allColors - ) - - extendObjectBodyAtEnd(objectBuilder) - - if (generatedProperties.isEmpty()) return null - - return MRGenerator.GenerationResult( - typeSpec = objectBuilder.build(), - metadata = outputMetadata.copy(properties = generatedProperties) - ) - } - - private fun getPreviousColors( - inputMetadata: List, - targetObject: GeneratedObject, - ): List { - if (!targetObject.isObject || !targetObject.isActual) return emptyList() - - val json = Json - val objectsWithProperties: List = inputMetadata.objectsWithProperties( - targetObject = targetObject - ) - - val colors = mutableListOf() - - objectsWithProperties.forEach { generatedObject -> - generatedObject.properties.forEach { property -> - val colorNode = json.decodeFromJsonElement(property.data) - - colors.add(colorNode) - } - } - - return colors - } - - protected open fun getClassModifiers(): Array = emptyArray() - - abstract fun getPropertyInitializer(color: ColorNode): CodeBlock? - - protected open fun generateResources( - project: Project, - assetsGenerationDir: File, - resourcesGenerationDir: File, - colors: List, - ) = Unit - - private fun parseColors(): List { - val colorNodes = mutableListOf() - val colorValues = mutableMapOf() - - fun getColor(color: String?): String? { - return if (color?.startsWith(XmlColorReferencePrefix) == true) { - val colorName = color.replace(XmlColorReferencePrefix, "") - val colorValue = colorValues[colorName] - getColor(colorValue) - } else { - val rawColor = color?.removePrefix("#")?.removePrefix("0x") - if (rawColor?.length == RgbFormatLength) "${rawColor}FF" else rawColor - } - } - - inputFiles.map { file -> - val dbFactory = DocumentBuilderFactory.newInstance() - val dBuilder = dbFactory.newDocumentBuilder() - val doc = dBuilder.parse(file) - - val stringNodes = doc.getElementsByTagName(XmlColorTag) - - for (i in 0 until stringNodes.length) { - val stringNode = stringNodes.item(i) - - val colorName = stringNode.attributes.getNamedItem(XmlNodeAttrColorName).textContent - var lightColor: String? = null - var darkColor: String? = null - var singleColor: String? = null - val nodeList: NodeList = stringNode.childNodes - for (nodeIdx in 0 until nodeList.length) { - val xmlNode: Node = nodeList.item(nodeIdx) - when (xmlNode.nodeName) { - "light" -> { - lightColor = xmlNode.textContent - } - - "dark" -> { - darkColor = xmlNode.textContent - } - - else -> { - singleColor = xmlNode.textContent - singleColor?.let { - colorValues[colorName] = it - } - } - } - } - colorNodes.add( - ColorNode( - colorName, - getColor(lightColor), - getColor(darkColor), - getColor(singleColor) - ) - ) - } - } - - return colorNodes - } - - class Feature( - private val settings: MRGenerator.Settings, - ) : ResourceGeneratorFeature { - override fun createCommonGenerator() = CommonColorsGenerator( - resourcesFileTree = settings.ownResourcesFileTree, - ) - - override fun createAppleGenerator() = AppleColorsGenerator( - resourcesFileTree = settings.ownResourcesFileTree, - ) - - override fun createAndroidGenerator() = AndroidColorsGenerator( - resourcesFileTree = settings.ownResourcesFileTree, - ) - - override fun createJsGenerator(): ColorsGenerator = JsColorsGenerator( - resourcesFileTree = settings.ownResourcesFileTree, - ) - - override fun createJvmGenerator() = JvmColorsGenerator( - resourcesFileTree = settings.ownResourcesFileTree, - mrClassName = settings.className - ) - } - - protected fun replaceColorAlpha(color: String?): String? { - if (color == null) return null - - val alpha: String = if (isRgbFormat(color)) { - DefaultAlpha - } else { - color.substring(color.length - 2, color.length) - } - - return if (isRgbFormat(color)) { - "$alpha$color" - } else { - "$alpha${color.removeRange(color.length - 2, color.length)}" - } - } - - private fun isRgbFormat(color: String): Boolean = color.length == RgbFormatLength - - companion object { - internal const val XmlColorTag = "color" - internal const val XmlNodeAttrColorName = "name" - internal const val XmlColorReferencePrefix = "@color/" - internal const val RgbFormatLength = 6 - internal const val DefaultAlpha = "FF" - - val COLORS_REGEX: Regex = "^.*/colors.*.xml".toRegex() - } -} - -@Serializable -data class ColorNode( - @SerialName("name") - val name: String, - @SerialName("lightColor") - val lightColor: String?, // as rgba - @SerialName("darkColor") - val darkColor: String?, // as rgba - @SerialName("singleColor") - val singleColor: String?, // as rgba -) { - fun isThemed(): Boolean = lightColor != null && darkColor != null -} +///* +// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator +// +//import com.squareup.kotlinpoet.ClassName +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import com.squareup.kotlinpoet.PropertySpec +//import com.squareup.kotlinpoet.TypeSpec +//import dev.icerock.gradle.generator.android.AndroidColorsGenerator +//import dev.icerock.gradle.generator.apple.AppleColorsGenerator +//import dev.icerock.gradle.generator.common.CommonColorsGenerator +//import dev.icerock.gradle.generator.js.JsColorsGenerator +//import dev.icerock.gradle.generator.jvm.JvmColorsGenerator +//import dev.icerock.gradle.metadata.model.GeneratedObject +//import dev.icerock.gradle.metadata.model.GeneratedObjectModifier +//import dev.icerock.gradle.metadata.model.GeneratedProperty +//import dev.icerock.gradle.metadata.model.GeneratorType +//import dev.icerock.gradle.metadata.objectsWithProperties +//import kotlinx.serialization.SerialName +//import kotlinx.serialization.Serializable +//import kotlinx.serialization.json.Json +//import kotlinx.serialization.json.decodeFromJsonElement +//import kotlinx.serialization.json.encodeToJsonElement +//import org.gradle.api.Project +//import org.gradle.api.file.FileTree +//import org.w3c.dom.Node +//import org.w3c.dom.NodeList +//import java.io.File +//import javax.xml.parsers.DocumentBuilderFactory +// +//abstract class ColorsGenerator( +// private val resourcesFileTree: FileTree, +//) : MRGenerator.Generator { +// +// override val inputFiles: Iterable +// get() = resourcesFileTree.matching { it.include("**/colors*.xml") } +// override val resourceClassName: ClassName = +// ClassName("dev.icerock.moko.resources", "ColorResource") +// override val mrObjectName: String = "colors" +// +// override val type: GeneratorType = GeneratorType.Colors +// +// open fun beforeGenerate(objectBuilder: TypeSpec.Builder, keys: List) = Unit +// +// @Suppress("SpreadOperator") +// override fun generateObject( +// project: Project, +// inputMetadata: List, +// outputMetadata: GeneratedObject, +// assetsGenerationDir: File, +// resourcesGenerationDir: File, +// objectBuilder: TypeSpec.Builder, +// ): MRGenerator.GenerationResult? { +// if (outputMetadata.isActual) { +// objectBuilder.addModifiers(KModifier.ACTUAL) +// } +// +// if (outputMetadata.isActualObject || outputMetadata.isTargetObject) { +// extendObjectBodyAtStart(objectBuilder) +// } +// +// // Read colors from previous levels, if target interface or expect +// // return emptyList() +// val previousColors: List = getPreviousColors( +// inputMetadata = inputMetadata, +// targetObject = outputMetadata +// ) +// +// // Read target colors +// val targetColors: List = parseColors() +// val allColors: List = (previousColors + targetColors).distinct() +// val generatedProperties: MutableList = mutableListOf() +// +// beforeGenerate(objectBuilder, allColors.map { it.name }) +// +// val json = Json +// +// allColors.forEach { colorNode -> +// val property = PropertySpec.builder(colorNode.name, resourceClassName) +// +// // Create metadata property +// var generatedProperty = GeneratedProperty( +// modifier = GeneratedObjectModifier.None, +// name = colorNode.name, +// data = json.encodeToJsonElement(colorNode) +// ) +// +// if (outputMetadata.isActualObject || outputMetadata.isTargetObject) { +// // Setup property modifier and correction metadata info +// generatedProperty = generatedProperty.copy( +// modifier = addActualOverrideModifier( +// propertyName = colorNode.name, +// property = property, +// inputMetadata = inputMetadata, +// targetObject = outputMetadata +// ) +// ) +// +// getPropertyInitializer(colorNode)?.let { +// property.initializer(it) +// } +// } +// +// objectBuilder.addProperty(property.build()) +// generatedProperties.add(generatedProperty) +// } +// +// generateResources( +// project = project, +// assetsGenerationDir = assetsGenerationDir, +// resourcesGenerationDir = resourcesGenerationDir, +// colors = allColors +// ) +// +// extendObjectBodyAtEnd(objectBuilder) +// +// if (generatedProperties.isEmpty()) return null +// +// return MRGenerator.GenerationResult( +// typeSpec = objectBuilder.build(), +// metadata = outputMetadata.copy(properties = generatedProperties) +// ) +// } +// +// private fun getPreviousColors( +// inputMetadata: List, +// targetObject: GeneratedObject, +// ): List { +// if (!targetObject.isObject || !targetObject.isActual) return emptyList() +// +// val json = Json +// val objectsWithProperties: List = inputMetadata.objectsWithProperties( +// targetObject = targetObject +// ) +// +// val colors = mutableListOf() +// +// objectsWithProperties.forEach { generatedObject -> +// generatedObject.properties.forEach { property -> +// val colorNode = json.decodeFromJsonElement(property.data) +// +// colors.add(colorNode) +// } +// } +// +// return colors +// } +// +// protected open fun getClassModifiers(): Array = emptyArray() +// +// abstract fun getPropertyInitializer(color: ColorNode): CodeBlock? +// +// protected open fun generateResources( +// project: Project, +// assetsGenerationDir: File, +// resourcesGenerationDir: File, +// colors: List, +// ) = Unit +// +// private fun parseColors(): List { +// val colorNodes = mutableListOf() +// val colorValues = mutableMapOf() +// +// fun getColor(color: String?): String? { +// return if (color?.startsWith(XmlColorReferencePrefix) == true) { +// val colorName = color.replace(XmlColorReferencePrefix, "") +// val colorValue = colorValues[colorName] +// getColor(colorValue) +// } else { +// val rawColor = color?.removePrefix("#")?.removePrefix("0x") +// if (rawColor?.length == RgbFormatLength) "${rawColor}FF" else rawColor +// } +// } +// +// inputFiles.map { file -> +// val dbFactory = DocumentBuilderFactory.newInstance() +// val dBuilder = dbFactory.newDocumentBuilder() +// val doc = dBuilder.parse(file) +// +// val stringNodes = doc.getElementsByTagName(XmlColorTag) +// +// for (i in 0 until stringNodes.length) { +// val stringNode = stringNodes.item(i) +// +// val colorName = stringNode.attributes.getNamedItem(XmlNodeAttrColorName).textContent +// var lightColor: String? = null +// var darkColor: String? = null +// var singleColor: String? = null +// val nodeList: NodeList = stringNode.childNodes +// for (nodeIdx in 0 until nodeList.length) { +// val xmlNode: Node = nodeList.item(nodeIdx) +// when (xmlNode.nodeName) { +// "light" -> { +// lightColor = xmlNode.textContent +// } +// +// "dark" -> { +// darkColor = xmlNode.textContent +// } +// +// else -> { +// singleColor = xmlNode.textContent +// singleColor?.let { +// colorValues[colorName] = it +// } +// } +// } +// } +// colorNodes.add( +// ColorNode( +// colorName, +// getColor(lightColor), +// getColor(darkColor), +// getColor(singleColor) +// ) +// ) +// } +// } +// +// return colorNodes +// } +// +// class Feature( +// private val settings: MRGenerator.Settings, +// ) : ResourceGeneratorFeature { +// override fun createCommonGenerator() = CommonColorsGenerator( +// resourcesFileTree = settings.ownResourcesFileTree, +// ) +// +// override fun createAppleGenerator() = AppleColorsGenerator( +// resourcesFileTree = settings.ownResourcesFileTree, +// ) +// +// override fun createAndroidGenerator() = AndroidColorsGenerator( +// resourcesFileTree = settings.ownResourcesFileTree, +// ) +// +// override fun createJsGenerator(): ColorsGenerator = JsColorsGenerator( +// resourcesFileTree = settings.ownResourcesFileTree, +// ) +// +// override fun createJvmGenerator() = JvmColorsGenerator( +// resourcesFileTree = settings.ownResourcesFileTree, +// mrClassName = settings.className +// ) +// } +// +// protected fun replaceColorAlpha(color: String?): String? { +// if (color == null) return null +// +// val alpha: String = if (isRgbFormat(color)) { +// DefaultAlpha +// } else { +// color.substring(color.length - 2, color.length) +// } +// +// return if (isRgbFormat(color)) { +// "$alpha$color" +// } else { +// "$alpha${color.removeRange(color.length - 2, color.length)}" +// } +// } +// +// private fun isRgbFormat(color: String): Boolean = color.length == RgbFormatLength +// +// companion object { +// internal const val XmlColorTag = "color" +// internal const val XmlNodeAttrColorName = "name" +// internal const val XmlColorReferencePrefix = "@color/" +// internal const val RgbFormatLength = 6 +// internal const val DefaultAlpha = "FF" +// +// val COLORS_REGEX: Regex = "^.*/colors.*.xml".toRegex() +// } +//} +// +//@Serializable +//data class ColorNode( +// @SerialName("name") +// val name: String, +// @SerialName("lightColor") +// val lightColor: String?, // as rgba +// @SerialName("darkColor") +// val darkColor: String?, // as rgba +// @SerialName("singleColor") +// val singleColor: String?, // as rgba +//) { +// fun isThemed(): Boolean = lightColor != null && darkColor != null +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt index adb366e29..0a292c9d0 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt @@ -1,222 +1,222 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.PropertySpec -import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.android.AndroidFilesGenerator -import dev.icerock.gradle.generator.apple.AppleFilesGenerator -import dev.icerock.gradle.generator.common.CommonFilesGenerator -import dev.icerock.gradle.generator.js.JsFilesGenerator -import dev.icerock.gradle.generator.jvm.JvmFilesGenerator -import dev.icerock.gradle.metadata.model.GeneratedObject -import dev.icerock.gradle.metadata.model.GeneratedObjectModifier -import dev.icerock.gradle.metadata.model.GeneratedProperty -import dev.icerock.gradle.metadata.model.GeneratorType -import dev.icerock.gradle.metadata.objectsWithProperties -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.JsonPrimitive -import kotlinx.serialization.json.decodeFromJsonElement -import org.gradle.api.Project -import org.gradle.api.file.FileTree -import java.io.File - -abstract class FilesGenerator( - private val resourceFiles: FileTree, -) : MRGenerator.Generator { - - override val inputFiles: Iterable - get() = resourceFiles.matching { it.include("files/**") } - override val resourceClassName = ClassName("dev.icerock.moko.resources", "FileResource") - override val mrObjectName: String = "files" - - override val type: GeneratorType = GeneratorType.Files - - override fun generate( - project: Project, - inputMetadata: List, - outputMetadata: GeneratedObject, - assetsGenerationDir: File, - resourcesGenerationDir: File, - objectBuilder: TypeSpec.Builder - ): MRGenerator.GenerationResult? { - val previousFilesSpec: List = getPreviousFiles( - inputMetadata = inputMetadata, - targetObject = outputMetadata - ) - - val targetFilesSpecs: List = if ( - outputMetadata.isActualObject || outputMetadata.isTargetObject - ) { - emptyList() - } else { - inputFiles.getFileSpecList() - } - - val allFilesSpecs = (previousFilesSpec + targetFilesSpecs).distinctBy { it.key } - - beforeGenerate(objectBuilder, allFilesSpecs) - - val result: MRGenerator.GenerationResult = createTypeSpec( - inputMetadata = inputMetadata, - targetObject = outputMetadata, - keys = allFilesSpecs, - objectBuilder = objectBuilder - ) ?: return null - - generateResources( - resourcesGenerationDir = resourcesGenerationDir, - files = allFilesSpecs - ) - - return result - } - - private fun Iterable.getFileSpecList(): List { - return this.map { file -> - FileSpec( - key = processKey(file.nameWithoutExtension), - file = file - ) - }.sortedBy { it.key } - } - - private fun getPreviousFiles( - inputMetadata: List, - targetObject: GeneratedObject, - ): List { - if (!targetObject.isObject || !targetObject.isActual) return emptyList() - - val json = Json - val objectsWithProperties: List = inputMetadata.objectsWithProperties( - targetObject = targetObject - ) - - val files = mutableListOf() - - objectsWithProperties.forEach { generatedObject -> - generatedObject.properties.forEach { property -> - val data = json.decodeFromJsonElement(property.data) - files.add( - File(data.content) - ) - } - } - - return files.getFileSpecList() - } - - private fun createTypeSpec( - inputMetadata: List, - targetObject: GeneratedObject, - keys: List, - objectBuilder: TypeSpec.Builder, - ): MRGenerator.GenerationResult? { - if (targetObject.isActual) { - objectBuilder.addModifiers(KModifier.ACTUAL) - } - - if (targetObject.isActualObject || targetObject.isTargetObject) { - extendObjectBodyAtStart(objectBuilder) - } - - val generatedProperties = mutableListOf() - - keys.forEach { fileSpec -> - val property = PropertySpec.builder(fileSpec.key, resourceClassName) - - var generatedProperty = GeneratedProperty( - modifier = GeneratedObjectModifier.None, - name = fileSpec.key, - data = JsonPrimitive(fileSpec.file.path) - ) - - if (targetObject.isActualObject || targetObject.isTargetObject) { - // Add modifier for property and setup metadata - generatedProperty = generatedProperty.copy( - modifier = addActualOverrideModifier( - propertyName = fileSpec.key, - property = property, - inputMetadata = inputMetadata, - targetObject = targetObject - ) - ) - - getPropertyInitializer(fileSpec)?.let { - property.initializer(it) - } - } - - objectBuilder.addProperty(property.build()) - generatedProperties.add(generatedProperty) - } - - extendObjectBodyAtEnd(objectBuilder) - - if (generatedProperties.isEmpty()) return null - - return MRGenerator.GenerationResult( - typeSpec = objectBuilder.build(), - metadata = targetObject.copy(properties = generatedProperties) - ) - } - - override fun getImports(): List = emptyList() - - protected open fun beforeGenerate( - objectBuilder: TypeSpec.Builder, - files: List, - ) = Unit - - protected open fun generateResources( - resourcesGenerationDir: File, - files: List, - ) = Unit - - private fun processKey(key: String): String { - return key.replace("-", "_") - } - - abstract fun getClassModifiers(): Array - - abstract fun getPropertyModifiers(): Array - - abstract fun getPropertyInitializer(fileSpec: FileSpec): CodeBlock? - - data class FileSpec( - val key: String, - val file: File, - ) - - class Feature( - private val settings: MRGenerator.Settings, - ) : ResourceGeneratorFeature { - - override fun createCommonGenerator(): FilesGenerator = CommonFilesGenerator( - ownInputFileTree = settings.ownResourcesFileTree, - ) - - override fun createAppleGenerator(): FilesGenerator = AppleFilesGenerator( - ownInputFileTree = settings.ownResourcesFileTree, - ) - - override fun createAndroidGenerator(): FilesGenerator = AndroidFilesGenerator( - ownInputFileTree = settings.ownResourcesFileTree, - androidRClassPackage = settings.androidRClassPackage, - ) - - override fun createJsGenerator(): FilesGenerator = JsFilesGenerator( - ownInputFileTree = settings.ownResourcesFileTree, - ) - - override fun createJvmGenerator(): FilesGenerator = JvmFilesGenerator( - ownInputFileTree = settings.ownResourcesFileTree, - settings = settings - ) - } -} +///* +// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator +// +//import com.squareup.kotlinpoet.ClassName +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import com.squareup.kotlinpoet.PropertySpec +//import com.squareup.kotlinpoet.TypeSpec +//import dev.icerock.gradle.generator.android.AndroidFilesGenerator +//import dev.icerock.gradle.generator.apple.AppleFilesGenerator +//import dev.icerock.gradle.generator.common.CommonFilesGenerator +//import dev.icerock.gradle.generator.js.JsFilesGenerator +//import dev.icerock.gradle.generator.jvm.JvmFilesGenerator +//import dev.icerock.gradle.metadata.model.GeneratedObject +//import dev.icerock.gradle.metadata.model.GeneratedObjectModifier +//import dev.icerock.gradle.metadata.model.GeneratedProperty +//import dev.icerock.gradle.metadata.model.GeneratorType +//import dev.icerock.gradle.metadata.objectsWithProperties +//import kotlinx.serialization.json.Json +//import kotlinx.serialization.json.JsonPrimitive +//import kotlinx.serialization.json.decodeFromJsonElement +//import org.gradle.api.Project +//import org.gradle.api.file.FileTree +//import java.io.File +// +//abstract class FilesGenerator( +// private val resourceFiles: FileTree, +//) : MRGenerator.Generator { +// +// override val inputFiles: Iterable +// get() = resourceFiles.matching { it.include("files/**") } +// override val resourceClassName = ClassName("dev.icerock.moko.resources", "FileResource") +// override val mrObjectName: String = "files" +// +// override val type: GeneratorType = GeneratorType.Files +// +// override fun generateObject( +// project: Project, +// inputMetadata: List, +// outputMetadata: GeneratedObject, +// assetsGenerationDir: File, +// resourcesGenerationDir: File, +// objectBuilder: TypeSpec.Builder +// ): MRGenerator.GenerationResult? { +// val previousFilesSpec: List = getPreviousFiles( +// inputMetadata = inputMetadata, +// targetObject = outputMetadata +// ) +// +// val targetFilesSpecs: List = if ( +// outputMetadata.isActualObject || outputMetadata.isTargetObject +// ) { +// emptyList() +// } else { +// inputFiles.getFileSpecList() +// } +// +// val allFilesSpecs = (previousFilesSpec + targetFilesSpecs).distinctBy { it.key } +// +// beforeGenerate(objectBuilder, allFilesSpecs) +// +// val result: MRGenerator.GenerationResult = createTypeSpec( +// inputMetadata = inputMetadata, +// targetObject = outputMetadata, +// keys = allFilesSpecs, +// objectBuilder = objectBuilder +// ) ?: return null +// +// generateResources( +// resourcesGenerationDir = resourcesGenerationDir, +// files = allFilesSpecs +// ) +// +// return result +// } +// +// private fun Iterable.getFileSpecList(): List { +// return this.map { file -> +// FileSpec( +// key = processKey(file.nameWithoutExtension), +// file = file +// ) +// }.sortedBy { it.key } +// } +// +// private fun getPreviousFiles( +// inputMetadata: List, +// targetObject: GeneratedObject, +// ): List { +// if (!targetObject.isObject || !targetObject.isActual) return emptyList() +// +// val json = Json +// val objectsWithProperties: List = inputMetadata.objectsWithProperties( +// targetObject = targetObject +// ) +// +// val files = mutableListOf() +// +// objectsWithProperties.forEach { generatedObject -> +// generatedObject.properties.forEach { property -> +// val data = json.decodeFromJsonElement(property.data) +// files.add( +// File(data.content) +// ) +// } +// } +// +// return files.getFileSpecList() +// } +// +// private fun createTypeSpec( +// inputMetadata: List, +// targetObject: GeneratedObject, +// keys: List, +// objectBuilder: TypeSpec.Builder, +// ): MRGenerator.GenerationResult? { +// if (targetObject.isActual) { +// objectBuilder.addModifiers(KModifier.ACTUAL) +// } +// +// if (targetObject.isActualObject || targetObject.isTargetObject) { +// extendObjectBodyAtStart(objectBuilder) +// } +// +// val generatedProperties = mutableListOf() +// +// keys.forEach { fileSpec -> +// val property = PropertySpec.builder(fileSpec.key, resourceClassName) +// +// var generatedProperty = GeneratedProperty( +// modifier = GeneratedObjectModifier.None, +// name = fileSpec.key, +// data = JsonPrimitive(fileSpec.file.path) +// ) +// +// if (targetObject.isActualObject || targetObject.isTargetObject) { +// // Add modifier for property and setup metadata +// generatedProperty = generatedProperty.copy( +// modifier = addActualOverrideModifier( +// propertyName = fileSpec.key, +// property = property, +// inputMetadata = inputMetadata, +// targetObject = targetObject +// ) +// ) +// +// getPropertyInitializer(fileSpec)?.let { +// property.initializer(it) +// } +// } +// +// objectBuilder.addProperty(property.build()) +// generatedProperties.add(generatedProperty) +// } +// +// extendObjectBodyAtEnd(objectBuilder) +// +// if (generatedProperties.isEmpty()) return null +// +// return MRGenerator.GenerationResult( +// typeSpec = objectBuilder.build(), +// metadata = targetObject.copy(properties = generatedProperties) +// ) +// } +// +// override fun getImports(): List = emptyList() +// +// protected open fun beforeGenerate( +// objectBuilder: TypeSpec.Builder, +// files: List, +// ) = Unit +// +// protected open fun generateResources( +// resourcesGenerationDir: File, +// files: List, +// ) = Unit +// +// private fun processKey(key: String): String { +// return key.replace("-", "_") +// } +// +// abstract fun getClassModifiers(): Array +// +// abstract fun getPropertyModifiers(): Array +// +// abstract fun getPropertyInitializer(fileSpec: FileSpec): CodeBlock? +// +// data class FileSpec( +// val key: String, +// val file: File, +// ) +// +// class Feature( +// private val settings: MRGenerator.Settings, +// ) : ResourceGeneratorFeature { +// +// override fun createCommonGenerator(): FilesGenerator = CommonFilesGenerator( +// ownInputFileTree = settings.ownResourcesFileTree, +// ) +// +// override fun createAppleGenerator(): FilesGenerator = AppleFilesGenerator( +// ownInputFileTree = settings.ownResourcesFileTree, +// ) +// +// override fun createAndroidGenerator(): FilesGenerator = AndroidFilesGenerator( +// ownInputFileTree = settings.ownResourcesFileTree, +// androidRClassPackage = settings.androidRClassPackage, +// ) +// +// override fun createJsGenerator(): FilesGenerator = JsFilesGenerator( +// ownInputFileTree = settings.ownResourcesFileTree, +// ) +// +// override fun createJvmGenerator(): FilesGenerator = JvmFilesGenerator( +// ownInputFileTree = settings.ownResourcesFileTree, +// settings = settings +// ) +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt index a349ba221..bc5042a40 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt @@ -1,300 +1,300 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.PropertySpec -import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.android.AndroidFontsGenerator -import dev.icerock.gradle.generator.apple.AppleFontsGenerator -import dev.icerock.gradle.generator.common.CommonFontsGenerator -import dev.icerock.gradle.generator.js.JsFontsGenerator -import dev.icerock.gradle.generator.jvm.JvmFontsGenerator -import dev.icerock.gradle.metadata.getActualInterfaces -import dev.icerock.gradle.metadata.model.GeneratedObject -import dev.icerock.gradle.metadata.model.GeneratedObjectModifier -import dev.icerock.gradle.metadata.model.GeneratedProperty -import dev.icerock.gradle.metadata.model.GeneratorType -import dev.icerock.gradle.metadata.objectsWithProperties -import dev.icerock.gradle.utils.decapitalize -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.JsonObject -import kotlinx.serialization.json.JsonPrimitive -import kotlinx.serialization.json.decodeFromJsonElement -import org.gradle.api.Project -import org.gradle.api.file.FileTree -import java.io.File - -abstract class FontsGenerator( - private val resourcesFileTree: FileTree, -) : MRGenerator.Generator { - - override val inputFiles: Iterable - get() = resourcesFileTree.matching { - it.include("fonts/**.ttf", "fonts/**.otf") - } - override val resourceClassName = ClassName("dev.icerock.moko.resources", "FontResource") - override val mrObjectName: String = "fonts" - - override val type: GeneratorType = GeneratorType.Fonts - - override fun generate( - project: Project, - inputMetadata: List, - outputMetadata: GeneratedObject, - assetsGenerationDir: File, - resourcesGenerationDir: File, - objectBuilder: TypeSpec.Builder - ): MRGenerator.GenerationResult? { - val previousFontFiles: List = getPreviousFontFiles( - inputMetadata = inputMetadata, - targetObject = outputMetadata - ) - - val fontFiles: List = if ( - outputMetadata.isActualObject || outputMetadata.isTargetObject - ) { - emptyList() - } else { - inputFiles.getFontFiles() - } - - // Sum of all fonts files and filter his on unical fonts - val allFontFiles: List = (previousFontFiles + fontFiles).distinctBy { it.key } - - beforeGenerateResources(objectBuilder, allFontFiles) - - val typeSpec: MRGenerator.GenerationResult = createTypeSpec( - inputMetadata = inputMetadata, - outputMetadata = outputMetadata, - filesSpec = allFontFiles.sortedBy { it.key }, - objectBuilder = objectBuilder - ) ?: return null - - generateResources(resourcesGenerationDir, allFontFiles) - - return typeSpec - } - - private fun getPreviousFontFiles( - inputMetadata: List, - targetObject: GeneratedObject, - ): List { - if (!targetObject.isObject || !targetObject.isActual) return emptyList() - - val json = Json - val objectsWithProperties: List = inputMetadata.objectsWithProperties( - targetObject = targetObject - ) - - val fontFiles: MutableList = mutableListOf() - - objectsWithProperties.forEach { generatedObject -> - generatedObject.properties.forEach { property -> - val data = json.decodeFromJsonElement>(property.data) - - data.forEach { - fontFiles.add(File(it.value.content)) - } - } - } - - return fontFiles.getFontFiles() - } - - private fun Iterable.getFontFiles(): List { - return this.map { - FontFile( - key = it.nameWithoutExtension, - file = it - ) - } - } - - /* - @param keys: names of files like anastasia-regular.ttf - */ - private fun createTypeSpec( - inputMetadata: List, - outputMetadata: GeneratedObject, - filesSpec: List, - objectBuilder: TypeSpec.Builder, - ): MRGenerator.GenerationResult? { - if (outputMetadata.isActual) { - objectBuilder.addModifiers(KModifier.ACTUAL) - } - - if (outputMetadata.isActualObject || outputMetadata.isTargetObject) { - extendObjectBodyAtStart(objectBuilder) - } - - /* - * 1. Group fileNames by family name (split('-').first()) - * 2. Generate subtype for each family `classBuilder.addType(...)` - * 3. Generate properties in family subtype for each font style - * */ - - val familyGroups: Map> = filesSpec.groupBy { fileSpec -> - fileSpec.file.nameWithoutExtension.substringBefore("-") - } - - val generatedProperties = mutableListOf() - - familyGroups.forEach { group -> - // Make pairs: "style name" - "font file" - val stylePairs: List> = group - .value - .map { it.file.nameWithoutExtension.substringAfter("-") to it } - - val propertyName: String = group.key - val property: TypeSpec.Builder = TypeSpec.objectBuilder(propertyName) - - var generatedProperty = GeneratedProperty( - modifier = addObjectActualOverrideModifier( - propertyName = propertyName, - property = property, - inputMetadata = inputMetadata, - targetObject = outputMetadata - ), - name = propertyName, - data = JsonPrimitive("") - ) - - val fontsProperty: MutableMap = mutableMapOf() - - stylePairs.map { - Pair(it.first, it.second.file) - }.forEach { (styleName, file) -> - val styleProperty: PropertySpec.Builder = PropertySpec - .builder(styleName.decapitalize(), resourceClassName) - - if (generatedProperty.isActualProperty) { - styleProperty.addModifiers(KModifier.ACTUAL) - } - - if (outputMetadata.isActualObject || outputMetadata.isTargetObject) { - getPropertyInitializer(file)?.let { codeBlock -> - styleProperty.initializer(codeBlock) - } - } - - fontsProperty[styleName] = JsonPrimitive(file.path) - - property.addProperty(styleProperty.build()) - generatedProperty = generatedProperty.copy( - data = JsonObject(fontsProperty) - ) - } - - objectBuilder.addType(property.build()) - generatedProperties.add(generatedProperty) - } - - extendObjectBodyAtEnd(objectBuilder) - - if (generatedProperties.isEmpty()) return null - - return MRGenerator.GenerationResult( - typeSpec = objectBuilder.build(), - metadata = outputMetadata.copy(properties = generatedProperties) - ) - } - - private fun addObjectActualOverrideModifier( - propertyName: String, - property: TypeSpec.Builder, - inputMetadata: List, - targetObject: GeneratedObject, - ): GeneratedObjectModifier { - // Read actual interfaces of target object generator type - val actualInterfaces: List = inputMetadata.getActualInterfaces( - generatorType = targetObject.generatorType - ) - - var containsInActualInterfaces = false - - // Search property in actual interfaces - actualInterfaces.forEach { genInterface -> - val hasInInterface = genInterface.properties.any { - it.name == propertyName - } - - if (hasInInterface) { - containsInActualInterfaces = true - } - } - - return if (targetObject.isObject) { - if (containsInActualInterfaces) { - property.addModifiers(KModifier.OVERRIDE) - GeneratedObjectModifier.Override - } else { - when (targetObject.modifier) { - GeneratedObjectModifier.Actual -> { - property.addModifiers(KModifier.ACTUAL) - GeneratedObjectModifier.Actual - } - - else -> { - GeneratedObjectModifier.None - } - } - } - } else { - GeneratedObjectModifier.None - } - - } - - override fun getImports(): List = emptyList() - - protected open fun generateResources( - resourcesGenerationDir: File, - files: List, - ) { - } - - abstract fun getClassModifiers(): Array - - abstract fun getPropertyModifiers(): Array - - abstract fun getPropertyInitializer(fontFile: File): CodeBlock? - - open fun beforeGenerateResources(objectBuilder: TypeSpec.Builder, files: List) {} - - data class FontFile( - val key: String, - val file: File, - ) - - class Feature( - private val settings: MRGenerator.Settings, - ) : ResourceGeneratorFeature { - override fun createCommonGenerator(): FontsGenerator = CommonFontsGenerator( - ownInputFileTree = settings.ownResourcesFileTree, - ) - - override fun createAppleGenerator(): FontsGenerator = AppleFontsGenerator( - ownInputFileTree = settings.ownResourcesFileTree, - ) - - override fun createAndroidGenerator(): FontsGenerator = AndroidFontsGenerator( - ownInputFileTree = settings.ownResourcesFileTree, - androidRClassPackage = settings.androidRClassPackage - ) - - override fun createJsGenerator(): FontsGenerator = JsFontsGenerator( - ownInputFileTree = settings.ownResourcesFileTree, - mrClassPackage = settings.packageName - ) - - override fun createJvmGenerator(): FontsGenerator = JvmFontsGenerator( - ownInputFileTree = settings.ownResourcesFileTree, - settings = settings - ) - } -} +///* +// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator +// +//import com.squareup.kotlinpoet.ClassName +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import com.squareup.kotlinpoet.PropertySpec +//import com.squareup.kotlinpoet.TypeSpec +//import dev.icerock.gradle.generator.android.AndroidFontsGenerator +//import dev.icerock.gradle.generator.apple.AppleFontsGenerator +//import dev.icerock.gradle.generator.common.CommonFontsGenerator +//import dev.icerock.gradle.generator.js.JsFontsGenerator +//import dev.icerock.gradle.generator.jvm.JvmFontsGenerator +//import dev.icerock.gradle.metadata.getActualInterfaces +//import dev.icerock.gradle.metadata.model.GeneratedObject +//import dev.icerock.gradle.metadata.model.GeneratedObjectModifier +//import dev.icerock.gradle.metadata.model.GeneratedProperty +//import dev.icerock.gradle.metadata.model.GeneratorType +//import dev.icerock.gradle.metadata.objectsWithProperties +//import dev.icerock.gradle.utils.decapitalize +//import kotlinx.serialization.json.Json +//import kotlinx.serialization.json.JsonObject +//import kotlinx.serialization.json.JsonPrimitive +//import kotlinx.serialization.json.decodeFromJsonElement +//import org.gradle.api.Project +//import org.gradle.api.file.FileTree +//import java.io.File +// +//abstract class FontsGenerator( +// private val resourcesFileTree: FileTree, +//) : MRGenerator.Generator { +// +// override val inputFiles: Iterable +// get() = resourcesFileTree.matching { +// it.include("fonts/**.ttf", "fonts/**.otf") +// } +// override val resourceClassName = ClassName("dev.icerock.moko.resources", "FontResource") +// override val mrObjectName: String = "fonts" +// +// override val type: GeneratorType = GeneratorType.Fonts +// +// override fun generateObject( +// project: Project, +// inputMetadata: List, +// outputMetadata: GeneratedObject, +// assetsGenerationDir: File, +// resourcesGenerationDir: File, +// objectBuilder: TypeSpec.Builder +// ): MRGenerator.GenerationResult? { +// val previousFontFiles: List = getPreviousFontFiles( +// inputMetadata = inputMetadata, +// targetObject = outputMetadata +// ) +// +// val fontFiles: List = if ( +// outputMetadata.isActualObject || outputMetadata.isTargetObject +// ) { +// emptyList() +// } else { +// inputFiles.getFontFiles() +// } +// +// // Sum of all fonts files and filter his on unical fonts +// val allFontFiles: List = (previousFontFiles + fontFiles).distinctBy { it.key } +// +// beforeGenerateResources(objectBuilder, allFontFiles) +// +// val typeSpec: MRGenerator.GenerationResult = createTypeSpec( +// inputMetadata = inputMetadata, +// outputMetadata = outputMetadata, +// filesSpec = allFontFiles.sortedBy { it.key }, +// objectBuilder = objectBuilder +// ) ?: return null +// +// generateResources(resourcesGenerationDir, allFontFiles) +// +// return typeSpec +// } +// +// private fun getPreviousFontFiles( +// inputMetadata: List, +// targetObject: GeneratedObject, +// ): List { +// if (!targetObject.isObject || !targetObject.isActual) return emptyList() +// +// val json = Json +// val objectsWithProperties: List = inputMetadata.objectsWithProperties( +// targetObject = targetObject +// ) +// +// val fontFiles: MutableList = mutableListOf() +// +// objectsWithProperties.forEach { generatedObject -> +// generatedObject.properties.forEach { property -> +// val data = json.decodeFromJsonElement>(property.data) +// +// data.forEach { +// fontFiles.add(File(it.value.content)) +// } +// } +// } +// +// return fontFiles.getFontFiles() +// } +// +// private fun Iterable.getFontFiles(): List { +// return this.map { +// FontFile( +// key = it.nameWithoutExtension, +// file = it +// ) +// } +// } +// +// /* +// @param keys: names of files like anastasia-regular.ttf +// */ +// private fun createTypeSpec( +// inputMetadata: List, +// outputMetadata: GeneratedObject, +// filesSpec: List, +// objectBuilder: TypeSpec.Builder, +// ): MRGenerator.GenerationResult? { +// if (outputMetadata.isActual) { +// objectBuilder.addModifiers(KModifier.ACTUAL) +// } +// +// if (outputMetadata.isActualObject || outputMetadata.isTargetObject) { +// extendObjectBodyAtStart(objectBuilder) +// } +// +// /* +// * 1. Group fileNames by family name (split('-').first()) +// * 2. Generate subtype for each family `classBuilder.addType(...)` +// * 3. Generate properties in family subtype for each font style +// * */ +// +// val familyGroups: Map> = filesSpec.groupBy { fileSpec -> +// fileSpec.file.nameWithoutExtension.substringBefore("-") +// } +// +// val generatedProperties = mutableListOf() +// +// familyGroups.forEach { group -> +// // Make pairs: "style name" - "font file" +// val stylePairs: List> = group +// .value +// .map { it.file.nameWithoutExtension.substringAfter("-") to it } +// +// val propertyName: String = group.key +// val property: TypeSpec.Builder = TypeSpec.objectBuilder(propertyName) +// +// var generatedProperty = GeneratedProperty( +// modifier = addObjectActualOverrideModifier( +// propertyName = propertyName, +// property = property, +// inputMetadata = inputMetadata, +// targetObject = outputMetadata +// ), +// name = propertyName, +// data = JsonPrimitive("") +// ) +// +// val fontsProperty: MutableMap = mutableMapOf() +// +// stylePairs.map { +// Pair(it.first, it.second.file) +// }.forEach { (styleName, file) -> +// val styleProperty: PropertySpec.Builder = PropertySpec +// .builder(styleName.decapitalize(), resourceClassName) +// +// if (generatedProperty.isActualProperty) { +// styleProperty.addModifiers(KModifier.ACTUAL) +// } +// +// if (outputMetadata.isActualObject || outputMetadata.isTargetObject) { +// getPropertyInitializer(file)?.let { codeBlock -> +// styleProperty.initializer(codeBlock) +// } +// } +// +// fontsProperty[styleName] = JsonPrimitive(file.path) +// +// property.addProperty(styleProperty.build()) +// generatedProperty = generatedProperty.copy( +// data = JsonObject(fontsProperty) +// ) +// } +// +// objectBuilder.addType(property.build()) +// generatedProperties.add(generatedProperty) +// } +// +// extendObjectBodyAtEnd(objectBuilder) +// +// if (generatedProperties.isEmpty()) return null +// +// return MRGenerator.GenerationResult( +// typeSpec = objectBuilder.build(), +// metadata = outputMetadata.copy(properties = generatedProperties) +// ) +// } +// +// private fun addObjectActualOverrideModifier( +// propertyName: String, +// property: TypeSpec.Builder, +// inputMetadata: List, +// targetObject: GeneratedObject, +// ): GeneratedObjectModifier { +// // Read actual interfaces of target object generator type +// val actualInterfaces: List = inputMetadata.getActualInterfaces( +// generatorType = targetObject.generatorType +// ) +// +// var containsInActualInterfaces = false +// +// // Search property in actual interfaces +// actualInterfaces.forEach { genInterface -> +// val hasInInterface = genInterface.properties.any { +// it.name == propertyName +// } +// +// if (hasInInterface) { +// containsInActualInterfaces = true +// } +// } +// +// return if (targetObject.isObject) { +// if (containsInActualInterfaces) { +// property.addModifiers(KModifier.OVERRIDE) +// GeneratedObjectModifier.Override +// } else { +// when (targetObject.modifier) { +// GeneratedObjectModifier.Actual -> { +// property.addModifiers(KModifier.ACTUAL) +// GeneratedObjectModifier.Actual +// } +// +// else -> { +// GeneratedObjectModifier.None +// } +// } +// } +// } else { +// GeneratedObjectModifier.None +// } +// +// } +// +// override fun getImports(): List = emptyList() +// +// protected open fun generateResources( +// resourcesGenerationDir: File, +// files: List, +// ) { +// } +// +// abstract fun getClassModifiers(): Array +// +// abstract fun getPropertyModifiers(): Array +// +// abstract fun getPropertyInitializer(fontFile: File): CodeBlock? +// +// open fun beforeGenerateResources(objectBuilder: TypeSpec.Builder, files: List) {} +// +// data class FontFile( +// val key: String, +// val file: File, +// ) +// +// class Feature( +// private val settings: MRGenerator.Settings, +// ) : ResourceGeneratorFeature { +// override fun createCommonGenerator(): FontsGenerator = CommonFontsGenerator( +// ownInputFileTree = settings.ownResourcesFileTree, +// ) +// +// override fun createAppleGenerator(): FontsGenerator = AppleFontsGenerator( +// ownInputFileTree = settings.ownResourcesFileTree, +// ) +// +// override fun createAndroidGenerator(): FontsGenerator = AndroidFontsGenerator( +// ownInputFileTree = settings.ownResourcesFileTree, +// androidRClassPackage = settings.androidRClassPackage +// ) +// +// override fun createJsGenerator(): FontsGenerator = JsFontsGenerator( +// ownInputFileTree = settings.ownResourcesFileTree, +// mrClassPackage = settings.packageName +// ) +// +// override fun createJvmGenerator(): FontsGenerator = JvmFontsGenerator( +// ownInputFileTree = settings.ownResourcesFileTree, +// settings = settings +// ) +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt index 1107ee424..c001387b4 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt @@ -1,270 +1,270 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.PropertySpec -import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.android.AndroidImagesGenerator -import dev.icerock.gradle.generator.apple.AppleImagesGenerator -import dev.icerock.gradle.generator.common.CommonImagesGenerator -import dev.icerock.gradle.generator.js.JsImagesGenerator -import dev.icerock.gradle.generator.jvm.JvmImagesGenerator -import dev.icerock.gradle.metadata.model.GeneratedObject -import dev.icerock.gradle.metadata.model.GeneratedObjectModifier -import dev.icerock.gradle.metadata.model.GeneratedProperty -import dev.icerock.gradle.metadata.model.GeneratorType -import dev.icerock.gradle.metadata.objectsWithProperties -import dev.icerock.gradle.utils.withoutScale -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.JsonElement -import kotlinx.serialization.json.JsonObject -import kotlinx.serialization.json.JsonPrimitive -import kotlinx.serialization.json.decodeFromJsonElement -import org.gradle.api.Project -import org.gradle.api.file.FileTree -import org.gradle.api.logging.Logger -import java.io.File - -abstract class ImagesGenerator( - private val resourcesFileTree: FileTree, -) : MRGenerator.Generator { - - override val inputFiles: Iterable - get() = resourcesFileTree.matching { - it.include("images/**/*.png", "images/**/*.jpg", "images/**/*.svg") - } - - override val resourceClassName = ClassName("dev.icerock.moko.resources", "ImageResource") - override val mrObjectName: String = "images" - - override val type: GeneratorType = GeneratorType.Images - - override fun generate( - project: Project, - inputMetadata: List, - outputMetadata: GeneratedObject, - assetsGenerationDir: File, - resourcesGenerationDir: File, - objectBuilder: TypeSpec.Builder - ): MRGenerator.GenerationResult? { - val previousFilesMap: Map> = getPreviousImageFilesMap( - inputMetadata = inputMetadata, - targetObject = outputMetadata - ) - - val imageFileMap: Map> = if ( - outputMetadata.isActualObject || outputMetadata.isTargetObject - ) { - emptyMap() - } else { - inputFiles.getImageMap() - } - - - val allImagesMap: Map> = getAllImagesMap(previousFilesMap, imageFileMap) - - beforeGenerateResources(objectBuilder, allImagesMap.keys.sorted()) - - val result: MRGenerator.GenerationResult = createTypeSpec( - inputMetadata = inputMetadata, - targetObject = outputMetadata, - fileNames = allImagesMap.keys.sorted(), - allImagesMap = allImagesMap, - objectBuilder = objectBuilder - ) ?: return null - - generateResources( - assetsGenerationDir = assetsGenerationDir, - resourcesGenerationDir = resourcesGenerationDir, - keyFileMap = allImagesMap.mapKeys { (key, _) -> - key.substringBeforeLast(".") // Remove file extension from keys - } - ) - - return result - } - - private fun createTypeSpec( - inputMetadata: List, - targetObject: GeneratedObject, - fileNames: List, - allImagesMap: Map>, - objectBuilder: TypeSpec.Builder, - ): MRGenerator.GenerationResult? { - if (targetObject.isActual) { - objectBuilder.addModifiers(KModifier.ACTUAL) - } - - if (targetObject.isActualObject || targetObject.isTargetObject) { - extendObjectBodyAtStart(objectBuilder) - } - - val generatedProperties = mutableListOf() - - fileNames.forEach { fileName: String -> - val updatedFileName = fileName.substringBeforeLast(".") - .replace(".", "_") + ".${fileName.substringAfterLast(".")}" - val propertyName = updatedFileName.substringBeforeLast(".") - val property = PropertySpec.builder(propertyName, resourceClassName) - - var generatedProperty = GeneratedProperty( - modifier = GeneratedObjectModifier.None, - name = propertyName, - data = JsonObject( - content = getPropertyMetadata( - fileName = fileName, - allImagesMap = allImagesMap - ) - ) - ) - - if (targetObject.isActualObject || targetObject.isTargetObject) { - // Add modifier for property and setup metadata - generatedProperty = generatedProperty.copy( - modifier = addActualOverrideModifier( - propertyName = propertyName, - property = property, - inputMetadata = inputMetadata, - targetObject = targetObject - ) - ) - - getPropertyInitializer(updatedFileName)?.let { - property.initializer(it) - } - } - - objectBuilder.addProperty(property.build()) - generatedProperties.add(generatedProperty) - } - - extendObjectBodyAtEnd(objectBuilder) - - if (generatedProperties.isEmpty()) return null - - return MRGenerator.GenerationResult( - typeSpec = objectBuilder.build(), - metadata = targetObject.copy(properties = generatedProperties) - ) - } - - private fun getPropertyMetadata( - fileName: String, - allImagesMap: Map>, - ): Map { - //Structure: FileName, Path - val resultMap = mutableMapOf() - - allImagesMap[fileName]?.forEach { - resultMap[it.name] = JsonPrimitive(it.path) - } - - return resultMap - } - - private fun getPreviousImageFilesMap( - inputMetadata: List, - targetObject: GeneratedObject, - ): Map> { - if (!targetObject.isObject || !targetObject.isActual) return emptyMap() - - val json = Json - val objectsWithProperties: List = inputMetadata.objectsWithProperties( - targetObject = targetObject - ) - - val fileImage = mutableListOf() - - objectsWithProperties.forEach { generatedObject -> - generatedObject.properties.forEach { property -> - val data = json.decodeFromJsonElement>(property.data) - - data.forEach { - fileImage.add(File(it.value.content)) - } - } - } - - return fileImage.getImageMap() - } - - private fun Iterable.getImageMap(): Map> { - return this.groupBy { file -> - // SVGs do not have scale suffixes, so we need to remove the extension first - val key = file - .nameWithoutExtension - .withoutScale - - "$key.${file.extension}" - } - } - - private fun getAllImagesMap( - previousFilesMap: Map>, - imageFileMap: Map>, - ): Map> { - val resultMap = mutableMapOf>() - - previousFilesMap.forEach { map -> - resultMap[map.key] = map.value - } - - imageFileMap.forEach { map -> - resultMap[map.key] = map.value - } - - return resultMap - } - - override fun getImports(): List = emptyList() - - protected open fun beforeGenerateResources( - objectBuilder: TypeSpec.Builder, - keys: List, - ) = Unit - - protected open fun generateResources( - assetsGenerationDir: File, - resourcesGenerationDir: File, - keyFileMap: Map>, - ) = Unit - - abstract fun getClassModifiers(): Array - - abstract fun getPropertyModifiers(): Array - - abstract fun getPropertyInitializer(fileName: String): CodeBlock? - - class Feature( - private val settings: MRGenerator.Settings, - private val logger: Logger, - ) : ResourceGeneratorFeature { - override fun createCommonGenerator(): ImagesGenerator = CommonImagesGenerator( - ownInputFileTree = settings.ownResourcesFileTree, - ) - - override fun createAppleGenerator(): ImagesGenerator = AppleImagesGenerator( - ownInputFileTree = settings.ownResourcesFileTree, - ) - - override fun createAndroidGenerator(): ImagesGenerator = AndroidImagesGenerator( - ownInputFileTree = settings.ownResourcesFileTree, - androidRClassPackage = settings.androidRClassPackage, - logger = logger - ) - - override fun createJsGenerator(): ImagesGenerator = JsImagesGenerator( - ownInputFileTree = settings.ownResourcesFileTree, - ) - - override fun createJvmGenerator(): ImagesGenerator = JvmImagesGenerator( - ownInputFileTree = settings.ownResourcesFileTree, - settings = settings - ) - } -} +///* +// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator +// +//import com.squareup.kotlinpoet.ClassName +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import com.squareup.kotlinpoet.PropertySpec +//import com.squareup.kotlinpoet.TypeSpec +//import dev.icerock.gradle.generator.android.AndroidImagesGenerator +//import dev.icerock.gradle.generator.apple.AppleImagesGenerator +//import dev.icerock.gradle.generator.common.CommonImagesGenerator +//import dev.icerock.gradle.generator.js.JsImagesGenerator +//import dev.icerock.gradle.generator.jvm.JvmImagesGenerator +//import dev.icerock.gradle.metadata.model.GeneratedObject +//import dev.icerock.gradle.metadata.model.GeneratedObjectModifier +//import dev.icerock.gradle.metadata.model.GeneratedProperty +//import dev.icerock.gradle.metadata.model.GeneratorType +//import dev.icerock.gradle.metadata.objectsWithProperties +//import dev.icerock.gradle.utils.withoutScale +//import kotlinx.serialization.json.Json +//import kotlinx.serialization.json.JsonElement +//import kotlinx.serialization.json.JsonObject +//import kotlinx.serialization.json.JsonPrimitive +//import kotlinx.serialization.json.decodeFromJsonElement +//import org.gradle.api.Project +//import org.gradle.api.file.FileTree +//import org.gradle.api.logging.Logger +//import java.io.File +// +//abstract class ImagesGenerator( +// private val resourcesFileTree: FileTree, +//) : MRGenerator.Generator { +// +// override val inputFiles: Iterable +// get() = resourcesFileTree.matching { +// it.include("images/**/*.png", "images/**/*.jpg", "images/**/*.svg") +// } +// +// override val resourceClassName = ClassName("dev.icerock.moko.resources", "ImageResource") +// override val mrObjectName: String = "images" +// +// override val type: GeneratorType = GeneratorType.Images +// +// override fun generateObject( +// project: Project, +// inputMetadata: List, +// outputMetadata: GeneratedObject, +// assetsGenerationDir: File, +// resourcesGenerationDir: File, +// objectBuilder: TypeSpec.Builder +// ): MRGenerator.GenerationResult? { +// val previousFilesMap: Map> = getPreviousImageFilesMap( +// inputMetadata = inputMetadata, +// targetObject = outputMetadata +// ) +// +// val imageFileMap: Map> = if ( +// outputMetadata.isActualObject || outputMetadata.isTargetObject +// ) { +// emptyMap() +// } else { +// inputFiles.getImageMap() +// } +// +// +// val allImagesMap: Map> = getAllImagesMap(previousFilesMap, imageFileMap) +// +// beforeGenerateResources(objectBuilder, allImagesMap.keys.sorted()) +// +// val result: MRGenerator.GenerationResult = createTypeSpec( +// inputMetadata = inputMetadata, +// targetObject = outputMetadata, +// fileNames = allImagesMap.keys.sorted(), +// allImagesMap = allImagesMap, +// objectBuilder = objectBuilder +// ) ?: return null +// +// generateResources( +// assetsGenerationDir = assetsGenerationDir, +// resourcesGenerationDir = resourcesGenerationDir, +// keyFileMap = allImagesMap.mapKeys { (key, _) -> +// key.substringBeforeLast(".") // Remove file extension from keys +// } +// ) +// +// return result +// } +// +// private fun createTypeSpec( +// inputMetadata: List, +// targetObject: GeneratedObject, +// fileNames: List, +// allImagesMap: Map>, +// objectBuilder: TypeSpec.Builder, +// ): MRGenerator.GenerationResult? { +// if (targetObject.isActual) { +// objectBuilder.addModifiers(KModifier.ACTUAL) +// } +// +// if (targetObject.isActualObject || targetObject.isTargetObject) { +// extendObjectBodyAtStart(objectBuilder) +// } +// +// val generatedProperties = mutableListOf() +// +// fileNames.forEach { fileName: String -> +// val updatedFileName = fileName.substringBeforeLast(".") +// .replace(".", "_") + ".${fileName.substringAfterLast(".")}" +// val propertyName = updatedFileName.substringBeforeLast(".") +// val property = PropertySpec.builder(propertyName, resourceClassName) +// +// var generatedProperty = GeneratedProperty( +// modifier = GeneratedObjectModifier.None, +// name = propertyName, +// data = JsonObject( +// content = getPropertyMetadata( +// fileName = fileName, +// allImagesMap = allImagesMap +// ) +// ) +// ) +// +// if (targetObject.isActualObject || targetObject.isTargetObject) { +// // Add modifier for property and setup metadata +// generatedProperty = generatedProperty.copy( +// modifier = addActualOverrideModifier( +// propertyName = propertyName, +// property = property, +// inputMetadata = inputMetadata, +// targetObject = targetObject +// ) +// ) +// +// getPropertyInitializer(updatedFileName)?.let { +// property.initializer(it) +// } +// } +// +// objectBuilder.addProperty(property.build()) +// generatedProperties.add(generatedProperty) +// } +// +// extendObjectBodyAtEnd(objectBuilder) +// +// if (generatedProperties.isEmpty()) return null +// +// return MRGenerator.GenerationResult( +// typeSpec = objectBuilder.build(), +// metadata = targetObject.copy(properties = generatedProperties) +// ) +// } +// +// private fun getPropertyMetadata( +// fileName: String, +// allImagesMap: Map>, +// ): Map { +// //Structure: FileName, Path +// val resultMap = mutableMapOf() +// +// allImagesMap[fileName]?.forEach { +// resultMap[it.name] = JsonPrimitive(it.path) +// } +// +// return resultMap +// } +// +// private fun getPreviousImageFilesMap( +// inputMetadata: List, +// targetObject: GeneratedObject, +// ): Map> { +// if (!targetObject.isObject || !targetObject.isActual) return emptyMap() +// +// val json = Json +// val objectsWithProperties: List = inputMetadata.objectsWithProperties( +// targetObject = targetObject +// ) +// +// val fileImage = mutableListOf() +// +// objectsWithProperties.forEach { generatedObject -> +// generatedObject.properties.forEach { property -> +// val data = json.decodeFromJsonElement>(property.data) +// +// data.forEach { +// fileImage.add(File(it.value.content)) +// } +// } +// } +// +// return fileImage.getImageMap() +// } +// +// private fun Iterable.getImageMap(): Map> { +// return this.groupBy { file -> +// // SVGs do not have scale suffixes, so we need to remove the extension first +// val key = file +// .nameWithoutExtension +// .withoutScale +// +// "$key.${file.extension}" +// } +// } +// +// private fun getAllImagesMap( +// previousFilesMap: Map>, +// imageFileMap: Map>, +// ): Map> { +// val resultMap = mutableMapOf>() +// +// previousFilesMap.forEach { map -> +// resultMap[map.key] = map.value +// } +// +// imageFileMap.forEach { map -> +// resultMap[map.key] = map.value +// } +// +// return resultMap +// } +// +// override fun getImports(): List = emptyList() +// +// protected open fun beforeGenerateResources( +// objectBuilder: TypeSpec.Builder, +// keys: List, +// ) = Unit +// +// protected open fun generateResources( +// assetsGenerationDir: File, +// resourcesGenerationDir: File, +// keyFileMap: Map>, +// ) = Unit +// +// abstract fun getClassModifiers(): Array +// +// abstract fun getPropertyModifiers(): Array +// +// abstract fun getPropertyInitializer(fileName: String): CodeBlock? +// +// class Feature( +// private val settings: MRGenerator.Settings, +// private val logger: Logger, +// ) : ResourceGeneratorFeature { +// override fun createCommonGenerator(): ImagesGenerator = CommonImagesGenerator( +// ownInputFileTree = settings.ownResourcesFileTree, +// ) +// +// override fun createAppleGenerator(): ImagesGenerator = AppleImagesGenerator( +// ownInputFileTree = settings.ownResourcesFileTree, +// ) +// +// override fun createAndroidGenerator(): ImagesGenerator = AndroidImagesGenerator( +// ownInputFileTree = settings.ownResourcesFileTree, +// androidRClassPackage = settings.androidRClassPackage, +// logger = logger +// ) +// +// override fun createJsGenerator(): ImagesGenerator = JsImagesGenerator( +// ownInputFileTree = settings.ownResourcesFileTree, +// ) +// +// override fun createJvmGenerator(): ImagesGenerator = JvmImagesGenerator( +// ownInputFileTree = settings.ownResourcesFileTree, +// settings = settings +// ) +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/LanguageType.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/LanguageType.kt index 347c7fa58..1430b644a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/LanguageType.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/LanguageType.kt @@ -86,5 +86,10 @@ sealed interface LanguageType { BASE -> Base else -> Locale(fileName.replace("-r", "-")) } + + fun fromLanguage(language: String): LanguageType = when (language) { + Base.language() -> Base + else -> Locale(language) + } } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/LocalizationGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/LocalizationGenerator.kt index 2d4290513..d7fc4655b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/LocalizationGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/LocalizationGenerator.kt @@ -1,175 +1,269 @@ -/* - * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator - -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.PropertySpec -import com.squareup.kotlinpoet.PropertySpec.Builder -import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.metadata.model.GeneratedObject -import dev.icerock.gradle.metadata.model.GeneratedObjectModifier -import dev.icerock.gradle.metadata.model.GeneratedProperty -import kotlinx.serialization.json.JsonElement -import kotlinx.serialization.json.JsonObject -import org.gradle.api.Project -import java.io.File - -abstract class LocalizationGenerator : MRGenerator.Generator { - override fun generate( - project: Project, - inputMetadata: List, - outputMetadata: GeneratedObject, - assetsGenerationDir: File, - resourcesGenerationDir: File, - objectBuilder: TypeSpec.Builder, - ): MRGenerator.GenerationResult? { - // Read previous languages map from metadata - // if target object is expect object or interface return emptyMap() - val previousLanguagesMap: Map> = getPreviousLanguagesMap( - inputMetadata = inputMetadata, - targetObject = outputMetadata - ) - - // Read actual resources of target - // If target object is actual object: skip read files again - // - // Structure: language - key - value - val languageMap: Map> = - if (outputMetadata.isActualObject || outputMetadata.isTargetObject) { - emptyMap() - } else { - loadLanguageMap() - } - - // Sum of previous and target language fields - val languagesAllMaps: Map> = getLanguagesAllMaps( - previousLanguageMaps = previousLanguagesMap, - languageMap = languageMap - ) - val languageKeyValues: Map = languagesAllMaps[LanguageType.Base].orEmpty() - - beforeGenerateResources(objectBuilder, languagesAllMaps) - - val result: MRGenerator.GenerationResult = createTypeSpec( - inputMetadata = inputMetadata, - targetObject = outputMetadata, - keys = languageKeyValues.keys.toList(), - languageMap = languagesAllMaps, - objectBuilder = objectBuilder - ) ?: return null - - languagesAllMaps.forEach { (language: LanguageType, strings: Map) -> - generateResources( - resourcesGenerationDir = resourcesGenerationDir, - language = language, - strings = strings - ) - } - - return result - } - - private fun createTypeSpec( - inputMetadata: List, - targetObject: GeneratedObject, - keys: List, - languageMap: Map>, - objectBuilder: TypeSpec.Builder, - ): MRGenerator.GenerationResult? { - if (targetObject.isActual) { - objectBuilder.addModifiers(KModifier.ACTUAL) - } - - if (targetObject.isActualObject || targetObject.isTargetObject) { - extendObjectBodyAtStart(objectBuilder) - } - - val generatedProperties = mutableListOf() - - keys.forEach { key -> - val name = key.replace(".", "_") - - //Create metadata property - var generatedProperty = GeneratedProperty( - modifier = GeneratedObjectModifier.None, - name = name, - data = JsonObject( - content = getPropertyMetadata( - key = key, - languageMap = languageMap - ) - ) - ) - - val property: Builder = PropertySpec.builder(name, resourceClassName) - - if (targetObject.isActualObject || targetObject.isTargetObject) { - // Add modifier for property and setup metadata - generatedProperty = generatedProperty.copy( - modifier = addActualOverrideModifier( - propertyName = name, - property = property, - inputMetadata = inputMetadata, - targetObject = targetObject - ) - ) - - getPropertyInitializer(key)?.let { - property.initializer(it) - } - } - - objectBuilder.addProperty(property.build()) - generatedProperties.add(generatedProperty) - } - - extendObjectBodyAtEnd(objectBuilder) - - if (generatedProperties.isEmpty()) return null - - // Add object in metadata with remove expect realisation - return MRGenerator.GenerationResult( - typeSpec = objectBuilder.build(), - metadata = targetObject.copy(properties = generatedProperties) - ) - } - - abstract fun getPropertyMetadata( - key: KeyType, - languageMap: Map>, - ): Map - - abstract fun getLanguagesAllMaps( - previousLanguageMaps: Map>, - languageMap: Map> - ): Map> - - abstract fun getPreviousLanguagesMap( - inputMetadata: List, - targetObject: GeneratedObject, - ): Map> - - protected abstract fun loadLanguageMap(): Map> - protected abstract fun getPropertyInitializer(key: String): CodeBlock? - - protected open fun getClassModifiers(): Array = emptyArray() - protected open fun getPropertyModifiers(): Array = emptyArray() - - protected open fun beforeGenerateResources( - objectBuilder: TypeSpec.Builder, - languageMap: Map>, - ) = Unit - - protected open fun generateResources( - resourcesGenerationDir: File, - language: LanguageType, - strings: Map, - ) = Unit - - protected companion object { - const val BASE_LANGUAGE = "base" - } -} +///* +// * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator +// +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import com.squareup.kotlinpoet.PropertySpec +//import com.squareup.kotlinpoet.PropertySpec.Builder +//import com.squareup.kotlinpoet.TypeSpec +//import dev.icerock.gradle.metadata.getInterfaceName +//import dev.icerock.gradle.metadata.model.GeneratedObject +//import dev.icerock.gradle.metadata.model.GeneratedObjectModifier +//import dev.icerock.gradle.metadata.model.GeneratedObjectType +//import dev.icerock.gradle.metadata.model.GeneratedProperty +//import dev.icerock.gradle.metadata.model.GeneratorType +//import kotlinx.serialization.json.JsonElement +//import kotlinx.serialization.json.JsonObject +//import org.gradle.api.Project +//import java.io.File +// +//abstract class LocalizationGenerator : MRGenerator.Generator { +// +// override fun generateObject( +// project: Project, +// inputMetadata: List, +// outputMetadata: GeneratedObject, +// assetsGenerationDir: File, +// resourcesGenerationDir: File, +// objectBuilder: TypeSpec.Builder, +// ): MRGenerator.GenerationResult? { +// // Read previous languages map from metadata +// // if target object is expect object or interface return emptyMap() +// val previousLanguagesMap: Map> = getPreviousLanguagesMap( +// inputMetadata = inputMetadata, +// targetObject = outputMetadata +// ) +// +// // Read actual resources of target +// // If target object is actual object: skip read files again +// // +// // Structure: language - key - value +// val languageMap: Map> = +// if (outputMetadata.isActualObject || outputMetadata.isTargetObject) { +// emptyMap() +// } else { +// loadLanguageMap() +// } +// +// // Sum of previous and target language fields +// val languagesAllMaps: Map> = getLanguagesAllMaps( +// previousLanguageMaps = previousLanguagesMap, +// languageMap = languageMap +// ) +// val languageKeyValues: Map = languagesAllMaps[LanguageType.Base].orEmpty() +// +// beforeGenerateResources(objectBuilder, languagesAllMaps) +// +// val result: MRGenerator.GenerationResult = createTypeSpec( +// inputMetadata = inputMetadata, +// targetObject = outputMetadata, +// keys = languageKeyValues.keys.toList(), +// languageMap = languagesAllMaps, +// objectBuilder = objectBuilder +// ) ?: return null +// +// languagesAllMaps.forEach { (language: LanguageType, strings: Map) -> +// generateResources( +// resourcesGenerationDir = resourcesGenerationDir, +// language = language, +// strings = strings +// ) +// } +// +// return result +// } +// +// private fun createTypeSpec( +// inputMetadata: List, +// targetObject: GeneratedObject, +// keys: List, +// languageMap: Map>, +// objectBuilder: TypeSpec.Builder, +// ): MRGenerator.GenerationResult? { +// if (targetObject.isActual) { +// objectBuilder.addModifiers(KModifier.ACTUAL) +// } +// +// if (targetObject.isActualObject || targetObject.isTargetObject) { +// extendObjectBodyAtStart(objectBuilder) +// } +// +// val generatedProperties = mutableListOf() +// +// keys.forEach { key -> +// val name = key.replace(".", "_") +// +// //Create metadata property +// var generatedProperty = GeneratedProperty( +// modifier = GeneratedObjectModifier.None, +// name = name, +// data = JsonObject( +// content = getPropertyMetadata( +// key = key, +// languageMap = languageMap +// ) +// ) +// ) +// +// val property: Builder = PropertySpec.builder(name, resourceClassName) +// +// if (targetObject.isActualObject || targetObject.isTargetObject) { +// // Add modifier for property and setup metadata +// generatedProperty = generatedProperty.copy( +// modifier = addActualOverrideModifier( +// propertyName = name, +// property = property, +// inputMetadata = inputMetadata, +// targetObject = targetObject +// ) +// ) +// +// getPropertyInitializer(key)?.let { +// property.initializer(it) +// } +// } +// +// objectBuilder.addProperty(property.build()) +// generatedProperties.add(generatedProperty) +// } +// +// extendObjectBodyAtEnd(objectBuilder) +// +// if (generatedProperties.isEmpty()) return null +// +// // Add object in metadata with remove expect realisation +// return MRGenerator.GenerationResult( +// typeSpec = objectBuilder.build(), +// metadata = targetObject.copy(properties = generatedProperties) +// ) +// } +// +// abstract fun getPropertyMetadata( +// key: KeyType, +// languageMap: Map>, +// ): Map +// +// abstract fun getLanguagesAllMaps( +// previousLanguageMaps: Map>, +// languageMap: Map> +// ): Map> +// +// abstract fun getPreviousLanguagesMap( +// inputMetadata: List, +// targetObject: GeneratedObject, +// ): Map> +// +// protected abstract fun loadLanguageMap(): Map> +// protected abstract fun getPropertyInitializer(key: String): CodeBlock? +// +// protected open fun getClassModifiers(): Array = emptyArray() +// protected open fun getPropertyModifiers(): Array = emptyArray() +// +// protected open fun beforeGenerateResources( +// objectBuilder: TypeSpec.Builder, +// languageMap: Map>, +// ) = Unit +// +// protected open fun generateResources( +// resourcesGenerationDir: File, +// language: LanguageType, +// strings: Map, +// ) = Unit +// +// protected companion object { +// const val BASE_LANGUAGE = "base" +// } +//} +// +//internal class CommonLocalizationInterfaceGenerator( +// private val sourceSetName: String, +// private val filesRegex: Regex, +// private val generatorType: GeneratorType, +// private val visibilityModifier: KModifier +//) : MRGenerator.InterfaceGenerator { +// override fun generateInterface( +// project: Project, +// metadata: List, +// resourcesFiles: MRGenerator.ResourcesFiles +// ): MRGenerator.GenerationResult? { +// if (resourcesFiles.lowerResourcesFileTree.isEmpty.not()) { +// // we should generate actual interfaces for own resources +// return generateActualInterface(project, metadata, resourcesFiles) +// } +// +// return generateExpectInterface(project, metadata, resourcesFiles) +// } +// +// private fun generateActualInterface( +// project: Project, +// metadata: List, +// resourcesFiles: MRGenerator.ResourcesFiles +// ): MRGenerator.GenerationResult? { +// val interfaceName: String = getInterfaceName( +// sourceSetName = sourceSetName, +// generatorType = generatorType +// ) +// +// val resourcesInterfaceBuilder: TypeSpec.Builder = +// TypeSpec.interfaceBuilder(interfaceName) +// .addModifiers(visibilityModifier) +// .addModifiers(KModifier.ACTUAL) +// +// generator.generateObject( +// project = project, +// metadata = inputMetadata, +// outputMetadata = GeneratedObject( +// generatorType = generator.type, +// name = interfaceName, +// type = GeneratedObjectType.Interface, +// modifier = GeneratedObjectModifier.Actual, +// ), +// assetsGenerationDir = assetsGenerationDir, +// resourcesGenerationDir = resourcesGenerationDir, +// objectBuilder = resourcesInterfaceBuilder, +// ) +// } +// +// private fun generateExpectInterface( +// project: Project, +// metadata: List, +// resourcesFiles: MRGenerator.ResourcesFiles +// ): MRGenerator.GenerationResult? { +// if (resourcesFiles.upperResourcesFileTree.isEmpty) return null +// +// val name: String = getInterfaceName( +// sourceSetName = sourceSetName, +// generatorType = generatorType +// ) +// +// return MRGenerator.GenerationResult( +// typeSpec = TypeSpec.interfaceBuilder(name) +// .addModifiers(visibilityModifier) +// .addModifiers(KModifier.EXPECT) +// .build(), +// metadata = GeneratedObject( +// generatorType = generatorType, +// type = GeneratedObjectType.Interface, +// modifier = GeneratedObjectModifier.Expect, +// name = name +// ) +// ) +// } +//} +// +//internal class PropertiesGenerator { +// +//} +// +//// разница в ресурсах - в итоговом генерируемом actual классе +//// (точнее в значениях, которые должны быть сгенерированы) +//// и в самих файлах, которые генерируются для платформы +// +//// генерацию файлов и значений, то есть actual данные, можно делать из метаданных, не читая +//// вообще файлы +// +//// тогда пайплайн такой: читаем файлы -> генерируем метаданные для них -> пишем файлы expect, interface +//// а в таргет генераторах пишем уже значения и сами файлы платформы diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt index 3c0f539a3..4abef684f 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt @@ -1,149 +1,171 @@ -/* - * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.FileSpec -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.PropertySpec -import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.MRVisibility -import dev.icerock.gradle.metadata.getActualInterfaces -import dev.icerock.gradle.metadata.model.GeneratedObject -import dev.icerock.gradle.metadata.model.GeneratedObjectModifier -import dev.icerock.gradle.metadata.model.GeneratorType -import org.gradle.api.Project -import org.gradle.api.file.Directory -import org.gradle.api.file.FileTree -import org.gradle.api.provider.Provider -import java.io.File - -abstract class MRGenerator( - protected val settings: Settings, - internal val generators: List, -) { - protected open val sourcesGenerationDir: File = settings.sourceSetDir.asFile - protected open val resourcesGenerationDir: File = settings.resourcesDir.asFile - protected open val assetsGenerationDir: File = settings.assetsDir.asFile - - internal fun generate() { - sourcesGenerationDir.deleteRecursively() - resourcesGenerationDir.deleteRecursively() - assetsGenerationDir.deleteRecursively() - - beforeMRGeneration() - - val file = generateFileSpec() - file?.writeTo(sourcesGenerationDir) - - afterMRGeneration() - } - - abstract fun generateFileSpec(): FileSpec? - - protected open fun beforeMRGeneration() = Unit - protected open fun afterMRGeneration() = Unit - - protected abstract fun getMRClassModifiers(): Array - - protected open fun processMRClass(mrClass: TypeSpec.Builder) {} - protected open fun getImports(): List = emptyList() - - interface Generator : ObjectBodyExtendable { - val mrObjectName: String - val resourceContainerClass: ClassName - get() = ClassName("dev.icerock.moko.resources", "ResourceContainer") - val resourceClassName: ClassName - val inputFiles: Iterable - - val type: GeneratorType - - fun generate( - project: Project, - inputMetadata: List, - outputMetadata: GeneratedObject, - assetsGenerationDir: File, - resourcesGenerationDir: File, - objectBuilder: TypeSpec.Builder, - ): GenerationResult? - - fun getImports(): List - - fun addActualOverrideModifier( - propertyName: String, - property: PropertySpec.Builder, - inputMetadata: List, - targetObject: GeneratedObject, - ): GeneratedObjectModifier { - // Read actual interfaces of target object generator type - val actualInterfaces: List = inputMetadata.getActualInterfaces( - generatorType = targetObject.generatorType - ) - - var containsInActualInterfaces = false - - // Search property in actual interfaces - actualInterfaces.forEach { genInterface -> - val hasInInterface = genInterface.properties.any { - it.name == propertyName - } - - if (hasInInterface) { - containsInActualInterfaces = true - } - } - - return if (targetObject.isObject) { - if (containsInActualInterfaces) { - property.addModifiers(KModifier.OVERRIDE) - GeneratedObjectModifier.Override - } else { - when (targetObject.modifier) { - GeneratedObjectModifier.Actual -> { - property.addModifiers(KModifier.ACTUAL) - GeneratedObjectModifier.Actual - } - - else -> { - GeneratedObjectModifier.None - } - } - } - } else { - GeneratedObjectModifier.None - } - } - } - - data class GenerationResult( - val typeSpec: TypeSpec, - val metadata: GeneratedObject - ) - - interface SourceSet { - val name: String - - fun addSourceDir(directory: File) - fun addResourcesDir(directory: File) - fun addAssetsDir(directory: File) - } - - data class Settings( - val inputMetadataFiles: FileTree, - val outputMetadataFile: File, - val packageName: String, - val className: String, - val visibility: MRVisibility, - val assetsDir: Directory, - val sourceSetDir: Directory, - val resourcesDir: Directory, - val isStrictLineBreaks: Boolean, - val ownResourcesFileTree: FileTree, - val lowerResourcesFileTree: FileTree, - val upperResourcesFileTree: FileTree, - val iosLocalizationRegion: Provider, - val androidRClassPackage: Provider, - ) -} +///* +// * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator +// +//import com.squareup.kotlinpoet.ClassName +//import com.squareup.kotlinpoet.FileSpec +//import com.squareup.kotlinpoet.KModifier +//import com.squareup.kotlinpoet.PropertySpec +//import com.squareup.kotlinpoet.TypeSpec +//import dev.icerock.gradle.MRVisibility +//import dev.icerock.gradle.metadata.getActualInterfaces +//import dev.icerock.gradle.metadata.model.GeneratedObject +//import dev.icerock.gradle.metadata.model.GeneratedObjectModifier +//import dev.icerock.gradle.metadata.model.GeneratorType +//import org.gradle.api.Project +//import org.gradle.api.file.Directory +//import org.gradle.api.file.FileTree +//import org.gradle.api.provider.Provider +//import java.io.File +// +//abstract class MRGenerator( +// protected val settings: Settings, +// internal val generators: List, +//) { +// protected open val sourcesGenerationDir: File = settings.sourceSetDir.asFile +// protected open val resourcesGenerationDir: File = settings.resourcesDir.asFile +// protected open val assetsGenerationDir: File = settings.assetsDir.asFile +// +// internal fun generate() { +// sourcesGenerationDir.deleteRecursively() +// resourcesGenerationDir.deleteRecursively() +// assetsGenerationDir.deleteRecursively() +// +// beforeMRGeneration() +// +// val file = generateFileSpec() +// file?.writeTo(sourcesGenerationDir) +// +// afterMRGeneration() +// } +// +// abstract fun generateFileSpec(): FileSpec? +// +// protected open fun beforeMRGeneration() = Unit +// protected open fun afterMRGeneration() = Unit +// +// protected abstract fun getMRClassModifiers(): Array +// +// protected open fun processMRClass(mrClass: TypeSpec.Builder) {} +// protected open fun getImports(): List = emptyList() +// +// interface Generator : InterfaceGenerator, ObjectGenerator, ResourcesGenerator, +// ObjectBodyExtendable { +// val mrObjectName: String +// val resourceContainerClass: ClassName +// get() = ClassName("dev.icerock.moko.resources", "ResourceContainer") +// val resourceClassName: ClassName +// val inputFiles: Iterable +// +// val type: GeneratorType +// +// fun resourcesFilesFilter(input: FileTree): FileTree +// +// fun getImports(): List +// +// fun addActualOverrideModifier( +// propertyName: String, +// property: PropertySpec.Builder, +// inputMetadata: List, +// targetObject: GeneratedObject, +// ): GeneratedObjectModifier { +// // Read actual interfaces of target object generator type +// val actualInterfaces: List = inputMetadata.getActualInterfaces( +// generatorType = targetObject.generatorType +// ) +// +// var containsInActualInterfaces = false +// +// // Search property in actual interfaces +// actualInterfaces.forEach { genInterface -> +// val hasInInterface = genInterface.properties.any { +// it.name == propertyName +// } +// +// if (hasInInterface) { +// containsInActualInterfaces = true +// } +// } +// +// return if (targetObject.isObject) { +// if (containsInActualInterfaces) { +// property.addModifiers(KModifier.OVERRIDE) +// GeneratedObjectModifier.Override +// } else { +// when (targetObject.modifier) { +// GeneratedObjectModifier.Actual -> { +// property.addModifiers(KModifier.ACTUAL) +// GeneratedObjectModifier.Actual +// } +// +// else -> { +// GeneratedObjectModifier.None +// } +// } +// } +// } else { +// GeneratedObjectModifier.None +// } +// } +// } +// +// interface InterfaceGenerator { +// fun generateInterface( +// project: Project, +// metadata: List, +// resourcesFiles: ResourcesFiles +// ): GenerationResult? +// } +// +// interface ObjectGenerator { +// fun generateObject( +// project: Project, +// metadata: List, +// resourcesFiles: ResourcesFiles +// ): GenerationResult? +// } +// +// interface ResourcesGenerator { +// fun generateResources( +// project: Project, +// metadata: List, +// resourcesFiles: ResourcesFiles +// ) +// } +// +// data class GenerationResult( +// val typeSpec: TypeSpec, +// val metadata: GeneratedObject +// ) +// +// data class ResourcesFiles( +// val lowerResourcesFileTree: FileTree, +// val ownResourcesFileTree: FileTree, +// val upperResourcesFileTree: FileTree +// ) +// +// interface SourceSet { +// val name: String +// +// fun addSourceDir(directory: File) +// fun addResourcesDir(directory: File) +// fun addAssetsDir(directory: File) +// } +// +// data class Settings( +// val inputMetadataFiles: FileTree, +// val outputMetadataFile: File, +// val packageName: String, +// val className: String, +// val visibility: MRVisibility, +// val assetsDir: Directory, +// val sourceSetName: String, +// val sourceSetDir: Directory, +// val resourcesDir: Directory, +// val isStrictLineBreaks: Boolean, +// val iosLocalizationRegion: Provider, +// val androidRClassPackage: Provider, +// ) +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/NOPObjectBodyExtendable.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/NOPObjectBodyExtendable.kt index d0f677a8e..c04de3fca 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/NOPObjectBodyExtendable.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/NOPObjectBodyExtendable.kt @@ -1,13 +1,13 @@ -/* - * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator - -import com.squareup.kotlinpoet.TypeSpec - -class NOPObjectBodyExtendable : ObjectBodyExtendable { - override fun extendObjectBodyAtStart(classBuilder: TypeSpec.Builder) = Unit - - override fun extendObjectBodyAtEnd(classBuilder: TypeSpec.Builder) = Unit -} +///* +// * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator +// +//import com.squareup.kotlinpoet.TypeSpec +// +//class NOPObjectBodyExtendable : ObjectBodyExtendable { +// override fun extendObjectBodyAtStart(classBuilder: TypeSpec.Builder) = Unit +// +// override fun extendObjectBodyAtEnd(classBuilder: TypeSpec.Builder) = Unit +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ObjectBodyExtendable.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ObjectBodyExtendable.kt index 72f2c5f98..82e1ce8de 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ObjectBodyExtendable.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ObjectBodyExtendable.kt @@ -1,12 +1,12 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator - -import com.squareup.kotlinpoet.TypeSpec - -interface ObjectBodyExtendable { - fun extendObjectBodyAtStart(classBuilder: TypeSpec.Builder) - fun extendObjectBodyAtEnd(classBuilder: TypeSpec.Builder) -} +///* +// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator +// +//import com.squareup.kotlinpoet.TypeSpec +// +//interface ObjectBodyExtendable { +// fun extendObjectBodyAtStart(classBuilder: TypeSpec.Builder) +// fun extendObjectBodyAtEnd(classBuilder: TypeSpec.Builder) +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt index 47c1d070d..0b4843545 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt @@ -1,218 +1,218 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator - -import com.squareup.kotlinpoet.ClassName -import dev.icerock.gradle.generator.android.AndroidPluralsGenerator -import dev.icerock.gradle.generator.apple.ApplePluralsGenerator -import dev.icerock.gradle.generator.common.CommonPluralsGenerator -import dev.icerock.gradle.generator.js.JsPluralsGenerator -import dev.icerock.gradle.generator.jvm.JvmPluralsGenerator -import dev.icerock.gradle.metadata.model.GeneratedObject -import dev.icerock.gradle.metadata.model.GeneratorType -import dev.icerock.gradle.metadata.objectsWithProperties -import dev.icerock.gradle.utils.removeLineWraps -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.JsonElement -import kotlinx.serialization.json.JsonObject -import kotlinx.serialization.json.JsonPrimitive -import kotlinx.serialization.json.decodeFromJsonElement -import org.gradle.api.file.FileTree -import org.w3c.dom.Document -import org.w3c.dom.Element -import java.io.File -import javax.xml.parsers.DocumentBuilderFactory - -typealias PluralMap = Map - -/** - * How the plural element can be declared in our xml files. - * - * 'plurals' match the element name used on the Android platform. This allows us to upload the source xml as-is to - * translation websites as they'll interpret it as an Android resource file. - */ -private val SOURCE_PLURAL_NODE_NAMES = listOf("plural", "plurals") - -abstract class PluralsGenerator( - private val ownResourcesFileTree: FileTree, - private val strictLineBreaks: Boolean -) : LocalizationGenerator() { - - override val inputFiles: Iterable - get() = ownResourcesFileTree.matching { it.include(PLURALS_MASK) }.files - - override val resourceClassName = ClassName("dev.icerock.moko.resources", "PluralsResource") - override val mrObjectName: String = "plurals" - - override val type: GeneratorType = GeneratorType.Plurals - - override fun getLanguagesAllMaps( - previousLanguageMaps: Map>, - languageMap: Map> - ): Map> { - val resultLanguageMap: MutableMap> = mutableMapOf() - - resultLanguageMap.putAll(previousLanguageMaps) - - languageMap.forEach { (languageType: LanguageType, value: Map) -> - - val currentMap: MutableMap = - previousLanguageMaps[languageType]?.toMutableMap() ?: mutableMapOf() - - value.forEach { (key, value) -> currentMap[key] = value } - - resultLanguageMap[languageType] = currentMap - } - - return resultLanguageMap - } - - override fun getPreviousLanguagesMap( - inputMetadata: List, - targetObject: GeneratedObject, - ): Map> { - if (!targetObject.isObject || !targetObject.isActual) return emptyMap() - val json = Json - val objectsWithProperties: List = inputMetadata.objectsWithProperties(targetObject) - - val languagesMaps = mutableMapOf>() - - objectsWithProperties.forEach { generatedObject -> - generatedObject.properties.forEach { property -> - val data = json.decodeFromJsonElement>(property.data) - - data.forEach { (languageTag, value) -> - val languageType: LanguageType = if (languageTag == BASE_LANGUAGE) { - LanguageType.Base - } else { - LanguageType.Locale(languageTag) - } - - val currentMap: MutableMap = - languagesMaps[languageType]?.toMutableMap() ?: mutableMapOf() - currentMap[property.name] = value - - languagesMaps[languageType] = currentMap - } - } - } - - return languagesMaps - } - - override fun getPropertyMetadata( - key: KeyType, - languageMap: Map> - ): Map { - val values = mutableMapOf() - - languageMap.forEach { (languageType, plurals) -> - plurals.forEach { (pluralKey: KeyType, value: Map) -> - if (pluralKey == key) { - values[languageType.language()] = JsonObject(content = value.mapValues { - JsonPrimitive(it.value) - }) - } - } - } - - return values - } - - override fun loadLanguageMap(): Map> { - return inputFiles.map { file -> - val language: LanguageType = LanguageType.fromFileName(file.parentFile.name) - val strings: Map = loadLanguagePlurals(file) - language to strings - }.groupBy( - keySelector = { it.first }, - valueTransform = { it.second } - ).mapValues { value -> - val maps = value.value - maps.fold(mutableMapOf()) { result, keyValueMap -> - result.putAll(keyValueMap) - result - } - } - } - - override fun getImports(): List = emptyList() - - private fun loadLanguagePlurals(pluralsFile: File): Map { - val dbFactory = DocumentBuilderFactory.newInstance() - val dBuilder = dbFactory.newDocumentBuilder() - val doc = dBuilder.parse(pluralsFile) - - val mutableMap = mutableMapOf() - - doc.findPluralNodes().forEach { pluralNode -> - val pluralMap = mutableMapOf() - - val name = pluralNode.attributes.getNamedItem("name").textContent - - val itemNodes = pluralNode.getElementsByTagName("item") - for (j in 0 until itemNodes.length) { - val item = itemNodes.item(j) - - val quantity = item.attributes.getNamedItem("quantity").textContent.trim() - val value = item.textContent - - pluralMap[quantity] = if (strictLineBreaks) value else value.removeLineWraps() - } - - mutableMap[name] = pluralMap - } - - return mutableMap - } - - private fun Document.findPluralNodes() = sequence { - SOURCE_PLURAL_NODE_NAMES.forEach { elementName -> - val pluralNodes = getElementsByTagName(elementName) - for (i in 0 until pluralNodes.length) { - yield(pluralNodes.item(i) as Element) - } - } - } - - class Feature( - private val settings: MRGenerator.Settings - ) : ResourceGeneratorFeature { - override fun createCommonGenerator(): PluralsGenerator = CommonPluralsGenerator( - ownResourcesFileTree = settings.ownResourcesFileTree, - strictLineBreaks = settings.isStrictLineBreaks - ) - - override fun createAppleGenerator(): PluralsGenerator = ApplePluralsGenerator( - ownResourcesFileTree = settings.ownResourcesFileTree, - strictLineBreaks = settings.isStrictLineBreaks, - baseLocalizationRegion = settings.iosLocalizationRegion - ) - - override fun createAndroidGenerator(): PluralsGenerator = AndroidPluralsGenerator( - ownResourcesFileTree = settings.ownResourcesFileTree, - strictLineBreaks = settings.isStrictLineBreaks, - androidRClassPackage = settings.androidRClassPackage, - ) - - override fun createJvmGenerator(): PluralsGenerator = JvmPluralsGenerator( - ownResourcesFileTree = settings.ownResourcesFileTree, - strictLineBreaks = settings.isStrictLineBreaks, - settings = settings - ) - - override fun createJsGenerator(): PluralsGenerator = JsPluralsGenerator( - ownResourcesFileTree = settings.ownResourcesFileTree, - mrClassPackage = settings.packageName, - strictLineBreaks = settings.isStrictLineBreaks - ) - } - - - companion object { - const val PLURALS_MASK = "**/plurals*.xml" - val PLURALS_REGEX: Regex = "^.*/plurals.*.xml".toRegex() - } -} +///* +// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator +// +//import com.squareup.kotlinpoet.ClassName +//import dev.icerock.gradle.generator.android.AndroidPluralsGenerator +//import dev.icerock.gradle.generator.apple.ApplePluralsGenerator +//import dev.icerock.gradle.generator.common.CommonPluralsGenerator +//import dev.icerock.gradle.generator.js.JsPluralsGenerator +//import dev.icerock.gradle.generator.jvm.JvmPluralsGenerator +//import dev.icerock.gradle.metadata.model.GeneratedObject +//import dev.icerock.gradle.metadata.model.GeneratorType +//import dev.icerock.gradle.metadata.objectsWithProperties +//import dev.icerock.gradle.utils.removeLineWraps +//import kotlinx.serialization.json.Json +//import kotlinx.serialization.json.JsonElement +//import kotlinx.serialization.json.JsonObject +//import kotlinx.serialization.json.JsonPrimitive +//import kotlinx.serialization.json.decodeFromJsonElement +//import org.gradle.api.file.FileTree +//import org.w3c.dom.Document +//import org.w3c.dom.Element +//import java.io.File +//import javax.xml.parsers.DocumentBuilderFactory +// +//typealias PluralMap = Map +// +///** +// * How the plural element can be declared in our xml files. +// * +// * 'plurals' match the element name used on the Android platform. This allows us to upload the source xml as-is to +// * translation websites as they'll interpret it as an Android resource file. +// */ +//private val SOURCE_PLURAL_NODE_NAMES = listOf("plural", "plurals") +// +//abstract class PluralsGenerator( +// private val ownResourcesFileTree: FileTree, +// private val strictLineBreaks: Boolean +//) : LocalizationGenerator() { +// +// override val inputFiles: Iterable +// get() = ownResourcesFileTree.matching { it.include(PLURALS_MASK) }.files +// +// override val resourceClassName = ClassName("dev.icerock.moko.resources", "PluralsResource") +// override val mrObjectName: String = "plurals" +// +// override val type: GeneratorType = GeneratorType.Plurals +// +// override fun getLanguagesAllMaps( +// previousLanguageMaps: Map>, +// languageMap: Map> +// ): Map> { +// val resultLanguageMap: MutableMap> = mutableMapOf() +// +// resultLanguageMap.putAll(previousLanguageMaps) +// +// languageMap.forEach { (languageType: LanguageType, value: Map) -> +// +// val currentMap: MutableMap = +// previousLanguageMaps[languageType]?.toMutableMap() ?: mutableMapOf() +// +// value.forEach { (key, value) -> currentMap[key] = value } +// +// resultLanguageMap[languageType] = currentMap +// } +// +// return resultLanguageMap +// } +// +// override fun getPreviousLanguagesMap( +// inputMetadata: List, +// targetObject: GeneratedObject, +// ): Map> { +// if (!targetObject.isObject || !targetObject.isActual) return emptyMap() +// val json = Json +// val objectsWithProperties: List = inputMetadata.objectsWithProperties(targetObject) +// +// val languagesMaps = mutableMapOf>() +// +// objectsWithProperties.forEach { generatedObject -> +// generatedObject.properties.forEach { property -> +// val data = json.decodeFromJsonElement>(property.data) +// +// data.forEach { (languageTag, value) -> +// val languageType: LanguageType = if (languageTag == BASE_LANGUAGE) { +// LanguageType.Base +// } else { +// LanguageType.Locale(languageTag) +// } +// +// val currentMap: MutableMap = +// languagesMaps[languageType]?.toMutableMap() ?: mutableMapOf() +// currentMap[property.name] = value +// +// languagesMaps[languageType] = currentMap +// } +// } +// } +// +// return languagesMaps +// } +// +// override fun getPropertyMetadata( +// key: KeyType, +// languageMap: Map> +// ): Map { +// val values = mutableMapOf() +// +// languageMap.forEach { (languageType, plurals) -> +// plurals.forEach { (pluralKey: KeyType, value: Map) -> +// if (pluralKey == key) { +// values[languageType.language()] = JsonObject(content = value.mapValues { +// JsonPrimitive(it.value) +// }) +// } +// } +// } +// +// return values +// } +// +// override fun loadLanguageMap(): Map> { +// return inputFiles.map { file -> +// val language: LanguageType = LanguageType.fromFileName(file.parentFile.name) +// val strings: Map = loadLanguagePlurals(file) +// language to strings +// }.groupBy( +// keySelector = { it.first }, +// valueTransform = { it.second } +// ).mapValues { value -> +// val maps = value.value +// maps.fold(mutableMapOf()) { result, keyValueMap -> +// result.putAll(keyValueMap) +// result +// } +// } +// } +// +// override fun getImports(): List = emptyList() +// +// private fun loadLanguagePlurals(pluralsFile: File): Map { +// val dbFactory = DocumentBuilderFactory.newInstance() +// val dBuilder = dbFactory.newDocumentBuilder() +// val doc = dBuilder.parse(pluralsFile) +// +// val mutableMap = mutableMapOf() +// +// doc.findPluralNodes().forEach { pluralNode -> +// val pluralMap = mutableMapOf() +// +// val name = pluralNode.attributes.getNamedItem("name").textContent +// +// val itemNodes = pluralNode.getElementsByTagName("item") +// for (j in 0 until itemNodes.length) { +// val item = itemNodes.item(j) +// +// val quantity = item.attributes.getNamedItem("quantity").textContent.trim() +// val value = item.textContent +// +// pluralMap[quantity] = if (strictLineBreaks) value else value.removeLineWraps() +// } +// +// mutableMap[name] = pluralMap +// } +// +// return mutableMap +// } +// +// private fun Document.findPluralNodes() = sequence { +// SOURCE_PLURAL_NODE_NAMES.forEach { elementName -> +// val pluralNodes = getElementsByTagName(elementName) +// for (i in 0 until pluralNodes.length) { +// yield(pluralNodes.item(i) as Element) +// } +// } +// } +// +// class Feature( +// private val settings: MRGenerator.Settings +// ) : ResourceGeneratorFeature { +// override fun createCommonGenerator(): PluralsGenerator = CommonPluralsGenerator( +// ownResourcesFileTree = settings.ownResourcesFileTree, +// strictLineBreaks = settings.isStrictLineBreaks +// ) +// +// override fun createAppleGenerator(): PluralsGenerator = ApplePluralsGenerator( +// ownResourcesFileTree = settings.ownResourcesFileTree, +// strictLineBreaks = settings.isStrictLineBreaks, +// baseLocalizationRegion = settings.iosLocalizationRegion +// ) +// +// override fun createAndroidGenerator(): PluralsGenerator = AndroidPluralsGenerator( +// ownResourcesFileTree = settings.ownResourcesFileTree, +// strictLineBreaks = settings.isStrictLineBreaks, +// androidRClassPackage = settings.androidRClassPackage, +// ) +// +// override fun createJvmGenerator(): PluralsGenerator = JvmPluralsGenerator( +// ownResourcesFileTree = settings.ownResourcesFileTree, +// strictLineBreaks = settings.isStrictLineBreaks, +// settings = settings +// ) +// +// override fun createJsGenerator(): PluralsGenerator = JsPluralsGenerator( +// ownResourcesFileTree = settings.ownResourcesFileTree, +// mrClassPackage = settings.packageName, +// strictLineBreaks = settings.isStrictLineBreaks +// ) +// } +// +// +// companion object { +// const val PLURALS_MASK = "**/plurals*.xml" +// val PLURALS_REGEX: Regex = "^.*/plurals.*.xml".toRegex() +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceGeneratorFeature.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceGeneratorFeature.kt index 99178802f..adad88965 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceGeneratorFeature.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceGeneratorFeature.kt @@ -1,13 +1,13 @@ -/* - * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator - -interface ResourceGeneratorFeature { - fun createCommonGenerator(): T - fun createAppleGenerator(): T - fun createAndroidGenerator(): T - fun createJvmGenerator(): T - fun createJsGenerator(): T -} +///* +// * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator +// +//interface ResourceGeneratorFeature { +// fun createCommonGenerator(): T +// fun createAppleGenerator(): T +// fun createAndroidGenerator(): T +// fun createJvmGenerator(): T +// fun createJsGenerator(): T +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt index f3ee6606f..494561ba2 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt @@ -1,198 +1,198 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator - -import com.squareup.kotlinpoet.ClassName -import dev.icerock.gradle.generator.android.AndroidStringsGenerator -import dev.icerock.gradle.generator.apple.AppleStringsGenerator -import dev.icerock.gradle.generator.common.CommonStringsGenerator -import dev.icerock.gradle.generator.js.JsStringsGenerator -import dev.icerock.gradle.generator.jvm.JvmStringsGenerator -import dev.icerock.gradle.metadata.model.GeneratedObject -import dev.icerock.gradle.metadata.model.GeneratorType -import dev.icerock.gradle.metadata.objectsWithProperties -import dev.icerock.gradle.utils.removeLineWraps -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.JsonElement -import kotlinx.serialization.json.JsonPrimitive -import kotlinx.serialization.json.decodeFromJsonElement -import org.gradle.api.file.FileTree -import java.io.File -import javax.xml.parsers.DocumentBuilderFactory - -typealias KeyType = String - -abstract class StringsGenerator( - private val resourcesFileTree: FileTree, - private val strictLineBreaks: Boolean, -) : LocalizationGenerator() { - - override val inputFiles: Iterable - get() = resourcesFileTree.matching { it.include(STRINGS_MASK) }.files - - override val resourceClassName = ClassName("dev.icerock.moko.resources", "StringResource") - override val mrObjectName: String = "strings" - - override val type: GeneratorType = GeneratorType.Strings - - override fun getLanguagesAllMaps( - previousLanguageMaps: Map>, - languageMap: Map> - ): Map> { - val resultLanguageMap: MutableMap> = mutableMapOf() - - resultLanguageMap.putAll(previousLanguageMaps) - - languageMap.forEach { (languageType: LanguageType, value: Map) -> - - val currentMap: MutableMap = - previousLanguageMaps[languageType]?.toMutableMap() ?: mutableMapOf() - - value.forEach { (key, value) -> currentMap[key] = value } - - resultLanguageMap[languageType] = currentMap - } - - return resultLanguageMap - } - - override fun getPreviousLanguagesMap( - inputMetadata: List, - targetObject: GeneratedObject, - ): Map> { - if (!targetObject.isObject || !targetObject.isActual) return emptyMap() - - val json = Json - val objectsWithProperties: List = inputMetadata.objectsWithProperties(targetObject) - - val languagesMaps = mutableMapOf>() - - objectsWithProperties.forEach { generatedObject -> - generatedObject.properties.forEach { property -> - val data = json.decodeFromJsonElement>(property.data) - - data.forEach { (languageTag, value) -> - val languageType: LanguageType = if (languageTag == BASE_LANGUAGE) { - LanguageType.Base - } else { - LanguageType.Locale(languageTag) - } - - val currentMap: MutableMap = - languagesMaps[languageType]?.toMutableMap() ?: mutableMapOf() - - currentMap[property.name] = value.content - - languagesMaps[languageType] = currentMap - } - } - } - - return languagesMaps - } - - override fun getPropertyMetadata( - key: KeyType, - languageMap: Map>, - ): Map { - val values = mutableMapOf() - - languageMap.forEach { (languageType, strings) -> - strings.forEach { (stringKey, value) -> - if (stringKey == key) { - values[languageType.language()] = JsonPrimitive(value) - } - } - } - - return values - } - - - override fun loadLanguageMap(): Map> { - return inputFiles.map { file -> - val language: LanguageType = LanguageType.fromFileName(file.parentFile.name) - val strings: Map = loadLanguageStrings(file) - language to strings - }.groupBy( - keySelector = { it.first }, - valueTransform = { it.second } - ).mapValues { value -> - val maps = value.value - maps.fold(mutableMapOf()) { result, keyValueMap -> - result.putAll(keyValueMap) - result - } - } - } - - private fun loadLanguageStrings(stringsFile: File): Map { - val dbFactory = DocumentBuilderFactory.newInstance() - val dBuilder = dbFactory.newDocumentBuilder() - val doc = dBuilder.parse(stringsFile) - - val stringNodes = doc.getElementsByTagName("string") - val mutableMap = mutableMapOf() - - for (i in 0 until stringNodes.length) { - val stringNode = stringNodes.item(i) - val name = stringNode.attributes.getNamedItem("name").textContent - val value = stringNode.textContent - - mutableMap[name] = if (strictLineBreaks) value else value.removeLineWraps() - } - - val incorrectKeys = mutableMap - .filter { it.key == it.value } - .keys - .toList() - - if (incorrectKeys.isNotEmpty()) { - throw EqualStringKeysException(incorrectKeys) - } - - return mutableMap - } - - override fun getImports(): List = emptyList() - - class Feature( - private val settings: MRGenerator.Settings, - ) : ResourceGeneratorFeature { - override fun createCommonGenerator(): StringsGenerator = CommonStringsGenerator( - resourcesFileTree = settings.ownResourcesFileTree, - strictLineBreaks = settings.isStrictLineBreaks - ) - - override fun createAppleGenerator(): StringsGenerator = AppleStringsGenerator( - resourcesFileTree = settings.ownResourcesFileTree, - strictLineBreaks = settings.isStrictLineBreaks, - baseLocalizationRegion = settings.iosLocalizationRegion - ) - - override fun createAndroidGenerator(): StringsGenerator = AndroidStringsGenerator( - resourcesFileTree = settings.ownResourcesFileTree, - strictLineBreaks = settings.isStrictLineBreaks, - androidRClassPackage = settings.androidRClassPackage - ) - - override fun createJsGenerator(): StringsGenerator = JsStringsGenerator( - resourcesFileTree = settings.ownResourcesFileTree, - mrClassPackage = settings.packageName, - strictLineBreaks = settings.isStrictLineBreaks - ) - - override fun createJvmGenerator(): StringsGenerator = JvmStringsGenerator( - resourcesFileTree = settings.ownResourcesFileTree, - strictLineBreaks = settings.isStrictLineBreaks, - settings = settings - ) - } - - companion object { - const val STRINGS_MASK = "**/strings*.xml" - val STRINGS_REGEX: Regex = "^.*/strings.*.xml".toRegex() - } -} +///* +// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator +// +//import com.squareup.kotlinpoet.ClassName +//import dev.icerock.gradle.generator.android.AndroidStringsGenerator +//import dev.icerock.gradle.generator.apple.AppleStringsGenerator +//import dev.icerock.gradle.generator.common.CommonStringsGenerator +//import dev.icerock.gradle.generator.js.JsStringsGenerator +//import dev.icerock.gradle.generator.jvm.JvmStringsGenerator +//import dev.icerock.gradle.metadata.model.GeneratedObject +//import dev.icerock.gradle.metadata.model.GeneratorType +//import dev.icerock.gradle.metadata.objectsWithProperties +//import dev.icerock.gradle.utils.removeLineWraps +//import kotlinx.serialization.json.Json +//import kotlinx.serialization.json.JsonElement +//import kotlinx.serialization.json.JsonPrimitive +//import kotlinx.serialization.json.decodeFromJsonElement +//import org.gradle.api.file.FileTree +//import java.io.File +//import javax.xml.parsers.DocumentBuilderFactory +// +//typealias KeyType = String +// +//abstract class StringsGenerator( +// private val resourcesFileTree: FileTree, +// private val strictLineBreaks: Boolean, +//) : LocalizationGenerator() { +// +// override val inputFiles: Iterable +// get() = resourcesFileTree.matching { it.include(STRINGS_MASK) }.files +// +// override val resourceClassName = ClassName("dev.icerock.moko.resources", "StringResource") +// override val mrObjectName: String = "strings" +// +// override val type: GeneratorType = GeneratorType.Strings +// +// override fun getLanguagesAllMaps( +// previousLanguageMaps: Map>, +// languageMap: Map> +// ): Map> { +// val resultLanguageMap: MutableMap> = mutableMapOf() +// +// resultLanguageMap.putAll(previousLanguageMaps) +// +// languageMap.forEach { (languageType: LanguageType, value: Map) -> +// +// val currentMap: MutableMap = +// previousLanguageMaps[languageType]?.toMutableMap() ?: mutableMapOf() +// +// value.forEach { (key, value) -> currentMap[key] = value } +// +// resultLanguageMap[languageType] = currentMap +// } +// +// return resultLanguageMap +// } +// +// override fun getPreviousLanguagesMap( +// inputMetadata: List, +// targetObject: GeneratedObject, +// ): Map> { +// if (!targetObject.isObject || !targetObject.isActual) return emptyMap() +// +// val json = Json +// val objectsWithProperties: List = inputMetadata.objectsWithProperties(targetObject) +// +// val languagesMaps = mutableMapOf>() +// +// objectsWithProperties.forEach { generatedObject -> +// generatedObject.properties.forEach { property -> +// val data = json.decodeFromJsonElement>(property.data) +// +// data.forEach { (languageTag, value) -> +// val languageType: LanguageType = if (languageTag == BASE_LANGUAGE) { +// LanguageType.Base +// } else { +// LanguageType.Locale(languageTag) +// } +// +// val currentMap: MutableMap = +// languagesMaps[languageType]?.toMutableMap() ?: mutableMapOf() +// +// currentMap[property.name] = value.content +// +// languagesMaps[languageType] = currentMap +// } +// } +// } +// +// return languagesMaps +// } +// +// override fun getPropertyMetadata( +// key: KeyType, +// languageMap: Map>, +// ): Map { +// val values = mutableMapOf() +// +// languageMap.forEach { (languageType, strings) -> +// strings.forEach { (stringKey, value) -> +// if (stringKey == key) { +// values[languageType.language()] = JsonPrimitive(value) +// } +// } +// } +// +// return values +// } +// +// +// override fun loadLanguageMap(): Map> { +// return inputFiles.map { file -> +// val language: LanguageType = LanguageType.fromFileName(file.parentFile.name) +// val strings: Map = loadLanguageStrings(file) +// language to strings +// }.groupBy( +// keySelector = { it.first }, +// valueTransform = { it.second } +// ).mapValues { value -> +// val maps = value.value +// maps.fold(mutableMapOf()) { result, keyValueMap -> +// result.putAll(keyValueMap) +// result +// } +// } +// } +// +// private fun loadLanguageStrings(stringsFile: File): Map { +// val dbFactory = DocumentBuilderFactory.newInstance() +// val dBuilder = dbFactory.newDocumentBuilder() +// val doc = dBuilder.parse(stringsFile) +// +// val stringNodes = doc.getElementsByTagName("string") +// val mutableMap = mutableMapOf() +// +// for (i in 0 until stringNodes.length) { +// val stringNode = stringNodes.item(i) +// val name = stringNode.attributes.getNamedItem("name").textContent +// val value = stringNode.textContent +// +// mutableMap[name] = if (strictLineBreaks) value else value.removeLineWraps() +// } +// +// val incorrectKeys = mutableMap +// .filter { it.key == it.value } +// .keys +// .toList() +// +// if (incorrectKeys.isNotEmpty()) { +// throw EqualStringKeysException(incorrectKeys) +// } +// +// return mutableMap +// } +// +// override fun getImports(): List = emptyList() +// +// class Feature( +// private val settings: MRGenerator.Settings, +// ) : ResourceGeneratorFeature { +// override fun createCommonGenerator(): StringsGenerator = CommonStringsGenerator( +// resourcesFileTree = settings.ownResourcesFileTree, +// strictLineBreaks = settings.isStrictLineBreaks +// ) +// +// override fun createAppleGenerator(): StringsGenerator = AppleStringsGenerator( +// resourcesFileTree = settings.ownResourcesFileTree, +// strictLineBreaks = settings.isStrictLineBreaks, +// baseLocalizationRegion = settings.iosLocalizationRegion +// ) +// +// override fun createAndroidGenerator(): StringsGenerator = AndroidStringsGenerator( +// resourcesFileTree = settings.ownResourcesFileTree, +// strictLineBreaks = settings.isStrictLineBreaks, +// androidRClassPackage = settings.androidRClassPackage +// ) +// +// override fun createJsGenerator(): StringsGenerator = JsStringsGenerator( +// resourcesFileTree = settings.ownResourcesFileTree, +// mrClassPackage = settings.packageName, +// strictLineBreaks = settings.isStrictLineBreaks +// ) +// +// override fun createJvmGenerator(): StringsGenerator = JvmStringsGenerator( +// resourcesFileTree = settings.ownResourcesFileTree, +// strictLineBreaks = settings.isStrictLineBreaks, +// settings = settings +// ) +// } +// +// companion object { +// const val STRINGS_MASK = "**/strings*.xml" +// val STRINGS_REGEX: Regex = "^.*/strings.*.xml".toRegex() +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt index f1e925730..b39b530ef 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt @@ -1,241 +1,241 @@ -package dev.icerock.gradle.generator - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.FileSpec -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.metadata.Metadata.createOutputMetadata -import dev.icerock.gradle.metadata.Metadata.readInputMetadata -import dev.icerock.gradle.metadata.getExpectInterfaces -import dev.icerock.gradle.metadata.getGeneratorInterfaces -import dev.icerock.gradle.metadata.getInterfaceName -import dev.icerock.gradle.metadata.isNotEmptyMetadata -import dev.icerock.gradle.metadata.model.GeneratedObject -import dev.icerock.gradle.metadata.model.GeneratedObjectModifier -import dev.icerock.gradle.metadata.model.GeneratedObjectType -import dev.icerock.gradle.metadata.model.GeneratorType -import dev.icerock.gradle.metadata.resourcesIsEmpty -import dev.icerock.gradle.toModifier -import dev.icerock.gradle.utils.targetName -import org.gradle.api.Project - -abstract class TargetMRGenerator( - private val project: Project, - settings: Settings, - generators: List, -) : MRGenerator( - settings = settings, - generators = generators -) { - - override fun getMRClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun generateFileSpec(): FileSpec? { - //Read list of generated resources on previous level's - val inputMetadata: List = readInputMetadata( - inputMetadataFiles = settings.inputMetadataFiles - ) - - // Check resources for generation: if lower resources is empty - // and own resources has no files - skip step - if (resourcesIsEmpty(inputMetadata, settings)) return null - - val outputMetadata: MutableList = mutableListOf() - - // If previous levels has resources, need generate actual objects - val needGenerateActual: Boolean = inputMetadata.isNotEmptyMetadata() - - val visibilityModifier: KModifier = settings.visibility.toModifier() - - val fileSpec: FileSpec.Builder = FileSpec.builder( - packageName = settings.packageName, - fileName = settings.className - ) - - @Suppress("SpreadOperator") - val mrClassSpec = TypeSpec.objectBuilder(settings.className) // default: object MR - .addModifiers(visibilityModifier) // public/internal - - if (needGenerateActual) { - mrClassSpec.addModifiers(KModifier.ACTUAL) - } - - // Add actual implementation of expect interfaces from previous levels - if (inputMetadata.isNotEmpty()) { - generateTargetInterfaces( - inputMetadata = inputMetadata, - outputMetadata = outputMetadata, - visibilityModifier = settings.visibility.toModifier(), - generateActualObject = needGenerateActual, - fileSpec = fileSpec - ) - - // Generation of actual interfaces not realised on current level - val expectInterfaces: List = inputMetadata.getExpectInterfaces() - - expectInterfaces.forEach { expectInterface -> - val actualInterfaceTypeSpec: TypeSpec = - TypeSpec.interfaceBuilder(expectInterface.name) - .addModifiers(visibilityModifier) - .addModifiers(KModifier.ACTUAL) - .build() - - fileSpec.addType(actualInterfaceTypeSpec) - outputMetadata.add(expectInterface.copy(modifier = GeneratedObjectModifier.Actual)) - } - } - - val generatedActualObjects = mutableListOf() - - generators.forEach { generator: Generator -> - val objectBuilder: TypeSpec.Builder = TypeSpec - .objectBuilder(generator.mrObjectName) - .addModifiers(visibilityModifier) - .addSuperinterface( - superinterface = generator.resourceContainerClass.parameterizedBy( - generator.resourceClassName - ) - ) - - // Implement to object expect interfaces from previous - // levels of resources - inputMetadata.getGeneratorInterfaces(generator.type) - .forEach { generatedObject: GeneratedObject -> - objectBuilder.addSuperinterface( - ClassName( - packageName = settings.packageName, - generatedObject.name - ) - ) - } - - val result: GenerationResult? = generator.generate( - project = project, - inputMetadata = inputMetadata, - outputMetadata = GeneratedObject( - generatorType = generator.type, - modifier = if (needGenerateActual) { - GeneratedObjectModifier.Actual - } else { - GeneratedObjectModifier.None - }, - type = GeneratedObjectType.Object, - name = generator.mrObjectName, - interfaces = getObjectInterfaces( - generatorType = generator.type, - objectName = generator.mrObjectName, - inputMetadata = inputMetadata - ) - ), - assetsGenerationDir = assetsGenerationDir, - resourcesGenerationDir = resourcesGenerationDir, - objectBuilder = objectBuilder, - ) - - if (result != null) { - mrClassSpec.addType(result.typeSpec) - outputMetadata.add(result.metadata) - generatedActualObjects.add(result.metadata) - } - } - - processMRClass(mrClassSpec) - - if (generatedActualObjects.isNotEmpty()) { - val mrClass = mrClassSpec.build() - fileSpec.addType(mrClass) - - outputMetadata.add( - GeneratedObject( - generatorType = GeneratorType.None, - type = GeneratedObjectType.Object, - name = settings.className, - modifier = GeneratedObjectModifier.Actual, - objects = generatedActualObjects - ) - ) - } - - generators - .flatMap { it.getImports() } - .plus(getImports()) - .forEach { fileSpec.addImport(it.packageName, it.simpleName) } - - createOutputMetadata( - outputMetadataFile = settings.outputMetadataFile, - generatedObjects = inputMetadata - ) - - return fileSpec.build() - } - - private fun generateTargetInterfaces( - inputMetadata: List, - outputMetadata: MutableList, - visibilityModifier: KModifier, - generateActualObject: Boolean, - fileSpec: FileSpec.Builder, - ) { - if (settings.ownResourcesFileTree.files.isEmpty()) return - - val targetName: String = settings.ownResourcesFileTree.files - .firstOrNull()?.targetName ?: return - - generators.forEach { generator -> - val interfaceName = getInterfaceName( - sourceSetName = targetName, - generatorType = generator.type - ) - - val resourcesInterfaceBuilder: TypeSpec.Builder = - TypeSpec.interfaceBuilder(interfaceName) - .addModifiers(visibilityModifier) - - val result: GenerationResult? = generator.generate( - project = project, - inputMetadata = inputMetadata, - outputMetadata = GeneratedObject( - generatorType = generator.type, - modifier = if (generateActualObject) { - GeneratedObjectModifier.Actual - } else { - GeneratedObjectModifier.None - }, - type = GeneratedObjectType.Interface, - name = interfaceName - ), - assetsGenerationDir = assetsGenerationDir, - resourcesGenerationDir = resourcesGenerationDir, - objectBuilder = resourcesInterfaceBuilder - ) - - if (result != null) { - fileSpec.addType(result.typeSpec) - outputMetadata.add(result.metadata) - } - } - } - - private fun getObjectInterfaces( - generatorType: GeneratorType, - objectName: String, - inputMetadata: List, - ): List { - val interfaces = mutableListOf() - - val mrObjects: List = inputMetadata.filter { - it.isExpectObject && it.generatorType == GeneratorType.None - } - - mrObjects.forEach { mrObject -> - mrObject.objects.forEach { - if (it.generatorType == generatorType && it.name == objectName) { - interfaces.addAll(it.interfaces) - } - } - } - - return interfaces.distinct() - } -} \ No newline at end of file +//package dev.icerock.gradle.generator +// +//import com.squareup.kotlinpoet.ClassName +//import com.squareup.kotlinpoet.FileSpec +//import com.squareup.kotlinpoet.KModifier +//import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +//import com.squareup.kotlinpoet.TypeSpec +//import dev.icerock.gradle.metadata.Metadata.createOutputMetadata +//import dev.icerock.gradle.metadata.Metadata.readInputMetadata +//import dev.icerock.gradle.metadata.getExpectInterfaces +//import dev.icerock.gradle.metadata.getGeneratorInterfaces +//import dev.icerock.gradle.metadata.getInterfaceName +//import dev.icerock.gradle.metadata.isNotEmptyMetadata +//import dev.icerock.gradle.metadata.model.GeneratedObject +//import dev.icerock.gradle.metadata.model.GeneratedObjectModifier +//import dev.icerock.gradle.metadata.model.GeneratedObjectType +//import dev.icerock.gradle.metadata.model.GeneratorType +//import dev.icerock.gradle.metadata.resourcesIsEmpty +//import dev.icerock.gradle.toModifier +//import dev.icerock.gradle.utils.targetName +//import org.gradle.api.Project +// +//abstract class TargetMRGenerator( +// private val project: Project, +// settings: Settings, +// generators: List, +//) : MRGenerator( +// settings = settings, +// generators = generators +//) { +// +// override fun getMRClassModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun generateFileSpec(): FileSpec? { +// //Read list of generated resources on previous level's +// val inputMetadata: List = readInputMetadata( +// inputMetadataFiles = settings.inputMetadataFiles +// ) +// +// // Check resources for generation: if lower resources is empty +// // and own resources has no files - skip step +// if (resourcesIsEmpty(inputMetadata, settings)) return null +// +// val outputMetadata: MutableList = mutableListOf() +// +// // If previous levels has resources, need generate actual objects +// val needGenerateActual: Boolean = inputMetadata.isNotEmptyMetadata() +// +// val visibilityModifier: KModifier = settings.visibility.toModifier() +// +// val fileSpec: FileSpec.Builder = FileSpec.builder( +// packageName = settings.packageName, +// fileName = settings.className +// ) +// +// @Suppress("SpreadOperator") +// val mrClassSpec = TypeSpec.objectBuilder(settings.className) // default: object MR +// .addModifiers(visibilityModifier) // public/internal +// +// if (needGenerateActual) { +// mrClassSpec.addModifiers(KModifier.ACTUAL) +// } +// +// // Add actual implementation of expect interfaces from previous levels +// if (inputMetadata.isNotEmpty()) { +// generateTargetInterfaces( +// inputMetadata = inputMetadata, +// outputMetadata = outputMetadata, +// visibilityModifier = settings.visibility.toModifier(), +// generateActualObject = needGenerateActual, +// fileSpec = fileSpec +// ) +// +// // Generation of actual interfaces not realised on current level +// val expectInterfaces: List = inputMetadata.getExpectInterfaces() +// +// expectInterfaces.forEach { expectInterface -> +// val actualInterfaceTypeSpec: TypeSpec = +// TypeSpec.interfaceBuilder(expectInterface.name) +// .addModifiers(visibilityModifier) +// .addModifiers(KModifier.ACTUAL) +// .build() +// +// fileSpec.addType(actualInterfaceTypeSpec) +// outputMetadata.add(expectInterface.copy(modifier = GeneratedObjectModifier.Actual)) +// } +// } +// +// val generatedActualObjects = mutableListOf() +// +// generators.forEach { generator: Generator -> +// val objectBuilder: TypeSpec.Builder = TypeSpec +// .objectBuilder(generator.mrObjectName) +// .addModifiers(visibilityModifier) +// .addSuperinterface( +// superinterface = generator.resourceContainerClass.parameterizedBy( +// generator.resourceClassName +// ) +// ) +// +// // Implement to object expect interfaces from previous +// // levels of resources +// inputMetadata.getGeneratorInterfaces(generator.type) +// .forEach { generatedObject: GeneratedObject -> +// objectBuilder.addSuperinterface( +// ClassName( +// packageName = settings.packageName, +// generatedObject.name +// ) +// ) +// } +// +// val result: GenerationResult? = generator.generateObject( +// project = project, +// metadata = inputMetadata, +// outputMetadata = GeneratedObject( +// generatorType = generator.type, +// modifier = if (needGenerateActual) { +// GeneratedObjectModifier.Actual +// } else { +// GeneratedObjectModifier.None +// }, +// type = GeneratedObjectType.Object, +// name = generator.mrObjectName, +// interfaces = getObjectInterfaces( +// generatorType = generator.type, +// objectName = generator.mrObjectName, +// inputMetadata = inputMetadata +// ) +// ), +// assetsGenerationDir = assetsGenerationDir, +// resourcesGenerationDir = resourcesGenerationDir, +// objectBuilder = objectBuilder, +// ) +// +// if (result != null) { +// mrClassSpec.addType(result.typeSpec) +// outputMetadata.add(result.metadata) +// generatedActualObjects.add(result.metadata) +// } +// } +// +// processMRClass(mrClassSpec) +// +// if (generatedActualObjects.isNotEmpty()) { +// val mrClass = mrClassSpec.build() +// fileSpec.addType(mrClass) +// +// outputMetadata.add( +// GeneratedObject( +// generatorType = GeneratorType.None, +// type = GeneratedObjectType.Object, +// name = settings.className, +// modifier = GeneratedObjectModifier.Actual, +// objects = generatedActualObjects +// ) +// ) +// } +// +// generators +// .flatMap { it.getImports() } +// .plus(getImports()) +// .forEach { fileSpec.addImport(it.packageName, it.simpleName) } +// +// createOutputMetadata( +// outputMetadataFile = settings.outputMetadataFile, +// generatedObjects = inputMetadata +// ) +// +// return fileSpec.build() +// } +// +// private fun generateTargetInterfaces( +// inputMetadata: List, +// outputMetadata: MutableList, +// visibilityModifier: KModifier, +// generateActualObject: Boolean, +// fileSpec: FileSpec.Builder, +// ) { +// if (settings.ownResourcesFileTree.files.isEmpty()) return +// +// val targetName: String = settings.ownResourcesFileTree.files +// .firstOrNull()?.targetName ?: return +// +// generators.forEach { generator -> +// val interfaceName = getInterfaceName( +// sourceSetName = targetName, +// generatorType = generator.type +// ) +// +// val resourcesInterfaceBuilder: TypeSpec.Builder = +// TypeSpec.interfaceBuilder(interfaceName) +// .addModifiers(visibilityModifier) +// +// val result: GenerationResult? = generator.generateObject( +// project = project, +// metadata = inputMetadata, +// outputMetadata = GeneratedObject( +// generatorType = generator.type, +// modifier = if (generateActualObject) { +// GeneratedObjectModifier.Actual +// } else { +// GeneratedObjectModifier.None +// }, +// type = GeneratedObjectType.Interface, +// name = interfaceName +// ), +// assetsGenerationDir = assetsGenerationDir, +// resourcesGenerationDir = resourcesGenerationDir, +// objectBuilder = resourcesInterfaceBuilder +// ) +// +// if (result != null) { +// fileSpec.addType(result.typeSpec) +// outputMetadata.add(result.metadata) +// } +// } +// } +// +// private fun getObjectInterfaces( +// generatorType: GeneratorType, +// objectName: String, +// inputMetadata: List, +// ): List { +// val interfaces = mutableListOf() +// +// val mrObjects: List = inputMetadata.filter { +// it.isExpectObject && it.generatorType == GeneratorType.None +// } +// +// mrObjects.forEach { mrObject -> +// mrObject.objects.forEach { +// if (it.generatorType == generatorType && it.name == objectName) { +// interfaces.addAll(it.interfaces) +// } +// } +// } +// +// return interfaces.distinct() +// } +//} \ No newline at end of file diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidAssetsGenerator.kt index faadd2344..1165d4b83 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidAssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidAssetsGenerator.kt @@ -1,42 +1,42 @@ -/* - * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.android - -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.AssetsGenerator -import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecDirectory -import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecFile -import dev.icerock.gradle.generator.NOPObjectBodyExtendable -import dev.icerock.gradle.generator.ObjectBodyExtendable -import org.gradle.api.file.FileTree -import java.io.File - -class AndroidAssetsGenerator( - ownResourcesFileTree: FileTree, -) : AssetsGenerator(ownResourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { - - override fun generateResources( - assetsGenerationDir: File, - resourcesGenerationDir: File, - files: List - ) { - files.forEach { assetSpec -> - when (assetSpec) { - is AssetSpecDirectory -> - generateResources(assetsGenerationDir, resourcesGenerationDir, assetSpec.assets) - is AssetSpecFile -> - assetSpec.file.copyTo(File(assetsGenerationDir, assetSpec.pathRelativeToBase)) - } - } - } - - override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyInitializer(fileSpec: AssetSpecFile) = - CodeBlock.of("AssetResource(path = %S)", fileSpec.pathRelativeToBase) -} +///* +// * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.android +// +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import dev.icerock.gradle.generator.AssetsGenerator +//import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecDirectory +//import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecFile +//import dev.icerock.gradle.generator.NOPObjectBodyExtendable +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import org.gradle.api.file.FileTree +//import java.io.File +// +//class AndroidAssetsGenerator( +// ownResourcesFileTree: FileTree, +//) : AssetsGenerator(ownResourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { +// +// override fun generateResources( +// assetsGenerationDir: File, +// resourcesGenerationDir: File, +// files: List +// ) { +// files.forEach { assetSpec -> +// when (assetSpec) { +// is AssetSpecDirectory -> +// generateResources(assetsGenerationDir, resourcesGenerationDir, assetSpec.assets) +// is AssetSpecFile -> +// assetSpec.file.copyTo(File(assetsGenerationDir, assetSpec.pathRelativeToBase)) +// } +// } +// } +// +// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyInitializer(fileSpec: AssetSpecFile) = +// CodeBlock.of("AssetResource(path = %S)", fileSpec.pathRelativeToBase) +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt index d5f3b6969..b69a5d46c 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt @@ -1,85 +1,85 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.android - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.ColorNode -import dev.icerock.gradle.generator.ColorsGenerator -import dev.icerock.gradle.generator.NOPObjectBodyExtendable -import dev.icerock.gradle.generator.ObjectBodyExtendable -import org.gradle.api.Project -import org.gradle.api.file.FileTree -import java.io.File - -class AndroidColorsGenerator( - resourcesFileTree: FileTree, -) : ColorsGenerator(resourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { - - override fun getImports() = listOf( - ClassName("dev.icerock.moko.graphics", "Color") - ) - - override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun generateResources( - project: Project, - assetsGenerationDir: File, - resourcesGenerationDir: File, - colors: List - ) { - val valuesDir = File(resourcesGenerationDir, "values") - val defaultStringsFile = File(valuesDir, COLORS_XML_FILE_NAME) - valuesDir.mkdirs() - - val valuesNightDir = File(resourcesGenerationDir, "values-night") - val darkStringsFile = File(valuesNightDir, COLORS_XML_FILE_NAME) - valuesNightDir.mkdirs() - - val header = - """ - - - """.trimIndent() - - val footer = - """ - - """.trimIndent() - - val defaultContent = colors.joinToString("\n") { colorNode -> - if (colorNode.isThemed()) { - buildColorString(colorNode.name, replaceColorAlpha(colorNode.lightColor)) - } else { - buildColorString(colorNode.name, replaceColorAlpha(colorNode.singleColor)) - } - } - - val darkContent = colors.filter { it.isThemed() }.joinToString("\n") { colorNode -> - buildColorString(colorNode.name, replaceColorAlpha(colorNode.darkColor)) - } - - defaultStringsFile.writeText(header + "\n") - defaultStringsFile.appendText(defaultContent) - defaultStringsFile.appendText("\n" + footer) - - darkStringsFile.writeText(header + "\n") - darkStringsFile.appendText(darkContent) - darkStringsFile.appendText("\n" + footer) - } - - private fun buildColorString(name: String, colorCode: String?): String { - return "\t#$colorCode" - } - - override fun getPropertyInitializer(color: ColorNode): CodeBlock { - return CodeBlock.of("ColorResource(resourceId = R.color.${color.name})") - } - - companion object { - private const val COLORS_XML_FILE_NAME = "colors.xml" - } -} +///* +// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.android +// +//import com.squareup.kotlinpoet.ClassName +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import dev.icerock.gradle.generator.ColorNode +//import dev.icerock.gradle.generator.ColorsGenerator +//import dev.icerock.gradle.generator.NOPObjectBodyExtendable +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import org.gradle.api.Project +//import org.gradle.api.file.FileTree +//import java.io.File +// +//class AndroidColorsGenerator( +// resourcesFileTree: FileTree, +//) : ColorsGenerator(resourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { +// +// override fun getImports() = listOf( +// ClassName("dev.icerock.moko.graphics", "Color") +// ) +// +// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun generateResources( +// project: Project, +// assetsGenerationDir: File, +// resourcesGenerationDir: File, +// colors: List +// ) { +// val valuesDir = File(resourcesGenerationDir, "values") +// val defaultStringsFile = File(valuesDir, COLORS_XML_FILE_NAME) +// valuesDir.mkdirs() +// +// val valuesNightDir = File(resourcesGenerationDir, "values-night") +// val darkStringsFile = File(valuesNightDir, COLORS_XML_FILE_NAME) +// valuesNightDir.mkdirs() +// +// val header = +// """ +// +// +// """.trimIndent() +// +// val footer = +// """ +// +// """.trimIndent() +// +// val defaultContent = colors.joinToString("\n") { colorNode -> +// if (colorNode.isThemed()) { +// buildColorString(colorNode.name, replaceColorAlpha(colorNode.lightColor)) +// } else { +// buildColorString(colorNode.name, replaceColorAlpha(colorNode.singleColor)) +// } +// } +// +// val darkContent = colors.filter { it.isThemed() }.joinToString("\n") { colorNode -> +// buildColorString(colorNode.name, replaceColorAlpha(colorNode.darkColor)) +// } +// +// defaultStringsFile.writeText(header + "\n") +// defaultStringsFile.appendText(defaultContent) +// defaultStringsFile.appendText("\n" + footer) +// +// darkStringsFile.writeText(header + "\n") +// darkStringsFile.appendText(darkContent) +// darkStringsFile.appendText("\n" + footer) +// } +// +// private fun buildColorString(name: String, colorCode: String?): String { +// return "\t#$colorCode" +// } +// +// override fun getPropertyInitializer(color: ColorNode): CodeBlock { +// return CodeBlock.of("ColorResource(resourceId = R.color.${color.name})") +// } +// +// companion object { +// private const val COLORS_XML_FILE_NAME = "colors.xml" +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt index d7167a024..959c1c82a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt @@ -1,47 +1,47 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.android - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.FilesGenerator -import dev.icerock.gradle.generator.NOPObjectBodyExtendable -import dev.icerock.gradle.generator.ObjectBodyExtendable -import org.gradle.api.file.FileTree -import org.gradle.api.provider.Provider -import java.io.File -import java.util.Locale - -class AndroidFilesGenerator( - ownInputFileTree: FileTree, - private val androidRClassPackage: Provider, -) : FilesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { - override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyInitializer(fileSpec: FileSpec) = - CodeBlock.of("FileResource(rawResId = R.raw.%L)", keyToResourceId(fileSpec.key)) - - override fun getImports() = listOf( - ClassName(androidRClassPackage.get(), "R") - ) - - override fun generateResources( - resourcesGenerationDir: File, - files: List - ) { - val targetDir = File(resourcesGenerationDir, "raw") - targetDir.mkdirs() - - files.forEach { fileSpec -> - val fileName = keyToResourceId(fileSpec.key) + "." + fileSpec.file.extension - fileSpec.file.copyTo(File(targetDir, fileName)) - } - } - - private fun keyToResourceId(key: String) = key.lowercase(Locale.ROOT) -} +///* +// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.android +// +//import com.squareup.kotlinpoet.ClassName +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import dev.icerock.gradle.generator.FilesGenerator +//import dev.icerock.gradle.generator.NOPObjectBodyExtendable +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import org.gradle.api.file.FileTree +//import org.gradle.api.provider.Provider +//import java.io.File +//import java.util.Locale +// +//class AndroidFilesGenerator( +// ownInputFileTree: FileTree, +// private val androidRClassPackage: Provider, +//) : FilesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { +// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyInitializer(fileSpec: FileSpec) = +// CodeBlock.of("FileResource(rawResId = R.raw.%L)", keyToResourceId(fileSpec.key)) +// +// override fun getImports() = listOf( +// ClassName(androidRClassPackage.get(), "R") +// ) +// +// override fun generateResources( +// resourcesGenerationDir: File, +// files: List +// ) { +// val targetDir = File(resourcesGenerationDir, "raw") +// targetDir.mkdirs() +// +// files.forEach { fileSpec -> +// val fileName = keyToResourceId(fileSpec.key) + "." + fileSpec.file.extension +// fileSpec.file.copyTo(File(targetDir, fileName)) +// } +// } +// +// private fun keyToResourceId(key: String) = key.lowercase(Locale.ROOT) +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFontsGenerator.kt index 058562a98..ce336393c 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFontsGenerator.kt @@ -1,50 +1,50 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.android - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.FontsGenerator -import dev.icerock.gradle.generator.NOPObjectBodyExtendable -import dev.icerock.gradle.generator.ObjectBodyExtendable -import org.gradle.api.file.FileTree -import org.gradle.api.provider.Provider -import java.io.File -import java.util.Locale - -class AndroidFontsGenerator( - ownInputFileTree: FileTree, - private val androidRClassPackage: Provider, -) : FontsGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { - override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyInitializer(fontFile: File): CodeBlock { - return CodeBlock.of("FontResource(fontResourceId = R.font.%L)", keyToResourceId(fontFile.nameWithoutExtension)) - } - - override fun getImports(): List = listOf( - ClassName(androidRClassPackage.get(), "R") - ) - - override fun generateResources( - resourcesGenerationDir: File, - files: List - ) { - val fontResDir = File(resourcesGenerationDir, "font") - fontResDir.mkdirs() - - files.forEach { (key, file) -> - val fileName = keyToResourceId(key) + "." + file.extension - file.copyTo(File(fontResDir, fileName)) - } - } - - private fun keyToResourceId(key: String): String { - return key.replace("-", "_").lowercase(Locale.ROOT) - } -} +///* +// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.android +// +//import com.squareup.kotlinpoet.ClassName +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import dev.icerock.gradle.generator.FontsGenerator +//import dev.icerock.gradle.generator.NOPObjectBodyExtendable +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import org.gradle.api.file.FileTree +//import org.gradle.api.provider.Provider +//import java.io.File +//import java.util.Locale +// +//class AndroidFontsGenerator( +// ownInputFileTree: FileTree, +// private val androidRClassPackage: Provider, +//) : FontsGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { +// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyInitializer(fontFile: File): CodeBlock { +// return CodeBlock.of("FontResource(fontResourceId = R.font.%L)", keyToResourceId(fontFile.nameWithoutExtension)) +// } +// +// override fun getImports(): List = listOf( +// ClassName(androidRClassPackage.get(), "R") +// ) +// +// override fun generateResources( +// resourcesGenerationDir: File, +// files: List +// ) { +// val fontResDir = File(resourcesGenerationDir, "font") +// fontResDir.mkdirs() +// +// files.forEach { (key, file) -> +// val fileName = keyToResourceId(key) + "." + file.extension +// file.copyTo(File(fontResDir, fileName)) +// } +// } +// +// private fun keyToResourceId(key: String): String { +// return key.replace("-", "_").lowercase(Locale.ROOT) +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt index bb162fae9..a4eb6c48a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt @@ -1,122 +1,122 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.android - -import com.android.ide.common.vectordrawable.Svg2Vector -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.ImagesGenerator -import dev.icerock.gradle.generator.NOPObjectBodyExtendable -import dev.icerock.gradle.generator.ObjectBodyExtendable -import dev.icerock.gradle.utils.svg -import org.gradle.api.file.FileTree -import org.gradle.api.logging.Logger -import org.gradle.api.provider.Provider -import java.io.File -import java.io.FileOutputStream -import java.io.IOException -import java.io.OutputStream -import java.nio.file.Path -import kotlin.reflect.full.functions - -class AndroidImagesGenerator( - ownInputFileTree: FileTree, - private val androidRClassPackage: Provider, - private val logger: Logger -) : ImagesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { - override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyInitializer(fileName: String): CodeBlock { - val processedKey: String = processKey(fileName.substringBefore(".")) - return CodeBlock.of("ImageResource(R.drawable.%L)", processedKey) - } - - override fun getImports(): List = listOf( - ClassName(androidRClassPackage.get(), "R") - ) - - override fun generateResources( - assetsGenerationDir: File, - resourcesGenerationDir: File, - keyFileMap: Map> - ) { - keyFileMap.flatMap { (key, files) -> - files.map { key to it } - }.forEach { (key, file) -> - val scale = file.nameWithoutExtension.substringAfter("@").substringBefore("x") - val drawableDirName = "drawable" + when (scale) { - "0.75" -> "-ldpi" - "1" -> "-mdpi" - "1.5" -> "-hdpi" - "2" -> "-xhdpi" - "3" -> "-xxhdpi" - "4" -> "-xxxhdpi" - else -> { - if (file.svg) { - "" - } else { - logger.warn("ignore $file - unknown scale ($scale)") - return@forEach - } - } - } - - val drawableDir = File(resourcesGenerationDir, drawableDirName) - val processedKey = processKey(key) - - val resourceExtension = if (file.svg) "xml" else file.extension - val resourceFile = File(drawableDir, "$processedKey.$resourceExtension") - if (file.svg) { - parseSvgToVectorDrawable(file, resourceFile) - } else { - file.copyTo(resourceFile) - } - } - } - - private fun parseSvgToVectorDrawable(svgFile: File, vectorDrawableFile: File) { - try { - vectorDrawableFile.parentFile.mkdirs() - vectorDrawableFile.createNewFile() - FileOutputStream(vectorDrawableFile, false).use { os -> - parseSvgToXml(svgFile, os) - .takeIf { it.isNotEmpty() } - ?.let { error -> logger.warn("parse from $svgFile to xml:\n$error") } - } - } catch (e: IOException) { - logger.error("parse from $svgFile to xml error", e) - } - } - - private fun parseSvgToXml(file: File, os: OutputStream): String { - return try { - Svg2Vector.parseSvgToXml(Path.of(file.absolutePath), os) - } catch (e: NoSuchMethodError) { - logger.debug( - buildString { - append("Not found parseSvgToXml function with Path parameter. ") - append("Fallback to parseSvgToXml function with File parameter.") - }, - e - ) - val parseSvgToXmlFunction = Svg2Vector::class.functions.first { - // broken ktlint rule Indentation workaround - if (it.name != "parseSvgToXml") return@first false - if (it.parameters.size != 2) return@first false - if (it.parameters[0].type.classifier != File::class) return@first false - if (it.parameters[1].type.classifier != OutputStream::class) return@first false - return@first true - } - return parseSvgToXmlFunction.call(file, os) as String - } - } - - private fun processKey(key: String): String { - return key.lowercase() - } -} +///* +// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.android +// +//import com.android.ide.common.vectordrawable.Svg2Vector +//import com.squareup.kotlinpoet.ClassName +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import dev.icerock.gradle.generator.ImagesGenerator +//import dev.icerock.gradle.generator.NOPObjectBodyExtendable +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import dev.icerock.gradle.utils.svg +//import org.gradle.api.file.FileTree +//import org.gradle.api.logging.Logger +//import org.gradle.api.provider.Provider +//import java.io.File +//import java.io.FileOutputStream +//import java.io.IOException +//import java.io.OutputStream +//import java.nio.file.Path +//import kotlin.reflect.full.functions +// +//class AndroidImagesGenerator( +// ownInputFileTree: FileTree, +// private val androidRClassPackage: Provider, +// private val logger: Logger +//) : ImagesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { +// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyInitializer(fileName: String): CodeBlock { +// val processedKey: String = processKey(fileName.substringBefore(".")) +// return CodeBlock.of("ImageResource(R.drawable.%L)", processedKey) +// } +// +// override fun getImports(): List = listOf( +// ClassName(androidRClassPackage.get(), "R") +// ) +// +// override fun generateResources( +// assetsGenerationDir: File, +// resourcesGenerationDir: File, +// keyFileMap: Map> +// ) { +// keyFileMap.flatMap { (key, files) -> +// files.map { key to it } +// }.forEach { (key, file) -> +// val scale = file.nameWithoutExtension.substringAfter("@").substringBefore("x") +// val drawableDirName = "drawable" + when (scale) { +// "0.75" -> "-ldpi" +// "1" -> "-mdpi" +// "1.5" -> "-hdpi" +// "2" -> "-xhdpi" +// "3" -> "-xxhdpi" +// "4" -> "-xxxhdpi" +// else -> { +// if (file.svg) { +// "" +// } else { +// logger.warn("ignore $file - unknown scale ($scale)") +// return@forEach +// } +// } +// } +// +// val drawableDir = File(resourcesGenerationDir, drawableDirName) +// val processedKey = processKey(key) +// +// val resourceExtension = if (file.svg) "xml" else file.extension +// val resourceFile = File(drawableDir, "$processedKey.$resourceExtension") +// if (file.svg) { +// parseSvgToVectorDrawable(file, resourceFile) +// } else { +// file.copyTo(resourceFile) +// } +// } +// } +// +// private fun parseSvgToVectorDrawable(svgFile: File, vectorDrawableFile: File) { +// try { +// vectorDrawableFile.parentFile.mkdirs() +// vectorDrawableFile.createNewFile() +// FileOutputStream(vectorDrawableFile, false).use { os -> +// parseSvgToXml(svgFile, os) +// .takeIf { it.isNotEmpty() } +// ?.let { error -> logger.warn("parse from $svgFile to xml:\n$error") } +// } +// } catch (e: IOException) { +// logger.error("parse from $svgFile to xml error", e) +// } +// } +// +// private fun parseSvgToXml(file: File, os: OutputStream): String { +// return try { +// Svg2Vector.parseSvgToXml(Path.of(file.absolutePath), os) +// } catch (e: NoSuchMethodError) { +// logger.debug( +// buildString { +// append("Not found parseSvgToXml function with Path parameter. ") +// append("Fallback to parseSvgToXml function with File parameter.") +// }, +// e +// ) +// val parseSvgToXmlFunction = Svg2Vector::class.functions.first { +// // broken ktlint rule Indentation workaround +// if (it.name != "parseSvgToXml") return@first false +// if (it.parameters.size != 2) return@first false +// if (it.parameters[0].type.classifier != File::class) return@first false +// if (it.parameters[1].type.classifier != OutputStream::class) return@first false +// return@first true +// } +// return parseSvgToXmlFunction.call(file, os) as String +// } +// } +// +// private fun processKey(key: String): String { +// return key.lowercase() +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt index 29efd4e2d..84cf5e82a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt @@ -1,33 +1,33 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.android - -import com.android.build.gradle.tasks.GenerateResValues -import com.android.build.gradle.tasks.MergeSourceSetFolders -import dev.icerock.gradle.generator.TargetMRGenerator -import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask -import org.gradle.api.Project -import org.gradle.kotlin.dsl.withType - -class AndroidMRGenerator( - project: Project, - settings: Settings, - generators: List, -) : TargetMRGenerator( - project = project, - settings = settings, - generators = generators -) { - // TODO not used. remove after complete migration of task configuration to Plugin configuration time -// override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { +///* +// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ // -// project.tasks.withType().configureEach { -// it.dependsOn(generationTask) -// } -// project.tasks.withType().configureEach { -// it.dependsOn(generationTask) -// } -// } -} +//package dev.icerock.gradle.generator.android +// +//import com.android.build.gradle.tasks.GenerateResValues +//import com.android.build.gradle.tasks.MergeSourceSetFolders +//import dev.icerock.gradle.generator.TargetMRGenerator +//import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask +//import org.gradle.api.Project +//import org.gradle.kotlin.dsl.withType +// +//class AndroidMRGenerator( +// project: Project, +// settings: Settings, +// generators: List, +//) : TargetMRGenerator( +// project = project, +// settings = settings, +// generators = generators +//) { +// // TODO not used. remove after complete migration of task configuration to Plugin configuration time +//// override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { +//// +//// project.tasks.withType().configureEach { +//// it.dependsOn(generationTask) +//// } +//// project.tasks.withType().configureEach { +//// it.dependsOn(generationTask) +//// } +//// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt index 1e8e512ab..16d3eb8c1 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt @@ -1,78 +1,78 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.android - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.KeyType -import dev.icerock.gradle.generator.LanguageType -import dev.icerock.gradle.generator.NOPObjectBodyExtendable -import dev.icerock.gradle.generator.ObjectBodyExtendable -import dev.icerock.gradle.generator.PluralMap -import dev.icerock.gradle.generator.PluralsGenerator -import org.apache.commons.lang3.StringEscapeUtils -import org.gradle.api.file.FileTree -import org.gradle.api.provider.Provider -import java.io.File - -class AndroidPluralsGenerator( - ownResourcesFileTree: FileTree, - strictLineBreaks: Boolean, - private val androidRClassPackage: Provider, -) : PluralsGenerator(ownResourcesFileTree, strictLineBreaks), - ObjectBodyExtendable by NOPObjectBodyExtendable() { - override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyInitializer(key: String) = - CodeBlock.of("PluralsResource(R.plurals.%L)", processKey(key)) - - override fun getImports(): List = listOf( - ClassName(androidRClassPackage.get(), "R") - ) - - override fun generateResources( - resourcesGenerationDir: File, - language: LanguageType, - strings: Map, - ) { - val valuesDir = File(resourcesGenerationDir, language.androidResourcesDir) - val stringsFile = File(valuesDir, "multiplatform_plurals.xml") - valuesDir.mkdirs() - - val header = - """ - - - """.trimIndent() - - val content = strings.map { (key, pluralMap) -> - val processedKey = processKey(key) - val start = "\t\n" - val items = pluralMap.map { (quantity, value) -> - val processedValue = StringEscapeUtils.escapeXml(value) - "\t\t$processedValue" - }.joinToString("\n") - val end = "\n\t" - - start + items + end - }.joinToString("\n") - - val footer = - """ - - """.trimIndent() - - stringsFile.writeText(header + "\n") - stringsFile.appendText(content) - stringsFile.appendText("\n" + footer) - } - - private fun processKey(key: String): String { - return key.replace(".", "_") - } -} +///* +// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.android +// +//import com.squareup.kotlinpoet.ClassName +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import dev.icerock.gradle.generator.KeyType +//import dev.icerock.gradle.generator.LanguageType +//import dev.icerock.gradle.generator.NOPObjectBodyExtendable +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import dev.icerock.gradle.generator.PluralMap +//import dev.icerock.gradle.generator.PluralsGenerator +//import org.apache.commons.lang3.StringEscapeUtils +//import org.gradle.api.file.FileTree +//import org.gradle.api.provider.Provider +//import java.io.File +// +//class AndroidPluralsGenerator( +// ownResourcesFileTree: FileTree, +// strictLineBreaks: Boolean, +// private val androidRClassPackage: Provider, +//) : PluralsGenerator(ownResourcesFileTree, strictLineBreaks), +// ObjectBodyExtendable by NOPObjectBodyExtendable() { +// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyInitializer(key: String) = +// CodeBlock.of("PluralsResource(R.plurals.%L)", processKey(key)) +// +// override fun getImports(): List = listOf( +// ClassName(androidRClassPackage.get(), "R") +// ) +// +// override fun generateResources( +// resourcesGenerationDir: File, +// language: LanguageType, +// strings: Map, +// ) { +// val valuesDir = File(resourcesGenerationDir, language.androidResourcesDir) +// val stringsFile = File(valuesDir, "multiplatform_plurals.xml") +// valuesDir.mkdirs() +// +// val header = +// """ +// +// +// """.trimIndent() +// +// val content = strings.map { (key, pluralMap) -> +// val processedKey = processKey(key) +// val start = "\t\n" +// val items = pluralMap.map { (quantity, value) -> +// val processedValue = StringEscapeUtils.escapeXml(value) +// "\t\t$processedValue" +// }.joinToString("\n") +// val end = "\n\t" +// +// start + items + end +// }.joinToString("\n") +// +// val footer = +// """ +// +// """.trimIndent() +// +// stringsFile.writeText(header + "\n") +// stringsFile.appendText(content) +// stringsFile.appendText("\n" + footer) +// } +// +// private fun processKey(key: String): String { +// return key.replace(".", "_") +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt index dc838dbce..2402b3b1c 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt @@ -1,80 +1,80 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.android - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.KeyType -import dev.icerock.gradle.generator.LanguageType -import dev.icerock.gradle.generator.NOPObjectBodyExtendable -import dev.icerock.gradle.generator.ObjectBodyExtendable -import dev.icerock.gradle.generator.StringsGenerator -import org.apache.commons.text.StringEscapeUtils -import org.gradle.api.file.FileTree -import org.gradle.api.provider.Provider -import java.io.File - -class AndroidStringsGenerator( - resourcesFileTree: FileTree, - strictLineBreaks: Boolean, - private val androidRClassPackage: Provider, -) : StringsGenerator( - resourcesFileTree = resourcesFileTree, - strictLineBreaks = strictLineBreaks -), ObjectBodyExtendable by NOPObjectBodyExtendable() { - - override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyInitializer(key: String) = - CodeBlock.of("StringResource(R.string.%L)", processKey(key)) - - override fun getImports(): List = listOf( - ClassName(androidRClassPackage.get(), "R") - ) - - override fun generateResources( - resourcesGenerationDir: File, - language: LanguageType, - strings: Map - ) { - val valuesDir = File(resourcesGenerationDir, language.androidResourcesDir) - val stringsFile = File(valuesDir, "multiplatform_strings.xml") - valuesDir.mkdirs() - - val header = - """ - - - """.trimIndent() - - val content = strings.map { (key, value) -> - val processedKey = processKey(key) - val processedValue = convertXmlStringToAndroidLocalization(value) - "\t$processedValue" - }.joinToString("\n") - - val footer = - """ - - """.trimIndent() - - stringsFile.writeText(header + "\n") - stringsFile.appendText(content) - stringsFile.appendText("\n" + footer) - } - - private fun processKey(key: String): String { - return key.replace(".", "_") - } - - private fun convertXmlStringToAndroidLocalization(input: String): String { - val xmlDecoded = StringEscapeUtils.unescapeXml(input) - return xmlDecoded.replace("\n", "\\n") - .replace("\"", "\\\"").let { StringEscapeUtils.escapeXml11(it) } - } -} +///* +// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.android +// +//import com.squareup.kotlinpoet.ClassName +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import dev.icerock.gradle.generator.KeyType +//import dev.icerock.gradle.generator.LanguageType +//import dev.icerock.gradle.generator.NOPObjectBodyExtendable +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import dev.icerock.gradle.generator.StringsGenerator +//import org.apache.commons.text.StringEscapeUtils +//import org.gradle.api.file.FileTree +//import org.gradle.api.provider.Provider +//import java.io.File +// +//class AndroidStringsGenerator( +// resourcesFileTree: FileTree, +// strictLineBreaks: Boolean, +// private val androidRClassPackage: Provider, +//) : StringsGenerator( +// resourcesFileTree = resourcesFileTree, +// strictLineBreaks = strictLineBreaks +//), ObjectBodyExtendable by NOPObjectBodyExtendable() { +// +// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyInitializer(key: String) = +// CodeBlock.of("StringResource(R.string.%L)", processKey(key)) +// +// override fun getImports(): List = listOf( +// ClassName(androidRClassPackage.get(), "R") +// ) +// +// override fun generateResources( +// resourcesGenerationDir: File, +// language: LanguageType, +// strings: Map +// ) { +// val valuesDir = File(resourcesGenerationDir, language.androidResourcesDir) +// val stringsFile = File(valuesDir, "multiplatform_strings.xml") +// valuesDir.mkdirs() +// +// val header = +// """ +// +// +// """.trimIndent() +// +// val content = strings.map { (key, value) -> +// val processedKey = processKey(key) +// val processedValue = convertXmlStringToAndroidLocalization(value) +// "\t$processedValue" +// }.joinToString("\n") +// +// val footer = +// """ +// +// """.trimIndent() +// +// stringsFile.writeText(header + "\n") +// stringsFile.appendText(content) +// stringsFile.appendText("\n" + footer) +// } +// +// private fun processKey(key: String): String { +// return key.replace(".", "_") +// } +// +// private fun convertXmlStringToAndroidLocalization(input: String): String { +// val xmlDecoded = StringEscapeUtils.unescapeXml(input) +// return xmlDecoded.replace("\n", "\\n") +// .replace("\"", "\\\"").let { StringEscapeUtils.escapeXml11(it) } +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleAssetsGenerator.kt index 5a1433272..d4e158287 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleAssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleAssetsGenerator.kt @@ -1,58 +1,58 @@ -/* - * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.apple - -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.AssetsGenerator -import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecDirectory -import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecFile -import dev.icerock.gradle.generator.ObjectBodyExtendable -import org.gradle.api.file.FileTree -import java.io.File - -class AppleAssetsGenerator( - ownResourcesFileTree: FileTree, -) : AssetsGenerator(ownResourcesFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { - - override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyInitializer(fileSpec: AssetSpecFile): CodeBlock { - val ext = fileSpec.file.extension - - val relativePathWithoutExt = fileSpec - .pathRelativeToBase - .replace('/', PATH_DELIMITER) - .substringBeforeLast('.') - - return CodeBlock.of( - "AssetResource(originalPath = %S, fileName = %S, extension = %S, bundle = %N)", - fileSpec.pathRelativeToBase, - relativePathWithoutExt, - ext, - AppleMRGenerator.BUNDLE_PROPERTY_NAME - ) - } - - override fun generateResources( - assetsGenerationDir: File, - resourcesGenerationDir: File, - files: List - ) { - files.forEach { assetSpec -> - when (assetSpec) { - is AssetSpecDirectory -> - generateResources(assetsGenerationDir, resourcesGenerationDir, assetSpec.assets) - - is AssetSpecFile -> { - val newName = assetSpec.pathRelativeToBase.replace('/', PATH_DELIMITER) - assetSpec.file.copyTo(File(resourcesGenerationDir, newName)) - } - } - } - } -} +///* +// * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.apple +// +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import dev.icerock.gradle.generator.AssetsGenerator +//import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecDirectory +//import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecFile +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import org.gradle.api.file.FileTree +//import java.io.File +// +//class AppleAssetsGenerator( +// ownResourcesFileTree: FileTree, +//) : AssetsGenerator(ownResourcesFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { +// +// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyInitializer(fileSpec: AssetSpecFile): CodeBlock { +// val ext = fileSpec.file.extension +// +// val relativePathWithoutExt = fileSpec +// .pathRelativeToBase +// .replace('/', PATH_DELIMITER) +// .substringBeforeLast('.') +// +// return CodeBlock.of( +// "AssetResource(originalPath = %S, fileName = %S, extension = %S, bundle = %N)", +// fileSpec.pathRelativeToBase, +// relativePathWithoutExt, +// ext, +// AppleMRGenerator.BUNDLE_PROPERTY_NAME +// ) +// } +// +// override fun generateResources( +// assetsGenerationDir: File, +// resourcesGenerationDir: File, +// files: List +// ) { +// files.forEach { assetSpec -> +// when (assetSpec) { +// is AssetSpecDirectory -> +// generateResources(assetsGenerationDir, resourcesGenerationDir, assetSpec.assets) +// +// is AssetSpecFile -> { +// val newName = assetSpec.pathRelativeToBase.replace('/', PATH_DELIMITER) +// assetSpec.file.copyTo(File(resourcesGenerationDir, newName)) +// } +// } +// } +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt index a6839d6d6..1341f4619 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt @@ -1,133 +1,133 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.apple - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.ColorNode -import dev.icerock.gradle.generator.ColorsGenerator -import dev.icerock.gradle.generator.ObjectBodyExtendable -import dev.icerock.gradle.generator.apple.AppleMRGenerator.Companion.ASSETS_DIR_NAME -import dev.icerock.gradle.utils.ArgbColor -import dev.icerock.gradle.utils.parseRgbaColor -import kotlinx.serialization.json.JsonObject -import kotlinx.serialization.json.buildJsonArray -import kotlinx.serialization.json.buildJsonObject -import kotlinx.serialization.json.put -import org.gradle.api.Project -import org.gradle.api.file.FileTree -import java.io.File - -class AppleColorsGenerator( - resourcesFileTree: FileTree, -) : ColorsGenerator(resourcesFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { - override fun getImports(): List { - return listOf( - ClassName("dev.icerock.moko.graphics", "Color") - ) - } - - override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun generateResources( - project: Project, - assetsGenerationDir: File, - resourcesGenerationDir: File, - colors: List - ) { - val assetsDirectory = File(assetsGenerationDir, ASSETS_DIR_NAME) - - colors.forEach { colorNode -> - val assetDir = File(assetsDirectory, "${colorNode.name}.colorset") - assetDir.mkdirs() - val contentsFile = File(assetDir, "Contents.json") - contentsFile.createNewFile() - - val colorContentObj = if (colorNode.isThemed()) { - @Suppress("MagicNumber") - val lightColor = parseRgbaColor(colorNode.lightColor!!.toLong(16)) - - @Suppress("MagicNumber") - val darkColor = parseRgbaColor(colorNode.darkColor!!.toLong(16)) - - /* - Sets any color as light. Check about colors in the docs: - https://developer.apple.com/documentation/xcode/supporting_dark_mode_in_your_interface - */ - val anyColor = buildColorIdiomJsonObj(lightColor) - val lightColorObj = buildAppearancesIdiomJsonBlock("light", lightColor) - val darkColorObj = buildAppearancesIdiomJsonBlock("dark", darkColor) - - buildJsonArray { - add(anyColor) - add(lightColorObj) - add(darkColorObj) - } - } else { - @Suppress("MagicNumber") - val singleColor = parseRgbaColor(colorNode.singleColor!!.toLong(16)) - buildJsonArray { - add(buildColorIdiomJsonObj(singleColor)) - } - } - - val resultObj = buildJsonObject { - put("colors", colorContentObj) - put( - "info", - buildJsonObject { - put("author", "xcode") - put("version", 1) - } - ) - } - contentsFile.writeText(resultObj.toString()) - } - } - - private fun buildColorJsonObj(argbColor: ArgbColor): JsonObject = buildJsonObject { - put("color-space", "srgb") - put( - "components", - buildJsonObject { - put("alpha", argbColor.a) - put("red", argbColor.r) - put("green", argbColor.g) - put("blue", argbColor.b) - } - ) - } - - private fun buildColorIdiomJsonObj(argbColor: ArgbColor): JsonObject = buildJsonObject { - put("color", buildColorJsonObj(argbColor)) - put("idiom", "universal") - } - - private fun buildAppearancesIdiomJsonBlock(valueTag: String, argbColor: ArgbColor): JsonObject { - return buildJsonObject { - put( - "appearances", - buildJsonArray { - add( - buildJsonObject { - put("appearance", "luminosity") - put("value", valueTag) - } - ) - } - ) - put("color", buildColorJsonObj(argbColor)) - put("idiom", "universal") - } - } - - override fun getPropertyInitializer(color: ColorNode): CodeBlock { - return CodeBlock.of( - "ColorResource(name = %S, bundle = ${AppleMRGenerator.BUNDLE_PROPERTY_NAME})", - color.name - ) - } -} +///* +// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.apple +// +//import com.squareup.kotlinpoet.ClassName +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import dev.icerock.gradle.generator.ColorNode +//import dev.icerock.gradle.generator.ColorsGenerator +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import dev.icerock.gradle.generator.apple.AppleMRGenerator.Companion.ASSETS_DIR_NAME +//import dev.icerock.gradle.utils.ArgbColor +//import dev.icerock.gradle.utils.parseRgbaColor +//import kotlinx.serialization.json.JsonObject +//import kotlinx.serialization.json.buildJsonArray +//import kotlinx.serialization.json.buildJsonObject +//import kotlinx.serialization.json.put +//import org.gradle.api.Project +//import org.gradle.api.file.FileTree +//import java.io.File +// +//class AppleColorsGenerator( +// resourcesFileTree: FileTree, +//) : ColorsGenerator(resourcesFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { +// override fun getImports(): List { +// return listOf( +// ClassName("dev.icerock.moko.graphics", "Color") +// ) +// } +// +// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun generateResources( +// project: Project, +// assetsGenerationDir: File, +// resourcesGenerationDir: File, +// colors: List +// ) { +// val assetsDirectory = File(assetsGenerationDir, ASSETS_DIR_NAME) +// +// colors.forEach { colorNode -> +// val assetDir = File(assetsDirectory, "${colorNode.name}.colorset") +// assetDir.mkdirs() +// val contentsFile = File(assetDir, "Contents.json") +// contentsFile.createNewFile() +// +// val colorContentObj = if (colorNode.isThemed()) { +// @Suppress("MagicNumber") +// val lightColor = parseRgbaColor(colorNode.lightColor!!.toLong(16)) +// +// @Suppress("MagicNumber") +// val darkColor = parseRgbaColor(colorNode.darkColor!!.toLong(16)) +// +// /* +// Sets any color as light. Check about colors in the docs: +// https://developer.apple.com/documentation/xcode/supporting_dark_mode_in_your_interface +// */ +// val anyColor = buildColorIdiomJsonObj(lightColor) +// val lightColorObj = buildAppearancesIdiomJsonBlock("light", lightColor) +// val darkColorObj = buildAppearancesIdiomJsonBlock("dark", darkColor) +// +// buildJsonArray { +// add(anyColor) +// add(lightColorObj) +// add(darkColorObj) +// } +// } else { +// @Suppress("MagicNumber") +// val singleColor = parseRgbaColor(colorNode.singleColor!!.toLong(16)) +// buildJsonArray { +// add(buildColorIdiomJsonObj(singleColor)) +// } +// } +// +// val resultObj = buildJsonObject { +// put("colors", colorContentObj) +// put( +// "info", +// buildJsonObject { +// put("author", "xcode") +// put("version", 1) +// } +// ) +// } +// contentsFile.writeText(resultObj.toString()) +// } +// } +// +// private fun buildColorJsonObj(argbColor: ArgbColor): JsonObject = buildJsonObject { +// put("color-space", "srgb") +// put( +// "components", +// buildJsonObject { +// put("alpha", argbColor.a) +// put("red", argbColor.r) +// put("green", argbColor.g) +// put("blue", argbColor.b) +// } +// ) +// } +// +// private fun buildColorIdiomJsonObj(argbColor: ArgbColor): JsonObject = buildJsonObject { +// put("color", buildColorJsonObj(argbColor)) +// put("idiom", "universal") +// } +// +// private fun buildAppearancesIdiomJsonBlock(valueTag: String, argbColor: ArgbColor): JsonObject { +// return buildJsonObject { +// put( +// "appearances", +// buildJsonArray { +// add( +// buildJsonObject { +// put("appearance", "luminosity") +// put("value", valueTag) +// } +// ) +// } +// ) +// put("color", buildColorJsonObj(argbColor)) +// put("idiom", "universal") +// } +// } +// +// override fun getPropertyInitializer(color: ColorNode): CodeBlock { +// return CodeBlock.of( +// "ColorResource(name = %S, bundle = ${AppleMRGenerator.BUNDLE_PROPERTY_NAME})", +// color.name +// ) +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFilesGenerator.kt index 3f200155a..9a3998ca9 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFilesGenerator.kt @@ -1,39 +1,39 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.apple - -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.FilesGenerator -import dev.icerock.gradle.generator.ObjectBodyExtendable -import org.gradle.api.file.FileTree -import java.io.File - -class AppleFilesGenerator( - ownInputFileTree: FileTree, -) : FilesGenerator(resourceFiles = ownInputFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { - - override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyInitializer(fileSpec: FileSpec) = CodeBlock.of( - "FileResource(fileName = %S, extension = %S,bundle = ${AppleMRGenerator.BUNDLE_PROPERTY_NAME})", - fileSpec.file.nameWithoutExtension, - fileSpec.file.extension - ) - - override fun generateResources( - resourcesGenerationDir: File, - files: List, - ) { - val targetDir = File(resourcesGenerationDir, "files") - targetDir.mkdirs() - - files.forEach { fileSpec -> - fileSpec.file.copyTo(File(targetDir, fileSpec.file.name)) - } - } -} +///* +// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.apple +// +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import dev.icerock.gradle.generator.FilesGenerator +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import org.gradle.api.file.FileTree +//import java.io.File +// +//class AppleFilesGenerator( +// ownInputFileTree: FileTree, +//) : FilesGenerator(resourceFiles = ownInputFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { +// +// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyInitializer(fileSpec: FileSpec) = CodeBlock.of( +// "FileResource(fileName = %S, extension = %S,bundle = ${AppleMRGenerator.BUNDLE_PROPERTY_NAME})", +// fileSpec.file.nameWithoutExtension, +// fileSpec.file.extension +// ) +// +// override fun generateResources( +// resourcesGenerationDir: File, +// files: List, +// ) { +// val targetDir = File(resourcesGenerationDir, "files") +// targetDir.mkdirs() +// +// files.forEach { fileSpec -> +// fileSpec.file.copyTo(File(targetDir, fileSpec.file.name)) +// } +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFontsGenerator.kt index 4dd1172bb..52a261b39 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFontsGenerator.kt @@ -1,37 +1,37 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.apple - -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.FontsGenerator -import dev.icerock.gradle.generator.ObjectBodyExtendable -import org.gradle.api.file.FileTree -import java.io.File - -class AppleFontsGenerator( - ownInputFileTree: FileTree, -) : FontsGenerator(ownInputFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { - - override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyInitializer(fontFile: File): CodeBlock { - return CodeBlock.of( - "FontResource(fontName = %S, bundle = ${AppleMRGenerator.BUNDLE_PROPERTY_NAME})", - fontFile.name - ) - } - - override fun generateResources( - resourcesGenerationDir: File, - files: List - ) { - files.forEach { (_, file) -> - file.copyTo(File(resourcesGenerationDir, file.name)) - } - } -} +///* +// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.apple +// +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import dev.icerock.gradle.generator.FontsGenerator +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import org.gradle.api.file.FileTree +//import java.io.File +// +//class AppleFontsGenerator( +// ownInputFileTree: FileTree, +//) : FontsGenerator(ownInputFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { +// +// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyInitializer(fontFile: File): CodeBlock { +// return CodeBlock.of( +// "FontResource(fontName = %S, bundle = ${AppleMRGenerator.BUNDLE_PROPERTY_NAME})", +// fontFile.name +// ) +// } +// +// override fun generateResources( +// resourcesGenerationDir: File, +// files: List +// ) { +// files.forEach { (_, file) -> +// file.copyTo(File(resourcesGenerationDir, file.name)) +// } +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleGeneratorHelper.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleGeneratorHelper.kt index 8fdff6ed5..b7ebf5422 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleGeneratorHelper.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleGeneratorHelper.kt @@ -1,28 +1,28 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.apple - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.PropertySpec -import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.ObjectBodyExtendable - -class AppleGeneratorHelper( - private val propertyName: String = "nsBundle" -) : ObjectBodyExtendable { - - override fun extendObjectBodyAtStart(classBuilder: TypeSpec.Builder) = Unit - - override fun extendObjectBodyAtEnd(classBuilder: TypeSpec.Builder) { - val bundleType = ClassName("platform.Foundation", "NSBundle") - val bundleProperty = PropertySpec.builder(propertyName, bundleType) - .addModifiers(KModifier.OVERRIDE) - .initializer(AppleMRGenerator.BUNDLE_PROPERTY_NAME) - .build() - - classBuilder.addProperty(bundleProperty) - } -} +///* +// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.apple +// +//import com.squareup.kotlinpoet.ClassName +//import com.squareup.kotlinpoet.KModifier +//import com.squareup.kotlinpoet.PropertySpec +//import com.squareup.kotlinpoet.TypeSpec +//import dev.icerock.gradle.generator.ObjectBodyExtendable +// +//class AppleGeneratorHelper( +// private val propertyName: String = "nsBundle" +//) : ObjectBodyExtendable { +// +// override fun extendObjectBodyAtStart(classBuilder: TypeSpec.Builder) = Unit +// +// override fun extendObjectBodyAtEnd(classBuilder: TypeSpec.Builder) { +// val bundleType = ClassName("platform.Foundation", "NSBundle") +// val bundleProperty = PropertySpec.builder(propertyName, bundleType) +// .addModifiers(KModifier.OVERRIDE) +// .initializer(AppleMRGenerator.BUNDLE_PROPERTY_NAME) +// .build() +// +// classBuilder.addProperty(bundleProperty) +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleImagesGenerator.kt index c99c3d8a9..945766cc8 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleImagesGenerator.kt @@ -1,106 +1,106 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.apple - -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.ImagesGenerator -import dev.icerock.gradle.generator.ObjectBodyExtendable -import dev.icerock.gradle.generator.apple.AppleMRGenerator.Companion.ASSETS_DIR_NAME -import dev.icerock.gradle.utils.nameWithoutScale -import dev.icerock.gradle.utils.scale -import dev.icerock.gradle.utils.svg -import kotlinx.serialization.json.JsonPrimitive -import kotlinx.serialization.json.buildJsonArray -import kotlinx.serialization.json.buildJsonObject -import org.gradle.api.file.FileTree -import java.io.File - -class AppleImagesGenerator( - ownInputFileTree: FileTree, -) : ImagesGenerator(resourcesFileTree = ownInputFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { - - override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyInitializer(fileName: String): CodeBlock? { - return CodeBlock.of( - "ImageResource(assetImageName = %S, bundle = ${AppleMRGenerator.BUNDLE_PROPERTY_NAME})", - fileName.substringBefore(".") - ) - } - - override fun generateResources( - assetsGenerationDir: File, - resourcesGenerationDir: File, - keyFileMap: Map> - ) { - val assetsDirectory = File(assetsGenerationDir, ASSETS_DIR_NAME) - - keyFileMap.forEach { (key, files) -> - val assetDir = File(assetsDirectory, "$key.imageset") - val contentsFile = File(assetDir, "Contents.json") - - val validFiles = files.filter { file -> - file.svg || VALID_SIZES.any { size -> file.scale == "${size}x" } - } - - val uniqueNames = files.map { it.nameWithoutScale }.distinct() - uniqueNames.forEach { name -> - require(validFiles.any { it.nameWithoutScale == name }) { - buildString { - appendLine("Apple Generator cannot find a valid scale for file with name \"$name\".") - append("Note: Apple resources can have only 1x, 2x and 3x scale factors ") - append("(https://developer.apple.com/design/human-interface-guidelines/ios/") - appendLine("icons-and-images/image-size-and-resolution/).") - append("It is still possible to use 4x images for android, but you need to ") - append("add a valid iOS variant.") - } - } - } - - validFiles.forEach { it.copyTo(File(assetDir, it.name)) } - - val imagesContent = buildJsonArray { - validFiles.map { file -> - buildJsonObject { - put("idiom", JsonPrimitive("universal")) - put("filename", JsonPrimitive(file.name)) - if (!file.svg) { - put("scale", JsonPrimitive(file.scale)) - } - } - }.forEach { add(it) } - } - - val content = buildJsonObject { - put("images", imagesContent) - put( - "info", - buildJsonObject { - put("version", JsonPrimitive(1)) - put("author", JsonPrimitive("xcode")) - } - ) - - if (validFiles.any { file -> file.svg }) { - put( - "properties", - buildJsonObject { - put("preserves-vector-representation", JsonPrimitive(true)) - } - ) - } - }.toString() - - contentsFile.writeText(content) - } - } - - private companion object { - val VALID_SIZES: IntRange = 1..3 - } -} +///* +// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.apple +// +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import dev.icerock.gradle.generator.ImagesGenerator +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import dev.icerock.gradle.generator.apple.AppleMRGenerator.Companion.ASSETS_DIR_NAME +//import dev.icerock.gradle.utils.nameWithoutScale +//import dev.icerock.gradle.utils.scale +//import dev.icerock.gradle.utils.svg +//import kotlinx.serialization.json.JsonPrimitive +//import kotlinx.serialization.json.buildJsonArray +//import kotlinx.serialization.json.buildJsonObject +//import org.gradle.api.file.FileTree +//import java.io.File +// +//class AppleImagesGenerator( +// ownInputFileTree: FileTree, +//) : ImagesGenerator(resourcesFileTree = ownInputFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { +// +// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyInitializer(fileName: String): CodeBlock? { +// return CodeBlock.of( +// "ImageResource(assetImageName = %S, bundle = ${AppleMRGenerator.BUNDLE_PROPERTY_NAME})", +// fileName.substringBefore(".") +// ) +// } +// +// override fun generateResources( +// assetsGenerationDir: File, +// resourcesGenerationDir: File, +// keyFileMap: Map> +// ) { +// val assetsDirectory = File(assetsGenerationDir, ASSETS_DIR_NAME) +// +// keyFileMap.forEach { (key, files) -> +// val assetDir = File(assetsDirectory, "$key.imageset") +// val contentsFile = File(assetDir, "Contents.json") +// +// val validFiles = files.filter { file -> +// file.svg || VALID_SIZES.any { size -> file.scale == "${size}x" } +// } +// +// val uniqueNames = files.map { it.nameWithoutScale }.distinct() +// uniqueNames.forEach { name -> +// require(validFiles.any { it.nameWithoutScale == name }) { +// buildString { +// appendLine("Apple Generator cannot find a valid scale for file with name \"$name\".") +// append("Note: Apple resources can have only 1x, 2x and 3x scale factors ") +// append("(https://developer.apple.com/design/human-interface-guidelines/ios/") +// appendLine("icons-and-images/image-size-and-resolution/).") +// append("It is still possible to use 4x images for android, but you need to ") +// append("add a valid iOS variant.") +// } +// } +// } +// +// validFiles.forEach { it.copyTo(File(assetDir, it.name)) } +// +// val imagesContent = buildJsonArray { +// validFiles.map { file -> +// buildJsonObject { +// put("idiom", JsonPrimitive("universal")) +// put("filename", JsonPrimitive(file.name)) +// if (!file.svg) { +// put("scale", JsonPrimitive(file.scale)) +// } +// } +// }.forEach { add(it) } +// } +// +// val content = buildJsonObject { +// put("images", imagesContent) +// put( +// "info", +// buildJsonObject { +// put("version", JsonPrimitive(1)) +// put("author", JsonPrimitive("xcode")) +// } +// ) +// +// if (validFiles.any { file -> file.svg }) { +// put( +// "properties", +// buildJsonObject { +// put("preserves-vector-representation", JsonPrimitive(true)) +// } +// ) +// } +// }.toString() +// +// contentsFile.writeText(content) +// } +// } +// +// private companion object { +// val VALID_SIZES: IntRange = 1..3 +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt index f27038eba..9b887062b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt @@ -1,63 +1,63 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.apple - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.PropertySpec -import com.squareup.kotlinpoet.STRING -import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.TargetMRGenerator -import dev.icerock.gradle.utils.calculateResourcesHash -import org.gradle.api.Project - -@Suppress("TooManyFunctions") -class AppleMRGenerator( - project: Project, - settings: Settings, - generators: List, -) : TargetMRGenerator( - project = project, - settings = settings, - generators = generators -) { - private val bundleClassName = ClassName("platform.Foundation", "NSBundle") - private val bundleIdentifier = "${settings.packageName}.MR" - - override fun processMRClass(mrClass: TypeSpec.Builder) { - super.processMRClass(mrClass) - - mrClass.addProperty( - PropertySpec.builder( - BUNDLE_PROPERTY_NAME, - bundleClassName, - KModifier.PRIVATE - ) - .delegate(CodeBlock.of("lazy { NSBundle.loadableBundle(\"${bundleIdentifier}\") }")) - .build() - ) - - mrClass.addProperty( - PropertySpec.builder("contentHash", STRING, KModifier.PRIVATE) - .initializer("%S", resourcesGenerationDir.calculateResourcesHash()) - .build() - ) - } - - override fun getImports(): List = listOf( - bundleClassName, - ClassName("dev.icerock.moko.resources.utils", "loadableBundle") - ) - - override fun beforeMRGeneration() { - assetsGenerationDir.mkdirs() - } - - companion object { - const val BUNDLE_PROPERTY_NAME = "bundle" - const val ASSETS_DIR_NAME = "Assets.xcassets" - } -} +///* +// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.apple +// +//import com.squareup.kotlinpoet.ClassName +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import com.squareup.kotlinpoet.PropertySpec +//import com.squareup.kotlinpoet.STRING +//import com.squareup.kotlinpoet.TypeSpec +//import dev.icerock.gradle.generator.TargetMRGenerator +//import dev.icerock.gradle.utils.calculateResourcesHash +//import org.gradle.api.Project +// +//@Suppress("TooManyFunctions") +//class AppleMRGenerator( +// project: Project, +// settings: Settings, +// generators: List, +//) : TargetMRGenerator( +// project = project, +// settings = settings, +// generators = generators +//) { +// private val bundleClassName = ClassName("platform.Foundation", "NSBundle") +// private val bundleIdentifier = "${settings.packageName}.MR" +// +// override fun processMRClass(mrClass: TypeSpec.Builder) { +// super.processMRClass(mrClass) +// +// mrClass.addProperty( +// PropertySpec.builder( +// BUNDLE_PROPERTY_NAME, +// bundleClassName, +// KModifier.PRIVATE +// ) +// .delegate(CodeBlock.of("lazy { NSBundle.loadableBundle(\"${bundleIdentifier}\") }")) +// .build() +// ) +// +// mrClass.addProperty( +// PropertySpec.builder("contentHash", STRING, KModifier.PRIVATE) +// .initializer("%S", resourcesGenerationDir.calculateResourcesHash()) +// .build() +// ) +// } +// +// override fun getImports(): List = listOf( +// bundleClassName, +// ClassName("dev.icerock.moko.resources.utils", "loadableBundle") +// ) +// +// override fun beforeMRGeneration() { +// assetsGenerationDir.mkdirs() +// } +// +// companion object { +// const val BUNDLE_PROPERTY_NAME = "bundle" +// const val ASSETS_DIR_NAME = "Assets.xcassets" +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/ApplePluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/ApplePluralsGenerator.kt index b7e402c1b..231ec4985 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/ApplePluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/ApplePluralsGenerator.kt @@ -1,98 +1,98 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.apple - -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.KeyType -import dev.icerock.gradle.generator.LanguageType -import dev.icerock.gradle.generator.ObjectBodyExtendable -import dev.icerock.gradle.generator.PluralMap -import dev.icerock.gradle.generator.PluralsGenerator -import org.gradle.api.file.FileTree -import org.gradle.api.provider.Provider -import java.io.File - -class ApplePluralsGenerator( - ownResourcesFileTree: FileTree, - strictLineBreaks: Boolean, - private val baseLocalizationRegion: Provider -) : PluralsGenerator(ownResourcesFileTree, strictLineBreaks), - ObjectBodyExtendable by AppleGeneratorHelper() { - - override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyInitializer(key: String) = CodeBlock.of( - "PluralsResource(resourceId = %S, bundle = ${AppleMRGenerator.BUNDLE_PROPERTY_NAME})", - key - ) - - private fun writeStringsFile(file: File, strings: Map) { - val head = """ - - - - """ - - val content = strings.map { (key, pluralMap) -> - val start = """$key - - NSStringLocalizedFormatKey - %#@pluraled@ - pluraled - - NSStringFormatSpecTypeKey - NSStringPluralRuleType - NSStringFormatValueTypeKey - d -""" - - val items = pluralMap.map { (quantity, value) -> - val processedValue = value.escapeFormatArguments() - """ $quantity - $processedValue""" - }.joinToString(separator = "\n") - - val end = """ - - """ - - start + items + end - }.joinToString("\n") - - val footer = """ - -""" - - file.writeText(head) - file.appendText(content) - file.appendText(footer) - } - - override fun generateResources( - resourcesGenerationDir: File, - language: LanguageType, - strings: Map - ) { - val resDir = File(resourcesGenerationDir, language.appleResourcesDir) - val localizableFile = File(resDir, "Localizable.stringsdict") - resDir.mkdirs() - writeStringsFile(localizableFile, strings) - - if (language == LanguageType.Base) { - val localRegion: String = baseLocalizationRegion.get() - val regionDir = File(resourcesGenerationDir, "$localRegion.lproj") - regionDir.mkdirs() - val regionFile = File(regionDir, "Localizable.stringsdict") - writeStringsFile(regionFile, strings) - } - } - - private fun String.escapeFormatArguments(): String { - return this.replace(Regex("%(((?:\\.|\\d|\\$)*)[abcdefs])"), "%%$1") - } -} +///* +// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.apple +// +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import dev.icerock.gradle.generator.KeyType +//import dev.icerock.gradle.generator.LanguageType +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import dev.icerock.gradle.generator.PluralMap +//import dev.icerock.gradle.generator.PluralsGenerator +//import org.gradle.api.file.FileTree +//import org.gradle.api.provider.Provider +//import java.io.File +// +//class ApplePluralsGenerator( +// ownResourcesFileTree: FileTree, +// strictLineBreaks: Boolean, +// private val baseLocalizationRegion: Provider +//) : PluralsGenerator(ownResourcesFileTree, strictLineBreaks), +// ObjectBodyExtendable by AppleGeneratorHelper() { +// +// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyInitializer(key: String) = CodeBlock.of( +// "PluralsResource(resourceId = %S, bundle = ${AppleMRGenerator.BUNDLE_PROPERTY_NAME})", +// key +// ) +// +// private fun writeStringsFile(file: File, strings: Map) { +// val head = """ +// +// +// +// """ +// +// val content = strings.map { (key, pluralMap) -> +// val start = """$key +// +// NSStringLocalizedFormatKey +// %#@pluraled@ +// pluraled +// +// NSStringFormatSpecTypeKey +// NSStringPluralRuleType +// NSStringFormatValueTypeKey +// d +//""" +// +// val items = pluralMap.map { (quantity, value) -> +// val processedValue = value.escapeFormatArguments() +// """ $quantity +// $processedValue""" +// }.joinToString(separator = "\n") +// +// val end = """ +// +// """ +// +// start + items + end +// }.joinToString("\n") +// +// val footer = """ +// +//""" +// +// file.writeText(head) +// file.appendText(content) +// file.appendText(footer) +// } +// +// override fun generateResources( +// resourcesGenerationDir: File, +// language: LanguageType, +// strings: Map +// ) { +// val resDir = File(resourcesGenerationDir, language.appleResourcesDir) +// val localizableFile = File(resDir, "Localizable.stringsdict") +// resDir.mkdirs() +// writeStringsFile(localizableFile, strings) +// +// if (language == LanguageType.Base) { +// val localRegion: String = baseLocalizationRegion.get() +// val regionDir = File(resourcesGenerationDir, "$localRegion.lproj") +// regionDir.mkdirs() +// val regionFile = File(regionDir, "Localizable.stringsdict") +// writeStringsFile(regionFile, strings) +// } +// } +// +// private fun String.escapeFormatArguments(): String { +// return this.replace(Regex("%(((?:\\.|\\d|\\$)*)[abcdefs])"), "%%$1") +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleStringsGenerator.kt index 91c219450..f2137513b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleStringsGenerator.kt @@ -1,65 +1,65 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.apple - -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.KeyType -import dev.icerock.gradle.generator.LanguageType -import dev.icerock.gradle.generator.ObjectBodyExtendable -import dev.icerock.gradle.generator.StringsGenerator -import dev.icerock.gradle.generator.apple.AppleMRGenerator.Companion.BUNDLE_PROPERTY_NAME -import org.apache.commons.text.StringEscapeUtils -import org.gradle.api.file.FileTree -import org.gradle.api.provider.Provider -import java.io.File - -class AppleStringsGenerator( - resourcesFileTree: FileTree, - strictLineBreaks: Boolean, - private val baseLocalizationRegion: Provider -) : StringsGenerator( - resourcesFileTree = resourcesFileTree, - strictLineBreaks = strictLineBreaks -), - ObjectBodyExtendable by AppleGeneratorHelper() { - - override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyInitializer(key: String) = - CodeBlock.of("StringResource(resourceId = %S, bundle = $BUNDLE_PROPERTY_NAME)", key) - - override fun generateResources( - resourcesGenerationDir: File, - language: LanguageType, - strings: Map - ) { - val resDir = File(resourcesGenerationDir, language.appleResourcesDir) - val localizableFile = File(resDir, "Localizable.strings") - resDir.mkdirs() - - val content = strings.mapValues { (_, value) -> - convertXmlStringToAppleLocalization(value) - }.map { (key, value) -> - "\"$key\" = \"$value\";" - }.joinToString("\n") - localizableFile.writeText(content) - - if (language == LanguageType.Base) { - val regionDir = File(resourcesGenerationDir, "${baseLocalizationRegion.get()}.lproj") - regionDir.mkdirs() - val regionFile = File(regionDir, "Localizable.strings") - regionFile.writeText(content) - } - } - - private fun convertXmlStringToAppleLocalization(input: String): String { - val xmlDecoded = StringEscapeUtils.unescapeXml(input) - return xmlDecoded.replace("\n", "\\n") - .replace("\"", "\\\"") - } -} +///* +// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.apple +// +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import dev.icerock.gradle.generator.KeyType +//import dev.icerock.gradle.generator.LanguageType +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import dev.icerock.gradle.generator.StringsGenerator +//import dev.icerock.gradle.generator.apple.AppleMRGenerator.Companion.BUNDLE_PROPERTY_NAME +//import org.apache.commons.text.StringEscapeUtils +//import org.gradle.api.file.FileTree +//import org.gradle.api.provider.Provider +//import java.io.File +// +//class AppleStringsGenerator( +// resourcesFileTree: FileTree, +// strictLineBreaks: Boolean, +// private val baseLocalizationRegion: Provider +//) : StringsGenerator( +// resourcesFileTree = resourcesFileTree, +// strictLineBreaks = strictLineBreaks +//), +// ObjectBodyExtendable by AppleGeneratorHelper() { +// +// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyInitializer(key: String) = +// CodeBlock.of("StringResource(resourceId = %S, bundle = $BUNDLE_PROPERTY_NAME)", key) +// +// override fun generateResources( +// resourcesGenerationDir: File, +// language: LanguageType, +// strings: Map +// ) { +// val resDir = File(resourcesGenerationDir, language.appleResourcesDir) +// val localizableFile = File(resDir, "Localizable.strings") +// resDir.mkdirs() +// +// val content = strings.mapValues { (_, value) -> +// convertXmlStringToAppleLocalization(value) +// }.map { (key, value) -> +// "\"$key\" = \"$value\";" +// }.joinToString("\n") +// localizableFile.writeText(content) +// +// if (language == LanguageType.Base) { +// val regionDir = File(resourcesGenerationDir, "${baseLocalizationRegion.get()}.lproj") +// regionDir.mkdirs() +// val regionFile = File(regionDir, "Localizable.strings") +// regionFile.writeText(content) +// } +// } +// +// private fun convertXmlStringToAppleLocalization(input: String): String { +// val xmlDecoded = StringEscapeUtils.unescapeXml(input) +// return xmlDecoded.replace("\n", "\\n") +// .replace("\"", "\\\"") +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonAssetsGenerator.kt index 9bfc84a54..1e8d85b08 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonAssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonAssetsGenerator.kt @@ -1,24 +1,24 @@ -/* - * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.common - -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.AssetsGenerator -import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecFile -import dev.icerock.gradle.generator.NOPObjectBodyExtendable -import dev.icerock.gradle.generator.ObjectBodyExtendable -import org.gradle.api.file.FileTree - -class CommonAssetsGenerator( - ownResourcesFileTree: FileTree, -) : AssetsGenerator(ownResourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { - - override fun getClassModifiers(): Array = emptyArray() - - override fun getPropertyModifiers(): Array = emptyArray() - - override fun getPropertyInitializer(fileSpec: AssetSpecFile): CodeBlock? = null -} +///* +// * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.common +// +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import dev.icerock.gradle.generator.AssetsGenerator +//import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecFile +//import dev.icerock.gradle.generator.NOPObjectBodyExtendable +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import org.gradle.api.file.FileTree +// +//class CommonAssetsGenerator( +// ownResourcesFileTree: FileTree, +//) : AssetsGenerator(ownResourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { +// +// override fun getClassModifiers(): Array = emptyArray() +// +// override fun getPropertyModifiers(): Array = emptyArray() +// +// override fun getPropertyInitializer(fileSpec: AssetSpecFile): CodeBlock? = null +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonColorsGenerator.kt index 19524211e..012ea81e7 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonColorsGenerator.kt @@ -1,24 +1,24 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.common - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import dev.icerock.gradle.generator.ColorNode -import dev.icerock.gradle.generator.ColorsGenerator -import dev.icerock.gradle.generator.NOPObjectBodyExtendable -import dev.icerock.gradle.generator.ObjectBodyExtendable -import org.gradle.api.file.FileTree - -class CommonColorsGenerator( - resourcesFileTree: FileTree, -) : ColorsGenerator(resourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { - - override fun getImports(): List { - return emptyList() - } - - override fun getPropertyInitializer(color: ColorNode): CodeBlock? = null -} +///* +// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.common +// +//import com.squareup.kotlinpoet.ClassName +//import com.squareup.kotlinpoet.CodeBlock +//import dev.icerock.gradle.generator.ColorNode +//import dev.icerock.gradle.generator.ColorsGenerator +//import dev.icerock.gradle.generator.NOPObjectBodyExtendable +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import org.gradle.api.file.FileTree +// +//class CommonColorsGenerator( +// resourcesFileTree: FileTree, +//) : ColorsGenerator(resourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { +// +// override fun getImports(): List { +// return emptyList() +// } +// +// override fun getPropertyInitializer(color: ColorNode): CodeBlock? = null +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt index e9f4e1792..f7191d93e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt @@ -1,22 +1,22 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.common - -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.FilesGenerator -import dev.icerock.gradle.generator.NOPObjectBodyExtendable -import dev.icerock.gradle.generator.ObjectBodyExtendable -import org.gradle.api.file.FileTree - -class CommonFilesGenerator( - ownInputFileTree: FileTree, -) : FilesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { - override fun getClassModifiers(): Array = emptyArray() - - override fun getPropertyModifiers(): Array = emptyArray() - - override fun getPropertyInitializer(fileSpec: FileSpec): CodeBlock? = null -} +///* +// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.common +// +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import dev.icerock.gradle.generator.FilesGenerator +//import dev.icerock.gradle.generator.NOPObjectBodyExtendable +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import org.gradle.api.file.FileTree +// +//class CommonFilesGenerator( +// ownInputFileTree: FileTree, +//) : FilesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { +// override fun getClassModifiers(): Array = emptyArray() +// +// override fun getPropertyModifiers(): Array = emptyArray() +// +// override fun getPropertyInitializer(fileSpec: FileSpec): CodeBlock? = null +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFontsGenerator.kt index eaad16af2..6322b5d5b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFontsGenerator.kt @@ -1,23 +1,23 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.common - -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.FontsGenerator -import dev.icerock.gradle.generator.NOPObjectBodyExtendable -import dev.icerock.gradle.generator.ObjectBodyExtendable -import org.gradle.api.file.FileTree -import java.io.File - -class CommonFontsGenerator( - ownInputFileTree: FileTree, -) : FontsGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { - override fun getClassModifiers(): Array = emptyArray() - - override fun getPropertyModifiers(): Array = emptyArray() - - override fun getPropertyInitializer(fontFile: File): CodeBlock? = null -} +///* +// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.common +// +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import dev.icerock.gradle.generator.FontsGenerator +//import dev.icerock.gradle.generator.NOPObjectBodyExtendable +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import org.gradle.api.file.FileTree +//import java.io.File +// +//class CommonFontsGenerator( +// ownInputFileTree: FileTree, +//) : FontsGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { +// override fun getClassModifiers(): Array = emptyArray() +// +// override fun getPropertyModifiers(): Array = emptyArray() +// +// override fun getPropertyInitializer(fontFile: File): CodeBlock? = null +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonImagesGenerator.kt index 808513ef6..18512bca6 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonImagesGenerator.kt @@ -1,22 +1,22 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.common - -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.ImagesGenerator -import dev.icerock.gradle.generator.NOPObjectBodyExtendable -import dev.icerock.gradle.generator.ObjectBodyExtendable -import org.gradle.api.file.FileTree - -class CommonImagesGenerator( - ownInputFileTree: FileTree, -) : ImagesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { - override fun getClassModifiers(): Array = emptyArray() - - override fun getPropertyModifiers(): Array = emptyArray() - - override fun getPropertyInitializer(fileName: String): CodeBlock? = null -} +///* +// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.common +// +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import dev.icerock.gradle.generator.ImagesGenerator +//import dev.icerock.gradle.generator.NOPObjectBodyExtendable +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import org.gradle.api.file.FileTree +// +//class CommonImagesGenerator( +// ownInputFileTree: FileTree, +//) : ImagesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { +// override fun getClassModifiers(): Array = emptyArray() +// +// override fun getPropertyModifiers(): Array = emptyArray() +// +// override fun getPropertyInitializer(fileName: String): CodeBlock? = null +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index fb1151615..8b23542e0 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -1,263 +1,263 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.common - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.FileSpec -import com.squareup.kotlinpoet.FileSpec.Builder -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.AssetsGenerator -import dev.icerock.gradle.generator.ColorsGenerator -import dev.icerock.gradle.generator.MRGenerator -import dev.icerock.gradle.generator.PluralsGenerator -import dev.icerock.gradle.generator.StringsGenerator -import dev.icerock.gradle.metadata.Metadata.createOutputMetadata -import dev.icerock.gradle.metadata.Metadata.readInputMetadata -import dev.icerock.gradle.metadata.getInterfaceName -import dev.icerock.gradle.metadata.model.GeneratedObject -import dev.icerock.gradle.metadata.model.GeneratedObjectModifier -import dev.icerock.gradle.metadata.model.GeneratedObjectType -import dev.icerock.gradle.metadata.model.GeneratorType -import dev.icerock.gradle.metadata.resourcesIsEmpty -import dev.icerock.gradle.toModifier -import dev.icerock.gradle.utils.targetName -import org.gradle.api.Project -import org.gradle.api.file.FileTree - -class CommonMRGenerator( - private val project: Project, - private val sourceSetName: String, - settings: Settings, - generators: List, -) : MRGenerator( - settings = settings, - generators = generators -) { - override fun getMRClassModifiers(): Array = arrayOf(KModifier.EXPECT) - - // TODO not used. remove after complete migration of task configuration to Plugin configuration time -// override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { -// project.tasks -// .withType>() -//// .matching { it.name.contains(sourceSet.name, ignoreCase = true) } -// .configureEach { it.dependsOn(generationTask) } +///* +// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ // -// project.rootProject.tasks.matching { -// it.name.contains("prepareKotlinBuildScriptModel") -// }.configureEach { -// it.dependsOn(generationTask) +//package dev.icerock.gradle.generator.common +// +//import com.squareup.kotlinpoet.ClassName +//import com.squareup.kotlinpoet.FileSpec +//import com.squareup.kotlinpoet.FileSpec.Builder +//import com.squareup.kotlinpoet.KModifier +//import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +//import com.squareup.kotlinpoet.TypeSpec +//import dev.icerock.gradle.generator.AssetsGenerator +//import dev.icerock.gradle.generator.ColorsGenerator +//import dev.icerock.gradle.generator.MRGenerator +//import dev.icerock.gradle.generator.PluralsGenerator +//import dev.icerock.gradle.generator.StringsGenerator +//import dev.icerock.gradle.metadata.Metadata.createOutputMetadata +//import dev.icerock.gradle.metadata.Metadata.readInputMetadata +//import dev.icerock.gradle.metadata.getInterfaceName +//import dev.icerock.gradle.metadata.model.GeneratedObject +//import dev.icerock.gradle.metadata.model.GeneratedObjectModifier +//import dev.icerock.gradle.metadata.model.GeneratedObjectType +//import dev.icerock.gradle.metadata.model.GeneratorType +//import dev.icerock.gradle.metadata.resourcesIsEmpty +//import dev.icerock.gradle.toModifier +//import dev.icerock.gradle.utils.targetName +//import org.gradle.api.Project +//import org.gradle.api.file.FileTree +// +//class CommonMRGenerator( +// private val project: Project, +// private val sourceSetName: String, +// settings: Settings, +// generators: List, +//) : MRGenerator( +// settings = settings, +// generators = generators +//) { +// override fun getMRClassModifiers(): Array = arrayOf(KModifier.EXPECT) +// +// // TODO not used. remove after complete migration of task configuration to Plugin configuration time +//// override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { +//// project.tasks +//// .withType>() +////// .matching { it.name.contains(sourceSet.name, ignoreCase = true) } +//// .configureEach { it.dependsOn(generationTask) } +//// +//// project.rootProject.tasks.matching { +//// it.name.contains("prepareKotlinBuildScriptModel") +//// }.configureEach { +//// it.dependsOn(generationTask) +//// } +//// +//// project.tasks +//// .matching { it.name.startsWith("metadata") && it.name.endsWith("ProcessResources") } +//// .configureEach { +//// it.dependsOn(generationTask) +//// } +//// } +// +// override fun generateFileSpec(): FileSpec? { +// val inputMetadata: List = readInputMetadata( +// inputMetadataFiles = settings.inputMetadataFiles +// ) +// +// // If previous level's doesn't has resources for generation +// // and target resource has no files - skip step +// if (resourcesIsEmpty(inputMetadata, settings)) return null +// +// val fileSpec: Builder = FileSpec.builder( +// packageName = settings.packageName, +// fileName = settings.className +// ) +// +// val visibilityModifier: KModifier = settings.visibility.toModifier() +// +// val isShouldGenerateExpectObject: Boolean = settings.lowerResourcesFileTree.files +// .none { it.isFile } +// +// val results: List = if (isShouldGenerateExpectObject) { +// // When lower resources is empty, should generate expect MR object +// generateExpectMRObjects( +// inputMetadata = inputMetadata, +// resourcePackage = settings.packageName, +// visibilityModifier = visibilityModifier, +// ) +// } else { +// // If lower resources has files, when on lower level has expect object and +// // need to generate actual interface with fields +// generateActualInterfacesFileSpec( +// visibilityModifier = visibilityModifier, +// inputMetadata = inputMetadata, +// ) // } // -// project.tasks -// .matching { it.name.startsWith("metadata") && it.name.endsWith("ProcessResources") } -// .configureEach { -// it.dependsOn(generationTask) +// if (results.isEmpty()) return null +// +// generators +// .flatMap { generator -> generator.getImports() } +// .plus(getImports()) +// .forEach { className -> +// fileSpec.addImport(className.packageName, className.simpleName) +// } +// +// results.forEach { fileSpec.addType(it.typeSpec) } +// +// createOutputMetadata( +// outputMetadataFile = settings.outputMetadataFile, +// generatedObjects = results.map { it.metadata } +// ) +// +// return fileSpec.build() +// } +// +// private fun generateExpectMRObjects( +// inputMetadata: List, +// resourcePackage: String, +// visibilityModifier: KModifier, +// ): List { +// // generated MR class structure: +// val mrClassSpec: TypeSpec.Builder = +// TypeSpec.objectBuilder(settings.className) // default: object MR +// .addModifiers(KModifier.EXPECT) +// .addModifiers(visibilityModifier) // public/internal +// +// val expectInterfaceResults: List = generateExpectInterfaces( +// visibilityModifier = visibilityModifier, +// upperResourcesFileTree = settings.upperResourcesFileTree +// ) +// val generatedObjects: MutableList = mutableListOf() +// +// generators.forEach { generator: Generator -> +// val builder: TypeSpec.Builder = TypeSpec +// .objectBuilder(generator.mrObjectName) // resource name: example strings +// .addModifiers(visibilityModifier) // public/internal +// .addSuperinterface(generator.resourceContainerClass.parameterizedBy(generator.resourceClassName)) +// +// val expectInterfaces: List = expectInterfaceResults +// .filter { it.metadata.generatorType == generator.type } +// .map { it.metadata } +// +// //Implement interfaces for generated expect object +// expectInterfaces +// .forEach { +// builder.addSuperinterface( +// ClassName(packageName = resourcePackage, it.name) +// ) +// } +// +// val result: GenerationResult? = generator.generateObject( +// project = project, +// metadata = inputMetadata, +// outputMetadata = GeneratedObject( +// generatorType = generator.type, +// modifier = GeneratedObjectModifier.Expect, +// type = GeneratedObjectType.Object, +// name = generator.mrObjectName, +// interfaces = expectInterfaces.map { it.name } +// ), +// assetsGenerationDir = assetsGenerationDir, +// resourcesGenerationDir = resourcesGenerationDir, +// objectBuilder = builder +// ) +// +// if (result != null) { +// mrClassSpec.addType(result.typeSpec) +// generatedObjects.add(result.metadata) // } +// } +// +// processMRClass(mrClassSpec) +// +// if (generatedObjects.isEmpty()) return expectInterfaceResults +// +// return expectInterfaceResults + GenerationResult( +// typeSpec = mrClassSpec.build(), +// // Metadata: Add generated objects in MR +// metadata = GeneratedObject( +// generatorType = GeneratorType.None, +// type = GeneratedObjectType.Object, +// name = settings.className, +// modifier = GeneratedObjectModifier.Expect, +// objects = generatedObjects +// ) +// ) +// } +// +// private fun generateExpectInterfaces( +// visibilityModifier: KModifier, +// upperResourcesFileTree: FileTree, +// ): List { +// return upperResourcesFileTree.mapNotNull { file -> +// val generatorType: GeneratorType = +// if (file.path.matches(StringsGenerator.STRINGS_REGEX)) { +// GeneratorType.Strings +// } else if (file.path.matches(PluralsGenerator.PLURALS_REGEX)) { +// GeneratorType.Plurals +// } else if (file.path.matches(ColorsGenerator.COLORS_REGEX)) { +// GeneratorType.Colors +// } else if (file.parentFile.name == "images") { +// GeneratorType.Images +// } else if (file.parentFile.name == "files") { +// GeneratorType.Files +// } else if (file.parentFile.name == "fonts") { +// GeneratorType.Fonts +// } else if (file.path.matches(AssetsGenerator.ASSETS_REGEX)) { +// GeneratorType.Assets +// } else return@mapNotNull null +// +// GeneratedObject( +// generatorType = generatorType, +// type = GeneratedObjectType.Interface, +// modifier = GeneratedObjectModifier.Expect, +// name = getInterfaceName( +// sourceSetName = file.targetName, +// generatorType = generatorType +// ) +// ) +// }.distinctBy { it.name }.map { expectInterface -> +// val resourcesInterface: TypeSpec = TypeSpec.interfaceBuilder(expectInterface.name) +// .addModifiers(visibilityModifier) +// .addModifiers(KModifier.EXPECT) +// .build() +// +// GenerationResult( +// typeSpec = resourcesInterface, +// metadata = expectInterface +// ) +// } +// } +// +// private fun generateActualInterfacesFileSpec( +// inputMetadata: List, +// visibilityModifier: KModifier, +// ): List { +// return generators.mapNotNull { generator -> +// val interfaceName: String = getInterfaceName( +// sourceSetName = sourceSetName, +// generatorType = generator.type +// ) +// +// val resourcesInterfaceBuilder: TypeSpec.Builder = +// TypeSpec.interfaceBuilder(interfaceName) +// .addModifiers(visibilityModifier) +// .addModifiers(KModifier.ACTUAL) +// +// generator.generateObject( +// project = project, +// metadata = inputMetadata, +// outputMetadata = GeneratedObject( +// generatorType = generator.type, +// name = interfaceName, +// type = GeneratedObjectType.Interface, +// modifier = GeneratedObjectModifier.Actual, +// ), +// assetsGenerationDir = assetsGenerationDir, +// resourcesGenerationDir = resourcesGenerationDir, +// objectBuilder = resourcesInterfaceBuilder, +// ) +// } // } - - override fun generateFileSpec(): FileSpec? { - val inputMetadata: List = readInputMetadata( - inputMetadataFiles = settings.inputMetadataFiles - ) - - // If previous level's doesn't has resources for generation - // and target resource has no files - skip step - if (resourcesIsEmpty(inputMetadata, settings)) return null - - val fileSpec: Builder = FileSpec.builder( - packageName = settings.packageName, - fileName = settings.className - ) - - val visibilityModifier: KModifier = settings.visibility.toModifier() - - val isShouldGenerateExpectObject: Boolean = settings.lowerResourcesFileTree.files - .none { it.isFile } - - val results: List = if (isShouldGenerateExpectObject) { - // When lower resources is empty, should generate expect MR object - generateExpectMRObjects( - inputMetadata = inputMetadata, - resourcePackage = settings.packageName, - visibilityModifier = visibilityModifier, - ) - } else { - // If lower resources has files, when on lower level has expect object and - // need to generate actual interface with fields - generateActualInterfacesFileSpec( - visibilityModifier = visibilityModifier, - inputMetadata = inputMetadata, - ) - } - - if (results.isEmpty()) return null - - generators - .flatMap { generator -> generator.getImports() } - .plus(getImports()) - .forEach { className -> - fileSpec.addImport(className.packageName, className.simpleName) - } - - results.forEach { fileSpec.addType(it.typeSpec) } - - createOutputMetadata( - outputMetadataFile = settings.outputMetadataFile, - generatedObjects = results.map { it.metadata } - ) - - return fileSpec.build() - } - - private fun generateExpectMRObjects( - inputMetadata: List, - resourcePackage: String, - visibilityModifier: KModifier, - ): List { - // generated MR class structure: - val mrClassSpec: TypeSpec.Builder = - TypeSpec.objectBuilder(settings.className) // default: object MR - .addModifiers(KModifier.EXPECT) - .addModifiers(visibilityModifier) // public/internal - - val expectInterfaceResults: List = generateExpectInterfaces( - visibilityModifier = visibilityModifier, - upperResourcesFileTree = settings.upperResourcesFileTree - ) - val generatedObjects: MutableList = mutableListOf() - - generators.forEach { generator: Generator -> - val builder: TypeSpec.Builder = TypeSpec - .objectBuilder(generator.mrObjectName) // resource name: example strings - .addModifiers(visibilityModifier) // public/internal - .addSuperinterface(generator.resourceContainerClass.parameterizedBy(generator.resourceClassName)) - - val expectInterfaces: List = expectInterfaceResults - .filter { it.metadata.generatorType == generator.type } - .map { it.metadata } - - //Implement interfaces for generated expect object - expectInterfaces - .forEach { - builder.addSuperinterface( - ClassName(packageName = resourcePackage, it.name) - ) - } - - val result: GenerationResult? = generator.generate( - project = project, - inputMetadata = inputMetadata, - outputMetadata = GeneratedObject( - generatorType = generator.type, - modifier = GeneratedObjectModifier.Expect, - type = GeneratedObjectType.Object, - name = generator.mrObjectName, - interfaces = expectInterfaces.map { it.name } - ), - assetsGenerationDir = assetsGenerationDir, - resourcesGenerationDir = resourcesGenerationDir, - objectBuilder = builder - ) - - if (result != null) { - mrClassSpec.addType(result.typeSpec) - generatedObjects.add(result.metadata) - } - } - - processMRClass(mrClassSpec) - - if (generatedObjects.isEmpty()) return expectInterfaceResults - - return expectInterfaceResults + GenerationResult( - typeSpec = mrClassSpec.build(), - // Metadata: Add generated objects in MR - metadata = GeneratedObject( - generatorType = GeneratorType.None, - type = GeneratedObjectType.Object, - name = settings.className, - modifier = GeneratedObjectModifier.Expect, - objects = generatedObjects - ) - ) - } - - private fun generateExpectInterfaces( - visibilityModifier: KModifier, - upperResourcesFileTree: FileTree, - ): List { - return upperResourcesFileTree.mapNotNull { file -> - val generatorType: GeneratorType = - if (file.path.matches(StringsGenerator.STRINGS_REGEX)) { - GeneratorType.Strings - } else if (file.path.matches(PluralsGenerator.PLURALS_REGEX)) { - GeneratorType.Plurals - } else if (file.path.matches(ColorsGenerator.COLORS_REGEX)) { - GeneratorType.Colors - } else if (file.parentFile.name == "images") { - GeneratorType.Images - } else if (file.parentFile.name == "files") { - GeneratorType.Files - } else if (file.parentFile.name == "fonts") { - GeneratorType.Fonts - } else if (file.path.matches(AssetsGenerator.ASSETS_REGEX)) { - GeneratorType.Assets - } else return@mapNotNull null - - GeneratedObject( - generatorType = generatorType, - type = GeneratedObjectType.Interface, - modifier = GeneratedObjectModifier.Expect, - name = getInterfaceName( - sourceSetName = file.targetName, - generatorType = generatorType - ) - ) - }.distinctBy { it.name }.map { expectInterface -> - val resourcesInterface: TypeSpec = TypeSpec.interfaceBuilder(expectInterface.name) - .addModifiers(visibilityModifier) - .addModifiers(KModifier.EXPECT) - .build() - - GenerationResult( - typeSpec = resourcesInterface, - metadata = expectInterface - ) - } - } - - private fun generateActualInterfacesFileSpec( - inputMetadata: List, - visibilityModifier: KModifier, - ): List { - return generators.mapNotNull { generator -> - val interfaceName: String = getInterfaceName( - sourceSetName = sourceSetName, - generatorType = generator.type - ) - - val resourcesInterfaceBuilder: TypeSpec.Builder = - TypeSpec.interfaceBuilder(interfaceName) - .addModifiers(visibilityModifier) - .addModifiers(KModifier.ACTUAL) - - generator.generate( - project = project, - inputMetadata = inputMetadata, - outputMetadata = GeneratedObject( - generatorType = generator.type, - name = interfaceName, - type = GeneratedObjectType.Interface, - modifier = GeneratedObjectModifier.Actual, - ), - assetsGenerationDir = assetsGenerationDir, - resourcesGenerationDir = resourcesGenerationDir, - objectBuilder = resourcesInterfaceBuilder, - ) - } - } -} +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonPluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonPluralsGenerator.kt index 67d387dda..4c49bcd64 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonPluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonPluralsGenerator.kt @@ -1,21 +1,21 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.common - -import com.squareup.kotlinpoet.CodeBlock -import dev.icerock.gradle.generator.NOPObjectBodyExtendable -import dev.icerock.gradle.generator.ObjectBodyExtendable -import dev.icerock.gradle.generator.PluralsGenerator -import org.gradle.api.file.FileTree - -class CommonPluralsGenerator( - ownResourcesFileTree: FileTree, - strictLineBreaks: Boolean, -) : PluralsGenerator(ownResourcesFileTree, strictLineBreaks), - ObjectBodyExtendable by NOPObjectBodyExtendable() { - override fun getPropertyInitializer( - key: String - ): CodeBlock? = null -} +///* +// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.common +// +//import com.squareup.kotlinpoet.CodeBlock +//import dev.icerock.gradle.generator.NOPObjectBodyExtendable +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import dev.icerock.gradle.generator.PluralsGenerator +//import org.gradle.api.file.FileTree +// +//class CommonPluralsGenerator( +// ownResourcesFileTree: FileTree, +// strictLineBreaks: Boolean, +//) : PluralsGenerator(ownResourcesFileTree, strictLineBreaks), +// ObjectBodyExtendable by NOPObjectBodyExtendable() { +// override fun getPropertyInitializer( +// key: String +// ): CodeBlock? = null +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonStringsGenerator.kt index e06f12aaf..c714206fc 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonStringsGenerator.kt @@ -1,21 +1,21 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.common - -import com.squareup.kotlinpoet.CodeBlock -import dev.icerock.gradle.generator.NOPObjectBodyExtendable -import dev.icerock.gradle.generator.ObjectBodyExtendable -import dev.icerock.gradle.generator.StringsGenerator -import org.gradle.api.file.FileTree - -class CommonStringsGenerator( - resourcesFileTree: FileTree, - strictLineBreaks: Boolean -) : StringsGenerator( - resourcesFileTree = resourcesFileTree, - strictLineBreaks = strictLineBreaks -), ObjectBodyExtendable by NOPObjectBodyExtendable() { - override fun getPropertyInitializer(key: String): CodeBlock? = null -} +///* +// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.common +// +//import com.squareup.kotlinpoet.CodeBlock +//import dev.icerock.gradle.generator.NOPObjectBodyExtendable +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import dev.icerock.gradle.generator.StringsGenerator +//import org.gradle.api.file.FileTree +// +//class CommonStringsGenerator( +// resourcesFileTree: FileTree, +// strictLineBreaks: Boolean +//) : StringsGenerator( +// resourcesFileTree = resourcesFileTree, +// strictLineBreaks = strictLineBreaks +//), ObjectBodyExtendable by NOPObjectBodyExtendable() { +// override fun getPropertyInitializer(key: String): CodeBlock? = null +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsAssetsGenerator.kt index b6578488b..2287110ae 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsAssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsAssetsGenerator.kt @@ -1,105 +1,105 @@ -/* - * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.js - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.FunSpec -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.AssetsGenerator -import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecDirectory -import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecFile -import dev.icerock.gradle.generator.NOPObjectBodyExtendable -import dev.icerock.gradle.generator.ObjectBodyExtendable -import org.gradle.api.file.FileTree -import java.io.File - -class JsAssetsGenerator( - ownResourcesFileTree: FileTree, -) : AssetsGenerator(ownResourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { - - override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyInitializer(fileSpec: AssetSpecFile): CodeBlock { - val filePath: String = File(FILES_DIR, fileSpec.pathRelativeToBase).path - .replace("\\", "/") - val requireDeclaration = """require("$filePath")""" - return CodeBlock.of( - "AssetResource(originalPath = js(%S) as String, rawPath = %S)", - requireDeclaration, - fileSpec.pathRelativeToBase - ) - } - - override fun beforeGenerate(objectBuilder: TypeSpec.Builder, files: List) { - val languageKeysList = flattenAssets(files).joinToString() - - objectBuilder.addFunction( - FunSpec.builder("values") - .addModifiers(KModifier.OVERRIDE) - .addStatement("return listOf($languageKeysList)") - .returns( - ClassName("kotlin.collections", "List") - .parameterizedBy(resourceClassName) - ) - .build() - ) - } - - private fun flattenAssets(assets: List, prefix: String? = null): List { - return assets.flatMap { spec -> - when (spec) { - is AssetSpecDirectory -> { - val key = spec.name.replace('-', '_') - val nextPrefix = when (prefix) { - null -> key - else -> "$prefix.$key" - } - return@flatMap flattenAssets(spec.assets, nextPrefix) - } - - is AssetSpecFile -> { - val key = spec.file.nameWithoutExtension.replace('-', '_') - val name = when (prefix) { - null -> key - else -> "$prefix.$key" - } - return@flatMap listOf(name) - } - } - } - } - - override fun generateResources( - assetsGenerationDir: File, - resourcesGenerationDir: File, - files: List - ) { - val fileResDir = File(resourcesGenerationDir, FILES_DIR).apply { mkdirs() } - generateResourcesInner(files, fileResDir) - } - - private fun generateResourcesInner(files: List, fileResDir: File) { - files.forEach { assetSpec -> - when (assetSpec) { - is AssetSpecDirectory -> { - generateResourcesInner(assetSpec.assets, fileResDir) - } - - is AssetSpecFile -> { - assetSpec.file.copyTo(File(fileResDir, assetSpec.pathRelativeToBase)) - } - } - } - } - - private companion object { - const val FILES_DIR = "files" - } -} +///* +// * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.js +// +//import com.squareup.kotlinpoet.ClassName +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.FunSpec +//import com.squareup.kotlinpoet.KModifier +//import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +//import com.squareup.kotlinpoet.TypeSpec +//import dev.icerock.gradle.generator.AssetsGenerator +//import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecDirectory +//import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecFile +//import dev.icerock.gradle.generator.NOPObjectBodyExtendable +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import org.gradle.api.file.FileTree +//import java.io.File +// +//class JsAssetsGenerator( +// ownResourcesFileTree: FileTree, +//) : AssetsGenerator(ownResourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { +// +// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyInitializer(fileSpec: AssetSpecFile): CodeBlock { +// val filePath: String = File(FILES_DIR, fileSpec.pathRelativeToBase).path +// .replace("\\", "/") +// val requireDeclaration = """require("$filePath")""" +// return CodeBlock.of( +// "AssetResource(originalPath = js(%S) as String, rawPath = %S)", +// requireDeclaration, +// fileSpec.pathRelativeToBase +// ) +// } +// +// override fun beforeGenerate(objectBuilder: TypeSpec.Builder, files: List) { +// val languageKeysList = flattenAssets(files).joinToString() +// +// objectBuilder.addFunction( +// FunSpec.builder("values") +// .addModifiers(KModifier.OVERRIDE) +// .addStatement("return listOf($languageKeysList)") +// .returns( +// ClassName("kotlin.collections", "List") +// .parameterizedBy(resourceClassName) +// ) +// .build() +// ) +// } +// +// private fun flattenAssets(assets: List, prefix: String? = null): List { +// return assets.flatMap { spec -> +// when (spec) { +// is AssetSpecDirectory -> { +// val key = spec.name.replace('-', '_') +// val nextPrefix = when (prefix) { +// null -> key +// else -> "$prefix.$key" +// } +// return@flatMap flattenAssets(spec.assets, nextPrefix) +// } +// +// is AssetSpecFile -> { +// val key = spec.file.nameWithoutExtension.replace('-', '_') +// val name = when (prefix) { +// null -> key +// else -> "$prefix.$key" +// } +// return@flatMap listOf(name) +// } +// } +// } +// } +// +// override fun generateResources( +// assetsGenerationDir: File, +// resourcesGenerationDir: File, +// files: List +// ) { +// val fileResDir = File(resourcesGenerationDir, FILES_DIR).apply { mkdirs() } +// generateResourcesInner(files, fileResDir) +// } +// +// private fun generateResourcesInner(files: List, fileResDir: File) { +// files.forEach { assetSpec -> +// when (assetSpec) { +// is AssetSpecDirectory -> { +// generateResourcesInner(assetSpec.assets, fileResDir) +// } +// +// is AssetSpecFile -> { +// assetSpec.file.copyTo(File(fileResDir, assetSpec.pathRelativeToBase)) +// } +// } +// } +// } +// +// private companion object { +// const val FILES_DIR = "files" +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsColorsGenerator.kt index d4eb657a6..cdae70428 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsColorsGenerator.kt @@ -1,48 +1,48 @@ -/* - * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.js - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.FunSpec -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.ColorNode -import dev.icerock.gradle.generator.ColorsGenerator -import dev.icerock.gradle.generator.NOPObjectBodyExtendable -import dev.icerock.gradle.generator.ObjectBodyExtendable -import dev.icerock.gradle.generator.jsJvmCommon.createColorResourceInitializer -import org.gradle.api.file.FileTree - -class JsColorsGenerator( - resourcesFileTree: FileTree, -) : ColorsGenerator(resourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { - - override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getImports() = listOf( - ClassName("dev.icerock.moko.graphics", "Color") - ) - - override fun beforeGenerate(objectBuilder: TypeSpec.Builder, keys: List) { - val languageKeysList = keys.joinToString() - - objectBuilder.addFunction( - FunSpec.builder("values") - .addModifiers(KModifier.OVERRIDE) - .addStatement("return listOf($languageKeysList)") - .returns( - ClassName("kotlin.collections", "List") - .parameterizedBy(resourceClassName) - ) - .build() - ) - } - - override fun getPropertyInitializer(color: ColorNode): CodeBlock { - return createColorResourceInitializer(color) - } -} +///* +// * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.js +// +//import com.squareup.kotlinpoet.ClassName +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.FunSpec +//import com.squareup.kotlinpoet.KModifier +//import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +//import com.squareup.kotlinpoet.TypeSpec +//import dev.icerock.gradle.generator.ColorNode +//import dev.icerock.gradle.generator.ColorsGenerator +//import dev.icerock.gradle.generator.NOPObjectBodyExtendable +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import dev.icerock.gradle.generator.jsJvmCommon.createColorResourceInitializer +//import org.gradle.api.file.FileTree +// +//class JsColorsGenerator( +// resourcesFileTree: FileTree, +//) : ColorsGenerator(resourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { +// +// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getImports() = listOf( +// ClassName("dev.icerock.moko.graphics", "Color") +// ) +// +// override fun beforeGenerate(objectBuilder: TypeSpec.Builder, keys: List) { +// val languageKeysList = keys.joinToString() +// +// objectBuilder.addFunction( +// FunSpec.builder("values") +// .addModifiers(KModifier.OVERRIDE) +// .addStatement("return listOf($languageKeysList)") +// .returns( +// ClassName("kotlin.collections", "List") +// .parameterizedBy(resourceClassName) +// ) +// .build() +// ) +// } +// +// override fun getPropertyInitializer(color: ColorNode): CodeBlock { +// return createColorResourceInitializer(color) +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFilesGenerator.kt index 8850bc42b..bdc078ae5 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFilesGenerator.kt @@ -1,62 +1,62 @@ -/* - * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.js - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.FunSpec -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.FilesGenerator -import dev.icerock.gradle.generator.NOPObjectBodyExtendable -import dev.icerock.gradle.generator.ObjectBodyExtendable -import org.gradle.api.file.FileTree -import java.io.File - -class JsFilesGenerator( - ownInputFileTree: FileTree, -) : FilesGenerator( - resourceFiles = ownInputFileTree -), ObjectBodyExtendable by NOPObjectBodyExtendable() { - - override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyInitializer(fileSpec: FileSpec): CodeBlock { - val requireDeclaration = """require("$FILES_DIR/${fileSpec.file.name}")""" - return CodeBlock.of( - "FileResource(fileUrl = js(%S) as String)", - requireDeclaration - ) - } - - override fun beforeGenerate(objectBuilder: TypeSpec.Builder, files: List) { - val languageKeysList = files.joinToString { it.key } - - objectBuilder.addFunction( - FunSpec.builder("values") - .addModifiers(KModifier.OVERRIDE) - .addStatement("return listOf($languageKeysList)") - .returns( - ClassName("kotlin.collections", "List") - .parameterizedBy(resourceClassName) - ) - .build() - ) - } - - override fun generateResources(resourcesGenerationDir: File, files: List) { - val fileResDir = File(resourcesGenerationDir, FILES_DIR).apply { mkdirs() } - files.forEach { (_, file) -> - file.copyTo(File(fileResDir, file.name)) - } - } - - companion object { - const val FILES_DIR = "files" - } -} +///* +// * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.js +// +//import com.squareup.kotlinpoet.ClassName +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.FunSpec +//import com.squareup.kotlinpoet.KModifier +//import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +//import com.squareup.kotlinpoet.TypeSpec +//import dev.icerock.gradle.generator.FilesGenerator +//import dev.icerock.gradle.generator.NOPObjectBodyExtendable +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import org.gradle.api.file.FileTree +//import java.io.File +// +//class JsFilesGenerator( +// ownInputFileTree: FileTree, +//) : FilesGenerator( +// resourceFiles = ownInputFileTree +//), ObjectBodyExtendable by NOPObjectBodyExtendable() { +// +// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyInitializer(fileSpec: FileSpec): CodeBlock { +// val requireDeclaration = """require("$FILES_DIR/${fileSpec.file.name}")""" +// return CodeBlock.of( +// "FileResource(fileUrl = js(%S) as String)", +// requireDeclaration +// ) +// } +// +// override fun beforeGenerate(objectBuilder: TypeSpec.Builder, files: List) { +// val languageKeysList = files.joinToString { it.key } +// +// objectBuilder.addFunction( +// FunSpec.builder("values") +// .addModifiers(KModifier.OVERRIDE) +// .addStatement("return listOf($languageKeysList)") +// .returns( +// ClassName("kotlin.collections", "List") +// .parameterizedBy(resourceClassName) +// ) +// .build() +// ) +// } +// +// override fun generateResources(resourcesGenerationDir: File, files: List) { +// val fileResDir = File(resourcesGenerationDir, FILES_DIR).apply { mkdirs() } +// files.forEach { (_, file) -> +// file.copyTo(File(fileResDir, file.name)) +// } +// } +// +// companion object { +// const val FILES_DIR = "files" +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFontsGenerator.kt index 26c60d6e1..8c5c99523 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFontsGenerator.kt @@ -1,100 +1,100 @@ -/* - * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.js - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.FunSpec -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.FontsGenerator -import dev.icerock.gradle.generator.NOPObjectBodyExtendable -import dev.icerock.gradle.generator.ObjectBodyExtendable -import dev.icerock.gradle.utils.flatName -import org.gradle.api.file.FileTree -import org.gradle.api.provider.Provider -import org.gradle.kotlin.dsl.provideDelegate -import java.io.File - -class JsFontsGenerator( - ownInputFileTree: FileTree, - mrClassPackage: String, -) : FontsGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { - - private val flattenPackage: String = mrClassPackage.flatName - private val cssDeclarationsFileName: String = "$flattenPackage-generated-declarations.css" - - override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - - @Suppress("StringTemplate") - override fun getPropertyInitializer(fontFile: File): CodeBlock { - val requireDeclaration = """require("$FONTS_DIR/${fontFile.name}")""" - return CodeBlock.of( - "FontResource(fileUrl = js(%S) as String, fontFamily = %S)", - requireDeclaration, - fontFile.nameWithoutExtension - ) - } - - override fun beforeGenerateResources(objectBuilder: TypeSpec.Builder, files: List) { - val languageKeysList = files.joinToString { - val (style, family) = it.key.split("-", limit = 2) - val familyName = family.replaceFirstChar(Char::lowercase) - return@joinToString "$style.$familyName" - } - - objectBuilder.addFunction( - FunSpec.builder("values") - .addModifiers(KModifier.OVERRIDE) - .addStatement("return listOf($languageKeysList)") - .returns( - ClassName("kotlin.collections", "List") - .parameterizedBy(resourceClassName) - ) - .build() - ) - - if (files.isEmpty()) return - - objectBuilder.addFunction( - FunSpec.builder("addFontsToPage") - .addCode( - "js(%S)", - """require("$FONTS_DIR/${cssDeclarationsFileName}")""" - ).build() - ) - } - - override fun generateResources(resourcesGenerationDir: File, files: List) { - val fontsDir = File(resourcesGenerationDir, FONTS_DIR).apply { mkdirs() } - - files.forEach { (_, file) -> - file.copyTo(File(fontsDir, file.name)) - } - - val cssDeclarationsFile = File(fontsDir, cssDeclarationsFileName) - - val declarations = files - .takeIf(List<*>::isNotEmpty) - ?.joinToString(separator = "\n") { (family, file) -> - // language=css - """ - @font-face { - font-family: "$family"; - src: url("${file.name}"); - } - """.trimIndent() - } - - if (declarations != null) cssDeclarationsFile.writeText(declarations) - } - - companion object { - const val FONTS_DIR = "fonts" - } -} +///* +// * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.js +// +//import com.squareup.kotlinpoet.ClassName +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.FunSpec +//import com.squareup.kotlinpoet.KModifier +//import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +//import com.squareup.kotlinpoet.TypeSpec +//import dev.icerock.gradle.generator.FontsGenerator +//import dev.icerock.gradle.generator.NOPObjectBodyExtendable +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import dev.icerock.gradle.utils.flatName +//import org.gradle.api.file.FileTree +//import org.gradle.api.provider.Provider +//import org.gradle.kotlin.dsl.provideDelegate +//import java.io.File +// +//class JsFontsGenerator( +// ownInputFileTree: FileTree, +// mrClassPackage: String, +//) : FontsGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { +// +// private val flattenPackage: String = mrClassPackage.flatName +// private val cssDeclarationsFileName: String = "$flattenPackage-generated-declarations.css" +// +// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// @Suppress("StringTemplate") +// override fun getPropertyInitializer(fontFile: File): CodeBlock { +// val requireDeclaration = """require("$FONTS_DIR/${fontFile.name}")""" +// return CodeBlock.of( +// "FontResource(fileUrl = js(%S) as String, fontFamily = %S)", +// requireDeclaration, +// fontFile.nameWithoutExtension +// ) +// } +// +// override fun beforeGenerateResources(objectBuilder: TypeSpec.Builder, files: List) { +// val languageKeysList = files.joinToString { +// val (style, family) = it.key.split("-", limit = 2) +// val familyName = family.replaceFirstChar(Char::lowercase) +// return@joinToString "$style.$familyName" +// } +// +// objectBuilder.addFunction( +// FunSpec.builder("values") +// .addModifiers(KModifier.OVERRIDE) +// .addStatement("return listOf($languageKeysList)") +// .returns( +// ClassName("kotlin.collections", "List") +// .parameterizedBy(resourceClassName) +// ) +// .build() +// ) +// +// if (files.isEmpty()) return +// +// objectBuilder.addFunction( +// FunSpec.builder("addFontsToPage") +// .addCode( +// "js(%S)", +// """require("$FONTS_DIR/${cssDeclarationsFileName}")""" +// ).build() +// ) +// } +// +// override fun generateResources(resourcesGenerationDir: File, files: List) { +// val fontsDir = File(resourcesGenerationDir, FONTS_DIR).apply { mkdirs() } +// +// files.forEach { (_, file) -> +// file.copyTo(File(fontsDir, file.name)) +// } +// +// val cssDeclarationsFile = File(fontsDir, cssDeclarationsFileName) +// +// val declarations = files +// .takeIf(List<*>::isNotEmpty) +// ?.joinToString(separator = "\n") { (family, file) -> +// // language=css +// """ +// @font-face { +// font-family: "$family"; +// src: url("${file.name}"); +// } +// """.trimIndent() +// } +// +// if (declarations != null) cssDeclarationsFile.writeText(declarations) +// } +// +// companion object { +// const val FONTS_DIR = "fonts" +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsImagesGenerator.kt index a3c4eb1e0..86a6c8839 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsImagesGenerator.kt @@ -1,64 +1,64 @@ -/* - * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.js - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.FunSpec -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.ImagesGenerator -import dev.icerock.gradle.generator.NOPObjectBodyExtendable -import dev.icerock.gradle.generator.ObjectBodyExtendable -import dev.icerock.gradle.generator.jsJvmCommon.generateHighestQualityImageResources -import org.gradle.api.file.FileTree -import java.io.File - -class JsImagesGenerator( - ownInputFileTree: FileTree, -) : ImagesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { - override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyInitializer(fileName: String): CodeBlock { - val requireDeclaration = """require("$IMAGES_DIR/$fileName")""" - return CodeBlock.of( - "ImageResource(fileUrl = js(%S) as String, fileName = %S)", - requireDeclaration, - fileName - ) - } - - override fun beforeGenerateResources(objectBuilder: TypeSpec.Builder, keys: List) { - val languageKeysList = keys.joinToString { key -> - key.substringBeforeLast(".").replace(".", "_") - } - - objectBuilder.addFunction( - FunSpec.builder("values") - .addModifiers(KModifier.OVERRIDE) - .addStatement("return listOf($languageKeysList)") - .returns( - ClassName("kotlin.collections", "List") - .parameterizedBy(resourceClassName) - ) - .build() - ) - } - - override fun generateResources( - assetsGenerationDir: File, - resourcesGenerationDir: File, - keyFileMap: Map> - ) { - generateHighestQualityImageResources(resourcesGenerationDir, keyFileMap, IMAGES_DIR) - } - - companion object { - const val IMAGES_DIR = "images" - } -} +///* +// * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.js +// +//import com.squareup.kotlinpoet.ClassName +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.FunSpec +//import com.squareup.kotlinpoet.KModifier +//import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +//import com.squareup.kotlinpoet.TypeSpec +//import dev.icerock.gradle.generator.ImagesGenerator +//import dev.icerock.gradle.generator.NOPObjectBodyExtendable +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import dev.icerock.gradle.generator.jsJvmCommon.generateHighestQualityImageResources +//import org.gradle.api.file.FileTree +//import java.io.File +// +//class JsImagesGenerator( +// ownInputFileTree: FileTree, +//) : ImagesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { +// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyInitializer(fileName: String): CodeBlock { +// val requireDeclaration = """require("$IMAGES_DIR/$fileName")""" +// return CodeBlock.of( +// "ImageResource(fileUrl = js(%S) as String, fileName = %S)", +// requireDeclaration, +// fileName +// ) +// } +// +// override fun beforeGenerateResources(objectBuilder: TypeSpec.Builder, keys: List) { +// val languageKeysList = keys.joinToString { key -> +// key.substringBeforeLast(".").replace(".", "_") +// } +// +// objectBuilder.addFunction( +// FunSpec.builder("values") +// .addModifiers(KModifier.OVERRIDE) +// .addStatement("return listOf($languageKeysList)") +// .returns( +// ClassName("kotlin.collections", "List") +// .parameterizedBy(resourceClassName) +// ) +// .build() +// ) +// } +// +// override fun generateResources( +// assetsGenerationDir: File, +// resourcesGenerationDir: File, +// keyFileMap: Map> +// ) { +// generateHighestQualityImageResources(resourcesGenerationDir, keyFileMap, IMAGES_DIR) +// } +// +// companion object { +// const val IMAGES_DIR = "images" +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt index 21d01584f..1aff24843 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt @@ -1,98 +1,98 @@ -/* - * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.js - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.PropertySpec -import com.squareup.kotlinpoet.STRING -import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.TargetMRGenerator -import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask -import dev.icerock.gradle.utils.calculateResourcesHash -import dev.icerock.gradle.utils.flatName -import org.gradle.api.Project -import org.gradle.jvm.tasks.Jar -import org.gradle.kotlin.dsl.withType -import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile -import java.io.File - -class JsMRGenerator( - project: Project, - settings: Settings, - generators: List, -) : TargetMRGenerator( - project = project, - settings = settings, - generators = generators -) { - private val flattenClassName: String = settings.packageName.flatName - override val resourcesGenerationDir: File = settings.resourcesDir.asFile - - override fun processMRClass(mrClass: TypeSpec.Builder) { - mrClass.addProperty( - PropertySpec.builder("contentHash", STRING, KModifier.PRIVATE) - .initializer("%S", resourcesGenerationDir.calculateResourcesHash()) - .build() - ) - - val stringsLoaderInitializer = buildList { - val stringsObjectLoader = mrClass - .typeSpecs - .find { it.name == "strings" } - ?.propertySpecs - ?.find { it.name == "stringsLoader" } - - val pluralsObjectLoader = mrClass - .typeSpecs - .find { it.name == "plurals" } - ?.propertySpecs - ?.find { it.name == "stringsLoader" } - - if (stringsObjectLoader != null) { - add("strings.stringsLoader") - } - if (pluralsObjectLoader != null) { - add("plurals.stringsLoader") - } - }.takeIf(List<*>::isNotEmpty) - ?.joinToString(separator = " + ") - - if (stringsLoaderInitializer != null) { - mrClass.addProperty( - PropertySpec.builder( - "stringsLoader", - ClassName("dev.icerock.moko.resources.provider", "RemoteJsStringLoader"), - ).initializer(stringsLoaderInitializer) - .build() - ) - } - } - - // TODO not used. remove after complete migration of task configuration to Plugin configuration time -// override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { -// project.tasks.withType().configureEach { -// it.dependsOn(generationTask) -// } -//// setupKLibResources(generationTask) -//// setupResources() +///* +// * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.js +// +//import com.squareup.kotlinpoet.ClassName +//import com.squareup.kotlinpoet.KModifier +//import com.squareup.kotlinpoet.PropertySpec +//import com.squareup.kotlinpoet.STRING +//import com.squareup.kotlinpoet.TypeSpec +//import dev.icerock.gradle.generator.TargetMRGenerator +//import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask +//import dev.icerock.gradle.utils.calculateResourcesHash +//import dev.icerock.gradle.utils.flatName +//import org.gradle.api.Project +//import org.gradle.jvm.tasks.Jar +//import org.gradle.kotlin.dsl.withType +//import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile +//import java.io.File +// +//class JsMRGenerator( +// project: Project, +// settings: Settings, +// generators: List, +//) : TargetMRGenerator( +// project = project, +// settings = settings, +// generators = generators +//) { +// private val flattenClassName: String = settings.packageName.flatName +// override val resourcesGenerationDir: File = settings.resourcesDir.asFile +// +// override fun processMRClass(mrClass: TypeSpec.Builder) { +// mrClass.addProperty( +// PropertySpec.builder("contentHash", STRING, KModifier.PRIVATE) +// .initializer("%S", resourcesGenerationDir.calculateResourcesHash()) +// .build() +// ) // -// // Declare task ':web-app:generateMRcommonMain' as an input of ':web-app:jsSourcesJar'. -// project.tasks.withType().configureEach { -// it.dependsOn(generationTask) +// val stringsLoaderInitializer = buildList { +// val stringsObjectLoader = mrClass +// .typeSpecs +// .find { it.name == "strings" } +// ?.propertySpecs +// ?.find { it.name == "stringsLoader" } +// +// val pluralsObjectLoader = mrClass +// .typeSpecs +// .find { it.name == "plurals" } +// ?.propertySpecs +// ?.find { it.name == "stringsLoader" } +// +// if (stringsObjectLoader != null) { +// add("strings.stringsLoader") +// } +// if (pluralsObjectLoader != null) { +// add("plurals.stringsLoader") +// } +// }.takeIf(List<*>::isNotEmpty) +// ?.joinToString(separator = " + ") +// +// if (stringsLoaderInitializer != null) { +// mrClass.addProperty( +// PropertySpec.builder( +// "stringsLoader", +// ClassName("dev.icerock.moko.resources.provider", "RemoteJsStringLoader"), +// ).initializer(stringsLoaderInitializer) +// .build() +// ) // } +// } +// +// // TODO not used. remove after complete migration of task configuration to Plugin configuration time +//// override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { +//// project.tasks.withType().configureEach { +//// it.dependsOn(generationTask) +//// } +////// setupKLibResources(generationTask) +////// setupResources() +//// +//// // Declare task ':web-app:generateMRcommonMain' as an input of ':web-app:jsSourcesJar'. +//// project.tasks.withType().configureEach { +//// it.dependsOn(generationTask) +//// } +//// +////// dependsOnProcessResources( +////// project = project, +////// sourceSet = sourceSet, +////// task = generationTask, +////// ) +//// } // -//// dependsOnProcessResources( -//// project = project, -//// sourceSet = sourceSet, -//// task = generationTask, -//// ) +// companion object { +// const val SUPPORTED_LOCALES_PROPERTY_NAME = "supportedLocales" +// const val LOCALIZATION_DIR = "localization" // } - - companion object { - const val SUPPORTED_LOCALES_PROPERTY_NAME = "supportedLocales" - const val LOCALIZATION_DIR = "localization" - } -} +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsPluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsPluralsGenerator.kt index ad8ea3cb1..1bb093c0b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsPluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsPluralsGenerator.kt @@ -1,118 +1,118 @@ -/* - * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.js - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.FunSpec -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.KeyType -import dev.icerock.gradle.generator.LanguageType -import dev.icerock.gradle.generator.NOPObjectBodyExtendable -import dev.icerock.gradle.generator.ObjectBodyExtendable -import dev.icerock.gradle.generator.PluralMap -import dev.icerock.gradle.generator.PluralsGenerator -import dev.icerock.gradle.utils.flatName -import kotlinx.serialization.json.buildJsonObject -import kotlinx.serialization.json.put -import org.gradle.api.file.FileTree -import java.io.File - -class JsPluralsGenerator( - ownResourcesFileTree: FileTree, - mrClassPackage: String, - strictLineBreaks: Boolean -) : PluralsGenerator(ownResourcesFileTree, strictLineBreaks), - ObjectBodyExtendable by NOPObjectBodyExtendable() { - - private val flattenClassPackage = mrClassPackage.flatName - - override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyInitializer(key: String): CodeBlock { - return CodeBlock.of("PluralsResource(key = %S, loader = stringsLoader)", key) - } - - override fun beforeGenerateResources( - objectBuilder: TypeSpec.Builder, - languageMap: Map> - ) { - objectBuilder.generateFallbackAndSupportedLanguageProperties( - languages = languageMap.keys.toList(), - folder = JsMRGenerator.LOCALIZATION_DIR, - fallbackFilePropertyName = PLURALS_FALLBACK_FILE_URL_PROPERTY_NAME, - fallbackFile = "${flattenClassPackage}_${PLURALS_JSON_NAME}.json", - supportedLocalesPropertyName = JsMRGenerator.SUPPORTED_LOCALES_PROPERTY_NAME, - getFileNameForLanguage = { language -> - "${flattenClassPackage}_${PLURALS_JSON_NAME}${language.jsResourcesSuffix}.json" - } - ) - val languageKeys = languageMap[LanguageType.Base].orEmpty().keys - val languageKeysList = languageKeys.joinToString { it.replace(".", "_") } - - objectBuilder.addFunction( - FunSpec.builder("values") - .addModifiers(KModifier.OVERRIDE) - .addStatement("return listOf($languageKeysList)") - .returns( - ClassName("kotlin.collections", "List") - .parameterizedBy(resourceClassName) - ) - .build() - ) - } - - override fun generateResources( - resourcesGenerationDir: File, - language: LanguageType, - strings: Map - ) { - val fileDirName = - "${flattenClassPackage}_${PLURALS_JSON_NAME}${language.jsResourcesSuffix}" - - val localizationDir = File(resourcesGenerationDir, JsMRGenerator.LOCALIZATION_DIR).apply { - mkdirs() - } - - val pluralsFile = File(localizationDir, "$fileDirName.json") - - val content = buildJsonObject { - strings.forEach { (key, pluralMap) -> - val messageFormatString = StringBuilder().apply { - append("{ PLURAL, plural, ") - pluralMap.forEach { (pluralKey, pluralString) -> - // Zero isn't allowed in english (which is default for base), but we support it through =0 - val actPluralKey = when (pluralKey) { - "zero" -> "=0" - "two" -> "=2" - else -> pluralKey - } - - append(actPluralKey) - append(" ") - append("{") - append(pluralString.convertToMessageFormat()) - append("} ") - } - - append("}") - }.toString() - - put(key, messageFormatString) - } - }.toString() - - pluralsFile.writeText(content) - } - - companion object { - const val PLURALS_JSON_NAME = "pluralsJson" - const val PLURALS_FALLBACK_FILE_URL_PROPERTY_NAME = "stringsFallbackFileUrl" - } -} +///* +// * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.js +// +//import com.squareup.kotlinpoet.ClassName +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.FunSpec +//import com.squareup.kotlinpoet.KModifier +//import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +//import com.squareup.kotlinpoet.TypeSpec +//import dev.icerock.gradle.generator.KeyType +//import dev.icerock.gradle.generator.LanguageType +//import dev.icerock.gradle.generator.NOPObjectBodyExtendable +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import dev.icerock.gradle.generator.PluralMap +//import dev.icerock.gradle.generator.PluralsGenerator +//import dev.icerock.gradle.utils.flatName +//import kotlinx.serialization.json.buildJsonObject +//import kotlinx.serialization.json.put +//import org.gradle.api.file.FileTree +//import java.io.File +// +//class JsPluralsGenerator( +// ownResourcesFileTree: FileTree, +// mrClassPackage: String, +// strictLineBreaks: Boolean +//) : PluralsGenerator(ownResourcesFileTree, strictLineBreaks), +// ObjectBodyExtendable by NOPObjectBodyExtendable() { +// +// private val flattenClassPackage = mrClassPackage.flatName +// +// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyInitializer(key: String): CodeBlock { +// return CodeBlock.of("PluralsResource(key = %S, loader = stringsLoader)", key) +// } +// +// override fun beforeGenerateResources( +// objectBuilder: TypeSpec.Builder, +// languageMap: Map> +// ) { +// objectBuilder.generateFallbackAndSupportedLanguageProperties( +// languages = languageMap.keys.toList(), +// folder = JsMRGenerator.LOCALIZATION_DIR, +// fallbackFilePropertyName = PLURALS_FALLBACK_FILE_URL_PROPERTY_NAME, +// fallbackFile = "${flattenClassPackage}_${PLURALS_JSON_NAME}.json", +// supportedLocalesPropertyName = JsMRGenerator.SUPPORTED_LOCALES_PROPERTY_NAME, +// getFileNameForLanguage = { language -> +// "${flattenClassPackage}_${PLURALS_JSON_NAME}${language.jsResourcesSuffix}.json" +// } +// ) +// val languageKeys = languageMap[LanguageType.Base].orEmpty().keys +// val languageKeysList = languageKeys.joinToString { it.replace(".", "_") } +// +// objectBuilder.addFunction( +// FunSpec.builder("values") +// .addModifiers(KModifier.OVERRIDE) +// .addStatement("return listOf($languageKeysList)") +// .returns( +// ClassName("kotlin.collections", "List") +// .parameterizedBy(resourceClassName) +// ) +// .build() +// ) +// } +// +// override fun generateResources( +// resourcesGenerationDir: File, +// language: LanguageType, +// strings: Map +// ) { +// val fileDirName = +// "${flattenClassPackage}_${PLURALS_JSON_NAME}${language.jsResourcesSuffix}" +// +// val localizationDir = File(resourcesGenerationDir, JsMRGenerator.LOCALIZATION_DIR).apply { +// mkdirs() +// } +// +// val pluralsFile = File(localizationDir, "$fileDirName.json") +// +// val content = buildJsonObject { +// strings.forEach { (key, pluralMap) -> +// val messageFormatString = StringBuilder().apply { +// append("{ PLURAL, plural, ") +// pluralMap.forEach { (pluralKey, pluralString) -> +// // Zero isn't allowed in english (which is default for base), but we support it through =0 +// val actPluralKey = when (pluralKey) { +// "zero" -> "=0" +// "two" -> "=2" +// else -> pluralKey +// } +// +// append(actPluralKey) +// append(" ") +// append("{") +// append(pluralString.convertToMessageFormat()) +// append("} ") +// } +// +// append("}") +// }.toString() +// +// put(key, messageFormatString) +// } +// }.toString() +// +// pluralsFile.writeText(content) +// } +// +// companion object { +// const val PLURALS_JSON_NAME = "pluralsJson" +// const val PLURALS_FALLBACK_FILE_URL_PROPERTY_NAME = "stringsFallbackFileUrl" +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt index 3e5e9163d..99c71c4a4 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt @@ -1,101 +1,101 @@ -/* - * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.js - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.FunSpec -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.KeyType -import dev.icerock.gradle.generator.LanguageType -import dev.icerock.gradle.generator.NOPObjectBodyExtendable -import dev.icerock.gradle.generator.ObjectBodyExtendable -import dev.icerock.gradle.generator.StringsGenerator -import dev.icerock.gradle.generator.js.JsMRGenerator.Companion.SUPPORTED_LOCALES_PROPERTY_NAME -import dev.icerock.gradle.utils.flatName -import kotlinx.serialization.json.buildJsonObject -import kotlinx.serialization.json.put -import org.gradle.api.file.FileTree -import java.io.File - -class JsStringsGenerator( - resourcesFileTree: FileTree, - mrClassPackage: String, - strictLineBreaks: Boolean -) : StringsGenerator( - resourcesFileTree = resourcesFileTree, - strictLineBreaks = strictLineBreaks -), - ObjectBodyExtendable by NOPObjectBodyExtendable() { - - private val flattenClassPackage = mrClassPackage.flatName - - override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyInitializer(key: String): CodeBlock { - return CodeBlock.of("StringResource(key = %S, loader = stringsLoader)", key) - } - - override fun beforeGenerateResources( - objectBuilder: TypeSpec.Builder, - languageMap: Map> - ) { - objectBuilder.generateFallbackAndSupportedLanguageProperties( - languages = languageMap.keys.toList(), - folder = JsMRGenerator.LOCALIZATION_DIR, - fallbackFilePropertyName = STRINGS_FALLBACK_FILE_URL_PROPERTY_NAME, - fallbackFile = "${flattenClassPackage}_${STRINGS_JSON_NAME}.json", - supportedLocalesPropertyName = SUPPORTED_LOCALES_PROPERTY_NAME, - getFileNameForLanguage = { language -> - "${flattenClassPackage}_${STRINGS_JSON_NAME}${language.jsResourcesSuffix}.json" - } - ) - val languageKeys = languageMap[LanguageType.Base].orEmpty().keys - val languageKeysList = languageKeys.joinToString { it.replace(".", "_") } - - objectBuilder.addFunction( - FunSpec.builder("values") - .addModifiers(KModifier.OVERRIDE) - .addStatement("return listOf($languageKeysList)") - .returns( - ClassName("kotlin.collections", "List") - .parameterizedBy(resourceClassName) - ) - .build() - ) - } - - override fun generateResources( - resourcesGenerationDir: File, - language: LanguageType, - strings: Map - ) { - val fileDirName = - "${flattenClassPackage}_${STRINGS_JSON_NAME}${language.jsResourcesSuffix}" - - val localizationDir = File(resourcesGenerationDir, JsMRGenerator.LOCALIZATION_DIR).apply { - mkdirs() - } - - val stringsFile = File(localizationDir, "$fileDirName.json") - - val content = buildJsonObject { - strings.forEach { (key, value) -> - put(key, value.convertToMessageFormat()) - } - }.toString() - - stringsFile.writeText(content) - } - - companion object { - const val STRINGS_JSON_NAME = "stringsJson" - const val STRINGS_FALLBACK_FILE_URL_PROPERTY_NAME = "stringsFallbackFileUrl" - } -} +///* +// * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.js +// +//import com.squareup.kotlinpoet.ClassName +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.FunSpec +//import com.squareup.kotlinpoet.KModifier +//import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +//import com.squareup.kotlinpoet.TypeSpec +//import dev.icerock.gradle.generator.KeyType +//import dev.icerock.gradle.generator.LanguageType +//import dev.icerock.gradle.generator.NOPObjectBodyExtendable +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import dev.icerock.gradle.generator.StringsGenerator +//import dev.icerock.gradle.generator.js.JsMRGenerator.Companion.SUPPORTED_LOCALES_PROPERTY_NAME +//import dev.icerock.gradle.utils.flatName +//import kotlinx.serialization.json.buildJsonObject +//import kotlinx.serialization.json.put +//import org.gradle.api.file.FileTree +//import java.io.File +// +//class JsStringsGenerator( +// resourcesFileTree: FileTree, +// mrClassPackage: String, +// strictLineBreaks: Boolean +//) : StringsGenerator( +// resourcesFileTree = resourcesFileTree, +// strictLineBreaks = strictLineBreaks +//), +// ObjectBodyExtendable by NOPObjectBodyExtendable() { +// +// private val flattenClassPackage = mrClassPackage.flatName +// +// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyInitializer(key: String): CodeBlock { +// return CodeBlock.of("StringResource(key = %S, loader = stringsLoader)", key) +// } +// +// override fun beforeGenerateResources( +// objectBuilder: TypeSpec.Builder, +// languageMap: Map> +// ) { +// objectBuilder.generateFallbackAndSupportedLanguageProperties( +// languages = languageMap.keys.toList(), +// folder = JsMRGenerator.LOCALIZATION_DIR, +// fallbackFilePropertyName = STRINGS_FALLBACK_FILE_URL_PROPERTY_NAME, +// fallbackFile = "${flattenClassPackage}_${STRINGS_JSON_NAME}.json", +// supportedLocalesPropertyName = SUPPORTED_LOCALES_PROPERTY_NAME, +// getFileNameForLanguage = { language -> +// "${flattenClassPackage}_${STRINGS_JSON_NAME}${language.jsResourcesSuffix}.json" +// } +// ) +// val languageKeys = languageMap[LanguageType.Base].orEmpty().keys +// val languageKeysList = languageKeys.joinToString { it.replace(".", "_") } +// +// objectBuilder.addFunction( +// FunSpec.builder("values") +// .addModifiers(KModifier.OVERRIDE) +// .addStatement("return listOf($languageKeysList)") +// .returns( +// ClassName("kotlin.collections", "List") +// .parameterizedBy(resourceClassName) +// ) +// .build() +// ) +// } +// +// override fun generateResources( +// resourcesGenerationDir: File, +// language: LanguageType, +// strings: Map +// ) { +// val fileDirName = +// "${flattenClassPackage}_${STRINGS_JSON_NAME}${language.jsResourcesSuffix}" +// +// val localizationDir = File(resourcesGenerationDir, JsMRGenerator.LOCALIZATION_DIR).apply { +// mkdirs() +// } +// +// val stringsFile = File(localizationDir, "$fileDirName.json") +// +// val content = buildJsonObject { +// strings.forEach { (key, value) -> +// put(key, value.convertToMessageFormat()) +// } +// }.toString() +// +// stringsFile.writeText(content) +// } +// +// companion object { +// const val STRINGS_JSON_NAME = "stringsJson" +// const val STRINGS_FALLBACK_FILE_URL_PROPERTY_NAME = "stringsFallbackFileUrl" +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/StringPluralPropertyGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/StringPluralPropertyGenerator.kt index c8a271c58..c5d2ff918 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/StringPluralPropertyGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/StringPluralPropertyGenerator.kt @@ -1,92 +1,92 @@ -/* - * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.js - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.PropertySpec -import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.LanguageType - -/** - * @param folder the folder, where the localization files are in. - * @param languages the language codes supported - * @param fallbackFilePropertyName the property name in the MR object - * @param fallbackFile the name of the file webpack will use, e.g. my_plurals.json - */ -@Suppress("LongParameterList") -fun TypeSpec.Builder.generateFallbackAndSupportedLanguageProperties( - languages: List, - folder: String, - fallbackFilePropertyName: String, - fallbackFile: String, - supportedLocalesPropertyName: String, - getFileNameForLanguage: (language: LanguageType.Locale) -> String -) { - if (languages.isEmpty()) return - - addProperty( - PropertySpec - .builder(fallbackFilePropertyName, String::class, KModifier.PRIVATE) - .initializer( - CodeBlock.of( - "js(%S) as %T", - "require(\"$folder/$fallbackFile\")", - String::class - ) - ) - .build() - ) - - val internalPackage = "dev.icerock.moko.resources.internal" - val supportedLocalesName = ClassName(internalPackage, "SupportedLocales") - val supportedLocaleName = ClassName(internalPackage, "SupportedLocale") - val loaderHolderName = ClassName(internalPackage, "RemoteJsStringLoaderHolder") - - val loaderPackage = "dev.icerock.moko.resources.provider" - val loaderName = ClassName(loaderPackage, "RemoteJsStringLoader") - - addProperty( - PropertySpec - .builder(supportedLocalesPropertyName, supportedLocalesName, KModifier.PRIVATE) - .initializer( - CodeBlock - .builder() - .apply { - add("%T(listOf(\n", supportedLocalesName) - languages.filterIsInstance().forEach { language -> - val fileName = getFileNameForLanguage(language) - add( - "%T(%S, js(%S) as %T),\n", - supportedLocaleName, - language.toBcpString(), - "require(\"$folder/$fileName\")", - String::class - ) - } - add("))") - } - .build() - ) - .build() - ) - - addSuperinterface(loaderHolderName) - - addProperty( - PropertySpec.builder( - "stringsLoader", - loaderName, - KModifier.OVERRIDE - ).initializer( - CodeBlock.of( - "RemoteJsStringLoader.Impl(supportedLocales = %N, fallbackFileUri = %N)", - supportedLocalesPropertyName, - fallbackFilePropertyName - ) - ).build() - ) -} +///* +// * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.js +// +//import com.squareup.kotlinpoet.ClassName +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import com.squareup.kotlinpoet.PropertySpec +//import com.squareup.kotlinpoet.TypeSpec +//import dev.icerock.gradle.generator.LanguageType +// +///** +// * @param folder the folder, where the localization files are in. +// * @param languages the language codes supported +// * @param fallbackFilePropertyName the property name in the MR object +// * @param fallbackFile the name of the file webpack will use, e.g. my_plurals.json +// */ +//@Suppress("LongParameterList") +//fun TypeSpec.Builder.generateFallbackAndSupportedLanguageProperties( +// languages: List, +// folder: String, +// fallbackFilePropertyName: String, +// fallbackFile: String, +// supportedLocalesPropertyName: String, +// getFileNameForLanguage: (language: LanguageType.Locale) -> String +//) { +// if (languages.isEmpty()) return +// +// addProperty( +// PropertySpec +// .builder(fallbackFilePropertyName, String::class, KModifier.PRIVATE) +// .initializer( +// CodeBlock.of( +// "js(%S) as %T", +// "require(\"$folder/$fallbackFile\")", +// String::class +// ) +// ) +// .build() +// ) +// +// val internalPackage = "dev.icerock.moko.resources.internal" +// val supportedLocalesName = ClassName(internalPackage, "SupportedLocales") +// val supportedLocaleName = ClassName(internalPackage, "SupportedLocale") +// val loaderHolderName = ClassName(internalPackage, "RemoteJsStringLoaderHolder") +// +// val loaderPackage = "dev.icerock.moko.resources.provider" +// val loaderName = ClassName(loaderPackage, "RemoteJsStringLoader") +// +// addProperty( +// PropertySpec +// .builder(supportedLocalesPropertyName, supportedLocalesName, KModifier.PRIVATE) +// .initializer( +// CodeBlock +// .builder() +// .apply { +// add("%T(listOf(\n", supportedLocalesName) +// languages.filterIsInstance().forEach { language -> +// val fileName = getFileNameForLanguage(language) +// add( +// "%T(%S, js(%S) as %T),\n", +// supportedLocaleName, +// language.toBcpString(), +// "require(\"$folder/$fileName\")", +// String::class +// ) +// } +// add("))") +// } +// .build() +// ) +// .build() +// ) +// +// addSuperinterface(loaderHolderName) +// +// addProperty( +// PropertySpec.builder( +// "stringsLoader", +// loaderName, +// KModifier.OVERRIDE +// ).initializer( +// CodeBlock.of( +// "RemoteJsStringLoader.Impl(supportedLocales = %N, fallbackFileUri = %N)", +// supportedLocalesPropertyName, +// fallbackFilePropertyName +// ) +// ).build() +// ) +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jsJvmCommon/ColorResourceUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jsJvmCommon/ColorResourceUtils.kt index bc4bffb69..7b55ccf6f 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jsJvmCommon/ColorResourceUtils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jsJvmCommon/ColorResourceUtils.kt @@ -1,16 +1,16 @@ -/* - * Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.jsJvmCommon - -import com.squareup.kotlinpoet.CodeBlock -import dev.icerock.gradle.generator.ColorNode - -fun createColorResourceInitializer(color: ColorNode): CodeBlock { - return if (color.isThemed()) { - "ColorResource(lightColor = Color(0x${color.lightColor}), darkColor = Color(0x${color.darkColor}))" - } else { - "ColorResource(lightColor = Color(0x${color.singleColor}), darkColor = Color(0x${color.singleColor}))" - }.let { CodeBlock.of(it) } -} +///* +// * Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.jsJvmCommon +// +//import com.squareup.kotlinpoet.CodeBlock +//import dev.icerock.gradle.generator.ColorNode +// +//fun createColorResourceInitializer(color: ColorNode): CodeBlock { +// return if (color.isThemed()) { +// "ColorResource(lightColor = Color(0x${color.lightColor}), darkColor = Color(0x${color.darkColor}))" +// } else { +// "ColorResource(lightColor = Color(0x${color.singleColor}), darkColor = Color(0x${color.singleColor}))" +// }.let { CodeBlock.of(it) } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jsJvmCommon/GenerateImageUtil.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jsJvmCommon/GenerateImageUtil.kt index 90b8a81ba..55d79ccfb 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jsJvmCommon/GenerateImageUtil.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jsJvmCommon/GenerateImageUtil.kt @@ -1,22 +1,22 @@ -/* - * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.jsJvmCommon - -import java.io.File - -fun generateHighestQualityImageResources( - resourcesGenerationDir: File, - keyFileMap: Map>, - imagesDirName: String -) { - val imagesDir = File(resourcesGenerationDir, imagesDirName).apply { mkdirs() } - - keyFileMap.forEach { (key, files) -> - val hqFile = files.maxByOrNull { - it.nameWithoutExtension.substringAfter("@").substringBefore("x").toDouble() - } ?: return - hqFile.copyTo(File(imagesDir, "$key.${hqFile.extension}")) - } -} +///* +// * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.jsJvmCommon +// +//import java.io.File +// +//fun generateHighestQualityImageResources( +// resourcesGenerationDir: File, +// keyFileMap: Map>, +// imagesDirName: String +//) { +// val imagesDir = File(resourcesGenerationDir, imagesDirName).apply { mkdirs() } +// +// keyFileMap.forEach { (key, files) -> +// val hqFile = files.maxByOrNull { +// it.nameWithoutExtension.substringAfter("@").substringBefore("x").toDouble() +// } ?: return +// hqFile.copyTo(File(imagesDir, "$key.${hqFile.extension}")) +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/ClassLoaderExtender.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/ClassLoaderExtender.kt index 1d50bc5f5..6fd49743d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/ClassLoaderExtender.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/ClassLoaderExtender.kt @@ -1,28 +1,28 @@ -/* - * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.jvm - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.PropertySpec -import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.ObjectBodyExtendable - -class ClassLoaderExtender(private val mrClassName: String) : ObjectBodyExtendable { - override fun extendObjectBodyAtStart(classBuilder: TypeSpec.Builder) { - classBuilder.addProperty( - PropertySpec.builder( - "resourcesClassLoader", - ClassName("java.lang", "ClassLoader"), - KModifier.OVERRIDE - ) - .initializer(CodeBlock.of("${mrClassName}::class.java.classLoader")) - .build() - ) - } - - override fun extendObjectBodyAtEnd(classBuilder: TypeSpec.Builder) = Unit -} +///* +// * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.jvm +// +//import com.squareup.kotlinpoet.ClassName +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import com.squareup.kotlinpoet.PropertySpec +//import com.squareup.kotlinpoet.TypeSpec +//import dev.icerock.gradle.generator.ObjectBodyExtendable +// +//class ClassLoaderExtender(private val mrClassName: String) : ObjectBodyExtendable { +// override fun extendObjectBodyAtStart(classBuilder: TypeSpec.Builder) { +// classBuilder.addProperty( +// PropertySpec.builder( +// "resourcesClassLoader", +// ClassName("java.lang", "ClassLoader"), +// KModifier.OVERRIDE +// ) +// .initializer(CodeBlock.of("${mrClassName}::class.java.classLoader")) +// .build() +// ) +// } +// +// override fun extendObjectBodyAtEnd(classBuilder: TypeSpec.Builder) = Unit +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmAssetsGenerator.kt index 8fc119d51..7764bc3b2 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmAssetsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmAssetsGenerator.kt @@ -1,57 +1,57 @@ -/* - * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.jvm - -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.AssetsGenerator -import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecDirectory -import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecFile -import dev.icerock.gradle.generator.MRGenerator -import dev.icerock.gradle.generator.ObjectBodyExtendable -import org.gradle.api.file.FileTree -import java.io.File - -class JvmAssetsGenerator( - ownResourcesFileTree: FileTree, - settings: MRGenerator.Settings -) : AssetsGenerator(ownResourcesFileTree), - ObjectBodyExtendable by ClassLoaderExtender(settings.className) { - - override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyInitializer(fileSpec: AssetSpecFile) = CodeBlock.of( - "AssetResource(resourcesClassLoader = resourcesClassLoader, originalPath = %S, path = %S)", - fileSpec.pathRelativeToBase, - File(FILES_DIR, fileSpec.pathRelativeToBase).path.replace('\\', '/') - ) - - override fun generateResources( - assetsGenerationDir: File, - resourcesGenerationDir: File, - files: List - ) { - val fileResDir = File(resourcesGenerationDir, FILES_DIR).apply { mkdirs() } - generateResourcesInner(files, fileResDir) - } - - private fun generateResourcesInner(files: List, fileResDir: File) { - files.forEach { assetSpec -> - when (assetSpec) { - is AssetSpecDirectory -> - generateResourcesInner(assetSpec.assets, fileResDir) - - is AssetSpecFile -> - assetSpec.file.copyTo(File(fileResDir, assetSpec.pathRelativeToBase)) - } - } - } - - companion object { - private const val FILES_DIR = "files" - } -} +///* +// * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.jvm +// +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import dev.icerock.gradle.generator.AssetsGenerator +//import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecDirectory +//import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecFile +//import dev.icerock.gradle.generator.MRGenerator +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import org.gradle.api.file.FileTree +//import java.io.File +// +//class JvmAssetsGenerator( +// ownResourcesFileTree: FileTree, +// settings: MRGenerator.Settings +//) : AssetsGenerator(ownResourcesFileTree), +// ObjectBodyExtendable by ClassLoaderExtender(settings.className) { +// +// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyInitializer(fileSpec: AssetSpecFile) = CodeBlock.of( +// "AssetResource(resourcesClassLoader = resourcesClassLoader, originalPath = %S, path = %S)", +// fileSpec.pathRelativeToBase, +// File(FILES_DIR, fileSpec.pathRelativeToBase).path.replace('\\', '/') +// ) +// +// override fun generateResources( +// assetsGenerationDir: File, +// resourcesGenerationDir: File, +// files: List +// ) { +// val fileResDir = File(resourcesGenerationDir, FILES_DIR).apply { mkdirs() } +// generateResourcesInner(files, fileResDir) +// } +// +// private fun generateResourcesInner(files: List, fileResDir: File) { +// files.forEach { assetSpec -> +// when (assetSpec) { +// is AssetSpecDirectory -> +// generateResourcesInner(assetSpec.assets, fileResDir) +// +// is AssetSpecFile -> +// assetSpec.file.copyTo(File(fileResDir, assetSpec.pathRelativeToBase)) +// } +// } +// } +// +// companion object { +// private const val FILES_DIR = "files" +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmColorsGenerator.kt index fc7ac6746..52c823d48 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmColorsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmColorsGenerator.kt @@ -1,31 +1,31 @@ -/* - * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.jvm - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.ColorNode -import dev.icerock.gradle.generator.ColorsGenerator -import dev.icerock.gradle.generator.ObjectBodyExtendable -import dev.icerock.gradle.generator.jsJvmCommon.createColorResourceInitializer -import org.gradle.api.file.FileTree - -class JvmColorsGenerator( - resourcesFileTree: FileTree, - mrClassName: String, -) : ColorsGenerator(resourcesFileTree), - ObjectBodyExtendable by ClassLoaderExtender(mrClassName) { - - override fun getImports() = listOf( - ClassName("dev.icerock.moko.graphics", "Color") - ) - - override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyInitializer(color: ColorNode): CodeBlock { - return createColorResourceInitializer(color) - } -} +///* +// * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.jvm +// +//import com.squareup.kotlinpoet.ClassName +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import dev.icerock.gradle.generator.ColorNode +//import dev.icerock.gradle.generator.ColorsGenerator +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import dev.icerock.gradle.generator.jsJvmCommon.createColorResourceInitializer +//import org.gradle.api.file.FileTree +// +//class JvmColorsGenerator( +// resourcesFileTree: FileTree, +// mrClassName: String, +//) : ColorsGenerator(resourcesFileTree), +// ObjectBodyExtendable by ClassLoaderExtender(mrClassName) { +// +// override fun getImports() = listOf( +// ClassName("dev.icerock.moko.graphics", "Color") +// ) +// +// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyInitializer(color: ColorNode): CodeBlock { +// return createColorResourceInitializer(color) +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFilesGenerator.kt index da546e728..157fb86fa 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFilesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFilesGenerator.kt @@ -1,43 +1,43 @@ -/* - * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.jvm - -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.FilesGenerator -import dev.icerock.gradle.generator.MRGenerator -import dev.icerock.gradle.generator.ObjectBodyExtendable -import org.gradle.api.file.FileTree -import java.io.File - -class JvmFilesGenerator( - ownInputFileTree: FileTree, - settings: MRGenerator.Settings, -) : FilesGenerator(ownInputFileTree), - ObjectBodyExtendable by ClassLoaderExtender(settings.className) { - - override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyInitializer(fileSpec: FileSpec) = CodeBlock.of( - "FileResource(resourcesClassLoader = resourcesClassLoader, filePath = %S)", - "$FILES_DIR/${fileSpec.file.name}" - ) - - override fun generateResources( - resourcesGenerationDir: File, - files: List, - ) { - val fileResDir = File(resourcesGenerationDir, FILES_DIR).apply { mkdirs() } - files.forEach { fileSpec -> - fileSpec.file.copyTo(File(fileResDir, fileSpec.file.name)) - } - } - - companion object { - private const val FILES_DIR = "files" - } -} +///* +// * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.jvm +// +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import dev.icerock.gradle.generator.FilesGenerator +//import dev.icerock.gradle.generator.MRGenerator +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import org.gradle.api.file.FileTree +//import java.io.File +// +//class JvmFilesGenerator( +// ownInputFileTree: FileTree, +// settings: MRGenerator.Settings, +//) : FilesGenerator(ownInputFileTree), +// ObjectBodyExtendable by ClassLoaderExtender(settings.className) { +// +// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyInitializer(fileSpec: FileSpec) = CodeBlock.of( +// "FileResource(resourcesClassLoader = resourcesClassLoader, filePath = %S)", +// "$FILES_DIR/${fileSpec.file.name}" +// ) +// +// override fun generateResources( +// resourcesGenerationDir: File, +// files: List, +// ) { +// val fileResDir = File(resourcesGenerationDir, FILES_DIR).apply { mkdirs() } +// files.forEach { fileSpec -> +// fileSpec.file.copyTo(File(fileResDir, fileSpec.file.name)) +// } +// } +// +// companion object { +// private const val FILES_DIR = "files" +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFontsGenerator.kt index 190d53720..0b96b4898 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFontsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFontsGenerator.kt @@ -1,40 +1,40 @@ -/* - * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.jvm - -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.FontsGenerator -import dev.icerock.gradle.generator.MRGenerator -import dev.icerock.gradle.generator.ObjectBodyExtendable -import org.gradle.api.file.FileTree -import java.io.File - -class JvmFontsGenerator( - ownInputFileTree: FileTree, - settings: MRGenerator.Settings -) : FontsGenerator(ownInputFileTree), - ObjectBodyExtendable by ClassLoaderExtender(settings.className) { - - override fun getClassModifiers() = arrayOf(KModifier.ACTUAL) - - override fun getPropertyModifiers() = arrayOf(KModifier.ACTUAL) - override fun getPropertyInitializer(fontFile: File): CodeBlock? = - CodeBlock.of( - "FontResource(resourcesClassLoader = resourcesClassLoader, filePath = %S)", - "$FONTS_DIR/${fontFile.name}" - ) - - override fun generateResources(resourcesGenerationDir: File, files: List) { - val fontsDir = File(resourcesGenerationDir, FONTS_DIR).apply { mkdirs() } - files.forEach { (_, file) -> - file.copyTo(File(fontsDir, file.name)) - } - } - - companion object { - private const val FONTS_DIR = "fonts" - } -} +///* +// * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.jvm +// +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import dev.icerock.gradle.generator.FontsGenerator +//import dev.icerock.gradle.generator.MRGenerator +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import org.gradle.api.file.FileTree +//import java.io.File +// +//class JvmFontsGenerator( +// ownInputFileTree: FileTree, +// settings: MRGenerator.Settings +//) : FontsGenerator(ownInputFileTree), +// ObjectBodyExtendable by ClassLoaderExtender(settings.className) { +// +// override fun getClassModifiers() = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyModifiers() = arrayOf(KModifier.ACTUAL) +// override fun getPropertyInitializer(fontFile: File): CodeBlock? = +// CodeBlock.of( +// "FontResource(resourcesClassLoader = resourcesClassLoader, filePath = %S)", +// "$FONTS_DIR/${fontFile.name}" +// ) +// +// override fun generateResources(resourcesGenerationDir: File, files: List) { +// val fontsDir = File(resourcesGenerationDir, FONTS_DIR).apply { mkdirs() } +// files.forEach { (_, file) -> +// file.copyTo(File(fontsDir, file.name)) +// } +// } +// +// companion object { +// private const val FONTS_DIR = "fonts" +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmImagesGenerator.kt index 93e1f60b1..c1cb4c84c 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmImagesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmImagesGenerator.kt @@ -1,43 +1,43 @@ -/* - * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.jvm - -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.ImagesGenerator -import dev.icerock.gradle.generator.MRGenerator -import dev.icerock.gradle.generator.ObjectBodyExtendable -import dev.icerock.gradle.generator.jsJvmCommon.generateHighestQualityImageResources -import org.gradle.api.file.FileTree -import java.io.File - -class JvmImagesGenerator( - ownInputFileTree: FileTree, - settings: MRGenerator.Settings -) : ImagesGenerator(ownInputFileTree), - ObjectBodyExtendable by ClassLoaderExtender(settings.className) { - - override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyInitializer(fileName: String) = - CodeBlock.of( - "ImageResource(resourcesClassLoader = resourcesClassLoader, filePath = %S)", - "$IMAGES_DIR/$fileName" - ) - - override fun generateResources( - assetsGenerationDir: File, - resourcesGenerationDir: File, - keyFileMap: Map> - ) { - generateHighestQualityImageResources(resourcesGenerationDir, keyFileMap, IMAGES_DIR) - } - - companion object { - private const val IMAGES_DIR = "images" - } -} +///* +// * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.jvm +// +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import dev.icerock.gradle.generator.ImagesGenerator +//import dev.icerock.gradle.generator.MRGenerator +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import dev.icerock.gradle.generator.jsJvmCommon.generateHighestQualityImageResources +//import org.gradle.api.file.FileTree +//import java.io.File +// +//class JvmImagesGenerator( +// ownInputFileTree: FileTree, +// settings: MRGenerator.Settings +//) : ImagesGenerator(ownInputFileTree), +// ObjectBodyExtendable by ClassLoaderExtender(settings.className) { +// +// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyInitializer(fileName: String) = +// CodeBlock.of( +// "ImageResource(resourcesClassLoader = resourcesClassLoader, filePath = %S)", +// "$IMAGES_DIR/$fileName" +// ) +// +// override fun generateResources( +// assetsGenerationDir: File, +// resourcesGenerationDir: File, +// keyFileMap: Map> +// ) { +// generateHighestQualityImageResources(resourcesGenerationDir, keyFileMap, IMAGES_DIR) +// } +// +// companion object { +// private const val IMAGES_DIR = "images" +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt index 0e187d02a..2958f8760 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt @@ -1,88 +1,88 @@ -/* - * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.jvm - -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.PropertySpec -import com.squareup.kotlinpoet.STRING -import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.TargetMRGenerator -import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask -import dev.icerock.gradle.utils.flatName -import org.gradle.api.Project -import org.gradle.jvm.tasks.Jar -import org.gradle.kotlin.dsl.withType -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -import java.io.File - -class JvmMRGenerator( - project: Project, - settings: Settings, - generators: List -) : TargetMRGenerator( - project = project, - settings = settings, - generators = generators -) { - private val flattenClassName: String = settings.packageName.flatName - - override val resourcesGenerationDir: File = settings.resourcesDir.asFile - - override fun processMRClass(mrClass: TypeSpec.Builder) { - super.processMRClass(mrClass) - - mrClass.addProperty( - PropertySpec.builder( - STRINGS_BUNDLE_PROPERTY_NAME, - STRING, - KModifier.PRIVATE - ).initializer( - CodeBlock.of( - "\"%L/%L\"", - LOCALIZATION_DIR, - "${flattenClassName}_$STRINGS_BUNDLE_NAME" - ) - ).build() - ) - - mrClass.addProperty( - PropertySpec.builder( - PLURALS_BUNDLE_PROPERTY_NAME, - STRING, - KModifier.PRIVATE - ).initializer( - CodeBlock.of( - "\"%L/%L\"", - LOCALIZATION_DIR, - "${flattenClassName}_$PLURALS_BUNDLE_NAME" - ) - ).build() - ) - } - - // TODO not used. remove after complete migration of task configuration to Plugin configuration time -// override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { -// project.tasks.withType().configureEach { -// it.dependsOn(generationTask) -// } -// project.tasks.withType().configureEach { -// it.dependsOn(generationTask) -// } -//// dependsOnProcessResources( -//// project = project, -//// sourceSet = sourceSet, -//// task = generationTask, -//// ) +///* +// * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.jvm +// +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import com.squareup.kotlinpoet.PropertySpec +//import com.squareup.kotlinpoet.STRING +//import com.squareup.kotlinpoet.TypeSpec +//import dev.icerock.gradle.generator.TargetMRGenerator +//import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask +//import dev.icerock.gradle.utils.flatName +//import org.gradle.api.Project +//import org.gradle.jvm.tasks.Jar +//import org.gradle.kotlin.dsl.withType +//import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +//import java.io.File +// +//class JvmMRGenerator( +// project: Project, +// settings: Settings, +// generators: List +//) : TargetMRGenerator( +// project = project, +// settings = settings, +// generators = generators +//) { +// private val flattenClassName: String = settings.packageName.flatName +// +// override val resourcesGenerationDir: File = settings.resourcesDir.asFile +// +// override fun processMRClass(mrClass: TypeSpec.Builder) { +// super.processMRClass(mrClass) +// +// mrClass.addProperty( +// PropertySpec.builder( +// STRINGS_BUNDLE_PROPERTY_NAME, +// STRING, +// KModifier.PRIVATE +// ).initializer( +// CodeBlock.of( +// "\"%L/%L\"", +// LOCALIZATION_DIR, +// "${flattenClassName}_$STRINGS_BUNDLE_NAME" +// ) +// ).build() +// ) +// +// mrClass.addProperty( +// PropertySpec.builder( +// PLURALS_BUNDLE_PROPERTY_NAME, +// STRING, +// KModifier.PRIVATE +// ).initializer( +// CodeBlock.of( +// "\"%L/%L\"", +// LOCALIZATION_DIR, +// "${flattenClassName}_$PLURALS_BUNDLE_NAME" +// ) +// ).build() +// ) // } - - companion object { - const val STRINGS_BUNDLE_PROPERTY_NAME = "stringsBundle" - const val PLURALS_BUNDLE_PROPERTY_NAME = "pluralsBundle" - const val STRINGS_BUNDLE_NAME = "mokoBundle" - const val PLURALS_BUNDLE_NAME = "mokoPluralsBundle" - const val LOCALIZATION_DIR = "localization" - } -} +// +// // TODO not used. remove after complete migration of task configuration to Plugin configuration time +//// override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { +//// project.tasks.withType().configureEach { +//// it.dependsOn(generationTask) +//// } +//// project.tasks.withType().configureEach { +//// it.dependsOn(generationTask) +//// } +////// dependsOnProcessResources( +////// project = project, +////// sourceSet = sourceSet, +////// task = generationTask, +////// ) +//// } +// +// companion object { +// const val STRINGS_BUNDLE_PROPERTY_NAME = "stringsBundle" +// const val PLURALS_BUNDLE_PROPERTY_NAME = "pluralsBundle" +// const val STRINGS_BUNDLE_NAME = "mokoBundle" +// const val PLURALS_BUNDLE_NAME = "mokoPluralsBundle" +// const val LOCALIZATION_DIR = "localization" +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmPluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmPluralsGenerator.kt index 884b07d78..07e953eef 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmPluralsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmPluralsGenerator.kt @@ -1,63 +1,63 @@ -/* - * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.jvm - -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.KeyType -import dev.icerock.gradle.generator.LanguageType -import dev.icerock.gradle.generator.MRGenerator -import dev.icerock.gradle.generator.ObjectBodyExtendable -import dev.icerock.gradle.generator.PluralMap -import dev.icerock.gradle.generator.PluralsGenerator -import dev.icerock.gradle.utils.flatName -import org.gradle.api.file.FileTree -import java.io.File - -class JvmPluralsGenerator( - ownResourcesFileTree: FileTree, - strictLineBreaks: Boolean, - settings: MRGenerator.Settings -) : PluralsGenerator(ownResourcesFileTree, strictLineBreaks), - ObjectBodyExtendable by ClassLoaderExtender(settings.className) { - - private val flattenClassPackage: String = settings.packageName.flatName - - override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyInitializer(key: String) = - CodeBlock.of( - "PluralsResource(resourcesClassLoader = resourcesClassLoader, bundleName = %L, key = %S)", - JvmMRGenerator.PLURALS_BUNDLE_PROPERTY_NAME, - key, - ) - - override fun generateResources( - resourcesGenerationDir: File, - language: LanguageType, - strings: Map - ) { - val fileDirName = - "${flattenClassPackage}_${JvmMRGenerator.PLURALS_BUNDLE_NAME}${language.jvmResourcesSuffix}" - - val localizationDir = - File(resourcesGenerationDir, JvmMRGenerator.LOCALIZATION_DIR).apply { mkdirs() } - val stringsFile = File(localizationDir, "$fileDirName.properties") - - val content = strings.map { (key, pluralMap) -> - val keysWithPlurals = pluralMap.map { (quantity, value) -> - "$key.$quantity" to value - } - - keysWithPlurals.joinToString("\n") { (key, value) -> - "$key = ${convertXmlStringToJvmLocalization(value)}" - } - }.joinToString("\n") - - stringsFile.writeText(content) - } -} +///* +// * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.jvm +// +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import dev.icerock.gradle.generator.KeyType +//import dev.icerock.gradle.generator.LanguageType +//import dev.icerock.gradle.generator.MRGenerator +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import dev.icerock.gradle.generator.PluralMap +//import dev.icerock.gradle.generator.PluralsGenerator +//import dev.icerock.gradle.utils.flatName +//import org.gradle.api.file.FileTree +//import java.io.File +// +//class JvmPluralsGenerator( +// ownResourcesFileTree: FileTree, +// strictLineBreaks: Boolean, +// settings: MRGenerator.Settings +//) : PluralsGenerator(ownResourcesFileTree, strictLineBreaks), +// ObjectBodyExtendable by ClassLoaderExtender(settings.className) { +// +// private val flattenClassPackage: String = settings.packageName.flatName +// +// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyInitializer(key: String) = +// CodeBlock.of( +// "PluralsResource(resourcesClassLoader = resourcesClassLoader, bundleName = %L, key = %S)", +// JvmMRGenerator.PLURALS_BUNDLE_PROPERTY_NAME, +// key, +// ) +// +// override fun generateResources( +// resourcesGenerationDir: File, +// language: LanguageType, +// strings: Map +// ) { +// val fileDirName = +// "${flattenClassPackage}_${JvmMRGenerator.PLURALS_BUNDLE_NAME}${language.jvmResourcesSuffix}" +// +// val localizationDir = +// File(resourcesGenerationDir, JvmMRGenerator.LOCALIZATION_DIR).apply { mkdirs() } +// val stringsFile = File(localizationDir, "$fileDirName.properties") +// +// val content = strings.map { (key, pluralMap) -> +// val keysWithPlurals = pluralMap.map { (quantity, value) -> +// "$key.$quantity" to value +// } +// +// keysWithPlurals.joinToString("\n") { (key, value) -> +// "$key = ${convertXmlStringToJvmLocalization(value)}" +// } +// }.joinToString("\n") +// +// stringsFile.writeText(content) +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringUtils.kt index d8d93d47f..c933900b8 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringUtils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringUtils.kt @@ -1,13 +1,13 @@ -/* - * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.jvm - -import org.apache.commons.text.StringEscapeUtils - -internal fun convertXmlStringToJvmLocalization(input: String): String { - val xmlDecoded = StringEscapeUtils.unescapeXml(input) - return xmlDecoded.replace("\n", "\\n") - .replace("\"", "\\\"") -} +///* +// * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.jvm +// +//import org.apache.commons.text.StringEscapeUtils +// +//internal fun convertXmlStringToJvmLocalization(input: String): String { +// val xmlDecoded = StringEscapeUtils.unescapeXml(input) +// return xmlDecoded.replace("\n", "\\n") +// .replace("\"", "\\\"") +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt index 2f0f89270..ce8253b7b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt @@ -1,59 +1,59 @@ -/* - * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.jvm - -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.KeyType -import dev.icerock.gradle.generator.LanguageType -import dev.icerock.gradle.generator.MRGenerator -import dev.icerock.gradle.generator.ObjectBodyExtendable -import dev.icerock.gradle.generator.StringsGenerator -import dev.icerock.gradle.utils.flatName -import org.gradle.api.file.FileTree -import java.io.File - -class JvmStringsGenerator( - resourcesFileTree: FileTree, - strictLineBreaks: Boolean, - settings: MRGenerator.Settings, -) : StringsGenerator( - resourcesFileTree = resourcesFileTree, - strictLineBreaks = strictLineBreaks -), ObjectBodyExtendable by ClassLoaderExtender(settings.className) { - - private val flattenClassPackage = settings.packageName.flatName - - override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - - override fun getPropertyInitializer(key: String) = - CodeBlock.of( - "StringResource(resourcesClassLoader = resourcesClassLoader, bundleName = %L, key = %S)", - JvmMRGenerator.STRINGS_BUNDLE_PROPERTY_NAME, - key - ) - - override fun generateResources( - resourcesGenerationDir: File, - language: LanguageType, - strings: Map, - ) { - val fileDirName = - "${flattenClassPackage}_${JvmMRGenerator.STRINGS_BUNDLE_NAME}${language.jvmResourcesSuffix}" - - val localizationDir = File(resourcesGenerationDir, JvmMRGenerator.LOCALIZATION_DIR).apply { - mkdirs() - } - val stringsFile = File(localizationDir, "$fileDirName.properties") - - val content = strings.map { (key, value) -> - "$key = ${convertXmlStringToJvmLocalization(value)}" - }.joinToString("\n") - - stringsFile.writeText(content) - } -} +///* +// * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.generator.jvm +// +//import com.squareup.kotlinpoet.CodeBlock +//import com.squareup.kotlinpoet.KModifier +//import dev.icerock.gradle.generator.KeyType +//import dev.icerock.gradle.generator.LanguageType +//import dev.icerock.gradle.generator.MRGenerator +//import dev.icerock.gradle.generator.ObjectBodyExtendable +//import dev.icerock.gradle.generator.StringsGenerator +//import dev.icerock.gradle.utils.flatName +//import org.gradle.api.file.FileTree +//import java.io.File +// +//class JvmStringsGenerator( +// resourcesFileTree: FileTree, +// strictLineBreaks: Boolean, +// settings: MRGenerator.Settings, +//) : StringsGenerator( +// resourcesFileTree = resourcesFileTree, +// strictLineBreaks = strictLineBreaks +//), ObjectBodyExtendable by ClassLoaderExtender(settings.className) { +// +// private val flattenClassPackage = settings.packageName.flatName +// +// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) +// +// override fun getPropertyInitializer(key: String) = +// CodeBlock.of( +// "StringResource(resourcesClassLoader = resourcesClassLoader, bundleName = %L, key = %S)", +// JvmMRGenerator.STRINGS_BUNDLE_PROPERTY_NAME, +// key +// ) +// +// override fun generateResources( +// resourcesGenerationDir: File, +// language: LanguageType, +// strings: Map, +// ) { +// val fileDirName = +// "${flattenClassPackage}_${JvmMRGenerator.STRINGS_BUNDLE_NAME}${language.jvmResourcesSuffix}" +// +// val localizationDir = File(resourcesGenerationDir, JvmMRGenerator.LOCALIZATION_DIR).apply { +// mkdirs() +// } +// val stringsFile = File(localizationDir, "$fileDirName.properties") +// +// val content = strings.map { (key, value) -> +// "$key = ${convertXmlStringToJvmLocalization(value)}" +// }.joinToString("\n") +// +// stringsFile.writeText(content) +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt index f42fe4f31..40f9868a9 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt @@ -1,37 +1,37 @@ -package dev.icerock.gradle.metadata - -import dev.icerock.gradle.metadata.model.GeneratedObject -import kotlinx.serialization.builtins.ListSerializer -import kotlinx.serialization.json.Json -import org.gradle.api.file.FileTree -import java.io.File - -object Metadata { - fun createOutputMetadata( - outputMetadataFile: File, - generatedObjects: List, - ) { - if (generatedObjects.isEmpty()) return - - outputMetadataFile.createNewFile() - - val generatedJson: String = Json.encodeToString( - serializer = ListSerializer(GeneratedObject.serializer()), - value = generatedObjects - ) - - outputMetadataFile.writeText(generatedJson) - } - - fun readInputMetadata( - inputMetadataFiles: FileTree, - ): List { - return inputMetadataFiles.filter { it.isFile }.flatMap { inputFile -> - val inputString: String = inputFile.readText() - Json.decodeFromString( - deserializer = ListSerializer(GeneratedObject.serializer()), - string = inputString - ) - } - } -} +//package dev.icerock.gradle.metadata +// +//import dev.icerock.gradle.metadata.model.GeneratedObject +//import kotlinx.serialization.builtins.ListSerializer +//import kotlinx.serialization.json.Json +//import org.gradle.api.file.FileTree +//import java.io.File +// +//object Metadata { +// fun createOutputMetadata( +// outputMetadataFile: File, +// generatedObjects: List, +// ) { +// if (generatedObjects.isEmpty()) return +// +// outputMetadataFile.createNewFile() +// +// val generatedJson: String = Json.encodeToString( +// serializer = ListSerializer(GeneratedObject.serializer()), +// value = generatedObjects +// ) +// +// outputMetadataFile.writeText(generatedJson) +// } +// +// fun readInputMetadata( +// inputMetadataFiles: FileTree, +// ): List { +// return inputMetadataFiles.filter { it.isFile }.flatMap { inputFile -> +// val inputString: String = inputFile.readText() +// Json.decodeFromString( +// deserializer = ListSerializer(GeneratedObject.serializer()), +// string = inputString +// ) +// } +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt index 7d60c6a5e..5d23b862e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt @@ -1,71 +1,71 @@ -package dev.icerock.gradle.metadata - -import dev.icerock.gradle.metadata.model.GeneratedObject -import dev.icerock.gradle.metadata.model.GeneratorType - -fun MutableList.addActual(actualObject: GeneratedObject) { - val expect: GeneratedObject? = firstOrNull { - it.name == actualObject.name - && it.generatorType == actualObject.generatorType - && it.type == actualObject.type - } - - if (expect != null) { - remove(expect) - } - - add(actualObject) -} - -fun List.getExpectInterfaces(): List { - return filter { it.isExpectInterface } -} - -fun List.getActualInterfaces(generatorType: GeneratorType): List { - return filter { - (it.isActualInterface || it.isTargetInterface) && it.generatorType == generatorType - } -} - -fun List.getGeneratorInterfaces(generatorType: GeneratorType): List { - return filter { - it.isInterface && it.generatorType == generatorType - } -} - -fun List.isEmptyMetadata(): Boolean { - if (this.isEmpty()) return true - - return this.none { it.isObject } -} - -fun List.isNotEmptyMetadata(): Boolean { - return !this.isEmptyMetadata() -} - -fun List.hasActualInterfacesOrExpectObject(): Boolean { - return this.any { - it.isActualInterface || it.isExpectObject - } -} - -fun List.objectsWithProperties( - targetObject: GeneratedObject, -): List { - val objectsWithProperties = mutableListOf() - - this.forEach { genObject -> - if (genObject.generatorType == targetObject.generatorType && genObject.properties.isNotEmpty()) { - objectsWithProperties.add(genObject) - } - - genObject.objects.forEach { innerObject -> - if (innerObject.generatorType == targetObject.generatorType && innerObject.properties.isNotEmpty()) { - objectsWithProperties.add(innerObject) - } - } - } - - return objectsWithProperties -} - +//package dev.icerock.gradle.metadata +// +//import dev.icerock.gradle.metadata.model.GeneratedObject +//import dev.icerock.gradle.metadata.model.GeneratorType +// +//fun MutableList.addActual(actualObject: GeneratedObject) { +// val expect: GeneratedObject? = firstOrNull { +// it.name == actualObject.name +// && it.generatorType == actualObject.generatorType +// && it.type == actualObject.type +// } +// +// if (expect != null) { +// remove(expect) +// } +// +// add(actualObject) +//} +// +//fun List.getExpectInterfaces(): List { +// return filter { it.isExpectInterface } +//} +// +//fun List.getActualInterfaces(generatorType: GeneratorType): List { +// return filter { +// (it.isActualInterface || it.isTargetInterface) && it.generatorType == generatorType +// } +//} +// +//fun List.getGeneratorInterfaces(generatorType: GeneratorType): List { +// return filter { +// it.isInterface && it.generatorType == generatorType +// } +//} +// +//fun List.isEmptyMetadata(): Boolean { +// if (this.isEmpty()) return true +// +// return this.none { it.isObject } +//} +// +//fun List.isNotEmptyMetadata(): Boolean { +// return !this.isEmptyMetadata() +//} +// +//fun List.hasActualInterfacesOrExpectObject(): Boolean { +// return this.any { +// it.isActualInterface || it.isExpectObject +// } +//} +// +//fun List.objectsWithProperties( +// targetObject: GeneratedObject, +//): List { +// val objectsWithProperties = mutableListOf() +// +// this.forEach { genObject -> +// if (genObject.generatorType == targetObject.generatorType && genObject.properties.isNotEmpty()) { +// objectsWithProperties.add(genObject) +// } +// +// genObject.objects.forEach { innerObject -> +// if (innerObject.generatorType == targetObject.generatorType && innerObject.properties.isNotEmpty()) { +// objectsWithProperties.add(innerObject) +// } +// } +// } +// +// return objectsWithProperties +//} +// diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Utils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Utils.kt index 9a80f7326..16b25c2e4 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Utils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Utils.kt @@ -1,18 +1,18 @@ -package dev.icerock.gradle.metadata - -import dev.icerock.gradle.generator.MRGenerator.Settings -import dev.icerock.gradle.metadata.model.GeneratedObject -import dev.icerock.gradle.metadata.model.GeneratorType -import dev.icerock.gradle.utils.capitalize - -internal fun getInterfaceName(sourceSetName: String, generatorType: GeneratorType): String { - return sourceSetName.capitalize() + generatorType.name.capitalize() -} - -internal fun resourcesIsEmpty( - inputMetadata: List, - settings: Settings, -): Boolean { - return inputMetadata.isEmptyMetadata() - && settings.ownResourcesFileTree.files.none { it.isFile } -} \ No newline at end of file +//package dev.icerock.gradle.metadata +// +//import dev.icerock.gradle.generator.MRGenerator.Settings +//import dev.icerock.gradle.metadata.model.GeneratedObject +//import dev.icerock.gradle.metadata.model.GeneratorType +//import dev.icerock.gradle.utils.capitalize +// +//internal fun getInterfaceName(sourceSetName: String, generatorType: GeneratorType): String { +// return sourceSetName.capitalize() + generatorType.name.capitalize() +//} +// +//internal fun resourcesIsEmpty( +// inputMetadata: List, +// settings: Settings, +//): Boolean { +// return inputMetadata.isEmptyMetadata() +// && settings.ownResourcesFileTree.files.none { it.isFile } +//} \ No newline at end of file diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/AssetsMetadata.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/AssetsMetadata.kt index 6edcc55f8..c4068726e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/AssetsMetadata.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/AssetsMetadata.kt @@ -1,19 +1,19 @@ -package dev.icerock.gradle.metadata.model - -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -data class AssetsMetadata( - @SerialName("type") - val type: AssetsType, - val name: String, - val path: String?, - val files: List?, - val assets: List?, -) - -enum class AssetsType { - File, - Directory -} +//package dev.icerock.gradle.metadata.model +// +//import kotlinx.serialization.SerialName +//import kotlinx.serialization.Serializable +// +//@Serializable +//data class AssetsMetadata( +// @SerialName("type") +// val type: AssetsType, +// val name: String, +// val path: String?, +// val files: List?, +// val assets: List?, +//) +// +//enum class AssetsType { +// File, +// Directory +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObject.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObject.kt index 35b05d9d9..2ab7791e6 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObject.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObject.kt @@ -1,49 +1,49 @@ -package dev.icerock.gradle.metadata.model - -import dev.icerock.gradle.metadata.model.GeneratedObjectModifier.Actual -import dev.icerock.gradle.metadata.model.GeneratedObjectModifier.Expect -import dev.icerock.gradle.metadata.model.GeneratedObjectModifier.None -import dev.icerock.gradle.metadata.model.GeneratedObjectType.Interface -import dev.icerock.gradle.metadata.model.GeneratedObjectType.Object -import kotlinx.serialization.Serializable - -@Serializable -data class GeneratedObject( - val generatorType: GeneratorType, - val modifier: GeneratedObjectModifier, - val type: GeneratedObjectType, - val name: String, - val interfaces: List = emptyList(), - val properties: List = emptyList(), - val objects: List = emptyList() -) { - val isExpect: Boolean - get() = modifier == Expect - - val isActual: Boolean - get() = modifier == Actual - - val isObject: Boolean - get() = type == Object - - val isInterface: Boolean - get() = type == Interface - - val isExpectObject - get() = isObject && isExpect - - val isActualObject: Boolean - get() = isObject && isActual - - val isExpectInterface - get() = isInterface && isExpect - - val isActualInterface: Boolean - get() = isInterface && isActual - - val isTargetObject: Boolean - get() = isObject && modifier == None - - val isTargetInterface: Boolean - get() = isInterface && modifier == None -} +//package dev.icerock.gradle.metadata.model +// +//import dev.icerock.gradle.metadata.model.GeneratedObjectModifier.Actual +//import dev.icerock.gradle.metadata.model.GeneratedObjectModifier.Expect +//import dev.icerock.gradle.metadata.model.GeneratedObjectModifier.None +//import dev.icerock.gradle.metadata.model.GeneratedObjectType.Interface +//import dev.icerock.gradle.metadata.model.GeneratedObjectType.Object +//import kotlinx.serialization.Serializable +// +//@Serializable +//data class GeneratedObject( +// val generatorType: GeneratorType, +// val modifier: GeneratedObjectModifier, +// val type: GeneratedObjectType, +// val name: String, +// val interfaces: List = emptyList(), +// val properties: List = emptyList(), +// val objects: List = emptyList() +//) { +// val isExpect: Boolean +// get() = modifier == Expect +// +// val isActual: Boolean +// get() = modifier == Actual +// +// val isObject: Boolean +// get() = type == Object +// +// val isInterface: Boolean +// get() = type == Interface +// +// val isExpectObject +// get() = isObject && isExpect +// +// val isActualObject: Boolean +// get() = isObject && isActual +// +// val isExpectInterface +// get() = isInterface && isExpect +// +// val isActualInterface: Boolean +// get() = isInterface && isActual +// +// val isTargetObject: Boolean +// get() = isObject && modifier == None +// +// val isTargetInterface: Boolean +// get() = isInterface && modifier == None +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObjectModifier.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObjectModifier.kt index 382ba4e77..68b6500c0 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObjectModifier.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObjectModifier.kt @@ -1,8 +1,8 @@ -package dev.icerock.gradle.metadata.model - -enum class GeneratedObjectModifier { - Expect, - Actual, - Override, - None; -} +//package dev.icerock.gradle.metadata.model +// +//enum class GeneratedObjectModifier { +// Expect, +// Actual, +// Override, +// None; +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObjectType.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObjectType.kt index 14ea45a10..65ea36fff 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObjectType.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObjectType.kt @@ -1,14 +1,14 @@ -package dev.icerock.gradle.metadata.model - -enum class GeneratedObjectType(val value: String) { - Object("object"), - Interface("interface"); - - companion object { - private val VALUES = values() - fun getByValue(value: String): GeneratedObjectType { - return VALUES.firstOrNull { it.value.lowercase() == value.lowercase() } - ?: throw Exception("Invalid object type") - } - } -} +//package dev.icerock.gradle.metadata.model +// +//enum class GeneratedObjectType(val value: String) { +// Object("object"), +// Interface("interface"); +// +// companion object { +// private val VALUES = values() +// fun getByValue(value: String): GeneratedObjectType { +// return VALUES.firstOrNull { it.value.lowercase() == value.lowercase() } +// ?: throw Exception("Invalid object type") +// } +// } +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedProperty.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedProperty.kt index 25d28bd47..3ba94bb72 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedProperty.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedProperty.kt @@ -1,15 +1,15 @@ -package dev.icerock.gradle.metadata.model - -import dev.icerock.gradle.metadata.model.GeneratedObjectModifier.Actual -import kotlinx.serialization.Serializable -import kotlinx.serialization.json.JsonElement - -@Serializable -data class GeneratedProperty( - val modifier: GeneratedObjectModifier, - val name: String, - val data: JsonElement // Can contain data with dependencies from generator type -){ - val isActualProperty: Boolean - get() = modifier == Actual -} +//package dev.icerock.gradle.metadata.model +// +//import dev.icerock.gradle.metadata.model.GeneratedObjectModifier.Actual +//import kotlinx.serialization.Serializable +//import kotlinx.serialization.json.JsonElement +// +//@Serializable +//data class GeneratedProperty( +// val modifier: GeneratedObjectModifier, +// val name: String, +// val data: JsonElement // Can contain data with dependencies from generator type +//){ +// val isActualProperty: Boolean +// get() = modifier == Actual +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratorType.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratorType.kt index 788df5962..e97f99a27 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratorType.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratorType.kt @@ -1,12 +1,12 @@ -package dev.icerock.gradle.metadata.model - -enum class GeneratorType { - Strings, - Plurals, - Assets, - Colors, - Images, - Files, - Fonts, - None -} +//package dev.icerock.gradle.metadata.model +// +//enum class GeneratorType { +// Strings, +// Plurals, +// Assets, +// Colors, +// Images, +// Files, +// Fonts, +// None +//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/GenerationResult.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/GenerationResult.kt new file mode 100644 index 000000000..2816f5bec --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/GenerationResult.kt @@ -0,0 +1,13 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.rework + +import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.rework.metadata.container.ContainerMetadata + +data class GenerationResult( + val typeSpec: TypeSpec, + val metadata: ContainerMetadata +) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/PlatformGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/PlatformGenerator.kt new file mode 100644 index 000000000..b7339aabc --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/PlatformGenerator.kt @@ -0,0 +1,16 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.rework + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import dev.icerock.gradle.rework.metadata.resource.ResourceMetadata + +interface PlatformGenerator { + fun imports(): List + + fun generateInitializer(metadata: T): CodeBlock + fun generateResourceFiles(data: List) +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourceGenerator.kt new file mode 100644 index 000000000..dd4853ff4 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourceGenerator.kt @@ -0,0 +1,15 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.rework + +import com.squareup.kotlinpoet.PropertySpec +import dev.icerock.gradle.rework.metadata.resource.ResourceMetadata +import java.io.File + +interface ResourceGenerator { + fun generateMetadata(files: Set): List + + fun generateProperty(metadata: T): PropertySpec.Builder +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourceTypeGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourceTypeGenerator.kt new file mode 100644 index 000000000..626c4ca25 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourceTypeGenerator.kt @@ -0,0 +1,183 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.rework + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +import com.squareup.kotlinpoet.PropertySpec +import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.rework.metadata.container.ActualInterfaceMetadata +import dev.icerock.gradle.rework.metadata.container.ExpectInterfaceMetadata +import dev.icerock.gradle.rework.metadata.container.ObjectMetadata +import dev.icerock.gradle.rework.metadata.container.ResourceType +import dev.icerock.gradle.rework.metadata.resource.ResourceMetadata +import dev.icerock.gradle.utils.capitalize +import org.gradle.api.tasks.util.PatternFilterable + +class ResourceTypeGenerator( + private val generationPackage: String, + private val resourceClass: ClassName, + private val resourceType: ResourceType, + private val visibilityModifier: KModifier, + private val generator: ResourceGenerator, + private val platformGenerator: PlatformGenerator, + private val filter: PatternFilterable.() -> Unit +) { + fun generateMetadata(files: ResourcesFiles): List { + return generator.generateMetadata(files.matching(filter).ownSourceSet.fileTree.files) + } + + fun generateExpectInterfaces(files: ResourcesFiles): List { + // we should generate expect interface only if we have resources of our type upper + return files.matching(filter).upperSourceSets.mapNotNull { sourceSetResources -> + if (sourceSetResources.fileTree.isEmpty) return@mapNotNull null + + val interfaceName: String = sourceSetResources.sourceSetName.capitalize() + + resourceType.name.lowercase().capitalize() + + GenerationResult( + typeSpec = TypeSpec.interfaceBuilder(interfaceName) + .addModifiers(visibilityModifier) + .addModifiers(KModifier.EXPECT) + .build(), + metadata = ExpectInterfaceMetadata( + name = interfaceName, + sourceSet = sourceSetResources.sourceSetName, + resourceType = resourceType + ) + ) + } + } + + fun generateExpectObject( + metadata: List, + interfaces: List + ): GenerationResult? { + @Suppress("UNCHECKED_CAST") + val typeMetadata: List = metadata.mapNotNull { it as? T } + val typeInterfaces: List = interfaces + .filter { it.resourceType == resourceType } + + // if we not have any resources of our type at all - not generate object + if (typeMetadata.isEmpty() && typeInterfaces.isEmpty()) return null + + val objectName: String = resourceType.name.lowercase() + + val objectBuilder: TypeSpec.Builder = TypeSpec + .objectBuilder(objectName) + .addModifiers(visibilityModifier) + // implement ResourceType<**Resource> for extensions + .addSuperinterface(resourceContainerClass.parameterizedBy(resourceClass)) + // implement interfaces for generated expect object + .addSuperinterfaces(typeInterfaces.map { + ClassName(packageName = generationPackage, it.name) + }) + // add all properties of available resources + .addProperties(typeMetadata.map { generator.generateProperty(it).build() }) + + return GenerationResult( + typeSpec = objectBuilder.build(), + metadata = ObjectMetadata( + name = objectName, + resourceType = resourceType, + interfaces = typeInterfaces.map { it.name }, + resources = typeMetadata + ) + ) + } + + fun generateActualInterface( + interfaces: List, + metadata: List, + sourceSet: String + ): GenerationResult? { + @Suppress("UNCHECKED_CAST") + val typeMetadata: List = metadata.mapNotNull { it as? T } + val typeInterface: ExpectInterfaceMetadata = interfaces + .filter { it.resourceType == resourceType } + .singleOrNull { it.sourceSet == sourceSet } + ?: return null + + return GenerationResult( + typeSpec = TypeSpec.interfaceBuilder(typeInterface.name) + .addModifiers(visibilityModifier) + .addModifiers(KModifier.ACTUAL) + // add all properties of available resources + .addProperties(typeMetadata.map { generator.generateProperty(it).build() }) + .build(), + metadata = ActualInterfaceMetadata( + name = typeInterface.name, + resources = typeMetadata + ) + ) + } + + fun generateActualObject( + objects: List, + interfaces: List + ): GenerationResult? { + val typeObject: ObjectMetadata = objects + .singleOrNull { it.resourceType == resourceType } ?: return null + val typeInterfaces: List = interfaces + .filter { typeObject.interfaces.contains(it.name) } + + val interfaceResources: List = typeInterfaces.flatMap { it.resources } + + val objectBuilder: TypeSpec.Builder = TypeSpec + .objectBuilder(typeObject.name) + .addModifiers(visibilityModifier) + .addModifiers(KModifier.ACTUAL) + // implement ResourceType<**Resource> for extensions + .addSuperinterface(resourceContainerClass.parameterizedBy(resourceClass)) + // implement interfaces for generated expect object + .addSuperinterfaces(typeInterfaces.map { + ClassName(packageName = generationPackage, it.name) + }) + // add all properties of object + .addProperties(typeObject.resources.map(::createActualProperty)) + // add all properties of interfaces + .addProperties(interfaceResources.map(::createOverrideProperty)) + + return GenerationResult( + typeSpec = objectBuilder.build(), + metadata = ObjectMetadata( + name = typeObject.name, + resourceType = resourceType, + interfaces = typeInterfaces.map { it.name }, + resources = typeObject.resources + interfaceResources + ) + ) + } + + fun generateFiles(resources: List) { + @Suppress("UNCHECKED_CAST") + val typeMetadata: List = resources.mapNotNull { it as? T } + + platformGenerator.generateResourceFiles(typeMetadata) + } + + private fun createActualProperty(resource: ResourceMetadata): PropertySpec { + return createProperty(resource, KModifier.ACTUAL) + } + + private fun createOverrideProperty(resource: ResourceMetadata): PropertySpec { + return createProperty(resource, KModifier.OVERRIDE) + } + + private fun createProperty(resource: ResourceMetadata, modifier: KModifier): PropertySpec { + @Suppress("UNCHECKED_CAST") + resource as T + + return generator.generateProperty(resource) + .addModifiers(modifier) + .initializer(platformGenerator.generateInitializer(resource)) + .build() + } + + private companion object { + val resourceContainerClass = ClassName("dev.icerock.moko.resources", "ResourceContainer") + } +} \ No newline at end of file diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourcesFiles.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourcesFiles.kt new file mode 100644 index 000000000..c95c95ac8 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourcesFiles.kt @@ -0,0 +1,25 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.rework + +import org.gradle.api.file.FileTree +import org.gradle.api.tasks.util.PatternFilterable + +data class ResourcesFiles( + val ownSourceSet: SourceSetResources, + val upperSourceSets: List +) { + fun matching(filter: PatternFilterable.() -> Unit): ResourcesFiles { + return ResourcesFiles( + ownSourceSet = ownSourceSet.copy(fileTree = ownSourceSet.fileTree.matching(filter)), + upperSourceSets = upperSourceSets.map { it.copy(fileTree = it.fileTree.matching(filter)) } + ) + } + + data class SourceSetResources( + val sourceSetName: String, + val fileTree: FileTree + ) +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourcesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourcesGenerator.kt new file mode 100644 index 000000000..098fa7e2d --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourcesGenerator.kt @@ -0,0 +1,193 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.rework + +import com.squareup.kotlinpoet.FileSpec +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.rework.metadata.container.ActualInterfaceMetadata +import dev.icerock.gradle.rework.metadata.container.ContainerMetadata +import dev.icerock.gradle.rework.metadata.container.ExpectInterfaceMetadata +import dev.icerock.gradle.rework.metadata.container.ObjectMetadata +import dev.icerock.gradle.rework.metadata.resource.ResourceMetadata +import java.io.File + +class ResourcesGenerator( + private val typesGenerators: List>, + private val resourcesPackageName: String, + private val resourcesClassName: String, + private val sourceSetName: String, + private val visibilityModifier: KModifier, + private val sourcesGenerationDir: File +) { + fun generateTargetKotlin( + files: ResourcesFiles, + inputMetadata: List + ): List { + val ownMetadata: List = typesGenerators + .flatMap { it.generateMetadata(files) } + + // no resources - no file + if (inputMetadata.isEmpty() && ownMetadata.isEmpty()) return emptyList() + + val fileSpec: FileSpec.Builder = FileSpec.builder( + packageName = resourcesPackageName, + fileName = resourcesClassName + ) + + val outputMetadata: MutableList = mutableListOf() + + // for each input metadata we should generate actual + + // at first we should filter already generated expect-actual interfaces + val expectInterfaces: List = inputMetadata + .mapNotNull { it as? ExpectInterfaceMetadata } + .filter { expectInterface -> + inputMetadata.mapNotNull { it as? ActualInterfaceMetadata } + .none { expectInterface.name == it.name } + } + val alreadyActualInterfaces: List = inputMetadata + .mapNotNull { it as? ActualInterfaceMetadata } + .map { it.name } + + // then we should generate actual interfaces with resources at our level + val actualInterfaces: List = typesGenerators.mapNotNull { typeGenerator -> + typeGenerator.generateActualInterface( + interfaces = expectInterfaces.filterNot { alreadyActualInterfaces.contains(it.name) }, + metadata = ownMetadata, + sourceSet = sourceSetName + ) + } + + actualInterfaces.forEach { result -> + fileSpec.addType(result.typeSpec) + outputMetadata.add(result.metadata) + } + + // then we should generate dummy actual interfaces + val dummyInterfaces: List = expectInterfaces.map { it.name } + .minus(actualInterfaces.map { (it.metadata as ActualInterfaceMetadata).name }.toSet()) + .map { dummyInterfaceName -> + GenerationResult( + typeSpec = TypeSpec.interfaceBuilder(dummyInterfaceName) + .addModifiers(visibilityModifier) + .addModifiers(KModifier.ACTUAL) + .build(), + metadata = ActualInterfaceMetadata( + name = dummyInterfaceName, + resources = emptyList() + ) + ) + } + + dummyInterfaces + .forEach { result -> + fileSpec.addType(result.typeSpec) + outputMetadata.add(result.metadata) + } + + // then we should generate actual object + val objects: List = typesGenerators.mapNotNull { typeGenerator -> + typeGenerator.generateActualObject( + objects = inputMetadata.mapNotNull { it as? ObjectMetadata }, + interfaces = inputMetadata.mapNotNull { it as? ActualInterfaceMetadata } + + (actualInterfaces + dummyInterfaces).map { it.metadata as ActualInterfaceMetadata } + ) + } + + val objectSpec: TypeSpec.Builder = + TypeSpec.objectBuilder(resourcesClassName) // default: object MR + .addModifiers(KModifier.ACTUAL) + .addModifiers(visibilityModifier) + // TODO here should be added extra properties for platforms + + objects.forEach { result -> + objectSpec.addType(result.typeSpec) + outputMetadata.add(result.metadata) + } + + fileSpec.addType(objectSpec.build()) + + // write file + fileSpec.build().writeTo(sourcesGenerationDir) + + return outputMetadata + } + + fun generateCommonKotlin( + files: ResourcesFiles, + inputMetadata: List + ): List { + val ownMetadata: List = typesGenerators + .flatMap { it.generateMetadata(files) } + + // we not have any resources on this level. + // so we should not generate expect and actuals too + if (ownMetadata.isEmpty()) return emptyList() + + // here we see metadata on our level + val fileSpec: FileSpec.Builder = FileSpec.builder( + packageName = resourcesPackageName, + fileName = resourcesClassName + ) + + val outputMetadata: MutableList = mutableListOf() + + if (inputMetadata.isEmpty()) { + // at lower level we not see any resources. so we should generate expects + // read upper files for interface + val interfaces: List = typesGenerators + .flatMap { it.generateExpectInterfaces(files) } + // read own metadata for object + val objects: List = typesGenerators.mapNotNull { typeGenerator -> + typeGenerator.generateExpectObject( + metadata = ownMetadata, + interfaces = interfaces.mapNotNull { it.metadata as? ExpectInterfaceMetadata } + ) + } + + interfaces.forEach { result -> + fileSpec.addType(result.typeSpec) + outputMetadata.add(result.metadata) + } + + val objectSpec: TypeSpec.Builder = + TypeSpec.objectBuilder(resourcesClassName) // default: object MR + .addModifiers(KModifier.EXPECT) + .addModifiers(visibilityModifier) + + objects.forEach { result -> + objectSpec.addType(result.typeSpec) + outputMetadata.add(result.metadata) + } + + fileSpec.addType(objectSpec.build()) + } else { + // at lower level already exist expect. we should generate our actual interfaces + val interfaces: List = typesGenerators.mapNotNull { typeGenerator -> + typeGenerator.generateActualInterface( + interfaces = inputMetadata.mapNotNull { it as? ExpectInterfaceMetadata }, + metadata = ownMetadata, + sourceSet = sourceSetName + ) + } + + interfaces.forEach { result -> + fileSpec.addType(result.typeSpec) + outputMetadata.add(result.metadata) + } + } + + // write file + fileSpec.build().writeTo(sourcesGenerationDir) + + return outputMetadata + } + + fun generateResources(metadata: List) { + val resources: List = metadata.flatMap { it.resources } + typesGenerators.forEach { it.generateFiles(resources) } + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/metadata/container/ContainerMetadata.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/metadata/container/ContainerMetadata.kt new file mode 100644 index 000000000..e7d4ca263 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/metadata/container/ContainerMetadata.kt @@ -0,0 +1,40 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.rework.metadata.container + +import dev.icerock.gradle.rework.metadata.resource.ResourceMetadata +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +sealed interface ContainerMetadata + +@Serializable +@SerialName("expect-interface") +data class ExpectInterfaceMetadata( + val name: String, + val resourceType: ResourceType, + val sourceSet: String +) : ContainerMetadata + +@Serializable +@SerialName("actual-interface") +data class ActualInterfaceMetadata( + val name: String, + val resources: List +) : ContainerMetadata + +@Serializable +@SerialName("object") +data class ObjectMetadata( + val name: String, + val resourceType: ResourceType, + val interfaces: List, + val resources: List +) : ContainerMetadata + +enum class ResourceType { + STRINGS, PLURALS, IMAGES, FONTS, FILES, COLORS, ASSETS +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/metadata/resource/ResourceMetadata.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/metadata/resource/ResourceMetadata.kt new file mode 100644 index 000000000..0337fd4e2 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/metadata/resource/ResourceMetadata.kt @@ -0,0 +1,114 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +@file:UseSerializers(FileSerializer::class) + +package dev.icerock.gradle.rework.metadata.resource + +import dev.icerock.gradle.rework.serialization.FileSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.UseSerializers +import java.io.File + +@Serializable +sealed interface ResourceMetadata { + val key: String +} + +@Serializable +data class StringMetadata( + override val key: String, + val values: List +) : ResourceMetadata { + @Serializable + data class LocaleItem( + val locale: String, + val value: String + ) +} + +@Serializable +data class PluralMetadata( + override val key: String, + val values: List +) : ResourceMetadata { + @Serializable + data class LocaleItem( + val locale: String, + val values: List + ) + + @Serializable + data class PluralItem( + val quantity: Quantity, + val value: String + ) { + enum class Quantity { + ZERO, ONE, TWO, FEW, MANY, OTHER; + } + } +} + +@Serializable +data class ImageMetadata( + override val key: String, + val values: List +) : ResourceMetadata { + @Serializable + data class ImageQualityItem( + val quality: Int, + val filePath: File + ) +} + +@Serializable +data class FontMetadata( + override val key: String, + val values: List +) : ResourceMetadata { + @Serializable + data class FontFamilyItem( + val family: String, + val filePath: File + ) +} + +@Serializable +data class FileMetadata( + override val key: String, + val filePath: File +) : ResourceMetadata + +@Serializable +data class ColorMetadata( + override val key: String, + val value: ColorItem +) : ResourceMetadata { + @Serializable + sealed interface ColorItem { + @Serializable + data class Single(val color: Color) : ColorItem + + @Serializable + data class Themed(val light: Color, val dark: Color) : ColorItem + + @Serializable + data class Reference(val key: String) : ColorItem + } + + @Serializable + data class Color( + val red: Int, + val green: Int, + val blue: Int, + val alpha: Int + ) +} + +@Serializable +data class AssetsMetadata( + override val key: String, + val relativePath: File, + val filePath: File +) : ResourceMetadata diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/serialization/FileSerializer.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/serialization/FileSerializer.kt new file mode 100644 index 000000000..225eb78d6 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/serialization/FileSerializer.kt @@ -0,0 +1,28 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.rework.serialization + +import kotlinx.serialization.KSerializer +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder +import java.io.File + +object FileSerializer : KSerializer { + override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor( + serialName = "FileSerializer", + kind = PrimitiveKind.STRING + ) + + override fun deserialize(decoder: Decoder): File { + return File(decoder.decodeString()) + } + + override fun serialize(encoder: Encoder, value: File) { + encoder.encodeString(value.path) + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/AndroidStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/AndroidStringResourceGenerator.kt new file mode 100644 index 000000000..9a007455e --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/AndroidStringResourceGenerator.kt @@ -0,0 +1,74 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.rework.string + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import dev.icerock.gradle.generator.LanguageType +import dev.icerock.gradle.rework.PlatformGenerator +import dev.icerock.gradle.rework.metadata.resource.StringMetadata +import org.apache.commons.text.StringEscapeUtils +import java.io.File + +class AndroidStringResourceGenerator( + private val androidRClassPackage: String, + private val resourcesGenerationDir: File +) : PlatformGenerator { + override fun imports(): List = listOf( + ClassName(androidRClassPackage, "R") + ) + + override fun generateInitializer(metadata: StringMetadata): CodeBlock { + return CodeBlock.of("StringResource(R.string.%L)", processKey(metadata.key)) + } + + override fun generateResourceFiles(data: List) { + data.processLanguages().forEach { (lang, strings) -> + generateLanguageFile( + language = LanguageType.fromLanguage(lang), + strings = strings + ) + } + } + + private fun generateLanguageFile(language: LanguageType, strings: Map) { + val valuesDir = File(resourcesGenerationDir, language.androidResourcesDir) + val stringsFile = File(valuesDir, "multiplatform_strings.xml") + valuesDir.mkdirs() + + val header = + """ + + + """.trimIndent() + + val content = strings.map { (key, value) -> + val processedKey = processKey(key) + val processedValue = convertXmlStringToAndroidLocalization(value) + "\t$processedValue" + }.joinToString("\n") + + val footer = + """ + + """.trimIndent() + + stringsFile.writeText(header + "\n") + stringsFile.appendText(content) + stringsFile.appendText("\n" + footer) + } + + // TODO should we do that? + private fun processKey(key: String): String { + return key.replace(".", "_") + } + + // TODO should we do that? + private fun convertXmlStringToAndroidLocalization(input: String): String { + val xmlDecoded = StringEscapeUtils.unescapeXml(input) + return xmlDecoded.replace("\n", "\\n") + .replace("\"", "\\\"").let { StringEscapeUtils.escapeXml11(it) } + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/AppleStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/AppleStringResourceGenerator.kt new file mode 100644 index 000000000..f69ead25f --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/AppleStringResourceGenerator.kt @@ -0,0 +1,65 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.rework.string + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import dev.icerock.gradle.generator.LanguageType +import dev.icerock.gradle.rework.PlatformGenerator +import dev.icerock.gradle.rework.metadata.resource.StringMetadata +import org.apache.commons.text.StringEscapeUtils +import java.io.File + +class AppleStringResourceGenerator( + private val baseLocalizationRegion: String, + private val resourcesGenerationDir: File +) : PlatformGenerator { + override fun imports(): List = emptyList() + + override fun generateInitializer(metadata: StringMetadata): CodeBlock { + return CodeBlock.of( + "StringResource(resourceId = %S, bundle = %L)", + metadata.key, + // TODO change to const + "nsBundle" + ) + } + + override fun generateResourceFiles(data: List) { + data.processLanguages().forEach { (lang, strings) -> + generateLanguageFile( + language = LanguageType.fromLanguage(lang), + strings = strings + ) + } + } + + private fun generateLanguageFile(language: LanguageType, strings: Map) { + val resDir = File(resourcesGenerationDir, language.appleResourcesDir) + val localizableFile = File(resDir, "Localizable.strings") + resDir.mkdirs() + + val content = strings.mapValues { (_, value) -> + convertXmlStringToAppleLocalization(value) + }.map { (key, value) -> + "\"$key\" = \"$value\";" + }.joinToString("\n") + localizableFile.writeText(content) + + if (language == LanguageType.Base) { + val regionDir = File(resourcesGenerationDir, "$baseLocalizationRegion.lproj") + regionDir.mkdirs() + val regionFile = File(regionDir, "Localizable.strings") + regionFile.writeText(content) + } + } + + // TODO should we do that? + private fun convertXmlStringToAppleLocalization(input: String): String { + return StringEscapeUtils.unescapeXml(input) + .replace("\n", "\\n") + .replace("\"", "\\\"") + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JsStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JsStringResourceGenerator.kt new file mode 100644 index 000000000..398b56e4e --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JsStringResourceGenerator.kt @@ -0,0 +1,72 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.rework.string + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import dev.icerock.gradle.generator.LanguageType +import dev.icerock.gradle.generator.js.convertToMessageFormat +import dev.icerock.gradle.rework.PlatformGenerator +import dev.icerock.gradle.rework.metadata.resource.StringMetadata +import dev.icerock.gradle.utils.flatName +import kotlinx.serialization.json.buildJsonObject +import kotlinx.serialization.json.put +import java.io.File + +// TODO migrate dev.icerock.gradle.generator.js.JsStringsGenerator.beforeGenerateResources +// add fun values to MR.strings object +// add property stringsFallbackFileUrl to MR.strings object +// add property supportedLocales to MR.strings object +class JsStringResourceGenerator( + resourcesPackageName: String, + private val resourcesGenerationDir: File +) : PlatformGenerator { + private val flattenClassPackage: String = resourcesPackageName.flatName + + override fun imports(): List = emptyList() + + // TODO we should add stringsLoader to MR + override fun generateInitializer(metadata: StringMetadata): CodeBlock { + return CodeBlock.of( + "StringResource(key = %S, loader = %L)", + metadata.key, + "stringsLoader" + ) + } + + override fun generateResourceFiles(data: List) { + data.processLanguages().forEach { (lang, strings) -> + generateLanguageFile( + language = LanguageType.fromLanguage(lang), + strings = strings + ) + } + } + + private fun generateLanguageFile(language: LanguageType, strings: Map) { + val fileDirName = + "${flattenClassPackage}_${STRINGS_JSON_NAME}${language.jsResourcesSuffix}" + + val localizationDir = File(resourcesGenerationDir, LOCALIZATION_DIR) + + localizationDir.mkdirs() + + val stringsFile = File(localizationDir, "$fileDirName.json") + + val content: String = buildJsonObject { + strings.forEach { (key, value) -> + put(key, value.convertToMessageFormat()) + } + }.toString() + + stringsFile.writeText(content) + } + + // TODO share const + private companion object { + const val STRINGS_JSON_NAME = "stringsJson" + const val LOCALIZATION_DIR = "localization" + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JvmStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JvmStringResourceGenerator.kt new file mode 100644 index 000000000..a2f41d36b --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JvmStringResourceGenerator.kt @@ -0,0 +1,73 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.rework.string + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import dev.icerock.gradle.generator.LanguageType +import dev.icerock.gradle.rework.PlatformGenerator +import dev.icerock.gradle.rework.metadata.resource.StringMetadata +import dev.icerock.gradle.utils.flatName +import org.apache.commons.text.StringEscapeUtils +import java.io.File + +class JvmStringResourceGenerator( + resourcesPackageName: String, + private val resourcesGenerationDir: File +) : PlatformGenerator { + private val flattenClassPackage: String = resourcesPackageName.flatName + + override fun imports(): List = emptyList() + + // TODO we should add resourcesClassLoader to MR object + // TODO we should add stringsBundle to MR object + override fun generateInitializer(metadata: StringMetadata): CodeBlock { + return CodeBlock.of( + "StringResource(resourcesClassLoader = %L, bundleName = %L, key = %S)", + "resourcesClassLoader", + STRINGS_BUNDLE_PROPERTY_NAME, + metadata.key + ) + } + + override fun generateResourceFiles(data: List) { + data.processLanguages().forEach { (lang, strings) -> + generateLanguageFile( + language = LanguageType.fromLanguage(lang), + strings = strings + ) + } + } + + private fun generateLanguageFile(language: LanguageType, strings: Map) { + val fileDirName = + "${flattenClassPackage}_${STRINGS_BUNDLE_NAME}${language.jvmResourcesSuffix}" + + val localizationDir = File(resourcesGenerationDir, LOCALIZATION_DIR) + localizationDir.mkdirs() + + val stringsFile = File(localizationDir, "$fileDirName.properties") + + val content: String = strings.map { (key, value) -> + "$key = ${convertXmlStringToJvmLocalization(value)}" + }.joinToString("\n") + + stringsFile.writeText(content) + } + + // TODO should we do that? + private fun convertXmlStringToJvmLocalization(input: String): String { + return StringEscapeUtils.unescapeXml(input) + .replace("\n", "\\n") + .replace("\"", "\\\"") + } + + // TODO share const + private companion object { + const val STRINGS_BUNDLE_PROPERTY_NAME = "stringsBundle" + const val STRINGS_BUNDLE_NAME = "mokoBundle" + const val LOCALIZATION_DIR = "localization" + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/NOPStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/NOPStringResourceGenerator.kt new file mode 100644 index 000000000..fc7e41bd3 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/NOPStringResourceGenerator.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.rework.string + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import dev.icerock.gradle.rework.PlatformGenerator +import dev.icerock.gradle.rework.metadata.resource.StringMetadata + +class NOPStringResourceGenerator : PlatformGenerator { + override fun imports(): List { + TODO("Not yet implemented") + } + + override fun generateResourceFiles(data: List) { + TODO("Not yet implemented") + } + + override fun generateInitializer(metadata: StringMetadata): CodeBlock { + TODO("Not yet implemented") + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/StringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/StringResourceGenerator.kt new file mode 100644 index 000000000..99c172e0b --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/StringResourceGenerator.kt @@ -0,0 +1,90 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.rework.string + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.PropertySpec +import dev.icerock.gradle.generator.EqualStringKeysException +import dev.icerock.gradle.generator.LanguageType +import dev.icerock.gradle.rework.ResourceGenerator +import dev.icerock.gradle.rework.metadata.resource.StringMetadata +import dev.icerock.gradle.utils.removeLineWraps +import org.w3c.dom.Document +import org.w3c.dom.Node +import org.w3c.dom.NodeList +import java.io.File +import javax.xml.parsers.DocumentBuilder +import javax.xml.parsers.DocumentBuilderFactory + +private typealias KeyType = String + +class StringResourceGenerator( + private val strictLineBreaks: Boolean +) : ResourceGenerator { + + override fun generateMetadata(files: Set): List { + val keyLangText: Map> = files.flatMap { file -> + val language: LanguageType = LanguageType.fromFileName(file.parentFile.name) + val strings: Map = loadLanguageStrings(file) + strings.map { (key: KeyType, text: String) -> + key to (language to text) + } + }.groupBy( + keySelector = { it.first }, + valueTransform = { it.second } + ).mapValues { it.value.toMap() } + + return keyLangText.map { (key, langText) -> + StringMetadata( + key = key, + values = langText.map { (lang, value) -> + StringMetadata.LocaleItem( + locale = lang.language(), + value = value + ) + } + ) + } + } + + private fun loadLanguageStrings(stringsFile: File): Map { + val dbFactory: DocumentBuilderFactory = DocumentBuilderFactory.newInstance() + val dBuilder: DocumentBuilder = dbFactory.newDocumentBuilder() + val doc: Document = dBuilder.parse(stringsFile) + + val stringNodes: NodeList = doc.getElementsByTagName("string") + + val resultMap: MutableMap = mutableMapOf() + + for (i: Int in 0 until stringNodes.length) { + val stringNode: Node = stringNodes.item(i) + val name: String = stringNode.attributes.getNamedItem("name").textContent + val value: String = stringNode.textContent + + resultMap[name] = if (strictLineBreaks) value else value.removeLineWraps() + } + + // check keys == values for apple locale change logic + // TODO maybe remove this logic? + val incorrectKeys: List = resultMap + .filter { it.key == it.value } + .keys + .toList() + + if (incorrectKeys.isNotEmpty()) { + throw EqualStringKeysException(incorrectKeys) + } + + return resultMap + } + + override fun generateProperty(metadata: StringMetadata): PropertySpec.Builder { + return PropertySpec.builder(metadata.key, className) + } + + companion object { + val className = ClassName("dev.icerock.moko.resources", "StringResource") + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/Utils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/Utils.kt new file mode 100644 index 000000000..1b56a04ef --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/Utils.kt @@ -0,0 +1,18 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.rework.string + +import dev.icerock.gradle.rework.metadata.resource.StringMetadata + +internal fun List.processLanguages(): Map> { + return this.flatMap { metadata -> + metadata.values.map { localeItem -> + localeItem.locale to (metadata.key to localeItem.value) + } + }.groupBy( + keySelector = { it.first }, + valueTransform = { it.second } + ).mapValues { it.value.toMap() } +} 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 ace54d2c1..298a87b7f 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 @@ -6,26 +6,32 @@ package dev.icerock.gradle.tasks import dev.icerock.gradle.MRVisibility import dev.icerock.gradle.configuration.getAndroidRClassPackage -import dev.icerock.gradle.generator.AssetsGenerator -import dev.icerock.gradle.generator.ColorsGenerator -import dev.icerock.gradle.generator.FilesGenerator -import dev.icerock.gradle.generator.FontsGenerator -import dev.icerock.gradle.generator.ImagesGenerator -import dev.icerock.gradle.generator.MRGenerator -import dev.icerock.gradle.generator.PluralsGenerator -import dev.icerock.gradle.generator.ResourceGeneratorFeature -import dev.icerock.gradle.generator.StringsGenerator -import dev.icerock.gradle.generator.android.AndroidMRGenerator -import dev.icerock.gradle.generator.apple.AppleMRGenerator -import dev.icerock.gradle.generator.common.CommonMRGenerator -import dev.icerock.gradle.generator.js.JsMRGenerator -import dev.icerock.gradle.generator.jvm.JvmMRGenerator +import dev.icerock.gradle.rework.PlatformGenerator +import dev.icerock.gradle.rework.ResourceTypeGenerator +import dev.icerock.gradle.rework.ResourcesFiles +import dev.icerock.gradle.rework.ResourcesGenerator +import dev.icerock.gradle.rework.metadata.container.ContainerMetadata +import dev.icerock.gradle.rework.metadata.container.ObjectMetadata +import dev.icerock.gradle.rework.metadata.container.ResourceType +import dev.icerock.gradle.rework.metadata.resource.StringMetadata +import dev.icerock.gradle.rework.string.AndroidStringResourceGenerator +import dev.icerock.gradle.rework.string.AppleStringResourceGenerator +import dev.icerock.gradle.rework.string.JsStringResourceGenerator +import dev.icerock.gradle.rework.string.JvmStringResourceGenerator +import dev.icerock.gradle.rework.string.NOPStringResourceGenerator +import dev.icerock.gradle.rework.string.StringResourceGenerator +import dev.icerock.gradle.toModifier import dev.icerock.gradle.utils.isStrictLineBreaks +import kotlinx.serialization.InternalSerializationApi +import kotlinx.serialization.KSerializer +import kotlinx.serialization.builtins.ListSerializer +import kotlinx.serialization.json.Json import org.gradle.api.DefaultTask -import org.gradle.api.GradleException import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.DirectoryProperty +import org.gradle.api.file.FileCollection import org.gradle.api.file.RegularFileProperty +import org.gradle.api.provider.MapProperty import org.gradle.api.provider.Property import org.gradle.api.tasks.CacheableTask import org.gradle.api.tasks.Classpath @@ -39,6 +45,7 @@ import org.gradle.api.tasks.PathSensitivity import org.gradle.api.tasks.TaskAction import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import org.jetbrains.kotlin.konan.target.KonanTarget +import java.io.File @CacheableTask abstract class GenerateMultiplatformResourcesTask : DefaultTask() { @@ -50,13 +57,8 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { @get:Classpath abstract val ownResources: ConfigurableFileCollection - @get:InputFiles - @get:Classpath - abstract val lowerResources: ConfigurableFileCollection - - @get:InputFiles - @get:Classpath - abstract val upperResources: ConfigurableFileCollection + @get:Input + abstract val upperSourceSets: MapProperty @get:Optional @get:Input @@ -103,151 +105,169 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { @get:OutputDirectory abstract val outputAssetsDir: DirectoryProperty + private val kotlinPlatformType: KotlinPlatformType + get() = KotlinPlatformType.valueOf(platformType.get()) + + private val kotlinKonanTarget: KonanTarget + get() { + val name: String = konanTarget.get() + return KonanTarget.predefinedTargets[name] ?: error("can't find $name in KonanTarget") + } + init { group = "moko-resources" } + @OptIn(InternalSerializationApi::class) @TaskAction fun generate() { - val settings: MRGenerator.Settings = createGeneratorSettings() - val features: List> = createGeneratorFeatures(settings) - val mrGenerator: MRGenerator = resolveGenerator(settings, features) - mrGenerator.generate() - } - - private fun resolveGenerator( - settings: MRGenerator.Settings, - generators: List>, - ): MRGenerator { - return when (KotlinPlatformType.valueOf(platformType.get())) { - KotlinPlatformType.common -> createCommonGenerator(settings, generators) - KotlinPlatformType.jvm -> createJvmGenerator(settings, generators) - KotlinPlatformType.js -> createJsGenerator(settings, generators) - KotlinPlatformType.androidJvm -> createAndroidJvmGenerator(settings, generators) - KotlinPlatformType.native -> createNativeGenerator(settings, generators) - KotlinPlatformType.wasm -> throw GradleException("moko-resources not support wasm target now") + val json = Json { + prettyPrint = true } - } - - private fun createGeneratorSettings(): MRGenerator.Settings { - return MRGenerator.Settings( - inputMetadataFiles = inputMetadataFiles.asFileTree, - outputMetadataFile = outputMetadataFile.asFile.get(), - packageName = resourcesPackageName.get(), - className = resourcesClassName.get(), - assetsDir = outputAssetsDir.get(), - sourceSetDir = outputSourcesDir.get(), - resourcesDir = outputResourcesDir.get(), - ownResourcesFileTree = ownResources.asFileTree, - lowerResourcesFileTree = lowerResources.asFileTree, - upperResourcesFileTree = upperResources.asFileTree, - isStrictLineBreaks = project.isStrictLineBreaks, - visibility = resourcesVisibility.get(), - androidRClassPackage = project.getAndroidRClassPackage(), - iosLocalizationRegion = iosBaseLocalizationRegion, + val generator: ResourcesGenerator = createGenerator() + + val files = ResourcesFiles( + ownSourceSet = ResourcesFiles.SourceSetResources( + sourceSetName = sourceSetName.get(), + fileTree = ownResources.asFileTree + ), + upperSourceSets = upperSourceSets.get().map { item -> + ResourcesFiles.SourceSetResources( + sourceSetName = item.key, + fileTree = item.value.asFileTree + ) + } ) - } + val serializer: KSerializer> = + ListSerializer(ContainerMetadata.serializer()) + val inputMetadata: List = inputMetadataFiles.files.flatMap { file -> + json.decodeFromString(serializer, file.readText()) + } - private fun createGeneratorFeatures( - settings: MRGenerator.Settings, - ): List> { - return listOf( - StringsGenerator.Feature(settings), - PluralsGenerator.Feature(settings), - ColorsGenerator.Feature(settings), - ImagesGenerator.Feature(settings, logger), - FontsGenerator.Feature(settings), - FilesGenerator.Feature(settings), - AssetsGenerator.Feature(settings) - ) - } + val outputMetadata: List = + if (kotlinPlatformType == KotlinPlatformType.common) { + generator.generateCommonKotlin(files, inputMetadata) + } else { + generator.generateTargetKotlin(files, inputMetadata).also { containers -> + generator.generateResources(containers.mapNotNull { it as? ObjectMetadata }) + } + } - private fun createCommonGenerator( - settings: MRGenerator.Settings, - generators: List>, - ): CommonMRGenerator { - return CommonMRGenerator( - project = project, - sourceSetName = sourceSetName.get(), - settings = settings, - generators = generators.map { it.createCommonGenerator() } - ) + outputMetadataFile.get().asFile.writeText(json.encodeToString(serializer, outputMetadata)) } - private fun createAndroidJvmGenerator( - settings: MRGenerator.Settings, - generators: List>, - ): AndroidMRGenerator { - return AndroidMRGenerator( - project = project, - settings = settings, - generators = generators.map { it.createAndroidGenerator() } + private fun createGenerator(): ResourcesGenerator { + return ResourcesGenerator( + typesGenerators = listOf( + createStringGenerator() + ), + resourcesPackageName = resourcesPackageName.get(), + resourcesClassName = resourcesClassName.get(), + sourceSetName = sourceSetName.get(), + visibilityModifier = resourcesVisibility.get().toModifier(), + sourcesGenerationDir = outputSourcesDir.get().asFile ) } - private fun createJvmGenerator( - settings: MRGenerator.Settings, - generators: List>, - ): JvmMRGenerator { - return JvmMRGenerator( - project = project, - settings = settings, - generators = generators.map { it.createJvmGenerator() } + private fun createStringGenerator(): ResourceTypeGenerator { + return ResourceTypeGenerator( + generationPackage = resourcesPackageName.get(), + resourceClass = StringResourceGenerator.className, + resourceType = ResourceType.STRINGS, + visibilityModifier = resourcesVisibility.get().toModifier(), + generator = StringResourceGenerator( + strictLineBreaks = project.isStrictLineBreaks + ), + platformGenerator = createPlatformStringGenerator(), + filter = { include("**/strings*.xml") } ) } - private fun createJsGenerator( - settings: MRGenerator.Settings, - generators: List>, - ): JsMRGenerator { - return JsMRGenerator( - project = project, - settings = settings, - generators = generators.map { it.createJsGenerator() } + private fun getAndroidR(): String = project.getAndroidRClassPackage().get() + + private fun createPlatformStringGenerator(): PlatformGenerator { + val resourcesGenerationDir: File = outputResourcesDir.get().asFile + return createByPlatform( + createCommon = { NOPStringResourceGenerator() }, + createAndroid = { + AndroidStringResourceGenerator( + androidRClassPackage = getAndroidR(), + resourcesGenerationDir = resourcesGenerationDir + ) + }, + createApple = { + AppleStringResourceGenerator( + baseLocalizationRegion = iosBaseLocalizationRegion.get(), + resourcesGenerationDir = resourcesGenerationDir + ) + }, + createJvm = { + JvmStringResourceGenerator( + resourcesPackageName = resourcesPackageName.get(), + resourcesGenerationDir = resourcesGenerationDir + ) + }, + createJs = { + JsStringResourceGenerator( + resourcesPackageName = resourcesPackageName.get(), + resourcesGenerationDir = resourcesGenerationDir + ) + } ) } - private fun createNativeGenerator( - settings: MRGenerator.Settings, - generators: List>, - ): MRGenerator { - val konanTargetName: String = konanTarget.get() - val konanTarget: KonanTarget = KonanTarget.predefinedTargets[konanTargetName] - ?: error("can't find $konanTargetName in KonanTarget") - - return when (konanTarget) { - KonanTarget.IOS_ARM32, - KonanTarget.IOS_ARM64, - KonanTarget.IOS_SIMULATOR_ARM64, - KonanTarget.IOS_X64, - - KonanTarget.MACOS_ARM64, - KonanTarget.MACOS_X64, - - KonanTarget.TVOS_ARM64, - KonanTarget.TVOS_SIMULATOR_ARM64, - KonanTarget.TVOS_X64, - - KonanTarget.WATCHOS_ARM32, - KonanTarget.WATCHOS_ARM64, - KonanTarget.WATCHOS_DEVICE_ARM64, - KonanTarget.WATCHOS_SIMULATOR_ARM64, - KonanTarget.WATCHOS_X64, - KonanTarget.WATCHOS_X86, - -> createAppleGenerator(settings, generators) - - else -> error("$konanTarget is not supported by moko-resources now!") + private fun createByPlatform( + createCommon: () -> T, + createAndroid: () -> T, + createApple: () -> T, + createJvm: () -> T, + createJs: () -> T, + ): T { + return when (kotlinPlatformType) { + KotlinPlatformType.common -> createCommon() + KotlinPlatformType.jvm -> createJvm() + KotlinPlatformType.androidJvm -> createAndroid() + KotlinPlatformType.js -> createJs() + KotlinPlatformType.native -> when (kotlinKonanTarget) { + KonanTarget.IOS_ARM32, + KonanTarget.IOS_ARM64, + KonanTarget.IOS_SIMULATOR_ARM64, + KonanTarget.IOS_X64, + + KonanTarget.MACOS_ARM64, + KonanTarget.MACOS_X64, + + KonanTarget.TVOS_ARM64, + KonanTarget.TVOS_SIMULATOR_ARM64, + KonanTarget.TVOS_X64, + + KonanTarget.WATCHOS_ARM32, + KonanTarget.WATCHOS_ARM64, + KonanTarget.WATCHOS_DEVICE_ARM64, + KonanTarget.WATCHOS_SIMULATOR_ARM64, + KonanTarget.WATCHOS_X64, + KonanTarget.WATCHOS_X86 -> createApple() + + KonanTarget.ANDROID_ARM32, + KonanTarget.ANDROID_ARM64, + KonanTarget.ANDROID_X64, + KonanTarget.ANDROID_X86, + + KonanTarget.LINUX_ARM32_HFP, + KonanTarget.LINUX_ARM64, + KonanTarget.LINUX_MIPS32, + KonanTarget.LINUX_MIPSEL32, + KonanTarget.LINUX_X64, + + KonanTarget.MINGW_X64, + KonanTarget.MINGW_X86, + + KonanTarget.WASM32, + + is KonanTarget.ZEPHYR -> error("$kotlinKonanTarget not supported by moko-resources now") + } + + KotlinPlatformType.wasm -> error("$kotlinPlatformType not supported by moko-resources now") } } - - private fun createAppleGenerator( - settings: MRGenerator.Settings, - generators: List>, - ): AppleMRGenerator { - return AppleMRGenerator( - project = project, - settings = settings, - generators = generators.map { it.createAppleGenerator() }, - ) - } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProcessResourcesUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProcessResourcesUtils.kt index 03a22f9eb..4a20cc4e1 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProcessResourcesUtils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProcessResourcesUtils.kt @@ -1,28 +1,28 @@ -/* - * Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.utils - -import dev.icerock.gradle.generator.MRGenerator -import org.gradle.api.Project -import org.gradle.api.Task -import org.gradle.api.provider.Provider -import org.gradle.kotlin.dsl.withType -import org.gradle.language.jvm.tasks.ProcessResources - -fun dependsOnProcessResources( - project: Project, - @Suppress("UNUSED_PARAMETER") sourceSet: Provider, - task: Task, -) { - val sourceSet: MRGenerator.SourceSet = sourceSet.get() - project.logger.warn("source set name is ${sourceSet.name}") - - project.tasks - .matching { it.name == sourceSet.name.removeSuffix("Main") + "ProcessResources" } - .withType() - .configureEach { processResourcesTask -> - processResourcesTask.dependsOn(task) - } -} +///* +// * Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. +// */ +// +//package dev.icerock.gradle.utils +// +//import dev.icerock.gradle.generator.MRGenerator +//import org.gradle.api.Project +//import org.gradle.api.Task +//import org.gradle.api.provider.Provider +//import org.gradle.kotlin.dsl.withType +//import org.gradle.language.jvm.tasks.ProcessResources +// +//fun dependsOnProcessResources( +// project: Project, +// @Suppress("UNUSED_PARAMETER") sourceSet: Provider, +// task: Task, +//) { +// val sourceSet: MRGenerator.SourceSet = sourceSet.get() +// project.logger.warn("source set name is ${sourceSet.name}") +// +// project.tasks +// .matching { it.name == sourceSet.name.removeSuffix("Main") + "ProcessResources" } +// .withType() +// .configureEach { processResourcesTask -> +// processResourcesTask.dependsOn(task) +// } +//} diff --git a/resources-generator/src/test/kotlin/dev/icerock/gradle/rework/metadata/container/ContainerMetadataTest.kt b/resources-generator/src/test/kotlin/dev/icerock/gradle/rework/metadata/container/ContainerMetadataTest.kt new file mode 100644 index 000000000..162ad7bcf --- /dev/null +++ b/resources-generator/src/test/kotlin/dev/icerock/gradle/rework/metadata/container/ContainerMetadataTest.kt @@ -0,0 +1,40 @@ +package dev.icerock.gradle.rework.metadata.container + +import dev.icerock.gradle.rework.metadata.resource.StringMetadata +import kotlinx.serialization.builtins.ListSerializer +import kotlinx.serialization.json.Json +import org.junit.Test + +class ContainerMetadataTest { + + @Test + fun testSerialization() { + val expectInter = ExpectInterfaceMetadata( + name = "test2", + resourceType = ResourceType.STRINGS, + sourceSet = "testing" + ) + val obj = ObjectMetadata( + name = "test", + resourceType = ResourceType.STRINGS, + resources = listOf( + StringMetadata( + key = "hello", + values = listOf( + StringMetadata.LocaleItem(locale = "ru", value = "ru"), + StringMetadata.LocaleItem(locale = "en", value = "en") + ) + ) + ), + interfaces = listOf("test1", "test2") + ) + val serializer = ListSerializer(ContainerMetadata.serializer()) + + val json: String = Json.encodeToString(serializer, listOf(expectInter, obj)) + println(json) + + val list: List = Json.decodeFromString(serializer, json) + + println(list) + } +} diff --git a/samples/compose-resources-gallery/.run/iosApp.run.xml b/samples/compose-resources-gallery/.run/iosApp.run.xml deleted file mode 100644 index 778f6afeb..000000000 --- a/samples/compose-resources-gallery/.run/iosApp.run.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/samples/compose-resources-gallery/gradle.properties b/samples/compose-resources-gallery/gradle.properties index 3d755dbae..71545320b 100644 --- a/samples/compose-resources-gallery/gradle.properties +++ b/samples/compose-resources-gallery/gradle.properties @@ -8,12 +8,11 @@ android.useAndroidX=true org.jetbrains.compose.experimental.jscanvas.enabled=true org.jetbrains.compose.experimental.macos.enabled=true org.jetbrains.compose.experimental.uikit.enabled=true -kotlin.native.cacheKind=none kotlin.native.useEmbeddableCompilerJar=true kotlin.mpp.androidSourceSetLayoutVersion=2 kotlin.mpp.androidGradlePluginCompatibility.nowarn=true # Enable kotlin/native experimental memory model kotlin.native.binary.memoryModel=experimental -kotlin.version=1.9.10 +kotlin.version=1.9.21 agp.version=8.0.2 -compose.version=1.5.1 +compose.version=1.5.11 diff --git a/samples/compose-resources-gallery/gradle/wrapper/gradle-wrapper.jar b/samples/compose-resources-gallery/gradle/wrapper/gradle-wrapper.jar index c1962a79e29d3e0ab67b14947c167a862655af9b..7f93135c49b765f8051ef9d0a6055ff8e46073d8 100644 GIT binary patch delta 37652 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 delta 36122 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 Ac-xW1# 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 Q>rd#Eb%7 diff --git a/samples/compose-resources-gallery/gradle/wrapper/gradle-wrapper.properties b/samples/compose-resources-gallery/gradle/wrapper/gradle-wrapper.properties index 37aef8d3f..3fa8f862f 100644 --- a/samples/compose-resources-gallery/gradle/wrapper/gradle-wrapper.properties +++ b/samples/compose-resources-gallery/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/samples/compose-resources-gallery/gradlew b/samples/compose-resources-gallery/gradlew index aeb74cbb4..1aa94a426 100755 --- a/samples/compose-resources-gallery/gradlew +++ b/samples/compose-resources-gallery/gradlew @@ -83,7 +83,8 @@ done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -130,10 +131,13 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. @@ -141,7 +145,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -149,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -198,11 +202,11 @@ fi # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ diff --git a/samples/compose-resources-gallery/macosApp/build.gradle.kts b/samples/compose-resources-gallery/macosApp/build.gradle.kts index 804eaea02..261b24ed6 100644 --- a/samples/compose-resources-gallery/macosApp/build.gradle.kts +++ b/samples/compose-resources-gallery/macosApp/build.gradle.kts @@ -108,39 +108,39 @@ tasks.withType() // TODO move to moko-resources gradle plugin // copy .bundle from .kexe to .app -tasks.withType() - .configureEach { - val packTask: org.jetbrains.compose.experimental.uikit.tasks.ExperimentalPackComposeApplicationForXCodeTask = - this - - val kclass = - org.jetbrains.compose.experimental.uikit.tasks.ExperimentalPackComposeApplicationForXCodeTask::class - val kotlinBinaryField = - kclass.declaredMemberProperties.single { it.name == "kotlinBinary" } - val destinationDirField = - kclass.declaredMemberProperties.single { it.name == "destinationDir" } - val executablePathField = - kclass.declaredMemberProperties.single { it.name == "executablePath" } - - @Suppress("ObjectLiteralToLambda") // lambda broke up-to-date - val action = object : Action { - override fun execute(t: Task) { - val kotlinBinary: RegularFile = - (kotlinBinaryField.get(packTask) as RegularFileProperty).get() - val destinationDir: Directory = - (destinationDirField.get(packTask) as DirectoryProperty).get() - val executablePath: String = - (executablePathField.get(packTask) as Provider<*>).get().toString() - - val outputDir: File = File(destinationDir.asFile, executablePath).parentFile - - val bundleSearchDir: File = kotlinBinary.asFile.parentFile - bundleSearchDir - .listFiles { file: File -> file.extension == "bundle" } - ?.forEach { file -> - file.copyRecursively(File(outputDir, file.name), true) - } - } - } - doLast(action) - } +//tasks.withType() +// .configureEach { +// val packTask: org.jetbrains.compose.experimental.uikit.tasks.ExperimentalPackComposeApplicationForXCodeTask = +// this +// +// val kclass = +// org.jetbrains.compose.experimental.uikit.tasks.ExperimentalPackComposeApplicationForXCodeTask::class +// val kotlinBinaryField = +// kclass.declaredMemberProperties.single { it.name == "kotlinBinary" } +// val destinationDirField = +// kclass.declaredMemberProperties.single { it.name == "destinationDir" } +// val executablePathField = +// kclass.declaredMemberProperties.single { it.name == "executablePath" } +// +// @Suppress("ObjectLiteralToLambda") // lambda broke up-to-date +// val action = object : Action { +// override fun execute(t: Task) { +// val kotlinBinary: RegularFile = +// (kotlinBinaryField.get(packTask) as RegularFileProperty).get() +// val destinationDir: Directory = +// (destinationDirField.get(packTask) as DirectoryProperty).get() +// val executablePath: String = +// (executablePathField.get(packTask) as Provider<*>).get().toString() +// +// val outputDir: File = File(destinationDir.asFile, executablePath).parentFile +// +// val bundleSearchDir: File = kotlinBinary.asFile.parentFile +// bundleSearchDir +// .listFiles { file: File -> file.extension == "bundle" } +// ?.forEach { file -> +// file.copyRecursively(File(outputDir, file.name), true) +// } +// } +// } +// doLast(action) +// } diff --git a/samples/compose-resources-gallery/shared/build.gradle.kts b/samples/compose-resources-gallery/shared/build.gradle.kts index 7f8838933..b47e30062 100644 --- a/samples/compose-resources-gallery/shared/build.gradle.kts +++ b/samples/compose-resources-gallery/shared/build.gradle.kts @@ -101,21 +101,21 @@ multiplatformResources { } // TODO move to gradle plugin -tasks.withType().configureEach { - @Suppress("ObjectLiteralToLambda") - doLast(object : Action { - override fun execute(task: Task) { - task as DummyFrameworkTask - - val frameworkDir = File(task.destinationDir, task.frameworkName.get() + ".framework") - - listOf( - "compose-resources-gallery:shared.bundle" - ).forEach { bundleName -> - val bundleDir = File(frameworkDir, bundleName) - bundleDir.mkdir() - File(bundleDir, "dummyFile").writeText("dummy") - } - } - }) -} +//tasks.withType().configureEach { +// @Suppress("ObjectLiteralToLambda") +// doLast(object : Action { +// override fun execute(task: Task) { +// task as DummyFrameworkTask +// +// val frameworkDir = File(task.destinationDir, task.frameworkName.get() + ".framework") +// +// listOf( +// "compose-resources-gallery:shared.bundle" +// ).forEach { bundleName -> +// val bundleDir = File(frameworkDir, bundleName) +// bundleDir.mkdir() +// File(bundleDir, "dummyFile").writeText("dummy") +// } +// } +// }) +//} From 093f01606b2e0a20587f91737b950bbaddac6c6c Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sat, 6 Jan 2024 20:36:07 +0700 Subject: [PATCH 084/352] #535 migrate more generator logic to new version --- .../icerock/gradle/generator/MRGenerator.kt | 156 +----------- .../generator/NOPObjectBodyExtendable.kt | 13 - .../gradle/generator/ObjectBodyExtendable.kt | 12 - .../generator/ResourceGeneratorFeature.kt | 13 - .../gradle/generator/StringsGenerator.kt | 198 --------------- .../generator/android/AndroidMRGenerator.kt | 23 -- .../android/AndroidStringsGenerator.kt | 80 ------ .../generator/apple/AppleGeneratorHelper.kt | 28 --- .../generator/apple/AppleMRGenerator.kt | 27 -- .../generator/apple/AppleStringsGenerator.kt | 65 ----- .../generator/common/CommonAssetsGenerator.kt | 24 -- .../generator/common/CommonColorsGenerator.kt | 24 -- .../generator/common/CommonFilesGenerator.kt | 22 -- .../generator/common/CommonFontsGenerator.kt | 23 -- .../generator/common/CommonImagesGenerator.kt | 22 -- .../generator/common/CommonMRGenerator.kt | 230 +----------------- .../common/CommonPluralsGenerator.kt | 21 -- .../common/CommonStringsGenerator.kt | 21 -- .../gradle/generator/js/JsMRGenerator.kt | 6 - .../gradle/generator/js/JsStringsGenerator.kt | 38 +-- .../generator/jvm/ClassLoaderExtender.kt | 28 --- .../gradle/generator/jvm/JvmMRGenerator.kt | 19 +- .../gradle/generator/jvm/JvmStringUtils.kt | 13 - .../generator/jvm/JvmStringsGenerator.kt | 59 ----- .../dev/icerock/gradle/rework/CodeConst.kt | 24 ++ .../icerock/gradle/rework/CodeGenerators.kt | 54 ++++ .../rework/PlatformContainerGenerator.kt | 14 ++ ...erator.kt => PlatformResourceGenerator.kt} | 6 +- .../gradle/rework/ResourceTypeGenerator.kt | 24 +- .../gradle/rework/ResourcesGenerator.kt | 21 +- .../container/AppleContainerGenerator.kt | 26 ++ .../rework/container/JvmContainerGenerator.kt | 24 ++ .../rework/container/NOPContainerGenerator.kt | 9 + .../metadata/container/ContainerMetadata.kt | 18 +- .../metadata/resource/ResourceMetadata.kt | 25 +- .../string/AndroidStringResourceGenerator.kt | 4 +- .../string/AppleStringResourceGenerator.kt | 14 +- .../string/JsStringResourceGenerator.kt | 13 +- .../string/JvmStringResourceGenerator.kt | 44 ++-- .../string/NOPStringResourceGenerator.kt | 4 +- .../GenerateMultiplatformResourcesTask.kt | 34 ++- .../dev/icerock/gradle/utils/calcHash.kt | 4 + 42 files changed, 313 insertions(+), 1214 deletions(-) delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/NOPObjectBodyExtendable.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ObjectBodyExtendable.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceGeneratorFeature.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleGeneratorHelper.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleStringsGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonAssetsGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonColorsGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFontsGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonImagesGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonPluralsGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonStringsGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/ClassLoaderExtender.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringUtils.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/rework/CodeConst.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/rework/CodeGenerators.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/rework/PlatformContainerGenerator.kt rename resources-generator/src/main/kotlin/dev/icerock/gradle/rework/{PlatformGenerator.kt => PlatformResourceGenerator.kt} (64%) create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/AppleContainerGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/JvmContainerGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/NOPContainerGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt index 4abef684f..a5b32193d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt @@ -1,29 +1,4 @@ -///* -// * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator -// -//import com.squareup.kotlinpoet.ClassName -//import com.squareup.kotlinpoet.FileSpec -//import com.squareup.kotlinpoet.KModifier -//import com.squareup.kotlinpoet.PropertySpec -//import com.squareup.kotlinpoet.TypeSpec -//import dev.icerock.gradle.MRVisibility -//import dev.icerock.gradle.metadata.getActualInterfaces -//import dev.icerock.gradle.metadata.model.GeneratedObject -//import dev.icerock.gradle.metadata.model.GeneratedObjectModifier -//import dev.icerock.gradle.metadata.model.GeneratorType -//import org.gradle.api.Project -//import org.gradle.api.file.Directory -//import org.gradle.api.file.FileTree -//import org.gradle.api.provider.Provider -//import java.io.File -// -//abstract class MRGenerator( -// protected val settings: Settings, -// internal val generators: List, -//) { + // protected open val sourcesGenerationDir: File = settings.sourceSetDir.asFile // protected open val resourcesGenerationDir: File = settings.resourcesDir.asFile // protected open val assetsGenerationDir: File = settings.assetsDir.asFile @@ -40,132 +15,3 @@ // // afterMRGeneration() // } -// -// abstract fun generateFileSpec(): FileSpec? -// -// protected open fun beforeMRGeneration() = Unit -// protected open fun afterMRGeneration() = Unit -// -// protected abstract fun getMRClassModifiers(): Array -// -// protected open fun processMRClass(mrClass: TypeSpec.Builder) {} -// protected open fun getImports(): List = emptyList() -// -// interface Generator : InterfaceGenerator, ObjectGenerator, ResourcesGenerator, -// ObjectBodyExtendable { -// val mrObjectName: String -// val resourceContainerClass: ClassName -// get() = ClassName("dev.icerock.moko.resources", "ResourceContainer") -// val resourceClassName: ClassName -// val inputFiles: Iterable -// -// val type: GeneratorType -// -// fun resourcesFilesFilter(input: FileTree): FileTree -// -// fun getImports(): List -// -// fun addActualOverrideModifier( -// propertyName: String, -// property: PropertySpec.Builder, -// inputMetadata: List, -// targetObject: GeneratedObject, -// ): GeneratedObjectModifier { -// // Read actual interfaces of target object generator type -// val actualInterfaces: List = inputMetadata.getActualInterfaces( -// generatorType = targetObject.generatorType -// ) -// -// var containsInActualInterfaces = false -// -// // Search property in actual interfaces -// actualInterfaces.forEach { genInterface -> -// val hasInInterface = genInterface.properties.any { -// it.name == propertyName -// } -// -// if (hasInInterface) { -// containsInActualInterfaces = true -// } -// } -// -// return if (targetObject.isObject) { -// if (containsInActualInterfaces) { -// property.addModifiers(KModifier.OVERRIDE) -// GeneratedObjectModifier.Override -// } else { -// when (targetObject.modifier) { -// GeneratedObjectModifier.Actual -> { -// property.addModifiers(KModifier.ACTUAL) -// GeneratedObjectModifier.Actual -// } -// -// else -> { -// GeneratedObjectModifier.None -// } -// } -// } -// } else { -// GeneratedObjectModifier.None -// } -// } -// } -// -// interface InterfaceGenerator { -// fun generateInterface( -// project: Project, -// metadata: List, -// resourcesFiles: ResourcesFiles -// ): GenerationResult? -// } -// -// interface ObjectGenerator { -// fun generateObject( -// project: Project, -// metadata: List, -// resourcesFiles: ResourcesFiles -// ): GenerationResult? -// } -// -// interface ResourcesGenerator { -// fun generateResources( -// project: Project, -// metadata: List, -// resourcesFiles: ResourcesFiles -// ) -// } -// -// data class GenerationResult( -// val typeSpec: TypeSpec, -// val metadata: GeneratedObject -// ) -// -// data class ResourcesFiles( -// val lowerResourcesFileTree: FileTree, -// val ownResourcesFileTree: FileTree, -// val upperResourcesFileTree: FileTree -// ) -// -// interface SourceSet { -// val name: String -// -// fun addSourceDir(directory: File) -// fun addResourcesDir(directory: File) -// fun addAssetsDir(directory: File) -// } -// -// data class Settings( -// val inputMetadataFiles: FileTree, -// val outputMetadataFile: File, -// val packageName: String, -// val className: String, -// val visibility: MRVisibility, -// val assetsDir: Directory, -// val sourceSetName: String, -// val sourceSetDir: Directory, -// val resourcesDir: Directory, -// val isStrictLineBreaks: Boolean, -// val iosLocalizationRegion: Provider, -// val androidRClassPackage: Provider, -// ) -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/NOPObjectBodyExtendable.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/NOPObjectBodyExtendable.kt deleted file mode 100644 index c04de3fca..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/NOPObjectBodyExtendable.kt +++ /dev/null @@ -1,13 +0,0 @@ -///* -// * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator -// -//import com.squareup.kotlinpoet.TypeSpec -// -//class NOPObjectBodyExtendable : ObjectBodyExtendable { -// override fun extendObjectBodyAtStart(classBuilder: TypeSpec.Builder) = Unit -// -// override fun extendObjectBodyAtEnd(classBuilder: TypeSpec.Builder) = Unit -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ObjectBodyExtendable.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ObjectBodyExtendable.kt deleted file mode 100644 index 82e1ce8de..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ObjectBodyExtendable.kt +++ /dev/null @@ -1,12 +0,0 @@ -///* -// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator -// -//import com.squareup.kotlinpoet.TypeSpec -// -//interface ObjectBodyExtendable { -// fun extendObjectBodyAtStart(classBuilder: TypeSpec.Builder) -// fun extendObjectBodyAtEnd(classBuilder: TypeSpec.Builder) -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceGeneratorFeature.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceGeneratorFeature.kt deleted file mode 100644 index adad88965..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceGeneratorFeature.kt +++ /dev/null @@ -1,13 +0,0 @@ -///* -// * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator -// -//interface ResourceGeneratorFeature { -// fun createCommonGenerator(): T -// fun createAppleGenerator(): T -// fun createAndroidGenerator(): T -// fun createJvmGenerator(): T -// fun createJsGenerator(): T -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt deleted file mode 100644 index 494561ba2..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt +++ /dev/null @@ -1,198 +0,0 @@ -///* -// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator -// -//import com.squareup.kotlinpoet.ClassName -//import dev.icerock.gradle.generator.android.AndroidStringsGenerator -//import dev.icerock.gradle.generator.apple.AppleStringsGenerator -//import dev.icerock.gradle.generator.common.CommonStringsGenerator -//import dev.icerock.gradle.generator.js.JsStringsGenerator -//import dev.icerock.gradle.generator.jvm.JvmStringsGenerator -//import dev.icerock.gradle.metadata.model.GeneratedObject -//import dev.icerock.gradle.metadata.model.GeneratorType -//import dev.icerock.gradle.metadata.objectsWithProperties -//import dev.icerock.gradle.utils.removeLineWraps -//import kotlinx.serialization.json.Json -//import kotlinx.serialization.json.JsonElement -//import kotlinx.serialization.json.JsonPrimitive -//import kotlinx.serialization.json.decodeFromJsonElement -//import org.gradle.api.file.FileTree -//import java.io.File -//import javax.xml.parsers.DocumentBuilderFactory -// -//typealias KeyType = String -// -//abstract class StringsGenerator( -// private val resourcesFileTree: FileTree, -// private val strictLineBreaks: Boolean, -//) : LocalizationGenerator() { -// -// override val inputFiles: Iterable -// get() = resourcesFileTree.matching { it.include(STRINGS_MASK) }.files -// -// override val resourceClassName = ClassName("dev.icerock.moko.resources", "StringResource") -// override val mrObjectName: String = "strings" -// -// override val type: GeneratorType = GeneratorType.Strings -// -// override fun getLanguagesAllMaps( -// previousLanguageMaps: Map>, -// languageMap: Map> -// ): Map> { -// val resultLanguageMap: MutableMap> = mutableMapOf() -// -// resultLanguageMap.putAll(previousLanguageMaps) -// -// languageMap.forEach { (languageType: LanguageType, value: Map) -> -// -// val currentMap: MutableMap = -// previousLanguageMaps[languageType]?.toMutableMap() ?: mutableMapOf() -// -// value.forEach { (key, value) -> currentMap[key] = value } -// -// resultLanguageMap[languageType] = currentMap -// } -// -// return resultLanguageMap -// } -// -// override fun getPreviousLanguagesMap( -// inputMetadata: List, -// targetObject: GeneratedObject, -// ): Map> { -// if (!targetObject.isObject || !targetObject.isActual) return emptyMap() -// -// val json = Json -// val objectsWithProperties: List = inputMetadata.objectsWithProperties(targetObject) -// -// val languagesMaps = mutableMapOf>() -// -// objectsWithProperties.forEach { generatedObject -> -// generatedObject.properties.forEach { property -> -// val data = json.decodeFromJsonElement>(property.data) -// -// data.forEach { (languageTag, value) -> -// val languageType: LanguageType = if (languageTag == BASE_LANGUAGE) { -// LanguageType.Base -// } else { -// LanguageType.Locale(languageTag) -// } -// -// val currentMap: MutableMap = -// languagesMaps[languageType]?.toMutableMap() ?: mutableMapOf() -// -// currentMap[property.name] = value.content -// -// languagesMaps[languageType] = currentMap -// } -// } -// } -// -// return languagesMaps -// } -// -// override fun getPropertyMetadata( -// key: KeyType, -// languageMap: Map>, -// ): Map { -// val values = mutableMapOf() -// -// languageMap.forEach { (languageType, strings) -> -// strings.forEach { (stringKey, value) -> -// if (stringKey == key) { -// values[languageType.language()] = JsonPrimitive(value) -// } -// } -// } -// -// return values -// } -// -// -// override fun loadLanguageMap(): Map> { -// return inputFiles.map { file -> -// val language: LanguageType = LanguageType.fromFileName(file.parentFile.name) -// val strings: Map = loadLanguageStrings(file) -// language to strings -// }.groupBy( -// keySelector = { it.first }, -// valueTransform = { it.second } -// ).mapValues { value -> -// val maps = value.value -// maps.fold(mutableMapOf()) { result, keyValueMap -> -// result.putAll(keyValueMap) -// result -// } -// } -// } -// -// private fun loadLanguageStrings(stringsFile: File): Map { -// val dbFactory = DocumentBuilderFactory.newInstance() -// val dBuilder = dbFactory.newDocumentBuilder() -// val doc = dBuilder.parse(stringsFile) -// -// val stringNodes = doc.getElementsByTagName("string") -// val mutableMap = mutableMapOf() -// -// for (i in 0 until stringNodes.length) { -// val stringNode = stringNodes.item(i) -// val name = stringNode.attributes.getNamedItem("name").textContent -// val value = stringNode.textContent -// -// mutableMap[name] = if (strictLineBreaks) value else value.removeLineWraps() -// } -// -// val incorrectKeys = mutableMap -// .filter { it.key == it.value } -// .keys -// .toList() -// -// if (incorrectKeys.isNotEmpty()) { -// throw EqualStringKeysException(incorrectKeys) -// } -// -// return mutableMap -// } -// -// override fun getImports(): List = emptyList() -// -// class Feature( -// private val settings: MRGenerator.Settings, -// ) : ResourceGeneratorFeature { -// override fun createCommonGenerator(): StringsGenerator = CommonStringsGenerator( -// resourcesFileTree = settings.ownResourcesFileTree, -// strictLineBreaks = settings.isStrictLineBreaks -// ) -// -// override fun createAppleGenerator(): StringsGenerator = AppleStringsGenerator( -// resourcesFileTree = settings.ownResourcesFileTree, -// strictLineBreaks = settings.isStrictLineBreaks, -// baseLocalizationRegion = settings.iosLocalizationRegion -// ) -// -// override fun createAndroidGenerator(): StringsGenerator = AndroidStringsGenerator( -// resourcesFileTree = settings.ownResourcesFileTree, -// strictLineBreaks = settings.isStrictLineBreaks, -// androidRClassPackage = settings.androidRClassPackage -// ) -// -// override fun createJsGenerator(): StringsGenerator = JsStringsGenerator( -// resourcesFileTree = settings.ownResourcesFileTree, -// mrClassPackage = settings.packageName, -// strictLineBreaks = settings.isStrictLineBreaks -// ) -// -// override fun createJvmGenerator(): StringsGenerator = JvmStringsGenerator( -// resourcesFileTree = settings.ownResourcesFileTree, -// strictLineBreaks = settings.isStrictLineBreaks, -// settings = settings -// ) -// } -// -// companion object { -// const val STRINGS_MASK = "**/strings*.xml" -// val STRINGS_REGEX: Regex = "^.*/strings.*.xml".toRegex() -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt index 84cf5e82a..a8480a75d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt @@ -1,25 +1,3 @@ -///* -// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.android -// -//import com.android.build.gradle.tasks.GenerateResValues -//import com.android.build.gradle.tasks.MergeSourceSetFolders -//import dev.icerock.gradle.generator.TargetMRGenerator -//import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask -//import org.gradle.api.Project -//import org.gradle.kotlin.dsl.withType -// -//class AndroidMRGenerator( -// project: Project, -// settings: Settings, -// generators: List, -//) : TargetMRGenerator( -// project = project, -// settings = settings, -// generators = generators -//) { // // TODO not used. remove after complete migration of task configuration to Plugin configuration time //// override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { //// @@ -30,4 +8,3 @@ //// it.dependsOn(generationTask) //// } //// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt deleted file mode 100644 index 2402b3b1c..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt +++ /dev/null @@ -1,80 +0,0 @@ -///* -// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.android -// -//import com.squareup.kotlinpoet.ClassName -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import dev.icerock.gradle.generator.KeyType -//import dev.icerock.gradle.generator.LanguageType -//import dev.icerock.gradle.generator.NOPObjectBodyExtendable -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import dev.icerock.gradle.generator.StringsGenerator -//import org.apache.commons.text.StringEscapeUtils -//import org.gradle.api.file.FileTree -//import org.gradle.api.provider.Provider -//import java.io.File -// -//class AndroidStringsGenerator( -// resourcesFileTree: FileTree, -// strictLineBreaks: Boolean, -// private val androidRClassPackage: Provider, -//) : StringsGenerator( -// resourcesFileTree = resourcesFileTree, -// strictLineBreaks = strictLineBreaks -//), ObjectBodyExtendable by NOPObjectBodyExtendable() { -// -// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyInitializer(key: String) = -// CodeBlock.of("StringResource(R.string.%L)", processKey(key)) -// -// override fun getImports(): List = listOf( -// ClassName(androidRClassPackage.get(), "R") -// ) -// -// override fun generateResources( -// resourcesGenerationDir: File, -// language: LanguageType, -// strings: Map -// ) { -// val valuesDir = File(resourcesGenerationDir, language.androidResourcesDir) -// val stringsFile = File(valuesDir, "multiplatform_strings.xml") -// valuesDir.mkdirs() -// -// val header = -// """ -// -// -// """.trimIndent() -// -// val content = strings.map { (key, value) -> -// val processedKey = processKey(key) -// val processedValue = convertXmlStringToAndroidLocalization(value) -// "\t$processedValue" -// }.joinToString("\n") -// -// val footer = -// """ -// -// """.trimIndent() -// -// stringsFile.writeText(header + "\n") -// stringsFile.appendText(content) -// stringsFile.appendText("\n" + footer) -// } -// -// private fun processKey(key: String): String { -// return key.replace(".", "_") -// } -// -// private fun convertXmlStringToAndroidLocalization(input: String): String { -// val xmlDecoded = StringEscapeUtils.unescapeXml(input) -// return xmlDecoded.replace("\n", "\\n") -// .replace("\"", "\\\"").let { StringEscapeUtils.escapeXml11(it) } -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleGeneratorHelper.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleGeneratorHelper.kt deleted file mode 100644 index b7ebf5422..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleGeneratorHelper.kt +++ /dev/null @@ -1,28 +0,0 @@ -///* -// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.apple -// -//import com.squareup.kotlinpoet.ClassName -//import com.squareup.kotlinpoet.KModifier -//import com.squareup.kotlinpoet.PropertySpec -//import com.squareup.kotlinpoet.TypeSpec -//import dev.icerock.gradle.generator.ObjectBodyExtendable -// -//class AppleGeneratorHelper( -// private val propertyName: String = "nsBundle" -//) : ObjectBodyExtendable { -// -// override fun extendObjectBodyAtStart(classBuilder: TypeSpec.Builder) = Unit -// -// override fun extendObjectBodyAtEnd(classBuilder: TypeSpec.Builder) { -// val bundleType = ClassName("platform.Foundation", "NSBundle") -// val bundleProperty = PropertySpec.builder(propertyName, bundleType) -// .addModifiers(KModifier.OVERRIDE) -// .initializer(AppleMRGenerator.BUNDLE_PROPERTY_NAME) -// .build() -// -// classBuilder.addProperty(bundleProperty) -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt index 9b887062b..b7e8977f6 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt @@ -24,33 +24,6 @@ // settings = settings, // generators = generators //) { -// private val bundleClassName = ClassName("platform.Foundation", "NSBundle") -// private val bundleIdentifier = "${settings.packageName}.MR" -// -// override fun processMRClass(mrClass: TypeSpec.Builder) { -// super.processMRClass(mrClass) -// -// mrClass.addProperty( -// PropertySpec.builder( -// BUNDLE_PROPERTY_NAME, -// bundleClassName, -// KModifier.PRIVATE -// ) -// .delegate(CodeBlock.of("lazy { NSBundle.loadableBundle(\"${bundleIdentifier}\") }")) -// .build() -// ) -// -// mrClass.addProperty( -// PropertySpec.builder("contentHash", STRING, KModifier.PRIVATE) -// .initializer("%S", resourcesGenerationDir.calculateResourcesHash()) -// .build() -// ) -// } -// -// override fun getImports(): List = listOf( -// bundleClassName, -// ClassName("dev.icerock.moko.resources.utils", "loadableBundle") -// ) // // override fun beforeMRGeneration() { // assetsGenerationDir.mkdirs() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleStringsGenerator.kt deleted file mode 100644 index f2137513b..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleStringsGenerator.kt +++ /dev/null @@ -1,65 +0,0 @@ -///* -// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.apple -// -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import dev.icerock.gradle.generator.KeyType -//import dev.icerock.gradle.generator.LanguageType -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import dev.icerock.gradle.generator.StringsGenerator -//import dev.icerock.gradle.generator.apple.AppleMRGenerator.Companion.BUNDLE_PROPERTY_NAME -//import org.apache.commons.text.StringEscapeUtils -//import org.gradle.api.file.FileTree -//import org.gradle.api.provider.Provider -//import java.io.File -// -//class AppleStringsGenerator( -// resourcesFileTree: FileTree, -// strictLineBreaks: Boolean, -// private val baseLocalizationRegion: Provider -//) : StringsGenerator( -// resourcesFileTree = resourcesFileTree, -// strictLineBreaks = strictLineBreaks -//), -// ObjectBodyExtendable by AppleGeneratorHelper() { -// -// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyInitializer(key: String) = -// CodeBlock.of("StringResource(resourceId = %S, bundle = $BUNDLE_PROPERTY_NAME)", key) -// -// override fun generateResources( -// resourcesGenerationDir: File, -// language: LanguageType, -// strings: Map -// ) { -// val resDir = File(resourcesGenerationDir, language.appleResourcesDir) -// val localizableFile = File(resDir, "Localizable.strings") -// resDir.mkdirs() -// -// val content = strings.mapValues { (_, value) -> -// convertXmlStringToAppleLocalization(value) -// }.map { (key, value) -> -// "\"$key\" = \"$value\";" -// }.joinToString("\n") -// localizableFile.writeText(content) -// -// if (language == LanguageType.Base) { -// val regionDir = File(resourcesGenerationDir, "${baseLocalizationRegion.get()}.lproj") -// regionDir.mkdirs() -// val regionFile = File(regionDir, "Localizable.strings") -// regionFile.writeText(content) -// } -// } -// -// private fun convertXmlStringToAppleLocalization(input: String): String { -// val xmlDecoded = StringEscapeUtils.unescapeXml(input) -// return xmlDecoded.replace("\n", "\\n") -// .replace("\"", "\\\"") -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonAssetsGenerator.kt deleted file mode 100644 index 1e8d85b08..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonAssetsGenerator.kt +++ /dev/null @@ -1,24 +0,0 @@ -///* -// * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.common -// -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import dev.icerock.gradle.generator.AssetsGenerator -//import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecFile -//import dev.icerock.gradle.generator.NOPObjectBodyExtendable -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import org.gradle.api.file.FileTree -// -//class CommonAssetsGenerator( -// ownResourcesFileTree: FileTree, -//) : AssetsGenerator(ownResourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { -// -// override fun getClassModifiers(): Array = emptyArray() -// -// override fun getPropertyModifiers(): Array = emptyArray() -// -// override fun getPropertyInitializer(fileSpec: AssetSpecFile): CodeBlock? = null -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonColorsGenerator.kt deleted file mode 100644 index 012ea81e7..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonColorsGenerator.kt +++ /dev/null @@ -1,24 +0,0 @@ -///* -// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.common -// -//import com.squareup.kotlinpoet.ClassName -//import com.squareup.kotlinpoet.CodeBlock -//import dev.icerock.gradle.generator.ColorNode -//import dev.icerock.gradle.generator.ColorsGenerator -//import dev.icerock.gradle.generator.NOPObjectBodyExtendable -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import org.gradle.api.file.FileTree -// -//class CommonColorsGenerator( -// resourcesFileTree: FileTree, -//) : ColorsGenerator(resourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { -// -// override fun getImports(): List { -// return emptyList() -// } -// -// override fun getPropertyInitializer(color: ColorNode): CodeBlock? = null -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt deleted file mode 100644 index f7191d93e..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt +++ /dev/null @@ -1,22 +0,0 @@ -///* -// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.common -// -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import dev.icerock.gradle.generator.FilesGenerator -//import dev.icerock.gradle.generator.NOPObjectBodyExtendable -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import org.gradle.api.file.FileTree -// -//class CommonFilesGenerator( -// ownInputFileTree: FileTree, -//) : FilesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { -// override fun getClassModifiers(): Array = emptyArray() -// -// override fun getPropertyModifiers(): Array = emptyArray() -// -// override fun getPropertyInitializer(fileSpec: FileSpec): CodeBlock? = null -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFontsGenerator.kt deleted file mode 100644 index 6322b5d5b..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFontsGenerator.kt +++ /dev/null @@ -1,23 +0,0 @@ -///* -// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.common -// -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import dev.icerock.gradle.generator.FontsGenerator -//import dev.icerock.gradle.generator.NOPObjectBodyExtendable -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import org.gradle.api.file.FileTree -//import java.io.File -// -//class CommonFontsGenerator( -// ownInputFileTree: FileTree, -//) : FontsGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { -// override fun getClassModifiers(): Array = emptyArray() -// -// override fun getPropertyModifiers(): Array = emptyArray() -// -// override fun getPropertyInitializer(fontFile: File): CodeBlock? = null -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonImagesGenerator.kt deleted file mode 100644 index 18512bca6..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonImagesGenerator.kt +++ /dev/null @@ -1,22 +0,0 @@ -///* -// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.common -// -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import dev.icerock.gradle.generator.ImagesGenerator -//import dev.icerock.gradle.generator.NOPObjectBodyExtendable -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import org.gradle.api.file.FileTree -// -//class CommonImagesGenerator( -// ownInputFileTree: FileTree, -//) : ImagesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { -// override fun getClassModifiers(): Array = emptyArray() -// -// override fun getPropertyModifiers(): Array = emptyArray() -// -// override fun getPropertyInitializer(fileName: String): CodeBlock? = null -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index 8b23542e0..c13795d37 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -1,44 +1,4 @@ -///* -// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.common -// -//import com.squareup.kotlinpoet.ClassName -//import com.squareup.kotlinpoet.FileSpec -//import com.squareup.kotlinpoet.FileSpec.Builder -//import com.squareup.kotlinpoet.KModifier -//import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -//import com.squareup.kotlinpoet.TypeSpec -//import dev.icerock.gradle.generator.AssetsGenerator -//import dev.icerock.gradle.generator.ColorsGenerator -//import dev.icerock.gradle.generator.MRGenerator -//import dev.icerock.gradle.generator.PluralsGenerator -//import dev.icerock.gradle.generator.StringsGenerator -//import dev.icerock.gradle.metadata.Metadata.createOutputMetadata -//import dev.icerock.gradle.metadata.Metadata.readInputMetadata -//import dev.icerock.gradle.metadata.getInterfaceName -//import dev.icerock.gradle.metadata.model.GeneratedObject -//import dev.icerock.gradle.metadata.model.GeneratedObjectModifier -//import dev.icerock.gradle.metadata.model.GeneratedObjectType -//import dev.icerock.gradle.metadata.model.GeneratorType -//import dev.icerock.gradle.metadata.resourcesIsEmpty -//import dev.icerock.gradle.toModifier -//import dev.icerock.gradle.utils.targetName -//import org.gradle.api.Project -//import org.gradle.api.file.FileTree -// -//class CommonMRGenerator( -// private val project: Project, -// private val sourceSetName: String, -// settings: Settings, -// generators: List, -//) : MRGenerator( -// settings = settings, -// generators = generators -//) { -// override fun getMRClassModifiers(): Array = arrayOf(KModifier.EXPECT) -// + // // TODO not used. remove after complete migration of task configuration to Plugin configuration time //// override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { //// project.tasks @@ -58,139 +18,7 @@ //// it.dependsOn(generationTask) //// } //// } -// -// override fun generateFileSpec(): FileSpec? { -// val inputMetadata: List = readInputMetadata( -// inputMetadataFiles = settings.inputMetadataFiles -// ) -// -// // If previous level's doesn't has resources for generation -// // and target resource has no files - skip step -// if (resourcesIsEmpty(inputMetadata, settings)) return null -// -// val fileSpec: Builder = FileSpec.builder( -// packageName = settings.packageName, -// fileName = settings.className -// ) -// -// val visibilityModifier: KModifier = settings.visibility.toModifier() -// -// val isShouldGenerateExpectObject: Boolean = settings.lowerResourcesFileTree.files -// .none { it.isFile } -// -// val results: List = if (isShouldGenerateExpectObject) { -// // When lower resources is empty, should generate expect MR object -// generateExpectMRObjects( -// inputMetadata = inputMetadata, -// resourcePackage = settings.packageName, -// visibilityModifier = visibilityModifier, -// ) -// } else { -// // If lower resources has files, when on lower level has expect object and -// // need to generate actual interface with fields -// generateActualInterfacesFileSpec( -// visibilityModifier = visibilityModifier, -// inputMetadata = inputMetadata, -// ) -// } -// -// if (results.isEmpty()) return null -// -// generators -// .flatMap { generator -> generator.getImports() } -// .plus(getImports()) -// .forEach { className -> -// fileSpec.addImport(className.packageName, className.simpleName) -// } -// -// results.forEach { fileSpec.addType(it.typeSpec) } -// -// createOutputMetadata( -// outputMetadataFile = settings.outputMetadataFile, -// generatedObjects = results.map { it.metadata } -// ) -// -// return fileSpec.build() -// } -// -// private fun generateExpectMRObjects( -// inputMetadata: List, -// resourcePackage: String, -// visibilityModifier: KModifier, -// ): List { -// // generated MR class structure: -// val mrClassSpec: TypeSpec.Builder = -// TypeSpec.objectBuilder(settings.className) // default: object MR -// .addModifiers(KModifier.EXPECT) -// .addModifiers(visibilityModifier) // public/internal -// -// val expectInterfaceResults: List = generateExpectInterfaces( -// visibilityModifier = visibilityModifier, -// upperResourcesFileTree = settings.upperResourcesFileTree -// ) -// val generatedObjects: MutableList = mutableListOf() -// -// generators.forEach { generator: Generator -> -// val builder: TypeSpec.Builder = TypeSpec -// .objectBuilder(generator.mrObjectName) // resource name: example strings -// .addModifiers(visibilityModifier) // public/internal -// .addSuperinterface(generator.resourceContainerClass.parameterizedBy(generator.resourceClassName)) -// -// val expectInterfaces: List = expectInterfaceResults -// .filter { it.metadata.generatorType == generator.type } -// .map { it.metadata } -// -// //Implement interfaces for generated expect object -// expectInterfaces -// .forEach { -// builder.addSuperinterface( -// ClassName(packageName = resourcePackage, it.name) -// ) -// } -// -// val result: GenerationResult? = generator.generateObject( -// project = project, -// metadata = inputMetadata, -// outputMetadata = GeneratedObject( -// generatorType = generator.type, -// modifier = GeneratedObjectModifier.Expect, -// type = GeneratedObjectType.Object, -// name = generator.mrObjectName, -// interfaces = expectInterfaces.map { it.name } -// ), -// assetsGenerationDir = assetsGenerationDir, -// resourcesGenerationDir = resourcesGenerationDir, -// objectBuilder = builder -// ) -// -// if (result != null) { -// mrClassSpec.addType(result.typeSpec) -// generatedObjects.add(result.metadata) -// } -// } -// -// processMRClass(mrClassSpec) -// -// if (generatedObjects.isEmpty()) return expectInterfaceResults -// -// return expectInterfaceResults + GenerationResult( -// typeSpec = mrClassSpec.build(), -// // Metadata: Add generated objects in MR -// metadata = GeneratedObject( -// generatorType = GeneratorType.None, -// type = GeneratedObjectType.Object, -// name = settings.className, -// modifier = GeneratedObjectModifier.Expect, -// objects = generatedObjects -// ) -// ) -// } -// -// private fun generateExpectInterfaces( -// visibilityModifier: KModifier, -// upperResourcesFileTree: FileTree, -// ): List { -// return upperResourcesFileTree.mapNotNull { file -> + // val generatorType: GeneratorType = // if (file.path.matches(StringsGenerator.STRINGS_REGEX)) { // GeneratorType.Strings @@ -207,57 +35,3 @@ // } else if (file.path.matches(AssetsGenerator.ASSETS_REGEX)) { // GeneratorType.Assets // } else return@mapNotNull null -// -// GeneratedObject( -// generatorType = generatorType, -// type = GeneratedObjectType.Interface, -// modifier = GeneratedObjectModifier.Expect, -// name = getInterfaceName( -// sourceSetName = file.targetName, -// generatorType = generatorType -// ) -// ) -// }.distinctBy { it.name }.map { expectInterface -> -// val resourcesInterface: TypeSpec = TypeSpec.interfaceBuilder(expectInterface.name) -// .addModifiers(visibilityModifier) -// .addModifiers(KModifier.EXPECT) -// .build() -// -// GenerationResult( -// typeSpec = resourcesInterface, -// metadata = expectInterface -// ) -// } -// } -// -// private fun generateActualInterfacesFileSpec( -// inputMetadata: List, -// visibilityModifier: KModifier, -// ): List { -// return generators.mapNotNull { generator -> -// val interfaceName: String = getInterfaceName( -// sourceSetName = sourceSetName, -// generatorType = generator.type -// ) -// -// val resourcesInterfaceBuilder: TypeSpec.Builder = -// TypeSpec.interfaceBuilder(interfaceName) -// .addModifiers(visibilityModifier) -// .addModifiers(KModifier.ACTUAL) -// -// generator.generateObject( -// project = project, -// metadata = inputMetadata, -// outputMetadata = GeneratedObject( -// generatorType = generator.type, -// name = interfaceName, -// type = GeneratedObjectType.Interface, -// modifier = GeneratedObjectModifier.Actual, -// ), -// assetsGenerationDir = assetsGenerationDir, -// resourcesGenerationDir = resourcesGenerationDir, -// objectBuilder = resourcesInterfaceBuilder, -// ) -// } -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonPluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonPluralsGenerator.kt deleted file mode 100644 index 4c49bcd64..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonPluralsGenerator.kt +++ /dev/null @@ -1,21 +0,0 @@ -///* -// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.common -// -//import com.squareup.kotlinpoet.CodeBlock -//import dev.icerock.gradle.generator.NOPObjectBodyExtendable -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import dev.icerock.gradle.generator.PluralsGenerator -//import org.gradle.api.file.FileTree -// -//class CommonPluralsGenerator( -// ownResourcesFileTree: FileTree, -// strictLineBreaks: Boolean, -//) : PluralsGenerator(ownResourcesFileTree, strictLineBreaks), -// ObjectBodyExtendable by NOPObjectBodyExtendable() { -// override fun getPropertyInitializer( -// key: String -// ): CodeBlock? = null -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonStringsGenerator.kt deleted file mode 100644 index c714206fc..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonStringsGenerator.kt +++ /dev/null @@ -1,21 +0,0 @@ -///* -// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.common -// -//import com.squareup.kotlinpoet.CodeBlock -//import dev.icerock.gradle.generator.NOPObjectBodyExtendable -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import dev.icerock.gradle.generator.StringsGenerator -//import org.gradle.api.file.FileTree -// -//class CommonStringsGenerator( -// resourcesFileTree: FileTree, -// strictLineBreaks: Boolean -//) : StringsGenerator( -// resourcesFileTree = resourcesFileTree, -// strictLineBreaks = strictLineBreaks -//), ObjectBodyExtendable by NOPObjectBodyExtendable() { -// override fun getPropertyInitializer(key: String): CodeBlock? = null -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt index 1aff24843..1744df606 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt @@ -32,12 +32,6 @@ // override val resourcesGenerationDir: File = settings.resourcesDir.asFile // // override fun processMRClass(mrClass: TypeSpec.Builder) { -// mrClass.addProperty( -// PropertySpec.builder("contentHash", STRING, KModifier.PRIVATE) -// .initializer("%S", resourcesGenerationDir.calculateResourcesHash()) -// .build() -// ) -// // val stringsLoaderInitializer = buildList { // val stringsObjectLoader = mrClass // .typeSpecs diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt index 99c71c4a4..88d95d245 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt @@ -30,18 +30,7 @@ // resourcesFileTree = resourcesFileTree, // strictLineBreaks = strictLineBreaks //), -// ObjectBodyExtendable by NOPObjectBodyExtendable() { -// -// private val flattenClassPackage = mrClassPackage.flatName -// -// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyInitializer(key: String): CodeBlock { -// return CodeBlock.of("StringResource(key = %S, loader = stringsLoader)", key) -// } -// + // override fun beforeGenerateResources( // objectBuilder: TypeSpec.Builder, // languageMap: Map> @@ -70,30 +59,7 @@ // .build() // ) // } -// -// override fun generateResources( -// resourcesGenerationDir: File, -// language: LanguageType, -// strings: Map -// ) { -// val fileDirName = -// "${flattenClassPackage}_${STRINGS_JSON_NAME}${language.jsResourcesSuffix}" -// -// val localizationDir = File(resourcesGenerationDir, JsMRGenerator.LOCALIZATION_DIR).apply { -// mkdirs() -// } -// -// val stringsFile = File(localizationDir, "$fileDirName.json") -// -// val content = buildJsonObject { -// strings.forEach { (key, value) -> -// put(key, value.convertToMessageFormat()) -// } -// }.toString() -// -// stringsFile.writeText(content) -// } -// + // companion object { // const val STRINGS_JSON_NAME = "stringsJson" // const val STRINGS_FALLBACK_FILE_URL_PROPERTY_NAME = "stringsFallbackFileUrl" diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/ClassLoaderExtender.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/ClassLoaderExtender.kt deleted file mode 100644 index 6fd49743d..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/ClassLoaderExtender.kt +++ /dev/null @@ -1,28 +0,0 @@ -///* -// * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.jvm -// -//import com.squareup.kotlinpoet.ClassName -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import com.squareup.kotlinpoet.PropertySpec -//import com.squareup.kotlinpoet.TypeSpec -//import dev.icerock.gradle.generator.ObjectBodyExtendable -// -//class ClassLoaderExtender(private val mrClassName: String) : ObjectBodyExtendable { -// override fun extendObjectBodyAtStart(classBuilder: TypeSpec.Builder) { -// classBuilder.addProperty( -// PropertySpec.builder( -// "resourcesClassLoader", -// ClassName("java.lang", "ClassLoader"), -// KModifier.OVERRIDE -// ) -// .initializer(CodeBlock.of("${mrClassName}::class.java.classLoader")) -// .build() -// ) -// } -// -// override fun extendObjectBodyAtEnd(classBuilder: TypeSpec.Builder) = Unit -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt index 2958f8760..90f86d866 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt @@ -33,21 +33,7 @@ // // override fun processMRClass(mrClass: TypeSpec.Builder) { // super.processMRClass(mrClass) -// -// mrClass.addProperty( -// PropertySpec.builder( -// STRINGS_BUNDLE_PROPERTY_NAME, -// STRING, -// KModifier.PRIVATE -// ).initializer( -// CodeBlock.of( -// "\"%L/%L\"", -// LOCALIZATION_DIR, -// "${flattenClassName}_$STRINGS_BUNDLE_NAME" -// ) -// ).build() -// ) -// + // mrClass.addProperty( // PropertySpec.builder( // PLURALS_BUNDLE_PROPERTY_NAME, @@ -79,10 +65,7 @@ //// } // // companion object { -// const val STRINGS_BUNDLE_PROPERTY_NAME = "stringsBundle" // const val PLURALS_BUNDLE_PROPERTY_NAME = "pluralsBundle" -// const val STRINGS_BUNDLE_NAME = "mokoBundle" // const val PLURALS_BUNDLE_NAME = "mokoPluralsBundle" -// const val LOCALIZATION_DIR = "localization" // } //} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringUtils.kt deleted file mode 100644 index c933900b8..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringUtils.kt +++ /dev/null @@ -1,13 +0,0 @@ -///* -// * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.jvm -// -//import org.apache.commons.text.StringEscapeUtils -// -//internal fun convertXmlStringToJvmLocalization(input: String): String { -// val xmlDecoded = StringEscapeUtils.unescapeXml(input) -// return xmlDecoded.replace("\n", "\\n") -// .replace("\"", "\\\"") -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt deleted file mode 100644 index ce8253b7b..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmStringsGenerator.kt +++ /dev/null @@ -1,59 +0,0 @@ -///* -// * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.jvm -// -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import dev.icerock.gradle.generator.KeyType -//import dev.icerock.gradle.generator.LanguageType -//import dev.icerock.gradle.generator.MRGenerator -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import dev.icerock.gradle.generator.StringsGenerator -//import dev.icerock.gradle.utils.flatName -//import org.gradle.api.file.FileTree -//import java.io.File -// -//class JvmStringsGenerator( -// resourcesFileTree: FileTree, -// strictLineBreaks: Boolean, -// settings: MRGenerator.Settings, -//) : StringsGenerator( -// resourcesFileTree = resourcesFileTree, -// strictLineBreaks = strictLineBreaks -//), ObjectBodyExtendable by ClassLoaderExtender(settings.className) { -// -// private val flattenClassPackage = settings.packageName.flatName -// -// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyInitializer(key: String) = -// CodeBlock.of( -// "StringResource(resourcesClassLoader = resourcesClassLoader, bundleName = %L, key = %S)", -// JvmMRGenerator.STRINGS_BUNDLE_PROPERTY_NAME, -// key -// ) -// -// override fun generateResources( -// resourcesGenerationDir: File, -// language: LanguageType, -// strings: Map, -// ) { -// val fileDirName = -// "${flattenClassPackage}_${JvmMRGenerator.STRINGS_BUNDLE_NAME}${language.jvmResourcesSuffix}" -// -// val localizationDir = File(resourcesGenerationDir, JvmMRGenerator.LOCALIZATION_DIR).apply { -// mkdirs() -// } -// val stringsFile = File(localizationDir, "$fileDirName.properties") -// -// val content = strings.map { (key, value) -> -// "$key = ${convertXmlStringToJvmLocalization(value)}" -// }.joinToString("\n") -// -// stringsFile.writeText(content) -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/CodeConst.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/CodeConst.kt new file mode 100644 index 000000000..04c2c9dbf --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/CodeConst.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.rework + +import com.squareup.kotlinpoet.ClassName + +object CodeConst { + val resourceContainerClass = ClassName("dev.icerock.moko.resources", "ResourceContainer") + + object Apple { + val nsBundleClass = ClassName("platform.Foundation", "NSBundle") + val loadableBundleClass = ClassName("dev.icerock.moko.resources.utils", "loadableBundle") + const val resourcesBundlePropertyName = "bundle" + const val containerBundlePropertyName = "nsBundle" + } + + object Jvm { + val classLoaderClass = ClassName("java.lang", "ClassLoader") + const val resourcesClassLoaderPropertyName = "resourcesClassLoader" + const val localizationDir = "localization" + } +} \ No newline at end of file diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/CodeGenerators.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/CodeGenerators.kt new file mode 100644 index 000000000..67a46edde --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/CodeGenerators.kt @@ -0,0 +1,54 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.rework + +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.PropertySpec +import com.squareup.kotlinpoet.STRING +import com.squareup.kotlinpoet.TypeSpec + +internal fun TypeSpec.Builder.addAppleResourcesBundleProperty(bundleIdentifier: String) { + val bundleProperty: PropertySpec = PropertySpec.builder( + CodeConst.Apple.resourcesBundlePropertyName, + CodeConst.Apple.nsBundleClass, + KModifier.PRIVATE + ).delegate(CodeBlock.of("lazy { NSBundle.loadableBundle(%S) }", bundleIdentifier)) + .build() + + addProperty(bundleProperty) +} + +internal fun TypeSpec.Builder.addContentHashProperty(hash: String) { + val bundleProperty: PropertySpec = + PropertySpec.builder("contentHash", STRING, KModifier.PRIVATE) + .initializer("%S", hash) + .build() + + addProperty(bundleProperty) +} + +internal fun TypeSpec.Builder.addAppleContainerBundleProperty() { + val bundleProperty: PropertySpec = + PropertySpec.builder( + CodeConst.Apple.containerBundlePropertyName, + CodeConst.Apple.nsBundleClass, + KModifier.OVERRIDE + ).initializer(CodeConst.Apple.resourcesBundlePropertyName) + .build() + + addProperty(bundleProperty) +} + +internal fun TypeSpec.Builder.addJvmClassLoaderProperty(resourcesClassName: String) { + val property: PropertySpec = PropertySpec.builder( + CodeConst.Jvm.resourcesClassLoaderPropertyName, + CodeConst.Jvm.classLoaderClass, + KModifier.PRIVATE + ).initializer(CodeBlock.of("$resourcesClassName::class.java.classLoader")) + .build() + + addProperty(property) +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/PlatformContainerGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/PlatformContainerGenerator.kt new file mode 100644 index 000000000..44b32cf73 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/PlatformContainerGenerator.kt @@ -0,0 +1,14 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.rework + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.TypeSpec + +interface PlatformContainerGenerator { + fun getImports(): List = emptyList() + fun generateBeforeTypes(builder: TypeSpec.Builder) = Unit + fun generateAfterTypes(builder: TypeSpec.Builder) = Unit +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/PlatformGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/PlatformResourceGenerator.kt similarity index 64% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/rework/PlatformGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/rework/PlatformResourceGenerator.kt index b7339aabc..63a6fe4d0 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/PlatformGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/PlatformResourceGenerator.kt @@ -6,11 +6,15 @@ package dev.icerock.gradle.rework import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.rework.metadata.resource.ResourceMetadata -interface PlatformGenerator { +interface PlatformResourceGenerator { fun imports(): List + fun generateBeforeProperties(builder: TypeSpec.Builder) = Unit + fun generateAfterProperties(builder: TypeSpec.Builder) = Unit + fun generateInitializer(metadata: T): CodeBlock fun generateResourceFiles(data: List) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourceTypeGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourceTypeGenerator.kt index 626c4ca25..1842fb4fd 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourceTypeGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourceTypeGenerator.kt @@ -23,13 +23,15 @@ class ResourceTypeGenerator( private val resourceType: ResourceType, private val visibilityModifier: KModifier, private val generator: ResourceGenerator, - private val platformGenerator: PlatformGenerator, + private val platformResourceGenerator: PlatformResourceGenerator, private val filter: PatternFilterable.() -> Unit ) { fun generateMetadata(files: ResourcesFiles): List { return generator.generateMetadata(files.matching(filter).ownSourceSet.fileTree.files) } + fun getImports(): List = platformResourceGenerator.imports() + fun generateExpectInterfaces(files: ResourcesFiles): List { // we should generate expect interface only if we have resources of our type upper return files.matching(filter).upperSourceSets.mapNotNull { sourceSetResources -> @@ -70,7 +72,7 @@ class ResourceTypeGenerator( .objectBuilder(objectName) .addModifiers(visibilityModifier) // implement ResourceType<**Resource> for extensions - .addSuperinterface(resourceContainerClass.parameterizedBy(resourceClass)) + .addSuperinterface(CodeConst.resourceContainerClass.parameterizedBy(resourceClass)) // implement interfaces for generated expect object .addSuperinterfaces(typeInterfaces.map { ClassName(packageName = generationPackage, it.name) @@ -131,15 +133,17 @@ class ResourceTypeGenerator( .addModifiers(visibilityModifier) .addModifiers(KModifier.ACTUAL) // implement ResourceType<**Resource> for extensions - .addSuperinterface(resourceContainerClass.parameterizedBy(resourceClass)) + .addSuperinterface(CodeConst.resourceContainerClass.parameterizedBy(resourceClass)) // implement interfaces for generated expect object .addSuperinterfaces(typeInterfaces.map { ClassName(packageName = generationPackage, it.name) }) - // add all properties of object - .addProperties(typeObject.resources.map(::createActualProperty)) + .also(platformResourceGenerator::generateBeforeProperties) // add all properties of interfaces .addProperties(interfaceResources.map(::createOverrideProperty)) + // add all properties of object + .addProperties(typeObject.resources.map(::createActualProperty)) + .also(platformResourceGenerator::generateAfterProperties) return GenerationResult( typeSpec = objectBuilder.build(), @@ -156,7 +160,7 @@ class ResourceTypeGenerator( @Suppress("UNCHECKED_CAST") val typeMetadata: List = resources.mapNotNull { it as? T } - platformGenerator.generateResourceFiles(typeMetadata) + platformResourceGenerator.generateResourceFiles(typeMetadata) } private fun createActualProperty(resource: ResourceMetadata): PropertySpec { @@ -173,11 +177,7 @@ class ResourceTypeGenerator( return generator.generateProperty(resource) .addModifiers(modifier) - .initializer(platformGenerator.generateInitializer(resource)) + .initializer(platformResourceGenerator.generateInitializer(resource)) .build() } - - private companion object { - val resourceContainerClass = ClassName("dev.icerock.moko.resources", "ResourceContainer") - } -} \ No newline at end of file +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourcesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourcesGenerator.kt index 098fa7e2d..377f748c9 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourcesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourcesGenerator.kt @@ -12,9 +12,11 @@ import dev.icerock.gradle.rework.metadata.container.ContainerMetadata import dev.icerock.gradle.rework.metadata.container.ExpectInterfaceMetadata import dev.icerock.gradle.rework.metadata.container.ObjectMetadata import dev.icerock.gradle.rework.metadata.resource.ResourceMetadata +import dev.icerock.gradle.utils.calculateHash import java.io.File class ResourcesGenerator( + private val containerGenerator: PlatformContainerGenerator, private val typesGenerators: List>, private val resourcesPackageName: String, private val resourcesClassName: String, @@ -96,17 +98,26 @@ class ResourcesGenerator( (actualInterfaces + dummyInterfaces).map { it.metadata as ActualInterfaceMetadata } ) } + objects.forEach { outputMetadata.add(it.metadata) } val objectSpec: TypeSpec.Builder = TypeSpec.objectBuilder(resourcesClassName) // default: object MR .addModifiers(KModifier.ACTUAL) .addModifiers(visibilityModifier) - // TODO here should be added extra properties for platforms - objects.forEach { result -> - objectSpec.addType(result.typeSpec) - outputMetadata.add(result.metadata) - } + containerGenerator.getImports() + .plus(typesGenerators.flatMap { it.getImports() }) + .forEach { fileSpec.addImport(it.packageName, it.simpleNames) } + + val contentHash: String = (inputMetadata + outputMetadata).mapNotNull { it.contentHash() } + .calculateHash() + objectSpec.addContentHashProperty(contentHash) + + objectSpec.also(containerGenerator::generateBeforeTypes) + + objects.forEach { objectSpec.addType(it.typeSpec) } + + objectSpec.also(containerGenerator::generateAfterTypes) fileSpec.addType(objectSpec.build()) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/AppleContainerGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/AppleContainerGenerator.kt new file mode 100644 index 000000000..3376a0278 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/AppleContainerGenerator.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.rework.container + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.rework.CodeConst +import dev.icerock.gradle.rework.PlatformContainerGenerator +import dev.icerock.gradle.rework.addAppleResourcesBundleProperty + +class AppleContainerGenerator( + private val bundleIdentifier: String +) : PlatformContainerGenerator { + override fun getImports(): List { + return listOf( + CodeConst.Apple.nsBundleClass, + CodeConst.Apple.loadableBundleClass + ) + } + + override fun generateBeforeTypes(builder: TypeSpec.Builder) { + builder.addAppleResourcesBundleProperty(bundleIdentifier) + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/JvmContainerGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/JvmContainerGenerator.kt new file mode 100644 index 000000000..d1341fb16 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/JvmContainerGenerator.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.rework.container + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.rework.CodeConst +import dev.icerock.gradle.rework.PlatformContainerGenerator +import dev.icerock.gradle.rework.addJvmClassLoaderProperty + +class JvmContainerGenerator( + private val resourcesClassName: String, + private val flattenClassPackage: String +) : PlatformContainerGenerator { + override fun getImports(): List { + return listOf(CodeConst.Jvm.classLoaderClass) + } + + override fun generateBeforeTypes(builder: TypeSpec.Builder) { + builder.addJvmClassLoaderProperty(resourcesClassName) + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/NOPContainerGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/NOPContainerGenerator.kt new file mode 100644 index 000000000..0f10997f9 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/NOPContainerGenerator.kt @@ -0,0 +1,9 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.rework.container + +import dev.icerock.gradle.rework.PlatformContainerGenerator + +class NOPContainerGenerator : PlatformContainerGenerator diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/metadata/container/ContainerMetadata.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/metadata/container/ContainerMetadata.kt index e7d4ca263..ecbc51a02 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/metadata/container/ContainerMetadata.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/metadata/container/ContainerMetadata.kt @@ -5,11 +5,14 @@ package dev.icerock.gradle.rework.metadata.container import dev.icerock.gradle.rework.metadata.resource.ResourceMetadata +import dev.icerock.gradle.utils.calculateHash import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -sealed interface ContainerMetadata +sealed interface ContainerMetadata { + fun contentHash(): String? +} @Serializable @SerialName("expect-interface") @@ -17,14 +20,18 @@ data class ExpectInterfaceMetadata( val name: String, val resourceType: ResourceType, val sourceSet: String -) : ContainerMetadata +) : ContainerMetadata { + override fun contentHash() = null +} @Serializable @SerialName("actual-interface") data class ActualInterfaceMetadata( val name: String, val resources: List -) : ContainerMetadata +) : ContainerMetadata { + override fun contentHash(): String = resources.mapNotNull { it.contentHash() }.calculateHash() +} @Serializable @SerialName("object") @@ -33,7 +40,10 @@ data class ObjectMetadata( val resourceType: ResourceType, val interfaces: List, val resources: List -) : ContainerMetadata +) : ContainerMetadata { + + override fun contentHash(): String = resources.mapNotNull { it.contentHash() }.calculateHash() +} enum class ResourceType { STRINGS, PLURALS, IMAGES, FONTS, FILES, COLORS, ASSETS diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/metadata/resource/ResourceMetadata.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/metadata/resource/ResourceMetadata.kt index 0337fd4e2..36cba3dd9 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/metadata/resource/ResourceMetadata.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/metadata/resource/ResourceMetadata.kt @@ -7,6 +7,8 @@ package dev.icerock.gradle.rework.metadata.resource import dev.icerock.gradle.rework.serialization.FileSerializer +import dev.icerock.gradle.utils.calculateHash +import dev.icerock.gradle.utils.calculateResourcesHash import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers import java.io.File @@ -14,6 +16,8 @@ import java.io.File @Serializable sealed interface ResourceMetadata { val key: String + + fun contentHash(): String? } @Serializable @@ -26,6 +30,8 @@ data class StringMetadata( val locale: String, val value: String ) + + override fun contentHash(): String = values.hashCode().toString(16) } @Serializable @@ -48,6 +54,8 @@ data class PluralMetadata( ZERO, ONE, TWO, FEW, MANY, OTHER; } } + + override fun contentHash(): String = values.hashCode().toString(16) } @Serializable @@ -60,6 +68,9 @@ data class ImageMetadata( val quality: Int, val filePath: File ) + + override fun contentHash(): String = values.map { it.filePath.calculateResourcesHash() } + .calculateHash() } @Serializable @@ -72,13 +83,19 @@ data class FontMetadata( val family: String, val filePath: File ) + + override fun contentHash(): String = values.map { it.filePath.calculateResourcesHash() } + .calculateHash() } @Serializable data class FileMetadata( override val key: String, val filePath: File -) : ResourceMetadata +) : ResourceMetadata { + + override fun contentHash(): String = filePath.calculateResourcesHash() +} @Serializable data class ColorMetadata( @@ -104,6 +121,8 @@ data class ColorMetadata( val blue: Int, val alpha: Int ) + + override fun contentHash(): String = value.hashCode().toString(16) } @Serializable @@ -111,4 +130,6 @@ data class AssetsMetadata( override val key: String, val relativePath: File, val filePath: File -) : ResourceMetadata +) : ResourceMetadata { + override fun contentHash(): String = filePath.calculateResourcesHash() +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/AndroidStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/AndroidStringResourceGenerator.kt index 9a007455e..47e18c9f5 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/AndroidStringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/AndroidStringResourceGenerator.kt @@ -7,7 +7,7 @@ package dev.icerock.gradle.rework.string import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock import dev.icerock.gradle.generator.LanguageType -import dev.icerock.gradle.rework.PlatformGenerator +import dev.icerock.gradle.rework.PlatformResourceGenerator import dev.icerock.gradle.rework.metadata.resource.StringMetadata import org.apache.commons.text.StringEscapeUtils import java.io.File @@ -15,7 +15,7 @@ import java.io.File class AndroidStringResourceGenerator( private val androidRClassPackage: String, private val resourcesGenerationDir: File -) : PlatformGenerator { +) : PlatformResourceGenerator { override fun imports(): List = listOf( ClassName(androidRClassPackage, "R") ) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/AppleStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/AppleStringResourceGenerator.kt index f69ead25f..45ed96a25 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/AppleStringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/AppleStringResourceGenerator.kt @@ -6,8 +6,11 @@ package dev.icerock.gradle.rework.string import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.LanguageType -import dev.icerock.gradle.rework.PlatformGenerator +import dev.icerock.gradle.rework.CodeConst +import dev.icerock.gradle.rework.PlatformResourceGenerator +import dev.icerock.gradle.rework.addAppleContainerBundleProperty import dev.icerock.gradle.rework.metadata.resource.StringMetadata import org.apache.commons.text.StringEscapeUtils import java.io.File @@ -15,15 +18,14 @@ import java.io.File class AppleStringResourceGenerator( private val baseLocalizationRegion: String, private val resourcesGenerationDir: File -) : PlatformGenerator { +) : PlatformResourceGenerator { override fun imports(): List = emptyList() override fun generateInitializer(metadata: StringMetadata): CodeBlock { return CodeBlock.of( "StringResource(resourceId = %S, bundle = %L)", metadata.key, - // TODO change to const - "nsBundle" + CodeConst.Apple.containerBundlePropertyName ) } @@ -56,6 +58,10 @@ class AppleStringResourceGenerator( } } + override fun generateBeforeProperties(builder: TypeSpec.Builder) { + builder.addAppleContainerBundleProperty() + } + // TODO should we do that? private fun convertXmlStringToAppleLocalization(input: String): String { return StringEscapeUtils.unescapeXml(input) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JsStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JsStringResourceGenerator.kt index 398b56e4e..c0182da26 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JsStringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JsStringResourceGenerator.kt @@ -6,9 +6,10 @@ package dev.icerock.gradle.rework.string import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.LanguageType import dev.icerock.gradle.generator.js.convertToMessageFormat -import dev.icerock.gradle.rework.PlatformGenerator +import dev.icerock.gradle.rework.PlatformResourceGenerator import dev.icerock.gradle.rework.metadata.resource.StringMetadata import dev.icerock.gradle.utils.flatName import kotlinx.serialization.json.buildJsonObject @@ -22,7 +23,7 @@ import java.io.File class JsStringResourceGenerator( resourcesPackageName: String, private val resourcesGenerationDir: File -) : PlatformGenerator { +) : PlatformResourceGenerator { private val flattenClassPackage: String = resourcesPackageName.flatName override fun imports(): List = emptyList() @@ -64,6 +65,14 @@ class JsStringResourceGenerator( stringsFile.writeText(content) } + override fun generateBeforeProperties(builder: TypeSpec.Builder) { + super.generateBeforeProperties(builder) + } + + override fun generateAfterProperties(builder: TypeSpec.Builder) { + super.generateAfterProperties(builder) + } + // TODO share const private companion object { const val STRINGS_JSON_NAME = "stringsJson" diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JvmStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JvmStringResourceGenerator.kt index a2f41d36b..830800bcf 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JvmStringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JvmStringResourceGenerator.kt @@ -6,28 +6,28 @@ package dev.icerock.gradle.rework.string import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.PropertySpec +import com.squareup.kotlinpoet.STRING +import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.LanguageType -import dev.icerock.gradle.rework.PlatformGenerator +import dev.icerock.gradle.rework.CodeConst +import dev.icerock.gradle.rework.PlatformResourceGenerator import dev.icerock.gradle.rework.metadata.resource.StringMetadata -import dev.icerock.gradle.utils.flatName import org.apache.commons.text.StringEscapeUtils import java.io.File class JvmStringResourceGenerator( - resourcesPackageName: String, + private val flattenClassPackage: String, private val resourcesGenerationDir: File -) : PlatformGenerator { - private val flattenClassPackage: String = resourcesPackageName.flatName - +) : PlatformResourceGenerator { override fun imports(): List = emptyList() - // TODO we should add resourcesClassLoader to MR object - // TODO we should add stringsBundle to MR object override fun generateInitializer(metadata: StringMetadata): CodeBlock { return CodeBlock.of( "StringResource(resourcesClassLoader = %L, bundleName = %L, key = %S)", - "resourcesClassLoader", - STRINGS_BUNDLE_PROPERTY_NAME, + CodeConst.Jvm.resourcesClassLoaderPropertyName, + stringsBundlePropertyName, metadata.key ) } @@ -41,11 +41,21 @@ class JvmStringResourceGenerator( } } + override fun generateBeforeProperties(builder: TypeSpec.Builder) { + val property: PropertySpec = PropertySpec.builder( + stringsBundlePropertyName, + STRING, + KModifier.PRIVATE + ).initializer(CodeBlock.of("\"%L/%L\"", CodeConst.Jvm.localizationDir, getBundlePath())) + .build() + + builder.addProperty(property) + } + private fun generateLanguageFile(language: LanguageType, strings: Map) { - val fileDirName = - "${flattenClassPackage}_${STRINGS_BUNDLE_NAME}${language.jvmResourcesSuffix}" + val fileDirName = "${getBundlePath()}${language.jvmResourcesSuffix}" - val localizationDir = File(resourcesGenerationDir, LOCALIZATION_DIR) + val localizationDir = File(resourcesGenerationDir, CodeConst.Jvm.localizationDir) localizationDir.mkdirs() val stringsFile = File(localizationDir, "$fileDirName.properties") @@ -57,6 +67,8 @@ class JvmStringResourceGenerator( stringsFile.writeText(content) } + private fun getBundlePath(): String = "${flattenClassPackage}_${stringsBundleName}" + // TODO should we do that? private fun convertXmlStringToJvmLocalization(input: String): String { return StringEscapeUtils.unescapeXml(input) @@ -64,10 +76,8 @@ class JvmStringResourceGenerator( .replace("\"", "\\\"") } - // TODO share const private companion object { - const val STRINGS_BUNDLE_PROPERTY_NAME = "stringsBundle" - const val STRINGS_BUNDLE_NAME = "mokoBundle" - const val LOCALIZATION_DIR = "localization" + const val stringsBundlePropertyName = "stringsBundle" + const val stringsBundleName = "mokoBundle" } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/NOPStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/NOPStringResourceGenerator.kt index fc7e41bd3..86464cfaf 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/NOPStringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/NOPStringResourceGenerator.kt @@ -6,10 +6,10 @@ package dev.icerock.gradle.rework.string import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock -import dev.icerock.gradle.rework.PlatformGenerator +import dev.icerock.gradle.rework.PlatformResourceGenerator import dev.icerock.gradle.rework.metadata.resource.StringMetadata -class NOPStringResourceGenerator : PlatformGenerator { +class NOPStringResourceGenerator : PlatformResourceGenerator { override fun imports(): List { TODO("Not yet implemented") } 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 298a87b7f..2984a2b99 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 @@ -6,10 +6,14 @@ package dev.icerock.gradle.tasks import dev.icerock.gradle.MRVisibility import dev.icerock.gradle.configuration.getAndroidRClassPackage -import dev.icerock.gradle.rework.PlatformGenerator +import dev.icerock.gradle.rework.PlatformContainerGenerator +import dev.icerock.gradle.rework.PlatformResourceGenerator import dev.icerock.gradle.rework.ResourceTypeGenerator import dev.icerock.gradle.rework.ResourcesFiles import dev.icerock.gradle.rework.ResourcesGenerator +import dev.icerock.gradle.rework.container.AppleContainerGenerator +import dev.icerock.gradle.rework.container.JvmContainerGenerator +import dev.icerock.gradle.rework.container.NOPContainerGenerator import dev.icerock.gradle.rework.metadata.container.ContainerMetadata import dev.icerock.gradle.rework.metadata.container.ObjectMetadata import dev.icerock.gradle.rework.metadata.container.ResourceType @@ -21,6 +25,7 @@ import dev.icerock.gradle.rework.string.JvmStringResourceGenerator import dev.icerock.gradle.rework.string.NOPStringResourceGenerator import dev.icerock.gradle.rework.string.StringResourceGenerator import dev.icerock.gradle.toModifier +import dev.icerock.gradle.utils.flatName import dev.icerock.gradle.utils.isStrictLineBreaks import kotlinx.serialization.InternalSerializationApi import kotlinx.serialization.KSerializer @@ -158,6 +163,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { private fun createGenerator(): ResourcesGenerator { return ResourcesGenerator( + containerGenerator = createPlatformContainerGenerator(), typesGenerators = listOf( createStringGenerator() ), @@ -169,6 +175,25 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { ) } + private fun createPlatformContainerGenerator(): PlatformContainerGenerator { + return createByPlatform( + createCommon = { NOPContainerGenerator() }, + createAndroid = { NOPContainerGenerator() }, + createJs = { NOPContainerGenerator() }, + createApple = { + AppleContainerGenerator( + bundleIdentifier = "${resourcesPackageName.get()}.MR" + ) + }, + createJvm = { + JvmContainerGenerator( + resourcesClassName = resourcesClassName.get(), + flattenClassPackage = resourcesPackageName.get().flatName + ) + } + ) + } + private fun createStringGenerator(): ResourceTypeGenerator { return ResourceTypeGenerator( generationPackage = resourcesPackageName.get(), @@ -178,16 +203,17 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { generator = StringResourceGenerator( strictLineBreaks = project.isStrictLineBreaks ), - platformGenerator = createPlatformStringGenerator(), + platformResourceGenerator = createPlatformStringGenerator(), filter = { include("**/strings*.xml") } ) } private fun getAndroidR(): String = project.getAndroidRClassPackage().get() - private fun createPlatformStringGenerator(): PlatformGenerator { + private fun createPlatformStringGenerator(): PlatformResourceGenerator { val resourcesGenerationDir: File = outputResourcesDir.get().asFile return createByPlatform( + // TODO find way to remove this NOP createCommon = { NOPStringResourceGenerator() }, createAndroid = { AndroidStringResourceGenerator( @@ -203,7 +229,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { }, createJvm = { JvmStringResourceGenerator( - resourcesPackageName = resourcesPackageName.get(), + flattenClassPackage = resourcesPackageName.get().flatName, resourcesGenerationDir = resourcesGenerationDir ) }, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/calcHash.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/calcHash.kt index 309192c2f..5df62d2a9 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/calcHash.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/calcHash.kt @@ -19,3 +19,7 @@ internal fun File.calculateResourcesHash(): String { return singleInputStream.use { DigestUtils.md5Hex(it) } } + +internal fun List.calculateHash(): String { + return DigestUtils.md5Hex(this.joinToString(":")) +} From 66649575ce438427a46f05e3388adcaabcc906b3 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sat, 6 Jan 2024 21:26:46 +0700 Subject: [PATCH 085/352] #535 complete strings generator migration --- .../gradle/generator/js/JsStringsGenerator.kt | 67 -------------- .../js/StringPluralPropertyGenerator.kt | 92 ------------------- .../dev/icerock/gradle/metadata/Metadata.kt | 37 -------- .../icerock/gradle/metadata/MetadataExt.kt | 71 -------------- .../dev/icerock/gradle/metadata/Utils.kt | 18 ---- .../gradle/metadata/model/AssetsMetadata.kt | 19 ---- .../gradle/metadata/model/GeneratedObject.kt | 49 ---------- .../metadata/model/GeneratedObjectModifier.kt | 8 -- .../metadata/model/GeneratedObjectType.kt | 14 --- .../metadata/model/GeneratedProperty.kt | 15 --- .../gradle/metadata/model/GeneratorType.kt | 12 --- .../dev/icerock/gradle/rework/CodeConst.kt | 26 +++++- .../icerock/gradle/rework/CodeGenerators.kt | 65 ++++++++++++- .../rework/PlatformResourceGenerator.kt | 4 +- .../gradle/rework/ResourceTypeGenerator.kt | 18 +++- .../container/AppleContainerGenerator.kt | 4 +- .../rework/container/JvmContainerGenerator.kt | 5 +- .../string/AppleStringResourceGenerator.kt | 5 +- .../string/JsStringResourceGenerator.kt | 68 ++++++++++---- .../string/JvmStringResourceGenerator.kt | 16 +++- .../rework/string/StringResourceGenerator.kt | 8 +- .../GenerateMultiplatformResourcesTask.kt | 11 +-- .../shared/src/commonMain/kotlin/App.kt | 64 ++++++------- 23 files changed, 211 insertions(+), 485 deletions(-) delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/StringPluralPropertyGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Utils.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/AssetsMetadata.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObject.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObjectModifier.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObjectType.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedProperty.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratorType.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt deleted file mode 100644 index 88d95d245..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsStringsGenerator.kt +++ /dev/null @@ -1,67 +0,0 @@ -///* -// * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.js -// -//import com.squareup.kotlinpoet.ClassName -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.FunSpec -//import com.squareup.kotlinpoet.KModifier -//import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -//import com.squareup.kotlinpoet.TypeSpec -//import dev.icerock.gradle.generator.KeyType -//import dev.icerock.gradle.generator.LanguageType -//import dev.icerock.gradle.generator.NOPObjectBodyExtendable -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import dev.icerock.gradle.generator.StringsGenerator -//import dev.icerock.gradle.generator.js.JsMRGenerator.Companion.SUPPORTED_LOCALES_PROPERTY_NAME -//import dev.icerock.gradle.utils.flatName -//import kotlinx.serialization.json.buildJsonObject -//import kotlinx.serialization.json.put -//import org.gradle.api.file.FileTree -//import java.io.File -// -//class JsStringsGenerator( -// resourcesFileTree: FileTree, -// mrClassPackage: String, -// strictLineBreaks: Boolean -//) : StringsGenerator( -// resourcesFileTree = resourcesFileTree, -// strictLineBreaks = strictLineBreaks -//), - -// override fun beforeGenerateResources( -// objectBuilder: TypeSpec.Builder, -// languageMap: Map> -// ) { -// objectBuilder.generateFallbackAndSupportedLanguageProperties( -// languages = languageMap.keys.toList(), -// folder = JsMRGenerator.LOCALIZATION_DIR, -// fallbackFilePropertyName = STRINGS_FALLBACK_FILE_URL_PROPERTY_NAME, -// fallbackFile = "${flattenClassPackage}_${STRINGS_JSON_NAME}.json", -// supportedLocalesPropertyName = SUPPORTED_LOCALES_PROPERTY_NAME, -// getFileNameForLanguage = { language -> -// "${flattenClassPackage}_${STRINGS_JSON_NAME}${language.jsResourcesSuffix}.json" -// } -// ) -// val languageKeys = languageMap[LanguageType.Base].orEmpty().keys -// val languageKeysList = languageKeys.joinToString { it.replace(".", "_") } -// -// objectBuilder.addFunction( -// FunSpec.builder("values") -// .addModifiers(KModifier.OVERRIDE) -// .addStatement("return listOf($languageKeysList)") -// .returns( -// ClassName("kotlin.collections", "List") -// .parameterizedBy(resourceClassName) -// ) -// .build() -// ) -// } - -// companion object { -// const val STRINGS_JSON_NAME = "stringsJson" -// const val STRINGS_FALLBACK_FILE_URL_PROPERTY_NAME = "stringsFallbackFileUrl" -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/StringPluralPropertyGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/StringPluralPropertyGenerator.kt deleted file mode 100644 index c5d2ff918..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/StringPluralPropertyGenerator.kt +++ /dev/null @@ -1,92 +0,0 @@ -///* -// * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.js -// -//import com.squareup.kotlinpoet.ClassName -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import com.squareup.kotlinpoet.PropertySpec -//import com.squareup.kotlinpoet.TypeSpec -//import dev.icerock.gradle.generator.LanguageType -// -///** -// * @param folder the folder, where the localization files are in. -// * @param languages the language codes supported -// * @param fallbackFilePropertyName the property name in the MR object -// * @param fallbackFile the name of the file webpack will use, e.g. my_plurals.json -// */ -//@Suppress("LongParameterList") -//fun TypeSpec.Builder.generateFallbackAndSupportedLanguageProperties( -// languages: List, -// folder: String, -// fallbackFilePropertyName: String, -// fallbackFile: String, -// supportedLocalesPropertyName: String, -// getFileNameForLanguage: (language: LanguageType.Locale) -> String -//) { -// if (languages.isEmpty()) return -// -// addProperty( -// PropertySpec -// .builder(fallbackFilePropertyName, String::class, KModifier.PRIVATE) -// .initializer( -// CodeBlock.of( -// "js(%S) as %T", -// "require(\"$folder/$fallbackFile\")", -// String::class -// ) -// ) -// .build() -// ) -// -// val internalPackage = "dev.icerock.moko.resources.internal" -// val supportedLocalesName = ClassName(internalPackage, "SupportedLocales") -// val supportedLocaleName = ClassName(internalPackage, "SupportedLocale") -// val loaderHolderName = ClassName(internalPackage, "RemoteJsStringLoaderHolder") -// -// val loaderPackage = "dev.icerock.moko.resources.provider" -// val loaderName = ClassName(loaderPackage, "RemoteJsStringLoader") -// -// addProperty( -// PropertySpec -// .builder(supportedLocalesPropertyName, supportedLocalesName, KModifier.PRIVATE) -// .initializer( -// CodeBlock -// .builder() -// .apply { -// add("%T(listOf(\n", supportedLocalesName) -// languages.filterIsInstance().forEach { language -> -// val fileName = getFileNameForLanguage(language) -// add( -// "%T(%S, js(%S) as %T),\n", -// supportedLocaleName, -// language.toBcpString(), -// "require(\"$folder/$fileName\")", -// String::class -// ) -// } -// add("))") -// } -// .build() -// ) -// .build() -// ) -// -// addSuperinterface(loaderHolderName) -// -// addProperty( -// PropertySpec.builder( -// "stringsLoader", -// loaderName, -// KModifier.OVERRIDE -// ).initializer( -// CodeBlock.of( -// "RemoteJsStringLoader.Impl(supportedLocales = %N, fallbackFileUri = %N)", -// supportedLocalesPropertyName, -// fallbackFilePropertyName -// ) -// ).build() -// ) -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt deleted file mode 100644 index 40f9868a9..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Metadata.kt +++ /dev/null @@ -1,37 +0,0 @@ -//package dev.icerock.gradle.metadata -// -//import dev.icerock.gradle.metadata.model.GeneratedObject -//import kotlinx.serialization.builtins.ListSerializer -//import kotlinx.serialization.json.Json -//import org.gradle.api.file.FileTree -//import java.io.File -// -//object Metadata { -// fun createOutputMetadata( -// outputMetadataFile: File, -// generatedObjects: List, -// ) { -// if (generatedObjects.isEmpty()) return -// -// outputMetadataFile.createNewFile() -// -// val generatedJson: String = Json.encodeToString( -// serializer = ListSerializer(GeneratedObject.serializer()), -// value = generatedObjects -// ) -// -// outputMetadataFile.writeText(generatedJson) -// } -// -// fun readInputMetadata( -// inputMetadataFiles: FileTree, -// ): List { -// return inputMetadataFiles.filter { it.isFile }.flatMap { inputFile -> -// val inputString: String = inputFile.readText() -// Json.decodeFromString( -// deserializer = ListSerializer(GeneratedObject.serializer()), -// string = inputString -// ) -// } -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt deleted file mode 100644 index 5d23b862e..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/MetadataExt.kt +++ /dev/null @@ -1,71 +0,0 @@ -//package dev.icerock.gradle.metadata -// -//import dev.icerock.gradle.metadata.model.GeneratedObject -//import dev.icerock.gradle.metadata.model.GeneratorType -// -//fun MutableList.addActual(actualObject: GeneratedObject) { -// val expect: GeneratedObject? = firstOrNull { -// it.name == actualObject.name -// && it.generatorType == actualObject.generatorType -// && it.type == actualObject.type -// } -// -// if (expect != null) { -// remove(expect) -// } -// -// add(actualObject) -//} -// -//fun List.getExpectInterfaces(): List { -// return filter { it.isExpectInterface } -//} -// -//fun List.getActualInterfaces(generatorType: GeneratorType): List { -// return filter { -// (it.isActualInterface || it.isTargetInterface) && it.generatorType == generatorType -// } -//} -// -//fun List.getGeneratorInterfaces(generatorType: GeneratorType): List { -// return filter { -// it.isInterface && it.generatorType == generatorType -// } -//} -// -//fun List.isEmptyMetadata(): Boolean { -// if (this.isEmpty()) return true -// -// return this.none { it.isObject } -//} -// -//fun List.isNotEmptyMetadata(): Boolean { -// return !this.isEmptyMetadata() -//} -// -//fun List.hasActualInterfacesOrExpectObject(): Boolean { -// return this.any { -// it.isActualInterface || it.isExpectObject -// } -//} -// -//fun List.objectsWithProperties( -// targetObject: GeneratedObject, -//): List { -// val objectsWithProperties = mutableListOf() -// -// this.forEach { genObject -> -// if (genObject.generatorType == targetObject.generatorType && genObject.properties.isNotEmpty()) { -// objectsWithProperties.add(genObject) -// } -// -// genObject.objects.forEach { innerObject -> -// if (innerObject.generatorType == targetObject.generatorType && innerObject.properties.isNotEmpty()) { -// objectsWithProperties.add(innerObject) -// } -// } -// } -// -// return objectsWithProperties -//} -// diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Utils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Utils.kt deleted file mode 100644 index 16b25c2e4..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/Utils.kt +++ /dev/null @@ -1,18 +0,0 @@ -//package dev.icerock.gradle.metadata -// -//import dev.icerock.gradle.generator.MRGenerator.Settings -//import dev.icerock.gradle.metadata.model.GeneratedObject -//import dev.icerock.gradle.metadata.model.GeneratorType -//import dev.icerock.gradle.utils.capitalize -// -//internal fun getInterfaceName(sourceSetName: String, generatorType: GeneratorType): String { -// return sourceSetName.capitalize() + generatorType.name.capitalize() -//} -// -//internal fun resourcesIsEmpty( -// inputMetadata: List, -// settings: Settings, -//): Boolean { -// return inputMetadata.isEmptyMetadata() -// && settings.ownResourcesFileTree.files.none { it.isFile } -//} \ No newline at end of file diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/AssetsMetadata.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/AssetsMetadata.kt deleted file mode 100644 index c4068726e..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/AssetsMetadata.kt +++ /dev/null @@ -1,19 +0,0 @@ -//package dev.icerock.gradle.metadata.model -// -//import kotlinx.serialization.SerialName -//import kotlinx.serialization.Serializable -// -//@Serializable -//data class AssetsMetadata( -// @SerialName("type") -// val type: AssetsType, -// val name: String, -// val path: String?, -// val files: List?, -// val assets: List?, -//) -// -//enum class AssetsType { -// File, -// Directory -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObject.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObject.kt deleted file mode 100644 index 2ab7791e6..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObject.kt +++ /dev/null @@ -1,49 +0,0 @@ -//package dev.icerock.gradle.metadata.model -// -//import dev.icerock.gradle.metadata.model.GeneratedObjectModifier.Actual -//import dev.icerock.gradle.metadata.model.GeneratedObjectModifier.Expect -//import dev.icerock.gradle.metadata.model.GeneratedObjectModifier.None -//import dev.icerock.gradle.metadata.model.GeneratedObjectType.Interface -//import dev.icerock.gradle.metadata.model.GeneratedObjectType.Object -//import kotlinx.serialization.Serializable -// -//@Serializable -//data class GeneratedObject( -// val generatorType: GeneratorType, -// val modifier: GeneratedObjectModifier, -// val type: GeneratedObjectType, -// val name: String, -// val interfaces: List = emptyList(), -// val properties: List = emptyList(), -// val objects: List = emptyList() -//) { -// val isExpect: Boolean -// get() = modifier == Expect -// -// val isActual: Boolean -// get() = modifier == Actual -// -// val isObject: Boolean -// get() = type == Object -// -// val isInterface: Boolean -// get() = type == Interface -// -// val isExpectObject -// get() = isObject && isExpect -// -// val isActualObject: Boolean -// get() = isObject && isActual -// -// val isExpectInterface -// get() = isInterface && isExpect -// -// val isActualInterface: Boolean -// get() = isInterface && isActual -// -// val isTargetObject: Boolean -// get() = isObject && modifier == None -// -// val isTargetInterface: Boolean -// get() = isInterface && modifier == None -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObjectModifier.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObjectModifier.kt deleted file mode 100644 index 68b6500c0..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObjectModifier.kt +++ /dev/null @@ -1,8 +0,0 @@ -//package dev.icerock.gradle.metadata.model -// -//enum class GeneratedObjectModifier { -// Expect, -// Actual, -// Override, -// None; -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObjectType.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObjectType.kt deleted file mode 100644 index 65ea36fff..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedObjectType.kt +++ /dev/null @@ -1,14 +0,0 @@ -//package dev.icerock.gradle.metadata.model -// -//enum class GeneratedObjectType(val value: String) { -// Object("object"), -// Interface("interface"); -// -// companion object { -// private val VALUES = values() -// fun getByValue(value: String): GeneratedObjectType { -// return VALUES.firstOrNull { it.value.lowercase() == value.lowercase() } -// ?: throw Exception("Invalid object type") -// } -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedProperty.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedProperty.kt deleted file mode 100644 index 3ba94bb72..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratedProperty.kt +++ /dev/null @@ -1,15 +0,0 @@ -//package dev.icerock.gradle.metadata.model -// -//import dev.icerock.gradle.metadata.model.GeneratedObjectModifier.Actual -//import kotlinx.serialization.Serializable -//import kotlinx.serialization.json.JsonElement -// -//@Serializable -//data class GeneratedProperty( -// val modifier: GeneratedObjectModifier, -// val name: String, -// val data: JsonElement // Can contain data with dependencies from generator type -//){ -// val isActualProperty: Boolean -// get() = modifier == Actual -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratorType.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratorType.kt deleted file mode 100644 index e97f99a27..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/model/GeneratorType.kt +++ /dev/null @@ -1,12 +0,0 @@ -//package dev.icerock.gradle.metadata.model -// -//enum class GeneratorType { -// Strings, -// Plurals, -// Assets, -// Colors, -// Images, -// Files, -// Fonts, -// None -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/CodeConst.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/CodeConst.kt index 04c2c9dbf..7c181e786 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/CodeConst.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/CodeConst.kt @@ -6,19 +6,35 @@ package dev.icerock.gradle.rework import com.squareup.kotlinpoet.ClassName -object CodeConst { - val resourceContainerClass = ClassName("dev.icerock.moko.resources", "ResourceContainer") +internal object CodeConst { + val resourceContainerName = ClassName("dev.icerock.moko.resources", "ResourceContainer") + val stringResourceName = ClassName("dev.icerock.moko.resources", "StringResource") object Apple { - val nsBundleClass = ClassName("platform.Foundation", "NSBundle") - val loadableBundleClass = ClassName("dev.icerock.moko.resources.utils", "loadableBundle") + val nsBundleName = ClassName("platform.Foundation", "NSBundle") + val loadableBundleName = ClassName("dev.icerock.moko.resources.utils", "loadableBundle") const val resourcesBundlePropertyName = "bundle" const val containerBundlePropertyName = "nsBundle" } object Jvm { - val classLoaderClass = ClassName("java.lang", "ClassLoader") + val classLoaderName = ClassName("java.lang", "ClassLoader") const val resourcesClassLoaderPropertyName = "resourcesClassLoader" const val localizationDir = "localization" } + + object Js { + private const val internalPackage = "dev.icerock.moko.resources.internal" + val supportedLocalesName = ClassName(internalPackage, "SupportedLocales") + val supportedLocaleName = ClassName(internalPackage, "SupportedLocale") + val loaderHolderName = ClassName(internalPackage, "RemoteJsStringLoaderHolder") + + val stringLoaderName = ClassName( + "dev.icerock.moko.resources.provider", "RemoteJsStringLoader" + ) + const val stringsLoaderPropertyName = "stringsLoader" + + const val fallbackFilePropertyName = "fallbackFileUrl" + const val supportedLocalesPropertyName = "supportedLocales" + } } \ No newline at end of file diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/CodeGenerators.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/CodeGenerators.kt index 67a46edde..c321f9d75 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/CodeGenerators.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/CodeGenerators.kt @@ -13,7 +13,7 @@ import com.squareup.kotlinpoet.TypeSpec internal fun TypeSpec.Builder.addAppleResourcesBundleProperty(bundleIdentifier: String) { val bundleProperty: PropertySpec = PropertySpec.builder( CodeConst.Apple.resourcesBundlePropertyName, - CodeConst.Apple.nsBundleClass, + CodeConst.Apple.nsBundleName, KModifier.PRIVATE ).delegate(CodeBlock.of("lazy { NSBundle.loadableBundle(%S) }", bundleIdentifier)) .build() @@ -34,7 +34,7 @@ internal fun TypeSpec.Builder.addAppleContainerBundleProperty() { val bundleProperty: PropertySpec = PropertySpec.builder( CodeConst.Apple.containerBundlePropertyName, - CodeConst.Apple.nsBundleClass, + CodeConst.Apple.nsBundleName, KModifier.OVERRIDE ).initializer(CodeConst.Apple.resourcesBundlePropertyName) .build() @@ -45,10 +45,69 @@ internal fun TypeSpec.Builder.addAppleContainerBundleProperty() { internal fun TypeSpec.Builder.addJvmClassLoaderProperty(resourcesClassName: String) { val property: PropertySpec = PropertySpec.builder( CodeConst.Jvm.resourcesClassLoaderPropertyName, - CodeConst.Jvm.classLoaderClass, + CodeConst.Jvm.classLoaderName, KModifier.PRIVATE ).initializer(CodeBlock.of("$resourcesClassName::class.java.classLoader")) .build() addProperty(property) } + +internal fun TypeSpec.Builder.addJsFallbackProperty(fallbackFilePath: String) { + val property: PropertySpec = PropertySpec + .builder(CodeConst.Js.fallbackFilePropertyName, String::class, KModifier.PRIVATE) + .initializer( + CodeBlock.of( + "js(%S) as %T", + "require(\"$fallbackFilePath\")", + String::class + ) + ) + .build() + + addProperty(property) +} + +internal fun TypeSpec.Builder.addJsSupportedLocalesProperty( + bcpLangToPath: List> +) { + val property: PropertySpec = PropertySpec + .builder( + CodeConst.Js.supportedLocalesPropertyName, + CodeConst.Js.supportedLocalesName, + KModifier.PRIVATE + ).initializer( + CodeBlock + .builder() + .apply { + add("%T(listOf(\n", CodeConst.Js.supportedLocalesName) + bcpLangToPath.forEach { (bcpLang, filePath) -> + add( + "%T(%S, js(%S) as %T),\n", + CodeConst.Js.supportedLocaleName, + bcpLang, + "require(\"$filePath\")", + String::class + ) + } + add("))") + }.build() + ).build() + + addProperty(property) +} + +internal fun TypeSpec.Builder.addJsContainerStringsLoaderProperty() { + val property = PropertySpec.builder( + CodeConst.Js.stringsLoaderPropertyName, + CodeConst.Js.stringLoaderName, + KModifier.OVERRIDE + ).initializer( + CodeBlock.of( + "RemoteJsStringLoader.Impl(supportedLocales = %N, fallbackFileUri = %N)", + CodeConst.Js.supportedLocalesPropertyName, + CodeConst.Js.fallbackFilePropertyName + ) + ).build() + addProperty(property) +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/PlatformResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/PlatformResourceGenerator.kt index 63a6fe4d0..60c61703b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/PlatformResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/PlatformResourceGenerator.kt @@ -12,8 +12,8 @@ import dev.icerock.gradle.rework.metadata.resource.ResourceMetadata interface PlatformResourceGenerator { fun imports(): List - fun generateBeforeProperties(builder: TypeSpec.Builder) = Unit - fun generateAfterProperties(builder: TypeSpec.Builder) = Unit + fun generateBeforeProperties(builder: TypeSpec.Builder, metadata: List) = Unit + fun generateAfterProperties(builder: TypeSpec.Builder, metadata: List) = Unit fun generateInitializer(metadata: T): CodeBlock fun generateResourceFiles(data: List) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourceTypeGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourceTypeGenerator.kt index 1842fb4fd..4a2f4a594 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourceTypeGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourceTypeGenerator.kt @@ -72,7 +72,7 @@ class ResourceTypeGenerator( .objectBuilder(objectName) .addModifiers(visibilityModifier) // implement ResourceType<**Resource> for extensions - .addSuperinterface(CodeConst.resourceContainerClass.parameterizedBy(resourceClass)) + .addSuperinterface(CodeConst.resourceContainerName.parameterizedBy(resourceClass)) // implement interfaces for generated expect object .addSuperinterfaces(typeInterfaces.map { ClassName(packageName = generationPackage, it.name) @@ -133,17 +133,27 @@ class ResourceTypeGenerator( .addModifiers(visibilityModifier) .addModifiers(KModifier.ACTUAL) // implement ResourceType<**Resource> for extensions - .addSuperinterface(CodeConst.resourceContainerClass.parameterizedBy(resourceClass)) + .addSuperinterface(CodeConst.resourceContainerName.parameterizedBy(resourceClass)) // implement interfaces for generated expect object .addSuperinterfaces(typeInterfaces.map { ClassName(packageName = generationPackage, it.name) }) - .also(platformResourceGenerator::generateBeforeProperties) + .also { builder -> + platformResourceGenerator.generateBeforeProperties( + builder, + (interfaceResources + typeObject.resources).mapNotNull { it as? T } + ) + } // add all properties of interfaces .addProperties(interfaceResources.map(::createOverrideProperty)) // add all properties of object .addProperties(typeObject.resources.map(::createActualProperty)) - .also(platformResourceGenerator::generateAfterProperties) + .also { builder -> + platformResourceGenerator.generateAfterProperties( + builder, + (interfaceResources + typeObject.resources).mapNotNull { it as? T } + ) + } return GenerationResult( typeSpec = objectBuilder.build(), diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/AppleContainerGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/AppleContainerGenerator.kt index 3376a0278..433186e93 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/AppleContainerGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/AppleContainerGenerator.kt @@ -15,8 +15,8 @@ class AppleContainerGenerator( ) : PlatformContainerGenerator { override fun getImports(): List { return listOf( - CodeConst.Apple.nsBundleClass, - CodeConst.Apple.loadableBundleClass + CodeConst.Apple.nsBundleName, + CodeConst.Apple.loadableBundleName ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/JvmContainerGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/JvmContainerGenerator.kt index d1341fb16..e7290d54c 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/JvmContainerGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/JvmContainerGenerator.kt @@ -11,11 +11,10 @@ import dev.icerock.gradle.rework.PlatformContainerGenerator import dev.icerock.gradle.rework.addJvmClassLoaderProperty class JvmContainerGenerator( - private val resourcesClassName: String, - private val flattenClassPackage: String + private val resourcesClassName: String ) : PlatformContainerGenerator { override fun getImports(): List { - return listOf(CodeConst.Jvm.classLoaderClass) + return listOf(CodeConst.Jvm.classLoaderName) } override fun generateBeforeTypes(builder: TypeSpec.Builder) { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/AppleStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/AppleStringResourceGenerator.kt index 45ed96a25..8d7e3f5db 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/AppleStringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/AppleStringResourceGenerator.kt @@ -58,7 +58,10 @@ class AppleStringResourceGenerator( } } - override fun generateBeforeProperties(builder: TypeSpec.Builder) { + override fun generateBeforeProperties( + builder: TypeSpec.Builder, + metadata: List + ) { builder.addAppleContainerBundleProperty() } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JsStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JsStringResourceGenerator.kt index c0182da26..0ff459616 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JsStringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JsStringResourceGenerator.kt @@ -6,20 +6,23 @@ package dev.icerock.gradle.rework.string import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.FunSpec +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.LanguageType import dev.icerock.gradle.generator.js.convertToMessageFormat +import dev.icerock.gradle.rework.CodeConst import dev.icerock.gradle.rework.PlatformResourceGenerator +import dev.icerock.gradle.rework.addJsContainerStringsLoaderProperty +import dev.icerock.gradle.rework.addJsFallbackProperty +import dev.icerock.gradle.rework.addJsSupportedLocalesProperty import dev.icerock.gradle.rework.metadata.resource.StringMetadata import dev.icerock.gradle.utils.flatName import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.put import java.io.File -// TODO migrate dev.icerock.gradle.generator.js.JsStringsGenerator.beforeGenerateResources -// add fun values to MR.strings object -// add property stringsFallbackFileUrl to MR.strings object -// add property supportedLocales to MR.strings object class JsStringResourceGenerator( resourcesPackageName: String, private val resourcesGenerationDir: File @@ -28,12 +31,11 @@ class JsStringResourceGenerator( override fun imports(): List = emptyList() - // TODO we should add stringsLoader to MR override fun generateInitializer(metadata: StringMetadata): CodeBlock { return CodeBlock.of( "StringResource(key = %S, loader = %L)", metadata.key, - "stringsLoader" + CodeConst.Js.stringsLoaderPropertyName ) } @@ -47,17 +49,13 @@ class JsStringResourceGenerator( } private fun generateLanguageFile(language: LanguageType, strings: Map) { - val fileDirName = - "${flattenClassPackage}_${STRINGS_JSON_NAME}${language.jsResourcesSuffix}" - val localizationDir = File(resourcesGenerationDir, LOCALIZATION_DIR) - localizationDir.mkdirs() - val stringsFile = File(localizationDir, "$fileDirName.json") + val stringsFile = File(localizationDir, getFileNameForLanguage(language)) val content: String = buildJsonObject { - strings.forEach { (key, value) -> + strings.forEach { (key: String, value: String) -> put(key, value.convertToMessageFormat()) } }.toString() @@ -65,15 +63,51 @@ class JsStringResourceGenerator( stringsFile.writeText(content) } - override fun generateBeforeProperties(builder: TypeSpec.Builder) { - super.generateBeforeProperties(builder) + override fun generateBeforeProperties( + builder: TypeSpec.Builder, + metadata: List + ) { + builder.addSuperinterface(CodeConst.Js.loaderHolderName) + + builder.addJsFallbackProperty( + fallbackFilePath = LOCALIZATION_DIR + "/" + getFileNameForLanguage(LanguageType.Base) + ) + builder.addJsSupportedLocalesProperty( + bcpLangToPath = metadata.asSequence() + .flatMap { resource -> + resource.values.map { it.locale } + }.distinct().map { locale -> + LanguageType.fromLanguage(locale) + }.filterIsInstance().map { language -> + val fileName: String = getFileNameForLanguage(language) + language.toBcpString() to "$LOCALIZATION_DIR/$fileName" + }.toList() + ) + builder.addJsContainerStringsLoaderProperty() + } + + override fun generateAfterProperties( + builder: TypeSpec.Builder, + metadata: List + ) { + val languageKeysList: String = metadata.joinToString { it.key } + + val valuesFun: FunSpec = FunSpec.builder("values") + .addModifiers(KModifier.OVERRIDE) + .addStatement("return listOf($languageKeysList)") + .returns( + ClassName("kotlin.collections", "List") + .parameterizedBy(CodeConst.stringResourceName) + ) + .build() + + builder.addFunction(valuesFun) } - override fun generateAfterProperties(builder: TypeSpec.Builder) { - super.generateAfterProperties(builder) + private fun getFileNameForLanguage(language: LanguageType): String { + return "${flattenClassPackage}_${STRINGS_JSON_NAME}${language.jsResourcesSuffix}.json" } - // TODO share const private companion object { const val STRINGS_JSON_NAME = "stringsJson" const val LOCALIZATION_DIR = "localization" diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JvmStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JvmStringResourceGenerator.kt index 830800bcf..50c11a5d1 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JvmStringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JvmStringResourceGenerator.kt @@ -19,6 +19,7 @@ import java.io.File class JvmStringResourceGenerator( private val flattenClassPackage: String, + private val className: String, private val resourcesGenerationDir: File ) : PlatformResourceGenerator { override fun imports(): List = emptyList() @@ -41,7 +42,20 @@ class JvmStringResourceGenerator( } } - override fun generateBeforeProperties(builder: TypeSpec.Builder) { + override fun generateBeforeProperties( + builder: TypeSpec.Builder, + metadata: List + ) { + val classLoaderProperty: PropertySpec = PropertySpec.builder( + CodeConst.Jvm.resourcesClassLoaderPropertyName, + CodeConst.Jvm.classLoaderName, + KModifier.OVERRIDE + ) + .initializer(CodeBlock.of(className + "." + CodeConst.Jvm.resourcesClassLoaderPropertyName)) + .build() + + builder.addProperty(classLoaderProperty) + val property: PropertySpec = PropertySpec.builder( stringsBundlePropertyName, STRING, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/StringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/StringResourceGenerator.kt index 99c172e0b..4d9e78ed4 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/StringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/StringResourceGenerator.kt @@ -4,10 +4,10 @@ package dev.icerock.gradle.rework.string -import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.PropertySpec import dev.icerock.gradle.generator.EqualStringKeysException import dev.icerock.gradle.generator.LanguageType +import dev.icerock.gradle.rework.CodeConst import dev.icerock.gradle.rework.ResourceGenerator import dev.icerock.gradle.rework.metadata.resource.StringMetadata import dev.icerock.gradle.utils.removeLineWraps @@ -81,10 +81,6 @@ class StringResourceGenerator( } override fun generateProperty(metadata: StringMetadata): PropertySpec.Builder { - return PropertySpec.builder(metadata.key, className) - } - - companion object { - val className = ClassName("dev.icerock.moko.resources", "StringResource") + return PropertySpec.builder(metadata.key, CodeConst.stringResourceName) } } 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 2984a2b99..9d787e8ce 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 @@ -6,6 +6,7 @@ package dev.icerock.gradle.tasks import dev.icerock.gradle.MRVisibility import dev.icerock.gradle.configuration.getAndroidRClassPackage +import dev.icerock.gradle.rework.CodeConst import dev.icerock.gradle.rework.PlatformContainerGenerator import dev.icerock.gradle.rework.PlatformResourceGenerator import dev.icerock.gradle.rework.ResourceTypeGenerator @@ -97,10 +98,6 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { @get:InputFiles abstract val inputMetadataFiles: ConfigurableFileCollection - //TODO Realise -// @get:OutputFile -// abstract val generationReport: RegularFileProperty - @get:OutputDirectory abstract val outputResourcesDir: DirectoryProperty @@ -187,8 +184,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { }, createJvm = { JvmContainerGenerator( - resourcesClassName = resourcesClassName.get(), - flattenClassPackage = resourcesPackageName.get().flatName + resourcesClassName = resourcesClassName.get() ) } ) @@ -197,7 +193,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { private fun createStringGenerator(): ResourceTypeGenerator { return ResourceTypeGenerator( generationPackage = resourcesPackageName.get(), - resourceClass = StringResourceGenerator.className, + resourceClass = CodeConst.stringResourceName, resourceType = ResourceType.STRINGS, visibilityModifier = resourcesVisibility.get().toModifier(), generator = StringResourceGenerator( @@ -230,6 +226,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { createJvm = { JvmStringResourceGenerator( flattenClassPackage = resourcesPackageName.get().flatName, + className = resourcesClassName.get(), resourcesGenerationDir = resourcesGenerationDir ) }, diff --git a/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt b/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt index 34854f96c..ae95b5daa 100644 --- a/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt +++ b/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt @@ -40,17 +40,17 @@ internal fun App() { .padding(16.dp), horizontalAlignment = Alignment.CenterHorizontally ) { - Image( - painter = painterResource(MR.images.moko_logo), - contentDescription = null - ) - - Image( - modifier = Modifier.size(30.dp).padding(top = 16.dp), - painter = painterResource(MR.images.car_black), - contentDescription = null, - colorFilter = ColorFilter.tint(MaterialTheme.colors.onBackground) - ) +// Image( +// painter = painterResource(MR.images.moko_logo), +// contentDescription = null +// ) +// +// Image( +// modifier = Modifier.size(30.dp).padding(top = 16.dp), +// painter = painterResource(MR.images.car_black), +// contentDescription = null, +// colorFilter = ColorFilter.tint(MaterialTheme.colors.onBackground) +// ) var text: String by remember { mutableStateOf("") } @@ -64,32 +64,32 @@ internal fun App() { onValueChange = { text = it } ) - val counter: Int = text.length - Text( - modifier = Modifier.fillMaxWidth() - .padding(vertical = 8.dp), - text = stringResource(MR.plurals.chars_count, counter, counter), - color = colorResource(MR.colors.textColor), - fontFamily = fontFamilyResource(MR.fonts.cormorant.italic) - ) +// val counter: Int = text.length +// Text( +// modifier = Modifier.fillMaxWidth() +// .padding(vertical = 8.dp), +// text = stringResource(MR.plurals.chars_count, counter, counter), +// color = colorResource(MR.colors.textColor), +// fontFamily = fontFamilyResource(MR.fonts.cormorant.italic) +// ) Button(onClick = { text = "Hello, ${getPlatformName()}" }) { Text(text = stringResource(MR.strings.hello_world)) } - val fileContent: String? by MR.files.some_file.readTextAsState() - Text( - modifier = Modifier.padding(top = 16.dp), - text = fileContent.orEmpty(), - color = MaterialTheme.colors.onBackground - ) - - val assetContent: String? by MR.assets.some_asset.readTextAsState() - Text( - modifier = Modifier.padding(top = 16.dp), - text = assetContent.orEmpty(), - color = MaterialTheme.colors.onBackground - ) +// val fileContent: String? by MR.files.some_file.readTextAsState() +// Text( +// modifier = Modifier.padding(top = 16.dp), +// text = fileContent.orEmpty(), +// color = MaterialTheme.colors.onBackground +// ) +// +// val assetContent: String? by MR.assets.some_asset.readTextAsState() +// Text( +// modifier = Modifier.padding(top = 16.dp), +// text = assetContent.orEmpty(), +// color = MaterialTheme.colors.onBackground +// ) } } } From 15bc3bdef4341334b00cb9dbd52261ac8d483d84 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 7 Jan 2024 00:12:44 +0700 Subject: [PATCH 086/352] #535 generate object without expect/actual --- .../gradle/rework/ResourceTypeGenerator.kt | 47 +++++- .../gradle/rework/ResourcesGenerator.kt | 154 +++++++++++------- 2 files changed, 137 insertions(+), 64 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourceTypeGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourceTypeGenerator.kt index 4a2f4a594..ebbe9f16d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourceTypeGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourceTypeGenerator.kt @@ -166,6 +166,40 @@ class ResourceTypeGenerator( ) } + fun generateObject( + metadata: List + ): GenerationResult? { + val typeResources: List = metadata.mapNotNull { it as? T } + if (typeResources.isEmpty()) return null + + val objectName: String = resourceType.name.lowercase() + + val objectBuilder: TypeSpec.Builder = TypeSpec + .objectBuilder(objectName) + .addModifiers(visibilityModifier) + // implement ResourceType<**Resource> for extensions + .addSuperinterface(CodeConst.resourceContainerName.parameterizedBy(resourceClass)) + // implement interfaces for generated expect object + .also { builder -> + platformResourceGenerator.generateBeforeProperties(builder, typeResources) + } + // add all properties of object + .addProperties(typeResources.map(::createSimpleProperty)) + .also { builder -> + platformResourceGenerator.generateAfterProperties(builder, typeResources) + } + + return GenerationResult( + typeSpec = objectBuilder.build(), + metadata = ObjectMetadata( + name = objectName, + resourceType = resourceType, + interfaces = emptyList(), + resources = typeResources + ) + ) + } + fun generateFiles(resources: List) { @Suppress("UNCHECKED_CAST") val typeMetadata: List = resources.mapNotNull { it as? T } @@ -173,6 +207,10 @@ class ResourceTypeGenerator( platformResourceGenerator.generateResourceFiles(typeMetadata) } + private fun createSimpleProperty(resource: ResourceMetadata): PropertySpec { + return createProperty(resource) + } + private fun createActualProperty(resource: ResourceMetadata): PropertySpec { return createProperty(resource, KModifier.ACTUAL) } @@ -181,12 +219,17 @@ class ResourceTypeGenerator( return createProperty(resource, KModifier.OVERRIDE) } - private fun createProperty(resource: ResourceMetadata, modifier: KModifier): PropertySpec { + private fun createProperty( + resource: ResourceMetadata, + modifier: KModifier? = null + ): PropertySpec { @Suppress("UNCHECKED_CAST") resource as T return generator.generateProperty(resource) - .addModifiers(modifier) + .apply { + if (modifier != null) addModifiers(modifier) + } .initializer(platformResourceGenerator.generateInitializer(resource)) .build() } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourcesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourcesGenerator.kt index 377f748c9..2c7aea32d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourcesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourcesGenerator.kt @@ -41,85 +41,115 @@ class ResourcesGenerator( val outputMetadata: MutableList = mutableListOf() - // for each input metadata we should generate actual - - // at first we should filter already generated expect-actual interfaces - val expectInterfaces: List = inputMetadata - .mapNotNull { it as? ExpectInterfaceMetadata } - .filter { expectInterface -> - inputMetadata.mapNotNull { it as? ActualInterfaceMetadata } - .none { expectInterface.name == it.name } + val inputObject: ObjectMetadata? = inputMetadata.mapNotNull { it as? ObjectMetadata } + .singleOrNull() + if (inputObject == null) { + // we not have expect - we should generate simple object + val objects: List = typesGenerators.mapNotNull { typeGenerator -> + typeGenerator.generateObject(ownMetadata) } - val alreadyActualInterfaces: List = inputMetadata - .mapNotNull { it as? ActualInterfaceMetadata } - .map { it.name } - - // then we should generate actual interfaces with resources at our level - val actualInterfaces: List = typesGenerators.mapNotNull { typeGenerator -> - typeGenerator.generateActualInterface( - interfaces = expectInterfaces.filterNot { alreadyActualInterfaces.contains(it.name) }, - metadata = ownMetadata, - sourceSet = sourceSetName - ) - } + objects.forEach { outputMetadata.add(it.metadata) } - actualInterfaces.forEach { result -> - fileSpec.addType(result.typeSpec) - outputMetadata.add(result.metadata) - } + val objectSpec: TypeSpec.Builder = + TypeSpec.objectBuilder(resourcesClassName) // default: object MR + .addModifiers(visibilityModifier) - // then we should generate dummy actual interfaces - val dummyInterfaces: List = expectInterfaces.map { it.name } - .minus(actualInterfaces.map { (it.metadata as ActualInterfaceMetadata).name }.toSet()) - .map { dummyInterfaceName -> - GenerationResult( - typeSpec = TypeSpec.interfaceBuilder(dummyInterfaceName) - .addModifiers(visibilityModifier) - .addModifiers(KModifier.ACTUAL) - .build(), - metadata = ActualInterfaceMetadata( - name = dummyInterfaceName, - resources = emptyList() - ) + containerGenerator.getImports() + .plus(typesGenerators.flatMap { it.getImports() }) + .forEach { fileSpec.addImport(it.packageName, it.simpleNames) } + + val contentHash: String = (inputMetadata + outputMetadata).mapNotNull { it.contentHash() } + .calculateHash() + objectSpec.addContentHashProperty(contentHash) + + objectSpec.also(containerGenerator::generateBeforeTypes) + + objects.forEach { objectSpec.addType(it.typeSpec) } + + objectSpec.also(containerGenerator::generateAfterTypes) + + fileSpec.addType(objectSpec.build()) + } else { + // for each input metadata we should generate actual + + // at first we should filter already generated expect-actual interfaces + val expectInterfaces: List = inputMetadata + .mapNotNull { it as? ExpectInterfaceMetadata } + .filter { expectInterface -> + inputMetadata.mapNotNull { it as? ActualInterfaceMetadata } + .none { expectInterface.name == it.name } + } + val alreadyActualInterfaces: List = inputMetadata + .mapNotNull { it as? ActualInterfaceMetadata } + .map { it.name } + + // then we should generate actual interfaces with resources at our level + val actualInterfaces: List = typesGenerators.mapNotNull { typeGenerator -> + typeGenerator.generateActualInterface( + interfaces = expectInterfaces.filterNot { alreadyActualInterfaces.contains(it.name) }, + metadata = ownMetadata, + sourceSet = sourceSetName ) } - dummyInterfaces - .forEach { result -> + actualInterfaces.forEach { result -> fileSpec.addType(result.typeSpec) outputMetadata.add(result.metadata) } - // then we should generate actual object - val objects: List = typesGenerators.mapNotNull { typeGenerator -> - typeGenerator.generateActualObject( - objects = inputMetadata.mapNotNull { it as? ObjectMetadata }, - interfaces = inputMetadata.mapNotNull { it as? ActualInterfaceMetadata } + - (actualInterfaces + dummyInterfaces).map { it.metadata as ActualInterfaceMetadata } - ) - } - objects.forEach { outputMetadata.add(it.metadata) } + // then we should generate dummy actual interfaces + val dummyInterfaces: List = expectInterfaces.map { it.name } + .minus(actualInterfaces.map { (it.metadata as ActualInterfaceMetadata).name }.toSet()) + .map { dummyInterfaceName -> + GenerationResult( + typeSpec = TypeSpec.interfaceBuilder(dummyInterfaceName) + .addModifiers(visibilityModifier) + .addModifiers(KModifier.ACTUAL) + .build(), + metadata = ActualInterfaceMetadata( + name = dummyInterfaceName, + resources = emptyList() + ) + ) + } + + dummyInterfaces + .forEach { result -> + fileSpec.addType(result.typeSpec) + outputMetadata.add(result.metadata) + } + + // then we should generate actual object + val objects: List = typesGenerators.mapNotNull { typeGenerator -> + typeGenerator.generateActualObject( + objects = inputMetadata.mapNotNull { it as? ObjectMetadata }, + interfaces = inputMetadata.mapNotNull { it as? ActualInterfaceMetadata } + + (actualInterfaces + dummyInterfaces).map { it.metadata as ActualInterfaceMetadata } + ) + } + objects.forEach { outputMetadata.add(it.metadata) } - val objectSpec: TypeSpec.Builder = - TypeSpec.objectBuilder(resourcesClassName) // default: object MR - .addModifiers(KModifier.ACTUAL) - .addModifiers(visibilityModifier) + val objectSpec: TypeSpec.Builder = + TypeSpec.objectBuilder(resourcesClassName) // default: object MR + .addModifiers(KModifier.ACTUAL) + .addModifiers(visibilityModifier) - containerGenerator.getImports() - .plus(typesGenerators.flatMap { it.getImports() }) - .forEach { fileSpec.addImport(it.packageName, it.simpleNames) } + containerGenerator.getImports() + .plus(typesGenerators.flatMap { it.getImports() }) + .forEach { fileSpec.addImport(it.packageName, it.simpleNames) } - val contentHash: String = (inputMetadata + outputMetadata).mapNotNull { it.contentHash() } - .calculateHash() - objectSpec.addContentHashProperty(contentHash) + val contentHash: String = (inputMetadata + outputMetadata).mapNotNull { it.contentHash() } + .calculateHash() + objectSpec.addContentHashProperty(contentHash) - objectSpec.also(containerGenerator::generateBeforeTypes) + objectSpec.also(containerGenerator::generateBeforeTypes) - objects.forEach { objectSpec.addType(it.typeSpec) } + objects.forEach { objectSpec.addType(it.typeSpec) } - objectSpec.also(containerGenerator::generateAfterTypes) + objectSpec.also(containerGenerator::generateAfterTypes) - fileSpec.addType(objectSpec.build()) + fileSpec.addType(objectSpec.build()) + } // write file fileSpec.build().writeTo(sourcesGenerationDir) From 7a393eb16b90b6ee6b3a836bc909dee0704af2ff Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 7 Jan 2024 00:23:42 +0700 Subject: [PATCH 087/352] #535 assemble successful --- .../androidApp/build.gradle.kts | 4 +- .../kotlin-js-store/yarn.lock | 832 +++++++----------- 2 files changed, 303 insertions(+), 533 deletions(-) diff --git a/samples/compose-resources-gallery/androidApp/build.gradle.kts b/samples/compose-resources-gallery/androidApp/build.gradle.kts index 168b66b61..75953d8f7 100644 --- a/samples/compose-resources-gallery/androidApp/build.gradle.kts +++ b/samples/compose-resources-gallery/androidApp/build.gradle.kts @@ -18,11 +18,11 @@ kotlin { } android { - compileSdk = 33 + compileSdk = 34 defaultConfig { applicationId = "com.myapplication.MyApplication" minSdk = 26 - targetSdk = 33 + targetSdk = 34 versionCode = 1 versionName = "1.0" } diff --git a/samples/compose-resources-gallery/kotlin-js-store/yarn.lock b/samples/compose-resources-gallery/kotlin-js-store/yarn.lock index 44a669fe4..629709eae 100644 --- a/samples/compose-resources-gallery/kotlin-js-store/yarn.lock +++ b/samples/compose-resources-gallery/kotlin-js-store/yarn.lock @@ -2,27 +2,6 @@ # yarn lockfile v1 -"@babel/code-frame@^7.10.4": - version "7.21.4" - resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.21.4.tgz#d0fa9e4413aca81f2b23b9442797bda1826edb39" - integrity sha512-LYvhNKfwWSPpocw8GI7gpK2nq3HSDuEPC/uSYaALSJu9xjsalaaYFOq0Pwt5KmVqwEbZlDu81aLXwBOmD/Fv9g== - dependencies: - "@babel/highlight" "^7.18.6" - -"@babel/helper-validator-identifier@^7.18.6": - version "7.19.1" - resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.19.1.tgz#7eea834cf32901ffdc1a7ee555e2f9c27e249ca2" - integrity sha512-awrNfaMtnHUr653GgGEs++LlAvW6w+DcPrOliSMXWCKo597CwL5Acf/wWdNkf/tfEQE3mjkeD1YOVZOUV/od1w== - -"@babel/highlight@^7.18.6": - version "7.18.6" - resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.18.6.tgz#81158601e93e2563795adcbfbdf5d64be3f2ecdf" - integrity sha512-u7stbOuYjaPezCuLj29hNW1v64M2Md2qupEKP1fHc7WdOA3DgLh37suiSrZYY7haUB7iBeQZ9P1uiRF359do3g== - dependencies: - "@babel/helper-validator-identifier" "^7.18.6" - chalk "^2.0.0" - js-tokens "^4.0.0" - "@colors/colors@1.5.0": version "1.5.0" resolved "https://registry.yarnpkg.com/@colors/colors/-/colors-1.5.0.tgz#bb504579c1cae923e6576a4f5da43d25f97bdbd9" @@ -47,19 +26,16 @@ resolved "https://registry.yarnpkg.com/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz#2203b118c157721addfe69d47b70465463066d78" integrity sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w== +"@jridgewell/resolve-uri@^3.1.0": + version "3.1.1" + resolved "https://registry.yarnpkg.com/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz#c08679063f279615a3326583ba3a90d1d82cc721" + integrity sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA== + "@jridgewell/set-array@^1.0.1": version "1.1.2" resolved "https://registry.yarnpkg.com/@jridgewell/set-array/-/set-array-1.1.2.tgz#7c6cf998d6d20b914c0a55a91ae928ff25965e72" integrity sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw== -"@jridgewell/source-map@^0.3.2": - version "0.3.2" - resolved "https://registry.yarnpkg.com/@jridgewell/source-map/-/source-map-0.3.2.tgz#f45351aaed4527a298512ec72f81040c998580fb" - integrity sha512-m7O9o2uR8k2ObDysZYzdfhb08VuEml5oWGiosa1VdaPZ/A6QyPkAJuwN0Q1lhULOf6B7MtQmHENS743hWtCrgw== - dependencies: - "@jridgewell/gen-mapping" "^0.3.0" - "@jridgewell/trace-mapping" "^0.3.9" - "@jridgewell/source-map@^0.3.3": version "0.3.3" resolved "https://registry.yarnpkg.com/@jridgewell/source-map/-/source-map-0.3.3.tgz#8108265659d4c33e72ffe14e33d6cc5eb59f2fda" @@ -73,7 +49,20 @@ resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz#add4c98d341472a289190b424efbdb096991bb24" integrity sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw== -"@jridgewell/trace-mapping@^0.3.17", "@jridgewell/trace-mapping@^0.3.9": +"@jridgewell/sourcemap-codec@^1.4.14": + version "1.4.15" + resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz#d7c6e6755c78567a951e04ab52ef0fd26de59f32" + integrity sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg== + +"@jridgewell/trace-mapping@^0.3.20": + version "0.3.20" + resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.20.tgz#72e45707cf240fa6b081d0366f8265b0cd10197f" + integrity sha512-R8LcPeWZol2zR8mmH3JeKQ6QRCFb7XgUhV9ZlGhHLGyg4wpPiPZNQOOWhFZhxKw8u//yTbNGI42Bx/3paXEQ+Q== + dependencies: + "@jridgewell/resolve-uri" "^3.1.0" + "@jridgewell/sourcemap-codec" "^1.4.14" + +"@jridgewell/trace-mapping@^0.3.9": version "0.3.17" resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.17.tgz#793041277af9073b0951a7fe0f0d8c4c98c36985" integrity sha512-MCNzAp77qzKca9+W/+I0+sEpaUnZoeasnghNeVc41VZCEKaCH73Vq3BZZ/SzWIgrqE4H4ceI+p+b6C0mHf9T4g== @@ -122,48 +111,6 @@ dependencies: make-plural "^7.0.0" -"@rollup/plugin-commonjs@^21.0.1": - version "21.1.0" - resolved "https://registry.yarnpkg.com/@rollup/plugin-commonjs/-/plugin-commonjs-21.1.0.tgz#45576d7b47609af2db87f55a6d4b46e44fc3a553" - integrity sha512-6ZtHx3VHIp2ReNNDxHjuUml6ur+WcQ28N1yHgCQwsbNkQg2suhxGMDQGJOn/KuDxKtd1xuZP5xSTwBA4GQ8hbA== - dependencies: - "@rollup/pluginutils" "^3.1.0" - commondir "^1.0.1" - estree-walker "^2.0.1" - glob "^7.1.6" - is-reference "^1.2.1" - magic-string "^0.25.7" - resolve "^1.17.0" - -"@rollup/plugin-node-resolve@^13.1.3": - version "13.3.0" - resolved "https://registry.yarnpkg.com/@rollup/plugin-node-resolve/-/plugin-node-resolve-13.3.0.tgz#da1c5c5ce8316cef96a2f823d111c1e4e498801c" - integrity sha512-Lus8rbUo1eEcnS4yTFKLZrVumLPY+YayBdWXgFSHYhTT2iJbMhoaaBL3xl5NCdeRytErGr8tZ0L71BMRmnlwSw== - dependencies: - "@rollup/pluginutils" "^3.1.0" - "@types/resolve" "1.17.1" - deepmerge "^4.2.2" - is-builtin-module "^3.1.0" - is-module "^1.0.0" - resolve "^1.19.0" - -"@rollup/plugin-typescript@^8.3.0": - version "8.5.0" - resolved "https://registry.yarnpkg.com/@rollup/plugin-typescript/-/plugin-typescript-8.5.0.tgz#7ea11599a15b0a30fa7ea69ce3b791d41b862515" - integrity sha512-wMv1/scv0m/rXx21wD2IsBbJFba8wGF3ErJIr6IKRfRj49S85Lszbxb4DCo8iILpluTjk2GAAu9CoZt4G3ppgQ== - dependencies: - "@rollup/pluginutils" "^3.1.0" - resolve "^1.17.0" - -"@rollup/pluginutils@^3.0.9", "@rollup/pluginutils@^3.1.0": - version "3.1.0" - resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-3.1.0.tgz#706b4524ee6dc8b103b3c995533e5ad680c02b9b" - integrity sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg== - dependencies: - "@types/estree" "0.0.39" - estree-walker "^1.0.1" - picomatch "^2.2.2" - "@socket.io/component-emitter@~3.1.0": version "3.1.0" resolved "https://registry.yarnpkg.com/@socket.io/component-emitter/-/component-emitter-3.1.0.tgz#96116f2a912e0c02817345b3c10751069920d553" @@ -232,15 +179,10 @@ resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.0.tgz#5fb2e536c1ae9bf35366eed879e827fa59ca41c2" integrity sha512-WulqXMDUTYAXCjZnk6JtIHPigp55cVtDgDrO2gHRwhyJto21+1zbVCtOYB2L1F9w4qCQ0rOGWBnBe0FNTiEJIQ== -"@types/estree@0.0.39": - version "0.0.39" - resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f" - integrity sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw== - -"@types/estree@^0.0.51": - version "0.0.51" - resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.51.tgz#cfd70924a25a3fd32b218e5e420e6897e1ac4f40" - integrity sha512-CuPgU6f3eT/XgKKPqKd/gLZV1Xmvf1a2R5POBOGQa6uv82xpls89HU5zKeVoyR8XzHd1RGNOlQlvUe3CFkjWNQ== +"@types/estree@^1.0.0": + version "1.0.5" + resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.5.tgz#a6ce3e556e00fd9895dd872dd172ad0d4bd687f4" + integrity sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw== "@types/express-serve-static-core@*", "@types/express-serve-static-core@^4.17.33": version "4.17.33" @@ -278,16 +220,18 @@ resolved "https://registry.yarnpkg.com/@types/mime/-/mime-3.0.1.tgz#5f8f2bca0a5863cb69bc0b0acd88c96cb1d4ae10" integrity sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA== +"@types/node-forge@^1.3.0": + version "1.3.11" + resolved "https://registry.yarnpkg.com/@types/node-forge/-/node-forge-1.3.11.tgz#0972ea538ddb0f4d9c2fa0ec5db5724773a604da" + integrity sha512-FQx220y22OKNTqaByeBGqHWYz4cl94tpcxeFdvBo3wjG6XPBuZ0BNgNZRV5J5TFmmcsJ4IzsLkmGRiQbnYsBEQ== + dependencies: + "@types/node" "*" + "@types/node@*", "@types/node@>=10.0.0": version "18.15.1" resolved "https://registry.yarnpkg.com/@types/node/-/node-18.15.1.tgz#41dc2bf78e8085a250d4670d95edb7fba621dd29" integrity sha512-U2TWca8AeHSmbpi314QBESRk7oPjSZjDsR+c+H4ECC1l+kFgpZf8Ydhv3SJpPy51VyZHHqxlb6mTTqYNNRVAIw== -"@types/node@^12.12.14": - version "12.20.55" - resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.55.tgz#c329cbd434c42164f846b909bd6f85b5537f6240" - integrity sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ== - "@types/qs@*": version "6.9.7" resolved "https://registry.yarnpkg.com/@types/qs/-/qs-6.9.7.tgz#63bb7d067db107cc1e457c303bc25d511febf6cb" @@ -298,13 +242,6 @@ resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.4.tgz#cd667bcfdd025213aafb7ca5915a932590acdcdc" integrity sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw== -"@types/resolve@1.17.1": - version "1.17.1" - resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-1.17.1.tgz#3afd6ad8967c77e4376c598a82ddd58f46ec45d6" - integrity sha512-yy7HuzQhj0dhGpD8RLXSZWEkLsV9ibvxvi6EiJ3bkqLAO1RGo0WbkWQiwpRlSFymTJRz0d3k5LM3kkx8ArDbLw== - dependencies: - "@types/node" "*" - "@types/retry@0.12.0": version "0.12.0" resolved "https://registry.yarnpkg.com/@types/retry/-/retry-0.12.0.tgz#2b35eccfcee7d38cd72ad99232fbd58bffb3c84d" @@ -339,148 +276,141 @@ dependencies: "@types/node" "*" -"@ungap/promise-all-settled@1.1.2": - version "1.1.2" - resolved "https://registry.yarnpkg.com/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz#aa58042711d6e3275dd37dc597e5d31e8c290a44" - integrity sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q== - -"@webassemblyjs/ast@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.11.1.tgz#2bfd767eae1a6996f432ff7e8d7fc75679c0b6a7" - integrity sha512-ukBh14qFLjxTQNTXocdyksN5QdM28S1CxHt2rdskFyL+xFV7VremuBLVbmCePj+URalXBENx/9Lm7lnhihtCSw== - dependencies: - "@webassemblyjs/helper-numbers" "1.11.1" - "@webassemblyjs/helper-wasm-bytecode" "1.11.1" - -"@webassemblyjs/floating-point-hex-parser@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.11.1.tgz#f6c61a705f0fd7a6aecaa4e8198f23d9dc179e4f" - integrity sha512-iGRfyc5Bq+NnNuX8b5hwBrRjzf0ocrJPI6GWFodBFzmFnyvrQ83SHKhmilCU/8Jv67i4GJZBMhEzltxzcNagtQ== - -"@webassemblyjs/helper-api-error@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-api-error/-/helper-api-error-1.11.1.tgz#1a63192d8788e5c012800ba6a7a46c705288fd16" - integrity sha512-RlhS8CBCXfRUR/cwo2ho9bkheSXG0+NwooXcc3PAILALf2QLdFyj7KGsKRbVc95hZnhnERon4kW/D3SZpp6Tcg== - -"@webassemblyjs/helper-buffer@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.11.1.tgz#832a900eb444884cde9a7cad467f81500f5e5ab5" - integrity sha512-gwikF65aDNeeXa8JxXa2BAk+REjSyhrNC9ZwdT0f8jc4dQQeDQ7G4m0f2QCLPJiMTTO6wfDmRmj/pW0PsUvIcA== - -"@webassemblyjs/helper-numbers@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-numbers/-/helper-numbers-1.11.1.tgz#64d81da219fbbba1e3bd1bfc74f6e8c4e10a62ae" - integrity sha512-vDkbxiB8zfnPdNK9Rajcey5C0w+QJugEglN0of+kmO8l7lDb77AnlKYQF7aarZuCrv+l0UvqL+68gSDr3k9LPQ== - dependencies: - "@webassemblyjs/floating-point-hex-parser" "1.11.1" - "@webassemblyjs/helper-api-error" "1.11.1" +"@webassemblyjs/ast@1.11.6", "@webassemblyjs/ast@^1.11.5": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.11.6.tgz#db046555d3c413f8966ca50a95176a0e2c642e24" + integrity sha512-IN1xI7PwOvLPgjcf180gC1bqn3q/QaOCwYUahIOhbYUu8KA/3tw2RT/T0Gidi1l7Hhj5D/INhJxiICObqpMu4Q== + dependencies: + "@webassemblyjs/helper-numbers" "1.11.6" + "@webassemblyjs/helper-wasm-bytecode" "1.11.6" + +"@webassemblyjs/floating-point-hex-parser@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.11.6.tgz#dacbcb95aff135c8260f77fa3b4c5fea600a6431" + integrity sha512-ejAj9hfRJ2XMsNHk/v6Fu2dGS+i4UaXBXGemOfQ/JfQ6mdQg/WXtwleQRLLS4OvfDhv8rYnVwH27YJLMyYsxhw== + +"@webassemblyjs/helper-api-error@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-api-error/-/helper-api-error-1.11.6.tgz#6132f68c4acd59dcd141c44b18cbebbd9f2fa768" + integrity sha512-o0YkoP4pVu4rN8aTJgAyj9hC2Sv5UlkzCHhxqWj8butaLvnpdc2jOwh4ewE6CX0txSfLn/UYaV/pheS2Txg//Q== + +"@webassemblyjs/helper-buffer@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.11.6.tgz#b66d73c43e296fd5e88006f18524feb0f2c7c093" + integrity sha512-z3nFzdcp1mb8nEOFFk8DrYLpHvhKC3grJD2ardfKOzmbmJvEf/tPIqCY+sNcwZIY8ZD7IkB2l7/pqhUhqm7hLA== + +"@webassemblyjs/helper-numbers@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-numbers/-/helper-numbers-1.11.6.tgz#cbce5e7e0c1bd32cf4905ae444ef64cea919f1b5" + integrity sha512-vUIhZ8LZoIWHBohiEObxVm6hwP034jwmc9kuq5GdHZH0wiLVLIPcMCdpJzG4C11cHoQ25TFIQj9kaVADVX7N3g== + dependencies: + "@webassemblyjs/floating-point-hex-parser" "1.11.6" + "@webassemblyjs/helper-api-error" "1.11.6" "@xtuc/long" "4.2.2" -"@webassemblyjs/helper-wasm-bytecode@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.11.1.tgz#f328241e41e7b199d0b20c18e88429c4433295e1" - integrity sha512-PvpoOGiJwXeTrSf/qfudJhwlvDQxFgelbMqtq52WWiXC6Xgg1IREdngmPN3bs4RoO83PnL/nFrxucXj1+BX62Q== +"@webassemblyjs/helper-wasm-bytecode@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.11.6.tgz#bb2ebdb3b83aa26d9baad4c46d4315283acd51e9" + integrity sha512-sFFHKwcmBprO9e7Icf0+gddyWYDViL8bpPjJJl0WHxCdETktXdmtWLGVzoHbqUcY4Be1LkNfwTmXOJUFZYSJdA== -"@webassemblyjs/helper-wasm-section@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.11.1.tgz#21ee065a7b635f319e738f0dd73bfbda281c097a" - integrity sha512-10P9No29rYX1j7F3EVPX3JvGPQPae+AomuSTPiF9eBQeChHI6iqjMIwR9JmOJXwpnn/oVGDk7I5IlskuMwU/pg== +"@webassemblyjs/helper-wasm-section@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.11.6.tgz#ff97f3863c55ee7f580fd5c41a381e9def4aa577" + integrity sha512-LPpZbSOwTpEC2cgn4hTydySy1Ke+XEu+ETXuoyvuyezHO3Kjdu90KK95Sh9xTbmjrCsUwvWwCOQQNta37VrS9g== dependencies: - "@webassemblyjs/ast" "1.11.1" - "@webassemblyjs/helper-buffer" "1.11.1" - "@webassemblyjs/helper-wasm-bytecode" "1.11.1" - "@webassemblyjs/wasm-gen" "1.11.1" + "@webassemblyjs/ast" "1.11.6" + "@webassemblyjs/helper-buffer" "1.11.6" + "@webassemblyjs/helper-wasm-bytecode" "1.11.6" + "@webassemblyjs/wasm-gen" "1.11.6" -"@webassemblyjs/ieee754@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/ieee754/-/ieee754-1.11.1.tgz#963929e9bbd05709e7e12243a099180812992614" - integrity sha512-hJ87QIPtAMKbFq6CGTkZYJivEwZDbQUgYd3qKSadTNOhVY7p+gfP6Sr0lLRVTaG1JjFj+r3YchoqRYxNH3M0GQ== +"@webassemblyjs/ieee754@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/ieee754/-/ieee754-1.11.6.tgz#bb665c91d0b14fffceb0e38298c329af043c6e3a" + integrity sha512-LM4p2csPNvbij6U1f19v6WR56QZ8JcHg3QIJTlSwzFcmx6WSORicYj6I63f9yU1kEUtrpG+kjkiIAkevHpDXrg== dependencies: "@xtuc/ieee754" "^1.2.0" -"@webassemblyjs/leb128@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/leb128/-/leb128-1.11.1.tgz#ce814b45574e93d76bae1fb2644ab9cdd9527aa5" - integrity sha512-BJ2P0hNZ0u+Th1YZXJpzW6miwqQUGcIHT1G/sf72gLVD9DZ5AdYTqPNbHZh6K1M5VmKvFXwGSWZADz+qBWxeRw== +"@webassemblyjs/leb128@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/leb128/-/leb128-1.11.6.tgz#70e60e5e82f9ac81118bc25381a0b283893240d7" + integrity sha512-m7a0FhE67DQXgouf1tbN5XQcdWoNgaAuoULHIfGFIEVKA6tu/edls6XnIlkmS6FrXAquJRPni3ZZKjw6FSPjPQ== dependencies: "@xtuc/long" "4.2.2" -"@webassemblyjs/utf8@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/utf8/-/utf8-1.11.1.tgz#d1f8b764369e7c6e6bae350e854dec9a59f0a3ff" - integrity sha512-9kqcxAEdMhiwQkHpkNiorZzqpGrodQQ2IGrHHxCy+Ozng0ofyMA0lTqiLkVs1uzTRejX+/O0EOT7KxqVPuXosQ== - -"@webassemblyjs/wasm-edit@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-edit/-/wasm-edit-1.11.1.tgz#ad206ebf4bf95a058ce9880a8c092c5dec8193d6" - integrity sha512-g+RsupUC1aTHfR8CDgnsVRVZFJqdkFHpsHMfJuWQzWU3tvnLC07UqHICfP+4XyL2tnr1amvl1Sdp06TnYCmVkA== - dependencies: - "@webassemblyjs/ast" "1.11.1" - "@webassemblyjs/helper-buffer" "1.11.1" - "@webassemblyjs/helper-wasm-bytecode" "1.11.1" - "@webassemblyjs/helper-wasm-section" "1.11.1" - "@webassemblyjs/wasm-gen" "1.11.1" - "@webassemblyjs/wasm-opt" "1.11.1" - "@webassemblyjs/wasm-parser" "1.11.1" - "@webassemblyjs/wast-printer" "1.11.1" - -"@webassemblyjs/wasm-gen@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-gen/-/wasm-gen-1.11.1.tgz#86c5ea304849759b7d88c47a32f4f039ae3c8f76" - integrity sha512-F7QqKXwwNlMmsulj6+O7r4mmtAlCWfO/0HdgOxSklZfQcDu0TpLiD1mRt/zF25Bk59FIjEuGAIyn5ei4yMfLhA== - dependencies: - "@webassemblyjs/ast" "1.11.1" - "@webassemblyjs/helper-wasm-bytecode" "1.11.1" - "@webassemblyjs/ieee754" "1.11.1" - "@webassemblyjs/leb128" "1.11.1" - "@webassemblyjs/utf8" "1.11.1" - -"@webassemblyjs/wasm-opt@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-opt/-/wasm-opt-1.11.1.tgz#657b4c2202f4cf3b345f8a4c6461c8c2418985f2" - integrity sha512-VqnkNqnZlU5EB64pp1l7hdm3hmQw7Vgqa0KF/KCNO9sIpI6Fk6brDEiX+iCOYrvMuBWDws0NkTOxYEb85XQHHw== - dependencies: - "@webassemblyjs/ast" "1.11.1" - "@webassemblyjs/helper-buffer" "1.11.1" - "@webassemblyjs/wasm-gen" "1.11.1" - "@webassemblyjs/wasm-parser" "1.11.1" - -"@webassemblyjs/wasm-parser@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.11.1.tgz#86ca734534f417e9bd3c67c7a1c75d8be41fb199" - integrity sha512-rrBujw+dJu32gYB7/Lup6UhdkPx9S9SnobZzRVL7VcBH9Bt9bCBLEuX/YXOOtBsOZ4NQrRykKhffRWHvigQvOA== - dependencies: - "@webassemblyjs/ast" "1.11.1" - "@webassemblyjs/helper-api-error" "1.11.1" - "@webassemblyjs/helper-wasm-bytecode" "1.11.1" - "@webassemblyjs/ieee754" "1.11.1" - "@webassemblyjs/leb128" "1.11.1" - "@webassemblyjs/utf8" "1.11.1" - -"@webassemblyjs/wast-printer@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-printer/-/wast-printer-1.11.1.tgz#d0c73beda8eec5426f10ae8ef55cee5e7084c2f0" - integrity sha512-IQboUWM4eKzWW+N/jij2sRatKMh99QEelo3Eb2q0qXkvPRISAj8Qxtmw5itwqK+TTkBuUIE45AxYPToqPtL5gg== - dependencies: - "@webassemblyjs/ast" "1.11.1" +"@webassemblyjs/utf8@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/utf8/-/utf8-1.11.6.tgz#90f8bc34c561595fe156603be7253cdbcd0fab5a" + integrity sha512-vtXf2wTQ3+up9Zsg8sa2yWiQpzSsMyXj0qViVP6xKGCUT8p8YJ6HqI7l5eCnWx1T/FYdsv07HQs2wTFbbof/RA== + +"@webassemblyjs/wasm-edit@^1.11.5": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-edit/-/wasm-edit-1.11.6.tgz#c72fa8220524c9b416249f3d94c2958dfe70ceab" + integrity sha512-Ybn2I6fnfIGuCR+Faaz7YcvtBKxvoLV3Lebn1tM4o/IAJzmi9AWYIPWpyBfU8cC+JxAO57bk4+zdsTjJR+VTOw== + dependencies: + "@webassemblyjs/ast" "1.11.6" + "@webassemblyjs/helper-buffer" "1.11.6" + "@webassemblyjs/helper-wasm-bytecode" "1.11.6" + "@webassemblyjs/helper-wasm-section" "1.11.6" + "@webassemblyjs/wasm-gen" "1.11.6" + "@webassemblyjs/wasm-opt" "1.11.6" + "@webassemblyjs/wasm-parser" "1.11.6" + "@webassemblyjs/wast-printer" "1.11.6" + +"@webassemblyjs/wasm-gen@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-gen/-/wasm-gen-1.11.6.tgz#fb5283e0e8b4551cc4e9c3c0d7184a65faf7c268" + integrity sha512-3XOqkZP/y6B4F0PBAXvI1/bky7GryoogUtfwExeP/v7Nzwo1QLcq5oQmpKlftZLbT+ERUOAZVQjuNVak6UXjPA== + dependencies: + "@webassemblyjs/ast" "1.11.6" + "@webassemblyjs/helper-wasm-bytecode" "1.11.6" + "@webassemblyjs/ieee754" "1.11.6" + "@webassemblyjs/leb128" "1.11.6" + "@webassemblyjs/utf8" "1.11.6" + +"@webassemblyjs/wasm-opt@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-opt/-/wasm-opt-1.11.6.tgz#d9a22d651248422ca498b09aa3232a81041487c2" + integrity sha512-cOrKuLRE7PCe6AsOVl7WasYf3wbSo4CeOk6PkrjS7g57MFfVUF9u6ysQBBODX0LdgSvQqRiGz3CXvIDKcPNy4g== + dependencies: + "@webassemblyjs/ast" "1.11.6" + "@webassemblyjs/helper-buffer" "1.11.6" + "@webassemblyjs/wasm-gen" "1.11.6" + "@webassemblyjs/wasm-parser" "1.11.6" + +"@webassemblyjs/wasm-parser@1.11.6", "@webassemblyjs/wasm-parser@^1.11.5": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.11.6.tgz#bb85378c527df824004812bbdb784eea539174a1" + integrity sha512-6ZwPeGzMJM3Dqp3hCsLgESxBGtT/OeCvCZ4TA1JUPYgmhAx38tTPR9JaKy0S5H3evQpO/h2uWs2j6Yc/fjkpTQ== + dependencies: + "@webassemblyjs/ast" "1.11.6" + "@webassemblyjs/helper-api-error" "1.11.6" + "@webassemblyjs/helper-wasm-bytecode" "1.11.6" + "@webassemblyjs/ieee754" "1.11.6" + "@webassemblyjs/leb128" "1.11.6" + "@webassemblyjs/utf8" "1.11.6" + +"@webassemblyjs/wast-printer@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-printer/-/wast-printer-1.11.6.tgz#a7bf8dd7e362aeb1668ff43f35cb849f188eff20" + integrity sha512-JM7AhRcE+yW2GWYaKeHL5vt4xqee5N2WcezptmgyhNS+ScggqcT1OtXykhAb13Sn5Yas0j2uv9tHgrjwvzAP4A== + dependencies: + "@webassemblyjs/ast" "1.11.6" "@xtuc/long" "4.2.2" -"@webpack-cli/configtest@^1.2.0": - version "1.2.0" - resolved "https://registry.yarnpkg.com/@webpack-cli/configtest/-/configtest-1.2.0.tgz#7b20ce1c12533912c3b217ea68262365fa29a6f5" - integrity sha512-4FB8Tj6xyVkyqjj1OaTqCjXYULB9FMkqQ8yGrZjRDrYh0nOE+7Lhs45WioWQQMV+ceFlE368Ukhe6xdvJM9Egg== +"@webpack-cli/configtest@^2.1.0": + version "2.1.1" + resolved "https://registry.yarnpkg.com/@webpack-cli/configtest/-/configtest-2.1.1.tgz#3b2f852e91dac6e3b85fb2a314fb8bef46d94646" + integrity sha512-wy0mglZpDSiSS0XHrVR+BAdId2+yxPSoJW8fsna3ZpYSlufjvxnP4YbKTCBZnNIcGN4r6ZPXV55X4mYExOfLmw== -"@webpack-cli/info@^1.5.0": - version "1.5.0" - resolved "https://registry.yarnpkg.com/@webpack-cli/info/-/info-1.5.0.tgz#6c78c13c5874852d6e2dd17f08a41f3fe4c261b1" - integrity sha512-e8tSXZpw2hPl2uMJY6fsMswaok5FdlGNRTktvFk2sD8RjH0hE2+XistawJx1vmKteh4NmGmNUrp+Tb2w+udPcQ== - dependencies: - envinfo "^7.7.3" +"@webpack-cli/info@^2.0.1": + version "2.0.2" + resolved "https://registry.yarnpkg.com/@webpack-cli/info/-/info-2.0.2.tgz#cc3fbf22efeb88ff62310cf885c5b09f44ae0fdd" + integrity sha512-zLHQdI/Qs1UyT5UBdWNqsARasIA+AaF8t+4u2aS2nEpBQh2mWIVb8qAklq0eUENnC5mOItrIB4LiS9xMtph18A== -"@webpack-cli/serve@^1.7.0": - version "1.7.0" - resolved "https://registry.yarnpkg.com/@webpack-cli/serve/-/serve-1.7.0.tgz#e1993689ac42d2b16e9194376cfb6753f6254db1" - integrity sha512-oxnCNGj88fL+xzV+dacXs44HcDwf1ovs3AuEzvP7mqXw7fQntqIhQ1BRmynh4qEKQSSSRSWVyXRjmTbZIX9V2Q== +"@webpack-cli/serve@^2.0.3": + version "2.0.5" + resolved "https://registry.yarnpkg.com/@webpack-cli/serve/-/serve-2.0.5.tgz#325db42395cd49fe6c14057f9a900e427df8810e" + integrity sha512-lqaoKnRYBdo1UgDX8uF24AfGMifWK19TxPmM5FHc2vAGxrJ/qtyUyFBWoY1tISZdelsQ5fBcOusifo5o5wSJxQ== "@xtuc/ieee754@^1.2.0": version "1.2.0" @@ -510,7 +440,7 @@ acorn-import-assertions@^1.7.6: resolved "https://registry.yarnpkg.com/acorn-import-assertions/-/acorn-import-assertions-1.8.0.tgz#ba2b5939ce62c238db6d93d81c9b111b29b855e9" integrity sha512-m7VZ3jwz4eK6A4Vtt8Ew1/mNbP24u0FhdyfA7fSvnJR6LMdfOYnmuIrrJAgrYfYJ10F/otaHTtrtrtmHdMNzEw== -acorn@^8.5.0, acorn@^8.7.1, acorn@^8.8.2: +acorn@^8.7.1, acorn@^8.8.2: version "8.8.2" resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.8.2.tgz#1b2f25db02af965399b9776b0c2c391276d37c4a" integrity sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw== @@ -569,13 +499,6 @@ ansi-regex@^5.0.1: resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304" integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ== -ansi-styles@^3.2.1: - version "3.2.1" - resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d" - integrity sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA== - dependencies: - color-convert "^1.9.0" - ansi-styles@^4.0.0, ansi-styles@^4.1.0: version "4.3.0" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.3.0.tgz#edd803628ae71c04c85ae7a0906edad34b648937" @@ -606,11 +529,6 @@ array-flatten@^2.1.2: resolved "https://registry.yarnpkg.com/array-flatten/-/array-flatten-2.1.2.tgz#24ef80a28c1a893617e2149b0c6d0d788293b099" integrity sha512-hNfzcOV8W4NdualtqBFPyVO+54DSJuZGY9qT4pRroB6S9e3iiido2ISIC5h9R2sPJ8H3FHCIiEnsv1lPXO3KtQ== -atob@^2.1.2: - version "2.1.2" - resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9" - integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg== - balanced-match@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" @@ -728,11 +646,6 @@ buffer-from@^1.0.0: resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.2.tgz#2b146a6fd72e80b4f55d255f35ed59a3a9a41bd5" integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ== -builtin-modules@^3.3.0: - version "3.3.0" - resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-3.3.0.tgz#cae62812b89801e9656336e46223e030386be7b6" - integrity sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw== - bytes@3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.0.0.tgz#d32815404d689699f85a4ea4fa8755dd13a96048" @@ -761,15 +674,6 @@ caniuse-lite@^1.0.30001449: resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001465.tgz#c1b715bbb4ff6fdc20a4827e0afe9f4374fca217" integrity sha512-HvjgL3MYAJjceTDCcjRnQGjwUz/5qec9n7JPOzUursUoOTIsYCSDOb1l7RsnZE8mjbxG78zVRCKfrBXyvChBag== -chalk@^2.0.0: - version "2.4.2" - resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" - integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== - dependencies: - ansi-styles "^3.2.1" - escape-string-regexp "^1.0.5" - supports-color "^5.3.0" - chalk@^4.1.0: version "4.1.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01" @@ -816,13 +720,6 @@ clone-deep@^4.0.1: kind-of "^6.0.2" shallow-clone "^3.0.0" -color-convert@^1.9.0: - version "1.9.3" - resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8" - integrity sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg== - dependencies: - color-name "1.1.3" - color-convert@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3" @@ -830,11 +727,6 @@ color-convert@^2.0.1: dependencies: color-name "~1.1.4" -color-name@1.1.3: - version "1.1.3" - resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25" - integrity sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw== - color-name@~1.1.4: version "1.1.4" resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" @@ -845,21 +737,16 @@ colorette@^2.0.10, colorette@^2.0.14: resolved "https://registry.yarnpkg.com/colorette/-/colorette-2.0.19.tgz#cdf044f47ad41a0f4b56b3a0d5b4e6e1a2d5a798" integrity sha512-3tlv/dIP7FWvj3BsbHrGLJ6l/oKh1O3TcgBqMn+yyCagOxc23fyzDS6HypQbgxWbkpDnf52p1LuR4eWDQ/K9WQ== +commander@^10.0.1: + version "10.0.1" + resolved "https://registry.yarnpkg.com/commander/-/commander-10.0.1.tgz#881ee46b4f77d1c1dccc5823433aa39b022cbe06" + integrity sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug== + commander@^2.20.0: version "2.20.3" resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ== -commander@^7.0.0: - version "7.2.0" - resolved "https://registry.yarnpkg.com/commander/-/commander-7.2.0.tgz#a36cb57d0b501ce108e4d20559a150a391d97ab7" - integrity sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw== - -commondir@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b" - integrity sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg== - compressible@~2.0.16: version "2.0.18" resolved "https://registry.yarnpkg.com/compressible/-/compressible-2.0.18.tgz#af53cca6b070d4c3c0750fbd77286a6d7cc46fba" @@ -997,16 +884,6 @@ decamelize@^4.0.0: resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-4.0.0.tgz#aa472d7bf660eb15f3494efd531cab7f2a709837" integrity sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ== -decode-uri-component@^0.2.0: - version "0.2.2" - resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.2.tgz#e69dbe25d37941171dd540e024c444cd5188e1e9" - integrity sha512-FqUYQ+8o158GyGTrMFJms9qh3CqTKvAqgqsTnkLI8sKu0028orqBhxNMFkFen0zGyg6epACD32pjVk58ngIErQ== - -deepmerge@^4.2.2: - version "4.3.1" - resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-4.3.1.tgz#44b5f2147cd3b00d4b56137685966f26fd25dd4a" - integrity sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A== - default-gateway@^6.0.3: version "6.0.3" resolved "https://registry.yarnpkg.com/default-gateway/-/default-gateway-6.0.3.tgz#819494c888053bdb743edbf343d6cdf7f2943a71" @@ -1112,10 +989,10 @@ engine.io@~6.4.1: engine.io-parser "~5.0.3" ws "~8.11.0" -enhanced-resolve@^5.10.0: - version "5.12.0" - resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.12.0.tgz#300e1c90228f5b570c4d35babf263f6da7155634" - integrity sha512-QHTXI/sZQmko1cbDoNAa3mJ5qhWUUNAq3vR0/YiD379fWQrcfuoX1+HW2S0MTt7XmoPLapdaDKUtelUSPic7hQ== +enhanced-resolve@^5.13.0: + version "5.15.0" + resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.15.0.tgz#1af946c7d93603eb88e9896cee4904dc012e9c35" + integrity sha512-LXYT42KJ7lpIKECr2mAXIaMldcNCh/7E0KBKOu4KSfkHmP+mZmSs+8V5gBAqisWBy0OO4W5Oyys0GO1Y8KtdKg== dependencies: graceful-fs "^4.2.4" tapable "^2.2.0" @@ -1130,10 +1007,10 @@ envinfo@^7.7.3: resolved "https://registry.yarnpkg.com/envinfo/-/envinfo-7.8.1.tgz#06377e3e5f4d379fea7ac592d5ad8927e0c4d475" integrity sha512-/o+BXHmB7ocbHEAs6F2EnG0ogybVVUdkRunTT2glZU9XAaGmhqskrvKwqXuDfNjEO0LZKWdejEEpnq8aM0tOaw== -es-module-lexer@^0.9.0: - version "0.9.3" - resolved "https://registry.yarnpkg.com/es-module-lexer/-/es-module-lexer-0.9.3.tgz#6f13db00cc38417137daf74366f535c8eb438f19" - integrity sha512-1HQ2M2sPtxwnvOvT1ZClHyQDiggdNjURWpY2we6aMKCQiUVxTmVs2UYPLIrD84sS+kMdUwfBSylbJPwNnBrnHQ== +es-module-lexer@^1.2.1: + version "1.4.1" + resolved "https://registry.yarnpkg.com/es-module-lexer/-/es-module-lexer-1.4.1.tgz#41ea21b43908fe6a287ffcbe4300f790555331f5" + integrity sha512-cXLGjP0c4T3flZJKQSuziYoq7MlT+rnvfZjfp7h+I7K9BNX54kP9nyWvdbwjQ4u1iWbOL4u96fgeZLToQlZC7w== escalade@^3.1.1: version "3.1.1" @@ -1150,11 +1027,6 @@ escape-string-regexp@4.0.0: resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34" integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA== -escape-string-regexp@^1.0.5: - version "1.0.5" - resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" - integrity sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg== - eslint-scope@5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c" @@ -1180,16 +1052,6 @@ estraverse@^5.2.0: resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-5.3.0.tgz#2eea5290702f26ab8fe5370370ff86c965d21123" integrity sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA== -estree-walker@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-1.0.1.tgz#31bc5d612c96b704106b477e6dd5d8aa138cb700" - integrity sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg== - -estree-walker@^2.0.1: - version "2.0.2" - resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-2.0.2.tgz#52f010178c2a4c117a7757cfe942adb7d2da4cac" - integrity sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w== - etag@~1.8.1: version "1.8.1" resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887" @@ -1348,7 +1210,7 @@ follow-redirects@^1.0.0: resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== -format-util@1.0.5, format-util@^1.0.5: +format-util@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/format-util/-/format-util-1.0.5.tgz#1ffb450c8a03e7bccffe40643180918cc297d271" integrity sha512-varLbTj0e0yVyRpqQhuWV+8hlePAgaoFRhNFj50BNjEIrw1/DphHSObtqwskVCPWNgzwPoQrZAbfa/SBiicNeg== @@ -1392,6 +1254,11 @@ function-bind@^1.1.1: resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d" integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A== +function-bind@^1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.2.tgz#2c02d864d97f3ea6c8830c464cbd11ab6eab7a1c" + integrity sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA== + get-caller-file@^2.0.5: version "2.0.5" resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e" @@ -1435,7 +1302,7 @@ glob@7.2.0: once "^1.3.0" path-is-absolute "^1.0.0" -glob@^7.1.3, glob@^7.1.6, glob@^7.1.7: +glob@^7.1.3, glob@^7.1.7: version "7.2.3" resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.3.tgz#b8df0fb802bbfa8e89bd1d938b4e16578ed44f2b" integrity sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q== @@ -1452,16 +1319,16 @@ graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.4, resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.10.tgz#147d3a006da4ca3ce14728c7aefc287c367d7a6c" integrity sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA== +graceful-fs@^4.2.10: + version "4.2.11" + resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3" + integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ== + handle-thing@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/handle-thing/-/handle-thing-2.0.1.tgz#857f79ce359580c340d43081cc648970d0bb234e" integrity sha512-9Qn4yBxelxoh2Ow62nP+Ka/kMnOXRi8BXnRaUwezLNhqelnN49xKz4F/dPP8OYLxLxq6JDtZb2i9XznUQbNPTg== -has-flag@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd" - integrity sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw== - has-flag@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b" @@ -1479,6 +1346,13 @@ has@^1.0.3: dependencies: function-bind "^1.1.1" +hasown@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/hasown/-/hasown-2.0.0.tgz#f4c513d454a57b7c7e1650778de226b11700546c" + integrity sha512-vUptKVTpIJhcczKBbgnS+RtcuYMB8+oNzPK2/Hp3hanz8JmpATdmmgLgSaadVREkDm+e2giHwY3ZRkyjSIDDFA== + dependencies: + function-bind "^1.1.2" + he@1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f" @@ -1600,10 +1474,10 @@ inherits@2.0.3: resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" integrity sha512-x00IRNXNy63jwGkJmzPigoySHbaqpNuzKbBOmzK+g2OdZpQ9w+sxCN+VSB3ja7IAge2OP2qpfxTjeNcyjmW1uw== -interpret@^2.2.0: - version "2.2.0" - resolved "https://registry.yarnpkg.com/interpret/-/interpret-2.2.0.tgz#1a78a0b5965c40a5416d007ad6f50ad27c417df9" - integrity sha512-Ju0Bz/cEia55xDwUWEa8+olFpCiQoypjnQySseKtmjNrnps3P+xfpUmGr90T7yjlVJmOtybRvPXhKMbHr+fWnw== +interpret@^3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/interpret/-/interpret-3.1.1.tgz#5be0ceed67ca79c6c4bc5cf0d7ee843dcea110c4" + integrity sha512-6xwYfHbajpoF0xLW+iwLkhwgvLoZDfjYfoFNu8ftMoXINzwuymNLd9u/KmwtdT2GbR+/Cz66otEGEVVUHX9QLQ== ipaddr.js@1.9.1: version "1.9.1" @@ -1635,26 +1509,12 @@ is-binary-path@~2.1.0: dependencies: binary-extensions "^2.0.0" -is-builtin-module@^3.1.0: - version "3.2.1" - resolved "https://registry.yarnpkg.com/is-builtin-module/-/is-builtin-module-3.2.1.tgz#f03271717d8654cfcaf07ab0463faa3571581169" - integrity sha512-BSLE3HnV2syZ0FK0iMA/yUGplUeMmNz4AW5fnTunbCIqZi4vG3WjJT9FHMy5D69xmAYBHXQhJdALdpwVxV501A== - dependencies: - builtin-modules "^3.3.0" - -is-core-module@^2.11.0: - version "2.12.1" - resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.12.1.tgz#0c0b6885b6f80011c71541ce15c8d66cf5a4f9fd" - integrity sha512-Q4ZuBAe2FUsKtyQJoQHlvP8OvBERxO3jEmy1I7hcRXcJBGGHFh/aJBswbXuS9sgrDH2QUO8ilkwNPHvHMd8clg== +is-core-module@^2.13.0: + version "2.13.1" + resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.13.1.tgz#ad0d7532c6fea9da1ebdc82742d74525c6273384" + integrity sha512-hHrIjvZsftOsvKSn2TRYl63zvxsgE0K+0mYMoH6gD4omR5IWB2KynivBQczo3+wF1cCkjzvptnI9Q0sPU66ilw== dependencies: - has "^1.0.3" - -is-core-module@^2.9.0: - version "2.11.0" - resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.11.0.tgz#ad4cb3e3863e814523c96f3f58d26cc570ff0144" - integrity sha512-RRjxlvLDkD1YJwDbroBHMb+cukurkDWNyHx7D3oNB5x9rb5ogcksMC5wHCadcXoo67gVr/+3GFySh3134zi6rw== - dependencies: - has "^1.0.3" + hasown "^2.0.0" is-decimal@^2.0.0: version "2.0.1" @@ -1683,11 +1543,6 @@ is-glob@^4.0.1, is-glob@~4.0.1: dependencies: is-extglob "^2.1.1" -is-module@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/is-module/-/is-module-1.0.0.tgz#3258fb69f78c14d5b815d664336b4cffb6441591" - integrity sha512-51ypPSPCoTEIN9dy5Oy+h4pShgJmPCygKfyRCISBI+JoWT/2oJvK8QPxmwv7b/p239jXrm9M1mlQbyKJ5A152g== - is-number@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/is-number/-/is-number-7.0.0.tgz#7535345b896734d5f80c4d06c50955527a14f12b" @@ -1710,13 +1565,6 @@ is-plain-object@^2.0.4: dependencies: isobject "^3.0.1" -is-reference@^1.2.1: - version "1.2.1" - resolved "https://registry.yarnpkg.com/is-reference/-/is-reference-1.2.1.tgz#8b2dac0b371f4bc994fdeaba9eb542d03002d0b7" - integrity sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ== - dependencies: - "@types/estree" "*" - is-stream@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-2.0.1.tgz#fac1e3d53b97ad5a9d0ae9cef2389f5810a5c077" @@ -1754,15 +1602,6 @@ isobject@^3.0.1: resolved "https://registry.yarnpkg.com/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df" integrity sha512-WhB9zCku7EGTj/HQQRz5aUQEUeoQZH2bWcltRErOpymJ4boYE6wL9Tbr23krRPSZ+C5zqNSrSw+Cc7sZZ4b7vg== -jest-worker@^26.2.1: - version "26.6.2" - resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-26.6.2.tgz#7f72cbc4d643c365e27b9fd775f9d0eaa9c7a8ed" - integrity sha512-KWYVV1c4i+jbMpaBC+U++4Va0cp8OisU185o73T1vo99hqi7w8tSJfUXYswwqqrjzwxa6KpRK54WhPvwf5w6PQ== - dependencies: - "@types/node" "*" - merge-stream "^2.0.0" - supports-color "^7.0.0" - jest-worker@^27.4.5: version "27.5.1" resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-27.5.1.tgz#8d146f0900e8973b106b6f73cc1e9a8cb86f8db0" @@ -1772,11 +1611,6 @@ jest-worker@^27.4.5: merge-stream "^2.0.0" supports-color "^8.0.0" -js-tokens@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" - integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ== - js-yaml@4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.0.tgz#c1fb65f8f5017901cdd2c951864ba18458a10602" @@ -1806,10 +1640,10 @@ jsonfile@^4.0.0: optionalDependencies: graceful-fs "^4.1.6" -karma-chrome-launcher@3.1.1: - version "3.1.1" - resolved "https://registry.yarnpkg.com/karma-chrome-launcher/-/karma-chrome-launcher-3.1.1.tgz#baca9cc071b1562a1db241827257bfe5cab597ea" - integrity sha512-hsIglcq1vtboGPAN+DGCISCFOxW+ZVnIqhDQcCMqqCp+4dmJ0Qpq5QAjkbA0X2L9Mi6OBkHi2Srrbmm7pUKkzQ== +karma-chrome-launcher@3.2.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/karma-chrome-launcher/-/karma-chrome-launcher-3.2.0.tgz#eb9c95024f2d6dfbb3748d3415ac9b381906b9a9" + integrity sha512-rE9RkUPI7I9mAxByQWkGJFXfFD6lE4gC5nPuZdobf/QdTEJI6EU4yIay/cfU/xV4ZxlM5JiTv7zWYgA64NpS5Q== dependencies: which "^1.2.1" @@ -1820,12 +1654,12 @@ karma-mocha@2.0.1: dependencies: minimist "^1.2.3" -karma-sourcemap-loader@0.3.8: - version "0.3.8" - resolved "https://registry.yarnpkg.com/karma-sourcemap-loader/-/karma-sourcemap-loader-0.3.8.tgz#d4bae72fb7a8397328a62b75013d2df937bdcf9c" - integrity sha512-zorxyAakYZuBcHRJE+vbrK2o2JXLFWK8VVjiT/6P+ltLBUGUvqTEkUiQ119MGdOrK7mrmxXHZF1/pfT6GgIZ6g== +karma-sourcemap-loader@0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/karma-sourcemap-loader/-/karma-sourcemap-loader-0.4.0.tgz#b01d73f8f688f533bcc8f5d273d43458e13b5488" + integrity sha512-xCRL3/pmhAYF3I6qOrcn0uhbQevitc2DERMPH82FMnG+4WReoGcGFZb1pURf2a5apyrOHRdvD+O6K7NljqKHyA== dependencies: - graceful-fs "^4.1.2" + graceful-fs "^4.2.10" karma-webpack@5.0.0: version "5.0.0" @@ -1836,10 +1670,10 @@ karma-webpack@5.0.0: minimatch "^3.0.4" webpack-merge "^4.1.5" -karma@6.4.0: - version "6.4.0" - resolved "https://registry.yarnpkg.com/karma/-/karma-6.4.0.tgz#82652dfecdd853ec227b74ed718a997028a99508" - integrity sha512-s8m7z0IF5g/bS5ONT7wsOavhW4i4aFkzD4u4wgzAQWT4HGUeWI3i21cK2Yz6jndMAeHETp5XuNsRoyGJZXVd4w== +karma@6.4.2: + version "6.4.2" + resolved "https://registry.yarnpkg.com/karma/-/karma-6.4.2.tgz#a983f874cee6f35990c4b2dcc3d274653714de8e" + integrity sha512-C6SU/53LB31BEgRg+omznBEMY4SjHU3ricV6zBcAe1EeILKkeScr+fZXtaI5WyDbkVowJxxAI6h73NcFPmXolQ== dependencies: "@colors/colors" "1.5.0" body-parser "^1.19.0" @@ -1871,6 +1705,14 @@ kind-of@^6.0.2: resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.3.tgz#07c05034a6c349fa06e24fa35aa76db4580ce4dd" integrity sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw== +launch-editor@^2.6.0: + version "2.6.1" + resolved "https://registry.yarnpkg.com/launch-editor/-/launch-editor-2.6.1.tgz#f259c9ef95cbc9425620bbbd14b468fcdb4ffe3c" + integrity sha512-eB/uXmFVpY4zezmGp5XtU21kwo7GBbKB+EQ+UZeWtGb9yAM5xt/Evk+lYH3eRNAtId+ej4u7TYPFZ07w4s7rRw== + dependencies: + picocolors "^1.0.0" + shell-quote "^1.8.1" + loader-runner@^4.2.0: version "4.3.0" resolved "https://registry.yarnpkg.com/loader-runner/-/loader-runner-4.3.0.tgz#c1b4a163b99f614830353b16755e7149ac2314e1" @@ -1921,13 +1763,6 @@ lru-cache@^6.0.0: dependencies: yallist "^4.0.0" -magic-string@^0.25.7: - version "0.25.9" - resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.25.9.tgz#de7f9faf91ef8a1c91d02c2e5314c8277dbcdd1c" - integrity sha512-RmF0AsMzgt25qzqqLc1+MbHmhdx0ojF2Fvs4XnOqz2ZOBXzzkEwc/dJQZCYHAn7v1jbVOjAZfK8msRn4BxO4VQ== - dependencies: - sourcemap-codec "^1.4.8" - make-plural@^7.0.0: version "7.2.0" resolved "https://registry.yarnpkg.com/make-plural/-/make-plural-7.2.0.tgz#93174b1419672a48a2340db6c1d3fb217530c684" @@ -2033,12 +1868,11 @@ mkdirp@^0.5.5: dependencies: minimist "^1.2.6" -mocha@10.0.0: - version "10.0.0" - resolved "https://registry.yarnpkg.com/mocha/-/mocha-10.0.0.tgz#205447d8993ec755335c4b13deba3d3a13c4def9" - integrity sha512-0Wl+elVUD43Y0BqPZBzZt8Tnkw9CMUdNYnUsTfOM1vuhJVZL+kiesFYsqwBkEEuEixaiPe5ZQdqDgX2jddhmoA== +mocha@10.2.0: + version "10.2.0" + resolved "https://registry.yarnpkg.com/mocha/-/mocha-10.2.0.tgz#1fd4a7c32ba5ac372e03a17eef435bd00e5c68b8" + integrity sha512-IDY7fl/BecMwFHzoqF2sg/SHHANeBoMMXFlS9r0OXKDssYE1M5O43wUY/9BVPeIvfH2zmEbBfseqN9gBQZzXkg== dependencies: - "@ungap/promise-all-settled" "1.1.2" ansi-colors "4.1.1" browser-stdout "1.3.1" chokidar "3.5.3" @@ -2264,7 +2098,7 @@ picocolors@^1.0.0: resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c" integrity sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ== -picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.2.2, picomatch@^2.3.1: +picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.3.1: version "2.3.1" resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42" integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA== @@ -2417,12 +2251,12 @@ readdirp@~3.6.0: dependencies: picomatch "^2.2.1" -rechoir@^0.7.0: - version "0.7.1" - resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.7.1.tgz#9478a96a1ca135b5e88fc027f03ee92d6c645686" - integrity sha512-/njmZ8s1wVeR6pjTZ+0nCnv8SpZNRMT2D1RLOJQESlYFDBvwpTA4KWJpZ+sBJ4+vhjILRcK7JIFdGCdxEAAitg== +rechoir@^0.8.0: + version "0.8.0" + resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.8.0.tgz#49f866e0d32146142da3ad8f0eff352b3215ff22" + integrity sha512-/vxpCXddiX8NGfGO/mTafwjq4aFa/71pvamip0++IQk3zG8cbCj0fifNPrjjF1XMXUne91jL9OoxmdykoEtifQ== dependencies: - resolve "^1.9.0" + resolve "^1.20.0" require-directory@^2.1.1: version "2.1.1" @@ -2451,21 +2285,12 @@ resolve-from@^5.0.0: resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-5.0.0.tgz#c35225843df8f776df21c57557bc087e9dfdfc69" integrity sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw== -resolve@^1.17.0, resolve@^1.19.0: - version "1.22.2" - resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.2.tgz#0ed0943d4e301867955766c9f3e1ae6d01c6845f" - integrity sha512-Sb+mjNHOULsBv818T40qSPeRiuWLyaGMa5ewydRLFimneixmVy2zdivRl+AF6jaYPC8ERxGDmFSiqui6SfPd+g== - dependencies: - is-core-module "^2.11.0" - path-parse "^1.0.7" - supports-preserve-symlinks-flag "^1.0.0" - -resolve@^1.9.0: - version "1.22.1" - resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.1.tgz#27cb2ebb53f91abb49470a928bba7558066ac177" - integrity sha512-nBpuuYuY5jFsli/JIs1oldw6fOQCBioohqWZg/2hiaOybXOft4lonv85uDOKXdf8rhyK159cxU5cDcK/NKk8zw== +resolve@^1.20.0: + version "1.22.8" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.8.tgz#b6c87a9f2aa06dfab52e3d70ac8cde321fa5a48d" + integrity sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw== dependencies: - is-core-module "^2.9.0" + is-core-module "^2.13.0" path-parse "^1.0.7" supports-preserve-symlinks-flag "^1.0.0" @@ -2486,31 +2311,6 @@ rimraf@^3.0.0, rimraf@^3.0.2: dependencies: glob "^7.1.3" -rollup-plugin-sourcemaps@^0.6.3: - version "0.6.3" - resolved "https://registry.yarnpkg.com/rollup-plugin-sourcemaps/-/rollup-plugin-sourcemaps-0.6.3.tgz#bf93913ffe056e414419607f1d02780d7ece84ed" - integrity sha512-paFu+nT1xvuO1tPFYXGe+XnQvg4Hjqv/eIhG8i5EspfYYPBKL57X7iVbfv55aNVASg3dzWvES9dmWsL2KhfByw== - dependencies: - "@rollup/pluginutils" "^3.0.9" - source-map-resolve "^0.6.0" - -rollup-plugin-terser@^7.0.2: - version "7.0.2" - resolved "https://registry.yarnpkg.com/rollup-plugin-terser/-/rollup-plugin-terser-7.0.2.tgz#e8fbba4869981b2dc35ae7e8a502d5c6c04d324d" - integrity sha512-w3iIaU4OxcF52UUXiZNsNeuXIMDvFrr+ZXK6bFZ0Q60qyVfq4uLptoS4bbq3paG3x216eQllFZX7zt6TIImguQ== - dependencies: - "@babel/code-frame" "^7.10.4" - jest-worker "^26.2.1" - serialize-javascript "^4.0.0" - terser "^5.0.0" - -rollup@^2.68.0: - version "2.79.1" - resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.79.1.tgz#bedee8faef7c9f93a2647ac0108748f497f081c7" - integrity sha512-uKxbd0IhMZOhjAiD5oAFp7BqvkA4Dv47qpOCtaNvng4HBwdbWtdOh8f5nZNuk2rp51PMGk3bzfWu5oayNEuYnw== - optionalDependencies: - fsevents "~2.3.2" - safe-buffer@5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1: version "5.1.2" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d" @@ -2531,7 +2331,7 @@ safe-identifier@^0.4.1: resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== -schema-utils@^3.1.0, schema-utils@^3.1.1: +schema-utils@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-3.1.1.tgz#bc74c4b6b6995c1d88f76a8b77bea7219e0c8281" integrity sha512-Y5PQxS4ITlC+EahLuXaY86TXfR7Dc5lw294alXOq86JAHCihAIZfqv8nNCWvaEJvaC51uN9hbLGeV0cFBdH+Fw== @@ -2540,6 +2340,15 @@ schema-utils@^3.1.0, schema-utils@^3.1.1: ajv "^6.12.5" ajv-keywords "^3.5.2" +schema-utils@^3.1.2: + version "3.3.0" + resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-3.3.0.tgz#f50a88877c3c01652a15b622ae9e9795df7a60fe" + integrity sha512-pN/yOAvcC+5rQ5nERGuwrjLlYvLTbCibnZ1I7B1LaiAz9BRBlE9GMgE/eqV30P7aJQUf7Ddimy/RsbYO/GrVGg== + dependencies: + "@types/json-schema" "^7.0.8" + ajv "^6.12.5" + ajv-keywords "^3.5.2" + schema-utils@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-4.0.0.tgz#60331e9e3ae78ec5d16353c467c34b3a0a1d3df7" @@ -2555,11 +2364,12 @@ select-hose@^2.0.0: resolved "https://registry.yarnpkg.com/select-hose/-/select-hose-2.0.0.tgz#625d8658f865af43ec962bfc376a37359a4994ca" integrity sha512-mEugaLK+YfkijB4fx0e6kImuJdCIt2LxCRcbEYPqRGCs4F2ogyfZU5IAZRdjCP8JPq2AtdNoC/Dux63d9Kiryg== -selfsigned@^2.0.1: - version "2.1.1" - resolved "https://registry.yarnpkg.com/selfsigned/-/selfsigned-2.1.1.tgz#18a7613d714c0cd3385c48af0075abf3f266af61" - integrity sha512-GSL3aowiF7wa/WtSFwnUrludWFoNhftq8bUkH9pkzjpN2XSPOAYEgg6e0sS9s0rZwgJzJiQRPU18A6clnoW5wQ== +selfsigned@^2.1.1: + version "2.4.1" + resolved "https://registry.yarnpkg.com/selfsigned/-/selfsigned-2.4.1.tgz#560d90565442a3ed35b674034cec4e95dceb4ae0" + integrity sha512-th5B4L2U+eGLq1TVh7zNRGBapioSORUeymIydxgFpwww9d2qyKvtuPU2jJuHvYAwwqi2Y596QBL3eEqcPEYL8Q== dependencies: + "@types/node-forge" "^1.3.0" node-forge "^1" semver@^7.3.8: @@ -2595,13 +2405,6 @@ serialize-javascript@6.0.0: dependencies: randombytes "^2.1.0" -serialize-javascript@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-4.0.0.tgz#b525e1238489a5ecfc42afacc3fe99e666f4b1aa" - integrity sha512-GaNA54380uFefWghODBWEGisLZFj00nS5ACs6yHa9nLqlLpVLO8ChDGeKRjZnV4Nh4n0Qi7nhYZD/9fCPzEqkw== - dependencies: - randombytes "^2.1.0" - serialize-javascript@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-6.0.1.tgz#b206efb27c3da0b0ab6b52f48d170b7996458e5c" @@ -2661,6 +2464,11 @@ shebang-regex@^3.0.0: resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172" integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A== +shell-quote@^1.8.1: + version "1.8.1" + resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.8.1.tgz#6dbf4db75515ad5bac63b4f1894c3a154c766680" + integrity sha512-6j1W9l1iAs/4xYBI1SYOVZyFcCis9b4KCLQ8fgAGG07QvzaRLVVRQvAy85yNmmZSjYjg4MWh4gNvlPujU/5LpA== + side-channel@^1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/side-channel/-/side-channel-1.0.4.tgz#efce5c8fdc104ee751b25c58d4290011fa5ea2cf" @@ -2716,23 +2524,15 @@ source-map-js@^1.0.2: resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.0.2.tgz#adbc361d9c62df380125e7f161f71c826f1e490c" integrity sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw== -source-map-loader@4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/source-map-loader/-/source-map-loader-4.0.0.tgz#bdc6b118bc6c87ee4d8d851f2d4efcc5abdb2ef5" - integrity sha512-i3KVgM3+QPAHNbGavK+VBq03YoJl24m9JWNbLgsjTj8aJzXG9M61bantBTNBt7CNwY2FYf+RJRYJ3pzalKjIrw== +source-map-loader@4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/source-map-loader/-/source-map-loader-4.0.1.tgz#72f00d05f5d1f90f80974eda781cbd7107c125f2" + integrity sha512-oqXpzDIByKONVY8g1NUPOTQhe0UTU5bWUl32GSkqK2LjJj0HmwTMVKxcUip0RgAYhY1mqgOxjbQM48a0mmeNfA== dependencies: abab "^2.0.6" iconv-lite "^0.6.3" source-map-js "^1.0.2" -source-map-resolve@^0.6.0: - version "0.6.0" - resolved "https://registry.yarnpkg.com/source-map-resolve/-/source-map-resolve-0.6.0.tgz#3d9df87e236b53f16d01e58150fc7711138e5ed2" - integrity sha512-KXBr9d/fO/bWo97NXsPIAW1bFSBOuCnjbNTBMO7N59hsv5i9yzRDfcYwwt0l04+VqnKC+EwzvJZIP/qkuMgR/w== - dependencies: - atob "^2.1.2" - decode-uri-component "^0.2.0" - source-map-support@~0.5.20: version "0.5.21" resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f" @@ -2746,11 +2546,6 @@ source-map@^0.6.0, source-map@^0.6.1: resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== -sourcemap-codec@^1.4.8: - version "1.4.8" - resolved "https://registry.yarnpkg.com/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz#ea804bd94857402e6992d05a38ef1ae35a9ab4c4" - integrity sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA== - spdy-transport@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/spdy-transport/-/spdy-transport-3.0.0.tgz#00d4863a6400ad75df93361a1608605e5dcdcf31" @@ -2845,14 +2640,7 @@ supports-color@8.1.1, supports-color@^8.0.0: dependencies: has-flag "^4.0.0" -supports-color@^5.3.0: - version "5.5.0" - resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f" - integrity sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow== - dependencies: - has-flag "^3.0.0" - -supports-color@^7.0.0, supports-color@^7.1.0: +supports-color@^7.1.0: version "7.2.0" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da" integrity sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw== @@ -2869,37 +2657,27 @@ tapable@^2.1.1, tapable@^2.2.0: resolved "https://registry.yarnpkg.com/tapable/-/tapable-2.2.1.tgz#1967a73ef4060a82f12ab96af86d52fdb76eeca0" integrity sha512-GNzQvQTOIP6RyTfE2Qxb8ZVlNmw0n88vp1szwWRimP02mnTsx3Wtn5qRdqY9w2XduFNUgvOwhNnQsjwCp+kqaQ== -terser-webpack-plugin@^5.1.3: - version "5.3.7" - resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-5.3.7.tgz#ef760632d24991760f339fe9290deb936ad1ffc7" - integrity sha512-AfKwIktyP7Cu50xNjXF/6Qb5lBNzYaWpU6YfoX3uZicTx0zTy0stDDCsvjDapKsSDvOeWo5MEq4TmdBy2cNoHw== +terser-webpack-plugin@^5.3.7: + version "5.3.10" + resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-5.3.10.tgz#904f4c9193c6fd2a03f693a2150c62a92f40d199" + integrity sha512-BKFPWlPDndPs+NGGCr1U59t0XScL5317Y0UReNrHaw9/FwhPENlq6bfgs+4yPfyP51vqC1bQ4rp1EfXW5ZSH9w== dependencies: - "@jridgewell/trace-mapping" "^0.3.17" + "@jridgewell/trace-mapping" "^0.3.20" jest-worker "^27.4.5" schema-utils "^3.1.1" serialize-javascript "^6.0.1" - terser "^5.16.5" + terser "^5.26.0" -terser@^5.0.0: - version "5.17.7" - resolved "https://registry.yarnpkg.com/terser/-/terser-5.17.7.tgz#2a8b134826fe179b711969fd9d9a0c2479b2a8c3" - integrity sha512-/bi0Zm2C6VAexlGgLlVxA0P2lru/sdLyfCVaRMfKVo9nWxbmz7f/sD8VPybPeSUJaJcwmCJis9pBIhcVcG1QcQ== +terser@^5.26.0: + version "5.26.0" + resolved "https://registry.yarnpkg.com/terser/-/terser-5.26.0.tgz#ee9f05d929f4189a9c28a0feb889d96d50126fe1" + integrity sha512-dytTGoE2oHgbNV9nTzgBEPaqAWvcJNl66VZ0BkJqlvp71IjO8CxdBx/ykCNb47cLnCmCvRZ6ZR0tLkqvZCdVBQ== dependencies: "@jridgewell/source-map" "^0.3.3" acorn "^8.8.2" commander "^2.20.0" source-map-support "~0.5.20" -terser@^5.16.5: - version "5.16.6" - resolved "https://registry.yarnpkg.com/terser/-/terser-5.16.6.tgz#f6c7a14a378ee0630fbe3ac8d1f41b4681109533" - integrity sha512-IBZ+ZQIA9sMaXmRZCUMDjNH0D5AQQfdn4WUjHL0+1lF4TP1IHRJbrhb6fNaXWikrYQTSkb7SLxkeXAiy1p7mbg== - dependencies: - "@jridgewell/source-map" "^0.3.2" - acorn "^8.5.0" - commander "^2.20.0" - source-map-support "~0.5.20" - thunky@^1.0.2: version "1.1.0" resolved "https://registry.yarnpkg.com/thunky/-/thunky-1.1.0.tgz#5abaf714a9405db0504732bbccd2cedd9ef9537d" @@ -2924,11 +2702,6 @@ toidentifier@1.0.1: resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.1.tgz#3be34321a88a820ed1bd80dfaa33e479fbb8dd35" integrity sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA== -tslib@^2.3.1: - version "2.5.3" - resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.3.tgz#24944ba2d990940e6e982c4bea147aba80209913" - integrity sha512-mSxlJJwl3BMEQCUNnxXBU9jP4JBktcEGhURcPR6VQVlnP0FdDEsIaz0C35dXNGLyRfrATNofF0F5p2KPxQgB+w== - type-is@~1.6.18: version "1.6.18" resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.18.tgz#4e552cd05df09467dcbc4ef739de89f2cf37c131" @@ -2937,15 +2710,10 @@ type-is@~1.6.18: media-typer "0.3.0" mime-types "~2.1.24" -typescript@4.7.4: - version "4.7.4" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.4.tgz#1a88596d1cf47d59507a1bcdfb5b9dfe4d488235" - integrity sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ== - -typescript@^3.7.2: - version "3.9.10" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.10.tgz#70f3910ac7a51ed6bef79da7800690b19bf778b8" - integrity sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q== +typescript@5.0.4: + version "5.0.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.0.4.tgz#b217fd20119bd61a94d4011274e0ab369058da3b" + integrity sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw== ua-parser-js@^0.7.30: version "0.7.34" @@ -3017,22 +2785,23 @@ wbuf@^1.1.0, wbuf@^1.7.3: dependencies: minimalistic-assert "^1.0.0" -webpack-cli@4.10.0: - version "4.10.0" - resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-4.10.0.tgz#37c1d69c8d85214c5a65e589378f53aec64dab31" - integrity sha512-NLhDfH/h4O6UOy+0LSso42xvYypClINuMNBVVzX4vX98TmTaTUxwRbXdhucbFMd2qLaCTcLq/PdYrvi8onw90w== +webpack-cli@5.1.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-5.1.0.tgz#abc4b1f44b50250f2632d8b8b536cfe2f6257891" + integrity sha512-a7KRJnCxejFoDpYTOwzm5o21ZXMaNqtRlvS183XzGDUPRdVEzJNImcQokqYZ8BNTnk9DkKiuWxw75+DCCoZ26w== dependencies: "@discoveryjs/json-ext" "^0.5.0" - "@webpack-cli/configtest" "^1.2.0" - "@webpack-cli/info" "^1.5.0" - "@webpack-cli/serve" "^1.7.0" + "@webpack-cli/configtest" "^2.1.0" + "@webpack-cli/info" "^2.0.1" + "@webpack-cli/serve" "^2.0.3" colorette "^2.0.14" - commander "^7.0.0" + commander "^10.0.1" cross-spawn "^7.0.3" + envinfo "^7.7.3" fastest-levenshtein "^1.0.12" import-local "^3.0.2" - interpret "^2.2.0" - rechoir "^0.7.0" + interpret "^3.1.1" + rechoir "^0.8.0" webpack-merge "^5.7.3" webpack-dev-middleware@^5.3.1: @@ -3046,10 +2815,10 @@ webpack-dev-middleware@^5.3.1: range-parser "^1.2.1" schema-utils "^4.0.0" -webpack-dev-server@4.9.3: - version "4.9.3" - resolved "https://registry.yarnpkg.com/webpack-dev-server/-/webpack-dev-server-4.9.3.tgz#2360a5d6d532acb5410a668417ad549ee3b8a3c9" - integrity sha512-3qp/eoboZG5/6QgiZ3llN8TUzkSpYg1Ko9khWX1h40MIEUNS2mDoIa8aXsPfskER+GbTvs/IJZ1QTBBhhuetSw== +webpack-dev-server@4.15.0: + version "4.15.0" + resolved "https://registry.yarnpkg.com/webpack-dev-server/-/webpack-dev-server-4.15.0.tgz#87ba9006eca53c551607ea0d663f4ae88be7af21" + integrity sha512-HmNB5QeSl1KpulTBQ8UT4FPrByYyaLxpJoQ0+s7EvUrMc16m0ZS1sgb1XGqzmgCPk0c9y+aaXxn11tbLzuM7NQ== dependencies: "@types/bonjour" "^3.5.9" "@types/connect-history-api-fallback" "^1.3.5" @@ -3070,16 +2839,17 @@ webpack-dev-server@4.9.3: html-entities "^2.3.2" http-proxy-middleware "^2.0.3" ipaddr.js "^2.0.1" + launch-editor "^2.6.0" open "^8.0.9" p-retry "^4.5.0" rimraf "^3.0.2" schema-utils "^4.0.0" - selfsigned "^2.0.1" + selfsigned "^2.1.1" serve-index "^1.9.1" sockjs "^0.3.24" spdy "^4.0.2" webpack-dev-middleware "^5.3.1" - ws "^8.4.2" + ws "^8.13.0" webpack-merge@^4.1.5: version "4.2.2" @@ -3101,22 +2871,22 @@ webpack-sources@^3.2.3: resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.2.3.tgz#2d4daab8451fd4b240cc27055ff6a0c2ccea0cde" integrity sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w== -webpack@5.74.0: - version "5.74.0" - resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.74.0.tgz#02a5dac19a17e0bb47093f2be67c695102a55980" - integrity sha512-A2InDwnhhGN4LYctJj6M1JEaGL7Luj6LOmyBHjcI8529cm5p6VXiTIW2sn6ffvEAKmveLzvu4jrihwXtPojlAA== +webpack@5.82.0: + version "5.82.0" + resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.82.0.tgz#3c0d074dec79401db026b4ba0fb23d6333f88e7d" + integrity sha512-iGNA2fHhnDcV1bONdUu554eZx+XeldsaeQ8T67H6KKHl2nUSwX8Zm7cmzOA46ox/X1ARxf7Bjv8wQ/HsB5fxBg== dependencies: "@types/eslint-scope" "^3.7.3" - "@types/estree" "^0.0.51" - "@webassemblyjs/ast" "1.11.1" - "@webassemblyjs/wasm-edit" "1.11.1" - "@webassemblyjs/wasm-parser" "1.11.1" + "@types/estree" "^1.0.0" + "@webassemblyjs/ast" "^1.11.5" + "@webassemblyjs/wasm-edit" "^1.11.5" + "@webassemblyjs/wasm-parser" "^1.11.5" acorn "^8.7.1" acorn-import-assertions "^1.7.6" browserslist "^4.14.5" chrome-trace-event "^1.0.2" - enhanced-resolve "^5.10.0" - es-module-lexer "^0.9.0" + enhanced-resolve "^5.13.0" + es-module-lexer "^1.2.1" eslint-scope "5.1.1" events "^3.2.0" glob-to-regexp "^0.4.1" @@ -3125,9 +2895,9 @@ webpack@5.74.0: loader-runner "^4.2.0" mime-types "^2.1.27" neo-async "^2.6.2" - schema-utils "^3.1.0" + schema-utils "^3.1.2" tapable "^2.1.1" - terser-webpack-plugin "^5.1.3" + terser-webpack-plugin "^5.3.7" watchpack "^2.4.0" webpack-sources "^3.2.3" @@ -3183,10 +2953,10 @@ wrappy@1: resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" integrity sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ== -ws@^8.4.2: - version "8.13.0" - resolved "https://registry.yarnpkg.com/ws/-/ws-8.13.0.tgz#9a9fb92f93cf41512a0735c8f4dd09b8a1211cd0" - integrity sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA== +ws@^8.13.0: + version "8.16.0" + resolved "https://registry.yarnpkg.com/ws/-/ws-8.16.0.tgz#d1cd774f36fbc07165066a60e40323eab6446fd4" + integrity sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ== ws@~8.11.0: version "8.11.0" From 7e721b606f74ca6fccfedb6d92cc8a580fc7b43f Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 7 Jan 2024 23:42:29 +0700 Subject: [PATCH 088/352] #535 successful run all supported targets on compose sample --- .../gradle/MultiplatformResourcesPlugin.kt | 18 +- .../gradle.properties | 2 +- .../kotlin-js-store/yarn.lock | 163 ++++++++++-------- .../shared/build.gradle.kts | 4 + 4 files changed, 100 insertions(+), 87 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index f384ed197..acf3e505a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -6,6 +6,7 @@ package dev.icerock.gradle import com.android.build.api.dsl.AndroidSourceSet import com.android.build.gradle.api.BaseVariant +import com.android.build.gradle.internal.lint.AndroidLintAnalysisTask import dev.icerock.gradle.generator.apple.setupAppleKLibResources import dev.icerock.gradle.generator.apple.setupFatFrameworkTasks import dev.icerock.gradle.generator.apple.setupFrameworkResources @@ -234,6 +235,12 @@ open class MultiplatformResourcesPlugin : Plugin { @Suppress("DEPRECATION") val androidVariant: BaseVariant = compilation.androidVariant androidVariant.preBuildProvider.configure { it.dependsOn(genTaskProvider) } + + // TODO this way do more than required - we trigger generate all android related resources at all + project.tasks.withType().configureEach { + it.logger.warn("${it.name} depends on $genTaskProvider") + it.dependsOn(genTaskProvider) + } } private fun setupAppleTasks( @@ -362,17 +369,6 @@ open class MultiplatformResourcesPlugin : Plugin { } } -private fun KotlinSourceSet.whenDependsOn(sourceSetName: String, action: () -> Unit) { - if (this.name == sourceSetName) { - action() - } - - dependsOnObservable.forAll { dependencySourceSet -> - if (dependencySourceSet.name == sourceSetName) action() - else dependencySourceSet.whenDependsOn(sourceSetName, action) - } -} - internal fun mokoResourcesSourceDirectoryKey() = extrasKeyOf("moko-resources-source-directory") diff --git a/samples/compose-resources-gallery/gradle.properties b/samples/compose-resources-gallery/gradle.properties index 71545320b..78b79350f 100644 --- a/samples/compose-resources-gallery/gradle.properties +++ b/samples/compose-resources-gallery/gradle.properties @@ -14,5 +14,5 @@ kotlin.mpp.androidGradlePluginCompatibility.nowarn=true # Enable kotlin/native experimental memory model kotlin.native.binary.memoryModel=experimental kotlin.version=1.9.21 -agp.version=8.0.2 +agp.version=8.1.0 compose.version=1.5.11 diff --git a/samples/compose-resources-gallery/kotlin-js-store/yarn.lock b/samples/compose-resources-gallery/kotlin-js-store/yarn.lock index 629709eae..a2e17b6a1 100644 --- a/samples/compose-resources-gallery/kotlin-js-store/yarn.lock +++ b/samples/compose-resources-gallery/kotlin-js-store/yarn.lock @@ -117,32 +117,32 @@ integrity sha512-+9jVqKhRSpsc591z5vX+X5Yyw+he/HCB4iQ/RYxw35CEPaY1gnsNE43nf9n9AaYjAQrTiI/mOwKUKdUs9vf7Xg== "@types/body-parser@*": - version "1.19.2" - resolved "https://registry.yarnpkg.com/@types/body-parser/-/body-parser-1.19.2.tgz#aea2059e28b7658639081347ac4fab3de166e6f0" - integrity sha512-ALYone6pm6QmwZoAgeyNksccT9Q4AWZQ6PvfwR37GT6r6FWUPguq6sUmNGSMV2Wr761oQoBxwGGa6DR5o1DC9g== + version "1.19.5" + resolved "https://registry.yarnpkg.com/@types/body-parser/-/body-parser-1.19.5.tgz#04ce9a3b677dc8bd681a17da1ab9835dc9d3ede4" + integrity sha512-fB3Zu92ucau0iQ0JMCFQE7b/dv8Ot07NI3KaZIkIUNXq82k4eBAqUaneXfleGY9JWskeS9y+u0nXMyspcuQrCg== dependencies: "@types/connect" "*" "@types/node" "*" "@types/bonjour@^3.5.9": - version "3.5.10" - resolved "https://registry.yarnpkg.com/@types/bonjour/-/bonjour-3.5.10.tgz#0f6aadfe00ea414edc86f5d106357cda9701e275" - integrity sha512-p7ienRMiS41Nu2/igbJxxLDWrSZ0WxM8UQgCeO9KhoVF7cOVFkrKsiDr1EsJIla8vV3oEEjGcz11jc5yimhzZw== + version "3.5.13" + resolved "https://registry.yarnpkg.com/@types/bonjour/-/bonjour-3.5.13.tgz#adf90ce1a105e81dd1f9c61fdc5afda1bfb92956" + integrity sha512-z9fJ5Im06zvUL548KvYNecEVlA7cVDkGUi6kZusb04mpyEFKCIZJvloCcmpmLaIahDpOQGHaHmG6imtPMmPXGQ== dependencies: "@types/node" "*" "@types/connect-history-api-fallback@^1.3.5": - version "1.3.5" - resolved "https://registry.yarnpkg.com/@types/connect-history-api-fallback/-/connect-history-api-fallback-1.3.5.tgz#d1f7a8a09d0ed5a57aee5ae9c18ab9b803205dae" - integrity sha512-h8QJa8xSb1WD4fpKBDcATDNGXghFj6/3GRWG6dhmRcu0RX1Ubasur2Uvx5aeEwlf0MwblEC2bMzzMQntxnw/Cw== + version "1.5.4" + resolved "https://registry.yarnpkg.com/@types/connect-history-api-fallback/-/connect-history-api-fallback-1.5.4.tgz#7de71645a103056b48ac3ce07b3520b819c1d5b3" + integrity sha512-n6Cr2xS1h4uAulPRdlw6Jl6s1oG8KrVilPN2yUITEs+K48EzMJJ3W1xy8K5eWuFvjp3R74AOIGSmp2UfBJ8HFw== dependencies: "@types/express-serve-static-core" "*" "@types/node" "*" "@types/connect@*": - version "3.4.35" - resolved "https://registry.yarnpkg.com/@types/connect/-/connect-3.4.35.tgz#5fcf6ae445e4021d1fc2219a4873cc73a3bb2ad1" - integrity sha512-cdeYyv4KWoEgpBISTxWvqYsVy444DOqehiF3fM3ne10AmJ62RSyNkUnxMJXHQWRQQX2eR94m5y1IZyDwBjV9FQ== + version "3.4.38" + resolved "https://registry.yarnpkg.com/@types/connect/-/connect-3.4.38.tgz#5ba7f3bc4fbbdeaff8dded952e5ff2cc53f8d858" + integrity sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug== dependencies: "@types/node" "*" @@ -185,28 +185,34 @@ integrity sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw== "@types/express-serve-static-core@*", "@types/express-serve-static-core@^4.17.33": - version "4.17.33" - resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.33.tgz#de35d30a9d637dc1450ad18dd583d75d5733d543" - integrity sha512-TPBqmR/HRYI3eC2E5hmiivIzv+bidAfXofM+sbonAGvyDhySGw9/PQZFt2BLOrjUUR++4eJVpx6KnLQK1Fk9tA== + version "4.17.41" + resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.41.tgz#5077defa630c2e8d28aa9ffc2c01c157c305bef6" + integrity sha512-OaJ7XLaelTgrvlZD8/aa0vvvxZdUmlCn6MtWeB7TkiKW70BQLc9XEPpDLPdbo52ZhXUCrznlWdCHWxJWtdyajA== dependencies: "@types/node" "*" "@types/qs" "*" "@types/range-parser" "*" + "@types/send" "*" "@types/express@*", "@types/express@^4.17.13": - version "4.17.17" - resolved "https://registry.yarnpkg.com/@types/express/-/express-4.17.17.tgz#01d5437f6ef9cfa8668e616e13c2f2ac9a491ae4" - integrity sha512-Q4FmmuLGBG58btUnfS1c1r/NQdlp3DMfGDGig8WhfpA2YRUtEkxAjkZb0yvplJGYdF1fsQ81iMDcH24sSCNC/Q== + version "4.17.21" + resolved "https://registry.yarnpkg.com/@types/express/-/express-4.17.21.tgz#c26d4a151e60efe0084b23dc3369ebc631ed192d" + integrity sha512-ejlPM315qwLpaQlQDTjPdsUFSc6ZsP4AN6AlWnogPjQ7CVi7PYF3YVz+CY3jE2pwYf7E/7HlDAN0rV2GxTG0HQ== dependencies: "@types/body-parser" "*" "@types/express-serve-static-core" "^4.17.33" "@types/qs" "*" "@types/serve-static" "*" +"@types/http-errors@*": + version "2.0.4" + resolved "https://registry.yarnpkg.com/@types/http-errors/-/http-errors-2.0.4.tgz#7eb47726c391b7345a6ec35ad7f4de469cf5ba4f" + integrity sha512-D0CFMMtydbJAegzOyHjtiKPLlvnm3iTZyZRSZoLq2mRhDdmLfIWOCYPfQJ4cu2erKghU++QvjcUjp/5h7hESpA== + "@types/http-proxy@^1.17.8": - version "1.17.10" - resolved "https://registry.yarnpkg.com/@types/http-proxy/-/http-proxy-1.17.10.tgz#e576c8e4a0cc5c6a138819025a88e167ebb38d6c" - integrity sha512-Qs5aULi+zV1bwKAg5z1PWnDXWmsn+LxIvUGv6E2+OOMYhclZMO+OXd9pYVf2gLykf2I7IV2u7oTHwChPNsvJ7g== + version "1.17.14" + resolved "https://registry.yarnpkg.com/@types/http-proxy/-/http-proxy-1.17.14.tgz#57f8ccaa1c1c3780644f8a94f9c6b5000b5e2eec" + integrity sha512-SSrD0c1OQzlFX7pGu1eXxSEjemej64aaNPRhhVYUGqXh0BtldAAx37MG8btcumvpgKyZp1F5Gn3JkktdxiFv6w== dependencies: "@types/node" "*" @@ -216,9 +222,14 @@ integrity sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ== "@types/mime@*": - version "3.0.1" - resolved "https://registry.yarnpkg.com/@types/mime/-/mime-3.0.1.tgz#5f8f2bca0a5863cb69bc0b0acd88c96cb1d4ae10" - integrity sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA== + version "3.0.4" + resolved "https://registry.yarnpkg.com/@types/mime/-/mime-3.0.4.tgz#2198ac274de6017b44d941e00261d5bc6a0e0a45" + integrity sha512-iJt33IQnVRkqeqC7PzBHPTC6fDlRNRW8vjrgqtScAhrmMwe8c4Eo7+fUGTa+XdWrpEgpyKWMYmi2dIwMAYRzPw== + +"@types/mime@^1": + version "1.3.5" + resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.5.tgz#1ef302e01cf7d2b5a0fa526790c9123bf1d06690" + integrity sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w== "@types/node-forge@^1.3.0": version "1.3.11" @@ -233,46 +244,55 @@ integrity sha512-U2TWca8AeHSmbpi314QBESRk7oPjSZjDsR+c+H4ECC1l+kFgpZf8Ydhv3SJpPy51VyZHHqxlb6mTTqYNNRVAIw== "@types/qs@*": - version "6.9.7" - resolved "https://registry.yarnpkg.com/@types/qs/-/qs-6.9.7.tgz#63bb7d067db107cc1e457c303bc25d511febf6cb" - integrity sha512-FGa1F62FT09qcrueBA6qYTrJPVDzah9a+493+o2PCXsesWHIn27G98TsSMs3WPNbZIEj4+VJf6saSFpvD+3Zsw== + version "6.9.11" + resolved "https://registry.yarnpkg.com/@types/qs/-/qs-6.9.11.tgz#208d8a30bc507bd82e03ada29e4732ea46a6bbda" + integrity sha512-oGk0gmhnEJK4Yyk+oI7EfXsLayXatCWPHary1MtcmbAifkobT9cM9yutG/hZKIseOU0MqbIwQ/u2nn/Gb+ltuQ== "@types/range-parser@*": - version "1.2.4" - resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.4.tgz#cd667bcfdd025213aafb7ca5915a932590acdcdc" - integrity sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw== + version "1.2.7" + resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.7.tgz#50ae4353eaaddc04044279812f52c8c65857dbcb" + integrity sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ== "@types/retry@0.12.0": version "0.12.0" resolved "https://registry.yarnpkg.com/@types/retry/-/retry-0.12.0.tgz#2b35eccfcee7d38cd72ad99232fbd58bffb3c84d" integrity sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA== +"@types/send@*": + version "0.17.4" + resolved "https://registry.yarnpkg.com/@types/send/-/send-0.17.4.tgz#6619cd24e7270793702e4e6a4b958a9010cfc57a" + integrity sha512-x2EM6TJOybec7c52BX0ZspPodMsQUd5L6PRwOunVyVUhXiBSKf3AezDL8Dgvgt5o0UfKNfuA0eMLr2wLT4AiBA== + dependencies: + "@types/mime" "^1" + "@types/node" "*" + "@types/serve-index@^1.9.1": - version "1.9.1" - resolved "https://registry.yarnpkg.com/@types/serve-index/-/serve-index-1.9.1.tgz#1b5e85370a192c01ec6cec4735cf2917337a6278" - integrity sha512-d/Hs3nWDxNL2xAczmOVZNj92YZCS6RGxfBPjKzuu/XirCgXdpKEb88dYNbrYGint6IVWLNP+yonwVAuRC0T2Dg== + version "1.9.4" + resolved "https://registry.yarnpkg.com/@types/serve-index/-/serve-index-1.9.4.tgz#e6ae13d5053cb06ed36392110b4f9a49ac4ec898" + integrity sha512-qLpGZ/c2fhSs5gnYsQxtDEq3Oy8SXPClIXkW5ghvAvsNuVSA8k+gCONcUCS/UjLEYvYps+e8uBtfgXgvhwfNug== dependencies: "@types/express" "*" "@types/serve-static@*", "@types/serve-static@^1.13.10": - version "1.15.1" - resolved "https://registry.yarnpkg.com/@types/serve-static/-/serve-static-1.15.1.tgz#86b1753f0be4f9a1bee68d459fcda5be4ea52b5d" - integrity sha512-NUo5XNiAdULrJENtJXZZ3fHtfMolzZwczzBbnAeBbqBwG+LaG6YaJtuwzwGSQZ2wsCrxjEhNNjAkKigy3n8teQ== + version "1.15.5" + resolved "https://registry.yarnpkg.com/@types/serve-static/-/serve-static-1.15.5.tgz#15e67500ec40789a1e8c9defc2d32a896f05b033" + integrity sha512-PDRk21MnK70hja/YF8AHfC7yIsiQHn1rcXx7ijCFBX/k+XQJhQT/gw3xekXKJvx+5SXaMMS8oqQy09Mzvz2TuQ== dependencies: + "@types/http-errors" "*" "@types/mime" "*" "@types/node" "*" "@types/sockjs@^0.3.33": - version "0.3.33" - resolved "https://registry.yarnpkg.com/@types/sockjs/-/sockjs-0.3.33.tgz#570d3a0b99ac995360e3136fd6045113b1bd236f" - integrity sha512-f0KEEe05NvUnat+boPTZ0dgaLZ4SfSouXUgv5noUiefG2ajgKjmETo9ZJyuqsl7dfl2aHlLJUiki6B4ZYldiiw== + version "0.3.36" + resolved "https://registry.yarnpkg.com/@types/sockjs/-/sockjs-0.3.36.tgz#ce322cf07bcc119d4cbf7f88954f3a3bd0f67535" + integrity sha512-MK9V6NzAS1+Ud7JV9lJLFqW85VbC9dq3LmwZCuBe4wBDgKC0Kj/jd8Xl+nSviU+Qc3+m7umHHyHg//2KSa0a0Q== dependencies: "@types/node" "*" "@types/ws@^8.5.1": - version "8.5.4" - resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.4.tgz#bb10e36116d6e570dd943735f86c933c1587b8a5" - integrity sha512-zdQDHKUgcX/zBc4GrwsE/7dVdAD8JR4EuiAXiiUhhfyIJXXb2+PrGshFyeXWQPMmmZ2XxgaqclgpIC7eTXc1mg== + version "8.5.10" + resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.10.tgz#4acfb517970853fa6574a3a6886791d04a396787" + integrity sha512-vmQSUcfalpIq0R9q7uTo2lXs6eGIpt9wtnLdMv9LVpIjCA/+ufZRozlVoVelIYixx1ugCBKDhn89vnsEGOCx9A== dependencies: "@types/node" "*" @@ -524,11 +544,6 @@ array-flatten@1.1.1: resolved "https://registry.yarnpkg.com/array-flatten/-/array-flatten-1.1.1.tgz#9a5f699051b1e7073328f2a008968b64ea2955d2" integrity sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg== -array-flatten@^2.1.2: - version "2.1.2" - resolved "https://registry.yarnpkg.com/array-flatten/-/array-flatten-2.1.2.tgz#24ef80a28c1a893617e2149b0c6d0d788293b099" - integrity sha512-hNfzcOV8W4NdualtqBFPyVO+54DSJuZGY9qT4pRroB6S9e3iiido2ISIC5h9R2sPJ8H3FHCIiEnsv1lPXO3KtQ== - balanced-match@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" @@ -595,12 +610,10 @@ body-parser@^1.19.0: unpipe "1.0.0" bonjour-service@^1.0.11: - version "1.1.0" - resolved "https://registry.yarnpkg.com/bonjour-service/-/bonjour-service-1.1.0.tgz#424170268d68af26ff83a5c640b95def01803a13" - integrity sha512-LVRinRB3k1/K0XzZ2p58COnWvkQknIY6sf0zF2rpErvcJXpMBttEPQSxK+HEXSS9VmpZlDoDnQWv8ftJT20B0Q== + version "1.2.0" + resolved "https://registry.yarnpkg.com/bonjour-service/-/bonjour-service-1.2.0.tgz#1c56da07a76e33b049ba7d865859abee5297f55a" + integrity sha512-xdzMA6JGckxyJzZByjEWRcfKmDxXaGXZWVftah3FkCqdlePNS9DjHSUN5zkP4oEfz/t0EXXlro88EIhzwMB4zA== dependencies: - array-flatten "^2.1.2" - dns-equal "^1.0.0" fast-deep-equal "^3.1.3" multicast-dns "^7.2.5" @@ -732,7 +745,12 @@ color-name@~1.1.4: resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== -colorette@^2.0.10, colorette@^2.0.14: +colorette@^2.0.10: + version "2.0.20" + resolved "https://registry.yarnpkg.com/colorette/-/colorette-2.0.20.tgz#9eb793e6833067f7235902fcd3b09917a000a95a" + integrity sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w== + +colorette@^2.0.14: version "2.0.19" resolved "https://registry.yarnpkg.com/colorette/-/colorette-2.0.19.tgz#cdf044f47ad41a0f4b56b3a0d5b4e6e1a2d5a798" integrity sha512-3tlv/dIP7FWvj3BsbHrGLJ6l/oKh1O3TcgBqMn+yyCagOxc23fyzDS6HypQbgxWbkpDnf52p1LuR4eWDQ/K9WQ== @@ -926,15 +944,10 @@ diff@5.0.0: resolved "https://registry.yarnpkg.com/diff/-/diff-5.0.0.tgz#7ed6ad76d859d030787ec35855f5b1daf31d852b" integrity sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w== -dns-equal@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/dns-equal/-/dns-equal-1.0.0.tgz#b39e7f1da6eb0a75ba9c17324b34753c47e0654d" - integrity sha512-z+paD6YUQsk+AbGCEM4PrOXSss5gd66QfcVBFTKR/HpFL9jCqikS94HYwKww6fQyO7IxrIIyUu+g0Ka9tUS2Cg== - dns-packet@^5.2.2: - version "5.4.0" - resolved "https://registry.yarnpkg.com/dns-packet/-/dns-packet-5.4.0.tgz#1f88477cf9f27e78a213fb6d118ae38e759a879b" - integrity sha512-EgqGeaBB8hLiHLZtp/IbaDQTL8pZ0+IvwzSHA6d7VyMDM+B9hgddEMa9xjK5oYnw0ci0JQ6g2XCD7/f6cafU6g== + version "5.6.1" + resolved "https://registry.yarnpkg.com/dns-packet/-/dns-packet-5.6.1.tgz#ae888ad425a9d1478a0674256ab866de1012cf2f" + integrity sha512-l4gcSouhcgIKRvyy99RNVOgxXiicE+2jZoNmaNmZ6JXiGajBOJAesk1OBlJuM5k2c+eudGdLxDqXuPCKIj6kpw== dependencies: "@leichtgewicht/ip-codec" "^2.0.1" @@ -1234,10 +1247,10 @@ fs-extra@^8.1.0: jsonfile "^4.0.0" universalify "^0.1.0" -fs-monkey@^1.0.3: - version "1.0.3" - resolved "https://registry.yarnpkg.com/fs-monkey/-/fs-monkey-1.0.3.tgz#ae3ac92d53bb328efe0e9a1d9541f6ad8d48e2d3" - integrity sha512-cybjIfiiE+pTWicSCLFHSrXZ6EilF30oh91FDP9S2B051prEa7QWfrVTQm10/dDpswBDXZugPa1Ogu8Yh+HV0Q== +fs-monkey@^1.0.4: + version "1.0.5" + resolved "https://registry.yarnpkg.com/fs-monkey/-/fs-monkey-1.0.5.tgz#fe450175f0db0d7ea758102e1d84096acb925788" + integrity sha512-8uMbBjrhzW76TYgEV27Y5E//W2f/lTFmx78P2w19FZSxarhI/798APGQyuGCwmkNxgwGRhrLfvWyLBvNtuOmew== fs.realpath@^1.0.0: version "1.0.0" @@ -1369,9 +1382,9 @@ hpack.js@^2.1.6: wbuf "^1.1.0" html-entities@^2.3.2: - version "2.3.3" - resolved "https://registry.yarnpkg.com/html-entities/-/html-entities-2.3.3.tgz#117d7626bece327fc8baace8868fa6f5ef856e46" - integrity sha512-DV5Ln36z34NNTDgnz0EWGBLZENelNAtkiFA4kyNOG2tDI6Mz1uSWiq1wAKdyjnJwyDiDO7Fa2SO1CTxPXL8VxA== + version "2.4.0" + resolved "https://registry.yarnpkg.com/html-entities/-/html-entities-2.4.0.tgz#edd0cee70402584c8c76cc2c0556db09d1f45061" + integrity sha512-igBTJcNNNhvZFRtm8uA6xMY6xYleeDwn3PeBCkDz7tHttv4F2hsDI2aPgNERWzvRcNYHNT3ymRaQzllmXj4YsQ== http-deceiver@^1.2.7: version "1.2.7" @@ -1485,9 +1498,9 @@ ipaddr.js@1.9.1: integrity sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g== ipaddr.js@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-2.0.1.tgz#eca256a7a877e917aeb368b0a7497ddf42ef81c0" - integrity sha512-1qTgH9NG+IIJ4yfKs2e6Pp1bZg8wbDbKHT21HrLIeYBTRLgMYKnMTPAuI3Lcs61nfx5h1xlXnbJtH1kX5/d/ng== + version "2.1.0" + resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-2.1.0.tgz#2119bc447ff8c257753b196fc5f1ce08a4cdf39f" + integrity sha512-LlbxQ7xKzfBusov6UMi4MFpEg0m+mAm9xyNGEduwXMEDuf4WfzB/RZwMVYEd7IKGvh4IUkEXYxtAVu9T3OelJQ== is-alphabetical@^2.0.0: version "2.0.1" @@ -1774,11 +1787,11 @@ media-typer@0.3.0: integrity sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ== memfs@^3.4.3: - version "3.4.13" - resolved "https://registry.yarnpkg.com/memfs/-/memfs-3.4.13.tgz#248a8bd239b3c240175cd5ec548de5227fc4f345" - integrity sha512-omTM41g3Skpvx5dSYeZIbXKcXoAVc/AoMNwn9TKx++L/gaen/+4TTttmu8ZSch5vfVJ8uJvGbroTsIlslRg6lg== + version "3.6.0" + resolved "https://registry.yarnpkg.com/memfs/-/memfs-3.6.0.tgz#d7a2110f86f79dd950a8b6df6d57bc984aa185f6" + integrity sha512-EGowvkkgbMcIChjMTMkESFDbZeSh8xZ7kNSF0hAiAN4Jh6jgHCRS0Ga/+C8y6Au+oqpezRHCfPsmJ2+DwAgiwQ== dependencies: - fs-monkey "^1.0.3" + fs-monkey "^1.0.4" merge-descriptors@1.0.1: version "1.0.1" diff --git a/samples/compose-resources-gallery/shared/build.gradle.kts b/samples/compose-resources-gallery/shared/build.gradle.kts index b47e30062..f72377602 100644 --- a/samples/compose-resources-gallery/shared/build.gradle.kts +++ b/samples/compose-resources-gallery/shared/build.gradle.kts @@ -93,6 +93,10 @@ android { targetCompatibility = JavaVersion.VERSION_17 } + lint { + disable.add("MissingTranslation") + } + namespace = "com.myapplication.common" } From d38556d5cce542e8f5f24d6b67c4370d28449560 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 7 Jan 2024 23:43:04 +0700 Subject: [PATCH 089/352] #535 remove verbose log --- .../kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index acf3e505a..01d5d8d70 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -238,7 +238,6 @@ open class MultiplatformResourcesPlugin : Plugin { // TODO this way do more than required - we trigger generate all android related resources at all project.tasks.withType().configureEach { - it.logger.warn("${it.name} depends on $genTaskProvider") it.dependsOn(genTaskProvider) } } From 26db0f0ca8843fff4631952eb13f7dd96a2480d6 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 8 Jan 2024 14:11:28 +0700 Subject: [PATCH 090/352] #535 cleanup structure --- .../gradle/MultiplatformResourcesPlugin.kt | 12 +- .../apple}/CopyResourcesFromKLibsAction.kt | 4 +- ...opyResourcesFromKLibsToExecutableAction.kt | 4 +- ...CopyResourcesFromKLibsToFrameworkAction.kt | 4 +- .../apple}/PackResourcesToKLibAction.kt | 6 +- .../js}/CopyResourcesToExecutableAction.kt | 10 +- .../js}/CopyResourcesToKLibAction.kt | 8 +- .../gradle/configuration/AndroidTarget.kt | 74 ------ .../gradle/configuration/AppleTargets.kt | 35 --- .../gradle/configuration/CommonTarget.kt | 30 --- .../icerock/gradle/configuration/JsTarget.kt | 37 --- .../icerock/gradle/configuration/JvmTarget.kt | 25 -- .../dev/icerock/gradle/configuration/Utils.kt | 64 ----- .../gradle/{rework => generator}/CodeConst.kt | 2 +- .../{rework => generator}/CodeGenerators.kt | 2 +- .../{rework => generator}/GenerationResult.kt | 6 +- .../PlatformContainerGenerator.kt | 4 +- .../PlatformResourceGenerator.kt | 6 +- .../ResourceGenerator.kt | 6 +- .../ResourceTypeGenerator.kt | 14 +- .../{rework => generator}/ResourcesFiles.kt | 4 +- .../ResourcesGenerator.kt | 14 +- .../gradle/generator/TargetMRGenerator.kt | 241 ------------------ .../container/AppleContainerGenerator.kt | 10 +- .../container/JvmContainerGenerator.kt | 10 +- .../container/NOPContainerGenerator.kt | 9 + .../EqualStringKeysException.kt | 2 +- .../{ => localization}/LanguageType.kt | 8 +- .../{ => platform}/apple/LoadableBundle.kt | 6 +- .../{ => platform}/apple/SetupAppleUtils.kt | 12 +- .../{ => platform}/js/JsParamsHelper.kt | 6 +- .../{ => platform}/js/JsSetupUtils.kt | 16 +- .../string/AndroidStringResourceGenerator.kt | 10 +- .../string/AppleStringResourceGenerator.kt | 14 +- .../string/JsStringResourceGenerator.kt | 20 +- .../string/JvmStringResourceGenerator.kt | 12 +- .../string/NOPStringResourceGenerator.kt | 8 +- .../string/StringResourceGenerator.kt | 14 +- .../{rework => generator}/string/Utils.kt | 4 +- .../metadata/container/ContainerMetadata.kt | 14 +- .../metadata/resource/ResourceMetadata.kt | 20 +- .../{generator => oldgen}/AssetsGenerator.kt | 0 .../{generator => oldgen}/ColorsGenerator.kt | 0 .../{generator => oldgen}/FilesGenerator.kt | 0 .../{generator => oldgen}/FontsGenerator.kt | 0 .../{generator => oldgen}/ImagesGenerator.kt | 0 .../LocalizationGenerator.kt | 90 ------- .../{generator => oldgen}/MRGenerator.kt | 0 .../{generator => oldgen}/PluralsGenerator.kt | 0 .../android/AndroidAssetsGenerator.kt | 0 .../android/AndroidColorsGenerator.kt | 0 .../android/AndroidFilesGenerator.kt | 0 .../android/AndroidFontsGenerator.kt | 0 .../android/AndroidImagesGenerator.kt | 0 .../android/AndroidMRGenerator.kt | 0 .../android/AndroidPluralsGenerator.kt | 0 .../apple/AppleAssetsGenerator.kt | 0 .../apple/AppleColorsGenerator.kt | 0 .../apple/AppleFilesGenerator.kt | 0 .../apple/AppleFontsGenerator.kt | 0 .../apple/AppleImagesGenerator.kt | 0 .../apple/AppleMRGenerator.kt | 0 .../apple/ApplePluralsGenerator.kt | 0 .../common/CommonMRGenerator.kt | 0 .../js/JsAssetsGenerator.kt | 0 .../js/JsColorsGenerator.kt | 0 .../js/JsFilesGenerator.kt | 0 .../js/JsFontsGenerator.kt | 0 .../js/JsImagesGenerator.kt | 0 .../{generator => oldgen}/js/JsMRGenerator.kt | 0 .../js/JsPluralsGenerator.kt | 0 .../jsJvmCommon/ColorResourceUtils.kt | 0 .../jsJvmCommon/GenerateImageUtil.kt | 0 .../jvm/JvmAssetsGenerator.kt | 0 .../jvm/JvmColorsGenerator.kt | 0 .../jvm/JvmFilesGenerator.kt | 0 .../jvm/JvmFontsGenerator.kt | 0 .../jvm/JvmImagesGenerator.kt | 0 .../jvm/JvmMRGenerator.kt | 0 .../jvm/JvmPluralsGenerator.kt | 0 .../rework/container/NOPContainerGenerator.kt | 9 - .../serialization/FileSerializer.kt | 4 +- .../tasks/CopyExecutableResourcesToApp.kt | 1 + .../tasks/CopyXCFrameworkResourcesToApp.kt | 1 + .../GenerateMultiplatformResourcesTask.kt | 42 ++- .../dev/icerock/gradle/utils/ArgbColor.kt | 2 +- .../gradle/utils/KotlinNativeLinkExt.kt | 4 +- .../gradle/utils/KotlinSourceSetExt.kt | 31 --- .../dev/icerock/gradle/utils/ProjectExt.kt | 40 +++ .../dev/icerock/gradle/utils/PropertiesExt.kt | 5 +- .../icerock/gradle/utils/TasksContainer.kt | 21 -- .../container/ContainerMetadataTest.kt | 16 +- 92 files changed, 241 insertions(+), 832 deletions(-) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator/apple/action => actions/apple}/CopyResourcesFromKLibsAction.kt (94%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator/apple/action => actions/apple}/CopyResourcesFromKLibsToExecutableAction.kt (84%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator/apple/action => actions/apple}/CopyResourcesFromKLibsToFrameworkAction.kt (83%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator/apple/action => actions/apple}/PackResourcesToKLibAction.kt (94%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator/js/action => actions/js}/CopyResourcesToExecutableAction.kt (94%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator/js/action => actions/js}/CopyResourcesToKLibAction.kt (79%) delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/CommonTarget.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JsTarget.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JvmTarget.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/Utils.kt rename resources-generator/src/main/kotlin/dev/icerock/gradle/{rework => generator}/CodeConst.kt (97%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{rework => generator}/CodeGenerators.kt (99%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{rework => generator}/GenerationResult.kt (60%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{rework => generator}/PlatformContainerGenerator.kt (81%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{rework => generator}/PlatformResourceGenerator.kt (76%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{rework => generator}/ResourceGenerator.kt (64%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{rework => generator}/ResourceTypeGenerator.kt (95%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{rework => generator}/ResourcesFiles.kt (90%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{rework => generator}/ResourcesGenerator.kt (95%) delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt rename resources-generator/src/main/kotlin/dev/icerock/gradle/{rework => generator}/container/AppleContainerGenerator.kt (68%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{rework => generator}/container/JvmContainerGenerator.kt (66%) create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/container/NOPContainerGenerator.kt rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => exceptions}/EqualStringKeysException.kt (84%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => localization}/LanguageType.kt (92%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => platform}/apple/LoadableBundle.kt (88%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => platform}/apple/SetupAppleUtils.kt (94%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => platform}/js/JsParamsHelper.kt (86%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => platform}/js/JsSetupUtils.kt (66%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{rework => generator}/string/AndroidStringResourceGenerator.kt (89%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{rework => generator}/string/AppleStringResourceGenerator.kt (85%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{rework => generator}/string/JsStringResourceGenerator.kt (86%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{rework => generator}/string/JvmStringResourceGenerator.kt (90%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{rework => generator}/string/NOPStringResourceGenerator.kt (66%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{rework => generator}/string/StringResourceGenerator.kt (88%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{rework => generator}/string/Utils.kt (81%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{rework => }/metadata/container/ContainerMetadata.kt (77%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{rework => }/metadata/resource/ResourceMetadata.kt (87%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/AssetsGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/ColorsGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/FilesGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/FontsGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/ImagesGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/LocalizationGenerator.kt (64%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/MRGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/PluralsGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/android/AndroidAssetsGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/android/AndroidColorsGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/android/AndroidFilesGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/android/AndroidFontsGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/android/AndroidImagesGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/android/AndroidMRGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/android/AndroidPluralsGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/apple/AppleAssetsGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/apple/AppleColorsGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/apple/AppleFilesGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/apple/AppleFontsGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/apple/AppleImagesGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/apple/AppleMRGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/apple/ApplePluralsGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/common/CommonMRGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/js/JsAssetsGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/js/JsColorsGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/js/JsFilesGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/js/JsFontsGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/js/JsImagesGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/js/JsMRGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/js/JsPluralsGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/jsJvmCommon/ColorResourceUtils.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/jsJvmCommon/GenerateImageUtil.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/jvm/JvmAssetsGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/jvm/JvmColorsGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/jvm/JvmFilesGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/jvm/JvmFontsGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/jvm/JvmImagesGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/jvm/JvmMRGenerator.kt (100%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/{generator => oldgen}/jvm/JvmPluralsGenerator.kt (100%) delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/NOPContainerGenerator.kt rename resources-generator/src/main/kotlin/dev/icerock/gradle/{rework => }/serialization/FileSerializer.kt (89%) create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProjectExt.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/utils/TasksContainer.kt rename resources-generator/src/test/kotlin/dev/icerock/gradle/{rework => generator}/metadata/container/ContainerMetadataTest.kt (64%) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 01d5d8d70..31ff29348 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -7,12 +7,12 @@ package dev.icerock.gradle import com.android.build.api.dsl.AndroidSourceSet import com.android.build.gradle.api.BaseVariant import com.android.build.gradle.internal.lint.AndroidLintAnalysisTask -import dev.icerock.gradle.generator.apple.setupAppleKLibResources -import dev.icerock.gradle.generator.apple.setupFatFrameworkTasks -import dev.icerock.gradle.generator.apple.setupFrameworkResources -import dev.icerock.gradle.generator.apple.setupTestsResources -import dev.icerock.gradle.generator.js.setupJsKLibResources -import dev.icerock.gradle.generator.js.setupJsResources +import dev.icerock.gradle.generator.platform.apple.setupAppleKLibResources +import dev.icerock.gradle.generator.platform.apple.setupFatFrameworkTasks +import dev.icerock.gradle.generator.platform.apple.setupFrameworkResources +import dev.icerock.gradle.generator.platform.apple.setupTestsResources +import dev.icerock.gradle.generator.platform.js.setupJsKLibResources +import dev.icerock.gradle.generator.platform.js.setupJsResources import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.utils.dependsOnObservable import dev.icerock.gradle.utils.kotlinSourceSetsObservable diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/CopyResourcesFromKLibsAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsAction.kt similarity index 94% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/CopyResourcesFromKLibsAction.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsAction.kt index 0e59dfad6..3c0a16571 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/CopyResourcesFromKLibsAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsAction.kt @@ -1,8 +1,8 @@ /* - * Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.apple.action +package dev.icerock.gradle.actions.apple import dev.icerock.gradle.utils.klibs import org.gradle.api.Action diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/CopyResourcesFromKLibsToExecutableAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsToExecutableAction.kt similarity index 84% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/CopyResourcesFromKLibsToExecutableAction.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsToExecutableAction.kt index b07a084ef..33e73d26e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/CopyResourcesFromKLibsToExecutableAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsToExecutableAction.kt @@ -1,8 +1,8 @@ /* - * Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.apple.action +package dev.icerock.gradle.actions.apple import org.gradle.api.Task import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractExecutable diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/CopyResourcesFromKLibsToFrameworkAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsToFrameworkAction.kt similarity index 83% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/CopyResourcesFromKLibsToFrameworkAction.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsToFrameworkAction.kt index aa13398c5..151984025 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/CopyResourcesFromKLibsToFrameworkAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsToFrameworkAction.kt @@ -1,8 +1,8 @@ /* - * Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.apple.action +package dev.icerock.gradle.actions.apple import org.gradle.api.Task import org.jetbrains.kotlin.gradle.plugin.mpp.Framework diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/PackResourcesToKLibAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/PackResourcesToKLibAction.kt similarity index 94% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/PackResourcesToKLibAction.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/PackResourcesToKLibAction.kt index 9678c5176..13da669f7 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/action/PackResourcesToKLibAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/PackResourcesToKLibAction.kt @@ -1,10 +1,10 @@ /* - * Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.apple.action +package dev.icerock.gradle.actions.apple -import dev.icerock.gradle.generator.apple.LoadableBundle +import dev.icerock.gradle.generator.platform.apple.LoadableBundle import dev.icerock.gradle.utils.unzipTo import org.gradle.api.Action import org.gradle.api.GradleException diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/action/CopyResourcesToExecutableAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/js/CopyResourcesToExecutableAction.kt similarity index 94% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/action/CopyResourcesToExecutableAction.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/actions/js/CopyResourcesToExecutableAction.kt index a28ed0fdf..a49ea50b5 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/action/CopyResourcesToExecutableAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/js/CopyResourcesToExecutableAction.kt @@ -1,4 +1,8 @@ -package dev.icerock.gradle.generator.js.action +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.actions.js import dev.icerock.gradle.utils.klibs import org.gradle.api.Action @@ -8,7 +12,7 @@ import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile import org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl import java.io.File -class CopyResourcesToExecutableAction( +internal class CopyResourcesToExecutableAction( private val resourcesGeneratedDir: Provider, ) : Action { override fun execute(task: Kotlin2JsCompile) { @@ -136,7 +140,7 @@ class CopyResourcesToExecutableAction( target = outputDir, overwrite = true ) - } catch (@Suppress("SwallowedException") exc: kotlin.io.NoSuchFileException) { + } catch (@Suppress("SwallowedException") exc: NoSuchFileException) { project.logger.info("resources in $inputFile not found") } catch (@Suppress("SwallowedException") exc: java.nio.file.NoSuchFileException) { project.logger.info("resources in $inputFile not found (empty lib)") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/action/CopyResourcesToKLibAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/js/CopyResourcesToKLibAction.kt similarity index 79% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/action/CopyResourcesToKLibAction.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/actions/js/CopyResourcesToKLibAction.kt index d02f095a2..f937288c9 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/action/CopyResourcesToKLibAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/js/CopyResourcesToKLibAction.kt @@ -1,11 +1,15 @@ -package dev.icerock.gradle.generator.js.action +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.actions.js import org.gradle.api.Action import org.gradle.api.provider.Provider import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile import java.io.File -class CopyResourcesToKLibAction( +internal class CopyResourcesToKLibAction( private val resourcesDirProvider: Provider, ) : Action { override fun execute(task: Kotlin2JsCompile) { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AndroidTarget.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AndroidTarget.kt index 1a15d989b..cad12c4bd 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AndroidTarget.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AndroidTarget.kt @@ -4,69 +4,9 @@ package dev.icerock.gradle.configuration -import com.android.build.gradle.BaseExtension -import com.android.build.gradle.api.AndroidSourceDirectorySet -import com.android.build.gradle.api.AndroidSourceSet //import dev.icerock.gradle.generator.MRGenerator //import dev.icerock.gradle.generator.ResourceGeneratorFeature //import dev.icerock.gradle.generator.android.AndroidMRGenerator -import org.gradle.api.Action -import org.gradle.api.Project -import org.gradle.api.Task -import org.gradle.api.provider.Provider -import org.gradle.api.tasks.SourceSet -import org.gradle.kotlin.dsl.getByType -import org.jetbrains.kotlin.gradle.plugin.KotlinTarget -import org.w3c.dom.Document -import org.w3c.dom.Node -import org.w3c.dom.NodeList -import java.io.File -import javax.xml.parsers.DocumentBuilder -import javax.xml.parsers.DocumentBuilderFactory - -// TODO not used. remove after complete migration of task configuration to Plugin configuration time -//internal fun configureAndroidTargetGenerator( -// target: KotlinTarget, -// settings: MRGenerator.Settings, -// features: List> -//) { -// val project: Project = target.project -// -// listOf( -// "com.android.library", -// "com.android.application" -// ).forEach { id -> -// project.plugins.withId(id) { -// setupAndroidGenerator( -// settings = settings, -// features = features, -// project = project -// ) -// } -// } -//} - -internal fun Project.getAndroidRClassPackage(): Provider { - return provider { - val androidExt: BaseExtension = project.extensions.getByType() - androidExt.namespace ?: getAndroidPackage(androidExt.mainSourceSet.manifest.srcFile) - } -} - -//@Suppress("LongParameterList") -//private fun setupAndroidGenerator( -// project: Project, -// settings: MRGenerator.Settings, -// features: List>, -//) { -// setAssetsDirsRefresh(project) -// -// AndroidMRGenerator( -// project = project, -// settings = settings, -// generators = features.map { it.createAndroidGenerator() }, -// ).apply(project) -//} //private fun setAssetsDirsRefresh(project: Project) { // // without this code Android Gradle Plugin not copy assets to aar @@ -84,17 +24,3 @@ internal fun Project.getAndroidRClassPackage(): Provider { // }) // } //} - -private fun getAndroidPackage(manifestFile: File): String { - val dbFactory: DocumentBuilderFactory = DocumentBuilderFactory.newInstance() - val dBuilder: DocumentBuilder = dbFactory.newDocumentBuilder() - val doc: Document = dBuilder.parse(manifestFile) - - val manifestNodes: NodeList = doc.getElementsByTagName("manifest") - val manifest: Node = manifestNodes.item(0) - - return manifest.attributes.getNamedItem("package").textContent -} - -private val BaseExtension.mainSourceSet: AndroidSourceSet - get() = this.sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt index 04ab23616..2fcf3cef9 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt @@ -20,41 +20,6 @@ package dev.icerock.gradle.configuration //import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink //import org.jetbrains.kotlin.konan.target.HostManager -// TODO not used. remove after complete migration of task configuration to Plugin configuration time -//internal fun configureAppleTargetGenerator( -// target: KotlinNativeTarget, -// settings: MRGenerator.Settings, -// features: List> -//) { -// if (HostManager.hostIsMac.not()) { -// target.project.logger.warn("MR file generation for Apple is not supported on your system!") -// return -// } -// -// val mainCompilation: KotlinNativeCompilation = target.compilations -// .getByName(KotlinCompilation.MAIN_COMPILATION_NAME) -// -// AppleMRGenerator( -// project = target.project, -// settings = settings, -// generators = features.map { it.createAppleGenerator() }, -// ).apply(target.project) -//} - -//internal fun setupProjectForApple(project: Project) { -// if (HostManager.hostIsMac.not()) { -// project.logger.warn("MR file generation for Apple is not supported on your system!") -// return -// } -// -// // without this afterEvaluate in ios-static-xcframework sample we got -// // configuration iosArm64DebugFrameworkExport not found error -// project.afterEvaluate { -// setupCopyXCFrameworkResourcesTask(project) -// createCopyResourcesToAppTask(project) -// } -//} - //private fun setupCopyXCFrameworkResourcesTask(project: Project) { // // Seems that there were problem with this block in the past with mystic task adding. Need more info // // Now, that works perfectly, I've tested on the real project with Kotlin 1.9.10 and KSP enabled diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/CommonTarget.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/CommonTarget.kt deleted file mode 100644 index 18ccadca9..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/CommonTarget.kt +++ /dev/null @@ -1,30 +0,0 @@ -///* -// * Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.configuration -// -//import dev.icerock.gradle.generator.MRGenerator -//import dev.icerock.gradle.generator.ResourceGeneratorFeature -//import dev.icerock.gradle.generator.common.CommonMRGenerator -//import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask -//import org.gradle.kotlin.dsl.withType -//import org.jetbrains.kotlin.gradle.plugin.KotlinTarget -// -//// TODO not used. remove after complete migration of task configuration to Plugin configuration time -////internal fun configureCommonTargetGenerator( -//// target: KotlinTarget, -//// settings: MRGenerator.Settings, -//// features: List>, -////) { -//// val generationTask: GenerateMultiplatformResourcesTask = CommonMRGenerator( -//// project = target.project, -//// settings = settings, -//// generators = features.map { it.createCommonGenerator() } -//// ).apply(project = target.project,) -//// -//// target.project.tasks -//// .withType() -//// .matching { it != generationTask } -//// .configureEach { it.dependsOn(generationTask) } -////} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JsTarget.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JsTarget.kt deleted file mode 100644 index 6c2a14fbf..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JsTarget.kt +++ /dev/null @@ -1,37 +0,0 @@ -///* -// * Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.configuration -// -//import dev.icerock.gradle.generator.MRGenerator -//import dev.icerock.gradle.generator.ResourceGeneratorFeature -//import dev.icerock.gradle.generator.js.JsMRGenerator -//import org.gradle.api.Project -//import org.jetbrains.kotlin.gradle.plugin.KotlinTarget -//import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget -// -//// TODO not used. remove after complete migration of task configuration to Plugin configuration time -////internal fun configureJsTargetGenerator( -//// target: KotlinTarget, -//// settings: MRGenerator.Settings, -//// features: List> -////) { -//// val project: Project = target.project -//// val jsTarget: KotlinJsIrTarget? = target as? KotlinJsIrTarget -//// if (jsTarget == null) { -//// project.logger.warn("$target is not supported by MOKO Resources") -//// return -//// } -//// -//// jsTarget.compilations.configureEach { compilation -> -//// // TODO rollback ifDepends -////// compilation.defaultSourceSet.ifDependsOn(commonSourceSet) { -//// JsMRGenerator( -//// project = project, -//// settings = settings, -//// generators = features.map { it.createJsGenerator() }, -//// ).apply(project = project) -////// } -//// } -////} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JvmTarget.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JvmTarget.kt deleted file mode 100644 index a73c56cfd..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/JvmTarget.kt +++ /dev/null @@ -1,25 +0,0 @@ -///* -// * Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.configuration -// -//import dev.icerock.gradle.generator.MRGenerator -//import dev.icerock.gradle.generator.ResourceGeneratorFeature -//import dev.icerock.gradle.generator.jvm.JvmMRGenerator -//import org.jetbrains.kotlin.gradle.plugin.KotlinTarget -// -//// TODO not used. remove after complete migration of task configuration to Plugin configuration time -////internal fun configureJvmTargetGenerator( -//// target: KotlinTarget, -//// settings: MRGenerator.Settings, -//// features: List> -////) { -//// JvmMRGenerator( -//// project = target.project, -//// settings = settings, -//// generators = features.map { it.createJvmGenerator() } -//// ).apply(project = target.project) -//// // TODO fix depends on -////// compilation.defaultSourceSet.ifDependsOn(commonSourceSet) { -////} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/Utils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/Utils.kt deleted file mode 100644 index 14b35db78..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/Utils.kt +++ /dev/null @@ -1,64 +0,0 @@ -///* -// * Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.configuration -// -//import com.android.build.api.dsl.AndroidSourceSet -//import dev.icerock.gradle.generator.MRGenerator -//import dev.icerock.gradle.utils.capitalize -//import org.gradle.api.provider.Provider -//import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet -//import java.io.File -// -//internal fun createSourceSet(kotlinSourceSet: KotlinSourceSet): MRGenerator.SourceSet { -// return object : MRGenerator.SourceSet { -// override val name: String -// get() = kotlinSourceSet.name -// -// override fun addSourceDir(directory: File) { -// kotlinSourceSet.kotlin.srcDir(directory) -// } -// -// override fun addResourcesDir(directory: File) { -// kotlinSourceSet.resources.srcDir(directory) -// } -// -// override fun addAssetsDir(directory: File) { -// // nothing -// } -// } -//} -// -//internal fun createSourceSet( -// androidSourceSet: AndroidSourceSet, -//): MRGenerator.SourceSet { -// return object : MRGenerator.SourceSet { -// override val name: String -// get() = "android${androidSourceSet.name.capitalize()}" -// -// override fun addSourceDir(directory: File) { -// androidSourceSet.java.srcDirs(directory) -//// targets.configureEach { target -> -//// target.compilations.configureEach { compilation -> -//// val lazyDirectory = { -//// directory.takeIf { -//// compilation.kotlinSourceSets.any { compilationSourceSet -> -//// compilationSourceSet.isDependsOn(commonSourceSet) -//// } -//// } -//// } -//// compilation.defaultSourceSet.kotlin.srcDir(lazyDirectory) -//// } -//// } -// } -// -// override fun addResourcesDir(directory: File) { -// androidSourceSet.res.srcDir(directory) -// } -// -// override fun addAssetsDir(directory: File) { -// androidSourceSet.assets.srcDir(directory) -// } -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/CodeConst.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt similarity index 97% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/rework/CodeConst.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt index 7c181e786..155ff734e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/CodeConst.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.rework +package dev.icerock.gradle.generator import com.squareup.kotlinpoet.ClassName diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/CodeGenerators.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeGenerators.kt similarity index 99% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/rework/CodeGenerators.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeGenerators.kt index c321f9d75..19194072a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/CodeGenerators.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeGenerators.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.rework +package dev.icerock.gradle.generator import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/GenerationResult.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/GenerationResult.kt similarity index 60% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/rework/GenerationResult.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/GenerationResult.kt index 2816f5bec..39378e9e3 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/GenerationResult.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/GenerationResult.kt @@ -2,12 +2,12 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.rework +package dev.icerock.gradle.generator import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.rework.metadata.container.ContainerMetadata +import dev.icerock.gradle.metadata.container.ContainerMetadata -data class GenerationResult( +internal data class GenerationResult( val typeSpec: TypeSpec, val metadata: ContainerMetadata ) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/PlatformContainerGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PlatformContainerGenerator.kt similarity index 81% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/rework/PlatformContainerGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PlatformContainerGenerator.kt index 44b32cf73..66615ef34 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/PlatformContainerGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PlatformContainerGenerator.kt @@ -2,12 +2,12 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.rework +package dev.icerock.gradle.generator import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.TypeSpec -interface PlatformContainerGenerator { +internal interface PlatformContainerGenerator { fun getImports(): List = emptyList() fun generateBeforeTypes(builder: TypeSpec.Builder) = Unit fun generateAfterTypes(builder: TypeSpec.Builder) = Unit diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/PlatformResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PlatformResourceGenerator.kt similarity index 76% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/rework/PlatformResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PlatformResourceGenerator.kt index 60c61703b..347408032 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/PlatformResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PlatformResourceGenerator.kt @@ -2,14 +2,14 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.rework +package dev.icerock.gradle.generator import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.rework.metadata.resource.ResourceMetadata +import dev.icerock.gradle.metadata.resource.ResourceMetadata -interface PlatformResourceGenerator { +internal interface PlatformResourceGenerator { fun imports(): List fun generateBeforeProperties(builder: TypeSpec.Builder, metadata: List) = Unit diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceGenerator.kt similarity index 64% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceGenerator.kt index dd4853ff4..194b7ccb8 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceGenerator.kt @@ -2,13 +2,13 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.rework +package dev.icerock.gradle.generator import com.squareup.kotlinpoet.PropertySpec -import dev.icerock.gradle.rework.metadata.resource.ResourceMetadata +import dev.icerock.gradle.metadata.resource.ResourceMetadata import java.io.File -interface ResourceGenerator { +internal interface ResourceGenerator { fun generateMetadata(files: Set): List fun generateProperty(metadata: T): PropertySpec.Builder diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourceTypeGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceTypeGenerator.kt similarity index 95% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourceTypeGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceTypeGenerator.kt index ebbe9f16d..3b73bfd04 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourceTypeGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceTypeGenerator.kt @@ -2,22 +2,22 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.rework +package dev.icerock.gradle.generator import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.rework.metadata.container.ActualInterfaceMetadata -import dev.icerock.gradle.rework.metadata.container.ExpectInterfaceMetadata -import dev.icerock.gradle.rework.metadata.container.ObjectMetadata -import dev.icerock.gradle.rework.metadata.container.ResourceType -import dev.icerock.gradle.rework.metadata.resource.ResourceMetadata +import dev.icerock.gradle.metadata.container.ActualInterfaceMetadata +import dev.icerock.gradle.metadata.container.ExpectInterfaceMetadata +import dev.icerock.gradle.metadata.container.ObjectMetadata +import dev.icerock.gradle.metadata.container.ResourceType +import dev.icerock.gradle.metadata.resource.ResourceMetadata import dev.icerock.gradle.utils.capitalize import org.gradle.api.tasks.util.PatternFilterable -class ResourceTypeGenerator( +internal class ResourceTypeGenerator( private val generationPackage: String, private val resourceClass: ClassName, private val resourceType: ResourceType, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourcesFiles.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourcesFiles.kt similarity index 90% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourcesFiles.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourcesFiles.kt index c95c95ac8..91a6443bb 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourcesFiles.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourcesFiles.kt @@ -2,12 +2,12 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.rework +package dev.icerock.gradle.generator import org.gradle.api.file.FileTree import org.gradle.api.tasks.util.PatternFilterable -data class ResourcesFiles( +internal data class ResourcesFiles( val ownSourceSet: SourceSetResources, val upperSourceSets: List ) { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourcesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourcesGenerator.kt similarity index 95% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourcesGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourcesGenerator.kt index 2c7aea32d..0cb1c5a94 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/ResourcesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourcesGenerator.kt @@ -2,20 +2,20 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.rework +package dev.icerock.gradle.generator import com.squareup.kotlinpoet.FileSpec import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.rework.metadata.container.ActualInterfaceMetadata -import dev.icerock.gradle.rework.metadata.container.ContainerMetadata -import dev.icerock.gradle.rework.metadata.container.ExpectInterfaceMetadata -import dev.icerock.gradle.rework.metadata.container.ObjectMetadata -import dev.icerock.gradle.rework.metadata.resource.ResourceMetadata +import dev.icerock.gradle.metadata.container.ActualInterfaceMetadata +import dev.icerock.gradle.metadata.container.ContainerMetadata +import dev.icerock.gradle.metadata.container.ExpectInterfaceMetadata +import dev.icerock.gradle.metadata.container.ObjectMetadata +import dev.icerock.gradle.metadata.resource.ResourceMetadata import dev.icerock.gradle.utils.calculateHash import java.io.File -class ResourcesGenerator( +internal class ResourcesGenerator( private val containerGenerator: PlatformContainerGenerator, private val typesGenerators: List>, private val resourcesPackageName: String, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt deleted file mode 100644 index b39b530ef..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/TargetMRGenerator.kt +++ /dev/null @@ -1,241 +0,0 @@ -//package dev.icerock.gradle.generator -// -//import com.squareup.kotlinpoet.ClassName -//import com.squareup.kotlinpoet.FileSpec -//import com.squareup.kotlinpoet.KModifier -//import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -//import com.squareup.kotlinpoet.TypeSpec -//import dev.icerock.gradle.metadata.Metadata.createOutputMetadata -//import dev.icerock.gradle.metadata.Metadata.readInputMetadata -//import dev.icerock.gradle.metadata.getExpectInterfaces -//import dev.icerock.gradle.metadata.getGeneratorInterfaces -//import dev.icerock.gradle.metadata.getInterfaceName -//import dev.icerock.gradle.metadata.isNotEmptyMetadata -//import dev.icerock.gradle.metadata.model.GeneratedObject -//import dev.icerock.gradle.metadata.model.GeneratedObjectModifier -//import dev.icerock.gradle.metadata.model.GeneratedObjectType -//import dev.icerock.gradle.metadata.model.GeneratorType -//import dev.icerock.gradle.metadata.resourcesIsEmpty -//import dev.icerock.gradle.toModifier -//import dev.icerock.gradle.utils.targetName -//import org.gradle.api.Project -// -//abstract class TargetMRGenerator( -// private val project: Project, -// settings: Settings, -// generators: List, -//) : MRGenerator( -// settings = settings, -// generators = generators -//) { -// -// override fun getMRClassModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun generateFileSpec(): FileSpec? { -// //Read list of generated resources on previous level's -// val inputMetadata: List = readInputMetadata( -// inputMetadataFiles = settings.inputMetadataFiles -// ) -// -// // Check resources for generation: if lower resources is empty -// // and own resources has no files - skip step -// if (resourcesIsEmpty(inputMetadata, settings)) return null -// -// val outputMetadata: MutableList = mutableListOf() -// -// // If previous levels has resources, need generate actual objects -// val needGenerateActual: Boolean = inputMetadata.isNotEmptyMetadata() -// -// val visibilityModifier: KModifier = settings.visibility.toModifier() -// -// val fileSpec: FileSpec.Builder = FileSpec.builder( -// packageName = settings.packageName, -// fileName = settings.className -// ) -// -// @Suppress("SpreadOperator") -// val mrClassSpec = TypeSpec.objectBuilder(settings.className) // default: object MR -// .addModifiers(visibilityModifier) // public/internal -// -// if (needGenerateActual) { -// mrClassSpec.addModifiers(KModifier.ACTUAL) -// } -// -// // Add actual implementation of expect interfaces from previous levels -// if (inputMetadata.isNotEmpty()) { -// generateTargetInterfaces( -// inputMetadata = inputMetadata, -// outputMetadata = outputMetadata, -// visibilityModifier = settings.visibility.toModifier(), -// generateActualObject = needGenerateActual, -// fileSpec = fileSpec -// ) -// -// // Generation of actual interfaces not realised on current level -// val expectInterfaces: List = inputMetadata.getExpectInterfaces() -// -// expectInterfaces.forEach { expectInterface -> -// val actualInterfaceTypeSpec: TypeSpec = -// TypeSpec.interfaceBuilder(expectInterface.name) -// .addModifiers(visibilityModifier) -// .addModifiers(KModifier.ACTUAL) -// .build() -// -// fileSpec.addType(actualInterfaceTypeSpec) -// outputMetadata.add(expectInterface.copy(modifier = GeneratedObjectModifier.Actual)) -// } -// } -// -// val generatedActualObjects = mutableListOf() -// -// generators.forEach { generator: Generator -> -// val objectBuilder: TypeSpec.Builder = TypeSpec -// .objectBuilder(generator.mrObjectName) -// .addModifiers(visibilityModifier) -// .addSuperinterface( -// superinterface = generator.resourceContainerClass.parameterizedBy( -// generator.resourceClassName -// ) -// ) -// -// // Implement to object expect interfaces from previous -// // levels of resources -// inputMetadata.getGeneratorInterfaces(generator.type) -// .forEach { generatedObject: GeneratedObject -> -// objectBuilder.addSuperinterface( -// ClassName( -// packageName = settings.packageName, -// generatedObject.name -// ) -// ) -// } -// -// val result: GenerationResult? = generator.generateObject( -// project = project, -// metadata = inputMetadata, -// outputMetadata = GeneratedObject( -// generatorType = generator.type, -// modifier = if (needGenerateActual) { -// GeneratedObjectModifier.Actual -// } else { -// GeneratedObjectModifier.None -// }, -// type = GeneratedObjectType.Object, -// name = generator.mrObjectName, -// interfaces = getObjectInterfaces( -// generatorType = generator.type, -// objectName = generator.mrObjectName, -// inputMetadata = inputMetadata -// ) -// ), -// assetsGenerationDir = assetsGenerationDir, -// resourcesGenerationDir = resourcesGenerationDir, -// objectBuilder = objectBuilder, -// ) -// -// if (result != null) { -// mrClassSpec.addType(result.typeSpec) -// outputMetadata.add(result.metadata) -// generatedActualObjects.add(result.metadata) -// } -// } -// -// processMRClass(mrClassSpec) -// -// if (generatedActualObjects.isNotEmpty()) { -// val mrClass = mrClassSpec.build() -// fileSpec.addType(mrClass) -// -// outputMetadata.add( -// GeneratedObject( -// generatorType = GeneratorType.None, -// type = GeneratedObjectType.Object, -// name = settings.className, -// modifier = GeneratedObjectModifier.Actual, -// objects = generatedActualObjects -// ) -// ) -// } -// -// generators -// .flatMap { it.getImports() } -// .plus(getImports()) -// .forEach { fileSpec.addImport(it.packageName, it.simpleName) } -// -// createOutputMetadata( -// outputMetadataFile = settings.outputMetadataFile, -// generatedObjects = inputMetadata -// ) -// -// return fileSpec.build() -// } -// -// private fun generateTargetInterfaces( -// inputMetadata: List, -// outputMetadata: MutableList, -// visibilityModifier: KModifier, -// generateActualObject: Boolean, -// fileSpec: FileSpec.Builder, -// ) { -// if (settings.ownResourcesFileTree.files.isEmpty()) return -// -// val targetName: String = settings.ownResourcesFileTree.files -// .firstOrNull()?.targetName ?: return -// -// generators.forEach { generator -> -// val interfaceName = getInterfaceName( -// sourceSetName = targetName, -// generatorType = generator.type -// ) -// -// val resourcesInterfaceBuilder: TypeSpec.Builder = -// TypeSpec.interfaceBuilder(interfaceName) -// .addModifiers(visibilityModifier) -// -// val result: GenerationResult? = generator.generateObject( -// project = project, -// metadata = inputMetadata, -// outputMetadata = GeneratedObject( -// generatorType = generator.type, -// modifier = if (generateActualObject) { -// GeneratedObjectModifier.Actual -// } else { -// GeneratedObjectModifier.None -// }, -// type = GeneratedObjectType.Interface, -// name = interfaceName -// ), -// assetsGenerationDir = assetsGenerationDir, -// resourcesGenerationDir = resourcesGenerationDir, -// objectBuilder = resourcesInterfaceBuilder -// ) -// -// if (result != null) { -// fileSpec.addType(result.typeSpec) -// outputMetadata.add(result.metadata) -// } -// } -// } -// -// private fun getObjectInterfaces( -// generatorType: GeneratorType, -// objectName: String, -// inputMetadata: List, -// ): List { -// val interfaces = mutableListOf() -// -// val mrObjects: List = inputMetadata.filter { -// it.isExpectObject && it.generatorType == GeneratorType.None -// } -// -// mrObjects.forEach { mrObject -> -// mrObject.objects.forEach { -// if (it.generatorType == generatorType && it.name == objectName) { -// interfaces.addAll(it.interfaces) -// } -// } -// } -// -// return interfaces.distinct() -// } -//} \ No newline at end of file diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/AppleContainerGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/container/AppleContainerGenerator.kt similarity index 68% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/AppleContainerGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/container/AppleContainerGenerator.kt index 433186e93..44ab2af5c 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/AppleContainerGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/container/AppleContainerGenerator.kt @@ -2,15 +2,15 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.rework.container +package dev.icerock.gradle.generator.container import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.rework.CodeConst -import dev.icerock.gradle.rework.PlatformContainerGenerator -import dev.icerock.gradle.rework.addAppleResourcesBundleProperty +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.PlatformContainerGenerator +import dev.icerock.gradle.generator.addAppleResourcesBundleProperty -class AppleContainerGenerator( +internal class AppleContainerGenerator( private val bundleIdentifier: String ) : PlatformContainerGenerator { override fun getImports(): List { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/JvmContainerGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/container/JvmContainerGenerator.kt similarity index 66% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/JvmContainerGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/container/JvmContainerGenerator.kt index e7290d54c..f842d1220 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/JvmContainerGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/container/JvmContainerGenerator.kt @@ -2,15 +2,15 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.rework.container +package dev.icerock.gradle.generator.container import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.rework.CodeConst -import dev.icerock.gradle.rework.PlatformContainerGenerator -import dev.icerock.gradle.rework.addJvmClassLoaderProperty +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.PlatformContainerGenerator +import dev.icerock.gradle.generator.addJvmClassLoaderProperty -class JvmContainerGenerator( +internal class JvmContainerGenerator( private val resourcesClassName: String ) : PlatformContainerGenerator { override fun getImports(): List { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/container/NOPContainerGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/container/NOPContainerGenerator.kt new file mode 100644 index 000000000..f43feae40 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/container/NOPContainerGenerator.kt @@ -0,0 +1,9 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.container + +import dev.icerock.gradle.generator.PlatformContainerGenerator + +internal class NOPContainerGenerator : PlatformContainerGenerator diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/EqualStringKeysException.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/exceptions/EqualStringKeysException.kt similarity index 84% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/EqualStringKeysException.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/exceptions/EqualStringKeysException.kt index 5357140e8..36327818b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/EqualStringKeysException.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/exceptions/EqualStringKeysException.kt @@ -2,7 +2,7 @@ * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator +package dev.icerock.gradle.generator.exceptions class EqualStringKeysException( val keys: List diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/LanguageType.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/localization/LanguageType.kt similarity index 92% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/LanguageType.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/localization/LanguageType.kt index 1430b644a..aac99be3e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/LanguageType.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/localization/LanguageType.kt @@ -1,12 +1,12 @@ /* - * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator +package dev.icerock.gradle.generator.localization import java.util.Locale as JvmLocale -sealed interface LanguageType { +internal sealed interface LanguageType { val androidResourcesDir: String val appleResourcesDir: String @@ -54,7 +54,7 @@ sealed interface LanguageType { * Throw an error here so that we safeguard ourselves from implicitly calling `Local.toString`. * You should always use the more explicit methods defined above. */ - override fun toString(): String = TODO("Use toLocaleString or toBcpString instead!") + override fun toString(): String = error("Use toLocaleString or toBcpString instead!") override fun hashCode(): Int = jvmLocale.hashCode() override fun equals(other: Any?): Boolean { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/LoadableBundle.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/LoadableBundle.kt similarity index 88% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/LoadableBundle.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/LoadableBundle.kt index fdcc9a10d..8d34141df 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/LoadableBundle.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/LoadableBundle.kt @@ -1,12 +1,12 @@ /* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.apple +package dev.icerock.gradle.generator.platform.apple import java.io.File -class LoadableBundle( +internal class LoadableBundle( directory: File, bundleName: String, private val developmentRegion: String, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/SetupAppleUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt similarity index 94% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/SetupAppleUtils.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt index 7ebc5c5db..e01638835 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/SetupAppleUtils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt @@ -1,10 +1,14 @@ -package dev.icerock.gradle.generator.apple +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.platform.apple import com.android.build.gradle.internal.tasks.factory.dependsOn import dev.icerock.gradle.MultiplatformResourcesPluginExtension -import dev.icerock.gradle.generator.apple.action.CopyResourcesFromKLibsToExecutableAction -import dev.icerock.gradle.generator.apple.action.CopyResourcesFromKLibsToFrameworkAction -import dev.icerock.gradle.generator.apple.action.PackResourcesToKLibAction +import dev.icerock.gradle.actions.apple.CopyResourcesFromKLibsToExecutableAction +import dev.icerock.gradle.actions.apple.CopyResourcesFromKLibsToFrameworkAction +import dev.icerock.gradle.actions.apple.PackResourcesToKLibAction import dev.icerock.gradle.tasks.CopyFrameworkResourcesToAppEntryPointTask import dev.icerock.gradle.tasks.CopyFrameworkResourcesToAppTask import org.gradle.api.Action diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsParamsHelper.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/js/JsParamsHelper.kt similarity index 86% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsParamsHelper.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/js/JsParamsHelper.kt index fcb245246..ee8dafda6 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsParamsHelper.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/js/JsParamsHelper.kt @@ -1,12 +1,12 @@ /* - * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.js +package dev.icerock.gradle.generator.platform.js private val messageFormatRegex = "%(.)(?:\\\$(.))?".toRegex() -fun String.convertToMessageFormat(): String { +internal fun String.convertToMessageFormat(): String { val allMatches = messageFormatRegex.findAll(this) if (allMatches.count() == 0) return this diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsSetupUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/js/JsSetupUtils.kt similarity index 66% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsSetupUtils.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/js/JsSetupUtils.kt index 5c67d5043..95322b733 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsSetupUtils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/js/JsSetupUtils.kt @@ -1,14 +1,18 @@ -package dev.icerock.gradle.generator.js +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ -import dev.icerock.gradle.generator.js.action.CopyResourcesToExecutableAction -import dev.icerock.gradle.generator.js.action.CopyResourcesToKLibAction +package dev.icerock.gradle.generator.platform.js + +import dev.icerock.gradle.actions.js.CopyResourcesToExecutableAction +import dev.icerock.gradle.actions.js.CopyResourcesToKLibAction import org.gradle.api.Action import org.gradle.api.Task import org.gradle.api.provider.Provider import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile import java.io.File -fun setupJsKLibResources( +internal fun setupJsKLibResources( compileTask: Kotlin2JsCompile, resourcesGenerationDir: Provider ) { @@ -17,11 +21,11 @@ fun setupJsKLibResources( compileTask.doLast(copyResourcesToKLibAction as Action) } -fun setupJsResources( +internal fun setupJsResources( compileTask: Kotlin2JsCompile, resourcesGenerationDir: Provider ) { val copyResourcesAction = CopyResourcesToExecutableAction(resourcesGenerationDir) @Suppress("UNCHECKED_CAST") compileTask.doLast(copyResourcesAction as Action) -} \ No newline at end of file +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/AndroidStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/AndroidStringResourceGenerator.kt similarity index 89% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/AndroidStringResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/AndroidStringResourceGenerator.kt index 47e18c9f5..d7a2ee8a6 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/AndroidStringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/AndroidStringResourceGenerator.kt @@ -2,17 +2,17 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.rework.string +package dev.icerock.gradle.generator.string import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock -import dev.icerock.gradle.generator.LanguageType -import dev.icerock.gradle.rework.PlatformResourceGenerator -import dev.icerock.gradle.rework.metadata.resource.StringMetadata +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.generator.localization.LanguageType +import dev.icerock.gradle.metadata.resource.StringMetadata import org.apache.commons.text.StringEscapeUtils import java.io.File -class AndroidStringResourceGenerator( +internal class AndroidStringResourceGenerator( private val androidRClassPackage: String, private val resourcesGenerationDir: File ) : PlatformResourceGenerator { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/AppleStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/AppleStringResourceGenerator.kt similarity index 85% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/AppleStringResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/AppleStringResourceGenerator.kt index 8d7e3f5db..0e3aa191c 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/AppleStringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/AppleStringResourceGenerator.kt @@ -2,20 +2,20 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.rework.string +package dev.icerock.gradle.generator.string import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.LanguageType -import dev.icerock.gradle.rework.CodeConst -import dev.icerock.gradle.rework.PlatformResourceGenerator -import dev.icerock.gradle.rework.addAppleContainerBundleProperty -import dev.icerock.gradle.rework.metadata.resource.StringMetadata +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.generator.addAppleContainerBundleProperty +import dev.icerock.gradle.generator.localization.LanguageType +import dev.icerock.gradle.metadata.resource.StringMetadata import org.apache.commons.text.StringEscapeUtils import java.io.File -class AppleStringResourceGenerator( +internal class AppleStringResourceGenerator( private val baseLocalizationRegion: String, private val resourcesGenerationDir: File ) : PlatformResourceGenerator { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JsStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/JsStringResourceGenerator.kt similarity index 86% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JsStringResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/JsStringResourceGenerator.kt index 0ff459616..c8bb813e4 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JsStringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/JsStringResourceGenerator.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.rework.string +package dev.icerock.gradle.generator.string import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock @@ -10,20 +10,20 @@ import com.squareup.kotlinpoet.FunSpec import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.LanguageType -import dev.icerock.gradle.generator.js.convertToMessageFormat -import dev.icerock.gradle.rework.CodeConst -import dev.icerock.gradle.rework.PlatformResourceGenerator -import dev.icerock.gradle.rework.addJsContainerStringsLoaderProperty -import dev.icerock.gradle.rework.addJsFallbackProperty -import dev.icerock.gradle.rework.addJsSupportedLocalesProperty -import dev.icerock.gradle.rework.metadata.resource.StringMetadata +import dev.icerock.gradle.generator.platform.js.convertToMessageFormat +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.generator.addJsContainerStringsLoaderProperty +import dev.icerock.gradle.generator.addJsFallbackProperty +import dev.icerock.gradle.generator.addJsSupportedLocalesProperty +import dev.icerock.gradle.generator.localization.LanguageType +import dev.icerock.gradle.metadata.resource.StringMetadata import dev.icerock.gradle.utils.flatName import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.put import java.io.File -class JsStringResourceGenerator( +internal class JsStringResourceGenerator( resourcesPackageName: String, private val resourcesGenerationDir: File ) : PlatformResourceGenerator { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JvmStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/JvmStringResourceGenerator.kt similarity index 90% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JvmStringResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/JvmStringResourceGenerator.kt index 50c11a5d1..c32deb248 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/JvmStringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/JvmStringResourceGenerator.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.rework.string +package dev.icerock.gradle.generator.string import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock @@ -10,14 +10,14 @@ import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.STRING import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.LanguageType -import dev.icerock.gradle.rework.CodeConst -import dev.icerock.gradle.rework.PlatformResourceGenerator -import dev.icerock.gradle.rework.metadata.resource.StringMetadata +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.generator.localization.LanguageType +import dev.icerock.gradle.metadata.resource.StringMetadata import org.apache.commons.text.StringEscapeUtils import java.io.File -class JvmStringResourceGenerator( +internal class JvmStringResourceGenerator( private val flattenClassPackage: String, private val className: String, private val resourcesGenerationDir: File diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/NOPStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/NOPStringResourceGenerator.kt similarity index 66% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/NOPStringResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/NOPStringResourceGenerator.kt index 86464cfaf..ff2b1107f 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/NOPStringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/NOPStringResourceGenerator.kt @@ -2,14 +2,14 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.rework.string +package dev.icerock.gradle.generator.string import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock -import dev.icerock.gradle.rework.PlatformResourceGenerator -import dev.icerock.gradle.rework.metadata.resource.StringMetadata +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.metadata.resource.StringMetadata -class NOPStringResourceGenerator : PlatformResourceGenerator { +internal class NOPStringResourceGenerator : PlatformResourceGenerator { override fun imports(): List { TODO("Not yet implemented") } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/StringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/StringResourceGenerator.kt similarity index 88% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/StringResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/StringResourceGenerator.kt index 4d9e78ed4..333c322ce 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/StringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/StringResourceGenerator.kt @@ -2,14 +2,14 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.rework.string +package dev.icerock.gradle.generator.string import com.squareup.kotlinpoet.PropertySpec -import dev.icerock.gradle.generator.EqualStringKeysException -import dev.icerock.gradle.generator.LanguageType -import dev.icerock.gradle.rework.CodeConst -import dev.icerock.gradle.rework.ResourceGenerator -import dev.icerock.gradle.rework.metadata.resource.StringMetadata +import dev.icerock.gradle.generator.exceptions.EqualStringKeysException +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.ResourceGenerator +import dev.icerock.gradle.generator.localization.LanguageType +import dev.icerock.gradle.metadata.resource.StringMetadata import dev.icerock.gradle.utils.removeLineWraps import org.w3c.dom.Document import org.w3c.dom.Node @@ -20,7 +20,7 @@ import javax.xml.parsers.DocumentBuilderFactory private typealias KeyType = String -class StringResourceGenerator( +internal class StringResourceGenerator( private val strictLineBreaks: Boolean ) : ResourceGenerator { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/Utils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/Utils.kt similarity index 81% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/Utils.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/Utils.kt index 1b56a04ef..64ccb661e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/string/Utils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/Utils.kt @@ -2,9 +2,9 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.rework.string +package dev.icerock.gradle.generator.string -import dev.icerock.gradle.rework.metadata.resource.StringMetadata +import dev.icerock.gradle.metadata.resource.StringMetadata internal fun List.processLanguages(): Map> { return this.flatMap { metadata -> diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/metadata/container/ContainerMetadata.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/container/ContainerMetadata.kt similarity index 77% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/rework/metadata/container/ContainerMetadata.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/container/ContainerMetadata.kt index ecbc51a02..63e20b224 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/metadata/container/ContainerMetadata.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/container/ContainerMetadata.kt @@ -2,21 +2,21 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.rework.metadata.container +package dev.icerock.gradle.metadata.container -import dev.icerock.gradle.rework.metadata.resource.ResourceMetadata +import dev.icerock.gradle.metadata.resource.ResourceMetadata import dev.icerock.gradle.utils.calculateHash import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -sealed interface ContainerMetadata { +internal sealed interface ContainerMetadata { fun contentHash(): String? } @Serializable @SerialName("expect-interface") -data class ExpectInterfaceMetadata( +internal data class ExpectInterfaceMetadata( val name: String, val resourceType: ResourceType, val sourceSet: String @@ -26,7 +26,7 @@ data class ExpectInterfaceMetadata( @Serializable @SerialName("actual-interface") -data class ActualInterfaceMetadata( +internal data class ActualInterfaceMetadata( val name: String, val resources: List ) : ContainerMetadata { @@ -35,7 +35,7 @@ data class ActualInterfaceMetadata( @Serializable @SerialName("object") -data class ObjectMetadata( +internal data class ObjectMetadata( val name: String, val resourceType: ResourceType, val interfaces: List, @@ -45,6 +45,6 @@ data class ObjectMetadata( override fun contentHash(): String = resources.mapNotNull { it.contentHash() }.calculateHash() } -enum class ResourceType { +internal enum class ResourceType { STRINGS, PLURALS, IMAGES, FONTS, FILES, COLORS, ASSETS } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/metadata/resource/ResourceMetadata.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt similarity index 87% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/rework/metadata/resource/ResourceMetadata.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt index 36cba3dd9..445c54a96 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/metadata/resource/ResourceMetadata.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt @@ -4,9 +4,9 @@ @file:UseSerializers(FileSerializer::class) -package dev.icerock.gradle.rework.metadata.resource +package dev.icerock.gradle.metadata.resource -import dev.icerock.gradle.rework.serialization.FileSerializer +import dev.icerock.gradle.serialization.FileSerializer import dev.icerock.gradle.utils.calculateHash import dev.icerock.gradle.utils.calculateResourcesHash import kotlinx.serialization.Serializable @@ -14,14 +14,14 @@ import kotlinx.serialization.UseSerializers import java.io.File @Serializable -sealed interface ResourceMetadata { +internal sealed interface ResourceMetadata { val key: String fun contentHash(): String? } @Serializable -data class StringMetadata( +internal data class StringMetadata( override val key: String, val values: List ) : ResourceMetadata { @@ -35,7 +35,7 @@ data class StringMetadata( } @Serializable -data class PluralMetadata( +internal data class PluralMetadata( override val key: String, val values: List ) : ResourceMetadata { @@ -59,7 +59,7 @@ data class PluralMetadata( } @Serializable -data class ImageMetadata( +internal data class ImageMetadata( override val key: String, val values: List ) : ResourceMetadata { @@ -74,7 +74,7 @@ data class ImageMetadata( } @Serializable -data class FontMetadata( +internal data class FontMetadata( override val key: String, val values: List ) : ResourceMetadata { @@ -89,7 +89,7 @@ data class FontMetadata( } @Serializable -data class FileMetadata( +internal data class FileMetadata( override val key: String, val filePath: File ) : ResourceMetadata { @@ -98,7 +98,7 @@ data class FileMetadata( } @Serializable -data class ColorMetadata( +internal data class ColorMetadata( override val key: String, val value: ColorItem ) : ResourceMetadata { @@ -126,7 +126,7 @@ data class ColorMetadata( } @Serializable -data class AssetsMetadata( +internal data class AssetsMetadata( override val key: String, val relativePath: File, val filePath: File diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/AssetsGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/AssetsGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/AssetsGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/ColorsGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/ColorsGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/FilesGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/FilesGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/FontsGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/FontsGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/ImagesGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/ImagesGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/LocalizationGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/LocalizationGenerator.kt similarity index 64% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/LocalizationGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/LocalizationGenerator.kt index d7fc4655b..f962f22ce 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/LocalizationGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/LocalizationGenerator.kt @@ -177,93 +177,3 @@ // const val BASE_LANGUAGE = "base" // } //} -// -//internal class CommonLocalizationInterfaceGenerator( -// private val sourceSetName: String, -// private val filesRegex: Regex, -// private val generatorType: GeneratorType, -// private val visibilityModifier: KModifier -//) : MRGenerator.InterfaceGenerator { -// override fun generateInterface( -// project: Project, -// metadata: List, -// resourcesFiles: MRGenerator.ResourcesFiles -// ): MRGenerator.GenerationResult? { -// if (resourcesFiles.lowerResourcesFileTree.isEmpty.not()) { -// // we should generate actual interfaces for own resources -// return generateActualInterface(project, metadata, resourcesFiles) -// } -// -// return generateExpectInterface(project, metadata, resourcesFiles) -// } -// -// private fun generateActualInterface( -// project: Project, -// metadata: List, -// resourcesFiles: MRGenerator.ResourcesFiles -// ): MRGenerator.GenerationResult? { -// val interfaceName: String = getInterfaceName( -// sourceSetName = sourceSetName, -// generatorType = generatorType -// ) -// -// val resourcesInterfaceBuilder: TypeSpec.Builder = -// TypeSpec.interfaceBuilder(interfaceName) -// .addModifiers(visibilityModifier) -// .addModifiers(KModifier.ACTUAL) -// -// generator.generateObject( -// project = project, -// metadata = inputMetadata, -// outputMetadata = GeneratedObject( -// generatorType = generator.type, -// name = interfaceName, -// type = GeneratedObjectType.Interface, -// modifier = GeneratedObjectModifier.Actual, -// ), -// assetsGenerationDir = assetsGenerationDir, -// resourcesGenerationDir = resourcesGenerationDir, -// objectBuilder = resourcesInterfaceBuilder, -// ) -// } -// -// private fun generateExpectInterface( -// project: Project, -// metadata: List, -// resourcesFiles: MRGenerator.ResourcesFiles -// ): MRGenerator.GenerationResult? { -// if (resourcesFiles.upperResourcesFileTree.isEmpty) return null -// -// val name: String = getInterfaceName( -// sourceSetName = sourceSetName, -// generatorType = generatorType -// ) -// -// return MRGenerator.GenerationResult( -// typeSpec = TypeSpec.interfaceBuilder(name) -// .addModifiers(visibilityModifier) -// .addModifiers(KModifier.EXPECT) -// .build(), -// metadata = GeneratedObject( -// generatorType = generatorType, -// type = GeneratedObjectType.Interface, -// modifier = GeneratedObjectModifier.Expect, -// name = name -// ) -// ) -// } -//} -// -//internal class PropertiesGenerator { -// -//} -// -//// разница в ресурсах - в итоговом генерируемом actual классе -//// (точнее в значениях, которые должны быть сгенерированы) -//// и в самих файлах, которые генерируются для платформы -// -//// генерацию файлов и значений, то есть actual данные, можно делать из метаданных, не читая -//// вообще файлы -// -//// тогда пайплайн такой: читаем файлы -> генерируем метаданные для них -> пишем файлы expect, interface -//// а в таргет генераторах пишем уже значения и сами файлы платформы diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/MRGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/MRGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/PluralsGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/PluralsGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidAssetsGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidAssetsGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidAssetsGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidColorsGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidColorsGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidColorsGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidFilesGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidFilesGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidFontsGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFontsGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidFontsGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidImagesGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidImagesGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidMRGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidMRGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidPluralsGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidPluralsGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleAssetsGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleAssetsGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleAssetsGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleColorsGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleColorsGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleColorsGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleFilesGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFilesGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleFilesGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleFontsGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleFontsGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleFontsGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleImagesGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleImagesGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleImagesGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleMRGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/AppleMRGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleMRGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/ApplePluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/ApplePluralsGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/apple/ApplePluralsGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/ApplePluralsGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/common/CommonMRGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/common/CommonMRGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsAssetsGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsAssetsGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsAssetsGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsColorsGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsColorsGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsColorsGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsFilesGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFilesGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsFilesGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsFontsGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsFontsGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsFontsGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsImagesGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsImagesGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsImagesGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsMRGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsMRGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsMRGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsPluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsPluralsGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/js/JsPluralsGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsPluralsGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jsJvmCommon/ColorResourceUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jsJvmCommon/ColorResourceUtils.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jsJvmCommon/ColorResourceUtils.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jsJvmCommon/ColorResourceUtils.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jsJvmCommon/GenerateImageUtil.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jsJvmCommon/GenerateImageUtil.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jsJvmCommon/GenerateImageUtil.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jsJvmCommon/GenerateImageUtil.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmAssetsGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmAssetsGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmAssetsGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmColorsGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmColorsGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmColorsGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmFilesGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFilesGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmFilesGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmFontsGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmFontsGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmFontsGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmImagesGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmImagesGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmImagesGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmMRGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmMRGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmMRGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmPluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmPluralsGenerator.kt similarity index 100% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/jvm/JvmPluralsGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmPluralsGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/NOPContainerGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/NOPContainerGenerator.kt deleted file mode 100644 index 0f10997f9..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/container/NOPContainerGenerator.kt +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.rework.container - -import dev.icerock.gradle.rework.PlatformContainerGenerator - -class NOPContainerGenerator : PlatformContainerGenerator diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/serialization/FileSerializer.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/serialization/FileSerializer.kt similarity index 89% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/rework/serialization/FileSerializer.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/serialization/FileSerializer.kt index 225eb78d6..892ef0f21 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/rework/serialization/FileSerializer.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/serialization/FileSerializer.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.rework.serialization +package dev.icerock.gradle.serialization import kotlinx.serialization.KSerializer import kotlinx.serialization.descriptors.PrimitiveKind @@ -12,7 +12,7 @@ import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder import java.io.File -object FileSerializer : KSerializer { +internal object FileSerializer : KSerializer { override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor( serialName = "FileSerializer", kind = PrimitiveKind.STRING diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt index 795d43981..db1fd53c6 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt @@ -13,6 +13,7 @@ import org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl import java.io.File import java.io.FileFilter +// TODO register tasks abstract class CopyExecutableResourcesToApp : DefaultTask() { @get:Internal abstract var linkTask: KotlinNativeLink diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyXCFrameworkResourcesToApp.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyXCFrameworkResourcesToApp.kt index 115376d41..4ee722f76 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyXCFrameworkResourcesToApp.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyXCFrameworkResourcesToApp.kt @@ -10,6 +10,7 @@ import org.gradle.api.tasks.TaskAction import java.io.File import java.io.FileFilter +// TODO register tasks open class CopyXCFrameworkResourcesToApp : DefaultTask() { init { group = "moko-resources" 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 9d787e8ce..37098c88c 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 @@ -5,30 +5,29 @@ package dev.icerock.gradle.tasks import dev.icerock.gradle.MRVisibility -import dev.icerock.gradle.configuration.getAndroidRClassPackage -import dev.icerock.gradle.rework.CodeConst -import dev.icerock.gradle.rework.PlatformContainerGenerator -import dev.icerock.gradle.rework.PlatformResourceGenerator -import dev.icerock.gradle.rework.ResourceTypeGenerator -import dev.icerock.gradle.rework.ResourcesFiles -import dev.icerock.gradle.rework.ResourcesGenerator -import dev.icerock.gradle.rework.container.AppleContainerGenerator -import dev.icerock.gradle.rework.container.JvmContainerGenerator -import dev.icerock.gradle.rework.container.NOPContainerGenerator -import dev.icerock.gradle.rework.metadata.container.ContainerMetadata -import dev.icerock.gradle.rework.metadata.container.ObjectMetadata -import dev.icerock.gradle.rework.metadata.container.ResourceType -import dev.icerock.gradle.rework.metadata.resource.StringMetadata -import dev.icerock.gradle.rework.string.AndroidStringResourceGenerator -import dev.icerock.gradle.rework.string.AppleStringResourceGenerator -import dev.icerock.gradle.rework.string.JsStringResourceGenerator -import dev.icerock.gradle.rework.string.JvmStringResourceGenerator -import dev.icerock.gradle.rework.string.NOPStringResourceGenerator -import dev.icerock.gradle.rework.string.StringResourceGenerator +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.PlatformContainerGenerator +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.generator.ResourceTypeGenerator +import dev.icerock.gradle.generator.ResourcesFiles +import dev.icerock.gradle.generator.ResourcesGenerator +import dev.icerock.gradle.generator.container.AppleContainerGenerator +import dev.icerock.gradle.generator.container.JvmContainerGenerator +import dev.icerock.gradle.generator.container.NOPContainerGenerator +import dev.icerock.gradle.generator.string.AndroidStringResourceGenerator +import dev.icerock.gradle.generator.string.AppleStringResourceGenerator +import dev.icerock.gradle.generator.string.JsStringResourceGenerator +import dev.icerock.gradle.generator.string.JvmStringResourceGenerator +import dev.icerock.gradle.generator.string.NOPStringResourceGenerator +import dev.icerock.gradle.generator.string.StringResourceGenerator +import dev.icerock.gradle.metadata.container.ContainerMetadata +import dev.icerock.gradle.metadata.container.ObjectMetadata +import dev.icerock.gradle.metadata.container.ResourceType +import dev.icerock.gradle.metadata.resource.StringMetadata import dev.icerock.gradle.toModifier import dev.icerock.gradle.utils.flatName +import dev.icerock.gradle.utils.getAndroidRClassPackage import dev.icerock.gradle.utils.isStrictLineBreaks -import kotlinx.serialization.InternalSerializationApi import kotlinx.serialization.KSerializer import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.json.Json @@ -120,7 +119,6 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { group = "moko-resources" } - @OptIn(InternalSerializationApi::class) @TaskAction fun generate() { val json = Json { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ArgbColor.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ArgbColor.kt index 7e6d69269..31f9f7352 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ArgbColor.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ArgbColor.kt @@ -4,7 +4,7 @@ package dev.icerock.gradle.utils -data class ArgbColor(val a: Float, val r: Float, val g: Float, val b: Float) +internal data class ArgbColor(val a: Float, val r: Float, val g: Float, val b: Float) @Suppress("MagicNumber") internal fun parseArgbColor(argbColor: Long): ArgbColor { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/KotlinNativeLinkExt.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/KotlinNativeLinkExt.kt index d5e5ac73d..9beaa7bd2 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/KotlinNativeLinkExt.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/KotlinNativeLinkExt.kt @@ -10,7 +10,7 @@ import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinNativeCompile import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink -val KotlinNativeLink.klibs: FileCollection +internal val KotlinNativeLink.klibs: FileCollection get() { return try { val getLibraries = @@ -28,7 +28,7 @@ val KotlinNativeLink.klibs: FileCollection } } -val Kotlin2JsCompile.klibs: FileCollection +internal val Kotlin2JsCompile.klibs: FileCollection get() { return try { val getClasspath = diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/KotlinSourceSetExt.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/KotlinSourceSetExt.kt index 26ae3d627..97d6300d6 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/KotlinSourceSetExt.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/KotlinSourceSetExt.kt @@ -6,37 +6,6 @@ package dev.icerock.gradle.utils import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import org.jetbrains.kotlin.gradle.utils.ObservableSet -import java.util.concurrent.atomic.AtomicBoolean internal val KotlinSourceSet.dependsOnObservable get() = this.dependsOn as ObservableSet - -@Suppress("ReturnCount") -internal fun KotlinSourceSet.isDependsOn(sourceSet: KotlinSourceSet): Boolean { - if (dependsOn.contains(sourceSet)) return true - dependsOn.forEach { parent -> - if (parent.isDependsOn(sourceSet)) return true - } - return false -} - -internal fun KotlinSourceSet.ifDependsOn( - sourceSet: KotlinSourceSet, - block: () -> Unit -) = ifDependsOn(sourceSet, AtomicBoolean(false), block) - -private fun KotlinSourceSet.ifDependsOn( - sourceSet: KotlinSourceSet, - sourceSetFound: AtomicBoolean, - block: () -> Unit -) { - if (this == sourceSet) { - if (sourceSetFound.compareAndSet(false, true)) { - block() - } - } else { - dependsOnObservable.forAll { parent -> - parent.ifDependsOn(sourceSet, sourceSetFound, block) - } - } -} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProjectExt.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProjectExt.kt new file mode 100644 index 000000000..67b64bb12 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProjectExt.kt @@ -0,0 +1,40 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.utils + +import com.android.build.gradle.BaseExtension +import com.android.build.gradle.api.AndroidSourceSet +import org.gradle.api.Project +import org.gradle.api.provider.Provider +import org.gradle.api.tasks.SourceSet +import org.gradle.kotlin.dsl.getByType +import org.w3c.dom.Document +import org.w3c.dom.Node +import org.w3c.dom.NodeList +import java.io.File +import javax.xml.parsers.DocumentBuilder +import javax.xml.parsers.DocumentBuilderFactory + + +internal fun Project.getAndroidRClassPackage(): Provider { + return provider { + val androidExt: BaseExtension = project.extensions.getByType() + androidExt.namespace ?: getAndroidPackage(androidExt.mainSourceSet.manifest.srcFile) + } +} + +private fun getAndroidPackage(manifestFile: File): String { + val dbFactory: DocumentBuilderFactory = DocumentBuilderFactory.newInstance() + val dBuilder: DocumentBuilder = dbFactory.newDocumentBuilder() + val doc: Document = dBuilder.parse(manifestFile) + + val manifestNodes: NodeList = doc.getElementsByTagName("manifest") + val manifest: Node = manifestNodes.item(0) + + return manifest.attributes.getNamedItem("package").textContent +} + +internal val BaseExtension.mainSourceSet: AndroidSourceSet + get() = this.sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/PropertiesExt.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/PropertiesExt.kt index 674c4f37b..35a682b18 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/PropertiesExt.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/PropertiesExt.kt @@ -16,11 +16,8 @@ internal fun Project.propertyString(name: String): String? { } internal fun Project.requiredPropertyString(name: String): String { - val property: Any = findProperty(name) + return propertyString(name) ?: throw GradleException("Required property $name not found") - - return property as? String - ?: throw GradleException("Property $name should be String") } internal val Project.isStrictLineBreaks: Boolean diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/TasksContainer.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/TasksContainer.kt deleted file mode 100644 index 483c0a621..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/TasksContainer.kt +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.utils - -import org.gradle.api.Task -import org.gradle.api.UnknownTaskException -import org.gradle.api.tasks.TaskContainer -import org.gradle.api.tasks.TaskProvider -import org.gradle.kotlin.dsl.named -import org.gradle.kotlin.dsl.register - -inline fun TaskContainer.maybeRegister( - taskName: String, - noinline configuration: T.() -> Unit -): TaskProvider = try { - named(taskName) -} catch (@Suppress("SwallowedException") ex: UnknownTaskException) { - register(taskName, configuration) -} diff --git a/resources-generator/src/test/kotlin/dev/icerock/gradle/rework/metadata/container/ContainerMetadataTest.kt b/resources-generator/src/test/kotlin/dev/icerock/gradle/generator/metadata/container/ContainerMetadataTest.kt similarity index 64% rename from resources-generator/src/test/kotlin/dev/icerock/gradle/rework/metadata/container/ContainerMetadataTest.kt rename to resources-generator/src/test/kotlin/dev/icerock/gradle/generator/metadata/container/ContainerMetadataTest.kt index 162ad7bcf..6e952f24a 100644 --- a/resources-generator/src/test/kotlin/dev/icerock/gradle/rework/metadata/container/ContainerMetadataTest.kt +++ b/resources-generator/src/test/kotlin/dev/icerock/gradle/generator/metadata/container/ContainerMetadataTest.kt @@ -1,9 +1,14 @@ -package dev.icerock.gradle.rework.metadata.container +package dev.icerock.gradle.generator.metadata.container -import dev.icerock.gradle.rework.metadata.resource.StringMetadata +import dev.icerock.gradle.metadata.container.ContainerMetadata +import dev.icerock.gradle.metadata.container.ExpectInterfaceMetadata +import dev.icerock.gradle.metadata.container.ObjectMetadata +import dev.icerock.gradle.metadata.container.ResourceType +import dev.icerock.gradle.metadata.resource.StringMetadata import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.json.Json import org.junit.Test +import kotlin.test.assertEquals class ContainerMetadataTest { @@ -30,11 +35,10 @@ class ContainerMetadataTest { ) val serializer = ListSerializer(ContainerMetadata.serializer()) - val json: String = Json.encodeToString(serializer, listOf(expectInter, obj)) - println(json) - + val input: List = listOf(expectInter, obj) + val json: String = Json.encodeToString(serializer, input) val list: List = Json.decodeFromString(serializer, json) - println(list) + assertEquals(expected = input, actual = list) } } From 9c4020356270d4d63450ef1b9ddc9763b1fdfcd8 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 8 Jan 2024 15:16:53 +0700 Subject: [PATCH 091/352] #535 migrate plurals to new generator --- .../dev/icerock/gradle/generator/CodeConst.kt | 1 + .../gradle/generator/ResourceTypeGenerator.kt | 44 ++-- .../gradle/generator/ResourcesGenerator.kt | 34 +-- .../plural/AndroidPluralResourceGenerator.kt | 76 ++++++ .../plural/ApplePluralResourceGenerator.kt | 109 +++++++++ .../plural/JsPluralResourceGenerator.kt | 138 +++++++++++ .../plural/JvmPluralResourceGenerator.kt | 108 +++++++++ .../plural/NOPPluralResourceGenerator.kt | 24 ++ .../plural/PluralResourceGenerator.kt | 101 ++++++++ .../icerock/gradle/generator/plural/Utils.kt | 20 ++ .../string/AppleStringResourceGenerator.kt | 14 +- .../string/JsStringResourceGenerator.kt | 30 +-- .../string/JvmStringResourceGenerator.kt | 3 + .../string/StringResourceGenerator.kt | 8 +- .../metadata/resource/ResourceMetadata.kt | 2 + .../gradle/oldgen/LocalizationGenerator.kt | 179 -------------- .../icerock/gradle/oldgen/PluralsGenerator.kt | 218 ------------------ .../oldgen/android/AndroidPluralsGenerator.kt | 78 ------- .../oldgen/apple/ApplePluralsGenerator.kt | 98 -------- .../gradle/oldgen/common/CommonMRGenerator.kt | 17 -- .../gradle/oldgen/js/JsPluralsGenerator.kt | 118 ---------- .../gradle/oldgen/jvm/JvmMRGenerator.kt | 55 ----- .../gradle/oldgen/jvm/JvmPluralsGenerator.kt | 63 ----- .../GenerateMultiplatformResourcesTask.kt | 59 ++++- .../dev/icerock/gradle/utils/ListExt.kt | 9 + .../shared/src/commonMain/kotlin/App.kt | 12 +- 26 files changed, 721 insertions(+), 897 deletions(-) create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/AndroidPluralResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/ApplePluralResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/JsPluralResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/JvmPluralResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/NOPPluralResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/PluralResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/Utils.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/LocalizationGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/PluralsGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidPluralsGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/ApplePluralsGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsPluralsGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmPluralsGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt index 155ff734e..2fc2249b7 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt @@ -9,6 +9,7 @@ import com.squareup.kotlinpoet.ClassName internal object CodeConst { val resourceContainerName = ClassName("dev.icerock.moko.resources", "ResourceContainer") val stringResourceName = ClassName("dev.icerock.moko.resources", "StringResource") + val pluralsResourceName = ClassName("dev.icerock.moko.resources", "PluralsResource") object Apple { val nsBundleName = ClassName("platform.Foundation", "NSBundle") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceTypeGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceTypeGenerator.kt index 3b73bfd04..d35046626 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceTypeGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceTypeGenerator.kt @@ -15,12 +15,15 @@ import dev.icerock.gradle.metadata.container.ObjectMetadata import dev.icerock.gradle.metadata.container.ResourceType import dev.icerock.gradle.metadata.resource.ResourceMetadata import dev.icerock.gradle.utils.capitalize +import dev.icerock.gradle.utils.filterClass import org.gradle.api.tasks.util.PatternFilterable +import kotlin.reflect.KClass internal class ResourceTypeGenerator( private val generationPackage: String, private val resourceClass: ClassName, private val resourceType: ResourceType, + private val metadataClass: KClass, private val visibilityModifier: KModifier, private val generator: ResourceGenerator, private val platformResourceGenerator: PlatformResourceGenerator, @@ -58,8 +61,7 @@ internal class ResourceTypeGenerator( metadata: List, interfaces: List ): GenerationResult? { - @Suppress("UNCHECKED_CAST") - val typeMetadata: List = metadata.mapNotNull { it as? T } + val typeMetadata: List = metadata.filterClass(typeClass = metadataClass) val typeInterfaces: List = interfaces .filter { it.resourceType == resourceType } @@ -96,8 +98,7 @@ internal class ResourceTypeGenerator( metadata: List, sourceSet: String ): GenerationResult? { - @Suppress("UNCHECKED_CAST") - val typeMetadata: List = metadata.mapNotNull { it as? T } + val typeMetadata: List = metadata.filterClass(typeClass = metadataClass) val typeInterface: ExpectInterfaceMetadata = interfaces .filter { it.resourceType == resourceType } .singleOrNull { it.sourceSet == sourceSet } @@ -126,7 +127,12 @@ internal class ResourceTypeGenerator( val typeInterfaces: List = interfaces .filter { typeObject.interfaces.contains(it.name) } - val interfaceResources: List = typeInterfaces.flatMap { it.resources } + val interfaceResources: List = typeInterfaces + .flatMap { it.resources } + .filterClass(metadataClass) + + val typeResources: List = typeObject.resources.filterClass(metadataClass) + val resources: List = (interfaceResources + typeResources) val objectBuilder: TypeSpec.Builder = TypeSpec .objectBuilder(typeObject.name) @@ -139,20 +145,14 @@ internal class ResourceTypeGenerator( ClassName(packageName = generationPackage, it.name) }) .also { builder -> - platformResourceGenerator.generateBeforeProperties( - builder, - (interfaceResources + typeObject.resources).mapNotNull { it as? T } - ) + platformResourceGenerator.generateBeforeProperties(builder, resources) } // add all properties of interfaces .addProperties(interfaceResources.map(::createOverrideProperty)) // add all properties of object - .addProperties(typeObject.resources.map(::createActualProperty)) + .addProperties(typeResources.map(::createActualProperty)) .also { builder -> - platformResourceGenerator.generateAfterProperties( - builder, - (interfaceResources + typeObject.resources).mapNotNull { it as? T } - ) + platformResourceGenerator.generateAfterProperties(builder, resources) } return GenerationResult( @@ -169,7 +169,7 @@ internal class ResourceTypeGenerator( fun generateObject( metadata: List ): GenerationResult? { - val typeResources: List = metadata.mapNotNull { it as? T } + val typeResources: List = metadata.filterClass(metadataClass) if (typeResources.isEmpty()) return null val objectName: String = resourceType.name.lowercase() @@ -201,31 +201,27 @@ internal class ResourceTypeGenerator( } fun generateFiles(resources: List) { - @Suppress("UNCHECKED_CAST") - val typeMetadata: List = resources.mapNotNull { it as? T } + val typeMetadata: List = resources.filterClass(metadataClass) platformResourceGenerator.generateResourceFiles(typeMetadata) } - private fun createSimpleProperty(resource: ResourceMetadata): PropertySpec { + private fun createSimpleProperty(resource: T): PropertySpec { return createProperty(resource) } - private fun createActualProperty(resource: ResourceMetadata): PropertySpec { + private fun createActualProperty(resource: T): PropertySpec { return createProperty(resource, KModifier.ACTUAL) } - private fun createOverrideProperty(resource: ResourceMetadata): PropertySpec { + private fun createOverrideProperty(resource: T): PropertySpec { return createProperty(resource, KModifier.OVERRIDE) } private fun createProperty( - resource: ResourceMetadata, + resource: T, modifier: KModifier? = null ): PropertySpec { - @Suppress("UNCHECKED_CAST") - resource as T - return generator.generateProperty(resource) .apply { if (modifier != null) addModifiers(modifier) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourcesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourcesGenerator.kt index 0cb1c5a94..e8247ecda 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourcesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourcesGenerator.kt @@ -41,9 +41,7 @@ internal class ResourcesGenerator( val outputMetadata: MutableList = mutableListOf() - val inputObject: ObjectMetadata? = inputMetadata.mapNotNull { it as? ObjectMetadata } - .singleOrNull() - if (inputObject == null) { + if (inputMetadata.isEmpty()) { // we not have expect - we should generate simple object val objects: List = typesGenerators.mapNotNull { typeGenerator -> typeGenerator.generateObject(ownMetadata) @@ -58,7 +56,8 @@ internal class ResourcesGenerator( .plus(typesGenerators.flatMap { it.getImports() }) .forEach { fileSpec.addImport(it.packageName, it.simpleNames) } - val contentHash: String = (inputMetadata + outputMetadata).mapNotNull { it.contentHash() } + val contentHash: String = (inputMetadata + outputMetadata) + .mapNotNull { it.contentHash() } .calculateHash() objectSpec.addContentHashProperty(contentHash) @@ -84,13 +83,18 @@ internal class ResourcesGenerator( .map { it.name } // then we should generate actual interfaces with resources at our level - val actualInterfaces: List = typesGenerators.mapNotNull { typeGenerator -> - typeGenerator.generateActualInterface( - interfaces = expectInterfaces.filterNot { alreadyActualInterfaces.contains(it.name) }, - metadata = ownMetadata, - sourceSet = sourceSetName - ) - } + val actualInterfaces: List = + typesGenerators.mapNotNull { typeGenerator -> + typeGenerator.generateActualInterface( + interfaces = expectInterfaces.filterNot { + alreadyActualInterfaces.contains( + it.name + ) + }, + metadata = ownMetadata, + sourceSet = sourceSetName + ) + } actualInterfaces.forEach { result -> fileSpec.addType(result.typeSpec) @@ -99,7 +103,8 @@ internal class ResourcesGenerator( // then we should generate dummy actual interfaces val dummyInterfaces: List = expectInterfaces.map { it.name } - .minus(actualInterfaces.map { (it.metadata as ActualInterfaceMetadata).name }.toSet()) + .minus(actualInterfaces.map { (it.metadata as ActualInterfaceMetadata).name } + .toSet()) .map { dummyInterfaceName -> GenerationResult( typeSpec = TypeSpec.interfaceBuilder(dummyInterfaceName) @@ -138,8 +143,9 @@ internal class ResourcesGenerator( .plus(typesGenerators.flatMap { it.getImports() }) .forEach { fileSpec.addImport(it.packageName, it.simpleNames) } - val contentHash: String = (inputMetadata + outputMetadata).mapNotNull { it.contentHash() } - .calculateHash() + val contentHash: String = + (inputMetadata + outputMetadata).mapNotNull { it.contentHash() } + .calculateHash() objectSpec.addContentHashProperty(contentHash) objectSpec.also(containerGenerator::generateBeforeTypes) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/AndroidPluralResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/AndroidPluralResourceGenerator.kt new file mode 100644 index 000000000..3dd6aef70 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/AndroidPluralResourceGenerator.kt @@ -0,0 +1,76 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.plural + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.generator.localization.LanguageType +import dev.icerock.gradle.metadata.resource.PluralMetadata +import org.apache.commons.text.StringEscapeUtils +import java.io.File + +internal class AndroidPluralResourceGenerator( + private val androidRClassPackage: String, + private val resourcesGenerationDir: File +) : PlatformResourceGenerator { + override fun imports(): List = listOf( + ClassName(androidRClassPackage, "R") + ) + + override fun generateInitializer(metadata: PluralMetadata): CodeBlock { + return CodeBlock.of("PluralsResource(R.plurals.%L)", processKey(metadata.key)) + } + + override fun generateResourceFiles(data: List) { + data.processLanguages().forEach { (lang, pluralMap) -> + generateLanguageFile( + language = LanguageType.fromLanguage(lang), + strings = pluralMap + ) + } + } + + private fun generateLanguageFile( + language: LanguageType, + strings: Map> + ) { + val valuesDir = File(resourcesGenerationDir, language.androidResourcesDir) + val stringsFile = File(valuesDir, "multiplatform_plurals.xml") + valuesDir.mkdirs() + + val header = + """ + + + """.trimIndent() + + val content = strings.map { (key, pluralMap) -> + val processedKey = processKey(key) + val start = "\t\n" + val items: String = pluralMap.map { (quantity, value) -> + val processedValue = StringEscapeUtils.escapeXml10(value) + "\t\t$processedValue" + }.joinToString("\n") + val end = "\n\t" + + start + items + end + }.joinToString("\n") + + val footer = + """ + + """.trimIndent() + + stringsFile.writeText(header + "\n") + stringsFile.appendText(content) + stringsFile.appendText("\n" + footer) + } + + // TODO should we do that? + private fun processKey(key: String): String { + return key.replace(".", "_") + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/ApplePluralResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/ApplePluralResourceGenerator.kt new file mode 100644 index 000000000..43bf2a667 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/ApplePluralResourceGenerator.kt @@ -0,0 +1,109 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.plural + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.generator.addAppleContainerBundleProperty +import dev.icerock.gradle.generator.localization.LanguageType +import dev.icerock.gradle.metadata.resource.PluralMetadata +import java.io.File + +internal class ApplePluralResourceGenerator( + private val baseLocalizationRegion: String, + private val resourcesGenerationDir: File +) : PlatformResourceGenerator { + override fun imports(): List = emptyList() + + override fun generateInitializer(metadata: PluralMetadata): CodeBlock { + return CodeBlock.of( + "PluralsResource(resourceId = %S, bundle = %L)", + metadata.key, + CodeConst.Apple.containerBundlePropertyName + ) + } + + override fun generateResourceFiles(data: List) { + data.processLanguages().forEach { (lang, strings) -> + generateLanguageFile( + language = LanguageType.fromLanguage(lang), + strings = strings + ) + } + } + + override fun generateBeforeProperties( + builder: TypeSpec.Builder, + metadata: List + ) { + builder.addAppleContainerBundleProperty() + } + + private fun generateLanguageFile( + language: LanguageType, + strings: Map> + ) { + val resDir = File(resourcesGenerationDir, language.appleResourcesDir) + val localizableFile = File(resDir, "Localizable.stringsdict") + resDir.mkdirs() + writeStringsFile(localizableFile, strings) + + if (language == LanguageType.Base) { + val regionDir = File(resourcesGenerationDir, "$baseLocalizationRegion.lproj") + regionDir.mkdirs() + val regionFile = File(regionDir, "Localizable.stringsdict") + writeStringsFile(regionFile, strings) + } + } + + private fun writeStringsFile(file: File, strings: Map>) { + val head = """ + + + + """ + + val content = strings.map { (key, pluralMap) -> + val start = """$key + + NSStringLocalizedFormatKey + %#@pluraled@ + pluraled + + NSStringFormatSpecTypeKey + NSStringPluralRuleType + NSStringFormatValueTypeKey + d +""" + + val items = pluralMap.map { (quantity, value) -> + val processedValue = value.escapeFormatArguments() + """ $quantity + $processedValue""" + }.joinToString(separator = "\n") + + val end = """ + + """ + + start + items + end + }.joinToString("\n") + + val footer = """ + +""" + + file.writeText(head) + file.appendText(content) + file.appendText(footer) + } + + private fun String.escapeFormatArguments(): String { + return this.replace(Regex("%(((?:\\.|\\d|\\$)*)[abcdefs])"), "%%$1") + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/JsPluralResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/JsPluralResourceGenerator.kt new file mode 100644 index 000000000..34ffe3132 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/JsPluralResourceGenerator.kt @@ -0,0 +1,138 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.plural + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.FunSpec +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.generator.addJsContainerStringsLoaderProperty +import dev.icerock.gradle.generator.addJsFallbackProperty +import dev.icerock.gradle.generator.addJsSupportedLocalesProperty +import dev.icerock.gradle.generator.localization.LanguageType +import dev.icerock.gradle.generator.platform.js.convertToMessageFormat +import dev.icerock.gradle.metadata.resource.PluralMetadata +import dev.icerock.gradle.utils.flatName +import kotlinx.serialization.json.buildJsonObject +import kotlinx.serialization.json.put +import java.io.File + +internal class JsPluralResourceGenerator( + resourcesPackageName: String, + private val resourcesGenerationDir: File +) : PlatformResourceGenerator { + private val flattenClassPackage: String = resourcesPackageName.flatName + + override fun imports(): List = emptyList() + + override fun generateInitializer(metadata: PluralMetadata): CodeBlock { + return CodeBlock.of( + "PluralsResource(key = %S, loader = %L)", + metadata.key, + CodeConst.Js.stringsLoaderPropertyName + ) + } + + override fun generateResourceFiles(data: List) { + data.processLanguages().forEach { (lang, strings) -> + generateLanguageFile( + language = LanguageType.fromLanguage(lang), + strings = strings + ) + } + } + + override fun generateBeforeProperties( + builder: TypeSpec.Builder, + metadata: List + ) { + builder.addSuperinterface(CodeConst.Js.loaderHolderName) + + builder.addJsFallbackProperty( + fallbackFilePath = LOCALIZATION_DIR + "/" + getFileNameForLanguage(LanguageType.Base) + ) + builder.addJsSupportedLocalesProperty( + bcpLangToPath = metadata.asSequence() + .flatMap { resource -> + resource.values.map { it.locale } + }.distinct().map { locale -> + LanguageType.fromLanguage(locale) + }.filterIsInstance().map { language -> + val fileName: String = getFileNameForLanguage(language) + language.toBcpString() to "$LOCALIZATION_DIR/$fileName" + }.toList() + ) + builder.addJsContainerStringsLoaderProperty() + } + + override fun generateAfterProperties( + builder: TypeSpec.Builder, + metadata: List + ) { + val languageKeysList: String = metadata.joinToString { it.key } + + val valuesFun: FunSpec = FunSpec.builder("values") + .addModifiers(KModifier.OVERRIDE) + .addStatement("return listOf($languageKeysList)") + .returns( + ClassName("kotlin.collections", "List") + .parameterizedBy(CodeConst.pluralsResourceName) + ) + .build() + + builder.addFunction(valuesFun) + } + + private fun generateLanguageFile( + language: LanguageType, + strings: Map> + ) { + val localizationDir = File(resourcesGenerationDir, LOCALIZATION_DIR) + localizationDir.mkdirs() + + val pluralsFile = File(localizationDir, getFileNameForLanguage(language)) + + val content: String = buildJsonObject { + strings.forEach { (key: String, pluralMap: Map) -> + val messageFormatString = StringBuilder().apply { + append("{ PLURAL, plural, ") + pluralMap.forEach { (pluralKey, pluralString) -> + // Zero isn't allowed in english (which is default for base), but we support it through =0 + val actPluralKey: String = when (pluralKey) { + "zero" -> "=0" + "two" -> "=2" + else -> pluralKey + } + + append(actPluralKey) + append(" ") + append("{") + append(pluralString.convertToMessageFormat()) + append("} ") + } + + append("}") + }.toString() + + put(key, messageFormatString) + } + }.toString() + + pluralsFile.writeText(content) + } + + private fun getFileNameForLanguage(language: LanguageType): String { + return "${flattenClassPackage}_${PLURALS_JSON_NAME}${language.jsResourcesSuffix}.json" + } + + private companion object { + const val PLURALS_JSON_NAME = "pluralsJson" + const val LOCALIZATION_DIR = "localization" + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/JvmPluralResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/JvmPluralResourceGenerator.kt new file mode 100644 index 000000000..ddcf0bbb2 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/JvmPluralResourceGenerator.kt @@ -0,0 +1,108 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.plural + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.PropertySpec +import com.squareup.kotlinpoet.STRING +import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.generator.localization.LanguageType +import dev.icerock.gradle.metadata.resource.PluralMetadata +import org.apache.commons.text.StringEscapeUtils +import java.io.File + +internal class JvmPluralResourceGenerator( + private val flattenClassPackage: String, + private val className: String, + private val resourcesGenerationDir: File +) : PlatformResourceGenerator { + override fun imports(): List = emptyList() + + override fun generateInitializer(metadata: PluralMetadata): CodeBlock { + return CodeBlock.of( + "PluralsResource(resourcesClassLoader = %L, bundleName = %L, key = %S)", + CodeConst.Jvm.resourcesClassLoaderPropertyName, + pluralsBundlePropertyName, + metadata.key + ) + } + + override fun generateResourceFiles(data: List) { + data.processLanguages().forEach { (lang, strings) -> + generateLanguageFile( + language = LanguageType.fromLanguage(lang), + strings = strings + ) + } + } + + override fun generateBeforeProperties( + builder: TypeSpec.Builder, + metadata: List + ) { + // FIXME duplication + val classLoaderProperty: PropertySpec = PropertySpec.builder( + CodeConst.Jvm.resourcesClassLoaderPropertyName, + CodeConst.Jvm.classLoaderName, + KModifier.OVERRIDE + ) + .initializer(CodeBlock.of(className + "." + CodeConst.Jvm.resourcesClassLoaderPropertyName)) + .build() + + builder.addProperty(classLoaderProperty) + + // FIXME duplication + val property: PropertySpec = PropertySpec.builder( + pluralsBundlePropertyName, + STRING, + KModifier.PRIVATE + ).initializer(CodeBlock.of("\"%L/%L\"", CodeConst.Jvm.localizationDir, getBundlePath())) + .build() + + builder.addProperty(property) + } + + private fun generateLanguageFile( + language: LanguageType, + strings: Map> + ) { + val fileDirName = "${getBundlePath()}${language.jvmResourcesSuffix}" + + val localizationDir = File(resourcesGenerationDir, CodeConst.Jvm.localizationDir) + localizationDir.mkdirs() + + val stringsFile = File(localizationDir, "$fileDirName.properties") + + val content: String = strings.map { (key, pluralMap) -> + val keysWithPlurals = pluralMap.map { (quantity, value) -> + "$key.$quantity" to value + } + keysWithPlurals.joinToString("\n") { (key, value) -> + "$key = ${convertXmlStringToJvmLocalization(value)}" + } + }.joinToString("\n") + + stringsFile.writeText(content) + } + + private fun getBundlePath(): String = "${flattenClassPackage}_${pluralsBundleName}" + + // FIXME duplication + // TODO should we do that? + private fun convertXmlStringToJvmLocalization(input: String): String { + return StringEscapeUtils.unescapeXml(input) + .replace("\n", "\\n") + .replace("\"", "\\\"") + } + + private companion object { + const val pluralsBundlePropertyName = "pluralsBundle" + const val pluralsBundleName = "mokoPluralsBundle" + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/NOPPluralResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/NOPPluralResourceGenerator.kt new file mode 100644 index 000000000..a14db214a --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/NOPPluralResourceGenerator.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.plural + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.metadata.resource.PluralMetadata + +internal class NOPPluralResourceGenerator : PlatformResourceGenerator { + override fun imports(): List { + TODO("Not yet implemented") + } + + override fun generateResourceFiles(data: List) { + TODO("Not yet implemented") + } + + override fun generateInitializer(metadata: PluralMetadata): CodeBlock { + TODO("Not yet implemented") + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/PluralResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/PluralResourceGenerator.kt new file mode 100644 index 000000000..7f9b300ff --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/PluralResourceGenerator.kt @@ -0,0 +1,101 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.plural + +import com.squareup.kotlinpoet.PropertySpec +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.ResourceGenerator +import dev.icerock.gradle.generator.localization.LanguageType +import dev.icerock.gradle.metadata.resource.PluralMetadata +import dev.icerock.gradle.utils.removeLineWraps +import org.w3c.dom.Document +import org.w3c.dom.Element +import org.w3c.dom.Node +import org.w3c.dom.NodeList +import java.io.File +import javax.xml.parsers.DocumentBuilder +import javax.xml.parsers.DocumentBuilderFactory + +private typealias KeyType = String +private typealias PluralMap = Map + +internal class PluralResourceGenerator( + private val strictLineBreaks: Boolean +) : ResourceGenerator { + + override fun generateMetadata(files: Set): List { + val keyLangText: Map> = files.flatMap { file -> + val language: LanguageType = LanguageType.fromFileName(file.parentFile.name) + val strings: Map = loadLanguageStrings(file) + strings.map { (key: KeyType, plural: PluralMap) -> + key to (language to plural) + } + }.groupBy( + keySelector = { it.first }, + valueTransform = { it.second } + ).mapValues { it.value.toMap() } + + return keyLangText.map { (key: KeyType, langText: Map) -> + PluralMetadata( + key = key, + values = langText.map { (lang: LanguageType, value: PluralMap) -> + PluralMetadata.LocaleItem( + locale = lang.language(), + values = value.map { (quantity: String, value: String) -> + PluralMetadata.PluralItem( + quantity = PluralMetadata.PluralItem.Quantity.valueOf(quantity.uppercase()), + value = value + ) + } + ) + } + ) + } + } + + override fun generateProperty(metadata: PluralMetadata): PropertySpec.Builder { + return PropertySpec.builder(metadata.key, CodeConst.pluralsResourceName) + } + + private fun loadLanguageStrings(stringsFile: File): Map { + val dbFactory: DocumentBuilderFactory = DocumentBuilderFactory.newInstance() + val dBuilder: DocumentBuilder = dbFactory.newDocumentBuilder() + val doc: Document = dBuilder.parse(stringsFile) + + val resultMap: MutableMap = mutableMapOf() + + doc.findPluralNodes().forEach { pluralNode -> + val pluralMap: MutableMap = mutableMapOf() + + val name: String = pluralNode.attributes.getNamedItem("name").textContent + val itemNodes: NodeList = pluralNode.getElementsByTagName("item") + for (j: Int in 0 until itemNodes.length) { + val item: Node = itemNodes.item(j) + + val quantity: String = item.attributes.getNamedItem("quantity").textContent.trim() + val value: String = item.textContent + + pluralMap[quantity] = if (strictLineBreaks) value else value.removeLineWraps() + } + + resultMap[name] = pluralMap + } + + return resultMap + } + + private fun Document.findPluralNodes(): Sequence = sequence { + SOURCE_PLURAL_NODE_NAMES.forEach { elementName -> + val pluralNodes: NodeList = getElementsByTagName(elementName) + for (i: Int in 0 until pluralNodes.length) { + yield(pluralNodes.item(i) as Element) + } + } + } + + private companion object { + val SOURCE_PLURAL_NODE_NAMES: List = listOf("plural", "plurals") + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/Utils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/Utils.kt new file mode 100644 index 000000000..91b6d243c --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/Utils.kt @@ -0,0 +1,20 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.plural + +import dev.icerock.gradle.metadata.resource.PluralMetadata + +internal fun List.processLanguages(): Map>> { + return this.flatMap { metadata -> + metadata.values.map { localeItem -> + val pluralMap: Map = localeItem.values + .associate { it.quantity.name.lowercase() to it.value } + localeItem.locale to (metadata.key to pluralMap) + } + }.groupBy( + keySelector = { it.first }, + valueTransform = { it.second } + ).mapValues { it.value.toMap() } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/AppleStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/AppleStringResourceGenerator.kt index 0e3aa191c..bb71c986a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/AppleStringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/AppleStringResourceGenerator.kt @@ -38,6 +38,13 @@ internal class AppleStringResourceGenerator( } } + override fun generateBeforeProperties( + builder: TypeSpec.Builder, + metadata: List + ) { + builder.addAppleContainerBundleProperty() + } + private fun generateLanguageFile(language: LanguageType, strings: Map) { val resDir = File(resourcesGenerationDir, language.appleResourcesDir) val localizableFile = File(resDir, "Localizable.strings") @@ -58,13 +65,6 @@ internal class AppleStringResourceGenerator( } } - override fun generateBeforeProperties( - builder: TypeSpec.Builder, - metadata: List - ) { - builder.addAppleContainerBundleProperty() - } - // TODO should we do that? private fun convertXmlStringToAppleLocalization(input: String): String { return StringEscapeUtils.unescapeXml(input) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/JsStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/JsStringResourceGenerator.kt index c8bb813e4..5c5dca8be 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/JsStringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/JsStringResourceGenerator.kt @@ -48,21 +48,6 @@ internal class JsStringResourceGenerator( } } - private fun generateLanguageFile(language: LanguageType, strings: Map) { - val localizationDir = File(resourcesGenerationDir, LOCALIZATION_DIR) - localizationDir.mkdirs() - - val stringsFile = File(localizationDir, getFileNameForLanguage(language)) - - val content: String = buildJsonObject { - strings.forEach { (key: String, value: String) -> - put(key, value.convertToMessageFormat()) - } - }.toString() - - stringsFile.writeText(content) - } - override fun generateBeforeProperties( builder: TypeSpec.Builder, metadata: List @@ -104,6 +89,21 @@ internal class JsStringResourceGenerator( builder.addFunction(valuesFun) } + private fun generateLanguageFile(language: LanguageType, strings: Map) { + val localizationDir = File(resourcesGenerationDir, LOCALIZATION_DIR) + localizationDir.mkdirs() + + val stringsFile = File(localizationDir, getFileNameForLanguage(language)) + + val content: String = buildJsonObject { + strings.forEach { (key: String, value: String) -> + put(key, value.convertToMessageFormat()) + } + }.toString() + + stringsFile.writeText(content) + } + private fun getFileNameForLanguage(language: LanguageType): String { return "${flattenClassPackage}_${STRINGS_JSON_NAME}${language.jsResourcesSuffix}.json" } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/JvmStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/JvmStringResourceGenerator.kt index c32deb248..7052ccac2 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/JvmStringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/JvmStringResourceGenerator.kt @@ -46,6 +46,7 @@ internal class JvmStringResourceGenerator( builder: TypeSpec.Builder, metadata: List ) { + // FIXME duplication val classLoaderProperty: PropertySpec = PropertySpec.builder( CodeConst.Jvm.resourcesClassLoaderPropertyName, CodeConst.Jvm.classLoaderName, @@ -56,6 +57,7 @@ internal class JvmStringResourceGenerator( builder.addProperty(classLoaderProperty) + // FIXME duplication val property: PropertySpec = PropertySpec.builder( stringsBundlePropertyName, STRING, @@ -83,6 +85,7 @@ internal class JvmStringResourceGenerator( private fun getBundlePath(): String = "${flattenClassPackage}_${stringsBundleName}" + // FIXME duplication // TODO should we do that? private fun convertXmlStringToJvmLocalization(input: String): String { return StringEscapeUtils.unescapeXml(input) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/StringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/StringResourceGenerator.kt index 333c322ce..db1b0aaa7 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/StringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/StringResourceGenerator.kt @@ -49,6 +49,10 @@ internal class StringResourceGenerator( } } + override fun generateProperty(metadata: StringMetadata): PropertySpec.Builder { + return PropertySpec.builder(metadata.key, CodeConst.stringResourceName) + } + private fun loadLanguageStrings(stringsFile: File): Map { val dbFactory: DocumentBuilderFactory = DocumentBuilderFactory.newInstance() val dBuilder: DocumentBuilder = dbFactory.newDocumentBuilder() @@ -79,8 +83,4 @@ internal class StringResourceGenerator( return resultMap } - - override fun generateProperty(metadata: StringMetadata): PropertySpec.Builder { - return PropertySpec.builder(metadata.key, CodeConst.stringResourceName) - } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt index 445c54a96..825a07447 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt @@ -15,6 +15,7 @@ import java.io.File @Serializable internal sealed interface ResourceMetadata { + // TODO validate key at create val key: String fun contentHash(): String? @@ -52,6 +53,7 @@ internal data class PluralMetadata( ) { enum class Quantity { ZERO, ONE, TWO, FEW, MANY, OTHER; + } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/LocalizationGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/LocalizationGenerator.kt deleted file mode 100644 index f962f22ce..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/LocalizationGenerator.kt +++ /dev/null @@ -1,179 +0,0 @@ -///* -// * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator -// -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import com.squareup.kotlinpoet.PropertySpec -//import com.squareup.kotlinpoet.PropertySpec.Builder -//import com.squareup.kotlinpoet.TypeSpec -//import dev.icerock.gradle.metadata.getInterfaceName -//import dev.icerock.gradle.metadata.model.GeneratedObject -//import dev.icerock.gradle.metadata.model.GeneratedObjectModifier -//import dev.icerock.gradle.metadata.model.GeneratedObjectType -//import dev.icerock.gradle.metadata.model.GeneratedProperty -//import dev.icerock.gradle.metadata.model.GeneratorType -//import kotlinx.serialization.json.JsonElement -//import kotlinx.serialization.json.JsonObject -//import org.gradle.api.Project -//import java.io.File -// -//abstract class LocalizationGenerator : MRGenerator.Generator { -// -// override fun generateObject( -// project: Project, -// inputMetadata: List, -// outputMetadata: GeneratedObject, -// assetsGenerationDir: File, -// resourcesGenerationDir: File, -// objectBuilder: TypeSpec.Builder, -// ): MRGenerator.GenerationResult? { -// // Read previous languages map from metadata -// // if target object is expect object or interface return emptyMap() -// val previousLanguagesMap: Map> = getPreviousLanguagesMap( -// inputMetadata = inputMetadata, -// targetObject = outputMetadata -// ) -// -// // Read actual resources of target -// // If target object is actual object: skip read files again -// // -// // Structure: language - key - value -// val languageMap: Map> = -// if (outputMetadata.isActualObject || outputMetadata.isTargetObject) { -// emptyMap() -// } else { -// loadLanguageMap() -// } -// -// // Sum of previous and target language fields -// val languagesAllMaps: Map> = getLanguagesAllMaps( -// previousLanguageMaps = previousLanguagesMap, -// languageMap = languageMap -// ) -// val languageKeyValues: Map = languagesAllMaps[LanguageType.Base].orEmpty() -// -// beforeGenerateResources(objectBuilder, languagesAllMaps) -// -// val result: MRGenerator.GenerationResult = createTypeSpec( -// inputMetadata = inputMetadata, -// targetObject = outputMetadata, -// keys = languageKeyValues.keys.toList(), -// languageMap = languagesAllMaps, -// objectBuilder = objectBuilder -// ) ?: return null -// -// languagesAllMaps.forEach { (language: LanguageType, strings: Map) -> -// generateResources( -// resourcesGenerationDir = resourcesGenerationDir, -// language = language, -// strings = strings -// ) -// } -// -// return result -// } -// -// private fun createTypeSpec( -// inputMetadata: List, -// targetObject: GeneratedObject, -// keys: List, -// languageMap: Map>, -// objectBuilder: TypeSpec.Builder, -// ): MRGenerator.GenerationResult? { -// if (targetObject.isActual) { -// objectBuilder.addModifiers(KModifier.ACTUAL) -// } -// -// if (targetObject.isActualObject || targetObject.isTargetObject) { -// extendObjectBodyAtStart(objectBuilder) -// } -// -// val generatedProperties = mutableListOf() -// -// keys.forEach { key -> -// val name = key.replace(".", "_") -// -// //Create metadata property -// var generatedProperty = GeneratedProperty( -// modifier = GeneratedObjectModifier.None, -// name = name, -// data = JsonObject( -// content = getPropertyMetadata( -// key = key, -// languageMap = languageMap -// ) -// ) -// ) -// -// val property: Builder = PropertySpec.builder(name, resourceClassName) -// -// if (targetObject.isActualObject || targetObject.isTargetObject) { -// // Add modifier for property and setup metadata -// generatedProperty = generatedProperty.copy( -// modifier = addActualOverrideModifier( -// propertyName = name, -// property = property, -// inputMetadata = inputMetadata, -// targetObject = targetObject -// ) -// ) -// -// getPropertyInitializer(key)?.let { -// property.initializer(it) -// } -// } -// -// objectBuilder.addProperty(property.build()) -// generatedProperties.add(generatedProperty) -// } -// -// extendObjectBodyAtEnd(objectBuilder) -// -// if (generatedProperties.isEmpty()) return null -// -// // Add object in metadata with remove expect realisation -// return MRGenerator.GenerationResult( -// typeSpec = objectBuilder.build(), -// metadata = targetObject.copy(properties = generatedProperties) -// ) -// } -// -// abstract fun getPropertyMetadata( -// key: KeyType, -// languageMap: Map>, -// ): Map -// -// abstract fun getLanguagesAllMaps( -// previousLanguageMaps: Map>, -// languageMap: Map> -// ): Map> -// -// abstract fun getPreviousLanguagesMap( -// inputMetadata: List, -// targetObject: GeneratedObject, -// ): Map> -// -// protected abstract fun loadLanguageMap(): Map> -// protected abstract fun getPropertyInitializer(key: String): CodeBlock? -// -// protected open fun getClassModifiers(): Array = emptyArray() -// protected open fun getPropertyModifiers(): Array = emptyArray() -// -// protected open fun beforeGenerateResources( -// objectBuilder: TypeSpec.Builder, -// languageMap: Map>, -// ) = Unit -// -// protected open fun generateResources( -// resourcesGenerationDir: File, -// language: LanguageType, -// strings: Map, -// ) = Unit -// -// protected companion object { -// const val BASE_LANGUAGE = "base" -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/PluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/PluralsGenerator.kt deleted file mode 100644 index 0b4843545..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/PluralsGenerator.kt +++ /dev/null @@ -1,218 +0,0 @@ -///* -// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator -// -//import com.squareup.kotlinpoet.ClassName -//import dev.icerock.gradle.generator.android.AndroidPluralsGenerator -//import dev.icerock.gradle.generator.apple.ApplePluralsGenerator -//import dev.icerock.gradle.generator.common.CommonPluralsGenerator -//import dev.icerock.gradle.generator.js.JsPluralsGenerator -//import dev.icerock.gradle.generator.jvm.JvmPluralsGenerator -//import dev.icerock.gradle.metadata.model.GeneratedObject -//import dev.icerock.gradle.metadata.model.GeneratorType -//import dev.icerock.gradle.metadata.objectsWithProperties -//import dev.icerock.gradle.utils.removeLineWraps -//import kotlinx.serialization.json.Json -//import kotlinx.serialization.json.JsonElement -//import kotlinx.serialization.json.JsonObject -//import kotlinx.serialization.json.JsonPrimitive -//import kotlinx.serialization.json.decodeFromJsonElement -//import org.gradle.api.file.FileTree -//import org.w3c.dom.Document -//import org.w3c.dom.Element -//import java.io.File -//import javax.xml.parsers.DocumentBuilderFactory -// -//typealias PluralMap = Map -// -///** -// * How the plural element can be declared in our xml files. -// * -// * 'plurals' match the element name used on the Android platform. This allows us to upload the source xml as-is to -// * translation websites as they'll interpret it as an Android resource file. -// */ -//private val SOURCE_PLURAL_NODE_NAMES = listOf("plural", "plurals") -// -//abstract class PluralsGenerator( -// private val ownResourcesFileTree: FileTree, -// private val strictLineBreaks: Boolean -//) : LocalizationGenerator() { -// -// override val inputFiles: Iterable -// get() = ownResourcesFileTree.matching { it.include(PLURALS_MASK) }.files -// -// override val resourceClassName = ClassName("dev.icerock.moko.resources", "PluralsResource") -// override val mrObjectName: String = "plurals" -// -// override val type: GeneratorType = GeneratorType.Plurals -// -// override fun getLanguagesAllMaps( -// previousLanguageMaps: Map>, -// languageMap: Map> -// ): Map> { -// val resultLanguageMap: MutableMap> = mutableMapOf() -// -// resultLanguageMap.putAll(previousLanguageMaps) -// -// languageMap.forEach { (languageType: LanguageType, value: Map) -> -// -// val currentMap: MutableMap = -// previousLanguageMaps[languageType]?.toMutableMap() ?: mutableMapOf() -// -// value.forEach { (key, value) -> currentMap[key] = value } -// -// resultLanguageMap[languageType] = currentMap -// } -// -// return resultLanguageMap -// } -// -// override fun getPreviousLanguagesMap( -// inputMetadata: List, -// targetObject: GeneratedObject, -// ): Map> { -// if (!targetObject.isObject || !targetObject.isActual) return emptyMap() -// val json = Json -// val objectsWithProperties: List = inputMetadata.objectsWithProperties(targetObject) -// -// val languagesMaps = mutableMapOf>() -// -// objectsWithProperties.forEach { generatedObject -> -// generatedObject.properties.forEach { property -> -// val data = json.decodeFromJsonElement>(property.data) -// -// data.forEach { (languageTag, value) -> -// val languageType: LanguageType = if (languageTag == BASE_LANGUAGE) { -// LanguageType.Base -// } else { -// LanguageType.Locale(languageTag) -// } -// -// val currentMap: MutableMap = -// languagesMaps[languageType]?.toMutableMap() ?: mutableMapOf() -// currentMap[property.name] = value -// -// languagesMaps[languageType] = currentMap -// } -// } -// } -// -// return languagesMaps -// } -// -// override fun getPropertyMetadata( -// key: KeyType, -// languageMap: Map> -// ): Map { -// val values = mutableMapOf() -// -// languageMap.forEach { (languageType, plurals) -> -// plurals.forEach { (pluralKey: KeyType, value: Map) -> -// if (pluralKey == key) { -// values[languageType.language()] = JsonObject(content = value.mapValues { -// JsonPrimitive(it.value) -// }) -// } -// } -// } -// -// return values -// } -// -// override fun loadLanguageMap(): Map> { -// return inputFiles.map { file -> -// val language: LanguageType = LanguageType.fromFileName(file.parentFile.name) -// val strings: Map = loadLanguagePlurals(file) -// language to strings -// }.groupBy( -// keySelector = { it.first }, -// valueTransform = { it.second } -// ).mapValues { value -> -// val maps = value.value -// maps.fold(mutableMapOf()) { result, keyValueMap -> -// result.putAll(keyValueMap) -// result -// } -// } -// } -// -// override fun getImports(): List = emptyList() -// -// private fun loadLanguagePlurals(pluralsFile: File): Map { -// val dbFactory = DocumentBuilderFactory.newInstance() -// val dBuilder = dbFactory.newDocumentBuilder() -// val doc = dBuilder.parse(pluralsFile) -// -// val mutableMap = mutableMapOf() -// -// doc.findPluralNodes().forEach { pluralNode -> -// val pluralMap = mutableMapOf() -// -// val name = pluralNode.attributes.getNamedItem("name").textContent -// -// val itemNodes = pluralNode.getElementsByTagName("item") -// for (j in 0 until itemNodes.length) { -// val item = itemNodes.item(j) -// -// val quantity = item.attributes.getNamedItem("quantity").textContent.trim() -// val value = item.textContent -// -// pluralMap[quantity] = if (strictLineBreaks) value else value.removeLineWraps() -// } -// -// mutableMap[name] = pluralMap -// } -// -// return mutableMap -// } -// -// private fun Document.findPluralNodes() = sequence { -// SOURCE_PLURAL_NODE_NAMES.forEach { elementName -> -// val pluralNodes = getElementsByTagName(elementName) -// for (i in 0 until pluralNodes.length) { -// yield(pluralNodes.item(i) as Element) -// } -// } -// } -// -// class Feature( -// private val settings: MRGenerator.Settings -// ) : ResourceGeneratorFeature { -// override fun createCommonGenerator(): PluralsGenerator = CommonPluralsGenerator( -// ownResourcesFileTree = settings.ownResourcesFileTree, -// strictLineBreaks = settings.isStrictLineBreaks -// ) -// -// override fun createAppleGenerator(): PluralsGenerator = ApplePluralsGenerator( -// ownResourcesFileTree = settings.ownResourcesFileTree, -// strictLineBreaks = settings.isStrictLineBreaks, -// baseLocalizationRegion = settings.iosLocalizationRegion -// ) -// -// override fun createAndroidGenerator(): PluralsGenerator = AndroidPluralsGenerator( -// ownResourcesFileTree = settings.ownResourcesFileTree, -// strictLineBreaks = settings.isStrictLineBreaks, -// androidRClassPackage = settings.androidRClassPackage, -// ) -// -// override fun createJvmGenerator(): PluralsGenerator = JvmPluralsGenerator( -// ownResourcesFileTree = settings.ownResourcesFileTree, -// strictLineBreaks = settings.isStrictLineBreaks, -// settings = settings -// ) -// -// override fun createJsGenerator(): PluralsGenerator = JsPluralsGenerator( -// ownResourcesFileTree = settings.ownResourcesFileTree, -// mrClassPackage = settings.packageName, -// strictLineBreaks = settings.isStrictLineBreaks -// ) -// } -// -// -// companion object { -// const val PLURALS_MASK = "**/plurals*.xml" -// val PLURALS_REGEX: Regex = "^.*/plurals.*.xml".toRegex() -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidPluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidPluralsGenerator.kt deleted file mode 100644 index 16d3eb8c1..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidPluralsGenerator.kt +++ /dev/null @@ -1,78 +0,0 @@ -///* -// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.android -// -//import com.squareup.kotlinpoet.ClassName -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import dev.icerock.gradle.generator.KeyType -//import dev.icerock.gradle.generator.LanguageType -//import dev.icerock.gradle.generator.NOPObjectBodyExtendable -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import dev.icerock.gradle.generator.PluralMap -//import dev.icerock.gradle.generator.PluralsGenerator -//import org.apache.commons.lang3.StringEscapeUtils -//import org.gradle.api.file.FileTree -//import org.gradle.api.provider.Provider -//import java.io.File -// -//class AndroidPluralsGenerator( -// ownResourcesFileTree: FileTree, -// strictLineBreaks: Boolean, -// private val androidRClassPackage: Provider, -//) : PluralsGenerator(ownResourcesFileTree, strictLineBreaks), -// ObjectBodyExtendable by NOPObjectBodyExtendable() { -// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyInitializer(key: String) = -// CodeBlock.of("PluralsResource(R.plurals.%L)", processKey(key)) -// -// override fun getImports(): List = listOf( -// ClassName(androidRClassPackage.get(), "R") -// ) -// -// override fun generateResources( -// resourcesGenerationDir: File, -// language: LanguageType, -// strings: Map, -// ) { -// val valuesDir = File(resourcesGenerationDir, language.androidResourcesDir) -// val stringsFile = File(valuesDir, "multiplatform_plurals.xml") -// valuesDir.mkdirs() -// -// val header = -// """ -// -// -// """.trimIndent() -// -// val content = strings.map { (key, pluralMap) -> -// val processedKey = processKey(key) -// val start = "\t\n" -// val items = pluralMap.map { (quantity, value) -> -// val processedValue = StringEscapeUtils.escapeXml(value) -// "\t\t$processedValue" -// }.joinToString("\n") -// val end = "\n\t" -// -// start + items + end -// }.joinToString("\n") -// -// val footer = -// """ -// -// """.trimIndent() -// -// stringsFile.writeText(header + "\n") -// stringsFile.appendText(content) -// stringsFile.appendText("\n" + footer) -// } -// -// private fun processKey(key: String): String { -// return key.replace(".", "_") -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/ApplePluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/ApplePluralsGenerator.kt deleted file mode 100644 index 231ec4985..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/ApplePluralsGenerator.kt +++ /dev/null @@ -1,98 +0,0 @@ -///* -// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.apple -// -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import dev.icerock.gradle.generator.KeyType -//import dev.icerock.gradle.generator.LanguageType -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import dev.icerock.gradle.generator.PluralMap -//import dev.icerock.gradle.generator.PluralsGenerator -//import org.gradle.api.file.FileTree -//import org.gradle.api.provider.Provider -//import java.io.File -// -//class ApplePluralsGenerator( -// ownResourcesFileTree: FileTree, -// strictLineBreaks: Boolean, -// private val baseLocalizationRegion: Provider -//) : PluralsGenerator(ownResourcesFileTree, strictLineBreaks), -// ObjectBodyExtendable by AppleGeneratorHelper() { -// -// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyInitializer(key: String) = CodeBlock.of( -// "PluralsResource(resourceId = %S, bundle = ${AppleMRGenerator.BUNDLE_PROPERTY_NAME})", -// key -// ) -// -// private fun writeStringsFile(file: File, strings: Map) { -// val head = """ -// -// -// -// """ -// -// val content = strings.map { (key, pluralMap) -> -// val start = """$key -// -// NSStringLocalizedFormatKey -// %#@pluraled@ -// pluraled -// -// NSStringFormatSpecTypeKey -// NSStringPluralRuleType -// NSStringFormatValueTypeKey -// d -//""" -// -// val items = pluralMap.map { (quantity, value) -> -// val processedValue = value.escapeFormatArguments() -// """ $quantity -// $processedValue""" -// }.joinToString(separator = "\n") -// -// val end = """ -// -// """ -// -// start + items + end -// }.joinToString("\n") -// -// val footer = """ -// -//""" -// -// file.writeText(head) -// file.appendText(content) -// file.appendText(footer) -// } -// -// override fun generateResources( -// resourcesGenerationDir: File, -// language: LanguageType, -// strings: Map -// ) { -// val resDir = File(resourcesGenerationDir, language.appleResourcesDir) -// val localizableFile = File(resDir, "Localizable.stringsdict") -// resDir.mkdirs() -// writeStringsFile(localizableFile, strings) -// -// if (language == LanguageType.Base) { -// val localRegion: String = baseLocalizationRegion.get() -// val regionDir = File(resourcesGenerationDir, "$localRegion.lproj") -// regionDir.mkdirs() -// val regionFile = File(regionDir, "Localizable.stringsdict") -// writeStringsFile(regionFile, strings) -// } -// } -// -// private fun String.escapeFormatArguments(): String { -// return this.replace(Regex("%(((?:\\.|\\d|\\$)*)[abcdefs])"), "%%$1") -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/common/CommonMRGenerator.kt index c13795d37..2809f81ac 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/common/CommonMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/common/CommonMRGenerator.kt @@ -18,20 +18,3 @@ //// it.dependsOn(generationTask) //// } //// } - -// val generatorType: GeneratorType = -// if (file.path.matches(StringsGenerator.STRINGS_REGEX)) { -// GeneratorType.Strings -// } else if (file.path.matches(PluralsGenerator.PLURALS_REGEX)) { -// GeneratorType.Plurals -// } else if (file.path.matches(ColorsGenerator.COLORS_REGEX)) { -// GeneratorType.Colors -// } else if (file.parentFile.name == "images") { -// GeneratorType.Images -// } else if (file.parentFile.name == "files") { -// GeneratorType.Files -// } else if (file.parentFile.name == "fonts") { -// GeneratorType.Fonts -// } else if (file.path.matches(AssetsGenerator.ASSETS_REGEX)) { -// GeneratorType.Assets -// } else return@mapNotNull null diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsPluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsPluralsGenerator.kt deleted file mode 100644 index 1bb093c0b..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsPluralsGenerator.kt +++ /dev/null @@ -1,118 +0,0 @@ -///* -// * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.js -// -//import com.squareup.kotlinpoet.ClassName -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.FunSpec -//import com.squareup.kotlinpoet.KModifier -//import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -//import com.squareup.kotlinpoet.TypeSpec -//import dev.icerock.gradle.generator.KeyType -//import dev.icerock.gradle.generator.LanguageType -//import dev.icerock.gradle.generator.NOPObjectBodyExtendable -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import dev.icerock.gradle.generator.PluralMap -//import dev.icerock.gradle.generator.PluralsGenerator -//import dev.icerock.gradle.utils.flatName -//import kotlinx.serialization.json.buildJsonObject -//import kotlinx.serialization.json.put -//import org.gradle.api.file.FileTree -//import java.io.File -// -//class JsPluralsGenerator( -// ownResourcesFileTree: FileTree, -// mrClassPackage: String, -// strictLineBreaks: Boolean -//) : PluralsGenerator(ownResourcesFileTree, strictLineBreaks), -// ObjectBodyExtendable by NOPObjectBodyExtendable() { -// -// private val flattenClassPackage = mrClassPackage.flatName -// -// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyInitializer(key: String): CodeBlock { -// return CodeBlock.of("PluralsResource(key = %S, loader = stringsLoader)", key) -// } -// -// override fun beforeGenerateResources( -// objectBuilder: TypeSpec.Builder, -// languageMap: Map> -// ) { -// objectBuilder.generateFallbackAndSupportedLanguageProperties( -// languages = languageMap.keys.toList(), -// folder = JsMRGenerator.LOCALIZATION_DIR, -// fallbackFilePropertyName = PLURALS_FALLBACK_FILE_URL_PROPERTY_NAME, -// fallbackFile = "${flattenClassPackage}_${PLURALS_JSON_NAME}.json", -// supportedLocalesPropertyName = JsMRGenerator.SUPPORTED_LOCALES_PROPERTY_NAME, -// getFileNameForLanguage = { language -> -// "${flattenClassPackage}_${PLURALS_JSON_NAME}${language.jsResourcesSuffix}.json" -// } -// ) -// val languageKeys = languageMap[LanguageType.Base].orEmpty().keys -// val languageKeysList = languageKeys.joinToString { it.replace(".", "_") } -// -// objectBuilder.addFunction( -// FunSpec.builder("values") -// .addModifiers(KModifier.OVERRIDE) -// .addStatement("return listOf($languageKeysList)") -// .returns( -// ClassName("kotlin.collections", "List") -// .parameterizedBy(resourceClassName) -// ) -// .build() -// ) -// } -// -// override fun generateResources( -// resourcesGenerationDir: File, -// language: LanguageType, -// strings: Map -// ) { -// val fileDirName = -// "${flattenClassPackage}_${PLURALS_JSON_NAME}${language.jsResourcesSuffix}" -// -// val localizationDir = File(resourcesGenerationDir, JsMRGenerator.LOCALIZATION_DIR).apply { -// mkdirs() -// } -// -// val pluralsFile = File(localizationDir, "$fileDirName.json") -// -// val content = buildJsonObject { -// strings.forEach { (key, pluralMap) -> -// val messageFormatString = StringBuilder().apply { -// append("{ PLURAL, plural, ") -// pluralMap.forEach { (pluralKey, pluralString) -> -// // Zero isn't allowed in english (which is default for base), but we support it through =0 -// val actPluralKey = when (pluralKey) { -// "zero" -> "=0" -// "two" -> "=2" -// else -> pluralKey -// } -// -// append(actPluralKey) -// append(" ") -// append("{") -// append(pluralString.convertToMessageFormat()) -// append("} ") -// } -// -// append("}") -// }.toString() -// -// put(key, messageFormatString) -// } -// }.toString() -// -// pluralsFile.writeText(content) -// } -// -// companion object { -// const val PLURALS_JSON_NAME = "pluralsJson" -// const val PLURALS_FALLBACK_FILE_URL_PROPERTY_NAME = "stringsFallbackFileUrl" -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmMRGenerator.kt index 90f86d866..6ca80777f 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmMRGenerator.kt @@ -1,54 +1,3 @@ -///* -// * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.jvm -// -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import com.squareup.kotlinpoet.PropertySpec -//import com.squareup.kotlinpoet.STRING -//import com.squareup.kotlinpoet.TypeSpec -//import dev.icerock.gradle.generator.TargetMRGenerator -//import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask -//import dev.icerock.gradle.utils.flatName -//import org.gradle.api.Project -//import org.gradle.jvm.tasks.Jar -//import org.gradle.kotlin.dsl.withType -//import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -//import java.io.File -// -//class JvmMRGenerator( -// project: Project, -// settings: Settings, -// generators: List -//) : TargetMRGenerator( -// project = project, -// settings = settings, -// generators = generators -//) { -// private val flattenClassName: String = settings.packageName.flatName -// -// override val resourcesGenerationDir: File = settings.resourcesDir.asFile -// -// override fun processMRClass(mrClass: TypeSpec.Builder) { -// super.processMRClass(mrClass) - -// mrClass.addProperty( -// PropertySpec.builder( -// PLURALS_BUNDLE_PROPERTY_NAME, -// STRING, -// KModifier.PRIVATE -// ).initializer( -// CodeBlock.of( -// "\"%L/%L\"", -// LOCALIZATION_DIR, -// "${flattenClassName}_$PLURALS_BUNDLE_NAME" -// ) -// ).build() -// ) -// } -// // // TODO not used. remove after complete migration of task configuration to Plugin configuration time //// override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { //// project.tasks.withType().configureEach { @@ -64,8 +13,4 @@ ////// ) //// } // -// companion object { -// const val PLURALS_BUNDLE_PROPERTY_NAME = "pluralsBundle" -// const val PLURALS_BUNDLE_NAME = "mokoPluralsBundle" -// } //} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmPluralsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmPluralsGenerator.kt deleted file mode 100644 index 07e953eef..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmPluralsGenerator.kt +++ /dev/null @@ -1,63 +0,0 @@ -///* -// * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.jvm -// -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import dev.icerock.gradle.generator.KeyType -//import dev.icerock.gradle.generator.LanguageType -//import dev.icerock.gradle.generator.MRGenerator -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import dev.icerock.gradle.generator.PluralMap -//import dev.icerock.gradle.generator.PluralsGenerator -//import dev.icerock.gradle.utils.flatName -//import org.gradle.api.file.FileTree -//import java.io.File -// -//class JvmPluralsGenerator( -// ownResourcesFileTree: FileTree, -// strictLineBreaks: Boolean, -// settings: MRGenerator.Settings -//) : PluralsGenerator(ownResourcesFileTree, strictLineBreaks), -// ObjectBodyExtendable by ClassLoaderExtender(settings.className) { -// -// private val flattenClassPackage: String = settings.packageName.flatName -// -// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyInitializer(key: String) = -// CodeBlock.of( -// "PluralsResource(resourcesClassLoader = resourcesClassLoader, bundleName = %L, key = %S)", -// JvmMRGenerator.PLURALS_BUNDLE_PROPERTY_NAME, -// key, -// ) -// -// override fun generateResources( -// resourcesGenerationDir: File, -// language: LanguageType, -// strings: Map -// ) { -// val fileDirName = -// "${flattenClassPackage}_${JvmMRGenerator.PLURALS_BUNDLE_NAME}${language.jvmResourcesSuffix}" -// -// val localizationDir = -// File(resourcesGenerationDir, JvmMRGenerator.LOCALIZATION_DIR).apply { mkdirs() } -// val stringsFile = File(localizationDir, "$fileDirName.properties") -// -// val content = strings.map { (key, pluralMap) -> -// val keysWithPlurals = pluralMap.map { (quantity, value) -> -// "$key.$quantity" to value -// } -// -// keysWithPlurals.joinToString("\n") { (key, value) -> -// "$key = ${convertXmlStringToJvmLocalization(value)}" -// } -// }.joinToString("\n") -// -// stringsFile.writeText(content) -// } -//} 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 37098c88c..6e3b7f007 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 @@ -14,6 +14,12 @@ import dev.icerock.gradle.generator.ResourcesGenerator import dev.icerock.gradle.generator.container.AppleContainerGenerator import dev.icerock.gradle.generator.container.JvmContainerGenerator import dev.icerock.gradle.generator.container.NOPContainerGenerator +import dev.icerock.gradle.generator.plural.AndroidPluralResourceGenerator +import dev.icerock.gradle.generator.plural.ApplePluralResourceGenerator +import dev.icerock.gradle.generator.plural.JsPluralResourceGenerator +import dev.icerock.gradle.generator.plural.JvmPluralResourceGenerator +import dev.icerock.gradle.generator.plural.NOPPluralResourceGenerator +import dev.icerock.gradle.generator.plural.PluralResourceGenerator import dev.icerock.gradle.generator.string.AndroidStringResourceGenerator import dev.icerock.gradle.generator.string.AppleStringResourceGenerator import dev.icerock.gradle.generator.string.JsStringResourceGenerator @@ -23,6 +29,7 @@ import dev.icerock.gradle.generator.string.StringResourceGenerator import dev.icerock.gradle.metadata.container.ContainerMetadata import dev.icerock.gradle.metadata.container.ObjectMetadata import dev.icerock.gradle.metadata.container.ResourceType +import dev.icerock.gradle.metadata.resource.PluralMetadata import dev.icerock.gradle.metadata.resource.StringMetadata import dev.icerock.gradle.toModifier import dev.icerock.gradle.utils.flatName @@ -160,7 +167,8 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { return ResourcesGenerator( containerGenerator = createPlatformContainerGenerator(), typesGenerators = listOf( - createStringGenerator() + createStringGenerator(), + createPluralsGenerator() ), resourcesPackageName = resourcesPackageName.get(), resourcesClassName = resourcesClassName.get(), @@ -193,6 +201,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { generationPackage = resourcesPackageName.get(), resourceClass = CodeConst.stringResourceName, resourceType = ResourceType.STRINGS, + metadataClass = StringMetadata::class, visibilityModifier = resourcesVisibility.get().toModifier(), generator = StringResourceGenerator( strictLineBreaks = project.isStrictLineBreaks @@ -202,6 +211,54 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { ) } + private fun createPluralsGenerator(): ResourceTypeGenerator { + return ResourceTypeGenerator( + generationPackage = resourcesPackageName.get(), + resourceClass = CodeConst.pluralsResourceName, + resourceType = ResourceType.PLURALS, + metadataClass = PluralMetadata::class, + visibilityModifier = resourcesVisibility.get().toModifier(), + generator = PluralResourceGenerator( + strictLineBreaks = project.isStrictLineBreaks + ), + platformResourceGenerator = createPlatformPluralGenerator(), + filter = { include("**/plurals*.xml") } + ) + } + + private fun createPlatformPluralGenerator(): PlatformResourceGenerator { + val resourcesGenerationDir: File = outputResourcesDir.get().asFile + return createByPlatform( + // TODO find way to remove this NOP + createCommon = { NOPPluralResourceGenerator() }, + createAndroid = { + AndroidPluralResourceGenerator( + androidRClassPackage = getAndroidR(), + resourcesGenerationDir = resourcesGenerationDir + ) + }, + createApple = { + ApplePluralResourceGenerator( + baseLocalizationRegion = iosBaseLocalizationRegion.get(), + resourcesGenerationDir = resourcesGenerationDir + ) + }, + createJvm = { + JvmPluralResourceGenerator( + flattenClassPackage = resourcesPackageName.get().flatName, + className = resourcesClassName.get(), + resourcesGenerationDir = resourcesGenerationDir + ) + }, + createJs = { + JsPluralResourceGenerator( + resourcesPackageName = resourcesPackageName.get(), + resourcesGenerationDir = resourcesGenerationDir + ) + } + ) + } + private fun getAndroidR(): String = project.getAndroidRClassPackage().get() private fun createPlatformStringGenerator(): PlatformResourceGenerator { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ListExt.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ListExt.kt index 01fb7c946..6370e939e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ListExt.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ListExt.kt @@ -5,6 +5,7 @@ package dev.icerock.gradle.utils import java.util.Enumeration +import kotlin.reflect.KClass internal fun List.toEnumeration(): Enumeration { return object : Enumeration { @@ -22,3 +23,11 @@ internal fun List.toEnumeration(): Enumeration { } } } + +internal fun List.filterClass(typeClass: KClass): List { + return this.filter { it::class == typeClass } + .map { + @Suppress("UNCHECKED_CAST") + it as T + } +} diff --git a/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt b/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt index ae95b5daa..64d5a3d3c 100644 --- a/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt +++ b/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt @@ -64,14 +64,14 @@ internal fun App() { onValueChange = { text = it } ) -// val counter: Int = text.length -// Text( -// modifier = Modifier.fillMaxWidth() -// .padding(vertical = 8.dp), -// text = stringResource(MR.plurals.chars_count, counter, counter), + val counter: Int = text.length + Text( + modifier = Modifier.fillMaxWidth() + .padding(vertical = 8.dp), + text = stringResource(MR.plurals.chars_count, counter, counter), // color = colorResource(MR.colors.textColor), // fontFamily = fontFamilyResource(MR.fonts.cormorant.italic) -// ) + ) Button(onClick = { text = "Hello, ${getPlatformName()}" }) { Text(text = stringResource(MR.strings.hello_world)) From 6833e96ecfda8f40c81e391b34f46fc4ed8ef5da Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Tue, 9 Jan 2024 20:38:32 +0700 Subject: [PATCH 092/352] #535 images generator migration --- .../gradle/MultiplatformResourcesPlugin.kt | 9 +- .../MultiplatformResourcesPluginExtension.kt | 2 + ...n.kt => PackAppleResourcesToKLibAction.kt} | 71 +++-- .../dev/icerock/gradle/generator/CodeConst.kt | 4 + .../image/AndroidImageResourceGenerator.kt | 107 +++++++ .../image/AppleImageResourceGenerator.kt | 107 +++++++ .../generator/image/ImageResourceGenerator.kt | 43 +++ .../image/JsImageResourceGenerator.kt | 64 +++++ .../image/JvmImageResourceGenerator.kt | 56 ++++ .../image/NOPImageResourceGenerator.kt | 24 ++ .../icerock/gradle/generator/image/Utils.kt | 30 ++ .../platform/apple/SetupAppleUtils.kt | 8 +- .../metadata/resource/ResourceMetadata.kt | 2 +- .../icerock/gradle/oldgen/ImagesGenerator.kt | 270 ------------------ .../oldgen/android/AndroidImagesGenerator.kt | 122 -------- .../oldgen/apple/AppleImagesGenerator.kt | 106 ------- .../gradle/oldgen/apple/AppleMRGenerator.kt | 36 --- .../gradle/oldgen/js/JsImagesGenerator.kt | 64 ----- .../icerock/gradle/oldgen/js/JsMRGenerator.kt | 5 - .../oldgen/jsJvmCommon/GenerateImageUtil.kt | 22 -- .../gradle/oldgen/jvm/JvmImagesGenerator.kt | 43 --- .../tasks/CopyExecutableResourcesToApp.kt | 3 +- .../GenerateMultiplatformResourcesTask.kt | 126 ++++---- .../dev/icerock/gradle/utils/FileExt.kt | 7 +- .../icerock/gradle/utils/createByPlatform.kt | 65 +++++ .../shared/src/commonMain/kotlin/App.kt | 22 +- 26 files changed, 643 insertions(+), 775 deletions(-) rename resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/{PackResourcesToKLibAction.kt => PackAppleResourcesToKLibAction.kt} (58%) create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/AndroidImageResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/AppleImageResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/ImageResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/JsImageResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/JvmImageResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/NOPImageResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/Utils.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/ImagesGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidImagesGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleImagesGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleMRGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsImagesGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jsJvmCommon/GenerateImageUtil.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmImagesGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/utils/createByPlatform.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 31ff29348..064c48471 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -156,12 +156,9 @@ open class MultiplatformResourcesPlugin : Plugin { resourcesGenerationDir = genTaskProvider.flatMap { it.outputResourcesDir.asFile }, - iosLocalizationRegion = genTaskProvider.flatMap { - it.iosBaseLocalizationRegion - }, - resourcePackageName = genTaskProvider.flatMap { - it.resourcesPackageName - } + iosLocalizationRegion = mrExtension.iosBaseLocalizationRegion, + resourcePackageName = mrExtension.resourcesPackage, + acToolMinimalDeploymentTarget = mrExtension.acToolMinimalDeploymentTarget ) } } 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 55edb85d5..2a8287f6e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPluginExtension.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPluginExtension.kt @@ -13,6 +13,7 @@ abstract class MultiplatformResourcesPluginExtension { abstract val iosBaseLocalizationRegion: Property abstract val staticFrameworkWarningEnabled: Property abstract val resourcesVisibility: Property + abstract val acToolMinimalDeploymentTarget: Property } internal fun MultiplatformResourcesPluginExtension.setupConvention(project: Project) { @@ -21,4 +22,5 @@ internal fun MultiplatformResourcesPluginExtension.setupConvention(project: Proj iosBaseLocalizationRegion.convention("en") staticFrameworkWarningEnabled.convention(true) resourcesVisibility.convention(MRVisibility.Public) + acToolMinimalDeploymentTarget.convention("9.0") } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/PackResourcesToKLibAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/PackAppleResourcesToKLibAction.kt similarity index 58% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/PackResourcesToKLibAction.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/PackAppleResourcesToKLibAction.kt index 13da669f7..e3d95ab21 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/PackResourcesToKLibAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/PackAppleResourcesToKLibAction.kt @@ -4,6 +4,7 @@ package dev.icerock.gradle.actions.apple +import dev.icerock.gradle.generator.CodeConst import dev.icerock.gradle.generator.platform.apple.LoadableBundle import dev.icerock.gradle.utils.unzipTo import org.gradle.api.Action @@ -15,29 +16,36 @@ import org.jetbrains.kotlin.konan.file.zipDirAs import java.io.File import java.util.Properties -internal class PackResourcesToKLibAction( +internal class PackAppleResourcesToKLibAction( private val assetsDirectory: Provider, private val baseLocalizationRegion: Provider, private val resourcePackageName: Provider, private val resourcesGenerationDir: Provider, + private val acToolMinimalDeploymentTarget: Provider ) : Action { override fun execute(task: Task) { task as KotlinNativeCompile - val klibFile: File = task.outputFile.get() - val repackDir = File(klibFile.parent, klibFile.nameWithoutExtension) - val defaultDir = File(repackDir, "default") - val resRepackDir = File(defaultDir, "resources") val assetsDirectory: File = assetsDirectory.get() val resourcesGenerationDir: File = resourcesGenerationDir.get() - if (resourcesGenerationDir.exists().not() - || resourcesGenerationDir.listFiles()?.isEmpty() != false - ) { + val resourcesExists: Boolean = listOf( + assetsDirectory, + resourcesGenerationDir + ).any { file -> + file.exists() && file.listFiles()?.isNotEmpty() == true + } + + if (!resourcesExists) { task.logger.info("Resources not found. Skip klib repack action.") return } + val klibFile: File = task.outputFile.get() + val repackDir = File(klibFile.parent, klibFile.nameWithoutExtension) + val defaultDir = File(repackDir, "default") + val resRepackDir = File(defaultDir, "resources") + task.logger.info("Adding resources to klib file `{}`", klibFile) unzipTo(zipFile = klibFile, outputDirectory = repackDir) @@ -45,7 +53,7 @@ internal class PackResourcesToKLibAction( val manifest = Properties() manifest.load(manifestFile.inputStream()) - val uniqueName = manifest["unique_name"] as String + val uniqueName: String = manifest["unique_name"] as String val loadableBundle = LoadableBundle( directory = resRepackDir, @@ -56,28 +64,37 @@ internal class PackResourcesToKLibAction( loadableBundle.write() - val process: Process = Runtime.getRuntime().exec( - "xcrun actool Assets.xcassets --compile . --platform iphoneos --minimum-deployment-target 9.0", - emptyArray(), - assetsDirectory.parentFile - ) - val errors: String = process.errorStream.bufferedReader().readText() - val input: String = process.inputStream.bufferedReader().readText() - val result: Int = process.waitFor() - if (result != 0) { - task.logger.error("can't compile assets - $result") - task.logger.info(input) - task.logger.error(errors) - throw GradleException("Assets compilation failed: $errors") - } else { - task.logger.info("assets compiled") - assetsDirectory.deleteRecursively() - } - resourcesGenerationDir.copyRecursively( loadableBundle.resourcesDir, overwrite = true ) + assetsDirectory.copyRecursively( + loadableBundle.resourcesDir, + overwrite = true + ) + + val rawAssetsDir = File(loadableBundle.resourcesDir, CodeConst.Apple.assetsDirectoryName) + if (rawAssetsDir.exists()) { + val process: Process = Runtime.getRuntime().exec( + "xcrun actool ${rawAssetsDir.name} --compile . --platform iphoneos --minimum-deployment-target ${acToolMinimalDeploymentTarget.get()}", + emptyArray(), + rawAssetsDir.parentFile + ) + val errors: String = process.errorStream.bufferedReader().readText() + val input: String = process.inputStream.bufferedReader().readText() + val result: Int = process.waitFor() + if (result != 0) { + task.logger.error("can't compile assets - $result") + task.logger.info(input) + task.logger.error(errors) + throw GradleException("Assets compilation failed: $errors") + } else { + task.logger.info("assets compiled") + rawAssetsDir.deleteRecursively() + } + } else { + task.logger.info("assets not found, compilation not required") + } val repackKonan = org.jetbrains.kotlin.konan.file.File(repackDir.path) val klibKonan = org.jetbrains.kotlin.konan.file.File(klibFile.path) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt index 2fc2249b7..a98fbe0c1 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt @@ -10,10 +10,14 @@ internal object CodeConst { val resourceContainerName = ClassName("dev.icerock.moko.resources", "ResourceContainer") val stringResourceName = ClassName("dev.icerock.moko.resources", "StringResource") val pluralsResourceName = ClassName("dev.icerock.moko.resources", "PluralsResource") + val imageResourceName = ClassName("dev.icerock.moko.resources", "ImageResource") object Apple { val nsBundleName = ClassName("platform.Foundation", "NSBundle") val loadableBundleName = ClassName("dev.icerock.moko.resources.utils", "loadableBundle") + + const val assetsDirectoryName = "Assets.xcassets" + const val resourcesBundlePropertyName = "bundle" const val containerBundlePropertyName = "nsBundle" } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/AndroidImageResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/AndroidImageResourceGenerator.kt new file mode 100644 index 000000000..5e3f058ed --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/AndroidImageResourceGenerator.kt @@ -0,0 +1,107 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.image + +import com.android.ide.common.vectordrawable.Svg2Vector +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.metadata.resource.ImageMetadata +import org.slf4j.Logger +import java.io.File +import java.io.FileOutputStream +import java.io.IOException +import java.io.OutputStream +import java.nio.file.Path +import kotlin.reflect.full.functions + +internal class AndroidImageResourceGenerator( + private val androidRClassPackage: String, + private val resourcesGenerationDir: File, + private val logger: Logger +) : PlatformResourceGenerator { + override fun imports(): List = listOf( + ClassName(androidRClassPackage, "R") + ) + + override fun generateInitializer(metadata: ImageMetadata): CodeBlock { + return CodeBlock.of("ImageResource(R.drawable.%L)", processKey(metadata.key)) + } + + override fun generateResourceFiles(data: List) { + data.flatMap { imageMetadata -> + imageMetadata.values.map { imageMetadata.key to it } + }.forEach { (key: String, item: ImageMetadata.ImageQualityItem) -> + val drawableDirName: String = "drawable" + when (item.quality) { + "0.75" -> "-ldpi" + "1" -> "-mdpi" + "1.5" -> "-hdpi" + "2" -> "-xhdpi" + "3" -> "-xxhdpi" + "4" -> "-xxxhdpi" + null -> "" + else -> { + logger.warn("ignore $item for android - unknown scale (${item.quality})") + return@forEach + } + } + + val drawableDir = File(resourcesGenerationDir, drawableDirName) + val processedKey: String = processKey(key) + + val resourceExtension: String = if (item.quality == null) "xml" + else item.filePath.extension + + val resourceFile = File(drawableDir, "$processedKey.$resourceExtension") + if (item.quality == null) { + parseSvgToVectorDrawable(item.filePath, resourceFile) + } else { + item.filePath.copyTo(resourceFile) + } + } + } + + private fun parseSvgToVectorDrawable(svgFile: File, vectorDrawableFile: File) { + try { + vectorDrawableFile.parentFile.mkdirs() + vectorDrawableFile.createNewFile() + FileOutputStream(vectorDrawableFile, false).use { os -> + parseSvgToXml(svgFile, os) + .takeIf { it.isNotEmpty() } + ?.let { error -> logger.warn("parse from $svgFile to xml:\n$error") } + } + } catch (e: IOException) { + logger.error("parse from $svgFile to xml error", e) + } + } + + private fun parseSvgToXml(file: File, os: OutputStream): String { + return try { + Svg2Vector.parseSvgToXml(Path.of(file.absolutePath), os) + } catch (e: NoSuchMethodError) { + logger.debug( + buildString { + append("Not found parseSvgToXml function with Path parameter. ") + append("Fallback to parseSvgToXml function with File parameter.") + }, + e + ) + val parseSvgToXmlFunction = Svg2Vector::class.functions.first { + // broken ktlint rule Indentation workaround + if (it.name != "parseSvgToXml") return@first false + if (it.parameters.size != 2) return@first false + if (it.parameters[0].type.classifier != File::class) return@first false + if (it.parameters[1].type.classifier != OutputStream::class) return@first false + return@first true + } + return parseSvgToXmlFunction.call(file, os) as String + } + } + + // TODO we need this? + private fun processKey(key: String): String { + return key.lowercase() + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/AppleImageResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/AppleImageResourceGenerator.kt new file mode 100644 index 000000000..774066746 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/AppleImageResourceGenerator.kt @@ -0,0 +1,107 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.image + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.generator.addAppleContainerBundleProperty +import dev.icerock.gradle.metadata.resource.ImageMetadata +import kotlinx.serialization.json.JsonArray +import kotlinx.serialization.json.JsonPrimitive +import kotlinx.serialization.json.buildJsonArray +import kotlinx.serialization.json.buildJsonObject +import org.gradle.api.InvalidUserDataException +import java.io.File + +internal class AppleImageResourceGenerator( + private val assetsGenerationDir: File +) : PlatformResourceGenerator { + override fun imports(): List = emptyList() + + override fun generateInitializer(metadata: ImageMetadata): CodeBlock { + return CodeBlock.of( + "ImageResource(assetImageName = %S, bundle = %L)", + metadata.key, + CodeConst.Apple.containerBundlePropertyName + ) + } + + override fun generateResourceFiles(data: List) { + val assetsDirectory = File(assetsGenerationDir, CodeConst.Apple.assetsDirectoryName) + + data.forEach { imageMetadata -> + val assetDir = File(assetsDirectory, "${imageMetadata.key}.imageset") + val contentsFile = File(assetDir, "Contents.json") + + val validItems: List = + imageMetadata.values.filter { item -> + item.quality == null || VALID_SIZES.any { item.quality == it.toString() } + } + + if (validItems.isEmpty()) { + val errorMessage: String = buildString { + val name: String = imageMetadata.key + appendLine("Apple Generator cannot find a valid scale for file with name \"${name}\".") + append("Note: Apple resources can have only 1x, 2x and 3x scale factors ") + append("(https://developer.apple.com/design/human-interface-guidelines/ios/") + appendLine("icons-and-images/image-size-and-resolution/).") + append("It is still possible to use 4x images for android, but you need to ") + append("add a valid iOS variant.") + } + throw InvalidUserDataException(errorMessage) + } + + validItems.forEach { it.filePath.copyTo(File(assetDir, it.filePath.name)) } + + val imagesContent: JsonArray = buildJsonArray { + validItems.map { item -> + buildJsonObject { + put("idiom", JsonPrimitive("universal")) + put("filename", JsonPrimitive(item.filePath.name)) + item.quality?.let { quality -> + put("scale", JsonPrimitive(quality + "x")) + } + } + }.forEach { add(it) } + } + + val content: String = buildJsonObject { + put("images", imagesContent) + put( + "info", + buildJsonObject { + put("version", JsonPrimitive(1)) + put("author", JsonPrimitive("xcode")) + } + ) + + if (validItems.any { it.quality == null }) { + put( + "properties", + buildJsonObject { + put("preserves-vector-representation", JsonPrimitive(true)) + } + ) + } + }.toString() + + contentsFile.writeText(content) + } + } + + override fun generateBeforeProperties( + builder: TypeSpec.Builder, + metadata: List + ) { + builder.addAppleContainerBundleProperty() + } + + private companion object { + val VALID_SIZES: IntRange = 1..3 + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/ImageResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/ImageResourceGenerator.kt new file mode 100644 index 000000000..6bfc3e002 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/ImageResourceGenerator.kt @@ -0,0 +1,43 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.image + +import com.squareup.kotlinpoet.PropertySpec +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.ResourceGenerator +import dev.icerock.gradle.metadata.resource.ImageMetadata +import dev.icerock.gradle.utils.nameWithoutScale +import dev.icerock.gradle.utils.scale +import dev.icerock.gradle.utils.svg +import java.io.File + +internal class ImageResourceGenerator : ResourceGenerator { + + override fun generateMetadata(files: Set): List { + return files.groupBy { extractKey(it) }.map { (key: String, files: List) -> + ImageMetadata( + key = key, + values = files.map { file -> + ImageMetadata.ImageQualityItem( + quality = if (file.svg) null else file.scale, + filePath = file + ) + } + ) + } + } + + override fun generateProperty(metadata: ImageMetadata): PropertySpec.Builder { + return PropertySpec.builder(metadata.key, CodeConst.imageResourceName) + } + + private fun extractKey(file: File): String { + return if (file.svg) { + file.nameWithoutExtension + } else { + file.nameWithoutScale + } + } +} \ No newline at end of file diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/JsImageResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/JsImageResourceGenerator.kt new file mode 100644 index 000000000..2ceaeb8fd --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/JsImageResourceGenerator.kt @@ -0,0 +1,64 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.image + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.FunSpec +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.metadata.resource.ImageMetadata +import java.io.File + +internal class JsImageResourceGenerator( + private val resourcesGenerationDir: File +) : PlatformResourceGenerator { + + override fun imports(): List = emptyList() + + override fun generateInitializer(metadata: ImageMetadata): CodeBlock { + val item: ImageMetadata.ImageQualityItem = metadata.getHighestQualityItem() + val fileName = "${metadata.key}.${item.filePath.extension}" + val requireDeclaration = """require("$IMAGES_DIR/$fileName")""" + return CodeBlock.of( + "ImageResource(fileUrl = js(%S) as String, fileName = %S)", + requireDeclaration, + fileName + ) + } + + override fun generateResourceFiles(data: List) { + generateHighestQualityImageResources( + resourcesGenerationDir = resourcesGenerationDir, + data = data, + imagesDirName = IMAGES_DIR + ) + } + + override fun generateAfterProperties( + builder: TypeSpec.Builder, + metadata: List + ) { + val languageKeysList: String = metadata.joinToString { it.key } + + val valuesFun: FunSpec = FunSpec.builder("values") + .addModifiers(KModifier.OVERRIDE) + .addStatement("return listOf($languageKeysList)") + .returns( + ClassName("kotlin.collections", "List") + .parameterizedBy(CodeConst.imageResourceName) + ) + .build() + + builder.addFunction(valuesFun) + } + + private companion object { + const val IMAGES_DIR = "images" + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/JvmImageResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/JvmImageResourceGenerator.kt new file mode 100644 index 000000000..b0cbdca93 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/JvmImageResourceGenerator.kt @@ -0,0 +1,56 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.image + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.PropertySpec +import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.metadata.resource.ImageMetadata +import java.io.File + +internal class JvmImageResourceGenerator( + private val className: String, + private val resourcesGenerationDir: File +) : PlatformResourceGenerator { + override fun imports(): List = emptyList() + + override fun generateInitializer(metadata: ImageMetadata): CodeBlock { + val item: ImageMetadata.ImageQualityItem = metadata.getHighestQualityItem() + val fileName = "${metadata.key}.${item.filePath.extension}" + return CodeBlock.of( + "ImageResource(resourcesClassLoader = %L, filePath = %S)", + CodeConst.Jvm.resourcesClassLoaderPropertyName, + "$IMAGES_DIR/${fileName}" + ) + } + + override fun generateResourceFiles(data: List) { + generateHighestQualityImageResources(resourcesGenerationDir, data, IMAGES_DIR) + } + + override fun generateBeforeProperties( + builder: TypeSpec.Builder, + metadata: List + ) { + // FIXME duplication + val classLoaderProperty: PropertySpec = PropertySpec.builder( + CodeConst.Jvm.resourcesClassLoaderPropertyName, + CodeConst.Jvm.classLoaderName, + KModifier.OVERRIDE + ) + .initializer(CodeBlock.of(className + "." + CodeConst.Jvm.resourcesClassLoaderPropertyName)) + .build() + + builder.addProperty(classLoaderProperty) + } + + private companion object { + const val IMAGES_DIR = "images" + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/NOPImageResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/NOPImageResourceGenerator.kt new file mode 100644 index 000000000..4353df036 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/NOPImageResourceGenerator.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.image + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.metadata.resource.ImageMetadata + +internal class NOPImageResourceGenerator() : PlatformResourceGenerator { + override fun imports(): List { + TODO("Not yet implemented") + } + + override fun generateResourceFiles(data: List) { + TODO("Not yet implemented") + } + + override fun generateInitializer(metadata: ImageMetadata): CodeBlock { + TODO("Not yet implemented") + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/Utils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/Utils.kt new file mode 100644 index 000000000..6322b8626 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/Utils.kt @@ -0,0 +1,30 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.image + +import dev.icerock.gradle.metadata.resource.ImageMetadata +import java.io.File + +internal fun generateHighestQualityImageResources( + resourcesGenerationDir: File, + data: List, + imagesDirName: String +) { + val imagesDir = File(resourcesGenerationDir, imagesDirName) + imagesDir.mkdirs() + + data.forEach { metadata -> + val item: ImageMetadata.ImageQualityItem = metadata.getHighestQualityItem() + val file: File = item.filePath + val key: String = metadata.key + + file.copyTo(File(imagesDir, "$key.${file.extension}")) + } +} + +internal fun ImageMetadata.getHighestQualityItem(): ImageMetadata.ImageQualityItem { + return values.singleOrNull { it.quality == null } + ?: values.maxBy { it.quality!!.toDouble() } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt index e01638835..785e8225e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt @@ -8,7 +8,7 @@ import com.android.build.gradle.internal.tasks.factory.dependsOn import dev.icerock.gradle.MultiplatformResourcesPluginExtension import dev.icerock.gradle.actions.apple.CopyResourcesFromKLibsToExecutableAction import dev.icerock.gradle.actions.apple.CopyResourcesFromKLibsToFrameworkAction -import dev.icerock.gradle.actions.apple.PackResourcesToKLibAction +import dev.icerock.gradle.actions.apple.PackAppleResourcesToKLibAction import dev.icerock.gradle.tasks.CopyFrameworkResourcesToAppEntryPointTask import dev.icerock.gradle.tasks.CopyFrameworkResourcesToAppTask import org.gradle.api.Action @@ -36,13 +36,15 @@ fun setupAppleKLibResources( resourcesGenerationDir: Provider, iosLocalizationRegion: Provider, resourcePackageName: Provider, + acToolMinimalDeploymentTarget: Provider ) { - compileTask.doLast ( - PackResourcesToKLibAction( + compileTask.doLast( + PackAppleResourcesToKLibAction( baseLocalizationRegion = iosLocalizationRegion, resourcePackageName = resourcePackageName, assetsDirectory = assetsDirectory, resourcesGenerationDir = resourcesGenerationDir, + acToolMinimalDeploymentTarget = acToolMinimalDeploymentTarget ) ) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt index 825a07447..73bf2339b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt @@ -67,7 +67,7 @@ internal data class ImageMetadata( ) : ResourceMetadata { @Serializable data class ImageQualityItem( - val quality: Int, + val quality: String?, val filePath: File ) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/ImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/ImagesGenerator.kt deleted file mode 100644 index c001387b4..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/ImagesGenerator.kt +++ /dev/null @@ -1,270 +0,0 @@ -///* -// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator -// -//import com.squareup.kotlinpoet.ClassName -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import com.squareup.kotlinpoet.PropertySpec -//import com.squareup.kotlinpoet.TypeSpec -//import dev.icerock.gradle.generator.android.AndroidImagesGenerator -//import dev.icerock.gradle.generator.apple.AppleImagesGenerator -//import dev.icerock.gradle.generator.common.CommonImagesGenerator -//import dev.icerock.gradle.generator.js.JsImagesGenerator -//import dev.icerock.gradle.generator.jvm.JvmImagesGenerator -//import dev.icerock.gradle.metadata.model.GeneratedObject -//import dev.icerock.gradle.metadata.model.GeneratedObjectModifier -//import dev.icerock.gradle.metadata.model.GeneratedProperty -//import dev.icerock.gradle.metadata.model.GeneratorType -//import dev.icerock.gradle.metadata.objectsWithProperties -//import dev.icerock.gradle.utils.withoutScale -//import kotlinx.serialization.json.Json -//import kotlinx.serialization.json.JsonElement -//import kotlinx.serialization.json.JsonObject -//import kotlinx.serialization.json.JsonPrimitive -//import kotlinx.serialization.json.decodeFromJsonElement -//import org.gradle.api.Project -//import org.gradle.api.file.FileTree -//import org.gradle.api.logging.Logger -//import java.io.File -// -//abstract class ImagesGenerator( -// private val resourcesFileTree: FileTree, -//) : MRGenerator.Generator { -// -// override val inputFiles: Iterable -// get() = resourcesFileTree.matching { -// it.include("images/**/*.png", "images/**/*.jpg", "images/**/*.svg") -// } -// -// override val resourceClassName = ClassName("dev.icerock.moko.resources", "ImageResource") -// override val mrObjectName: String = "images" -// -// override val type: GeneratorType = GeneratorType.Images -// -// override fun generateObject( -// project: Project, -// inputMetadata: List, -// outputMetadata: GeneratedObject, -// assetsGenerationDir: File, -// resourcesGenerationDir: File, -// objectBuilder: TypeSpec.Builder -// ): MRGenerator.GenerationResult? { -// val previousFilesMap: Map> = getPreviousImageFilesMap( -// inputMetadata = inputMetadata, -// targetObject = outputMetadata -// ) -// -// val imageFileMap: Map> = if ( -// outputMetadata.isActualObject || outputMetadata.isTargetObject -// ) { -// emptyMap() -// } else { -// inputFiles.getImageMap() -// } -// -// -// val allImagesMap: Map> = getAllImagesMap(previousFilesMap, imageFileMap) -// -// beforeGenerateResources(objectBuilder, allImagesMap.keys.sorted()) -// -// val result: MRGenerator.GenerationResult = createTypeSpec( -// inputMetadata = inputMetadata, -// targetObject = outputMetadata, -// fileNames = allImagesMap.keys.sorted(), -// allImagesMap = allImagesMap, -// objectBuilder = objectBuilder -// ) ?: return null -// -// generateResources( -// assetsGenerationDir = assetsGenerationDir, -// resourcesGenerationDir = resourcesGenerationDir, -// keyFileMap = allImagesMap.mapKeys { (key, _) -> -// key.substringBeforeLast(".") // Remove file extension from keys -// } -// ) -// -// return result -// } -// -// private fun createTypeSpec( -// inputMetadata: List, -// targetObject: GeneratedObject, -// fileNames: List, -// allImagesMap: Map>, -// objectBuilder: TypeSpec.Builder, -// ): MRGenerator.GenerationResult? { -// if (targetObject.isActual) { -// objectBuilder.addModifiers(KModifier.ACTUAL) -// } -// -// if (targetObject.isActualObject || targetObject.isTargetObject) { -// extendObjectBodyAtStart(objectBuilder) -// } -// -// val generatedProperties = mutableListOf() -// -// fileNames.forEach { fileName: String -> -// val updatedFileName = fileName.substringBeforeLast(".") -// .replace(".", "_") + ".${fileName.substringAfterLast(".")}" -// val propertyName = updatedFileName.substringBeforeLast(".") -// val property = PropertySpec.builder(propertyName, resourceClassName) -// -// var generatedProperty = GeneratedProperty( -// modifier = GeneratedObjectModifier.None, -// name = propertyName, -// data = JsonObject( -// content = getPropertyMetadata( -// fileName = fileName, -// allImagesMap = allImagesMap -// ) -// ) -// ) -// -// if (targetObject.isActualObject || targetObject.isTargetObject) { -// // Add modifier for property and setup metadata -// generatedProperty = generatedProperty.copy( -// modifier = addActualOverrideModifier( -// propertyName = propertyName, -// property = property, -// inputMetadata = inputMetadata, -// targetObject = targetObject -// ) -// ) -// -// getPropertyInitializer(updatedFileName)?.let { -// property.initializer(it) -// } -// } -// -// objectBuilder.addProperty(property.build()) -// generatedProperties.add(generatedProperty) -// } -// -// extendObjectBodyAtEnd(objectBuilder) -// -// if (generatedProperties.isEmpty()) return null -// -// return MRGenerator.GenerationResult( -// typeSpec = objectBuilder.build(), -// metadata = targetObject.copy(properties = generatedProperties) -// ) -// } -// -// private fun getPropertyMetadata( -// fileName: String, -// allImagesMap: Map>, -// ): Map { -// //Structure: FileName, Path -// val resultMap = mutableMapOf() -// -// allImagesMap[fileName]?.forEach { -// resultMap[it.name] = JsonPrimitive(it.path) -// } -// -// return resultMap -// } -// -// private fun getPreviousImageFilesMap( -// inputMetadata: List, -// targetObject: GeneratedObject, -// ): Map> { -// if (!targetObject.isObject || !targetObject.isActual) return emptyMap() -// -// val json = Json -// val objectsWithProperties: List = inputMetadata.objectsWithProperties( -// targetObject = targetObject -// ) -// -// val fileImage = mutableListOf() -// -// objectsWithProperties.forEach { generatedObject -> -// generatedObject.properties.forEach { property -> -// val data = json.decodeFromJsonElement>(property.data) -// -// data.forEach { -// fileImage.add(File(it.value.content)) -// } -// } -// } -// -// return fileImage.getImageMap() -// } -// -// private fun Iterable.getImageMap(): Map> { -// return this.groupBy { file -> -// // SVGs do not have scale suffixes, so we need to remove the extension first -// val key = file -// .nameWithoutExtension -// .withoutScale -// -// "$key.${file.extension}" -// } -// } -// -// private fun getAllImagesMap( -// previousFilesMap: Map>, -// imageFileMap: Map>, -// ): Map> { -// val resultMap = mutableMapOf>() -// -// previousFilesMap.forEach { map -> -// resultMap[map.key] = map.value -// } -// -// imageFileMap.forEach { map -> -// resultMap[map.key] = map.value -// } -// -// return resultMap -// } -// -// override fun getImports(): List = emptyList() -// -// protected open fun beforeGenerateResources( -// objectBuilder: TypeSpec.Builder, -// keys: List, -// ) = Unit -// -// protected open fun generateResources( -// assetsGenerationDir: File, -// resourcesGenerationDir: File, -// keyFileMap: Map>, -// ) = Unit -// -// abstract fun getClassModifiers(): Array -// -// abstract fun getPropertyModifiers(): Array -// -// abstract fun getPropertyInitializer(fileName: String): CodeBlock? -// -// class Feature( -// private val settings: MRGenerator.Settings, -// private val logger: Logger, -// ) : ResourceGeneratorFeature { -// override fun createCommonGenerator(): ImagesGenerator = CommonImagesGenerator( -// ownInputFileTree = settings.ownResourcesFileTree, -// ) -// -// override fun createAppleGenerator(): ImagesGenerator = AppleImagesGenerator( -// ownInputFileTree = settings.ownResourcesFileTree, -// ) -// -// override fun createAndroidGenerator(): ImagesGenerator = AndroidImagesGenerator( -// ownInputFileTree = settings.ownResourcesFileTree, -// androidRClassPackage = settings.androidRClassPackage, -// logger = logger -// ) -// -// override fun createJsGenerator(): ImagesGenerator = JsImagesGenerator( -// ownInputFileTree = settings.ownResourcesFileTree, -// ) -// -// override fun createJvmGenerator(): ImagesGenerator = JvmImagesGenerator( -// ownInputFileTree = settings.ownResourcesFileTree, -// settings = settings -// ) -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidImagesGenerator.kt deleted file mode 100644 index a4eb6c48a..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidImagesGenerator.kt +++ /dev/null @@ -1,122 +0,0 @@ -///* -// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.android -// -//import com.android.ide.common.vectordrawable.Svg2Vector -//import com.squareup.kotlinpoet.ClassName -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import dev.icerock.gradle.generator.ImagesGenerator -//import dev.icerock.gradle.generator.NOPObjectBodyExtendable -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import dev.icerock.gradle.utils.svg -//import org.gradle.api.file.FileTree -//import org.gradle.api.logging.Logger -//import org.gradle.api.provider.Provider -//import java.io.File -//import java.io.FileOutputStream -//import java.io.IOException -//import java.io.OutputStream -//import java.nio.file.Path -//import kotlin.reflect.full.functions -// -//class AndroidImagesGenerator( -// ownInputFileTree: FileTree, -// private val androidRClassPackage: Provider, -// private val logger: Logger -//) : ImagesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { -// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyInitializer(fileName: String): CodeBlock { -// val processedKey: String = processKey(fileName.substringBefore(".")) -// return CodeBlock.of("ImageResource(R.drawable.%L)", processedKey) -// } -// -// override fun getImports(): List = listOf( -// ClassName(androidRClassPackage.get(), "R") -// ) -// -// override fun generateResources( -// assetsGenerationDir: File, -// resourcesGenerationDir: File, -// keyFileMap: Map> -// ) { -// keyFileMap.flatMap { (key, files) -> -// files.map { key to it } -// }.forEach { (key, file) -> -// val scale = file.nameWithoutExtension.substringAfter("@").substringBefore("x") -// val drawableDirName = "drawable" + when (scale) { -// "0.75" -> "-ldpi" -// "1" -> "-mdpi" -// "1.5" -> "-hdpi" -// "2" -> "-xhdpi" -// "3" -> "-xxhdpi" -// "4" -> "-xxxhdpi" -// else -> { -// if (file.svg) { -// "" -// } else { -// logger.warn("ignore $file - unknown scale ($scale)") -// return@forEach -// } -// } -// } -// -// val drawableDir = File(resourcesGenerationDir, drawableDirName) -// val processedKey = processKey(key) -// -// val resourceExtension = if (file.svg) "xml" else file.extension -// val resourceFile = File(drawableDir, "$processedKey.$resourceExtension") -// if (file.svg) { -// parseSvgToVectorDrawable(file, resourceFile) -// } else { -// file.copyTo(resourceFile) -// } -// } -// } -// -// private fun parseSvgToVectorDrawable(svgFile: File, vectorDrawableFile: File) { -// try { -// vectorDrawableFile.parentFile.mkdirs() -// vectorDrawableFile.createNewFile() -// FileOutputStream(vectorDrawableFile, false).use { os -> -// parseSvgToXml(svgFile, os) -// .takeIf { it.isNotEmpty() } -// ?.let { error -> logger.warn("parse from $svgFile to xml:\n$error") } -// } -// } catch (e: IOException) { -// logger.error("parse from $svgFile to xml error", e) -// } -// } -// -// private fun parseSvgToXml(file: File, os: OutputStream): String { -// return try { -// Svg2Vector.parseSvgToXml(Path.of(file.absolutePath), os) -// } catch (e: NoSuchMethodError) { -// logger.debug( -// buildString { -// append("Not found parseSvgToXml function with Path parameter. ") -// append("Fallback to parseSvgToXml function with File parameter.") -// }, -// e -// ) -// val parseSvgToXmlFunction = Svg2Vector::class.functions.first { -// // broken ktlint rule Indentation workaround -// if (it.name != "parseSvgToXml") return@first false -// if (it.parameters.size != 2) return@first false -// if (it.parameters[0].type.classifier != File::class) return@first false -// if (it.parameters[1].type.classifier != OutputStream::class) return@first false -// return@first true -// } -// return parseSvgToXmlFunction.call(file, os) as String -// } -// } -// -// private fun processKey(key: String): String { -// return key.lowercase() -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleImagesGenerator.kt deleted file mode 100644 index 945766cc8..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleImagesGenerator.kt +++ /dev/null @@ -1,106 +0,0 @@ -///* -// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.apple -// -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import dev.icerock.gradle.generator.ImagesGenerator -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import dev.icerock.gradle.generator.apple.AppleMRGenerator.Companion.ASSETS_DIR_NAME -//import dev.icerock.gradle.utils.nameWithoutScale -//import dev.icerock.gradle.utils.scale -//import dev.icerock.gradle.utils.svg -//import kotlinx.serialization.json.JsonPrimitive -//import kotlinx.serialization.json.buildJsonArray -//import kotlinx.serialization.json.buildJsonObject -//import org.gradle.api.file.FileTree -//import java.io.File -// -//class AppleImagesGenerator( -// ownInputFileTree: FileTree, -//) : ImagesGenerator(resourcesFileTree = ownInputFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { -// -// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyInitializer(fileName: String): CodeBlock? { -// return CodeBlock.of( -// "ImageResource(assetImageName = %S, bundle = ${AppleMRGenerator.BUNDLE_PROPERTY_NAME})", -// fileName.substringBefore(".") -// ) -// } -// -// override fun generateResources( -// assetsGenerationDir: File, -// resourcesGenerationDir: File, -// keyFileMap: Map> -// ) { -// val assetsDirectory = File(assetsGenerationDir, ASSETS_DIR_NAME) -// -// keyFileMap.forEach { (key, files) -> -// val assetDir = File(assetsDirectory, "$key.imageset") -// val contentsFile = File(assetDir, "Contents.json") -// -// val validFiles = files.filter { file -> -// file.svg || VALID_SIZES.any { size -> file.scale == "${size}x" } -// } -// -// val uniqueNames = files.map { it.nameWithoutScale }.distinct() -// uniqueNames.forEach { name -> -// require(validFiles.any { it.nameWithoutScale == name }) { -// buildString { -// appendLine("Apple Generator cannot find a valid scale for file with name \"$name\".") -// append("Note: Apple resources can have only 1x, 2x and 3x scale factors ") -// append("(https://developer.apple.com/design/human-interface-guidelines/ios/") -// appendLine("icons-and-images/image-size-and-resolution/).") -// append("It is still possible to use 4x images for android, but you need to ") -// append("add a valid iOS variant.") -// } -// } -// } -// -// validFiles.forEach { it.copyTo(File(assetDir, it.name)) } -// -// val imagesContent = buildJsonArray { -// validFiles.map { file -> -// buildJsonObject { -// put("idiom", JsonPrimitive("universal")) -// put("filename", JsonPrimitive(file.name)) -// if (!file.svg) { -// put("scale", JsonPrimitive(file.scale)) -// } -// } -// }.forEach { add(it) } -// } -// -// val content = buildJsonObject { -// put("images", imagesContent) -// put( -// "info", -// buildJsonObject { -// put("version", JsonPrimitive(1)) -// put("author", JsonPrimitive("xcode")) -// } -// ) -// -// if (validFiles.any { file -> file.svg }) { -// put( -// "properties", -// buildJsonObject { -// put("preserves-vector-representation", JsonPrimitive(true)) -// } -// ) -// } -// }.toString() -// -// contentsFile.writeText(content) -// } -// } -// -// private companion object { -// val VALID_SIZES: IntRange = 1..3 -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleMRGenerator.kt deleted file mode 100644 index b7e8977f6..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleMRGenerator.kt +++ /dev/null @@ -1,36 +0,0 @@ -///* -// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.apple -// -//import com.squareup.kotlinpoet.ClassName -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import com.squareup.kotlinpoet.PropertySpec -//import com.squareup.kotlinpoet.STRING -//import com.squareup.kotlinpoet.TypeSpec -//import dev.icerock.gradle.generator.TargetMRGenerator -//import dev.icerock.gradle.utils.calculateResourcesHash -//import org.gradle.api.Project -// -//@Suppress("TooManyFunctions") -//class AppleMRGenerator( -// project: Project, -// settings: Settings, -// generators: List, -//) : TargetMRGenerator( -// project = project, -// settings = settings, -// generators = generators -//) { -// -// override fun beforeMRGeneration() { -// assetsGenerationDir.mkdirs() -// } -// -// companion object { -// const val BUNDLE_PROPERTY_NAME = "bundle" -// const val ASSETS_DIR_NAME = "Assets.xcassets" -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsImagesGenerator.kt deleted file mode 100644 index 86a6c8839..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsImagesGenerator.kt +++ /dev/null @@ -1,64 +0,0 @@ -///* -// * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.js -// -//import com.squareup.kotlinpoet.ClassName -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.FunSpec -//import com.squareup.kotlinpoet.KModifier -//import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -//import com.squareup.kotlinpoet.TypeSpec -//import dev.icerock.gradle.generator.ImagesGenerator -//import dev.icerock.gradle.generator.NOPObjectBodyExtendable -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import dev.icerock.gradle.generator.jsJvmCommon.generateHighestQualityImageResources -//import org.gradle.api.file.FileTree -//import java.io.File -// -//class JsImagesGenerator( -// ownInputFileTree: FileTree, -//) : ImagesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { -// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyInitializer(fileName: String): CodeBlock { -// val requireDeclaration = """require("$IMAGES_DIR/$fileName")""" -// return CodeBlock.of( -// "ImageResource(fileUrl = js(%S) as String, fileName = %S)", -// requireDeclaration, -// fileName -// ) -// } -// -// override fun beforeGenerateResources(objectBuilder: TypeSpec.Builder, keys: List) { -// val languageKeysList = keys.joinToString { key -> -// key.substringBeforeLast(".").replace(".", "_") -// } -// -// objectBuilder.addFunction( -// FunSpec.builder("values") -// .addModifiers(KModifier.OVERRIDE) -// .addStatement("return listOf($languageKeysList)") -// .returns( -// ClassName("kotlin.collections", "List") -// .parameterizedBy(resourceClassName) -// ) -// .build() -// ) -// } -// -// override fun generateResources( -// assetsGenerationDir: File, -// resourcesGenerationDir: File, -// keyFileMap: Map> -// ) { -// generateHighestQualityImageResources(resourcesGenerationDir, keyFileMap, IMAGES_DIR) -// } -// -// companion object { -// const val IMAGES_DIR = "images" -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsMRGenerator.kt index 1744df606..6a4f535de 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsMRGenerator.kt @@ -84,9 +84,4 @@ ////// task = generationTask, ////// ) //// } -// -// companion object { -// const val SUPPORTED_LOCALES_PROPERTY_NAME = "supportedLocales" -// const val LOCALIZATION_DIR = "localization" -// } //} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jsJvmCommon/GenerateImageUtil.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jsJvmCommon/GenerateImageUtil.kt deleted file mode 100644 index 55d79ccfb..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jsJvmCommon/GenerateImageUtil.kt +++ /dev/null @@ -1,22 +0,0 @@ -///* -// * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.jsJvmCommon -// -//import java.io.File -// -//fun generateHighestQualityImageResources( -// resourcesGenerationDir: File, -// keyFileMap: Map>, -// imagesDirName: String -//) { -// val imagesDir = File(resourcesGenerationDir, imagesDirName).apply { mkdirs() } -// -// keyFileMap.forEach { (key, files) -> -// val hqFile = files.maxByOrNull { -// it.nameWithoutExtension.substringAfter("@").substringBefore("x").toDouble() -// } ?: return -// hqFile.copyTo(File(imagesDir, "$key.${hqFile.extension}")) -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmImagesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmImagesGenerator.kt deleted file mode 100644 index c1cb4c84c..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmImagesGenerator.kt +++ /dev/null @@ -1,43 +0,0 @@ -///* -// * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.jvm -// -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import dev.icerock.gradle.generator.ImagesGenerator -//import dev.icerock.gradle.generator.MRGenerator -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import dev.icerock.gradle.generator.jsJvmCommon.generateHighestQualityImageResources -//import org.gradle.api.file.FileTree -//import java.io.File -// -//class JvmImagesGenerator( -// ownInputFileTree: FileTree, -// settings: MRGenerator.Settings -//) : ImagesGenerator(ownInputFileTree), -// ObjectBodyExtendable by ClassLoaderExtender(settings.className) { -// -// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyInitializer(fileName: String) = -// CodeBlock.of( -// "ImageResource(resourcesClassLoader = resourcesClassLoader, filePath = %S)", -// "$IMAGES_DIR/$fileName" -// ) -// -// override fun generateResources( -// assetsGenerationDir: File, -// resourcesGenerationDir: File, -// keyFileMap: Map> -// ) { -// generateHighestQualityImageResources(resourcesGenerationDir, keyFileMap, IMAGES_DIR) -// } -// -// companion object { -// private const val IMAGES_DIR = "images" -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt index db1fd53c6..a59c14f16 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt @@ -5,6 +5,7 @@ package dev.icerock.gradle.tasks import dev.icerock.gradle.utils.klibs +import dev.icerock.gradle.utils.toKonanFile import org.gradle.api.DefaultTask import org.gradle.api.tasks.Internal import org.gradle.api.tasks.TaskAction @@ -35,7 +36,7 @@ abstract class CopyExecutableResourcesToApp : DefaultTask() { .filter { library -> library.extension == "klib" } .filter(File::exists) .forEach { inputFile -> - val klibKonan = org.jetbrains.kotlin.konan.file.File(inputFile.path) + val klibKonan: org.jetbrains.kotlin.konan.file.File = inputFile.toKonanFile() val klib = KotlinLibraryLayoutImpl(klib = klibKonan, component = "default") val layout = klib.extractingToTemp 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 6e3b7f007..d2e286f78 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 @@ -14,6 +14,12 @@ import dev.icerock.gradle.generator.ResourcesGenerator import dev.icerock.gradle.generator.container.AppleContainerGenerator import dev.icerock.gradle.generator.container.JvmContainerGenerator import dev.icerock.gradle.generator.container.NOPContainerGenerator +import dev.icerock.gradle.generator.image.AndroidImageResourceGenerator +import dev.icerock.gradle.generator.image.AppleImageResourceGenerator +import dev.icerock.gradle.generator.image.ImageResourceGenerator +import dev.icerock.gradle.generator.image.JsImageResourceGenerator +import dev.icerock.gradle.generator.image.JvmImageResourceGenerator +import dev.icerock.gradle.generator.image.NOPImageResourceGenerator import dev.icerock.gradle.generator.plural.AndroidPluralResourceGenerator import dev.icerock.gradle.generator.plural.ApplePluralResourceGenerator import dev.icerock.gradle.generator.plural.JsPluralResourceGenerator @@ -29,9 +35,11 @@ import dev.icerock.gradle.generator.string.StringResourceGenerator import dev.icerock.gradle.metadata.container.ContainerMetadata import dev.icerock.gradle.metadata.container.ObjectMetadata import dev.icerock.gradle.metadata.container.ResourceType +import dev.icerock.gradle.metadata.resource.ImageMetadata import dev.icerock.gradle.metadata.resource.PluralMetadata import dev.icerock.gradle.metadata.resource.StringMetadata import dev.icerock.gradle.toModifier +import dev.icerock.gradle.utils.createByPlatform import dev.icerock.gradle.utils.flatName import dev.icerock.gradle.utils.getAndroidRClassPackage import dev.icerock.gradle.utils.isStrictLineBreaks @@ -128,6 +136,11 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { @TaskAction fun generate() { + // cleanup destinations + listOf(outputResourcesDir, outputSourcesDir, outputAssetsDir, outputMetadataFile).forEach { + it.get().asFile.deleteRecursively() + } + val json = Json { prettyPrint = true } @@ -168,7 +181,8 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { containerGenerator = createPlatformContainerGenerator(), typesGenerators = listOf( createStringGenerator(), - createPluralsGenerator() + createPluralsGenerator(), + createImagesGenerator() ), resourcesPackageName = resourcesPackageName.get(), resourcesClassName = resourcesClassName.get(), @@ -180,6 +194,8 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { private fun createPlatformContainerGenerator(): PlatformContainerGenerator { return createByPlatform( + kotlinPlatformType = kotlinPlatformType, + konanTarget = ::kotlinKonanTarget, createCommon = { NOPContainerGenerator() }, createAndroid = { NOPContainerGenerator() }, createJs = { NOPContainerGenerator() }, @@ -226,9 +242,60 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { ) } + private fun createImagesGenerator(): ResourceTypeGenerator { + return ResourceTypeGenerator( + generationPackage = resourcesPackageName.get(), + resourceClass = CodeConst.imageResourceName, + resourceType = ResourceType.IMAGES, + metadataClass = ImageMetadata::class, + visibilityModifier = resourcesVisibility.get().toModifier(), + generator = ImageResourceGenerator(), + platformResourceGenerator = createPlatformImageGenerator(), + filter = { + include("images/**/*.png", "images/**/*.jpg", "images/**/*.svg") + } + ) + } + + private fun createPlatformImageGenerator(): PlatformResourceGenerator { + val resourcesGenerationDir: File = outputResourcesDir.get().asFile + val assetsGenerationDir: File = outputAssetsDir.get().asFile + return createByPlatform( + kotlinPlatformType = kotlinPlatformType, + konanTarget = ::kotlinKonanTarget, + // TODO find way to remove this NOP + createCommon = { NOPImageResourceGenerator() }, + createAndroid = { + AndroidImageResourceGenerator( + androidRClassPackage = getAndroidR(), + resourcesGenerationDir = resourcesGenerationDir, + logger = this.logger + ) + }, + createApple = { + AppleImageResourceGenerator( + assetsGenerationDir = assetsGenerationDir + ) + }, + createJvm = { + JvmImageResourceGenerator( + className = resourcesClassName.get(), + resourcesGenerationDir = resourcesGenerationDir + ) + }, + createJs = { + JsImageResourceGenerator( + resourcesGenerationDir = resourcesGenerationDir + ) + } + ) + } + private fun createPlatformPluralGenerator(): PlatformResourceGenerator { val resourcesGenerationDir: File = outputResourcesDir.get().asFile return createByPlatform( + kotlinPlatformType = kotlinPlatformType, + konanTarget = ::kotlinKonanTarget, // TODO find way to remove this NOP createCommon = { NOPPluralResourceGenerator() }, createAndroid = { @@ -264,6 +331,8 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { private fun createPlatformStringGenerator(): PlatformResourceGenerator { val resourcesGenerationDir: File = outputResourcesDir.get().asFile return createByPlatform( + kotlinPlatformType = kotlinPlatformType, + konanTarget = ::kotlinKonanTarget, // TODO find way to remove this NOP createCommon = { NOPStringResourceGenerator() }, createAndroid = { @@ -293,59 +362,4 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { } ) } - - private fun createByPlatform( - createCommon: () -> T, - createAndroid: () -> T, - createApple: () -> T, - createJvm: () -> T, - createJs: () -> T, - ): T { - return when (kotlinPlatformType) { - KotlinPlatformType.common -> createCommon() - KotlinPlatformType.jvm -> createJvm() - KotlinPlatformType.androidJvm -> createAndroid() - KotlinPlatformType.js -> createJs() - KotlinPlatformType.native -> when (kotlinKonanTarget) { - KonanTarget.IOS_ARM32, - KonanTarget.IOS_ARM64, - KonanTarget.IOS_SIMULATOR_ARM64, - KonanTarget.IOS_X64, - - KonanTarget.MACOS_ARM64, - KonanTarget.MACOS_X64, - - KonanTarget.TVOS_ARM64, - KonanTarget.TVOS_SIMULATOR_ARM64, - KonanTarget.TVOS_X64, - - KonanTarget.WATCHOS_ARM32, - KonanTarget.WATCHOS_ARM64, - KonanTarget.WATCHOS_DEVICE_ARM64, - KonanTarget.WATCHOS_SIMULATOR_ARM64, - KonanTarget.WATCHOS_X64, - KonanTarget.WATCHOS_X86 -> createApple() - - KonanTarget.ANDROID_ARM32, - KonanTarget.ANDROID_ARM64, - KonanTarget.ANDROID_X64, - KonanTarget.ANDROID_X86, - - KonanTarget.LINUX_ARM32_HFP, - KonanTarget.LINUX_ARM64, - KonanTarget.LINUX_MIPS32, - KonanTarget.LINUX_MIPSEL32, - KonanTarget.LINUX_X64, - - KonanTarget.MINGW_X64, - KonanTarget.MINGW_X86, - - KonanTarget.WASM32, - - is KonanTarget.ZEPHYR -> error("$kotlinKonanTarget not supported by moko-resources now") - } - - KotlinPlatformType.wasm -> error("$kotlinPlatformType not supported by moko-resources now") - } - } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/FileExt.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/FileExt.kt index 0af32a742..6d263d9a6 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/FileExt.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/FileExt.kt @@ -5,15 +5,18 @@ package dev.icerock.gradle.utils import java.io.File +import org.jetbrains.kotlin.konan.file.File as KonanFile internal val File.svg: Boolean get() = extension.equals("svg", ignoreCase = true) internal val File.scale: String get() = - nameWithoutExtension.substringAfter("@") + nameWithoutExtension.substringAfter("@").substringBefore("x") internal val File.nameWithoutScale: String get() = nameWithoutExtension.withoutScale internal val File.targetName: String - get() = parentFile.parentFile.parentFile.name \ No newline at end of file + get() = parentFile.parentFile.parentFile.name + +internal fun File.toKonanFile(): KonanFile = KonanFile(this.path) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/createByPlatform.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/createByPlatform.kt new file mode 100644 index 000000000..cc85d0aa7 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/createByPlatform.kt @@ -0,0 +1,65 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.utils + +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType +import org.jetbrains.kotlin.konan.target.KonanTarget + +internal fun createByPlatform( + kotlinPlatformType: KotlinPlatformType, + konanTarget: () -> KonanTarget, + createCommon: () -> T, + createAndroid: () -> T, + createApple: () -> T, + createJvm: () -> T, + createJs: () -> T, +): T { + return when (kotlinPlatformType) { + KotlinPlatformType.common -> createCommon() + KotlinPlatformType.jvm -> createJvm() + KotlinPlatformType.androidJvm -> createAndroid() + KotlinPlatformType.js -> createJs() + KotlinPlatformType.native -> when (konanTarget()) { + KonanTarget.IOS_ARM32, + KonanTarget.IOS_ARM64, + KonanTarget.IOS_SIMULATOR_ARM64, + KonanTarget.IOS_X64, + + KonanTarget.MACOS_ARM64, + KonanTarget.MACOS_X64, + + KonanTarget.TVOS_ARM64, + KonanTarget.TVOS_SIMULATOR_ARM64, + KonanTarget.TVOS_X64, + + KonanTarget.WATCHOS_ARM32, + KonanTarget.WATCHOS_ARM64, + KonanTarget.WATCHOS_DEVICE_ARM64, + KonanTarget.WATCHOS_SIMULATOR_ARM64, + KonanTarget.WATCHOS_X64, + KonanTarget.WATCHOS_X86 -> createApple() + + KonanTarget.ANDROID_ARM32, + KonanTarget.ANDROID_ARM64, + KonanTarget.ANDROID_X64, + KonanTarget.ANDROID_X86, + + KonanTarget.LINUX_ARM32_HFP, + KonanTarget.LINUX_ARM64, + KonanTarget.LINUX_MIPS32, + KonanTarget.LINUX_MIPSEL32, + KonanTarget.LINUX_X64, + + KonanTarget.MINGW_X64, + KonanTarget.MINGW_X86, + + KonanTarget.WASM32, + + is KonanTarget.ZEPHYR -> error("$konanTarget not supported by moko-resources now") + } + + KotlinPlatformType.wasm -> error("$kotlinPlatformType not supported by moko-resources now") + } +} diff --git a/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt b/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt index 64d5a3d3c..e84369e69 100644 --- a/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt +++ b/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt @@ -40,17 +40,17 @@ internal fun App() { .padding(16.dp), horizontalAlignment = Alignment.CenterHorizontally ) { -// Image( -// painter = painterResource(MR.images.moko_logo), -// contentDescription = null -// ) -// -// Image( -// modifier = Modifier.size(30.dp).padding(top = 16.dp), -// painter = painterResource(MR.images.car_black), -// contentDescription = null, -// colorFilter = ColorFilter.tint(MaterialTheme.colors.onBackground) -// ) + Image( + painter = painterResource(MR.images.moko_logo), + contentDescription = null + ) + + Image( + modifier = Modifier.size(30.dp).padding(top = 16.dp), + painter = painterResource(MR.images.car_black), + contentDescription = null, + colorFilter = ColorFilter.tint(MaterialTheme.colors.onBackground) + ) var text: String by remember { mutableStateOf("") } From 4b6f1191df16588cc07f346dd0663694a197443e Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Tue, 9 Jan 2024 21:49:54 +0700 Subject: [PATCH 093/352] #535 colors resources migration --- .../dev/icerock/gradle/generator/CodeConst.kt | 3 + .../color/AndroidColorResourceGenerator.kt | 80 +++++ .../color/AppleColorResourceGenerator.kt | 133 ++++++++ .../generator/color/ColorResourceGenerator.kt | 133 ++++++++ .../color/JsColorResourceGenerator.kt | 43 +++ .../color/JvmColorResourceGenerator.kt | 42 +++ .../color/NOPColorResourceGenerator.kt | 24 ++ .../icerock/gradle/generator/color/Utils.kt | 24 ++ .../image/AppleImageResourceGenerator.kt | 1 + .../metadata/resource/ResourceMetadata.kt | 15 +- .../icerock/gradle/oldgen/ColorsGenerator.kt | 292 ------------------ .../dev/icerock/gradle/oldgen/MRGenerator.kt | 17 - .../oldgen/android/AndroidColorsGenerator.kt | 85 ----- .../oldgen/apple/AppleColorsGenerator.kt | 133 -------- .../gradle/oldgen/js/JsColorsGenerator.kt | 48 --- .../oldgen/jsJvmCommon/ColorResourceUtils.kt | 16 - .../gradle/oldgen/jvm/JvmColorsGenerator.kt | 31 -- .../GenerateMultiplatformResourcesTask.kt | 53 +++- .../shared/src/commonMain/kotlin/App.kt | 2 +- 19 files changed, 547 insertions(+), 628 deletions(-) create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/AndroidColorResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/AppleColorResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/ColorResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/JsColorResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/JvmColorResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/NOPColorResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/Utils.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/ColorsGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/MRGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidColorsGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleColorsGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsColorsGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jsJvmCommon/ColorResourceUtils.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmColorsGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt index a98fbe0c1..341973aca 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt @@ -11,6 +11,9 @@ internal object CodeConst { val stringResourceName = ClassName("dev.icerock.moko.resources", "StringResource") val pluralsResourceName = ClassName("dev.icerock.moko.resources", "PluralsResource") val imageResourceName = ClassName("dev.icerock.moko.resources", "ImageResource") + val colorResourceName = ClassName("dev.icerock.moko.resources", "ColorResource") + + val graphicsColorName = ClassName("dev.icerock.moko.graphics", "Color") object Apple { val nsBundleName = ClassName("platform.Foundation", "NSBundle") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/AndroidColorResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/AndroidColorResourceGenerator.kt new file mode 100644 index 000000000..ad5d12b5c --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/AndroidColorResourceGenerator.kt @@ -0,0 +1,80 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.color + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.metadata.resource.ColorMetadata +import java.io.File + +internal class AndroidColorResourceGenerator( + private val androidRClassPackage: String, + private val resourcesGenerationDir: File +) : PlatformResourceGenerator { + override fun imports(): List = listOf( + ClassName(androidRClassPackage, "R") + ) + + override fun generateInitializer(metadata: ColorMetadata): CodeBlock { + return CodeBlock.of("ColorResource(R.color.%L)", metadata.key) + } + + override fun generateResourceFiles(data: List) { + val valuesDir = File(resourcesGenerationDir, "values") + val defaultStringsFile = File(valuesDir, COLORS_XML_FILE_NAME) + valuesDir.mkdirs() + + val valuesNightDir = File(resourcesGenerationDir, "values-night") + val darkStringsFile = File(valuesNightDir, COLORS_XML_FILE_NAME) + valuesNightDir.mkdirs() + + val header = + """ + + + """.trimIndent() + + val footer = + """ + + """.trimIndent() + + val defaultContent: String = data.joinToString("\n") { metadata -> + when (metadata.value) { + is ColorMetadata.ColorItem.Single -> + buildColorString(metadata.key, metadata.value.color) + + is ColorMetadata.ColorItem.Themed -> + buildColorString(metadata.key, metadata.value.light) + } + } + + val darkContent: String = data + .filter { it.value is ColorMetadata.ColorItem.Themed } + .joinToString("\n") { metadata -> + val value: ColorMetadata.ColorItem.Themed = + (metadata.value as ColorMetadata.ColorItem.Themed) + buildColorString(metadata.key, value.dark) + } + + defaultStringsFile.writeText(header + "\n") + defaultStringsFile.appendText(defaultContent) + defaultStringsFile.appendText("\n" + footer) + + darkStringsFile.writeText(header + "\n") + darkStringsFile.appendText(darkContent) + darkStringsFile.appendText("\n" + footer) + } + + private fun buildColorString(name: String, color: ColorMetadata.Color): String { + val argbString: String = color.toArgbHex() + return "\t#$argbString" + } + + private companion object { + const val COLORS_XML_FILE_NAME = "colors.xml" + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/AppleColorResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/AppleColorResourceGenerator.kt new file mode 100644 index 000000000..8eef9a13a --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/AppleColorResourceGenerator.kt @@ -0,0 +1,133 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.color + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.generator.addAppleContainerBundleProperty +import dev.icerock.gradle.metadata.resource.ColorMetadata +import kotlinx.serialization.json.JsonArray +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.buildJsonArray +import kotlinx.serialization.json.buildJsonObject +import kotlinx.serialization.json.put +import java.io.File + +internal class AppleColorResourceGenerator( + private val assetsGenerationDir: File +) : PlatformResourceGenerator { + override fun imports(): List = emptyList() + + override fun generateInitializer(metadata: ColorMetadata): CodeBlock { + return CodeBlock.of( + "ColorResource(name = %S, bundle = %L)", + metadata.key, + CodeConst.Apple.containerBundlePropertyName + ) + } + + override fun generateResourceFiles(data: List) { + val assetsDirectory = File(assetsGenerationDir, CodeConst.Apple.assetsDirectoryName) + + data.forEach { imageMetadata -> + val assetDir = File(assetsDirectory, "${imageMetadata.key}.colorset") + assetDir.mkdirs() + + val contentsFile = File(assetDir, "Contents.json") + contentsFile.createNewFile() + + val colorContentObj: JsonArray = when (imageMetadata.value) { + is ColorMetadata.ColorItem.Single -> { + buildJsonArray { + add(buildColorIdiomJson(imageMetadata.value.color)) + } + } + + is ColorMetadata.ColorItem.Themed -> { + /* + Sets any color as light. Check about colors in the docs: + https://developer.apple.com/documentation/xcode/supporting_dark_mode_in_your_interface + */ + val anyColor = buildColorIdiomJson(imageMetadata.value.light) + val lightColorObj = buildAppearancesIdiomJson( + valueTag = "light", + color = imageMetadata.value.light + ) + val darkColorObj = buildAppearancesIdiomJson( + valueTag = "dark", + color = imageMetadata.value.dark + ) + + buildJsonArray { + add(anyColor) + add(lightColorObj) + add(darkColorObj) + } + } + } + + val resultObj: JsonObject = buildJsonObject { + put("colors", colorContentObj) + put( + "info", + buildJsonObject { + put("author", "xcode") + put("version", 1) + } + ) + } + contentsFile.writeText(resultObj.toString()) + } + } + + override fun generateBeforeProperties( + builder: TypeSpec.Builder, + metadata: List + ) { + builder.addAppleContainerBundleProperty() + } + + private fun buildAppearancesIdiomJson( + valueTag: String, + color: ColorMetadata.Color + ): JsonObject { + return buildJsonObject { + put( + "appearances", + buildJsonArray { + add( + buildJsonObject { + put("appearance", "luminosity") + put("value", valueTag) + } + ) + } + ) + put("color", buildColorJson(color)) + put("idiom", "universal") + } + } + + private fun buildColorIdiomJson(color: ColorMetadata.Color): JsonObject = buildJsonObject { + put("color", buildColorJson(color)) + put("idiom", "universal") + } + + private fun buildColorJson(color: ColorMetadata.Color): JsonObject = buildJsonObject { + put("color-space", "srgb") + put( + "components", + buildJsonObject { + put("alpha", color.alpha / 255.0f) + put("red", color.red / 255.0f) + put("green", color.green / 255.0f) + put("blue", color.blue / 255.0f) + } + ) + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/ColorResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/ColorResourceGenerator.kt new file mode 100644 index 000000000..6ed2176f5 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/ColorResourceGenerator.kt @@ -0,0 +1,133 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.color + +import com.squareup.kotlinpoet.PropertySpec +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.ResourceGenerator +import dev.icerock.gradle.metadata.resource.ColorMetadata +import org.gradle.api.GradleException +import org.w3c.dom.Document +import org.w3c.dom.Node +import org.w3c.dom.NodeList +import java.io.File +import javax.xml.parsers.DocumentBuilder +import javax.xml.parsers.DocumentBuilderFactory + +internal class ColorResourceGenerator : ResourceGenerator { + + override fun generateMetadata(files: Set): List { + val result: MutableList = mutableListOf() + val colorValues: MutableMap = mutableMapOf() + + files.forEach { file -> + val dbFactory: DocumentBuilderFactory = DocumentBuilderFactory.newInstance() + val dBuilder: DocumentBuilder = dbFactory.newDocumentBuilder() + val doc: Document = dBuilder.parse(file) + + val stringNodes: NodeList = doc.getElementsByTagName(XmlColorTag) + + for (i: Int in 0 until stringNodes.length) { + val stringNode: Node = stringNodes.item(i) + + val metadata: ColorMetadata = readColorValue( + stringNode = stringNode, + colorValues = colorValues + ) + result.add(metadata) + } + } + + return result + } + + private fun readColorValue( + stringNode: Node, + colorValues: MutableMap + ): ColorMetadata { + val colorName: String = stringNode.attributes.getNamedItem(XmlNodeAttrColorName).textContent + + var lightColor: String? = null + var darkColor: String? = null + var singleColor: String? = null + val nodeList: NodeList = stringNode.childNodes + for (nodeIdx: Int in 0 until nodeList.length) { + val xmlNode: Node = nodeList.item(nodeIdx) + when (xmlNode.nodeName) { + "light" -> { + lightColor = colorValues.parseColor(xmlNode.textContent) + } + + "dark" -> { + darkColor = colorValues.parseColor(xmlNode.textContent) + } + + else -> { + if (xmlNode.textContent.isBlank()) continue + + singleColor = colorValues.parseColor(xmlNode.textContent) + .also { colorValues[colorName] = it } + } + } + } + + val item: ColorMetadata.ColorItem = if (singleColor != null) { + ColorMetadata.ColorItem.Single( + color = singleColor.toColor() + ) + } else { + ColorMetadata.ColorItem.Themed( + light = requireNotNull(lightColor) { "light color should be set for themed color" } + .toColor(), + dark = requireNotNull(darkColor) { "dark color should be set for themed color" } + .toColor() + ) + } + + return ColorMetadata( + key = colorName, + value = item + ) + } + + override fun generateProperty(metadata: ColorMetadata): PropertySpec.Builder { + return PropertySpec.builder(metadata.key, CodeConst.colorResourceName) + } + + private fun Map.parseColor(color: String): String { + return if (color.startsWith(XmlColorReferencePrefix)) { + val colorName: String = color.replace(XmlColorReferencePrefix, "") + val colorValue: String = this[colorName] + ?: error("color reference $colorName not found") + parseColor(colorValue) + } else { + val rawColor: String = color.removePrefix("#").removePrefix("0x") + return if (rawColor.length == RgbFormatLength) "${rawColor}${DefaultAlpha}" + else rawColor + } + } + + private fun String.toColor(): ColorMetadata.Color { + val rgbaColor: Long = try { + this.toLong(16) + } catch (exc: Exception) { + throw GradleException("can't parse $this to ColorMetadata.Color", exc) + } + return ColorMetadata.Color( + red = (rgbaColor shr 24 and 0xff).toInt(), + green = (rgbaColor shr 16 and 0xff).toInt(), + blue = (rgbaColor shr 8 and 0xff).toInt(), + alpha = (rgbaColor and 0xff).toInt() + ) + } + + private companion object { + const val XmlColorTag = "color" + const val XmlNodeAttrColorName = "name" + const val XmlColorReferencePrefix = "@color/" + const val RgbFormatLength = 6 + const val DefaultAlpha = "FF" + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/JsColorResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/JsColorResourceGenerator.kt new file mode 100644 index 000000000..d216fd454 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/JsColorResourceGenerator.kt @@ -0,0 +1,43 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.color + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.FunSpec +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.metadata.resource.ColorMetadata + +internal class JsColorResourceGenerator : PlatformResourceGenerator { + override fun imports(): List = listOf(CodeConst.graphicsColorName) + + override fun generateInitializer(metadata: ColorMetadata): CodeBlock { + return createColorResourceCodeInitializer(metadata) + } + + override fun generateResourceFiles(data: List) = Unit + + override fun generateAfterProperties( + builder: TypeSpec.Builder, + metadata: List + ) { + val languageKeysList: String = metadata.joinToString { it.key } + + val valuesFun: FunSpec = FunSpec.builder("values") + .addModifiers(KModifier.OVERRIDE) + .addStatement("return listOf($languageKeysList)") + .returns( + ClassName("kotlin.collections", "List") + .parameterizedBy(CodeConst.colorResourceName) + ) + .build() + + builder.addFunction(valuesFun) + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/JvmColorResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/JvmColorResourceGenerator.kt new file mode 100644 index 000000000..d60b493f6 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/JvmColorResourceGenerator.kt @@ -0,0 +1,42 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.color + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.PropertySpec +import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.metadata.resource.ColorMetadata + +internal class JvmColorResourceGenerator( + private val className: String +) : PlatformResourceGenerator { + override fun imports(): List = listOf(CodeConst.graphicsColorName) + + override fun generateInitializer(metadata: ColorMetadata): CodeBlock { + return createColorResourceCodeInitializer(metadata) + } + + override fun generateResourceFiles(data: List) = Unit + + override fun generateBeforeProperties( + builder: TypeSpec.Builder, + metadata: List + ) { + // FIXME duplication + val classLoaderProperty: PropertySpec = PropertySpec.builder( + CodeConst.Jvm.resourcesClassLoaderPropertyName, + CodeConst.Jvm.classLoaderName, + KModifier.OVERRIDE + ) + .initializer(CodeBlock.of(className + "." + CodeConst.Jvm.resourcesClassLoaderPropertyName)) + .build() + + builder.addProperty(classLoaderProperty) + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/NOPColorResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/NOPColorResourceGenerator.kt new file mode 100644 index 000000000..e0bf2e0b4 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/NOPColorResourceGenerator.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.color + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.metadata.resource.ColorMetadata + +internal class NOPColorResourceGenerator : PlatformResourceGenerator { + override fun imports(): List { + TODO("Not yet implemented") + } + + override fun generateResourceFiles(data: List) { + TODO("Not yet implemented") + } + + override fun generateInitializer(metadata: ColorMetadata): CodeBlock { + TODO("Not yet implemented") + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/Utils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/Utils.kt new file mode 100644 index 000000000..d4f6379ee --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/Utils.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.color + +import com.squareup.kotlinpoet.CodeBlock +import dev.icerock.gradle.metadata.resource.ColorMetadata + + +internal fun createColorResourceCodeInitializer(color: ColorMetadata): CodeBlock { + return when (color.value) { + is ColorMetadata.ColorItem.Single -> { + val colorHex: String = color.value.color.toRgbaHex() + "ColorResource(lightColor = Color(0x$colorHex), darkColor = Color(0x$colorHex))" + } + + is ColorMetadata.ColorItem.Themed -> { + val lightHex: String = color.value.light.toRgbaHex() + val darkHex: String = color.value.dark.toRgbaHex() + "ColorResource(lightColor = Color(0x$lightHex), darkColor = Color(0x$darkHex))" + } + }.let { CodeBlock.of(it) } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/AppleImageResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/AppleImageResourceGenerator.kt index 774066746..593d7ee3f 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/AppleImageResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/AppleImageResourceGenerator.kt @@ -36,6 +36,7 @@ internal class AppleImageResourceGenerator( data.forEach { imageMetadata -> val assetDir = File(assetsDirectory, "${imageMetadata.key}.imageset") + assetDir.mkdirs() val contentsFile = File(assetDir, "Contents.json") val validItems: List = diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt index 73bf2339b..28332992e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt @@ -111,9 +111,6 @@ internal data class ColorMetadata( @Serializable data class Themed(val light: Color, val dark: Color) : ColorItem - - @Serializable - data class Reference(val key: String) : ColorItem } @Serializable @@ -122,7 +119,17 @@ internal data class ColorMetadata( val green: Int, val blue: Int, val alpha: Int - ) + ) { + fun toArgbHex(): String { + return listOf(alpha, red, green, blue) + .joinToString(separator = "") { it.toString(16).padStart(2, '0') } + } + + fun toRgbaHex(): String { + return listOf(red, green, blue, alpha) + .joinToString(separator = "") { it.toString(16).padStart(2, '0') } + } + } override fun contentHash(): String = value.hashCode().toString(16) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/ColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/ColorsGenerator.kt deleted file mode 100644 index 61545b94b..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/ColorsGenerator.kt +++ /dev/null @@ -1,292 +0,0 @@ -///* -// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator -// -//import com.squareup.kotlinpoet.ClassName -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import com.squareup.kotlinpoet.PropertySpec -//import com.squareup.kotlinpoet.TypeSpec -//import dev.icerock.gradle.generator.android.AndroidColorsGenerator -//import dev.icerock.gradle.generator.apple.AppleColorsGenerator -//import dev.icerock.gradle.generator.common.CommonColorsGenerator -//import dev.icerock.gradle.generator.js.JsColorsGenerator -//import dev.icerock.gradle.generator.jvm.JvmColorsGenerator -//import dev.icerock.gradle.metadata.model.GeneratedObject -//import dev.icerock.gradle.metadata.model.GeneratedObjectModifier -//import dev.icerock.gradle.metadata.model.GeneratedProperty -//import dev.icerock.gradle.metadata.model.GeneratorType -//import dev.icerock.gradle.metadata.objectsWithProperties -//import kotlinx.serialization.SerialName -//import kotlinx.serialization.Serializable -//import kotlinx.serialization.json.Json -//import kotlinx.serialization.json.decodeFromJsonElement -//import kotlinx.serialization.json.encodeToJsonElement -//import org.gradle.api.Project -//import org.gradle.api.file.FileTree -//import org.w3c.dom.Node -//import org.w3c.dom.NodeList -//import java.io.File -//import javax.xml.parsers.DocumentBuilderFactory -// -//abstract class ColorsGenerator( -// private val resourcesFileTree: FileTree, -//) : MRGenerator.Generator { -// -// override val inputFiles: Iterable -// get() = resourcesFileTree.matching { it.include("**/colors*.xml") } -// override val resourceClassName: ClassName = -// ClassName("dev.icerock.moko.resources", "ColorResource") -// override val mrObjectName: String = "colors" -// -// override val type: GeneratorType = GeneratorType.Colors -// -// open fun beforeGenerate(objectBuilder: TypeSpec.Builder, keys: List) = Unit -// -// @Suppress("SpreadOperator") -// override fun generateObject( -// project: Project, -// inputMetadata: List, -// outputMetadata: GeneratedObject, -// assetsGenerationDir: File, -// resourcesGenerationDir: File, -// objectBuilder: TypeSpec.Builder, -// ): MRGenerator.GenerationResult? { -// if (outputMetadata.isActual) { -// objectBuilder.addModifiers(KModifier.ACTUAL) -// } -// -// if (outputMetadata.isActualObject || outputMetadata.isTargetObject) { -// extendObjectBodyAtStart(objectBuilder) -// } -// -// // Read colors from previous levels, if target interface or expect -// // return emptyList() -// val previousColors: List = getPreviousColors( -// inputMetadata = inputMetadata, -// targetObject = outputMetadata -// ) -// -// // Read target colors -// val targetColors: List = parseColors() -// val allColors: List = (previousColors + targetColors).distinct() -// val generatedProperties: MutableList = mutableListOf() -// -// beforeGenerate(objectBuilder, allColors.map { it.name }) -// -// val json = Json -// -// allColors.forEach { colorNode -> -// val property = PropertySpec.builder(colorNode.name, resourceClassName) -// -// // Create metadata property -// var generatedProperty = GeneratedProperty( -// modifier = GeneratedObjectModifier.None, -// name = colorNode.name, -// data = json.encodeToJsonElement(colorNode) -// ) -// -// if (outputMetadata.isActualObject || outputMetadata.isTargetObject) { -// // Setup property modifier and correction metadata info -// generatedProperty = generatedProperty.copy( -// modifier = addActualOverrideModifier( -// propertyName = colorNode.name, -// property = property, -// inputMetadata = inputMetadata, -// targetObject = outputMetadata -// ) -// ) -// -// getPropertyInitializer(colorNode)?.let { -// property.initializer(it) -// } -// } -// -// objectBuilder.addProperty(property.build()) -// generatedProperties.add(generatedProperty) -// } -// -// generateResources( -// project = project, -// assetsGenerationDir = assetsGenerationDir, -// resourcesGenerationDir = resourcesGenerationDir, -// colors = allColors -// ) -// -// extendObjectBodyAtEnd(objectBuilder) -// -// if (generatedProperties.isEmpty()) return null -// -// return MRGenerator.GenerationResult( -// typeSpec = objectBuilder.build(), -// metadata = outputMetadata.copy(properties = generatedProperties) -// ) -// } -// -// private fun getPreviousColors( -// inputMetadata: List, -// targetObject: GeneratedObject, -// ): List { -// if (!targetObject.isObject || !targetObject.isActual) return emptyList() -// -// val json = Json -// val objectsWithProperties: List = inputMetadata.objectsWithProperties( -// targetObject = targetObject -// ) -// -// val colors = mutableListOf() -// -// objectsWithProperties.forEach { generatedObject -> -// generatedObject.properties.forEach { property -> -// val colorNode = json.decodeFromJsonElement(property.data) -// -// colors.add(colorNode) -// } -// } -// -// return colors -// } -// -// protected open fun getClassModifiers(): Array = emptyArray() -// -// abstract fun getPropertyInitializer(color: ColorNode): CodeBlock? -// -// protected open fun generateResources( -// project: Project, -// assetsGenerationDir: File, -// resourcesGenerationDir: File, -// colors: List, -// ) = Unit -// -// private fun parseColors(): List { -// val colorNodes = mutableListOf() -// val colorValues = mutableMapOf() -// -// fun getColor(color: String?): String? { -// return if (color?.startsWith(XmlColorReferencePrefix) == true) { -// val colorName = color.replace(XmlColorReferencePrefix, "") -// val colorValue = colorValues[colorName] -// getColor(colorValue) -// } else { -// val rawColor = color?.removePrefix("#")?.removePrefix("0x") -// if (rawColor?.length == RgbFormatLength) "${rawColor}FF" else rawColor -// } -// } -// -// inputFiles.map { file -> -// val dbFactory = DocumentBuilderFactory.newInstance() -// val dBuilder = dbFactory.newDocumentBuilder() -// val doc = dBuilder.parse(file) -// -// val stringNodes = doc.getElementsByTagName(XmlColorTag) -// -// for (i in 0 until stringNodes.length) { -// val stringNode = stringNodes.item(i) -// -// val colorName = stringNode.attributes.getNamedItem(XmlNodeAttrColorName).textContent -// var lightColor: String? = null -// var darkColor: String? = null -// var singleColor: String? = null -// val nodeList: NodeList = stringNode.childNodes -// for (nodeIdx in 0 until nodeList.length) { -// val xmlNode: Node = nodeList.item(nodeIdx) -// when (xmlNode.nodeName) { -// "light" -> { -// lightColor = xmlNode.textContent -// } -// -// "dark" -> { -// darkColor = xmlNode.textContent -// } -// -// else -> { -// singleColor = xmlNode.textContent -// singleColor?.let { -// colorValues[colorName] = it -// } -// } -// } -// } -// colorNodes.add( -// ColorNode( -// colorName, -// getColor(lightColor), -// getColor(darkColor), -// getColor(singleColor) -// ) -// ) -// } -// } -// -// return colorNodes -// } -// -// class Feature( -// private val settings: MRGenerator.Settings, -// ) : ResourceGeneratorFeature { -// override fun createCommonGenerator() = CommonColorsGenerator( -// resourcesFileTree = settings.ownResourcesFileTree, -// ) -// -// override fun createAppleGenerator() = AppleColorsGenerator( -// resourcesFileTree = settings.ownResourcesFileTree, -// ) -// -// override fun createAndroidGenerator() = AndroidColorsGenerator( -// resourcesFileTree = settings.ownResourcesFileTree, -// ) -// -// override fun createJsGenerator(): ColorsGenerator = JsColorsGenerator( -// resourcesFileTree = settings.ownResourcesFileTree, -// ) -// -// override fun createJvmGenerator() = JvmColorsGenerator( -// resourcesFileTree = settings.ownResourcesFileTree, -// mrClassName = settings.className -// ) -// } -// -// protected fun replaceColorAlpha(color: String?): String? { -// if (color == null) return null -// -// val alpha: String = if (isRgbFormat(color)) { -// DefaultAlpha -// } else { -// color.substring(color.length - 2, color.length) -// } -// -// return if (isRgbFormat(color)) { -// "$alpha$color" -// } else { -// "$alpha${color.removeRange(color.length - 2, color.length)}" -// } -// } -// -// private fun isRgbFormat(color: String): Boolean = color.length == RgbFormatLength -// -// companion object { -// internal const val XmlColorTag = "color" -// internal const val XmlNodeAttrColorName = "name" -// internal const val XmlColorReferencePrefix = "@color/" -// internal const val RgbFormatLength = 6 -// internal const val DefaultAlpha = "FF" -// -// val COLORS_REGEX: Regex = "^.*/colors.*.xml".toRegex() -// } -//} -// -//@Serializable -//data class ColorNode( -// @SerialName("name") -// val name: String, -// @SerialName("lightColor") -// val lightColor: String?, // as rgba -// @SerialName("darkColor") -// val darkColor: String?, // as rgba -// @SerialName("singleColor") -// val singleColor: String?, // as rgba -//) { -// fun isThemed(): Boolean = lightColor != null && darkColor != null -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/MRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/MRGenerator.kt deleted file mode 100644 index a5b32193d..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/MRGenerator.kt +++ /dev/null @@ -1,17 +0,0 @@ - -// protected open val sourcesGenerationDir: File = settings.sourceSetDir.asFile -// protected open val resourcesGenerationDir: File = settings.resourcesDir.asFile -// protected open val assetsGenerationDir: File = settings.assetsDir.asFile -// -// internal fun generate() { -// sourcesGenerationDir.deleteRecursively() -// resourcesGenerationDir.deleteRecursively() -// assetsGenerationDir.deleteRecursively() -// -// beforeMRGeneration() -// -// val file = generateFileSpec() -// file?.writeTo(sourcesGenerationDir) -// -// afterMRGeneration() -// } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidColorsGenerator.kt deleted file mode 100644 index b69a5d46c..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidColorsGenerator.kt +++ /dev/null @@ -1,85 +0,0 @@ -///* -// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.android -// -//import com.squareup.kotlinpoet.ClassName -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import dev.icerock.gradle.generator.ColorNode -//import dev.icerock.gradle.generator.ColorsGenerator -//import dev.icerock.gradle.generator.NOPObjectBodyExtendable -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import org.gradle.api.Project -//import org.gradle.api.file.FileTree -//import java.io.File -// -//class AndroidColorsGenerator( -// resourcesFileTree: FileTree, -//) : ColorsGenerator(resourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { -// -// override fun getImports() = listOf( -// ClassName("dev.icerock.moko.graphics", "Color") -// ) -// -// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun generateResources( -// project: Project, -// assetsGenerationDir: File, -// resourcesGenerationDir: File, -// colors: List -// ) { -// val valuesDir = File(resourcesGenerationDir, "values") -// val defaultStringsFile = File(valuesDir, COLORS_XML_FILE_NAME) -// valuesDir.mkdirs() -// -// val valuesNightDir = File(resourcesGenerationDir, "values-night") -// val darkStringsFile = File(valuesNightDir, COLORS_XML_FILE_NAME) -// valuesNightDir.mkdirs() -// -// val header = -// """ -// -// -// """.trimIndent() -// -// val footer = -// """ -// -// """.trimIndent() -// -// val defaultContent = colors.joinToString("\n") { colorNode -> -// if (colorNode.isThemed()) { -// buildColorString(colorNode.name, replaceColorAlpha(colorNode.lightColor)) -// } else { -// buildColorString(colorNode.name, replaceColorAlpha(colorNode.singleColor)) -// } -// } -// -// val darkContent = colors.filter { it.isThemed() }.joinToString("\n") { colorNode -> -// buildColorString(colorNode.name, replaceColorAlpha(colorNode.darkColor)) -// } -// -// defaultStringsFile.writeText(header + "\n") -// defaultStringsFile.appendText(defaultContent) -// defaultStringsFile.appendText("\n" + footer) -// -// darkStringsFile.writeText(header + "\n") -// darkStringsFile.appendText(darkContent) -// darkStringsFile.appendText("\n" + footer) -// } -// -// private fun buildColorString(name: String, colorCode: String?): String { -// return "\t#$colorCode" -// } -// -// override fun getPropertyInitializer(color: ColorNode): CodeBlock { -// return CodeBlock.of("ColorResource(resourceId = R.color.${color.name})") -// } -// -// companion object { -// private const val COLORS_XML_FILE_NAME = "colors.xml" -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleColorsGenerator.kt deleted file mode 100644 index 1341f4619..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleColorsGenerator.kt +++ /dev/null @@ -1,133 +0,0 @@ -///* -// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.apple -// -//import com.squareup.kotlinpoet.ClassName -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import dev.icerock.gradle.generator.ColorNode -//import dev.icerock.gradle.generator.ColorsGenerator -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import dev.icerock.gradle.generator.apple.AppleMRGenerator.Companion.ASSETS_DIR_NAME -//import dev.icerock.gradle.utils.ArgbColor -//import dev.icerock.gradle.utils.parseRgbaColor -//import kotlinx.serialization.json.JsonObject -//import kotlinx.serialization.json.buildJsonArray -//import kotlinx.serialization.json.buildJsonObject -//import kotlinx.serialization.json.put -//import org.gradle.api.Project -//import org.gradle.api.file.FileTree -//import java.io.File -// -//class AppleColorsGenerator( -// resourcesFileTree: FileTree, -//) : ColorsGenerator(resourcesFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { -// override fun getImports(): List { -// return listOf( -// ClassName("dev.icerock.moko.graphics", "Color") -// ) -// } -// -// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun generateResources( -// project: Project, -// assetsGenerationDir: File, -// resourcesGenerationDir: File, -// colors: List -// ) { -// val assetsDirectory = File(assetsGenerationDir, ASSETS_DIR_NAME) -// -// colors.forEach { colorNode -> -// val assetDir = File(assetsDirectory, "${colorNode.name}.colorset") -// assetDir.mkdirs() -// val contentsFile = File(assetDir, "Contents.json") -// contentsFile.createNewFile() -// -// val colorContentObj = if (colorNode.isThemed()) { -// @Suppress("MagicNumber") -// val lightColor = parseRgbaColor(colorNode.lightColor!!.toLong(16)) -// -// @Suppress("MagicNumber") -// val darkColor = parseRgbaColor(colorNode.darkColor!!.toLong(16)) -// -// /* -// Sets any color as light. Check about colors in the docs: -// https://developer.apple.com/documentation/xcode/supporting_dark_mode_in_your_interface -// */ -// val anyColor = buildColorIdiomJsonObj(lightColor) -// val lightColorObj = buildAppearancesIdiomJsonBlock("light", lightColor) -// val darkColorObj = buildAppearancesIdiomJsonBlock("dark", darkColor) -// -// buildJsonArray { -// add(anyColor) -// add(lightColorObj) -// add(darkColorObj) -// } -// } else { -// @Suppress("MagicNumber") -// val singleColor = parseRgbaColor(colorNode.singleColor!!.toLong(16)) -// buildJsonArray { -// add(buildColorIdiomJsonObj(singleColor)) -// } -// } -// -// val resultObj = buildJsonObject { -// put("colors", colorContentObj) -// put( -// "info", -// buildJsonObject { -// put("author", "xcode") -// put("version", 1) -// } -// ) -// } -// contentsFile.writeText(resultObj.toString()) -// } -// } -// -// private fun buildColorJsonObj(argbColor: ArgbColor): JsonObject = buildJsonObject { -// put("color-space", "srgb") -// put( -// "components", -// buildJsonObject { -// put("alpha", argbColor.a) -// put("red", argbColor.r) -// put("green", argbColor.g) -// put("blue", argbColor.b) -// } -// ) -// } -// -// private fun buildColorIdiomJsonObj(argbColor: ArgbColor): JsonObject = buildJsonObject { -// put("color", buildColorJsonObj(argbColor)) -// put("idiom", "universal") -// } -// -// private fun buildAppearancesIdiomJsonBlock(valueTag: String, argbColor: ArgbColor): JsonObject { -// return buildJsonObject { -// put( -// "appearances", -// buildJsonArray { -// add( -// buildJsonObject { -// put("appearance", "luminosity") -// put("value", valueTag) -// } -// ) -// } -// ) -// put("color", buildColorJsonObj(argbColor)) -// put("idiom", "universal") -// } -// } -// -// override fun getPropertyInitializer(color: ColorNode): CodeBlock { -// return CodeBlock.of( -// "ColorResource(name = %S, bundle = ${AppleMRGenerator.BUNDLE_PROPERTY_NAME})", -// color.name -// ) -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsColorsGenerator.kt deleted file mode 100644 index cdae70428..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsColorsGenerator.kt +++ /dev/null @@ -1,48 +0,0 @@ -///* -// * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.js -// -//import com.squareup.kotlinpoet.ClassName -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.FunSpec -//import com.squareup.kotlinpoet.KModifier -//import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -//import com.squareup.kotlinpoet.TypeSpec -//import dev.icerock.gradle.generator.ColorNode -//import dev.icerock.gradle.generator.ColorsGenerator -//import dev.icerock.gradle.generator.NOPObjectBodyExtendable -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import dev.icerock.gradle.generator.jsJvmCommon.createColorResourceInitializer -//import org.gradle.api.file.FileTree -// -//class JsColorsGenerator( -// resourcesFileTree: FileTree, -//) : ColorsGenerator(resourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { -// -// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getImports() = listOf( -// ClassName("dev.icerock.moko.graphics", "Color") -// ) -// -// override fun beforeGenerate(objectBuilder: TypeSpec.Builder, keys: List) { -// val languageKeysList = keys.joinToString() -// -// objectBuilder.addFunction( -// FunSpec.builder("values") -// .addModifiers(KModifier.OVERRIDE) -// .addStatement("return listOf($languageKeysList)") -// .returns( -// ClassName("kotlin.collections", "List") -// .parameterizedBy(resourceClassName) -// ) -// .build() -// ) -// } -// -// override fun getPropertyInitializer(color: ColorNode): CodeBlock { -// return createColorResourceInitializer(color) -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jsJvmCommon/ColorResourceUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jsJvmCommon/ColorResourceUtils.kt deleted file mode 100644 index 7b55ccf6f..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jsJvmCommon/ColorResourceUtils.kt +++ /dev/null @@ -1,16 +0,0 @@ -///* -// * Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.jsJvmCommon -// -//import com.squareup.kotlinpoet.CodeBlock -//import dev.icerock.gradle.generator.ColorNode -// -//fun createColorResourceInitializer(color: ColorNode): CodeBlock { -// return if (color.isThemed()) { -// "ColorResource(lightColor = Color(0x${color.lightColor}), darkColor = Color(0x${color.darkColor}))" -// } else { -// "ColorResource(lightColor = Color(0x${color.singleColor}), darkColor = Color(0x${color.singleColor}))" -// }.let { CodeBlock.of(it) } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmColorsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmColorsGenerator.kt deleted file mode 100644 index 52c823d48..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmColorsGenerator.kt +++ /dev/null @@ -1,31 +0,0 @@ -///* -// * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.jvm -// -//import com.squareup.kotlinpoet.ClassName -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import dev.icerock.gradle.generator.ColorNode -//import dev.icerock.gradle.generator.ColorsGenerator -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import dev.icerock.gradle.generator.jsJvmCommon.createColorResourceInitializer -//import org.gradle.api.file.FileTree -// -//class JvmColorsGenerator( -// resourcesFileTree: FileTree, -// mrClassName: String, -//) : ColorsGenerator(resourcesFileTree), -// ObjectBodyExtendable by ClassLoaderExtender(mrClassName) { -// -// override fun getImports() = listOf( -// ClassName("dev.icerock.moko.graphics", "Color") -// ) -// -// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyInitializer(color: ColorNode): CodeBlock { -// return createColorResourceInitializer(color) -// } -//} 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 d2e286f78..ad9b06074 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 @@ -11,6 +11,12 @@ import dev.icerock.gradle.generator.PlatformResourceGenerator import dev.icerock.gradle.generator.ResourceTypeGenerator import dev.icerock.gradle.generator.ResourcesFiles import dev.icerock.gradle.generator.ResourcesGenerator +import dev.icerock.gradle.generator.color.AndroidColorResourceGenerator +import dev.icerock.gradle.generator.color.AppleColorResourceGenerator +import dev.icerock.gradle.generator.color.ColorResourceGenerator +import dev.icerock.gradle.generator.color.JsColorResourceGenerator +import dev.icerock.gradle.generator.color.JvmColorResourceGenerator +import dev.icerock.gradle.generator.color.NOPColorResourceGenerator import dev.icerock.gradle.generator.container.AppleContainerGenerator import dev.icerock.gradle.generator.container.JvmContainerGenerator import dev.icerock.gradle.generator.container.NOPContainerGenerator @@ -35,6 +41,7 @@ import dev.icerock.gradle.generator.string.StringResourceGenerator import dev.icerock.gradle.metadata.container.ContainerMetadata import dev.icerock.gradle.metadata.container.ObjectMetadata import dev.icerock.gradle.metadata.container.ResourceType +import dev.icerock.gradle.metadata.resource.ColorMetadata import dev.icerock.gradle.metadata.resource.ImageMetadata import dev.icerock.gradle.metadata.resource.PluralMetadata import dev.icerock.gradle.metadata.resource.StringMetadata @@ -182,7 +189,8 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { typesGenerators = listOf( createStringGenerator(), createPluralsGenerator(), - createImagesGenerator() + createImagesGenerator(), + createColorsGenerator() ), resourcesPackageName = resourcesPackageName.get(), resourcesClassName = resourcesClassName.get(), @@ -257,6 +265,49 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { ) } + private fun createColorsGenerator(): ResourceTypeGenerator { + return ResourceTypeGenerator( + generationPackage = resourcesPackageName.get(), + resourceClass = CodeConst.colorResourceName, + resourceType = ResourceType.COLORS, + metadataClass = ColorMetadata::class, + visibilityModifier = resourcesVisibility.get().toModifier(), + generator = ColorResourceGenerator(), + platformResourceGenerator = createPlatformColorGenerator(), + filter = { include("**/colors*.xml") } + ) + } + + private fun createPlatformColorGenerator(): PlatformResourceGenerator { + val resourcesGenerationDir: File = outputResourcesDir.get().asFile + val assetsGenerationDir: File = outputAssetsDir.get().asFile + return createByPlatform( + kotlinPlatformType = kotlinPlatformType, + konanTarget = ::kotlinKonanTarget, + // TODO find way to remove this NOP + createCommon = { NOPColorResourceGenerator() }, + createAndroid = { + AndroidColorResourceGenerator( + androidRClassPackage = getAndroidR(), + resourcesGenerationDir = resourcesGenerationDir + ) + }, + createApple = { + AppleColorResourceGenerator( + assetsGenerationDir = assetsGenerationDir + ) + }, + createJvm = { + JvmColorResourceGenerator( + className = resourcesClassName.get() + ) + }, + createJs = { + JsColorResourceGenerator() + } + ) + } + private fun createPlatformImageGenerator(): PlatformResourceGenerator { val resourcesGenerationDir: File = outputResourcesDir.get().asFile val assetsGenerationDir: File = outputAssetsDir.get().asFile diff --git a/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt b/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt index e84369e69..3df22545e 100644 --- a/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt +++ b/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt @@ -69,7 +69,7 @@ internal fun App() { modifier = Modifier.fillMaxWidth() .padding(vertical = 8.dp), text = stringResource(MR.plurals.chars_count, counter, counter), -// color = colorResource(MR.colors.textColor), + color = colorResource(MR.colors.textColor), // fontFamily = fontFamilyResource(MR.fonts.cormorant.italic) ) From 9131539cc065b43d9f7ad22d4867cef2b3e5aa60 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Tue, 9 Jan 2024 21:59:25 +0700 Subject: [PATCH 094/352] #311 fix configuration cache support --- .../gradle/MultiplatformResourcesPlugin.kt | 4 ++++ .../GenerateMultiplatformResourcesTask.kt | 22 ++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 064c48471..d1bca26ad 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -15,6 +15,8 @@ import dev.icerock.gradle.generator.platform.js.setupJsKLibResources import dev.icerock.gradle.generator.platform.js.setupJsResources import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask import dev.icerock.gradle.utils.dependsOnObservable +import dev.icerock.gradle.utils.getAndroidRClassPackage +import dev.icerock.gradle.utils.isStrictLineBreaks import dev.icerock.gradle.utils.kotlinSourceSetsObservable import org.gradle.api.GradleException import org.gradle.api.Plugin @@ -296,6 +298,8 @@ open class MultiplatformResourcesPlugin : Plugin { generateTask.resourcesClassName.set(mrExtension.resourcesClassName) generateTask.resourcesPackageName.set(mrExtension.resourcesPackage) generateTask.resourcesVisibility.set(mrExtension.resourcesVisibility) + generateTask.androidRClassPackage.set(project.getAndroidRClassPackage()) + generateTask.strictLineBreaks.set(project.provider { project.isStrictLineBreaks }) generateTask.outputMetadataFile.set( File( File(generatedMokoResourcesDir, "metadata"), 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 ad9b06074..1ee379f7b 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 @@ -48,8 +48,6 @@ import dev.icerock.gradle.metadata.resource.StringMetadata import dev.icerock.gradle.toModifier import dev.icerock.gradle.utils.createByPlatform import dev.icerock.gradle.utils.flatName -import dev.icerock.gradle.utils.getAndroidRClassPackage -import dev.icerock.gradle.utils.isStrictLineBreaks import kotlinx.serialization.KSerializer import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.json.Json @@ -111,6 +109,12 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { @get:Input abstract val resourcesVisibility: Property + @get:Input + abstract val androidRClassPackage: Property + + @get:Input + abstract val strictLineBreaks: Property + @get:OutputFile abstract val outputMetadataFile: RegularFileProperty @@ -228,7 +232,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { metadataClass = StringMetadata::class, visibilityModifier = resourcesVisibility.get().toModifier(), generator = StringResourceGenerator( - strictLineBreaks = project.isStrictLineBreaks + strictLineBreaks = strictLineBreaks.get() ), platformResourceGenerator = createPlatformStringGenerator(), filter = { include("**/strings*.xml") } @@ -243,7 +247,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { metadataClass = PluralMetadata::class, visibilityModifier = resourcesVisibility.get().toModifier(), generator = PluralResourceGenerator( - strictLineBreaks = project.isStrictLineBreaks + strictLineBreaks = strictLineBreaks.get() ), platformResourceGenerator = createPlatformPluralGenerator(), filter = { include("**/plurals*.xml") } @@ -288,7 +292,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { createCommon = { NOPColorResourceGenerator() }, createAndroid = { AndroidColorResourceGenerator( - androidRClassPackage = getAndroidR(), + androidRClassPackage = androidRClassPackage.get(), resourcesGenerationDir = resourcesGenerationDir ) }, @@ -318,7 +322,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { createCommon = { NOPImageResourceGenerator() }, createAndroid = { AndroidImageResourceGenerator( - androidRClassPackage = getAndroidR(), + androidRClassPackage = androidRClassPackage.get(), resourcesGenerationDir = resourcesGenerationDir, logger = this.logger ) @@ -351,7 +355,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { createCommon = { NOPPluralResourceGenerator() }, createAndroid = { AndroidPluralResourceGenerator( - androidRClassPackage = getAndroidR(), + androidRClassPackage = androidRClassPackage.get(), resourcesGenerationDir = resourcesGenerationDir ) }, @@ -377,8 +381,6 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { ) } - private fun getAndroidR(): String = project.getAndroidRClassPackage().get() - private fun createPlatformStringGenerator(): PlatformResourceGenerator { val resourcesGenerationDir: File = outputResourcesDir.get().asFile return createByPlatform( @@ -388,7 +390,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { createCommon = { NOPStringResourceGenerator() }, createAndroid = { AndroidStringResourceGenerator( - androidRClassPackage = getAndroidR(), + androidRClassPackage = androidRClassPackage.get(), resourcesGenerationDir = resourcesGenerationDir ) }, From f4b6550ffd54c960565be6fc7518ec9f10da206c Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Wed, 10 Jan 2024 10:21:38 +0700 Subject: [PATCH 095/352] #311 apple fixes for configuration cache --- .../gradle/MultiplatformResourcesPlugin.kt | 3 +- .../CopyResourcesFromFrameworkToFatAction.kt | 36 ++++++ .../apple/CopyResourcesFromKLibsAction.kt | 22 +--- ...opyResourcesFromKLibsToExecutableAction.kt | 5 +- ...CopyResourcesFromKLibsToFrameworkAction.kt | 5 +- .../js/CopyResourcesToExecutableAction.kt | 31 ++--- .../platform/apple/SetupAppleUtils.kt | 119 +++++++----------- .../generator/platform/js/JsSetupUtils.kt | 8 +- .../tasks/CopyFrameworkResourcesToAppTask.kt | 24 ++-- .../gradle.properties | 13 +- 10 files changed, 132 insertions(+), 134 deletions(-) create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromFrameworkToFatAction.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index d1bca26ad..c9e79cdac 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -137,7 +137,8 @@ open class MultiplatformResourcesPlugin : Plugin { compileTask = compileTask, resourcesGenerationDir = genTaskProvider.flatMap { it.outputResourcesDir.asFile - } + }, + projectDir = project.provider { project.projectDir } ) setupJsKLibResources( compileTask = compileTask, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromFrameworkToFatAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromFrameworkToFatAction.kt new file mode 100644 index 000000000..48ccfcef0 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromFrameworkToFatAction.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.actions.apple + +import org.gradle.api.Action +import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask +import java.io.File + +internal class CopyResourcesFromFrameworkToFatAction : Action { + override fun execute(task: FatFrameworkTask) { + val fatFrameworkDir: File = task.fatFramework + val frameworkFile: File = task.frameworks.first().files.rootDir + + executeWithFramework(fatFrameworkDir, frameworkFile) + } + + private fun executeWithFramework( + fatFrameworkDir: File, + frameworkFile: File, + ) { + frameworkFile.listFiles().orEmpty() + .filter { it.extension == "bundle" } + .forEach { bundleFile -> + val destinationDir = File(fatFrameworkDir, bundleFile.name) + + destinationDir.deleteRecursively() + + bundleFile.copyRecursively( + target = destinationDir, + overwrite = false + ) + } + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsAction.kt index 3c0a16571..2a2141db8 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsAction.kt @@ -6,39 +6,27 @@ package dev.icerock.gradle.actions.apple import dev.icerock.gradle.utils.klibs import org.gradle.api.Action -import org.gradle.api.Project import org.gradle.api.Task import org.jetbrains.kotlin.gradle.plugin.mpp.Framework import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink +import org.jetbrains.kotlin.library.KotlinLibraryLayout import org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl import java.io.File internal abstract class CopyResourcesFromKLibsAction : Action { - protected fun copyKlibsResourcesIntoFramework(linkTask: KotlinNativeLink) { - val project = linkTask.project - val framework = linkTask.binary as Framework - - copyResourcesFromLibraries( - linkTask = linkTask, - project = project, - outputDir = framework.outputFile - ) - } - protected fun copyResourcesFromLibraries( linkTask: KotlinNativeLink, - project: Project, outputDir: File ) { linkTask.klibs .filter { it.extension == "klib" } .filter { it.exists() } .forEach { inputFile -> - project.logger.info("copy resources from $inputFile into $outputDir") + linkTask.logger.info("copy resources from $inputFile into $outputDir") val klibKonan = org.jetbrains.kotlin.konan.file.File(inputFile.path) val klib = KotlinLibraryLayoutImpl(klib = klibKonan, component = "default") - val layout = klib.extractingToTemp + val layout: KotlinLibraryLayout = klib.extractingToTemp try { File(layout.resourcesDir.path).copyRecursively( @@ -46,9 +34,9 @@ internal abstract class CopyResourcesFromKLibsAction : Action { overwrite = true ) } catch (@Suppress("SwallowedException") exc: NoSuchFileException) { - project.logger.info("resources in $inputFile not found") + linkTask.logger.info("resources in $inputFile not found") } catch (@Suppress("SwallowedException") exc: java.nio.file.NoSuchFileException) { - project.logger.info("resources in $inputFile not found (empty lib)") + linkTask.logger.info("resources in $inputFile not found (empty lib)") } } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsToExecutableAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsToExecutableAction.kt index 33e73d26e..efb82a2e0 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsToExecutableAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsToExecutableAction.kt @@ -12,12 +12,9 @@ internal class CopyResourcesFromKLibsToExecutableAction : CopyResourcesFromKLibs override fun execute(task: Task) { task as KotlinNativeLink - val executable: AbstractExecutable = task.binary as AbstractExecutable - copyResourcesFromLibraries( linkTask = task, - project = task.project, - outputDir = executable.outputDirectory + outputDir = task.outputFile.get() ) } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsToFrameworkAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsToFrameworkAction.kt index 151984025..82933d54a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsToFrameworkAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsToFrameworkAction.kt @@ -12,12 +12,9 @@ internal class CopyResourcesFromKLibsToFrameworkAction : CopyResourcesFromKLibsA override fun execute(task: Task) { task as KotlinNativeLink - val framework: Framework = task.binary as Framework - copyResourcesFromLibraries( linkTask = task, - project = task.project, - outputDir = framework.outputFile + outputDir = task.outputFile.get() ) } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/js/CopyResourcesToExecutableAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/js/CopyResourcesToExecutableAction.kt index a49ea50b5..800c13d0d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/js/CopyResourcesToExecutableAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/js/CopyResourcesToExecutableAction.kt @@ -6,33 +6,34 @@ package dev.icerock.gradle.actions.js import dev.icerock.gradle.utils.klibs import org.gradle.api.Action -import org.gradle.api.Project +import org.gradle.api.logging.Logger import org.gradle.api.provider.Provider import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile +import org.jetbrains.kotlin.library.KotlinLibraryLayout import org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl import java.io.File internal class CopyResourcesToExecutableAction( private val resourcesGeneratedDir: Provider, + private val projectDir: Provider ) : Action { override fun execute(task: Kotlin2JsCompile) { - val project: Project = task.project val resourceDir = resourcesGeneratedDir.get() task.klibs.forEach { dependency -> copyResourcesFromLibraries( + logger = task.logger, inputFile = dependency, - project = project, outputDir = resourceDir ) } - generateWebpackConfig(project, resourceDir) - generateKarmaConfig(project) + generateWebpackConfig(resourceDir) + generateKarmaConfig() } - private fun generateWebpackConfig(project: Project, resourcesOutput: File) { - val webpackDir = File(project.projectDir, "webpack.config.d") + private fun generateWebpackConfig(resourcesOutput: File) { + val webpackDir = File(projectDir.get(), "webpack.config.d") webpackDir.mkdirs() val webpackConfig = File(webpackDir, "moko-resources-generated.js") @@ -88,8 +89,8 @@ internal class CopyResourcesToExecutableAction( ) } - private fun generateKarmaConfig(project: Project) { - val webpackDir = File(project.projectDir, "karma.config.d") + private fun generateKarmaConfig() { + val webpackDir = File(projectDir.get(), "karma.config.d") webpackDir.mkdirs() val webpackTestConfig = File(webpackDir, "moko-resources-generated.js") @@ -124,16 +125,16 @@ internal class CopyResourcesToExecutableAction( private fun copyResourcesFromLibraries( inputFile: File, - project: Project, - outputDir: File + outputDir: File, + logger: Logger ) { if (inputFile.extension != "klib") return if (inputFile.exists().not()) return - project.logger.info("copy resources from $inputFile into $outputDir") + logger.info("copy resources from $inputFile into $outputDir") val klibKonan = org.jetbrains.kotlin.konan.file.File(inputFile.path) val klib = KotlinLibraryLayoutImpl(klib = klibKonan, component = "default") - val layout = klib.extractingToTemp + val layout: KotlinLibraryLayout = klib.extractingToTemp try { File(layout.resourcesDir.path, "moko-resources-js").copyRecursively( @@ -141,9 +142,9 @@ internal class CopyResourcesToExecutableAction( overwrite = true ) } catch (@Suppress("SwallowedException") exc: NoSuchFileException) { - project.logger.info("resources in $inputFile not found") + logger.info("resources in $inputFile not found") } catch (@Suppress("SwallowedException") exc: java.nio.file.NoSuchFileException) { - project.logger.info("resources in $inputFile not found (empty lib)") + logger.info("resources in $inputFile not found (empty lib)") } } } \ No newline at end of file diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt index 785e8225e..c998267a2 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt @@ -6,31 +6,26 @@ package dev.icerock.gradle.generator.platform.apple import com.android.build.gradle.internal.tasks.factory.dependsOn import dev.icerock.gradle.MultiplatformResourcesPluginExtension +import dev.icerock.gradle.actions.apple.CopyResourcesFromFrameworkToFatAction import dev.icerock.gradle.actions.apple.CopyResourcesFromKLibsToExecutableAction import dev.icerock.gradle.actions.apple.CopyResourcesFromKLibsToFrameworkAction import dev.icerock.gradle.actions.apple.PackAppleResourcesToKLibAction -import dev.icerock.gradle.tasks.CopyFrameworkResourcesToAppEntryPointTask import dev.icerock.gradle.tasks.CopyFrameworkResourcesToAppTask import org.gradle.api.Action import org.gradle.api.Project import org.gradle.api.Task -import org.gradle.api.plugins.ExtensionAware import org.gradle.api.provider.Provider -import org.gradle.kotlin.dsl.findByType +import org.gradle.api.tasks.TaskProvider import org.gradle.kotlin.dsl.getByType import org.gradle.kotlin.dsl.withType -import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension -import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension import org.jetbrains.kotlin.gradle.plugin.mpp.Framework import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask -import org.jetbrains.kotlin.gradle.tasks.FrameworkDescriptor import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile import java.io.File -import kotlin.reflect.full.memberProperties -fun setupAppleKLibResources( +internal fun setupAppleKLibResources( compileTask: KotlinNativeCompile, assetsDirectory: Provider, resourcesGenerationDir: Provider, @@ -62,11 +57,10 @@ fun setupAppleKLibResources( // ) } -fun setupFrameworkResources(compilation: KotlinNativeCompilation) { +internal fun setupFrameworkResources(compilation: KotlinNativeCompilation) { compilation.target.binaries.withType().configureEach { framework -> framework.linkTaskProvider.configure { linkTask -> linkTask.doLast(CopyResourcesFromKLibsToFrameworkAction()) - } if (framework.isStatic) { @@ -85,34 +79,46 @@ ${framework.linkTaskName} produces static framework, Xcode should have Build Pha } } -fun createCopyFrameworkResourcesTask(framework: Framework) { - val project = framework.project - val taskName = framework.linkTaskName.replace("link", "copyResources") +internal fun createCopyFrameworkResourcesTask(framework: Framework) { + val project: Project = framework.project + val taskName: String = framework.linkTaskName.replace("link", "copyResources") - val copyTask = project.tasks.register(taskName, CopyFrameworkResourcesToAppTask::class.java) { - it.framework = framework - } + val copyTask: TaskProvider = + project.tasks.register(taskName, CopyFrameworkResourcesToAppTask::class.java) { + it.inputFrameworkDirectory.set(framework.outputDirectoryProperty) + it.outputDirectory.set(project.provider { + val buildProductsDir = + project.property("moko.resources.BUILT_PRODUCTS_DIR") as String + val contentsFolderPath = + project.property("moko.resources.CONTENTS_FOLDER_PATH") as String + + val targetDir = File("$buildProductsDir/$contentsFolderPath") + val baseDir: File = project.layout.projectDirectory.asFile + + project.layout.projectDirectory.dir(targetDir.relativeTo(baseDir).path) + }) + } copyTask.dependsOn(framework.linkTaskProvider) //TODO: Вынести в отдельную таску, должно создаваться один раз - val xcodeTask = project.tasks.maybeCreate( - "copyFrameworkResourcesToApp", - CopyFrameworkResourcesToAppEntryPointTask::class.java - ) - val multiplatformExtension = project.extensions.getByType() - xcodeTask.configurationMapper = (multiplatformExtension as? ExtensionAware)?.extensions - ?.findByType() - ?.xcodeConfigurationToNativeBuildType - ?: emptyMap() - - if (framework.target.konanTarget == xcodeTask.konanTarget && - framework.buildType.getName() == xcodeTask.configuration?.lowercase() - ) { - xcodeTask.dependsOn(copyTask) - } +// val xcodeTask = project.tasks.maybeCreate( +// "copyFrameworkResourcesToApp", +// CopyFrameworkResourcesToAppEntryPointTask::class.java +// ) +// val multiplatformExtension = project.extensions.getByType() +// xcodeTask.configurationMapper = (multiplatformExtension as? ExtensionAware)?.extensions +// ?.findByType() +// ?.xcodeConfigurationToNativeBuildType +// ?: emptyMap() +// +// if (framework.target.konanTarget == xcodeTask.konanTarget && +// framework.buildType.getName() == xcodeTask.configuration?.lowercase() +// ) { +// xcodeTask.dependsOn(copyTask) +// } } -fun setupTestsResources(compilation: KotlinNativeCompilation) { +internal fun setupTestsResources(compilation: KotlinNativeCompilation) { compilation.target.binaries.withType().configureEach { executable -> executable.linkTaskProvider.configure { link -> link.doLast(CopyResourcesFromKLibsToExecutableAction()) @@ -120,48 +126,9 @@ fun setupTestsResources(compilation: KotlinNativeCompilation) { } } -fun setupFatFrameworkTasks(compilation: KotlinNativeCompilation) { - val project = compilation.project - - val fatAction: Action = object : Action { - override fun execute(task: Task) { - val fatTask: FatFrameworkTask = task as FatFrameworkTask - - // compatibility of this api was changed - // from 1.6.10 to 1.6.20, so reflection was - // used here. - val fatFrameworkDir: File = FatFrameworkTask::class - .memberProperties - .run { - find { it.name == "fatFrameworkDir" } - ?: find { it.name == "fatFramework" } - }?.invoke(fatTask) as File - - val frameworkFile = when (val any: Any = fatTask.frameworks.first()) { - is Framework -> any.outputFile - is FrameworkDescriptor -> any.files.rootDir - else -> error("Unsupported type of $any") - } - - executeWithFramework(fatFrameworkDir, frameworkFile) - } - - private fun executeWithFramework( - fatFrameworkDir: File, - frameworkFile: File, - ) = frameworkFile - .listFiles() - ?.asSequence() - ?.filter { it.name.contains(".bundle") } - ?.forEach { bundleFile -> - project.copy { - it.from(bundleFile) - it.into(File(fatFrameworkDir, bundleFile.name)) - } - } - } - - project.tasks.withType().configureEach { - it.doLast(fatAction) +internal fun setupFatFrameworkTasks(compilation: KotlinNativeCompilation) { + compilation.project.tasks.withType().configureEach { + @Suppress("UNCHECKED_CAST") + it.doLast(CopyResourcesFromFrameworkToFatAction() as Action) } -} \ No newline at end of file +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/js/JsSetupUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/js/JsSetupUtils.kt index 95322b733..10a73da19 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/js/JsSetupUtils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/js/JsSetupUtils.kt @@ -23,9 +23,13 @@ internal fun setupJsKLibResources( internal fun setupJsResources( compileTask: Kotlin2JsCompile, - resourcesGenerationDir: Provider + resourcesGenerationDir: Provider, + projectDir: Provider ) { - val copyResourcesAction = CopyResourcesToExecutableAction(resourcesGenerationDir) + val copyResourcesAction = CopyResourcesToExecutableAction( + resourcesGeneratedDir = resourcesGenerationDir, + projectDir = projectDir + ) @Suppress("UNCHECKED_CAST") compileTask.doLast(copyResourcesAction as Action) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyFrameworkResourcesToAppTask.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyFrameworkResourcesToAppTask.kt index f54eada88..70c366e3b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyFrameworkResourcesToAppTask.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyFrameworkResourcesToAppTask.kt @@ -5,31 +5,31 @@ package dev.icerock.gradle.tasks import org.gradle.api.DefaultTask -import org.gradle.api.tasks.Internal +import org.gradle.api.file.DirectoryProperty +import org.gradle.api.tasks.InputDirectory +import org.gradle.api.tasks.OutputDirectory import org.gradle.api.tasks.TaskAction -import org.jetbrains.kotlin.gradle.plugin.mpp.Framework import java.io.File import java.io.FileFilter -open class CopyFrameworkResourcesToAppTask : DefaultTask() { +abstract class CopyFrameworkResourcesToAppTask : DefaultTask() { init { group = "moko-resources" } - @Internal - lateinit var framework: Framework + @get:InputDirectory + abstract val inputFrameworkDirectory: DirectoryProperty + + @get:OutputDirectory + abstract val outputDirectory: DirectoryProperty @TaskAction fun copyResources() { - val buildProductsDir = - project.property("moko.resources.BUILT_PRODUCTS_DIR") as String - val contentsFolderPath = - project.property("moko.resources.CONTENTS_FOLDER_PATH") as String - val outputDir = File("$buildProductsDir/$contentsFolderPath") + val outputDir: File = outputDirectory.get().asFile - val inputDir = framework.outputFile + val inputDir: File = inputFrameworkDirectory.get().asFile inputDir.listFiles(FileFilter { it.extension == "bundle" })?.forEach { - project.logger.info("copy resources bundle $it to $outputDir") + logger.info("copy resources bundle $it to $outputDir") it.copyRecursively(File(outputDir, it.name), overwrite = true) } } diff --git a/samples/compose-resources-gallery/gradle.properties b/samples/compose-resources-gallery/gradle.properties index 78b79350f..b99d20441 100644 --- a/samples/compose-resources-gallery/gradle.properties +++ b/samples/compose-resources-gallery/gradle.properties @@ -1,18 +1,25 @@ org.gradle.jvmargs=-Xmx12g org.gradle.parallel=true org.gradle.caching=true +org.gradle.configuration-cache=true + kotlin.code.style=official + xcodeproj=./iosApp + kotlin.native.cocoapods.generate.wrapper=true +kotlin.native.useEmbeddableCompilerJar=true +kotlin.native.binary.memoryModel=experimental + android.useAndroidX=true + org.jetbrains.compose.experimental.jscanvas.enabled=true org.jetbrains.compose.experimental.macos.enabled=true org.jetbrains.compose.experimental.uikit.enabled=true -kotlin.native.useEmbeddableCompilerJar=true + kotlin.mpp.androidSourceSetLayoutVersion=2 kotlin.mpp.androidGradlePluginCompatibility.nowarn=true -# Enable kotlin/native experimental memory model -kotlin.native.binary.memoryModel=experimental + kotlin.version=1.9.21 agp.version=8.1.0 compose.version=1.5.11 From 2369582194053695f17e67210bb35aab8271d511 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Wed, 10 Jan 2024 11:26:18 +0700 Subject: [PATCH 096/352] #535 move generators --- .../color/AndroidColorResourceGenerator.kt | 2 +- .../color/AppleColorResourceGenerator.kt | 2 +- .../color/ColorResourceGenerator.kt | 2 +- .../color/JsColorResourceGenerator.kt | 2 +- .../color/JvmColorResourceGenerator.kt | 2 +- .../color/NOPColorResourceGenerator.kt | 2 +- .../generator/{ => resources}/color/Utils.kt | 2 +- .../image/AndroidImageResourceGenerator.kt | 2 +- .../image/AppleImageResourceGenerator.kt | 2 +- .../image/ImageResourceGenerator.kt | 2 +- .../image/JsImageResourceGenerator.kt | 2 +- .../image/JvmImageResourceGenerator.kt | 2 +- .../image/NOPImageResourceGenerator.kt | 2 +- .../generator/{ => resources}/image/Utils.kt | 2 +- .../plural/AndroidPluralResourceGenerator.kt | 2 +- .../plural/ApplePluralResourceGenerator.kt | 2 +- .../plural/JsPluralResourceGenerator.kt | 2 +- .../plural/JvmPluralResourceGenerator.kt | 2 +- .../plural/NOPPluralResourceGenerator.kt | 2 +- .../plural/PluralResourceGenerator.kt | 2 +- .../generator/{ => resources}/plural/Utils.kt | 2 +- .../string/AndroidStringResourceGenerator.kt | 2 +- .../string/AppleStringResourceGenerator.kt | 2 +- .../string/JsStringResourceGenerator.kt | 2 +- .../string/JvmStringResourceGenerator.kt | 2 +- .../string/NOPStringResourceGenerator.kt | 2 +- .../string/StringResourceGenerator.kt | 2 +- .../generator/{ => resources}/string/Utils.kt | 2 +- .../GenerateMultiplatformResourcesTask.kt | 48 +++++++++---------- 29 files changed, 52 insertions(+), 52 deletions(-) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => resources}/color/AndroidColorResourceGenerator.kt (98%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => resources}/color/AppleColorResourceGenerator.kt (98%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => resources}/color/ColorResourceGenerator.kt (98%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => resources}/color/JsColorResourceGenerator.kt (96%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => resources}/color/JvmColorResourceGenerator.kt (96%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => resources}/color/NOPColorResourceGenerator.kt (93%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => resources}/color/Utils.kt (94%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => resources}/image/AndroidImageResourceGenerator.kt (98%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => resources}/image/AppleImageResourceGenerator.kt (98%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => resources}/image/ImageResourceGenerator.kt (96%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => resources}/image/JsImageResourceGenerator.kt (97%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => resources}/image/JvmImageResourceGenerator.kt (97%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => resources}/image/NOPImageResourceGenerator.kt (93%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => resources}/image/Utils.kt (94%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => resources}/plural/AndroidPluralResourceGenerator.kt (97%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => resources}/plural/ApplePluralResourceGenerator.kt (98%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => resources}/plural/JsPluralResourceGenerator.kt (98%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => resources}/plural/JvmPluralResourceGenerator.kt (98%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => resources}/plural/NOPPluralResourceGenerator.kt (93%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => resources}/plural/PluralResourceGenerator.kt (98%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => resources}/plural/Utils.kt (92%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => resources}/string/AndroidStringResourceGenerator.kt (97%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => resources}/string/AppleStringResourceGenerator.kt (97%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => resources}/string/JsStringResourceGenerator.kt (98%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => resources}/string/JvmStringResourceGenerator.kt (98%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => resources}/string/NOPStringResourceGenerator.kt (93%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => resources}/string/StringResourceGenerator.kt (98%) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{ => resources}/string/Utils.kt (90%) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/AndroidColorResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/AndroidColorResourceGenerator.kt similarity index 98% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/AndroidColorResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/AndroidColorResourceGenerator.kt index ad5d12b5c..c3f0a4277 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/AndroidColorResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/AndroidColorResourceGenerator.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.color +package dev.icerock.gradle.generator.resources.color import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/AppleColorResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/AppleColorResourceGenerator.kt similarity index 98% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/AppleColorResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/AppleColorResourceGenerator.kt index 8eef9a13a..3be47c438 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/AppleColorResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/AppleColorResourceGenerator.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.color +package dev.icerock.gradle.generator.resources.color import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/ColorResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/ColorResourceGenerator.kt similarity index 98% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/ColorResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/ColorResourceGenerator.kt index 6ed2176f5..32ab0dfe6 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/ColorResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/ColorResourceGenerator.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.color +package dev.icerock.gradle.generator.resources.color import com.squareup.kotlinpoet.PropertySpec import dev.icerock.gradle.generator.CodeConst diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/JsColorResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/JsColorResourceGenerator.kt similarity index 96% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/JsColorResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/JsColorResourceGenerator.kt index d216fd454..ed4184b8b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/JsColorResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/JsColorResourceGenerator.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.color +package dev.icerock.gradle.generator.resources.color import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/JvmColorResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/JvmColorResourceGenerator.kt similarity index 96% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/JvmColorResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/JvmColorResourceGenerator.kt index d60b493f6..ead818cf6 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/JvmColorResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/JvmColorResourceGenerator.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.color +package dev.icerock.gradle.generator.resources.color import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/NOPColorResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/NOPColorResourceGenerator.kt similarity index 93% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/NOPColorResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/NOPColorResourceGenerator.kt index e0bf2e0b4..9da692147 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/NOPColorResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/NOPColorResourceGenerator.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.color +package dev.icerock.gradle.generator.resources.color import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/Utils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/Utils.kt similarity index 94% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/Utils.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/Utils.kt index d4f6379ee..85e8a19a2 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/color/Utils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/Utils.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.color +package dev.icerock.gradle.generator.resources.color import com.squareup.kotlinpoet.CodeBlock import dev.icerock.gradle.metadata.resource.ColorMetadata diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/AndroidImageResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/AndroidImageResourceGenerator.kt similarity index 98% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/AndroidImageResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/AndroidImageResourceGenerator.kt index 5e3f058ed..08db7dca4 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/AndroidImageResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/AndroidImageResourceGenerator.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.image +package dev.icerock.gradle.generator.resources.image import com.android.ide.common.vectordrawable.Svg2Vector import com.squareup.kotlinpoet.ClassName diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/AppleImageResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/AppleImageResourceGenerator.kt similarity index 98% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/AppleImageResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/AppleImageResourceGenerator.kt index 593d7ee3f..e2f9fb269 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/AppleImageResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/AppleImageResourceGenerator.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.image +package dev.icerock.gradle.generator.resources.image import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/ImageResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/ImageResourceGenerator.kt similarity index 96% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/ImageResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/ImageResourceGenerator.kt index 6bfc3e002..20ff05c4e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/ImageResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/ImageResourceGenerator.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.image +package dev.icerock.gradle.generator.resources.image import com.squareup.kotlinpoet.PropertySpec import dev.icerock.gradle.generator.CodeConst diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/JsImageResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/JsImageResourceGenerator.kt similarity index 97% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/JsImageResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/JsImageResourceGenerator.kt index 2ceaeb8fd..e00b647dc 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/JsImageResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/JsImageResourceGenerator.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.image +package dev.icerock.gradle.generator.resources.image import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/JvmImageResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/JvmImageResourceGenerator.kt similarity index 97% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/JvmImageResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/JvmImageResourceGenerator.kt index b0cbdca93..56509d5cc 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/JvmImageResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/JvmImageResourceGenerator.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.image +package dev.icerock.gradle.generator.resources.image import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/NOPImageResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/NOPImageResourceGenerator.kt similarity index 93% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/NOPImageResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/NOPImageResourceGenerator.kt index 4353df036..bbefe7957 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/NOPImageResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/NOPImageResourceGenerator.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.image +package dev.icerock.gradle.generator.resources.image import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/Utils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/Utils.kt similarity index 94% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/Utils.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/Utils.kt index 6322b8626..69b894187 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/image/Utils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/Utils.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.image +package dev.icerock.gradle.generator.resources.image import dev.icerock.gradle.metadata.resource.ImageMetadata import java.io.File diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/AndroidPluralResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/AndroidPluralResourceGenerator.kt similarity index 97% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/AndroidPluralResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/AndroidPluralResourceGenerator.kt index 3dd6aef70..e424f5f64 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/AndroidPluralResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/AndroidPluralResourceGenerator.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.plural +package dev.icerock.gradle.generator.resources.plural import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/ApplePluralResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/ApplePluralResourceGenerator.kt similarity index 98% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/ApplePluralResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/ApplePluralResourceGenerator.kt index 43bf2a667..4a3f09bbf 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/ApplePluralResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/ApplePluralResourceGenerator.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.plural +package dev.icerock.gradle.generator.resources.plural import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/JsPluralResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/JsPluralResourceGenerator.kt similarity index 98% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/JsPluralResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/JsPluralResourceGenerator.kt index 34ffe3132..f6c42a97e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/JsPluralResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/JsPluralResourceGenerator.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.plural +package dev.icerock.gradle.generator.resources.plural import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/JvmPluralResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/JvmPluralResourceGenerator.kt similarity index 98% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/JvmPluralResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/JvmPluralResourceGenerator.kt index ddcf0bbb2..456072006 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/JvmPluralResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/JvmPluralResourceGenerator.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.plural +package dev.icerock.gradle.generator.resources.plural import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/NOPPluralResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/NOPPluralResourceGenerator.kt similarity index 93% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/NOPPluralResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/NOPPluralResourceGenerator.kt index a14db214a..6dffb2cbb 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/NOPPluralResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/NOPPluralResourceGenerator.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.plural +package dev.icerock.gradle.generator.resources.plural import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/PluralResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/PluralResourceGenerator.kt similarity index 98% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/PluralResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/PluralResourceGenerator.kt index 7f9b300ff..407a2e888 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/PluralResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/PluralResourceGenerator.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.plural +package dev.icerock.gradle.generator.resources.plural import com.squareup.kotlinpoet.PropertySpec import dev.icerock.gradle.generator.CodeConst diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/Utils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/Utils.kt similarity index 92% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/Utils.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/Utils.kt index 91b6d243c..4ed7749c7 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/plural/Utils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/Utils.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.plural +package dev.icerock.gradle.generator.resources.plural import dev.icerock.gradle.metadata.resource.PluralMetadata diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/AndroidStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/AndroidStringResourceGenerator.kt similarity index 97% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/AndroidStringResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/AndroidStringResourceGenerator.kt index d7a2ee8a6..75e25b5f6 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/AndroidStringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/AndroidStringResourceGenerator.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.string +package dev.icerock.gradle.generator.resources.string import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/AppleStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/AppleStringResourceGenerator.kt similarity index 97% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/AppleStringResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/AppleStringResourceGenerator.kt index bb71c986a..cc5f17a95 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/AppleStringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/AppleStringResourceGenerator.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.string +package dev.icerock.gradle.generator.resources.string import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/JsStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/JsStringResourceGenerator.kt similarity index 98% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/JsStringResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/JsStringResourceGenerator.kt index 5c5dca8be..3e8fd8aeb 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/JsStringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/JsStringResourceGenerator.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.string +package dev.icerock.gradle.generator.resources.string import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/JvmStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/JvmStringResourceGenerator.kt similarity index 98% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/JvmStringResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/JvmStringResourceGenerator.kt index 7052ccac2..b8a45c617 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/JvmStringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/JvmStringResourceGenerator.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.string +package dev.icerock.gradle.generator.resources.string import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/NOPStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/NOPStringResourceGenerator.kt similarity index 93% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/NOPStringResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/NOPStringResourceGenerator.kt index ff2b1107f..02c1c5d52 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/NOPStringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/NOPStringResourceGenerator.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.string +package dev.icerock.gradle.generator.resources.string import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/StringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/StringResourceGenerator.kt similarity index 98% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/StringResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/StringResourceGenerator.kt index db1b0aaa7..d77bf828a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/StringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/StringResourceGenerator.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.string +package dev.icerock.gradle.generator.resources.string import com.squareup.kotlinpoet.PropertySpec import dev.icerock.gradle.generator.exceptions.EqualStringKeysException diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/Utils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/Utils.kt similarity index 90% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/Utils.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/Utils.kt index 64ccb661e..f4084d9dc 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/string/Utils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/Utils.kt @@ -2,7 +2,7 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.string +package dev.icerock.gradle.generator.resources.string import dev.icerock.gradle.metadata.resource.StringMetadata 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 1ee379f7b..4d9bbc669 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 @@ -11,33 +11,33 @@ import dev.icerock.gradle.generator.PlatformResourceGenerator import dev.icerock.gradle.generator.ResourceTypeGenerator import dev.icerock.gradle.generator.ResourcesFiles import dev.icerock.gradle.generator.ResourcesGenerator -import dev.icerock.gradle.generator.color.AndroidColorResourceGenerator -import dev.icerock.gradle.generator.color.AppleColorResourceGenerator -import dev.icerock.gradle.generator.color.ColorResourceGenerator -import dev.icerock.gradle.generator.color.JsColorResourceGenerator -import dev.icerock.gradle.generator.color.JvmColorResourceGenerator -import dev.icerock.gradle.generator.color.NOPColorResourceGenerator import dev.icerock.gradle.generator.container.AppleContainerGenerator import dev.icerock.gradle.generator.container.JvmContainerGenerator import dev.icerock.gradle.generator.container.NOPContainerGenerator -import dev.icerock.gradle.generator.image.AndroidImageResourceGenerator -import dev.icerock.gradle.generator.image.AppleImageResourceGenerator -import dev.icerock.gradle.generator.image.ImageResourceGenerator -import dev.icerock.gradle.generator.image.JsImageResourceGenerator -import dev.icerock.gradle.generator.image.JvmImageResourceGenerator -import dev.icerock.gradle.generator.image.NOPImageResourceGenerator -import dev.icerock.gradle.generator.plural.AndroidPluralResourceGenerator -import dev.icerock.gradle.generator.plural.ApplePluralResourceGenerator -import dev.icerock.gradle.generator.plural.JsPluralResourceGenerator -import dev.icerock.gradle.generator.plural.JvmPluralResourceGenerator -import dev.icerock.gradle.generator.plural.NOPPluralResourceGenerator -import dev.icerock.gradle.generator.plural.PluralResourceGenerator -import dev.icerock.gradle.generator.string.AndroidStringResourceGenerator -import dev.icerock.gradle.generator.string.AppleStringResourceGenerator -import dev.icerock.gradle.generator.string.JsStringResourceGenerator -import dev.icerock.gradle.generator.string.JvmStringResourceGenerator -import dev.icerock.gradle.generator.string.NOPStringResourceGenerator -import dev.icerock.gradle.generator.string.StringResourceGenerator +import dev.icerock.gradle.generator.resources.color.AndroidColorResourceGenerator +import dev.icerock.gradle.generator.resources.color.AppleColorResourceGenerator +import dev.icerock.gradle.generator.resources.color.ColorResourceGenerator +import dev.icerock.gradle.generator.resources.color.JsColorResourceGenerator +import dev.icerock.gradle.generator.resources.color.JvmColorResourceGenerator +import dev.icerock.gradle.generator.resources.color.NOPColorResourceGenerator +import dev.icerock.gradle.generator.resources.image.AndroidImageResourceGenerator +import dev.icerock.gradle.generator.resources.image.AppleImageResourceGenerator +import dev.icerock.gradle.generator.resources.image.ImageResourceGenerator +import dev.icerock.gradle.generator.resources.image.JsImageResourceGenerator +import dev.icerock.gradle.generator.resources.image.JvmImageResourceGenerator +import dev.icerock.gradle.generator.resources.image.NOPImageResourceGenerator +import dev.icerock.gradle.generator.resources.plural.AndroidPluralResourceGenerator +import dev.icerock.gradle.generator.resources.plural.ApplePluralResourceGenerator +import dev.icerock.gradle.generator.resources.plural.JsPluralResourceGenerator +import dev.icerock.gradle.generator.resources.plural.JvmPluralResourceGenerator +import dev.icerock.gradle.generator.resources.plural.NOPPluralResourceGenerator +import dev.icerock.gradle.generator.resources.plural.PluralResourceGenerator +import dev.icerock.gradle.generator.resources.string.AndroidStringResourceGenerator +import dev.icerock.gradle.generator.resources.string.AppleStringResourceGenerator +import dev.icerock.gradle.generator.resources.string.JsStringResourceGenerator +import dev.icerock.gradle.generator.resources.string.JvmStringResourceGenerator +import dev.icerock.gradle.generator.resources.string.NOPStringResourceGenerator +import dev.icerock.gradle.generator.resources.string.StringResourceGenerator import dev.icerock.gradle.metadata.container.ContainerMetadata import dev.icerock.gradle.metadata.container.ObjectMetadata import dev.icerock.gradle.metadata.container.ResourceType From 52bee192658a525f8f5c42ed50c58930c66a05cc Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Wed, 10 Jan 2024 18:17:31 +0700 Subject: [PATCH 097/352] #535 fonts generator migration --- .../dev/icerock/gradle/generator/CodeConst.kt | 1 + .../font/AndroidFontResourceGenerator.kt | 34 ++ .../font/AppleFontResourceGenerator.kt | 41 +++ .../resources/font/FontResourceGenerator.kt | 27 ++ .../resources/font/JsFontResourceGenerator.kt | 89 ++++++ .../font/JvmFontResourceGenerator.kt | 59 ++++ .../font/NOPFontResourceGenerator.kt | 24 ++ .../string/StringResourceGenerator.kt | 2 +- .../metadata/resource/ResourceMetadata.kt | 10 +- .../icerock/gradle/oldgen/FontsGenerator.kt | 300 ------------------ .../oldgen/android/AndroidFontsGenerator.kt | 50 --- .../oldgen/apple/AppleFontsGenerator.kt | 37 --- .../gradle/oldgen/js/JsFontsGenerator.kt | 100 ------ .../gradle/oldgen/jvm/JvmFontsGenerator.kt | 40 --- .../GenerateMultiplatformResourcesTask.kt | 57 +++- .../dev/icerock/gradle/utils/ProjectExt.kt | 5 +- .../shared/src/commonMain/kotlin/App.kt | 2 +- 17 files changed, 338 insertions(+), 540 deletions(-) create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/AndroidFontResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/AppleFontResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/FontResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/JsFontResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/JvmFontResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/NOPFontResourceGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/FontsGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidFontsGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleFontsGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsFontsGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmFontsGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt index 341973aca..5d3578f88 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt @@ -12,6 +12,7 @@ internal object CodeConst { val pluralsResourceName = ClassName("dev.icerock.moko.resources", "PluralsResource") val imageResourceName = ClassName("dev.icerock.moko.resources", "ImageResource") val colorResourceName = ClassName("dev.icerock.moko.resources", "ColorResource") + val fontResourceName = ClassName("dev.icerock.moko.resources", "FontResource") val graphicsColorName = ClassName("dev.icerock.moko.graphics", "Color") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/AndroidFontResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/AndroidFontResourceGenerator.kt new file mode 100644 index 000000000..53e6f8878 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/AndroidFontResourceGenerator.kt @@ -0,0 +1,34 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.resources.font + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.metadata.resource.FontMetadata +import java.io.File + +internal class AndroidFontResourceGenerator( + private val androidRClassPackage: String, + private val resourcesGenerationDir: File +) : PlatformResourceGenerator { + override fun imports(): List = listOf( + ClassName(androidRClassPackage, "R") + ) + + override fun generateInitializer(metadata: FontMetadata): CodeBlock { + return CodeBlock.of("FontResource(R.font.%L)", metadata.key) + } + + override fun generateResourceFiles(data: List) { + val fontResDir = File(resourcesGenerationDir, "font") + fontResDir.mkdirs() + + data.forEach { metadata -> + val fileName: String = metadata.key + "." + metadata.filePath.extension + metadata.filePath.copyTo(File(fontResDir, fileName)) + } + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/AppleFontResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/AppleFontResourceGenerator.kt new file mode 100644 index 000000000..513106fc4 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/AppleFontResourceGenerator.kt @@ -0,0 +1,41 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.resources.font + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.generator.addAppleContainerBundleProperty +import dev.icerock.gradle.metadata.resource.FontMetadata +import java.io.File + +internal class AppleFontResourceGenerator( + private val resourcesGenerationDir: File +) : PlatformResourceGenerator { + override fun imports(): List = emptyList() + + override fun generateInitializer(metadata: FontMetadata): CodeBlock { + return CodeBlock.of( + "FontResource(fontName = %S, bundle = %L)", + metadata.filePath.name, + CodeConst.Apple.containerBundlePropertyName + ) + } + + override fun generateResourceFiles(data: List) { + data.map { it.filePath }.forEach { file -> + file.copyTo(File(resourcesGenerationDir, file.name)) + } + } + + override fun generateBeforeProperties( + builder: TypeSpec.Builder, + metadata: List + ) { + builder.addAppleContainerBundleProperty() + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/FontResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/FontResourceGenerator.kt new file mode 100644 index 000000000..964bfce3f --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/FontResourceGenerator.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.resources.font + +import com.squareup.kotlinpoet.PropertySpec +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.ResourceGenerator +import dev.icerock.gradle.metadata.resource.FontMetadata +import java.io.File + +internal class FontResourceGenerator : ResourceGenerator { + + override fun generateMetadata(files: Set): List { + return files.map { file -> + FontMetadata( + key = file.nameWithoutExtension.replace('-', '_').lowercase(), + filePath = file, + ) + } + } + + override fun generateProperty(metadata: FontMetadata): PropertySpec.Builder { + return PropertySpec.builder(metadata.key, CodeConst.fontResourceName) + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/JsFontResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/JsFontResourceGenerator.kt new file mode 100644 index 000000000..0f8dcdb60 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/JsFontResourceGenerator.kt @@ -0,0 +1,89 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.resources.font + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.FunSpec +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.metadata.resource.FontMetadata +import dev.icerock.gradle.utils.flatName +import java.io.File + +internal class JsFontResourceGenerator( + resourcesPackageName: String, + private val resourcesGenerationDir: File +) : PlatformResourceGenerator { + private val flattenClassPackage: String = resourcesPackageName.flatName + private val cssDeclarationsFileName: String = "$flattenClassPackage-generated-declarations.css" + + override fun imports(): List = emptyList() + + override fun generateInitializer(metadata: FontMetadata): CodeBlock { + val requireDeclaration = """require("$FONTS_DIR/${metadata.filePath.name}")""" + return CodeBlock.of( + "FontResource(fileUrl = js(%S) as String, fontFamily = %S)", + requireDeclaration, + metadata.key + ) + } + + override fun generateResourceFiles(data: List) { + val fontsDir = File(resourcesGenerationDir, FONTS_DIR) + fontsDir.mkdirs() + + data.map { it.filePath }.forEach { file -> + file.copyTo(File(fontsDir, file.name)) + } + + val cssDeclarationsFile = File(fontsDir, cssDeclarationsFileName) + + val declarations: String = data + .joinToString(separator = "\n") { (family, file) -> + // language=css + """ + @font-face { + font-family: "$family"; + src: url("${file.name}"); + } + """.trimIndent() + } + + cssDeclarationsFile.writeText(declarations) + } + + override fun generateAfterProperties( + builder: TypeSpec.Builder, + metadata: List + ) { + val languageKeysList: String = metadata.joinToString { it.key } + + val valuesFun: FunSpec = FunSpec.builder("values") + .addModifiers(KModifier.OVERRIDE) + .addStatement("return listOf($languageKeysList)") + .returns( + ClassName("kotlin.collections", "List") + .parameterizedBy(CodeConst.fontResourceName) + ) + .build() + + builder.addFunction(valuesFun) + + val addFontsFun: FunSpec = FunSpec.builder("addFontsToPage") + .addCode( + "js(%S)", + """require("$FONTS_DIR/${cssDeclarationsFileName}")""" + ).build() + builder.addFunction(addFontsFun) + } + + private companion object { + const val FONTS_DIR = "fonts" + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/JvmFontResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/JvmFontResourceGenerator.kt new file mode 100644 index 000000000..1ddd98492 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/JvmFontResourceGenerator.kt @@ -0,0 +1,59 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.resources.font + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.PropertySpec +import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.metadata.resource.FontMetadata +import java.io.File + +internal class JvmFontResourceGenerator( + private val className: String, + private val resourcesGenerationDir: File +) : PlatformResourceGenerator { + override fun imports(): List = emptyList() + + override fun generateInitializer(metadata: FontMetadata): CodeBlock { + return CodeBlock.of( + "FontResource(resourcesClassLoader = %L, filePath = %S)", + CodeConst.Jvm.resourcesClassLoaderPropertyName, + "$FONTS_DIR/${metadata.filePath.name}" + ) + } + + override fun generateResourceFiles(data: List) { + val fontsDir = File(resourcesGenerationDir, FONTS_DIR) + fontsDir.mkdirs() + + data.map { it.filePath }.forEach { file -> + file.copyTo(File(fontsDir, file.name)) + } + } + + override fun generateBeforeProperties( + builder: TypeSpec.Builder, + metadata: List + ) { + // FIXME duplication + val classLoaderProperty: PropertySpec = PropertySpec.builder( + CodeConst.Jvm.resourcesClassLoaderPropertyName, + CodeConst.Jvm.classLoaderName, + KModifier.OVERRIDE + ) + .initializer(CodeBlock.of(className + "." + CodeConst.Jvm.resourcesClassLoaderPropertyName)) + .build() + + builder.addProperty(classLoaderProperty) + } + + private companion object { + const val FONTS_DIR = "fonts" + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/NOPFontResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/NOPFontResourceGenerator.kt new file mode 100644 index 000000000..ca74b8894 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/NOPFontResourceGenerator.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.resources.font + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.metadata.resource.FontMetadata + +internal class NOPFontResourceGenerator : PlatformResourceGenerator { + override fun imports(): List { + TODO("Not yet implemented") + } + + override fun generateResourceFiles(data: List) { + TODO("Not yet implemented") + } + + override fun generateInitializer(metadata: FontMetadata): CodeBlock { + TODO("Not yet implemented") + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/StringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/StringResourceGenerator.kt index d77bf828a..84bb2ed77 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/StringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/StringResourceGenerator.kt @@ -5,9 +5,9 @@ package dev.icerock.gradle.generator.resources.string import com.squareup.kotlinpoet.PropertySpec -import dev.icerock.gradle.generator.exceptions.EqualStringKeysException import dev.icerock.gradle.generator.CodeConst import dev.icerock.gradle.generator.ResourceGenerator +import dev.icerock.gradle.generator.exceptions.EqualStringKeysException import dev.icerock.gradle.generator.localization.LanguageType import dev.icerock.gradle.metadata.resource.StringMetadata import dev.icerock.gradle.utils.removeLineWraps diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt index 28332992e..3d16ffafa 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt @@ -78,16 +78,10 @@ internal data class ImageMetadata( @Serializable internal data class FontMetadata( override val key: String, - val values: List + val filePath: File ) : ResourceMetadata { - @Serializable - data class FontFamilyItem( - val family: String, - val filePath: File - ) - override fun contentHash(): String = values.map { it.filePath.calculateResourcesHash() } - .calculateHash() + override fun contentHash(): String = filePath.calculateResourcesHash() } @Serializable diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/FontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/FontsGenerator.kt deleted file mode 100644 index bc5042a40..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/FontsGenerator.kt +++ /dev/null @@ -1,300 +0,0 @@ -///* -// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator -// -//import com.squareup.kotlinpoet.ClassName -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import com.squareup.kotlinpoet.PropertySpec -//import com.squareup.kotlinpoet.TypeSpec -//import dev.icerock.gradle.generator.android.AndroidFontsGenerator -//import dev.icerock.gradle.generator.apple.AppleFontsGenerator -//import dev.icerock.gradle.generator.common.CommonFontsGenerator -//import dev.icerock.gradle.generator.js.JsFontsGenerator -//import dev.icerock.gradle.generator.jvm.JvmFontsGenerator -//import dev.icerock.gradle.metadata.getActualInterfaces -//import dev.icerock.gradle.metadata.model.GeneratedObject -//import dev.icerock.gradle.metadata.model.GeneratedObjectModifier -//import dev.icerock.gradle.metadata.model.GeneratedProperty -//import dev.icerock.gradle.metadata.model.GeneratorType -//import dev.icerock.gradle.metadata.objectsWithProperties -//import dev.icerock.gradle.utils.decapitalize -//import kotlinx.serialization.json.Json -//import kotlinx.serialization.json.JsonObject -//import kotlinx.serialization.json.JsonPrimitive -//import kotlinx.serialization.json.decodeFromJsonElement -//import org.gradle.api.Project -//import org.gradle.api.file.FileTree -//import java.io.File -// -//abstract class FontsGenerator( -// private val resourcesFileTree: FileTree, -//) : MRGenerator.Generator { -// -// override val inputFiles: Iterable -// get() = resourcesFileTree.matching { -// it.include("fonts/**.ttf", "fonts/**.otf") -// } -// override val resourceClassName = ClassName("dev.icerock.moko.resources", "FontResource") -// override val mrObjectName: String = "fonts" -// -// override val type: GeneratorType = GeneratorType.Fonts -// -// override fun generateObject( -// project: Project, -// inputMetadata: List, -// outputMetadata: GeneratedObject, -// assetsGenerationDir: File, -// resourcesGenerationDir: File, -// objectBuilder: TypeSpec.Builder -// ): MRGenerator.GenerationResult? { -// val previousFontFiles: List = getPreviousFontFiles( -// inputMetadata = inputMetadata, -// targetObject = outputMetadata -// ) -// -// val fontFiles: List = if ( -// outputMetadata.isActualObject || outputMetadata.isTargetObject -// ) { -// emptyList() -// } else { -// inputFiles.getFontFiles() -// } -// -// // Sum of all fonts files and filter his on unical fonts -// val allFontFiles: List = (previousFontFiles + fontFiles).distinctBy { it.key } -// -// beforeGenerateResources(objectBuilder, allFontFiles) -// -// val typeSpec: MRGenerator.GenerationResult = createTypeSpec( -// inputMetadata = inputMetadata, -// outputMetadata = outputMetadata, -// filesSpec = allFontFiles.sortedBy { it.key }, -// objectBuilder = objectBuilder -// ) ?: return null -// -// generateResources(resourcesGenerationDir, allFontFiles) -// -// return typeSpec -// } -// -// private fun getPreviousFontFiles( -// inputMetadata: List, -// targetObject: GeneratedObject, -// ): List { -// if (!targetObject.isObject || !targetObject.isActual) return emptyList() -// -// val json = Json -// val objectsWithProperties: List = inputMetadata.objectsWithProperties( -// targetObject = targetObject -// ) -// -// val fontFiles: MutableList = mutableListOf() -// -// objectsWithProperties.forEach { generatedObject -> -// generatedObject.properties.forEach { property -> -// val data = json.decodeFromJsonElement>(property.data) -// -// data.forEach { -// fontFiles.add(File(it.value.content)) -// } -// } -// } -// -// return fontFiles.getFontFiles() -// } -// -// private fun Iterable.getFontFiles(): List { -// return this.map { -// FontFile( -// key = it.nameWithoutExtension, -// file = it -// ) -// } -// } -// -// /* -// @param keys: names of files like anastasia-regular.ttf -// */ -// private fun createTypeSpec( -// inputMetadata: List, -// outputMetadata: GeneratedObject, -// filesSpec: List, -// objectBuilder: TypeSpec.Builder, -// ): MRGenerator.GenerationResult? { -// if (outputMetadata.isActual) { -// objectBuilder.addModifiers(KModifier.ACTUAL) -// } -// -// if (outputMetadata.isActualObject || outputMetadata.isTargetObject) { -// extendObjectBodyAtStart(objectBuilder) -// } -// -// /* -// * 1. Group fileNames by family name (split('-').first()) -// * 2. Generate subtype for each family `classBuilder.addType(...)` -// * 3. Generate properties in family subtype for each font style -// * */ -// -// val familyGroups: Map> = filesSpec.groupBy { fileSpec -> -// fileSpec.file.nameWithoutExtension.substringBefore("-") -// } -// -// val generatedProperties = mutableListOf() -// -// familyGroups.forEach { group -> -// // Make pairs: "style name" - "font file" -// val stylePairs: List> = group -// .value -// .map { it.file.nameWithoutExtension.substringAfter("-") to it } -// -// val propertyName: String = group.key -// val property: TypeSpec.Builder = TypeSpec.objectBuilder(propertyName) -// -// var generatedProperty = GeneratedProperty( -// modifier = addObjectActualOverrideModifier( -// propertyName = propertyName, -// property = property, -// inputMetadata = inputMetadata, -// targetObject = outputMetadata -// ), -// name = propertyName, -// data = JsonPrimitive("") -// ) -// -// val fontsProperty: MutableMap = mutableMapOf() -// -// stylePairs.map { -// Pair(it.first, it.second.file) -// }.forEach { (styleName, file) -> -// val styleProperty: PropertySpec.Builder = PropertySpec -// .builder(styleName.decapitalize(), resourceClassName) -// -// if (generatedProperty.isActualProperty) { -// styleProperty.addModifiers(KModifier.ACTUAL) -// } -// -// if (outputMetadata.isActualObject || outputMetadata.isTargetObject) { -// getPropertyInitializer(file)?.let { codeBlock -> -// styleProperty.initializer(codeBlock) -// } -// } -// -// fontsProperty[styleName] = JsonPrimitive(file.path) -// -// property.addProperty(styleProperty.build()) -// generatedProperty = generatedProperty.copy( -// data = JsonObject(fontsProperty) -// ) -// } -// -// objectBuilder.addType(property.build()) -// generatedProperties.add(generatedProperty) -// } -// -// extendObjectBodyAtEnd(objectBuilder) -// -// if (generatedProperties.isEmpty()) return null -// -// return MRGenerator.GenerationResult( -// typeSpec = objectBuilder.build(), -// metadata = outputMetadata.copy(properties = generatedProperties) -// ) -// } -// -// private fun addObjectActualOverrideModifier( -// propertyName: String, -// property: TypeSpec.Builder, -// inputMetadata: List, -// targetObject: GeneratedObject, -// ): GeneratedObjectModifier { -// // Read actual interfaces of target object generator type -// val actualInterfaces: List = inputMetadata.getActualInterfaces( -// generatorType = targetObject.generatorType -// ) -// -// var containsInActualInterfaces = false -// -// // Search property in actual interfaces -// actualInterfaces.forEach { genInterface -> -// val hasInInterface = genInterface.properties.any { -// it.name == propertyName -// } -// -// if (hasInInterface) { -// containsInActualInterfaces = true -// } -// } -// -// return if (targetObject.isObject) { -// if (containsInActualInterfaces) { -// property.addModifiers(KModifier.OVERRIDE) -// GeneratedObjectModifier.Override -// } else { -// when (targetObject.modifier) { -// GeneratedObjectModifier.Actual -> { -// property.addModifiers(KModifier.ACTUAL) -// GeneratedObjectModifier.Actual -// } -// -// else -> { -// GeneratedObjectModifier.None -// } -// } -// } -// } else { -// GeneratedObjectModifier.None -// } -// -// } -// -// override fun getImports(): List = emptyList() -// -// protected open fun generateResources( -// resourcesGenerationDir: File, -// files: List, -// ) { -// } -// -// abstract fun getClassModifiers(): Array -// -// abstract fun getPropertyModifiers(): Array -// -// abstract fun getPropertyInitializer(fontFile: File): CodeBlock? -// -// open fun beforeGenerateResources(objectBuilder: TypeSpec.Builder, files: List) {} -// -// data class FontFile( -// val key: String, -// val file: File, -// ) -// -// class Feature( -// private val settings: MRGenerator.Settings, -// ) : ResourceGeneratorFeature { -// override fun createCommonGenerator(): FontsGenerator = CommonFontsGenerator( -// ownInputFileTree = settings.ownResourcesFileTree, -// ) -// -// override fun createAppleGenerator(): FontsGenerator = AppleFontsGenerator( -// ownInputFileTree = settings.ownResourcesFileTree, -// ) -// -// override fun createAndroidGenerator(): FontsGenerator = AndroidFontsGenerator( -// ownInputFileTree = settings.ownResourcesFileTree, -// androidRClassPackage = settings.androidRClassPackage -// ) -// -// override fun createJsGenerator(): FontsGenerator = JsFontsGenerator( -// ownInputFileTree = settings.ownResourcesFileTree, -// mrClassPackage = settings.packageName -// ) -// -// override fun createJvmGenerator(): FontsGenerator = JvmFontsGenerator( -// ownInputFileTree = settings.ownResourcesFileTree, -// settings = settings -// ) -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidFontsGenerator.kt deleted file mode 100644 index ce336393c..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidFontsGenerator.kt +++ /dev/null @@ -1,50 +0,0 @@ -///* -// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.android -// -//import com.squareup.kotlinpoet.ClassName -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import dev.icerock.gradle.generator.FontsGenerator -//import dev.icerock.gradle.generator.NOPObjectBodyExtendable -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import org.gradle.api.file.FileTree -//import org.gradle.api.provider.Provider -//import java.io.File -//import java.util.Locale -// -//class AndroidFontsGenerator( -// ownInputFileTree: FileTree, -// private val androidRClassPackage: Provider, -//) : FontsGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { -// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyInitializer(fontFile: File): CodeBlock { -// return CodeBlock.of("FontResource(fontResourceId = R.font.%L)", keyToResourceId(fontFile.nameWithoutExtension)) -// } -// -// override fun getImports(): List = listOf( -// ClassName(androidRClassPackage.get(), "R") -// ) -// -// override fun generateResources( -// resourcesGenerationDir: File, -// files: List -// ) { -// val fontResDir = File(resourcesGenerationDir, "font") -// fontResDir.mkdirs() -// -// files.forEach { (key, file) -> -// val fileName = keyToResourceId(key) + "." + file.extension -// file.copyTo(File(fontResDir, fileName)) -// } -// } -// -// private fun keyToResourceId(key: String): String { -// return key.replace("-", "_").lowercase(Locale.ROOT) -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleFontsGenerator.kt deleted file mode 100644 index 52a261b39..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleFontsGenerator.kt +++ /dev/null @@ -1,37 +0,0 @@ -///* -// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.apple -// -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import dev.icerock.gradle.generator.FontsGenerator -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import org.gradle.api.file.FileTree -//import java.io.File -// -//class AppleFontsGenerator( -// ownInputFileTree: FileTree, -//) : FontsGenerator(ownInputFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { -// -// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyInitializer(fontFile: File): CodeBlock { -// return CodeBlock.of( -// "FontResource(fontName = %S, bundle = ${AppleMRGenerator.BUNDLE_PROPERTY_NAME})", -// fontFile.name -// ) -// } -// -// override fun generateResources( -// resourcesGenerationDir: File, -// files: List -// ) { -// files.forEach { (_, file) -> -// file.copyTo(File(resourcesGenerationDir, file.name)) -// } -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsFontsGenerator.kt deleted file mode 100644 index 8c5c99523..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsFontsGenerator.kt +++ /dev/null @@ -1,100 +0,0 @@ -///* -// * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.js -// -//import com.squareup.kotlinpoet.ClassName -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.FunSpec -//import com.squareup.kotlinpoet.KModifier -//import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -//import com.squareup.kotlinpoet.TypeSpec -//import dev.icerock.gradle.generator.FontsGenerator -//import dev.icerock.gradle.generator.NOPObjectBodyExtendable -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import dev.icerock.gradle.utils.flatName -//import org.gradle.api.file.FileTree -//import org.gradle.api.provider.Provider -//import org.gradle.kotlin.dsl.provideDelegate -//import java.io.File -// -//class JsFontsGenerator( -// ownInputFileTree: FileTree, -// mrClassPackage: String, -//) : FontsGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { -// -// private val flattenPackage: String = mrClassPackage.flatName -// private val cssDeclarationsFileName: String = "$flattenPackage-generated-declarations.css" -// -// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// @Suppress("StringTemplate") -// override fun getPropertyInitializer(fontFile: File): CodeBlock { -// val requireDeclaration = """require("$FONTS_DIR/${fontFile.name}")""" -// return CodeBlock.of( -// "FontResource(fileUrl = js(%S) as String, fontFamily = %S)", -// requireDeclaration, -// fontFile.nameWithoutExtension -// ) -// } -// -// override fun beforeGenerateResources(objectBuilder: TypeSpec.Builder, files: List) { -// val languageKeysList = files.joinToString { -// val (style, family) = it.key.split("-", limit = 2) -// val familyName = family.replaceFirstChar(Char::lowercase) -// return@joinToString "$style.$familyName" -// } -// -// objectBuilder.addFunction( -// FunSpec.builder("values") -// .addModifiers(KModifier.OVERRIDE) -// .addStatement("return listOf($languageKeysList)") -// .returns( -// ClassName("kotlin.collections", "List") -// .parameterizedBy(resourceClassName) -// ) -// .build() -// ) -// -// if (files.isEmpty()) return -// -// objectBuilder.addFunction( -// FunSpec.builder("addFontsToPage") -// .addCode( -// "js(%S)", -// """require("$FONTS_DIR/${cssDeclarationsFileName}")""" -// ).build() -// ) -// } -// -// override fun generateResources(resourcesGenerationDir: File, files: List) { -// val fontsDir = File(resourcesGenerationDir, FONTS_DIR).apply { mkdirs() } -// -// files.forEach { (_, file) -> -// file.copyTo(File(fontsDir, file.name)) -// } -// -// val cssDeclarationsFile = File(fontsDir, cssDeclarationsFileName) -// -// val declarations = files -// .takeIf(List<*>::isNotEmpty) -// ?.joinToString(separator = "\n") { (family, file) -> -// // language=css -// """ -// @font-face { -// font-family: "$family"; -// src: url("${file.name}"); -// } -// """.trimIndent() -// } -// -// if (declarations != null) cssDeclarationsFile.writeText(declarations) -// } -// -// companion object { -// const val FONTS_DIR = "fonts" -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmFontsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmFontsGenerator.kt deleted file mode 100644 index 0b96b4898..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmFontsGenerator.kt +++ /dev/null @@ -1,40 +0,0 @@ -///* -// * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.jvm -// -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import dev.icerock.gradle.generator.FontsGenerator -//import dev.icerock.gradle.generator.MRGenerator -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import org.gradle.api.file.FileTree -//import java.io.File -// -//class JvmFontsGenerator( -// ownInputFileTree: FileTree, -// settings: MRGenerator.Settings -//) : FontsGenerator(ownInputFileTree), -// ObjectBodyExtendable by ClassLoaderExtender(settings.className) { -// -// override fun getClassModifiers() = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyModifiers() = arrayOf(KModifier.ACTUAL) -// override fun getPropertyInitializer(fontFile: File): CodeBlock? = -// CodeBlock.of( -// "FontResource(resourcesClassLoader = resourcesClassLoader, filePath = %S)", -// "$FONTS_DIR/${fontFile.name}" -// ) -// -// override fun generateResources(resourcesGenerationDir: File, files: List) { -// val fontsDir = File(resourcesGenerationDir, FONTS_DIR).apply { mkdirs() } -// files.forEach { (_, file) -> -// file.copyTo(File(fontsDir, file.name)) -// } -// } -// -// companion object { -// private const val FONTS_DIR = "fonts" -// } -//} 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 4d9bbc669..a17809291 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 @@ -20,6 +20,12 @@ import dev.icerock.gradle.generator.resources.color.ColorResourceGenerator import dev.icerock.gradle.generator.resources.color.JsColorResourceGenerator import dev.icerock.gradle.generator.resources.color.JvmColorResourceGenerator import dev.icerock.gradle.generator.resources.color.NOPColorResourceGenerator +import dev.icerock.gradle.generator.resources.font.AndroidFontResourceGenerator +import dev.icerock.gradle.generator.resources.font.AppleFontResourceGenerator +import dev.icerock.gradle.generator.resources.font.FontResourceGenerator +import dev.icerock.gradle.generator.resources.font.JsFontResourceGenerator +import dev.icerock.gradle.generator.resources.font.JvmFontResourceGenerator +import dev.icerock.gradle.generator.resources.font.NOPFontResourceGenerator import dev.icerock.gradle.generator.resources.image.AndroidImageResourceGenerator import dev.icerock.gradle.generator.resources.image.AppleImageResourceGenerator import dev.icerock.gradle.generator.resources.image.ImageResourceGenerator @@ -42,6 +48,7 @@ import dev.icerock.gradle.metadata.container.ContainerMetadata import dev.icerock.gradle.metadata.container.ObjectMetadata import dev.icerock.gradle.metadata.container.ResourceType import dev.icerock.gradle.metadata.resource.ColorMetadata +import dev.icerock.gradle.metadata.resource.FontMetadata import dev.icerock.gradle.metadata.resource.ImageMetadata import dev.icerock.gradle.metadata.resource.PluralMetadata import dev.icerock.gradle.metadata.resource.StringMetadata @@ -109,6 +116,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { @get:Input abstract val resourcesVisibility: Property + @get:Optional @get:Input abstract val androidRClassPackage: Property @@ -194,7 +202,8 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { createStringGenerator(), createPluralsGenerator(), createImagesGenerator(), - createColorsGenerator() + createColorsGenerator(), + createFontsGenerator() ), resourcesPackageName = resourcesPackageName.get(), resourcesClassName = resourcesClassName.get(), @@ -282,6 +291,52 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { ) } + private fun createFontsGenerator(): ResourceTypeGenerator { + return ResourceTypeGenerator( + generationPackage = resourcesPackageName.get(), + resourceClass = CodeConst.fontResourceName, + resourceType = ResourceType.FONTS, + metadataClass = FontMetadata::class, + visibilityModifier = resourcesVisibility.get().toModifier(), + generator = FontResourceGenerator(), + platformResourceGenerator = createPlatformFontGenerator(), + filter = { include("fonts/**.ttf", "fonts/**.otf") } + ) + } + + private fun createPlatformFontGenerator(): PlatformResourceGenerator { + val resourcesGenerationDir: File = outputResourcesDir.get().asFile + return createByPlatform( + kotlinPlatformType = kotlinPlatformType, + konanTarget = ::kotlinKonanTarget, + // TODO find way to remove this NOP + createCommon = { NOPFontResourceGenerator() }, + createAndroid = { + AndroidFontResourceGenerator( + androidRClassPackage = androidRClassPackage.get(), + resourcesGenerationDir = resourcesGenerationDir + ) + }, + createApple = { + AppleFontResourceGenerator( + resourcesGenerationDir = resourcesGenerationDir + ) + }, + createJvm = { + JvmFontResourceGenerator( + className = resourcesClassName.get(), + resourcesGenerationDir = resourcesGenerationDir + ) + }, + createJs = { + JsFontResourceGenerator( + resourcesPackageName = resourcesPackageName.get(), + resourcesGenerationDir = resourcesGenerationDir + ) + } + ) + } + private fun createPlatformColorGenerator(): PlatformResourceGenerator { val resourcesGenerationDir: File = outputResourcesDir.get().asFile val assetsGenerationDir: File = outputAssetsDir.get().asFile diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProjectExt.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProjectExt.kt index 67b64bb12..60334413f 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProjectExt.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProjectExt.kt @@ -9,7 +9,7 @@ import com.android.build.gradle.api.AndroidSourceSet import org.gradle.api.Project import org.gradle.api.provider.Provider import org.gradle.api.tasks.SourceSet -import org.gradle.kotlin.dsl.getByType +import org.gradle.kotlin.dsl.findByType import org.w3c.dom.Document import org.w3c.dom.Node import org.w3c.dom.NodeList @@ -20,7 +20,8 @@ import javax.xml.parsers.DocumentBuilderFactory internal fun Project.getAndroidRClassPackage(): Provider { return provider { - val androidExt: BaseExtension = project.extensions.getByType() + val androidExt: BaseExtension = project.extensions.findByType() + ?: return@provider null androidExt.namespace ?: getAndroidPackage(androidExt.mainSourceSet.manifest.srcFile) } } diff --git a/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt b/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt index 3df22545e..66f653885 100644 --- a/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt +++ b/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt @@ -70,7 +70,7 @@ internal fun App() { .padding(vertical = 8.dp), text = stringResource(MR.plurals.chars_count, counter, counter), color = colorResource(MR.colors.textColor), -// fontFamily = fontFamilyResource(MR.fonts.cormorant.italic) + fontFamily = fontFamilyResource(MR.fonts.cormorant_italic) ) Button(onClick = { text = "Hello, ${getPlatformName()}" }) { From 8d3d3a384dba5a36ccab0cd2c602a12fc8f9c7e8 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Wed, 10 Jan 2024 18:21:14 +0700 Subject: [PATCH 098/352] #535 remove duplicates --- ...ceGenerator.kt => NOPResourceGenerator.kt} | 10 ++++---- .../color/NOPColorResourceGenerator.kt | 24 ------------------- .../image/NOPImageResourceGenerator.kt | 24 ------------------- .../plural/NOPPluralResourceGenerator.kt | 24 ------------------- .../string/NOPStringResourceGenerator.kt | 24 ------------------- .../GenerateMultiplatformResourcesTask.kt | 16 +++++-------- 6 files changed, 11 insertions(+), 111 deletions(-) rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/{font/NOPFontResourceGenerator.kt => NOPResourceGenerator.kt} (56%) delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/NOPColorResourceGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/NOPImageResourceGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/NOPPluralResourceGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/NOPStringResourceGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/NOPFontResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/NOPResourceGenerator.kt similarity index 56% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/NOPFontResourceGenerator.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/NOPResourceGenerator.kt index ca74b8894..77f23bcb1 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/NOPFontResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/NOPResourceGenerator.kt @@ -2,23 +2,23 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.resources.font +package dev.icerock.gradle.generator.resources import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock import dev.icerock.gradle.generator.PlatformResourceGenerator -import dev.icerock.gradle.metadata.resource.FontMetadata +import dev.icerock.gradle.metadata.resource.ResourceMetadata -internal class NOPFontResourceGenerator : PlatformResourceGenerator { +internal class NOPResourceGenerator : PlatformResourceGenerator { override fun imports(): List { TODO("Not yet implemented") } - override fun generateResourceFiles(data: List) { + override fun generateResourceFiles(data: List) { TODO("Not yet implemented") } - override fun generateInitializer(metadata: FontMetadata): CodeBlock { + override fun generateInitializer(metadata: T): CodeBlock { TODO("Not yet implemented") } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/NOPColorResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/NOPColorResourceGenerator.kt deleted file mode 100644 index 9da692147..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/NOPColorResourceGenerator.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.resources.color - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import dev.icerock.gradle.generator.PlatformResourceGenerator -import dev.icerock.gradle.metadata.resource.ColorMetadata - -internal class NOPColorResourceGenerator : PlatformResourceGenerator { - override fun imports(): List { - TODO("Not yet implemented") - } - - override fun generateResourceFiles(data: List) { - TODO("Not yet implemented") - } - - override fun generateInitializer(metadata: ColorMetadata): CodeBlock { - TODO("Not yet implemented") - } -} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/NOPImageResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/NOPImageResourceGenerator.kt deleted file mode 100644 index bbefe7957..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/NOPImageResourceGenerator.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.resources.image - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import dev.icerock.gradle.generator.PlatformResourceGenerator -import dev.icerock.gradle.metadata.resource.ImageMetadata - -internal class NOPImageResourceGenerator() : PlatformResourceGenerator { - override fun imports(): List { - TODO("Not yet implemented") - } - - override fun generateResourceFiles(data: List) { - TODO("Not yet implemented") - } - - override fun generateInitializer(metadata: ImageMetadata): CodeBlock { - TODO("Not yet implemented") - } -} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/NOPPluralResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/NOPPluralResourceGenerator.kt deleted file mode 100644 index 6dffb2cbb..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/NOPPluralResourceGenerator.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.resources.plural - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import dev.icerock.gradle.generator.PlatformResourceGenerator -import dev.icerock.gradle.metadata.resource.PluralMetadata - -internal class NOPPluralResourceGenerator : PlatformResourceGenerator { - override fun imports(): List { - TODO("Not yet implemented") - } - - override fun generateResourceFiles(data: List) { - TODO("Not yet implemented") - } - - override fun generateInitializer(metadata: PluralMetadata): CodeBlock { - TODO("Not yet implemented") - } -} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/NOPStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/NOPStringResourceGenerator.kt deleted file mode 100644 index 02c1c5d52..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/NOPStringResourceGenerator.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.generator.resources.string - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import dev.icerock.gradle.generator.PlatformResourceGenerator -import dev.icerock.gradle.metadata.resource.StringMetadata - -internal class NOPStringResourceGenerator : PlatformResourceGenerator { - override fun imports(): List { - TODO("Not yet implemented") - } - - override fun generateResourceFiles(data: List) { - TODO("Not yet implemented") - } - - override fun generateInitializer(metadata: StringMetadata): CodeBlock { - TODO("Not yet implemented") - } -} 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 a17809291..ad0f1b5f9 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 @@ -14,35 +14,31 @@ import dev.icerock.gradle.generator.ResourcesGenerator import dev.icerock.gradle.generator.container.AppleContainerGenerator import dev.icerock.gradle.generator.container.JvmContainerGenerator import dev.icerock.gradle.generator.container.NOPContainerGenerator +import dev.icerock.gradle.generator.resources.NOPResourceGenerator import dev.icerock.gradle.generator.resources.color.AndroidColorResourceGenerator import dev.icerock.gradle.generator.resources.color.AppleColorResourceGenerator import dev.icerock.gradle.generator.resources.color.ColorResourceGenerator import dev.icerock.gradle.generator.resources.color.JsColorResourceGenerator import dev.icerock.gradle.generator.resources.color.JvmColorResourceGenerator -import dev.icerock.gradle.generator.resources.color.NOPColorResourceGenerator import dev.icerock.gradle.generator.resources.font.AndroidFontResourceGenerator import dev.icerock.gradle.generator.resources.font.AppleFontResourceGenerator import dev.icerock.gradle.generator.resources.font.FontResourceGenerator import dev.icerock.gradle.generator.resources.font.JsFontResourceGenerator import dev.icerock.gradle.generator.resources.font.JvmFontResourceGenerator -import dev.icerock.gradle.generator.resources.font.NOPFontResourceGenerator import dev.icerock.gradle.generator.resources.image.AndroidImageResourceGenerator import dev.icerock.gradle.generator.resources.image.AppleImageResourceGenerator import dev.icerock.gradle.generator.resources.image.ImageResourceGenerator import dev.icerock.gradle.generator.resources.image.JsImageResourceGenerator import dev.icerock.gradle.generator.resources.image.JvmImageResourceGenerator -import dev.icerock.gradle.generator.resources.image.NOPImageResourceGenerator import dev.icerock.gradle.generator.resources.plural.AndroidPluralResourceGenerator import dev.icerock.gradle.generator.resources.plural.ApplePluralResourceGenerator import dev.icerock.gradle.generator.resources.plural.JsPluralResourceGenerator import dev.icerock.gradle.generator.resources.plural.JvmPluralResourceGenerator -import dev.icerock.gradle.generator.resources.plural.NOPPluralResourceGenerator import dev.icerock.gradle.generator.resources.plural.PluralResourceGenerator import dev.icerock.gradle.generator.resources.string.AndroidStringResourceGenerator import dev.icerock.gradle.generator.resources.string.AppleStringResourceGenerator import dev.icerock.gradle.generator.resources.string.JsStringResourceGenerator import dev.icerock.gradle.generator.resources.string.JvmStringResourceGenerator -import dev.icerock.gradle.generator.resources.string.NOPStringResourceGenerator import dev.icerock.gradle.generator.resources.string.StringResourceGenerator import dev.icerock.gradle.metadata.container.ContainerMetadata import dev.icerock.gradle.metadata.container.ObjectMetadata @@ -310,7 +306,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { kotlinPlatformType = kotlinPlatformType, konanTarget = ::kotlinKonanTarget, // TODO find way to remove this NOP - createCommon = { NOPFontResourceGenerator() }, + createCommon = { NOPResourceGenerator() }, createAndroid = { AndroidFontResourceGenerator( androidRClassPackage = androidRClassPackage.get(), @@ -344,7 +340,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { kotlinPlatformType = kotlinPlatformType, konanTarget = ::kotlinKonanTarget, // TODO find way to remove this NOP - createCommon = { NOPColorResourceGenerator() }, + createCommon = { NOPResourceGenerator() }, createAndroid = { AndroidColorResourceGenerator( androidRClassPackage = androidRClassPackage.get(), @@ -374,7 +370,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { kotlinPlatformType = kotlinPlatformType, konanTarget = ::kotlinKonanTarget, // TODO find way to remove this NOP - createCommon = { NOPImageResourceGenerator() }, + createCommon = { NOPResourceGenerator() }, createAndroid = { AndroidImageResourceGenerator( androidRClassPackage = androidRClassPackage.get(), @@ -407,7 +403,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { kotlinPlatformType = kotlinPlatformType, konanTarget = ::kotlinKonanTarget, // TODO find way to remove this NOP - createCommon = { NOPPluralResourceGenerator() }, + createCommon = { NOPResourceGenerator() }, createAndroid = { AndroidPluralResourceGenerator( androidRClassPackage = androidRClassPackage.get(), @@ -442,7 +438,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { kotlinPlatformType = kotlinPlatformType, konanTarget = ::kotlinKonanTarget, // TODO find way to remove this NOP - createCommon = { NOPStringResourceGenerator() }, + createCommon = { NOPResourceGenerator() }, createAndroid = { AndroidStringResourceGenerator( androidRClassPackage = androidRClassPackage.get(), From c11f2a475133869ec3c728756f18c10d0e7fd85e Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Wed, 10 Jan 2024 18:56:29 +0700 Subject: [PATCH 099/352] #535 files generator migration --- .../apple/PackAppleResourcesToKLibAction.kt | 20 +- .../dev/icerock/gradle/generator/CodeConst.kt | 1 + .../file/AndroidFileResourceGenerator.kt | 37 +++ .../file/AppleFileResourceGenerator.kt | 45 ++++ .../resources/file/FileResourceGenerator.kt | 32 +++ .../resources/file/JsFileResourceGenerator.kt | 63 +++++ .../file/JvmFileResourceGenerator.kt | 60 +++++ .../icerock/gradle/oldgen/FilesGenerator.kt | 222 ------------------ .../oldgen/android/AndroidFilesGenerator.kt | 47 ---- .../oldgen/apple/AppleFilesGenerator.kt | 39 --- .../gradle/oldgen/js/JsFilesGenerator.kt | 62 ----- .../gradle/oldgen/jvm/JvmFilesGenerator.kt | 43 ---- .../GenerateMultiplatformResourcesTask.kt | 54 ++++- .../shared/src/commonMain/kotlin/App.kt | 14 +- 14 files changed, 310 insertions(+), 429 deletions(-) create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/AndroidFileResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/AppleFileResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/FileResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/JsFileResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/JvmFileResourceGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/FilesGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidFilesGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleFilesGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsFilesGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmFilesGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/PackAppleResourcesToKLibAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/PackAppleResourcesToKLibAction.kt index e3d95ab21..1e6134da6 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/PackAppleResourcesToKLibAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/PackAppleResourcesToKLibAction.kt @@ -64,14 +64,18 @@ internal class PackAppleResourcesToKLibAction( loadableBundle.write() - resourcesGenerationDir.copyRecursively( - loadableBundle.resourcesDir, - overwrite = true - ) - assetsDirectory.copyRecursively( - loadableBundle.resourcesDir, - overwrite = true - ) + if (resourcesGenerationDir.exists()) { + resourcesGenerationDir.copyRecursively( + loadableBundle.resourcesDir, + overwrite = true + ) + } + if (assetsDirectory.exists()) { + assetsDirectory.copyRecursively( + loadableBundle.resourcesDir, + overwrite = true + ) + } val rawAssetsDir = File(loadableBundle.resourcesDir, CodeConst.Apple.assetsDirectoryName) if (rawAssetsDir.exists()) { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt index 5d3578f88..c50058e1c 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt @@ -13,6 +13,7 @@ internal object CodeConst { val imageResourceName = ClassName("dev.icerock.moko.resources", "ImageResource") val colorResourceName = ClassName("dev.icerock.moko.resources", "ColorResource") val fontResourceName = ClassName("dev.icerock.moko.resources", "FontResource") + val fileResourceName = ClassName("dev.icerock.moko.resources", "FileResource") val graphicsColorName = ClassName("dev.icerock.moko.graphics", "Color") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/AndroidFileResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/AndroidFileResourceGenerator.kt new file mode 100644 index 000000000..63ba9ce2c --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/AndroidFileResourceGenerator.kt @@ -0,0 +1,37 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.resources.file + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.metadata.resource.FileMetadata +import java.io.File +import java.util.Locale + +internal class AndroidFileResourceGenerator( + private val androidRClassPackage: String, + private val resourcesGenerationDir: File +) : PlatformResourceGenerator { + override fun imports(): List = listOf( + ClassName(androidRClassPackage, "R") + ) + + override fun generateInitializer(metadata: FileMetadata): CodeBlock { + return CodeBlock.of("FileResource(R.raw.%L)", keyToResourceId(metadata.key)) + } + + override fun generateResourceFiles(data: List) { + val targetDir = File(resourcesGenerationDir, "raw") + targetDir.mkdirs() + + data.forEach { metadata -> + val fileName: String = keyToResourceId(metadata.key) + "." + metadata.filePath.extension + metadata.filePath.copyTo(File(targetDir, fileName)) + } + } + + private fun keyToResourceId(key: String) = key.lowercase(Locale.ROOT) +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/AppleFileResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/AppleFileResourceGenerator.kt new file mode 100644 index 000000000..514762a32 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/AppleFileResourceGenerator.kt @@ -0,0 +1,45 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.resources.file + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.generator.addAppleContainerBundleProperty +import dev.icerock.gradle.metadata.resource.FileMetadata +import java.io.File + +internal class AppleFileResourceGenerator( + private val resourcesGenerationDir: File +) : PlatformResourceGenerator { + override fun imports(): List = emptyList() + + override fun generateInitializer(metadata: FileMetadata): CodeBlock { + return CodeBlock.of( + "FileResource(fileName = %S, extension = %S, bundle = %L)", + metadata.filePath.nameWithoutExtension, + metadata.filePath.extension, + CodeConst.Apple.containerBundlePropertyName + ) + } + + override fun generateResourceFiles(data: List) { + val targetDir = File(resourcesGenerationDir, "files") + targetDir.mkdirs() + + data.forEach { metadata -> + metadata.filePath.copyTo(File(targetDir, metadata.filePath.name)) + } + } + + override fun generateBeforeProperties( + builder: TypeSpec.Builder, + metadata: List + ) { + builder.addAppleContainerBundleProperty() + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/FileResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/FileResourceGenerator.kt new file mode 100644 index 000000000..6d14f2679 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/FileResourceGenerator.kt @@ -0,0 +1,32 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.resources.file + +import com.squareup.kotlinpoet.PropertySpec +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.ResourceGenerator +import dev.icerock.gradle.metadata.resource.FileMetadata +import java.io.File + +internal class FileResourceGenerator : ResourceGenerator { + + override fun generateMetadata(files: Set): List { + return files.map { file -> + FileMetadata( + key = processKey(file.nameWithoutExtension), + filePath = file, + ) + } + } + + override fun generateProperty(metadata: FileMetadata): PropertySpec.Builder { + return PropertySpec.builder(metadata.key, CodeConst.fileResourceName) + } + + // TODO commonize? + private fun processKey(key: String): String { + return key.replace("-", "_") + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/JsFileResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/JsFileResourceGenerator.kt new file mode 100644 index 000000000..adbee1add --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/JsFileResourceGenerator.kt @@ -0,0 +1,63 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.resources.file + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.FunSpec +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.metadata.resource.FileMetadata +import java.io.File + +internal class JsFileResourceGenerator( + private val resourcesGenerationDir: File +) : PlatformResourceGenerator { + + override fun imports(): List = emptyList() + + override fun generateInitializer(metadata: FileMetadata): CodeBlock { + val requireDeclaration = """require("$FILES_DIR/${metadata.filePath.name}")""" + return CodeBlock.of( + "FileResource(fileUrl = js(%S) as String)", + requireDeclaration + ) + } + + override fun generateResourceFiles(data: List) { + val targetDir = File(resourcesGenerationDir, FILES_DIR) + targetDir.mkdirs() + + data.map { it.filePath }.forEach { file -> + file.copyTo(File(targetDir, file.name)) + } + } + + override fun generateAfterProperties( + builder: TypeSpec.Builder, + metadata: List + ) { + // FIXME duplicate + val values: String = metadata.joinToString { it.key } + + val valuesFun: FunSpec = FunSpec.builder("values") + .addModifiers(KModifier.OVERRIDE) + .addStatement("return listOf($values)") + .returns( + ClassName("kotlin.collections", "List") + .parameterizedBy(CodeConst.fileResourceName) + ) + .build() + + builder.addFunction(valuesFun) + } + + private companion object { + const val FILES_DIR = "files" + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/JvmFileResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/JvmFileResourceGenerator.kt new file mode 100644 index 000000000..0679fa6c5 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/JvmFileResourceGenerator.kt @@ -0,0 +1,60 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.resources.file + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.PropertySpec +import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.metadata.resource.FileMetadata +import dev.icerock.gradle.metadata.resource.FontMetadata +import java.io.File + +internal class JvmFileResourceGenerator( + private val className: String, + private val resourcesGenerationDir: File +) : PlatformResourceGenerator { + override fun imports(): List = emptyList() + + override fun generateInitializer(metadata: FileMetadata): CodeBlock { + return CodeBlock.of( + "FileResource(resourcesClassLoader = %L, filePath = %S)", + CodeConst.Jvm.resourcesClassLoaderPropertyName, + "$FILES_DIR/${metadata.filePath.name}" + ) + } + + override fun generateResourceFiles(data: List) { + val fontsDir = File(resourcesGenerationDir, FILES_DIR) + fontsDir.mkdirs() + + data.map { it.filePath }.forEach { file -> + file.copyTo(File(fontsDir, file.name)) + } + } + + override fun generateBeforeProperties( + builder: TypeSpec.Builder, + metadata: List + ) { + // FIXME duplication + val classLoaderProperty: PropertySpec = PropertySpec.builder( + CodeConst.Jvm.resourcesClassLoaderPropertyName, + CodeConst.Jvm.classLoaderName, + KModifier.OVERRIDE + ) + .initializer(CodeBlock.of(className + "." + CodeConst.Jvm.resourcesClassLoaderPropertyName)) + .build() + + builder.addProperty(classLoaderProperty) + } + + private companion object { + const val FILES_DIR = "files" + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/FilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/FilesGenerator.kt deleted file mode 100644 index 0a292c9d0..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/FilesGenerator.kt +++ /dev/null @@ -1,222 +0,0 @@ -///* -// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator -// -//import com.squareup.kotlinpoet.ClassName -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import com.squareup.kotlinpoet.PropertySpec -//import com.squareup.kotlinpoet.TypeSpec -//import dev.icerock.gradle.generator.android.AndroidFilesGenerator -//import dev.icerock.gradle.generator.apple.AppleFilesGenerator -//import dev.icerock.gradle.generator.common.CommonFilesGenerator -//import dev.icerock.gradle.generator.js.JsFilesGenerator -//import dev.icerock.gradle.generator.jvm.JvmFilesGenerator -//import dev.icerock.gradle.metadata.model.GeneratedObject -//import dev.icerock.gradle.metadata.model.GeneratedObjectModifier -//import dev.icerock.gradle.metadata.model.GeneratedProperty -//import dev.icerock.gradle.metadata.model.GeneratorType -//import dev.icerock.gradle.metadata.objectsWithProperties -//import kotlinx.serialization.json.Json -//import kotlinx.serialization.json.JsonPrimitive -//import kotlinx.serialization.json.decodeFromJsonElement -//import org.gradle.api.Project -//import org.gradle.api.file.FileTree -//import java.io.File -// -//abstract class FilesGenerator( -// private val resourceFiles: FileTree, -//) : MRGenerator.Generator { -// -// override val inputFiles: Iterable -// get() = resourceFiles.matching { it.include("files/**") } -// override val resourceClassName = ClassName("dev.icerock.moko.resources", "FileResource") -// override val mrObjectName: String = "files" -// -// override val type: GeneratorType = GeneratorType.Files -// -// override fun generateObject( -// project: Project, -// inputMetadata: List, -// outputMetadata: GeneratedObject, -// assetsGenerationDir: File, -// resourcesGenerationDir: File, -// objectBuilder: TypeSpec.Builder -// ): MRGenerator.GenerationResult? { -// val previousFilesSpec: List = getPreviousFiles( -// inputMetadata = inputMetadata, -// targetObject = outputMetadata -// ) -// -// val targetFilesSpecs: List = if ( -// outputMetadata.isActualObject || outputMetadata.isTargetObject -// ) { -// emptyList() -// } else { -// inputFiles.getFileSpecList() -// } -// -// val allFilesSpecs = (previousFilesSpec + targetFilesSpecs).distinctBy { it.key } -// -// beforeGenerate(objectBuilder, allFilesSpecs) -// -// val result: MRGenerator.GenerationResult = createTypeSpec( -// inputMetadata = inputMetadata, -// targetObject = outputMetadata, -// keys = allFilesSpecs, -// objectBuilder = objectBuilder -// ) ?: return null -// -// generateResources( -// resourcesGenerationDir = resourcesGenerationDir, -// files = allFilesSpecs -// ) -// -// return result -// } -// -// private fun Iterable.getFileSpecList(): List { -// return this.map { file -> -// FileSpec( -// key = processKey(file.nameWithoutExtension), -// file = file -// ) -// }.sortedBy { it.key } -// } -// -// private fun getPreviousFiles( -// inputMetadata: List, -// targetObject: GeneratedObject, -// ): List { -// if (!targetObject.isObject || !targetObject.isActual) return emptyList() -// -// val json = Json -// val objectsWithProperties: List = inputMetadata.objectsWithProperties( -// targetObject = targetObject -// ) -// -// val files = mutableListOf() -// -// objectsWithProperties.forEach { generatedObject -> -// generatedObject.properties.forEach { property -> -// val data = json.decodeFromJsonElement(property.data) -// files.add( -// File(data.content) -// ) -// } -// } -// -// return files.getFileSpecList() -// } -// -// private fun createTypeSpec( -// inputMetadata: List, -// targetObject: GeneratedObject, -// keys: List, -// objectBuilder: TypeSpec.Builder, -// ): MRGenerator.GenerationResult? { -// if (targetObject.isActual) { -// objectBuilder.addModifiers(KModifier.ACTUAL) -// } -// -// if (targetObject.isActualObject || targetObject.isTargetObject) { -// extendObjectBodyAtStart(objectBuilder) -// } -// -// val generatedProperties = mutableListOf() -// -// keys.forEach { fileSpec -> -// val property = PropertySpec.builder(fileSpec.key, resourceClassName) -// -// var generatedProperty = GeneratedProperty( -// modifier = GeneratedObjectModifier.None, -// name = fileSpec.key, -// data = JsonPrimitive(fileSpec.file.path) -// ) -// -// if (targetObject.isActualObject || targetObject.isTargetObject) { -// // Add modifier for property and setup metadata -// generatedProperty = generatedProperty.copy( -// modifier = addActualOverrideModifier( -// propertyName = fileSpec.key, -// property = property, -// inputMetadata = inputMetadata, -// targetObject = targetObject -// ) -// ) -// -// getPropertyInitializer(fileSpec)?.let { -// property.initializer(it) -// } -// } -// -// objectBuilder.addProperty(property.build()) -// generatedProperties.add(generatedProperty) -// } -// -// extendObjectBodyAtEnd(objectBuilder) -// -// if (generatedProperties.isEmpty()) return null -// -// return MRGenerator.GenerationResult( -// typeSpec = objectBuilder.build(), -// metadata = targetObject.copy(properties = generatedProperties) -// ) -// } -// -// override fun getImports(): List = emptyList() -// -// protected open fun beforeGenerate( -// objectBuilder: TypeSpec.Builder, -// files: List, -// ) = Unit -// -// protected open fun generateResources( -// resourcesGenerationDir: File, -// files: List, -// ) = Unit -// -// private fun processKey(key: String): String { -// return key.replace("-", "_") -// } -// -// abstract fun getClassModifiers(): Array -// -// abstract fun getPropertyModifiers(): Array -// -// abstract fun getPropertyInitializer(fileSpec: FileSpec): CodeBlock? -// -// data class FileSpec( -// val key: String, -// val file: File, -// ) -// -// class Feature( -// private val settings: MRGenerator.Settings, -// ) : ResourceGeneratorFeature { -// -// override fun createCommonGenerator(): FilesGenerator = CommonFilesGenerator( -// ownInputFileTree = settings.ownResourcesFileTree, -// ) -// -// override fun createAppleGenerator(): FilesGenerator = AppleFilesGenerator( -// ownInputFileTree = settings.ownResourcesFileTree, -// ) -// -// override fun createAndroidGenerator(): FilesGenerator = AndroidFilesGenerator( -// ownInputFileTree = settings.ownResourcesFileTree, -// androidRClassPackage = settings.androidRClassPackage, -// ) -// -// override fun createJsGenerator(): FilesGenerator = JsFilesGenerator( -// ownInputFileTree = settings.ownResourcesFileTree, -// ) -// -// override fun createJvmGenerator(): FilesGenerator = JvmFilesGenerator( -// ownInputFileTree = settings.ownResourcesFileTree, -// settings = settings -// ) -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidFilesGenerator.kt deleted file mode 100644 index 959c1c82a..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidFilesGenerator.kt +++ /dev/null @@ -1,47 +0,0 @@ -///* -// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.android -// -//import com.squareup.kotlinpoet.ClassName -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import dev.icerock.gradle.generator.FilesGenerator -//import dev.icerock.gradle.generator.NOPObjectBodyExtendable -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import org.gradle.api.file.FileTree -//import org.gradle.api.provider.Provider -//import java.io.File -//import java.util.Locale -// -//class AndroidFilesGenerator( -// ownInputFileTree: FileTree, -// private val androidRClassPackage: Provider, -//) : FilesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { -// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyInitializer(fileSpec: FileSpec) = -// CodeBlock.of("FileResource(rawResId = R.raw.%L)", keyToResourceId(fileSpec.key)) -// -// override fun getImports() = listOf( -// ClassName(androidRClassPackage.get(), "R") -// ) -// -// override fun generateResources( -// resourcesGenerationDir: File, -// files: List -// ) { -// val targetDir = File(resourcesGenerationDir, "raw") -// targetDir.mkdirs() -// -// files.forEach { fileSpec -> -// val fileName = keyToResourceId(fileSpec.key) + "." + fileSpec.file.extension -// fileSpec.file.copyTo(File(targetDir, fileName)) -// } -// } -// -// private fun keyToResourceId(key: String) = key.lowercase(Locale.ROOT) -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleFilesGenerator.kt deleted file mode 100644 index 9a3998ca9..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleFilesGenerator.kt +++ /dev/null @@ -1,39 +0,0 @@ -///* -// * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.apple -// -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import dev.icerock.gradle.generator.FilesGenerator -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import org.gradle.api.file.FileTree -//import java.io.File -// -//class AppleFilesGenerator( -// ownInputFileTree: FileTree, -//) : FilesGenerator(resourceFiles = ownInputFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { -// -// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyInitializer(fileSpec: FileSpec) = CodeBlock.of( -// "FileResource(fileName = %S, extension = %S,bundle = ${AppleMRGenerator.BUNDLE_PROPERTY_NAME})", -// fileSpec.file.nameWithoutExtension, -// fileSpec.file.extension -// ) -// -// override fun generateResources( -// resourcesGenerationDir: File, -// files: List, -// ) { -// val targetDir = File(resourcesGenerationDir, "files") -// targetDir.mkdirs() -// -// files.forEach { fileSpec -> -// fileSpec.file.copyTo(File(targetDir, fileSpec.file.name)) -// } -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsFilesGenerator.kt deleted file mode 100644 index bdc078ae5..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsFilesGenerator.kt +++ /dev/null @@ -1,62 +0,0 @@ -///* -// * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.js -// -//import com.squareup.kotlinpoet.ClassName -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.FunSpec -//import com.squareup.kotlinpoet.KModifier -//import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -//import com.squareup.kotlinpoet.TypeSpec -//import dev.icerock.gradle.generator.FilesGenerator -//import dev.icerock.gradle.generator.NOPObjectBodyExtendable -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import org.gradle.api.file.FileTree -//import java.io.File -// -//class JsFilesGenerator( -// ownInputFileTree: FileTree, -//) : FilesGenerator( -// resourceFiles = ownInputFileTree -//), ObjectBodyExtendable by NOPObjectBodyExtendable() { -// -// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyInitializer(fileSpec: FileSpec): CodeBlock { -// val requireDeclaration = """require("$FILES_DIR/${fileSpec.file.name}")""" -// return CodeBlock.of( -// "FileResource(fileUrl = js(%S) as String)", -// requireDeclaration -// ) -// } -// -// override fun beforeGenerate(objectBuilder: TypeSpec.Builder, files: List) { -// val languageKeysList = files.joinToString { it.key } -// -// objectBuilder.addFunction( -// FunSpec.builder("values") -// .addModifiers(KModifier.OVERRIDE) -// .addStatement("return listOf($languageKeysList)") -// .returns( -// ClassName("kotlin.collections", "List") -// .parameterizedBy(resourceClassName) -// ) -// .build() -// ) -// } -// -// override fun generateResources(resourcesGenerationDir: File, files: List) { -// val fileResDir = File(resourcesGenerationDir, FILES_DIR).apply { mkdirs() } -// files.forEach { (_, file) -> -// file.copyTo(File(fileResDir, file.name)) -// } -// } -// -// companion object { -// const val FILES_DIR = "files" -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmFilesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmFilesGenerator.kt deleted file mode 100644 index 157fb86fa..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmFilesGenerator.kt +++ /dev/null @@ -1,43 +0,0 @@ -///* -// * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.jvm -// -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import dev.icerock.gradle.generator.FilesGenerator -//import dev.icerock.gradle.generator.MRGenerator -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import org.gradle.api.file.FileTree -//import java.io.File -// -//class JvmFilesGenerator( -// ownInputFileTree: FileTree, -// settings: MRGenerator.Settings, -//) : FilesGenerator(ownInputFileTree), -// ObjectBodyExtendable by ClassLoaderExtender(settings.className) { -// -// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyInitializer(fileSpec: FileSpec) = CodeBlock.of( -// "FileResource(resourcesClassLoader = resourcesClassLoader, filePath = %S)", -// "$FILES_DIR/${fileSpec.file.name}" -// ) -// -// override fun generateResources( -// resourcesGenerationDir: File, -// files: List, -// ) { -// val fileResDir = File(resourcesGenerationDir, FILES_DIR).apply { mkdirs() } -// files.forEach { fileSpec -> -// fileSpec.file.copyTo(File(fileResDir, fileSpec.file.name)) -// } -// } -// -// companion object { -// private const val FILES_DIR = "files" -// } -//} 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 ad0f1b5f9..72341306a 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 @@ -20,6 +20,11 @@ import dev.icerock.gradle.generator.resources.color.AppleColorResourceGenerator import dev.icerock.gradle.generator.resources.color.ColorResourceGenerator import dev.icerock.gradle.generator.resources.color.JsColorResourceGenerator import dev.icerock.gradle.generator.resources.color.JvmColorResourceGenerator +import dev.icerock.gradle.generator.resources.file.AndroidFileResourceGenerator +import dev.icerock.gradle.generator.resources.file.AppleFileResourceGenerator +import dev.icerock.gradle.generator.resources.file.FileResourceGenerator +import dev.icerock.gradle.generator.resources.file.JsFileResourceGenerator +import dev.icerock.gradle.generator.resources.file.JvmFileResourceGenerator import dev.icerock.gradle.generator.resources.font.AndroidFontResourceGenerator import dev.icerock.gradle.generator.resources.font.AppleFontResourceGenerator import dev.icerock.gradle.generator.resources.font.FontResourceGenerator @@ -44,6 +49,7 @@ import dev.icerock.gradle.metadata.container.ContainerMetadata import dev.icerock.gradle.metadata.container.ObjectMetadata import dev.icerock.gradle.metadata.container.ResourceType import dev.icerock.gradle.metadata.resource.ColorMetadata +import dev.icerock.gradle.metadata.resource.FileMetadata import dev.icerock.gradle.metadata.resource.FontMetadata import dev.icerock.gradle.metadata.resource.ImageMetadata import dev.icerock.gradle.metadata.resource.PluralMetadata @@ -199,7 +205,8 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { createPluralsGenerator(), createImagesGenerator(), createColorsGenerator(), - createFontsGenerator() + createFontsGenerator(), + createFilesGenerator() ), resourcesPackageName = resourcesPackageName.get(), resourcesClassName = resourcesClassName.get(), @@ -300,6 +307,51 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { ) } + private fun createFilesGenerator(): ResourceTypeGenerator { + return ResourceTypeGenerator( + generationPackage = resourcesPackageName.get(), + resourceClass = CodeConst.fileResourceName, + resourceType = ResourceType.FILES, + metadataClass = FileMetadata::class, + visibilityModifier = resourcesVisibility.get().toModifier(), + generator = FileResourceGenerator(), + platformResourceGenerator = createPlatformFileGenerator(), + filter = { include("files/**") } + ) + } + + private fun createPlatformFileGenerator(): PlatformResourceGenerator { + val resourcesGenerationDir: File = outputResourcesDir.get().asFile + return createByPlatform( + kotlinPlatformType = kotlinPlatformType, + konanTarget = ::kotlinKonanTarget, + // TODO find way to remove this NOP + createCommon = { NOPResourceGenerator() }, + createAndroid = { + AndroidFileResourceGenerator( + androidRClassPackage = androidRClassPackage.get(), + resourcesGenerationDir = resourcesGenerationDir + ) + }, + createApple = { + AppleFileResourceGenerator( + resourcesGenerationDir = resourcesGenerationDir + ) + }, + createJvm = { + JvmFileResourceGenerator( + className = resourcesClassName.get(), + resourcesGenerationDir = resourcesGenerationDir + ) + }, + createJs = { + JsFileResourceGenerator( + resourcesGenerationDir = resourcesGenerationDir + ) + } + ) + } + private fun createPlatformFontGenerator(): PlatformResourceGenerator { val resourcesGenerationDir: File = outputResourcesDir.get().asFile return createByPlatform( diff --git a/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt b/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt index 66f653885..b8a8d1429 100644 --- a/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt +++ b/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt @@ -77,13 +77,13 @@ internal fun App() { Text(text = stringResource(MR.strings.hello_world)) } -// val fileContent: String? by MR.files.some_file.readTextAsState() -// Text( -// modifier = Modifier.padding(top = 16.dp), -// text = fileContent.orEmpty(), -// color = MaterialTheme.colors.onBackground -// ) -// + val fileContent: String? by MR.files.some_file.readTextAsState() + Text( + modifier = Modifier.padding(top = 16.dp), + text = fileContent.orEmpty(), + color = MaterialTheme.colors.onBackground + ) + // val assetContent: String? by MR.assets.some_asset.readTextAsState() // Text( // modifier = Modifier.padding(top = 16.dp), From 4515a44af457300603f589618511e86873505e3c Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Wed, 10 Jan 2024 20:03:02 +0700 Subject: [PATCH 100/352] #535 assets generator migration --- .../js/CopyResourcesToExecutableAction.kt | 1 + .../dev/icerock/gradle/generator/CodeConst.kt | 1 + .../asset/AndroidAssetResourceGenerator.kt | 30 ++ .../asset/AppleAssetResourceGenerator.kt | 50 +++ .../resources/asset/AssetResourceGenerator.kt | 35 ++ .../asset/JsAssetResourceGenerator.kt | 67 ++++ .../asset/JvmAssetResourceGenerator.kt | 62 ++++ .../metadata/resource/ResourceMetadata.kt | 5 +- .../icerock/gradle/oldgen/AssetsGenerator.kt | 322 ------------------ .../oldgen/android/AndroidAssetsGenerator.kt | 42 --- .../oldgen/android/AndroidMRGenerator.kt | 10 - .../oldgen/apple/AppleAssetsGenerator.kt | 58 ---- .../gradle/oldgen/common/CommonMRGenerator.kt | 20 -- .../gradle/oldgen/js/JsAssetsGenerator.kt | 105 ------ .../icerock/gradle/oldgen/js/JsMRGenerator.kt | 54 --- .../gradle/oldgen/jvm/JvmAssetsGenerator.kt | 57 ---- .../gradle/oldgen/jvm/JvmMRGenerator.kt | 16 - .../GenerateMultiplatformResourcesTask.kt | 62 +++- .../shared/src/commonMain/kotlin/App.kt | 12 +- .../additionalDir/second_inner_text_file.txt | 2 +- 20 files changed, 318 insertions(+), 693 deletions(-) create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/AndroidAssetResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/AppleAssetResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/AssetResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/JsAssetResourceGenerator.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/JvmAssetResourceGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/AssetsGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidAssetsGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidMRGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleAssetsGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/common/CommonMRGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsAssetsGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmAssetsGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmMRGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/js/CopyResourcesToExecutableAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/js/CopyResourcesToExecutableAction.kt index 800c13d0d..3f1a37faa 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/js/CopyResourcesToExecutableAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/js/CopyResourcesToExecutableAction.kt @@ -54,6 +54,7 @@ internal class CopyResourcesToExecutableAction( { test: /\.(.*)/, resource: [ + path.resolve(mokoResourcePath, "assets"), path.resolve(mokoResourcePath, "files"), path.resolve(mokoResourcePath, "images"), path.resolve(mokoResourcePath, "localization"), diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt index c50058e1c..e160c3ef6 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt @@ -14,6 +14,7 @@ internal object CodeConst { val colorResourceName = ClassName("dev.icerock.moko.resources", "ColorResource") val fontResourceName = ClassName("dev.icerock.moko.resources", "FontResource") val fileResourceName = ClassName("dev.icerock.moko.resources", "FileResource") + val assetResourceName = ClassName("dev.icerock.moko.resources", "AssetResource") val graphicsColorName = ClassName("dev.icerock.moko.graphics", "Color") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/AndroidAssetResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/AndroidAssetResourceGenerator.kt new file mode 100644 index 000000000..ad168639d --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/AndroidAssetResourceGenerator.kt @@ -0,0 +1,30 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.resources.asset + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.metadata.resource.AssetMetadata +import java.io.File + +internal class AndroidAssetResourceGenerator( + private val androidRClassPackage: String, + private val assetsGenerationDir: File +) : PlatformResourceGenerator { + override fun imports(): List = listOf( + ClassName(androidRClassPackage, "R") + ) + + override fun generateInitializer(metadata: AssetMetadata): CodeBlock { + return CodeBlock.of("AssetResource(path = %S)", metadata.pathRelativeToBase.path) + } + + override fun generateResourceFiles(data: List) { + data.forEach { metadata -> + metadata.filePath.copyTo(File(assetsGenerationDir, metadata.pathRelativeToBase.path)) + } + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/AppleAssetResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/AppleAssetResourceGenerator.kt new file mode 100644 index 000000000..6a80ed084 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/AppleAssetResourceGenerator.kt @@ -0,0 +1,50 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.resources.asset + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.generator.addAppleContainerBundleProperty +import dev.icerock.gradle.metadata.resource.AssetMetadata +import java.io.File + +internal class AppleAssetResourceGenerator( + private val resourcesGenerationDir: File +) : PlatformResourceGenerator { + override fun imports(): List = emptyList() + + override fun generateInitializer(metadata: AssetMetadata): CodeBlock { + return CodeBlock.of( + "AssetResource(originalPath = %S, fileName = %S, extension = %S, bundle = %L)", + metadata.pathRelativeToBase.path, + metadata.pathRelativeToBase.path + .replace('/', PATH_DELIMITER) + .substringBeforeLast('.'), + metadata.filePath.extension, + CodeConst.Apple.containerBundlePropertyName + ) + } + + override fun generateResourceFiles(data: List) { + data.forEach { metadata -> + val newName: String = metadata.pathRelativeToBase.path.replace('/', PATH_DELIMITER) + metadata.filePath.copyTo(File(resourcesGenerationDir, newName)) + } + } + + override fun generateBeforeProperties( + builder: TypeSpec.Builder, + metadata: List + ) { + builder.addAppleContainerBundleProperty() + } + + private companion object { + const val PATH_DELIMITER = '+' + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/AssetResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/AssetResourceGenerator.kt new file mode 100644 index 000000000..a62d62959 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/AssetResourceGenerator.kt @@ -0,0 +1,35 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.resources.asset + +import com.squareup.kotlinpoet.PropertySpec +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.ResourceGenerator +import dev.icerock.gradle.metadata.resource.AssetMetadata +import java.io.File + +internal class AssetResourceGenerator( + private val assetDirs: Set +) : ResourceGenerator { + + override fun generateMetadata(files: Set): List { + return files.map { file -> + AssetMetadata( + key = processKey(file.nameWithoutExtension), + relativePath = assetDirs.single { file.absolutePath.contains(it.absolutePath) }, + filePath = file, + ) + } + } + + override fun generateProperty(metadata: AssetMetadata): PropertySpec.Builder { + return PropertySpec.builder(metadata.key, CodeConst.assetResourceName) + } + + // TODO commonize? + private fun processKey(key: String): String { + return key.replace("-", "_") + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/JsAssetResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/JsAssetResourceGenerator.kt new file mode 100644 index 000000000..a1c77dcfe --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/JsAssetResourceGenerator.kt @@ -0,0 +1,67 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.resources.asset + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.FunSpec +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.metadata.resource.AssetMetadata +import java.io.File + +internal class JsAssetResourceGenerator( + private val resourcesGenerationDir: File +) : PlatformResourceGenerator { + + override fun imports(): List = emptyList() + + override fun generateInitializer(metadata: AssetMetadata): CodeBlock { + val filePath: String = File(ASSETS_DIR, metadata.pathRelativeToBase.path).path + .replace("\\", "/") + + val requireDeclaration = """require("$filePath")""" + return CodeBlock.of( + "AssetResource(originalPath = js(%S) as String, rawPath = %S)", + requireDeclaration, + metadata.pathRelativeToBase + ) + } + + override fun generateResourceFiles(data: List) { + val targetDir = File(resourcesGenerationDir, ASSETS_DIR) + targetDir.mkdirs() + + data.forEach { metadata -> + metadata.filePath.copyTo(File(targetDir, metadata.pathRelativeToBase.path)) + } + } + + override fun generateAfterProperties( + builder: TypeSpec.Builder, + metadata: List + ) { + // FIXME duplicate + val values: String = metadata.joinToString { it.key } + + val valuesFun: FunSpec = FunSpec.builder("values") + .addModifiers(KModifier.OVERRIDE) + .addStatement("return listOf($values)") + .returns( + ClassName("kotlin.collections", "List") + .parameterizedBy(CodeConst.assetResourceName) + ) + .build() + + builder.addFunction(valuesFun) + } + + private companion object { + const val ASSETS_DIR = "assets" + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/JvmAssetResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/JvmAssetResourceGenerator.kt new file mode 100644 index 000000000..44ff879c9 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/JvmAssetResourceGenerator.kt @@ -0,0 +1,62 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.resources.asset + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.PropertySpec +import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.metadata.resource.AssetMetadata +import java.io.File + +internal class JvmAssetResourceGenerator( + private val className: String, + private val resourcesGenerationDir: File +) : PlatformResourceGenerator { + override fun imports(): List = emptyList() + + override fun generateInitializer(metadata: AssetMetadata): CodeBlock { + return CodeBlock.of( + "AssetResource(resourcesClassLoader = %L, originalPath = %S, path = %S)", + CodeConst.Jvm.resourcesClassLoaderPropertyName, + metadata.pathRelativeToBase.path, + buildAssetPath(metadata) + ) + } + + override fun generateResourceFiles(data: List) { + data.forEach { metadata -> + metadata.filePath.copyTo(File(resourcesGenerationDir, buildAssetPath(metadata))) + } + } + + override fun generateBeforeProperties( + builder: TypeSpec.Builder, + metadata: List + ) { + // FIXME duplication + val classLoaderProperty: PropertySpec = PropertySpec.builder( + CodeConst.Jvm.resourcesClassLoaderPropertyName, + CodeConst.Jvm.classLoaderName, + KModifier.OVERRIDE + ) + .initializer(CodeBlock.of(className + "." + CodeConst.Jvm.resourcesClassLoaderPropertyName)) + .build() + + builder.addProperty(classLoaderProperty) + } + + private fun buildAssetPath(metadata: AssetMetadata): String { + return File(ASSETS_DIR, metadata.pathRelativeToBase.path).path + .replace('\\', '/') + } + + private companion object { + const val ASSETS_DIR = "assets" + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt index 3d16ffafa..b21966223 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt @@ -129,10 +129,13 @@ internal data class ColorMetadata( } @Serializable -internal data class AssetsMetadata( +internal data class AssetMetadata( override val key: String, val relativePath: File, val filePath: File ) : ResourceMetadata { + val pathRelativeToBase: File + get() = filePath.relativeTo(relativePath) + override fun contentHash(): String = filePath.calculateResourcesHash() } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/AssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/AssetsGenerator.kt deleted file mode 100644 index 512ee03c0..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/AssetsGenerator.kt +++ /dev/null @@ -1,322 +0,0 @@ -///* -// * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator -// -//import com.squareup.kotlinpoet.ClassName -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import com.squareup.kotlinpoet.PropertySpec -//import com.squareup.kotlinpoet.TypeSpec -//import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecDirectory -//import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecFile -//import dev.icerock.gradle.generator.android.AndroidAssetsGenerator -//import dev.icerock.gradle.generator.apple.AppleAssetsGenerator -//import dev.icerock.gradle.generator.common.CommonAssetsGenerator -//import dev.icerock.gradle.generator.js.JsAssetsGenerator -//import dev.icerock.gradle.generator.jvm.JvmAssetsGenerator -//import dev.icerock.gradle.metadata.model.GeneratedObject -//import dev.icerock.gradle.metadata.model.GeneratedObjectModifier -//import dev.icerock.gradle.metadata.model.GeneratedProperty -//import dev.icerock.gradle.metadata.model.GeneratorType -//import dev.icerock.gradle.metadata.objectsWithProperties -//import kotlinx.serialization.json.Json -//import kotlinx.serialization.json.JsonPrimitive -//import kotlinx.serialization.json.decodeFromJsonElement -//import org.gradle.api.Project -//import org.gradle.api.file.FileTree -//import java.io.File -// -//@Suppress("TooManyFunctions") -//abstract class AssetsGenerator( -// private val resourcesFileTree: FileTree, -//) : MRGenerator.Generator { -// override val inputFiles: Iterable -// get() = resourcesFileTree.matching { -// it.include("assets/**") -// } -// override val mrObjectName: String = ASSETS_DIR_NAME -// override val resourceClassName = ClassName("dev.icerock.moko.resources", "AssetResource") -// -// override val type: GeneratorType = GeneratorType.Assets -// -// override fun generateObject( -// project: Project, -// inputMetadata: List, -// outputMetadata: GeneratedObject, -// assetsGenerationDir: File, -// resourcesGenerationDir: File, -// objectBuilder: TypeSpec.Builder -// ): MRGenerator.GenerationResult? { -// val previousAssetsFiles: List = getPreviousAssets( -// inputMetadata = inputMetadata, -// targetObject = outputMetadata -// ) -// -// val previousAssets: List = parseRootContentInner(previousAssetsFiles) -// val targetAssets: List = parseRootContentInner(inputFiles) -// val allAssets: List = (previousAssets + targetAssets) -// -// beforeGenerate(objectBuilder, allAssets) -// -// val result: MRGenerator.GenerationResult = createTypeSpec( -// project = project, -// inputMetadata = inputMetadata, -// targetObject = outputMetadata, -// keys = allAssets, -// objectBuilder = objectBuilder -// ) ?: return null -// -// generateResources(assetsGenerationDir, resourcesGenerationDir, allAssets) -// -// return result -// } -// -// private fun createTypeSpec( -// project: Project, -// inputMetadata: List, -// targetObject: GeneratedObject, -// keys: List, -// objectBuilder: TypeSpec.Builder, -// ): MRGenerator.GenerationResult? { -// if (targetObject.isActual) { -// objectBuilder.addModifiers(KModifier.ACTUAL) -// } -// -// if (targetObject.isActualObject || targetObject.isTargetObject) { -// extendObjectBodyAtStart(objectBuilder) -// } -// -// val generatedProperties = mutableListOf() -// -// createInnerTypeSpec( -// project, -// inputMetadata = inputMetadata, -// generatedProperties = generatedProperties, -// targetObject = targetObject, -// keys = keys, -// objectBuilder = objectBuilder -// ) -// -// extendObjectBodyAtEnd(objectBuilder) -// -// if (generatedProperties.isEmpty()) return null -// -// return MRGenerator.GenerationResult( -// typeSpec = objectBuilder.build(), -// metadata = targetObject.copy(properties = generatedProperties) -// ) -// } -// -// private fun getBaseDir(file: File): String { -// val relativePathToAssets = file.path.substringAfterLast(ASSETS_DIR_NAME) -// val fixedRelativePath = File(relativePathToAssets).path -// -// val result: String = if (fixedRelativePath.startsWith(File.separatorChar)) { -// fixedRelativePath.substring(1) -// } else { -// fixedRelativePath -// } -// -// return if (File.separatorChar == '/') result else result.replace(File.separatorChar, '/') -// } -// -// private fun parseRootContentInner(folders: Iterable): List { -// val res = mutableListOf() -// -// for (it in folders) { -// if (it.isDirectory) { -// val files = it.listFiles() -// -// if (!files.isNullOrEmpty()) { -// res.add( -// AssetSpecDirectory( -// name = it.name, -// assets = parseRootContentInner(files.toList()) -// ) -// ) -// } -// } else { -// // skip empty files, like .DS_Store -// if (it.nameWithoutExtension.isEmpty()) { -// continue -// } -// -// val pathRelativeToBase = getBaseDir(it) -// -// if (pathRelativeToBase.contains(PATH_DELIMITER)) { -// error("file path can't have this symbol $PATH_DELIMITER. We use them as separators.") -// } -// -// res.add( -// AssetSpecFile( -// pathRelativeToBase = pathRelativeToBase, -// file = it -// ) -// ) -// } -// } -// -// return res -// } -// -// @Suppress("SpreadOperator") -// private fun createInnerTypeSpec( -// project: Project, -// inputMetadata: List, -// generatedProperties: MutableList, -// targetObject: GeneratedObject, -// keys: List, -// objectBuilder: TypeSpec.Builder, -// ) { -// for (specs: AssetSpec in keys) { -// if (specs is AssetSpecDirectory) { -// val spec = TypeSpec.objectBuilder(specs.name.replace('-', '_')) -// -// if (targetObject.isActualObject) { -// spec.addModifiers(KModifier.ACTUAL) -// } -// -// createInnerTypeSpec( -// project, -// inputMetadata = inputMetadata, -// generatedProperties = generatedProperties, -// targetObject = targetObject, -// keys = specs.assets, -// objectBuilder = spec -// ) -// -// objectBuilder.addType(spec.build()) -// } else if (specs is AssetSpecFile) { -// val fileName = specs.file.nameWithoutExtension.replace('-', '_') -// val styleProperty = PropertySpec.builder(fileName, resourceClassName) -// -// var generatedProperty = GeneratedProperty( -// modifier = GeneratedObjectModifier.None, -// name = fileName, -// data = JsonPrimitive(specs.file.path) -// ) -// -// if (targetObject.isActualObject || targetObject.isTargetObject) { -// // Add modifier for property and setup metadata -// generatedProperty = generatedProperty.copy( -// modifier = addActualOverrideModifier( -// propertyName = fileName, -// property = styleProperty, -// inputMetadata = inputMetadata, -// targetObject = targetObject -// ) -// ) -// -// getPropertyInitializer(specs)?.let { codeBlock -> -// styleProperty.initializer(codeBlock) -// } -// } -// -// generatedProperties.add(generatedProperty) -// objectBuilder.addProperty(styleProperty.build()) -// } -// } -// } -// -// private fun getPreviousAssets( -// inputMetadata: List, -// targetObject: GeneratedObject, -// ): List { -// if (!targetObject.isObject || !targetObject.isActual) return emptyList() -// -// val json = Json -// val objectsWithProperties: List = inputMetadata.objectsWithProperties( -// targetObject = targetObject -// ) -// -// val files = mutableListOf() -// -// objectsWithProperties.forEach { generatedObject -> -// generatedObject.properties.forEach { property -> -// val data = json.decodeFromJsonElement(property.data) -// files.add( -// File(data.content) -// ) -// } -// } -// -// return files -// } -// -// override fun getImports(): List = emptyList() -// -// protected open fun beforeGenerate( -// objectBuilder: TypeSpec.Builder, -// files: List, -// ) { -// } -// -// protected open fun generateResources( -// assetsGenerationDir: File, -// resourcesGenerationDir: File, -// files: List, -// ) = Unit -// -// abstract fun getClassModifiers(): Array -// -// abstract fun getPropertyModifiers(): Array -// -// abstract fun getPropertyInitializer(fileSpec: AssetSpecFile): CodeBlock? -// -// -// sealed class AssetSpec { -// class AssetSpecDirectory( -// val name: String, -// val assets: List, -// ) : AssetSpec() -// -// /** -// * @param pathRelativeToBase used to copy necessary resources in AssetsGenerator -// * @param file is a new name a of copied resource for systems which do not support path with / symbol -// */ -// class AssetSpecFile( -// val pathRelativeToBase: String, -// val file: File, -// ) : AssetSpec() -// } -// -// class Feature( -// private val settings: MRGenerator.Settings, -// ) : ResourceGeneratorFeature { -// -// override fun createCommonGenerator(): AssetsGenerator = CommonAssetsGenerator( -// ownResourcesFileTree = settings.ownResourcesFileTree, -// ) -// -// override fun createAppleGenerator(): AssetsGenerator = AppleAssetsGenerator( -// ownResourcesFileTree = settings.ownResourcesFileTree, -// ) -// -// override fun createAndroidGenerator(): AssetsGenerator = AndroidAssetsGenerator( -// ownResourcesFileTree = settings.ownResourcesFileTree, -// ) -// -// override fun createJvmGenerator(): AssetsGenerator = JvmAssetsGenerator( -// ownResourcesFileTree = settings.ownResourcesFileTree, -// settings = settings -// ) -// -// override fun createJsGenerator(): AssetsGenerator = JsAssetsGenerator( -// ownResourcesFileTree = settings.ownResourcesFileTree, -// ) -// } -// -// companion object { -// const val ASSETS_DIR_NAME: String = "assets" -// -// /* -// This is used for property name in MR class as well as a replacement of / for platforms which -// don't support it like apple. -// */ -// const val PATH_DELIMITER = '+' -// -// val ASSETS_REGEX: Regex = "^.*/assets/.*".toRegex() -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidAssetsGenerator.kt deleted file mode 100644 index 1165d4b83..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidAssetsGenerator.kt +++ /dev/null @@ -1,42 +0,0 @@ -///* -// * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.android -// -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import dev.icerock.gradle.generator.AssetsGenerator -//import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecDirectory -//import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecFile -//import dev.icerock.gradle.generator.NOPObjectBodyExtendable -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import org.gradle.api.file.FileTree -//import java.io.File -// -//class AndroidAssetsGenerator( -// ownResourcesFileTree: FileTree, -//) : AssetsGenerator(ownResourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { -// -// override fun generateResources( -// assetsGenerationDir: File, -// resourcesGenerationDir: File, -// files: List -// ) { -// files.forEach { assetSpec -> -// when (assetSpec) { -// is AssetSpecDirectory -> -// generateResources(assetsGenerationDir, resourcesGenerationDir, assetSpec.assets) -// is AssetSpecFile -> -// assetSpec.file.copyTo(File(assetsGenerationDir, assetSpec.pathRelativeToBase)) -// } -// } -// } -// -// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyInitializer(fileSpec: AssetSpecFile) = -// CodeBlock.of("AssetResource(path = %S)", fileSpec.pathRelativeToBase) -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidMRGenerator.kt deleted file mode 100644 index a8480a75d..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/android/AndroidMRGenerator.kt +++ /dev/null @@ -1,10 +0,0 @@ -// // TODO not used. remove after complete migration of task configuration to Plugin configuration time -//// override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { -//// -//// project.tasks.withType().configureEach { -//// it.dependsOn(generationTask) -//// } -//// project.tasks.withType().configureEach { -//// it.dependsOn(generationTask) -//// } -//// } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleAssetsGenerator.kt deleted file mode 100644 index d4e158287..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/apple/AppleAssetsGenerator.kt +++ /dev/null @@ -1,58 +0,0 @@ -///* -// * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.apple -// -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import dev.icerock.gradle.generator.AssetsGenerator -//import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecDirectory -//import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecFile -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import org.gradle.api.file.FileTree -//import java.io.File -// -//class AppleAssetsGenerator( -// ownResourcesFileTree: FileTree, -//) : AssetsGenerator(ownResourcesFileTree), ObjectBodyExtendable by AppleGeneratorHelper() { -// -// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyInitializer(fileSpec: AssetSpecFile): CodeBlock { -// val ext = fileSpec.file.extension -// -// val relativePathWithoutExt = fileSpec -// .pathRelativeToBase -// .replace('/', PATH_DELIMITER) -// .substringBeforeLast('.') -// -// return CodeBlock.of( -// "AssetResource(originalPath = %S, fileName = %S, extension = %S, bundle = %N)", -// fileSpec.pathRelativeToBase, -// relativePathWithoutExt, -// ext, -// AppleMRGenerator.BUNDLE_PROPERTY_NAME -// ) -// } -// -// override fun generateResources( -// assetsGenerationDir: File, -// resourcesGenerationDir: File, -// files: List -// ) { -// files.forEach { assetSpec -> -// when (assetSpec) { -// is AssetSpecDirectory -> -// generateResources(assetsGenerationDir, resourcesGenerationDir, assetSpec.assets) -// -// is AssetSpecFile -> { -// val newName = assetSpec.pathRelativeToBase.replace('/', PATH_DELIMITER) -// assetSpec.file.copyTo(File(resourcesGenerationDir, newName)) -// } -// } -// } -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/common/CommonMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/common/CommonMRGenerator.kt deleted file mode 100644 index 2809f81ac..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/common/CommonMRGenerator.kt +++ /dev/null @@ -1,20 +0,0 @@ - -// // TODO not used. remove after complete migration of task configuration to Plugin configuration time -//// override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { -//// project.tasks -//// .withType>() -////// .matching { it.name.contains(sourceSet.name, ignoreCase = true) } -//// .configureEach { it.dependsOn(generationTask) } -//// -//// project.rootProject.tasks.matching { -//// it.name.contains("prepareKotlinBuildScriptModel") -//// }.configureEach { -//// it.dependsOn(generationTask) -//// } -//// -//// project.tasks -//// .matching { it.name.startsWith("metadata") && it.name.endsWith("ProcessResources") } -//// .configureEach { -//// it.dependsOn(generationTask) -//// } -//// } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsAssetsGenerator.kt deleted file mode 100644 index 2287110ae..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsAssetsGenerator.kt +++ /dev/null @@ -1,105 +0,0 @@ -///* -// * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.js -// -//import com.squareup.kotlinpoet.ClassName -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.FunSpec -//import com.squareup.kotlinpoet.KModifier -//import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -//import com.squareup.kotlinpoet.TypeSpec -//import dev.icerock.gradle.generator.AssetsGenerator -//import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecDirectory -//import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecFile -//import dev.icerock.gradle.generator.NOPObjectBodyExtendable -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import org.gradle.api.file.FileTree -//import java.io.File -// -//class JsAssetsGenerator( -// ownResourcesFileTree: FileTree, -//) : AssetsGenerator(ownResourcesFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() { -// -// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyInitializer(fileSpec: AssetSpecFile): CodeBlock { -// val filePath: String = File(FILES_DIR, fileSpec.pathRelativeToBase).path -// .replace("\\", "/") -// val requireDeclaration = """require("$filePath")""" -// return CodeBlock.of( -// "AssetResource(originalPath = js(%S) as String, rawPath = %S)", -// requireDeclaration, -// fileSpec.pathRelativeToBase -// ) -// } -// -// override fun beforeGenerate(objectBuilder: TypeSpec.Builder, files: List) { -// val languageKeysList = flattenAssets(files).joinToString() -// -// objectBuilder.addFunction( -// FunSpec.builder("values") -// .addModifiers(KModifier.OVERRIDE) -// .addStatement("return listOf($languageKeysList)") -// .returns( -// ClassName("kotlin.collections", "List") -// .parameterizedBy(resourceClassName) -// ) -// .build() -// ) -// } -// -// private fun flattenAssets(assets: List, prefix: String? = null): List { -// return assets.flatMap { spec -> -// when (spec) { -// is AssetSpecDirectory -> { -// val key = spec.name.replace('-', '_') -// val nextPrefix = when (prefix) { -// null -> key -// else -> "$prefix.$key" -// } -// return@flatMap flattenAssets(spec.assets, nextPrefix) -// } -// -// is AssetSpecFile -> { -// val key = spec.file.nameWithoutExtension.replace('-', '_') -// val name = when (prefix) { -// null -> key -// else -> "$prefix.$key" -// } -// return@flatMap listOf(name) -// } -// } -// } -// } -// -// override fun generateResources( -// assetsGenerationDir: File, -// resourcesGenerationDir: File, -// files: List -// ) { -// val fileResDir = File(resourcesGenerationDir, FILES_DIR).apply { mkdirs() } -// generateResourcesInner(files, fileResDir) -// } -// -// private fun generateResourcesInner(files: List, fileResDir: File) { -// files.forEach { assetSpec -> -// when (assetSpec) { -// is AssetSpecDirectory -> { -// generateResourcesInner(assetSpec.assets, fileResDir) -// } -// -// is AssetSpecFile -> { -// assetSpec.file.copyTo(File(fileResDir, assetSpec.pathRelativeToBase)) -// } -// } -// } -// } -// -// private companion object { -// const val FILES_DIR = "files" -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsMRGenerator.kt index 6a4f535de..01eb8bc41 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsMRGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsMRGenerator.kt @@ -1,36 +1,3 @@ -///* -// * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.js -// -//import com.squareup.kotlinpoet.ClassName -//import com.squareup.kotlinpoet.KModifier -//import com.squareup.kotlinpoet.PropertySpec -//import com.squareup.kotlinpoet.STRING -//import com.squareup.kotlinpoet.TypeSpec -//import dev.icerock.gradle.generator.TargetMRGenerator -//import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask -//import dev.icerock.gradle.utils.calculateResourcesHash -//import dev.icerock.gradle.utils.flatName -//import org.gradle.api.Project -//import org.gradle.jvm.tasks.Jar -//import org.gradle.kotlin.dsl.withType -//import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile -//import java.io.File -// -//class JsMRGenerator( -// project: Project, -// settings: Settings, -// generators: List, -//) : TargetMRGenerator( -// project = project, -// settings = settings, -// generators = generators -//) { -// private val flattenClassName: String = settings.packageName.flatName -// override val resourcesGenerationDir: File = settings.resourcesDir.asFile -// // override fun processMRClass(mrClass: TypeSpec.Builder) { // val stringsLoaderInitializer = buildList { // val stringsObjectLoader = mrClass @@ -64,24 +31,3 @@ // ) // } // } -// -// // TODO not used. remove after complete migration of task configuration to Plugin configuration time -//// override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { -//// project.tasks.withType().configureEach { -//// it.dependsOn(generationTask) -//// } -////// setupKLibResources(generationTask) -////// setupResources() -//// -//// // Declare task ':web-app:generateMRcommonMain' as an input of ':web-app:jsSourcesJar'. -//// project.tasks.withType().configureEach { -//// it.dependsOn(generationTask) -//// } -//// -////// dependsOnProcessResources( -////// project = project, -////// sourceSet = sourceSet, -////// task = generationTask, -////// ) -//// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmAssetsGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmAssetsGenerator.kt deleted file mode 100644 index 7764bc3b2..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmAssetsGenerator.kt +++ /dev/null @@ -1,57 +0,0 @@ -///* -// * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.generator.jvm -// -//import com.squareup.kotlinpoet.CodeBlock -//import com.squareup.kotlinpoet.KModifier -//import dev.icerock.gradle.generator.AssetsGenerator -//import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecDirectory -//import dev.icerock.gradle.generator.AssetsGenerator.AssetSpec.AssetSpecFile -//import dev.icerock.gradle.generator.MRGenerator -//import dev.icerock.gradle.generator.ObjectBodyExtendable -//import org.gradle.api.file.FileTree -//import java.io.File -// -//class JvmAssetsGenerator( -// ownResourcesFileTree: FileTree, -// settings: MRGenerator.Settings -//) : AssetsGenerator(ownResourcesFileTree), -// ObjectBodyExtendable by ClassLoaderExtender(settings.className) { -// -// override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) -// -// override fun getPropertyInitializer(fileSpec: AssetSpecFile) = CodeBlock.of( -// "AssetResource(resourcesClassLoader = resourcesClassLoader, originalPath = %S, path = %S)", -// fileSpec.pathRelativeToBase, -// File(FILES_DIR, fileSpec.pathRelativeToBase).path.replace('\\', '/') -// ) -// -// override fun generateResources( -// assetsGenerationDir: File, -// resourcesGenerationDir: File, -// files: List -// ) { -// val fileResDir = File(resourcesGenerationDir, FILES_DIR).apply { mkdirs() } -// generateResourcesInner(files, fileResDir) -// } -// -// private fun generateResourcesInner(files: List, fileResDir: File) { -// files.forEach { assetSpec -> -// when (assetSpec) { -// is AssetSpecDirectory -> -// generateResourcesInner(assetSpec.assets, fileResDir) -// -// is AssetSpecFile -> -// assetSpec.file.copyTo(File(fileResDir, assetSpec.pathRelativeToBase)) -// } -// } -// } -// -// companion object { -// private const val FILES_DIR = "files" -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmMRGenerator.kt deleted file mode 100644 index 6ca80777f..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/jvm/JvmMRGenerator.kt +++ /dev/null @@ -1,16 +0,0 @@ -// // TODO not used. remove after complete migration of task configuration to Plugin configuration time -//// override fun apply(generationTask: GenerateMultiplatformResourcesTask, project: Project) { -//// project.tasks.withType().configureEach { -//// it.dependsOn(generationTask) -//// } -//// project.tasks.withType().configureEach { -//// it.dependsOn(generationTask) -//// } -////// dependsOnProcessResources( -////// project = project, -////// sourceSet = sourceSet, -////// task = generationTask, -////// ) -//// } -// -//} 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 72341306a..4f3fa4762 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 @@ -15,6 +15,11 @@ import dev.icerock.gradle.generator.container.AppleContainerGenerator import dev.icerock.gradle.generator.container.JvmContainerGenerator import dev.icerock.gradle.generator.container.NOPContainerGenerator import dev.icerock.gradle.generator.resources.NOPResourceGenerator +import dev.icerock.gradle.generator.resources.asset.AndroidAssetResourceGenerator +import dev.icerock.gradle.generator.resources.asset.AppleAssetResourceGenerator +import dev.icerock.gradle.generator.resources.asset.AssetResourceGenerator +import dev.icerock.gradle.generator.resources.asset.JsAssetResourceGenerator +import dev.icerock.gradle.generator.resources.asset.JvmAssetResourceGenerator import dev.icerock.gradle.generator.resources.color.AndroidColorResourceGenerator import dev.icerock.gradle.generator.resources.color.AppleColorResourceGenerator import dev.icerock.gradle.generator.resources.color.ColorResourceGenerator @@ -48,6 +53,7 @@ import dev.icerock.gradle.generator.resources.string.StringResourceGenerator import dev.icerock.gradle.metadata.container.ContainerMetadata import dev.icerock.gradle.metadata.container.ObjectMetadata import dev.icerock.gradle.metadata.container.ResourceType +import dev.icerock.gradle.metadata.resource.AssetMetadata import dev.icerock.gradle.metadata.resource.ColorMetadata import dev.icerock.gradle.metadata.resource.FileMetadata import dev.icerock.gradle.metadata.resource.FontMetadata @@ -65,6 +71,7 @@ import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.DirectoryProperty import org.gradle.api.file.FileCollection import org.gradle.api.file.RegularFileProperty +import org.gradle.api.internal.file.collections.FileCollectionAdapter import org.gradle.api.provider.MapProperty import org.gradle.api.provider.Property import org.gradle.api.tasks.CacheableTask @@ -206,7 +213,8 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { createImagesGenerator(), createColorsGenerator(), createFontsGenerator(), - createFilesGenerator() + createFilesGenerator(), + createAssetsGenerator() ), resourcesPackageName = resourcesPackageName.get(), resourcesClassName = resourcesClassName.get(), @@ -320,6 +328,58 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { ) } + private fun createAssetsGenerator(): ResourceTypeGenerator { + return ResourceTypeGenerator( + generationPackage = resourcesPackageName.get(), + resourceClass = CodeConst.assetResourceName, + resourceType = ResourceType.ASSETS, + metadataClass = AssetMetadata::class, + visibilityModifier = resourcesVisibility.get().toModifier(), + generator = AssetResourceGenerator( + assetDirs = ownResources.from + .map { it as FileCollectionAdapter } + .flatMap { it.files } + .map { File(it, "assets") } + .toSet() + ), + platformResourceGenerator = createPlatformAssetGenerator(), + filter = { include("assets/**") } + ) + } + + private fun createPlatformAssetGenerator(): PlatformResourceGenerator { + val resourcesGenerationDir: File = outputResourcesDir.get().asFile + val assetsGenerationDir: File = outputAssetsDir.get().asFile + return createByPlatform( + kotlinPlatformType = kotlinPlatformType, + konanTarget = ::kotlinKonanTarget, + // TODO find way to remove this NOP + createCommon = { NOPResourceGenerator() }, + createAndroid = { + AndroidAssetResourceGenerator( + androidRClassPackage = androidRClassPackage.get(), + assetsGenerationDir = assetsGenerationDir, + ) + }, + createApple = { + AppleAssetResourceGenerator( + resourcesGenerationDir = resourcesGenerationDir + ) + }, + createJvm = { + JvmAssetResourceGenerator( + className = resourcesClassName.get(), + resourcesGenerationDir = resourcesGenerationDir + ) + }, + createJs = { + JsAssetResourceGenerator( + resourcesGenerationDir = resourcesGenerationDir + ) + } + ) + } + private fun createPlatformFileGenerator(): PlatformResourceGenerator { val resourcesGenerationDir: File = outputResourcesDir.get().asFile return createByPlatform( diff --git a/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt b/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt index b8a8d1429..f2a9e7191 100644 --- a/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt +++ b/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt @@ -84,12 +84,12 @@ internal fun App() { color = MaterialTheme.colors.onBackground ) -// val assetContent: String? by MR.assets.some_asset.readTextAsState() -// Text( -// modifier = Modifier.padding(top = 16.dp), -// text = assetContent.orEmpty(), -// color = MaterialTheme.colors.onBackground -// ) + val assetContent: String? by MR.assets.second_inner_text_file.readTextAsState() + Text( + modifier = Modifier.padding(top = 16.dp), + text = assetContent.orEmpty(), + color = MaterialTheme.colors.onBackground + ) } } } diff --git a/samples/compose-resources-gallery/shared/src/commonMain/moko-resources/assets/additionalDir/second_inner_text_file.txt b/samples/compose-resources-gallery/shared/src/commonMain/moko-resources/assets/additionalDir/second_inner_text_file.txt index 82dc87c63..72eed4b42 100644 --- a/samples/compose-resources-gallery/shared/src/commonMain/moko-resources/assets/additionalDir/second_inner_text_file.txt +++ b/samples/compose-resources-gallery/shared/src/commonMain/moko-resources/assets/additionalDir/second_inner_text_file.txt @@ -1 +1 @@ -Text from asset resource. \ No newline at end of file +Text from inner asset resource. \ No newline at end of file From 842f14f09765035883da2f2a3b8bebf6ac6eaa49 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Wed, 10 Jan 2024 21:54:54 +0700 Subject: [PATCH 101/352] #535 cleanup and fix cache invalidation --- .../gradle/MultiplatformResourcesPlugin.kt | 25 ++++++++++ .../apple/CopyResourcesFromKLibsAction.kt | 1 - ...opyResourcesFromKLibsToExecutableAction.kt | 1 - ...CopyResourcesFromKLibsToFrameworkAction.kt | 1 - .../apple/PackAppleResourcesToKLibAction.kt | 4 +- .../gradle/configuration/AndroidTarget.kt | 26 ---------- .../gradle/configuration/AppleTargets.kt | 50 ------------------- .../gradle/generator/CodeGenerators.kt | 44 ++++++++++------ .../generator/{CodeConst.kt => Constants.kt} | 2 +- .../gradle/generator/ResourceTypeGenerator.kt | 6 +-- .../container/AppleContainerGenerator.kt | 6 +-- .../container/JsContainerGenerator.kt | 36 +++++++++++++ .../container/JvmContainerGenerator.kt | 4 +- .../platform/apple/SetupAppleUtils.kt | 42 +++++++++++----- .../asset/AppleAssetResourceGenerator.kt | 4 +- .../resources/asset/AssetResourceGenerator.kt | 4 +- .../asset/JsAssetResourceGenerator.kt | 4 +- .../asset/JvmAssetResourceGenerator.kt | 18 ++----- .../color/AppleColorResourceGenerator.kt | 6 +-- .../resources/color/ColorResourceGenerator.kt | 4 +- .../color/JsColorResourceGenerator.kt | 6 +-- .../color/JvmColorResourceGenerator.kt | 18 ++----- .../file/AppleFileResourceGenerator.kt | 4 +- .../resources/file/FileResourceGenerator.kt | 4 +- .../resources/file/JsFileResourceGenerator.kt | 4 +- .../file/JvmFileResourceGenerator.kt | 19 ++----- .../font/AppleFontResourceGenerator.kt | 4 +- .../resources/font/FontResourceGenerator.kt | 4 +- .../resources/font/JsFontResourceGenerator.kt | 4 +- .../font/JvmFontResourceGenerator.kt | 18 ++----- .../image/AppleImageResourceGenerator.kt | 6 +-- .../resources/image/ImageResourceGenerator.kt | 4 +- .../image/JsImageResourceGenerator.kt | 4 +- .../image/JvmImageResourceGenerator.kt | 18 ++----- .../plural/ApplePluralResourceGenerator.kt | 4 +- .../plural/JsPluralResourceGenerator.kt | 8 +-- .../plural/JvmPluralResourceGenerator.kt | 20 +++----- .../plural/PluralResourceGenerator.kt | 4 +- .../string/AppleStringResourceGenerator.kt | 4 +- .../string/JsStringResourceGenerator.kt | 10 ++-- .../string/JvmStringResourceGenerator.kt | 20 +++----- .../string/StringResourceGenerator.kt | 4 +- .../icerock/gradle/oldgen/js/JsMRGenerator.kt | 33 ------------ .../GenerateMultiplatformResourcesTask.kt | 29 +++++++---- .../dev/icerock/gradle/utils/FileExt.kt | 15 +++--- 45 files changed, 238 insertions(+), 318 deletions(-) delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AndroidTarget.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt rename resources-generator/src/main/kotlin/dev/icerock/gradle/generator/{CodeConst.kt => Constants.kt} (98%) create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/container/JsContainerGenerator.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsMRGenerator.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index c9e79cdac..30a333b8c 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -81,6 +81,11 @@ open class MultiplatformResourcesPlugin : Plugin { mrExtension = mrExtension ) + configureLowerDependencies( + kotlinSourceSet = kotlinSourceSet, + genTask = genTask + ) + configureUpperDependencies( kotlinSourceSet = kotlinSourceSet, resourcesSourceSetName = kotlinSourceSet.name, @@ -331,6 +336,26 @@ open class MultiplatformResourcesPlugin : Plugin { return taskProvider } + private fun configureLowerDependencies( + kotlinSourceSet: KotlinSourceSet, + genTask: TaskProvider, + ) { + kotlinSourceSet.dependsOnObservable.forAll { dependsSourceSet -> + val resourcesDir: SourceDirectorySet = + requireNotNull(dependsSourceSet.extras[mokoResourcesSourceDirectoryKey()]) + + genTask.configure { + val files: Set = resourcesDir.srcDirs + it.lowerResources.from(files) + } + + configureLowerDependencies( + kotlinSourceSet = dependsSourceSet, + genTask = genTask + ) + } + } + private fun configureUpperDependencies( kotlinSourceSet: KotlinSourceSet, resourcesSourceSetName: String, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsAction.kt index 2a2141db8..cb230563d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsAction.kt @@ -7,7 +7,6 @@ package dev.icerock.gradle.actions.apple import dev.icerock.gradle.utils.klibs import org.gradle.api.Action import org.gradle.api.Task -import org.jetbrains.kotlin.gradle.plugin.mpp.Framework import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink import org.jetbrains.kotlin.library.KotlinLibraryLayout import org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsToExecutableAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsToExecutableAction.kt index efb82a2e0..66d1b9226 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsToExecutableAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsToExecutableAction.kt @@ -5,7 +5,6 @@ package dev.icerock.gradle.actions.apple import org.gradle.api.Task -import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractExecutable import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink internal class CopyResourcesFromKLibsToExecutableAction : CopyResourcesFromKLibsAction() { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsToFrameworkAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsToFrameworkAction.kt index 82933d54a..8bb62e156 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsToFrameworkAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsToFrameworkAction.kt @@ -5,7 +5,6 @@ package dev.icerock.gradle.actions.apple import org.gradle.api.Task -import org.jetbrains.kotlin.gradle.plugin.mpp.Framework import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink internal class CopyResourcesFromKLibsToFrameworkAction : CopyResourcesFromKLibsAction() { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/PackAppleResourcesToKLibAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/PackAppleResourcesToKLibAction.kt index 1e6134da6..dc628ea81 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/PackAppleResourcesToKLibAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/PackAppleResourcesToKLibAction.kt @@ -4,7 +4,7 @@ package dev.icerock.gradle.actions.apple -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.platform.apple.LoadableBundle import dev.icerock.gradle.utils.unzipTo import org.gradle.api.Action @@ -77,7 +77,7 @@ internal class PackAppleResourcesToKLibAction( ) } - val rawAssetsDir = File(loadableBundle.resourcesDir, CodeConst.Apple.assetsDirectoryName) + val rawAssetsDir = File(loadableBundle.resourcesDir, Constants.Apple.assetsDirectoryName) if (rawAssetsDir.exists()) { val process: Process = Runtime.getRuntime().exec( "xcrun actool ${rawAssetsDir.name} --compile . --platform iphoneos --minimum-deployment-target ${acToolMinimalDeploymentTarget.get()}", diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AndroidTarget.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AndroidTarget.kt deleted file mode 100644 index cad12c4bd..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AndroidTarget.kt +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.configuration - -//import dev.icerock.gradle.generator.MRGenerator -//import dev.icerock.gradle.generator.ResourceGeneratorFeature -//import dev.icerock.gradle.generator.android.AndroidMRGenerator - -//private fun setAssetsDirsRefresh(project: Project) { -// // without this code Android Gradle Plugin not copy assets to aar -// project.tasks -// .matching { it.name.startsWith("package") && it.name.endsWith("Assets") } -// .configureEach { task -> -// // for gradle optimizations we should use anonymous object -// @Suppress("ObjectLiteralToLambda") -// task.doFirst(object : Action { -// override fun execute(t: Task) { -// val android: BaseExtension = project.extensions.getByType() -// val assets: AndroidSourceDirectorySet = android.mainSourceSet.assets -// assets.setSrcDirs(assets.srcDirs) -// } -// }) -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt deleted file mode 100644 index 2fcf3cef9..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/configuration/AppleTargets.kt +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.configuration - -//import dev.icerock.gradle.generator.MRGenerator -//import dev.icerock.gradle.generator.ResourceGeneratorFeature -//import dev.icerock.gradle.generator.apple.AppleMRGenerator -//import dev.icerock.gradle.tasks.CopyExecutableResourcesToApp -//import dev.icerock.gradle.tasks.CopyXCFrameworkResourcesToApp -//import org.gradle.api.Project -//import org.gradle.kotlin.dsl.register -//import org.gradle.kotlin.dsl.withType -//import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation -//import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractExecutable -//import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation -//import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget -//import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFrameworkTask -//import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink -//import org.jetbrains.kotlin.konan.target.HostManager - -//private fun setupCopyXCFrameworkResourcesTask(project: Project) { -// // Seems that there were problem with this block in the past with mystic task adding. Need more info -// // Now, that works perfectly, I've tested on the real project with Kotlin 1.9.10 and KSP enabled -// // Suppose that on that moment there were no lazy register method for task container -// project.tasks.withType(XCFrameworkTask::class).all { task -> -// val copyTaskName: String = task.name -// .replace("assemble", "copyResources").plus("ToApp") -// -// project.tasks.register(copyTaskName) { -// xcFrameworkDir = task.outputDir -// dependsOn(task) -// } -// } -//} - -//private fun createCopyResourcesToAppTask(project: Project) { -// project.tasks -// .withType() -// .matching { it.binary is AbstractExecutable } -// .all { linkTask -> -// val copyTaskName: String = linkTask.name.replace("link", "copyResources") -// -// project.tasks.register(copyTaskName) { -// this.linkTask = linkTask -// dependsOn(linkTask) -// } -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeGenerators.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeGenerators.kt index 19194072a..fbe52d593 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeGenerators.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeGenerators.kt @@ -12,8 +12,8 @@ import com.squareup.kotlinpoet.TypeSpec internal fun TypeSpec.Builder.addAppleResourcesBundleProperty(bundleIdentifier: String) { val bundleProperty: PropertySpec = PropertySpec.builder( - CodeConst.Apple.resourcesBundlePropertyName, - CodeConst.Apple.nsBundleName, + Constants.Apple.resourcesBundlePropertyName, + Constants.Apple.nsBundleName, KModifier.PRIVATE ).delegate(CodeBlock.of("lazy { NSBundle.loadableBundle(%S) }", bundleIdentifier)) .build() @@ -33,10 +33,10 @@ internal fun TypeSpec.Builder.addContentHashProperty(hash: String) { internal fun TypeSpec.Builder.addAppleContainerBundleProperty() { val bundleProperty: PropertySpec = PropertySpec.builder( - CodeConst.Apple.containerBundlePropertyName, - CodeConst.Apple.nsBundleName, + Constants.Apple.containerBundlePropertyName, + Constants.Apple.nsBundleName, KModifier.OVERRIDE - ).initializer(CodeConst.Apple.resourcesBundlePropertyName) + ).initializer(Constants.Apple.resourcesBundlePropertyName) .build() addProperty(bundleProperty) @@ -44,8 +44,8 @@ internal fun TypeSpec.Builder.addAppleContainerBundleProperty() { internal fun TypeSpec.Builder.addJvmClassLoaderProperty(resourcesClassName: String) { val property: PropertySpec = PropertySpec.builder( - CodeConst.Jvm.resourcesClassLoaderPropertyName, - CodeConst.Jvm.classLoaderName, + Constants.Jvm.resourcesClassLoaderPropertyName, + Constants.Jvm.classLoaderName, KModifier.PRIVATE ).initializer(CodeBlock.of("$resourcesClassName::class.java.classLoader")) .build() @@ -53,9 +53,21 @@ internal fun TypeSpec.Builder.addJvmClassLoaderProperty(resourcesClassName: Stri addProperty(property) } +internal fun TypeSpec.Builder.addJvmResourcesClassLoaderProperty(resourcesClassName: String) { + val classLoaderProperty: PropertySpec = PropertySpec.builder( + Constants.Jvm.resourcesClassLoaderPropertyName, + Constants.Jvm.classLoaderName, + KModifier.OVERRIDE + ) + .initializer(CodeBlock.of(resourcesClassName + "." + Constants.Jvm.resourcesClassLoaderPropertyName)) + .build() + + addProperty(classLoaderProperty) +} + internal fun TypeSpec.Builder.addJsFallbackProperty(fallbackFilePath: String) { val property: PropertySpec = PropertySpec - .builder(CodeConst.Js.fallbackFilePropertyName, String::class, KModifier.PRIVATE) + .builder(Constants.Js.fallbackFilePropertyName, String::class, KModifier.PRIVATE) .initializer( CodeBlock.of( "js(%S) as %T", @@ -73,18 +85,18 @@ internal fun TypeSpec.Builder.addJsSupportedLocalesProperty( ) { val property: PropertySpec = PropertySpec .builder( - CodeConst.Js.supportedLocalesPropertyName, - CodeConst.Js.supportedLocalesName, + Constants.Js.supportedLocalesPropertyName, + Constants.Js.supportedLocalesName, KModifier.PRIVATE ).initializer( CodeBlock .builder() .apply { - add("%T(listOf(\n", CodeConst.Js.supportedLocalesName) + add("%T(listOf(\n", Constants.Js.supportedLocalesName) bcpLangToPath.forEach { (bcpLang, filePath) -> add( "%T(%S, js(%S) as %T),\n", - CodeConst.Js.supportedLocaleName, + Constants.Js.supportedLocaleName, bcpLang, "require(\"$filePath\")", String::class @@ -99,14 +111,14 @@ internal fun TypeSpec.Builder.addJsSupportedLocalesProperty( internal fun TypeSpec.Builder.addJsContainerStringsLoaderProperty() { val property = PropertySpec.builder( - CodeConst.Js.stringsLoaderPropertyName, - CodeConst.Js.stringLoaderName, + Constants.Js.stringsLoaderPropertyName, + Constants.Js.stringLoaderName, KModifier.OVERRIDE ).initializer( CodeBlock.of( "RemoteJsStringLoader.Impl(supportedLocales = %N, fallbackFileUri = %N)", - CodeConst.Js.supportedLocalesPropertyName, - CodeConst.Js.fallbackFilePropertyName + Constants.Js.supportedLocalesPropertyName, + Constants.Js.fallbackFilePropertyName ) ).build() addProperty(property) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/Constants.kt similarity index 98% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/generator/Constants.kt index e160c3ef6..0257397e6 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/CodeConst.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/Constants.kt @@ -6,7 +6,7 @@ package dev.icerock.gradle.generator import com.squareup.kotlinpoet.ClassName -internal object CodeConst { +internal object Constants { val resourceContainerName = ClassName("dev.icerock.moko.resources", "ResourceContainer") val stringResourceName = ClassName("dev.icerock.moko.resources", "StringResource") val pluralsResourceName = ClassName("dev.icerock.moko.resources", "PluralsResource") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceTypeGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceTypeGenerator.kt index d35046626..5f7f4ba94 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceTypeGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceTypeGenerator.kt @@ -74,7 +74,7 @@ internal class ResourceTypeGenerator( .objectBuilder(objectName) .addModifiers(visibilityModifier) // implement ResourceType<**Resource> for extensions - .addSuperinterface(CodeConst.resourceContainerName.parameterizedBy(resourceClass)) + .addSuperinterface(Constants.resourceContainerName.parameterizedBy(resourceClass)) // implement interfaces for generated expect object .addSuperinterfaces(typeInterfaces.map { ClassName(packageName = generationPackage, it.name) @@ -139,7 +139,7 @@ internal class ResourceTypeGenerator( .addModifiers(visibilityModifier) .addModifiers(KModifier.ACTUAL) // implement ResourceType<**Resource> for extensions - .addSuperinterface(CodeConst.resourceContainerName.parameterizedBy(resourceClass)) + .addSuperinterface(Constants.resourceContainerName.parameterizedBy(resourceClass)) // implement interfaces for generated expect object .addSuperinterfaces(typeInterfaces.map { ClassName(packageName = generationPackage, it.name) @@ -178,7 +178,7 @@ internal class ResourceTypeGenerator( .objectBuilder(objectName) .addModifiers(visibilityModifier) // implement ResourceType<**Resource> for extensions - .addSuperinterface(CodeConst.resourceContainerName.parameterizedBy(resourceClass)) + .addSuperinterface(Constants.resourceContainerName.parameterizedBy(resourceClass)) // implement interfaces for generated expect object .also { builder -> platformResourceGenerator.generateBeforeProperties(builder, typeResources) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/container/AppleContainerGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/container/AppleContainerGenerator.kt index 44ab2af5c..fb4ed4a8f 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/container/AppleContainerGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/container/AppleContainerGenerator.kt @@ -6,7 +6,7 @@ package dev.icerock.gradle.generator.container import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.PlatformContainerGenerator import dev.icerock.gradle.generator.addAppleResourcesBundleProperty @@ -15,8 +15,8 @@ internal class AppleContainerGenerator( ) : PlatformContainerGenerator { override fun getImports(): List { return listOf( - CodeConst.Apple.nsBundleName, - CodeConst.Apple.loadableBundleName + Constants.Apple.nsBundleName, + Constants.Apple.loadableBundleName ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/container/JsContainerGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/container/JsContainerGenerator.kt new file mode 100644 index 000000000..3ae6f8924 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/container/JsContainerGenerator.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.container + +import com.squareup.kotlinpoet.PropertySpec +import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.generator.Constants +import dev.icerock.gradle.generator.PlatformContainerGenerator + +internal class JsContainerGenerator : PlatformContainerGenerator { + override fun generateAfterTypes(builder: TypeSpec.Builder) { + val loaders: List = builder.typeSpecs + .flatMap { it.typeSpecs } + .mapNotNull { typeSpec -> + val loaderProperty = typeSpec.propertySpecs + .singleOrNull { it.name == Constants.Js.stringsLoaderPropertyName } + ?: return@mapNotNull null + val objectName = typeSpec.name ?: return@mapNotNull null + + objectName + "." + loaderProperty.name + } + + if (loaders.size > 1) { + val initializer: String = loaders.joinToString(separator = " + ") + + val prop: PropertySpec = PropertySpec.builder( + Constants.Js.stringsLoaderPropertyName, + Constants.Js.stringLoaderName + ).initializer(initializer).build() + + builder.addProperty(prop) + } + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/container/JvmContainerGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/container/JvmContainerGenerator.kt index f842d1220..522806230 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/container/JvmContainerGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/container/JvmContainerGenerator.kt @@ -6,7 +6,7 @@ package dev.icerock.gradle.generator.container import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.PlatformContainerGenerator import dev.icerock.gradle.generator.addJvmClassLoaderProperty @@ -14,7 +14,7 @@ internal class JvmContainerGenerator( private val resourcesClassName: String ) : PlatformContainerGenerator { override fun getImports(): List { - return listOf(CodeConst.Jvm.classLoaderName) + return listOf(Constants.Jvm.classLoaderName) } override fun generateBeforeTypes(builder: TypeSpec.Builder) { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt index c998267a2..033ba680d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt @@ -42,19 +42,6 @@ internal fun setupAppleKLibResources( acToolMinimalDeploymentTarget = acToolMinimalDeploymentTarget ) ) - - // tasks like compileIosMainKotlinMetadata when only one target enabled -// generationTask.project.tasks -// .withType() -// .matching { it.name.contains(sourceSet.name, ignoreCase = true) } -// .configureEach { it.dependsOn(generationTask) } - - //TODO fix usage of sourceSet -// dependsOnProcessResources( -// project = generationTask.project, -// sourceSet = sourceSet, -// task = generationTask, -// ) } internal fun setupFrameworkResources(compilation: KotlinNativeCompilation) { @@ -118,6 +105,35 @@ internal fun createCopyFrameworkResourcesTask(framework: Framework) { // } } +//private fun setupCopyXCFrameworkResourcesTask(project: Project) { +// // Seems that there were problem with this block in the past with mystic task adding. Need more info +// // Now, that works perfectly, I've tested on the real project with Kotlin 1.9.10 and KSP enabled +// // Suppose that on that moment there were no lazy register method for task container +// project.tasks.withType(XCFrameworkTask::class).all { task -> +// val copyTaskName: String = task.name +// .replace("assemble", "copyResources").plus("ToApp") +// +// project.tasks.register(copyTaskName) { +// xcFrameworkDir = task.outputDir +// dependsOn(task) +// } +// } +//} + +//private fun createCopyResourcesToAppTask(project: Project) { +// project.tasks +// .withType() +// .matching { it.binary is AbstractExecutable } +// .all { linkTask -> +// val copyTaskName: String = linkTask.name.replace("link", "copyResources") +// +// project.tasks.register(copyTaskName) { +// this.linkTask = linkTask +// dependsOn(linkTask) +// } +// } +//} + internal fun setupTestsResources(compilation: KotlinNativeCompilation) { compilation.target.binaries.withType().configureEach { executable -> executable.linkTaskProvider.configure { link -> diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/AppleAssetResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/AppleAssetResourceGenerator.kt index 6a80ed084..60c33594a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/AppleAssetResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/AppleAssetResourceGenerator.kt @@ -7,7 +7,7 @@ package dev.icerock.gradle.generator.resources.asset import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.PlatformResourceGenerator import dev.icerock.gradle.generator.addAppleContainerBundleProperty import dev.icerock.gradle.metadata.resource.AssetMetadata @@ -26,7 +26,7 @@ internal class AppleAssetResourceGenerator( .replace('/', PATH_DELIMITER) .substringBeforeLast('.'), metadata.filePath.extension, - CodeConst.Apple.containerBundlePropertyName + Constants.Apple.containerBundlePropertyName ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/AssetResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/AssetResourceGenerator.kt index a62d62959..87c10f692 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/AssetResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/AssetResourceGenerator.kt @@ -5,7 +5,7 @@ package dev.icerock.gradle.generator.resources.asset import com.squareup.kotlinpoet.PropertySpec -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.ResourceGenerator import dev.icerock.gradle.metadata.resource.AssetMetadata import java.io.File @@ -25,7 +25,7 @@ internal class AssetResourceGenerator( } override fun generateProperty(metadata: AssetMetadata): PropertySpec.Builder { - return PropertySpec.builder(metadata.key, CodeConst.assetResourceName) + return PropertySpec.builder(metadata.key, Constants.assetResourceName) } // TODO commonize? diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/JsAssetResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/JsAssetResourceGenerator.kt index a1c77dcfe..fe5355a3d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/JsAssetResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/JsAssetResourceGenerator.kt @@ -10,7 +10,7 @@ import com.squareup.kotlinpoet.FunSpec import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.PlatformResourceGenerator import dev.icerock.gradle.metadata.resource.AssetMetadata import java.io.File @@ -54,7 +54,7 @@ internal class JsAssetResourceGenerator( .addStatement("return listOf($values)") .returns( ClassName("kotlin.collections", "List") - .parameterizedBy(CodeConst.assetResourceName) + .parameterizedBy(Constants.assetResourceName) ) .build() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/JvmAssetResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/JvmAssetResourceGenerator.kt index 44ff879c9..80ca1cdd9 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/JvmAssetResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/JvmAssetResourceGenerator.kt @@ -6,11 +6,10 @@ package dev.icerock.gradle.generator.resources.asset import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.generator.addJvmResourcesClassLoaderProperty import dev.icerock.gradle.metadata.resource.AssetMetadata import java.io.File @@ -23,7 +22,7 @@ internal class JvmAssetResourceGenerator( override fun generateInitializer(metadata: AssetMetadata): CodeBlock { return CodeBlock.of( "AssetResource(resourcesClassLoader = %L, originalPath = %S, path = %S)", - CodeConst.Jvm.resourcesClassLoaderPropertyName, + Constants.Jvm.resourcesClassLoaderPropertyName, metadata.pathRelativeToBase.path, buildAssetPath(metadata) ) @@ -39,16 +38,7 @@ internal class JvmAssetResourceGenerator( builder: TypeSpec.Builder, metadata: List ) { - // FIXME duplication - val classLoaderProperty: PropertySpec = PropertySpec.builder( - CodeConst.Jvm.resourcesClassLoaderPropertyName, - CodeConst.Jvm.classLoaderName, - KModifier.OVERRIDE - ) - .initializer(CodeBlock.of(className + "." + CodeConst.Jvm.resourcesClassLoaderPropertyName)) - .build() - - builder.addProperty(classLoaderProperty) + builder.addJvmResourcesClassLoaderProperty(className) } private fun buildAssetPath(metadata: AssetMetadata): String { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/AppleColorResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/AppleColorResourceGenerator.kt index 3be47c438..db7d1e5ba 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/AppleColorResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/AppleColorResourceGenerator.kt @@ -7,7 +7,7 @@ package dev.icerock.gradle.generator.resources.color import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.PlatformResourceGenerator import dev.icerock.gradle.generator.addAppleContainerBundleProperty import dev.icerock.gradle.metadata.resource.ColorMetadata @@ -27,12 +27,12 @@ internal class AppleColorResourceGenerator( return CodeBlock.of( "ColorResource(name = %S, bundle = %L)", metadata.key, - CodeConst.Apple.containerBundlePropertyName + Constants.Apple.containerBundlePropertyName ) } override fun generateResourceFiles(data: List) { - val assetsDirectory = File(assetsGenerationDir, CodeConst.Apple.assetsDirectoryName) + val assetsDirectory = File(assetsGenerationDir, Constants.Apple.assetsDirectoryName) data.forEach { imageMetadata -> val assetDir = File(assetsDirectory, "${imageMetadata.key}.colorset") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/ColorResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/ColorResourceGenerator.kt index 32ab0dfe6..ed13a9021 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/ColorResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/ColorResourceGenerator.kt @@ -5,7 +5,7 @@ package dev.icerock.gradle.generator.resources.color import com.squareup.kotlinpoet.PropertySpec -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.ResourceGenerator import dev.icerock.gradle.metadata.resource.ColorMetadata import org.gradle.api.GradleException @@ -93,7 +93,7 @@ internal class ColorResourceGenerator : ResourceGenerator { } override fun generateProperty(metadata: ColorMetadata): PropertySpec.Builder { - return PropertySpec.builder(metadata.key, CodeConst.colorResourceName) + return PropertySpec.builder(metadata.key, Constants.colorResourceName) } private fun Map.parseColor(color: String): String { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/JsColorResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/JsColorResourceGenerator.kt index ed4184b8b..c5506e320 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/JsColorResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/JsColorResourceGenerator.kt @@ -10,12 +10,12 @@ import com.squareup.kotlinpoet.FunSpec import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.PlatformResourceGenerator import dev.icerock.gradle.metadata.resource.ColorMetadata internal class JsColorResourceGenerator : PlatformResourceGenerator { - override fun imports(): List = listOf(CodeConst.graphicsColorName) + override fun imports(): List = listOf(Constants.graphicsColorName) override fun generateInitializer(metadata: ColorMetadata): CodeBlock { return createColorResourceCodeInitializer(metadata) @@ -34,7 +34,7 @@ internal class JsColorResourceGenerator : PlatformResourceGenerator { - override fun imports(): List = listOf(CodeConst.graphicsColorName) + override fun imports(): List = listOf(Constants.graphicsColorName) override fun generateInitializer(metadata: ColorMetadata): CodeBlock { return createColorResourceCodeInitializer(metadata) @@ -28,15 +27,6 @@ internal class JvmColorResourceGenerator( builder: TypeSpec.Builder, metadata: List ) { - // FIXME duplication - val classLoaderProperty: PropertySpec = PropertySpec.builder( - CodeConst.Jvm.resourcesClassLoaderPropertyName, - CodeConst.Jvm.classLoaderName, - KModifier.OVERRIDE - ) - .initializer(CodeBlock.of(className + "." + CodeConst.Jvm.resourcesClassLoaderPropertyName)) - .build() - - builder.addProperty(classLoaderProperty) + builder.addJvmResourcesClassLoaderProperty(className) } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/AppleFileResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/AppleFileResourceGenerator.kt index 514762a32..152cd300b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/AppleFileResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/AppleFileResourceGenerator.kt @@ -7,7 +7,7 @@ package dev.icerock.gradle.generator.resources.file import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.PlatformResourceGenerator import dev.icerock.gradle.generator.addAppleContainerBundleProperty import dev.icerock.gradle.metadata.resource.FileMetadata @@ -23,7 +23,7 @@ internal class AppleFileResourceGenerator( "FileResource(fileName = %S, extension = %S, bundle = %L)", metadata.filePath.nameWithoutExtension, metadata.filePath.extension, - CodeConst.Apple.containerBundlePropertyName + Constants.Apple.containerBundlePropertyName ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/FileResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/FileResourceGenerator.kt index 6d14f2679..e69964d5d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/FileResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/FileResourceGenerator.kt @@ -5,7 +5,7 @@ package dev.icerock.gradle.generator.resources.file import com.squareup.kotlinpoet.PropertySpec -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.ResourceGenerator import dev.icerock.gradle.metadata.resource.FileMetadata import java.io.File @@ -22,7 +22,7 @@ internal class FileResourceGenerator : ResourceGenerator { } override fun generateProperty(metadata: FileMetadata): PropertySpec.Builder { - return PropertySpec.builder(metadata.key, CodeConst.fileResourceName) + return PropertySpec.builder(metadata.key, Constants.fileResourceName) } // TODO commonize? diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/JsFileResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/JsFileResourceGenerator.kt index adbee1add..d6fcdbd43 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/JsFileResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/JsFileResourceGenerator.kt @@ -10,7 +10,7 @@ import com.squareup.kotlinpoet.FunSpec import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.PlatformResourceGenerator import dev.icerock.gradle.metadata.resource.FileMetadata import java.io.File @@ -50,7 +50,7 @@ internal class JsFileResourceGenerator( .addStatement("return listOf($values)") .returns( ClassName("kotlin.collections", "List") - .parameterizedBy(CodeConst.fileResourceName) + .parameterizedBy(Constants.fileResourceName) ) .build() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/JvmFileResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/JvmFileResourceGenerator.kt index 0679fa6c5..70450c5ed 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/JvmFileResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/JvmFileResourceGenerator.kt @@ -6,13 +6,11 @@ package dev.icerock.gradle.generator.resources.file import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.generator.addJvmResourcesClassLoaderProperty import dev.icerock.gradle.metadata.resource.FileMetadata -import dev.icerock.gradle.metadata.resource.FontMetadata import java.io.File internal class JvmFileResourceGenerator( @@ -24,7 +22,7 @@ internal class JvmFileResourceGenerator( override fun generateInitializer(metadata: FileMetadata): CodeBlock { return CodeBlock.of( "FileResource(resourcesClassLoader = %L, filePath = %S)", - CodeConst.Jvm.resourcesClassLoaderPropertyName, + Constants.Jvm.resourcesClassLoaderPropertyName, "$FILES_DIR/${metadata.filePath.name}" ) } @@ -42,16 +40,7 @@ internal class JvmFileResourceGenerator( builder: TypeSpec.Builder, metadata: List ) { - // FIXME duplication - val classLoaderProperty: PropertySpec = PropertySpec.builder( - CodeConst.Jvm.resourcesClassLoaderPropertyName, - CodeConst.Jvm.classLoaderName, - KModifier.OVERRIDE - ) - .initializer(CodeBlock.of(className + "." + CodeConst.Jvm.resourcesClassLoaderPropertyName)) - .build() - - builder.addProperty(classLoaderProperty) + builder.addJvmResourcesClassLoaderProperty(className) } private companion object { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/AppleFontResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/AppleFontResourceGenerator.kt index 513106fc4..7c702894e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/AppleFontResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/AppleFontResourceGenerator.kt @@ -7,7 +7,7 @@ package dev.icerock.gradle.generator.resources.font import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.PlatformResourceGenerator import dev.icerock.gradle.generator.addAppleContainerBundleProperty import dev.icerock.gradle.metadata.resource.FontMetadata @@ -22,7 +22,7 @@ internal class AppleFontResourceGenerator( return CodeBlock.of( "FontResource(fontName = %S, bundle = %L)", metadata.filePath.name, - CodeConst.Apple.containerBundlePropertyName + Constants.Apple.containerBundlePropertyName ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/FontResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/FontResourceGenerator.kt index 964bfce3f..1a46d42fa 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/FontResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/FontResourceGenerator.kt @@ -5,7 +5,7 @@ package dev.icerock.gradle.generator.resources.font import com.squareup.kotlinpoet.PropertySpec -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.ResourceGenerator import dev.icerock.gradle.metadata.resource.FontMetadata import java.io.File @@ -22,6 +22,6 @@ internal class FontResourceGenerator : ResourceGenerator { } override fun generateProperty(metadata: FontMetadata): PropertySpec.Builder { - return PropertySpec.builder(metadata.key, CodeConst.fontResourceName) + return PropertySpec.builder(metadata.key, Constants.fontResourceName) } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/JsFontResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/JsFontResourceGenerator.kt index 0f8dcdb60..52de9a7d8 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/JsFontResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/JsFontResourceGenerator.kt @@ -10,7 +10,7 @@ import com.squareup.kotlinpoet.FunSpec import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.PlatformResourceGenerator import dev.icerock.gradle.metadata.resource.FontMetadata import dev.icerock.gradle.utils.flatName @@ -69,7 +69,7 @@ internal class JsFontResourceGenerator( .addStatement("return listOf($languageKeysList)") .returns( ClassName("kotlin.collections", "List") - .parameterizedBy(CodeConst.fontResourceName) + .parameterizedBy(Constants.fontResourceName) ) .build() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/JvmFontResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/JvmFontResourceGenerator.kt index 1ddd98492..47ff4197d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/JvmFontResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/JvmFontResourceGenerator.kt @@ -6,11 +6,10 @@ package dev.icerock.gradle.generator.resources.font import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.generator.addJvmResourcesClassLoaderProperty import dev.icerock.gradle.metadata.resource.FontMetadata import java.io.File @@ -23,7 +22,7 @@ internal class JvmFontResourceGenerator( override fun generateInitializer(metadata: FontMetadata): CodeBlock { return CodeBlock.of( "FontResource(resourcesClassLoader = %L, filePath = %S)", - CodeConst.Jvm.resourcesClassLoaderPropertyName, + Constants.Jvm.resourcesClassLoaderPropertyName, "$FONTS_DIR/${metadata.filePath.name}" ) } @@ -41,16 +40,7 @@ internal class JvmFontResourceGenerator( builder: TypeSpec.Builder, metadata: List ) { - // FIXME duplication - val classLoaderProperty: PropertySpec = PropertySpec.builder( - CodeConst.Jvm.resourcesClassLoaderPropertyName, - CodeConst.Jvm.classLoaderName, - KModifier.OVERRIDE - ) - .initializer(CodeBlock.of(className + "." + CodeConst.Jvm.resourcesClassLoaderPropertyName)) - .build() - - builder.addProperty(classLoaderProperty) + builder.addJvmResourcesClassLoaderProperty(className) } private companion object { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/AppleImageResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/AppleImageResourceGenerator.kt index e2f9fb269..c0cf07310 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/AppleImageResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/AppleImageResourceGenerator.kt @@ -7,7 +7,7 @@ package dev.icerock.gradle.generator.resources.image import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.PlatformResourceGenerator import dev.icerock.gradle.generator.addAppleContainerBundleProperty import dev.icerock.gradle.metadata.resource.ImageMetadata @@ -27,12 +27,12 @@ internal class AppleImageResourceGenerator( return CodeBlock.of( "ImageResource(assetImageName = %S, bundle = %L)", metadata.key, - CodeConst.Apple.containerBundlePropertyName + Constants.Apple.containerBundlePropertyName ) } override fun generateResourceFiles(data: List) { - val assetsDirectory = File(assetsGenerationDir, CodeConst.Apple.assetsDirectoryName) + val assetsDirectory = File(assetsGenerationDir, Constants.Apple.assetsDirectoryName) data.forEach { imageMetadata -> val assetDir = File(assetsDirectory, "${imageMetadata.key}.imageset") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/ImageResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/ImageResourceGenerator.kt index 20ff05c4e..de5d0b76d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/ImageResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/ImageResourceGenerator.kt @@ -5,7 +5,7 @@ package dev.icerock.gradle.generator.resources.image import com.squareup.kotlinpoet.PropertySpec -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.ResourceGenerator import dev.icerock.gradle.metadata.resource.ImageMetadata import dev.icerock.gradle.utils.nameWithoutScale @@ -30,7 +30,7 @@ internal class ImageResourceGenerator : ResourceGenerator { } override fun generateProperty(metadata: ImageMetadata): PropertySpec.Builder { - return PropertySpec.builder(metadata.key, CodeConst.imageResourceName) + return PropertySpec.builder(metadata.key, Constants.imageResourceName) } private fun extractKey(file: File): String { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/JsImageResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/JsImageResourceGenerator.kt index e00b647dc..f9a2fb985 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/JsImageResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/JsImageResourceGenerator.kt @@ -10,7 +10,7 @@ import com.squareup.kotlinpoet.FunSpec import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.PlatformResourceGenerator import dev.icerock.gradle.metadata.resource.ImageMetadata import java.io.File @@ -51,7 +51,7 @@ internal class JsImageResourceGenerator( .addStatement("return listOf($languageKeysList)") .returns( ClassName("kotlin.collections", "List") - .parameterizedBy(CodeConst.imageResourceName) + .parameterizedBy(Constants.imageResourceName) ) .build() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/JvmImageResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/JvmImageResourceGenerator.kt index 56509d5cc..f083c591e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/JvmImageResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/JvmImageResourceGenerator.kt @@ -6,11 +6,10 @@ package dev.icerock.gradle.generator.resources.image import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.generator.addJvmResourcesClassLoaderProperty import dev.icerock.gradle.metadata.resource.ImageMetadata import java.io.File @@ -25,7 +24,7 @@ internal class JvmImageResourceGenerator( val fileName = "${metadata.key}.${item.filePath.extension}" return CodeBlock.of( "ImageResource(resourcesClassLoader = %L, filePath = %S)", - CodeConst.Jvm.resourcesClassLoaderPropertyName, + Constants.Jvm.resourcesClassLoaderPropertyName, "$IMAGES_DIR/${fileName}" ) } @@ -38,16 +37,7 @@ internal class JvmImageResourceGenerator( builder: TypeSpec.Builder, metadata: List ) { - // FIXME duplication - val classLoaderProperty: PropertySpec = PropertySpec.builder( - CodeConst.Jvm.resourcesClassLoaderPropertyName, - CodeConst.Jvm.classLoaderName, - KModifier.OVERRIDE - ) - .initializer(CodeBlock.of(className + "." + CodeConst.Jvm.resourcesClassLoaderPropertyName)) - .build() - - builder.addProperty(classLoaderProperty) + builder.addJvmResourcesClassLoaderProperty(className) } private companion object { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/ApplePluralResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/ApplePluralResourceGenerator.kt index 4a3f09bbf..a8f0780da 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/ApplePluralResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/ApplePluralResourceGenerator.kt @@ -7,7 +7,7 @@ package dev.icerock.gradle.generator.resources.plural import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.PlatformResourceGenerator import dev.icerock.gradle.generator.addAppleContainerBundleProperty import dev.icerock.gradle.generator.localization.LanguageType @@ -24,7 +24,7 @@ internal class ApplePluralResourceGenerator( return CodeBlock.of( "PluralsResource(resourceId = %S, bundle = %L)", metadata.key, - CodeConst.Apple.containerBundlePropertyName + Constants.Apple.containerBundlePropertyName ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/JsPluralResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/JsPluralResourceGenerator.kt index f6c42a97e..493290709 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/JsPluralResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/JsPluralResourceGenerator.kt @@ -10,7 +10,7 @@ import com.squareup.kotlinpoet.FunSpec import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.PlatformResourceGenerator import dev.icerock.gradle.generator.addJsContainerStringsLoaderProperty import dev.icerock.gradle.generator.addJsFallbackProperty @@ -35,7 +35,7 @@ internal class JsPluralResourceGenerator( return CodeBlock.of( "PluralsResource(key = %S, loader = %L)", metadata.key, - CodeConst.Js.stringsLoaderPropertyName + Constants.Js.stringsLoaderPropertyName ) } @@ -52,7 +52,7 @@ internal class JsPluralResourceGenerator( builder: TypeSpec.Builder, metadata: List ) { - builder.addSuperinterface(CodeConst.Js.loaderHolderName) + builder.addSuperinterface(Constants.Js.loaderHolderName) builder.addJsFallbackProperty( fallbackFilePath = LOCALIZATION_DIR + "/" + getFileNameForLanguage(LanguageType.Base) @@ -82,7 +82,7 @@ internal class JsPluralResourceGenerator( .addStatement("return listOf($languageKeysList)") .returns( ClassName("kotlin.collections", "List") - .parameterizedBy(CodeConst.pluralsResourceName) + .parameterizedBy(Constants.pluralsResourceName) ) .build() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/JvmPluralResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/JvmPluralResourceGenerator.kt index 456072006..b6a89b5d3 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/JvmPluralResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/JvmPluralResourceGenerator.kt @@ -10,8 +10,9 @@ import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.STRING import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.generator.addJvmResourcesClassLoaderProperty import dev.icerock.gradle.generator.localization.LanguageType import dev.icerock.gradle.metadata.resource.PluralMetadata import org.apache.commons.text.StringEscapeUtils @@ -27,7 +28,7 @@ internal class JvmPluralResourceGenerator( override fun generateInitializer(metadata: PluralMetadata): CodeBlock { return CodeBlock.of( "PluralsResource(resourcesClassLoader = %L, bundleName = %L, key = %S)", - CodeConst.Jvm.resourcesClassLoaderPropertyName, + Constants.Jvm.resourcesClassLoaderPropertyName, pluralsBundlePropertyName, metadata.key ) @@ -46,23 +47,14 @@ internal class JvmPluralResourceGenerator( builder: TypeSpec.Builder, metadata: List ) { - // FIXME duplication - val classLoaderProperty: PropertySpec = PropertySpec.builder( - CodeConst.Jvm.resourcesClassLoaderPropertyName, - CodeConst.Jvm.classLoaderName, - KModifier.OVERRIDE - ) - .initializer(CodeBlock.of(className + "." + CodeConst.Jvm.resourcesClassLoaderPropertyName)) - .build() - - builder.addProperty(classLoaderProperty) + builder.addJvmResourcesClassLoaderProperty(className) // FIXME duplication val property: PropertySpec = PropertySpec.builder( pluralsBundlePropertyName, STRING, KModifier.PRIVATE - ).initializer(CodeBlock.of("\"%L/%L\"", CodeConst.Jvm.localizationDir, getBundlePath())) + ).initializer(CodeBlock.of("\"%L/%L\"", Constants.Jvm.localizationDir, getBundlePath())) .build() builder.addProperty(property) @@ -74,7 +66,7 @@ internal class JvmPluralResourceGenerator( ) { val fileDirName = "${getBundlePath()}${language.jvmResourcesSuffix}" - val localizationDir = File(resourcesGenerationDir, CodeConst.Jvm.localizationDir) + val localizationDir = File(resourcesGenerationDir, Constants.Jvm.localizationDir) localizationDir.mkdirs() val stringsFile = File(localizationDir, "$fileDirName.properties") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/PluralResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/PluralResourceGenerator.kt index 407a2e888..ef65b5547 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/PluralResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/PluralResourceGenerator.kt @@ -5,7 +5,7 @@ package dev.icerock.gradle.generator.resources.plural import com.squareup.kotlinpoet.PropertySpec -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.ResourceGenerator import dev.icerock.gradle.generator.localization.LanguageType import dev.icerock.gradle.metadata.resource.PluralMetadata @@ -56,7 +56,7 @@ internal class PluralResourceGenerator( } override fun generateProperty(metadata: PluralMetadata): PropertySpec.Builder { - return PropertySpec.builder(metadata.key, CodeConst.pluralsResourceName) + return PropertySpec.builder(metadata.key, Constants.pluralsResourceName) } private fun loadLanguageStrings(stringsFile: File): Map { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/AppleStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/AppleStringResourceGenerator.kt index cc5f17a95..3c647f4dc 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/AppleStringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/AppleStringResourceGenerator.kt @@ -7,7 +7,7 @@ package dev.icerock.gradle.generator.resources.string import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.PlatformResourceGenerator import dev.icerock.gradle.generator.addAppleContainerBundleProperty import dev.icerock.gradle.generator.localization.LanguageType @@ -25,7 +25,7 @@ internal class AppleStringResourceGenerator( return CodeBlock.of( "StringResource(resourceId = %S, bundle = %L)", metadata.key, - CodeConst.Apple.containerBundlePropertyName + Constants.Apple.containerBundlePropertyName ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/JsStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/JsStringResourceGenerator.kt index 3e8fd8aeb..a616cc44d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/JsStringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/JsStringResourceGenerator.kt @@ -10,13 +10,13 @@ import com.squareup.kotlinpoet.FunSpec import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.platform.js.convertToMessageFormat -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.PlatformResourceGenerator import dev.icerock.gradle.generator.addJsContainerStringsLoaderProperty import dev.icerock.gradle.generator.addJsFallbackProperty import dev.icerock.gradle.generator.addJsSupportedLocalesProperty import dev.icerock.gradle.generator.localization.LanguageType +import dev.icerock.gradle.generator.platform.js.convertToMessageFormat import dev.icerock.gradle.metadata.resource.StringMetadata import dev.icerock.gradle.utils.flatName import kotlinx.serialization.json.buildJsonObject @@ -35,7 +35,7 @@ internal class JsStringResourceGenerator( return CodeBlock.of( "StringResource(key = %S, loader = %L)", metadata.key, - CodeConst.Js.stringsLoaderPropertyName + Constants.Js.stringsLoaderPropertyName ) } @@ -52,7 +52,7 @@ internal class JsStringResourceGenerator( builder: TypeSpec.Builder, metadata: List ) { - builder.addSuperinterface(CodeConst.Js.loaderHolderName) + builder.addSuperinterface(Constants.Js.loaderHolderName) builder.addJsFallbackProperty( fallbackFilePath = LOCALIZATION_DIR + "/" + getFileNameForLanguage(LanguageType.Base) @@ -82,7 +82,7 @@ internal class JsStringResourceGenerator( .addStatement("return listOf($languageKeysList)") .returns( ClassName("kotlin.collections", "List") - .parameterizedBy(CodeConst.stringResourceName) + .parameterizedBy(Constants.stringResourceName) ) .build() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/JvmStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/JvmStringResourceGenerator.kt index b8a45c617..af88ca135 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/JvmStringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/JvmStringResourceGenerator.kt @@ -10,8 +10,9 @@ import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.STRING import com.squareup.kotlinpoet.TypeSpec -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.generator.addJvmResourcesClassLoaderProperty import dev.icerock.gradle.generator.localization.LanguageType import dev.icerock.gradle.metadata.resource.StringMetadata import org.apache.commons.text.StringEscapeUtils @@ -27,7 +28,7 @@ internal class JvmStringResourceGenerator( override fun generateInitializer(metadata: StringMetadata): CodeBlock { return CodeBlock.of( "StringResource(resourcesClassLoader = %L, bundleName = %L, key = %S)", - CodeConst.Jvm.resourcesClassLoaderPropertyName, + Constants.Jvm.resourcesClassLoaderPropertyName, stringsBundlePropertyName, metadata.key ) @@ -46,23 +47,14 @@ internal class JvmStringResourceGenerator( builder: TypeSpec.Builder, metadata: List ) { - // FIXME duplication - val classLoaderProperty: PropertySpec = PropertySpec.builder( - CodeConst.Jvm.resourcesClassLoaderPropertyName, - CodeConst.Jvm.classLoaderName, - KModifier.OVERRIDE - ) - .initializer(CodeBlock.of(className + "." + CodeConst.Jvm.resourcesClassLoaderPropertyName)) - .build() - - builder.addProperty(classLoaderProperty) + builder.addJvmResourcesClassLoaderProperty(className) // FIXME duplication val property: PropertySpec = PropertySpec.builder( stringsBundlePropertyName, STRING, KModifier.PRIVATE - ).initializer(CodeBlock.of("\"%L/%L\"", CodeConst.Jvm.localizationDir, getBundlePath())) + ).initializer(CodeBlock.of("\"%L/%L\"", Constants.Jvm.localizationDir, getBundlePath())) .build() builder.addProperty(property) @@ -71,7 +63,7 @@ internal class JvmStringResourceGenerator( private fun generateLanguageFile(language: LanguageType, strings: Map) { val fileDirName = "${getBundlePath()}${language.jvmResourcesSuffix}" - val localizationDir = File(resourcesGenerationDir, CodeConst.Jvm.localizationDir) + val localizationDir = File(resourcesGenerationDir, Constants.Jvm.localizationDir) localizationDir.mkdirs() val stringsFile = File(localizationDir, "$fileDirName.properties") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/StringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/StringResourceGenerator.kt index 84bb2ed77..0e0cdaa91 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/StringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/StringResourceGenerator.kt @@ -5,7 +5,7 @@ package dev.icerock.gradle.generator.resources.string import com.squareup.kotlinpoet.PropertySpec -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.ResourceGenerator import dev.icerock.gradle.generator.exceptions.EqualStringKeysException import dev.icerock.gradle.generator.localization.LanguageType @@ -50,7 +50,7 @@ internal class StringResourceGenerator( } override fun generateProperty(metadata: StringMetadata): PropertySpec.Builder { - return PropertySpec.builder(metadata.key, CodeConst.stringResourceName) + return PropertySpec.builder(metadata.key, Constants.stringResourceName) } private fun loadLanguageStrings(stringsFile: File): Map { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsMRGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsMRGenerator.kt deleted file mode 100644 index 01eb8bc41..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/oldgen/js/JsMRGenerator.kt +++ /dev/null @@ -1,33 +0,0 @@ -// override fun processMRClass(mrClass: TypeSpec.Builder) { -// val stringsLoaderInitializer = buildList { -// val stringsObjectLoader = mrClass -// .typeSpecs -// .find { it.name == "strings" } -// ?.propertySpecs -// ?.find { it.name == "stringsLoader" } -// -// val pluralsObjectLoader = mrClass -// .typeSpecs -// .find { it.name == "plurals" } -// ?.propertySpecs -// ?.find { it.name == "stringsLoader" } -// -// if (stringsObjectLoader != null) { -// add("strings.stringsLoader") -// } -// if (pluralsObjectLoader != null) { -// add("plurals.stringsLoader") -// } -// }.takeIf(List<*>::isNotEmpty) -// ?.joinToString(separator = " + ") -// -// if (stringsLoaderInitializer != null) { -// mrClass.addProperty( -// PropertySpec.builder( -// "stringsLoader", -// ClassName("dev.icerock.moko.resources.provider", "RemoteJsStringLoader"), -// ).initializer(stringsLoaderInitializer) -// .build() -// ) -// } -// } 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 4f3fa4762..2df912d30 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 @@ -5,13 +5,14 @@ package dev.icerock.gradle.tasks import dev.icerock.gradle.MRVisibility -import dev.icerock.gradle.generator.CodeConst +import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.PlatformContainerGenerator import dev.icerock.gradle.generator.PlatformResourceGenerator import dev.icerock.gradle.generator.ResourceTypeGenerator import dev.icerock.gradle.generator.ResourcesFiles import dev.icerock.gradle.generator.ResourcesGenerator import dev.icerock.gradle.generator.container.AppleContainerGenerator +import dev.icerock.gradle.generator.container.JsContainerGenerator import dev.icerock.gradle.generator.container.JvmContainerGenerator import dev.icerock.gradle.generator.container.NOPContainerGenerator import dev.icerock.gradle.generator.resources.NOPResourceGenerator @@ -94,8 +95,14 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { @get:Input abstract val sourceSetName: Property + // not used directly in code, but required to outdate cache of target tasks when resources + // changed @get:InputFiles - @get:Classpath + @get:PathSensitive(PathSensitivity.RELATIVE) + abstract val lowerResources: ConfigurableFileCollection + + @get:InputFiles + @get:PathSensitive(PathSensitivity.RELATIVE) abstract val ownResources: ConfigurableFileCollection @get:Input @@ -136,7 +143,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { abstract val outputMetadataFile: RegularFileProperty @get:Optional - @get:PathSensitive(PathSensitivity.ABSOLUTE) + @get:PathSensitive(PathSensitivity.RELATIVE) @get:InputFiles abstract val inputMetadataFiles: ConfigurableFileCollection @@ -230,7 +237,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { konanTarget = ::kotlinKonanTarget, createCommon = { NOPContainerGenerator() }, createAndroid = { NOPContainerGenerator() }, - createJs = { NOPContainerGenerator() }, + createJs = { JsContainerGenerator() }, createApple = { AppleContainerGenerator( bundleIdentifier = "${resourcesPackageName.get()}.MR" @@ -247,7 +254,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { private fun createStringGenerator(): ResourceTypeGenerator { return ResourceTypeGenerator( generationPackage = resourcesPackageName.get(), - resourceClass = CodeConst.stringResourceName, + resourceClass = Constants.stringResourceName, resourceType = ResourceType.STRINGS, metadataClass = StringMetadata::class, visibilityModifier = resourcesVisibility.get().toModifier(), @@ -262,7 +269,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { private fun createPluralsGenerator(): ResourceTypeGenerator { return ResourceTypeGenerator( generationPackage = resourcesPackageName.get(), - resourceClass = CodeConst.pluralsResourceName, + resourceClass = Constants.pluralsResourceName, resourceType = ResourceType.PLURALS, metadataClass = PluralMetadata::class, visibilityModifier = resourcesVisibility.get().toModifier(), @@ -277,7 +284,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { private fun createImagesGenerator(): ResourceTypeGenerator { return ResourceTypeGenerator( generationPackage = resourcesPackageName.get(), - resourceClass = CodeConst.imageResourceName, + resourceClass = Constants.imageResourceName, resourceType = ResourceType.IMAGES, metadataClass = ImageMetadata::class, visibilityModifier = resourcesVisibility.get().toModifier(), @@ -292,7 +299,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { private fun createColorsGenerator(): ResourceTypeGenerator { return ResourceTypeGenerator( generationPackage = resourcesPackageName.get(), - resourceClass = CodeConst.colorResourceName, + resourceClass = Constants.colorResourceName, resourceType = ResourceType.COLORS, metadataClass = ColorMetadata::class, visibilityModifier = resourcesVisibility.get().toModifier(), @@ -305,7 +312,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { private fun createFontsGenerator(): ResourceTypeGenerator { return ResourceTypeGenerator( generationPackage = resourcesPackageName.get(), - resourceClass = CodeConst.fontResourceName, + resourceClass = Constants.fontResourceName, resourceType = ResourceType.FONTS, metadataClass = FontMetadata::class, visibilityModifier = resourcesVisibility.get().toModifier(), @@ -318,7 +325,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { private fun createFilesGenerator(): ResourceTypeGenerator { return ResourceTypeGenerator( generationPackage = resourcesPackageName.get(), - resourceClass = CodeConst.fileResourceName, + resourceClass = Constants.fileResourceName, resourceType = ResourceType.FILES, metadataClass = FileMetadata::class, visibilityModifier = resourcesVisibility.get().toModifier(), @@ -331,7 +338,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { private fun createAssetsGenerator(): ResourceTypeGenerator { return ResourceTypeGenerator( generationPackage = resourcesPackageName.get(), - resourceClass = CodeConst.assetResourceName, + resourceClass = Constants.assetResourceName, resourceType = ResourceType.ASSETS, metadataClass = AssetMetadata::class, visibilityModifier = resourcesVisibility.get().toModifier(), diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/FileExt.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/FileExt.kt index 6d263d9a6..a71b574d2 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/FileExt.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/FileExt.kt @@ -7,14 +7,17 @@ package dev.icerock.gradle.utils import java.io.File import org.jetbrains.kotlin.konan.file.File as KonanFile -internal val File.svg: Boolean get() = - extension.equals("svg", ignoreCase = true) +internal val File.svg: Boolean + get() = + extension.equals("svg", ignoreCase = true) -internal val File.scale: String get() = - nameWithoutExtension.substringAfter("@").substringBefore("x") +internal val File.scale: String + get() = + nameWithoutExtension.substringAfter("@").substringBefore("x") -internal val File.nameWithoutScale: String get() = - nameWithoutExtension.withoutScale +internal val File.nameWithoutScale: String + get() = + nameWithoutExtension.withoutScale internal val File.targetName: String get() = parentFile.parentFile.parentFile.name From da4c313d7417677a0654a7d8506858ef241d4312 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Wed, 10 Jan 2024 22:39:24 +0700 Subject: [PATCH 102/352] #535 detekt fixes --- .../gradle/MultiplatformResourcesPlugin.kt | 1 + .../MultiplatformResourcesPluginExtension.kt | 1 + .../apple/PackAppleResourcesToKLibAction.kt | 46 +- .../js/CopyResourcesToExecutableAction.kt | 6 +- .../dev/icerock/gradle/generator/Constants.kt | 7 +- .../gradle/generator/ResourceTypeGenerator.kt | 20 +- .../gradle/generator/ResourcesGenerator.kt | 16 +- .../factory/AssetGeneratorFactory.kt | 88 ++++ .../factory/ColorGeneratorFactory.kt | 76 +++ .../generator/factory/FileGeneratorFactory.kt | 78 +++ .../generator/factory/FontGeneratorFactory.kt | 79 +++ .../factory/ImageGeneratorFactory.kt | 84 ++++ .../factory/PluralGeneratorFactory.kt | 86 ++++ .../factory/StringGeneratorFactory.kt | 86 ++++ .../platform/apple/SetupAppleUtils.kt | 31 +- .../color/AppleColorResourceGenerator.kt | 1 + .../resources/color/ColorResourceGenerator.kt | 10 +- .../gradle/generator/resources/color/Utils.kt | 1 - .../resources/font/JsFontResourceGenerator.kt | 2 +- .../image/AndroidImageResourceGenerator.kt | 7 +- .../resources/image/ImageResourceGenerator.kt | 2 +- .../image/JvmImageResourceGenerator.kt | 2 +- .../plural/JvmPluralResourceGenerator.kt | 2 +- .../string/JvmStringResourceGenerator.kt | 2 +- .../metadata/resource/ResourceMetadata.kt | 8 +- .../GenerateMultiplatformResourcesTask.kt | 463 +++--------------- .../dev/icerock/gradle/utils/ArgbColor.kt | 25 - .../dev/icerock/gradle/utils/FileExt.kt | 3 - .../gradle/utils/KotlinCompilationExt.kt | 3 - .../gradle/utils/ProcessResourcesUtils.kt | 28 -- .../dev/icerock/gradle/utils/ProjectExt.kt | 1 - .../icerock/gradle/utils/createByPlatform.kt | 3 + 32 files changed, 756 insertions(+), 512 deletions(-) create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/AssetGeneratorFactory.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/ColorGeneratorFactory.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/FileGeneratorFactory.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/FontGeneratorFactory.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/ImageGeneratorFactory.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/PluralGeneratorFactory.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/StringGeneratorFactory.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ArgbColor.kt delete mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProcessResourcesUtils.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 30a333b8c..074df35a8 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -63,6 +63,7 @@ open class MultiplatformResourcesPlugin : Plugin { } } + @Suppress("LongMethod") private fun configureKotlinTargetGenerator( project: Project, mrExtension: MultiplatformResourcesPluginExtension, 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 2a8287f6e..190bcf5ed 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPluginExtension.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPluginExtension.kt @@ -7,6 +7,7 @@ package dev.icerock.gradle import org.gradle.api.Project import org.gradle.api.provider.Property +@Suppress("UnnecessaryAbstractClass") abstract class MultiplatformResourcesPluginExtension { abstract val resourcesPackage: Property abstract val resourcesClassName: Property diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/PackAppleResourcesToKLibAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/PackAppleResourcesToKLibAction.kt index dc628ea81..5ca24ee85 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/PackAppleResourcesToKLibAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/PackAppleResourcesToKLibAction.kt @@ -79,23 +79,7 @@ internal class PackAppleResourcesToKLibAction( val rawAssetsDir = File(loadableBundle.resourcesDir, Constants.Apple.assetsDirectoryName) if (rawAssetsDir.exists()) { - val process: Process = Runtime.getRuntime().exec( - "xcrun actool ${rawAssetsDir.name} --compile . --platform iphoneos --minimum-deployment-target ${acToolMinimalDeploymentTarget.get()}", - emptyArray(), - rawAssetsDir.parentFile - ) - val errors: String = process.errorStream.bufferedReader().readText() - val input: String = process.inputStream.bufferedReader().readText() - val result: Int = process.waitFor() - if (result != 0) { - task.logger.error("can't compile assets - $result") - task.logger.info(input) - task.logger.error(errors) - throw GradleException("Assets compilation failed: $errors") - } else { - task.logger.info("assets compiled") - rawAssetsDir.deleteRecursively() - } + compileAppleAssets(rawAssetsDir, task) } else { task.logger.info("assets not found, compilation not required") } @@ -108,4 +92,32 @@ internal class PackAppleResourcesToKLibAction( repackDir.deleteRecursively() } + + private fun compileAppleAssets( + rawAssetsDir: File, + task: KotlinNativeCompile + ) { + val process: Process = Runtime.getRuntime().exec( + buildString { + append("xcrun actool ") + append(rawAssetsDir.name) + append(" --compile . --platform iphoneos --minimum-deployment-target ") + append(acToolMinimalDeploymentTarget.get()) + }, + emptyArray(), + rawAssetsDir.parentFile + ) + val errors: String = process.errorStream.bufferedReader().readText() + val input: String = process.inputStream.bufferedReader().readText() + val result: Int = process.waitFor() + if (result != 0) { + task.logger.error("can't compile assets - $result") + task.logger.info(input) + task.logger.error(errors) + throw GradleException("Assets compilation failed: $errors") + } else { + task.logger.info("assets compiled") + rawAssetsDir.deleteRecursively() + } + } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/js/CopyResourcesToExecutableAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/js/CopyResourcesToExecutableAction.kt index 3f1a37faa..92d7a338b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/js/CopyResourcesToExecutableAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/js/CopyResourcesToExecutableAction.kt @@ -86,7 +86,7 @@ internal class CopyResourcesToExecutableAction( config.resolve.modules.push(mokoResourcePath); })(config); - """.trimIndent() + """.trimIndent() ) } @@ -120,7 +120,7 @@ internal class CopyResourcesToExecutableAction( ) } ) - """.trimIndent() + """.trimIndent() ) } @@ -148,4 +148,4 @@ internal class CopyResourcesToExecutableAction( logger.info("resources in $inputFile not found (empty lib)") } } -} \ No newline at end of file +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/Constants.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/Constants.kt index 0257397e6..72e7fcaf3 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/Constants.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/Constants.kt @@ -40,12 +40,11 @@ internal object Constants { val supportedLocaleName = ClassName(internalPackage, "SupportedLocale") val loaderHolderName = ClassName(internalPackage, "RemoteJsStringLoaderHolder") - val stringLoaderName = ClassName( - "dev.icerock.moko.resources.provider", "RemoteJsStringLoader" - ) + val stringLoaderName = + ClassName("dev.icerock.moko.resources.provider", "RemoteJsStringLoader") const val stringsLoaderPropertyName = "stringsLoader" const val fallbackFilePropertyName = "fallbackFileUrl" const val supportedLocalesPropertyName = "supportedLocales" } -} \ No newline at end of file +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceTypeGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceTypeGenerator.kt index 5f7f4ba94..0092a5fea 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceTypeGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourceTypeGenerator.kt @@ -19,6 +19,7 @@ import dev.icerock.gradle.utils.filterClass import org.gradle.api.tasks.util.PatternFilterable import kotlin.reflect.KClass +@Suppress("LongParameterList", "TooManyFunctions") internal class ResourceTypeGenerator( private val generationPackage: String, private val resourceClass: ClassName, @@ -40,8 +41,10 @@ internal class ResourceTypeGenerator( return files.matching(filter).upperSourceSets.mapNotNull { sourceSetResources -> if (sourceSetResources.fileTree.isEmpty) return@mapNotNull null - val interfaceName: String = sourceSetResources.sourceSetName.capitalize() + - resourceType.name.lowercase().capitalize() + val interfaceName: String = buildString { + append(sourceSetResources.sourceSetName.capitalize()) + append(resourceType.name.lowercase().capitalize()) + } GenerationResult( typeSpec = TypeSpec.interfaceBuilder(interfaceName) @@ -76,9 +79,9 @@ internal class ResourceTypeGenerator( // implement ResourceType<**Resource> for extensions .addSuperinterface(Constants.resourceContainerName.parameterizedBy(resourceClass)) // implement interfaces for generated expect object - .addSuperinterfaces(typeInterfaces.map { - ClassName(packageName = generationPackage, it.name) - }) + .addSuperinterfaces( + typeInterfaces.map { ClassName(packageName = generationPackage, it.name) } + ) // add all properties of available resources .addProperties(typeMetadata.map { generator.generateProperty(it).build() }) @@ -141,10 +144,9 @@ internal class ResourceTypeGenerator( // implement ResourceType<**Resource> for extensions .addSuperinterface(Constants.resourceContainerName.parameterizedBy(resourceClass)) // implement interfaces for generated expect object - .addSuperinterfaces(typeInterfaces.map { - ClassName(packageName = generationPackage, it.name) - }) - .also { builder -> + .addSuperinterfaces( + typeInterfaces.map { ClassName(packageName = generationPackage, it.name) } + ).also { builder -> platformResourceGenerator.generateBeforeProperties(builder, resources) } // add all properties of interfaces diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourcesGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourcesGenerator.kt index e8247ecda..5868324da 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourcesGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ResourcesGenerator.kt @@ -15,6 +15,7 @@ import dev.icerock.gradle.metadata.resource.ResourceMetadata import dev.icerock.gradle.utils.calculateHash import java.io.File +@Suppress("LongParameterList") internal class ResourcesGenerator( private val containerGenerator: PlatformContainerGenerator, private val typesGenerators: List>, @@ -24,6 +25,7 @@ internal class ResourcesGenerator( private val visibilityModifier: KModifier, private val sourcesGenerationDir: File ) { + @Suppress("LongMethod") fun generateTargetKotlin( files: ResourcesFiles, inputMetadata: List @@ -103,9 +105,9 @@ internal class ResourcesGenerator( // then we should generate dummy actual interfaces val dummyInterfaces: List = expectInterfaces.map { it.name } - .minus(actualInterfaces.map { (it.metadata as ActualInterfaceMetadata).name } - .toSet()) - .map { dummyInterfaceName -> + .minus( + actualInterfaces.map { (it.metadata as ActualInterfaceMetadata).name }.toSet() + ).map { dummyInterfaceName -> GenerationResult( typeSpec = TypeSpec.interfaceBuilder(dummyInterfaceName) .addModifiers(visibilityModifier) @@ -128,8 +130,12 @@ internal class ResourcesGenerator( val objects: List = typesGenerators.mapNotNull { typeGenerator -> typeGenerator.generateActualObject( objects = inputMetadata.mapNotNull { it as? ObjectMetadata }, - interfaces = inputMetadata.mapNotNull { it as? ActualInterfaceMetadata } + - (actualInterfaces + dummyInterfaces).map { it.metadata as ActualInterfaceMetadata } + interfaces = inputMetadata + .mapNotNull { it as? ActualInterfaceMetadata } + .plus( + (actualInterfaces + dummyInterfaces) + .map { it.metadata as ActualInterfaceMetadata } + ) ) } objects.forEach { outputMetadata.add(it.metadata) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/AssetGeneratorFactory.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/AssetGeneratorFactory.kt new file mode 100644 index 000000000..0f41c55d1 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/AssetGeneratorFactory.kt @@ -0,0 +1,88 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.factory + +import dev.icerock.gradle.MRVisibility +import dev.icerock.gradle.generator.Constants +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.generator.ResourceTypeGenerator +import dev.icerock.gradle.generator.resources.NOPResourceGenerator +import dev.icerock.gradle.generator.resources.asset.AndroidAssetResourceGenerator +import dev.icerock.gradle.generator.resources.asset.AppleAssetResourceGenerator +import dev.icerock.gradle.generator.resources.asset.AssetResourceGenerator +import dev.icerock.gradle.generator.resources.asset.JsAssetResourceGenerator +import dev.icerock.gradle.generator.resources.asset.JvmAssetResourceGenerator +import dev.icerock.gradle.metadata.container.ResourceType +import dev.icerock.gradle.metadata.resource.AssetMetadata +import dev.icerock.gradle.toModifier +import dev.icerock.gradle.utils.createByPlatform +import org.gradle.api.file.ConfigurableFileCollection +import org.gradle.api.internal.file.collections.FileCollectionAdapter +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType +import org.jetbrains.kotlin.konan.target.KonanTarget +import java.io.File + +@Suppress("LongParameterList") +internal class AssetGeneratorFactory( + private val resourcesPackageName: String, + private val resourcesClassName: String, + private val resourcesVisibility: MRVisibility, + private val outputResourcesDir: File, + private val outputAssetsDir: File, + private val kotlinPlatformType: KotlinPlatformType, + private val kotlinKonanTarget: () -> KonanTarget, + private val androidRClassPackage: () -> String, + private val ownResources: ConfigurableFileCollection +) { + fun create(): ResourceTypeGenerator { + return ResourceTypeGenerator( + generationPackage = resourcesPackageName, + resourceClass = Constants.assetResourceName, + resourceType = ResourceType.ASSETS, + metadataClass = AssetMetadata::class, + visibilityModifier = resourcesVisibility.toModifier(), + generator = AssetResourceGenerator( + assetDirs = ownResources.from + .map { it as FileCollectionAdapter } + .flatMap { it.files } + .map { File(it, "assets") } + .toSet() + ), + platformResourceGenerator = createPlatformAssetGenerator(), + filter = { include("assets/**") } + ) + } + + private fun createPlatformAssetGenerator(): PlatformResourceGenerator { + return createByPlatform( + kotlinPlatformType = kotlinPlatformType, + konanTarget = kotlinKonanTarget, + // TODO find way to remove this NOP + createCommon = { NOPResourceGenerator() }, + createAndroid = { + AndroidAssetResourceGenerator( + androidRClassPackage = androidRClassPackage(), + assetsGenerationDir = outputAssetsDir, + ) + }, + createApple = { + AppleAssetResourceGenerator( + resourcesGenerationDir = outputResourcesDir + ) + }, + createJvm = { + JvmAssetResourceGenerator( + className = resourcesClassName, + resourcesGenerationDir = outputResourcesDir + ) + }, + createJs = { + JsAssetResourceGenerator( + resourcesGenerationDir = outputResourcesDir + ) + } + ) + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/ColorGeneratorFactory.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/ColorGeneratorFactory.kt new file mode 100644 index 000000000..41ec85db2 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/ColorGeneratorFactory.kt @@ -0,0 +1,76 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.factory + +import dev.icerock.gradle.MRVisibility +import dev.icerock.gradle.generator.Constants +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.generator.ResourceTypeGenerator +import dev.icerock.gradle.generator.resources.NOPResourceGenerator +import dev.icerock.gradle.generator.resources.color.AndroidColorResourceGenerator +import dev.icerock.gradle.generator.resources.color.AppleColorResourceGenerator +import dev.icerock.gradle.generator.resources.color.ColorResourceGenerator +import dev.icerock.gradle.generator.resources.color.JsColorResourceGenerator +import dev.icerock.gradle.generator.resources.color.JvmColorResourceGenerator +import dev.icerock.gradle.metadata.container.ResourceType +import dev.icerock.gradle.metadata.resource.ColorMetadata +import dev.icerock.gradle.toModifier +import dev.icerock.gradle.utils.createByPlatform +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType +import org.jetbrains.kotlin.konan.target.KonanTarget +import java.io.File + +@Suppress("LongParameterList") +internal class ColorGeneratorFactory( + private val resourcesPackageName: String, + private val resourcesClassName: String, + private val resourcesVisibility: MRVisibility, + private val outputResourcesDir: File, + private val outputAssetsDir: File, + private val kotlinPlatformType: KotlinPlatformType, + private val kotlinKonanTarget: () -> KonanTarget, + private val androidRClassPackage: () -> String, +) { + fun create(): ResourceTypeGenerator { + return ResourceTypeGenerator( + generationPackage = resourcesPackageName, + resourceClass = Constants.colorResourceName, + resourceType = ResourceType.COLORS, + metadataClass = ColorMetadata::class, + visibilityModifier = resourcesVisibility.toModifier(), + generator = ColorResourceGenerator(), + platformResourceGenerator = createPlatformColorGenerator(), + filter = { include("**/colors*.xml") } + ) + } + + private fun createPlatformColorGenerator(): PlatformResourceGenerator { + return createByPlatform( + kotlinPlatformType = kotlinPlatformType, + konanTarget = kotlinKonanTarget, + // TODO find way to remove this NOP + createCommon = { NOPResourceGenerator() }, + createAndroid = { + AndroidColorResourceGenerator( + androidRClassPackage = androidRClassPackage(), + resourcesGenerationDir = outputResourcesDir + ) + }, + createApple = { + AppleColorResourceGenerator( + assetsGenerationDir = outputAssetsDir + ) + }, + createJvm = { + JvmColorResourceGenerator( + className = resourcesClassName + ) + }, + createJs = { + JsColorResourceGenerator() + } + ) + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/FileGeneratorFactory.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/FileGeneratorFactory.kt new file mode 100644 index 000000000..42f0bef73 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/FileGeneratorFactory.kt @@ -0,0 +1,78 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.factory + +import dev.icerock.gradle.MRVisibility +import dev.icerock.gradle.generator.Constants +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.generator.ResourceTypeGenerator +import dev.icerock.gradle.generator.resources.NOPResourceGenerator +import dev.icerock.gradle.generator.resources.file.AndroidFileResourceGenerator +import dev.icerock.gradle.generator.resources.file.AppleFileResourceGenerator +import dev.icerock.gradle.generator.resources.file.FileResourceGenerator +import dev.icerock.gradle.generator.resources.file.JsFileResourceGenerator +import dev.icerock.gradle.generator.resources.file.JvmFileResourceGenerator +import dev.icerock.gradle.metadata.container.ResourceType +import dev.icerock.gradle.metadata.resource.FileMetadata +import dev.icerock.gradle.toModifier +import dev.icerock.gradle.utils.createByPlatform +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType +import org.jetbrains.kotlin.konan.target.KonanTarget +import java.io.File + +@Suppress("LongParameterList") +internal class FileGeneratorFactory( + private val resourcesPackageName: String, + private val resourcesClassName: String, + private val resourcesVisibility: MRVisibility, + private val outputResourcesDir: File, + private val kotlinPlatformType: KotlinPlatformType, + private val kotlinKonanTarget: () -> KonanTarget, + private val androidRClassPackage: () -> String, +) { + fun create(): ResourceTypeGenerator { + return ResourceTypeGenerator( + generationPackage = resourcesPackageName, + resourceClass = Constants.fileResourceName, + resourceType = ResourceType.FILES, + metadataClass = FileMetadata::class, + visibilityModifier = resourcesVisibility.toModifier(), + generator = FileResourceGenerator(), + platformResourceGenerator = createPlatformFileGenerator(), + filter = { include("files/**") } + ) + } + + private fun createPlatformFileGenerator(): PlatformResourceGenerator { + return createByPlatform( + kotlinPlatformType = kotlinPlatformType, + konanTarget = kotlinKonanTarget, + // TODO find way to remove this NOP + createCommon = { NOPResourceGenerator() }, + createAndroid = { + AndroidFileResourceGenerator( + androidRClassPackage = androidRClassPackage(), + resourcesGenerationDir = outputResourcesDir + ) + }, + createApple = { + AppleFileResourceGenerator( + resourcesGenerationDir = outputResourcesDir + ) + }, + createJvm = { + JvmFileResourceGenerator( + className = resourcesClassName, + resourcesGenerationDir = outputResourcesDir + ) + }, + createJs = { + JsFileResourceGenerator( + resourcesGenerationDir = outputResourcesDir + ) + } + ) + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/FontGeneratorFactory.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/FontGeneratorFactory.kt new file mode 100644 index 000000000..abf49fd1c --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/FontGeneratorFactory.kt @@ -0,0 +1,79 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.factory + +import dev.icerock.gradle.MRVisibility +import dev.icerock.gradle.generator.Constants +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.generator.ResourceTypeGenerator +import dev.icerock.gradle.generator.resources.NOPResourceGenerator +import dev.icerock.gradle.generator.resources.font.AndroidFontResourceGenerator +import dev.icerock.gradle.generator.resources.font.AppleFontResourceGenerator +import dev.icerock.gradle.generator.resources.font.FontResourceGenerator +import dev.icerock.gradle.generator.resources.font.JsFontResourceGenerator +import dev.icerock.gradle.generator.resources.font.JvmFontResourceGenerator +import dev.icerock.gradle.metadata.container.ResourceType +import dev.icerock.gradle.metadata.resource.FontMetadata +import dev.icerock.gradle.toModifier +import dev.icerock.gradle.utils.createByPlatform +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType +import org.jetbrains.kotlin.konan.target.KonanTarget +import java.io.File + +@Suppress("LongParameterList") +internal class FontGeneratorFactory( + private val resourcesPackageName: String, + private val resourcesClassName: String, + private val resourcesVisibility: MRVisibility, + private val outputResourcesDir: File, + private val kotlinPlatformType: KotlinPlatformType, + private val kotlinKonanTarget: () -> KonanTarget, + private val androidRClassPackage: () -> String, +) { + fun create(): ResourceTypeGenerator { + return ResourceTypeGenerator( + generationPackage = resourcesPackageName, + resourceClass = Constants.fontResourceName, + resourceType = ResourceType.FONTS, + metadataClass = FontMetadata::class, + visibilityModifier = resourcesVisibility.toModifier(), + generator = FontResourceGenerator(), + platformResourceGenerator = createPlatformFontGenerator(), + filter = { include("fonts/**.ttf", "fonts/**.otf") } + ) + } + + private fun createPlatformFontGenerator(): PlatformResourceGenerator { + return createByPlatform( + kotlinPlatformType = kotlinPlatformType, + konanTarget = kotlinKonanTarget, + // TODO find way to remove this NOP + createCommon = { NOPResourceGenerator() }, + createAndroid = { + AndroidFontResourceGenerator( + androidRClassPackage = androidRClassPackage(), + resourcesGenerationDir = outputResourcesDir + ) + }, + createApple = { + AppleFontResourceGenerator( + resourcesGenerationDir = outputResourcesDir + ) + }, + createJvm = { + JvmFontResourceGenerator( + className = resourcesClassName, + resourcesGenerationDir = outputResourcesDir + ) + }, + createJs = { + JsFontResourceGenerator( + resourcesPackageName = resourcesPackageName, + resourcesGenerationDir = outputResourcesDir + ) + } + ) + } +} 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 new file mode 100644 index 000000000..002e51db2 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/ImageGeneratorFactory.kt @@ -0,0 +1,84 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.factory + +import dev.icerock.gradle.MRVisibility +import dev.icerock.gradle.generator.Constants +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.generator.ResourceTypeGenerator +import dev.icerock.gradle.generator.resources.NOPResourceGenerator +import dev.icerock.gradle.generator.resources.image.AndroidImageResourceGenerator +import dev.icerock.gradle.generator.resources.image.AppleImageResourceGenerator +import dev.icerock.gradle.generator.resources.image.ImageResourceGenerator +import dev.icerock.gradle.generator.resources.image.JsImageResourceGenerator +import dev.icerock.gradle.generator.resources.image.JvmImageResourceGenerator +import dev.icerock.gradle.metadata.container.ResourceType +import dev.icerock.gradle.metadata.resource.ImageMetadata +import dev.icerock.gradle.toModifier +import dev.icerock.gradle.utils.createByPlatform +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType +import org.jetbrains.kotlin.konan.target.KonanTarget +import org.slf4j.Logger +import java.io.File + +@Suppress("LongParameterList") +internal class ImageGeneratorFactory( + private val resourcesPackageName: String, + private val resourcesClassName: String, + private val resourcesVisibility: MRVisibility, + private val outputResourcesDir: File, + private val outputAssetsDir: File, + private val kotlinPlatformType: KotlinPlatformType, + private val kotlinKonanTarget: () -> KonanTarget, + private val androidRClassPackage: () -> String, + private val logger: Logger +) { + fun create(): ResourceTypeGenerator { + return ResourceTypeGenerator( + generationPackage = resourcesPackageName, + resourceClass = Constants.imageResourceName, + resourceType = ResourceType.IMAGES, + metadataClass = ImageMetadata::class, + visibilityModifier = resourcesVisibility.toModifier(), + generator = ImageResourceGenerator(), + platformResourceGenerator = createPlatformImageGenerator(), + filter = { + include("images/**/*.png", "images/**/*.jpg", "images/**/*.svg") + } + ) + } + + private fun createPlatformImageGenerator(): PlatformResourceGenerator { + return createByPlatform( + kotlinPlatformType = kotlinPlatformType, + konanTarget = kotlinKonanTarget, + // TODO find way to remove this NOP + createCommon = { NOPResourceGenerator() }, + createAndroid = { + AndroidImageResourceGenerator( + androidRClassPackage = androidRClassPackage(), + resourcesGenerationDir = outputResourcesDir, + logger = logger + ) + }, + createApple = { + AppleImageResourceGenerator( + assetsGenerationDir = outputAssetsDir + ) + }, + createJvm = { + JvmImageResourceGenerator( + className = resourcesClassName, + resourcesGenerationDir = outputResourcesDir + ) + }, + createJs = { + JsImageResourceGenerator( + resourcesGenerationDir = outputResourcesDir + ) + } + ) + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/PluralGeneratorFactory.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/PluralGeneratorFactory.kt new file mode 100644 index 000000000..6f882812d --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/PluralGeneratorFactory.kt @@ -0,0 +1,86 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.factory + +import dev.icerock.gradle.MRVisibility +import dev.icerock.gradle.generator.Constants +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.generator.ResourceTypeGenerator +import dev.icerock.gradle.generator.resources.NOPResourceGenerator +import dev.icerock.gradle.generator.resources.plural.AndroidPluralResourceGenerator +import dev.icerock.gradle.generator.resources.plural.ApplePluralResourceGenerator +import dev.icerock.gradle.generator.resources.plural.JsPluralResourceGenerator +import dev.icerock.gradle.generator.resources.plural.JvmPluralResourceGenerator +import dev.icerock.gradle.generator.resources.plural.PluralResourceGenerator +import dev.icerock.gradle.metadata.container.ResourceType +import dev.icerock.gradle.metadata.resource.PluralMetadata +import dev.icerock.gradle.toModifier +import dev.icerock.gradle.utils.createByPlatform +import dev.icerock.gradle.utils.flatName +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType +import org.jetbrains.kotlin.konan.target.KonanTarget +import java.io.File + +@Suppress("LongParameterList") +internal class PluralGeneratorFactory( + private val resourcesPackageName: String, + private val resourcesClassName: String, + private val resourcesVisibility: MRVisibility, + private val strictLineBreaks: Boolean, + private val outputResourcesDir: File, + private val kotlinPlatformType: KotlinPlatformType, + private val kotlinKonanTarget: () -> KonanTarget, + private val androidRClassPackage: () -> String, + private val iosBaseLocalizationRegion: () -> String +) { + fun create(): ResourceTypeGenerator { + return ResourceTypeGenerator( + generationPackage = resourcesPackageName, + resourceClass = Constants.pluralsResourceName, + resourceType = ResourceType.PLURALS, + metadataClass = PluralMetadata::class, + visibilityModifier = resourcesVisibility.toModifier(), + generator = PluralResourceGenerator( + strictLineBreaks = strictLineBreaks + ), + platformResourceGenerator = createPlatformPluralGenerator(), + filter = { include("**/plurals*.xml") } + ) + } + + private fun createPlatformPluralGenerator(): PlatformResourceGenerator { + return createByPlatform( + kotlinPlatformType = kotlinPlatformType, + konanTarget = kotlinKonanTarget, + // TODO find way to remove this NOP + createCommon = { NOPResourceGenerator() }, + createAndroid = { + AndroidPluralResourceGenerator( + androidRClassPackage = androidRClassPackage(), + resourcesGenerationDir = outputResourcesDir + ) + }, + createApple = { + ApplePluralResourceGenerator( + baseLocalizationRegion = iosBaseLocalizationRegion(), + resourcesGenerationDir = outputResourcesDir + ) + }, + createJvm = { + JvmPluralResourceGenerator( + flattenClassPackage = resourcesPackageName.flatName, + className = resourcesClassName, + resourcesGenerationDir = outputResourcesDir + ) + }, + createJs = { + JsPluralResourceGenerator( + resourcesPackageName = resourcesPackageName, + resourcesGenerationDir = outputResourcesDir + ) + } + ) + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/StringGeneratorFactory.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/StringGeneratorFactory.kt new file mode 100644 index 000000000..9051dc270 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/factory/StringGeneratorFactory.kt @@ -0,0 +1,86 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.factory + +import dev.icerock.gradle.MRVisibility +import dev.icerock.gradle.generator.Constants +import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.generator.ResourceTypeGenerator +import dev.icerock.gradle.generator.resources.NOPResourceGenerator +import dev.icerock.gradle.generator.resources.string.AndroidStringResourceGenerator +import dev.icerock.gradle.generator.resources.string.AppleStringResourceGenerator +import dev.icerock.gradle.generator.resources.string.JsStringResourceGenerator +import dev.icerock.gradle.generator.resources.string.JvmStringResourceGenerator +import dev.icerock.gradle.generator.resources.string.StringResourceGenerator +import dev.icerock.gradle.metadata.container.ResourceType +import dev.icerock.gradle.metadata.resource.StringMetadata +import dev.icerock.gradle.toModifier +import dev.icerock.gradle.utils.createByPlatform +import dev.icerock.gradle.utils.flatName +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType +import org.jetbrains.kotlin.konan.target.KonanTarget +import java.io.File + +@Suppress("LongParameterList") +internal class StringGeneratorFactory( + private val resourcesPackageName: String, + private val resourcesClassName: String, + private val resourcesVisibility: MRVisibility, + private val strictLineBreaks: Boolean, + private val outputResourcesDir: File, + private val kotlinPlatformType: KotlinPlatformType, + private val kotlinKonanTarget: () -> KonanTarget, + private val androidRClassPackage: () -> String, + private val iosBaseLocalizationRegion: () -> String +) { + fun create(): ResourceTypeGenerator { + return ResourceTypeGenerator( + generationPackage = resourcesPackageName, + resourceClass = Constants.stringResourceName, + resourceType = ResourceType.STRINGS, + metadataClass = StringMetadata::class, + visibilityModifier = resourcesVisibility.toModifier(), + generator = StringResourceGenerator( + strictLineBreaks = strictLineBreaks + ), + platformResourceGenerator = createPlatformStringGenerator(), + filter = { include("**/strings*.xml") } + ) + } + + private fun createPlatformStringGenerator(): PlatformResourceGenerator { + return createByPlatform( + kotlinPlatformType = kotlinPlatformType, + konanTarget = kotlinKonanTarget, + // TODO find way to remove this NOP + createCommon = { NOPResourceGenerator() }, + createAndroid = { + AndroidStringResourceGenerator( + androidRClassPackage = androidRClassPackage(), + resourcesGenerationDir = outputResourcesDir + ) + }, + createApple = { + AppleStringResourceGenerator( + baseLocalizationRegion = iosBaseLocalizationRegion(), + resourcesGenerationDir = outputResourcesDir + ) + }, + createJvm = { + JvmStringResourceGenerator( + flattenClassPackage = resourcesPackageName.flatName, + className = resourcesClassName, + resourcesGenerationDir = outputResourcesDir + ) + }, + createJs = { + JsStringResourceGenerator( + resourcesPackageName = resourcesPackageName, + resourcesGenerationDir = outputResourcesDir + ) + } + ) + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt index 033ba680d..c3457191f 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt @@ -25,6 +25,7 @@ import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile import java.io.File +@Suppress("LongParameterList") internal fun setupAppleKLibResources( compileTask: KotlinNativeCompile, assetsDirectory: Provider, @@ -73,21 +74,23 @@ internal fun createCopyFrameworkResourcesTask(framework: Framework) { val copyTask: TaskProvider = project.tasks.register(taskName, CopyFrameworkResourcesToAppTask::class.java) { it.inputFrameworkDirectory.set(framework.outputDirectoryProperty) - it.outputDirectory.set(project.provider { - val buildProductsDir = - project.property("moko.resources.BUILT_PRODUCTS_DIR") as String - val contentsFolderPath = - project.property("moko.resources.CONTENTS_FOLDER_PATH") as String + it.outputDirectory.set( + project.provider { + val buildProductsDir = + project.property("moko.resources.BUILT_PRODUCTS_DIR") as String + val contentsFolderPath = + project.property("moko.resources.CONTENTS_FOLDER_PATH") as String - val targetDir = File("$buildProductsDir/$contentsFolderPath") - val baseDir: File = project.layout.projectDirectory.asFile + val targetDir = File("$buildProductsDir/$contentsFolderPath") + val baseDir: File = project.layout.projectDirectory.asFile - project.layout.projectDirectory.dir(targetDir.relativeTo(baseDir).path) - }) + project.layout.projectDirectory.dir(targetDir.relativeTo(baseDir).path) + } + ) } copyTask.dependsOn(framework.linkTaskProvider) - //TODO: Вынести в отдельную таску, должно создаваться один раз +// FIXME Вынести в отдельную таску, должно создаваться один раз // val xcodeTask = project.tasks.maybeCreate( // "copyFrameworkResourcesToApp", // CopyFrameworkResourcesToAppEntryPointTask::class.java @@ -105,7 +108,7 @@ internal fun createCopyFrameworkResourcesTask(framework: Framework) { // } } -//private fun setupCopyXCFrameworkResourcesTask(project: Project) { +// private fun setupCopyXCFrameworkResourcesTask(project: Project) { // // Seems that there were problem with this block in the past with mystic task adding. Need more info // // Now, that works perfectly, I've tested on the real project with Kotlin 1.9.10 and KSP enabled // // Suppose that on that moment there were no lazy register method for task container @@ -118,9 +121,9 @@ internal fun createCopyFrameworkResourcesTask(framework: Framework) { // dependsOn(task) // } // } -//} +// } -//private fun createCopyResourcesToAppTask(project: Project) { +// private fun createCopyResourcesToAppTask(project: Project) { // project.tasks // .withType() // .matching { it.binary is AbstractExecutable } @@ -132,7 +135,7 @@ internal fun createCopyFrameworkResourcesTask(framework: Framework) { // dependsOn(linkTask) // } // } -//} +// } internal fun setupTestsResources(compilation: KotlinNativeCompilation) { compilation.target.binaries.withType().configureEach { executable -> diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/AppleColorResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/AppleColorResourceGenerator.kt index db7d1e5ba..c58a41e89 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/AppleColorResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/AppleColorResourceGenerator.kt @@ -122,6 +122,7 @@ internal class AppleColorResourceGenerator( put("color-space", "srgb") put( "components", + @Suppress("MagicNumber") buildJsonObject { put("alpha", color.alpha / 255.0f) put("red", color.red / 255.0f) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/ColorResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/ColorResourceGenerator.kt index ed13a9021..6fd727e55 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/ColorResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/ColorResourceGenerator.kt @@ -104,15 +104,19 @@ internal class ColorResourceGenerator : ResourceGenerator { parseColor(colorValue) } else { val rawColor: String = color.removePrefix("#").removePrefix("0x") - return if (rawColor.length == RgbFormatLength) "${rawColor}${DefaultAlpha}" - else rawColor + return if (rawColor.length == RgbFormatLength) { + "${rawColor}$DefaultAlpha" + } else { + rawColor + } } } + @Suppress("MagicNumber") private fun String.toColor(): ColorMetadata.Color { val rgbaColor: Long = try { this.toLong(16) - } catch (exc: Exception) { + } catch (exc: NumberFormatException) { throw GradleException("can't parse $this to ColorMetadata.Color", exc) } return ColorMetadata.Color( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/Utils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/Utils.kt index 85e8a19a2..a4c566537 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/Utils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/Utils.kt @@ -7,7 +7,6 @@ package dev.icerock.gradle.generator.resources.color import com.squareup.kotlinpoet.CodeBlock import dev.icerock.gradle.metadata.resource.ColorMetadata - internal fun createColorResourceCodeInitializer(color: ColorMetadata): CodeBlock { return when (color.value) { is ColorMetadata.ColorItem.Single -> { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/JsFontResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/JsFontResourceGenerator.kt index 52de9a7d8..b157f155e 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/JsFontResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/JsFontResourceGenerator.kt @@ -78,7 +78,7 @@ internal class JsFontResourceGenerator( val addFontsFun: FunSpec = FunSpec.builder("addFontsToPage") .addCode( "js(%S)", - """require("$FONTS_DIR/${cssDeclarationsFileName}")""" + """require("$FONTS_DIR/$cssDeclarationsFileName")""" ).build() builder.addFunction(addFontsFun) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/AndroidImageResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/AndroidImageResourceGenerator.kt index 08db7dca4..4d344f229 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/AndroidImageResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/AndroidImageResourceGenerator.kt @@ -51,8 +51,11 @@ internal class AndroidImageResourceGenerator( val drawableDir = File(resourcesGenerationDir, drawableDirName) val processedKey: String = processKey(key) - val resourceExtension: String = if (item.quality == null) "xml" - else item.filePath.extension + val resourceExtension: String = if (item.quality == null) { + "xml" + } else { + item.filePath.extension + } val resourceFile = File(drawableDir, "$processedKey.$resourceExtension") if (item.quality == null) { diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/ImageResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/ImageResourceGenerator.kt index de5d0b76d..5ece265fd 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/ImageResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/ImageResourceGenerator.kt @@ -40,4 +40,4 @@ internal class ImageResourceGenerator : ResourceGenerator { file.nameWithoutScale } } -} \ No newline at end of file +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/JvmImageResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/JvmImageResourceGenerator.kt index f083c591e..ef9bd2f27 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/JvmImageResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/JvmImageResourceGenerator.kt @@ -25,7 +25,7 @@ internal class JvmImageResourceGenerator( return CodeBlock.of( "ImageResource(resourcesClassLoader = %L, filePath = %S)", Constants.Jvm.resourcesClassLoaderPropertyName, - "$IMAGES_DIR/${fileName}" + "$IMAGES_DIR/$fileName" ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/JvmPluralResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/JvmPluralResourceGenerator.kt index b6a89b5d3..2731981c6 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/JvmPluralResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/JvmPluralResourceGenerator.kt @@ -83,7 +83,7 @@ internal class JvmPluralResourceGenerator( stringsFile.writeText(content) } - private fun getBundlePath(): String = "${flattenClassPackage}_${pluralsBundleName}" + private fun getBundlePath(): String = "${flattenClassPackage}_$pluralsBundleName" // FIXME duplication // TODO should we do that? diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/JvmStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/JvmStringResourceGenerator.kt index af88ca135..fc816311f 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/JvmStringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/JvmStringResourceGenerator.kt @@ -75,7 +75,7 @@ internal class JvmStringResourceGenerator( stringsFile.writeText(content) } - private fun getBundlePath(): String = "${flattenClassPackage}_${stringsBundleName}" + private fun getBundlePath(): String = "${flattenClassPackage}_$stringsBundleName" // FIXME duplication // TODO should we do that? diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt index b21966223..6733d7359 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt @@ -32,6 +32,7 @@ internal data class StringMetadata( val value: String ) + @Suppress("MagicNumber") override fun contentHash(): String = values.hashCode().toString(16) } @@ -52,11 +53,11 @@ internal data class PluralMetadata( val value: String ) { enum class Quantity { - ZERO, ONE, TWO, FEW, MANY, OTHER; - + ZERO, ONE, TWO, FEW, MANY, OTHER } } + @Suppress("MagicNumber") override fun contentHash(): String = values.hashCode().toString(16) } @@ -114,17 +115,20 @@ internal data class ColorMetadata( val blue: Int, val alpha: Int ) { + @Suppress("MagicNumber") fun toArgbHex(): String { return listOf(alpha, red, green, blue) .joinToString(separator = "") { it.toString(16).padStart(2, '0') } } + @Suppress("MagicNumber") fun toRgbaHex(): String { return listOf(red, green, blue, alpha) .joinToString(separator = "") { it.toString(16).padStart(2, '0') } } } + @Suppress("MagicNumber") override fun contentHash(): String = value.hashCode().toString(16) } 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 2df912d30..734318c70 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 @@ -5,65 +5,24 @@ package dev.icerock.gradle.tasks import dev.icerock.gradle.MRVisibility -import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.PlatformContainerGenerator -import dev.icerock.gradle.generator.PlatformResourceGenerator -import dev.icerock.gradle.generator.ResourceTypeGenerator import dev.icerock.gradle.generator.ResourcesFiles import dev.icerock.gradle.generator.ResourcesGenerator import dev.icerock.gradle.generator.container.AppleContainerGenerator import dev.icerock.gradle.generator.container.JsContainerGenerator import dev.icerock.gradle.generator.container.JvmContainerGenerator import dev.icerock.gradle.generator.container.NOPContainerGenerator -import dev.icerock.gradle.generator.resources.NOPResourceGenerator -import dev.icerock.gradle.generator.resources.asset.AndroidAssetResourceGenerator -import dev.icerock.gradle.generator.resources.asset.AppleAssetResourceGenerator -import dev.icerock.gradle.generator.resources.asset.AssetResourceGenerator -import dev.icerock.gradle.generator.resources.asset.JsAssetResourceGenerator -import dev.icerock.gradle.generator.resources.asset.JvmAssetResourceGenerator -import dev.icerock.gradle.generator.resources.color.AndroidColorResourceGenerator -import dev.icerock.gradle.generator.resources.color.AppleColorResourceGenerator -import dev.icerock.gradle.generator.resources.color.ColorResourceGenerator -import dev.icerock.gradle.generator.resources.color.JsColorResourceGenerator -import dev.icerock.gradle.generator.resources.color.JvmColorResourceGenerator -import dev.icerock.gradle.generator.resources.file.AndroidFileResourceGenerator -import dev.icerock.gradle.generator.resources.file.AppleFileResourceGenerator -import dev.icerock.gradle.generator.resources.file.FileResourceGenerator -import dev.icerock.gradle.generator.resources.file.JsFileResourceGenerator -import dev.icerock.gradle.generator.resources.file.JvmFileResourceGenerator -import dev.icerock.gradle.generator.resources.font.AndroidFontResourceGenerator -import dev.icerock.gradle.generator.resources.font.AppleFontResourceGenerator -import dev.icerock.gradle.generator.resources.font.FontResourceGenerator -import dev.icerock.gradle.generator.resources.font.JsFontResourceGenerator -import dev.icerock.gradle.generator.resources.font.JvmFontResourceGenerator -import dev.icerock.gradle.generator.resources.image.AndroidImageResourceGenerator -import dev.icerock.gradle.generator.resources.image.AppleImageResourceGenerator -import dev.icerock.gradle.generator.resources.image.ImageResourceGenerator -import dev.icerock.gradle.generator.resources.image.JsImageResourceGenerator -import dev.icerock.gradle.generator.resources.image.JvmImageResourceGenerator -import dev.icerock.gradle.generator.resources.plural.AndroidPluralResourceGenerator -import dev.icerock.gradle.generator.resources.plural.ApplePluralResourceGenerator -import dev.icerock.gradle.generator.resources.plural.JsPluralResourceGenerator -import dev.icerock.gradle.generator.resources.plural.JvmPluralResourceGenerator -import dev.icerock.gradle.generator.resources.plural.PluralResourceGenerator -import dev.icerock.gradle.generator.resources.string.AndroidStringResourceGenerator -import dev.icerock.gradle.generator.resources.string.AppleStringResourceGenerator -import dev.icerock.gradle.generator.resources.string.JsStringResourceGenerator -import dev.icerock.gradle.generator.resources.string.JvmStringResourceGenerator -import dev.icerock.gradle.generator.resources.string.StringResourceGenerator +import dev.icerock.gradle.generator.factory.AssetGeneratorFactory +import dev.icerock.gradle.generator.factory.ColorGeneratorFactory +import dev.icerock.gradle.generator.factory.FileGeneratorFactory +import dev.icerock.gradle.generator.factory.FontGeneratorFactory +import dev.icerock.gradle.generator.factory.ImageGeneratorFactory +import dev.icerock.gradle.generator.factory.PluralGeneratorFactory +import dev.icerock.gradle.generator.factory.StringGeneratorFactory import dev.icerock.gradle.metadata.container.ContainerMetadata import dev.icerock.gradle.metadata.container.ObjectMetadata -import dev.icerock.gradle.metadata.container.ResourceType -import dev.icerock.gradle.metadata.resource.AssetMetadata -import dev.icerock.gradle.metadata.resource.ColorMetadata -import dev.icerock.gradle.metadata.resource.FileMetadata -import dev.icerock.gradle.metadata.resource.FontMetadata -import dev.icerock.gradle.metadata.resource.ImageMetadata -import dev.icerock.gradle.metadata.resource.PluralMetadata -import dev.icerock.gradle.metadata.resource.StringMetadata import dev.icerock.gradle.toModifier import dev.icerock.gradle.utils.createByPlatform -import dev.icerock.gradle.utils.flatName import kotlinx.serialization.KSerializer import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.json.Json @@ -72,11 +31,9 @@ import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.DirectoryProperty import org.gradle.api.file.FileCollection import org.gradle.api.file.RegularFileProperty -import org.gradle.api.internal.file.collections.FileCollectionAdapter import org.gradle.api.provider.MapProperty import org.gradle.api.provider.Property import org.gradle.api.tasks.CacheableTask -import org.gradle.api.tasks.Classpath import org.gradle.api.tasks.Input import org.gradle.api.tasks.InputFiles import org.gradle.api.tasks.Optional @@ -87,7 +44,6 @@ import org.gradle.api.tasks.PathSensitivity import org.gradle.api.tasks.TaskAction import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import org.jetbrains.kotlin.konan.target.KonanTarget -import java.io.File @CacheableTask abstract class GenerateMultiplatformResourcesTask : DefaultTask() { @@ -214,15 +170,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { private fun createGenerator(): ResourcesGenerator { return ResourcesGenerator( containerGenerator = createPlatformContainerGenerator(), - typesGenerators = listOf( - createStringGenerator(), - createPluralsGenerator(), - createImagesGenerator(), - createColorsGenerator(), - createFontsGenerator(), - createFilesGenerator(), - createAssetsGenerator() - ), + typesGenerators = createTypeGenerators(), resourcesPackageName = resourcesPackageName.get(), resourcesClassName = resourcesClassName.get(), sourceSetName = sourceSetName.get(), @@ -251,338 +199,79 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { ) } - private fun createStringGenerator(): ResourceTypeGenerator { - return ResourceTypeGenerator( - generationPackage = resourcesPackageName.get(), - resourceClass = Constants.stringResourceName, - resourceType = ResourceType.STRINGS, - metadataClass = StringMetadata::class, - visibilityModifier = resourcesVisibility.get().toModifier(), - generator = StringResourceGenerator( - strictLineBreaks = strictLineBreaks.get() - ), - platformResourceGenerator = createPlatformStringGenerator(), - filter = { include("**/strings*.xml") } - ) - } - - private fun createPluralsGenerator(): ResourceTypeGenerator { - return ResourceTypeGenerator( - generationPackage = resourcesPackageName.get(), - resourceClass = Constants.pluralsResourceName, - resourceType = ResourceType.PLURALS, - metadataClass = PluralMetadata::class, - visibilityModifier = resourcesVisibility.get().toModifier(), - generator = PluralResourceGenerator( - strictLineBreaks = strictLineBreaks.get() - ), - platformResourceGenerator = createPlatformPluralGenerator(), - filter = { include("**/plurals*.xml") } - ) - } - - private fun createImagesGenerator(): ResourceTypeGenerator { - return ResourceTypeGenerator( - generationPackage = resourcesPackageName.get(), - resourceClass = Constants.imageResourceName, - resourceType = ResourceType.IMAGES, - metadataClass = ImageMetadata::class, - visibilityModifier = resourcesVisibility.get().toModifier(), - generator = ImageResourceGenerator(), - platformResourceGenerator = createPlatformImageGenerator(), - filter = { - include("images/**/*.png", "images/**/*.jpg", "images/**/*.svg") - } - ) - } - - private fun createColorsGenerator(): ResourceTypeGenerator { - return ResourceTypeGenerator( - generationPackage = resourcesPackageName.get(), - resourceClass = Constants.colorResourceName, - resourceType = ResourceType.COLORS, - metadataClass = ColorMetadata::class, - visibilityModifier = resourcesVisibility.get().toModifier(), - generator = ColorResourceGenerator(), - platformResourceGenerator = createPlatformColorGenerator(), - filter = { include("**/colors*.xml") } - ) - } - - private fun createFontsGenerator(): ResourceTypeGenerator { - return ResourceTypeGenerator( - generationPackage = resourcesPackageName.get(), - resourceClass = Constants.fontResourceName, - resourceType = ResourceType.FONTS, - metadataClass = FontMetadata::class, - visibilityModifier = resourcesVisibility.get().toModifier(), - generator = FontResourceGenerator(), - platformResourceGenerator = createPlatformFontGenerator(), - filter = { include("fonts/**.ttf", "fonts/**.otf") } - ) - } - - private fun createFilesGenerator(): ResourceTypeGenerator { - return ResourceTypeGenerator( - generationPackage = resourcesPackageName.get(), - resourceClass = Constants.fileResourceName, - resourceType = ResourceType.FILES, - metadataClass = FileMetadata::class, - visibilityModifier = resourcesVisibility.get().toModifier(), - generator = FileResourceGenerator(), - platformResourceGenerator = createPlatformFileGenerator(), - filter = { include("files/**") } - ) - } - - private fun createAssetsGenerator(): ResourceTypeGenerator { - return ResourceTypeGenerator( - generationPackage = resourcesPackageName.get(), - resourceClass = Constants.assetResourceName, - resourceType = ResourceType.ASSETS, - metadataClass = AssetMetadata::class, - visibilityModifier = resourcesVisibility.get().toModifier(), - generator = AssetResourceGenerator( - assetDirs = ownResources.from - .map { it as FileCollectionAdapter } - .flatMap { it.files } - .map { File(it, "assets") } - .toSet() - ), - platformResourceGenerator = createPlatformAssetGenerator(), - filter = { include("assets/**") } - ) - } - - private fun createPlatformAssetGenerator(): PlatformResourceGenerator { - val resourcesGenerationDir: File = outputResourcesDir.get().asFile - val assetsGenerationDir: File = outputAssetsDir.get().asFile - return createByPlatform( + @Suppress("LongMethod") + private fun createTypeGenerators() = listOf( + StringGeneratorFactory( + resourcesPackageName = resourcesPackageName.get(), + resourcesClassName = resourcesClassName.get(), + resourcesVisibility = resourcesVisibility.get(), + strictLineBreaks = strictLineBreaks.get(), + outputResourcesDir = outputResourcesDir.get().asFile, kotlinPlatformType = kotlinPlatformType, - konanTarget = ::kotlinKonanTarget, - // TODO find way to remove this NOP - createCommon = { NOPResourceGenerator() }, - createAndroid = { - AndroidAssetResourceGenerator( - androidRClassPackage = androidRClassPackage.get(), - assetsGenerationDir = assetsGenerationDir, - ) - }, - createApple = { - AppleAssetResourceGenerator( - resourcesGenerationDir = resourcesGenerationDir - ) - }, - createJvm = { - JvmAssetResourceGenerator( - className = resourcesClassName.get(), - resourcesGenerationDir = resourcesGenerationDir - ) - }, - createJs = { - JsAssetResourceGenerator( - resourcesGenerationDir = resourcesGenerationDir - ) - } - ) - } - - private fun createPlatformFileGenerator(): PlatformResourceGenerator { - val resourcesGenerationDir: File = outputResourcesDir.get().asFile - return createByPlatform( + kotlinKonanTarget = ::kotlinKonanTarget, + androidRClassPackage = androidRClassPackage::get, + iosBaseLocalizationRegion = iosBaseLocalizationRegion::get, + ).create(), + PluralGeneratorFactory( + resourcesPackageName = resourcesPackageName.get(), + resourcesClassName = resourcesClassName.get(), + resourcesVisibility = resourcesVisibility.get(), + strictLineBreaks = strictLineBreaks.get(), + outputResourcesDir = outputResourcesDir.get().asFile, kotlinPlatformType = kotlinPlatformType, - konanTarget = ::kotlinKonanTarget, - // TODO find way to remove this NOP - createCommon = { NOPResourceGenerator() }, - createAndroid = { - AndroidFileResourceGenerator( - androidRClassPackage = androidRClassPackage.get(), - resourcesGenerationDir = resourcesGenerationDir - ) - }, - createApple = { - AppleFileResourceGenerator( - resourcesGenerationDir = resourcesGenerationDir - ) - }, - createJvm = { - JvmFileResourceGenerator( - className = resourcesClassName.get(), - resourcesGenerationDir = resourcesGenerationDir - ) - }, - createJs = { - JsFileResourceGenerator( - resourcesGenerationDir = resourcesGenerationDir - ) - } - ) - } - - private fun createPlatformFontGenerator(): PlatformResourceGenerator { - val resourcesGenerationDir: File = outputResourcesDir.get().asFile - return createByPlatform( + kotlinKonanTarget = ::kotlinKonanTarget, + androidRClassPackage = androidRClassPackage::get, + iosBaseLocalizationRegion = iosBaseLocalizationRegion::get, + ).create(), + ImageGeneratorFactory( + resourcesPackageName = resourcesPackageName.get(), + resourcesClassName = resourcesClassName.get(), + resourcesVisibility = resourcesVisibility.get(), + outputResourcesDir = outputResourcesDir.get().asFile, + outputAssetsDir = outputAssetsDir.get().asFile, kotlinPlatformType = kotlinPlatformType, - konanTarget = ::kotlinKonanTarget, - // TODO find way to remove this NOP - createCommon = { NOPResourceGenerator() }, - createAndroid = { - AndroidFontResourceGenerator( - androidRClassPackage = androidRClassPackage.get(), - resourcesGenerationDir = resourcesGenerationDir - ) - }, - createApple = { - AppleFontResourceGenerator( - resourcesGenerationDir = resourcesGenerationDir - ) - }, - createJvm = { - JvmFontResourceGenerator( - className = resourcesClassName.get(), - resourcesGenerationDir = resourcesGenerationDir - ) - }, - createJs = { - JsFontResourceGenerator( - resourcesPackageName = resourcesPackageName.get(), - resourcesGenerationDir = resourcesGenerationDir - ) - } - ) - } - - private fun createPlatformColorGenerator(): PlatformResourceGenerator { - val resourcesGenerationDir: File = outputResourcesDir.get().asFile - val assetsGenerationDir: File = outputAssetsDir.get().asFile - return createByPlatform( + kotlinKonanTarget = ::kotlinKonanTarget, + androidRClassPackage = androidRClassPackage::get, + logger = logger + ).create(), + ColorGeneratorFactory( + resourcesPackageName = resourcesPackageName.get(), + resourcesClassName = resourcesClassName.get(), + resourcesVisibility = resourcesVisibility.get(), + outputResourcesDir = outputResourcesDir.get().asFile, + outputAssetsDir = outputAssetsDir.get().asFile, kotlinPlatformType = kotlinPlatformType, - konanTarget = ::kotlinKonanTarget, - // TODO find way to remove this NOP - createCommon = { NOPResourceGenerator() }, - createAndroid = { - AndroidColorResourceGenerator( - androidRClassPackage = androidRClassPackage.get(), - resourcesGenerationDir = resourcesGenerationDir - ) - }, - createApple = { - AppleColorResourceGenerator( - assetsGenerationDir = assetsGenerationDir - ) - }, - createJvm = { - JvmColorResourceGenerator( - className = resourcesClassName.get() - ) - }, - createJs = { - JsColorResourceGenerator() - } - ) - } - - private fun createPlatformImageGenerator(): PlatformResourceGenerator { - val resourcesGenerationDir: File = outputResourcesDir.get().asFile - val assetsGenerationDir: File = outputAssetsDir.get().asFile - return createByPlatform( + kotlinKonanTarget = ::kotlinKonanTarget, + androidRClassPackage = androidRClassPackage::get, + ).create(), + FontGeneratorFactory( + resourcesPackageName = resourcesPackageName.get(), + resourcesClassName = resourcesClassName.get(), + resourcesVisibility = resourcesVisibility.get(), + outputResourcesDir = outputResourcesDir.get().asFile, kotlinPlatformType = kotlinPlatformType, - konanTarget = ::kotlinKonanTarget, - // TODO find way to remove this NOP - createCommon = { NOPResourceGenerator() }, - createAndroid = { - AndroidImageResourceGenerator( - androidRClassPackage = androidRClassPackage.get(), - resourcesGenerationDir = resourcesGenerationDir, - logger = this.logger - ) - }, - createApple = { - AppleImageResourceGenerator( - assetsGenerationDir = assetsGenerationDir - ) - }, - createJvm = { - JvmImageResourceGenerator( - className = resourcesClassName.get(), - resourcesGenerationDir = resourcesGenerationDir - ) - }, - createJs = { - JsImageResourceGenerator( - resourcesGenerationDir = resourcesGenerationDir - ) - } - ) - } - - private fun createPlatformPluralGenerator(): PlatformResourceGenerator { - val resourcesGenerationDir: File = outputResourcesDir.get().asFile - return createByPlatform( + kotlinKonanTarget = ::kotlinKonanTarget, + androidRClassPackage = androidRClassPackage::get, + ).create(), + FileGeneratorFactory( + resourcesPackageName = resourcesPackageName.get(), + resourcesClassName = resourcesClassName.get(), + resourcesVisibility = resourcesVisibility.get(), + outputResourcesDir = outputResourcesDir.get().asFile, kotlinPlatformType = kotlinPlatformType, - konanTarget = ::kotlinKonanTarget, - // TODO find way to remove this NOP - createCommon = { NOPResourceGenerator() }, - createAndroid = { - AndroidPluralResourceGenerator( - androidRClassPackage = androidRClassPackage.get(), - resourcesGenerationDir = resourcesGenerationDir - ) - }, - createApple = { - ApplePluralResourceGenerator( - baseLocalizationRegion = iosBaseLocalizationRegion.get(), - resourcesGenerationDir = resourcesGenerationDir - ) - }, - createJvm = { - JvmPluralResourceGenerator( - flattenClassPackage = resourcesPackageName.get().flatName, - className = resourcesClassName.get(), - resourcesGenerationDir = resourcesGenerationDir - ) - }, - createJs = { - JsPluralResourceGenerator( - resourcesPackageName = resourcesPackageName.get(), - resourcesGenerationDir = resourcesGenerationDir - ) - } - ) - } - - private fun createPlatformStringGenerator(): PlatformResourceGenerator { - val resourcesGenerationDir: File = outputResourcesDir.get().asFile - return createByPlatform( + kotlinKonanTarget = ::kotlinKonanTarget, + androidRClassPackage = androidRClassPackage::get, + ).create(), + AssetGeneratorFactory( + resourcesPackageName = resourcesPackageName.get(), + resourcesClassName = resourcesClassName.get(), + resourcesVisibility = resourcesVisibility.get(), + outputResourcesDir = outputResourcesDir.get().asFile, + outputAssetsDir = outputAssetsDir.get().asFile, kotlinPlatformType = kotlinPlatformType, - konanTarget = ::kotlinKonanTarget, - // TODO find way to remove this NOP - createCommon = { NOPResourceGenerator() }, - createAndroid = { - AndroidStringResourceGenerator( - androidRClassPackage = androidRClassPackage.get(), - resourcesGenerationDir = resourcesGenerationDir - ) - }, - createApple = { - AppleStringResourceGenerator( - baseLocalizationRegion = iosBaseLocalizationRegion.get(), - resourcesGenerationDir = resourcesGenerationDir - ) - }, - createJvm = { - JvmStringResourceGenerator( - flattenClassPackage = resourcesPackageName.get().flatName, - className = resourcesClassName.get(), - resourcesGenerationDir = resourcesGenerationDir - ) - }, - createJs = { - JsStringResourceGenerator( - resourcesPackageName = resourcesPackageName.get(), - resourcesGenerationDir = resourcesGenerationDir - ) - } - ) - } + kotlinKonanTarget = ::kotlinKonanTarget, + androidRClassPackage = androidRClassPackage::get, + ownResources = ownResources + ).create() + ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ArgbColor.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ArgbColor.kt deleted file mode 100644 index 31f9f7352..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ArgbColor.kt +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.icerock.gradle.utils - -internal data class ArgbColor(val a: Float, val r: Float, val g: Float, val b: Float) - -@Suppress("MagicNumber") -internal fun parseArgbColor(argbColor: Long): ArgbColor { - val r: Float = (argbColor shr 16 and 0xff) / 255.0f - val g: Float = (argbColor shr 8 and 0xff) / 255.0f - val b: Float = (argbColor and 0xff) / 255.0f - val a: Float = (argbColor shr 24 and 0xff) / 255.0f - return ArgbColor(a, r, g, b) -} - -@Suppress("MagicNumber") -internal fun parseRgbaColor(rgbaColor: Long): ArgbColor { - val r: Float = (rgbaColor shr 24 and 0xff) / 255.0f - val g: Float = (rgbaColor shr 16 and 0xff) / 255.0f - val b: Float = (rgbaColor shr 8 and 0xff) / 255.0f - val a: Float = (rgbaColor and 0xff) / 255.0f - return ArgbColor(a, r, g, b) -} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/FileExt.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/FileExt.kt index a71b574d2..5ddc2ec22 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/FileExt.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/FileExt.kt @@ -19,7 +19,4 @@ internal val File.nameWithoutScale: String get() = nameWithoutExtension.withoutScale -internal val File.targetName: String - get() = parentFile.parentFile.parentFile.name - internal fun File.toKonanFile(): KonanFile = KonanFile(this.path) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/KotlinCompilationExt.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/KotlinCompilationExt.kt index e7591f511..cd911da6b 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/KotlinCompilationExt.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/KotlinCompilationExt.kt @@ -8,8 +8,5 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import org.jetbrains.kotlin.gradle.utils.ObservableSet -internal val KotlinCompilation<*>.allKotlinSourceSetsObservable - get() = this.allKotlinSourceSets as ObservableSet - internal val KotlinCompilation<*>.kotlinSourceSetsObservable get() = this.kotlinSourceSets as ObservableSet diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProcessResourcesUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProcessResourcesUtils.kt deleted file mode 100644 index 4a20cc4e1..000000000 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProcessResourcesUtils.kt +++ /dev/null @@ -1,28 +0,0 @@ -///* -// * Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. -// */ -// -//package dev.icerock.gradle.utils -// -//import dev.icerock.gradle.generator.MRGenerator -//import org.gradle.api.Project -//import org.gradle.api.Task -//import org.gradle.api.provider.Provider -//import org.gradle.kotlin.dsl.withType -//import org.gradle.language.jvm.tasks.ProcessResources -// -//fun dependsOnProcessResources( -// project: Project, -// @Suppress("UNUSED_PARAMETER") sourceSet: Provider, -// task: Task, -//) { -// val sourceSet: MRGenerator.SourceSet = sourceSet.get() -// project.logger.warn("source set name is ${sourceSet.name}") -// -// project.tasks -// .matching { it.name == sourceSet.name.removeSuffix("Main") + "ProcessResources" } -// .withType() -// .configureEach { processResourcesTask -> -// processResourcesTask.dependsOn(task) -// } -//} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProjectExt.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProjectExt.kt index 60334413f..040e31bab 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProjectExt.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProjectExt.kt @@ -17,7 +17,6 @@ import java.io.File import javax.xml.parsers.DocumentBuilder import javax.xml.parsers.DocumentBuilderFactory - internal fun Project.getAndroidRClassPackage(): Provider { return provider { val androidExt: BaseExtension = project.extensions.findByType() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/createByPlatform.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/createByPlatform.kt index cc85d0aa7..20e5977f3 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/createByPlatform.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/createByPlatform.kt @@ -2,11 +2,14 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ +@file:Suppress("Filename") + package dev.icerock.gradle.utils import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import org.jetbrains.kotlin.konan.target.KonanTarget +@Suppress("LongParameterList") internal fun createByPlatform( kotlinPlatformType: KotlinPlatformType, konanTarget: () -> KonanTarget, From ed3fd34af0c8d33b366784ccaab87ab0fa16ae58 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Thu, 11 Jan 2024 19:52:32 +0700 Subject: [PATCH 103/352] #535 fix compose-resources-gallery check --- .../iosApp/iosApp.xcodeproj/project.pbxproj | 32 +++++++-------- .../compose-resources-gallery/local-check.sh | 2 +- .../shared/build.gradle.kts | 39 ++++++++++--------- 3 files changed, 38 insertions(+), 35 deletions(-) diff --git a/samples/compose-resources-gallery/iosApp/iosApp.xcodeproj/project.pbxproj b/samples/compose-resources-gallery/iosApp/iosApp.xcodeproj/project.pbxproj index 24fb43719..7b3c27c5c 100644 --- a/samples/compose-resources-gallery/iosApp/iosApp.xcodeproj/project.pbxproj +++ b/samples/compose-resources-gallery/iosApp/iosApp.xcodeproj/project.pbxproj @@ -112,7 +112,7 @@ 7555FF77242A565900829871 /* Sources */, 7555FF79242A565900829871 /* Resources */, F85CB1118929364A9C6EFABC /* Frameworks */, - 77F733FF1C0E0F137B1CD22F /* [CP] Copy Pods Resources */, + F9858DAEDAC83064ADF688BC /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -167,43 +167,43 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 77F733FF1C0E0F137B1CD22F /* [CP] Copy Pods Resources */ = { + 98D614C51D2DA07C614CC46E /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-resources-${CONFIGURATION}-input-files.xcfilelist", ); - name = "[CP] Copy Pods Resources"; + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; outputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-resources-${CONFIGURATION}-output-files.xcfilelist", + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-iosApp-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-resources.sh\"\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; - 98D614C51D2DA07C614CC46E /* [CP] Check Pods Manifest.lock */ = { + F9858DAEDAC83064ADF688BC /* [CP] Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-resources-${CONFIGURATION}-input-files.xcfilelist", ); - inputPaths = ( - "${PODS_PODFILE_DIR_PATH}/Podfile.lock", - "${PODS_ROOT}/Manifest.lock", - ); - name = "[CP] Check Pods Manifest.lock"; + name = "[CP] Copy Pods Resources"; outputFileListPaths = ( - ); - outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-iosApp-checkManifestLockResult.txt", + "${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-resources-${CONFIGURATION}-output-files.xcfilelist", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-resources.sh\"\n"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ diff --git a/samples/compose-resources-gallery/local-check.sh b/samples/compose-resources-gallery/local-check.sh index 14395ad1d..0964a4d4f 100755 --- a/samples/compose-resources-gallery/local-check.sh +++ b/samples/compose-resources-gallery/local-check.sh @@ -18,7 +18,7 @@ log "compose-resources-gallery jvm success" log "compose-resources-gallery ios success" # rerun tasks because kotlinjs compilation broken with build cache :( -./gradlew clean podspec build --rerun-tasks +./gradlew clean podspec build generateDummyFramework --rerun-tasks log "compose-resources-gallery full build success" ( diff --git a/samples/compose-resources-gallery/shared/build.gradle.kts b/samples/compose-resources-gallery/shared/build.gradle.kts index f72377602..c1ad6e7b3 100644 --- a/samples/compose-resources-gallery/shared/build.gradle.kts +++ b/samples/compose-resources-gallery/shared/build.gradle.kts @@ -105,21 +105,24 @@ multiplatformResources { } // TODO move to gradle plugin -//tasks.withType().configureEach { -// @Suppress("ObjectLiteralToLambda") -// doLast(object : Action { -// override fun execute(task: Task) { -// task as DummyFrameworkTask -// -// val frameworkDir = File(task.destinationDir, task.frameworkName.get() + ".framework") -// -// listOf( -// "compose-resources-gallery:shared.bundle" -// ).forEach { bundleName -> -// val bundleDir = File(frameworkDir, bundleName) -// bundleDir.mkdir() -// File(bundleDir, "dummyFile").writeText("dummy") -// } -// } -// }) -//} +tasks.withType().configureEach { + @Suppress("ObjectLiteralToLambda") + doLast(object : Action { + override fun execute(task: Task) { + task as DummyFrameworkTask + + val frameworkDir: File = task.outputFramework.get().asFile + + // TODO here we should fill list from local gradle modules + // AND from external dependencies with bundles + // to fill full list of bundles + listOf( + "compose-resources-gallery:shared.bundle" + ).forEach { bundleName -> + val bundleDir = File(frameworkDir, bundleName) + bundleDir.mkdir() + File(bundleDir, "dummyFile").writeText("dummy") + } + } + }) +} From 42cf531e5ec451c32df7a8c797edac938df78c3d Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Thu, 11 Jan 2024 19:55:00 +0700 Subject: [PATCH 104/352] #535 enable configuration-cache in auto-manifest --- samples/auto-manifest/gradle.properties | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/samples/auto-manifest/gradle.properties b/samples/auto-manifest/gradle.properties index 691267055..79b5350bb 100755 --- a/samples/auto-manifest/gradle.properties +++ b/samples/auto-manifest/gradle.properties @@ -1,8 +1,12 @@ org.gradle.jvmargs=-Xmx12g org.gradle.parallel=true org.gradle.caching=true +org.gradle.configuration-cache=true + kotlin.code.style=official + kotlin.mpp.stability.nowarn=true kotlin.mpp.androidGradlePluginCompatibility.nowarn=true kotlin.mpp.androidSourceSetLayoutVersion=2 + android.useAndroidX=true From 128b86c0d95d79b92a675d38fd82b28295c15e49 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Thu, 11 Jan 2024 20:05:03 +0700 Subject: [PATCH 105/352] #535 map keys to valid kotlin names --- .../kotlin/dev/icerock/gradle/generator/KeyMapper.kt | 11 +++++++++++ .../resources/asset/AssetResourceGenerator.kt | 8 ++------ .../resources/color/ColorResourceGenerator.kt | 3 ++- .../generator/resources/file/FileResourceGenerator.kt | 8 ++------ .../generator/resources/font/FontResourceGenerator.kt | 7 ++++++- .../resources/image/AndroidImageResourceGenerator.kt | 1 - .../resources/image/ImageResourceGenerator.kt | 3 ++- .../plural/AndroidPluralResourceGenerator.kt | 10 ++-------- .../resources/plural/PluralResourceGenerator.kt | 3 ++- .../string/AndroidStringResourceGenerator.kt | 10 ++-------- .../resources/string/StringResourceGenerator.kt | 3 ++- 11 files changed, 33 insertions(+), 34 deletions(-) create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/generator/KeyMapper.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/KeyMapper.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/KeyMapper.kt new file mode 100644 index 000000000..cc5397419 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/KeyMapper.kt @@ -0,0 +1,11 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator + +internal fun generateKey(input: String): String { + return input + .replace("-", "_") + .replace(".", "_") +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/AssetResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/AssetResourceGenerator.kt index 87c10f692..3f5a234a6 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/AssetResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/asset/AssetResourceGenerator.kt @@ -7,6 +7,7 @@ package dev.icerock.gradle.generator.resources.asset import com.squareup.kotlinpoet.PropertySpec import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.ResourceGenerator +import dev.icerock.gradle.generator.generateKey import dev.icerock.gradle.metadata.resource.AssetMetadata import java.io.File @@ -17,7 +18,7 @@ internal class AssetResourceGenerator( override fun generateMetadata(files: Set): List { return files.map { file -> AssetMetadata( - key = processKey(file.nameWithoutExtension), + key = generateKey(file.nameWithoutExtension), relativePath = assetDirs.single { file.absolutePath.contains(it.absolutePath) }, filePath = file, ) @@ -27,9 +28,4 @@ internal class AssetResourceGenerator( override fun generateProperty(metadata: AssetMetadata): PropertySpec.Builder { return PropertySpec.builder(metadata.key, Constants.assetResourceName) } - - // TODO commonize? - private fun processKey(key: String): String { - return key.replace("-", "_") - } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/ColorResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/ColorResourceGenerator.kt index 6fd727e55..2fad2ae30 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/ColorResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/color/ColorResourceGenerator.kt @@ -7,6 +7,7 @@ package dev.icerock.gradle.generator.resources.color import com.squareup.kotlinpoet.PropertySpec import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.ResourceGenerator +import dev.icerock.gradle.generator.generateKey import dev.icerock.gradle.metadata.resource.ColorMetadata import org.gradle.api.GradleException import org.w3c.dom.Document @@ -87,7 +88,7 @@ internal class ColorResourceGenerator : ResourceGenerator { } return ColorMetadata( - key = colorName, + key = generateKey(colorName), value = item ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/FileResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/FileResourceGenerator.kt index e69964d5d..d8233073d 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/FileResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/file/FileResourceGenerator.kt @@ -7,6 +7,7 @@ package dev.icerock.gradle.generator.resources.file import com.squareup.kotlinpoet.PropertySpec import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.ResourceGenerator +import dev.icerock.gradle.generator.generateKey import dev.icerock.gradle.metadata.resource.FileMetadata import java.io.File @@ -15,7 +16,7 @@ internal class FileResourceGenerator : ResourceGenerator { override fun generateMetadata(files: Set): List { return files.map { file -> FileMetadata( - key = processKey(file.nameWithoutExtension), + key = generateKey(file.nameWithoutExtension), filePath = file, ) } @@ -24,9 +25,4 @@ internal class FileResourceGenerator : ResourceGenerator { override fun generateProperty(metadata: FileMetadata): PropertySpec.Builder { return PropertySpec.builder(metadata.key, Constants.fileResourceName) } - - // TODO commonize? - private fun processKey(key: String): String { - return key.replace("-", "_") - } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/FontResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/FontResourceGenerator.kt index 1a46d42fa..67d1bfdaf 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/FontResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/font/FontResourceGenerator.kt @@ -7,6 +7,7 @@ package dev.icerock.gradle.generator.resources.font import com.squareup.kotlinpoet.PropertySpec import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.ResourceGenerator +import dev.icerock.gradle.generator.generateKey import dev.icerock.gradle.metadata.resource.FontMetadata import java.io.File @@ -14,8 +15,12 @@ internal class FontResourceGenerator : ResourceGenerator { override fun generateMetadata(files: Set): List { return files.map { file -> + val key: String = file.nameWithoutExtension + .replace('-', '_') + .lowercase() + FontMetadata( - key = file.nameWithoutExtension.replace('-', '_').lowercase(), + key = generateKey(key), filePath = file, ) } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/AndroidImageResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/AndroidImageResourceGenerator.kt index 4d344f229..0a91f4f94 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/AndroidImageResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/AndroidImageResourceGenerator.kt @@ -103,7 +103,6 @@ internal class AndroidImageResourceGenerator( } } - // TODO we need this? private fun processKey(key: String): String { return key.lowercase() } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/ImageResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/ImageResourceGenerator.kt index 5ece265fd..f06c8eba4 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/ImageResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/ImageResourceGenerator.kt @@ -7,6 +7,7 @@ package dev.icerock.gradle.generator.resources.image import com.squareup.kotlinpoet.PropertySpec import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.ResourceGenerator +import dev.icerock.gradle.generator.generateKey import dev.icerock.gradle.metadata.resource.ImageMetadata import dev.icerock.gradle.utils.nameWithoutScale import dev.icerock.gradle.utils.scale @@ -18,7 +19,7 @@ internal class ImageResourceGenerator : ResourceGenerator { override fun generateMetadata(files: Set): List { return files.groupBy { extractKey(it) }.map { (key: String, files: List) -> ImageMetadata( - key = key, + key = generateKey(key), values = files.map { file -> ImageMetadata.ImageQualityItem( quality = if (file.svg) null else file.scale, diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/AndroidPluralResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/AndroidPluralResourceGenerator.kt index e424f5f64..9f2e8e0fe 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/AndroidPluralResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/AndroidPluralResourceGenerator.kt @@ -21,7 +21,7 @@ internal class AndroidPluralResourceGenerator( ) override fun generateInitializer(metadata: PluralMetadata): CodeBlock { - return CodeBlock.of("PluralsResource(R.plurals.%L)", processKey(metadata.key)) + return CodeBlock.of("PluralsResource(R.plurals.%L)", metadata.key) } override fun generateResourceFiles(data: List) { @@ -48,8 +48,7 @@ internal class AndroidPluralResourceGenerator( """.trimIndent() val content = strings.map { (key, pluralMap) -> - val processedKey = processKey(key) - val start = "\t\n" + val start = "\t\n" val items: String = pluralMap.map { (quantity, value) -> val processedValue = StringEscapeUtils.escapeXml10(value) "\t\t$processedValue" @@ -68,9 +67,4 @@ internal class AndroidPluralResourceGenerator( stringsFile.appendText(content) stringsFile.appendText("\n" + footer) } - - // TODO should we do that? - private fun processKey(key: String): String { - return key.replace(".", "_") - } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/PluralResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/PluralResourceGenerator.kt index ef65b5547..638294459 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/PluralResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/plural/PluralResourceGenerator.kt @@ -7,6 +7,7 @@ package dev.icerock.gradle.generator.resources.plural import com.squareup.kotlinpoet.PropertySpec import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.ResourceGenerator +import dev.icerock.gradle.generator.generateKey import dev.icerock.gradle.generator.localization.LanguageType import dev.icerock.gradle.metadata.resource.PluralMetadata import dev.icerock.gradle.utils.removeLineWraps @@ -39,7 +40,7 @@ internal class PluralResourceGenerator( return keyLangText.map { (key: KeyType, langText: Map) -> PluralMetadata( - key = key, + key = generateKey(key), values = langText.map { (lang: LanguageType, value: PluralMap) -> PluralMetadata.LocaleItem( locale = lang.language(), diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/AndroidStringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/AndroidStringResourceGenerator.kt index 75e25b5f6..13e5e1e0c 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/AndroidStringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/AndroidStringResourceGenerator.kt @@ -21,7 +21,7 @@ internal class AndroidStringResourceGenerator( ) override fun generateInitializer(metadata: StringMetadata): CodeBlock { - return CodeBlock.of("StringResource(R.string.%L)", processKey(metadata.key)) + return CodeBlock.of("StringResource(R.string.%L)", metadata.key) } override fun generateResourceFiles(data: List) { @@ -45,9 +45,8 @@ internal class AndroidStringResourceGenerator( """.trimIndent() val content = strings.map { (key, value) -> - val processedKey = processKey(key) val processedValue = convertXmlStringToAndroidLocalization(value) - "\t$processedValue" + "\t$processedValue" }.joinToString("\n") val footer = @@ -60,11 +59,6 @@ internal class AndroidStringResourceGenerator( stringsFile.appendText("\n" + footer) } - // TODO should we do that? - private fun processKey(key: String): String { - return key.replace(".", "_") - } - // TODO should we do that? private fun convertXmlStringToAndroidLocalization(input: String): String { val xmlDecoded = StringEscapeUtils.unescapeXml(input) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/StringResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/StringResourceGenerator.kt index 0e0cdaa91..715889b65 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/StringResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/string/StringResourceGenerator.kt @@ -8,6 +8,7 @@ import com.squareup.kotlinpoet.PropertySpec import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.ResourceGenerator import dev.icerock.gradle.generator.exceptions.EqualStringKeysException +import dev.icerock.gradle.generator.generateKey import dev.icerock.gradle.generator.localization.LanguageType import dev.icerock.gradle.metadata.resource.StringMetadata import dev.icerock.gradle.utils.removeLineWraps @@ -38,7 +39,7 @@ internal class StringResourceGenerator( return keyLangText.map { (key, langText) -> StringMetadata( - key = key, + key = generateKey(key), values = langText.map { (lang, value) -> StringMetadata.LocaleItem( locale = lang.language(), From 40f7f2781155e3ec043cb66b3d4f78b3a7e6ed6c Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Fri, 12 Jan 2024 16:42:13 +0700 Subject: [PATCH 106/352] #535 rework extras creation --- .../gradle/MultiplatformResourcesPlugin.kt | 177 +----------------- .../gradle/extra/mokoResourcesGenTask.kt | 175 +++++++++++++++++ .../extra/mokoResourcesSourceDirectory.kt | 32 ++++ 3 files changed, 210 insertions(+), 174 deletions(-) create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/extra/mokoResourcesGenTask.kt create mode 100644 resources-generator/src/main/kotlin/dev/icerock/gradle/extra/mokoResourcesSourceDirectory.kt diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 074df35a8..c601ded74 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -7,6 +7,7 @@ package dev.icerock.gradle import com.android.build.api.dsl.AndroidSourceSet import com.android.build.gradle.api.BaseVariant import com.android.build.gradle.internal.lint.AndroidLintAnalysisTask +import dev.icerock.gradle.extra.getOrRegisterGenerateResourcesTask import dev.icerock.gradle.generator.platform.apple.setupAppleKLibResources import dev.icerock.gradle.generator.platform.apple.setupFatFrameworkTasks import dev.icerock.gradle.generator.platform.apple.setupFrameworkResources @@ -14,14 +15,10 @@ import dev.icerock.gradle.generator.platform.apple.setupTestsResources import dev.icerock.gradle.generator.platform.js.setupJsKLibResources import dev.icerock.gradle.generator.platform.js.setupJsResources import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask -import dev.icerock.gradle.utils.dependsOnObservable -import dev.icerock.gradle.utils.getAndroidRClassPackage -import dev.icerock.gradle.utils.isStrictLineBreaks import dev.icerock.gradle.utils.kotlinSourceSetsObservable import org.gradle.api.GradleException import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.api.file.SourceDirectorySet import org.gradle.api.tasks.TaskProvider import org.gradle.kotlin.dsl.create import org.gradle.kotlin.dsl.getByType @@ -41,8 +38,6 @@ import org.jetbrains.kotlin.gradle.plugin.sources.android.findAndroidSourceSet import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile -import org.jetbrains.kotlin.tooling.core.extrasKeyOf -import java.io.File open class MultiplatformResourcesPlugin : Plugin { @@ -70,40 +65,14 @@ open class MultiplatformResourcesPlugin : Plugin { kmpExtension: KotlinMultiplatformExtension, ) { kmpExtension.sourceSets.configureEach { kotlinSourceSet: KotlinSourceSet -> - val resourcesSourceDirectory: SourceDirectorySet = createMokoResourcesSourceSet( - project = project, - kotlinSourceSet = kotlinSourceSet - ) - - val genTask: TaskProvider = registerGenerateTask( - kotlinSourceSet = kotlinSourceSet, - project = project, - resourcesSourceDirectory = resourcesSourceDirectory, - mrExtension = mrExtension - ) - - configureLowerDependencies( - kotlinSourceSet = kotlinSourceSet, - genTask = genTask - ) - - configureUpperDependencies( - kotlinSourceSet = kotlinSourceSet, - resourcesSourceSetName = kotlinSourceSet.name, - resourcesSourceDirectory = resourcesSourceDirectory - ) - - configureTaskDependencies( - kotlinSourceSet = kotlinSourceSet, - genTask = genTask - ) + kotlinSourceSet.getOrRegisterGenerateResourcesTask(mrExtension) } kmpExtension.targets.configureEach { target -> target.compilations.configureEach { compilation -> compilation.kotlinSourceSetsObservable.forAll { sourceSet: KotlinSourceSet -> val genTaskProvider: TaskProvider = - requireNotNull(sourceSet.extras[mokoResourcesGenTaskKey()]) + sourceSet.getOrRegisterGenerateResourcesTask(mrExtension) genTaskProvider.configure { it.platformType.set(target.platformType.name) @@ -260,144 +229,4 @@ open class MultiplatformResourcesPlugin : Plugin { setupTestsResources(compilation = compilation) setupFatFrameworkTasks(compilation = compilation) } - - private fun createMokoResourcesSourceSet( - project: Project, - kotlinSourceSet: KotlinSourceSet, - ): SourceDirectorySet { - val sources = File(project.projectDir, "src") - val resourceSourceSetDir = File(sources, kotlinSourceSet.name) - val mokoResourcesDir = File(resourceSourceSetDir, "moko-resources") - - val resourcesSourceDirectory: SourceDirectorySet = project.objects.sourceDirectorySet( - kotlinSourceSet.name + "MokoResources", - "moko-resources for ${kotlinSourceSet.name} sourceSet" - ) - resourcesSourceDirectory.srcDirs(mokoResourcesDir) - - kotlinSourceSet.extras[mokoResourcesSourceDirectoryKey()] = resourcesSourceDirectory - - return resourcesSourceDirectory - } - - private fun registerGenerateTask( - kotlinSourceSet: KotlinSourceSet, - project: Project, - resourcesSourceDirectory: SourceDirectorySet, - mrExtension: MultiplatformResourcesPluginExtension, - ): TaskProvider { - val generateTaskName: String = "generateMR" + kotlinSourceSet.name - val generatedMokoResourcesDir = File( - project.layout.buildDirectory.get().asFile, - "generated/moko-resources" - ) - - val taskProvider: TaskProvider = project.tasks.register( - generateTaskName, - GenerateMultiplatformResourcesTask::class.java - ) { generateTask -> - generateTask.sourceSetName.set(kotlinSourceSet.name) - - val files: Set = resourcesSourceDirectory.srcDirs - generateTask.ownResources.setFrom(files) - - generateTask.iosBaseLocalizationRegion.set(mrExtension.iosBaseLocalizationRegion) - generateTask.resourcesClassName.set(mrExtension.resourcesClassName) - generateTask.resourcesPackageName.set(mrExtension.resourcesPackage) - generateTask.resourcesVisibility.set(mrExtension.resourcesVisibility) - generateTask.androidRClassPackage.set(project.getAndroidRClassPackage()) - generateTask.strictLineBreaks.set(project.provider { project.isStrictLineBreaks }) - generateTask.outputMetadataFile.set( - File( - File(generatedMokoResourcesDir, "metadata"), - "${kotlinSourceSet.name}-metadata.json" - ) - ) - val sourceSetResourceDir = File(generatedMokoResourcesDir, kotlinSourceSet.name) - generateTask.outputAssetsDir.set(File(sourceSetResourceDir, "assets")) - generateTask.outputResourcesDir.set(File(sourceSetResourceDir, "res")) - generateTask.outputSourcesDir.set(File(sourceSetResourceDir, "src")) - - // by default source set will be common - generateTask.platformType.set(KotlinPlatformType.common.name) - - generateTask.onlyIf("generation on Android supported only for main flavor") { task -> - task as GenerateMultiplatformResourcesTask - - val platform: String = task.platformType.get() - if (platform != KotlinPlatformType.androidJvm.name) return@onlyIf true - - val flavor: String = task.androidSourceSetName.get() - flavor in listOf("main", "test", "androidTest") - } - } - - kotlinSourceSet.extras[mokoResourcesGenTaskKey()] = taskProvider - - return taskProvider - } - - private fun configureLowerDependencies( - kotlinSourceSet: KotlinSourceSet, - genTask: TaskProvider, - ) { - kotlinSourceSet.dependsOnObservable.forAll { dependsSourceSet -> - val resourcesDir: SourceDirectorySet = - requireNotNull(dependsSourceSet.extras[mokoResourcesSourceDirectoryKey()]) - - genTask.configure { - val files: Set = resourcesDir.srcDirs - it.lowerResources.from(files) - } - - configureLowerDependencies( - kotlinSourceSet = dependsSourceSet, - genTask = genTask - ) - } - } - - private fun configureUpperDependencies( - kotlinSourceSet: KotlinSourceSet, - resourcesSourceSetName: String, - resourcesSourceDirectory: SourceDirectorySet, - ) { - kotlinSourceSet.dependsOnObservable.forAll { dependsSourceSet -> - val dependsGenTask: TaskProvider = requireNotNull( - dependsSourceSet.extras[mokoResourcesGenTaskKey()] - ) - - dependsGenTask.configure { - val files: Set = resourcesSourceDirectory.srcDirs - it.upperSourceSets.put(resourcesSourceSetName, kotlinSourceSet.project.files(files)) - } - - configureUpperDependencies( - kotlinSourceSet = dependsSourceSet, - resourcesSourceSetName = resourcesSourceSetName, - resourcesSourceDirectory = resourcesSourceDirectory - ) - } - } - - private fun configureTaskDependencies( - kotlinSourceSet: KotlinSourceSet, - genTask: TaskProvider, - ) { - kotlinSourceSet.dependsOnObservable.forAll { dependsSourceSet -> - val dependsGenTask: TaskProvider = requireNotNull( - dependsSourceSet.extras[mokoResourcesGenTaskKey()] - ) - - genTask.configure { resourceTask -> - resourceTask.inputMetadataFiles.from(dependsGenTask.flatMap { it.outputMetadataFile }) - } - } - } } - -internal fun mokoResourcesSourceDirectoryKey() = - extrasKeyOf("moko-resources-source-directory") - -internal fun mokoResourcesGenTaskKey() = - extrasKeyOf>("moko-resources-generate-task") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/extra/mokoResourcesGenTask.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/extra/mokoResourcesGenTask.kt new file mode 100644 index 000000000..a52651035 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/extra/mokoResourcesGenTask.kt @@ -0,0 +1,175 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.extra + +import dev.icerock.gradle.MultiplatformResourcesPluginExtension +import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask +import dev.icerock.gradle.utils.dependsOnObservable +import dev.icerock.gradle.utils.getAndroidRClassPackage +import dev.icerock.gradle.utils.isStrictLineBreaks +import org.gradle.api.Project +import org.gradle.api.file.SourceDirectorySet +import org.gradle.api.tasks.TaskProvider +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType +import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet +import org.jetbrains.kotlin.tooling.core.extrasKeyOf +import java.io.File + + +private fun mokoResourcesGenTaskKey() = + extrasKeyOf>("moko-resources-generate-task") + +internal fun KotlinSourceSet.getOrRegisterGenerateResourcesTask( + mrExtension: MultiplatformResourcesPluginExtension +): TaskProvider { + val currentProvider: TaskProvider? = + this.extras[mokoResourcesGenTaskKey()] + if (currentProvider != null) return currentProvider + + val resourcesSourceDirectory: SourceDirectorySet = getOrCreateResourcesSourceDirectory() + + val genTask: TaskProvider = registerGenerateTask( + kotlinSourceSet = this, + project = project, + resourcesSourceDirectory = resourcesSourceDirectory, + mrExtension = mrExtension + ) + + configureLowerDependencies( + kotlinSourceSet = this, + genTask = genTask + ) + + configureUpperDependencies( + kotlinSourceSet = this, + resourcesSourceSetName = this.name, + resourcesSourceDirectory = resourcesSourceDirectory, + mrExtension = mrExtension + ) + + configureTaskDependencies( + kotlinSourceSet = this, + genTask = genTask, + mrExtension = mrExtension + ) + + this.extras[mokoResourcesGenTaskKey()] = genTask + + return genTask +} + +private fun registerGenerateTask( + kotlinSourceSet: KotlinSourceSet, + project: Project, + resourcesSourceDirectory: SourceDirectorySet, + mrExtension: MultiplatformResourcesPluginExtension, +): TaskProvider { + val generateTaskName: String = "generateMR" + kotlinSourceSet.name + val generatedMokoResourcesDir = File( + project.layout.buildDirectory.get().asFile, + "generated/moko-resources" + ) + + val taskProvider: TaskProvider = project.tasks.register( + generateTaskName, + GenerateMultiplatformResourcesTask::class.java + ) { generateTask -> + generateTask.sourceSetName.set(kotlinSourceSet.name) + + val files: Set = resourcesSourceDirectory.srcDirs + generateTask.ownResources.setFrom(files) + + generateTask.iosBaseLocalizationRegion.set(mrExtension.iosBaseLocalizationRegion) + generateTask.resourcesClassName.set(mrExtension.resourcesClassName) + generateTask.resourcesPackageName.set(mrExtension.resourcesPackage) + generateTask.resourcesVisibility.set(mrExtension.resourcesVisibility) + generateTask.androidRClassPackage.set(project.getAndroidRClassPackage()) + generateTask.strictLineBreaks.set(project.provider { project.isStrictLineBreaks }) + generateTask.outputMetadataFile.set( + File( + File(generatedMokoResourcesDir, "metadata"), + "${kotlinSourceSet.name}-metadata.json" + ) + ) + val sourceSetResourceDir = File(generatedMokoResourcesDir, kotlinSourceSet.name) + generateTask.outputAssetsDir.set(File(sourceSetResourceDir, "assets")) + generateTask.outputResourcesDir.set(File(sourceSetResourceDir, "res")) + generateTask.outputSourcesDir.set(File(sourceSetResourceDir, "src")) + + // by default source set will be common + generateTask.platformType.set(KotlinPlatformType.common.name) + + generateTask.onlyIf("generation on Android supported only for main flavor") { task -> + task as GenerateMultiplatformResourcesTask + + val platform: String = task.platformType.get() + if (platform != KotlinPlatformType.androidJvm.name) return@onlyIf true + + val flavor: String = task.androidSourceSetName.get() + flavor in listOf("main", "test", "androidTest") + } + } + + return taskProvider +} + +private fun configureLowerDependencies( + kotlinSourceSet: KotlinSourceSet, + genTask: TaskProvider, +) { + kotlinSourceSet.dependsOnObservable.forAll { dependsSourceSet -> + val resourcesDir: SourceDirectorySet = dependsSourceSet + .getOrCreateResourcesSourceDirectory() + + genTask.configure { + val files: Set = resourcesDir.srcDirs + it.lowerResources.from(files) + } + + configureLowerDependencies( + kotlinSourceSet = dependsSourceSet, + genTask = genTask + ) + } +} + +private fun configureUpperDependencies( + kotlinSourceSet: KotlinSourceSet, + resourcesSourceSetName: String, + resourcesSourceDirectory: SourceDirectorySet, + mrExtension: MultiplatformResourcesPluginExtension, +) { + kotlinSourceSet.dependsOnObservable.forAll { dependsSourceSet -> + val dependsGenTask: TaskProvider = dependsSourceSet + .getOrRegisterGenerateResourcesTask(mrExtension) + + dependsGenTask.configure { + val files: Set = resourcesSourceDirectory.srcDirs + it.upperSourceSets.put(resourcesSourceSetName, kotlinSourceSet.project.files(files)) + } + + configureUpperDependencies( + kotlinSourceSet = dependsSourceSet, + resourcesSourceSetName = resourcesSourceSetName, + resourcesSourceDirectory = resourcesSourceDirectory, + mrExtension = mrExtension + ) + } +} + +private fun configureTaskDependencies( + kotlinSourceSet: KotlinSourceSet, + genTask: TaskProvider, + mrExtension: MultiplatformResourcesPluginExtension, +) { + kotlinSourceSet.dependsOnObservable.forAll { dependsSourceSet -> + val dependsGenTask: TaskProvider = dependsSourceSet + .getOrRegisterGenerateResourcesTask(mrExtension) + + genTask.configure { resourceTask -> + resourceTask.inputMetadataFiles.from(dependsGenTask.flatMap { it.outputMetadataFile }) + } + } +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/extra/mokoResourcesSourceDirectory.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/extra/mokoResourcesSourceDirectory.kt new file mode 100644 index 000000000..388a26979 --- /dev/null +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/extra/mokoResourcesSourceDirectory.kt @@ -0,0 +1,32 @@ +/* + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.extra + +import org.gradle.api.file.SourceDirectorySet +import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet +import org.jetbrains.kotlin.tooling.core.extrasKeyOf +import java.io.File + +private fun mokoResourcesSourceDirectoryKey() = + extrasKeyOf("moko-resources-source-directory") + +internal fun KotlinSourceSet.getOrCreateResourcesSourceDirectory(): SourceDirectorySet { + val currentSourceDirectory: SourceDirectorySet? = this.extras[mokoResourcesSourceDirectoryKey()] + if (currentSourceDirectory != null) return currentSourceDirectory + + val sources = File(project.projectDir, "src") + val resourceSourceSetDir = File(sources, this.name) + val mokoResourcesDir = File(resourceSourceSetDir, "moko-resources") + + val resourcesSourceDirectory: SourceDirectorySet = project.objects.sourceDirectorySet( + this.name + "MokoResources", + "moko-resources for ${this.name} sourceSet" + ) + resourcesSourceDirectory.srcDirs(mokoResourcesDir) + + this.extras[mokoResourcesSourceDirectoryKey()] = resourcesSourceDirectory + + return resourcesSourceDirectory +} From df5b12ffe196e2147a26de247205f6990f6d81a1 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Fri, 12 Jan 2024 16:42:26 +0700 Subject: [PATCH 107/352] #535 fix js stringsLoader generation --- .../icerock/gradle/generator/container/JsContainerGenerator.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/container/JsContainerGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/container/JsContainerGenerator.kt index 3ae6f8924..1d8a07ebd 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/container/JsContainerGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/container/JsContainerGenerator.kt @@ -12,7 +12,6 @@ import dev.icerock.gradle.generator.PlatformContainerGenerator internal class JsContainerGenerator : PlatformContainerGenerator { override fun generateAfterTypes(builder: TypeSpec.Builder) { val loaders: List = builder.typeSpecs - .flatMap { it.typeSpecs } .mapNotNull { typeSpec -> val loaderProperty = typeSpec.propertySpecs .singleOrNull { it.name == Constants.Js.stringsLoaderPropertyName } From 97fc88538e1c66fbd8a94e65d650a7cc009c2f74 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Fri, 12 Jan 2024 16:42:34 +0700 Subject: [PATCH 108/352] #535 restruct --- .../gradle/tasks/GenerateMultiplatformResourcesTask.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 734318c70..8d24c98f8 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 @@ -95,14 +95,14 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { @get:Input abstract val strictLineBreaks: Property - @get:OutputFile - abstract val outputMetadataFile: RegularFileProperty - @get:Optional @get:PathSensitive(PathSensitivity.RELATIVE) @get:InputFiles abstract val inputMetadataFiles: ConfigurableFileCollection + @get:OutputFile + abstract val outputMetadataFile: RegularFileProperty + @get:OutputDirectory abstract val outputResourcesDir: DirectoryProperty From 940f1398390dee0c39a81d0ed7490a41b14c8117 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Fri, 12 Jan 2024 16:44:21 +0700 Subject: [PATCH 109/352] #535 update gradle for compose sample --- .../gradle/wrapper/gradle-wrapper.jar | Bin 63721 -> 43462 bytes .../gradle/wrapper/gradle-wrapper.properties | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/compose-resources-gallery/gradle/wrapper/gradle-wrapper.jar b/samples/compose-resources-gallery/gradle/wrapper/gradle-wrapper.jar index 7f93135c49b765f8051ef9d0a6055ff8e46073d8..d64cd4917707c1f8861d8cb53dd15194d4248596 100644 GIT binary patch literal 43462 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 literal 63721 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鯊%1Et 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⁢ zv5o9#E7!G0XmdzfsS{efPNi`1b44~SZ4Z8fuX!I}#8g+(wxzQwUT#Xb2(tbY1+EUhGKoT@KEU9Ktl>_0 z%bjDJg;#*gtJZv!-Zs`?^}v5eKmnbjqlvnSzE@_SP|LG_PJ6CYU+6zY6>92%E+ z=j@TZf-iW4(%U{lnYxQA;7Q!b;^brF8n0D>)`q5>|WDDXLrqYU_tKN2>=#@~OE7grMnNh?UOz-O~6 z6%rHy{#h9K0AT+lDC7q4{hw^|q6*Ry;;L%Q@)Ga}$60_q%D)rv(CtS$CQbpq9|y1e zRSrN4;$Jyl{m5bZw`$8TGvb}(LpY{-cQ)fcyJv7l3S52TLXVDsphtv&aPuDk1OzCA z4A^QtC(!11`IsNx_HnSy?>EKpHJWT^wmS~hc^p^zIIh@9f6U@I2 zC=Mve{j2^)mS#U$e{@Q?SO6%LDsXz@SY+=cK_QMmXBIU)j!$ajc-zLx3V60EXJ!qC zi<%2x8Q24YN+&8U@CIlN zrZkcT9yh%LrlGS9`G)KdP(@9Eo-AQz@8GEFWcb7U=a0H^ZVbLmz{+&M7W(nXJ4sN8 zJLR7eeK(K8`2-}j(T7JsO`L!+CvbueT%izanm-^A1Dn{`1Nw`9P?cq;7no+XfC`K(GO9?O^5zNIt4M+M8LM0=7Gz8UA@Z0N+lg+cX)NfazRu z5D)~HA^(u%w^cz+@2@_#S|u>GpB+j4KzQ^&Wcl9f z&hG#bCA(Yk0D&t&aJE^xME^&E-&xGHhXn%}psEIj641H+Nl-}boj;)Zt*t(4wZ5DN z@GXF$bL=&pBq-#vkTkh>7hl%K5|3 z{`Vn9b$iR-SoGENp}bn4;fR3>9sA%X2@1L3aE9yTra;Wb#_`xWwLSLdfu+PAu+o3| zGVnpzPr=ch{uuoHjtw7+_!L_2;knQ!DuDl0R`|%jr+}jFzXtrHIKc323?JO{l&;VF z*L1+}JU7%QJOg|5|Tc|D8fN zJORAg=_vsy{ak|o);@)Yh8Lkcg@$FG3k@ep36BRa^>~UmnRPziS>Z=`Jb2x*Q#`%A zU*i3&Vg?TluO@X0O;r2Jl6LKLUOVhSqg1*qOt^|8*c7 zo(298@+r$k_wQNGHv{|$tW(T8L+4_`FQ{kEW5Jgg{yf7ey4ss_(SNKfz(N9lx&a;< je(UuV8hP?p&}TPdm1I$XmG#(RzlD&B2izSj9sl%y5~4qc diff --git a/samples/compose-resources-gallery/gradle/wrapper/gradle-wrapper.properties b/samples/compose-resources-gallery/gradle/wrapper/gradle-wrapper.properties index 3fa8f862f..1af9e0930 100644 --- a/samples/compose-resources-gallery/gradle/wrapper/gradle-wrapper.properties +++ b/samples/compose-resources-gallery/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME From a6e3855a3fdd3a6e87ccabdcdffac10c008abfa9 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sat, 13 Jan 2024 19:22:55 +0700 Subject: [PATCH 110/352] #535 fix apple identifier in bundles of different compilations --- .../gradle/MultiplatformResourcesPlugin.kt | 16 +++++++++++++--- .../apple/PackAppleResourcesToKLibAction.kt | 4 ++-- .../generator/platform/apple/SetupAppleUtils.kt | 6 +++--- .../tasks/GenerateMultiplatformResourcesTask.kt | 6 +++++- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index c601ded74..3fd9415ae 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -19,6 +19,7 @@ import dev.icerock.gradle.utils.kotlinSourceSetsObservable import org.gradle.api.GradleException import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.provider.Provider import org.gradle.api.tasks.TaskProvider import org.gradle.kotlin.dsl.create import org.gradle.kotlin.dsl.getByType @@ -122,8 +123,17 @@ open class MultiplatformResourcesPlugin : Plugin { } ) } + } - if (target is KotlinNativeTarget) { + if (target is KotlinNativeTarget && target.konanTarget.family.isAppleFamily) { + val appleIdentifier: Provider = mrExtension.resourcesPackage + .map { it + "." + compilation.name } + + genTaskProvider.configure { + it.appleBundleIdentifier.set(appleIdentifier) + } + + compilation.compileTaskProvider.configure { compileTask: KotlinCompilationTask<*> -> compileTask as KotlinNativeCompile setupAppleKLibResources( @@ -135,8 +145,8 @@ open class MultiplatformResourcesPlugin : Plugin { it.outputResourcesDir.asFile }, iosLocalizationRegion = mrExtension.iosBaseLocalizationRegion, - resourcePackageName = mrExtension.resourcesPackage, - acToolMinimalDeploymentTarget = mrExtension.acToolMinimalDeploymentTarget + acToolMinimalDeploymentTarget = mrExtension.acToolMinimalDeploymentTarget, + appleBundleIdentifier = appleIdentifier ) } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/PackAppleResourcesToKLibAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/PackAppleResourcesToKLibAction.kt index 5ca24ee85..f865e37bf 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/PackAppleResourcesToKLibAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/PackAppleResourcesToKLibAction.kt @@ -19,7 +19,7 @@ import java.util.Properties internal class PackAppleResourcesToKLibAction( private val assetsDirectory: Provider, private val baseLocalizationRegion: Provider, - private val resourcePackageName: Provider, + private val bundleIdentifier: Provider, private val resourcesGenerationDir: Provider, private val acToolMinimalDeploymentTarget: Provider ) : Action { @@ -59,7 +59,7 @@ internal class PackAppleResourcesToKLibAction( directory = resRepackDir, bundleName = uniqueName, developmentRegion = baseLocalizationRegion.get(), - identifier = "${resourcePackageName.get()}.MR" + identifier = bundleIdentifier.get() ) loadableBundle.write() diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt index c3457191f..dcfba2fec 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt @@ -31,13 +31,13 @@ internal fun setupAppleKLibResources( assetsDirectory: Provider, resourcesGenerationDir: Provider, iosLocalizationRegion: Provider, - resourcePackageName: Provider, - acToolMinimalDeploymentTarget: Provider + appleBundleIdentifier: Provider, + acToolMinimalDeploymentTarget: Provider, ) { compileTask.doLast( PackAppleResourcesToKLibAction( baseLocalizationRegion = iosLocalizationRegion, - resourcePackageName = resourcePackageName, + bundleIdentifier = appleBundleIdentifier, assetsDirectory = assetsDirectory, resourcesGenerationDir = resourcesGenerationDir, acToolMinimalDeploymentTarget = acToolMinimalDeploymentTarget 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 8d24c98f8..20a5b611a 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 @@ -75,6 +75,10 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { @get:Input abstract val resourcesPackageName: Property + @get:Optional + @get:Input + abstract val appleBundleIdentifier: Property + @get:Input abstract val resourcesClassName: Property @@ -188,7 +192,7 @@ abstract class GenerateMultiplatformResourcesTask : DefaultTask() { createJs = { JsContainerGenerator() }, createApple = { AppleContainerGenerator( - bundleIdentifier = "${resourcesPackageName.get()}.MR" + bundleIdentifier = appleBundleIdentifier.get() ) }, createJvm = { From a1c68c13a03f683998437801175ddec5ba0db1e8 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sat, 13 Jan 2024 19:23:14 +0700 Subject: [PATCH 111/352] #535 fix resources copy to executables of apple --- .../actions/apple/CopyResourcesFromKLibsToExecutableAction.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsToExecutableAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsToExecutableAction.kt index 66d1b9226..45d806175 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsToExecutableAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromKLibsToExecutableAction.kt @@ -13,7 +13,7 @@ internal class CopyResourcesFromKLibsToExecutableAction : CopyResourcesFromKLibs copyResourcesFromLibraries( linkTask = task, - outputDir = task.outputFile.get() + outputDir = task.outputFile.get().parentFile ) } } From b45d1734d6247a666910210e5af3eb14bd899130 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sat, 13 Jan 2024 19:33:40 +0700 Subject: [PATCH 112/352] #535 fix apple bundle creation issue --- .../gradle/actions/apple/PackAppleResourcesToKLibAction.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/PackAppleResourcesToKLibAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/PackAppleResourcesToKLibAction.kt index f865e37bf..dc952a6a5 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/PackAppleResourcesToKLibAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/PackAppleResourcesToKLibAction.kt @@ -32,8 +32,8 @@ internal class PackAppleResourcesToKLibAction( val resourcesExists: Boolean = listOf( assetsDirectory, resourcesGenerationDir - ).any { file -> - file.exists() && file.listFiles()?.isNotEmpty() == true + ).any { dir -> + dir.exists() && dir.walkTopDown().any { it.isFile } } if (!resourcesExists) { From 524b12b4ea25717f9715127c8c37c6b3bfedc353 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sat, 13 Jan 2024 19:48:00 +0700 Subject: [PATCH 113/352] #535 update resources-gallery sample --- .../android-app/build.gradle.kts | 5 - samples/resources-gallery/build.gradle.kts | 18 +- samples/resources-gallery/gradle.properties | 5 + .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../kotlin-js-store/yarn.lock | 717 ++++++++++-------- .../MR => moko-resources}/base/strings.xml | 0 .../files/nested-test.json | 0 .../MR => moko-resources}/ru/strings.xml | 0 .../kotlin/com/icerockdev/library/Testing.kt | 12 +- .../MR => moko-resources}/assets/test-1.txt | 0 .../assets/texts/inner-1/test3.txt | 0 .../assets/texts/test2.txt | 0 .../base/plurals-test.xml | 0 .../MR => moko-resources}/base/plurals.xml | 0 .../base/strings-test.xml | 0 .../MR => moko-resources}/base/strings.xml | 0 .../MR => moko-resources}/colors/colors.xml | 0 .../en-rGB/plurals-test.xml | 0 .../MR => moko-resources}/en-rGB/plurals.xml | 0 .../en-rGB/strings-test.xml | 0 .../MR => moko-resources}/en-rGB/strings.xml | 0 .../en-rUS/plurals-test.xml | 0 .../MR => moko-resources}/en-rUS/plurals.xml | 0 .../en-rUS/strings-test.xml | 0 .../MR => moko-resources}/en-rUS/strings.xml | 0 .../MR => moko-resources}/es/plurals-test.xml | 0 .../MR => moko-resources}/es/plurals.xml | 0 .../MR => moko-resources}/es/strings.xml | 0 .../MR => moko-resources}/files/some.json | 0 .../MR => moko-resources}/files/test.txt | 0 .../fonts/Raleway-Bold.ttf | Bin .../fonts/Raleway-Italic.ttf | Bin .../fonts/Raleway-Regular.ttf | Bin .../fonts/cormorant-italic.otf | Bin .../fonts/cormorant-light.otf | Bin .../fonts/cormorant-regular.otf | Bin .../images/car_black.svg | 0 .../images/home_black_18@1x.png | Bin .../images/home_black_18@2x.png | Bin .../MR => moko-resources}/in-rPB/strings.xml | 0 .../MR => moko-resources}/in/strings.xml | 0 .../MR => moko-resources}/ru/plurals-test.xml | 0 .../MR => moko-resources}/ru/plurals.xml | 0 .../MR => moko-resources}/ru/strings.xml | 0 44 files changed, 424 insertions(+), 335 deletions(-) rename samples/resources-gallery/mpp-library/nested-module/src/commonMain/{resources/MR => moko-resources}/base/strings.xml (100%) rename samples/resources-gallery/mpp-library/nested-module/src/commonMain/{resources/MR => moko-resources}/files/nested-test.json (100%) rename samples/resources-gallery/mpp-library/nested-module/src/commonMain/{resources/MR => moko-resources}/ru/strings.xml (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/assets/test-1.txt (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/assets/texts/inner-1/test3.txt (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/assets/texts/test2.txt (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/base/plurals-test.xml (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/base/plurals.xml (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/base/strings-test.xml (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/base/strings.xml (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/colors/colors.xml (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/en-rGB/plurals-test.xml (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/en-rGB/plurals.xml (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/en-rGB/strings-test.xml (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/en-rGB/strings.xml (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/en-rUS/plurals-test.xml (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/en-rUS/plurals.xml (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/en-rUS/strings-test.xml (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/en-rUS/strings.xml (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/es/plurals-test.xml (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/es/plurals.xml (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/es/strings.xml (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/files/some.json (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/files/test.txt (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/fonts/Raleway-Bold.ttf (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/fonts/Raleway-Italic.ttf (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/fonts/Raleway-Regular.ttf (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/fonts/cormorant-italic.otf (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/fonts/cormorant-light.otf (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/fonts/cormorant-regular.otf (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/images/car_black.svg (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/images/home_black_18@1x.png (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/images/home_black_18@2x.png (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/in-rPB/strings.xml (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/in/strings.xml (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/ru/plurals-test.xml (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/ru/plurals.xml (100%) rename samples/resources-gallery/mpp-library/src/commonMain/{resources/MR => moko-resources}/ru/strings.xml (100%) diff --git a/samples/resources-gallery/android-app/build.gradle.kts b/samples/resources-gallery/android-app/build.gradle.kts index 036d19917..477019b14 100644 --- a/samples/resources-gallery/android-app/build.gradle.kts +++ b/samples/resources-gallery/android-app/build.gradle.kts @@ -15,11 +15,6 @@ android { versionName = "0.1.0" } namespace = "com.icerockdev" - - compileOptions { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 - } } dependencies { diff --git a/samples/resources-gallery/build.gradle.kts b/samples/resources-gallery/build.gradle.kts index 43c022ae7..89b90cde8 100644 --- a/samples/resources-gallery/build.gradle.kts +++ b/samples/resources-gallery/build.gradle.kts @@ -3,6 +3,8 @@ */ import com.android.build.gradle.BaseExtension +import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension +import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper buildscript { repositories { @@ -13,9 +15,9 @@ buildscript { } dependencies { classpath(moko.resourcesGradlePlugin) - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0") - classpath("org.jetbrains.compose:compose-gradle-plugin:1.5.1") - classpath("com.android.tools.build:gradle:7.4.2") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.10") + classpath("org.jetbrains.compose:compose-gradle-plugin:1.5.11") + classpath("com.android.tools.build:gradle:8.1.1") } } @@ -24,6 +26,16 @@ subprojects { configure { defaultConfig.minSdkVersion(16) compileSdkVersion(33) + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + } + } + plugins.withType { + configure { + jvmToolchain(17) } } } diff --git a/samples/resources-gallery/gradle.properties b/samples/resources-gallery/gradle.properties index 6b2bc0d5e..7bc653bbb 100755 --- a/samples/resources-gallery/gradle.properties +++ b/samples/resources-gallery/gradle.properties @@ -1,9 +1,14 @@ org.gradle.jvmargs=-Xmx12g org.gradle.parallel=true org.gradle.caching=true +org.gradle.configuration-cache=true + kotlin.code.style=official + kotlin.mpp.stability.nowarn=true kotlin.mpp.androidSourceSetLayoutVersion=2 kotlin.mpp.androidGradlePluginCompatibility.nowarn=true + android.useAndroidX=true + xcodeproj=./ios-app diff --git a/samples/resources-gallery/gradle/wrapper/gradle-wrapper.properties b/samples/resources-gallery/gradle/wrapper/gradle-wrapper.properties index 508322917..bdc9a83b1 100755 --- a/samples/resources-gallery/gradle/wrapper/gradle-wrapper.properties +++ b/samples/resources-gallery/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/samples/resources-gallery/kotlin-js-store/yarn.lock b/samples/resources-gallery/kotlin-js-store/yarn.lock index 193f66640..36d9b94fa 100644 --- a/samples/resources-gallery/kotlin-js-store/yarn.lock +++ b/samples/resources-gallery/kotlin-js-store/yarn.lock @@ -26,15 +26,20 @@ resolved "https://registry.yarnpkg.com/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz#2203b118c157721addfe69d47b70465463066d78" integrity sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w== +"@jridgewell/resolve-uri@^3.1.0": + version "3.1.1" + resolved "https://registry.yarnpkg.com/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz#c08679063f279615a3326583ba3a90d1d82cc721" + integrity sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA== + "@jridgewell/set-array@^1.0.1": version "1.1.2" resolved "https://registry.yarnpkg.com/@jridgewell/set-array/-/set-array-1.1.2.tgz#7c6cf998d6d20b914c0a55a91ae928ff25965e72" integrity sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw== -"@jridgewell/source-map@^0.3.2": - version "0.3.2" - resolved "https://registry.yarnpkg.com/@jridgewell/source-map/-/source-map-0.3.2.tgz#f45351aaed4527a298512ec72f81040c998580fb" - integrity sha512-m7O9o2uR8k2ObDysZYzdfhb08VuEml5oWGiosa1VdaPZ/A6QyPkAJuwN0Q1lhULOf6B7MtQmHENS743hWtCrgw== +"@jridgewell/source-map@^0.3.3": + version "0.3.5" + resolved "https://registry.yarnpkg.com/@jridgewell/source-map/-/source-map-0.3.5.tgz#a3bb4d5c6825aab0d281268f47f6ad5853431e91" + integrity sha512-UTYAUj/wviwdsMfzoSJspJxbkH5o1snzwX0//0ENX1u/55kkZZkcTZP6u9bwKGkv+dkk9at4m1Cpt0uY80kcpQ== dependencies: "@jridgewell/gen-mapping" "^0.3.0" "@jridgewell/trace-mapping" "^0.3.9" @@ -44,7 +49,20 @@ resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz#add4c98d341472a289190b424efbdb096991bb24" integrity sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw== -"@jridgewell/trace-mapping@^0.3.17", "@jridgewell/trace-mapping@^0.3.9": +"@jridgewell/sourcemap-codec@^1.4.14": + version "1.4.15" + resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz#d7c6e6755c78567a951e04ab52ef0fd26de59f32" + integrity sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg== + +"@jridgewell/trace-mapping@^0.3.20": + version "0.3.21" + resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.21.tgz#5dc1df7b3dc4a6209e503a924e1ca56097a2bb15" + integrity sha512-SRfKmRe1KvYnxjEMtxEr+J4HIeMX5YBg/qhRHpxEIGjhX1rshcHlnFUE9K0GazhVKWM7B+nARSkV8LuvJdJ5/g== + dependencies: + "@jridgewell/resolve-uri" "^3.1.0" + "@jridgewell/sourcemap-codec" "^1.4.14" + +"@jridgewell/trace-mapping@^0.3.9": version "0.3.17" resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.17.tgz#793041277af9073b0951a7fe0f0d8c4c98c36985" integrity sha512-MCNzAp77qzKca9+W/+I0+sEpaUnZoeasnghNeVc41VZCEKaCH73Vq3BZZ/SzWIgrqE4H4ceI+p+b6C0mHf9T4g== @@ -99,32 +117,32 @@ integrity sha512-+9jVqKhRSpsc591z5vX+X5Yyw+he/HCB4iQ/RYxw35CEPaY1gnsNE43nf9n9AaYjAQrTiI/mOwKUKdUs9vf7Xg== "@types/body-parser@*": - version "1.19.2" - resolved "https://registry.yarnpkg.com/@types/body-parser/-/body-parser-1.19.2.tgz#aea2059e28b7658639081347ac4fab3de166e6f0" - integrity sha512-ALYone6pm6QmwZoAgeyNksccT9Q4AWZQ6PvfwR37GT6r6FWUPguq6sUmNGSMV2Wr761oQoBxwGGa6DR5o1DC9g== + version "1.19.5" + resolved "https://registry.yarnpkg.com/@types/body-parser/-/body-parser-1.19.5.tgz#04ce9a3b677dc8bd681a17da1ab9835dc9d3ede4" + integrity sha512-fB3Zu92ucau0iQ0JMCFQE7b/dv8Ot07NI3KaZIkIUNXq82k4eBAqUaneXfleGY9JWskeS9y+u0nXMyspcuQrCg== dependencies: "@types/connect" "*" "@types/node" "*" "@types/bonjour@^3.5.9": - version "3.5.10" - resolved "https://registry.yarnpkg.com/@types/bonjour/-/bonjour-3.5.10.tgz#0f6aadfe00ea414edc86f5d106357cda9701e275" - integrity sha512-p7ienRMiS41Nu2/igbJxxLDWrSZ0WxM8UQgCeO9KhoVF7cOVFkrKsiDr1EsJIla8vV3oEEjGcz11jc5yimhzZw== + version "3.5.13" + resolved "https://registry.yarnpkg.com/@types/bonjour/-/bonjour-3.5.13.tgz#adf90ce1a105e81dd1f9c61fdc5afda1bfb92956" + integrity sha512-z9fJ5Im06zvUL548KvYNecEVlA7cVDkGUi6kZusb04mpyEFKCIZJvloCcmpmLaIahDpOQGHaHmG6imtPMmPXGQ== dependencies: "@types/node" "*" "@types/connect-history-api-fallback@^1.3.5": - version "1.3.5" - resolved "https://registry.yarnpkg.com/@types/connect-history-api-fallback/-/connect-history-api-fallback-1.3.5.tgz#d1f7a8a09d0ed5a57aee5ae9c18ab9b803205dae" - integrity sha512-h8QJa8xSb1WD4fpKBDcATDNGXghFj6/3GRWG6dhmRcu0RX1Ubasur2Uvx5aeEwlf0MwblEC2bMzzMQntxnw/Cw== + version "1.5.4" + resolved "https://registry.yarnpkg.com/@types/connect-history-api-fallback/-/connect-history-api-fallback-1.5.4.tgz#7de71645a103056b48ac3ce07b3520b819c1d5b3" + integrity sha512-n6Cr2xS1h4uAulPRdlw6Jl6s1oG8KrVilPN2yUITEs+K48EzMJJ3W1xy8K5eWuFvjp3R74AOIGSmp2UfBJ8HFw== dependencies: "@types/express-serve-static-core" "*" "@types/node" "*" "@types/connect@*": - version "3.4.35" - resolved "https://registry.yarnpkg.com/@types/connect/-/connect-3.4.35.tgz#5fcf6ae445e4021d1fc2219a4873cc73a3bb2ad1" - integrity sha512-cdeYyv4KWoEgpBISTxWvqYsVy444DOqehiF3fM3ne10AmJ62RSyNkUnxMJXHQWRQQX2eR94m5y1IZyDwBjV9FQ== + version "3.4.38" + resolved "https://registry.yarnpkg.com/@types/connect/-/connect-3.4.38.tgz#5ba7f3bc4fbbdeaff8dded952e5ff2cc53f8d858" + integrity sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug== dependencies: "@types/node" "*" @@ -161,34 +179,40 @@ resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.0.tgz#5fb2e536c1ae9bf35366eed879e827fa59ca41c2" integrity sha512-WulqXMDUTYAXCjZnk6JtIHPigp55cVtDgDrO2gHRwhyJto21+1zbVCtOYB2L1F9w4qCQ0rOGWBnBe0FNTiEJIQ== -"@types/estree@^0.0.51": - version "0.0.51" - resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.51.tgz#cfd70924a25a3fd32b218e5e420e6897e1ac4f40" - integrity sha512-CuPgU6f3eT/XgKKPqKd/gLZV1Xmvf1a2R5POBOGQa6uv82xpls89HU5zKeVoyR8XzHd1RGNOlQlvUe3CFkjWNQ== +"@types/estree@^1.0.0": + version "1.0.5" + resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.5.tgz#a6ce3e556e00fd9895dd872dd172ad0d4bd687f4" + integrity sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw== "@types/express-serve-static-core@*", "@types/express-serve-static-core@^4.17.33": - version "4.17.33" - resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.33.tgz#de35d30a9d637dc1450ad18dd583d75d5733d543" - integrity sha512-TPBqmR/HRYI3eC2E5hmiivIzv+bidAfXofM+sbonAGvyDhySGw9/PQZFt2BLOrjUUR++4eJVpx6KnLQK1Fk9tA== + version "4.17.41" + resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.41.tgz#5077defa630c2e8d28aa9ffc2c01c157c305bef6" + integrity sha512-OaJ7XLaelTgrvlZD8/aa0vvvxZdUmlCn6MtWeB7TkiKW70BQLc9XEPpDLPdbo52ZhXUCrznlWdCHWxJWtdyajA== dependencies: "@types/node" "*" "@types/qs" "*" "@types/range-parser" "*" + "@types/send" "*" "@types/express@*", "@types/express@^4.17.13": - version "4.17.17" - resolved "https://registry.yarnpkg.com/@types/express/-/express-4.17.17.tgz#01d5437f6ef9cfa8668e616e13c2f2ac9a491ae4" - integrity sha512-Q4FmmuLGBG58btUnfS1c1r/NQdlp3DMfGDGig8WhfpA2YRUtEkxAjkZb0yvplJGYdF1fsQ81iMDcH24sSCNC/Q== + version "4.17.21" + resolved "https://registry.yarnpkg.com/@types/express/-/express-4.17.21.tgz#c26d4a151e60efe0084b23dc3369ebc631ed192d" + integrity sha512-ejlPM315qwLpaQlQDTjPdsUFSc6ZsP4AN6AlWnogPjQ7CVi7PYF3YVz+CY3jE2pwYf7E/7HlDAN0rV2GxTG0HQ== dependencies: "@types/body-parser" "*" "@types/express-serve-static-core" "^4.17.33" "@types/qs" "*" "@types/serve-static" "*" +"@types/http-errors@*": + version "2.0.4" + resolved "https://registry.yarnpkg.com/@types/http-errors/-/http-errors-2.0.4.tgz#7eb47726c391b7345a6ec35ad7f4de469cf5ba4f" + integrity sha512-D0CFMMtydbJAegzOyHjtiKPLlvnm3iTZyZRSZoLq2mRhDdmLfIWOCYPfQJ4cu2erKghU++QvjcUjp/5h7hESpA== + "@types/http-proxy@^1.17.8": - version "1.17.10" - resolved "https://registry.yarnpkg.com/@types/http-proxy/-/http-proxy-1.17.10.tgz#e576c8e4a0cc5c6a138819025a88e167ebb38d6c" - integrity sha512-Qs5aULi+zV1bwKAg5z1PWnDXWmsn+LxIvUGv6E2+OOMYhclZMO+OXd9pYVf2gLykf2I7IV2u7oTHwChPNsvJ7g== + version "1.17.14" + resolved "https://registry.yarnpkg.com/@types/http-proxy/-/http-proxy-1.17.14.tgz#57f8ccaa1c1c3780644f8a94f9c6b5000b5e2eec" + integrity sha512-SSrD0c1OQzlFX7pGu1eXxSEjemej64aaNPRhhVYUGqXh0BtldAAx37MG8btcumvpgKyZp1F5Gn3JkktdxiFv6w== dependencies: "@types/node" "*" @@ -198,9 +222,21 @@ integrity sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ== "@types/mime@*": - version "3.0.1" - resolved "https://registry.yarnpkg.com/@types/mime/-/mime-3.0.1.tgz#5f8f2bca0a5863cb69bc0b0acd88c96cb1d4ae10" - integrity sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA== + version "3.0.4" + resolved "https://registry.yarnpkg.com/@types/mime/-/mime-3.0.4.tgz#2198ac274de6017b44d941e00261d5bc6a0e0a45" + integrity sha512-iJt33IQnVRkqeqC7PzBHPTC6fDlRNRW8vjrgqtScAhrmMwe8c4Eo7+fUGTa+XdWrpEgpyKWMYmi2dIwMAYRzPw== + +"@types/mime@^1": + version "1.3.5" + resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.5.tgz#1ef302e01cf7d2b5a0fa526790c9123bf1d06690" + integrity sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w== + +"@types/node-forge@^1.3.0": + version "1.3.11" + resolved "https://registry.yarnpkg.com/@types/node-forge/-/node-forge-1.3.11.tgz#0972ea538ddb0f4d9c2fa0ec5db5724773a604da" + integrity sha512-FQx220y22OKNTqaByeBGqHWYz4cl94tpcxeFdvBo3wjG6XPBuZ0BNgNZRV5J5TFmmcsJ4IzsLkmGRiQbnYsBEQ== + dependencies: + "@types/node" "*" "@types/node@*", "@types/node@>=10.0.0": version "18.15.0" @@ -208,191 +244,193 @@ integrity sha512-z6nr0TTEOBGkzLGmbypWOGnpSpSIBorEhC4L+4HeQ2iezKCi4f77kyslRwvHeNitymGQ+oFyIWGP96l/DPSV9w== "@types/qs@*": - version "6.9.7" - resolved "https://registry.yarnpkg.com/@types/qs/-/qs-6.9.7.tgz#63bb7d067db107cc1e457c303bc25d511febf6cb" - integrity sha512-FGa1F62FT09qcrueBA6qYTrJPVDzah9a+493+o2PCXsesWHIn27G98TsSMs3WPNbZIEj4+VJf6saSFpvD+3Zsw== + version "6.9.11" + resolved "https://registry.yarnpkg.com/@types/qs/-/qs-6.9.11.tgz#208d8a30bc507bd82e03ada29e4732ea46a6bbda" + integrity sha512-oGk0gmhnEJK4Yyk+oI7EfXsLayXatCWPHary1MtcmbAifkobT9cM9yutG/hZKIseOU0MqbIwQ/u2nn/Gb+ltuQ== "@types/range-parser@*": - version "1.2.4" - resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.4.tgz#cd667bcfdd025213aafb7ca5915a932590acdcdc" - integrity sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw== + version "1.2.7" + resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.7.tgz#50ae4353eaaddc04044279812f52c8c65857dbcb" + integrity sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ== "@types/retry@0.12.0": version "0.12.0" resolved "https://registry.yarnpkg.com/@types/retry/-/retry-0.12.0.tgz#2b35eccfcee7d38cd72ad99232fbd58bffb3c84d" integrity sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA== +"@types/send@*": + version "0.17.4" + resolved "https://registry.yarnpkg.com/@types/send/-/send-0.17.4.tgz#6619cd24e7270793702e4e6a4b958a9010cfc57a" + integrity sha512-x2EM6TJOybec7c52BX0ZspPodMsQUd5L6PRwOunVyVUhXiBSKf3AezDL8Dgvgt5o0UfKNfuA0eMLr2wLT4AiBA== + dependencies: + "@types/mime" "^1" + "@types/node" "*" + "@types/serve-index@^1.9.1": - version "1.9.1" - resolved "https://registry.yarnpkg.com/@types/serve-index/-/serve-index-1.9.1.tgz#1b5e85370a192c01ec6cec4735cf2917337a6278" - integrity sha512-d/Hs3nWDxNL2xAczmOVZNj92YZCS6RGxfBPjKzuu/XirCgXdpKEb88dYNbrYGint6IVWLNP+yonwVAuRC0T2Dg== + version "1.9.4" + resolved "https://registry.yarnpkg.com/@types/serve-index/-/serve-index-1.9.4.tgz#e6ae13d5053cb06ed36392110b4f9a49ac4ec898" + integrity sha512-qLpGZ/c2fhSs5gnYsQxtDEq3Oy8SXPClIXkW5ghvAvsNuVSA8k+gCONcUCS/UjLEYvYps+e8uBtfgXgvhwfNug== dependencies: "@types/express" "*" "@types/serve-static@*", "@types/serve-static@^1.13.10": - version "1.15.1" - resolved "https://registry.yarnpkg.com/@types/serve-static/-/serve-static-1.15.1.tgz#86b1753f0be4f9a1bee68d459fcda5be4ea52b5d" - integrity sha512-NUo5XNiAdULrJENtJXZZ3fHtfMolzZwczzBbnAeBbqBwG+LaG6YaJtuwzwGSQZ2wsCrxjEhNNjAkKigy3n8teQ== + version "1.15.5" + resolved "https://registry.yarnpkg.com/@types/serve-static/-/serve-static-1.15.5.tgz#15e67500ec40789a1e8c9defc2d32a896f05b033" + integrity sha512-PDRk21MnK70hja/YF8AHfC7yIsiQHn1rcXx7ijCFBX/k+XQJhQT/gw3xekXKJvx+5SXaMMS8oqQy09Mzvz2TuQ== dependencies: + "@types/http-errors" "*" "@types/mime" "*" "@types/node" "*" "@types/sockjs@^0.3.33": - version "0.3.33" - resolved "https://registry.yarnpkg.com/@types/sockjs/-/sockjs-0.3.33.tgz#570d3a0b99ac995360e3136fd6045113b1bd236f" - integrity sha512-f0KEEe05NvUnat+boPTZ0dgaLZ4SfSouXUgv5noUiefG2ajgKjmETo9ZJyuqsl7dfl2aHlLJUiki6B4ZYldiiw== + version "0.3.36" + resolved "https://registry.yarnpkg.com/@types/sockjs/-/sockjs-0.3.36.tgz#ce322cf07bcc119d4cbf7f88954f3a3bd0f67535" + integrity sha512-MK9V6NzAS1+Ud7JV9lJLFqW85VbC9dq3LmwZCuBe4wBDgKC0Kj/jd8Xl+nSviU+Qc3+m7umHHyHg//2KSa0a0Q== dependencies: "@types/node" "*" "@types/ws@^8.5.1": - version "8.5.4" - resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.4.tgz#bb10e36116d6e570dd943735f86c933c1587b8a5" - integrity sha512-zdQDHKUgcX/zBc4GrwsE/7dVdAD8JR4EuiAXiiUhhfyIJXXb2+PrGshFyeXWQPMmmZ2XxgaqclgpIC7eTXc1mg== + version "8.5.10" + resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.10.tgz#4acfb517970853fa6574a3a6886791d04a396787" + integrity sha512-vmQSUcfalpIq0R9q7uTo2lXs6eGIpt9wtnLdMv9LVpIjCA/+ufZRozlVoVelIYixx1ugCBKDhn89vnsEGOCx9A== dependencies: "@types/node" "*" -"@ungap/promise-all-settled@1.1.2": - version "1.1.2" - resolved "https://registry.yarnpkg.com/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz#aa58042711d6e3275dd37dc597e5d31e8c290a44" - integrity sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q== - -"@webassemblyjs/ast@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.11.1.tgz#2bfd767eae1a6996f432ff7e8d7fc75679c0b6a7" - integrity sha512-ukBh14qFLjxTQNTXocdyksN5QdM28S1CxHt2rdskFyL+xFV7VremuBLVbmCePj+URalXBENx/9Lm7lnhihtCSw== - dependencies: - "@webassemblyjs/helper-numbers" "1.11.1" - "@webassemblyjs/helper-wasm-bytecode" "1.11.1" - -"@webassemblyjs/floating-point-hex-parser@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.11.1.tgz#f6c61a705f0fd7a6aecaa4e8198f23d9dc179e4f" - integrity sha512-iGRfyc5Bq+NnNuX8b5hwBrRjzf0ocrJPI6GWFodBFzmFnyvrQ83SHKhmilCU/8Jv67i4GJZBMhEzltxzcNagtQ== - -"@webassemblyjs/helper-api-error@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-api-error/-/helper-api-error-1.11.1.tgz#1a63192d8788e5c012800ba6a7a46c705288fd16" - integrity sha512-RlhS8CBCXfRUR/cwo2ho9bkheSXG0+NwooXcc3PAILALf2QLdFyj7KGsKRbVc95hZnhnERon4kW/D3SZpp6Tcg== - -"@webassemblyjs/helper-buffer@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.11.1.tgz#832a900eb444884cde9a7cad467f81500f5e5ab5" - integrity sha512-gwikF65aDNeeXa8JxXa2BAk+REjSyhrNC9ZwdT0f8jc4dQQeDQ7G4m0f2QCLPJiMTTO6wfDmRmj/pW0PsUvIcA== - -"@webassemblyjs/helper-numbers@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-numbers/-/helper-numbers-1.11.1.tgz#64d81da219fbbba1e3bd1bfc74f6e8c4e10a62ae" - integrity sha512-vDkbxiB8zfnPdNK9Rajcey5C0w+QJugEglN0of+kmO8l7lDb77AnlKYQF7aarZuCrv+l0UvqL+68gSDr3k9LPQ== - dependencies: - "@webassemblyjs/floating-point-hex-parser" "1.11.1" - "@webassemblyjs/helper-api-error" "1.11.1" +"@webassemblyjs/ast@1.11.6", "@webassemblyjs/ast@^1.11.5": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.11.6.tgz#db046555d3c413f8966ca50a95176a0e2c642e24" + integrity sha512-IN1xI7PwOvLPgjcf180gC1bqn3q/QaOCwYUahIOhbYUu8KA/3tw2RT/T0Gidi1l7Hhj5D/INhJxiICObqpMu4Q== + dependencies: + "@webassemblyjs/helper-numbers" "1.11.6" + "@webassemblyjs/helper-wasm-bytecode" "1.11.6" + +"@webassemblyjs/floating-point-hex-parser@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.11.6.tgz#dacbcb95aff135c8260f77fa3b4c5fea600a6431" + integrity sha512-ejAj9hfRJ2XMsNHk/v6Fu2dGS+i4UaXBXGemOfQ/JfQ6mdQg/WXtwleQRLLS4OvfDhv8rYnVwH27YJLMyYsxhw== + +"@webassemblyjs/helper-api-error@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-api-error/-/helper-api-error-1.11.6.tgz#6132f68c4acd59dcd141c44b18cbebbd9f2fa768" + integrity sha512-o0YkoP4pVu4rN8aTJgAyj9hC2Sv5UlkzCHhxqWj8butaLvnpdc2jOwh4ewE6CX0txSfLn/UYaV/pheS2Txg//Q== + +"@webassemblyjs/helper-buffer@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.11.6.tgz#b66d73c43e296fd5e88006f18524feb0f2c7c093" + integrity sha512-z3nFzdcp1mb8nEOFFk8DrYLpHvhKC3grJD2ardfKOzmbmJvEf/tPIqCY+sNcwZIY8ZD7IkB2l7/pqhUhqm7hLA== + +"@webassemblyjs/helper-numbers@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-numbers/-/helper-numbers-1.11.6.tgz#cbce5e7e0c1bd32cf4905ae444ef64cea919f1b5" + integrity sha512-vUIhZ8LZoIWHBohiEObxVm6hwP034jwmc9kuq5GdHZH0wiLVLIPcMCdpJzG4C11cHoQ25TFIQj9kaVADVX7N3g== + dependencies: + "@webassemblyjs/floating-point-hex-parser" "1.11.6" + "@webassemblyjs/helper-api-error" "1.11.6" "@xtuc/long" "4.2.2" -"@webassemblyjs/helper-wasm-bytecode@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.11.1.tgz#f328241e41e7b199d0b20c18e88429c4433295e1" - integrity sha512-PvpoOGiJwXeTrSf/qfudJhwlvDQxFgelbMqtq52WWiXC6Xgg1IREdngmPN3bs4RoO83PnL/nFrxucXj1+BX62Q== +"@webassemblyjs/helper-wasm-bytecode@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.11.6.tgz#bb2ebdb3b83aa26d9baad4c46d4315283acd51e9" + integrity sha512-sFFHKwcmBprO9e7Icf0+gddyWYDViL8bpPjJJl0WHxCdETktXdmtWLGVzoHbqUcY4Be1LkNfwTmXOJUFZYSJdA== -"@webassemblyjs/helper-wasm-section@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.11.1.tgz#21ee065a7b635f319e738f0dd73bfbda281c097a" - integrity sha512-10P9No29rYX1j7F3EVPX3JvGPQPae+AomuSTPiF9eBQeChHI6iqjMIwR9JmOJXwpnn/oVGDk7I5IlskuMwU/pg== +"@webassemblyjs/helper-wasm-section@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.11.6.tgz#ff97f3863c55ee7f580fd5c41a381e9def4aa577" + integrity sha512-LPpZbSOwTpEC2cgn4hTydySy1Ke+XEu+ETXuoyvuyezHO3Kjdu90KK95Sh9xTbmjrCsUwvWwCOQQNta37VrS9g== dependencies: - "@webassemblyjs/ast" "1.11.1" - "@webassemblyjs/helper-buffer" "1.11.1" - "@webassemblyjs/helper-wasm-bytecode" "1.11.1" - "@webassemblyjs/wasm-gen" "1.11.1" + "@webassemblyjs/ast" "1.11.6" + "@webassemblyjs/helper-buffer" "1.11.6" + "@webassemblyjs/helper-wasm-bytecode" "1.11.6" + "@webassemblyjs/wasm-gen" "1.11.6" -"@webassemblyjs/ieee754@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/ieee754/-/ieee754-1.11.1.tgz#963929e9bbd05709e7e12243a099180812992614" - integrity sha512-hJ87QIPtAMKbFq6CGTkZYJivEwZDbQUgYd3qKSadTNOhVY7p+gfP6Sr0lLRVTaG1JjFj+r3YchoqRYxNH3M0GQ== +"@webassemblyjs/ieee754@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/ieee754/-/ieee754-1.11.6.tgz#bb665c91d0b14fffceb0e38298c329af043c6e3a" + integrity sha512-LM4p2csPNvbij6U1f19v6WR56QZ8JcHg3QIJTlSwzFcmx6WSORicYj6I63f9yU1kEUtrpG+kjkiIAkevHpDXrg== dependencies: "@xtuc/ieee754" "^1.2.0" -"@webassemblyjs/leb128@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/leb128/-/leb128-1.11.1.tgz#ce814b45574e93d76bae1fb2644ab9cdd9527aa5" - integrity sha512-BJ2P0hNZ0u+Th1YZXJpzW6miwqQUGcIHT1G/sf72gLVD9DZ5AdYTqPNbHZh6K1M5VmKvFXwGSWZADz+qBWxeRw== +"@webassemblyjs/leb128@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/leb128/-/leb128-1.11.6.tgz#70e60e5e82f9ac81118bc25381a0b283893240d7" + integrity sha512-m7a0FhE67DQXgouf1tbN5XQcdWoNgaAuoULHIfGFIEVKA6tu/edls6XnIlkmS6FrXAquJRPni3ZZKjw6FSPjPQ== dependencies: "@xtuc/long" "4.2.2" -"@webassemblyjs/utf8@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/utf8/-/utf8-1.11.1.tgz#d1f8b764369e7c6e6bae350e854dec9a59f0a3ff" - integrity sha512-9kqcxAEdMhiwQkHpkNiorZzqpGrodQQ2IGrHHxCy+Ozng0ofyMA0lTqiLkVs1uzTRejX+/O0EOT7KxqVPuXosQ== - -"@webassemblyjs/wasm-edit@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-edit/-/wasm-edit-1.11.1.tgz#ad206ebf4bf95a058ce9880a8c092c5dec8193d6" - integrity sha512-g+RsupUC1aTHfR8CDgnsVRVZFJqdkFHpsHMfJuWQzWU3tvnLC07UqHICfP+4XyL2tnr1amvl1Sdp06TnYCmVkA== - dependencies: - "@webassemblyjs/ast" "1.11.1" - "@webassemblyjs/helper-buffer" "1.11.1" - "@webassemblyjs/helper-wasm-bytecode" "1.11.1" - "@webassemblyjs/helper-wasm-section" "1.11.1" - "@webassemblyjs/wasm-gen" "1.11.1" - "@webassemblyjs/wasm-opt" "1.11.1" - "@webassemblyjs/wasm-parser" "1.11.1" - "@webassemblyjs/wast-printer" "1.11.1" - -"@webassemblyjs/wasm-gen@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-gen/-/wasm-gen-1.11.1.tgz#86c5ea304849759b7d88c47a32f4f039ae3c8f76" - integrity sha512-F7QqKXwwNlMmsulj6+O7r4mmtAlCWfO/0HdgOxSklZfQcDu0TpLiD1mRt/zF25Bk59FIjEuGAIyn5ei4yMfLhA== - dependencies: - "@webassemblyjs/ast" "1.11.1" - "@webassemblyjs/helper-wasm-bytecode" "1.11.1" - "@webassemblyjs/ieee754" "1.11.1" - "@webassemblyjs/leb128" "1.11.1" - "@webassemblyjs/utf8" "1.11.1" - -"@webassemblyjs/wasm-opt@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-opt/-/wasm-opt-1.11.1.tgz#657b4c2202f4cf3b345f8a4c6461c8c2418985f2" - integrity sha512-VqnkNqnZlU5EB64pp1l7hdm3hmQw7Vgqa0KF/KCNO9sIpI6Fk6brDEiX+iCOYrvMuBWDws0NkTOxYEb85XQHHw== - dependencies: - "@webassemblyjs/ast" "1.11.1" - "@webassemblyjs/helper-buffer" "1.11.1" - "@webassemblyjs/wasm-gen" "1.11.1" - "@webassemblyjs/wasm-parser" "1.11.1" - -"@webassemblyjs/wasm-parser@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.11.1.tgz#86ca734534f417e9bd3c67c7a1c75d8be41fb199" - integrity sha512-rrBujw+dJu32gYB7/Lup6UhdkPx9S9SnobZzRVL7VcBH9Bt9bCBLEuX/YXOOtBsOZ4NQrRykKhffRWHvigQvOA== - dependencies: - "@webassemblyjs/ast" "1.11.1" - "@webassemblyjs/helper-api-error" "1.11.1" - "@webassemblyjs/helper-wasm-bytecode" "1.11.1" - "@webassemblyjs/ieee754" "1.11.1" - "@webassemblyjs/leb128" "1.11.1" - "@webassemblyjs/utf8" "1.11.1" - -"@webassemblyjs/wast-printer@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-printer/-/wast-printer-1.11.1.tgz#d0c73beda8eec5426f10ae8ef55cee5e7084c2f0" - integrity sha512-IQboUWM4eKzWW+N/jij2sRatKMh99QEelo3Eb2q0qXkvPRISAj8Qxtmw5itwqK+TTkBuUIE45AxYPToqPtL5gg== - dependencies: - "@webassemblyjs/ast" "1.11.1" +"@webassemblyjs/utf8@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/utf8/-/utf8-1.11.6.tgz#90f8bc34c561595fe156603be7253cdbcd0fab5a" + integrity sha512-vtXf2wTQ3+up9Zsg8sa2yWiQpzSsMyXj0qViVP6xKGCUT8p8YJ6HqI7l5eCnWx1T/FYdsv07HQs2wTFbbof/RA== + +"@webassemblyjs/wasm-edit@^1.11.5": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-edit/-/wasm-edit-1.11.6.tgz#c72fa8220524c9b416249f3d94c2958dfe70ceab" + integrity sha512-Ybn2I6fnfIGuCR+Faaz7YcvtBKxvoLV3Lebn1tM4o/IAJzmi9AWYIPWpyBfU8cC+JxAO57bk4+zdsTjJR+VTOw== + dependencies: + "@webassemblyjs/ast" "1.11.6" + "@webassemblyjs/helper-buffer" "1.11.6" + "@webassemblyjs/helper-wasm-bytecode" "1.11.6" + "@webassemblyjs/helper-wasm-section" "1.11.6" + "@webassemblyjs/wasm-gen" "1.11.6" + "@webassemblyjs/wasm-opt" "1.11.6" + "@webassemblyjs/wasm-parser" "1.11.6" + "@webassemblyjs/wast-printer" "1.11.6" + +"@webassemblyjs/wasm-gen@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-gen/-/wasm-gen-1.11.6.tgz#fb5283e0e8b4551cc4e9c3c0d7184a65faf7c268" + integrity sha512-3XOqkZP/y6B4F0PBAXvI1/bky7GryoogUtfwExeP/v7Nzwo1QLcq5oQmpKlftZLbT+ERUOAZVQjuNVak6UXjPA== + dependencies: + "@webassemblyjs/ast" "1.11.6" + "@webassemblyjs/helper-wasm-bytecode" "1.11.6" + "@webassemblyjs/ieee754" "1.11.6" + "@webassemblyjs/leb128" "1.11.6" + "@webassemblyjs/utf8" "1.11.6" + +"@webassemblyjs/wasm-opt@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-opt/-/wasm-opt-1.11.6.tgz#d9a22d651248422ca498b09aa3232a81041487c2" + integrity sha512-cOrKuLRE7PCe6AsOVl7WasYf3wbSo4CeOk6PkrjS7g57MFfVUF9u6ysQBBODX0LdgSvQqRiGz3CXvIDKcPNy4g== + dependencies: + "@webassemblyjs/ast" "1.11.6" + "@webassemblyjs/helper-buffer" "1.11.6" + "@webassemblyjs/wasm-gen" "1.11.6" + "@webassemblyjs/wasm-parser" "1.11.6" + +"@webassemblyjs/wasm-parser@1.11.6", "@webassemblyjs/wasm-parser@^1.11.5": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.11.6.tgz#bb85378c527df824004812bbdb784eea539174a1" + integrity sha512-6ZwPeGzMJM3Dqp3hCsLgESxBGtT/OeCvCZ4TA1JUPYgmhAx38tTPR9JaKy0S5H3evQpO/h2uWs2j6Yc/fjkpTQ== + dependencies: + "@webassemblyjs/ast" "1.11.6" + "@webassemblyjs/helper-api-error" "1.11.6" + "@webassemblyjs/helper-wasm-bytecode" "1.11.6" + "@webassemblyjs/ieee754" "1.11.6" + "@webassemblyjs/leb128" "1.11.6" + "@webassemblyjs/utf8" "1.11.6" + +"@webassemblyjs/wast-printer@1.11.6": + version "1.11.6" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-printer/-/wast-printer-1.11.6.tgz#a7bf8dd7e362aeb1668ff43f35cb849f188eff20" + integrity sha512-JM7AhRcE+yW2GWYaKeHL5vt4xqee5N2WcezptmgyhNS+ScggqcT1OtXykhAb13Sn5Yas0j2uv9tHgrjwvzAP4A== + dependencies: + "@webassemblyjs/ast" "1.11.6" "@xtuc/long" "4.2.2" -"@webpack-cli/configtest@^1.2.0": - version "1.2.0" - resolved "https://registry.yarnpkg.com/@webpack-cli/configtest/-/configtest-1.2.0.tgz#7b20ce1c12533912c3b217ea68262365fa29a6f5" - integrity sha512-4FB8Tj6xyVkyqjj1OaTqCjXYULB9FMkqQ8yGrZjRDrYh0nOE+7Lhs45WioWQQMV+ceFlE368Ukhe6xdvJM9Egg== +"@webpack-cli/configtest@^2.1.0": + version "2.1.1" + resolved "https://registry.yarnpkg.com/@webpack-cli/configtest/-/configtest-2.1.1.tgz#3b2f852e91dac6e3b85fb2a314fb8bef46d94646" + integrity sha512-wy0mglZpDSiSS0XHrVR+BAdId2+yxPSoJW8fsna3ZpYSlufjvxnP4YbKTCBZnNIcGN4r6ZPXV55X4mYExOfLmw== -"@webpack-cli/info@^1.5.0": - version "1.5.0" - resolved "https://registry.yarnpkg.com/@webpack-cli/info/-/info-1.5.0.tgz#6c78c13c5874852d6e2dd17f08a41f3fe4c261b1" - integrity sha512-e8tSXZpw2hPl2uMJY6fsMswaok5FdlGNRTktvFk2sD8RjH0hE2+XistawJx1vmKteh4NmGmNUrp+Tb2w+udPcQ== - dependencies: - envinfo "^7.7.3" +"@webpack-cli/info@^2.0.1": + version "2.0.2" + resolved "https://registry.yarnpkg.com/@webpack-cli/info/-/info-2.0.2.tgz#cc3fbf22efeb88ff62310cf885c5b09f44ae0fdd" + integrity sha512-zLHQdI/Qs1UyT5UBdWNqsARasIA+AaF8t+4u2aS2nEpBQh2mWIVb8qAklq0eUENnC5mOItrIB4LiS9xMtph18A== -"@webpack-cli/serve@^1.7.0": - version "1.7.0" - resolved "https://registry.yarnpkg.com/@webpack-cli/serve/-/serve-1.7.0.tgz#e1993689ac42d2b16e9194376cfb6753f6254db1" - integrity sha512-oxnCNGj88fL+xzV+dacXs44HcDwf1ovs3AuEzvP7mqXw7fQntqIhQ1BRmynh4qEKQSSSRSWVyXRjmTbZIX9V2Q== +"@webpack-cli/serve@^2.0.3": + version "2.0.5" + resolved "https://registry.yarnpkg.com/@webpack-cli/serve/-/serve-2.0.5.tgz#325db42395cd49fe6c14057f9a900e427df8810e" + integrity sha512-lqaoKnRYBdo1UgDX8uF24AfGMifWK19TxPmM5FHc2vAGxrJ/qtyUyFBWoY1tISZdelsQ5fBcOusifo5o5wSJxQ== "@xtuc/ieee754@^1.2.0": version "1.2.0" @@ -422,11 +460,16 @@ acorn-import-assertions@^1.7.6: resolved "https://registry.yarnpkg.com/acorn-import-assertions/-/acorn-import-assertions-1.8.0.tgz#ba2b5939ce62c238db6d93d81c9b111b29b855e9" integrity sha512-m7VZ3jwz4eK6A4Vtt8Ew1/mNbP24u0FhdyfA7fSvnJR6LMdfOYnmuIrrJAgrYfYJ10F/otaHTtrtrtmHdMNzEw== -acorn@^8.5.0, acorn@^8.7.1: +acorn@^8.7.1: version "8.8.2" resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.8.2.tgz#1b2f25db02af965399b9776b0c2c391276d37c4a" integrity sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw== +acorn@^8.8.2: + version "8.11.3" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.11.3.tgz#71e0b14e13a4ec160724b38fb7b0f233b1b81d7a" + integrity sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg== + ajv-formats@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/ajv-formats/-/ajv-formats-2.1.1.tgz#6e669400659eb74973bbf2e33327180a0996b520" @@ -506,11 +549,6 @@ array-flatten@1.1.1: resolved "https://registry.yarnpkg.com/array-flatten/-/array-flatten-1.1.1.tgz#9a5f699051b1e7073328f2a008968b64ea2955d2" integrity sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg== -array-flatten@^2.1.2: - version "2.1.2" - resolved "https://registry.yarnpkg.com/array-flatten/-/array-flatten-2.1.2.tgz#24ef80a28c1a893617e2149b0c6d0d788293b099" - integrity sha512-hNfzcOV8W4NdualtqBFPyVO+54DSJuZGY9qT4pRroB6S9e3iiido2ISIC5h9R2sPJ8H3FHCIiEnsv1lPXO3KtQ== - balanced-match@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" @@ -577,12 +615,10 @@ body-parser@^1.19.0: unpipe "1.0.0" bonjour-service@^1.0.11: - version "1.1.0" - resolved "https://registry.yarnpkg.com/bonjour-service/-/bonjour-service-1.1.0.tgz#424170268d68af26ff83a5c640b95def01803a13" - integrity sha512-LVRinRB3k1/K0XzZ2p58COnWvkQknIY6sf0zF2rpErvcJXpMBttEPQSxK+HEXSS9VmpZlDoDnQWv8ftJT20B0Q== + version "1.2.1" + resolved "https://registry.yarnpkg.com/bonjour-service/-/bonjour-service-1.2.1.tgz#eb41b3085183df3321da1264719fbada12478d02" + integrity sha512-oSzCS2zV14bh2kji6vNe7vrpJYCHGvcZnlffFQ1MEoX/WOeQ/teD8SYWKR942OI3INjq8OMNJlbPK5LLLUxFDw== dependencies: - array-flatten "^2.1.2" - dns-equal "^1.0.0" fast-deep-equal "^3.1.3" multicast-dns "^7.2.5" @@ -714,21 +750,26 @@ color-name@~1.1.4: resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== -colorette@^2.0.10, colorette@^2.0.14: +colorette@^2.0.10: + version "2.0.20" + resolved "https://registry.yarnpkg.com/colorette/-/colorette-2.0.20.tgz#9eb793e6833067f7235902fcd3b09917a000a95a" + integrity sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w== + +colorette@^2.0.14: version "2.0.19" resolved "https://registry.yarnpkg.com/colorette/-/colorette-2.0.19.tgz#cdf044f47ad41a0f4b56b3a0d5b4e6e1a2d5a798" integrity sha512-3tlv/dIP7FWvj3BsbHrGLJ6l/oKh1O3TcgBqMn+yyCagOxc23fyzDS6HypQbgxWbkpDnf52p1LuR4eWDQ/K9WQ== +commander@^10.0.1: + version "10.0.1" + resolved "https://registry.yarnpkg.com/commander/-/commander-10.0.1.tgz#881ee46b4f77d1c1dccc5823433aa39b022cbe06" + integrity sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug== + commander@^2.20.0: version "2.20.3" resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ== -commander@^7.0.0: - version "7.2.0" - resolved "https://registry.yarnpkg.com/commander/-/commander-7.2.0.tgz#a36cb57d0b501ce108e4d20559a150a391d97ab7" - integrity sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw== - compressible@~2.0.16: version "2.0.18" resolved "https://registry.yarnpkg.com/compressible/-/compressible-2.0.18.tgz#af53cca6b070d4c3c0750fbd77286a6d7cc46fba" @@ -908,15 +949,10 @@ diff@5.0.0: resolved "https://registry.yarnpkg.com/diff/-/diff-5.0.0.tgz#7ed6ad76d859d030787ec35855f5b1daf31d852b" integrity sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w== -dns-equal@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/dns-equal/-/dns-equal-1.0.0.tgz#b39e7f1da6eb0a75ba9c17324b34753c47e0654d" - integrity sha512-z+paD6YUQsk+AbGCEM4PrOXSss5gd66QfcVBFTKR/HpFL9jCqikS94HYwKww6fQyO7IxrIIyUu+g0Ka9tUS2Cg== - dns-packet@^5.2.2: - version "5.4.0" - resolved "https://registry.yarnpkg.com/dns-packet/-/dns-packet-5.4.0.tgz#1f88477cf9f27e78a213fb6d118ae38e759a879b" - integrity sha512-EgqGeaBB8hLiHLZtp/IbaDQTL8pZ0+IvwzSHA6d7VyMDM+B9hgddEMa9xjK5oYnw0ci0JQ6g2XCD7/f6cafU6g== + version "5.6.1" + resolved "https://registry.yarnpkg.com/dns-packet/-/dns-packet-5.6.1.tgz#ae888ad425a9d1478a0674256ab866de1012cf2f" + integrity sha512-l4gcSouhcgIKRvyy99RNVOgxXiicE+2jZoNmaNmZ6JXiGajBOJAesk1OBlJuM5k2c+eudGdLxDqXuPCKIj6kpw== dependencies: "@leichtgewicht/ip-codec" "^2.0.1" @@ -971,10 +1007,10 @@ engine.io@~6.4.1: engine.io-parser "~5.0.3" ws "~8.11.0" -enhanced-resolve@^5.10.0: - version "5.12.0" - resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.12.0.tgz#300e1c90228f5b570c4d35babf263f6da7155634" - integrity sha512-QHTXI/sZQmko1cbDoNAa3mJ5qhWUUNAq3vR0/YiD379fWQrcfuoX1+HW2S0MTt7XmoPLapdaDKUtelUSPic7hQ== +enhanced-resolve@^5.13.0: + version "5.15.0" + resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.15.0.tgz#1af946c7d93603eb88e9896cee4904dc012e9c35" + integrity sha512-LXYT42KJ7lpIKECr2mAXIaMldcNCh/7E0KBKOu4KSfkHmP+mZmSs+8V5gBAqisWBy0OO4W5Oyys0GO1Y8KtdKg== dependencies: graceful-fs "^4.2.4" tapable "^2.2.0" @@ -989,10 +1025,10 @@ envinfo@^7.7.3: resolved "https://registry.yarnpkg.com/envinfo/-/envinfo-7.8.1.tgz#06377e3e5f4d379fea7ac592d5ad8927e0c4d475" integrity sha512-/o+BXHmB7ocbHEAs6F2EnG0ogybVVUdkRunTT2glZU9XAaGmhqskrvKwqXuDfNjEO0LZKWdejEEpnq8aM0tOaw== -es-module-lexer@^0.9.0: - version "0.9.3" - resolved "https://registry.yarnpkg.com/es-module-lexer/-/es-module-lexer-0.9.3.tgz#6f13db00cc38417137daf74366f535c8eb438f19" - integrity sha512-1HQ2M2sPtxwnvOvT1ZClHyQDiggdNjURWpY2we6aMKCQiUVxTmVs2UYPLIrD84sS+kMdUwfBSylbJPwNnBrnHQ== +es-module-lexer@^1.2.1: + version "1.4.1" + resolved "https://registry.yarnpkg.com/es-module-lexer/-/es-module-lexer-1.4.1.tgz#41ea21b43908fe6a287ffcbe4300f790555331f5" + integrity sha512-cXLGjP0c4T3flZJKQSuziYoq7MlT+rnvfZjfp7h+I7K9BNX54kP9nyWvdbwjQ4u1iWbOL4u96fgeZLToQlZC7w== escalade@^3.1.1: version "3.1.1" @@ -1192,7 +1228,7 @@ follow-redirects@^1.0.0: resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== -format-util@1.0.5: +format-util@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/format-util/-/format-util-1.0.5.tgz#1ffb450c8a03e7bccffe40643180918cc297d271" integrity sha512-varLbTj0e0yVyRpqQhuWV+8hlePAgaoFRhNFj50BNjEIrw1/DphHSObtqwskVCPWNgzwPoQrZAbfa/SBiicNeg== @@ -1216,10 +1252,10 @@ fs-extra@^8.1.0: jsonfile "^4.0.0" universalify "^0.1.0" -fs-monkey@^1.0.3: - version "1.0.3" - resolved "https://registry.yarnpkg.com/fs-monkey/-/fs-monkey-1.0.3.tgz#ae3ac92d53bb328efe0e9a1d9541f6ad8d48e2d3" - integrity sha512-cybjIfiiE+pTWicSCLFHSrXZ6EilF30oh91FDP9S2B051prEa7QWfrVTQm10/dDpswBDXZugPa1Ogu8Yh+HV0Q== +fs-monkey@^1.0.4: + version "1.0.5" + resolved "https://registry.yarnpkg.com/fs-monkey/-/fs-monkey-1.0.5.tgz#fe450175f0db0d7ea758102e1d84096acb925788" + integrity sha512-8uMbBjrhzW76TYgEV27Y5E//W2f/lTFmx78P2w19FZSxarhI/798APGQyuGCwmkNxgwGRhrLfvWyLBvNtuOmew== fs.realpath@^1.0.0: version "1.0.0" @@ -1236,6 +1272,11 @@ function-bind@^1.1.1: resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d" integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A== +function-bind@^1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.2.tgz#2c02d864d97f3ea6c8830c464cbd11ab6eab7a1c" + integrity sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA== + get-caller-file@^2.0.5: version "2.0.5" resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e" @@ -1296,6 +1337,11 @@ graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.4, resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.10.tgz#147d3a006da4ca3ce14728c7aefc287c367d7a6c" integrity sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA== +graceful-fs@^4.2.10: + version "4.2.11" + resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3" + integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ== + handle-thing@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/handle-thing/-/handle-thing-2.0.1.tgz#857f79ce359580c340d43081cc648970d0bb234e" @@ -1318,6 +1364,13 @@ has@^1.0.3: dependencies: function-bind "^1.1.1" +hasown@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/hasown/-/hasown-2.0.0.tgz#f4c513d454a57b7c7e1650778de226b11700546c" + integrity sha512-vUptKVTpIJhcczKBbgnS+RtcuYMB8+oNzPK2/Hp3hanz8JmpATdmmgLgSaadVREkDm+e2giHwY3ZRkyjSIDDFA== + dependencies: + function-bind "^1.1.2" + he@1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f" @@ -1334,9 +1387,9 @@ hpack.js@^2.1.6: wbuf "^1.1.0" html-entities@^2.3.2: - version "2.3.3" - resolved "https://registry.yarnpkg.com/html-entities/-/html-entities-2.3.3.tgz#117d7626bece327fc8baace8868fa6f5ef856e46" - integrity sha512-DV5Ln36z34NNTDgnz0EWGBLZENelNAtkiFA4kyNOG2tDI6Mz1uSWiq1wAKdyjnJwyDiDO7Fa2SO1CTxPXL8VxA== + version "2.4.0" + resolved "https://registry.yarnpkg.com/html-entities/-/html-entities-2.4.0.tgz#edd0cee70402584c8c76cc2c0556db09d1f45061" + integrity sha512-igBTJcNNNhvZFRtm8uA6xMY6xYleeDwn3PeBCkDz7tHttv4F2hsDI2aPgNERWzvRcNYHNT3ymRaQzllmXj4YsQ== http-deceiver@^1.2.7: version "1.2.7" @@ -1439,10 +1492,10 @@ inherits@2.0.3: resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" integrity sha512-x00IRNXNy63jwGkJmzPigoySHbaqpNuzKbBOmzK+g2OdZpQ9w+sxCN+VSB3ja7IAge2OP2qpfxTjeNcyjmW1uw== -interpret@^2.2.0: - version "2.2.0" - resolved "https://registry.yarnpkg.com/interpret/-/interpret-2.2.0.tgz#1a78a0b5965c40a5416d007ad6f50ad27c417df9" - integrity sha512-Ju0Bz/cEia55xDwUWEa8+olFpCiQoypjnQySseKtmjNrnps3P+xfpUmGr90T7yjlVJmOtybRvPXhKMbHr+fWnw== +interpret@^3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/interpret/-/interpret-3.1.1.tgz#5be0ceed67ca79c6c4bc5cf0d7ee843dcea110c4" + integrity sha512-6xwYfHbajpoF0xLW+iwLkhwgvLoZDfjYfoFNu8ftMoXINzwuymNLd9u/KmwtdT2GbR+/Cz66otEGEVVUHX9QLQ== ipaddr.js@1.9.1: version "1.9.1" @@ -1450,9 +1503,9 @@ ipaddr.js@1.9.1: integrity sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g== ipaddr.js@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-2.0.1.tgz#eca256a7a877e917aeb368b0a7497ddf42ef81c0" - integrity sha512-1qTgH9NG+IIJ4yfKs2e6Pp1bZg8wbDbKHT21HrLIeYBTRLgMYKnMTPAuI3Lcs61nfx5h1xlXnbJtH1kX5/d/ng== + version "2.1.0" + resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-2.1.0.tgz#2119bc447ff8c257753b196fc5f1ce08a4cdf39f" + integrity sha512-LlbxQ7xKzfBusov6UMi4MFpEg0m+mAm9xyNGEduwXMEDuf4WfzB/RZwMVYEd7IKGvh4IUkEXYxtAVu9T3OelJQ== is-alphabetical@^2.0.0: version "2.0.1" @@ -1474,12 +1527,12 @@ is-binary-path@~2.1.0: dependencies: binary-extensions "^2.0.0" -is-core-module@^2.9.0: - version "2.11.0" - resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.11.0.tgz#ad4cb3e3863e814523c96f3f58d26cc570ff0144" - integrity sha512-RRjxlvLDkD1YJwDbroBHMb+cukurkDWNyHx7D3oNB5x9rb5ogcksMC5wHCadcXoo67gVr/+3GFySh3134zi6rw== +is-core-module@^2.13.0: + version "2.13.1" + resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.13.1.tgz#ad0d7532c6fea9da1ebdc82742d74525c6273384" + integrity sha512-hHrIjvZsftOsvKSn2TRYl63zvxsgE0K+0mYMoH6gD4omR5IWB2KynivBQczo3+wF1cCkjzvptnI9Q0sPU66ilw== dependencies: - has "^1.0.3" + hasown "^2.0.0" is-decimal@^2.0.0: version "2.0.1" @@ -1605,10 +1658,10 @@ jsonfile@^4.0.0: optionalDependencies: graceful-fs "^4.1.6" -karma-chrome-launcher@3.1.1: - version "3.1.1" - resolved "https://registry.yarnpkg.com/karma-chrome-launcher/-/karma-chrome-launcher-3.1.1.tgz#baca9cc071b1562a1db241827257bfe5cab597ea" - integrity sha512-hsIglcq1vtboGPAN+DGCISCFOxW+ZVnIqhDQcCMqqCp+4dmJ0Qpq5QAjkbA0X2L9Mi6OBkHi2Srrbmm7pUKkzQ== +karma-chrome-launcher@3.2.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/karma-chrome-launcher/-/karma-chrome-launcher-3.2.0.tgz#eb9c95024f2d6dfbb3748d3415ac9b381906b9a9" + integrity sha512-rE9RkUPI7I9mAxByQWkGJFXfFD6lE4gC5nPuZdobf/QdTEJI6EU4yIay/cfU/xV4ZxlM5JiTv7zWYgA64NpS5Q== dependencies: which "^1.2.1" @@ -1619,12 +1672,12 @@ karma-mocha@2.0.1: dependencies: minimist "^1.2.3" -karma-sourcemap-loader@0.3.8: - version "0.3.8" - resolved "https://registry.yarnpkg.com/karma-sourcemap-loader/-/karma-sourcemap-loader-0.3.8.tgz#d4bae72fb7a8397328a62b75013d2df937bdcf9c" - integrity sha512-zorxyAakYZuBcHRJE+vbrK2o2JXLFWK8VVjiT/6P+ltLBUGUvqTEkUiQ119MGdOrK7mrmxXHZF1/pfT6GgIZ6g== +karma-sourcemap-loader@0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/karma-sourcemap-loader/-/karma-sourcemap-loader-0.4.0.tgz#b01d73f8f688f533bcc8f5d273d43458e13b5488" + integrity sha512-xCRL3/pmhAYF3I6qOrcn0uhbQevitc2DERMPH82FMnG+4WReoGcGFZb1pURf2a5apyrOHRdvD+O6K7NljqKHyA== dependencies: - graceful-fs "^4.1.2" + graceful-fs "^4.2.10" karma-webpack@5.0.0: version "5.0.0" @@ -1635,10 +1688,10 @@ karma-webpack@5.0.0: minimatch "^3.0.4" webpack-merge "^4.1.5" -karma@6.4.0: - version "6.4.0" - resolved "https://registry.yarnpkg.com/karma/-/karma-6.4.0.tgz#82652dfecdd853ec227b74ed718a997028a99508" - integrity sha512-s8m7z0IF5g/bS5ONT7wsOavhW4i4aFkzD4u4wgzAQWT4HGUeWI3i21cK2Yz6jndMAeHETp5XuNsRoyGJZXVd4w== +karma@6.4.2: + version "6.4.2" + resolved "https://registry.yarnpkg.com/karma/-/karma-6.4.2.tgz#a983f874cee6f35990c4b2dcc3d274653714de8e" + integrity sha512-C6SU/53LB31BEgRg+omznBEMY4SjHU3ricV6zBcAe1EeILKkeScr+fZXtaI5WyDbkVowJxxAI6h73NcFPmXolQ== dependencies: "@colors/colors" "1.5.0" body-parser "^1.19.0" @@ -1670,6 +1723,14 @@ kind-of@^6.0.2: resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.3.tgz#07c05034a6c349fa06e24fa35aa76db4580ce4dd" integrity sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw== +launch-editor@^2.6.0: + version "2.6.1" + resolved "https://registry.yarnpkg.com/launch-editor/-/launch-editor-2.6.1.tgz#f259c9ef95cbc9425620bbbd14b468fcdb4ffe3c" + integrity sha512-eB/uXmFVpY4zezmGp5XtU21kwo7GBbKB+EQ+UZeWtGb9yAM5xt/Evk+lYH3eRNAtId+ej4u7TYPFZ07w4s7rRw== + dependencies: + picocolors "^1.0.0" + shell-quote "^1.8.1" + loader-runner@^4.2.0: version "4.3.0" resolved "https://registry.yarnpkg.com/loader-runner/-/loader-runner-4.3.0.tgz#c1b4a163b99f614830353b16755e7149ac2314e1" @@ -1731,11 +1792,11 @@ media-typer@0.3.0: integrity sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ== memfs@^3.4.3: - version "3.4.13" - resolved "https://registry.yarnpkg.com/memfs/-/memfs-3.4.13.tgz#248a8bd239b3c240175cd5ec548de5227fc4f345" - integrity sha512-omTM41g3Skpvx5dSYeZIbXKcXoAVc/AoMNwn9TKx++L/gaen/+4TTttmu8ZSch5vfVJ8uJvGbroTsIlslRg6lg== + version "3.6.0" + resolved "https://registry.yarnpkg.com/memfs/-/memfs-3.6.0.tgz#d7a2110f86f79dd950a8b6df6d57bc984aa185f6" + integrity sha512-EGowvkkgbMcIChjMTMkESFDbZeSh8xZ7kNSF0hAiAN4Jh6jgHCRS0Ga/+C8y6Au+oqpezRHCfPsmJ2+DwAgiwQ== dependencies: - fs-monkey "^1.0.3" + fs-monkey "^1.0.4" merge-descriptors@1.0.1: version "1.0.1" @@ -1825,12 +1886,11 @@ mkdirp@^0.5.5: dependencies: minimist "^1.2.6" -mocha@10.0.0: - version "10.0.0" - resolved "https://registry.yarnpkg.com/mocha/-/mocha-10.0.0.tgz#205447d8993ec755335c4b13deba3d3a13c4def9" - integrity sha512-0Wl+elVUD43Y0BqPZBzZt8Tnkw9CMUdNYnUsTfOM1vuhJVZL+kiesFYsqwBkEEuEixaiPe5ZQdqDgX2jddhmoA== +mocha@10.2.0: + version "10.2.0" + resolved "https://registry.yarnpkg.com/mocha/-/mocha-10.2.0.tgz#1fd4a7c32ba5ac372e03a17eef435bd00e5c68b8" + integrity sha512-IDY7fl/BecMwFHzoqF2sg/SHHANeBoMMXFlS9r0OXKDssYE1M5O43wUY/9BVPeIvfH2zmEbBfseqN9gBQZzXkg== dependencies: - "@ungap/promise-all-settled" "1.1.2" ansi-colors "4.1.1" browser-stdout "1.3.1" chokidar "3.5.3" @@ -2209,12 +2269,12 @@ readdirp@~3.6.0: dependencies: picomatch "^2.2.1" -rechoir@^0.7.0: - version "0.7.1" - resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.7.1.tgz#9478a96a1ca135b5e88fc027f03ee92d6c645686" - integrity sha512-/njmZ8s1wVeR6pjTZ+0nCnv8SpZNRMT2D1RLOJQESlYFDBvwpTA4KWJpZ+sBJ4+vhjILRcK7JIFdGCdxEAAitg== +rechoir@^0.8.0: + version "0.8.0" + resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.8.0.tgz#49f866e0d32146142da3ad8f0eff352b3215ff22" + integrity sha512-/vxpCXddiX8NGfGO/mTafwjq4aFa/71pvamip0++IQk3zG8cbCj0fifNPrjjF1XMXUne91jL9OoxmdykoEtifQ== dependencies: - resolve "^1.9.0" + resolve "^1.20.0" require-directory@^2.1.1: version "2.1.1" @@ -2243,12 +2303,12 @@ resolve-from@^5.0.0: resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-5.0.0.tgz#c35225843df8f776df21c57557bc087e9dfdfc69" integrity sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw== -resolve@^1.9.0: - version "1.22.1" - resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.1.tgz#27cb2ebb53f91abb49470a928bba7558066ac177" - integrity sha512-nBpuuYuY5jFsli/JIs1oldw6fOQCBioohqWZg/2hiaOybXOft4lonv85uDOKXdf8rhyK159cxU5cDcK/NKk8zw== +resolve@^1.20.0: + version "1.22.8" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.8.tgz#b6c87a9f2aa06dfab52e3d70ac8cde321fa5a48d" + integrity sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw== dependencies: - is-core-module "^2.9.0" + is-core-module "^2.13.0" path-parse "^1.0.7" supports-preserve-symlinks-flag "^1.0.0" @@ -2289,7 +2349,7 @@ safe-identifier@^0.4.1: resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== -schema-utils@^3.1.0, schema-utils@^3.1.1: +schema-utils@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-3.1.1.tgz#bc74c4b6b6995c1d88f76a8b77bea7219e0c8281" integrity sha512-Y5PQxS4ITlC+EahLuXaY86TXfR7Dc5lw294alXOq86JAHCihAIZfqv8nNCWvaEJvaC51uN9hbLGeV0cFBdH+Fw== @@ -2298,6 +2358,15 @@ schema-utils@^3.1.0, schema-utils@^3.1.1: ajv "^6.12.5" ajv-keywords "^3.5.2" +schema-utils@^3.1.2: + version "3.3.0" + resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-3.3.0.tgz#f50a88877c3c01652a15b622ae9e9795df7a60fe" + integrity sha512-pN/yOAvcC+5rQ5nERGuwrjLlYvLTbCibnZ1I7B1LaiAz9BRBlE9GMgE/eqV30P7aJQUf7Ddimy/RsbYO/GrVGg== + dependencies: + "@types/json-schema" "^7.0.8" + ajv "^6.12.5" + ajv-keywords "^3.5.2" + schema-utils@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-4.0.0.tgz#60331e9e3ae78ec5d16353c467c34b3a0a1d3df7" @@ -2313,11 +2382,12 @@ select-hose@^2.0.0: resolved "https://registry.yarnpkg.com/select-hose/-/select-hose-2.0.0.tgz#625d8658f865af43ec962bfc376a37359a4994ca" integrity sha512-mEugaLK+YfkijB4fx0e6kImuJdCIt2LxCRcbEYPqRGCs4F2ogyfZU5IAZRdjCP8JPq2AtdNoC/Dux63d9Kiryg== -selfsigned@^2.0.1: - version "2.1.1" - resolved "https://registry.yarnpkg.com/selfsigned/-/selfsigned-2.1.1.tgz#18a7613d714c0cd3385c48af0075abf3f266af61" - integrity sha512-GSL3aowiF7wa/WtSFwnUrludWFoNhftq8bUkH9pkzjpN2XSPOAYEgg6e0sS9s0rZwgJzJiQRPU18A6clnoW5wQ== +selfsigned@^2.1.1: + version "2.4.1" + resolved "https://registry.yarnpkg.com/selfsigned/-/selfsigned-2.4.1.tgz#560d90565442a3ed35b674034cec4e95dceb4ae0" + integrity sha512-th5B4L2U+eGLq1TVh7zNRGBapioSORUeymIydxgFpwww9d2qyKvtuPU2jJuHvYAwwqi2Y596QBL3eEqcPEYL8Q== dependencies: + "@types/node-forge" "^1.3.0" node-forge "^1" semver@^7.3.8: @@ -2412,6 +2482,11 @@ shebang-regex@^3.0.0: resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172" integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A== +shell-quote@^1.8.1: + version "1.8.1" + resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.8.1.tgz#6dbf4db75515ad5bac63b4f1894c3a154c766680" + integrity sha512-6j1W9l1iAs/4xYBI1SYOVZyFcCis9b4KCLQ8fgAGG07QvzaRLVVRQvAy85yNmmZSjYjg4MWh4gNvlPujU/5LpA== + side-channel@^1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/side-channel/-/side-channel-1.0.4.tgz#efce5c8fdc104ee751b25c58d4290011fa5ea2cf" @@ -2467,10 +2542,10 @@ source-map-js@^1.0.2: resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.0.2.tgz#adbc361d9c62df380125e7f161f71c826f1e490c" integrity sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw== -source-map-loader@4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/source-map-loader/-/source-map-loader-4.0.0.tgz#bdc6b118bc6c87ee4d8d851f2d4efcc5abdb2ef5" - integrity sha512-i3KVgM3+QPAHNbGavK+VBq03YoJl24m9JWNbLgsjTj8aJzXG9M61bantBTNBt7CNwY2FYf+RJRYJ3pzalKjIrw== +source-map-loader@4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/source-map-loader/-/source-map-loader-4.0.1.tgz#72f00d05f5d1f90f80974eda781cbd7107c125f2" + integrity sha512-oqXpzDIByKONVY8g1NUPOTQhe0UTU5bWUl32GSkqK2LjJj0HmwTMVKxcUip0RgAYhY1mqgOxjbQM48a0mmeNfA== dependencies: abab "^2.0.6" iconv-lite "^0.6.3" @@ -2600,24 +2675,24 @@ tapable@^2.1.1, tapable@^2.2.0: resolved "https://registry.yarnpkg.com/tapable/-/tapable-2.2.1.tgz#1967a73ef4060a82f12ab96af86d52fdb76eeca0" integrity sha512-GNzQvQTOIP6RyTfE2Qxb8ZVlNmw0n88vp1szwWRimP02mnTsx3Wtn5qRdqY9w2XduFNUgvOwhNnQsjwCp+kqaQ== -terser-webpack-plugin@^5.1.3: - version "5.3.7" - resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-5.3.7.tgz#ef760632d24991760f339fe9290deb936ad1ffc7" - integrity sha512-AfKwIktyP7Cu50xNjXF/6Qb5lBNzYaWpU6YfoX3uZicTx0zTy0stDDCsvjDapKsSDvOeWo5MEq4TmdBy2cNoHw== +terser-webpack-plugin@^5.3.7: + version "5.3.10" + resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-5.3.10.tgz#904f4c9193c6fd2a03f693a2150c62a92f40d199" + integrity sha512-BKFPWlPDndPs+NGGCr1U59t0XScL5317Y0UReNrHaw9/FwhPENlq6bfgs+4yPfyP51vqC1bQ4rp1EfXW5ZSH9w== dependencies: - "@jridgewell/trace-mapping" "^0.3.17" + "@jridgewell/trace-mapping" "^0.3.20" jest-worker "^27.4.5" schema-utils "^3.1.1" serialize-javascript "^6.0.1" - terser "^5.16.5" + terser "^5.26.0" -terser@^5.16.5: - version "5.16.6" - resolved "https://registry.yarnpkg.com/terser/-/terser-5.16.6.tgz#f6c7a14a378ee0630fbe3ac8d1f41b4681109533" - integrity sha512-IBZ+ZQIA9sMaXmRZCUMDjNH0D5AQQfdn4WUjHL0+1lF4TP1IHRJbrhb6fNaXWikrYQTSkb7SLxkeXAiy1p7mbg== +terser@^5.26.0: + version "5.26.0" + resolved "https://registry.yarnpkg.com/terser/-/terser-5.26.0.tgz#ee9f05d929f4189a9c28a0feb889d96d50126fe1" + integrity sha512-dytTGoE2oHgbNV9nTzgBEPaqAWvcJNl66VZ0BkJqlvp71IjO8CxdBx/ykCNb47cLnCmCvRZ6ZR0tLkqvZCdVBQ== dependencies: - "@jridgewell/source-map" "^0.3.2" - acorn "^8.5.0" + "@jridgewell/source-map" "^0.3.3" + acorn "^8.8.2" commander "^2.20.0" source-map-support "~0.5.20" @@ -2653,10 +2728,10 @@ type-is@~1.6.18: media-typer "0.3.0" mime-types "~2.1.24" -typescript@4.7.4: - version "4.7.4" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.4.tgz#1a88596d1cf47d59507a1bcdfb5b9dfe4d488235" - integrity sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ== +typescript@5.0.4: + version "5.0.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.0.4.tgz#b217fd20119bd61a94d4011274e0ab369058da3b" + integrity sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw== ua-parser-js@^0.7.30: version "0.7.34" @@ -2728,22 +2803,23 @@ wbuf@^1.1.0, wbuf@^1.7.3: dependencies: minimalistic-assert "^1.0.0" -webpack-cli@4.10.0: - version "4.10.0" - resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-4.10.0.tgz#37c1d69c8d85214c5a65e589378f53aec64dab31" - integrity sha512-NLhDfH/h4O6UOy+0LSso42xvYypClINuMNBVVzX4vX98TmTaTUxwRbXdhucbFMd2qLaCTcLq/PdYrvi8onw90w== +webpack-cli@5.1.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-5.1.0.tgz#abc4b1f44b50250f2632d8b8b536cfe2f6257891" + integrity sha512-a7KRJnCxejFoDpYTOwzm5o21ZXMaNqtRlvS183XzGDUPRdVEzJNImcQokqYZ8BNTnk9DkKiuWxw75+DCCoZ26w== dependencies: "@discoveryjs/json-ext" "^0.5.0" - "@webpack-cli/configtest" "^1.2.0" - "@webpack-cli/info" "^1.5.0" - "@webpack-cli/serve" "^1.7.0" + "@webpack-cli/configtest" "^2.1.0" + "@webpack-cli/info" "^2.0.1" + "@webpack-cli/serve" "^2.0.3" colorette "^2.0.14" - commander "^7.0.0" + commander "^10.0.1" cross-spawn "^7.0.3" + envinfo "^7.7.3" fastest-levenshtein "^1.0.12" import-local "^3.0.2" - interpret "^2.2.0" - rechoir "^0.7.0" + interpret "^3.1.1" + rechoir "^0.8.0" webpack-merge "^5.7.3" webpack-dev-middleware@^5.3.1: @@ -2757,10 +2833,10 @@ webpack-dev-middleware@^5.3.1: range-parser "^1.2.1" schema-utils "^4.0.0" -webpack-dev-server@4.9.3: - version "4.9.3" - resolved "https://registry.yarnpkg.com/webpack-dev-server/-/webpack-dev-server-4.9.3.tgz#2360a5d6d532acb5410a668417ad549ee3b8a3c9" - integrity sha512-3qp/eoboZG5/6QgiZ3llN8TUzkSpYg1Ko9khWX1h40MIEUNS2mDoIa8aXsPfskER+GbTvs/IJZ1QTBBhhuetSw== +webpack-dev-server@4.15.0: + version "4.15.0" + resolved "https://registry.yarnpkg.com/webpack-dev-server/-/webpack-dev-server-4.15.0.tgz#87ba9006eca53c551607ea0d663f4ae88be7af21" + integrity sha512-HmNB5QeSl1KpulTBQ8UT4FPrByYyaLxpJoQ0+s7EvUrMc16m0ZS1sgb1XGqzmgCPk0c9y+aaXxn11tbLzuM7NQ== dependencies: "@types/bonjour" "^3.5.9" "@types/connect-history-api-fallback" "^1.3.5" @@ -2781,16 +2857,17 @@ webpack-dev-server@4.9.3: html-entities "^2.3.2" http-proxy-middleware "^2.0.3" ipaddr.js "^2.0.1" + launch-editor "^2.6.0" open "^8.0.9" p-retry "^4.5.0" rimraf "^3.0.2" schema-utils "^4.0.0" - selfsigned "^2.0.1" + selfsigned "^2.1.1" serve-index "^1.9.1" sockjs "^0.3.24" spdy "^4.0.2" webpack-dev-middleware "^5.3.1" - ws "^8.4.2" + ws "^8.13.0" webpack-merge@^4.1.5: version "4.2.2" @@ -2812,22 +2889,22 @@ webpack-sources@^3.2.3: resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.2.3.tgz#2d4daab8451fd4b240cc27055ff6a0c2ccea0cde" integrity sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w== -webpack@5.74.0: - version "5.74.0" - resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.74.0.tgz#02a5dac19a17e0bb47093f2be67c695102a55980" - integrity sha512-A2InDwnhhGN4LYctJj6M1JEaGL7Luj6LOmyBHjcI8529cm5p6VXiTIW2sn6ffvEAKmveLzvu4jrihwXtPojlAA== +webpack@5.82.0: + version "5.82.0" + resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.82.0.tgz#3c0d074dec79401db026b4ba0fb23d6333f88e7d" + integrity sha512-iGNA2fHhnDcV1bONdUu554eZx+XeldsaeQ8T67H6KKHl2nUSwX8Zm7cmzOA46ox/X1ARxf7Bjv8wQ/HsB5fxBg== dependencies: "@types/eslint-scope" "^3.7.3" - "@types/estree" "^0.0.51" - "@webassemblyjs/ast" "1.11.1" - "@webassemblyjs/wasm-edit" "1.11.1" - "@webassemblyjs/wasm-parser" "1.11.1" + "@types/estree" "^1.0.0" + "@webassemblyjs/ast" "^1.11.5" + "@webassemblyjs/wasm-edit" "^1.11.5" + "@webassemblyjs/wasm-parser" "^1.11.5" acorn "^8.7.1" acorn-import-assertions "^1.7.6" browserslist "^4.14.5" chrome-trace-event "^1.0.2" - enhanced-resolve "^5.10.0" - es-module-lexer "^0.9.0" + enhanced-resolve "^5.13.0" + es-module-lexer "^1.2.1" eslint-scope "5.1.1" events "^3.2.0" glob-to-regexp "^0.4.1" @@ -2836,9 +2913,9 @@ webpack@5.74.0: loader-runner "^4.2.0" mime-types "^2.1.27" neo-async "^2.6.2" - schema-utils "^3.1.0" + schema-utils "^3.1.2" tapable "^2.1.1" - terser-webpack-plugin "^5.1.3" + terser-webpack-plugin "^5.3.7" watchpack "^2.4.0" webpack-sources "^3.2.3" @@ -2894,10 +2971,10 @@ wrappy@1: resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" integrity sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ== -ws@^8.4.2: - version "8.13.0" - resolved "https://registry.yarnpkg.com/ws/-/ws-8.13.0.tgz#9a9fb92f93cf41512a0735c8f4dd09b8a1211cd0" - integrity sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA== +ws@^8.13.0: + version "8.16.0" + resolved "https://registry.yarnpkg.com/ws/-/ws-8.16.0.tgz#d1cd774f36fbc07165066a60e40323eab6446fd4" + integrity sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ== ws@~8.11.0: version "8.11.0" diff --git a/samples/resources-gallery/mpp-library/nested-module/src/commonMain/resources/MR/base/strings.xml b/samples/resources-gallery/mpp-library/nested-module/src/commonMain/moko-resources/base/strings.xml similarity index 100% rename from samples/resources-gallery/mpp-library/nested-module/src/commonMain/resources/MR/base/strings.xml rename to samples/resources-gallery/mpp-library/nested-module/src/commonMain/moko-resources/base/strings.xml diff --git a/samples/resources-gallery/mpp-library/nested-module/src/commonMain/resources/MR/files/nested-test.json b/samples/resources-gallery/mpp-library/nested-module/src/commonMain/moko-resources/files/nested-test.json similarity index 100% rename from samples/resources-gallery/mpp-library/nested-module/src/commonMain/resources/MR/files/nested-test.json rename to samples/resources-gallery/mpp-library/nested-module/src/commonMain/moko-resources/files/nested-test.json diff --git a/samples/resources-gallery/mpp-library/nested-module/src/commonMain/resources/MR/ru/strings.xml b/samples/resources-gallery/mpp-library/nested-module/src/commonMain/moko-resources/ru/strings.xml similarity index 100% rename from samples/resources-gallery/mpp-library/nested-module/src/commonMain/resources/MR/ru/strings.xml rename to samples/resources-gallery/mpp-library/nested-module/src/commonMain/moko-resources/ru/strings.xml diff --git a/samples/resources-gallery/mpp-library/src/commonMain/kotlin/com/icerockdev/library/Testing.kt b/samples/resources-gallery/mpp-library/src/commonMain/kotlin/com/icerockdev/library/Testing.kt index d0c694bc1..3b981d549 100644 --- a/samples/resources-gallery/mpp-library/src/commonMain/kotlin/com/icerockdev/library/Testing.kt +++ b/samples/resources-gallery/mpp-library/src/commonMain/kotlin/com/icerockdev/library/Testing.kt @@ -112,19 +112,19 @@ public object Testing { return list.joinToStringDesc("\n") } - public fun getFontTtf1(): FontResource = MR.fonts.Raleway.italic + public fun getFontTtf1(): FontResource = MR.fonts.raleway_italic - public fun getFontTtf2(): FontResource = MR.fonts.Raleway.bold + public fun getFontTtf2(): FontResource = MR.fonts.raleway_bold - public fun getFontOtf1(): FontResource = MR.fonts.cormorant.regular - public fun getFontOtf2(): FontResource = MR.fonts.cormorant.italic - public fun getFontOtf3(): FontResource = MR.fonts.cormorant.light + public fun getFontOtf1(): FontResource = MR.fonts.cormorant_regular + public fun getFontOtf2(): FontResource = MR.fonts.cormorant_italic + public fun getFontOtf3(): FontResource = MR.fonts.cormorant_light public fun getTextsFromAssets(): List { return listOf( MR.assets.test_1, MR.assets.getAssetByFilePath("texts/test2.txt") ?: error("Can't load asset"), - MR.assets.texts.inner_1.test3 + MR.assets.test3 // FIXME duplication will be here! ) } diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/assets/test-1.txt b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/assets/test-1.txt similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/assets/test-1.txt rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/assets/test-1.txt diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/assets/texts/inner-1/test3.txt b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/assets/texts/inner-1/test3.txt similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/assets/texts/inner-1/test3.txt rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/assets/texts/inner-1/test3.txt diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/assets/texts/test2.txt b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/assets/texts/test2.txt similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/assets/texts/test2.txt rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/assets/texts/test2.txt diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/base/plurals-test.xml b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/base/plurals-test.xml similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/base/plurals-test.xml rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/base/plurals-test.xml diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/base/plurals.xml b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/base/plurals.xml similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/base/plurals.xml rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/base/plurals.xml diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/base/strings-test.xml b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/base/strings-test.xml similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/base/strings-test.xml rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/base/strings-test.xml diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/base/strings.xml b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/base/strings.xml similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/base/strings.xml rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/base/strings.xml diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/colors/colors.xml b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/colors/colors.xml similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/colors/colors.xml rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/colors/colors.xml diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/en-rGB/plurals-test.xml b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/en-rGB/plurals-test.xml similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/en-rGB/plurals-test.xml rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/en-rGB/plurals-test.xml diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/en-rGB/plurals.xml b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/en-rGB/plurals.xml similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/en-rGB/plurals.xml rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/en-rGB/plurals.xml diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/en-rGB/strings-test.xml b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/en-rGB/strings-test.xml similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/en-rGB/strings-test.xml rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/en-rGB/strings-test.xml diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/en-rGB/strings.xml b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/en-rGB/strings.xml similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/en-rGB/strings.xml rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/en-rGB/strings.xml diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/en-rUS/plurals-test.xml b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/en-rUS/plurals-test.xml similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/en-rUS/plurals-test.xml rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/en-rUS/plurals-test.xml diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/en-rUS/plurals.xml b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/en-rUS/plurals.xml similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/en-rUS/plurals.xml rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/en-rUS/plurals.xml diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/en-rUS/strings-test.xml b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/en-rUS/strings-test.xml similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/en-rUS/strings-test.xml rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/en-rUS/strings-test.xml diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/en-rUS/strings.xml b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/en-rUS/strings.xml similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/en-rUS/strings.xml rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/en-rUS/strings.xml diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/es/plurals-test.xml b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/es/plurals-test.xml similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/es/plurals-test.xml rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/es/plurals-test.xml diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/es/plurals.xml b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/es/plurals.xml similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/es/plurals.xml rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/es/plurals.xml diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/es/strings.xml b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/es/strings.xml similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/es/strings.xml rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/es/strings.xml diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/files/some.json b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/files/some.json similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/files/some.json rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/files/some.json diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/files/test.txt b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/files/test.txt similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/files/test.txt rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/files/test.txt diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/fonts/Raleway-Bold.ttf b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/fonts/Raleway-Bold.ttf similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/fonts/Raleway-Bold.ttf rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/fonts/Raleway-Bold.ttf diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/fonts/Raleway-Italic.ttf b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/fonts/Raleway-Italic.ttf similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/fonts/Raleway-Italic.ttf rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/fonts/Raleway-Italic.ttf diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/fonts/Raleway-Regular.ttf b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/fonts/Raleway-Regular.ttf similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/fonts/Raleway-Regular.ttf rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/fonts/Raleway-Regular.ttf diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/fonts/cormorant-italic.otf b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/fonts/cormorant-italic.otf similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/fonts/cormorant-italic.otf rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/fonts/cormorant-italic.otf diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/fonts/cormorant-light.otf b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/fonts/cormorant-light.otf similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/fonts/cormorant-light.otf rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/fonts/cormorant-light.otf diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/fonts/cormorant-regular.otf b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/fonts/cormorant-regular.otf similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/fonts/cormorant-regular.otf rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/fonts/cormorant-regular.otf diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/images/car_black.svg b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/images/car_black.svg similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/images/car_black.svg rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/images/car_black.svg diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/images/home_black_18@1x.png b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/images/home_black_18@1x.png similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/images/home_black_18@1x.png rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/images/home_black_18@1x.png diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/images/home_black_18@2x.png b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/images/home_black_18@2x.png similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/images/home_black_18@2x.png rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/images/home_black_18@2x.png diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/in-rPB/strings.xml b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/in-rPB/strings.xml similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/in-rPB/strings.xml rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/in-rPB/strings.xml diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/in/strings.xml b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/in/strings.xml similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/in/strings.xml rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/in/strings.xml diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/ru/plurals-test.xml b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/ru/plurals-test.xml similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/ru/plurals-test.xml rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/ru/plurals-test.xml diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/ru/plurals.xml b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/ru/plurals.xml similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/ru/plurals.xml rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/ru/plurals.xml diff --git a/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/ru/strings.xml b/samples/resources-gallery/mpp-library/src/commonMain/moko-resources/ru/strings.xml similarity index 100% rename from samples/resources-gallery/mpp-library/src/commonMain/resources/MR/ru/strings.xml rename to samples/resources-gallery/mpp-library/src/commonMain/moko-resources/ru/strings.xml From 727e18e23901fcc15297699b222808e61b895cb2 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sat, 13 Jan 2024 20:43:26 +0700 Subject: [PATCH 114/352] #535 fix detekt --- .../kotlin/dev/icerock/gradle/extra/mokoResourcesGenTask.kt | 3 ++- .../dev/icerock/gradle/extra/mokoResourcesSourceDirectory.kt | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/extra/mokoResourcesGenTask.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/extra/mokoResourcesGenTask.kt index a52651035..38b40a3ba 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/extra/mokoResourcesGenTask.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/extra/mokoResourcesGenTask.kt @@ -2,6 +2,8 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ +@file:Suppress("Filename") + package dev.icerock.gradle.extra import dev.icerock.gradle.MultiplatformResourcesPluginExtension @@ -17,7 +19,6 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import org.jetbrains.kotlin.tooling.core.extrasKeyOf import java.io.File - private fun mokoResourcesGenTaskKey() = extrasKeyOf>("moko-resources-generate-task") diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/extra/mokoResourcesSourceDirectory.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/extra/mokoResourcesSourceDirectory.kt index 388a26979..64611301f 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/extra/mokoResourcesSourceDirectory.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/extra/mokoResourcesSourceDirectory.kt @@ -2,6 +2,8 @@ * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ +@file:Suppress("Filename") + package dev.icerock.gradle.extra import org.gradle.api.file.SourceDirectorySet From 9d6bc427511a0607294201cc37facc798b58396c Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sat, 13 Jan 2024 21:23:46 +0700 Subject: [PATCH 115/352] #535 fix generation without android target --- .../main/kotlin/dev/icerock/gradle/utils/ProjectExt.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProjectExt.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProjectExt.kt index 040e31bab..9e43361e2 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProjectExt.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/ProjectExt.kt @@ -19,6 +19,14 @@ import javax.xml.parsers.DocumentBuilderFactory internal fun Project.getAndroidRClassPackage(): Provider { return provider { + // before call android specific classes we should ensure that android plugin in classpath at all + // it's required to support gradle projects without android target + val isAndroidEnabled = listOf( + "com.android.library", + "com.android.application" + ).any { project.plugins.findPlugin(it) != null } + if (!isAndroidEnabled) return@provider null + val androidExt: BaseExtension = project.extensions.findByType() ?: return@provider null androidExt.namespace ?: getAndroidPackage(androidExt.mainSourceSet.manifest.srcFile) From 20f75559be833f73dd51adb30ac9cb415fb6f0f8 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sat, 13 Jan 2024 21:24:08 +0700 Subject: [PATCH 116/352] #535 update compose-jvm-app sample --- samples/compose-jvm-app/build.gradle.kts | 4 ++-- .../src/desktopMain/kotlin/me/amikhailov/common/Main.kt | 4 ++-- .../common/src/desktopMain/moko-resources/base/strings.xml | 4 ++++ samples/compose-jvm-app/gradle.properties | 4 ++-- 4 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 samples/compose-jvm-app/common/src/desktopMain/moko-resources/base/strings.xml diff --git a/samples/compose-jvm-app/build.gradle.kts b/samples/compose-jvm-app/build.gradle.kts index 791cf2917..17377f439 100644 --- a/samples/compose-jvm-app/build.gradle.kts +++ b/samples/compose-jvm-app/build.gradle.kts @@ -7,7 +7,7 @@ buildscript { } dependencies { classpath(moko.resourcesGradlePlugin) - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0") - classpath("org.jetbrains.compose:compose-gradle-plugin:1.5.0") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.10") + classpath("org.jetbrains.compose:compose-gradle-plugin:1.5.11") } } diff --git a/samples/compose-jvm-app/common/src/desktopMain/kotlin/me/amikhailov/common/Main.kt b/samples/compose-jvm-app/common/src/desktopMain/kotlin/me/amikhailov/common/Main.kt index 4c8ca787c..12de06687 100644 --- a/samples/compose-jvm-app/common/src/desktopMain/kotlin/me/amikhailov/common/Main.kt +++ b/samples/compose-jvm-app/common/src/desktopMain/kotlin/me/amikhailov/common/Main.kt @@ -11,11 +11,11 @@ import androidx.compose.ui.unit.DpSize import androidx.compose.ui.unit.dp import androidx.compose.ui.window.WindowState import androidx.compose.ui.window.singleWindowApplication +import com.icerockdev.app.MR fun main() { - singleWindowApplication( - title = "moko-resources", + title = MR.strings.title.localized(), state = WindowState(size = DpSize(1080.dp, 960.dp)) ) { Surface(Modifier.fillMaxSize()) { diff --git a/samples/compose-jvm-app/common/src/desktopMain/moko-resources/base/strings.xml b/samples/compose-jvm-app/common/src/desktopMain/moko-resources/base/strings.xml new file mode 100644 index 000000000..97621df9f --- /dev/null +++ b/samples/compose-jvm-app/common/src/desktopMain/moko-resources/base/strings.xml @@ -0,0 +1,4 @@ + + + Title of sample + diff --git a/samples/compose-jvm-app/gradle.properties b/samples/compose-jvm-app/gradle.properties index 65bc032da..f432cf1f4 100644 --- a/samples/compose-jvm-app/gradle.properties +++ b/samples/compose-jvm-app/gradle.properties @@ -1,6 +1,6 @@ org.gradle.jvmargs=-Xmx12g org.gradle.parallel=true org.gradle.caching=true +org.gradle.configuration-cache=true + kotlin.code.style=official -kotlin.mpp.enableGranularSourceSetsMetadata=true -kotlin.native.enableDependencyPropagation=false From 08d6b8e3dee026e715ee858cad1b64d63f11cfd3 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sat, 13 Jan 2024 23:25:29 +0700 Subject: [PATCH 117/352] #535 fix copyXCFrameworkResources task --- .../gradle/MultiplatformResourcesPlugin.kt | 3 ++ .../platform/apple/SetupAppleUtils.kt | 43 +++++++++++++------ .../tasks/CopyXCFrameworkResourcesToApp.kt | 22 ++++++---- 3 files changed, 45 insertions(+), 23 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 3fd9415ae..f1e967c07 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -9,6 +9,7 @@ import com.android.build.gradle.api.BaseVariant import com.android.build.gradle.internal.lint.AndroidLintAnalysisTask import dev.icerock.gradle.extra.getOrRegisterGenerateResourcesTask import dev.icerock.gradle.generator.platform.apple.setupAppleKLibResources +import dev.icerock.gradle.generator.platform.apple.setupCopyXCFrameworkResourcesTask import dev.icerock.gradle.generator.platform.apple.setupFatFrameworkTasks import dev.icerock.gradle.generator.platform.apple.setupFrameworkResources import dev.icerock.gradle.generator.platform.apple.setupTestsResources @@ -56,6 +57,8 @@ open class MultiplatformResourcesPlugin : Plugin { mrExtension = mrExtension, kmpExtension = kmpExtension ) + + setupCopyXCFrameworkResourcesTask(project = project) } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt index dcfba2fec..15fdc4be2 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt @@ -11,16 +11,19 @@ import dev.icerock.gradle.actions.apple.CopyResourcesFromKLibsToExecutableAction import dev.icerock.gradle.actions.apple.CopyResourcesFromKLibsToFrameworkAction import dev.icerock.gradle.actions.apple.PackAppleResourcesToKLibAction import dev.icerock.gradle.tasks.CopyFrameworkResourcesToAppTask +import dev.icerock.gradle.tasks.CopyXCFrameworkResourcesToApp import org.gradle.api.Action import org.gradle.api.Project import org.gradle.api.Task import org.gradle.api.provider.Provider import org.gradle.api.tasks.TaskProvider import org.gradle.kotlin.dsl.getByType +import org.gradle.kotlin.dsl.register import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.plugin.mpp.Framework import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable +import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFrameworkTask import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile import java.io.File @@ -108,20 +111,32 @@ internal fun createCopyFrameworkResourcesTask(framework: Framework) { // } } -// private fun setupCopyXCFrameworkResourcesTask(project: Project) { -// // Seems that there were problem with this block in the past with mystic task adding. Need more info -// // Now, that works perfectly, I've tested on the real project with Kotlin 1.9.10 and KSP enabled -// // Suppose that on that moment there were no lazy register method for task container -// project.tasks.withType(XCFrameworkTask::class).all { task -> -// val copyTaskName: String = task.name -// .replace("assemble", "copyResources").plus("ToApp") -// -// project.tasks.register(copyTaskName) { -// xcFrameworkDir = task.outputDir -// dependsOn(task) -// } -// } -// } +internal fun setupCopyXCFrameworkResourcesTask(project: Project) { + // Seems that there were problem with this block in the past with mystic task adding. Need more info + // Now, that works perfectly, I've tested on the real project with Kotlin 1.9.10 and KSP enabled + // Suppose that on that moment there were no lazy register method for task container + project.tasks.withType(XCFrameworkTask::class).all { task -> + val copyTaskName: String = task.name + .replace("assemble", "copyResources").plus("ToApp") + + project.tasks.register(copyTaskName) { + xcFrameworkDir.set(task.outputDir) + outputDir.set( + project.layout.dir( + project.provider { + val buildProductsDir = + project.property("moko.resources.BUILT_PRODUCTS_DIR") as String + val contentsFolderPath = + project.property("moko.resources.CONTENTS_FOLDER_PATH") as String + + File("$buildProductsDir/$contentsFolderPath") + } + ) + ) + dependsOn(task) + } + } +} // private fun createCopyResourcesToAppTask(project: Project) { // project.tasks diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyXCFrameworkResourcesToApp.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyXCFrameworkResourcesToApp.kt index 4ee722f76..c5f6f0a24 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyXCFrameworkResourcesToApp.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyXCFrameworkResourcesToApp.kt @@ -5,29 +5,33 @@ package dev.icerock.gradle.tasks import org.gradle.api.DefaultTask +import org.gradle.api.file.DirectoryProperty import org.gradle.api.tasks.InputDirectory +import org.gradle.api.tasks.OutputDirectory import org.gradle.api.tasks.TaskAction import java.io.File import java.io.FileFilter -// TODO register tasks -open class CopyXCFrameworkResourcesToApp : DefaultTask() { +abstract class CopyXCFrameworkResourcesToApp : DefaultTask() { init { group = "moko-resources" } - @InputDirectory - lateinit var xcFrameworkDir: File + @get:InputDirectory + abstract val xcFrameworkDir: DirectoryProperty + + @get:OutputDirectory + abstract val outputDir: DirectoryProperty @TaskAction fun copyResources() { - val buildProductsDir = project.property("moko.resources.BUILT_PRODUCTS_DIR") as String - val contentsFolderPath = project.property("moko.resources.CONTENTS_FOLDER_PATH") as String - val outputDir = File("$buildProductsDir/$contentsFolderPath") + val outputDir = outputDir.get().asFile + + val frameworkDir: File = xcFrameworkDir.get().asFile.walkTopDown() + .first { it.extension == "framework" } - val frameworkDir: File = xcFrameworkDir.walkTopDown().first { it.extension == "framework" } frameworkDir.listFiles(FileFilter { it.extension == "bundle" })?.forEach { - project.logger.info("copy resources bundle $it to $outputDir") + logger.info("copy resources bundle $it to $outputDir") it.copyRecursively(File(outputDir, it.name), overwrite = true) } } From cbfba8f3fd35438bad2f4472d3cb7ebf1b7f75a9 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sat, 13 Jan 2024 23:25:46 +0700 Subject: [PATCH 118/352] #535 update ios-static-xcframework sample --- samples/ios-static-xcframework/gradle.properties | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/samples/ios-static-xcframework/gradle.properties b/samples/ios-static-xcframework/gradle.properties index 6997371c9..4508c328f 100755 --- a/samples/ios-static-xcframework/gradle.properties +++ b/samples/ios-static-xcframework/gradle.properties @@ -1,6 +1,10 @@ org.gradle.jvmargs=-Xmx12g org.gradle.parallel=true org.gradle.caching=true +org.gradle.configuration-cache=true + kotlin.code.style=official + kotlin.mpp.stability.nowarn=true + xcodeproj=./ios-app From 8b06391f31b7fb2c7146e657cc879fbffc97a66f Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 14 Jan 2024 14:57:32 +0700 Subject: [PATCH 119/352] #535 update kotlin-ios-app sample --- samples/kotlin-ios-app/build.gradle.kts | 2 +- samples/kotlin-ios-app/gradle.properties | 4 ++++ samples/kotlin-ios-app/ios-kotlin-app/build.gradle.kts | 1 - .../ios-kotlin-app/src/iosMain/kotlin/AppDelegate.kt | 2 ++ .../kotlin-ios-app/ios-kotlin-app/src/iosMain/kotlin/main.kt | 3 +++ samples/kotlin-ios-app/mpp-library/build.gradle.kts | 1 - .../iosMain/{resources/MR => moko-resources}/base/strings.xml | 0 7 files changed, 10 insertions(+), 3 deletions(-) rename samples/kotlin-ios-app/mpp-library/src/iosMain/{resources/MR => moko-resources}/base/strings.xml (100%) diff --git a/samples/kotlin-ios-app/build.gradle.kts b/samples/kotlin-ios-app/build.gradle.kts index 7eada2742..37e7cc5c5 100644 --- a/samples/kotlin-ios-app/build.gradle.kts +++ b/samples/kotlin-ios-app/build.gradle.kts @@ -11,6 +11,6 @@ buildscript { } dependencies { classpath(moko.resourcesGradlePlugin) - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.10") } } diff --git a/samples/kotlin-ios-app/gradle.properties b/samples/kotlin-ios-app/gradle.properties index d1b4752d7..c77827bf9 100755 --- a/samples/kotlin-ios-app/gradle.properties +++ b/samples/kotlin-ios-app/gradle.properties @@ -1,7 +1,11 @@ org.gradle.jvmargs=-Xmx12g org.gradle.parallel=true org.gradle.caching=true +org.gradle.configuration-cache=true + kotlin.code.style=official + kotlin.mpp.stability.nowarn=true kotlin.mpp.androidGradlePluginCompatibility.nowarn=true + xcodeproj=./xcode-project diff --git a/samples/kotlin-ios-app/ios-kotlin-app/build.gradle.kts b/samples/kotlin-ios-app/ios-kotlin-app/build.gradle.kts index 7a3d9e31e..34d734415 100644 --- a/samples/kotlin-ios-app/ios-kotlin-app/build.gradle.kts +++ b/samples/kotlin-ios-app/ios-kotlin-app/build.gradle.kts @@ -41,5 +41,4 @@ kotlin { multiplatformResources { resourcesPackage.set("com.icerockdev.app") - resourcesSourceSet = "iosMain" } diff --git a/samples/kotlin-ios-app/ios-kotlin-app/src/iosMain/kotlin/AppDelegate.kt b/samples/kotlin-ios-app/ios-kotlin-app/src/iosMain/kotlin/AppDelegate.kt index 702ac240c..5bd38159b 100644 --- a/samples/kotlin-ios-app/ios-kotlin-app/src/iosMain/kotlin/AppDelegate.kt +++ b/samples/kotlin-ios-app/ios-kotlin-app/src/iosMain/kotlin/AppDelegate.kt @@ -1,3 +1,4 @@ +import kotlinx.cinterop.ExperimentalForeignApi import platform.UIKit.UIApplication import platform.UIKit.UIApplicationDelegateProtocol import platform.UIKit.UIApplicationDelegateProtocolMeta @@ -19,6 +20,7 @@ class AppDelegate : UIResponder, UIApplicationDelegateProtocol { _window = window } + @OptIn(ExperimentalForeignApi::class) override fun application( application: UIApplication, didFinishLaunchingWithOptions: Map? diff --git a/samples/kotlin-ios-app/ios-kotlin-app/src/iosMain/kotlin/main.kt b/samples/kotlin-ios-app/ios-kotlin-app/src/iosMain/kotlin/main.kt index 3dea467e6..d3e284560 100644 --- a/samples/kotlin-ios-app/ios-kotlin-app/src/iosMain/kotlin/main.kt +++ b/samples/kotlin-ios-app/ios-kotlin-app/src/iosMain/kotlin/main.kt @@ -1,3 +1,5 @@ +import kotlinx.cinterop.BetaInteropApi +import kotlinx.cinterop.ExperimentalForeignApi import kotlinx.cinterop.autoreleasepool import kotlinx.cinterop.cstr import kotlinx.cinterop.memScoped @@ -5,6 +7,7 @@ import kotlinx.cinterop.toCValues import platform.Foundation.NSStringFromClass import platform.UIKit.UIApplicationMain +@OptIn(ExperimentalForeignApi::class, BetaInteropApi::class) fun main() { val args = emptyArray() memScoped { diff --git a/samples/kotlin-ios-app/mpp-library/build.gradle.kts b/samples/kotlin-ios-app/mpp-library/build.gradle.kts index ee5f1e100..439ab8c58 100644 --- a/samples/kotlin-ios-app/mpp-library/build.gradle.kts +++ b/samples/kotlin-ios-app/mpp-library/build.gradle.kts @@ -25,5 +25,4 @@ kotlin { multiplatformResources { resourcesPackage.set("com.icerockdev.library") - resourcesSourceSet = "iosMain" } diff --git a/samples/kotlin-ios-app/mpp-library/src/iosMain/resources/MR/base/strings.xml b/samples/kotlin-ios-app/mpp-library/src/iosMain/moko-resources/base/strings.xml similarity index 100% rename from samples/kotlin-ios-app/mpp-library/src/iosMain/resources/MR/base/strings.xml rename to samples/kotlin-ios-app/mpp-library/src/iosMain/moko-resources/base/strings.xml From 54335bcf60cbb2fa037579f9d4e59b497c019245 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 14 Jan 2024 16:03:21 +0700 Subject: [PATCH 120/352] #535 fix copy resources to executable task --- .../gradle/MultiplatformResourcesPlugin.kt | 2 + .../platform/apple/SetupAppleUtils.kt | 44 +++++++++++++------ .../tasks/CopyExecutableResourcesToApp.kt | 31 +++++++------ 3 files changed, 50 insertions(+), 27 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index f1e967c07..06ad24269 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -9,6 +9,7 @@ import com.android.build.gradle.api.BaseVariant import com.android.build.gradle.internal.lint.AndroidLintAnalysisTask import dev.icerock.gradle.extra.getOrRegisterGenerateResourcesTask import dev.icerock.gradle.generator.platform.apple.setupAppleKLibResources +import dev.icerock.gradle.generator.platform.apple.setupCopyResourcesToAppTask import dev.icerock.gradle.generator.platform.apple.setupCopyXCFrameworkResourcesTask import dev.icerock.gradle.generator.platform.apple.setupFatFrameworkTasks import dev.icerock.gradle.generator.platform.apple.setupFrameworkResources @@ -59,6 +60,7 @@ open class MultiplatformResourcesPlugin : Plugin { ) setupCopyXCFrameworkResourcesTask(project = project) + setupCopyResourcesToAppTask(project = project) } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt index 15fdc4be2..5d772e0de 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt @@ -10,8 +10,10 @@ import dev.icerock.gradle.actions.apple.CopyResourcesFromFrameworkToFatAction import dev.icerock.gradle.actions.apple.CopyResourcesFromKLibsToExecutableAction import dev.icerock.gradle.actions.apple.CopyResourcesFromKLibsToFrameworkAction import dev.icerock.gradle.actions.apple.PackAppleResourcesToKLibAction +import dev.icerock.gradle.tasks.CopyExecutableResourcesToApp import dev.icerock.gradle.tasks.CopyFrameworkResourcesToAppTask import dev.icerock.gradle.tasks.CopyXCFrameworkResourcesToApp +import dev.icerock.gradle.utils.klibs import org.gradle.api.Action import org.gradle.api.Project import org.gradle.api.Task @@ -20,12 +22,14 @@ import org.gradle.api.tasks.TaskProvider import org.gradle.kotlin.dsl.getByType import org.gradle.kotlin.dsl.register import org.gradle.kotlin.dsl.withType +import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractExecutable import org.jetbrains.kotlin.gradle.plugin.mpp.Framework import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFrameworkTask import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile +import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink import java.io.File @Suppress("LongParameterList") @@ -138,19 +142,33 @@ internal fun setupCopyXCFrameworkResourcesTask(project: Project) { } } -// private fun createCopyResourcesToAppTask(project: Project) { -// project.tasks -// .withType() -// .matching { it.binary is AbstractExecutable } -// .all { linkTask -> -// val copyTaskName: String = linkTask.name.replace("link", "copyResources") -// -// project.tasks.register(copyTaskName) { -// this.linkTask = linkTask -// dependsOn(linkTask) -// } -// } -// } + internal fun setupCopyResourcesToAppTask(project: Project) { + project.tasks + .withType() + .matching { it.binary is AbstractExecutable } + .all { linkTask -> + val copyTaskName: String = linkTask.name.replace("link", "copyResources") + + project.tasks.register(copyTaskName) { + dependsOn(linkTask) + + klibs.from(linkTask.klibs) + + outputDirectory.set( + project.layout.dir( + project.provider { + val buildProductsDir = + project.property("moko.resources.BUILT_PRODUCTS_DIR") as String + val contentsFolderPath = + project.property("moko.resources.CONTENTS_FOLDER_PATH") as String + + File("$buildProductsDir/$contentsFolderPath") + } + ) + ) + } + } + } internal fun setupTestsResources(compilation: KotlinNativeCompilation) { compilation.target.binaries.withType().configureEach { executable -> diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt index a59c14f16..eb5af4062 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt @@ -4,20 +4,28 @@ package dev.icerock.gradle.tasks -import dev.icerock.gradle.utils.klibs import dev.icerock.gradle.utils.toKonanFile import org.gradle.api.DefaultTask -import org.gradle.api.tasks.Internal +import org.gradle.api.file.ConfigurableFileCollection +import org.gradle.api.file.DirectoryProperty +import org.gradle.api.tasks.InputFiles +import org.gradle.api.tasks.OutputDirectory +import org.gradle.api.tasks.PathSensitive +import org.gradle.api.tasks.PathSensitivity import org.gradle.api.tasks.TaskAction -import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink +import org.jetbrains.kotlin.library.KotlinLibraryLayout import org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl import java.io.File import java.io.FileFilter -// TODO register tasks abstract class CopyExecutableResourcesToApp : DefaultTask() { - @get:Internal - abstract var linkTask: KotlinNativeLink + + @get:InputFiles + @get:PathSensitive(PathSensitivity.RELATIVE) + abstract val klibs: ConfigurableFileCollection + + @get:OutputDirectory + abstract val outputDirectory: DirectoryProperty init { group = "moko-resources" @@ -25,20 +33,15 @@ abstract class CopyExecutableResourcesToApp : DefaultTask() { @TaskAction fun copyResources() { - val buildProductsDir = - File(project.property("moko.resources.BUILT_PRODUCTS_DIR") as String) - val contentsFolderPath = - project.property("moko.resources.CONTENTS_FOLDER_PATH") as String - - val outputDir = File(buildProductsDir, contentsFolderPath) + val outputDir: File = outputDirectory.get().asFile - linkTask.klibs + klibs .filter { library -> library.extension == "klib" } .filter(File::exists) .forEach { inputFile -> val klibKonan: org.jetbrains.kotlin.konan.file.File = inputFile.toKonanFile() val klib = KotlinLibraryLayoutImpl(klib = klibKonan, component = "default") - val layout = klib.extractingToTemp + val layout: KotlinLibraryLayout = klib.extractingToTemp // extracting bundles layout From d0d6b94782876aede23cea9c91eaa53f6babd5ea Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 14 Jan 2024 18:22:35 +0700 Subject: [PATCH 121/352] #535 fix detekt --- .../gradle/generator/platform/apple/SetupAppleUtils.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt index 5d772e0de..e72d3cd58 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt @@ -142,7 +142,7 @@ internal fun setupCopyXCFrameworkResourcesTask(project: Project) { } } - internal fun setupCopyResourcesToAppTask(project: Project) { +internal fun setupCopyResourcesToAppTask(project: Project) { project.tasks .withType() .matching { it.binary is AbstractExecutable } @@ -168,7 +168,7 @@ internal fun setupCopyXCFrameworkResourcesTask(project: Project) { ) } } - } +} internal fun setupTestsResources(compilation: KotlinNativeCompilation) { compilation.target.binaries.withType().configureEach { executable -> From 7e9d7d184239e36b086fe7459086f086a8bddcae Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 14 Jan 2024 20:11:38 +0700 Subject: [PATCH 122/352] #535 enable configuration cache --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index de47c7e24..03d729970 100755 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,7 @@ org.gradle.jvmargs=-Xmx12g org.gradle.parallel=true org.gradle.caching=true +org.gradle.configuration-cache=true kotlin.code.style=official @@ -13,6 +14,5 @@ org.jetbrains.compose.experimental.uikit.enabled=true org.jetbrains.compose.experimental.macos.enabled=true android.useAndroidX=true -android.disableAutomaticComponentCreation=true mobile.multiplatform.iosTargetWarning=false From a2d00b791b1f4a63d355f141bc5d375ecce685b7 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 14 Jan 2024 20:11:54 +0700 Subject: [PATCH 123/352] #535 update AGP to fix kotlin version conflict --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 743901711..10acaa8cc 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,6 @@ [versions] kotlinVersion = "1.9.10" -androidGradleVersion = "7.4.2" +androidGradleVersion = "8.1.0" androidSdkCommonVersion = "31.1.2" # kotlinx From 1d4d6a547d1aad259b013368e5de59bb5c8394fe Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 14 Jan 2024 20:12:42 +0700 Subject: [PATCH 124/352] #535 fix additional tasks registration --- .../gradle/MultiplatformResourcesPlugin.kt | 33 ++++------ ...AppleResourcesFromFrameworkToFatAction.kt} | 2 +- .../platform/apple/SetupAppleUtils.kt | 65 +++++++++---------- .../tasks/CopyExecutableResourcesToApp.kt | 14 ++-- 4 files changed, 49 insertions(+), 65 deletions(-) rename resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/{CopyResourcesFromFrameworkToFatAction.kt => CopyAppleResourcesFromFrameworkToFatAction.kt} (92%) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 06ad24269..42d5c9d72 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -9,8 +9,8 @@ import com.android.build.gradle.api.BaseVariant import com.android.build.gradle.internal.lint.AndroidLintAnalysisTask import dev.icerock.gradle.extra.getOrRegisterGenerateResourcesTask import dev.icerock.gradle.generator.platform.apple.setupAppleKLibResources -import dev.icerock.gradle.generator.platform.apple.setupCopyResourcesToAppTask import dev.icerock.gradle.generator.platform.apple.setupCopyXCFrameworkResourcesTask +import dev.icerock.gradle.generator.platform.apple.setupExecutableResources import dev.icerock.gradle.generator.platform.apple.setupFatFrameworkTasks import dev.icerock.gradle.generator.platform.apple.setupFrameworkResources import dev.icerock.gradle.generator.platform.apple.setupTestsResources @@ -35,7 +35,6 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import org.jetbrains.kotlin.gradle.plugin.KotlinTarget import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmAndroidCompilation -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.plugin.sources.android.findAndroidSourceSet import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile @@ -60,7 +59,8 @@ open class MultiplatformResourcesPlugin : Plugin { ) setupCopyXCFrameworkResourcesTask(project = project) - setupCopyResourcesToAppTask(project = project) + setupFatFrameworkTasks(project = project) + registerGenerateAllResources(project = project) } } @@ -75,6 +75,12 @@ open class MultiplatformResourcesPlugin : Plugin { } kmpExtension.targets.configureEach { target -> + if (target is KotlinNativeTarget) { + setupExecutableResources(target = target) + setupFrameworkResources(target = target) + setupTestsResources(target = target) + } + target.compilations.configureEach { compilation -> compilation.kotlinSourceSetsObservable.forAll { sourceSet: KotlinSourceSet -> val genTaskProvider: TaskProvider = @@ -104,12 +110,6 @@ open class MultiplatformResourcesPlugin : Plugin { compilation = compilation ) - // Setup apple specific tasks - setupAppleTasks( - target = target, - compilation = compilation - ) - compilation.compileTaskProvider.configure { compileTask: KotlinCompilationTask<*> -> compileTask.dependsOn(genTaskProvider) @@ -158,7 +158,9 @@ open class MultiplatformResourcesPlugin : Plugin { } } } + } + private fun registerGenerateAllResources(project: Project) { project.tasks.register("generateMR") { it.group = "moko-resources" it.dependsOn(project.tasks.withType()) @@ -231,17 +233,4 @@ open class MultiplatformResourcesPlugin : Plugin { it.dependsOn(genTaskProvider) } } - - private fun setupAppleTasks( - target: KotlinTarget, - compilation: KotlinCompilation<*>, - ) { - if (target !is KotlinNativeTarget) return - - compilation as KotlinNativeCompilation - - setupFrameworkResources(compilation = compilation) - setupTestsResources(compilation = compilation) - setupFatFrameworkTasks(compilation = compilation) - } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromFrameworkToFatAction.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyAppleResourcesFromFrameworkToFatAction.kt similarity index 92% rename from resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromFrameworkToFatAction.kt rename to resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyAppleResourcesFromFrameworkToFatAction.kt index 48ccfcef0..ed1544bf9 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyResourcesFromFrameworkToFatAction.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/actions/apple/CopyAppleResourcesFromFrameworkToFatAction.kt @@ -8,7 +8,7 @@ import org.gradle.api.Action import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask import java.io.File -internal class CopyResourcesFromFrameworkToFatAction : Action { +internal class CopyAppleResourcesFromFrameworkToFatAction : Action { override fun execute(task: FatFrameworkTask) { val fatFrameworkDir: File = task.fatFramework val frameworkFile: File = task.frameworks.first().files.rootDir diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt index e72d3cd58..75b2731c3 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt @@ -6,7 +6,7 @@ package dev.icerock.gradle.generator.platform.apple import com.android.build.gradle.internal.tasks.factory.dependsOn import dev.icerock.gradle.MultiplatformResourcesPluginExtension -import dev.icerock.gradle.actions.apple.CopyResourcesFromFrameworkToFatAction +import dev.icerock.gradle.actions.apple.CopyAppleResourcesFromFrameworkToFatAction import dev.icerock.gradle.actions.apple.CopyResourcesFromKLibsToExecutableAction import dev.icerock.gradle.actions.apple.CopyResourcesFromKLibsToFrameworkAction import dev.icerock.gradle.actions.apple.PackAppleResourcesToKLibAction @@ -24,12 +24,11 @@ import org.gradle.kotlin.dsl.register import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractExecutable import org.jetbrains.kotlin.gradle.plugin.mpp.Framework -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFrameworkTask import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile -import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink import java.io.File @Suppress("LongParameterList") @@ -52,8 +51,8 @@ internal fun setupAppleKLibResources( ) } -internal fun setupFrameworkResources(compilation: KotlinNativeCompilation) { - compilation.target.binaries.withType().configureEach { framework -> +internal fun setupFrameworkResources(target: KotlinNativeTarget) { + target.binaries.withType().configureEach { framework -> framework.linkTaskProvider.configure { linkTask -> linkTask.doLast(CopyResourcesFromKLibsToFrameworkAction()) } @@ -142,45 +141,43 @@ internal fun setupCopyXCFrameworkResourcesTask(project: Project) { } } -internal fun setupCopyResourcesToAppTask(project: Project) { - project.tasks - .withType() - .matching { it.binary is AbstractExecutable } - .all { linkTask -> - val copyTaskName: String = linkTask.name.replace("link", "copyResources") - - project.tasks.register(copyTaskName) { - dependsOn(linkTask) - - klibs.from(linkTask.klibs) - - outputDirectory.set( - project.layout.dir( - project.provider { - val buildProductsDir = - project.property("moko.resources.BUILT_PRODUCTS_DIR") as String - val contentsFolderPath = - project.property("moko.resources.CONTENTS_FOLDER_PATH") as String - - File("$buildProductsDir/$contentsFolderPath") - } - ) +internal fun setupExecutableResources(target: KotlinNativeTarget) { + val project: Project = target.project + target.binaries.withType().configureEach { executable -> + val copyTaskName: String = executable.linkTaskProvider.name.replace("link", "copyResources") + + project.tasks.register(copyTaskName) { + dependsOn(executable.linkTaskProvider) + + klibs.set(executable.linkTaskProvider.map { it.klibs }) + + outputDirectory.set( + project.layout.dir( + project.provider { + val buildProductsDir = + project.property("moko.resources.BUILT_PRODUCTS_DIR") as String + val contentsFolderPath = + project.property("moko.resources.CONTENTS_FOLDER_PATH") as String + + File("$buildProductsDir/$contentsFolderPath") + } ) - } + ) } + } } -internal fun setupTestsResources(compilation: KotlinNativeCompilation) { - compilation.target.binaries.withType().configureEach { executable -> +internal fun setupTestsResources(target: KotlinNativeTarget) { + target.binaries.withType().configureEach { executable -> executable.linkTaskProvider.configure { link -> link.doLast(CopyResourcesFromKLibsToExecutableAction()) } } } -internal fun setupFatFrameworkTasks(compilation: KotlinNativeCompilation) { - compilation.project.tasks.withType().configureEach { +internal fun setupFatFrameworkTasks(project: Project) { + project.tasks.withType().configureEach { @Suppress("UNCHECKED_CAST") - it.doLast(CopyResourcesFromFrameworkToFatAction() as Action) + it.doLast(CopyAppleResourcesFromFrameworkToFatAction() as Action) } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt index eb5af4062..99454f380 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt @@ -6,12 +6,11 @@ package dev.icerock.gradle.tasks import dev.icerock.gradle.utils.toKonanFile import org.gradle.api.DefaultTask -import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.DirectoryProperty -import org.gradle.api.tasks.InputFiles +import org.gradle.api.file.FileCollection +import org.gradle.api.provider.Property +import org.gradle.api.tasks.Input import org.gradle.api.tasks.OutputDirectory -import org.gradle.api.tasks.PathSensitive -import org.gradle.api.tasks.PathSensitivity import org.gradle.api.tasks.TaskAction import org.jetbrains.kotlin.library.KotlinLibraryLayout import org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl @@ -20,9 +19,8 @@ import java.io.FileFilter abstract class CopyExecutableResourcesToApp : DefaultTask() { - @get:InputFiles - @get:PathSensitive(PathSensitivity.RELATIVE) - abstract val klibs: ConfigurableFileCollection + @get:Input + abstract val klibs: Property @get:OutputDirectory abstract val outputDirectory: DirectoryProperty @@ -35,7 +33,7 @@ abstract class CopyExecutableResourcesToApp : DefaultTask() { fun copyResources() { val outputDir: File = outputDirectory.get().asFile - klibs + klibs.get() .filter { library -> library.extension == "klib" } .filter(File::exists) .forEach { inputFile -> From 07346e1a3d643de192ecfeae5afe40bf245ac5fc Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 14 Jan 2024 20:12:59 +0700 Subject: [PATCH 125/352] #535 suppress beta warnings --- .../kotlin/dev/icerock/moko/resources/FileResource.kt | 3 ++- .../icerock/moko/resources/desc/PluralFormattedStringDesc.kt | 2 ++ .../iosMain/kotlin/dev/icerock/moko/resources/FontResource.kt | 4 ++++ .../kotlin/dev/icerock/moko/resources/FontResource.kt | 3 +++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/resources/src/appleMain/kotlin/dev/icerock/moko/resources/FileResource.kt b/resources/src/appleMain/kotlin/dev/icerock/moko/resources/FileResource.kt index 82e0211c9..f79e5766c 100644 --- a/resources/src/appleMain/kotlin/dev/icerock/moko/resources/FileResource.kt +++ b/resources/src/appleMain/kotlin/dev/icerock/moko/resources/FileResource.kt @@ -4,6 +4,7 @@ package dev.icerock.moko.resources +import kotlinx.cinterop.BetaInteropApi import kotlinx.cinterop.ExperimentalForeignApi import kotlinx.cinterop.ObjCObjectVar import kotlinx.cinterop.alloc @@ -35,7 +36,7 @@ actual open class FileResource( subdirectory = "files" )!! - @OptIn(ExperimentalForeignApi::class) + @OptIn(ExperimentalForeignApi::class, BetaInteropApi::class) fun readText(): String { val filePath = path val (result: String?, error: NSError?) = memScoped { diff --git a/resources/src/appleMain/kotlin/dev/icerock/moko/resources/desc/PluralFormattedStringDesc.kt b/resources/src/appleMain/kotlin/dev/icerock/moko/resources/desc/PluralFormattedStringDesc.kt index 774b7c659..176410408 100644 --- a/resources/src/appleMain/kotlin/dev/icerock/moko/resources/desc/PluralFormattedStringDesc.kt +++ b/resources/src/appleMain/kotlin/dev/icerock/moko/resources/desc/PluralFormattedStringDesc.kt @@ -5,6 +5,7 @@ package dev.icerock.moko.resources.desc import dev.icerock.moko.resources.PluralsResource +import kotlinx.cinterop.BetaInteropApi import platform.Foundation.NSBundle import platform.Foundation.NSLocale import platform.Foundation.NSString @@ -30,6 +31,7 @@ actual data class PluralFormattedStringDesc actual constructor( } } +@OptIn(BetaInteropApi::class) internal fun pluralizedString( bundle: NSBundle, baseBundle: NSBundle, diff --git a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/FontResource.kt b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/FontResource.kt index db3128d98..87d4c06b6 100644 --- a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/FontResource.kt +++ b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/FontResource.kt @@ -7,6 +7,7 @@ package dev.icerock.moko.resources import cnames.structs.CGDataProvider import cnames.structs.__CFData import cnames.structs.__CTFont +import kotlinx.cinterop.BetaInteropApi import kotlinx.cinterop.CPointer import kotlinx.cinterop.ExperimentalForeignApi import platform.CoreFoundation.CFDataCreate @@ -37,6 +38,7 @@ actual class FontResource( ) ?: error("file $fontName not found in $bundle") } + @OptIn(BetaInteropApi::class) val data: NSData get() { val filePath: String = this.filePath @@ -46,6 +48,8 @@ actual class FontResource( init { val fontData: NSData = this.data + + @Suppress("UNCHECKED_CAST") val cfDataRef: CPointer<__CFData>? = CFDataCreate( kCFAllocatorDefault, fontData.bytes() as CPointer, diff --git a/resources/src/macosMain/kotlin/dev/icerock/moko/resources/FontResource.kt b/resources/src/macosMain/kotlin/dev/icerock/moko/resources/FontResource.kt index da7747453..9980a6c8a 100644 --- a/resources/src/macosMain/kotlin/dev/icerock/moko/resources/FontResource.kt +++ b/resources/src/macosMain/kotlin/dev/icerock/moko/resources/FontResource.kt @@ -7,6 +7,7 @@ package dev.icerock.moko.resources import cnames.structs.CGDataProvider import cnames.structs.__CFData import cnames.structs.__CTFont +import kotlinx.cinterop.BetaInteropApi import kotlinx.cinterop.CPointer import kotlinx.cinterop.ExperimentalForeignApi import platform.AppKit.NSFont @@ -37,6 +38,7 @@ actual class FontResource( ) ?: throw IllegalStateException("file $fontName not found in $bundle") } + @OptIn(BetaInteropApi::class) val data: NSData get() { val filePath: String = this.filePath @@ -46,6 +48,7 @@ actual class FontResource( init { val fontData: NSData = this.data + @Suppress("UNCHECKED_CAST") val cfDataRef: CPointer<__CFData>? = CFDataCreate( kCFAllocatorDefault, fontData.bytes() as CPointer, From 8af8b161442d23bcc414053ec43ecf42635706f2 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 14 Jan 2024 20:19:03 +0700 Subject: [PATCH 126/352] #535 fix klibs pass --- .../generator/platform/apple/SetupAppleUtils.kt | 2 +- .../gradle/tasks/CopyExecutableResourcesToApp.kt | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt index 75b2731c3..338bb9e12 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt @@ -149,7 +149,7 @@ internal fun setupExecutableResources(target: KotlinNativeTarget) { project.tasks.register(copyTaskName) { dependsOn(executable.linkTaskProvider) - klibs.set(executable.linkTaskProvider.map { it.klibs }) + klibs.from(executable.linkTaskProvider.map { it.klibs }) outputDirectory.set( project.layout.dir( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt index 99454f380..b7dff4c62 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/tasks/CopyExecutableResourcesToApp.kt @@ -6,10 +6,10 @@ package dev.icerock.gradle.tasks import dev.icerock.gradle.utils.toKonanFile import org.gradle.api.DefaultTask +import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.DirectoryProperty -import org.gradle.api.file.FileCollection -import org.gradle.api.provider.Property -import org.gradle.api.tasks.Input +import org.gradle.api.tasks.Classpath +import org.gradle.api.tasks.InputFiles import org.gradle.api.tasks.OutputDirectory import org.gradle.api.tasks.TaskAction import org.jetbrains.kotlin.library.KotlinLibraryLayout @@ -19,8 +19,9 @@ import java.io.FileFilter abstract class CopyExecutableResourcesToApp : DefaultTask() { - @get:Input - abstract val klibs: Property + @get:InputFiles + @get:Classpath + abstract val klibs: ConfigurableFileCollection @get:OutputDirectory abstract val outputDirectory: DirectoryProperty @@ -33,7 +34,7 @@ abstract class CopyExecutableResourcesToApp : DefaultTask() { fun copyResources() { val outputDir: File = outputDirectory.get().asFile - klibs.get() + klibs .filter { library -> library.extension == "klib" } .filter(File::exists) .forEach { inputFile -> From 99f4626b048650e058271aed4bca11e1f8e25006 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 14 Jan 2024 20:46:31 +0700 Subject: [PATCH 127/352] #535 local checks success --- samples/resources-gallery/ios-app/Podfile.lock | 4 ++-- samples/resources-gallery/macos-app/Podfile.lock | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/resources-gallery/ios-app/Podfile.lock b/samples/resources-gallery/ios-app/Podfile.lock index 92c95429d..2dacbacb7 100644 --- a/samples/resources-gallery/ios-app/Podfile.lock +++ b/samples/resources-gallery/ios-app/Podfile.lock @@ -9,8 +9,8 @@ EXTERNAL SOURCES: :path: "../mpp-library" SPEC CHECKSUMS: - mpp_library: 981e4f30991fee66143afbc51e6cec8c4d4782e6 + mpp_library: 22921beb698b09b813ca72745f2cb384b2ee8aa9 PODFILE CHECKSUM: 30d7a0645fcfdfc7d29c9d352fe92e63fe2a9f63 -COCOAPODS: 1.12.1 +COCOAPODS: 1.14.3 diff --git a/samples/resources-gallery/macos-app/Podfile.lock b/samples/resources-gallery/macos-app/Podfile.lock index 032409189..f5d63a12d 100644 --- a/samples/resources-gallery/macos-app/Podfile.lock +++ b/samples/resources-gallery/macos-app/Podfile.lock @@ -9,8 +9,8 @@ EXTERNAL SOURCES: :path: "../mpp-library" SPEC CHECKSUMS: - mpp_library: 981e4f30991fee66143afbc51e6cec8c4d4782e6 + mpp_library: 22921beb698b09b813ca72745f2cb384b2ee8aa9 PODFILE CHECKSUM: 6055317a84821966cb9ec76bbac09672d2f57bdf -COCOAPODS: 1.12.1 +COCOAPODS: 1.14.3 From 6e06d8692657855baf16c9d45f7f2ec46a2ddf87 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 14 Jan 2024 21:02:04 +0700 Subject: [PATCH 128/352] set alpha version --- gradle/moko.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/moko.versions.toml b/gradle/moko.versions.toml index 22271f2a0..bb8f85ec3 100644 --- a/gradle/moko.versions.toml +++ b/gradle/moko.versions.toml @@ -1,5 +1,5 @@ [versions] -resourcesVersion = "0.24.0" +resourcesVersion = "0.24.0-alpha-1" [libraries] resources = { module = "dev.icerock.moko:resources", version.ref = "resourcesVersion" } From 45c6db528b964b61d0189ff849833761dabde1dd Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 14 Jan 2024 21:34:40 +0700 Subject: [PATCH 129/352] fix CI case when plugin published and runtime not compiles --- .github/workflows/publish.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 84b9807ce..ccff8581c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -25,12 +25,14 @@ jobs: uses: actions/setup-java@v1 with: java-version: 17 - - name: Publish plugin - run: ./gradlew -p resources-generator publishPlugins -Pgradle.publish.key=${{ secrets.GRADLE_PLUGIN_PORTAL_KEY }} -Pgradle.publish.secret=${{ secrets.GRADLE_PLUGIN_PORTAL_SECRET }} + - name: Prebuild plugin + run: ./gradlew -p resources-generator publishToMavenLocal - name: Prebuild library run: ./gradlew publishToMavenLocal - name: Publish library run: ./gradlew publish --no-parallel + - name: Publish plugin + run: ./gradlew -p resources-generator publishPlugins -Pgradle.publish.key=${{ secrets.GRADLE_PLUGIN_PORTAL_KEY }} -Pgradle.publish.secret=${{ secrets.GRADLE_PLUGIN_PORTAL_SECRET }} release: name: Create release needs: publish From 6afb91b21bab177bf2f38d572f9449efe3579f15 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 14 Jan 2024 22:03:25 +0700 Subject: [PATCH 130/352] ignore cache at publish --- .github/workflows/publish.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ccff8581c..1030e4921 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -25,10 +25,8 @@ jobs: uses: actions/setup-java@v1 with: java-version: 17 - - name: Prebuild plugin - run: ./gradlew -p resources-generator publishToMavenLocal - name: Prebuild library - run: ./gradlew publishToMavenLocal + run: ./gradlew publishToMavenLocal --rerun-tasks - name: Publish library run: ./gradlew publish --no-parallel - name: Publish plugin From 46be208a5769d1441a1e77c532aa79dfb8efee37 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 14 Jan 2024 22:35:32 +0700 Subject: [PATCH 131/352] #535 fix build with config cache --- gradle/libs.versions.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 10acaa8cc..a4f016b11 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,6 @@ [versions] -kotlinVersion = "1.9.10" -androidGradleVersion = "8.1.0" +kotlinVersion = "1.9.21" +androidGradleVersion = "8.1.4" androidSdkCommonVersion = "31.1.2" # kotlinx @@ -14,7 +14,7 @@ androidAppCompatVersion = "1.6.1" composeUiVersion = "1.5.1" # jetbrains compose -composeJetbrainsVersion = "1.5.1" +composeJetbrainsVersion = "1.5.11" # jvm apacheCommonsTextVersion = "1.10.0" From 243f6466d6baa4b8a00e48a89e94f7438cdf08b6 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 14 Jan 2024 22:46:32 +0700 Subject: [PATCH 132/352] #535 remove config cache from root project for backward compatibility --- gradle.properties | 1 - gradle/libs.versions.toml | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 03d729970..9f9a44a59 100755 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,6 @@ org.gradle.jvmargs=-Xmx12g org.gradle.parallel=true org.gradle.caching=true -org.gradle.configuration-cache=true kotlin.code.style=official diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a4f016b11..dfb71e353 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -kotlinVersion = "1.9.21" +kotlinVersion = "1.9.10" androidGradleVersion = "8.1.4" androidSdkCommonVersion = "31.1.2" @@ -14,7 +14,7 @@ androidAppCompatVersion = "1.6.1" composeUiVersion = "1.5.1" # jetbrains compose -composeJetbrainsVersion = "1.5.11" +composeJetbrainsVersion = "1.5.1" # jvm apacheCommonsTextVersion = "1.10.0" From 9ab0d0506026017eeb28f23b915a4cc8e17a0beb Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 14 Jan 2024 22:47:08 +0700 Subject: [PATCH 133/352] #535 enable config cache in android-mpp sample --- samples/android-mpp-app/build.gradle.kts | 4 ++-- samples/android-mpp-app/gradle.properties | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/samples/android-mpp-app/build.gradle.kts b/samples/android-mpp-app/build.gradle.kts index e2ad3fa1d..0d4fb4b7c 100644 --- a/samples/android-mpp-app/build.gradle.kts +++ b/samples/android-mpp-app/build.gradle.kts @@ -11,7 +11,7 @@ buildscript { } dependencies { classpath(moko.resourcesGradlePlugin) - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0") - classpath("com.android.tools.build:gradle:8.0.1") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.10") + classpath("com.android.tools.build:gradle:8.1.0") } } diff --git a/samples/android-mpp-app/gradle.properties b/samples/android-mpp-app/gradle.properties index 4fd7fa5bb..418055514 100755 --- a/samples/android-mpp-app/gradle.properties +++ b/samples/android-mpp-app/gradle.properties @@ -1,9 +1,14 @@ org.gradle.jvmargs=-Xmx12g org.gradle.parallel=true org.gradle.caching=true +org.gradle.configuration-cache=true + kotlin.code.style=official + kotlin.mpp.stability.nowarn=true kotlin.mpp.androidSourceSetLayoutVersion=2 kotlin.mpp.androidGradlePluginCompatibility.nowarn=true + android.useAndroidX=true + xcodeproj=./sample/ios-app From 1df0dd8b623df0893aa4996824495aa4a906300d Mon Sep 17 00:00:00 2001 From: Lammert Westerhoff Date: Wed, 17 Jan 2024 10:16:07 -0600 Subject: [PATCH 134/352] Add support for dark mode for images --- README.md | 9 ++++++- .../image/AndroidImageResourceGenerator.kt | 10 +++++-- .../image/AppleImageResourceGenerator.kt | 10 ++++++- .../resources/image/ImageResourceGenerator.kt | 7 +++-- .../image/JsImageResourceGenerator.kt | 2 +- .../image/JvmImageResourceGenerator.kt | 2 +- .../gradle/generator/resources/image/Utils.kt | 4 +-- .../metadata/resource/ResourceMetadata.kt | 11 ++++++-- .../dev/icerock/gradle/utils/FileExt.kt | 5 ++++ .../dev/icerock/gradle/utils/StringExt.kt | 14 ++++++++++ .../moko-resources/images/car_white.svg | 26 ------------------- .../shared/src/commonMain/kotlin/App.kt | 1 - 12 files changed, 62 insertions(+), 39 deletions(-) delete mode 100644 samples/compose-resources-gallery/shared/src/androidMain/moko-resources/images/car_white.svg diff --git a/README.md b/README.md index 232c4b4cf..81fd59809 100755 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ implement all you UI in Kotlin with Jetpack Compose and MOKO resources. - **Strings, Plurals** to access the corresponding resources from common code; - **Colors** with light/dark mode support; - **Compose Multiplatform** support; -- **Images** support (`svg`, `png`, `jpg`); +- **Images** support (`svg`, `png`, `jpg`) with light/dark mode support; - **Fonts** support (`ttf`, `otf`); - **Files** support (as `raw` or `assets` for android); - **StringDesc** for lifecycle-aware access to resources and unified localization on both platforms; @@ -547,6 +547,13 @@ Then we get an autogenerated `MR.images.home_black_18` `ImageResource` in code. - Android: `imageView.setImageResource(image.drawableResId)` - iOS: `imageView.image = image.toUIImage()` +#### dark mode + +To support Dark Mode images, you can add _dark and optionally _light to the name of an image. Make sure the rest of the name matches the corresponding light mode image: + +- `car.svg` +- `car_dark.svg` + #### svg The Image generator also supports `svg` files. diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/AndroidImageResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/AndroidImageResourceGenerator.kt index 0a91f4f94..ce6ebbf48 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/AndroidImageResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/AndroidImageResourceGenerator.kt @@ -8,6 +8,7 @@ import com.android.ide.common.vectordrawable.Svg2Vector import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock import dev.icerock.gradle.generator.PlatformResourceGenerator +import dev.icerock.gradle.metadata.resource.Appearance import dev.icerock.gradle.metadata.resource.ImageMetadata import org.slf4j.Logger import java.io.File @@ -33,8 +34,8 @@ internal class AndroidImageResourceGenerator( override fun generateResourceFiles(data: List) { data.flatMap { imageMetadata -> imageMetadata.values.map { imageMetadata.key to it } - }.forEach { (key: String, item: ImageMetadata.ImageQualityItem) -> - val drawableDirName: String = "drawable" + when (item.quality) { + }.forEach { (key: String, item: ImageMetadata.ImageItem) -> + val densityRes = when (item.quality) { "0.75" -> "-ldpi" "1" -> "-mdpi" "1.5" -> "-hdpi" @@ -47,6 +48,11 @@ internal class AndroidImageResourceGenerator( return@forEach } } + val themeRes = when(item.appearance) { + Appearance.LIGHT, null -> "" + Appearance.DARK -> "-night" + } + val drawableDirName = "drawable$themeRes$densityRes" val drawableDir = File(resourcesGenerationDir, drawableDirName) val processedKey: String = processKey(key) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/AppleImageResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/AppleImageResourceGenerator.kt index c0cf07310..ec2a6cd6a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/AppleImageResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/AppleImageResourceGenerator.kt @@ -39,7 +39,7 @@ internal class AppleImageResourceGenerator( assetDir.mkdirs() val contentsFile = File(assetDir, "Contents.json") - val validItems: List = + val validItems: List = imageMetadata.values.filter { item -> item.quality == null || VALID_SIZES.any { item.quality == it.toString() } } @@ -67,6 +67,14 @@ internal class AppleImageResourceGenerator( item.quality?.let { quality -> put("scale", JsonPrimitive(quality + "x")) } + item.appearance?.let { appearance -> + put("appearances", buildJsonArray { + add(buildJsonObject { + put("appearance", JsonPrimitive("luminosity")) + put("value", JsonPrimitive(appearance.name.lowercase())) + }) + }) + } } }.forEach { add(it) } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/ImageResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/ImageResourceGenerator.kt index f06c8eba4..8f9e5c637 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/ImageResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/ImageResourceGenerator.kt @@ -9,9 +9,11 @@ import dev.icerock.gradle.generator.Constants import dev.icerock.gradle.generator.ResourceGenerator import dev.icerock.gradle.generator.generateKey import dev.icerock.gradle.metadata.resource.ImageMetadata +import dev.icerock.gradle.utils.appearance import dev.icerock.gradle.utils.nameWithoutScale import dev.icerock.gradle.utils.scale import dev.icerock.gradle.utils.svg +import dev.icerock.gradle.utils.withoutAppearance import java.io.File internal class ImageResourceGenerator : ResourceGenerator { @@ -21,8 +23,9 @@ internal class ImageResourceGenerator : ResourceGenerator { ImageMetadata( key = generateKey(key), values = files.map { file -> - ImageMetadata.ImageQualityItem( + ImageMetadata.ImageItem( quality = if (file.svg) null else file.scale, + appearance = file.appearance, filePath = file ) } @@ -39,6 +42,6 @@ internal class ImageResourceGenerator : ResourceGenerator { file.nameWithoutExtension } else { file.nameWithoutScale - } + }.withoutAppearance } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/JsImageResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/JsImageResourceGenerator.kt index f9a2fb985..965a1b49a 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/JsImageResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/JsImageResourceGenerator.kt @@ -22,7 +22,7 @@ internal class JsImageResourceGenerator( override fun imports(): List = emptyList() override fun generateInitializer(metadata: ImageMetadata): CodeBlock { - val item: ImageMetadata.ImageQualityItem = metadata.getHighestQualityItem() + val item: ImageMetadata.ImageItem = metadata.getHighestQualityItem() val fileName = "${metadata.key}.${item.filePath.extension}" val requireDeclaration = """require("$IMAGES_DIR/$fileName")""" return CodeBlock.of( diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/JvmImageResourceGenerator.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/JvmImageResourceGenerator.kt index ef9bd2f27..2dd22c772 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/JvmImageResourceGenerator.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/JvmImageResourceGenerator.kt @@ -20,7 +20,7 @@ internal class JvmImageResourceGenerator( override fun imports(): List = emptyList() override fun generateInitializer(metadata: ImageMetadata): CodeBlock { - val item: ImageMetadata.ImageQualityItem = metadata.getHighestQualityItem() + val item: ImageMetadata.ImageItem = metadata.getHighestQualityItem() val fileName = "${metadata.key}.${item.filePath.extension}" return CodeBlock.of( "ImageResource(resourcesClassLoader = %L, filePath = %S)", diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/Utils.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/Utils.kt index 69b894187..99ce10544 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/Utils.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/resources/image/Utils.kt @@ -16,7 +16,7 @@ internal fun generateHighestQualityImageResources( imagesDir.mkdirs() data.forEach { metadata -> - val item: ImageMetadata.ImageQualityItem = metadata.getHighestQualityItem() + val item: ImageMetadata.ImageItem = metadata.getHighestQualityItem() val file: File = item.filePath val key: String = metadata.key @@ -24,7 +24,7 @@ internal fun generateHighestQualityImageResources( } } -internal fun ImageMetadata.getHighestQualityItem(): ImageMetadata.ImageQualityItem { +internal fun ImageMetadata.getHighestQualityItem(): ImageMetadata.ImageItem { return values.singleOrNull { it.quality == null } ?: values.maxBy { it.quality!!.toDouble() } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt index 6733d7359..12508d138 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/metadata/resource/ResourceMetadata.kt @@ -64,11 +64,12 @@ internal data class PluralMetadata( @Serializable internal data class ImageMetadata( override val key: String, - val values: List + val values: List ) : ResourceMetadata { @Serializable - data class ImageQualityItem( + data class ImageItem( val quality: String?, + val appearance: Appearance?, val filePath: File ) @@ -143,3 +144,9 @@ internal data class AssetMetadata( override fun contentHash(): String = filePath.calculateResourcesHash() } + +@Serializable +internal enum class Appearance { + LIGHT, + DARK +} diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/FileExt.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/FileExt.kt index 5ddc2ec22..30ff4f025 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/FileExt.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/FileExt.kt @@ -4,6 +4,7 @@ package dev.icerock.gradle.utils +import dev.icerock.gradle.metadata.resource.Appearance import java.io.File import org.jetbrains.kotlin.konan.file.File as KonanFile @@ -19,4 +20,8 @@ internal val File.nameWithoutScale: String get() = nameWithoutExtension.withoutScale +internal val File.appearance: Appearance? + get() = + nameWithoutExtension.appearance + internal fun File.toKonanFile(): KonanFile = KonanFile(this.path) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/StringExt.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/StringExt.kt index 434cdc4d6..a1b65ebb5 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/StringExt.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/utils/StringExt.kt @@ -4,6 +4,7 @@ package dev.icerock.gradle.utils +import dev.icerock.gradle.metadata.resource.Appearance import java.util.Locale /** @@ -37,3 +38,16 @@ internal fun String.remove(char: String): String { internal val String.flatName: String get() = this.remove('.') + +internal val String.appearance: Appearance? + get() = Appearance.values().firstOrNull { this.contains("_${it.name}", true) } + +internal val String.withoutAppearance: String + get() { + var result = this + Appearance.values() + .forEach { + result = result.replace("_${it.name}", "", true) + } + return result + } diff --git a/samples/compose-resources-gallery/shared/src/androidMain/moko-resources/images/car_white.svg b/samples/compose-resources-gallery/shared/src/androidMain/moko-resources/images/car_white.svg deleted file mode 100644 index eb41b6115..000000000 --- a/samples/compose-resources-gallery/shared/src/androidMain/moko-resources/images/car_white.svg +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt b/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt index f2a9e7191..d6e869d68 100644 --- a/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt +++ b/samples/compose-resources-gallery/shared/src/commonMain/kotlin/App.kt @@ -49,7 +49,6 @@ internal fun App() { modifier = Modifier.size(30.dp).padding(top = 16.dp), painter = painterResource(MR.images.car_black), contentDescription = null, - colorFilter = ColorFilter.tint(MaterialTheme.colors.onBackground) ) var text: String by remember { mutableStateOf("") } From d7fa3b929876d6a07bb55ae388fed2d988291929 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Fri, 19 Jan 2024 17:52:27 +0700 Subject: [PATCH 135/352] #535 fix input metadata file dependencies --- gradle/moko.versions.toml | 2 +- .../kotlin/dev/icerock/gradle/extra/mokoResourcesGenTask.kt | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/gradle/moko.versions.toml b/gradle/moko.versions.toml index bb8f85ec3..68a20f95c 100644 --- a/gradle/moko.versions.toml +++ b/gradle/moko.versions.toml @@ -1,5 +1,5 @@ [versions] -resourcesVersion = "0.24.0-alpha-1" +resourcesVersion = "0.24.0-alpha-2" [libraries] resources = { module = "dev.icerock.moko:resources", version.ref = "resourcesVersion" } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/extra/mokoResourcesGenTask.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/extra/mokoResourcesGenTask.kt index 38b40a3ba..01e398ea3 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/extra/mokoResourcesGenTask.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/extra/mokoResourcesGenTask.kt @@ -172,5 +172,11 @@ private fun configureTaskDependencies( genTask.configure { resourceTask -> resourceTask.inputMetadataFiles.from(dependsGenTask.flatMap { it.outputMetadataFile }) } + + configureTaskDependencies( + kotlinSourceSet = dependsSourceSet, + genTask = genTask, + mrExtension = mrExtension + ) } } From 5cc5684a6e3195b327f79449aa4ecf47763e56e9 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Mon, 22 Jan 2024 23:06:07 +0700 Subject: [PATCH 136/352] #535 add sample with default hierarchy of targets --- local-samples-check.sh | 1 + ...ultiplatform-library-convention.gradle.kts | 2 +- .../.gitignore | 4 + .../README.md | 7 + .../android-app/build.gradle.kts | 23 ++ .../android-app/proguard-rules.pro | 17 + .../android-app/src/main/AndroidManifest.xml | 31 ++ .../main/java/com/icerockdev/LocaleHandler.kt | 36 ++ .../main/java/com/icerockdev/MainActivity.kt | 76 ++++ .../com/icerockdev/SelectLanguageActivity.kt | 35 ++ .../src/main/res/layout/activity_language.xml | 27 ++ .../src/main/res/layout/activity_main.xml | 47 +++ .../build.gradle.kts | 41 ++ .../gradle.properties | 14 + .../gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 61574 bytes .../gradle/wrapper/gradle-wrapper.properties | 6 + .../default-hierarchy-gallery-mobile/gradlew | 244 ++++++++++++ .../gradlew.bat | 92 +++++ .../ios-app/Podfile | 17 + .../ios-app/Podfile.lock | 16 + .../TestProj.xcodeproj/project.pbxproj | 367 ++++++++++++++++++ .../contents.xcworkspacedata | 7 + .../contents.xcworkspacedata | 10 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../ios-app/src/AppDelegate.swift | 17 + .../AppIcon.appiconset/Contents.json | 58 +++ .../ios-app/src/Assets.xcassets/Contents.json | 6 + .../ios-app/src/Info.plist | 68 ++++ .../Base.lproj/LaunchScreen.storyboard | 43 ++ .../src/Resources/Base.lproj/Main.storyboard | 194 +++++++++ .../ios-app/src/TestViewController.swift | 56 +++ .../local-check.sh | 23 ++ .../mpp-library/build.gradle.kts | 57 +++ .../mpp-library/mpp_library.podspec | 50 +++ .../com/icerockdev/library/TestResources.kt | 10 + .../appleMain/moko-resources/base/plurals.xml | 9 + .../appleMain/moko-resources/base/strings.xml | 4 + .../com/icerockdev/library/TestResources.kt | 7 + .../kotlin/com/icerockdev/library/Testing.kt | 158 ++++++++ .../moko-resources/assets/test-1.txt | 1 + .../assets/texts/inner-1/test3.txt | 1 + .../moko-resources/assets/texts/test2.txt | 1 + .../moko-resources/base/plurals-test.xml | 28 ++ .../moko-resources/base/plurals.xml | 15 + .../moko-resources/base/strings-test.xml | 8 + .../moko-resources/base/strings.xml | 10 + .../moko-resources/colors/colors.xml | 16 + .../moko-resources/en-rGB/plurals-test.xml | 28 ++ .../moko-resources/en-rGB/plurals.xml | 15 + .../moko-resources/en-rGB/strings-test.xml | 8 + .../moko-resources/en-rGB/strings.xml | 10 + .../moko-resources/en-rUS/plurals-test.xml | 28 ++ .../moko-resources/en-rUS/plurals.xml | 15 + .../moko-resources/en-rUS/strings-test.xml | 8 + .../moko-resources/en-rUS/strings.xml | 10 + .../moko-resources/es/plurals-test.xml | 30 ++ .../commonMain/moko-resources/es/plurals.xml | 19 + .../commonMain/moko-resources/es/strings.xml | 15 + .../commonMain/moko-resources/files/some.json | 4 + .../commonMain/moko-resources/files/test.txt | 1 + .../moko-resources/fonts/Raleway-Bold.ttf | Bin 0 -> 179244 bytes .../moko-resources/fonts/Raleway-Italic.ttf | Bin 0 -> 145920 bytes .../moko-resources/fonts/Raleway-Regular.ttf | Bin 0 -> 178520 bytes .../moko-resources/fonts/cormorant-italic.otf | Bin 0 -> 172260 bytes .../moko-resources/fonts/cormorant-light.otf | Bin 0 -> 142360 bytes .../fonts/cormorant-regular.otf | Bin 0 -> 144572 bytes .../moko-resources/images/car_black.svg | 30 ++ .../images/home_black_18@1x.png | Bin 0 -> 156 bytes .../images/home_black_18@2x.png | Bin 0 -> 208 bytes .../moko-resources/in-rPB/strings.xml | 4 + .../commonMain/moko-resources/in/strings.xml | 4 + .../moko-resources/ru/plurals-test.xml | 36 ++ .../commonMain/moko-resources/ru/plurals.xml | 19 + .../commonMain/moko-resources/ru/strings.xml | 15 + .../library/AppleTargetResourceTests.kt | 49 +++ .../library/BaseStringResourceTests.kt | 36 ++ .../com/icerockdev/library/TestResources.kt | 10 + .../kotlin/com/icerockdev/library/Testing.kt | 27 ++ .../com/icerockdev/library/TestResources.kt | 10 + .../com/icerockdev/library/TestResources.kt | 10 + .../mpp-library/test-utils/build.gradle.kts | 37 ++ .../src/androidMain/kotlin/BaseUnitTest.kt | 11 + .../src/androidMain/kotlin/StringDescExt.kt | 12 + .../src/commonMain/kotlin/BaseUnitTest.kt | 6 + .../src/commonMain/kotlin/StringDescExt.kt | 7 + .../src/iosMain/kotlin/BaseUnitTest.kt | 5 + .../src/iosMain/kotlin/StringDescExt.kt | 7 + .../settings.gradle.kts | 20 + 88 files changed, 2513 insertions(+), 1 deletion(-) create mode 100644 samples/default-hierarchy-gallery-mobile/.gitignore create mode 100644 samples/default-hierarchy-gallery-mobile/README.md create mode 100644 samples/default-hierarchy-gallery-mobile/android-app/build.gradle.kts create mode 100755 samples/default-hierarchy-gallery-mobile/android-app/proguard-rules.pro create mode 100755 samples/default-hierarchy-gallery-mobile/android-app/src/main/AndroidManifest.xml create mode 100644 samples/default-hierarchy-gallery-mobile/android-app/src/main/java/com/icerockdev/LocaleHandler.kt create mode 100755 samples/default-hierarchy-gallery-mobile/android-app/src/main/java/com/icerockdev/MainActivity.kt create mode 100755 samples/default-hierarchy-gallery-mobile/android-app/src/main/java/com/icerockdev/SelectLanguageActivity.kt create mode 100644 samples/default-hierarchy-gallery-mobile/android-app/src/main/res/layout/activity_language.xml create mode 100755 samples/default-hierarchy-gallery-mobile/android-app/src/main/res/layout/activity_main.xml create mode 100644 samples/default-hierarchy-gallery-mobile/build.gradle.kts create mode 100755 samples/default-hierarchy-gallery-mobile/gradle.properties create mode 100755 samples/default-hierarchy-gallery-mobile/gradle/wrapper/gradle-wrapper.jar create mode 100755 samples/default-hierarchy-gallery-mobile/gradle/wrapper/gradle-wrapper.properties create mode 100755 samples/default-hierarchy-gallery-mobile/gradlew create mode 100755 samples/default-hierarchy-gallery-mobile/gradlew.bat create mode 100644 samples/default-hierarchy-gallery-mobile/ios-app/Podfile create mode 100644 samples/default-hierarchy-gallery-mobile/ios-app/Podfile.lock create mode 100644 samples/default-hierarchy-gallery-mobile/ios-app/TestProj.xcodeproj/project.pbxproj create mode 100755 samples/default-hierarchy-gallery-mobile/ios-app/TestProj.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100755 samples/default-hierarchy-gallery-mobile/ios-app/TestProj.xcworkspace/contents.xcworkspacedata create mode 100644 samples/default-hierarchy-gallery-mobile/ios-app/TestProj.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100755 samples/default-hierarchy-gallery-mobile/ios-app/src/AppDelegate.swift create mode 100755 samples/default-hierarchy-gallery-mobile/ios-app/src/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100755 samples/default-hierarchy-gallery-mobile/ios-app/src/Assets.xcassets/Contents.json create mode 100755 samples/default-hierarchy-gallery-mobile/ios-app/src/Info.plist create mode 100755 samples/default-hierarchy-gallery-mobile/ios-app/src/Resources/Base.lproj/LaunchScreen.storyboard create mode 100755 samples/default-hierarchy-gallery-mobile/ios-app/src/Resources/Base.lproj/Main.storyboard create mode 100755 samples/default-hierarchy-gallery-mobile/ios-app/src/TestViewController.swift create mode 100755 samples/default-hierarchy-gallery-mobile/local-check.sh create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/build.gradle.kts create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/mpp_library.podspec create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/androidMain/kotlin/com/icerockdev/library/TestResources.kt create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/appleMain/moko-resources/base/plurals.xml create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/appleMain/moko-resources/base/strings.xml create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/kotlin/com/icerockdev/library/TestResources.kt create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/kotlin/com/icerockdev/library/Testing.kt create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/assets/test-1.txt create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/assets/texts/inner-1/test3.txt create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/assets/texts/test2.txt create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/base/plurals-test.xml create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/base/plurals.xml create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/base/strings-test.xml create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/base/strings.xml create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/colors/colors.xml create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/en-rGB/plurals-test.xml create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/en-rGB/plurals.xml create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/en-rGB/strings-test.xml create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/en-rGB/strings.xml create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/en-rUS/plurals-test.xml create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/en-rUS/plurals.xml create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/en-rUS/strings-test.xml create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/en-rUS/strings.xml create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/es/plurals-test.xml create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/es/plurals.xml create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/es/strings.xml create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/files/some.json create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/files/test.txt create mode 100755 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/fonts/Raleway-Bold.ttf create mode 100755 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/fonts/Raleway-Italic.ttf create mode 100755 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/fonts/Raleway-Regular.ttf create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/fonts/cormorant-italic.otf create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/fonts/cormorant-light.otf create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/fonts/cormorant-regular.otf create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/images/car_black.svg create mode 100755 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/images/home_black_18@1x.png create mode 100755 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/images/home_black_18@2x.png create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/in-rPB/strings.xml create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/in/strings.xml create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/ru/plurals-test.xml create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/ru/plurals.xml create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonMain/moko-resources/ru/strings.xml create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonTest/kotlin/com/icerock/library/AppleTargetResourceTests.kt create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/commonTest/kotlin/com/icerock/library/BaseStringResourceTests.kt create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/iosArm64Main/kotlin/com/icerockdev/library/TestResources.kt create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/iosArm64Main/kotlin/com/icerockdev/library/Testing.kt create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/iosSimulatorArm64Main/kotlin/com/icerockdev/library/TestResources.kt create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/src/iosX64Main/kotlin/com/icerockdev/library/TestResources.kt create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/test-utils/build.gradle.kts create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/test-utils/src/androidMain/kotlin/BaseUnitTest.kt create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/test-utils/src/androidMain/kotlin/StringDescExt.kt create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/test-utils/src/commonMain/kotlin/BaseUnitTest.kt create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/test-utils/src/commonMain/kotlin/StringDescExt.kt create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/test-utils/src/iosMain/kotlin/BaseUnitTest.kt create mode 100644 samples/default-hierarchy-gallery-mobile/mpp-library/test-utils/src/iosMain/kotlin/StringDescExt.kt create mode 100644 samples/default-hierarchy-gallery-mobile/settings.gradle.kts diff --git a/local-samples-check.sh b/local-samples-check.sh index 45c1d0e2b..387b582f1 100755 --- a/local-samples-check.sh +++ b/local-samples-check.sh @@ -11,3 +11,4 @@ set -e (cd samples/kotlin-ios-app && ./local-check.sh) (cd samples/resources-gallery && ./local-check.sh) (cd samples/compose-resources-gallery && ./local-check.sh) +(cd samples/default-hierarchy-gallery-mobile && ./local-check.sh) diff --git a/resources-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts b/resources-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts index bdd895ef4..635e85344 100644 --- a/resources-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts +++ b/resources-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ import org.gradle.api.tasks.testing.logging.TestExceptionFormat diff --git a/samples/default-hierarchy-gallery-mobile/.gitignore b/samples/default-hierarchy-gallery-mobile/.gitignore new file mode 100644 index 000000000..d980f0e18 --- /dev/null +++ b/samples/default-hierarchy-gallery-mobile/.gitignore @@ -0,0 +1,4 @@ +.idea/ +.gradle/ +build/ +local.properties diff --git a/samples/default-hierarchy-gallery-mobile/README.md b/samples/default-hierarchy-gallery-mobile/README.md new file mode 100644 index 000000000..2bb42a623 --- /dev/null +++ b/samples/default-hierarchy-gallery-mobile/README.md @@ -0,0 +1,7 @@ +# Sample of multiplatform resources usage on mobile targets +# with default hierarchy + +## Build + +1. publish moko-resources to local maven - `./gradlew publishToMavenLocal` in `moko-resources` root +2. build sample (in IDE or by `./gradlew build`) diff --git a/samples/default-hierarchy-gallery-mobile/android-app/build.gradle.kts b/samples/default-hierarchy-gallery-mobile/android-app/build.gradle.kts new file mode 100644 index 000000000..477019b14 --- /dev/null +++ b/samples/default-hierarchy-gallery-mobile/android-app/build.gradle.kts @@ -0,0 +1,23 @@ +/* + * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +plugins { + id("com.android.application") + kotlin("android") +} + +android { + defaultConfig { + targetSdk = 33 + applicationId = "dev.icerock.moko.samples.resources" + versionCode = 1 + versionName = "0.1.0" + } + namespace = "com.icerockdev" +} + +dependencies { + implementation("androidx.appcompat:appcompat:1.6.1") + implementation(project(":mpp-library")) +} diff --git a/samples/default-hierarchy-gallery-mobile/android-app/proguard-rules.pro b/samples/default-hierarchy-gallery-mobile/android-app/proguard-rules.pro new file mode 100755 index 000000000..1ecf581f6 --- /dev/null +++ b/samples/default-hierarchy-gallery-mobile/android-app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /opt/android/sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/samples/default-hierarchy-gallery-mobile/android-app/src/main/AndroidManifest.xml b/samples/default-hierarchy-gallery-mobile/android-app/src/main/AndroidManifest.xml new file mode 100755 index 000000000..67a86112c --- /dev/null +++ b/samples/default-hierarchy-gallery-mobile/android-app/src/main/AndroidManifest.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples/default-hierarchy-gallery-mobile/android-app/src/main/java/com/icerockdev/LocaleHandler.kt b/samples/default-hierarchy-gallery-mobile/android-app/src/main/java/com/icerockdev/LocaleHandler.kt new file mode 100644 index 000000000..d9ff96758 --- /dev/null +++ b/samples/default-hierarchy-gallery-mobile/android-app/src/main/java/com/icerockdev/LocaleHandler.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.icerockdev + +import android.content.Context +import android.content.res.Configuration +import android.os.Build +import android.os.LocaleList +import android.preference.PreferenceManager +import java.util.Locale + +object LocaleHandler { + + const val LOCALE_PREF_TAG = "pref:locale" + + fun updateLocale(newBase: Context): Context { + val currentLocale = PreferenceManager.getDefaultSharedPreferences(newBase) + .getString(LOCALE_PREF_TAG, Locale.getDefault().language) + + val newLocale = Locale(currentLocale) + Locale.setDefault(newLocale) + + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + val configuration: Configuration = newBase.resources.configuration + val newLocales = LocaleList(newLocale) + configuration.setLocales(newLocales) + newBase.createConfigurationContext(configuration) + } else { + newBase.resources.configuration.locale = newLocale + newBase.resources.updateConfiguration(newBase.resources.configuration, newBase.resources.displayMetrics) + newBase + } + } +} diff --git a/samples/default-hierarchy-gallery-mobile/android-app/src/main/java/com/icerockdev/MainActivity.kt b/samples/default-hierarchy-gallery-mobile/android-app/src/main/java/com/icerockdev/MainActivity.kt new file mode 100755 index 000000000..e30ca02a3 --- /dev/null +++ b/samples/default-hierarchy-gallery-mobile/android-app/src/main/java/com/icerockdev/MainActivity.kt @@ -0,0 +1,76 @@ +/* + * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.icerockdev + +import android.content.Context +import android.graphics.drawable.GradientDrawable +import android.os.Bundle +import android.util.Log +import android.widget.ImageView +import android.widget.TextView +import androidx.appcompat.app.AppCompatActivity +import androidx.core.content.ContextCompat +import com.icerockdev.library.Testing +import com.icerockdev.library.R as libraryR + +class MainActivity : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + setContentView(R.layout.activity_main) + + val imageView: ImageView = findViewById(R.id.imageView) + val svgImageView: ImageView = findViewById(R.id.svgImageView) + val textView: TextView = findViewById(R.id.textView) + val stringDescTextView: TextView = findViewById(R.id.stringDescTextView) + val otfFontsTestTextView: TextView = findViewById(R.id.stringOtfFontsTest) + + val strings = Testing.getStrings() + val text = strings.joinToString("\n") { it.toString(context = this) } + + val drawable = Testing.getDrawable() + + imageView.setImageResource(drawable.drawableResId) + imageView.background = GradientDrawable( + GradientDrawable.Orientation.LEFT_RIGHT, + Testing.getGradientColors().map { + it.getColor(context = this) + }.toIntArray() + ) + + val vectorDrawable = Testing.getVectorDrawable() + svgImageView.setImageResource(vectorDrawable.drawableResId) + + textView.text = text + textView.typeface = Testing.getFontTtf1().getTypeface(context = this) + + val textColorFromRes = ContextCompat.getColor(this, libraryR.color.textColor) + textView.setTextColor(textColorFromRes) + + stringDescTextView.text = Testing.getStringDesc().toString(context = this) + stringDescTextView.typeface = Testing.getFontTtf2().getTypeface(context = this) + + val textColorFromLib = Testing.getTextColor().getColor(context = this) + stringDescTextView.setTextColor(textColorFromLib) + + listOf( + Testing.getTextFile().readText(context = this), + Testing.getJsonFile().readText(context = this), + *Testing.getTextsFromAssets().map { it.readText(context = this) }.toTypedArray() + ).forEach { Log.d(MainActivity::class.java.simpleName, it) } + + otfFontsTestTextView.typeface = Testing.getFontOtf1().getTypeface(context = this) + otfFontsTestTextView.typeface = Testing.getFontOtf2().getTypeface(context = this) + otfFontsTestTextView.typeface = Testing.getFontOtf3().getTypeface(context = this) + } + + /** + * For unit-tests purposes. + */ + override fun attachBaseContext(newBase: Context) { + super.attachBaseContext(LocaleHandler.updateLocale(newBase)) + } +} diff --git a/samples/default-hierarchy-gallery-mobile/android-app/src/main/java/com/icerockdev/SelectLanguageActivity.kt b/samples/default-hierarchy-gallery-mobile/android-app/src/main/java/com/icerockdev/SelectLanguageActivity.kt new file mode 100755 index 000000000..50e99bf60 --- /dev/null +++ b/samples/default-hierarchy-gallery-mobile/android-app/src/main/java/com/icerockdev/SelectLanguageActivity.kt @@ -0,0 +1,35 @@ +/* + * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.icerockdev + +import android.content.Intent +import android.os.Bundle +import android.view.View +import android.widget.Button +import androidx.appcompat.app.AppCompatActivity +import com.icerockdev.library.Testing + +class SelectLanguageActivity : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + setContentView(R.layout.activity_language) + } + + fun onSystemLanguage(view: View) { + Testing.locale(null) + + startActivity(Intent(this, MainActivity::class.java)) + } + + fun onCustomLanguage(view: View) { + view as Button + + Testing.locale(view.text.toString()) + + startActivity(Intent(this, MainActivity::class.java)) + } +} diff --git a/samples/default-hierarchy-gallery-mobile/android-app/src/main/res/layout/activity_language.xml b/samples/default-hierarchy-gallery-mobile/android-app/src/main/res/layout/activity_language.xml new file mode 100644 index 000000000..688771af9 --- /dev/null +++ b/samples/default-hierarchy-gallery-mobile/android-app/src/main/res/layout/activity_language.xml @@ -0,0 +1,27 @@ + + + +