mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-17 14:29:24 +00:00
Compare commits
23 Commits
Author | SHA1 | Date | |
---|---|---|---|
4d155d0505 | |||
a169e733d9 | |||
f081e237c8 | |||
f412d387fa | |||
67354b43e2 | |||
39135a4000 | |||
eaa014cebd | |||
856e657f81 | |||
3a609e5b66 | |||
d0022dd599 | |||
7ba6eed453 | |||
beeb6ecc0a | |||
7cdc17a714 | |||
4765a950a9 | |||
65e8137e08 | |||
ae546dd9ad | |||
8110c42be0 | |||
bd2b5ae5fc | |||
2ddfffa6a9 | |||
a4b54e861d | |||
c6785f1a4f | |||
83fe621c56 | |||
b3a93e17eb |
40
CHANGELOG.md
40
CHANGELOG.md
@@ -1,5 +1,45 @@
|
||||
# Changelog
|
||||
|
||||
## 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`:
|
||||
* `Coroutines`: `1.7.2` -> `1.7.3`
|
||||
* `Kotlin`: `1.8.20` -> `1.8.22`
|
||||
* `Compose`: `1.4.1` -> `1.4.3`
|
||||
* `Okio`: `3.3.0` -> `3.4.0`
|
||||
* `RecyclerView`: `1.3.0` -> `1.3.1`
|
||||
* `Fragment`: `1.6.0` -> `1.6.1`
|
||||
* `Repos`:
|
||||
* Fixes In `KeyValueRepo.clear()` of almost all inheritors of `KeyValueRepo`
|
||||
* `Cache`:
|
||||
* All full caches got `skipStartInvalidate` property. By default, this property is `false` and fully caching repos
|
||||
will be automatically invalidated on start of their work
|
||||
|
||||
## 0.19.7
|
||||
|
||||
* `Versions`:
|
||||
* `Coroutines`: `1.7.1` -> `1.7.2`
|
||||
|
||||
## 0.19.6
|
||||
|
||||
* `Versions`:
|
||||
* `Coroutines`: `1.6.4` -> `1.7.1`
|
||||
* `Ktor`: `2.3.1` -> `2.3.2`
|
||||
* `Compose`: `1.4.0` -> `1.4.1`
|
||||
|
||||
## 0.19.5
|
||||
|
||||
* `Repos`:
|
||||
* `Generator`:
|
||||
* Fixes in new type generation
|
||||
|
||||
## 0.19.4
|
||||
|
||||
* `Versions`:
|
||||
|
@@ -17,6 +17,10 @@ buildscript {
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.versions)
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
@@ -38,3 +42,4 @@ allprojects {
|
||||
|
||||
apply from: "./extensions.gradle"
|
||||
apply from: "./github_release.gradle"
|
||||
apply from: "./versions_plugin_setup.gradle"
|
||||
|
@@ -14,5 +14,5 @@ crypto_js_version=4.1.1
|
||||
# Project data
|
||||
|
||||
group=dev.inmo
|
||||
version=0.19.4
|
||||
android_code_version=200
|
||||
version=0.19.9
|
||||
android_code_version=205
|
||||
|
@@ -1,36 +1,38 @@
|
||||
[versions]
|
||||
|
||||
kt = "1.8.20"
|
||||
kt = "1.8.22"
|
||||
kt-serialization = "1.5.1"
|
||||
kt-coroutines = "1.6.4"
|
||||
kt-coroutines = "1.7.3"
|
||||
|
||||
kslog = "1.1.1"
|
||||
|
||||
jb-compose = "1.4.0"
|
||||
jb-compose = "1.4.3"
|
||||
jb-exposed = "0.41.1"
|
||||
jb-dokka = "1.8.20"
|
||||
|
||||
korlibs = "4.0.3"
|
||||
uuid = "0.7.1"
|
||||
|
||||
ktor = "2.3.1"
|
||||
ktor = "2.3.2"
|
||||
|
||||
gh-release = "2.4.1"
|
||||
|
||||
koin = "3.4.2"
|
||||
koin = "3.4.3"
|
||||
|
||||
okio = "3.3.0"
|
||||
okio = "3.4.0"
|
||||
|
||||
ksp = "1.8.20-1.0.11"
|
||||
ksp = "1.8.22-1.0.11"
|
||||
kotlin-poet = "1.14.2"
|
||||
|
||||
versions = "0.47.0"
|
||||
|
||||
android-gradle = "7.4.2"
|
||||
dexcount = "4.0.0"
|
||||
|
||||
android-coreKtx = "1.10.1"
|
||||
android-recyclerView = "1.3.0"
|
||||
android-recyclerView = "1.3.1"
|
||||
android-appCompat = "1.6.1"
|
||||
android-fragment = "1.6.0"
|
||||
android-fragment = "1.6.1"
|
||||
android-espresso = "3.5.1"
|
||||
android-test = "1.1.5"
|
||||
|
||||
@@ -109,3 +111,5 @@ buildscript-android-dexcount = { module = "com.getkeepsafe.dexcount:dexcount-gra
|
||||
[plugins]
|
||||
|
||||
jb-compose = { id = "org.jetbrains.compose", version.ref = "jb-compose" }
|
||||
|
||||
versions = { id = "com.github.ben-manes.versions", version.ref = "versions" }
|
||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
@@ -38,7 +38,7 @@ fun <Key, Value> ReadKeyValueRepo<Key, Value>.cached(
|
||||
) = ReadKeyValueCacheRepo(this, kvCache)
|
||||
|
||||
open class KeyValueCacheRepo<Key,Value>(
|
||||
parentRepo: KeyValueRepo<Key, Value>,
|
||||
override val parentRepo: KeyValueRepo<Key, Value>,
|
||||
kvCache: KVCache<Key, Value>,
|
||||
scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
|
||||
) : ReadKeyValueCacheRepo<Key,Value>(parentRepo, kvCache), KeyValueRepo<Key,Value>, WriteKeyValueRepo<Key, Value> by parentRepo, CommonCacheRepo {
|
||||
@@ -46,6 +46,11 @@ open class KeyValueCacheRepo<Key,Value>(
|
||||
protected val onRemoveJob = parentRepo.onValueRemoved.onEach { kvCache.unset(it) }.launchIn(scope)
|
||||
|
||||
override suspend fun invalidate() = kvCache.clear()
|
||||
|
||||
override suspend fun clear() {
|
||||
parentRepo.clear()
|
||||
kvCache.clear()
|
||||
}
|
||||
}
|
||||
|
||||
fun <Key, Value> KeyValueRepo<Key, Value>.cached(
|
||||
|
@@ -21,6 +21,12 @@ open class SimpleFullKVCache<K, V>(
|
||||
kvParent.unset(toUnset)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun clear() {
|
||||
syncMutex.withLock {
|
||||
kvParent.clear()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <K, V> FullKVCache(
|
||||
|
@@ -37,6 +37,10 @@ open class SimpleKVCache<K, V>(
|
||||
override suspend fun unset(toUnset: List<K>) {
|
||||
syncMutex.withLock { makeUnset(toUnset) }
|
||||
}
|
||||
|
||||
override suspend fun clear() {
|
||||
syncMutex.withLock { makeUnset(cacheQueue) }
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <K, V> KVCache(
|
||||
|
@@ -39,4 +39,9 @@ open class AutoRecacheKeyValueRepo<Id, RegisteredObject>(
|
||||
).also {
|
||||
kvCache.unsetWithValues(toUnset)
|
||||
}
|
||||
|
||||
override suspend fun clear() {
|
||||
originalRepo.clear()
|
||||
kvCache.clear()
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.micro_utils.repos.cache.full
|
||||
|
||||
import dev.inmo.micro_utils.common.*
|
||||
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
||||
import dev.inmo.micro_utils.pagination.Pagination
|
||||
import dev.inmo.micro_utils.pagination.PaginationResult
|
||||
import dev.inmo.micro_utils.repos.*
|
||||
@@ -84,6 +85,7 @@ open class FullCRUDCacheRepo<ObjectType, IdType, InputValueType>(
|
||||
override val parentRepo: CRUDRepo<ObjectType, IdType, InputValueType>,
|
||||
kvCache: FullKVCache<IdType, ObjectType>,
|
||||
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
|
||||
skipStartInvalidate: Boolean = false,
|
||||
idGetter: (ObjectType) -> IdType
|
||||
) : FullReadCRUDCacheRepo<ObjectType, IdType>(
|
||||
parentRepo,
|
||||
@@ -97,6 +99,12 @@ open class FullCRUDCacheRepo<ObjectType, IdType, InputValueType>(
|
||||
idGetter
|
||||
),
|
||||
CRUDRepo<ObjectType, IdType, InputValueType> {
|
||||
init {
|
||||
if (!skipStartInvalidate) {
|
||||
scope.launchSafelyWithoutExceptions { invalidate() }
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun invalidate() {
|
||||
actualizeAll()
|
||||
}
|
||||
@@ -105,12 +113,14 @@ open class FullCRUDCacheRepo<ObjectType, IdType, InputValueType>(
|
||||
fun <ObjectType, IdType, InputType> CRUDRepo<ObjectType, IdType, InputType>.fullyCached(
|
||||
kvCache: FullKVCache<IdType, ObjectType> = FullKVCache(),
|
||||
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
|
||||
skipStartInvalidate: Boolean = false,
|
||||
idGetter: (ObjectType) -> IdType
|
||||
) = FullCRUDCacheRepo(this, kvCache, scope, idGetter)
|
||||
) = FullCRUDCacheRepo(this, kvCache, scope, skipStartInvalidate, idGetter)
|
||||
|
||||
@Deprecated("Renamed", ReplaceWith("this.fullyCached(kvCache, scope, idGetter)", "dev.inmo.micro_utils.repos.cache.full.fullyCached"))
|
||||
fun <ObjectType, IdType, InputType> CRUDRepo<ObjectType, IdType, InputType>.cached(
|
||||
kvCache: FullKVCache<IdType, ObjectType>,
|
||||
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
|
||||
skipStartInvalidate: Boolean = false,
|
||||
idGetter: (ObjectType) -> IdType
|
||||
) = fullyCached(kvCache, scope, idGetter)
|
||||
) = fullyCached(kvCache, scope, skipStartInvalidate, idGetter)
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.micro_utils.repos.cache.full
|
||||
|
||||
import dev.inmo.micro_utils.common.*
|
||||
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
||||
import dev.inmo.micro_utils.pagination.Pagination
|
||||
import dev.inmo.micro_utils.pagination.PaginationResult
|
||||
import dev.inmo.micro_utils.repos.*
|
||||
@@ -106,15 +107,30 @@ fun <Key, Value> WriteKeyValueRepo<Key, Value>.caching(
|
||||
open class FullKeyValueCacheRepo<Key,Value>(
|
||||
protected open val parentRepo: KeyValueRepo<Key, Value>,
|
||||
kvCache: FullKVCache<Key, Value>,
|
||||
scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
|
||||
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
|
||||
skipStartInvalidate: Boolean = false
|
||||
) : FullWriteKeyValueCacheRepo<Key,Value>(parentRepo, kvCache, scope),
|
||||
KeyValueRepo<Key,Value>,
|
||||
ReadKeyValueRepo<Key, Value> by FullReadKeyValueCacheRepo(parentRepo, kvCache) {
|
||||
ReadKeyValueRepo<Key, Value> by FullReadKeyValueCacheRepo(
|
||||
parentRepo,
|
||||
kvCache
|
||||
) {
|
||||
init {
|
||||
if (!skipStartInvalidate) {
|
||||
scope.launchSafelyWithoutExceptions { invalidate() }
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun unsetWithValues(toUnset: List<Value>) = parentRepo.unsetWithValues(toUnset)
|
||||
|
||||
override suspend fun invalidate() {
|
||||
kvCache.actualizeAll(parentRepo)
|
||||
}
|
||||
|
||||
override suspend fun clear() {
|
||||
parentRepo.clear()
|
||||
kvCache.clear()
|
||||
}
|
||||
}
|
||||
|
||||
fun <Key, Value> KeyValueRepo<Key, Value>.fullyCached(
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.micro_utils.repos.cache.full
|
||||
|
||||
import dev.inmo.micro_utils.common.*
|
||||
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
||||
import dev.inmo.micro_utils.pagination.*
|
||||
import dev.inmo.micro_utils.pagination.utils.*
|
||||
import dev.inmo.micro_utils.repos.*
|
||||
@@ -142,10 +143,17 @@ fun <Key, Value> WriteKeyValuesRepo<Key, Value>.caching(
|
||||
open class FullKeyValuesCacheRepo<Key,Value>(
|
||||
protected open val parentRepo: KeyValuesRepo<Key, Value>,
|
||||
kvCache: FullKVCache<Key, List<Value>>,
|
||||
scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
|
||||
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
|
||||
skipStartInvalidate: Boolean = false
|
||||
) : FullWriteKeyValuesCacheRepo<Key, Value>(parentRepo, kvCache, scope),
|
||||
KeyValuesRepo<Key, Value>,
|
||||
ReadKeyValuesRepo<Key, Value> by FullReadKeyValuesCacheRepo(parentRepo, kvCache) {
|
||||
init {
|
||||
if (!skipStartInvalidate) {
|
||||
scope.launchSafelyWithoutExceptions { invalidate() }
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun clearWithValue(v: Value) {
|
||||
doAllWithCurrentPaging {
|
||||
keys(v, it).also {
|
||||
|
@@ -127,7 +127,11 @@ open class MapperKeyValueRepo<FromKey, FromValue, ToKey, ToValue>(
|
||||
) : KeyValueRepo<FromKey, FromValue>,
|
||||
MapperRepo<FromKey, FromValue, ToKey, ToValue> by mapper,
|
||||
ReadKeyValueRepo<FromKey, FromValue> by MapperReadKeyValueRepo(to, mapper),
|
||||
WriteKeyValueRepo<FromKey, FromValue> by MapperWriteKeyValueRepo(to, mapper)
|
||||
WriteKeyValueRepo<FromKey, FromValue> by MapperWriteKeyValueRepo(to, mapper) {
|
||||
override suspend fun clear() {
|
||||
to.clear()
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun <FromKey, FromValue, ToKey, ToValue> KeyValueRepo<ToKey, ToValue>.withMapper(
|
||||
|
@@ -202,9 +202,14 @@ class FileWriteKeyValueRepo(
|
||||
@Warning("Files watching will not correctly works on Android Platform with version of API lower than API 26")
|
||||
@Suppress("DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE")
|
||||
class FileKeyValueRepo(
|
||||
folder: File,
|
||||
private val folder: File,
|
||||
filesChangedProcessingScope: CoroutineScope? = null
|
||||
) : KeyValueRepo<String, File>,
|
||||
WriteKeyValueRepo<String, File> by FileWriteKeyValueRepo(folder, filesChangedProcessingScope),
|
||||
ReadKeyValueRepo<String, File> by FileReadKeyValueRepo(folder) {
|
||||
override suspend fun clear() {
|
||||
withContext(Dispatchers.IO) {
|
||||
folder.listFiles() ?.forEach { runCatching { it.deleteRecursively() } }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@ import dev.inmo.micro_utils.pagination.*
|
||||
import dev.inmo.micro_utils.pagination.utils.paginate
|
||||
import dev.inmo.micro_utils.pagination.utils.reverse
|
||||
import dev.inmo.micro_utils.repos.KeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.pagination.maxPagePagination
|
||||
import kotlinx.coroutines.flow.*
|
||||
|
||||
private val cache = HashMap<String, KeyValueStore<*>>()
|
||||
@@ -159,6 +160,24 @@ class KeyValueStore<T : Any> internal constructor (
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun clear() {
|
||||
val keys = mutableSetOf<String>()
|
||||
doWithPagination(maxPagePagination()) {
|
||||
keys(it).also {
|
||||
keys.addAll(it.results)
|
||||
}.nextPageIfNotEmpty()
|
||||
}
|
||||
val success = sharedPreferences.edit().apply {
|
||||
clear()
|
||||
}.commit()
|
||||
|
||||
if (success) {
|
||||
keys.forEach {
|
||||
_onValueRemovedFlow.emit(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
operator fun <T : Any> invoke(
|
||||
context: Context,
|
||||
|
@@ -73,4 +73,18 @@ abstract class AbstractExposedKeyValueRepo<Key, Value>(
|
||||
_onValueRemoved.emit(it)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun clear() {
|
||||
transaction(database) {
|
||||
val keys = selectAll().map { it.asKey }
|
||||
|
||||
deleteAll()
|
||||
|
||||
keys
|
||||
}.also {
|
||||
it.forEach {
|
||||
_onValueRemoved.emit(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import kotlinx.coroutines.flow.*
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.inList
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.inSubQuery
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
|
||||
open class ExposedKeyValueRepo<Key, Value>(
|
||||
@@ -72,4 +73,18 @@ open class ExposedKeyValueRepo<Key, Value>(
|
||||
_onValueRemoved.emit(it)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun clear() {
|
||||
transaction(database) {
|
||||
val keys = selectAll().map { it.asKey }
|
||||
|
||||
deleteAll()
|
||||
|
||||
keys
|
||||
}.also {
|
||||
it.forEach {
|
||||
_onValueRemoved.emit(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -100,7 +100,11 @@ class Processor(
|
||||
primaryConstructor(
|
||||
FunSpec.constructorBuilder().apply {
|
||||
ksClassProperties.forEach {
|
||||
addParameter(it.simpleName.getShortName(), it.typeName)
|
||||
addParameter(
|
||||
ParameterSpec.builder(it.simpleName.getShortName(), it.typeName).apply {
|
||||
annotations += it.annotations.map { it.toAnnotationSpec() }
|
||||
}.build()
|
||||
)
|
||||
typeBuilder.addProperty(
|
||||
PropertySpec.builder(it.simpleName.getShortName(), it.typeName, KModifier.OVERRIDE).apply {
|
||||
initializer(it.simpleName.getShortName())
|
||||
|
@@ -11,18 +11,20 @@ import kotlinx.serialization.Serializable
|
||||
@Serializable
|
||||
@SerialName(value = "NewTest")
|
||||
public data class NewTest(
|
||||
public override val property1: String,
|
||||
public override val property2: Int,
|
||||
public override val parent: ParentTypeId?,
|
||||
override val property1: String,
|
||||
override val property2: Int,
|
||||
@Serializable
|
||||
override val parent: ParentTypeId?,
|
||||
) : Test
|
||||
|
||||
@Serializable
|
||||
@SerialName(value = "RegisteredTest")
|
||||
public data class RegisteredTest(
|
||||
public override val id: TestId,
|
||||
public override val property1: String,
|
||||
public override val property2: Int,
|
||||
public override val parent: ParentTypeId?,
|
||||
override val id: TestId,
|
||||
override val property1: String,
|
||||
override val property2: Int,
|
||||
@Serializable
|
||||
override val parent: ParentTypeId?,
|
||||
) : Test, IRegisteredTest
|
||||
|
||||
public fun Test.asNew(): NewTest = NewTest(property1, property2, parent)
|
||||
|
@@ -17,6 +17,7 @@ typealias ParentTypeId = TestId
|
||||
sealed interface Test {
|
||||
val property1: String
|
||||
val property2: Int
|
||||
@Serializable
|
||||
val parent: ParentTypeId?
|
||||
|
||||
@GenerateCRUDModelExcludeOverride
|
||||
|
@@ -94,6 +94,10 @@ class MapKeyValueRepo<Key, Value>(
|
||||
private val map: MutableMap<Key, Value> = mutableMapOf()
|
||||
) : KeyValueRepo<Key, Value>,
|
||||
ReadKeyValueRepo<Key, Value> by ReadMapKeyValueRepo(map),
|
||||
WriteKeyValueRepo<Key, Value> by WriteMapKeyValueRepo(map)
|
||||
WriteKeyValueRepo<Key, Value> by WriteMapKeyValueRepo(map) {
|
||||
override suspend fun clear() {
|
||||
map.clear()
|
||||
}
|
||||
}
|
||||
|
||||
fun <K, V> MutableMap<K, V>.asKeyValueRepo(): KeyValueRepo<K, V> = MapKeyValueRepo(this)
|
||||
|
@@ -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")
|
||||
startPlugin(koinApp.koin)
|
||||
logger.i("App has been setup")
|
||||
val launchJob = koinApp.koin.get<CoroutineScope>().launch {
|
||||
startPlugin(koinApp.koin)
|
||||
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
|
||||
|
||||
}
|
||||
}
|
||||
|
11
versions_plugin_setup.gradle
Normal file
11
versions_plugin_setup.gradle
Normal file
@@ -0,0 +1,11 @@
|
||||
def isNonStable = { String version ->
|
||||
def stableKeyword = ['RELEASE', 'FINAL', 'GA'].any { it -> version.toUpperCase().contains(it) }
|
||||
def regex = /^[0-9,.v-]+(-r)?$/
|
||||
return !stableKeyword && !(version ==~ regex)
|
||||
}
|
||||
|
||||
tasks.named("dependencyUpdates").configure {
|
||||
rejectVersionIf {
|
||||
isNonStable(it.candidate.version)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user