Compare commits

..

9 Commits

Author SHA1 Message Date
57ebed903f done migration 2023-08-08 18:45:36 +06:00
4478193d8a update dependencies 2023-08-05 13:49:45 +06:00
ee948395e3 start 0.20.0 2023-08-02 13:03:40 +06:00
0616b051ae Merge pull request #291 from InsanusMokrassar/0.19.9
0.19.9
2023-07-29 17:37:38 +06:00
4d155d0505 update koin 2023-07-29 16:37:25 +06:00
a169e733d9 fill changelog 2023-07-29 16:31:50 +06:00
f081e237c8 improvements in startup plugin 2023-07-29 16:30:17 +06:00
f412d387fa start 0.19.9 2023-07-29 16:05:24 +06:00
67354b43e2 Merge pull request #287 from InsanusMokrassar/0.19.8
0.19.8
2023-07-27 01:33:49 +06:00
85 changed files with 117 additions and 85 deletions

View File

@@ -1,5 +1,14 @@
# Changelog
## 0.20.0
## 0.19.9
* `Versions`:
* `Koin`: `3.4.2` -> `3.4.3`
* `Startup`:
* Now it is possible to start application in synchronous way
## 0.19.8
* `Versions`:

View File

@@ -1,12 +1,10 @@
package dev.inmo.micro_utils.common
import kotlinx.cinterop.ByteVar
import kotlinx.cinterop.allocArray
import kotlinx.cinterop.memScoped
import kotlinx.cinterop.toKString
import kotlinx.cinterop.*
import platform.posix.snprintf
import platform.posix.sprintf
@OptIn(ExperimentalForeignApi::class)
actual fun Float.fixed(signs: Int): Float {
return memScoped {
val buff = allocArray<ByteVar>(Float.SIZE_BYTES * 2)
@@ -16,6 +14,7 @@ actual fun Float.fixed(signs: Int): Float {
}
}
@OptIn(ExperimentalForeignApi::class)
actual fun Double.fixed(signs: Int): Double {
return memScoped {
val buff = allocArray<ByteVar>(Double.SIZE_BYTES * 2)

View File

@@ -1,12 +1,10 @@
package dev.inmo.micro_utils.common
import kotlinx.cinterop.ByteVar
import kotlinx.cinterop.allocArray
import kotlinx.cinterop.memScoped
import kotlinx.cinterop.toKString
import kotlinx.cinterop.*
import platform.posix.snprintf
import platform.posix.sprintf
@OptIn(ExperimentalForeignApi::class)
actual fun Float.fixed(signs: Int): Float {
return memScoped {
val buff = allocArray<ByteVar>(Float.SIZE_BYTES * 2)
@@ -16,6 +14,7 @@ actual fun Float.fixed(signs: Int): Float {
}
}
@OptIn(ExperimentalForeignApi::class)
actual fun Double.fixed(signs: Int): Double {
return memScoped {
val buff = allocArray<ByteVar>(Double.SIZE_BYTES * 2)

View File

@@ -29,8 +29,4 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}

View File

@@ -3,6 +3,7 @@ org.gradle.parallel=true
kotlin.js.generate.externals=true
kotlin.incremental=true
kotlin.incremental.js=true
#kotlin.experimental.tryK2=true
android.useAndroidX=true
android.enableJetifier=true
org.gradle.jvmargs=-Xmx2g
@@ -14,5 +15,5 @@ crypto_js_version=4.1.1
# Project data
group=dev.inmo
version=0.19.8
android_code_version=204
version=0.20.0
android_code_version=206

View File

@@ -1,27 +1,27 @@
[versions]
kt = "1.8.22"
kt = "1.9.0"
kt-serialization = "1.5.1"
kt-coroutines = "1.7.3"
kslog = "1.1.1"
kslog = "1.2.0"
jb-compose = "1.4.3"
jb-exposed = "0.41.1"
jb-exposed = "0.42.0"
jb-dokka = "1.8.20"
korlibs = "4.0.3"
uuid = "0.7.1"
korlibs = "4.0.9"
uuid = "0.8.0"
ktor = "2.3.2"
ktor = "2.3.3"
gh-release = "2.4.1"
koin = "3.4.2"
koin = "3.4.3"
okio = "3.4.0"
okio = "3.5.0"
ksp = "1.8.22-1.0.11"
ksp = "1.9.0-1.0.13"
kotlin-poet = "1.14.2"
versions = "0.47.0"

View File

@@ -159,9 +159,7 @@ class Processor(
}
if (generateSingle) {
fun FunSpec.Builder.configure(
useInstead: String? = null
) {
fun FunSpec.Builder.configure() {
addKdoc(
"""
Will register [definition] with [org.koin.core.module.Module.single] and key "${name}"
@@ -185,30 +183,9 @@ class Processor(
addTypeVariable(it)
addModifiers(KModifier.INLINE)
}
if (useInstead != null) {
addAnnotation(
AnnotationSpec.builder(
Deprecated::class
).apply {
addMember(
CodeBlock.of(
"""
"This definition is old style and should not be used anymore. Use $useInstead instead"
""".trimIndent()
)
)
addMember(CodeBlock.of("ReplaceWith(\"$useInstead\")"))
}.build()
)
}
}
val actualSingleName = "single${name.replaceFirstChar { it.uppercase() }}"
if (targetTypeAsGenericType == null) { // classic type
addFunction(
FunSpec.builder("${name}Single").apply { configure(actualSingleName) }.build()
)
}
addFunction(
FunSpec.builder(actualSingleName).apply { configure() }.build()
@@ -216,9 +193,7 @@ class Processor(
}
if (generateFactory) {
fun FunSpec.Builder.configure(
useInstead: String? = null
) {
fun FunSpec.Builder.configure() {
addKdoc(
"""
Will register [definition] with [org.koin.core.module.Module.factory] and key "${name}"
@@ -234,29 +209,8 @@ class Processor(
addTypeVariable(it)
addModifiers(KModifier.INLINE)
}
if (useInstead != null) {
addAnnotation(
AnnotationSpec.builder(
Deprecated::class
).apply {
addMember(
CodeBlock.of(
"""
"This definition is old style and should not be used anymore. Use $useInstead instead"
""".trimIndent()
)
)
addMember(CodeBlock.of("ReplaceWith(\"$useInstead\")"))
}.build()
)
}
}
val actualFactoryName = "factory${name.replaceFirstChar { it.uppercase() }}"
if (targetTypeAsGenericType == null) { // classic type
addFunction(
FunSpec.builder("${name}Factory").apply { configure(useInstead = actualFactoryName) }.build()
)
}
addFunction(
FunSpec.builder(actualFactoryName).apply { configure() }.build()
)

12
local.migrate.folder.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/bin/bash
function renameFolders() {
for folder in $(find . -depth -type d -name "$1");
do
sedString="s/$1/$2/g"
newFolder="$(echo $folder | sed $sedString)"
echo $folder "$newFolder"
done
}
renameFolders "androidTest" "androidUnitTest"

View File

@@ -45,7 +45,7 @@ kotlin {
implementation kotlin('test-junit')
}
}
androidTest {
androidUnitTest {
dependencies {
implementation kotlin('test-junit')
implementation libs.android.test.junit

View File

@@ -54,7 +54,7 @@ kotlin {
implementation kotlin('test-junit')
}
}
androidTest {
androidUnitTest {
dependencies {
implementation kotlin('test-junit')
implementation libs.android.test.junit

View File

@@ -9,10 +9,7 @@ import dev.inmo.micro_utils.koin.annotations.GenerateKoinDefinition
import dev.inmo.micro_utils.startup.launcher.StartLauncherPlugin.setupDI
import dev.inmo.micro_utils.startup.launcher.StartLauncherPlugin.startPlugin
import dev.inmo.micro_utils.startup.plugin.StartPlugin
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.joinAll
import kotlinx.coroutines.launch
import kotlinx.coroutines.*
import kotlinx.serialization.SerialFormat
import kotlinx.serialization.StringFormat
import kotlinx.serialization.json.Json
@@ -116,12 +113,16 @@ object StartLauncherPlugin : StartPlugin {
/**
* Will create [KoinApplication], init, load modules using [StartLauncherPlugin] and start plugins using the same base
* plugin. It is basic [start] method which accepts both [config] and [rawConfig] which suppose to be the same or
* at least [rawConfig] must contain serialized variant of [config]
* at least [rawConfig] must contain serialized variant of [config].
*
* Koin part will be started in-place. This means, that after ending of this method call you will be able to
* take any declared dependency from koin
*
* @param rawConfig It is expected that this [JsonObject] will contain serialized [Config] ([StartLauncherPlugin] will
* deserialize it in its [StartLauncherPlugin.setupDI]
* @return [KoinApplication] of current start and [Job] which can be used to call [CoroutineScope.join]
*/
suspend fun start(config: Config, rawConfig: JsonObject) {
fun startAsync(config: Config, rawConfig: JsonObject): Pair<KoinApplication, Job> {
logger.i("Start initialization")
val koinApp = KoinApplication.init()
@@ -133,8 +134,44 @@ object StartLauncherPlugin : StartPlugin {
logger.i("Modules loaded")
startKoin(koinApp)
logger.i("Koin started")
val launchJob = koinApp.koin.get<CoroutineScope>().launch {
startPlugin(koinApp.koin)
logger.i("App has been setup")
logger.i("App has been started")
}
return koinApp to launchJob
}
/**
* Will create [KoinApplication], init, load modules using [StartLauncherPlugin] and start plugins using the same base
* plugin. It is basic [start] method which accepts both [config] and [rawConfig] which suppose to be the same or
* at least [rawConfig] must contain serialized variant of [config]
*
* @param rawConfig It is expected that this [JsonObject] will contain serialized [Config] ([StartLauncherPlugin] will
* deserialize it in its [StartLauncherPlugin.setupDI]
* @return [KoinApplication] of current launch
*/
suspend fun start(config: Config, rawConfig: JsonObject): KoinApplication {
val (koinApp, job) = startAsync(config, rawConfig)
job.join()
return koinApp
}
/**
* Call [start] with deserialized [Config] as config and [rawConfig] as is
*
* Koin part will be started in-place. This means, that after ending of this method call you will be able to
* take any declared dependency from koin
*
* @param rawConfig It is expected that this [JsonObject] will contain serialized [Config]
* @return [KoinApplication] of current launch and [Job] of starting launch
*/
fun startAsync(rawConfig: JsonObject): Pair<KoinApplication, Job> {
return startAsync(defaultJson.decodeFromJsonElement(Config.serializer(), rawConfig), rawConfig)
}
@@ -143,9 +180,30 @@ object StartLauncherPlugin : StartPlugin {
*
* @param rawConfig It is expected that this [JsonObject] will contain serialized [Config]
*/
suspend fun start(rawConfig: JsonObject) {
suspend fun start(rawConfig: JsonObject): KoinApplication {
start(defaultJson.decodeFromJsonElement(Config.serializer(), rawConfig), rawConfig)
val (koinApp, job) = startAsync(rawConfig)
job.join()
return koinApp
}
/**
* Call [start] with deserialized [Config] as is and serialize it to [JsonObject] to pass as the first parameter
* to the basic [start] method
*
* Koin part will be started in-place. This means, that after ending of this method call you will be able to
* take any declared dependency from koin
*
* @param config Will be converted to [JsonObject] as raw config. That means that all plugins from [config] will
* receive serialized version of [config] in [StartPlugin.setupDI] method
* @return [KoinApplication] of current launch and [Job] of starting launch
*/
fun startAsync(config: Config): Pair<KoinApplication, Job> {
return startAsync(config, defaultJson.encodeToJsonElement(Config.serializer(), config).jsonObject)
}
@@ -156,9 +214,13 @@ object StartLauncherPlugin : StartPlugin {
* @param config Will be converted to [JsonObject] as raw config. That means that all plugins from [config] will
* receive serialized version of [config] in [StartPlugin.setupDI] method
*/
suspend fun start(config: Config) {
suspend fun start(config: Config): KoinApplication {
start(config, defaultJson.encodeToJsonElement(Config.serializer(), config).jsonObject)
val (koinApp, job) = startAsync(config)
job.join()
return koinApp
}
}