Skip to content

Commit

Permalink
Merge branch 'develop' into #44-file-resource
Browse files Browse the repository at this point in the history
# Conflicts:
#	gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/PluralsGenerator.kt
#	gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/StringsGenerator.kt
  • Loading branch information
Alex009 committed May 4, 2020
2 parents b5e82e6 + deca68c commit 0b9120c
Show file tree
Hide file tree
Showing 18 changed files with 157 additions and 84 deletions.
29 changes: 26 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,32 @@
* 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 {
with(Deps.Plugins) {
listOf(
androidApplication,
androidLibrary,
kotlinMultiplatform,
kotlinKapt,
kotlinAndroid,
mokoResources
)
}.let { plugins(it) }
}
}

allprojects {
repositories {
mavenLocal()
Expand All @@ -13,9 +39,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 {
Expand Down
50 changes: 37 additions & 13 deletions buildSrc/src/main/kotlin/Deps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -55,13 +88,4 @@ object Deps {
const val detektFormatting = "io.gitlab.arturbosch.detekt:detekt-formatting:${Versions.Plugins.detekt}"
}
}

val plugins: Map<String, String> = 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
)
}
25 changes: 25 additions & 0 deletions buildSrc/src/main/kotlin/PluginDesc.kt
Original file line number Diff line number Diff line change
@@ -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<PluginDesc>) {
pluginDescList
.distinctBy { it.module }
.forEach { plugin(it) }
}

fun PluginDependenciesSpec.plugin(pluginDesc: PluginDesc) {
id(pluginDesc.id)
}
6 changes: 3 additions & 3 deletions gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,19 @@ abstract class PluralsGenerator(
) : BaseGenerator<PluralMap>() {

override fun loadLanguageMap(): Map<LanguageType, Map<KeyType, PluralMap>> {
return pluralsFileTree.associate { file ->
return pluralsFileTree.map { file ->
val language: LanguageType = file.parentFile.name
val strings: Map<KeyType, PluralMap> = 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
}
}
}

Expand Down Expand Up @@ -72,7 +81,7 @@ abstract class PluralsGenerator(
private val info: SourceInfo,
private val iosBaseLocalizationRegion: String
) : ResourceGeneratorFeature<PluralsGenerator> {
private val stringsFileTree = info.commonResources.matching { include("MR/**/plurals.xml") }
private val stringsFileTree = info.commonResources.matching { include("MR/**/plurals*.xml") }
override fun createCommonGenerator(): PluralsGenerator {
return CommonPluralsGenerator(stringsFileTree)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,19 @@ abstract class StringsGenerator(
private val stringsFileTree: FileTree
) : BaseGenerator<String>() {
override fun loadLanguageMap(): Map<LanguageType, Map<KeyType, String>> {
return stringsFileTree.associate { file ->
return stringsFileTree.map { file ->
val language: LanguageType = file.parentFile.name
val strings: Map<KeyType, String> = 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
}
}
}

Expand Down Expand Up @@ -67,7 +76,7 @@ abstract class StringsGenerator(
private val info: SourceInfo,
private val iosBaseLocalizationRegion: String
) : ResourceGeneratorFeature<StringsGenerator> {
private val stringsFileTree = info.commonResources.matching { include("MR/**/strings.xml") }
private val stringsFileTree = info.commonResources.matching { include("MR/**/strings*.xml") }
override fun createCommonGenerator(): StringsGenerator {
return CommonStringsGenerator(stringsFileTree)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ class AndroidPluralsGenerator(
}

private fun processKey(key: String): String {
return key.replace(".", "_").toLowerCase()
return key.replace(".", "_")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ class AndroidStringsGenerator(
}

private fun processKey(key: String): String {
return key.replace(".", "_").toLowerCase()
return key.replace(".", "_")
}
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
33 changes: 14 additions & 19 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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

Expand All @@ -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" "$@"
3 changes: 3 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
8 changes: 4 additions & 4 deletions resources/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<plural name="test.plural">
<item quantity="zero">zero</item>
<item quantity="one">one</item>
<item quantity="two">two</item>
<item quantity="few">few</item>
<item quantity="many">many</item>
<item quantity="other">other</item>
</plural>
</resources>
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<plural name="test.plural">
<item quantity="zero">zero</item>
<item quantity="one">one</item>
<item quantity="two">two</item>
<item quantity="few">few</item>
<item quantity="many">many</item>
<item quantity="other">other</item>
</plural>
<plural name="my_plural">
<item quantity="zero">no items</item>
<item quantity="one">%d item</item>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<string name="test.simple">test</string>
<string name="test2">test 2</string>
<string name="test3">test 3</string>
<string name="Test4">test 4</string>
</resources>
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<string name="test.simple">test</string>
<string name="test2">test 2</string>
<string name="test3">test 3</string>
<string name="Test4">test 4</string>
<string name="common.name">Test Project</string>
<string name="format">Test data %d</string>
<string name="encoding">CHOOSE PORTFOLIO &amp; AMOUNT</string>
Expand Down
Loading

0 comments on commit 0b9120c

Please sign in to comment.