From bfdb4668f61fb9cec12ffdf4faaa736dfc447f1c Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Fri, 27 Dec 2019 12:25:59 +0700 Subject: [PATCH 01/54] #18 access to NSBundle by identifier, not by class (to allow static framework usage) --- .../gradle/generator/IosMRGenerator.kt | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt index dd2f7866..962e37f3 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt @@ -4,12 +4,17 @@ package dev.icerock.gradle.generator -import com.squareup.kotlinpoet.* +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 org.gradle.api.Project import org.gradle.api.Task import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import org.jetbrains.kotlin.gradle.plugin.mpp.Framework import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink +import org.w3c.dom.Element import java.io.File import java.io.FileWriter import javax.xml.parsers.DocumentBuilderFactory @@ -29,6 +34,7 @@ class IosMRGenerator( mrClassPackage = mrClassPackage, generators = generators ) { + private val bundleIdentifier = "multiplatform.$mrClassPackage" private val bundleClassName = ClassName("platform.Foundation", "NSBundle") @@ -43,14 +49,13 @@ class IosMRGenerator( bundleClassName, KModifier.PRIVATE ) - .initializer(CodeBlock.of("NSBundle.bundleForClass(object_getClass(this)!!)")) + .initializer(CodeBlock.of("NSBundle.bundleWithIdentifier(\"$bundleIdentifier\")!!")) .build() ) } override fun getImports(): List = listOf( - bundleClassName, - ClassName("platform.objc", "object_getClass") + bundleClassName ) override fun apply(generationTask: Task, project: Project) { @@ -81,6 +86,18 @@ class IosMRGenerator( rootDict.appendChild(doc.createElement("string").apply { textContent = "en" }) + var current = rootDict.firstChild + do { + if (current.textContent == "CFBundleIdentifier") { + var identifierValue = current.nextSibling + while(identifierValue != null && (identifierValue as? Element)?.tagName != "string") { + identifierValue = identifierValue.nextSibling + } + identifierValue?.textContent = bundleIdentifier + } + + current = current.nextSibling + } while (current != null) val transformerFactory = TransformerFactory.newInstance() val transformer = transformerFactory.newTransformer() From 19db484d384929aeeb77624784bda13d3965576e Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 30 Dec 2019 20:49:36 +0700 Subject: [PATCH 02/54] #18 try all do static framework --- .../dev/icerock/gradle/generator/IosMRGenerator.kt | 8 +++++++- sample/mpp-library/MultiPlatformLibrary.podspec | 1 + sample/mpp-library/build.gradle.kts | 10 ++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt index 962e37f3..44653181 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt @@ -34,6 +34,7 @@ class IosMRGenerator( mrClassPackage = mrClassPackage, generators = generators ) { + private lateinit var frameworkName: String private val bundleIdentifier = "multiplatform.$mrClassPackage" private val bundleClassName = ClassName("platform.Foundation", "NSBundle") @@ -43,13 +44,16 @@ class IosMRGenerator( override fun processMRClass(mrClass: TypeSpec.Builder) { super.processMRClass(mrClass) + val bundlePath = "NSBundle.mainBundle.pathForResource(\"$frameworkName\", \"framework\", \"Frameworks\")!!" + val bundle = "NSBundle.bundleWithPath($bundlePath)!!" + mrClass.addProperty( PropertySpec.builder( BUNDLE_PROPERTY_NAME, bundleClassName, KModifier.PRIVATE ) - .initializer(CodeBlock.of("NSBundle.bundleWithIdentifier(\"$bundleIdentifier\")!!")) + .initializer(CodeBlock.of(bundle)) .build() ) } @@ -64,6 +68,8 @@ class IosMRGenerator( .filter { it.binary is Framework } .filter { it.compilation.kotlinSourceSets.contains(sourceSet) } + frameworkName = linkTasks.first().baseName + linkTasks.forEach { linkTask -> linkTask.compilation.compileKotlinTask.dependsOn(generationTask) diff --git a/sample/mpp-library/MultiPlatformLibrary.podspec b/sample/mpp-library/MultiPlatformLibrary.podspec index f3870e5b..dd1e3e3d 100644 --- a/sample/mpp-library/MultiPlatformLibrary.podspec +++ b/sample/mpp-library/MultiPlatformLibrary.podspec @@ -11,6 +11,7 @@ Pod::Spec.new do |spec| spec.libraries = "c++" spec.module_name = "#{spec.name}_umbrella" + spec.static_framework = true spec.pod_target_xcconfig = { 'MPP_LIBRARY_NAME' => 'MultiPlatformLibrary', 'GRADLE_TASK[sdk=iphonesimulator*][config=*ebug]' => 'syncMultiPlatformLibraryDebugFrameworkIosX64', diff --git a/sample/mpp-library/build.gradle.kts b/sample/mpp-library/build.gradle.kts index 4b896cd4..a9ed39b5 100644 --- a/sample/mpp-library/build.gradle.kts +++ b/sample/mpp-library/build.gradle.kts @@ -32,3 +32,13 @@ dependencies { multiplatformResources { multiplatformResourcesPackage = "com.icerockdev.library" } + +kotlin { + targets + .filterIsInstance() + .flatMap { it.binaries } + .filterIsInstance() + .forEach { framework -> + framework.isStatic = true + } +} From 182e3caf8eb4f8c771edc0b2bacd2eba9cd8ed04 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 20 Apr 2020 18:40:19 +0700 Subject: [PATCH 03/54] #58 added samples of different target configurations --- buildSrc/build.gradle.kts | 8 ++- buildSrc/src/main/kotlin/Deps.kt | 2 +- buildSrc/src/main/kotlin/Versions.kt | 2 +- sample/mpp-conditional/build.gradle.kts | 44 +++++++++++++++ .../kotlin/com/icerockdev/library/Testing.kt | 9 ++++ .../mpp-conditional/src/commonMain/resources | 1 + .../src/main/AndroidManifest.xml | 2 + sample/mpp-hierarhical/build.gradle.kts | 32 +++++++++++ .../kotlin/com/icerockdev/library/Testing.kt | 9 ++++ .../mpp-hierarhical/src/commonMain/resources | 1 + .../src/main/AndroidManifest.xml | 2 + .../commonMain/resources/MR/es/plurals.xml | 27 ++++++++++ .../commonMain/resources/MR/es/strings.xml | 1 + .../commonMain/resources/MR/ru/plurals.xml | 18 +++++-- .../commonMain/resources/MR/ru/strings.xml | 1 + sample/mpp-mixed/build.gradle.kts | 54 +++++++++++++++++++ .../kotlin/com/icerockdev/library/Testing.kt | 9 ++++ sample/mpp-mixed/src/commonMain/resources | 1 + sample/mpp-mixed/src/main/AndroidManifest.xml | 2 + settings.gradle.kts | 3 ++ 20 files changed, 216 insertions(+), 12 deletions(-) create mode 100644 sample/mpp-conditional/build.gradle.kts create mode 100644 sample/mpp-conditional/src/commonMain/kotlin/com/icerockdev/library/Testing.kt create mode 120000 sample/mpp-conditional/src/commonMain/resources create mode 100755 sample/mpp-conditional/src/main/AndroidManifest.xml create mode 100644 sample/mpp-hierarhical/build.gradle.kts create mode 100644 sample/mpp-hierarhical/src/commonMain/kotlin/com/icerockdev/library/Testing.kt create mode 120000 sample/mpp-hierarhical/src/commonMain/resources create mode 100755 sample/mpp-hierarhical/src/main/AndroidManifest.xml create mode 100644 sample/mpp-library/src/commonMain/resources/MR/es/plurals.xml create mode 100644 sample/mpp-mixed/build.gradle.kts create mode 100644 sample/mpp-mixed/src/commonMain/kotlin/com/icerockdev/library/Testing.kt create mode 120000 sample/mpp-mixed/src/commonMain/resources create mode 100755 sample/mpp-mixed/src/main/AndroidManifest.xml diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 522372ab..771e954b 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -1,10 +1,8 @@ plugins { - `kotlin-dsl` + id("org.gradle.kotlin.kotlin-dsl") version "1.3.6" } repositories { - mavenLocal() - jcenter() google() @@ -13,8 +11,8 @@ repositories { dependencies { implementation("dev.icerock:mobile-multiplatform:0.6.1") - implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.71") - implementation("com.android.tools.build:gradle:3.6.2") + implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72") + implementation("com.android.tools.build:gradle:3.6.3") } kotlinDslPluginOptions { diff --git a/buildSrc/src/main/kotlin/Deps.kt b/buildSrc/src/main/kotlin/Deps.kt index e8d4192c..56a171c1 100755 --- a/buildSrc/src/main/kotlin/Deps.kt +++ b/buildSrc/src/main/kotlin/Deps.kt @@ -63,4 +63,4 @@ object Deps { "kotlin-android" to Plugins.kotlin, "dev.icerock.mobile.multiplatform-resources" to Plugins.mokoResources ) -} \ No newline at end of file +} diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index b5895369..669bbf2e 100755 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -40,4 +40,4 @@ object Versions { const val kotlinPoet = "1.3.0" } } -} \ No newline at end of file +} diff --git a/sample/mpp-conditional/build.gradle.kts b/sample/mpp-conditional/build.gradle.kts new file mode 100644 index 00000000..b383995b --- /dev/null +++ b/sample/mpp-conditional/build.gradle.kts @@ -0,0 +1,44 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +plugins { + id("com.android.library") + id("org.jetbrains.kotlin.multiplatform") + id("dev.icerock.mobile.multiplatform-resources") +} + +android { + compileSdkVersion(Versions.Android.compileSdk) + + defaultConfig { + minSdkVersion(Versions.Android.minSdk) + targetSdkVersion(Versions.Android.targetSdk) + } +} + +kotlin { + android() + val onPhone = System.getenv("SDK_NAME")?.startsWith("iphoneos") ?: false + if (onPhone) { + iosArm64("ios") + } else { + iosX64("ios") + } + + targets.getByName("ios") { + binaries.framework { + baseName = "MultiPlatformLibrary" + isStatic = false + } + } +} + +dependencies { + commonMainImplementation("org.jetbrains.kotlin:kotlin-stdlib:${Versions.kotlin}") + commonMainImplementation("dev.icerock.moko:resources:${Versions.Libs.MultiPlatform.mokoResources}") +} + +multiplatformResources { + multiplatformResourcesPackage = "com.icerockdev.library" +} diff --git a/sample/mpp-conditional/src/commonMain/kotlin/com/icerockdev/library/Testing.kt b/sample/mpp-conditional/src/commonMain/kotlin/com/icerockdev/library/Testing.kt new file mode 100644 index 00000000..92f9ffbe --- /dev/null +++ b/sample/mpp-conditional/src/commonMain/kotlin/com/icerockdev/library/Testing.kt @@ -0,0 +1,9 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.icerockdev.library + +fun test() { + +} diff --git a/sample/mpp-conditional/src/commonMain/resources b/sample/mpp-conditional/src/commonMain/resources new file mode 120000 index 00000000..0d9eb614 --- /dev/null +++ b/sample/mpp-conditional/src/commonMain/resources @@ -0,0 +1 @@ +../../../mpp-library/src/commonMain/resources \ No newline at end of file diff --git a/sample/mpp-conditional/src/main/AndroidManifest.xml b/sample/mpp-conditional/src/main/AndroidManifest.xml new file mode 100755 index 00000000..81963927 --- /dev/null +++ b/sample/mpp-conditional/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + + diff --git a/sample/mpp-hierarhical/build.gradle.kts b/sample/mpp-hierarhical/build.gradle.kts new file mode 100644 index 00000000..e6a77b25 --- /dev/null +++ b/sample/mpp-hierarhical/build.gradle.kts @@ -0,0 +1,32 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +plugins { + id("com.android.library") + id("org.jetbrains.kotlin.multiplatform") + id("dev.icerock.mobile.multiplatform-resources") +} + +android { + compileSdkVersion(Versions.Android.compileSdk) + + defaultConfig { + minSdkVersion(Versions.Android.minSdk) + targetSdkVersion(Versions.Android.targetSdk) + } +} + +kotlin { + android() + ios() +} + +dependencies { + commonMainImplementation("org.jetbrains.kotlin:kotlin-stdlib:${Versions.kotlin}") + commonMainImplementation("dev.icerock.moko:resources:${Versions.Libs.MultiPlatform.mokoResources}") +} + +multiplatformResources { + multiplatformResourcesPackage = "com.icerockdev.library" +} diff --git a/sample/mpp-hierarhical/src/commonMain/kotlin/com/icerockdev/library/Testing.kt b/sample/mpp-hierarhical/src/commonMain/kotlin/com/icerockdev/library/Testing.kt new file mode 100644 index 00000000..92f9ffbe --- /dev/null +++ b/sample/mpp-hierarhical/src/commonMain/kotlin/com/icerockdev/library/Testing.kt @@ -0,0 +1,9 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.icerockdev.library + +fun test() { + +} diff --git a/sample/mpp-hierarhical/src/commonMain/resources b/sample/mpp-hierarhical/src/commonMain/resources new file mode 120000 index 00000000..0d9eb614 --- /dev/null +++ b/sample/mpp-hierarhical/src/commonMain/resources @@ -0,0 +1 @@ +../../../mpp-library/src/commonMain/resources \ No newline at end of file diff --git a/sample/mpp-hierarhical/src/main/AndroidManifest.xml b/sample/mpp-hierarhical/src/main/AndroidManifest.xml new file mode 100755 index 00000000..81963927 --- /dev/null +++ b/sample/mpp-hierarhical/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + + diff --git a/sample/mpp-library/src/commonMain/resources/MR/es/plurals.xml b/sample/mpp-library/src/commonMain/resources/MR/es/plurals.xml new file mode 100644 index 00000000..79c292ee --- /dev/null +++ b/sample/mpp-library/src/commonMain/resources/MR/es/plurals.xml @@ -0,0 +1,27 @@ + + + + cero + uno + dos + algo + mucho + otro + + + cero + uno + dos + algo + mucho + otro + + + cero + uno + dos + algo + mucho + otro + + \ No newline at end of file diff --git a/sample/mpp-library/src/commonMain/resources/MR/es/strings.xml b/sample/mpp-library/src/commonMain/resources/MR/es/strings.xml index e8cb2b68..9e32eba8 100644 --- a/sample/mpp-library/src/commonMain/resources/MR/es/strings.xml +++ b/sample/mpp-library/src/commonMain/resources/MR/es/strings.xml @@ -3,6 +3,7 @@ prueba prueba 2 prueba 3 + prueba 4 proyecto de prueba datos de prueba %d ELIJA LA CARTERA Y LA CANTIDAD diff --git a/sample/mpp-library/src/commonMain/resources/MR/ru/plurals.xml b/sample/mpp-library/src/commonMain/resources/MR/ru/plurals.xml index 579a5194..7c2b0bca 100644 --- a/sample/mpp-library/src/commonMain/resources/MR/ru/plurals.xml +++ b/sample/mpp-library/src/commonMain/resources/MR/ru/plurals.xml @@ -2,11 +2,11 @@ ноль - один - два - несколько - много - другое + %d - один + %d - два + %d - несколько + %d - много + %d - другое нет элементов @@ -16,4 +16,12 @@ %d элементов %d элемента + + нет элементов + %d элемент + %d элемента + %d элементов + %d элементов + %d элемента + \ No newline at end of file diff --git a/sample/mpp-library/src/commonMain/resources/MR/ru/strings.xml b/sample/mpp-library/src/commonMain/resources/MR/ru/strings.xml index 671052a0..053c4698 100644 --- a/sample/mpp-library/src/commonMain/resources/MR/ru/strings.xml +++ b/sample/mpp-library/src/commonMain/resources/MR/ru/strings.xml @@ -3,6 +3,7 @@ тест тест 2 тест 3 + тест 4 Тестовый проект Тестовые данные %d Выберите портфель и сумму diff --git a/sample/mpp-mixed/build.gradle.kts b/sample/mpp-mixed/build.gradle.kts new file mode 100644 index 00000000..337539fb --- /dev/null +++ b/sample/mpp-mixed/build.gradle.kts @@ -0,0 +1,54 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +plugins { + id("com.android.library") + id("org.jetbrains.kotlin.multiplatform") + id("dev.icerock.mobile.multiplatform-resources") +} + +android { + compileSdkVersion(Versions.Android.compileSdk) + + defaultConfig { + minSdkVersion(Versions.Android.minSdk) + targetSdkVersion(Versions.Android.targetSdk) + } +} + +kotlin { + android() + iosX64 { + binaries.framework { + baseName = "MultiPlatformLibrary" + isStatic = false + } + } + iosArm64 { + binaries.framework { + baseName = "MultiPlatformLibrary" + isStatic = false + } + } + + sourceSets { + val iosX64Main by getting {} + val iosX64Test by getting {} + val iosArm64Main by getting { + dependsOn(iosX64Main) + } + val iosArm64Test by getting { + dependsOn(iosX64Test) + } + } +} + +dependencies { + commonMainImplementation("org.jetbrains.kotlin:kotlin-stdlib:${Versions.kotlin}") + commonMainImplementation("dev.icerock.moko:resources:${Versions.Libs.MultiPlatform.mokoResources}") +} + +multiplatformResources { + multiplatformResourcesPackage = "com.icerockdev.library" +} diff --git a/sample/mpp-mixed/src/commonMain/kotlin/com/icerockdev/library/Testing.kt b/sample/mpp-mixed/src/commonMain/kotlin/com/icerockdev/library/Testing.kt new file mode 100644 index 00000000..92f9ffbe --- /dev/null +++ b/sample/mpp-mixed/src/commonMain/kotlin/com/icerockdev/library/Testing.kt @@ -0,0 +1,9 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.icerockdev.library + +fun test() { + +} diff --git a/sample/mpp-mixed/src/commonMain/resources b/sample/mpp-mixed/src/commonMain/resources new file mode 120000 index 00000000..0d9eb614 --- /dev/null +++ b/sample/mpp-mixed/src/commonMain/resources @@ -0,0 +1 @@ +../../../mpp-library/src/commonMain/resources \ No newline at end of file diff --git a/sample/mpp-mixed/src/main/AndroidManifest.xml b/sample/mpp-mixed/src/main/AndroidManifest.xml new file mode 100755 index 00000000..81963927 --- /dev/null +++ b/sample/mpp-mixed/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + + diff --git a/settings.gradle.kts b/settings.gradle.kts index 2467804b..9ded2b90 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -33,4 +33,7 @@ include(":gradle-plugin") if(!libraryPublish) { include(":sample:android-app") include(":sample:mpp-library") + include(":sample:mpp-conditional") + include(":sample:mpp-hierarhical") + include(":sample:mpp-mixed") } From fd67bf88f51cbc8be9a5c964230cf4d0c40390e6 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 20 Apr 2020 19:43:47 +0700 Subject: [PATCH 04/54] fix some detekt issues in gradle-plugin --- .../dev/icerock/gradle/MultiplatformResourcesPlugin.kt | 3 +-- .../gradle/MultiplatformResourcesPluginExtension.kt | 2 +- .../dev/icerock/gradle/generator/AndroidMRGenerator.kt | 2 +- .../dev/icerock/gradle/generator/BaseGenerator.kt | 2 +- .../dev/icerock/gradle/generator/CommonMRGenerator.kt | 2 +- .../dev/icerock/gradle/generator/IosMRGenerator.kt | 3 +-- .../gradle/generator/ResourceGeneratorFeature.kt | 10 +++++----- .../kotlin/dev/icerock/gradle/generator/SourceInfo.kt | 2 +- .../gradle/generator/fonts/AndroidFontsGenerator.kt | 2 +- .../gradle/generator/fonts/CommonFontsGenerator.kt | 2 +- .../icerock/gradle/generator/fonts/FontsGenerator.kt | 2 -- .../gradle/generator/fonts/FontsGeneratorFeature.kt | 8 +++----- .../gradle/generator/fonts/IosFontsGenerator.kt | 2 +- .../gradle/generator/image/ImagesGeneratorFeature.kt | 8 +++----- .../gradle/generator/image/IosImagesGenerator.kt | 3 +-- .../gradle/generator/plurals/IosPluralsGenerator.kt | 2 +- .../generator/plurals/PluralsGeneratorFeature.kt | 8 +++----- .../gradle/generator/strings/IosStringsGenerator.kt | 2 +- .../generator/strings/StringsGeneratorFeature.kt | 7 +++---- 19 files changed, 30 insertions(+), 42 deletions(-) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index f7301f3d..3e282274 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -164,7 +164,7 @@ class MultiplatformResourcesPlugin : Plugin { info.generatedDir, info.sourceSet, info.mrClassPackage, - generators = features.map { it.createiOSGenerator() } + generators = features.map { it.createIosGenerator() } ) } else { println("unsupported native family $family") @@ -178,4 +178,3 @@ class MultiplatformResourcesPlugin : Plugin { } } } - diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPluginExtension.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPluginExtension.kt index 5bbed6fe..a1e64f4a 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPluginExtension.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPluginExtension.kt @@ -11,4 +11,4 @@ open class MultiplatformResourcesPluginExtension { var multiplatformResourcesSourceSet: String? = null var iosBaseLocalizationRegion: String = "en" val sourceSetName: String get() = multiplatformResourcesSourceSet ?: KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME -} \ No newline at end of file +} diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/AndroidMRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/AndroidMRGenerator.kt index fbb027c0..fee8a6de 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/AndroidMRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/AndroidMRGenerator.kt @@ -35,4 +35,4 @@ class AndroidMRGenerator( } referencedAndroidSet.res.srcDir(resourcesGenerationDir) } -} \ No newline at end of file +} diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt index 477f5891..95960a14 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt @@ -67,4 +67,4 @@ abstract class BaseGenerator : MRGenerator.Generator { protected companion object { const val BASE_LANGUAGE = "base" } -} \ No newline at end of file +} diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/CommonMRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/CommonMRGenerator.kt index 5185fcab..4ee705d9 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/CommonMRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/CommonMRGenerator.kt @@ -31,4 +31,4 @@ class CommonMRGenerator( .mapNotNull { it as? KotlinNativeLink } .forEach { it.compilation.compileKotlinTask.dependsOn(generationTask) } } -} \ No newline at end of file +} diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt index b3e47dc3..e91f8af6 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt @@ -86,7 +86,6 @@ class IosMRGenerator( (generator as? ExtendsPlistDictionary)?.let { it.appendPlistInfo(doc, rootDict) } - } val transformerFactory = TransformerFactory.newInstance() @@ -108,4 +107,4 @@ class IosMRGenerator( interface ExtendsPlistDictionary { fun appendPlistInfo(doc: Document, rootDict: Node) -} \ No newline at end of file +} diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ResourceGeneratorFeature.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ResourceGeneratorFeature.kt index 2bac5151..fefb0999 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ResourceGeneratorFeature.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ResourceGeneratorFeature.kt @@ -4,8 +4,8 @@ package dev.icerock.gradle.generator -abstract class ResourceGeneratorFeature(info: SourceInfo) { - abstract fun createCommonGenerator(): MRGenerator.Generator - abstract fun createiOSGenerator(): MRGenerator.Generator - abstract fun createAndroidGenerator(): MRGenerator.Generator -} \ No newline at end of file +interface ResourceGeneratorFeature { + fun createCommonGenerator(): MRGenerator.Generator + fun createIosGenerator(): MRGenerator.Generator + fun createAndroidGenerator(): MRGenerator.Generator +} diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/SourceInfo.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/SourceInfo.kt index cfc77eb8..a0100bdd 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/SourceInfo.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/SourceInfo.kt @@ -14,4 +14,4 @@ data class SourceInfo( val commonResources: FileTree, val mrClassPackage: String, val androidRClassPackage: String -) \ No newline at end of file +) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/AndroidFontsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/AndroidFontsGenerator.kt index d4cbd545..25c99378 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/AndroidFontsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/AndroidFontsGenerator.kt @@ -10,7 +10,7 @@ import com.squareup.kotlinpoet.KModifier import org.gradle.api.file.FileTree import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import java.io.File -import java.util.* +import java.util.Locale class AndroidFontsGenerator( sourceSet: KotlinSourceSet, diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/CommonFontsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/CommonFontsGenerator.kt index eec08c03..204a3940 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/CommonFontsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/CommonFontsGenerator.kt @@ -20,5 +20,5 @@ class CommonFontsGenerator( override fun getPropertyModifiers(): Array = emptyArray() - override fun getPropertyInitializer(key: String): CodeBlock? = null + override fun getPropertyInitializer(fontFileName: String): CodeBlock? = null } diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/FontsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/FontsGenerator.kt index 7386ad16..c6390053 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/FontsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/FontsGenerator.kt @@ -57,8 +57,6 @@ abstract class FontsGenerator( ) ) } - - return classBuilder.build() } diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/FontsGeneratorFeature.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/FontsGeneratorFeature.kt index 1ec7f756..b36389cf 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/FontsGeneratorFeature.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/FontsGeneratorFeature.kt @@ -8,8 +8,7 @@ import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.ResourceGeneratorFeature import dev.icerock.gradle.generator.SourceInfo - -class FontsGeneratorFeature(private val info: SourceInfo) : ResourceGeneratorFeature(info) { +class FontsGeneratorFeature(private val info: SourceInfo) : ResourceGeneratorFeature { private val stringsFileTree = info.commonResources.matching { include("MR/fonts/**.ttf") } @@ -18,12 +17,11 @@ class FontsGeneratorFeature(private val info: SourceInfo) : ResourceGeneratorFea return CommonFontsGenerator(info.sourceSet, stringsFileTree) } - override fun createiOSGenerator(): MRGenerator.Generator { + override fun createIosGenerator(): MRGenerator.Generator { return IosFontsGenerator(info.sourceSet, stringsFileTree) } override fun createAndroidGenerator(): MRGenerator.Generator { return AndroidFontsGenerator(info.sourceSet, stringsFileTree, info.androidRClassPackage) } - -} \ No newline at end of file +} diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/IosFontsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/IosFontsGenerator.kt index 60d6f7ca..379968ca 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/IosFontsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/IosFontsGenerator.kt @@ -34,4 +34,4 @@ class IosFontsGenerator( file.copyTo(File(resourcesGenerationDir, file.name)) } } -} \ No newline at end of file +} diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/ImagesGeneratorFeature.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/ImagesGeneratorFeature.kt index 5cb96c02..8c8200c0 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/ImagesGeneratorFeature.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/ImagesGeneratorFeature.kt @@ -8,8 +8,7 @@ import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.ResourceGeneratorFeature import dev.icerock.gradle.generator.SourceInfo - -class ImagesGeneratorFeature(private val info: SourceInfo) : ResourceGeneratorFeature(info) { +class ImagesGeneratorFeature(private val info: SourceInfo) : ResourceGeneratorFeature { private val stringsFileTree = info.commonResources.matching { include("MR/images/**/*.png", "MR/images/**/*.jpg") } @@ -18,12 +17,11 @@ class ImagesGeneratorFeature(private val info: SourceInfo) : ResourceGeneratorFe return CommonImagesGenerator(info.sourceSet, stringsFileTree) } - override fun createiOSGenerator(): MRGenerator.Generator { + override fun createIosGenerator(): MRGenerator.Generator { return IosImagesGenerator(info.sourceSet, stringsFileTree) } override fun createAndroidGenerator(): MRGenerator.Generator { return AndroidImagesGenerator(info.sourceSet, stringsFileTree, info.androidRClassPackage) } - -} \ No newline at end of file +} diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/IosImagesGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/IosImagesGenerator.kt index 2c031915..f3d592e2 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/IosImagesGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/IosImagesGenerator.kt @@ -22,7 +22,6 @@ class IosImagesGenerator( override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - override fun getPropertyInitializer(key: String): CodeBlock? { return CodeBlock.of( "ImageResource(assetImageName = %S, bundle = ${IosMRGenerator.BUNDLE_PROPERTY_NAME})", @@ -84,4 +83,4 @@ $imagesContent assetsDirectory.deleteRecursively() } } -} \ No newline at end of file +} diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/IosPluralsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/IosPluralsGenerator.kt index 1a800ba2..c68fdba7 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/IosPluralsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/IosPluralsGenerator.kt @@ -94,4 +94,4 @@ class IosPluralsGenerator( writeStringsFile(regionFile, strings) } } -} \ No newline at end of file +} diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/PluralsGeneratorFeature.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/PluralsGeneratorFeature.kt index 420ec87d..33347b51 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/PluralsGeneratorFeature.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/PluralsGeneratorFeature.kt @@ -8,22 +8,20 @@ import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.ResourceGeneratorFeature import dev.icerock.gradle.generator.SourceInfo - class PluralsGeneratorFeature( private val info: SourceInfo, private val iosBaseLocalizationRegion: String -) : ResourceGeneratorFeature(info) { +) : ResourceGeneratorFeature { private val stringsFileTree = info.commonResources.matching { include("MR/**/plurals.xml") } override fun createCommonGenerator(): MRGenerator.Generator { return CommonPluralsGenerator(info.sourceSet, stringsFileTree) } - override fun createiOSGenerator(): MRGenerator.Generator { + override fun createIosGenerator(): MRGenerator.Generator { return IosPluralsGenerator(info.sourceSet, stringsFileTree, iosBaseLocalizationRegion) } override fun createAndroidGenerator(): MRGenerator.Generator { return AndroidPluralsGenerator(info.sourceSet, stringsFileTree, info.androidRClassPackage) } - -} \ No newline at end of file +} diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/IosStringsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/IosStringsGenerator.kt index 099e22f6..8d2849be 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/IosStringsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/IosStringsGenerator.kt @@ -65,4 +65,4 @@ class IosStringsGenerator( textContent = baseLocalizationRegion }) } -} \ No newline at end of file +} diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/StringsGeneratorFeature.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/StringsGeneratorFeature.kt index a13b894a..ca16571d 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/StringsGeneratorFeature.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/StringsGeneratorFeature.kt @@ -11,18 +11,17 @@ import dev.icerock.gradle.generator.SourceInfo class StringsGeneratorFeature( private val info: SourceInfo, private val iosBaseLocalizationRegion: String -) : ResourceGeneratorFeature(info) { +) : ResourceGeneratorFeature { private val stringsFileTree = info.commonResources.matching { include("MR/**/strings.xml") } override fun createCommonGenerator(): MRGenerator.Generator { return CommonStringsGenerator(info.sourceSet, stringsFileTree) } - override fun createiOSGenerator(): MRGenerator.Generator { + override fun createIosGenerator(): MRGenerator.Generator { return IosStringsGenerator(info.sourceSet, stringsFileTree, iosBaseLocalizationRegion) } override fun createAndroidGenerator(): MRGenerator.Generator { return AndroidStringsGenerator(info.sourceSet, stringsFileTree, info.androidRClassPackage) } - -} \ No newline at end of file +} From 71772477ff99e67c32348a5c94e552d33de93f93 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 20 Apr 2020 21:15:36 +0700 Subject: [PATCH 05/54] configure detekt on gradle-plugin --- .github/workflows/compilation-check.yml | 2 +- buildSrc/src/main/kotlin/Deps.kt | 1 + buildSrc/src/main/kotlin/Versions.kt | 1 + gradle-plugin/build.gradle.kts | 6 ++++-- .../gradle/MultiplatformResourcesPlugin.kt | 17 ++++++++++++----- .../icerock/gradle/generator/BaseGenerator.kt | 1 + .../icerock/gradle/generator/IosMRGenerator.kt | 2 +- .../dev/icerock/gradle/generator/MRGenerator.kt | 1 + .../gradle/generator/fonts/FontsGenerator.kt | 4 +++- .../gradle/generator/image/ImagesGenerator.kt | 1 + .../generator/image/IosImagesGenerator.kt | 10 +++++++--- .../strings/EqualStringKeysException.kt | 9 +++++++++ .../generator/strings/StringsGenerator.kt | 3 +-- 13 files changed, 43 insertions(+), 15 deletions(-) create mode 100644 gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/EqualStringKeysException.kt diff --git a/.github/workflows/compilation-check.yml b/.github/workflows/compilation-check.yml index 76cf46b8..e5955b81 100644 --- a/.github/workflows/compilation-check.yml +++ b/.github/workflows/compilation-check.yml @@ -16,6 +16,6 @@ jobs: with: java-version: 1.8 - name: Check plugin build - run: ./gradlew -PlibraryPublish :gradle-plugin:publishPluginPublicationToMavenLocal + run: ./gradlew -PlibraryPublish :gradle-plugin:detekt :gradle-plugin:publishPluginPublicationToMavenLocal - name: Check library build run: ./gradlew -PlibraryPublish :resources:publishToMavenLocal diff --git a/buildSrc/src/main/kotlin/Deps.kt b/buildSrc/src/main/kotlin/Deps.kt index 56a171c1..f43b3d1b 100755 --- a/buildSrc/src/main/kotlin/Deps.kt +++ b/buildSrc/src/main/kotlin/Deps.kt @@ -52,6 +52,7 @@ object Deps { object Jvm { const val kotlinPoet = "com.squareup:kotlinpoet:${Versions.Libs.Jvm.kotlinPoet}" const val apacheCommonsText = "org.apache.commons:commons-text:${Versions.Libs.Jvm.apacheCommonsText}" + const val detektFormatting = "io.gitlab.arturbosch.detekt:detekt-formatting:${Versions.Plugins.detekt}" } } diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 669bbf2e..e1c80b5a 100755 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -18,6 +18,7 @@ object Versions { const val kotlin = Versions.kotlin const val mokoResources = Versions.mokoResources + const val detekt = "1.7.4" } object Libs { diff --git a/gradle-plugin/build.gradle.kts b/gradle-plugin/build.gradle.kts index 1a7a663f..b2deb892 100644 --- a/gradle-plugin/build.gradle.kts +++ b/gradle-plugin/build.gradle.kts @@ -3,8 +3,9 @@ */ plugins { - `kotlin-dsl` - `maven-publish` + id("org.gradle.kotlin.kotlin-dsl") version "1.3.6" + id("org.gradle.maven-publish") + id("io.gitlab.arturbosch.detekt") version(Versions.Plugins.detekt) } repositories { @@ -19,6 +20,7 @@ dependencies { compileOnly(Deps.Plugins.kotlin) compileOnly(Deps.Plugins.android) implementation(Deps.Libs.Jvm.apacheCommonsText) + detektPlugins(Deps.Libs.Jvm.detektFormatting) } kotlinDslPluginOptions { diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 3e282274..6a938d50 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -91,6 +91,7 @@ class MultiplatformResourcesPlugin : Plugin { return manifest.attributes.getNamedItem("package").textContent } + @Suppress("LongParameterList") private fun generateMultiplatformResources( project: Project, commonResources: FileTree, @@ -132,21 +133,27 @@ class MultiplatformResourcesPlugin : Plugin { info: SourceInfo, features: List ): MRGenerator? { - if (info.sourceSet.name == extension.sourceSetName) { - return CommonMRGenerator( + return when (info.sourceSet.name) { + extension.sourceSetName -> CommonMRGenerator( info.generatedDir, info.sourceSet, info.mrClassPackage, generators = features.map { it.createCommonGenerator() } ) - } else if (info.sourceSet.name == KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME) { - return null + KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME -> null + else -> createPlatformGenerator(multiplatformExtension, info, features) } + } + private fun createPlatformGenerator( + multiplatformExtension: KotlinMultiplatformExtension, + info: SourceInfo, + features: List + ): MRGenerator? { val target = multiplatformExtension.targets.firstOrNull { target -> val sourceSets = target.compilations.flatMap { it.kotlinSourceSets } sourceSets.any { it == info.sourceSet } - } ?: return null + } return when (target) { is KotlinAndroidTarget -> { diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt index 95960a14..6dfe29d6 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt @@ -32,6 +32,7 @@ abstract class BaseGenerator : MRGenerator.Generator { return stringsClass } + @Suppress("SpreadOperator") private fun createTypeSpec(keys: List): TypeSpec { val classBuilder = TypeSpec.objectBuilder(getClassName()) classBuilder.addModifiers(*getClassModifiers()) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt index e91f8af6..8f998006 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt @@ -90,7 +90,7 @@ class IosMRGenerator( val transformerFactory = TransformerFactory.newInstance() val transformer = transformerFactory.newTransformer() - transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + transformer.setOutputProperty(OutputKeys.INDENT, "yes") val writer = FileWriter(infoPList) val result = StreamResult(writer) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt index 6997e58c..63740745 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt @@ -34,6 +34,7 @@ abstract class MRGenerator( sourcesGenerationDir.deleteRecursively() resourcesGenerationDir.deleteRecursively() + @Suppress("SpreadOperator") val mrClassSpec = TypeSpec.objectBuilder(mrClassName) .addModifiers(*getMRClassModifiers()) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/FontsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/FontsGenerator.kt index c6390053..7ead4de9 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/FontsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/FontsGenerator.kt @@ -31,6 +31,7 @@ abstract class FontsGenerator( private fun createTypeSpec(keys: List): TypeSpec { val classBuilder = TypeSpec.objectBuilder("fonts") + @Suppress("SpreadOperator") classBuilder.addModifiers(*getClassModifiers()) /* @@ -44,7 +45,7 @@ abstract class FontsGenerator( } familyGroups.forEach { group -> - //Make pairs: "style name" - "font file" + // TODO Make pairs: "style name" - "font file" val stylePairs = group .value .map { it.substringAfter("-") to it } @@ -62,6 +63,7 @@ abstract class FontsGenerator( override fun getImports(): List = emptyList() + @Suppress("SpreadOperator") private fun generateFontFamilySpec( familyName: String, fontStyleFiles: List> diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/ImagesGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/ImagesGenerator.kt index eb1e0756..9bde0145 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/ImagesGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/ImagesGenerator.kt @@ -31,6 +31,7 @@ abstract class ImagesGenerator( return typeSpec } + @Suppress("SpreadOperator") fun createTypeSpec(keys: List): TypeSpec { val classBuilder = TypeSpec.objectBuilder("images") classBuilder.addModifiers(*getClassModifiers()) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/IosImagesGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/IosImagesGenerator.kt index f3d592e2..c03ed9fe 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/IosImagesGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/IosImagesGenerator.kt @@ -40,19 +40,19 @@ class IosImagesGenerator( val contentsFile = File(assetDir, "Contents.json") val validFiles = files.filter { file -> - (1..3).map { "@${it}x" }.any { file.nameWithoutExtension.endsWith(it) } + VALID_SIZES.map { "@${it}x" }.any { file.nameWithoutExtension.endsWith(it) } } validFiles.forEach { it.copyTo(File(assetDir, it.name)) } - val imagesContent = validFiles.map { file -> + val imagesContent = validFiles.joinToString(separator = ",\n") { file -> val scale = file.nameWithoutExtension.substringAfter("@") """ { "idiom" : "universal", "filename" : "${file.name}", "scale" : "$scale" }""" - }.joinToString(separator = ",\n") + } val content = """{ "images" : [ @@ -83,4 +83,8 @@ $imagesContent assetsDirectory.deleteRecursively() } } + + private companion object { + val VALID_SIZES: IntRange = 0..3 + } } diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/EqualStringKeysException.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/EqualStringKeysException.kt new file mode 100644 index 00000000..56c476da --- /dev/null +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/EqualStringKeysException.kt @@ -0,0 +1,9 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.strings + +class EqualStringKeysException( + val keys: List +) : Exception("Can't process keys which equals their value: ${keys.joinToString { "\"$it\"" }}") diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/StringsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/StringsGenerator.kt index 8ba286dc..b7e02ae3 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/StringsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/StringsGenerator.kt @@ -55,8 +55,7 @@ abstract class StringsGenerator( .keys .toList() if (incorrectKeys.isNotEmpty()) { - val excMessage = incorrectKeys.map { "\"$it\"" }.joinToString() - throw Exception("StringsGenerator: Can't process keys which equals their value: $excMessage") + throw EqualStringKeysException(incorrectKeys) } return mutableMap From a840c3b07c312bfe3bdc3a847df9d4250f1c5c8e Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 20 Apr 2020 21:18:41 +0700 Subject: [PATCH 06/54] remove duplicated schedule afterEvaluate --- .../gradle/MultiplatformResourcesPlugin.kt | 62 +++++++++---------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 6a938d50..c50c38fe 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -45,39 +45,37 @@ class MultiplatformResourcesPlugin : Plugin { target: Project, mrExtension: MultiplatformResourcesPluginExtension ) { - target.afterEvaluate { - val multiplatformExtension = - target.extensions.getByType(KotlinMultiplatformExtension::class) - - val sourceSets = multiplatformExtension.targets - .flatMap { it.compilations } - .filter { it.associateWith.isEmpty() } // filter all tests source sets - .map { compilation -> - if (compilation.target is KotlinAndroidTarget) { - compilation.kotlinSourceSets.first { it.name == "androidMain" } - } else { - compilation.defaultSourceSet - } + val multiplatformExtension = + target.extensions.getByType(KotlinMultiplatformExtension::class) + + val sourceSets = multiplatformExtension.targets + .flatMap { it.compilations } + .filter { it.associateWith.isEmpty() } // filter all tests source sets + .map { compilation -> + if (compilation.target is KotlinAndroidTarget) { + compilation.kotlinSourceSets.first { it.name == "androidMain" } + } else { + compilation.defaultSourceSet } - .distinct() - val commonSourceSet = multiplatformExtension.sourceSets.getByName(mrExtension.sourceSetName) - val commonResources = commonSourceSet.resources - - val androidExtension = target.extensions.getByType(LibraryExtension::class) - val mainAndroidSet = androidExtension.sourceSets.getByName("main") - val manifestFile = mainAndroidSet.manifest.srcFile - - val androidPackage = getAndroidPackage(manifestFile) - - generateMultiplatformResources( - project = target, - commonResources = commonResources, - sourceSets = sourceSets, - extension = mrExtension, - multiplatformExtension = multiplatformExtension, - androidPackage = androidPackage - ) - } + } + .distinct() + val commonSourceSet = multiplatformExtension.sourceSets.getByName(mrExtension.sourceSetName) + val commonResources = commonSourceSet.resources + + val androidExtension = target.extensions.getByType(LibraryExtension::class) + val mainAndroidSet = androidExtension.sourceSets.getByName("main") + val manifestFile = mainAndroidSet.manifest.srcFile + + val androidPackage = getAndroidPackage(manifestFile) + + generateMultiplatformResources( + project = target, + commonResources = commonResources, + sourceSets = sourceSets, + extension = mrExtension, + multiplatformExtension = multiplatformExtension, + androidPackage = androidPackage + ) } private fun getAndroidPackage(manifestFile: File): String { From a13dc58483a068ea86742deaf6d73566273d23de Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Tue, 21 Apr 2020 00:20:04 +0700 Subject: [PATCH 07/54] #58 rework sourcesets detection of gradle plugin (need to complete ios version) --- .../gradle/MultiplatformResourcesPlugin.kt | 260 ++++++++++-------- .../gradle/generator/AndroidMRGenerator.kt | 12 +- .../gradle/generator/CommonMRGenerator.kt | 2 +- .../gradle/generator/IosMRGenerator.kt | 11 +- .../icerock/gradle/generator/MRGenerator.kt | 13 +- .../icerock/gradle/generator/SourceInfo.kt | 2 - .../generator/fonts/AndroidFontsGenerator.kt | 3 - .../generator/fonts/CommonFontsGenerator.kt | 3 - .../gradle/generator/fonts/FontsGenerator.kt | 2 - .../generator/fonts/FontsGeneratorFeature.kt | 6 +- .../generator/fonts/IosFontsGenerator.kt | 3 - .../generator/image/AndroidImagesGenerator.kt | 3 - .../generator/image/CommonImagesGenerator.kt | 3 - .../gradle/generator/image/ImagesGenerator.kt | 2 - .../generator/image/ImagesGeneratorFeature.kt | 6 +- .../generator/image/IosImagesGenerator.kt | 3 - .../plurals/AndroidPluralsGenerator.kt | 3 - .../plurals/CommonPluralsGenerator.kt | 3 - .../generator/plurals/IosPluralsGenerator.kt | 3 - .../generator/plurals/PluralsGenerator.kt | 2 - .../plurals/PluralsGeneratorFeature.kt | 6 +- .../strings/AndroidStringsGenerator.kt | 3 - .../strings/CommonStringsGenerator.kt | 3 - .../generator/strings/IosStringsGenerator.kt | 2 - .../generator/strings/StringsGenerator.kt | 2 - .../strings/StringsGeneratorFeature.kt | 6 +- 26 files changed, 168 insertions(+), 199 deletions(-) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index c50c38fe..46a4a0de 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -5,6 +5,8 @@ package dev.icerock.gradle import com.android.build.gradle.LibraryExtension +import com.android.build.gradle.LibraryPlugin +import com.android.build.gradle.api.AndroidSourceSet import dev.icerock.gradle.generator.AndroidMRGenerator import dev.icerock.gradle.generator.CommonMRGenerator import dev.icerock.gradle.generator.IosMRGenerator @@ -17,12 +19,17 @@ import dev.icerock.gradle.generator.plurals.PluralsGeneratorFeature import dev.icerock.gradle.generator.strings.StringsGeneratorFeature import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.api.file.FileTree +import org.gradle.api.tasks.SourceSet 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.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.KotlinNativeCompilation import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.konan.target.Family import java.io.File @@ -33,153 +40,166 @@ class MultiplatformResourcesPlugin : Plugin { val mrExtension = target.extensions.create("multiplatformResources") - target.afterEvaluate { - configureGenerators( - target = target, - mrExtension = mrExtension - ) + target.plugins.withType { + val multiplatformExtension = target.extensions.getByType(this.projectExtensionClass) + + target.plugins.withType { + val androidExtension = target.extensions.getByName("android") as LibraryExtension + + target.afterEvaluate { + configureGenerators( + target = target, + mrExtension = mrExtension, + multiplatformExtension = multiplatformExtension, + androidExtension = androidExtension + ) + } + } } } private fun configureGenerators( target: Project, - mrExtension: MultiplatformResourcesPluginExtension + mrExtension: MultiplatformResourcesPluginExtension, + multiplatformExtension: KotlinMultiplatformExtension, + androidExtension: LibraryExtension ) { - val multiplatformExtension = - target.extensions.getByType(KotlinMultiplatformExtension::class) + val androidMainSourceSet = androidExtension.sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME) - val sourceSets = multiplatformExtension.targets - .flatMap { it.compilations } - .filter { it.associateWith.isEmpty() } // filter all tests source sets - .map { compilation -> - if (compilation.target is KotlinAndroidTarget) { - compilation.kotlinSourceSets.first { it.name == "androidMain" } - } else { - compilation.defaultSourceSet - } - } - .distinct() val commonSourceSet = multiplatformExtension.sourceSets.getByName(mrExtension.sourceSetName) val commonResources = commonSourceSet.resources - val androidExtension = target.extensions.getByType(LibraryExtension::class) - val mainAndroidSet = androidExtension.sourceSets.getByName("main") - val manifestFile = mainAndroidSet.manifest.srcFile - + val manifestFile = androidMainSourceSet.manifest.srcFile val androidPackage = getAndroidPackage(manifestFile) - generateMultiplatformResources( - project = target, - commonResources = commonResources, - sourceSets = sourceSets, - extension = mrExtension, - multiplatformExtension = multiplatformExtension, - androidPackage = androidPackage + val generatedDir = File(target.buildDir, "generated/moko") + val mrClassPackage: String = requireNotNull(mrExtension.multiplatformResourcesPackage) + val sourceInfo = SourceInfo( + generatedDir, + commonResources, + mrExtension.multiplatformResourcesPackage!!, + androidPackage ) - } - - private fun getAndroidPackage(manifestFile: File): String { - val dbFactory = DocumentBuilderFactory.newInstance() - val dBuilder = dbFactory.newDocumentBuilder() - val doc = dBuilder.parse(manifestFile) + val features = listOf( + StringsGeneratorFeature(sourceInfo, mrExtension.iosBaseLocalizationRegion), + PluralsGeneratorFeature(sourceInfo, mrExtension.iosBaseLocalizationRegion), + ImagesGeneratorFeature(sourceInfo), + FontsGeneratorFeature(sourceInfo) + ) + val targets: List = multiplatformExtension.targets.toList() - val manifestNodes = doc.getElementsByTagName("manifest") - val manifest = manifestNodes.item(0) + setupCommonGenerator(commonSourceSet, generatedDir, mrClassPackage, features, target) + setupAndroidGenerator(targets, androidMainSourceSet, generatedDir, mrClassPackage, features, target) + setupIosGenerator(targets, generatedDir, mrClassPackage, features) + } - return manifest.attributes.getNamedItem("package").textContent + private fun setupCommonGenerator( + commonSourceSet: KotlinSourceSet, + generatedDir: File, + mrClassPackage: String, + features: List, + target: Project + ) { + val commonGeneratorSourceSet: MRGenerator.SourceSet = createSourceSet(commonSourceSet) + val generator = CommonMRGenerator( + generatedDir, + commonGeneratorSourceSet, + mrClassPackage, + generators = features.map { it.createCommonGenerator() } + ) + generator.apply(target) } @Suppress("LongParameterList") - private fun generateMultiplatformResources( - project: Project, - commonResources: FileTree, - sourceSets: List, - extension: MultiplatformResourcesPluginExtension, - multiplatformExtension: KotlinMultiplatformExtension, - androidPackage: String + private fun setupAndroidGenerator( + targets: List, + androidMainSourceSet: AndroidSourceSet, + generatedDir: File, + mrClassPackage: String, + features: List, + target: Project ) { - val generatedDir = File(project.buildDir, "generated/moko") - - sourceSets.forEach { sourceSet -> - val sourceInfo = SourceInfo( - generatedDir, - sourceSet, - commonResources, - extension.multiplatformResourcesPackage!!, - androidPackage - ) - val features = listOf( - StringsGeneratorFeature(sourceInfo, extension.iosBaseLocalizationRegion), - PluralsGeneratorFeature(sourceInfo, extension.iosBaseLocalizationRegion), - ImagesGeneratorFeature(sourceInfo), - FontsGeneratorFeature(sourceInfo) - ) - val generator = createGenerator( - multiplatformExtension = multiplatformExtension, - extension = extension, - info = sourceInfo, - features = features - ) ?: return@forEach - - generator.apply(project = project) - } + val kotlinSourceSets: List = targets + .filterIsInstance() + .flatMap { it.compilations } + .filter { it.associateWith.isEmpty() } // remove tests compilations + .map { it.defaultSourceSet } + + val androidSourceSet: MRGenerator.SourceSet = createSourceSet(androidMainSourceSet, kotlinSourceSets) + val generator = AndroidMRGenerator( + generatedDir, + androidSourceSet, + mrClassPackage, + generators = features.map { it.createAndroidGenerator() } + ) + generator.apply(target) } - private fun createGenerator( - multiplatformExtension: KotlinMultiplatformExtension, - extension: MultiplatformResourcesPluginExtension, - info: SourceInfo, + private fun setupIosGenerator( + targets: List, + generatedDir: File, + mrClassPackage: String, features: List - ): MRGenerator? { - return when (info.sourceSet.name) { - extension.sourceSetName -> CommonMRGenerator( - info.generatedDir, - info.sourceSet, - info.mrClassPackage, - generators = features.map { it.createCommonGenerator() } - ) - KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME -> null - else -> createPlatformGenerator(multiplatformExtension, info, features) - } + ) { + targets + .filterIsInstance() + .filter { it.konanTarget.family == Family.IOS } + .map { kotlinNativeTarget -> + val mainCompilation: KotlinNativeCompilation = kotlinNativeTarget.compilations + .getByName(KotlinCompilation.MAIN_COMPILATION_NAME) + createSourceSet(mainCompilation.defaultSourceSet) + } + .forEach { sourceSet -> + IosMRGenerator( + generatedDir, + sourceSet, + mrClassPackage, + generators = features.map { it.createIosGenerator() } + ) + } } - private fun createPlatformGenerator( - multiplatformExtension: KotlinMultiplatformExtension, - info: SourceInfo, - features: List - ): MRGenerator? { - val target = multiplatformExtension.targets.firstOrNull { target -> - val sourceSets = target.compilations.flatMap { it.kotlinSourceSets } - sourceSets.any { it == info.sourceSet } - } + private fun createSourceSet(kotlinSourceSet: KotlinSourceSet): MRGenerator.SourceSet { + return object : MRGenerator.SourceSet { + override val name: String + get() = kotlinSourceSet.name - return when (target) { - is KotlinAndroidTarget -> { - AndroidMRGenerator( - info.generatedDir, - info.sourceSet, - info.mrClassPackage, - generators = features.map { it.createAndroidGenerator() } - ) + override fun addSourceDir(directory: File) { + kotlinSourceSet.kotlin.srcDir(directory) } - is KotlinNativeTarget -> { - val family = target.konanTarget.family - if (family == Family.IOS) { - IosMRGenerator( - info.generatedDir, - info.sourceSet, - info.mrClassPackage, - generators = features.map { it.createIosGenerator() } - ) - } else { - println("unsupported native family $family") - null - } + + override fun addResourcesDir(directory: File) { + kotlinSourceSet.resources.srcDir(directory) + } + } + } + + private fun createSourceSet( + androidSourceSet: AndroidSourceSet, + kotlinSourceSets: List + ): MRGenerator.SourceSet { + return object : MRGenerator.SourceSet { + override val name: String + get() = androidSourceSet.name + + override fun addSourceDir(directory: File) { + kotlinSourceSets.forEach { it.kotlin.srcDir(directory) } } - else -> { - println("unsupported target $target") - null + + override fun addResourcesDir(directory: File) { + androidSourceSet.res.srcDir(directory) } } } + + 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/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/AndroidMRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/AndroidMRGenerator.kt index fee8a6de..ade6520a 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/AndroidMRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/AndroidMRGenerator.kt @@ -4,17 +4,14 @@ package dev.icerock.gradle.generator -import com.android.build.gradle.LibraryExtension import com.squareup.kotlinpoet.KModifier import org.gradle.api.Project import org.gradle.api.Task -import org.gradle.kotlin.dsl.getByType -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import java.io.File class AndroidMRGenerator( generatedDir: File, - sourceSet: KotlinSourceSet, + sourceSet: SourceSet, mrClassPackage: String, generators: List ) : MRGenerator( @@ -27,12 +24,5 @@ class AndroidMRGenerator( override fun apply(generationTask: Task, project: Project) { project.tasks.getByName("preBuild").dependsOn(generationTask) - - val androidExtension = project.extensions.getByType(LibraryExtension::class) - val referencedAndroidSet = androidExtension.sourceSets.first { - val capitalized = it.name.capitalize() - "android$capitalized" == sourceSet.name - } - referencedAndroidSet.res.srcDir(resourcesGenerationDir) } } diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/CommonMRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/CommonMRGenerator.kt index 4ee705d9..d2a3b26e 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/CommonMRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/CommonMRGenerator.kt @@ -13,7 +13,7 @@ import java.io.File class CommonMRGenerator( generatedDir: File, - sourceSet: KotlinSourceSet, + sourceSet: SourceSet, mrClassPackage: String, generators: List ) : MRGenerator( diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt index 8f998006..939bc4a5 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt @@ -11,7 +11,6 @@ import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.TypeSpec import org.gradle.api.Project import org.gradle.api.Task -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import org.jetbrains.kotlin.gradle.plugin.mpp.Framework import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink import org.w3c.dom.Document @@ -26,7 +25,7 @@ import javax.xml.transform.stream.StreamResult class IosMRGenerator( generatedDir: File, - sourceSet: KotlinSourceSet, + sourceSet: SourceSet, mrClassPackage: String, private val generators: List ) : MRGenerator( @@ -82,11 +81,9 @@ class IosMRGenerator( val rootDict = doc.getElementsByTagName("dict").item(0) - generators.forEach { generator -> - (generator as? ExtendsPlistDictionary)?.let { - it.appendPlistInfo(doc, rootDict) - } - } + generators + .mapNotNull { it as? ExtendsPlistDictionary } + .forEach { it.appendPlistInfo(doc, rootDict) } val transformerFactory = TransformerFactory.newInstance() val transformer = transformerFactory.newTransformer() diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt index 63740745..fe26a026 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt @@ -15,7 +15,7 @@ import java.io.File abstract class MRGenerator( generatedDir: File, - protected val sourceSet: KotlinSourceSet, + protected val sourceSet: SourceSet, private val mrClassPackage: String, private val generators: List ) { @@ -24,10 +24,10 @@ abstract class MRGenerator( init { sourcesGenerationDir.mkdirs() - sourceSet.kotlin.srcDir(sourcesGenerationDir) + sourceSet.addSourceDir(sourcesGenerationDir) resourcesGenerationDir.mkdirs() - sourceSet.resources.srcDir(resourcesGenerationDir) + sourceSet.addResourcesDir(resourcesGenerationDir) } private fun generate() { @@ -83,4 +83,11 @@ abstract class MRGenerator( fun generate(resourcesGenerationDir: File): TypeSpec fun getImports(): List } + + interface SourceSet { + val name: String + + fun addSourceDir(directory: File) + fun addResourcesDir(directory: File) + } } diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/SourceInfo.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/SourceInfo.kt index a0100bdd..9689331c 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/SourceInfo.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/SourceInfo.kt @@ -5,12 +5,10 @@ package dev.icerock.gradle.generator import org.gradle.api.file.FileTree -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import java.io.File data class SourceInfo( val generatedDir: File, - val sourceSet: KotlinSourceSet, val commonResources: FileTree, val mrClassPackage: String, val androidRClassPackage: String diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/AndroidFontsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/AndroidFontsGenerator.kt index 25c99378..d22eb05f 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/AndroidFontsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/AndroidFontsGenerator.kt @@ -8,16 +8,13 @@ import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier import org.gradle.api.file.FileTree -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import java.io.File import java.util.Locale class AndroidFontsGenerator( - sourceSet: KotlinSourceSet, inputFileTree: FileTree, private val androidRClassPackage: String ) : FontsGenerator( - sourceSet = sourceSet, inputFileTree = inputFileTree ) { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/CommonFontsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/CommonFontsGenerator.kt index 204a3940..4b36ed59 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/CommonFontsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/CommonFontsGenerator.kt @@ -7,13 +7,10 @@ package dev.icerock.gradle.generator.fonts import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier import org.gradle.api.file.FileTree -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet class CommonFontsGenerator( - sourceSet: KotlinSourceSet, inputFileTree: FileTree ) : FontsGenerator( - sourceSet = sourceSet, inputFileTree = inputFileTree ) { override fun getClassModifiers(): Array = emptyArray() diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/FontsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/FontsGenerator.kt index 7ead4de9..169369ec 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/FontsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/FontsGenerator.kt @@ -11,11 +11,9 @@ import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.MRGenerator import org.gradle.api.file.FileTree -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import java.io.File abstract class FontsGenerator( - protected val sourceSet: KotlinSourceSet, private val inputFileTree: FileTree ) : MRGenerator.Generator { diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/FontsGeneratorFeature.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/FontsGeneratorFeature.kt index b36389cf..bb99fb5a 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/FontsGeneratorFeature.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/FontsGeneratorFeature.kt @@ -14,14 +14,14 @@ class FontsGeneratorFeature(private val info: SourceInfo) : ResourceGeneratorFea } override fun createCommonGenerator(): MRGenerator.Generator { - return CommonFontsGenerator(info.sourceSet, stringsFileTree) + return CommonFontsGenerator(stringsFileTree) } override fun createIosGenerator(): MRGenerator.Generator { - return IosFontsGenerator(info.sourceSet, stringsFileTree) + return IosFontsGenerator(stringsFileTree) } override fun createAndroidGenerator(): MRGenerator.Generator { - return AndroidFontsGenerator(info.sourceSet, stringsFileTree, info.androidRClassPackage) + return AndroidFontsGenerator(stringsFileTree, info.androidRClassPackage) } } diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/IosFontsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/IosFontsGenerator.kt index 379968ca..5a3e9add 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/IosFontsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/IosFontsGenerator.kt @@ -7,14 +7,11 @@ package dev.icerock.gradle.generator.fonts import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier import org.gradle.api.file.FileTree -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import java.io.File class IosFontsGenerator( - sourceSet: KotlinSourceSet, inputFileTree: FileTree ) : FontsGenerator( - sourceSet = sourceSet, inputFileTree = inputFileTree ) { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/AndroidImagesGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/AndroidImagesGenerator.kt index a16b633b..898d74d3 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/AndroidImagesGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/AndroidImagesGenerator.kt @@ -8,15 +8,12 @@ import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier import org.gradle.api.file.FileTree -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import java.io.File class AndroidImagesGenerator( - sourceSet: KotlinSourceSet, inputFileTree: FileTree, private val androidRClassPackage: String ) : ImagesGenerator( - sourceSet = sourceSet, inputFileTree = inputFileTree ) { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/CommonImagesGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/CommonImagesGenerator.kt index 793fe847..7ea94a9b 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/CommonImagesGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/CommonImagesGenerator.kt @@ -7,13 +7,10 @@ package dev.icerock.gradle.generator.image import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier import org.gradle.api.file.FileTree -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet class CommonImagesGenerator( - sourceSet: KotlinSourceSet, inputFileTree: FileTree ) : ImagesGenerator( - sourceSet = sourceSet, inputFileTree = inputFileTree ) { override fun getClassModifiers(): Array = emptyArray() diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/ImagesGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/ImagesGenerator.kt index 9bde0145..3cf6b200 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/ImagesGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/ImagesGenerator.kt @@ -11,11 +11,9 @@ import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.TypeSpec import dev.icerock.gradle.generator.MRGenerator import org.gradle.api.file.FileTree -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import java.io.File abstract class ImagesGenerator( - protected val sourceSet: KotlinSourceSet, private val inputFileTree: FileTree ) : MRGenerator.Generator { diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/ImagesGeneratorFeature.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/ImagesGeneratorFeature.kt index 8c8200c0..f20115fe 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/ImagesGeneratorFeature.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/ImagesGeneratorFeature.kt @@ -14,14 +14,14 @@ class ImagesGeneratorFeature(private val info: SourceInfo) : ResourceGeneratorFe } override fun createCommonGenerator(): MRGenerator.Generator { - return CommonImagesGenerator(info.sourceSet, stringsFileTree) + return CommonImagesGenerator(stringsFileTree) } override fun createIosGenerator(): MRGenerator.Generator { - return IosImagesGenerator(info.sourceSet, stringsFileTree) + return IosImagesGenerator(stringsFileTree) } override fun createAndroidGenerator(): MRGenerator.Generator { - return AndroidImagesGenerator(info.sourceSet, stringsFileTree, info.androidRClassPackage) + return AndroidImagesGenerator(stringsFileTree, info.androidRClassPackage) } } diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/IosImagesGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/IosImagesGenerator.kt index c03ed9fe..e5478de8 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/IosImagesGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/IosImagesGenerator.kt @@ -8,14 +8,11 @@ import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.IosMRGenerator import org.gradle.api.file.FileTree -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import java.io.File class IosImagesGenerator( - sourceSet: KotlinSourceSet, inputFileTree: FileTree ) : ImagesGenerator( - sourceSet = sourceSet, inputFileTree = inputFileTree ) { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/AndroidPluralsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/AndroidPluralsGenerator.kt index a853a249..70a39e94 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/AndroidPluralsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/AndroidPluralsGenerator.kt @@ -10,15 +10,12 @@ import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.strings.KeyType import org.apache.commons.lang3.StringEscapeUtils import org.gradle.api.file.FileTree -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import java.io.File class AndroidPluralsGenerator( - sourceSet: KotlinSourceSet, pluralsFileTree: FileTree, private val androidRClassPackage: String ) : PluralsGenerator( - sourceSet = sourceSet, pluralsFileTree = pluralsFileTree ) { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/CommonPluralsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/CommonPluralsGenerator.kt index f36125fd..e630a1da 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/CommonPluralsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/CommonPluralsGenerator.kt @@ -6,13 +6,10 @@ package dev.icerock.gradle.generator.plurals import com.squareup.kotlinpoet.CodeBlock import org.gradle.api.file.FileTree -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet class CommonPluralsGenerator( - sourceSet: KotlinSourceSet, pluralsFileTree: FileTree ) : PluralsGenerator( - sourceSet = sourceSet, pluralsFileTree = pluralsFileTree ) { override fun getPropertyInitializer(key: String): CodeBlock? = null diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/IosPluralsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/IosPluralsGenerator.kt index c68fdba7..250aba90 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/IosPluralsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/IosPluralsGenerator.kt @@ -9,15 +9,12 @@ import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.IosMRGenerator import dev.icerock.gradle.generator.strings.KeyType import org.gradle.api.file.FileTree -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import java.io.File class IosPluralsGenerator( - sourceSet: KotlinSourceSet, pluralsFileTree: FileTree, private val baseLocalizationRegion: String ) : PluralsGenerator( - sourceSet = sourceSet, pluralsFileTree = pluralsFileTree ) { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/PluralsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/PluralsGenerator.kt index fa8c64b7..d7cfa53f 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/PluralsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/PluralsGenerator.kt @@ -9,7 +9,6 @@ import dev.icerock.gradle.generator.BaseGenerator import dev.icerock.gradle.generator.strings.KeyType import dev.icerock.gradle.generator.strings.LanguageType import org.gradle.api.file.FileTree -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import org.w3c.dom.Element import java.io.File import javax.xml.parsers.DocumentBuilderFactory @@ -17,7 +16,6 @@ import javax.xml.parsers.DocumentBuilderFactory typealias PluralMap = Map abstract class PluralsGenerator( - protected val sourceSet: KotlinSourceSet, private val pluralsFileTree: FileTree ) : BaseGenerator() { diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/PluralsGeneratorFeature.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/PluralsGeneratorFeature.kt index 33347b51..7c2414f7 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/PluralsGeneratorFeature.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/PluralsGeneratorFeature.kt @@ -14,14 +14,14 @@ class PluralsGeneratorFeature( ) : ResourceGeneratorFeature { private val stringsFileTree = info.commonResources.matching { include("MR/**/plurals.xml") } override fun createCommonGenerator(): MRGenerator.Generator { - return CommonPluralsGenerator(info.sourceSet, stringsFileTree) + return CommonPluralsGenerator(stringsFileTree) } override fun createIosGenerator(): MRGenerator.Generator { - return IosPluralsGenerator(info.sourceSet, stringsFileTree, iosBaseLocalizationRegion) + return IosPluralsGenerator(stringsFileTree, iosBaseLocalizationRegion) } override fun createAndroidGenerator(): MRGenerator.Generator { - return AndroidPluralsGenerator(info.sourceSet, stringsFileTree, info.androidRClassPackage) + return AndroidPluralsGenerator(stringsFileTree, info.androidRClassPackage) } } diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/AndroidStringsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/AndroidStringsGenerator.kt index 3ca266b9..9574cd28 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/AndroidStringsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/AndroidStringsGenerator.kt @@ -9,15 +9,12 @@ import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier import org.apache.commons.lang3.StringEscapeUtils import org.gradle.api.file.FileTree -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import java.io.File class AndroidStringsGenerator( - sourceSet: KotlinSourceSet, stringsFileTree: FileTree, private val androidRClassPackage: String ) : StringsGenerator( - sourceSet = sourceSet, stringsFileTree = stringsFileTree ) { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/CommonStringsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/CommonStringsGenerator.kt index dc514350..3582bbd1 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/CommonStringsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/CommonStringsGenerator.kt @@ -6,13 +6,10 @@ package dev.icerock.gradle.generator.strings import com.squareup.kotlinpoet.CodeBlock import org.gradle.api.file.FileTree -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet class CommonStringsGenerator( - sourceSet: KotlinSourceSet, stringsFileTree: FileTree ) : StringsGenerator( - sourceSet = sourceSet, stringsFileTree = stringsFileTree ) { override fun getPropertyInitializer(key: String): CodeBlock? = null diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/IosStringsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/IosStringsGenerator.kt index 8d2849be..06d8c675 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/IosStringsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/IosStringsGenerator.kt @@ -15,11 +15,9 @@ import org.w3c.dom.Node import java.io.File class IosStringsGenerator( - sourceSet: KotlinSourceSet, stringsFileTree: FileTree, private val baseLocalizationRegion: String ) : StringsGenerator( - sourceSet = sourceSet, stringsFileTree = stringsFileTree ), ExtendsPlistDictionary { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/StringsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/StringsGenerator.kt index b7e02ae3..e2fef04c 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/StringsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/StringsGenerator.kt @@ -7,7 +7,6 @@ package dev.icerock.gradle.generator.strings import com.squareup.kotlinpoet.ClassName import dev.icerock.gradle.generator.BaseGenerator import org.gradle.api.file.FileTree -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import java.io.File import javax.xml.parsers.DocumentBuilderFactory @@ -15,7 +14,6 @@ typealias LanguageType = String typealias KeyType = String abstract class StringsGenerator( - protected val sourceSet: KotlinSourceSet, private val stringsFileTree: FileTree ) : BaseGenerator() { override fun loadLanguageMap(): Map> { diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/StringsGeneratorFeature.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/StringsGeneratorFeature.kt index ca16571d..fc5357f3 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/StringsGeneratorFeature.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/StringsGeneratorFeature.kt @@ -14,14 +14,14 @@ class StringsGeneratorFeature( ) : ResourceGeneratorFeature { private val stringsFileTree = info.commonResources.matching { include("MR/**/strings.xml") } override fun createCommonGenerator(): MRGenerator.Generator { - return CommonStringsGenerator(info.sourceSet, stringsFileTree) + return CommonStringsGenerator(stringsFileTree) } override fun createIosGenerator(): MRGenerator.Generator { - return IosStringsGenerator(info.sourceSet, stringsFileTree, iosBaseLocalizationRegion) + return IosStringsGenerator(stringsFileTree, iosBaseLocalizationRegion) } override fun createAndroidGenerator(): MRGenerator.Generator { - return AndroidStringsGenerator(info.sourceSet, stringsFileTree, info.androidRClassPackage) + return AndroidStringsGenerator(stringsFileTree, info.androidRClassPackage) } } From 8445368a69021ae2f81e2fde380a327cf97f1b77 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Tue, 21 Apr 2020 11:25:34 +0700 Subject: [PATCH 08/54] #58 fix of generator configuration and android tests targets --- .../gradle/MultiplatformResourcesPlugin.kt | 32 +++++----- .../gradle/generator/IosMRGenerator.kt | 60 +++++++++++-------- 2 files changed, 51 insertions(+), 41 deletions(-) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 46a4a0de..d3282288 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -29,8 +29,8 @@ 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.KotlinNativeCompilation import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmAndroidCompilation import org.jetbrains.kotlin.konan.target.Family import java.io.File import javax.xml.parsers.DocumentBuilderFactory @@ -90,7 +90,7 @@ class MultiplatformResourcesPlugin : Plugin { setupCommonGenerator(commonSourceSet, generatedDir, mrClassPackage, features, target) setupAndroidGenerator(targets, androidMainSourceSet, generatedDir, mrClassPackage, features, target) - setupIosGenerator(targets, generatedDir, mrClassPackage, features) + setupIosGenerator(targets, generatedDir, mrClassPackage, features, target) } private fun setupCommonGenerator( @@ -101,13 +101,12 @@ class MultiplatformResourcesPlugin : Plugin { target: Project ) { val commonGeneratorSourceSet: MRGenerator.SourceSet = createSourceSet(commonSourceSet) - val generator = CommonMRGenerator( + CommonMRGenerator( generatedDir, commonGeneratorSourceSet, mrClassPackage, generators = features.map { it.createCommonGenerator() } - ) - generator.apply(target) + ).apply(target) } @Suppress("LongParameterList") @@ -122,40 +121,41 @@ class MultiplatformResourcesPlugin : Plugin { val kotlinSourceSets: List = targets .filterIsInstance() .flatMap { it.compilations } - .filter { it.associateWith.isEmpty() } // remove tests compilations + .filterNot { it.name.endsWith("Test") } // remove tests compilations .map { it.defaultSourceSet } val androidSourceSet: MRGenerator.SourceSet = createSourceSet(androidMainSourceSet, kotlinSourceSets) - val generator = AndroidMRGenerator( + AndroidMRGenerator( generatedDir, androidSourceSet, mrClassPackage, generators = features.map { it.createAndroidGenerator() } - ) - generator.apply(target) + ).apply(target) } private fun setupIosGenerator( targets: List, generatedDir: File, mrClassPackage: String, - features: List + features: List, + target: Project ) { targets .filterIsInstance() .filter { it.konanTarget.family == Family.IOS } .map { kotlinNativeTarget -> - val mainCompilation: KotlinNativeCompilation = kotlinNativeTarget.compilations + kotlinNativeTarget.compilations .getByName(KotlinCompilation.MAIN_COMPILATION_NAME) - createSourceSet(mainCompilation.defaultSourceSet) } - .forEach { sourceSet -> + .forEach { compilation -> + val sourceSet = createSourceSet(compilation.defaultSourceSet) IosMRGenerator( generatedDir, sourceSet, mrClassPackage, - generators = features.map { it.createIosGenerator() } - ) + generators = features.map { it.createIosGenerator() }, + compilation = compilation + ).apply(target) } } @@ -180,7 +180,7 @@ class MultiplatformResourcesPlugin : Plugin { ): MRGenerator.SourceSet { return object : MRGenerator.SourceSet { override val name: String - get() = androidSourceSet.name + get() = "android${androidSourceSet.name.capitalize()}" override fun addSourceDir(directory: File) { kotlinSourceSets.forEach { it.kotlin.srcDir(directory) } diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt index 939bc4a5..735c5c2e 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt @@ -22,12 +22,16 @@ import javax.xml.transform.OutputKeys import javax.xml.transform.TransformerFactory import javax.xml.transform.dom.DOMSource import javax.xml.transform.stream.StreamResult +import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile +import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractKotlinNativeCompilation +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget class IosMRGenerator( generatedDir: File, sourceSet: SourceSet, mrClassPackage: String, - private val generators: List + private val generators: List, + private val compilation: AbstractKotlinNativeCompilation ) : MRGenerator( generatedDir = generatedDir, sourceSet = sourceSet, @@ -59,42 +63,48 @@ class IosMRGenerator( ) override fun apply(generationTask: Task, project: Project) { - val linkTasks = project.tasks - .mapNotNull { it as? KotlinNativeLink } - .filter { it.binary is Framework } - .filter { it.compilation.kotlinSourceSets.contains(sourceSet) } + val compileTask: KotlinNativeCompile = compilation.compileKotlinTask + compileTask.dependsOn(generationTask) - linkTasks.forEach { linkTask -> - linkTask.compilation.compileKotlinTask.dependsOn(generationTask) + val kotlinNativeTarget = compilation.target as KotlinNativeTarget - val framework = linkTask.binary as? Framework ?: return@forEach + val frameworkBinaries: List = kotlinNativeTarget.binaries + .filterIsInstance() + .filter { it.compilation == compilation } + + frameworkBinaries.forEach { framework -> + val linkTask = framework.linkTask linkTask.doLast { resourcesGenerationDir.copyRecursively(framework.outputFile, overwrite = true) - val infoPList = File(framework.outputFile, "Info.plist") + processInfoPlist(framework) + } + } + } - val dbFactory = DocumentBuilderFactory.newInstance() - dbFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false) - val dBuilder = dbFactory.newDocumentBuilder() - val doc = dBuilder.parse(infoPList) + private fun processInfoPlist(framework: Framework) { + val infoPList = File(framework.outputFile, "Info.plist") - val rootDict = doc.getElementsByTagName("dict").item(0) + val dbFactory = DocumentBuilderFactory.newInstance() + dbFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false) + val dBuilder = dbFactory.newDocumentBuilder() + val doc = dBuilder.parse(infoPList) - generators - .mapNotNull { it as? ExtendsPlistDictionary } - .forEach { it.appendPlistInfo(doc, rootDict) } + val rootDict = doc.getElementsByTagName("dict").item(0) - val transformerFactory = TransformerFactory.newInstance() - val transformer = transformerFactory.newTransformer() - transformer.setOutputProperty(OutputKeys.INDENT, "yes") + generators + .mapNotNull { it as? ExtendsPlistDictionary } + .forEach { it.appendPlistInfo(doc, rootDict) } - val writer = FileWriter(infoPList) - val result = StreamResult(writer) + val transformerFactory = TransformerFactory.newInstance() + val transformer = transformerFactory.newTransformer() + transformer.setOutputProperty(OutputKeys.INDENT, "yes") - transformer.transform(DOMSource(doc), result) - } - } + val writer = FileWriter(infoPList) + val result = StreamResult(writer) + + transformer.transform(DOMSource(doc), result) } companion object { From cf4205feacc4451be04d3f07af6e0bc9623f6277 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Fri, 1 May 2020 23:41:28 +0700 Subject: [PATCH 09/54] #58 fix crossdepend sourcesets --- .../gradle/MultiplatformResourcesPlugin.kt | 34 ++++++++++++------- .../icerock/gradle/generator/MRGenerator.kt | 6 ++-- sample/mpp-mixed/build.gradle.kts | 5 ++- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index d3282288..1c4f5cf5 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -30,7 +30,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.KotlinNativeTarget -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmAndroidCompilation import org.jetbrains.kotlin.konan.target.Family import java.io.File import javax.xml.parsers.DocumentBuilderFactory @@ -140,23 +139,34 @@ class MultiplatformResourcesPlugin : Plugin { features: List, target: Project ) { - targets + val compilations = targets .filterIsInstance() .filter { it.konanTarget.family == Family.IOS } .map { kotlinNativeTarget -> kotlinNativeTarget.compilations .getByName(KotlinCompilation.MAIN_COMPILATION_NAME) } - .forEach { compilation -> - val sourceSet = createSourceSet(compilation.defaultSourceSet) - IosMRGenerator( - generatedDir, - sourceSet, - mrClassPackage, - generators = features.map { it.createIosGenerator() }, - compilation = compilation - ).apply(target) - } + + val defSourceSets = compilations.map { it.defaultSourceSet } + compilations.forEach { compilation -> + val kss = compilation.defaultSourceSet + val depend = kss.getDependedFrom(defSourceSets) + + val sourceSet = createSourceSet(depend ?: kss) + IosMRGenerator( + generatedDir, + sourceSet, + mrClassPackage, + generators = features.map { it.createIosGenerator() }, + compilation = compilation + ).apply(target) + } + } + + private fun KotlinSourceSet.getDependedFrom(sourceSets: Collection): KotlinSourceSet? { + return sourceSets.firstOrNull { this.dependsOn.contains(it) } ?: this.dependsOn + .mapNotNull { it.getDependedFrom(sourceSets) } + .firstOrNull() } private fun createSourceSet(kotlinSourceSet: KotlinSourceSet): MRGenerator.SourceSet { diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt index fe26a026..4472db50 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt @@ -10,7 +10,6 @@ import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.TypeSpec import org.gradle.api.Project import org.gradle.api.Task -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import java.io.File abstract class MRGenerator( @@ -58,7 +57,10 @@ abstract class MRGenerator( fun apply(project: Project) { val name = sourceSet.name - val genTask = project.task("generateMR$name") { + val genTaskName = "generateMR$name" + val genTask = runCatching { + project.tasks.getByName(genTaskName) + }.getOrNull() ?: project.task(genTaskName) { group = "multiplatform" doLast { diff --git a/sample/mpp-mixed/build.gradle.kts b/sample/mpp-mixed/build.gradle.kts index 337539fb..f77498e1 100644 --- a/sample/mpp-mixed/build.gradle.kts +++ b/sample/mpp-mixed/build.gradle.kts @@ -35,9 +35,12 @@ kotlin { sourceSets { val iosX64Main by getting {} val iosX64Test by getting {} - val iosArm64Main by getting { + val iosMiddle by creating { dependsOn(iosX64Main) } + val iosArm64Main by getting { + dependsOn(iosMiddle) + } val iosArm64Test by getting { dependsOn(iosX64Test) } From 02d23fb2a1ebd8995524e78f8e8792d8ef15ed06 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Fri, 1 May 2020 23:49:21 +0700 Subject: [PATCH 10/54] #58 fix detekt issues --- .../dev/icerock/gradle/generator/CommonMRGenerator.kt | 1 - .../kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt | 7 +++---- .../gradle/generator/strings/IosStringsGenerator.kt | 1 - 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/CommonMRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/CommonMRGenerator.kt index d2a3b26e..1c8391a9 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/CommonMRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/CommonMRGenerator.kt @@ -7,7 +7,6 @@ package dev.icerock.gradle.generator import com.squareup.kotlinpoet.KModifier import org.gradle.api.Project import org.gradle.api.Task -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink import java.io.File diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt index 735c5c2e..f4bb1c5f 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt @@ -11,8 +11,10 @@ import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.TypeSpec import org.gradle.api.Project import org.gradle.api.Task +import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractKotlinNativeCompilation import org.jetbrains.kotlin.gradle.plugin.mpp.Framework -import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget +import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile import org.w3c.dom.Document import org.w3c.dom.Node import java.io.File @@ -22,9 +24,6 @@ import javax.xml.transform.OutputKeys import javax.xml.transform.TransformerFactory import javax.xml.transform.dom.DOMSource import javax.xml.transform.stream.StreamResult -import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile -import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractKotlinNativeCompilation -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget class IosMRGenerator( generatedDir: File, diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/IosStringsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/IosStringsGenerator.kt index 06d8c675..7c8a279d 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/IosStringsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/IosStringsGenerator.kt @@ -9,7 +9,6 @@ import com.squareup.kotlinpoet.KModifier import dev.icerock.gradle.generator.ExtendsPlistDictionary import dev.icerock.gradle.generator.IosMRGenerator.Companion.BUNDLE_PROPERTY_NAME import org.gradle.api.file.FileTree -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import org.w3c.dom.Document import org.w3c.dom.Node import java.io.File From 3ff113dbb68150f2bdf12e8a0b1a2d4697dbcab9 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Fri, 1 May 2020 23:50:47 +0700 Subject: [PATCH 11/54] run compilation check on mr to develop --- .github/workflows/compilation-check.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/compilation-check.yml b/.github/workflows/compilation-check.yml index e5955b81..20ea0886 100644 --- a/.github/workflows/compilation-check.yml +++ b/.github/workflows/compilation-check.yml @@ -4,6 +4,7 @@ on: pull_request: branches: - master + - develop jobs: build: From 83d545f464fdb5466c369d3ee1dd43ddc356057e Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Fri, 1 May 2020 23:57:10 +0700 Subject: [PATCH 12/54] fix russian plurals --- sample/mpp-conditional/build.gradle.kts | 4 +++ sample/mpp-hierarhical/build.gradle.kts | 4 +++ sample/mpp-library/build.gradle.kts | 4 +++ .../commonMain/resources/MR/ru/plurals.xml | 30 +++++++++---------- sample/mpp-mixed/build.gradle.kts | 4 +++ 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/sample/mpp-conditional/build.gradle.kts b/sample/mpp-conditional/build.gradle.kts index b383995b..9b1b6580 100644 --- a/sample/mpp-conditional/build.gradle.kts +++ b/sample/mpp-conditional/build.gradle.kts @@ -15,6 +15,10 @@ android { minSdkVersion(Versions.Android.minSdk) targetSdkVersion(Versions.Android.targetSdk) } + + lintOptions { + disable("ImpliedQuantity") + } } kotlin { diff --git a/sample/mpp-hierarhical/build.gradle.kts b/sample/mpp-hierarhical/build.gradle.kts index e6a77b25..f6446be3 100644 --- a/sample/mpp-hierarhical/build.gradle.kts +++ b/sample/mpp-hierarhical/build.gradle.kts @@ -15,6 +15,10 @@ android { minSdkVersion(Versions.Android.minSdk) targetSdkVersion(Versions.Android.targetSdk) } + + lintOptions { + disable("ImpliedQuantity") + } } kotlin { diff --git a/sample/mpp-library/build.gradle.kts b/sample/mpp-library/build.gradle.kts index 4b896cd4..be8de708 100644 --- a/sample/mpp-library/build.gradle.kts +++ b/sample/mpp-library/build.gradle.kts @@ -16,6 +16,10 @@ android { minSdkVersion(Versions.Android.minSdk) targetSdkVersion(Versions.Android.targetSdk) } + + lintOptions { + disable("ImpliedQuantity") + } } setupFramework( diff --git a/sample/mpp-library/src/commonMain/resources/MR/ru/plurals.xml b/sample/mpp-library/src/commonMain/resources/MR/ru/plurals.xml index 7c2b0bca..53f46ae3 100644 --- a/sample/mpp-library/src/commonMain/resources/MR/ru/plurals.xml +++ b/sample/mpp-library/src/commonMain/resources/MR/ru/plurals.xml @@ -2,26 +2,26 @@ ноль - %d - один - %d - два - %d - несколько - %d - много - %d - другое + один + два + несколько + много + другое нет элементов - %d элемент - %d элемента - %d элементов - %d элементов - %d элемента + элемент + элемента + элементов + элементов + элемента нет элементов - %d элемент - %d элемента - %d элементов - %d элементов - %d элемента + элемент + элемента + элементов + элементов + элемента \ No newline at end of file diff --git a/sample/mpp-mixed/build.gradle.kts b/sample/mpp-mixed/build.gradle.kts index f77498e1..e33b83ba 100644 --- a/sample/mpp-mixed/build.gradle.kts +++ b/sample/mpp-mixed/build.gradle.kts @@ -15,6 +15,10 @@ android { minSdkVersion(Versions.Android.minSdk) targetSdkVersion(Versions.Android.targetSdk) } + + lintOptions { + disable("ImpliedQuantity") + } } kotlin { From 226762c79c2cc9fd9d4515348dfe921202ce4689 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Fri, 1 May 2020 23:57:38 +0700 Subject: [PATCH 13/54] #58 add compilation of demo libraries to check different configs --- .github/workflows/compilation-check.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/compilation-check.yml b/.github/workflows/compilation-check.yml index 20ea0886..ae4d9dc8 100644 --- a/.github/workflows/compilation-check.yml +++ b/.github/workflows/compilation-check.yml @@ -20,3 +20,5 @@ jobs: run: ./gradlew -PlibraryPublish :gradle-plugin:detekt :gradle-plugin:publishPluginPublicationToMavenLocal - name: Check library build run: ./gradlew -PlibraryPublish :resources:publishToMavenLocal + - name: Check demo library + run: ./gradlew :mpp-conditional:build :mpp-hierarhical:build :mpp-library:build :mpp-mixed:build From 81e9db6b73e9676654042b741a76d6ea1b62dc7c Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sat, 2 May 2020 00:00:40 +0700 Subject: [PATCH 14/54] revert invalid plurals changes --- .../commonMain/resources/MR/es/plurals.xml | 20 +++++++++---------- .../commonMain/resources/MR/ru/plurals.xml | 20 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/sample/mpp-library/src/commonMain/resources/MR/es/plurals.xml b/sample/mpp-library/src/commonMain/resources/MR/es/plurals.xml index 79c292ee..ee8f7c8e 100644 --- a/sample/mpp-library/src/commonMain/resources/MR/es/plurals.xml +++ b/sample/mpp-library/src/commonMain/resources/MR/es/plurals.xml @@ -10,18 +10,18 @@ cero - uno - dos - algo - mucho - otro + %d uno + %d dos + %d algo + %d mucho + %d otro cero - uno - dos - algo - mucho - otro + %d uno + %d dos + %d algo + %d mucho + %d otro \ No newline at end of file diff --git a/sample/mpp-library/src/commonMain/resources/MR/ru/plurals.xml b/sample/mpp-library/src/commonMain/resources/MR/ru/plurals.xml index 53f46ae3..a05e3340 100644 --- a/sample/mpp-library/src/commonMain/resources/MR/ru/plurals.xml +++ b/sample/mpp-library/src/commonMain/resources/MR/ru/plurals.xml @@ -10,18 +10,18 @@ нет элементов - элемент - элемента - элементов - элементов - элемента + %d элемент + %d элемента + %d элементов + %d элементов + %d элемента нет элементов - элемент - элемента - элементов - элементов - элемента + %d элемент + %d элемента + %d элементов + %d элементов + %d элемента \ No newline at end of file From db69658d29772de437d0958fb8887710eb0ec42c Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sat, 2 May 2020 00:11:02 +0700 Subject: [PATCH 15/54] fix ci action --- .github/workflows/compilation-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/compilation-check.yml b/.github/workflows/compilation-check.yml index ae4d9dc8..c19b8f4a 100644 --- a/.github/workflows/compilation-check.yml +++ b/.github/workflows/compilation-check.yml @@ -21,4 +21,4 @@ jobs: - name: Check library build run: ./gradlew -PlibraryPublish :resources:publishToMavenLocal - name: Check demo library - run: ./gradlew :mpp-conditional:build :mpp-hierarhical:build :mpp-library:build :mpp-mixed:build + run: ./gradlew :sample:mpp-conditional:build :sample:mpp-hierarhical:build :sample:mpp-library:build :sample:mpp-mixed:build From 7f99e7209dfc7b6c80a17fdad6b8d78aeb0875db Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sat, 2 May 2020 00:23:15 +0700 Subject: [PATCH 16/54] fix k/n compilation bug --- gradle.properties | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 63dd12cb..8faa9fe2 100755 --- a/gradle.properties +++ b/gradle.properties @@ -5,4 +5,6 @@ org.gradle.parallel=true kotlin.code.style=official android.useAndroidX=true -android.enableJetifier=true \ No newline at end of file +android.enableJetifier=true + +kotlin.native.enableParallelExecutionCheck=false \ No newline at end of file From 1db7895f84d6ac0bbfcd7ccac63303ba2f81ea2d Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sat, 2 May 2020 01:48:23 +0700 Subject: [PATCH 17/54] #48 klib resources pack and framework repack --- .../gradle/generator/IosMRGenerator.kt | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt index f4bb1c5f..dc6b3c78 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt @@ -11,10 +11,13 @@ import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.TypeSpec import org.gradle.api.Project import org.gradle.api.Task +import org.gradle.kotlin.dsl.support.unzipTo 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.tasks.KotlinNativeCompile +import org.jetbrains.kotlin.konan.file.zipDirAs +import org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl import org.w3c.dom.Document import org.w3c.dom.Node import java.io.File @@ -62,9 +65,35 @@ class IosMRGenerator( ) override fun apply(generationTask: Task, project: Project) { + setupKLibResources(generationTask) + setupFrameworkResources() + } + + private fun setupKLibResources(generationTask: Task) { val compileTask: KotlinNativeCompile = compilation.compileKotlinTask compileTask.dependsOn(generationTask) + compileTask.doLast { + this as KotlinNativeCompile + + val klibFile = this.outputFile.get() + val repackDir = File(klibFile.parent, klibFile.nameWithoutExtension) + val resRepackDir = File(repackDir, "resources") + + unzipTo(zipFile = klibFile, outputDirectory = repackDir) + + resourcesGenerationDir.copyRecursively(resRepackDir, overwrite = true) + + val repackKonan = org.jetbrains.kotlin.konan.file.File(repackDir.path) + val klibKonan = org.jetbrains.kotlin.konan.file.File(klibFile.path) + + repackKonan.zipDirAs(klibKonan) + + repackDir.deleteRecursively() + } + } + + private fun setupFrameworkResources() { val kotlinNativeTarget = compilation.target as KotlinNativeTarget val frameworkBinaries: List = kotlinNativeTarget.binaries @@ -75,7 +104,16 @@ class IosMRGenerator( val linkTask = framework.linkTask linkTask.doLast { - resourcesGenerationDir.copyRecursively(framework.outputFile, overwrite = true) + linkTask.libraries + .plus(linkTask.intermediateLibrary.get()) + .filter { it.extension == "klib" } + .forEach { + project.logger.warn("copy resources from $it") + val klibKonan = org.jetbrains.kotlin.konan.file.File(it.path) + val klib = KotlinLibraryLayoutImpl(klibKonan) + val layout = klib.extractingToTemp + File(layout.resourcesDir.path).copyRecursively(framework.outputFile, overwrite = true) + } processInfoPlist(framework) } From 385b43c1a138e0c16c8fb5053609447a5ca5adbe Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sat, 2 May 2020 01:48:44 +0700 Subject: [PATCH 18/54] #48 add nested module sample for tests --- sample/mpp-library/build.gradle.kts | 2 ++ .../nested-module/build.gradle.kts | 28 +++++++++++++++++++ .../src/androidMain/AndroidManifest.xml | 2 ++ .../com/icerockdev/library/nested/Testing.kt | 12 ++++++++ .../commonMain/resources/MR/base/strings.xml | 4 +++ settings.gradle.kts | 2 +- 6 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 sample/mpp-library/nested-module/build.gradle.kts create mode 100755 sample/mpp-library/nested-module/src/androidMain/AndroidManifest.xml create mode 100644 sample/mpp-library/nested-module/src/commonMain/kotlin/com/icerockdev/library/nested/Testing.kt create mode 100644 sample/mpp-library/nested-module/src/commonMain/resources/MR/base/strings.xml diff --git a/sample/mpp-library/build.gradle.kts b/sample/mpp-library/build.gradle.kts index be8de708..f0665eb1 100644 --- a/sample/mpp-library/build.gradle.kts +++ b/sample/mpp-library/build.gradle.kts @@ -31,6 +31,8 @@ setupFramework( dependencies { mppLibrary(Deps.Libs.MultiPlatform.kotlinStdLib) mppLibrary(Deps.Libs.MultiPlatform.mokoResources) + + commonMainImplementation(project("$path:nested-module")) } multiplatformResources { diff --git a/sample/mpp-library/nested-module/build.gradle.kts b/sample/mpp-library/nested-module/build.gradle.kts new file mode 100644 index 00000000..c15de7a0 --- /dev/null +++ b/sample/mpp-library/nested-module/build.gradle.kts @@ -0,0 +1,28 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +plugins { + id("com.android.library") + id("org.jetbrains.kotlin.multiplatform") + id("dev.icerock.mobile.multiplatform") + id("dev.icerock.mobile.multiplatform-resources") +} + +android { + compileSdkVersion(Versions.Android.compileSdk) + + defaultConfig { + minSdkVersion(Versions.Android.minSdk) + targetSdkVersion(Versions.Android.targetSdk) + } +} + +dependencies { + mppLibrary(Deps.Libs.MultiPlatform.kotlinStdLib) + mppLibrary(Deps.Libs.MultiPlatform.mokoResources) +} + +multiplatformResources { + multiplatformResourcesPackage = "com.icerockdev.library.nested" +} diff --git a/sample/mpp-library/nested-module/src/androidMain/AndroidManifest.xml b/sample/mpp-library/nested-module/src/androidMain/AndroidManifest.xml new file mode 100755 index 00000000..c81d314e --- /dev/null +++ b/sample/mpp-library/nested-module/src/androidMain/AndroidManifest.xml @@ -0,0 +1,2 @@ + + diff --git a/sample/mpp-library/nested-module/src/commonMain/kotlin/com/icerockdev/library/nested/Testing.kt b/sample/mpp-library/nested-module/src/commonMain/kotlin/com/icerockdev/library/nested/Testing.kt new file mode 100644 index 00000000..7a1a5288 --- /dev/null +++ b/sample/mpp-library/nested-module/src/commonMain/kotlin/com/icerockdev/library/nested/Testing.kt @@ -0,0 +1,12 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.icerockdev.library.nested + +import dev.icerock.moko.resources.desc.StringDesc +import dev.icerock.moko.resources.desc.desc + +fun nestedTest(): StringDesc { + return MR.strings.nested_test.desc() +} diff --git a/sample/mpp-library/nested-module/src/commonMain/resources/MR/base/strings.xml b/sample/mpp-library/nested-module/src/commonMain/resources/MR/base/strings.xml new file mode 100644 index 00000000..446f0c96 --- /dev/null +++ b/sample/mpp-library/nested-module/src/commonMain/resources/MR/base/strings.xml @@ -0,0 +1,4 @@ + + + nested test + \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 9ded2b90..c9a2e834 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -32,7 +32,7 @@ include(":resources") include(":gradle-plugin") if(!libraryPublish) { include(":sample:android-app") - include(":sample:mpp-library") + include(":sample:mpp-library", ":sample:mpp-library:nested-module") include(":sample:mpp-conditional") include(":sample:mpp-hierarhical") include(":sample:mpp-mixed") From 0317c77c10ada4810c151d331b38c00700db1bb3 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sat, 2 May 2020 01:50:21 +0700 Subject: [PATCH 19/54] #48 important todo --- .../main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt index dc6b3c78..34c592d4 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt @@ -112,6 +112,9 @@ class IosMRGenerator( val klibKonan = org.jetbrains.kotlin.konan.file.File(it.path) val klib = KotlinLibraryLayoutImpl(klibKonan) val layout = klib.extractingToTemp + + // TODO merge each resource types + File(layout.resourcesDir.path).copyRecursively(framework.outputFile, overwrite = true) } From f6cb27a2b93d3ccfb87c345e5ffdc5b2d15a4a71 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 3 May 2020 00:59:04 +0700 Subject: [PATCH 20/54] #48 pack ios resources to loadable bundle --- .../gradle/MultiplatformResourcesPlugin.kt | 13 +- .../gradle/generator/IosMRGenerator.kt | 126 ++++++++++++------ .../icerock/gradle/generator/MRGenerator.kt | 2 +- .../generator/fonts/IosFontsGenerator.kt | 6 +- .../generator/strings/IosStringsGenerator.kt | 14 +- .../icerock/moko/resources/desc/StringDesc.kt | 5 +- .../icerock/moko/resources/desc/StringDesc.kt | 4 +- .../icerock/moko/resources/FontResource.kt | 8 +- .../icerock/moko/resources/desc/StringDesc.kt | 41 +++--- .../commonMain/resources/MR/ru/strings.xml | 4 + .../kotlin/com/icerockdev/library/Testing.kt | 6 +- 11 files changed, 134 insertions(+), 95 deletions(-) create mode 100644 sample/mpp-library/nested-module/src/commonMain/resources/MR/ru/strings.xml diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 1c4f5cf5..9f30b489 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -79,9 +79,10 @@ class MultiplatformResourcesPlugin : Plugin { mrExtension.multiplatformResourcesPackage!!, androidPackage ) + val iosLocalizationRegion = mrExtension.iosBaseLocalizationRegion val features = listOf( - StringsGeneratorFeature(sourceInfo, mrExtension.iosBaseLocalizationRegion), - PluralsGeneratorFeature(sourceInfo, mrExtension.iosBaseLocalizationRegion), + StringsGeneratorFeature(sourceInfo, iosLocalizationRegion), + PluralsGeneratorFeature(sourceInfo, iosLocalizationRegion), ImagesGeneratorFeature(sourceInfo), FontsGeneratorFeature(sourceInfo) ) @@ -89,7 +90,7 @@ class MultiplatformResourcesPlugin : Plugin { setupCommonGenerator(commonSourceSet, generatedDir, mrClassPackage, features, target) setupAndroidGenerator(targets, androidMainSourceSet, generatedDir, mrClassPackage, features, target) - setupIosGenerator(targets, generatedDir, mrClassPackage, features, target) + setupIosGenerator(targets, generatedDir, mrClassPackage, features, target, iosLocalizationRegion) } private fun setupCommonGenerator( @@ -137,7 +138,8 @@ class MultiplatformResourcesPlugin : Plugin { generatedDir: File, mrClassPackage: String, features: List, - target: Project + target: Project, + iosLocalizationRegion: String ) { val compilations = targets .filterIsInstance() @@ -158,7 +160,8 @@ class MultiplatformResourcesPlugin : Plugin { sourceSet, mrClassPackage, generators = features.map { it.createIosGenerator() }, - compilation = compilation + compilation = compilation, + baseLocalizationRegion = iosLocalizationRegion ).apply(target) } } diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt index 34c592d4..0c316dae 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt @@ -18,22 +18,16 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile import org.jetbrains.kotlin.konan.file.zipDirAs import org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl -import org.w3c.dom.Document -import org.w3c.dom.Node import java.io.File -import java.io.FileWriter -import javax.xml.parsers.DocumentBuilderFactory -import javax.xml.transform.OutputKeys -import javax.xml.transform.TransformerFactory -import javax.xml.transform.dom.DOMSource -import javax.xml.transform.stream.StreamResult +import java.util.Properties class IosMRGenerator( generatedDir: File, sourceSet: SourceSet, mrClassPackage: String, private val generators: List, - private val compilation: AbstractKotlinNativeCompilation + private val compilation: AbstractKotlinNativeCompilation, + private val baseLocalizationRegion: String ) : MRGenerator( generatedDir = generatedDir, sourceSet = sourceSet, @@ -42,6 +36,7 @@ class IosMRGenerator( ) { private val bundleClassName = ClassName("platform.Foundation", "NSBundle") + private val bundleIdentifier = "$mrClassPackage.MR" override fun getMRClassModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -54,14 +49,34 @@ class IosMRGenerator( bundleClassName, KModifier.PRIVATE ) - .initializer(CodeBlock.of("NSBundle.bundleForClass(object_getClass(this)!!)")) + .delegate( + CodeBlock.of( + """ +lazy { + val result = NSBundle.bundleWithIdentifier("$bundleIdentifier") + if (result != null) return@lazy result + + val mainPath = NSBundle.mainBundle.bundlePath + val appFrameworks = NSBundle.allFrameworks.filterIsInstance() + .filter { it.bundlePath.startsWith(mainPath) } + appFrameworks.flatMap { frameworkBundle -> + @Suppress("UNCHECKED_CAST") + frameworkBundle.pathsForResourcesOfType(ext = "bundle", inDirectory = null) as List + }.forEach { bundlePath -> + NSBundle.bundleWithPath(bundlePath)?.bundleIdentifier + } + + return@lazy NSBundle.bundleWithIdentifier("$bundleIdentifier")!! +} + """.trimIndent() + ) + ) .build() ) } override fun getImports(): List = listOf( - bundleClassName, - ClassName("platform.objc", "object_getClass") + bundleClassName ) override fun apply(generationTask: Task, project: Project) { @@ -82,7 +97,40 @@ class IosMRGenerator( unzipTo(zipFile = klibFile, outputDirectory = repackDir) - resourcesGenerationDir.copyRecursively(resRepackDir, overwrite = true) + val manifestFile = File(repackDir, "manifest") + val manifest = Properties() + manifest.load(manifestFile.inputStream()) + + val uniqueName = manifest["unique_name"] as String + + val bundleDir = File(resRepackDir, "$uniqueName.bundle") + bundleDir.mkdir() + + val bundleContentsDir = File(bundleDir, "Contents") + bundleContentsDir.mkdir() + + val bundlePList = File(bundleContentsDir, "Info.plist") + bundlePList.writeText( + """ + + + + CFBundleDevelopmentRegion + $baseLocalizationRegion + CFBundleIdentifier + $bundleIdentifier + CFBundleVersion + 1 + CFBundlePackageType + BNDL + +""" + ) + + val bundleResourcesDir = File(bundleContentsDir, "Resources") + bundleResourcesDir.mkdir() + + resourcesGenerationDir.copyRecursively(bundleResourcesDir, overwrite = true) val repackKonan = org.jetbrains.kotlin.konan.file.File(repackDir.path) val klibKonan = org.jetbrains.kotlin.konan.file.File(klibFile.path) @@ -113,45 +161,35 @@ class IosMRGenerator( val klib = KotlinLibraryLayoutImpl(klibKonan) val layout = klib.extractingToTemp - // TODO merge each resource types - File(layout.resourcesDir.path).copyRecursively(framework.outputFile, overwrite = true) } - - processInfoPlist(framework) +// +// processInfoPlist(framework) } } } - private fun processInfoPlist(framework: Framework) { - val infoPList = File(framework.outputFile, "Info.plist") - - val dbFactory = DocumentBuilderFactory.newInstance() - dbFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false) - val dBuilder = dbFactory.newDocumentBuilder() - val doc = dBuilder.parse(infoPList) - - val rootDict = doc.getElementsByTagName("dict").item(0) - - generators - .mapNotNull { it as? ExtendsPlistDictionary } - .forEach { it.appendPlistInfo(doc, rootDict) } - - val transformerFactory = TransformerFactory.newInstance() - val transformer = transformerFactory.newTransformer() - transformer.setOutputProperty(OutputKeys.INDENT, "yes") - - val writer = FileWriter(infoPList) - val result = StreamResult(writer) - - transformer.transform(DOMSource(doc), result) - } +// private fun processInfoPlist(framework: Framework) { +// val infoPList = File(framework.outputFile, "Info.plist") +// +// val dbFactory = DocumentBuilderFactory.newInstance() +// dbFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false) +// val dBuilder = dbFactory.newDocumentBuilder() +// val doc = dBuilder.parse(infoPList) +// +// val rootDict = doc.getElementsByTagName("dict").item(0) +// +// val transformerFactory = TransformerFactory.newInstance() +// val transformer = transformerFactory.newTransformer() +// transformer.setOutputProperty(OutputKeys.INDENT, "yes") +// +// val writer = FileWriter(infoPList) +// val result = StreamResult(writer) +// +// transformer.transform(DOMSource(doc), result) +// } companion object { const val BUNDLE_PROPERTY_NAME = "bundle" } } - -interface ExtendsPlistDictionary { - fun appendPlistInfo(doc: Document, rootDict: Node) -} diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt index 4472db50..1c1eb26b 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt @@ -15,7 +15,7 @@ import java.io.File abstract class MRGenerator( generatedDir: File, protected val sourceSet: SourceSet, - private val mrClassPackage: String, + protected val mrClassPackage: String, private val generators: List ) { private val sourcesGenerationDir = File(generatedDir, "${sourceSet.name}/src") diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/IosFontsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/IosFontsGenerator.kt index 5a3e9add..42968c90 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/IosFontsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/IosFontsGenerator.kt @@ -6,6 +6,7 @@ package dev.icerock.gradle.generator.fonts import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier +import dev.icerock.gradle.generator.IosMRGenerator import org.gradle.api.file.FileTree import java.io.File @@ -19,7 +20,10 @@ class IosFontsGenerator( override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) override fun getPropertyInitializer(fontFileName: String): CodeBlock? { - return CodeBlock.of("FontResource(fontName = %S)", fontFileName) + return CodeBlock.of( + "FontResource(fontName = %S, bundle = ${IosMRGenerator.BUNDLE_PROPERTY_NAME})", + fontFileName + ) } override fun generateResources( diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/IosStringsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/IosStringsGenerator.kt index 7c8a279d..cb3a1242 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/IosStringsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/IosStringsGenerator.kt @@ -6,11 +6,8 @@ package dev.icerock.gradle.generator.strings import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.ExtendsPlistDictionary import dev.icerock.gradle.generator.IosMRGenerator.Companion.BUNDLE_PROPERTY_NAME import org.gradle.api.file.FileTree -import org.w3c.dom.Document -import org.w3c.dom.Node import java.io.File class IosStringsGenerator( @@ -18,7 +15,7 @@ class IosStringsGenerator( private val baseLocalizationRegion: String ) : StringsGenerator( stringsFileTree = stringsFileTree -), ExtendsPlistDictionary { +) { override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) @@ -53,13 +50,4 @@ class IosStringsGenerator( regionFile.writeText(content) } } - - override fun appendPlistInfo(doc: Document, rootDict: Node) { - rootDict.appendChild(doc.createElement("key").apply { - textContent = "CFBundleDevelopmentRegion" - }) - rootDict.appendChild(doc.createElement("string").apply { - textContent = baseLocalizationRegion - }) - } } diff --git a/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/StringDesc.kt b/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/StringDesc.kt index 890e5aaf..24d21a87 100644 --- a/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/StringDesc.kt +++ b/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/StringDesc.kt @@ -97,8 +97,7 @@ actual sealed class StringDesc { abstract fun toString(context: Context): String actual sealed class LocaleType { - actual class System actual constructor() : - LocaleType() { + actual object System : LocaleType() { override val systemLocale: Locale? = null } @@ -131,6 +130,6 @@ actual sealed class StringDesc { return localizedContext(context).resources } - actual var localeType: LocaleType = LocaleType.System() + actual var localeType: LocaleType = LocaleType.System } } diff --git a/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/StringDesc.kt b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/StringDesc.kt index d9034100..a6375d9a 100644 --- a/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/StringDesc.kt +++ b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/StringDesc.kt @@ -22,7 +22,7 @@ expect sealed class StringDesc { class Composition(args: List, separator: String? = null) : StringDesc sealed class LocaleType { - class System() : LocaleType + object System : LocaleType class Custom(locale: String) : LocaleType } @@ -37,4 +37,4 @@ fun PluralsResource.desc(number: Int) = StringDesc.Plural(this, number) operator fun StringDesc.plus(other: StringDesc): StringDesc { return StringDesc.Composition(listOf(this, other)) -} \ No newline at end of file +} 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 350250c6..2c5625be 100644 --- a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/FontResource.kt +++ b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/FontResource.kt @@ -19,11 +19,13 @@ import platform.UIKit.UIFont import platform.darwin.UInt8Var import platform.objc.object_getClass -actual class FontResource(fontName: String) { +actual class FontResource( + fontName: String, + bundle: NSBundle = NSBundle.mainBundle +) { private val fontRef: CGFontRef init { - val bundle = NSBundle.bundleForClass(object_getClass(this)!!) val pathForResourceString = bundle.pathForResource(name = "$fontName.ttf", ofType = null)!! val fontData = NSData.create(contentsOfFile = pathForResourceString)!! val cfDataRef = CFDataCreate( @@ -39,4 +41,4 @@ actual class FontResource(fontName: String) { val ctFont = CTFontCreateWithGraphicsFont(fontRef, withSize, null, null) return CFBridgingRelease(ctFont) as UIFont } -} \ No newline at end of file +} diff --git a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/StringDesc.kt b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/StringDesc.kt index 34371845..e27efa0d 100644 --- a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/StringDesc.kt +++ b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/StringDesc.kt @@ -10,7 +10,6 @@ import dev.icerock.moko.resources.objc.pluralizedString import platform.Foundation.NSBundle import platform.Foundation.NSString import platform.Foundation.stringWithFormat -import platform.objc.object_getClass actual sealed class StringDesc { protected fun processArgs(args: List): Array { @@ -18,11 +17,11 @@ actual sealed class StringDesc { } protected fun localizedString(stringRes: StringResource): String { - var string = localeType.bundle.localizedStringForKey(stringRes.resourceId, null, null) - if (string == stringRes.resourceId) { - string = mainBundle.localizedStringForKey(stringRes.resourceId, null, null) - } - return string + val bundle = 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 } actual data class Resource actual constructor(val stringRes: StringResource) : StringDesc() { @@ -50,8 +49,8 @@ actual sealed class StringDesc { override fun localized(): String { return pluralizedString( - bundle = localeType.bundle, - baseBundle = mainBundle, + bundle = localeType.getLocaleBundle(pluralsRes.bundle), + baseBundle = pluralsRes.bundle, resourceId = pluralsRes.resourceId, number = number )!! @@ -72,8 +71,8 @@ actual sealed class StringDesc { override fun localized(): String { val pluralized = pluralizedString( - bundle = localeType.bundle, - baseBundle = mainBundle, + bundle = localeType.getLocaleBundle(pluralsRes.bundle), + baseBundle = pluralsRes.bundle, resourceId = pluralsRes.resourceId, number = number )!! @@ -157,25 +156,25 @@ actual sealed class StringDesc { } actual sealed class LocaleType { - actual class System actual constructor() : LocaleType() { - override val bundle: NSBundle = NSBundle.bundleForClass(object_getClass(this)!!) + actual object System : LocaleType() { + override fun getLocaleBundle(rootBundle: NSBundle): NSBundle { + return rootBundle + } } - actual class Custom actual constructor(locale: String) : LocaleType() { - override val bundle: NSBundle by lazy { - val currentBundle = NSBundle.bundleForClass(object_getClass(this)!!) - val bundlePath = currentBundle.pathForResource(locale, "lproj") - ?: return@lazy currentBundle - NSBundle(bundlePath) + actual class Custom actual constructor(private val locale: String) : LocaleType() { + override fun getLocaleBundle(rootBundle: NSBundle): NSBundle { + return rootBundle.pathForResource(locale, "lproj") + ?.let { NSBundle.bundleWithPath(it) } + ?: rootBundle } } - abstract val bundle: NSBundle + abstract fun getLocaleBundle(rootBundle: NSBundle): NSBundle } @ThreadLocal actual companion object { - actual var localeType: LocaleType = LocaleType.System() - val mainBundle = LocaleType.System().bundle + actual var localeType: LocaleType = LocaleType.System } } diff --git a/sample/mpp-library/nested-module/src/commonMain/resources/MR/ru/strings.xml b/sample/mpp-library/nested-module/src/commonMain/resources/MR/ru/strings.xml new file mode 100644 index 00000000..a77f7ec2 --- /dev/null +++ b/sample/mpp-library/nested-module/src/commonMain/resources/MR/ru/strings.xml @@ -0,0 +1,4 @@ + + + тест вложенный + \ No newline at end of file diff --git a/sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library/Testing.kt b/sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library/Testing.kt index ad907a6a..c3463f8b 100644 --- a/sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library/Testing.kt +++ b/sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library/Testing.kt @@ -8,6 +8,7 @@ import dev.icerock.moko.resources.ImageResource import dev.icerock.moko.resources.desc.StringDesc import dev.icerock.moko.resources.desc.desc import dev.icerock.moko.resources.desc.plus +import com.icerockdev.library.nested.nestedTest object Testing { fun getStrings(): List { @@ -20,7 +21,8 @@ object Testing { MR.plurals.test_plural.desc(0), MR.plurals.test_plural.desc(1), MR.plurals.test_plural.desc(2), - MR.plurals.test_plural.desc(3) + MR.plurals.test_plural.desc(3), + nestedTest() ) } @@ -80,6 +82,6 @@ object Testing { fun locale(lang: String?) { StringDesc.localeType = if (lang != null) StringDesc.LocaleType.Custom(lang) - else StringDesc.LocaleType.System() + else StringDesc.LocaleType.System } } From 0558bc27f9a0065686c078f78d501bc7200bbd0c Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 3 May 2020 01:02:46 +0700 Subject: [PATCH 21/54] #48 remove unused code --- .../gradle/generator/IosMRGenerator.kt | 28 ++----------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt index 0c316dae..f6e2ddec 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt @@ -25,7 +25,7 @@ class IosMRGenerator( generatedDir: File, sourceSet: SourceSet, mrClassPackage: String, - private val generators: List, + generators: List, private val compilation: AbstractKotlinNativeCompilation, private val baseLocalizationRegion: String ) : MRGenerator( @@ -51,7 +51,7 @@ class IosMRGenerator( ) .delegate( CodeBlock.of( - """ + """ lazy { val result = NSBundle.bundleWithIdentifier("$bundleIdentifier") if (result != null) return@lazy result @@ -69,7 +69,7 @@ lazy { return@lazy NSBundle.bundleWithIdentifier("$bundleIdentifier")!! } """.trimIndent() - ) + ) ) .build() ) @@ -163,32 +163,10 @@ lazy { File(layout.resourcesDir.path).copyRecursively(framework.outputFile, overwrite = true) } -// -// processInfoPlist(framework) } } } -// private fun processInfoPlist(framework: Framework) { -// val infoPList = File(framework.outputFile, "Info.plist") -// -// val dbFactory = DocumentBuilderFactory.newInstance() -// dbFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false) -// val dBuilder = dbFactory.newDocumentBuilder() -// val doc = dBuilder.parse(infoPList) -// -// val rootDict = doc.getElementsByTagName("dict").item(0) -// -// val transformerFactory = TransformerFactory.newInstance() -// val transformer = transformerFactory.newTransformer() -// transformer.setOutputProperty(OutputKeys.INDENT, "yes") -// -// val writer = FileWriter(infoPList) -// val result = StreamResult(writer) -// -// transformer.transform(DOMSource(doc), result) -// } - companion object { const val BUNDLE_PROPERTY_NAME = "bundle" } From c8cf31c8b14460efe32f15b0981803af4434d899 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 3 May 2020 01:03:07 +0700 Subject: [PATCH 22/54] #48 info logging of klib resources copy --- .../main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt index f6e2ddec..fd55b127 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt @@ -156,7 +156,7 @@ lazy { .plus(linkTask.intermediateLibrary.get()) .filter { it.extension == "klib" } .forEach { - project.logger.warn("copy resources from $it") + project.logger.info("copy resources from $it") val klibKonan = org.jetbrains.kotlin.konan.file.File(it.path) val klib = KotlinLibraryLayoutImpl(klibKonan) val layout = klib.extractingToTemp From 7413fae69bf297fd00412dd129c572bdd8c46d05 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 3 May 2020 01:11:38 +0700 Subject: [PATCH 23/54] #48 fix generation tasks dependencies --- .../icerock/gradle/MultiplatformResourcesPlugin.kt | 7 +++++++ .../icerock/gradle/generator/CommonMRGenerator.kt | 9 +-------- .../generator/GenerateMultiplatformResourcesTask.kt | 13 +++++++++++++ .../dev/icerock/gradle/generator/MRGenerator.kt | 4 +--- 4 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/GenerateMultiplatformResourcesTask.kt diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index 9f30b489..af22267c 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -9,6 +9,7 @@ import com.android.build.gradle.LibraryPlugin import com.android.build.gradle.api.AndroidSourceSet import dev.icerock.gradle.generator.AndroidMRGenerator import dev.icerock.gradle.generator.CommonMRGenerator +import dev.icerock.gradle.generator.GenerateMultiplatformResourcesTask import dev.icerock.gradle.generator.IosMRGenerator import dev.icerock.gradle.generator.MRGenerator import dev.icerock.gradle.generator.ResourceGeneratorFeature @@ -91,6 +92,11 @@ class MultiplatformResourcesPlugin : Plugin { setupCommonGenerator(commonSourceSet, generatedDir, mrClassPackage, features, target) setupAndroidGenerator(targets, androidMainSourceSet, generatedDir, mrClassPackage, features, target) setupIosGenerator(targets, generatedDir, mrClassPackage, features, target, iosLocalizationRegion) + + val generationTasks = target.tasks.filterIsInstance() + val commonGenerationTask = generationTasks.first { it.name == "generateMRcommonMain" } + generationTasks.filter { it != commonGenerationTask } + .forEach { it.dependsOn(commonGenerationTask) } } private fun setupCommonGenerator( @@ -133,6 +139,7 @@ class MultiplatformResourcesPlugin : Plugin { ).apply(target) } + @Suppress("LongParameterList") private fun setupIosGenerator( targets: List, generatedDir: File, diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/CommonMRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/CommonMRGenerator.kt index 1c8391a9..49bfab8f 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/CommonMRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/CommonMRGenerator.kt @@ -7,7 +7,6 @@ package dev.icerock.gradle.generator import com.squareup.kotlinpoet.KModifier import org.gradle.api.Project import org.gradle.api.Task -import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink import java.io.File class CommonMRGenerator( @@ -23,11 +22,5 @@ class CommonMRGenerator( ) { override fun getMRClassModifiers(): Array = arrayOf(KModifier.EXPECT) - override fun apply(generationTask: Task, project: Project) { - project.tasks.getByName("preBuild").dependsOn(generationTask) - - project.tasks - .mapNotNull { it as? KotlinNativeLink } - .forEach { it.compilation.compileKotlinTask.dependsOn(generationTask) } - } + override fun apply(generationTask: Task, project: Project) {} } diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/GenerateMultiplatformResourcesTask.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/GenerateMultiplatformResourcesTask.kt new file mode 100644 index 00000000..c231c44f --- /dev/null +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/GenerateMultiplatformResourcesTask.kt @@ -0,0 +1,13 @@ +/* + * Copyright 2020 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.DefaultTask + +open class GenerateMultiplatformResourcesTask : DefaultTask() { + init { + group = "multiplatform" + } +} diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt index 1c1eb26b..f08173e0 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/MRGenerator.kt @@ -60,9 +60,7 @@ abstract class MRGenerator( val genTaskName = "generateMR$name" val genTask = runCatching { project.tasks.getByName(genTaskName) - }.getOrNull() ?: project.task(genTaskName) { - group = "multiplatform" - + }.getOrNull() ?: project.tasks.create(genTaskName, GenerateMultiplatformResourcesTask::class.java) { doLast { this@MRGenerator.generate() } From 6c02b63779ab99d53f4f0fbcd4aaef37ce97e522 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 3 May 2020 01:12:48 +0700 Subject: [PATCH 24/54] #48 fix detekt issue --- .../kotlin/dev/icerock/gradle/generator/CommonMRGenerator.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/CommonMRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/CommonMRGenerator.kt index 49bfab8f..97db6151 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/CommonMRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/CommonMRGenerator.kt @@ -22,5 +22,6 @@ class CommonMRGenerator( ) { override fun getMRClassModifiers(): Array = arrayOf(KModifier.EXPECT) + @Suppress("EmptyFunctionBlock") override fun apply(generationTask: Task, project: Project) {} } From 2fb5395c6d887ef03a6fe42e3dd6de6da8186286 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 3 May 2020 11:44:34 +0700 Subject: [PATCH 25/54] #48 update ui test --- .../androidTest/java/com/icerockdev/StringResourcesTestEn.kt | 2 +- .../androidTest/java/com/icerockdev/StringResourcesTestRu.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sample/android-app/src/androidTest/java/com/icerockdev/StringResourcesTestEn.kt b/sample/android-app/src/androidTest/java/com/icerockdev/StringResourcesTestEn.kt index 2a1d80bb..1d8b0e59 100644 --- a/sample/android-app/src/androidTest/java/com/icerockdev/StringResourcesTestEn.kt +++ b/sample/android-app/src/androidTest/java/com/icerockdev/StringResourcesTestEn.kt @@ -15,7 +15,7 @@ class StringResourcesTestEn : StringResourcesTest() { override val locale: String = "en" override val stringAndPluralsCheck: String - get() = "test\ntest 2\ntest 3\nTest Project\nsome raw string\nother\none\nother\nother" + get() = "test\ntest 2\ntest 3\nTest Project\nsome raw string\nother\none\nother\nother\nnested test" override val stringDescsCheck: String get() = "test\ntest\nTest data 9\nother\nother\n10 items\nraw string\nraw string" + diff --git a/sample/android-app/src/androidTest/java/com/icerockdev/StringResourcesTestRu.kt b/sample/android-app/src/androidTest/java/com/icerockdev/StringResourcesTestRu.kt index 6df2b0c5..94485a6d 100644 --- a/sample/android-app/src/androidTest/java/com/icerockdev/StringResourcesTestRu.kt +++ b/sample/android-app/src/androidTest/java/com/icerockdev/StringResourcesTestRu.kt @@ -15,7 +15,7 @@ class StringResourcesTestRu : StringResourcesTest() { override val locale: String = "ru" override val stringAndPluralsCheck: String - get() = "тест\nтест 2\nтест 3\nТестовый проект\nsome raw string\nмного\nодин\nнесколько\nнесколько" + get() = "тест\nтест 2\nтест 3\nТестовый проект\nsome raw string\nмного\nодин\nнесколько\nнесколько\nтест вложенный" override val stringDescsCheck: String get() = "тест\nтест\nТестовые данные 9\nмного\nмного\n10 элементов\nraw string\nraw string\nтестraw string\nВыберите портфель и сумму\nвторая строка str первое число 9" From 2ff81c68d7f6dfd8e9d229ccba1d10a7445fd071 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 3 May 2020 20:45:50 +0700 Subject: [PATCH 26/54] #48 use runtime lib func instead of generation in each MR --- .../gradle/generator/IosMRGenerator.kt | 27 +++---------------- .../dev/icerock/moko/resources/NSBundleExt.kt | 25 +++++++++++++++++ 2 files changed, 29 insertions(+), 23 deletions(-) create mode 100644 resources/src/iosMain/kotlin/dev/icerock/moko/resources/NSBundleExt.kt diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt index fd55b127..5546a9b9 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt @@ -8,6 +8,7 @@ import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.PropertySpec +import com.squareup.kotlinpoet.TypeName import com.squareup.kotlinpoet.TypeSpec import org.gradle.api.Project import org.gradle.api.Task @@ -49,34 +50,14 @@ class IosMRGenerator( bundleClassName, KModifier.PRIVATE ) - .delegate( - CodeBlock.of( - """ -lazy { - val result = NSBundle.bundleWithIdentifier("$bundleIdentifier") - if (result != null) return@lazy result - - val mainPath = NSBundle.mainBundle.bundlePath - val appFrameworks = NSBundle.allFrameworks.filterIsInstance() - .filter { it.bundlePath.startsWith(mainPath) } - appFrameworks.flatMap { frameworkBundle -> - @Suppress("UNCHECKED_CAST") - frameworkBundle.pathsForResourcesOfType(ext = "bundle", inDirectory = null) as List - }.forEach { bundlePath -> - NSBundle.bundleWithPath(bundlePath)?.bundleIdentifier - } - - return@lazy NSBundle.bundleWithIdentifier("$bundleIdentifier")!! -} - """.trimIndent() - ) - ) + .delegate(CodeBlock.of("lazy { NSBundle.loadableBundle(\"$bundleIdentifier\") }")) .build() ) } override fun getImports(): List = listOf( - bundleClassName + bundleClassName, + ClassName(packageName = "dev.icerock.moko.resources", simpleName = "loadableBundle") ) override fun apply(generationTask: Task, project: Project) { diff --git a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/NSBundleExt.kt b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/NSBundleExt.kt new file mode 100644 index 00000000..b16ef56c --- /dev/null +++ b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/NSBundleExt.kt @@ -0,0 +1,25 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.moko.resources + +import platform.Foundation.NSBundle + +fun NSBundle.Companion.loadableBundle(identifier: String): NSBundle { + val result = NSBundle.bundleWithIdentifier(identifier) + if (result != null) return result + + val mainPath = NSBundle.mainBundle.bundlePath + val appFrameworks = NSBundle.allFrameworks.filterIsInstance() + .filter { it.bundlePath.startsWith(mainPath) } + appFrameworks.flatMap { frameworkBundle -> + @Suppress("UNCHECKED_CAST") + frameworkBundle.pathsForResourcesOfType(ext = "bundle", inDirectory = null) as List + }.forEach { bundlePath -> + // load each loadable bundle to correct load by identifier later + NSBundle.bundleWithPath(bundlePath)?.bundleIdentifier + } + + return NSBundle.bundleWithIdentifier(identifier)!! +} From 30b81261f57e180abe18a87a148b822faacdb554 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 3 May 2020 20:54:16 +0700 Subject: [PATCH 27/54] #48 rework packages of gradle plugin --- .../gradle/MultiplatformResourcesPlugin.kt | 22 ++++++------ .../icerock/gradle/generator/BaseGenerator.kt | 2 -- .../{strings => }/EqualStringKeysException.kt | 2 +- .../generator/{fonts => }/FontsGenerator.kt | 32 +++++++++++++++-- .../generator/{image => }/ImagesGenerator.kt | 29 ++++++++++++++-- .../{plurals => }/PluralsGenerator.kt | 34 ++++++++++++++++--- .../{strings => }/StringsGenerator.kt | 32 +++++++++++++++-- .../AndroidFontsGenerator.kt | 3 +- .../AndroidImagesGenerator.kt | 5 +-- .../{ => android}/AndroidMRGenerator.kt | 5 +-- .../AndroidPluralsGenerator.kt | 8 +++-- .../AndroidStringsGenerator.kt | 6 ++-- .../{fonts => common}/CommonFontsGenerator.kt | 3 +- .../CommonImagesGenerator.kt | 5 +-- .../{ => common}/CommonMRGenerator.kt | 5 +-- .../CommonPluralsGenerator.kt | 5 +-- .../CommonStringsGenerator.kt | 5 +-- .../generator/fonts/FontsGeneratorFeature.kt | 27 --------------- .../generator/image/ImagesGeneratorFeature.kt | 27 --------------- .../{fonts => ios}/IosFontsGenerator.kt | 4 +-- .../{image => ios}/IosImagesGenerator.kt | 6 ++-- .../generator/{ => ios}/IosMRGenerator.kt | 6 ++-- .../{plurals => ios}/IosPluralsGenerator.kt | 9 ++--- .../{strings => ios}/IosStringsGenerator.kt | 8 +++-- .../plurals/PluralsGeneratorFeature.kt | 27 --------------- .../strings/StringsGeneratorFeature.kt | 27 --------------- 26 files changed, 174 insertions(+), 170 deletions(-) rename gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/{strings => }/EqualStringKeysException.kt (85%) rename gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/{fonts => }/FontsGenerator.kt (75%) rename gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/{image => }/ImagesGenerator.kt (64%) rename gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/{plurals => }/PluralsGenerator.kt (64%) rename gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/{strings => }/StringsGenerator.kt (62%) rename gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/{fonts => android}/AndroidFontsGenerator.kt (93%) rename gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/{image => android}/AndroidImagesGenerator.kt (92%) rename gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/{ => android}/AndroidMRGenerator.kt (81%) rename gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/{plurals => android}/AndroidPluralsGenerator.kt (90%) rename gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/{strings => android}/AndroidStringsGenerator.kt (90%) rename gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/{fonts => common}/CommonFontsGenerator.kt (85%) rename gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/{image => common}/CommonImagesGenerator.kt (75%) rename gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/{ => common}/CommonMRGenerator.kt (80%) rename gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/{plurals => common}/CommonPluralsGenerator.kt (66%) rename gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/{strings => common}/CommonStringsGenerator.kt (66%) delete mode 100644 gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/FontsGeneratorFeature.kt delete mode 100644 gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/ImagesGeneratorFeature.kt rename gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/{fonts => ios}/IosFontsGenerator.kt (91%) rename gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/{image => ios}/IosImagesGenerator.kt (94%) rename gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/{ => ios}/IosMRGenerator.kt (97%) rename gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/{plurals => ios}/IosPluralsGenerator.kt (91%) rename gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/{strings => ios}/IosStringsGenerator.kt (84%) delete mode 100644 gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/PluralsGeneratorFeature.kt delete mode 100644 gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/StringsGeneratorFeature.kt diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index af22267c..c632f09f 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -7,17 +7,17 @@ package dev.icerock.gradle import com.android.build.gradle.LibraryExtension import com.android.build.gradle.LibraryPlugin import com.android.build.gradle.api.AndroidSourceSet -import dev.icerock.gradle.generator.AndroidMRGenerator -import dev.icerock.gradle.generator.CommonMRGenerator +import dev.icerock.gradle.generator.FontsGenerator import dev.icerock.gradle.generator.GenerateMultiplatformResourcesTask -import dev.icerock.gradle.generator.IosMRGenerator +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.SourceInfo -import dev.icerock.gradle.generator.fonts.FontsGeneratorFeature -import dev.icerock.gradle.generator.image.ImagesGeneratorFeature -import dev.icerock.gradle.generator.plurals.PluralsGeneratorFeature -import dev.icerock.gradle.generator.strings.StringsGeneratorFeature +import dev.icerock.gradle.generator.StringsGenerator +import dev.icerock.gradle.generator.android.AndroidMRGenerator +import dev.icerock.gradle.generator.common.CommonMRGenerator +import dev.icerock.gradle.generator.ios.IosMRGenerator import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.tasks.SourceSet @@ -82,10 +82,10 @@ class MultiplatformResourcesPlugin : Plugin { ) val iosLocalizationRegion = mrExtension.iosBaseLocalizationRegion val features = listOf( - StringsGeneratorFeature(sourceInfo, iosLocalizationRegion), - PluralsGeneratorFeature(sourceInfo, iosLocalizationRegion), - ImagesGeneratorFeature(sourceInfo), - FontsGeneratorFeature(sourceInfo) + StringsGenerator.Feature(sourceInfo, iosLocalizationRegion), + PluralsGenerator.Feature(sourceInfo, iosLocalizationRegion), + ImagesGenerator.Feature(sourceInfo), + FontsGenerator.Feature(sourceInfo) ) val targets: List = multiplatformExtension.targets.toList() diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt index 6dfe29d6..8e74e46c 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/BaseGenerator.kt @@ -9,8 +9,6 @@ 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.strings.KeyType -import dev.icerock.gradle.generator.strings.LanguageType import java.io.File abstract class BaseGenerator : MRGenerator.Generator { diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/EqualStringKeysException.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/EqualStringKeysException.kt similarity index 85% rename from gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/EqualStringKeysException.kt rename to gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/EqualStringKeysException.kt index 56c476da..5357140e 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/EqualStringKeysException.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/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.strings +package dev.icerock.gradle.generator class EqualStringKeysException( val keys: List diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/FontsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt similarity index 75% rename from gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/FontsGenerator.kt rename to gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt index 169369ec..1d0d24d9 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/FontsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt @@ -2,14 +2,16 @@ * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.fonts +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.MRGenerator +import dev.icerock.gradle.generator.android.AndroidFontsGenerator +import dev.icerock.gradle.generator.common.CommonFontsGenerator +import dev.icerock.gradle.generator.ios.IosFontsGenerator import org.gradle.api.file.FileTree import java.io.File @@ -22,7 +24,10 @@ abstract class FontsGenerator( override fun generate(resourcesGenerationDir: File): TypeSpec { val typeSpec = createTypeSpec(inputFileTree.map { it.nameWithoutExtension }.sorted()) generateResources(resourcesGenerationDir, inputFileTree.map { - FontFile(key = it.nameWithoutExtension, file = it) + FontFile( + key = it.nameWithoutExtension, + file = it + ) }) return typeSpec } @@ -98,4 +103,25 @@ abstract class FontsGenerator( val key: String, val file: File ) + + class Feature(private val info: SourceInfo) : ResourceGeneratorFeature { + private val stringsFileTree = info.commonResources.matching { + include("MR/fonts/**.ttf") + } + + override fun createCommonGenerator(): MRGenerator.Generator { + return CommonFontsGenerator(stringsFileTree) + } + + override fun createIosGenerator(): MRGenerator.Generator { + return IosFontsGenerator(stringsFileTree) + } + + override fun createAndroidGenerator(): MRGenerator.Generator { + return AndroidFontsGenerator( + stringsFileTree, + info.androidRClassPackage + ) + } + } } diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/ImagesGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt similarity index 64% rename from gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/ImagesGenerator.kt rename to gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt index 3cf6b200..367a8512 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/ImagesGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt @@ -1,15 +1,17 @@ /* - * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2020 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 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.MRGenerator +import dev.icerock.gradle.generator.android.AndroidImagesGenerator +import dev.icerock.gradle.generator.common.CommonImagesGenerator +import dev.icerock.gradle.generator.ios.IosImagesGenerator import org.gradle.api.file.FileTree import java.io.File @@ -60,4 +62,25 @@ abstract class ImagesGenerator( abstract fun getPropertyModifiers(): Array abstract fun getPropertyInitializer(key: String): CodeBlock? + + class Feature(private val info: SourceInfo) : ResourceGeneratorFeature { + private val stringsFileTree = info.commonResources.matching { + include("MR/images/**/*.png", "MR/images/**/*.jpg") + } + + override fun createCommonGenerator(): MRGenerator.Generator { + return CommonImagesGenerator(stringsFileTree) + } + + override fun createIosGenerator(): MRGenerator.Generator { + return IosImagesGenerator(stringsFileTree) + } + + override fun createAndroidGenerator(): MRGenerator.Generator { + return AndroidImagesGenerator( + stringsFileTree, + info.androidRClassPackage + ) + } + } } diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/PluralsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt similarity index 64% rename from gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/PluralsGenerator.kt rename to gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt index d7cfa53f..3f9f6922 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/PluralsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt @@ -1,13 +1,13 @@ /* - * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.plurals +package dev.icerock.gradle.generator import com.squareup.kotlinpoet.ClassName -import dev.icerock.gradle.generator.BaseGenerator -import dev.icerock.gradle.generator.strings.KeyType -import dev.icerock.gradle.generator.strings.LanguageType +import dev.icerock.gradle.generator.android.AndroidPluralsGenerator +import dev.icerock.gradle.generator.common.CommonPluralsGenerator +import dev.icerock.gradle.generator.ios.IosPluralsGenerator import org.gradle.api.file.FileTree import org.w3c.dom.Element import java.io.File @@ -67,4 +67,28 @@ abstract class PluralsGenerator( return mutableMap } + + class Feature( + private val info: SourceInfo, + private val iosBaseLocalizationRegion: String + ) : ResourceGeneratorFeature { + private val stringsFileTree = info.commonResources.matching { include("MR/**/plurals.xml") } + override fun createCommonGenerator(): MRGenerator.Generator { + return CommonPluralsGenerator(stringsFileTree) + } + + override fun createIosGenerator(): MRGenerator.Generator { + return IosPluralsGenerator( + stringsFileTree, + iosBaseLocalizationRegion + ) + } + + override fun createAndroidGenerator(): MRGenerator.Generator { + return AndroidPluralsGenerator( + stringsFileTree, + info.androidRClassPackage + ) + } + } } diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/StringsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt similarity index 62% rename from gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/StringsGenerator.kt rename to gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt index e2fef04c..5d40faec 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/StringsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt @@ -1,11 +1,13 @@ /* - * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.strings +package dev.icerock.gradle.generator import com.squareup.kotlinpoet.ClassName -import dev.icerock.gradle.generator.BaseGenerator +import dev.icerock.gradle.generator.android.AndroidStringsGenerator +import dev.icerock.gradle.generator.common.CommonStringsGenerator +import dev.icerock.gradle.generator.ios.IosStringsGenerator import org.gradle.api.file.FileTree import java.io.File import javax.xml.parsers.DocumentBuilderFactory @@ -60,4 +62,28 @@ abstract class StringsGenerator( } override fun getImports(): List = emptyList() + + class Feature( + private val info: SourceInfo, + private val iosBaseLocalizationRegion: String + ) : ResourceGeneratorFeature { + private val stringsFileTree = info.commonResources.matching { include("MR/**/strings.xml") } + override fun createCommonGenerator(): MRGenerator.Generator { + return CommonStringsGenerator(stringsFileTree) + } + + override fun createIosGenerator(): MRGenerator.Generator { + return IosStringsGenerator( + stringsFileTree, + iosBaseLocalizationRegion + ) + } + + override fun createAndroidGenerator(): MRGenerator.Generator { + return AndroidStringsGenerator( + stringsFileTree, + info.androidRClassPackage + ) + } + } } diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/AndroidFontsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFontsGenerator.kt similarity index 93% rename from gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/AndroidFontsGenerator.kt rename to gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFontsGenerator.kt index d22eb05f..a81c855b 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/AndroidFontsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFontsGenerator.kt @@ -2,11 +2,12 @@ * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.fonts +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 org.gradle.api.file.FileTree import java.io.File import java.util.Locale diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/AndroidImagesGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt similarity index 92% rename from gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/AndroidImagesGenerator.kt rename to gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt index 898d74d3..da023eea 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/AndroidImagesGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidImagesGenerator.kt @@ -1,12 +1,13 @@ /* - * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2020 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.android import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier +import dev.icerock.gradle.generator.ImagesGenerator import org.gradle.api.file.FileTree import java.io.File diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/AndroidMRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt similarity index 81% rename from gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/AndroidMRGenerator.kt rename to gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt index ade6520a..6c5f3e7b 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/AndroidMRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidMRGenerator.kt @@ -1,10 +1,11 @@ /* - * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + * 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.android import com.squareup.kotlinpoet.KModifier +import dev.icerock.gradle.generator.MRGenerator import org.gradle.api.Project import org.gradle.api.Task import java.io.File diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/AndroidPluralsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt similarity index 90% rename from gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/AndroidPluralsGenerator.kt rename to gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt index 70a39e94..d0d08811 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/AndroidPluralsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt @@ -1,13 +1,15 @@ /* - * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.plurals +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.strings.KeyType +import dev.icerock.gradle.generator.PluralMap +import dev.icerock.gradle.generator.PluralsGenerator +import dev.icerock.gradle.generator.KeyType import org.apache.commons.lang3.StringEscapeUtils import org.gradle.api.file.FileTree import java.io.File diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/AndroidStringsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt similarity index 90% rename from gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/AndroidStringsGenerator.kt rename to gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt index 9574cd28..d3b54645 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/AndroidStringsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt @@ -1,12 +1,14 @@ /* - * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.strings +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.StringsGenerator import org.apache.commons.lang3.StringEscapeUtils import org.gradle.api.file.FileTree import java.io.File diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/CommonFontsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFontsGenerator.kt similarity index 85% rename from gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/CommonFontsGenerator.kt rename to gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFontsGenerator.kt index 4b36ed59..531fd06a 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/CommonFontsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFontsGenerator.kt @@ -2,10 +2,11 @@ * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.fonts +package dev.icerock.gradle.generator.common import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier +import dev.icerock.gradle.generator.FontsGenerator import org.gradle.api.file.FileTree class CommonFontsGenerator( diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/CommonImagesGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/common/CommonImagesGenerator.kt similarity index 75% rename from gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/CommonImagesGenerator.kt rename to gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/common/CommonImagesGenerator.kt index 7ea94a9b..ef56c494 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/CommonImagesGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/common/CommonImagesGenerator.kt @@ -1,11 +1,12 @@ /* - * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2020 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.common import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier +import dev.icerock.gradle.generator.ImagesGenerator import org.gradle.api.file.FileTree class CommonImagesGenerator( diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/CommonMRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt similarity index 80% rename from gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/CommonMRGenerator.kt rename to gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt index 97db6151..5d18e67f 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/CommonMRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/common/CommonMRGenerator.kt @@ -1,10 +1,11 @@ /* - * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + * 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.common import com.squareup.kotlinpoet.KModifier +import dev.icerock.gradle.generator.MRGenerator import org.gradle.api.Project import org.gradle.api.Task import java.io.File diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/CommonPluralsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/common/CommonPluralsGenerator.kt similarity index 66% rename from gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/CommonPluralsGenerator.kt rename to gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/common/CommonPluralsGenerator.kt index e630a1da..451969d1 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/CommonPluralsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/common/CommonPluralsGenerator.kt @@ -1,10 +1,11 @@ /* - * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.plurals +package dev.icerock.gradle.generator.common import com.squareup.kotlinpoet.CodeBlock +import dev.icerock.gradle.generator.PluralsGenerator import org.gradle.api.file.FileTree class CommonPluralsGenerator( diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/CommonStringsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/common/CommonStringsGenerator.kt similarity index 66% rename from gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/CommonStringsGenerator.kt rename to gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/common/CommonStringsGenerator.kt index 3582bbd1..69107758 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/CommonStringsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/common/CommonStringsGenerator.kt @@ -1,10 +1,11 @@ /* - * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.strings +package dev.icerock.gradle.generator.common import com.squareup.kotlinpoet.CodeBlock +import dev.icerock.gradle.generator.StringsGenerator import org.gradle.api.file.FileTree class CommonStringsGenerator( diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/FontsGeneratorFeature.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/FontsGeneratorFeature.kt deleted file mode 100644 index bb99fb5a..00000000 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/FontsGeneratorFeature.kt +++ /dev/null @@ -1,27 +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.fonts - -import dev.icerock.gradle.generator.MRGenerator -import dev.icerock.gradle.generator.ResourceGeneratorFeature -import dev.icerock.gradle.generator.SourceInfo - -class FontsGeneratorFeature(private val info: SourceInfo) : ResourceGeneratorFeature { - private val stringsFileTree = info.commonResources.matching { - include("MR/fonts/**.ttf") - } - - override fun createCommonGenerator(): MRGenerator.Generator { - return CommonFontsGenerator(stringsFileTree) - } - - override fun createIosGenerator(): MRGenerator.Generator { - return IosFontsGenerator(stringsFileTree) - } - - override fun createAndroidGenerator(): MRGenerator.Generator { - return AndroidFontsGenerator(stringsFileTree, info.androidRClassPackage) - } -} diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/ImagesGeneratorFeature.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/ImagesGeneratorFeature.kt deleted file mode 100644 index f20115fe..00000000 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/ImagesGeneratorFeature.kt +++ /dev/null @@ -1,27 +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.image - -import dev.icerock.gradle.generator.MRGenerator -import dev.icerock.gradle.generator.ResourceGeneratorFeature -import dev.icerock.gradle.generator.SourceInfo - -class ImagesGeneratorFeature(private val info: SourceInfo) : ResourceGeneratorFeature { - private val stringsFileTree = info.commonResources.matching { - include("MR/images/**/*.png", "MR/images/**/*.jpg") - } - - override fun createCommonGenerator(): MRGenerator.Generator { - return CommonImagesGenerator(stringsFileTree) - } - - override fun createIosGenerator(): MRGenerator.Generator { - return IosImagesGenerator(stringsFileTree) - } - - override fun createAndroidGenerator(): MRGenerator.Generator { - return AndroidImagesGenerator(stringsFileTree, info.androidRClassPackage) - } -} diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/IosFontsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosFontsGenerator.kt similarity index 91% rename from gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/IosFontsGenerator.kt rename to gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosFontsGenerator.kt index 42968c90..6ae42f8e 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/fonts/IosFontsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosFontsGenerator.kt @@ -2,11 +2,11 @@ * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.fonts +package dev.icerock.gradle.generator.ios import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.IosMRGenerator +import dev.icerock.gradle.generator.FontsGenerator import org.gradle.api.file.FileTree import java.io.File diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/IosImagesGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosImagesGenerator.kt similarity index 94% rename from gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/IosImagesGenerator.kt rename to gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosImagesGenerator.kt index e5478de8..60154115 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/IosImagesGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosImagesGenerator.kt @@ -1,12 +1,12 @@ /* - * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2020 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.ios import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.IosMRGenerator +import dev.icerock.gradle.generator.ImagesGenerator import org.gradle.api.file.FileTree import java.io.File diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosMRGenerator.kt similarity index 97% rename from gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt rename to gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosMRGenerator.kt index 5546a9b9..1c031340 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/IosMRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosMRGenerator.kt @@ -1,15 +1,15 @@ /* - * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + * 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.ios import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.PropertySpec -import com.squareup.kotlinpoet.TypeName import com.squareup.kotlinpoet.TypeSpec +import dev.icerock.gradle.generator.MRGenerator import org.gradle.api.Project import org.gradle.api.Task import org.gradle.kotlin.dsl.support.unzipTo diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/IosPluralsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosPluralsGenerator.kt similarity index 91% rename from gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/IosPluralsGenerator.kt rename to gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosPluralsGenerator.kt index 250aba90..d45531b8 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/IosPluralsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosPluralsGenerator.kt @@ -1,13 +1,14 @@ /* - * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.plurals +package dev.icerock.gradle.generator.ios import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.IosMRGenerator -import dev.icerock.gradle.generator.strings.KeyType +import dev.icerock.gradle.generator.PluralMap +import dev.icerock.gradle.generator.PluralsGenerator +import dev.icerock.gradle.generator.KeyType import org.gradle.api.file.FileTree import java.io.File diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/IosStringsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosStringsGenerator.kt similarity index 84% rename from gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/IosStringsGenerator.kt rename to gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosStringsGenerator.kt index cb3a1242..0ef2799f 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/IosStringsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosStringsGenerator.kt @@ -1,12 +1,14 @@ /* - * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -package dev.icerock.gradle.generator.strings +package dev.icerock.gradle.generator.ios import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier -import dev.icerock.gradle.generator.IosMRGenerator.Companion.BUNDLE_PROPERTY_NAME +import dev.icerock.gradle.generator.ios.IosMRGenerator.Companion.BUNDLE_PROPERTY_NAME +import dev.icerock.gradle.generator.KeyType +import dev.icerock.gradle.generator.StringsGenerator import org.gradle.api.file.FileTree import java.io.File diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/PluralsGeneratorFeature.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/PluralsGeneratorFeature.kt deleted file mode 100644 index 7c2414f7..00000000 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/plurals/PluralsGeneratorFeature.kt +++ /dev/null @@ -1,27 +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.plurals - -import dev.icerock.gradle.generator.MRGenerator -import dev.icerock.gradle.generator.ResourceGeneratorFeature -import dev.icerock.gradle.generator.SourceInfo - -class PluralsGeneratorFeature( - private val info: SourceInfo, - private val iosBaseLocalizationRegion: String -) : ResourceGeneratorFeature { - private val stringsFileTree = info.commonResources.matching { include("MR/**/plurals.xml") } - override fun createCommonGenerator(): MRGenerator.Generator { - return CommonPluralsGenerator(stringsFileTree) - } - - override fun createIosGenerator(): MRGenerator.Generator { - return IosPluralsGenerator(stringsFileTree, iosBaseLocalizationRegion) - } - - override fun createAndroidGenerator(): MRGenerator.Generator { - return AndroidPluralsGenerator(stringsFileTree, info.androidRClassPackage) - } -} diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/StringsGeneratorFeature.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/StringsGeneratorFeature.kt deleted file mode 100644 index fc5357f3..00000000 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/strings/StringsGeneratorFeature.kt +++ /dev/null @@ -1,27 +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.strings - -import dev.icerock.gradle.generator.MRGenerator -import dev.icerock.gradle.generator.ResourceGeneratorFeature -import dev.icerock.gradle.generator.SourceInfo - -class StringsGeneratorFeature( - private val info: SourceInfo, - private val iosBaseLocalizationRegion: String -) : ResourceGeneratorFeature { - private val stringsFileTree = info.commonResources.matching { include("MR/**/strings.xml") } - override fun createCommonGenerator(): MRGenerator.Generator { - return CommonStringsGenerator(stringsFileTree) - } - - override fun createIosGenerator(): MRGenerator.Generator { - return IosStringsGenerator(stringsFileTree, iosBaseLocalizationRegion) - } - - override fun createAndroidGenerator(): MRGenerator.Generator { - return AndroidStringsGenerator(stringsFileTree, info.androidRClassPackage) - } -} From 85d730680b72b6a49980197dccf1a612374d6967 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 3 May 2020 21:02:01 +0700 Subject: [PATCH 28/54] #48 move loadable bundle logic to separated class --- .../gradle/generator/ios/IosMRGenerator.kt | 33 +++---------- .../gradle/generator/ios/LoadableBundle.kt | 46 +++++++++++++++++++ 2 files changed, 53 insertions(+), 26 deletions(-) create mode 100644 gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/LoadableBundle.kt diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosMRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosMRGenerator.kt index 1c031340..e7978555 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosMRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosMRGenerator.kt @@ -84,34 +84,15 @@ class IosMRGenerator( val uniqueName = manifest["unique_name"] as String - val bundleDir = File(resRepackDir, "$uniqueName.bundle") - bundleDir.mkdir() - - val bundleContentsDir = File(bundleDir, "Contents") - bundleContentsDir.mkdir() - - val bundlePList = File(bundleContentsDir, "Info.plist") - bundlePList.writeText( - """ - - - - CFBundleDevelopmentRegion - $baseLocalizationRegion - CFBundleIdentifier - $bundleIdentifier - CFBundleVersion - 1 - CFBundlePackageType - BNDL - -""" + val loadableBundle = LoadableBundle( + directory = resRepackDir, + bundleName = uniqueName, + developmentRegion = baseLocalizationRegion, + identifier = bundleIdentifier ) + loadableBundle.write() - val bundleResourcesDir = File(bundleContentsDir, "Resources") - bundleResourcesDir.mkdir() - - resourcesGenerationDir.copyRecursively(bundleResourcesDir, overwrite = true) + resourcesGenerationDir.copyRecursively(loadableBundle.resourcesDir, overwrite = true) val repackKonan = org.jetbrains.kotlin.konan.file.File(repackDir.path) val klibKonan = org.jetbrains.kotlin.konan.file.File(klibFile.path) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/LoadableBundle.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/LoadableBundle.kt new file mode 100644 index 00000000..872bcb67 --- /dev/null +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/LoadableBundle.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.ios + +import java.io.File + +class LoadableBundle( + directory: File, + bundleName: String, + private val developmentRegion: String, + private val identifier: String +) { + val bundleDir: File = File(directory, "$bundleName.bundle") + val contentsDir: File = File(bundleDir, "Contents") + val infoPListFile: File = File(contentsDir, "Info.plist") + val resourcesDir: File = File(contentsDir, "Resources") + + fun write() { + bundleDir.mkdir() + contentsDir.mkdir() + resourcesDir.mkdir() + + writeInfoPList() + } + + private fun writeInfoPList() { + infoPListFile.writeText( + """ + + + + CFBundleDevelopmentRegion + $developmentRegion + CFBundleIdentifier + $identifier + CFBundleVersion + 1 + CFBundlePackageType + BNDL + + """ + ) + } +} From e2699430fbe3ceeac54ebd07f131b07b49c26e28 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 3 May 2020 21:57:18 +0700 Subject: [PATCH 29/54] #48 allow to use static framework --- .../dev/icerock/moko/resources/NSBundleExt.kt | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/NSBundleExt.kt b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/NSBundleExt.kt index b16ef56c..47024217 100644 --- a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/NSBundleExt.kt +++ b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/NSBundleExt.kt @@ -7,19 +7,18 @@ package dev.icerock.moko.resources import platform.Foundation.NSBundle fun NSBundle.Companion.loadableBundle(identifier: String): NSBundle { - val result = NSBundle.bundleWithIdentifier(identifier) - if (result != null) return result + // try get already loaded bundle + NSBundle.bundleWithIdentifier(identifier)?.let { return it } - val mainPath = NSBundle.mainBundle.bundlePath - val appFrameworks = NSBundle.allFrameworks.filterIsInstance() - .filter { it.bundlePath.startsWith(mainPath) } - appFrameworks.flatMap { frameworkBundle -> - @Suppress("UNCHECKED_CAST") - frameworkBundle.pathsForResourcesOfType(ext = "bundle", inDirectory = null) as List - }.forEach { bundlePath -> + // try load from app framework + NSBundle.mainBundle + .pathsForResourcesOfType(ext = "framework", inDirectory = "Frameworks") + .filterIsInstance() + .mapNotNull { NSBundle.bundleWithPath(it) } + .flatMap { it.pathsForResourcesOfType(ext = "bundle", inDirectory = null) } + .filterIsInstance() // load each loadable bundle to correct load by identifier later - NSBundle.bundleWithPath(bundlePath)?.bundleIdentifier - } + .forEach { NSBundle.bundleWithPath(it)?.bundleIdentifier } return NSBundle.bundleWithIdentifier(identifier)!! } From d6926452f89473d961306e399a051ec16ac9924b Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 3 May 2020 22:16:10 +0700 Subject: [PATCH 30/54] #18 test on device dynamic and static frameworks --- sample/ios-app/Podfile.lock | 2 +- .../TestProj.xcodeproj/project.pbxproj | 18 +++++++++-------- sample/ios-app/src/Info.plist | 12 +++++------ .../mpp-library/MultiPlatformLibrary.podspec | 2 +- sample/mpp-library/build.gradle.kts | 20 ++++++++++--------- 5 files changed, 29 insertions(+), 25 deletions(-) diff --git a/sample/ios-app/Podfile.lock b/sample/ios-app/Podfile.lock index 0e3e0411..1b0f67ac 100644 --- a/sample/ios-app/Podfile.lock +++ b/sample/ios-app/Podfile.lock @@ -13,4 +13,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 95f068a0f3d27c63d621e129eadfe99686b704a0 -COCOAPODS: 1.9.0 +COCOAPODS: 1.9.1 diff --git a/sample/ios-app/TestProj.xcodeproj/project.pbxproj b/sample/ios-app/TestProj.xcodeproj/project.pbxproj index 751076e7..9933c41a 100644 --- a/sample/ios-app/TestProj.xcodeproj/project.pbxproj +++ b/sample/ios-app/TestProj.xcodeproj/project.pbxproj @@ -112,7 +112,7 @@ 287627FB1F319065007FA12B /* Sources */, 287627FC1F319065007FA12B /* Frameworks */, 287627FD1F319065007FA12B /* Resources */, - 9B9470727B06EFAA41C171BB /* [CP] Embed Pods Frameworks */, + B82E91042382B0A43D529F33 /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -173,7 +173,7 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 9B9470727B06EFAA41C171BB /* [CP] Embed Pods Frameworks */ = { + B82E91042382B0A43D529F33 /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -250,6 +250,7 @@ CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CURRENT_PROJECT_VERSION = 0; DEFINES_MODULE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; SWIFT_VERSION = 4.0; }; name = Debug; @@ -260,6 +261,7 @@ CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CURRENT_PROJECT_VERSION = 0; DEFINES_MODULE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; SWIFT_VERSION = 4.0; }; name = Release; @@ -269,11 +271,11 @@ baseConfigurationReference = DFBDF7D3559D080FDCA444A6 /* Pods-TestProj.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CODE_SIGN_IDENTITY = "iPhone Developer"; + CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = 4VU932NX78; + DEVELOPMENT_TEAM = RF9T8S9829; INFOPLIST_FILE = src/Info.plist; - PRODUCT_BUNDLE_IDENTIFIER = dev.icerock.moko.sample.resources; + PRODUCT_BUNDLE_IDENTIFIER = "dev.icerock.moko.sample.resources-test"; PRODUCT_NAME = mokoSampleResources; PROVISIONING_PROFILE_SPECIFIER = ""; SDKROOT = iphoneos; @@ -287,11 +289,11 @@ baseConfigurationReference = A644D2F1C5377C40A53FCD6A /* Pods-TestProj.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CODE_SIGN_IDENTITY = "iPhone Developer"; + CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = 4VU932NX78; + DEVELOPMENT_TEAM = RF9T8S9829; INFOPLIST_FILE = src/Info.plist; - PRODUCT_BUNDLE_IDENTIFIER = dev.icerock.moko.sample.resources; + PRODUCT_BUNDLE_IDENTIFIER = "dev.icerock.moko.sample.resources-test"; PRODUCT_NAME = mokoSampleResources; PROVISIONING_PROFILE_SPECIFIER = ""; SDKROOT = iphoneos; diff --git a/sample/ios-app/src/Info.plist b/sample/ios-app/src/Info.plist index 5ebc2e5e..e8ba3509 100755 --- a/sample/ios-app/src/Info.plist +++ b/sample/ios-app/src/Info.plist @@ -12,6 +12,12 @@ $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 + CFBundleLocalizations + + en + es + ru + CFBundleName $(BUNDLE_NAME) CFBundlePackageType @@ -47,12 +53,6 @@ UIStatusBarStyle UIStatusBarStyleLightContent - CFBundleLocalizations - - en - es - ru - UISupportedInterfaceOrientations UIInterfaceOrientationPortrait diff --git a/sample/mpp-library/MultiPlatformLibrary.podspec b/sample/mpp-library/MultiPlatformLibrary.podspec index dd1e3e3d..9bb6b5da 100644 --- a/sample/mpp-library/MultiPlatformLibrary.podspec +++ b/sample/mpp-library/MultiPlatformLibrary.podspec @@ -11,7 +11,7 @@ Pod::Spec.new do |spec| spec.libraries = "c++" spec.module_name = "#{spec.name}_umbrella" - spec.static_framework = true +# spec.static_framework = true spec.pod_target_xcconfig = { 'MPP_LIBRARY_NAME' => 'MultiPlatformLibrary', 'GRADLE_TASK[sdk=iphonesimulator*][config=*ebug]' => 'syncMultiPlatformLibraryDebugFrameworkIosX64', diff --git a/sample/mpp-library/build.gradle.kts b/sample/mpp-library/build.gradle.kts index 495b81d4..bac506e3 100644 --- a/sample/mpp-library/build.gradle.kts +++ b/sample/mpp-library/build.gradle.kts @@ -39,12 +39,14 @@ multiplatformResources { multiplatformResourcesPackage = "com.icerockdev.library" } -kotlin { - targets - .filterIsInstance() - .flatMap { it.binaries } - .filterIsInstance() - .forEach { framework -> - framework.isStatic = true - } -} +// uncomment to test static framework +// also in sample/mpp-library/MultiPlatformLibrary.podspec:14 flag should be uncommented +//kotlin { +// targets +// .filterIsInstance() +// .flatMap { it.binaries } +// .filterIsInstance() +// .forEach { framework -> +// framework.isStatic = true +// } +//} From da05560657c3fb90167ce47930e3349d3aafed99 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 3 May 2020 22:52:14 +0700 Subject: [PATCH 31/54] up version --- buildSrc/src/main/kotlin/Versions.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index e1c80b5a..1e4c12fd 100755 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -9,9 +9,9 @@ object Versions { const val minSdk = 16 } - const val kotlin = "1.3.71" + const val kotlin = "1.3.72" - private const val mokoResources = "0.9.1" + private const val mokoResources = "0.10.0" object Plugins { const val android = "3.6.2" From 38e851dc5ed4ba84b8287c7fc0aa9e790a33e80f Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 3 May 2020 22:52:32 +0700 Subject: [PATCH 32/54] #44 file resource runtime draft --- .../icerock/moko/resources/FileResource.kt | 18 ++++++++ .../icerock/moko/resources/FileResource.kt | 9 ++++ .../icerock/moko/resources/FileResource.kt | 42 +++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 resources/src/androidMain/kotlin/dev/icerock/moko/resources/FileResource.kt create mode 100644 resources/src/commonMain/kotlin/dev/icerock/moko/resources/FileResource.kt create mode 100644 resources/src/iosMain/kotlin/dev/icerock/moko/resources/FileResource.kt diff --git a/resources/src/androidMain/kotlin/dev/icerock/moko/resources/FileResource.kt b/resources/src/androidMain/kotlin/dev/icerock/moko/resources/FileResource.kt new file mode 100644 index 00000000..edb50117 --- /dev/null +++ b/resources/src/androidMain/kotlin/dev/icerock/moko/resources/FileResource.kt @@ -0,0 +1,18 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.moko.resources + +import java.io.File +import java.net.URI + +actual class FileResource( + val assetsPath: String +) { + actual fun readText(): String { + val assetUri: URI = URI.create("file:///android_asset/$assetsPath") + val file: File = File(assetUri) + return file.readText() + } +} diff --git a/resources/src/commonMain/kotlin/dev/icerock/moko/resources/FileResource.kt b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/FileResource.kt new file mode 100644 index 00000000..66714df2 --- /dev/null +++ b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/FileResource.kt @@ -0,0 +1,9 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.moko.resources + +expect class FileResource { + fun readText(): String +} diff --git a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/FileResource.kt b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/FileResource.kt new file mode 100644 index 00000000..f4e3895f --- /dev/null +++ b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/FileResource.kt @@ -0,0 +1,42 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.moko.resources + +import kotlinx.cinterop.ObjCObjectVar +import kotlinx.cinterop.alloc +import kotlinx.cinterop.memScoped +import kotlinx.cinterop.ptr +import kotlinx.cinterop.value +import platform.Foundation.NSBundle +import platform.Foundation.NSError +import platform.Foundation.NSString +import platform.Foundation.NSURL +import platform.Foundation.NSUTF8StringEncoding +import platform.Foundation.stringWithContentsOfFile + +actual class FileResource( + val fileName: String, + val bundle: NSBundle = NSBundle.mainBundle +) { + val path: String get() = bundle.pathForResource(name = fileName, ofType = null, inDirectory = "files")!! + val url: NSURL get() = bundle.URLForResource(name = fileName, withExtension = null, subdirectory = "files")!! + + actual fun readText(): String { + val (result: String?, error: NSError?) = memScoped { + val p = alloc>() + val result: String? = runCatching { + NSString.stringWithContentsOfFile( + path = path, + encoding = NSUTF8StringEncoding, + error = p.ptr + ) + }.getOrNull() + result to p.value + } + + if (error != null) throw RuntimeException(error.localizedDescription) + else return result!! + } +} From 15d564a365d41861e746e2b8bfb1b28a9fd259a7 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 4 May 2020 09:28:11 +0700 Subject: [PATCH 33/54] #44 generic ResourceGeneratorFeature --- .../kotlin/dev/icerock/gradle/generator/FontsGenerator.kt | 8 ++++---- .../dev/icerock/gradle/generator/ImagesGenerator.kt | 8 ++++---- .../dev/icerock/gradle/generator/PluralsGenerator.kt | 8 ++++---- .../icerock/gradle/generator/ResourceGeneratorFeature.kt | 8 ++++---- .../dev/icerock/gradle/generator/StringsGenerator.kt | 8 ++++---- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt index 1d0d24d9..60ae4bed 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/FontsGenerator.kt @@ -104,20 +104,20 @@ abstract class FontsGenerator( val file: File ) - class Feature(private val info: SourceInfo) : ResourceGeneratorFeature { + class Feature(private val info: SourceInfo) : ResourceGeneratorFeature { private val stringsFileTree = info.commonResources.matching { include("MR/fonts/**.ttf") } - override fun createCommonGenerator(): MRGenerator.Generator { + override fun createCommonGenerator(): FontsGenerator { return CommonFontsGenerator(stringsFileTree) } - override fun createIosGenerator(): MRGenerator.Generator { + override fun createIosGenerator(): FontsGenerator { return IosFontsGenerator(stringsFileTree) } - override fun createAndroidGenerator(): MRGenerator.Generator { + override fun createAndroidGenerator(): FontsGenerator { return AndroidFontsGenerator( stringsFileTree, info.androidRClassPackage diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt index 367a8512..64065d5e 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ImagesGenerator.kt @@ -63,20 +63,20 @@ abstract class ImagesGenerator( abstract fun getPropertyInitializer(key: String): CodeBlock? - class Feature(private val info: SourceInfo) : ResourceGeneratorFeature { + class Feature(private val info: SourceInfo) : ResourceGeneratorFeature { private val stringsFileTree = info.commonResources.matching { include("MR/images/**/*.png", "MR/images/**/*.jpg") } - override fun createCommonGenerator(): MRGenerator.Generator { + override fun createCommonGenerator(): ImagesGenerator { return CommonImagesGenerator(stringsFileTree) } - override fun createIosGenerator(): MRGenerator.Generator { + override fun createIosGenerator(): ImagesGenerator { return IosImagesGenerator(stringsFileTree) } - override fun createAndroidGenerator(): MRGenerator.Generator { + override fun createAndroidGenerator(): ImagesGenerator { return AndroidImagesGenerator( stringsFileTree, info.androidRClassPackage diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt index 3f9f6922..ddf3ef79 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt @@ -71,20 +71,20 @@ abstract class PluralsGenerator( class Feature( private val info: SourceInfo, private val iosBaseLocalizationRegion: String - ) : ResourceGeneratorFeature { + ) : ResourceGeneratorFeature { private val stringsFileTree = info.commonResources.matching { include("MR/**/plurals.xml") } - override fun createCommonGenerator(): MRGenerator.Generator { + override fun createCommonGenerator(): PluralsGenerator { return CommonPluralsGenerator(stringsFileTree) } - override fun createIosGenerator(): MRGenerator.Generator { + override fun createIosGenerator(): PluralsGenerator { return IosPluralsGenerator( stringsFileTree, iosBaseLocalizationRegion ) } - override fun createAndroidGenerator(): MRGenerator.Generator { + override fun createAndroidGenerator(): PluralsGenerator { return AndroidPluralsGenerator( stringsFileTree, info.androidRClassPackage diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ResourceGeneratorFeature.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ResourceGeneratorFeature.kt index fefb0999..4f0c00e6 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ResourceGeneratorFeature.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ResourceGeneratorFeature.kt @@ -4,8 +4,8 @@ package dev.icerock.gradle.generator -interface ResourceGeneratorFeature { - fun createCommonGenerator(): MRGenerator.Generator - fun createIosGenerator(): MRGenerator.Generator - fun createAndroidGenerator(): MRGenerator.Generator +interface ResourceGeneratorFeature { + fun createCommonGenerator(): T + fun createIosGenerator(): T + fun createAndroidGenerator(): T } diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt index 5d40faec..d3c789b7 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt @@ -66,20 +66,20 @@ abstract class StringsGenerator( class Feature( private val info: SourceInfo, private val iosBaseLocalizationRegion: String - ) : ResourceGeneratorFeature { + ) : ResourceGeneratorFeature { private val stringsFileTree = info.commonResources.matching { include("MR/**/strings.xml") } - override fun createCommonGenerator(): MRGenerator.Generator { + override fun createCommonGenerator(): StringsGenerator { return CommonStringsGenerator(stringsFileTree) } - override fun createIosGenerator(): MRGenerator.Generator { + override fun createIosGenerator(): StringsGenerator { return IosStringsGenerator( stringsFileTree, iosBaseLocalizationRegion ) } - override fun createAndroidGenerator(): MRGenerator.Generator { + override fun createAndroidGenerator(): StringsGenerator { return AndroidStringsGenerator( stringsFileTree, info.androidRClassPackage From fa381a25c9064320453bd0263c53c407ffe329fa Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 4 May 2020 09:32:54 +0700 Subject: [PATCH 34/54] #44 move utils func to separated package --- .../kotlin/dev/icerock/gradle/generator/ios/IosMRGenerator.kt | 2 +- .../dev/icerock/moko/resources/{ => utils}/NSBundleExt.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename resources/src/iosMain/kotlin/dev/icerock/moko/resources/{ => utils}/NSBundleExt.kt (95%) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosMRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosMRGenerator.kt index e7978555..08075b4c 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosMRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosMRGenerator.kt @@ -57,7 +57,7 @@ class IosMRGenerator( override fun getImports(): List = listOf( bundleClassName, - ClassName(packageName = "dev.icerock.moko.resources", simpleName = "loadableBundle") + ClassName(packageName = "dev.icerock.moko.resources.utils", simpleName = "loadableBundle") ) override fun apply(generationTask: Task, project: Project) { diff --git a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/NSBundleExt.kt b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/utils/NSBundleExt.kt similarity index 95% rename from resources/src/iosMain/kotlin/dev/icerock/moko/resources/NSBundleExt.kt rename to resources/src/iosMain/kotlin/dev/icerock/moko/resources/utils/NSBundleExt.kt index 47024217..1adaf213 100644 --- a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/NSBundleExt.kt +++ b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/utils/NSBundleExt.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.moko.resources +package dev.icerock.moko.resources.utils import platform.Foundation.NSBundle From 83e4231a4ab7805d01839edd72deb421030a35b3 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 4 May 2020 09:44:29 +0700 Subject: [PATCH 35/54] #44 complete generic generator --- .../dev/icerock/gradle/MultiplatformResourcesPlugin.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index c632f09f..e3df7b59 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -103,7 +103,7 @@ class MultiplatformResourcesPlugin : Plugin { commonSourceSet: KotlinSourceSet, generatedDir: File, mrClassPackage: String, - features: List, + features: List>, target: Project ) { val commonGeneratorSourceSet: MRGenerator.SourceSet = createSourceSet(commonSourceSet) @@ -121,7 +121,7 @@ class MultiplatformResourcesPlugin : Plugin { androidMainSourceSet: AndroidSourceSet, generatedDir: File, mrClassPackage: String, - features: List, + features: List>, target: Project ) { val kotlinSourceSets: List = targets @@ -144,7 +144,7 @@ class MultiplatformResourcesPlugin : Plugin { targets: List, generatedDir: File, mrClassPackage: String, - features: List, + features: List>, target: Project, iosLocalizationRegion: String ) { From cf5aeb0996df552c038b04333ffc52df6a1bd84a Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 4 May 2020 09:44:49 +0700 Subject: [PATCH 36/54] #44 add FilesGenerator --- .../gradle/MultiplatformResourcesPlugin.kt | 4 +- .../gradle/generator/FilesGenerator.kt | 96 +++++++++++++++++++ .../android/AndroidFilesGenerator.kt | 49 ++++++++++ .../generator/common/CommonFilesGenerator.kt | 23 +++++ .../gradle/generator/ios/IosFilesGenerator.kt | 40 ++++++++ .../icerock/moko/resources/FileResource.kt | 20 ++-- .../icerock/moko/resources/FileResource.kt | 4 +- .../icerock/moko/resources/FileResource.kt | 4 +- .../moko/resources/ReadFileTextException.kt | 14 +++ 9 files changed, 241 insertions(+), 13 deletions(-) create mode 100644 gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt create mode 100644 gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt create mode 100644 gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt create mode 100644 gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosFilesGenerator.kt create mode 100644 resources/src/iosMain/kotlin/dev/icerock/moko/resources/ReadFileTextException.kt diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt index e3df7b59..e11d80b5 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt @@ -7,6 +7,7 @@ package dev.icerock.gradle import com.android.build.gradle.LibraryExtension import com.android.build.gradle.LibraryPlugin import com.android.build.gradle.api.AndroidSourceSet +import dev.icerock.gradle.generator.FilesGenerator import dev.icerock.gradle.generator.FontsGenerator import dev.icerock.gradle.generator.GenerateMultiplatformResourcesTask import dev.icerock.gradle.generator.ImagesGenerator @@ -85,7 +86,8 @@ class MultiplatformResourcesPlugin : Plugin { StringsGenerator.Feature(sourceInfo, iosLocalizationRegion), PluralsGenerator.Feature(sourceInfo, iosLocalizationRegion), ImagesGenerator.Feature(sourceInfo), - FontsGenerator.Feature(sourceInfo) + FontsGenerator.Feature(sourceInfo), + FilesGenerator.Feature(sourceInfo) ) val targets: List = multiplatformExtension.targets.toList() diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt new file mode 100644 index 00000000..ebb66f80 --- /dev/null +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt @@ -0,0 +1,96 @@ +/* + * 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.common.CommonFilesGenerator +import dev.icerock.gradle.generator.ios.IosFilesGenerator +import org.gradle.api.file.FileTree +import java.io.File + +abstract class FilesGenerator( + private val inputFileTree: FileTree +) : MRGenerator.Generator { + + private val resourceClass = ClassName("dev.icerock.moko.resources", "FileResource") + + override fun generate(resourcesGenerationDir: File): TypeSpec { + val fileSpecs = inputFileTree.map { file -> + FileSpec( + key = file.nameWithoutExtension, + file = file + ) + }.sortedBy { it.key } + val typeSpec = createTypeSpec(fileSpecs.map { it.key }) + generateResources(resourcesGenerationDir, fileSpecs) + return typeSpec + } + + private fun createTypeSpec(keys: List): TypeSpec { + val classBuilder = TypeSpec.objectBuilder("files") + @Suppress("SpreadOperator") + classBuilder.addModifiers(*getClassModifiers()) + + keys.forEach { classBuilder.addProperty(generateFileProperty(fileName = it)) } + return classBuilder.build() + } + + override fun getImports(): List = emptyList() + + private fun generateFileProperty( + fileName: String + ): PropertySpec { + @Suppress("SpreadOperator") + return PropertySpec.builder(fileName, resourceClass) + .addModifiers(*getPropertyModifiers()) + .apply { + getPropertyInitializer(fileName)?.let { initializer(it) } + } + .build() + } + + protected open fun generateResources( + resourcesGenerationDir: File, + files: List + ) { + } + + abstract fun getClassModifiers(): Array + + abstract fun getPropertyModifiers(): Array + + abstract fun getPropertyInitializer(fileName: String): CodeBlock? + + data class FileSpec( + val key: String, + val file: File + ) + + class Feature(private val info: SourceInfo) : ResourceGeneratorFeature { + private val fileTree = info.commonResources.matching { + include("MR/files/**") + } + + override fun createCommonGenerator(): FilesGenerator { + return CommonFilesGenerator(fileTree) + } + + override fun createIosGenerator(): FilesGenerator { + return IosFilesGenerator(fileTree) + } + + override fun createAndroidGenerator(): FilesGenerator { + return AndroidFilesGenerator( + fileTree, + info.androidRClassPackage + ) + } + } +} diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt new file mode 100644 index 00000000..bbff1984 --- /dev/null +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt @@ -0,0 +1,49 @@ +/* + * 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 org.gradle.api.file.FileTree +import java.io.File +import java.util.Locale + +class AndroidFilesGenerator( + inputFileTree: FileTree, + private val androidRClassPackage: String +) : FilesGenerator( + inputFileTree = inputFileTree +) { + override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) + + override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) + + override fun getPropertyInitializer(fileName: String): CodeBlock? { + return CodeBlock.of("FileResource(rawResId = R.raw.%L)", keyToResourceId(fileName)) + } + + override fun getImports(): List = listOf( + ClassName(androidRClassPackage, "R") + ) + + override fun generateResources( + resourcesGenerationDir: File, + files: List + ) { + val targetDir = File(resourcesGenerationDir, "raw") + targetDir.mkdirs() + + files.forEach { (key, file) -> + val fileName = keyToResourceId(key) + "." + file.extension + file.copyTo(File(targetDir, fileName)) + } + } + + private fun keyToResourceId(key: String): String { + return key.replace("-", "_").toLowerCase(Locale.ROOT) + } +} diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt new file mode 100644 index 00000000..1b72e365 --- /dev/null +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt @@ -0,0 +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.FilesGenerator +import dev.icerock.gradle.generator.FontsGenerator +import org.gradle.api.file.FileTree + +class CommonFilesGenerator( + inputFileTree: FileTree +) : FilesGenerator( + inputFileTree = inputFileTree +) { + override fun getClassModifiers(): Array = emptyArray() + + override fun getPropertyModifiers(): Array = emptyArray() + + override fun getPropertyInitializer(fileName: String): CodeBlock? = null +} diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosFilesGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosFilesGenerator.kt new file mode 100644 index 00000000..2b32aecb --- /dev/null +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosFilesGenerator.kt @@ -0,0 +1,40 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.gradle.generator.ios + +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.KModifier +import dev.icerock.gradle.generator.FilesGenerator +import org.gradle.api.file.FileTree +import java.io.File + +class IosFilesGenerator( + inputFileTree: FileTree +) : FilesGenerator( + inputFileTree = inputFileTree +) { + override fun getClassModifiers(): Array = arrayOf(KModifier.ACTUAL) + + override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) + + override fun getPropertyInitializer(fileName: String): CodeBlock? { + return CodeBlock.of( + "FileResource(fileName = %S, bundle = ${IosMRGenerator.BUNDLE_PROPERTY_NAME})", + fileName + ) + } + + override fun generateResources( + resourcesGenerationDir: File, + files: List + ) { + val targetDir = File(resourcesGenerationDir, "files") + targetDir.mkdirs() + + files.forEach { (_, file) -> + file.copyTo(File(targetDir, file.name)) + } + } +} diff --git a/resources/src/androidMain/kotlin/dev/icerock/moko/resources/FileResource.kt b/resources/src/androidMain/kotlin/dev/icerock/moko/resources/FileResource.kt index edb50117..8c473bc2 100644 --- a/resources/src/androidMain/kotlin/dev/icerock/moko/resources/FileResource.kt +++ b/resources/src/androidMain/kotlin/dev/icerock/moko/resources/FileResource.kt @@ -4,15 +4,21 @@ package dev.icerock.moko.resources -import java.io.File -import java.net.URI +import android.content.Context +import android.content.res.Resources +import androidx.annotation.RawRes +import java.io.BufferedReader +import java.io.InputStream +import java.io.InputStreamReader actual class FileResource( - val assetsPath: String + @RawRes + val rawResId: Int ) { - actual fun readText(): String { - val assetUri: URI = URI.create("file:///android_asset/$assetsPath") - val file: File = File(assetUri) - return file.readText() + fun readText(context: Context): String { + val resources: Resources = context.resources + val inputStream: InputStream = resources.openRawResource(rawResId) + val bufferedReader = BufferedReader(InputStreamReader(inputStream)) + return bufferedReader.readText() } } diff --git a/resources/src/commonMain/kotlin/dev/icerock/moko/resources/FileResource.kt b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/FileResource.kt index 66714df2..709b3653 100644 --- a/resources/src/commonMain/kotlin/dev/icerock/moko/resources/FileResource.kt +++ b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/FileResource.kt @@ -4,6 +4,4 @@ package dev.icerock.moko.resources -expect class FileResource { - fun readText(): String -} +expect class FileResource diff --git a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/FileResource.kt b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/FileResource.kt index f4e3895f..36b57dc3 100644 --- a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/FileResource.kt +++ b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/FileResource.kt @@ -23,7 +23,7 @@ actual class FileResource( val path: String get() = bundle.pathForResource(name = fileName, ofType = null, inDirectory = "files")!! val url: NSURL get() = bundle.URLForResource(name = fileName, withExtension = null, subdirectory = "files")!! - actual fun readText(): String { + fun readText(): String { val (result: String?, error: NSError?) = memScoped { val p = alloc>() val result: String? = runCatching { @@ -36,7 +36,7 @@ actual class FileResource( result to p.value } - if (error != null) throw RuntimeException(error.localizedDescription) + if (error != null) throw ReadFileTextException(fileResource = this, error = error) else return result!! } } diff --git a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/ReadFileTextException.kt b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/ReadFileTextException.kt new file mode 100644 index 00000000..6c31e66b --- /dev/null +++ b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/ReadFileTextException.kt @@ -0,0 +1,14 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.moko.resources + +import platform.Foundation.NSError + +class ReadFileTextException( + val fileResource: FileResource, + val info: String +) : Exception("can't read file $fileResource text ($info)") { + constructor(fileResource: FileResource, error: NSError) : this(fileResource, error.localizedDescription) +} From 3da5c9530370efc44e1624ad8a19b181ff4a1018 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 4 May 2020 10:42:35 +0700 Subject: [PATCH 37/54] #44 implemented raw file resources --- .../gradle/generator/FilesGenerator.kt | 29 ++++++++++++++----- .../android/AndroidFilesGenerator.kt | 2 +- .../generator/common/CommonFilesGenerator.kt | 3 +- .../gradle/generator/ios/IosFilesGenerator.kt | 7 +++-- .../icerock/moko/resources/FileResource.kt | 8 +++-- .../main/java/com/icerockdev/MainActivity.kt | 8 ++++- sample/ios-app/src/TestViewController.swift | 7 +++++ .../com/icerockdev/library/nested/Testing.kt | 5 ++++ .../resources/MR/files/nested-test.json | 25 ++++++++++++++++ .../kotlin/com/icerockdev/library/Testing.kt | 16 +++++++++- .../commonMain/resources/MR/files/some.json | 4 +++ .../commonMain/resources/MR/files/test.txt | 1 + 12 files changed, 97 insertions(+), 18 deletions(-) create mode 100644 sample/mpp-library/nested-module/src/commonMain/resources/MR/files/nested-test.json create mode 100644 sample/mpp-library/src/commonMain/resources/MR/files/some.json create mode 100644 sample/mpp-library/src/commonMain/resources/MR/files/test.txt diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt index ebb66f80..bc6dcf81 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt @@ -28,30 +28,41 @@ abstract class FilesGenerator( file = file ) }.sortedBy { it.key } - val typeSpec = createTypeSpec(fileSpecs.map { it.key }) + val typeSpec = createTypeSpec(fileSpecs) generateResources(resourcesGenerationDir, fileSpecs) return typeSpec } - private fun createTypeSpec(keys: List): TypeSpec { + private fun createTypeSpec(keys: List): TypeSpec { val classBuilder = TypeSpec.objectBuilder("files") @Suppress("SpreadOperator") classBuilder.addModifiers(*getClassModifiers()) - keys.forEach { classBuilder.addProperty(generateFileProperty(fileName = it)) } + keys.forEach { + classBuilder.addProperty( + generateFileProperty( + fileName = it.key, + fileExtension = it.file.extension + ) + ) + } return classBuilder.build() } override fun getImports(): List = emptyList() private fun generateFileProperty( - fileName: String + fileName: String, + fileExtension: String ): PropertySpec { @Suppress("SpreadOperator") - return PropertySpec.builder(fileName, resourceClass) + return PropertySpec.builder(processKey(fileName), resourceClass) .addModifiers(*getPropertyModifiers()) .apply { - getPropertyInitializer(fileName)?.let { initializer(it) } + getPropertyInitializer( + fileName = fileName, + fileExtension = fileExtension + )?.let { initializer(it) } } .build() } @@ -62,11 +73,15 @@ abstract class FilesGenerator( ) { } + protected fun processKey(key: String): String { + return key.replace("-", "_") + } + abstract fun getClassModifiers(): Array abstract fun getPropertyModifiers(): Array - abstract fun getPropertyInitializer(fileName: String): CodeBlock? + abstract fun getPropertyInitializer(fileName: String, fileExtension: String): CodeBlock? data class FileSpec( val key: String, diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt index bbff1984..96fbb9fb 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt @@ -22,7 +22,7 @@ class AndroidFilesGenerator( override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - override fun getPropertyInitializer(fileName: String): CodeBlock? { + override fun getPropertyInitializer(fileName: String, fileExtension: String): CodeBlock? { return CodeBlock.of("FileResource(rawResId = R.raw.%L)", keyToResourceId(fileName)) } diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt index 1b72e365..c6592dc2 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt @@ -7,7 +7,6 @@ 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.FontsGenerator import org.gradle.api.file.FileTree class CommonFilesGenerator( @@ -19,5 +18,5 @@ class CommonFilesGenerator( override fun getPropertyModifiers(): Array = emptyArray() - override fun getPropertyInitializer(fileName: String): CodeBlock? = null + override fun getPropertyInitializer(fileName: String, fileExtension: String): CodeBlock? = null } diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosFilesGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosFilesGenerator.kt index 2b32aecb..cb0e2ac5 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosFilesGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosFilesGenerator.kt @@ -19,10 +19,11 @@ class IosFilesGenerator( override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - override fun getPropertyInitializer(fileName: String): CodeBlock? { + override fun getPropertyInitializer(fileName: String, fileExtension: String): CodeBlock? { return CodeBlock.of( - "FileResource(fileName = %S, bundle = ${IosMRGenerator.BUNDLE_PROPERTY_NAME})", - fileName + "FileResource(fileName = %S, extension = %S,bundle = ${IosMRGenerator.BUNDLE_PROPERTY_NAME})", + fileName, + fileExtension ) } diff --git a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/FileResource.kt b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/FileResource.kt index 36b57dc3..151ed74f 100644 --- a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/FileResource.kt +++ b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/FileResource.kt @@ -18,17 +18,19 @@ import platform.Foundation.stringWithContentsOfFile actual class FileResource( val fileName: String, + val extension: String, val bundle: NSBundle = NSBundle.mainBundle ) { - val path: String get() = bundle.pathForResource(name = fileName, ofType = null, inDirectory = "files")!! - val url: NSURL get() = bundle.URLForResource(name = fileName, withExtension = null, subdirectory = "files")!! + val path: String get() = bundle.pathForResource(name = fileName, ofType = extension, inDirectory = "files")!! + val url: NSURL get() = bundle.URLForResource(name = fileName, withExtension = extension, subdirectory = "files")!! fun readText(): String { + val filePath = path val (result: String?, error: NSError?) = memScoped { val p = alloc>() val result: String? = runCatching { NSString.stringWithContentsOfFile( - path = path, + path = filePath, encoding = NSUTF8StringEncoding, error = p.ptr ) diff --git a/sample/android-app/src/main/java/com/icerockdev/MainActivity.kt b/sample/android-app/src/main/java/com/icerockdev/MainActivity.kt index 79aadac2..ffaf8e1b 100755 --- a/sample/android-app/src/main/java/com/icerockdev/MainActivity.kt +++ b/sample/android-app/src/main/java/com/icerockdev/MainActivity.kt @@ -6,6 +6,7 @@ package com.icerockdev import android.content.Context import android.os.Bundle +import android.util.Log import android.widget.ImageView import android.widget.TextView import androidx.appcompat.app.AppCompatActivity @@ -33,6 +34,12 @@ class MainActivity : AppCompatActivity() { stringDescTextView.text = Testing.getStringDesc().toString(context = this) stringDescTextView.typeface = Testing.getFont2().getTypeface(context = this) + + listOf( + Testing.getTextFile().readText(context = this), + Testing.getJsonFile().readText(context = this), + Testing.getNestedJsonFile().readText(context = this) + ).forEach { Log.d(MainActivity::class.java.simpleName, it) } } /** @@ -41,5 +48,4 @@ class MainActivity : AppCompatActivity() { override fun attachBaseContext(newBase: Context) { super.attachBaseContext(LocaleHandler.updateLocale(newBase)) } - } diff --git a/sample/ios-app/src/TestViewController.swift b/sample/ios-app/src/TestViewController.swift index d07e7c3b..bb367c3f 100755 --- a/sample/ios-app/src/TestViewController.swift +++ b/sample/ios-app/src/TestViewController.swift @@ -25,6 +25,13 @@ class TestViewController: UIViewController { stringDescTextView.text = testing.getStringDesc().localized() stringDescTextView.font = testing.getFont2().uiFont(withSize: 14.0) + + [ + testing.getTextFile(), + testing.getJsonFile(), + testing.getNestedJsonFile() + ].map { $0.readText() } + .forEach { print($0) } } } diff --git a/sample/mpp-library/nested-module/src/commonMain/kotlin/com/icerockdev/library/nested/Testing.kt b/sample/mpp-library/nested-module/src/commonMain/kotlin/com/icerockdev/library/nested/Testing.kt index 7a1a5288..02c7a61a 100644 --- a/sample/mpp-library/nested-module/src/commonMain/kotlin/com/icerockdev/library/nested/Testing.kt +++ b/sample/mpp-library/nested-module/src/commonMain/kotlin/com/icerockdev/library/nested/Testing.kt @@ -4,9 +4,14 @@ package com.icerockdev.library.nested +import dev.icerock.moko.resources.FileResource import dev.icerock.moko.resources.desc.StringDesc import dev.icerock.moko.resources.desc.desc fun nestedTest(): StringDesc { return MR.strings.nested_test.desc() } + +fun nestedFile(): FileResource { + return MR.files.nested_test +} diff --git a/sample/mpp-library/nested-module/src/commonMain/resources/MR/files/nested-test.json b/sample/mpp-library/nested-module/src/commonMain/resources/MR/files/nested-test.json new file mode 100644 index 00000000..f75453a2 --- /dev/null +++ b/sample/mpp-library/nested-module/src/commonMain/resources/MR/files/nested-test.json @@ -0,0 +1,25 @@ +{ + "glossary": { + "title": "example glossary", + "GlossDiv": { + "title": "S", + "GlossList": { + "GlossEntry": { + "ID": "SGML", + "SortAs": "SGML", + "GlossTerm": "Standard Generalized Markup Language", + "Acronym": "SGML", + "Abbrev": "ISO 8879:1986", + "GlossDef": { + "para": "A meta-markup language, used to create markup languages such as DocBook.", + "GlossSeeAlso": [ + "GML", + "XML" + ] + }, + "GlossSee": "markup" + } + } + } + } +} \ No newline at end of file diff --git a/sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library/Testing.kt b/sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library/Testing.kt index c3463f8b..f8039801 100644 --- a/sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library/Testing.kt +++ b/sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library/Testing.kt @@ -4,11 +4,13 @@ package com.icerockdev.library +import com.icerockdev.library.nested.nestedFile +import com.icerockdev.library.nested.nestedTest +import dev.icerock.moko.resources.FileResource import dev.icerock.moko.resources.ImageResource import dev.icerock.moko.resources.desc.StringDesc import dev.icerock.moko.resources.desc.desc import dev.icerock.moko.resources.desc.plus -import com.icerockdev.library.nested.nestedTest object Testing { fun getStrings(): List { @@ -84,4 +86,16 @@ object Testing { StringDesc.localeType = if (lang != null) StringDesc.LocaleType.Custom(lang) else StringDesc.LocaleType.System } + + fun getTextFile(): FileResource { + return MR.files.test + } + + fun getJsonFile(): FileResource { + return MR.files.some + } + + fun getNestedJsonFile(): FileResource { + return nestedFile() + } } diff --git a/sample/mpp-library/src/commonMain/resources/MR/files/some.json b/sample/mpp-library/src/commonMain/resources/MR/files/some.json new file mode 100644 index 00000000..e35c9686 --- /dev/null +++ b/sample/mpp-library/src/commonMain/resources/MR/files/some.json @@ -0,0 +1,4 @@ +{ + "key": "value", + "number": 9 +} \ No newline at end of file diff --git a/sample/mpp-library/src/commonMain/resources/MR/files/test.txt b/sample/mpp-library/src/commonMain/resources/MR/files/test.txt new file mode 100644 index 00000000..59a1a48a --- /dev/null +++ b/sample/mpp-library/src/commonMain/resources/MR/files/test.txt @@ -0,0 +1 @@ +it's just test text file \ No newline at end of file From b5e82e6e6589064d23ae7ad9593ade7bf549819e Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 4 May 2020 10:59:15 +0700 Subject: [PATCH 38/54] #44 file property key and filename fix --- .../gradle/generator/FilesGenerator.kt | 23 +++++-------------- .../android/AndroidFilesGenerator.kt | 6 ++--- .../generator/common/CommonFilesGenerator.kt | 2 +- .../gradle/generator/ios/IosFilesGenerator.kt | 6 ++--- 4 files changed, 13 insertions(+), 24 deletions(-) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt index bc6dcf81..3692f3d7 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/FilesGenerator.kt @@ -24,7 +24,7 @@ abstract class FilesGenerator( override fun generate(resourcesGenerationDir: File): TypeSpec { val fileSpecs = inputFileTree.map { file -> FileSpec( - key = file.nameWithoutExtension, + key = processKey(file.nameWithoutExtension), file = file ) }.sortedBy { it.key } @@ -38,31 +38,20 @@ abstract class FilesGenerator( @Suppress("SpreadOperator") classBuilder.addModifiers(*getClassModifiers()) - keys.forEach { - classBuilder.addProperty( - generateFileProperty( - fileName = it.key, - fileExtension = it.file.extension - ) - ) - } + keys.forEach { classBuilder.addProperty(generateFileProperty(it)) } return classBuilder.build() } override fun getImports(): List = emptyList() private fun generateFileProperty( - fileName: String, - fileExtension: String + fileSpec: FileSpec ): PropertySpec { @Suppress("SpreadOperator") - return PropertySpec.builder(processKey(fileName), resourceClass) + return PropertySpec.builder(fileSpec.key, resourceClass) .addModifiers(*getPropertyModifiers()) .apply { - getPropertyInitializer( - fileName = fileName, - fileExtension = fileExtension - )?.let { initializer(it) } + getPropertyInitializer(fileSpec)?.let { initializer(it) } } .build() } @@ -81,7 +70,7 @@ abstract class FilesGenerator( abstract fun getPropertyModifiers(): Array - abstract fun getPropertyInitializer(fileName: String, fileExtension: String): CodeBlock? + abstract fun getPropertyInitializer(fileSpec: FileSpec): CodeBlock? data class FileSpec( val key: String, diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt index 96fbb9fb..e960e919 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidFilesGenerator.kt @@ -22,8 +22,8 @@ class AndroidFilesGenerator( override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - override fun getPropertyInitializer(fileName: String, fileExtension: String): CodeBlock? { - return CodeBlock.of("FileResource(rawResId = R.raw.%L)", keyToResourceId(fileName)) + override fun getPropertyInitializer(fileSpec: FileSpec): CodeBlock? { + return CodeBlock.of("FileResource(rawResId = R.raw.%L)", keyToResourceId(fileSpec.key)) } override fun getImports(): List = listOf( @@ -44,6 +44,6 @@ class AndroidFilesGenerator( } private fun keyToResourceId(key: String): String { - return key.replace("-", "_").toLowerCase(Locale.ROOT) + return key.toLowerCase(Locale.ROOT) } } diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt index c6592dc2..84573c1c 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/common/CommonFilesGenerator.kt @@ -18,5 +18,5 @@ class CommonFilesGenerator( override fun getPropertyModifiers(): Array = emptyArray() - override fun getPropertyInitializer(fileName: String, fileExtension: String): CodeBlock? = null + override fun getPropertyInitializer(fileSpec: FileSpec): CodeBlock? = null } diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosFilesGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosFilesGenerator.kt index cb0e2ac5..fa0b2ccf 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosFilesGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosFilesGenerator.kt @@ -19,11 +19,11 @@ class IosFilesGenerator( override fun getPropertyModifiers(): Array = arrayOf(KModifier.ACTUAL) - override fun getPropertyInitializer(fileName: String, fileExtension: String): CodeBlock? { + override fun getPropertyInitializer(fileSpec: FileSpec): CodeBlock? { return CodeBlock.of( "FileResource(fileName = %S, extension = %S,bundle = ${IosMRGenerator.BUNDLE_PROPERTY_NAME})", - fileName, - fileExtension + fileSpec.file.nameWithoutExtension, + fileSpec.file.extension ) } From e3cb3ca32f9a1ecb688ada0fe22613ef9d3d29f1 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 4 May 2020 11:27:24 +0700 Subject: [PATCH 39/54] #50 update gradle wrapper to 6.3 --- gradle/wrapper/gradle-wrapper.jar | Bin 55616 -> 58694 bytes gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 33 ++++++++++------------- gradlew.bat | 3 +++ 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 5c2d1cf016b3885f6930543d57b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Kq)5?vVpI8dBOf!80avL0G{)bsLgRoFl$^5xGV6F zc@A)pAVJ*;9^}8bmLL%Re~TcNVI)Zs4XaZT?=iuV$Ins!tIWr4$^9dw2QN;F0@w6O zW|cV|m@^4O9^Vf6uOGD`N%;5Xh%oZ_s``J0tj7NcSx9YjnnD1cmq`@P7Db|p9AR{S zJo2%jR^ZZ2zMok34uPB3vs3s7()LRBzv1qKStB7hIKK;8l*Xf=Bd2=yYtY+puF?i4Y1 z{tk(%T}FZua|l2%fM^PUp%GNz%eOG(|JOcfAQ0taHDC-R30)!);Ov|zP!~cn>F+ax zs`D`9u}R%Azml-u!sK`^q8kjXpGN@XktEmcc{$|&hj>g7i0U!7+GvuFp=z)pSgAU|kJL=^4GgOVVM*iQD>|Lt&*E^uwx5jf}ucZQXTJs}E=^n%SR7Xbb~ Z5H)%VJiSWIAOn$sbP+#;Q{V4m{s)AkOUM8K diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 5028f28f..a4b44297 100755 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 8e25e6c1..2fe81a7d 100755 --- a/gradlew +++ b/gradlew @@ -125,8 +125,8 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` JAVACMD=`cygpath --unix "$JAVACMD"` @@ -154,19 +154,19 @@ if $cygwin ; then else eval `echo args$i`="\"$arg\"" fi - i=$((i+1)) + i=`expr $i + 1` done case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi @@ -175,14 +175,9 @@ save () { for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done echo " " } -APP_ARGS=$(save "$@") +APP_ARGS=`save "$@"` # Collect all arguments for the java command, following the shell quoting and substitution rules eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi - exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index 9618d8d9..62bd9b9c 100755 --- a/gradlew.bat +++ b/gradlew.bat @@ -29,6 +29,9 @@ if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" From 61b4b4058511872d80f9f1d86515f1b075be2a2a Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 4 May 2020 11:37:03 +0700 Subject: [PATCH 40/54] #50 fix compilation with new gradle --- build.gradle.kts | 17 +++++++++++++++++ settings.gradle.kts | 19 ------------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 52424b66..b8f7abd0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,6 +2,23 @@ * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ +buildscript { + repositories { + mavenLocal() + + jcenter() + google() + + maven { url = uri("https://dl.bintray.com/kotlin/kotlin") } + maven { url = uri("https://kotlin.bintray.com/kotlinx") } + maven { url = uri("https://plugins.gradle.org/m2/") } + maven { url = uri("https://dl.bintray.com/icerockdev/plugins") } + } + dependencies { + Deps.plugins.values.forEach { classpath(it) } + } +} + allprojects { repositories { mavenLocal() diff --git a/settings.gradle.kts b/settings.gradle.kts index c9a2e834..66b4dfa2 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -2,25 +2,6 @@ * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -pluginManagement { - repositories { - mavenLocal() - - jcenter() - google() - - maven { url = uri("https://dl.bintray.com/kotlin/kotlin") } - maven { url = uri("https://kotlin.bintray.com/kotlinx") } - maven { url = uri("https://plugins.gradle.org/m2/") } - maven { url = uri("https://dl.bintray.com/icerockdev/plugins") } - } - resolutionStrategy.eachPlugin { - val module = Deps.plugins[requested.id.id] ?: return@eachPlugin - - useModule(module) - } -} - enableFeaturePreview("GRADLE_METADATA") val properties = startParameter.projectProperties From fd64fb335ad8f8e126b76c4b25285a835170e746 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 4 May 2020 11:37:16 +0700 Subject: [PATCH 41/54] #50 remove old workaround --- build.gradle.kts | 3 --- 1 file changed, 3 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index b8f7abd0..7c324584 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -30,9 +30,6 @@ allprojects { maven { url = uri("https://kotlin.bintray.com/kotlinx") } maven { url = uri("https://dl.bintray.com/icerockdev/moko") } } - - // workaround for https://youtrack.jetbrains.com/issue/KT-27170 - configurations.create("compileClasspath") } tasks.register("clean", Delete::class).configure { From b4b79f7841f2ba307f1c15a41708c2300a59fde9 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 4 May 2020 11:37:28 +0700 Subject: [PATCH 42/54] #50 clean settings.gradle --- settings.gradle.kts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index 66b4dfa2..de8206fc 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -4,14 +4,12 @@ enableFeaturePreview("GRADLE_METADATA") -val properties = startParameter.projectProperties - -// ./gradlew -PlibraryPublish :gradle-plugin:publishPluginPublicationToMavenLocal :resources:publishToMavenLocal +val properties: Map = startParameter.projectProperties val libraryPublish: Boolean = properties.containsKey("libraryPublish") include(":resources") include(":gradle-plugin") -if(!libraryPublish) { +if (!libraryPublish) { include(":sample:android-app") include(":sample:mpp-library", ":sample:mpp-library:nested-module") include(":sample:mpp-conditional") From 55318ceabf165a7f42e7131702feee9a7f791f62 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 4 May 2020 12:00:48 +0700 Subject: [PATCH 43/54] #50 update plugins handling --- build.gradle.kts | 11 +++++- buildSrc/src/main/kotlin/Deps.kt | 50 +++++++++++++++++++------- buildSrc/src/main/kotlin/PluginDesc.kt | 25 +++++++++++++ gradle-plugin/build.gradle.kts | 6 ++-- resources/build.gradle.kts | 8 ++--- 5 files changed, 79 insertions(+), 21 deletions(-) create mode 100644 buildSrc/src/main/kotlin/PluginDesc.kt diff --git a/build.gradle.kts b/build.gradle.kts index 7c324584..27524058 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,7 +15,16 @@ buildscript { maven { url = uri("https://dl.bintray.com/icerockdev/plugins") } } dependencies { - Deps.plugins.values.forEach { classpath(it) } + with(Deps.Plugins) { + listOf( + androidApplication, + androidLibrary, + kotlinMultiplatform, + kotlinKapt, + kotlinAndroid, + mokoResources + ) + }.let { plugins(it) } } } diff --git a/buildSrc/src/main/kotlin/Deps.kt b/buildSrc/src/main/kotlin/Deps.kt index f43b3d1b..7d2e640e 100755 --- a/buildSrc/src/main/kotlin/Deps.kt +++ b/buildSrc/src/main/kotlin/Deps.kt @@ -4,12 +4,45 @@ object Deps { object Plugins { - const val android = + private const val androidPluginModule = "com.android.tools.build:gradle:${Versions.Plugins.android}" - const val kotlin = + val androidApplication = PluginDesc( + id = "com.android.application", + module = androidPluginModule + ) + val androidLibrary = PluginDesc( + id = "com.android.library", + module = androidPluginModule + ) + + private const val kotlinPluginModule = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.Plugins.kotlin}" - const val mokoResources = - "dev.icerock.moko:resources-generator:${Versions.Plugins.mokoResources}" + val kotlinMultiplatform = PluginDesc( + id = "org.jetbrains.kotlin.multiplatform", + module = kotlinPluginModule + ) + val kotlinKapt = PluginDesc( + id = "kotlin-kapt", + module = kotlinPluginModule + ) + val kotlinAndroid = PluginDesc( + id = "kotlin-android", + module = kotlinPluginModule + ) + val kotlinAndroidExtensions = PluginDesc( + id = "kotlin-android-extensions", + module = kotlinPluginModule + ) + + val mobileMultiplatform = PluginDesc( + id = "dev.icerock.mobile.multiplatform", + module = "dev.icerock:mobile-multiplatform:0.6.1" + ) + + val mokoResources = PluginDesc( + id = "dev.icerock.mobile.multiplatform-resources", + module = "dev.icerock.moko:resources-generator:${Versions.Plugins.mokoResources}" + ) } object Libs { @@ -55,13 +88,4 @@ object Deps { const val detektFormatting = "io.gitlab.arturbosch.detekt:detekt-formatting:${Versions.Plugins.detekt}" } } - - val plugins: Map = mapOf( - "com.android.application" to Plugins.android, - "com.android.library" to Plugins.android, - "org.jetbrains.kotlin.multiplatform" to Plugins.kotlin, - "kotlin-kapt" to Plugins.kotlin, - "kotlin-android" to Plugins.kotlin, - "dev.icerock.mobile.multiplatform-resources" to Plugins.mokoResources - ) } diff --git a/buildSrc/src/main/kotlin/PluginDesc.kt b/buildSrc/src/main/kotlin/PluginDesc.kt new file mode 100644 index 00000000..19a35719 --- /dev/null +++ b/buildSrc/src/main/kotlin/PluginDesc.kt @@ -0,0 +1,25 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +import org.gradle.kotlin.dsl.DependencyHandlerScope +import org.gradle.plugin.use.PluginDependenciesSpec + +data class PluginDesc( + val id: String, + val module: String +) + +fun DependencyHandlerScope.plugin(pluginDesc: PluginDesc) { + "classpath"(pluginDesc.module) +} + +fun DependencyHandlerScope.plugins(pluginDescList: List) { + pluginDescList + .distinctBy { it.module } + .forEach { plugin(it) } +} + +fun PluginDependenciesSpec.plugin(pluginDesc: PluginDesc) { + id(pluginDesc.id) +} diff --git a/gradle-plugin/build.gradle.kts b/gradle-plugin/build.gradle.kts index b2deb892..96635e5a 100644 --- a/gradle-plugin/build.gradle.kts +++ b/gradle-plugin/build.gradle.kts @@ -3,7 +3,7 @@ */ plugins { - id("org.gradle.kotlin.kotlin-dsl") version "1.3.6" + `kotlin-dsl` id("org.gradle.maven-publish") id("io.gitlab.arturbosch.detekt") version(Versions.Plugins.detekt) } @@ -17,8 +17,8 @@ repositories { dependencies { implementation(Deps.Libs.Jvm.kotlinPoet) - compileOnly(Deps.Plugins.kotlin) - compileOnly(Deps.Plugins.android) + compileOnly(Deps.Plugins.kotlinMultiplatform.module) + compileOnly(Deps.Plugins.androidLibrary.module) implementation(Deps.Libs.Jvm.apacheCommonsText) detektPlugins(Deps.Libs.Jvm.detektFormatting) } diff --git a/resources/build.gradle.kts b/resources/build.gradle.kts index a62d2b2e..fd082cbf 100644 --- a/resources/build.gradle.kts +++ b/resources/build.gradle.kts @@ -3,10 +3,10 @@ */ plugins { - id("com.android.library") - id("org.jetbrains.kotlin.multiplatform") - id("kotlin-android-extensions") - id("dev.icerock.mobile.multiplatform") + plugin(Deps.Plugins.androidLibrary) + plugin(Deps.Plugins.kotlinMultiplatform) + plugin(Deps.Plugins.kotlinAndroidExtensions) + plugin(Deps.Plugins.mobileMultiplatform) id("maven-publish") } From d71d7d9ae837e34180d3db1cdac91e2fa8f09b25 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 4 May 2020 12:59:58 +0700 Subject: [PATCH 44/54] #59 implement multiple string/plural files in resources --- .../icerock/gradle/generator/PluralsGenerator.kt | 13 +++++++++++-- .../icerock/gradle/generator/StringsGenerator.kt | 13 +++++++++++-- .../commonMain/resources/MR/base/plurals-test.xml | 11 +++++++++++ .../src/commonMain/resources/MR/base/plurals.xml | 8 -------- .../commonMain/resources/MR/base/strings-test.xml | 7 +++++++ .../src/commonMain/resources/MR/base/strings.xml | 4 ---- 6 files changed, 40 insertions(+), 16 deletions(-) create mode 100644 sample/mpp-library/src/commonMain/resources/MR/base/plurals-test.xml create mode 100644 sample/mpp-library/src/commonMain/resources/MR/base/strings-test.xml diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt index 3f9f6922..c39195e0 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt @@ -20,10 +20,19 @@ abstract class PluralsGenerator( ) : BaseGenerator() { override fun loadLanguageMap(): Map> { - return pluralsFileTree.associate { file -> + return pluralsFileTree.map { file -> val language: LanguageType = 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 + } } } @@ -72,7 +81,7 @@ abstract class PluralsGenerator( private val info: SourceInfo, private val iosBaseLocalizationRegion: String ) : ResourceGeneratorFeature { - private val stringsFileTree = info.commonResources.matching { include("MR/**/plurals.xml") } + private val stringsFileTree = info.commonResources.matching { include("MR/**/plurals*.xml") } override fun createCommonGenerator(): MRGenerator.Generator { return CommonPluralsGenerator(stringsFileTree) } diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt index 5d40faec..d537571c 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt @@ -19,10 +19,19 @@ abstract class StringsGenerator( private val stringsFileTree: FileTree ) : BaseGenerator() { override fun loadLanguageMap(): Map> { - return stringsFileTree.associate { file -> + return stringsFileTree.map { file -> val language: LanguageType = 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 + } } } @@ -67,7 +76,7 @@ abstract class StringsGenerator( private val info: SourceInfo, private val iosBaseLocalizationRegion: String ) : ResourceGeneratorFeature { - private val stringsFileTree = info.commonResources.matching { include("MR/**/strings.xml") } + private val stringsFileTree = info.commonResources.matching { include("MR/**/strings*.xml") } override fun createCommonGenerator(): MRGenerator.Generator { return CommonStringsGenerator(stringsFileTree) } diff --git a/sample/mpp-library/src/commonMain/resources/MR/base/plurals-test.xml b/sample/mpp-library/src/commonMain/resources/MR/base/plurals-test.xml new file mode 100644 index 00000000..9d786f6e --- /dev/null +++ b/sample/mpp-library/src/commonMain/resources/MR/base/plurals-test.xml @@ -0,0 +1,11 @@ + + + + zero + one + two + few + many + other + + \ No newline at end of file diff --git a/sample/mpp-library/src/commonMain/resources/MR/base/plurals.xml b/sample/mpp-library/src/commonMain/resources/MR/base/plurals.xml index bdd7e05e..3b700d0d 100644 --- a/sample/mpp-library/src/commonMain/resources/MR/base/plurals.xml +++ b/sample/mpp-library/src/commonMain/resources/MR/base/plurals.xml @@ -1,13 +1,5 @@ - - zero - one - two - few - many - other - no items %d item diff --git a/sample/mpp-library/src/commonMain/resources/MR/base/strings-test.xml b/sample/mpp-library/src/commonMain/resources/MR/base/strings-test.xml new file mode 100644 index 00000000..e4460b00 --- /dev/null +++ b/sample/mpp-library/src/commonMain/resources/MR/base/strings-test.xml @@ -0,0 +1,7 @@ + + + test + test 2 + test 3 + test 4 + \ No newline at end of file diff --git a/sample/mpp-library/src/commonMain/resources/MR/base/strings.xml b/sample/mpp-library/src/commonMain/resources/MR/base/strings.xml index 93fd1d49..a2fb6d81 100644 --- a/sample/mpp-library/src/commonMain/resources/MR/base/strings.xml +++ b/sample/mpp-library/src/commonMain/resources/MR/base/strings.xml @@ -1,9 +1,5 @@ - test - test 2 - test 3 - test 4 Test Project Test data %d CHOOSE PORTFOLIO & AMOUNT From 863f53fc72546510d67ff2045ae5cc9b9f468f2e Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 4 May 2020 19:19:53 +0700 Subject: [PATCH 45/54] #60 enable anycase keys in strings and plurals on android --- .../icerock/gradle/generator/android/AndroidPluralsGenerator.kt | 2 +- .../icerock/gradle/generator/android/AndroidStringsGenerator.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt index d0d08811..d6b2d783 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidPluralsGenerator.kt @@ -74,6 +74,6 @@ class AndroidPluralsGenerator( } private fun processKey(key: String): String { - return key.replace(".", "_").toLowerCase() + return key.replace(".", "_") } } diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt index d3b54645..01766733 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/android/AndroidStringsGenerator.kt @@ -67,6 +67,6 @@ class AndroidStringsGenerator( } private fun processKey(key: String): String { - return key.replace(".", "_").toLowerCase() + return key.replace(".", "_") } } From 2b69dd1b0b2f999773806415bcb12a4069c674da Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 4 May 2020 19:51:38 +0700 Subject: [PATCH 46/54] #61 remove export usage (not required now) --- sample/mpp-library/build.gradle.kts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/sample/mpp-library/build.gradle.kts b/sample/mpp-library/build.gradle.kts index bac506e3..ab802c9d 100644 --- a/sample/mpp-library/build.gradle.kts +++ b/sample/mpp-library/build.gradle.kts @@ -22,11 +22,7 @@ android { } } -setupFramework( - exports = listOf( - Deps.Libs.MultiPlatform.mokoResources - ) -) +setupFramework(exports = emptyList()) dependencies { mppLibrary(Deps.Libs.MultiPlatform.kotlinStdLib) From 80cd094cdd513e40ec194f30b21a859f0bc18d75 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 4 May 2020 19:53:34 +0700 Subject: [PATCH 47/54] #61 remove old faq --- README.md | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/README.md b/README.md index 35c3e40e..2f41d3c8 100755 --- a/README.md +++ b/README.md @@ -10,9 +10,8 @@ This is a Kotlin MultiPlatform library that provides access to the resources on - [Versions](#versions) - [Installation](#installation) - [Usage](#usage) -- [FAQ](#faq) - [Samples](#samples) -- [Set Up Locally](#setup-locally) +- [Set Up Locally](#set-up-locally) - [Contributing](#contributing) - [License](#license) @@ -282,31 +281,6 @@ We got autogenerated `MR.fonts.Raleway.italic`, `MR.fonts.Raleway.regular`, `MR. - Android: `textView.typeface = font.getTypeface(context = this)` - iOS: `textView.font = font.uiFont(withSize: 14.0)` -## FAQ -If on iOS you see just localization keys - add to iOS framework exports `moko-resources`. -[Gradle - exports](https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#exporting-dependencies-to-binaries) -sample with [mobile-multiplatform-plugin](https://github.com/icerockdev/mobile-multiplatform-gradle-plugin): -``` -setupFramework( - exports = listOf(Deps.Libs.MultiPlatform.mokoResources) -) -``` -sample without our plugin: -``` -kotlin { - iosX64().binaries { - framework { - export("dev.icerock.moko:resources-iosx64:0.9.0") - } - } - iosArm64().binaries { - framework { - export("dev.icerock.moko:resources-iosarm64:0.9.0") - } - } -} -``` - ## Samples Please see more examples in the [sample directory](sample). From 61007fb3abc4052113430b3aebfaf61921c233ef Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 4 May 2020 20:09:49 +0700 Subject: [PATCH 48/54] #44 close reader after usage --- .../kotlin/dev/icerock/moko/resources/FileResource.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/src/androidMain/kotlin/dev/icerock/moko/resources/FileResource.kt b/resources/src/androidMain/kotlin/dev/icerock/moko/resources/FileResource.kt index 8c473bc2..c1b176ad 100644 --- a/resources/src/androidMain/kotlin/dev/icerock/moko/resources/FileResource.kt +++ b/resources/src/androidMain/kotlin/dev/icerock/moko/resources/FileResource.kt @@ -19,6 +19,6 @@ actual class FileResource( val resources: Resources = context.resources val inputStream: InputStream = resources.openRawResource(rawResId) val bufferedReader = BufferedReader(InputStreamReader(inputStream)) - return bufferedReader.readText() + return bufferedReader.use { it.readText() } } } From d037e85e1c37ed96c632305226dd70e33bd0429d Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 4 May 2020 20:16:36 +0700 Subject: [PATCH 49/54] #44 fix publish --- build.gradle.kts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 27524058..aba3fc27 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,14 +15,16 @@ buildscript { maven { url = uri("https://dl.bintray.com/icerockdev/plugins") } } dependencies { + val libraryPublish: Boolean = properties.containsKey("libraryPublish") + with(Deps.Plugins) { - listOf( + listOfNotNull( androidApplication, androidLibrary, kotlinMultiplatform, kotlinKapt, kotlinAndroid, - mokoResources + if(!libraryPublish) mokoResources else null ) }.let { plugins(it) } } From 951aa2aa1d7b1860414f1177e0876a9e1ca60181 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 4 May 2020 20:58:53 +0700 Subject: [PATCH 50/54] #62 StringDesc rework for extensions --- buildSrc/src/main/kotlin/Deps.kt | 5 + buildSrc/src/main/kotlin/Versions.kt | 1 + resources/build.gradle.kts | 2 + .../resources/desc/CompositionStringDesc.kt | 23 +++ .../desc/PluralFormattedStringDesc.kt | 23 +++ .../moko/resources/desc/PluralStringDesc.kt | 20 +++ .../moko/resources/desc/RawStringDesc.kt | 16 ++ .../desc/ResourceFormattedStringDesc.kt | 21 +++ .../moko/resources/desc/ResourceStringDesc.kt | 19 +++ .../icerock/moko/resources/desc/StringDesc.kt | 117 +------------- .../dev/icerock/moko/resources/desc/Utils.kt | 35 ++++ .../resources/desc/CompositionStringDesc.kt | 13 ++ .../desc/PluralFormattedStringDesc.kt | 23 +++ .../moko/resources/desc/PluralStringDesc.kt | 13 ++ .../moko/resources/desc/RawStringDesc.kt | 12 ++ .../desc/ResourceFormattedStringDesc.kt | 21 +++ .../moko/resources/desc/ResourceStringDesc.kt | 13 ++ .../icerock/moko/resources/desc/StringDesc.kt | 14 +- .../resources/desc/CompositionStringDesc.kt | 14 ++ .../desc/PluralFormattedStringDesc.kt | 24 +++ .../moko/resources/desc/PluralStringDesc.kt | 23 +++ .../moko/resources/desc/RawStringDesc.kt | 15 ++ .../desc/ResourceFormattedStringDesc.kt | 16 ++ .../moko/resources/desc/ResourceStringDesc.kt | 16 ++ .../icerock/moko/resources/desc/StringDesc.kt | 150 +----------------- .../dev/icerock/moko/resources/desc/Utils.kt | 81 ++++++++++ .../main/java/com/icerockdev/LocaleHandler.kt | 3 +- .../main/java/com/icerockdev/MainActivity.kt | 1 - .../com/icerockdev/SelectLanguageActivity.kt | 2 +- .../com/icerockdev/library/nested/Testing.kt | 2 +- .../kotlin/com/icerockdev/library/Testing.kt | 8 +- 31 files changed, 468 insertions(+), 278 deletions(-) create mode 100644 resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/CompositionStringDesc.kt create mode 100644 resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/PluralFormattedStringDesc.kt create mode 100644 resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/PluralStringDesc.kt create mode 100644 resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/RawStringDesc.kt create mode 100644 resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/ResourceFormattedStringDesc.kt create mode 100644 resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/ResourceStringDesc.kt create mode 100644 resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/Utils.kt create mode 100644 resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/CompositionStringDesc.kt create mode 100644 resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/PluralFormattedStringDesc.kt create mode 100644 resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/PluralStringDesc.kt create mode 100644 resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/RawStringDesc.kt create mode 100644 resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/ResourceFormattedStringDesc.kt create mode 100644 resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/ResourceStringDesc.kt create mode 100644 resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/CompositionStringDesc.kt create mode 100644 resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/PluralFormattedStringDesc.kt create mode 100644 resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/PluralStringDesc.kt create mode 100644 resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/RawStringDesc.kt create mode 100644 resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/ResourceFormattedStringDesc.kt create mode 100644 resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/ResourceStringDesc.kt create mode 100644 resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/Utils.kt diff --git a/buildSrc/src/main/kotlin/Deps.kt b/buildSrc/src/main/kotlin/Deps.kt index 7d2e640e..8b9b6f6e 100755 --- a/buildSrc/src/main/kotlin/Deps.kt +++ b/buildSrc/src/main/kotlin/Deps.kt @@ -80,6 +80,11 @@ object Deps { iosX64 = "dev.icerock.moko:resources-iosx64:${Versions.Libs.MultiPlatform.mokoResources}", iosArm64 = "dev.icerock.moko:resources-iosarm64:${Versions.Libs.MultiPlatform.mokoResources}" ) + val mokoParcelize = MultiPlatformLibrary( + common = "dev.icerock.moko:parcelize:${Versions.Libs.MultiPlatform.mokoParcelize}", + iosX64 = "dev.icerock.moko:parcelize-iosx64:${Versions.Libs.MultiPlatform.mokoParcelize}", + iosArm64 = "dev.icerock.moko:parcelize-iosarm64:${Versions.Libs.MultiPlatform.mokoParcelize}" + ) } object Jvm { diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index e1c80b5a..58d12ee3 100755 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -34,6 +34,7 @@ object Versions { object MultiPlatform { const val mokoResources = Versions.mokoResources + const val mokoParcelize = "0.3.0" } object Jvm { diff --git a/resources/build.gradle.kts b/resources/build.gradle.kts index fd082cbf..b3dd1a88 100644 --- a/resources/build.gradle.kts +++ b/resources/build.gradle.kts @@ -25,6 +25,8 @@ android { dependencies { mppLibrary(Deps.Libs.MultiPlatform.kotlinStdLib) + mppLibrary(Deps.Libs.MultiPlatform.mokoParcelize) + androidLibrary(Deps.Libs.Android.appCompat) } diff --git a/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/CompositionStringDesc.kt b/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/CompositionStringDesc.kt new file mode 100644 index 00000000..eaccccfb --- /dev/null +++ b/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/CompositionStringDesc.kt @@ -0,0 +1,23 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.moko.resources.desc + +import android.content.Context + +actual class CompositionStringDesc actual constructor( + val args: List, + val separator: String? +) : StringDesc { + override fun toString(context: Context): String { + return StringBuilder().apply { + args.forEachIndexed { index, stringDesc -> + if (index != 0 && separator != null) { + append(separator) + } + append(stringDesc.toString(context)) + } + }.toString() + } +} diff --git a/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/PluralFormattedStringDesc.kt b/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/PluralFormattedStringDesc.kt new file mode 100644 index 00000000..37ecf0ec --- /dev/null +++ b/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/PluralFormattedStringDesc.kt @@ -0,0 +1,23 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.moko.resources.desc + +import android.content.Context +import dev.icerock.moko.resources.PluralsResource + +actual class PluralFormattedStringDesc actual constructor( + val pluralsRes: PluralsResource, + val number: Int, + val args: List +) : StringDesc { + override fun toString(context: Context): String { + @Suppress("SpreadOperator") + return Utils.resourcesForContext(context).getQuantityString( + pluralsRes.resourceId, + number, + *Utils.processArgs(args, context) + ) + } +} diff --git a/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/PluralStringDesc.kt b/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/PluralStringDesc.kt new file mode 100644 index 00000000..0d180cb9 --- /dev/null +++ b/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/PluralStringDesc.kt @@ -0,0 +1,20 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.moko.resources.desc + +import android.content.Context +import dev.icerock.moko.parcelize.Parcelable +import dev.icerock.moko.parcelize.Parcelize +import dev.icerock.moko.resources.PluralsResource + +@Parcelize +actual class PluralStringDesc actual constructor( + val pluralsRes: PluralsResource, + val number: Int +) : StringDesc, Parcelable { + override fun toString(context: Context): String { + return Utils.resourcesForContext(context).getQuantityString(pluralsRes.resourceId, number) + } +} diff --git a/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/RawStringDesc.kt b/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/RawStringDesc.kt new file mode 100644 index 00000000..77118cc2 --- /dev/null +++ b/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/RawStringDesc.kt @@ -0,0 +1,16 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.moko.resources.desc + +import android.content.Context +import dev.icerock.moko.parcelize.Parcelable +import dev.icerock.moko.parcelize.Parcelize + +@Parcelize +actual class RawStringDesc actual constructor( + val string: String +) : StringDesc, Parcelable { + override fun toString(context: Context): String = string +} diff --git a/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/ResourceFormattedStringDesc.kt b/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/ResourceFormattedStringDesc.kt new file mode 100644 index 00000000..7c0b12e2 --- /dev/null +++ b/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/ResourceFormattedStringDesc.kt @@ -0,0 +1,21 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.moko.resources.desc + +import android.content.Context +import dev.icerock.moko.resources.StringResource + +actual class ResourceFormattedStringDesc actual constructor( + val stringRes: StringResource, + val args: List +) : StringDesc { + override fun toString(context: Context): String { + @Suppress("SpreadOperator") + return Utils.resourcesForContext(context).getString( + stringRes.resourceId, + *Utils.processArgs(args, context) + ) + } +} diff --git a/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/ResourceStringDesc.kt b/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/ResourceStringDesc.kt new file mode 100644 index 00000000..87430ba5 --- /dev/null +++ b/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/ResourceStringDesc.kt @@ -0,0 +1,19 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.moko.resources.desc + +import android.content.Context +import dev.icerock.moko.parcelize.Parcelable +import dev.icerock.moko.parcelize.Parcelize +import dev.icerock.moko.resources.StringResource + +@Parcelize +actual class ResourceStringDesc actual constructor( + val stringRes: StringResource +) : StringDesc, Parcelable { + override fun toString(context: Context): String { + return Utils.resourcesForContext(context).getString(stringRes.resourceId) + } +} diff --git a/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/StringDesc.kt b/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/StringDesc.kt index 24d21a87..0d23c87c 100644 --- a/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/StringDesc.kt +++ b/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/StringDesc.kt @@ -5,104 +5,19 @@ package dev.icerock.moko.resources.desc import android.content.Context -import android.content.res.Resources -import android.os.Build -import android.os.Parcelable -import dev.icerock.moko.resources.PluralsResource -import dev.icerock.moko.resources.StringResource -import kotlinx.android.parcel.Parcelize -import java.util.* +import java.util.Locale -actual sealed class StringDesc { - protected fun processArgs(args: List, context: Context): Array { - return args.toList().map { (it as? StringDesc)?.toString(context) ?: it }.toTypedArray() - } - - @Parcelize - actual data class Resource actual constructor(val stringRes: StringResource) : StringDesc(), Parcelable { - override fun toString(context: Context): String { - return resourcesForContext(context).getString(stringRes.resourceId) - } - } - - actual data class ResourceFormatted actual constructor( - val stringRes: StringResource, - val args: List - ) : StringDesc() { - override fun toString(context: Context): String { - return resourcesForContext(context).getString( - stringRes.resourceId, *processArgs(args, context) - ) - } - - actual constructor(stringRes: StringResource, vararg args: Any) : this( - stringRes, - args.toList() - ) - } - - @Parcelize - actual data class Plural actual constructor( - val pluralsRes: PluralsResource, - val number: Int - ) : StringDesc(), Parcelable { - override fun toString(context: Context): String { - return resourcesForContext(context).getQuantityString(pluralsRes.resourceId, number) - } - } - - actual data class PluralFormatted actual constructor( - val pluralsRes: PluralsResource, - val number: Int, - val args: List - ) : StringDesc() { - override fun toString(context: Context): String { - return resourcesForContext(context).getQuantityString( - pluralsRes.resourceId, - number, - *processArgs(args, context) - ) - } - - actual constructor(pluralsRes: PluralsResource, number: Int, vararg args: Any) : this( - pluralsRes, - number, - args.toList() - ) - } - - @Parcelize - actual data class Raw actual constructor( - val string: String - ) : StringDesc(), Parcelable { - override fun toString(context: Context): String { - return string - } - } - - actual data class Composition actual constructor(val args: List, val separator: String?) : - StringDesc() { - override fun toString(context: Context): String { - return StringBuilder().apply { - args.forEachIndexed { index, stringDesc -> - if (index != 0 && separator != null) { - append(separator) - } - append(stringDesc.toString(context)) - } - }.toString() - } - } - - abstract fun toString(context: Context): String +actual interface StringDesc { + fun toString(context: Context): String actual sealed class LocaleType { actual object System : LocaleType() { override val systemLocale: Locale? = null } - actual class Custom actual constructor(locale: String) : - LocaleType() { + actual class Custom actual constructor( + locale: String + ) : LocaleType() { override val systemLocale: Locale = Locale(locale) } @@ -110,26 +25,6 @@ actual sealed class StringDesc { } actual companion object { - private fun localizedContext(context: Context): Context { - if (localeType.systemLocale == null) return context - - val resources = context.resources - val config = resources.configuration - - return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { - config.setLocale(localeType.systemLocale) - context.createConfigurationContext(config) - } else { - config.locale = localeType.systemLocale - resources.updateConfiguration(config, resources.displayMetrics) - context - } - } - - private fun resourcesForContext(context: Context): Resources { - return localizedContext(context).resources - } - actual var localeType: LocaleType = LocaleType.System } } diff --git a/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/Utils.kt b/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/Utils.kt new file mode 100644 index 00000000..20937dff --- /dev/null +++ b/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/Utils.kt @@ -0,0 +1,35 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.moko.resources.desc + +import android.content.Context +import android.content.res.Resources +import android.os.Build + +object Utils { + fun processArgs(args: List, context: Context): Array { + return args.toList().map { (it as? StringDesc)?.toString(context) ?: it }.toTypedArray() + } + + fun resourcesForContext(context: Context): Resources { + return localizedContext(context).resources + } + + private fun localizedContext(context: Context): Context { + if (StringDesc.localeType.systemLocale == null) return context + + val resources = context.resources + val config = resources.configuration + + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + config.setLocale(StringDesc.localeType.systemLocale) + context.createConfigurationContext(config) + } else { + config.locale = StringDesc.localeType.systemLocale + resources.updateConfiguration(config, resources.displayMetrics) + context + } + } +} diff --git a/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/CompositionStringDesc.kt b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/CompositionStringDesc.kt new file mode 100644 index 00000000..b11bca26 --- /dev/null +++ b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/CompositionStringDesc.kt @@ -0,0 +1,13 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.moko.resources.desc + +expect class CompositionStringDesc(args: List, separator: String? = null) : StringDesc + +@Suppress("FunctionName") +fun StringDesc.Companion.Composition( + args: List, + separator: String? = null +) = CompositionStringDesc(args, separator) diff --git a/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/PluralFormattedStringDesc.kt b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/PluralFormattedStringDesc.kt new file mode 100644 index 00000000..438301ac --- /dev/null +++ b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/PluralFormattedStringDesc.kt @@ -0,0 +1,23 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.moko.resources.desc + +import dev.icerock.moko.resources.PluralsResource + +expect class PluralFormattedStringDesc(pluralsRes: PluralsResource, number: Int, args: List) : StringDesc + +@Suppress("FunctionName") +fun StringDesc.Companion.PluralFormatted( + pluralsRes: PluralsResource, + number: Int, + args: List +) = PluralFormattedStringDesc(pluralsRes, number, args) + +@Suppress("FunctionName") +fun StringDesc.Companion.PluralFormatted( + pluralsRes: PluralsResource, + number: Int, + vararg args: Any +) = PluralFormattedStringDesc(pluralsRes, number, args.asList()) diff --git a/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/PluralStringDesc.kt b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/PluralStringDesc.kt new file mode 100644 index 00000000..993b5309 --- /dev/null +++ b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/PluralStringDesc.kt @@ -0,0 +1,13 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.moko.resources.desc + +import dev.icerock.moko.parcelize.Parcelable +import dev.icerock.moko.resources.PluralsResource + +expect class PluralStringDesc(pluralsRes: PluralsResource, number: Int) : StringDesc, Parcelable + +@Suppress("FunctionName") +fun StringDesc.Companion.Plural(pluralsRes: PluralsResource, number: Int) = PluralStringDesc(pluralsRes, number) diff --git a/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/RawStringDesc.kt b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/RawStringDesc.kt new file mode 100644 index 00000000..9f0506b2 --- /dev/null +++ b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/RawStringDesc.kt @@ -0,0 +1,12 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.moko.resources.desc + +import dev.icerock.moko.parcelize.Parcelable + +expect class RawStringDesc(string: String) : StringDesc, Parcelable + +@Suppress("FunctionName") +fun StringDesc.Companion.Raw(string: String) = RawStringDesc(string) diff --git a/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/ResourceFormattedStringDesc.kt b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/ResourceFormattedStringDesc.kt new file mode 100644 index 00000000..be666be3 --- /dev/null +++ b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/ResourceFormattedStringDesc.kt @@ -0,0 +1,21 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.moko.resources.desc + +import dev.icerock.moko.resources.StringResource + +expect class ResourceFormattedStringDesc(stringRes: StringResource, args: List) : StringDesc + +@Suppress("FunctionName") +fun StringDesc.Companion.ResourceFormatted( + stringRes: StringResource, + args: List +) = ResourceFormattedStringDesc(stringRes, args) + +@Suppress("FunctionName") +fun StringDesc.Companion.ResourceFormatted( + stringRes: StringResource, + vararg args: Any +) = ResourceFormattedStringDesc(stringRes, args.asList()) diff --git a/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/ResourceStringDesc.kt b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/ResourceStringDesc.kt new file mode 100644 index 00000000..f684d185 --- /dev/null +++ b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/ResourceStringDesc.kt @@ -0,0 +1,13 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.moko.resources.desc + +import dev.icerock.moko.parcelize.Parcelable +import dev.icerock.moko.resources.StringResource + +expect class ResourceStringDesc(stringRes: StringResource) : StringDesc, Parcelable + +@Suppress("FunctionName") +fun StringDesc.Companion.Resource(stringRes: StringResource) = ResourceStringDesc(stringRes) diff --git a/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/StringDesc.kt b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/StringDesc.kt index a6375d9a..636f26ef 100644 --- a/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/StringDesc.kt +++ b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/desc/StringDesc.kt @@ -7,19 +7,7 @@ package dev.icerock.moko.resources.desc import dev.icerock.moko.resources.PluralsResource import dev.icerock.moko.resources.StringResource -expect sealed class StringDesc { - class Resource(stringRes: StringResource) : StringDesc - class ResourceFormatted(stringRes: StringResource, args: List) : StringDesc { - constructor(stringRes: StringResource, vararg args: Any) - } - - class Plural(pluralsRes: PluralsResource, number: Int) : StringDesc - class PluralFormatted(pluralsRes: PluralsResource, number: Int, args: List) : StringDesc { - constructor(pluralsRes: PluralsResource, number: Int, vararg args: Any) - } - - class Raw(string: String) : StringDesc - class Composition(args: List, separator: String? = null) : StringDesc +expect interface StringDesc { sealed class LocaleType { object System : LocaleType diff --git a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/CompositionStringDesc.kt b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/CompositionStringDesc.kt new file mode 100644 index 00000000..e18f8f3c --- /dev/null +++ b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/CompositionStringDesc.kt @@ -0,0 +1,14 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.moko.resources.desc + +actual class CompositionStringDesc actual constructor( + val args: List, + val separator: String? +) : StringDesc { + override fun localized(): String { + return args.joinToString(separator = separator ?: "") { it.localized() } + } +} diff --git a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/PluralFormattedStringDesc.kt b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/PluralFormattedStringDesc.kt new file mode 100644 index 00000000..500197ee --- /dev/null +++ b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/PluralFormattedStringDesc.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.moko.resources.desc + +import dev.icerock.moko.resources.PluralsResource +import dev.icerock.moko.resources.objc.pluralizedString + +actual class PluralFormattedStringDesc actual constructor( + val pluralsRes: PluralsResource, + val number: Int, + val args: List +) : StringDesc { + override fun localized(): String { + val pluralized = pluralizedString( + bundle = StringDesc.localeType.getLocaleBundle(pluralsRes.bundle), + baseBundle = pluralsRes.bundle, + resourceId = pluralsRes.resourceId, + number = number + )!! + return Utils.stringWithFormat(pluralized, Utils.processArgs(args)) + } +} diff --git a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/PluralStringDesc.kt b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/PluralStringDesc.kt new file mode 100644 index 00000000..2b6a18cb --- /dev/null +++ b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/PluralStringDesc.kt @@ -0,0 +1,23 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.moko.resources.desc + +import dev.icerock.moko.parcelize.Parcelable +import dev.icerock.moko.resources.PluralsResource +import dev.icerock.moko.resources.objc.pluralizedString + +actual class PluralStringDesc actual constructor( + val pluralsRes: PluralsResource, + val number: Int +) : StringDesc, Parcelable { + override fun localized(): String { + return pluralizedString( + bundle = StringDesc.localeType.getLocaleBundle(pluralsRes.bundle), + baseBundle = pluralsRes.bundle, + resourceId = pluralsRes.resourceId, + number = number + )!! + } +} diff --git a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/RawStringDesc.kt b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/RawStringDesc.kt new file mode 100644 index 00000000..6e694f9c --- /dev/null +++ b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/RawStringDesc.kt @@ -0,0 +1,15 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.moko.resources.desc + +import dev.icerock.moko.parcelize.Parcelable +import dev.icerock.moko.parcelize.Parcelize + +@Parcelize +actual class RawStringDesc actual constructor( + val string: String +) : StringDesc, Parcelable { + override fun localized(): String = string +} diff --git a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/ResourceFormattedStringDesc.kt b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/ResourceFormattedStringDesc.kt new file mode 100644 index 00000000..b16ffe4b --- /dev/null +++ b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/ResourceFormattedStringDesc.kt @@ -0,0 +1,16 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.moko.resources.desc + +import dev.icerock.moko.resources.StringResource + +actual class ResourceFormattedStringDesc actual constructor( + val stringRes: StringResource, + val args: List +) : StringDesc { + override fun localized(): String { + return Utils.stringWithFormat(Utils.localizedString(stringRes), Utils.processArgs(args)) + } +} diff --git a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/ResourceStringDesc.kt b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/ResourceStringDesc.kt new file mode 100644 index 00000000..e66e700d --- /dev/null +++ b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/ResourceStringDesc.kt @@ -0,0 +1,16 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.moko.resources.desc + +import dev.icerock.moko.parcelize.Parcelable +import dev.icerock.moko.resources.StringResource + +actual class ResourceStringDesc actual constructor( + private val stringRes: StringResource +) : StringDesc, Parcelable { + override fun localized(): String { + return Utils.localizedString(stringRes) + } +} diff --git a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/StringDesc.kt b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/StringDesc.kt index e27efa0d..1eeda9cc 100644 --- a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/StringDesc.kt +++ b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/StringDesc.kt @@ -4,156 +4,10 @@ package dev.icerock.moko.resources.desc -import dev.icerock.moko.resources.PluralsResource -import dev.icerock.moko.resources.StringResource -import dev.icerock.moko.resources.objc.pluralizedString import platform.Foundation.NSBundle -import platform.Foundation.NSString -import platform.Foundation.stringWithFormat -actual sealed class StringDesc { - protected fun processArgs(args: List): Array { - return args.toList().map { (it as? StringDesc)?.localized() ?: it }.toTypedArray() - } - - protected fun localizedString(stringRes: StringResource): String { - val bundle = 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 - } - - actual data class Resource actual constructor(val stringRes: StringResource) : StringDesc() { - override fun localized(): String { - return localizedString(stringRes) - } - } - - actual data class ResourceFormatted actual constructor( - val stringRes: StringResource, - val args: List - ) : StringDesc() { - actual constructor(stringRes: StringResource, vararg args: Any) : this( - stringRes, - args.toList() - ) - - override fun localized(): String { - return stringWithFormat(localizedString(stringRes), processArgs(args)) - } - } - - actual data class Plural actual constructor(val pluralsRes: PluralsResource, val number: Int) : - StringDesc() { - - override fun localized(): String { - return pluralizedString( - bundle = localeType.getLocaleBundle(pluralsRes.bundle), - baseBundle = pluralsRes.bundle, - resourceId = pluralsRes.resourceId, - number = number - )!! - } - } - - actual data class PluralFormatted actual constructor( - val pluralsRes: PluralsResource, - val number: Int, - val args: List - ) : StringDesc() { - - actual constructor(pluralsRes: PluralsResource, number: Int, vararg args: Any) : this( - pluralsRes, - number, - args.toList() - ) - - override fun localized(): String { - val pluralized = pluralizedString( - bundle = localeType.getLocaleBundle(pluralsRes.bundle), - baseBundle = pluralsRes.bundle, - resourceId = pluralsRes.resourceId, - number = number - )!! - return stringWithFormat(pluralized, processArgs(args)) - } - } - - actual data class Raw actual constructor(val string: String) : StringDesc() { - override fun localized(): String { - return string - } - } - - actual data class Composition actual constructor( - val args: List, - val separator: String? - ) : StringDesc() { - override fun localized(): String { - return args.joinToString(separator = separator ?: "") { it.localized() } - } - } - - abstract fun localized(): String - - protected fun stringWithFormat(format: String, args: Array): String { - // NSString format works with NSObjects via %@, we should change standard format to %@ - val objcFormat = format.replace(Regex("%((?:\\.|\\d|\\$)*)[abcdefs]"), "%$1@") - // bad but objc interop limited :( - // When calling variadic C functions spread operator is supported only for *arrayOf(...) - return when (args.size) { - 0 -> NSString.stringWithFormat(objcFormat) - 1 -> NSString.stringWithFormat(objcFormat, args[0]) - 2 -> NSString.stringWithFormat(objcFormat, args[0], args[1]) - 3 -> NSString.stringWithFormat(objcFormat, args[0], args[1], args[2]) - 4 -> NSString.stringWithFormat(objcFormat, args[0], args[1], args[2], args[3]) - 5 -> NSString.stringWithFormat(objcFormat, args[0], args[1], args[2], args[3], args[4]) - 6 -> NSString.stringWithFormat( - objcFormat, - args[0], - args[1], - args[2], - args[3], - args[4], - args[5] - ) - 7 -> NSString.stringWithFormat( - objcFormat, - args[0], - args[1], - args[2], - args[3], - args[4], - args[5], - args[6] - ) - 8 -> NSString.stringWithFormat( - objcFormat, - args[0], - args[1], - args[2], - args[3], - args[4], - args[5], - args[6], - args[7] - ) - 9 -> NSString.stringWithFormat( - objcFormat, - args[0], - args[1], - args[2], - args[3], - args[4], - args[5], - args[6], - args[7], - args[8] - ) - else -> throw IllegalArgumentException("can't handle more then 9 arguments now") - } - } +actual interface StringDesc { + fun localized(): String actual sealed class LocaleType { actual object System : LocaleType() { diff --git a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/Utils.kt b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/Utils.kt new file mode 100644 index 00000000..90144a70 --- /dev/null +++ b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/Utils.kt @@ -0,0 +1,81 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.moko.resources.desc + +import dev.icerock.moko.resources.StringResource +import platform.Foundation.NSString +import platform.Foundation.stringWithFormat + +object Utils { + fun processArgs(args: List): Array { + return args.toList().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 + } + + fun stringWithFormat(format: String, args: Array): String { + // NSString format works with NSObjects via %@, we should change standard format to %@ + val objcFormat = format.replace(Regex("%((?:\\.|\\d|\\$)*)[abcdefs]"), "%$1@") + // bad but objc interop limited :( + // When calling variadic C functions spread operator is supported only for *arrayOf(...) + return when (args.size) { + 0 -> NSString.stringWithFormat(objcFormat) + 1 -> NSString.stringWithFormat(objcFormat, args[0]) + 2 -> NSString.stringWithFormat(objcFormat, args[0], args[1]) + 3 -> NSString.stringWithFormat(objcFormat, args[0], args[1], args[2]) + 4 -> NSString.stringWithFormat(objcFormat, args[0], args[1], args[2], args[3]) + 5 -> NSString.stringWithFormat(objcFormat, args[0], args[1], args[2], args[3], args[4]) + 6 -> NSString.stringWithFormat( + objcFormat, + args[0], + args[1], + args[2], + args[3], + args[4], + args[5] + ) + 7 -> NSString.stringWithFormat( + objcFormat, + args[0], + args[1], + args[2], + args[3], + args[4], + args[5], + args[6] + ) + 8 -> NSString.stringWithFormat( + objcFormat, + args[0], + args[1], + args[2], + args[3], + args[4], + args[5], + args[6], + args[7] + ) + 9 -> NSString.stringWithFormat( + objcFormat, + args[0], + args[1], + args[2], + args[3], + args[4], + args[5], + args[6], + args[7], + args[8] + ) + else -> throw IllegalArgumentException("can't handle more then 9 arguments now") + } + } +} diff --git a/sample/android-app/src/main/java/com/icerockdev/LocaleHandler.kt b/sample/android-app/src/main/java/com/icerockdev/LocaleHandler.kt index 874b18be..61189037 100644 --- a/sample/android-app/src/main/java/com/icerockdev/LocaleHandler.kt +++ b/sample/android-app/src/main/java/com/icerockdev/LocaleHandler.kt @@ -30,5 +30,4 @@ object LocaleHandler { newBase } } - -} \ No newline at end of file +} diff --git a/sample/android-app/src/main/java/com/icerockdev/MainActivity.kt b/sample/android-app/src/main/java/com/icerockdev/MainActivity.kt index 79aadac2..198f1f6a 100755 --- a/sample/android-app/src/main/java/com/icerockdev/MainActivity.kt +++ b/sample/android-app/src/main/java/com/icerockdev/MainActivity.kt @@ -41,5 +41,4 @@ class MainActivity : AppCompatActivity() { override fun attachBaseContext(newBase: Context) { super.attachBaseContext(LocaleHandler.updateLocale(newBase)) } - } diff --git a/sample/android-app/src/main/java/com/icerockdev/SelectLanguageActivity.kt b/sample/android-app/src/main/java/com/icerockdev/SelectLanguageActivity.kt index 2075d93e..50e99bf6 100755 --- a/sample/android-app/src/main/java/com/icerockdev/SelectLanguageActivity.kt +++ b/sample/android-app/src/main/java/com/icerockdev/SelectLanguageActivity.kt @@ -27,7 +27,7 @@ class SelectLanguageActivity : AppCompatActivity() { fun onCustomLanguage(view: View) { view as Button - + Testing.locale(view.text.toString()) startActivity(Intent(this, MainActivity::class.java)) diff --git a/sample/mpp-library/nested-module/src/commonMain/kotlin/com/icerockdev/library/nested/Testing.kt b/sample/mpp-library/nested-module/src/commonMain/kotlin/com/icerockdev/library/nested/Testing.kt index 7a1a5288..067b10df 100644 --- a/sample/mpp-library/nested-module/src/commonMain/kotlin/com/icerockdev/library/nested/Testing.kt +++ b/sample/mpp-library/nested-module/src/commonMain/kotlin/com/icerockdev/library/nested/Testing.kt @@ -4,7 +4,7 @@ package com.icerockdev.library.nested -import dev.icerock.moko.resources.desc.StringDesc +import dev.icerock.moko.resources.desc.* import dev.icerock.moko.resources.desc.desc fun nestedTest(): StringDesc { diff --git a/sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library/Testing.kt b/sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library/Testing.kt index c3463f8b..911f2c99 100644 --- a/sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library/Testing.kt +++ b/sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library/Testing.kt @@ -4,11 +4,17 @@ package com.icerockdev.library +import com.icerockdev.library.nested.nestedTest import dev.icerock.moko.resources.ImageResource +import dev.icerock.moko.resources.desc.Composition +import dev.icerock.moko.resources.desc.Plural +import dev.icerock.moko.resources.desc.PluralFormatted +import dev.icerock.moko.resources.desc.Raw +import dev.icerock.moko.resources.desc.Resource +import dev.icerock.moko.resources.desc.ResourceFormatted import dev.icerock.moko.resources.desc.StringDesc import dev.icerock.moko.resources.desc.desc import dev.icerock.moko.resources.desc.plus -import com.icerockdev.library.nested.nestedTest object Testing { fun getStrings(): List { From 69e6ec17765248a2f02ca2556ac3068af90f59c0 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 4 May 2020 21:05:38 +0700 Subject: [PATCH 51/54] #62 optimize imports --- .../android-app/src/main/java/com/icerockdev/LocaleHandler.kt | 2 +- .../commonMain/kotlin/com/icerockdev/library/nested/Testing.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sample/android-app/src/main/java/com/icerockdev/LocaleHandler.kt b/sample/android-app/src/main/java/com/icerockdev/LocaleHandler.kt index 61189037..41cd8b1a 100644 --- a/sample/android-app/src/main/java/com/icerockdev/LocaleHandler.kt +++ b/sample/android-app/src/main/java/com/icerockdev/LocaleHandler.kt @@ -8,7 +8,7 @@ import android.content.Context import android.os.Build import android.os.LocaleList import android.preference.PreferenceManager -import java.util.* +import java.util.Locale object LocaleHandler { diff --git a/sample/mpp-library/nested-module/src/commonMain/kotlin/com/icerockdev/library/nested/Testing.kt b/sample/mpp-library/nested-module/src/commonMain/kotlin/com/icerockdev/library/nested/Testing.kt index 067b10df..7a1a5288 100644 --- a/sample/mpp-library/nested-module/src/commonMain/kotlin/com/icerockdev/library/nested/Testing.kt +++ b/sample/mpp-library/nested-module/src/commonMain/kotlin/com/icerockdev/library/nested/Testing.kt @@ -4,7 +4,7 @@ package com.icerockdev.library.nested -import dev.icerock.moko.resources.desc.* +import dev.icerock.moko.resources.desc.StringDesc import dev.icerock.moko.resources.desc.desc fun nestedTest(): StringDesc { From 6d9f9db74f570972245641ab597f1a6c97734602 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Tue, 5 May 2020 09:56:09 +0700 Subject: [PATCH 52/54] #62 remove duplicated `toList` --- .../androidMain/kotlin/dev/icerock/moko/resources/desc/Utils.kt | 2 +- .../src/iosMain/kotlin/dev/icerock/moko/resources/desc/Utils.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/Utils.kt b/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/Utils.kt index 20937dff..dea52054 100644 --- a/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/Utils.kt +++ b/resources/src/androidMain/kotlin/dev/icerock/moko/resources/desc/Utils.kt @@ -10,7 +10,7 @@ import android.os.Build object Utils { fun processArgs(args: List, context: Context): Array { - return args.toList().map { (it as? StringDesc)?.toString(context) ?: it }.toTypedArray() + return args.map { (it as? StringDesc)?.toString(context) ?: it }.toTypedArray() } fun resourcesForContext(context: Context): Resources { diff --git a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/Utils.kt b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/Utils.kt index 90144a70..0290a6c6 100644 --- a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/Utils.kt +++ b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/Utils.kt @@ -10,7 +10,7 @@ import platform.Foundation.stringWithFormat object Utils { fun processArgs(args: List): Array { - return args.toList().map { (it as? StringDesc)?.localized() ?: it }.toTypedArray() + return args.map { (it as? StringDesc)?.localized() ?: it }.toTypedArray() } fun localizedString(stringRes: StringResource): String { From 2e4a0e3c0e562a5d2cbff3cfe92521b02dafde8d Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Tue, 5 May 2020 19:52:18 +0700 Subject: [PATCH 53/54] fix review --- .github/workflows/compilation-check.yml | 26 ++++++------- build.gradle.kts | 17 ++++++++- buildSrc/build.gradle.kts | 2 +- buildSrc/src/main/kotlin/Deps.kt | 37 +++++-------------- buildSrc/src/main/kotlin/PluginDesc.kt | 16 +++++--- buildSrc/src/main/kotlin/Versions.kt | 2 +- gradle-plugin/build.gradle.kts | 5 +-- .../icerock/moko/resources/FontResource.kt | 2 +- .../icerock/moko/resources/ImageResource.kt | 2 +- .../icerock/moko/resources/PluralsResource.kt | 2 +- .../icerock/moko/resources/FontResource.kt | 1 - .../dev/icerock/moko/resources/desc/Utils.kt | 1 + .../kotlin/com/icerockdev/library/Testing.kt | 2 +- .../kotlin/com/icerockdev/library/Testing.kt | 2 +- .../kotlin/com/icerockdev/library/Testing.kt | 1 + .../kotlin/com/icerockdev/library/Testing.kt | 2 +- 16 files changed, 62 insertions(+), 58 deletions(-) diff --git a/.github/workflows/compilation-check.yml b/.github/workflows/compilation-check.yml index c19b8f4a..c412431a 100644 --- a/.github/workflows/compilation-check.yml +++ b/.github/workflows/compilation-check.yml @@ -3,22 +3,22 @@ name: KMP library compilation check on: pull_request: branches: - - master - - develop + - master + - develop jobs: build: runs-on: macOS-latest steps: - - uses: actions/checkout@v1 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 - with: - java-version: 1.8 - - name: Check plugin build - run: ./gradlew -PlibraryPublish :gradle-plugin:detekt :gradle-plugin:publishPluginPublicationToMavenLocal - - name: Check library build - run: ./gradlew -PlibraryPublish :resources:publishToMavenLocal - - name: Check demo library - run: ./gradlew :sample:mpp-conditional:build :sample:mpp-hierarhical:build :sample:mpp-library:build :sample:mpp-mixed:build + - uses: actions/checkout@v1 + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Check plugin build + run: ./gradlew -PlibraryPublish detekt :gradle-plugin:publishPluginPublicationToMavenLocal + - name: Check library build + run: ./gradlew -PlibraryPublish detekt :resources:publishToMavenLocal + - name: Check demo library + run: ./gradlew detekt :sample:mpp-conditional:build :sample:mpp-hierarhical:build :sample:mpp-library:build :sample:mpp-mixed:build diff --git a/build.gradle.kts b/build.gradle.kts index aba3fc27..bff422de 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,6 +2,10 @@ * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ +plugins { + plugin(Deps.Plugins.detekt) apply false +} + buildscript { repositories { mavenLocal() @@ -24,7 +28,7 @@ buildscript { kotlinMultiplatform, kotlinKapt, kotlinAndroid, - if(!libraryPublish) mokoResources else null + if (!libraryPublish) mokoResources else null ) }.let { plugins(it) } } @@ -41,6 +45,17 @@ allprojects { maven { url = uri("https://kotlin.bintray.com/kotlinx") } maven { url = uri("https://dl.bintray.com/icerockdev/moko") } } + + apply(plugin = Deps.Plugins.detekt.id) + + configure { + toolVersion = Versions.detekt + input.setFrom("src/commonMain/kotlin", "src/androidMain/kotlin", "src/iosMain/kotlin") + } + + dependencies { + "detektPlugins"(Deps.Libs.Jvm.detektFormatting) + } } tasks.register("clean", Delete::class).configure { diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 771e954b..faf8a855 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("org.gradle.kotlin.kotlin-dsl") version "1.3.6" + `kotlin-dsl` } repositories { diff --git a/buildSrc/src/main/kotlin/Deps.kt b/buildSrc/src/main/kotlin/Deps.kt index 8b9b6f6e..2732f910 100755 --- a/buildSrc/src/main/kotlin/Deps.kt +++ b/buildSrc/src/main/kotlin/Deps.kt @@ -4,45 +4,28 @@ object Deps { object Plugins { - private const val androidPluginModule = - "com.android.tools.build:gradle:${Versions.Plugins.android}" - val androidApplication = PluginDesc( - id = "com.android.application", - module = androidPluginModule - ) + val androidApplication = PluginDesc(id = "com.android.application") val androidLibrary = PluginDesc( id = "com.android.library", - module = androidPluginModule + module = "com.android.tools.build:gradle:${Versions.Plugins.android}" ) - private const val kotlinPluginModule = - "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.Plugins.kotlin}" val kotlinMultiplatform = PluginDesc( id = "org.jetbrains.kotlin.multiplatform", - module = kotlinPluginModule - ) - val kotlinKapt = PluginDesc( - id = "kotlin-kapt", - module = kotlinPluginModule - ) - val kotlinAndroid = PluginDesc( - id = "kotlin-android", - module = kotlinPluginModule - ) - val kotlinAndroidExtensions = PluginDesc( - id = "kotlin-android-extensions", - module = kotlinPluginModule + module = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.Plugins.kotlin}" ) + val kotlinKapt = PluginDesc(id = "kotlin-kapt") + val kotlinAndroid = PluginDesc(id = "kotlin-android") + val kotlinAndroidExtensions = PluginDesc(id = "kotlin-android-extensions") - val mobileMultiplatform = PluginDesc( - id = "dev.icerock.mobile.multiplatform", - module = "dev.icerock:mobile-multiplatform:0.6.1" - ) + val mobileMultiplatform = PluginDesc(id = "dev.icerock.mobile.multiplatform") val mokoResources = PluginDesc( id = "dev.icerock.mobile.multiplatform-resources", module = "dev.icerock.moko:resources-generator:${Versions.Plugins.mokoResources}" ) + + val detekt = PluginDesc(id = "io.gitlab.arturbosch.detekt", version = Versions.detekt) } object Libs { @@ -90,7 +73,7 @@ object Deps { object Jvm { const val kotlinPoet = "com.squareup:kotlinpoet:${Versions.Libs.Jvm.kotlinPoet}" const val apacheCommonsText = "org.apache.commons:commons-text:${Versions.Libs.Jvm.apacheCommonsText}" - const val detektFormatting = "io.gitlab.arturbosch.detekt:detekt-formatting:${Versions.Plugins.detekt}" + const val detektFormatting = "io.gitlab.arturbosch.detekt:detekt-formatting:${Versions.detekt}" } } } diff --git a/buildSrc/src/main/kotlin/PluginDesc.kt b/buildSrc/src/main/kotlin/PluginDesc.kt index 19a35719..2850c83a 100644 --- a/buildSrc/src/main/kotlin/PluginDesc.kt +++ b/buildSrc/src/main/kotlin/PluginDesc.kt @@ -2,16 +2,20 @@ * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ +import org.gradle.api.artifacts.Dependency import org.gradle.kotlin.dsl.DependencyHandlerScope import org.gradle.plugin.use.PluginDependenciesSpec +import org.gradle.plugin.use.PluginDependencySpec +// TODO move to https://github.com/icerockdev/mobile-multiplatform-gradle-plugin data class PluginDesc( val id: String, - val module: String + val module: String? = null, + val version: String? = null ) -fun DependencyHandlerScope.plugin(pluginDesc: PluginDesc) { - "classpath"(pluginDesc.module) +fun DependencyHandlerScope.plugin(pluginDesc: PluginDesc): Dependency? { + return pluginDesc.module?.let { "classpath"(it) } } fun DependencyHandlerScope.plugins(pluginDescList: List) { @@ -20,6 +24,8 @@ fun DependencyHandlerScope.plugins(pluginDescList: List) { .forEach { plugin(it) } } -fun PluginDependenciesSpec.plugin(pluginDesc: PluginDesc) { - id(pluginDesc.id) +fun PluginDependenciesSpec.plugin(pluginDesc: PluginDesc): PluginDependencySpec { + val spec = id(pluginDesc.id) + pluginDesc.version?.also { spec.version(it) } + return spec } diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 2e24b4fd..a01a74a0 100755 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -10,6 +10,7 @@ object Versions { } const val kotlin = "1.3.72" + const val detekt = "1.7.4" private const val mokoResources = "0.10.0" @@ -18,7 +19,6 @@ object Versions { const val kotlin = Versions.kotlin const val mokoResources = Versions.mokoResources - const val detekt = "1.7.4" } object Libs { diff --git a/gradle-plugin/build.gradle.kts b/gradle-plugin/build.gradle.kts index 96635e5a..11818180 100644 --- a/gradle-plugin/build.gradle.kts +++ b/gradle-plugin/build.gradle.kts @@ -5,7 +5,6 @@ plugins { `kotlin-dsl` id("org.gradle.maven-publish") - id("io.gitlab.arturbosch.detekt") version(Versions.Plugins.detekt) } repositories { @@ -17,8 +16,8 @@ repositories { dependencies { implementation(Deps.Libs.Jvm.kotlinPoet) - compileOnly(Deps.Plugins.kotlinMultiplatform.module) - compileOnly(Deps.Plugins.androidLibrary.module) + compileOnly(Deps.Plugins.kotlinMultiplatform.module!!) + compileOnly(Deps.Plugins.androidLibrary.module!!) implementation(Deps.Libs.Jvm.apacheCommonsText) detektPlugins(Deps.Libs.Jvm.detektFormatting) } diff --git a/resources/src/commonMain/kotlin/dev/icerock/moko/resources/FontResource.kt b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/FontResource.kt index 874780a5..a0501539 100644 --- a/resources/src/commonMain/kotlin/dev/icerock/moko/resources/FontResource.kt +++ b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/FontResource.kt @@ -4,4 +4,4 @@ package dev.icerock.moko.resources -expect class FontResource \ No newline at end of file +expect class FontResource 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 d36ecf5d..7bc6cd2f 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,4 @@ package dev.icerock.moko.resources -expect class ImageResource \ No newline at end of file +expect class ImageResource diff --git a/resources/src/commonMain/kotlin/dev/icerock/moko/resources/PluralsResource.kt b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/PluralsResource.kt index 98f51ed7..14557c86 100644 --- a/resources/src/commonMain/kotlin/dev/icerock/moko/resources/PluralsResource.kt +++ b/resources/src/commonMain/kotlin/dev/icerock/moko/resources/PluralsResource.kt @@ -4,4 +4,4 @@ package dev.icerock.moko.resources -expect class PluralsResource \ No newline at end of file +expect class PluralsResource 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 2c5625be..5af3496a 100644 --- a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/FontResource.kt +++ b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/FontResource.kt @@ -17,7 +17,6 @@ import platform.Foundation.NSData import platform.Foundation.create import platform.UIKit.UIFont import platform.darwin.UInt8Var -import platform.objc.object_getClass actual class FontResource( fontName: String, diff --git a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/Utils.kt b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/Utils.kt index 0290a6c6..b52e5675 100644 --- a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/Utils.kt +++ b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/desc/Utils.kt @@ -26,6 +26,7 @@ object Utils { val objcFormat = format.replace(Regex("%((?:\\.|\\d|\\$)*)[abcdefs]"), "%$1@") // bad but objc interop limited :( // When calling variadic C functions spread operator is supported only for *arrayOf(...) + @Suppress("MagicNumber") return when (args.size) { 0 -> NSString.stringWithFormat(objcFormat) 1 -> NSString.stringWithFormat(objcFormat, args[0]) diff --git a/sample/mpp-conditional/src/commonMain/kotlin/com/icerockdev/library/Testing.kt b/sample/mpp-conditional/src/commonMain/kotlin/com/icerockdev/library/Testing.kt index 92f9ffbe..bad0bb8d 100644 --- a/sample/mpp-conditional/src/commonMain/kotlin/com/icerockdev/library/Testing.kt +++ b/sample/mpp-conditional/src/commonMain/kotlin/com/icerockdev/library/Testing.kt @@ -4,6 +4,6 @@ package com.icerockdev.library +@Suppress("EmptyFunctionBlock") fun test() { - } diff --git a/sample/mpp-hierarhical/src/commonMain/kotlin/com/icerockdev/library/Testing.kt b/sample/mpp-hierarhical/src/commonMain/kotlin/com/icerockdev/library/Testing.kt index 92f9ffbe..bad0bb8d 100644 --- a/sample/mpp-hierarhical/src/commonMain/kotlin/com/icerockdev/library/Testing.kt +++ b/sample/mpp-hierarhical/src/commonMain/kotlin/com/icerockdev/library/Testing.kt @@ -4,6 +4,6 @@ package com.icerockdev.library +@Suppress("EmptyFunctionBlock") fun test() { - } diff --git a/sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library/Testing.kt b/sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library/Testing.kt index d2a99550..d7b95c52 100644 --- a/sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library/Testing.kt +++ b/sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library/Testing.kt @@ -18,6 +18,7 @@ import dev.icerock.moko.resources.desc.StringDesc import dev.icerock.moko.resources.desc.desc import dev.icerock.moko.resources.desc.plus +@Suppress("MagicNumber") object Testing { fun getStrings(): List { return listOf( diff --git a/sample/mpp-mixed/src/commonMain/kotlin/com/icerockdev/library/Testing.kt b/sample/mpp-mixed/src/commonMain/kotlin/com/icerockdev/library/Testing.kt index 92f9ffbe..bad0bb8d 100644 --- a/sample/mpp-mixed/src/commonMain/kotlin/com/icerockdev/library/Testing.kt +++ b/sample/mpp-mixed/src/commonMain/kotlin/com/icerockdev/library/Testing.kt @@ -4,6 +4,6 @@ package com.icerockdev.library +@Suppress("EmptyFunctionBlock") fun test() { - } From d545073a1572d2f225180437fe74170dfe6bae8e Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Tue, 5 May 2020 19:54:21 +0700 Subject: [PATCH 54/54] update readme --- README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2f41d3c8..b0e226b1 100755 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ ![moko-resources](img/logo.png) -[![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](http://www.apache.org/licenses/LICENSE-2.0) [![Download](https://api.bintray.com/packages/icerockdev/moko/moko-resources/images/download.svg) ](https://bintray.com/icerockdev/moko/moko-resources/_latestVersion) ![kotlin-version](https://img.shields.io/badge/kotlin-1.3.71-orange) +[![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](http://www.apache.org/licenses/LICENSE-2.0) [![Download](https://api.bintray.com/packages/icerockdev/moko/moko-resources/images/download.svg) ](https://bintray.com/icerockdev/moko/moko-resources/_latestVersion) ![kotlin-version](https://img.shields.io/badge/kotlin-1.3.72-orange) # Mobile Kotlin resources This is a Kotlin MultiPlatform library that provides access to the resources on iOS & Android with the support of the default system localization. @@ -16,7 +16,7 @@ This is a Kotlin MultiPlatform library that provides access to the resources on - [License](#license) ## Features -- **Strings, Plurals, Images** to access the corresponding resources from common code; +- **Strings, Plurals, Images, Fonts, Files** to access the corresponding resources from common code; - **StringDesc** for lifecycle-aware access to resources and unified localization on both platforms. ## Requirements @@ -42,6 +42,8 @@ This is a Kotlin MultiPlatform library that provides access to the resources on - 0.9.0 - kotlin 1.3.71 - 0.9.1 +- kotlin 1.3.72 + - 0.10.0 ## Installation root build.gradle @@ -52,7 +54,7 @@ buildscript { } dependencies { - classpath "dev.icerock.moko:resources-generator:0.9.1" + classpath "dev.icerock.moko:resources-generator:0.10.0" } } @@ -69,7 +71,7 @@ project build.gradle apply plugin: "dev.icerock.mobile.multiplatform-resources" dependencies { - commonMainApi("dev.icerock.moko:resources:0.9.1") + commonMainApi("dev.icerock.moko:resources:0.10.0") } multiplatformResources { @@ -288,8 +290,7 @@ Please see more examples in the [sample directory](sample). - The [resources directory](resources) contains the `resources` library; - The [gradle-plugin directory](gradle-plugin) contains a gradle plugin with a `MR` class generator; - The [sample directory](sample) contains sample apps for Android and iOS; plus the mpp-library connected to the apps; -- For local testing a library use the `:resources:publishToMavenLocal` gradle task - so that sample apps use the locally published version. -- For local testing a plugin use the `:gradle-plugin:publishToMavenLocal` gradle task so that sample apps will use the locally published version. +- For local testing use the `./publishToMavenLocal.sh` script - so that sample apps use the locally published version. ## Contributing All development (both new features and bug fixes) is performed in the `develop` branch. This way `master` always contains the sources of the most recently released version. Please send PRs with bug fixes to the `develop` branch. Documentation fixes in the markdown files are an exception to this rule. They are updated directly in `master`.