Skip to content

Commit

Permalink
Merge branch '0.22.0' into bpavuk.tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bpavuk authored Aug 2, 2024
2 parents 2df7e9b + 95d2f6d commit 83e3296
Show file tree
Hide file tree
Showing 40 changed files with 3,816 additions and 1,859 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
.kotlin
out/*
*.iml
target
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# Changelog

## 0.22.0


## 0.21.6

* `KSP`:
* `Sealed`:
* Fixes in generation


## 0.21.5

* `KSP`:
Expand Down
1 change: 1 addition & 0 deletions android/pickers/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id "org.jetbrains.kotlin.plugin.serialization"
id "com.android.library"
alias(libs.plugins.jb.compose)
alias(libs.plugins.kt.jb.compose)
}

apply from: "$mppProjectWithSerializationAndComposePresetPath"
Expand Down
1 change: 1 addition & 0 deletions android/smalltextfield/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id "org.jetbrains.kotlin.plugin.serialization"
id "com.android.library"
alias(libs.plugins.jb.compose)
alias(libs.plugins.kt.jb.compose)
}

apply from: "$mppProjectWithSerializationAndComposePresetPath"
Expand Down
9 changes: 0 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ allprojects {
maven { url "https://maven.pkg.jetbrains.space/public/p/compose/dev" }
maven { url "https://nexus.inmo.dev/repository/maven-releases/" }
}

// temporal crutch until legacy tests will be stabled or legacy target will be removed
if (it != rootProject.findProject("docs")) {
tasks.whenTaskAdded { task ->
if(task.name == "jsLegacyBrowserTest" || task.name == "jsLegacyNodeTest") {
task.enabled = false
}
}
}
}

apply from: "./extensions.gradle"
Expand Down
1 change: 1 addition & 0 deletions common/compose/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id "org.jetbrains.kotlin.plugin.serialization"
id "com.android.library"
alias(libs.plugins.jb.compose)
alias(libs.plugins.kt.jb.compose)
}

apply from: "$mppComposeJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
Expand Down
1 change: 1 addition & 0 deletions coroutines/compose/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id "org.jetbrains.kotlin.plugin.serialization"
id "com.android.library"
alias(libs.plugins.jb.compose)
alias(libs.plugins.kt.jb.compose)
}

apply from: "$mppComposeJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import kotlin.contracts.contract
* * [unlockWrite] will just unlock [writeMutex]
*/
class SmartRWLocker(private val readPermits: Int = Int.MAX_VALUE, writeIsLocked: Boolean = false) {
private val _readSemaphore = SmartSemaphore.Mutable(permits = readPermits, acquiredPermits = 0)
private val _readSemaphore = SmartSemaphore.Mutable(permits = readPermits, acquiredPermits = if (writeIsLocked) readPermits else 0)
private val _writeMutex = SmartMutex.Mutable(locked = writeIsLocked)

val readSemaphore: SmartSemaphore.Immutable = _readSemaphore.immutable()
Expand All @@ -23,7 +23,6 @@ class SmartRWLocker(private val readPermits: Int = Int.MAX_VALUE, writeIsLocked:
* Do lock in [readSemaphore] inside of [writeMutex] locking
*/
suspend fun acquireRead() {
_writeMutex.waitUnlock()
_readSemaphore.acquire()
}

Expand All @@ -38,8 +37,8 @@ class SmartRWLocker(private val readPermits: Int = Int.MAX_VALUE, writeIsLocked:
* Locking [writeMutex] and wait while all [readSemaphore] permits will be freed
*/
suspend fun lockWrite() {
_writeMutex.lock()
_readSemaphore.acquire(readPermits)
_writeMutex.lock()
}

/**
Expand Down
1 change: 1 addition & 0 deletions defaultAndroidSettings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ android {

defaultConfig {
minSdkVersion libs.versions.android.props.minSdk.get().toInteger()
compileSdkVersion libs.versions.android.props.compileSdk.get().toInteger()
targetSdkVersion libs.versions.android.props.compileSdk.get().toInteger()
versionCode "${android_code_version}".toInteger()
versionName "$version"
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ crypto_js_version=4.1.1
# Project data

group=dev.inmo
version=0.21.6
version=0.22.0
android_code_version=265
23 changes: 12 additions & 11 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[versions]

kt = "1.9.23"
kt-serialization = "1.6.3"
kt = "2.0.0"
kt-serialization = "1.7.1"
kt-coroutines = "1.8.1"

kslog = "1.3.4"

jb-compose = "1.6.2"
jb-exposed = "0.50.1"
jb-compose = "1.7.0-alpha02"
jb-exposed = "0.53.0"
jb-dokka = "1.9.20"

korlibs = "5.4.0"
Expand All @@ -21,20 +21,20 @@ koin = "3.5.6"

okio = "3.9.0"

ksp = "1.9.23-1.0.20"
kotlin-poet = "1.16.0"
ksp = "2.0.0-1.0.23"
kotlin-poet = "1.18.0"

versions = "0.51.0"

android-gradle = "8.2.0"
android-gradle = "8.2.2"
dexcount = "4.0.0"

android-coreKtx = "1.13.1"
android-recyclerView = "1.3.2"
android-appCompat = "1.6.1"
android-fragment = "1.7.1"
android-espresso = "3.5.1"
android-test = "1.1.5"
android-appCompat = "1.7.0"
android-fragment = "1.8.2"
android-espresso = "3.6.1"
android-test = "1.2.1"
android-compose-material3 = "1.2.1"

android-props-minSdk = "21"
Expand Down Expand Up @@ -113,5 +113,6 @@ buildscript-android-dexcount = { module = "com.getkeepsafe.dexcount:dexcount-gra
[plugins]

jb-compose = { id = "org.jetbrains.compose", version.ref = "jb-compose" }
kt-jb-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kt" }

versions = { id = "com.github.ben-manes.versions", version.ref = "versions" }
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-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
1 change: 1 addition & 0 deletions language_codes/generator/full.json

Large diffs are not rendered by default.

59 changes: 35 additions & 24 deletions language_codes/generator/src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,24 @@ private const val baseClassSerializerAnnotationName = "@Serializable(${baseClass

@Serializable
private data class LanguageCode(
@SerialName("alpha2")
val tag: String,
@SerialName("English")
val title: String
)
val title: String,
@SerialName("alpha2")
val alpha: String? = null,
@SerialName("alpha3-b")
val alpha2: String? = null,
@SerialName("alpha3-t")
val alpha3: String? = null,
) {
val tag: String
get() = alpha ?: alpha2 ?: alpha3!!
}

fun String.adaptAsTitle() = if (first().isDigit()) {
fun String.adaptAsTitle() = (if (first().isDigit()) {
"L$this"
} else {
this
}
}).replace(".", "_").replace("'", "_")

fun String.normalized() = Normalizer.normalize(this, Normalizer.Form.NFD).replace(Regex("[^\\p{ASCII}]"), "")

Expand Down Expand Up @@ -73,25 +80,30 @@ data class Tag(
val title: String,
val tag: String,
val subtags: List<Tag>
)
) {
val adaptedTitle
get() = title.adaptAsTitle()
}

private fun printLanguageCodeAndTags(
tag: Tag,
parent: Tag? = null,
indents: String = " "
): String = if (tag.subtags.isEmpty()) {
"""${indents}${baseClassSerializerAnnotationName}
${indents}object ${tag.title} : ${parent ?.title ?: baseClassName}() { override val code: String = "${tag.tag}"${parent ?.let { parent -> "; override val parentLang: ${parent.title} get() = ${parent.title};" } ?: ""} }"""
${indents}object ${tag.adaptedTitle} : ${parent ?.adaptedTitle ?: baseClassName} { override val code: String = "${tag.tag}"${parent ?.let { parent -> "; override val parentLang: ${parent.adaptedTitle} get() = ${parent.adaptedTitle}" } ?: ""}; override fun toString() = code }"""
} else {
"""
${indents}${baseClassSerializerAnnotationName}
${indents}sealed class ${tag.title} : ${parent ?.title ?: baseClassName}() {
${indents} override val code: String = "${tag.tag}"${parent ?.let { parent -> "\n${indents} override val parentLang: ${parent.title} get() = ${parent.title};" } ?: ""}
${indents}sealed interface ${tag.adaptedTitle} : ${parent ?.adaptedTitle ?: baseClassName} {
${tag.subtags.joinToString("\n") { printLanguageCodeAndTags(it, tag, "${indents} ") }}
${indents} ${baseClassSerializerAnnotationName}
${indents} companion object : ${tag.title}()
${indents} companion object : ${tag.adaptedTitle} {
${indents} override val code: String = "${tag.tag}"${parent ?.let { parent -> "\n${indents} override val parentLang: ${parent.adaptedTitle} get() = ${parent.adaptedTitle};" } ?: ""}
${indents} override fun toString() = code
${indents} }
${indents}}
"""
}
Expand All @@ -105,23 +117,22 @@ import kotlinx.serialization.Serializable
* https://datahub.io/core/language-codes/ files (base and tags) and create the whole hierarchy using it.
*/
${baseClassSerializerAnnotationName}
sealed class $baseClassName {
abstract val code: String
open val parentLang: $baseClassName?
get() = null
open val withoutDialect: String
sealed interface $baseClassName {
val code: String
val parentLang: $baseClassName?
get() = code.split("-").takeIf { it.size > 1 } ?.first() ?.let(::$unknownBaseClassName)
val withoutDialect: String
get() = parentLang ?.code ?: code
${tags.joinToString("\n") { printLanguageCodeAndTags(it, indents = " ") } }
$baseClassSerializerAnnotationName
data class $unknownBaseClassName (override val code: String) : $baseClassName() {
data class $unknownBaseClassName (override val code: String) : $baseClassName {
override val parentLang = code.dropLastWhile { it != '-' }.removeSuffix("-").takeIf { it.length > 0 } ?.let(::$unknownBaseClassName)
}
@Deprecated("Renamed", ReplaceWith("$baseClassName.$unknownBaseClassName", "${if (prePackage.isNotEmpty()) "$prePackage." else ""}$baseClassName.$unknownBaseClassName"))
val $oldUnknownBaseClassName = $unknownBaseClassName
override fun toString() = code
val $oldUnknownBaseClassName
get() = $unknownBaseClassName
}
@Deprecated("Renamed", ReplaceWith("$baseClassName", "${if (prePackage.isNotEmpty()) "$prePackage." else ""}$baseClassName"))
typealias $oldBaseClassName = $baseClassName
Expand All @@ -133,15 +144,15 @@ fun createStringConverterCode(tags: List<Tag>, prePackage: String): String {
pretitle: String = baseClassName,
indents: String = " "
): String {
val currentTitle = "$pretitle.${tag.title}"
val currentTitle = "$pretitle.${tag.adaptedTitle}"
return """${indents}$currentTitle.code -> $currentTitle${if (tag.subtags.isNotEmpty()) tag.subtags.joinToString("\n", "\n") { createDeserializeVariantForTag(it, currentTitle, indents) } else ""}"""
}
fun createInheritorVariantForTag(
tag: Tag,
pretitle: String = baseClassName,
indents: String = " "
): String {
val currentTitle = "$pretitle.${tag.title}"
val currentTitle = "$pretitle.${tag.adaptedTitle}"
val subtags = if (tag.subtags.isNotEmpty()) {
tag.subtags.joinToString(",\n", ",\n") { createInheritorVariantForTag(it, currentTitle, "$indents ") }
} else {
Expand All @@ -155,7 +166,7 @@ fun createStringConverterCode(tags: List<Tag>, prePackage: String): String {
indents: String = " ",
codeSuffix: String = ""
): String {
val currentTitle = "$pretitle.${tag.title}"
val currentTitle = "$pretitle.${tag.adaptedTitle}"
val subtags = if (tag.subtags.isNotEmpty()) {
tag.subtags.joinToString(",\n", ",\n") { createInheritorVariantForMapForTag(it, currentTitle, "$indents ", codeSuffix) }
} else {
Expand Down Expand Up @@ -266,7 +277,7 @@ suspend fun main(vararg args: String) {
File(outputFolder, "LanguageCodes.kt").apply {
delete()
createNewFile()
writeText(targetPackagePrefix + buildKtFileContent(tags, targetPackage ?: ""))
writeText("@file:Suppress(\"SERIALIZER_TYPE_INCOMPATIBLE\")\n\n" + targetPackagePrefix + buildKtFileContent(tags, targetPackage ?: ""))
}

File(outputFolder, "StringToLanguageCodes.kt").apply {
Expand Down
1 change: 1 addition & 0 deletions language_codes/generator/tags.json

Large diffs are not rendered by default.

Loading

0 comments on commit 83e3296

Please sign in to comment.