Compare commits

...

27 Commits

Author SHA1 Message Date
4ee67321c4 fill changelog and update android dependencies 2022-12-08 09:26:59 +06:00
59f1f2e59b Update libs.versions.toml 2022-12-08 08:53:37 +06:00
0766d48b7c Update libs.versions.toml 2022-12-08 07:56:04 +06:00
e18903b9e9 Update gradle.properties 2022-12-08 07:54:53 +06:00
d0eecdead2 Update gradle.properties 2022-12-08 07:53:59 +06:00
cc4a83a033 Update gradle.properties 2022-12-08 07:53:08 +06:00
1cf911bbde Update build.gradle 2022-12-07 19:40:30 +06:00
36d73d5023 Update StartupLaunchingTests.kt 2022-12-07 11:39:45 +06:00
c395242e3e fixes in StartupLauncingTests 2022-12-07 10:50:51 +06:00
cd9cd7cc5d Merge pull request #208 from InsanusMokrassar/0.15.1
0.15.1
2022-12-07 09:43:48 +06:00
acbb8a0c07 complete prepare startup module 2022-12-06 13:15:08 +06:00
b9d8528599 complete kdocs for the startup module 2022-12-06 13:14:05 +06:00
4971326eca add kdocs for the config of startup 2022-12-06 13:08:37 +06:00
09d1047260 add kdocs to the startup module 2022-12-06 13:06:21 +06:00
02dbd493c2 add tests and make several replacements/improvements 2022-12-06 12:38:24 +06:00
b17931e7bd complete startup module 2022-12-05 22:31:15 +06:00
2a4570eafc Update ServerLauncher.kt 2022-12-05 21:52:36 +06:00
c9514d3a6d Create DefaultJson.kt 2022-12-05 21:47:00 +06:00
072805efc7 Update ServerLauncher.kt 2022-12-05 21:45:30 +06:00
369ff26627 initialize startup module 2022-12-05 21:19:38 +06:00
c5abbbbd2d start 0.15.1 2022-12-05 20:04:50 +06:00
d974639f1e fixes in source roots of dokka 2022-12-05 07:47:35 +06:00
26efde316b remove redundant fix of android 32 dx files from worflows 2022-12-05 07:09:31 +06:00
fafe50f80a suppress kdocs of uniupload in actual realizations 2022-12-05 07:00:31 +06:00
41504469db Revert "potential fix of dokka"
This reverts commit 31022733ac.
2022-12-05 06:57:29 +06:00
03b3ddd98b Revert "remove redundant dokka println"
This reverts commit b53cfd5504.
2022-12-05 06:57:27 +06:00
89d919f2be Merge pull request #207 from InsanusMokrassar/0.15.0
0.15.0
2022-12-04 19:26:14 +06:00
23 changed files with 378 additions and 17 deletions

View File

@@ -11,9 +11,6 @@ jobs:
- uses: actions/setup-java@v1
with:
java-version: 11
- name: Fix android 32.0.0 dx
continue-on-error: true
run: cd /usr/local/lib/android/sdk/build-tools/32.0.0/ && mv d8 dx && cd lib && mv d8.jar dx.jar
- name: Build
run: ./gradlew build && ./gradlew dokkaHtml
- name: Publish KDocs

View File

@@ -1,5 +1,20 @@
# Changelog
## 0.16.0
* `Versions`:
* `Ktor`: `2.1.3` -> `2.2.1`
* `Android Fragment`: `1.5.3` -> `1.5.5`
## 0.15.1
* `Startup`:
* Inited :)
* `Plugin`:
* Inited :)
* `Launcher`:
* Inited :)
## 0.15.0
* `Repos`:

View File

@@ -17,7 +17,7 @@ kotlin {
// browser()
// nodejs()
// }
android()
android {}
sourceSets {
commonMain {
@@ -30,8 +30,8 @@ kotlin {
&& it.hasProperty("kotlin")
&& it.kotlin.sourceSets.any { it.name.contains("commonMain") }
// && it.kotlin.sourceSets.any { it.name.contains("jsMain") }
// && it.kotlin.sourceSets.any { it.name.contains("jvmMain") }
// && it.kotlin.sourceSets.any { it.name.contains("androidMain") }
&& it.kotlin.sourceSets.any { it.name.contains("jvmMain") }
&& it.kotlin.sourceSets.any { it.name.contains("androidMain") }
) {
api it
}
@@ -62,7 +62,7 @@ kotlin {
if (
it != project
&& it.hasProperty("kotlin")
// && it.kotlin.sourceSets.any { it.name.contains("commonMain") }
&& it.kotlin.sourceSets.any { it.name.contains("commonMain") }
&& it.kotlin.sourceSets.any { it.name.contains("jvmMain") }
) {
api it
@@ -78,7 +78,7 @@ kotlin {
if (
it != project
&& it.hasProperty("kotlin")
// && it.kotlin.sourceSets.any { it.name.contains("commonMain") }
&& it.kotlin.sourceSets.any { it.name.contains("commonMain") }
&& it.kotlin.sourceSets.any { it.name.contains("androidMain") }
) {
api it
@@ -100,7 +100,7 @@ private List<SourceDirectorySet> findSourcesWithName(String... approximateNames)
}.collect { it.kotlin }
}
dokkaHtml {
tasks.dokkaHtml {
dokkaSourceSets {
configureEach {
skipDeprecated.set(true)

View File

@@ -14,5 +14,5 @@ crypto_js_version=4.1.1
# Project data
group=dev.inmo
version=0.15.0
android_code_version=166
version=0.16.0
android_code_version=168

View File

@@ -4,6 +4,8 @@ kt = "1.7.20"
kt-serialization = "1.4.1"
kt-coroutines = "1.6.4"
kslog = "0.5.4"
jb-compose = "1.2.1"
jb-exposed = "0.41.1"
jb-dokka = "1.7.20"
@@ -11,19 +13,19 @@ jb-dokka = "1.7.20"
klock = "3.4.0"
uuid = "0.6.0"
ktor = "2.1.3"
ktor = "2.2.1"
gh-release = "2.4.1"
koin = "3.2.2"
android-gradle = "7.2.2"
android-gradle = "7.3.0"
dexcount = "3.1.0"
android-coreKtx = "1.9.0"
android-recyclerView = "1.2.1"
android-appCompat = "1.5.1"
android-fragment = "1.5.3"
android-fragment = "1.5.5"
android-espresso = "3.4.0"
android-test = "1.1.3"
@@ -60,6 +62,7 @@ ktor-server-websockets = { module = "io.ktor:ktor-server-websockets", version.re
ktor-server-statusPages = { module = "io.ktor:ktor-server-status-pages", version.ref = "ktor" }
ktor-server-content-negotiation = { module = "io.ktor:ktor-server-content-negotiation", version.ref = "ktor" }
kslog = { module = "dev.inmo:kslog", version.ref = "kslog" }
klock = { module = "com.soywiz.korlibs.klock:klock", version.ref = "klock" }
uuid = { module = "com.benasher44:uuid", version.ref = "uuid" }

View File

@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@@ -28,6 +28,7 @@ import org.w3c.xhr.XMLHttpRequestResponseType
* @param data [Map] where keys will be used as names for multipart parts and values as values. If you will pass
* [dev.inmo.micro_utils.common.MPPFile] (File from JS or JVM platform). Also you may pass [UniUploadFileInfo] as value
* in case you wish to pass other source of multipart binary data than regular file
* @suppress
*/
actual suspend fun <T> HttpClient.uniUpload(
url: String,

View File

@@ -27,6 +27,7 @@ import java.io.File
* @param data [Map] where keys will be used as names for multipart parts and values as values. If you will pass
* [dev.inmo.micro_utils.common.MPPFile] (File from JS or JVM platform). Also you may pass [UniUploadFileInfo] as value
* in case you wish to pass other source of multipart binary data than regular file
* @suppress
*/
actual suspend fun <T> HttpClient.uniUpload(
url: String,

View File

@@ -23,7 +23,7 @@ kotlin {
commonMain {
dependencies {
implementation kotlin('stdlib')
implementation libs.kt.serialization
api libs.kt.serialization
}
}
commonTest {

View File

@@ -23,7 +23,7 @@ kotlin {
commonMain {
dependencies {
implementation kotlin('stdlib')
implementation libs.kt.serialization
api libs.kt.serialization
implementation compose.runtime
}
}

View File

@@ -32,6 +32,8 @@ String[] includes = [
":serialization:base64",
":serialization:encapsulator",
":serialization:typed_serializer",
":startup:plugin",
":startup:launcher",
":fsm:common",
":fsm:repos:common",

View File

@@ -0,0 +1,31 @@
plugins {
id "org.jetbrains.kotlin.multiplatform"
id "org.jetbrains.kotlin.plugin.serialization"
id "application"
}
apply from: "$mppJavaProjectPresetPath"
kotlin {
sourceSets {
commonMain {
dependencies {
api internalProject("micro_utils.startup.plugin")
}
}
jvmTest {
dependencies {
implementation libs.kt.coroutines.test
}
}
}
}
application {
mainClassName = "dev.inmo.micro_utils.startup.launcher.MainKt"
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

View File

@@ -0,0 +1,22 @@
package dev.inmo.micro_utils.startup.launcher
import dev.inmo.micro_utils.startup.plugin.StartPlugin
import kotlinx.serialization.Serializable
/**
* Contains just [List] of [StartPlugin]s. In json this config should look like:
*
* ```json
* {
* "plugins": [
* "dev.inmo.micro_utils.startup.launcher.HelloWorldPlugin"
* ]
* }
* ```
*
* In the sample above [HelloWorldPlugin] will be loaded during startup of application
*/
@Serializable
data class Config(
val plugins: List<StartPlugin>
)

View File

@@ -0,0 +1,7 @@
package dev.inmo.micro_utils.startup.launcher
import kotlinx.serialization.json.Json
val defaultJson = Json {
ignoreUnknownKeys = true
}

View File

@@ -0,0 +1,13 @@
package dev.inmo.micro_utils.startup.launcher
import dev.inmo.kslog.common.i
import dev.inmo.kslog.common.logger
import dev.inmo.micro_utils.startup.plugin.StartPlugin
import org.koin.core.Koin
object HelloWorldPlugin : StartPlugin {
override suspend fun startPlugin(koin: Koin) {
super.startPlugin(koin)
logger.i("Hello world")
}
}

View File

@@ -0,0 +1,31 @@
package dev.inmo.micro_utils.startup.launcher
import dev.inmo.kslog.common.i
import kotlinx.serialization.json.JsonObject
import org.koin.core.KoinApplication
import org.koin.core.context.GlobalContext
import org.koin.dsl.module
/**
* Will create [KoinApplication], init, load modules using [StartLauncherPlugin] and start plugins using the same base
* plugin
*
* @param rawConfig It is expected that this [JsonObject] will contain serialized [Config] ([StartLauncherPlugin] will
* deserialize it in its [StartLauncherPlugin.setupDI]
*/
suspend fun start(rawConfig: JsonObject) {
with(StartLauncherPlugin) {
logger.i("Start initialization")
val koinApp = KoinApplication.init()
koinApp.modules(
module {
setupDI(rawConfig)
}
)
logger.i("Modules loaded")
GlobalContext.startKoin(koinApp)
logger.i("Koin started")
startPlugin(koinApp.koin)
logger.i("App has been setup")
}
}

View File

@@ -0,0 +1,76 @@
package dev.inmo.micro_utils.startup.launcher
import dev.inmo.kslog.common.i
import dev.inmo.kslog.common.taggedLogger
import dev.inmo.kslog.common.w
import dev.inmo.micro_utils.coroutines.runCatchingSafely
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.serialization.SerialFormat
import kotlinx.serialization.StringFormat
import kotlinx.serialization.json.JsonObject
import org.koin.core.Koin
import org.koin.core.module.Module
import org.koin.dsl.binds
import org.koin.dsl.module
/**
* Default startup plugin. See [setupDI] and [startPlugin] for more info
*/
object StartLauncherPlugin : StartPlugin {
internal val logger = taggedLogger(this)
/**
* Will deserialize [Config] from [config], register it in receiver [Module] (as well as [CoroutineScope] and
* [kotlinx.serialization.json.Json])
*
* Besides, in this method will be called [StartPlugin.setupDI] on each plugin from [Config.plugins]. In case when
* some plugin will not be loaded correctly it will be reported throw the [logger]
*/
override fun Module.setupDI(config: JsonObject) {
val pluginsConfig = defaultJson.decodeFromJsonElement(Config.serializer(), config)
single { pluginsConfig }
single { CoroutineScope(Dispatchers.Default) }
single { defaultJson } binds arrayOf(StringFormat::class, SerialFormat::class)
includes(
pluginsConfig.plugins.mapNotNull {
runCatching {
module {
with(it) {
setupDI(config)
}
}
}.onFailure { e ->
logger.w("Unable to load DI part of $it", e)
}.getOrNull()
}
)
}
/**
* Takes [CoroutineScope] and [Config] from the [koin], and call starting of each plugin from [Config.plugins]
* ASYNCHRONOUSLY. Just like in [setupDI], in case of fail in some plugin it will be reported using [logger]
*/
override suspend fun startPlugin(koin: Koin) {
val scope = koin.get<CoroutineScope>()
koin.get<Config>().plugins.map { plugin ->
scope.launch {
runCatchingSafely {
logger.i("Start loading of $plugin")
with(plugin) {
startPlugin(koin)
}
}.onFailure { e ->
logger.w("Unable to load bot part of $plugin", e)
}.onSuccess {
logger.i("Complete loading of $plugin")
}
}
}.joinAll()
}
}

View File

@@ -0,0 +1,37 @@
package dev.inmo.micro_utils.startup.launcher
import dev.inmo.kslog.common.KSLog
import dev.inmo.kslog.common.i
import kotlinx.serialization.json.jsonObject
import java.io.File
/**
* It is expected, that [args] will contain ONE argument with path to the config json. Sample of launching:
*
* ```bash
* ./gradlew run --args="sample.config.json"
* ```
*
* Content of `sample.config.json` described in [Config] KDocs.
*
* You may build runnable app using:
*
* ```bash
* ./gradlew assembleDist
* ```
*
* In that case in `build/distributions` folder you will be able to find zip and tar files with all required
* tools for application running (via their `bin/app_name` binary). In that case yoy will not need to pass
* `--args=...` and launch will look like `./bin/app_name sample.config.json`
*/
suspend fun main(args: Array<String>) {
KSLog.default = KSLog("ServerLauncher")
val (configPath) = args
val file = File(configPath)
KSLog.i("Start read config from ${file.absolutePath}")
val json = defaultJson.parseToJsonElement(file.readText()).jsonObject
KSLog.i("Config has been read")
start(json)
}

View File

@@ -0,0 +1,46 @@
import dev.inmo.micro_utils.coroutines.launchSynchronously
import dev.inmo.micro_utils.startup.launcher.Config
import dev.inmo.micro_utils.startup.launcher.HelloWorldPlugin
import dev.inmo.micro_utils.startup.launcher.defaultJson
import dev.inmo.micro_utils.startup.launcher.start
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.runTest
import kotlinx.serialization.json.jsonObject
import org.koin.core.context.GlobalContext
import kotlin.test.BeforeTest
import kotlin.test.Test
class StartupLaunchingTests {
@BeforeTest
fun resetGlobalKoinContext() {
kotlin.runCatching { GlobalContext.stopKoin() }
}
@Test(timeout = 60000L)
fun CheckThatEmptyPluginsListLeadsToEndOfMain() {
val emptyJson = defaultJson.encodeToJsonElement(
Config.serializer(),
Config(emptyList())
).jsonObject
runTest {
val job = launch {
start(emptyJson)
}
job.join()
}
}
@Test(timeout = 60000L)
fun CheckThatHelloWorldPluginsListLeadsToEndOfMain() {
val emptyJson = defaultJson.encodeToJsonElement(
Config.serializer(),
Config(listOf(HelloWorldPlugin))
).jsonObject
runTest {
val job = launch {
start(emptyJson)
}
job.join()
}
}
}

View File

@@ -0,0 +1,20 @@
plugins {
id "org.jetbrains.kotlin.multiplatform"
id "org.jetbrains.kotlin.plugin.serialization"
}
apply from: "$mppJavaProjectPresetPath"
kotlin {
sourceSets {
commonMain {
dependencies {
api libs.koin
api libs.kt.serialization
api libs.kslog
api libs.kt.reflect
api project(":micro_utils.coroutines")
}
}
}
}

View File

@@ -0,0 +1,31 @@
package dev.inmo.micro_utils.startup.plugin
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonObject
import org.koin.core.Koin
import org.koin.core.module.Module
/**
* Default plugin for start of your app
*/
@Serializable(StartPluginSerializer::class)
interface StartPlugin {
/**
* This method will be called first to configure [Koin] [Module] related to this plugin. You may use
* [org.koin.core.scope.Scope.get] in your koin definitions like [Module.single] to retrieve
* [kotlinx.coroutines.CoroutineScope], [kotlinx.serialization.json.Json] or [dev.inmo.micro_utils.startup.launcher.Config]
*/
fun Module.setupDI(config: JsonObject) {}
/**
* This method will be called after all other [StartPlugin] will [setupDI]
*
* It is allowed to lock end of this method in case you require to prevent application to end its run (for example,
* you are starting some web server)
*
* @param koin Will contains everything you will register in [setupDI] (as well as other [StartPlugin]s) and
* [kotlinx.coroutines.CoroutineScope], [kotlinx.serialization.json.Json] and [dev.inmo.micro_utils.startup.launcher.Config]
* by their types
*/
suspend fun startPlugin(koin: Koin) {}
}

View File

@@ -0,0 +1,5 @@
package dev.inmo.micro_utils.startup.plugin
import kotlinx.serialization.KSerializer
expect object StartPluginSerializer : KSerializer<StartPlugin>

View File

@@ -0,0 +1,23 @@
package dev.inmo.micro_utils.startup.plugin
import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
actual object StartPluginSerializer : KSerializer<StartPlugin> {
override val descriptor: SerialDescriptor
get() = String.serializer().descriptor
override fun deserialize(decoder: Decoder): StartPlugin {
val kclass = Class.forName(decoder.decodeString()).kotlin
return (kclass.objectInstance ?: kclass.constructors.first { it.parameters.isEmpty() }.call()) as StartPlugin
}
override fun serialize(encoder: Encoder, value: StartPlugin) {
encoder.encodeString(
value::class.java.canonicalName
)
}
}