diff --git a/CHANGELOG.md b/CHANGELOG.md index 5870e90..fea2f6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 44a5241..9469313 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/build.gradle b/build.gradle index ba67907..96915a8 100644 --- a/build.gradle +++ b/build.gradle @@ -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" +} diff --git a/gradle.properties b/gradle.properties index 79ca913..39f5f43 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/maven.publish.gradle b/maven.publish.gradle deleted file mode 100644 index de68bd9..0000000 --- a/maven.publish.gradle +++ /dev/null @@ -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" - } - - } - } - } -} \ No newline at end of file diff --git a/mpp_publish_config.kpsb b/mpp_publish_config.kpsb index 0c114e4..0828bf6 100644 --- a/mpp_publish_config.kpsb +++ b/mpp_publish_config.kpsb @@ -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"} \ No newline at end of file +{"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"}]}} \ No newline at end of file diff --git a/publish.gradle b/publish.gradle index 58338e1..67f4cf9 100644 --- a/publish.gradle +++ b/publish.gradle @@ -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 \ No newline at end of file +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') + } + } + } + + } +} diff --git a/src/commonMain/kotlin/dev/inmo/sdi/HelperTools.kt b/src/commonMain/kotlin/dev/inmo/sdi/HelperTools.kt index 77b3d37..8a04b64 100644 --- a/src/commonMain/kotlin/dev/inmo/sdi/HelperTools.kt +++ b/src/commonMain/kotlin/dev/inmo/sdi/HelperTools.kt @@ -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) +} diff --git a/src/commonMain/kotlin/dev/inmo/sdi/Module.kt b/src/commonMain/kotlin/dev/inmo/sdi/Module.kt index 121aad1..60a8b9a 100644 --- a/src/commonMain/kotlin/dev/inmo/sdi/Module.kt +++ b/src/commonMain/kotlin/dev/inmo/sdi/Module.kt @@ -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) : Map by base \ No newline at end of file diff --git a/src/commonMain/kotlin/dev/inmo/sdi/ModuleDeserializerStrategy.kt b/src/commonMain/kotlin/dev/inmo/sdi/ModuleDeserializerStrategy.kt index 893a333..a22873e 100644 --- a/src/commonMain/kotlin/dev/inmo/sdi/ModuleDeserializerStrategy.kt +++ b/src/commonMain/kotlin/dev/inmo/sdi/ModuleDeserializerStrategy.kt @@ -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 { + 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, + DeserializationStrategy 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") +} diff --git a/src/jvmMain/kotlin/dev/inmo/sdi/SDIIncludedRealization.kt b/src/jvmMain/kotlin/dev/inmo/sdi/SDIIncludedRealization.kt index c7409fd..66ed251 100644 --- a/src/jvmMain/kotlin/dev/inmo/sdi/SDIIncludedRealization.kt +++ b/src/jvmMain/kotlin/dev/inmo/sdi/SDIIncludedRealization.kt @@ -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) -internal actual fun getClassesForIncludingInSDI(): List, List>> = ClassIndex.getAnnotated( - SDIIncluded::class.java +internal actual fun getClassesForIncludingInSDI(): List, List>> = KlassIndex.getAnnotated( + SDIIncluded::class ).map { - it.kotlin.let { + it.let { it to it.annotations.flatMap { (it as? SDIIncluded) ?.customNames ?.toList() ?: emptyList() } } }