This commit is contained in:
InsanusMokrassar 2021-01-20 12:02:49 +06:00
parent e0aa2b4456
commit 6033eea537
11 changed files with 103 additions and 118 deletions

View File

@ -4,8 +4,12 @@
**ALL PROJECT HAS MIGRATED FROM PACKAGE `com.insanusmokrassar` TO `dev.inmo`**
* `Kotlin`: `1.3.72` -> `1.4.10`
* `Kotlin`: `1.3.72` -> `1.4.21`
* `Serialization`: `0.20.0` -> `1.0.1`
* New annotation `@SDIIncluded` has been added
* Now `KlassIndex` is used to get `SDIIncluded` things
* Now `Module` class is `Serializable` and is able to be deserialized from `Json` (unfortunately, currently is not
supported serialization)
## 0.3.1

View File

@ -1,6 +1,6 @@
# SDI
[ ![Download](https://api.bintray.com/packages/insanusmokrassar/InsanusMokrassar/sdi/images/download.svg) ](https://bintray.com/insanusmokrassar/InsanusMokrassar/sdi/_latestVersion)
[![Download](https://api.bintray.com/packages/insanusmokrassar/InsanusMokrassar/sdi/images/download.svg)](https://bintray.com/insanusmokrassar/InsanusMokrassar/sdi/_latestVersion)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.insanusmokrassar/sdi/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.insanusmokrassar/sdi)
[![Build Status](https://travis-ci.com/InsanusMokrassar/SDI.svg?branch=master)](https://travis-ci.com/InsanusMokrassar/SDI)

View File

@ -2,12 +2,12 @@ buildscript {
repositories {
jcenter()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$gradle_bintray_plugin_version"
classpath "com.github.breadmoirai:github-release:$github_release_plugin_version"
}
}
@ -15,6 +15,7 @@ buildscript {
plugins {
id "org.jetbrains.kotlin.multiplatform" version "$kotlin_version"
id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version"
id "org.jetbrains.kotlin.kapt" version "$kotlin_version"
}
project.version = "$version"
@ -27,6 +28,7 @@ repositories {
jcenter()
mavenCentral()
maven { url "https://kotlin.bintray.com/kotlinx" }
maven { url 'https://jitpack.io' }
}
kotlin {
@ -48,7 +50,7 @@ kotlin {
}
jvmMain {
dependencies {
api "org.atteo.classindex:classindex:$classindex_version"
api "com.github.matfax.klassindex:library:$klassindex_version"
}
}
jvmTest {
@ -58,3 +60,7 @@ kotlin {
}
}
}
dependencies {
kapt "com.github.matfax.klassindex:processor:$klassindex_version"
}

View File

@ -1,9 +1,8 @@
kotlin.code.style=official
kotlin_version=1.4.10
kotlin_version=1.4.21
kotlin_serialisation_runtime_version=1.0.1
classindex_version=3.4
klassindex_version=4.1.0-rc.1
gradle_bintray_plugin_version=1.8.5
github_release_plugin_version=2.2.12
group=dev.inmo

View File

@ -1,53 +0,0 @@
apply plugin: 'maven-publish'
task javadocsJar(type: Jar) {
classifier = 'javadoc'
}
afterEvaluate {
project.publishing.publications.all {
// rename artifacts
groupId "${project.group}"
if (it.name.contains('kotlinMultiplatform')) {
artifactId = "${project.name}"
} else {
artifactId = "${project.name}-$name"
}
}
}
publishing {
publications.all {
artifact javadocsJar
pom {
description = "Simple library for creating dependencies tree using Kotlin Serialization"
name = "Simple Dependency Injector"
url = "https://git.insanusmokrassar.com/InsanusMokrassar/SDI"
scm {
developerConnection = "scm:git:[fetch=]https://git.insanusmokrassar.com/InsanusMokrassar/SDI.git[push=]https://git.insanusmokrassar.com/InsanusMokrassar/SDI.git"
url = "https://git.insanusmokrassar.com/InsanusMokrassar/SDI.git"
}
developers {
developer {
id = "InsanusMokrassar"
name = "Ovsiannikov Aleksei"
email = "ovsyannikov.alexey95@gmail.com"
}
}
licenses {
license {
name = "Apache Software License 2.0"
url = "https://git.insanusmokrassar.com/PostsSystem/SDI/src/master/LICENSE"
}
}
}
}
}

View File

@ -1 +1 @@
{"bintrayConfig":{"repo":"InsanusMokrassar","packageName":"${project.name}","packageVcs":"https://git.insanusmokrassar.com/InsanusMokrassar/SDI.git","autoPublish":true,"overridePublish":true},"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://git.insanusmokrassar.com/PostsSystem/SDI/src/master/LICENSE"}],"mavenConfig":{"name":"Simple Dependency Injector","description":"Simple library for creating dependencies tree using Kotlin Serialization","url":"https://git.insanusmokrassar.com/InsanusMokrassar/SDI","vcsUrl":"https://git.insanusmokrassar.com/InsanusMokrassar/SDI.git","developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}]},"type":"Multiplatform"}
{"bintrayConfig":{"repo":"InsanusMokrassar","packageName":"${project.name}","packageVcs":"https://git.insanusmokrassar.com/InsanusMokrassar/SDI.git","autoPublish":true,"overridePublish":true},"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://git.insanusmokrassar.com/PostsSystem/SDI/src/master/LICENSE"}],"mavenConfig":{"name":"Simple Dependency Injector","description":"Simple library for creating dependencies tree using Kotlin Serialization","url":"https://git.insanusmokrassar.com/InsanusMokrassar/SDI","vcsUrl":"https://git.insanusmokrassar.com/InsanusMokrassar/SDI.git","developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}]}}

View File

@ -1,59 +1,69 @@
apply plugin: 'com.jfrog.bintray'
apply plugin: 'maven-publish'
apply from: "maven.publish.gradle"
bintray {
user = project.hasProperty('BINTRAY_USER') ? project.property('BINTRAY_USER') : System.getenv('BINTRAY_USER')
key = project.hasProperty('BINTRAY_KEY') ? project.property('BINTRAY_KEY') : System.getenv('BINTRAY_KEY')
filesSpec {
from "${buildDir}/publications/"
eachFile {
String directorySubname = it.getFile().parentFile.name
if (it.getName() == "module.json") {
if (directorySubname == "kotlinMultiplatform") {
it.setPath("${project.name}/${project.version}/${project.name}-${project.version}.module")
} else {
it.setPath("${project.name}-${directorySubname}/${project.version}/${project.name}-${directorySubname}-${project.version}.module")
}
} else {
if (directorySubname == "kotlinMultiplatform" && it.getName() == "pom-default.xml") {
it.setPath("${project.name}/${project.version}/${project.name}-${project.version}.pom")
} else {
it.exclude()
}
}
}
into "${project.group}".replace(".", "/")
}
publish = true
override = true
pkg {
repo = "InsanusMokrassar"
name = "${project.name}"
vcsUrl = "https://git.insanusmokrassar.com/InsanusMokrassar/SDI.git"
licenses = ["Apache-2.0"]
version {
name = "${project.version}"
released = new Date()
vcsTag = "${project.version}"
gpg {
sign = true
passphrase = project.hasProperty('signing.gnupg.passphrase') ? project.property('signing.gnupg.passphrase') : System.getenv('signing.gnupg.passphrase')
}
}
}
task javadocsJar(type: Jar) {
classifier = 'javadoc'
}
task sourceJar (type : Jar) {
classifier = 'sources'
}
bintrayUpload.doFirst {
publications = publishing.publications.collect {
afterEvaluate {
project.publishing.publications.all {
// rename artifacts
groupId "${project.group}"
if (it.name.contains('kotlinMultiplatform')) {
null
artifactId = "${project.name}"
artifact sourceJar
} else {
it.name
artifactId = "${project.name}-$name"
}
}
} - null
}
bintrayUpload.dependsOn publishToMavenLocal
publishing {
publications.all {
artifact javadocsJar
pom {
description = "Simple library for creating dependencies tree using Kotlin Serialization"
name = "Simple Dependency Injector"
url = "https://git.insanusmokrassar.com/InsanusMokrassar/SDI"
scm {
developerConnection = "scm:git:[fetch=]https://git.insanusmokrassar.com/InsanusMokrassar/SDI.git[push=]https://git.insanusmokrassar.com/InsanusMokrassar/SDI.git"
url = "https://git.insanusmokrassar.com/InsanusMokrassar/SDI.git"
}
developers {
developer {
id = "InsanusMokrassar"
name = "Ovsiannikov Aleksei"
email = "ovsyannikov.alexey95@gmail.com"
}
}
licenses {
license {
name = "Apache Software License 2.0"
url = "https://git.insanusmokrassar.com/PostsSystem/SDI/src/master/LICENSE"
}
}
}
repositories {
maven {
name = "bintray"
url = uri("https://api.bintray.com/maven/${project.hasProperty('BINTRAY_USER') ? project.property('BINTRAY_USER') : System.getenv('BINTRAY_USER')}/InsanusMokrassar/${project.name}/;publish=1;override=1")
credentials {
username = project.hasProperty('BINTRAY_USER') ? project.property('BINTRAY_USER') : System.getenv('BINTRAY_USER')
password = project.hasProperty('BINTRAY_KEY') ? project.property('BINTRAY_KEY') : System.getenv('BINTRAY_KEY')
}
}
}
}
}

View File

@ -33,4 +33,7 @@ fun loadModule(
json: String,
vararg additionalClassesToInclude: KClass<*>,
moduleBuilder: (SerializersModuleBuilder.() -> Unit)? = null
): Module = nonStrictJson.loadModule(json, *additionalClassesToInclude, moduleBuilder = moduleBuilder)
): Module = nonStrictJson.loadModule(json, *additionalClassesToInclude) {
includeClassesForSDI()
moduleBuilder ?.invoke(this)
}

View File

@ -1,5 +1,7 @@
package dev.inmo.sdi
import kotlinx.serialization.Contextual
import kotlinx.serialization.Serializable
@Serializable(ModuleFullSerializer::class)
class Module internal constructor(base: Map<String, @Contextual Any>) : Map<String, Any> by base

View File

@ -6,6 +6,7 @@ import kotlinx.serialization.builtins.MapSerializer
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.*
import kotlinx.serialization.modules.SerializersModuleBuilder
import kotlin.reflect.KClass
@ -14,6 +15,8 @@ internal class ModuleDeserializerStrategy(
private val moduleBuilder: (SerializersModuleBuilder.() -> Unit)? = null,
private vararg val additionalClassesToInclude: KClass<*>
) : DeserializationStrategy<Module> {
constructor() : this(null)
private val internalSerializer = MapSerializer(String.serializer(), ContextualSerializer(Any::class))
override val descriptor: SerialDescriptor
get() = internalSerializer.descriptor
@ -34,3 +37,14 @@ internal class ModuleDeserializerStrategy(
return Module(map)
}
}
@Serializer(Module::class)
internal class ModuleFullSerializer(
private val moduleBuilder: (SerializersModuleBuilder.() -> Unit)? = null,
private vararg val additionalClassesToInclude: KClass<*>
) : KSerializer<Module>,
DeserializationStrategy<Module> by ModuleDeserializerStrategy(moduleBuilder, *additionalClassesToInclude) {
constructor() : this(null)
override fun serialize(encoder: Encoder, value: Module) = throw NotImplementedError("Currently there is no support for serialization of modules")
}

View File

@ -1,7 +1,7 @@
package dev.inmo.sdi
import org.atteo.classindex.ClassIndex
import org.atteo.classindex.IndexAnnotated
import com.github.matfax.klassindex.IndexAnnotated
import com.github.matfax.klassindex.KlassIndex
import kotlin.reflect.KClass
@Retention(AnnotationRetention.RUNTIME)
@ -9,10 +9,10 @@ import kotlin.reflect.KClass
@IndexAnnotated
actual annotation class SDIIncluded actual constructor(actual val customNames: Array<String>)
internal actual fun getClassesForIncludingInSDI(): List<Pair<KClass<*>, List<String>>> = ClassIndex.getAnnotated(
SDIIncluded::class.java
internal actual fun getClassesForIncludingInSDI(): List<Pair<KClass<*>, List<String>>> = KlassIndex.getAnnotated(
SDIIncluded::class
).map {
it.kotlin.let {
it.let {
it to it.annotations.flatMap { (it as? SDIIncluded) ?.customNames ?.toList() ?: emptyList() }
}
}