diff --git a/postssystem.exposed/build.gradle b/postssystem.core.exposed/build.gradle similarity index 100% rename from postssystem.exposed/build.gradle rename to postssystem.core.exposed/build.gradle diff --git a/postssystem.exposed/gradle.properties b/postssystem.core.exposed/gradle.properties similarity index 100% rename from postssystem.exposed/gradle.properties rename to postssystem.core.exposed/gradle.properties diff --git a/postssystem.exposed/maven.publish.gradle b/postssystem.core.exposed/maven.publish.gradle similarity index 100% rename from postssystem.exposed/maven.publish.gradle rename to postssystem.core.exposed/maven.publish.gradle diff --git a/postssystem.exposed/publish.gradle b/postssystem.core.exposed/publish.gradle similarity index 100% rename from postssystem.exposed/publish.gradle rename to postssystem.core.exposed/publish.gradle diff --git a/postssystem.exposed/publish_config.json b/postssystem.core.exposed/publish_config.json similarity index 100% rename from postssystem.exposed/publish_config.json rename to postssystem.core.exposed/publish_config.json diff --git a/postssystem.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ChannelsSizes.kt b/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ChannelsSizes.kt similarity index 100% rename from postssystem.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ChannelsSizes.kt rename to postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ChannelsSizes.kt diff --git a/postssystem.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedContentAPI.kt b/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedContentAPI.kt similarity index 100% rename from postssystem.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedContentAPI.kt rename to postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedContentAPI.kt diff --git a/postssystem.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsAPI.kt b/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsAPI.kt similarity index 100% rename from postssystem.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsAPI.kt rename to postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsAPI.kt diff --git a/postssystem.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/QueryExtensions.kt b/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/QueryExtensions.kt similarity index 100% rename from postssystem.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/QueryExtensions.kt rename to postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/QueryExtensions.kt diff --git a/postssystem.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/content/BinaryContentHolderRepo.kt b/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/content/BinaryContentHolderRepo.kt similarity index 100% rename from postssystem.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/content/BinaryContentHolderRepo.kt rename to postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/content/BinaryContentHolderRepo.kt diff --git a/postssystem.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/content/ContentHolderRepo.kt b/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/content/ContentHolderRepo.kt similarity index 100% rename from postssystem.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/content/ContentHolderRepo.kt rename to postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/content/ContentHolderRepo.kt diff --git a/postssystem.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/content/SpecialContentHolderRepo.kt b/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/content/SpecialContentHolderRepo.kt similarity index 100% rename from postssystem.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/content/SpecialContentHolderRepo.kt rename to postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/content/SpecialContentHolderRepo.kt diff --git a/postssystem.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/content/TextContentHolderRepo.kt b/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/content/TextContentHolderRepo.kt similarity index 100% rename from postssystem.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/content/TextContentHolderRepo.kt rename to postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/content/TextContentHolderRepo.kt diff --git a/postssystem.exposed/src/test/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedContentAPICommonTests.kt b/postssystem.core.exposed/src/test/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedContentAPICommonTests.kt similarity index 100% rename from postssystem.exposed/src/test/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedContentAPICommonTests.kt rename to postssystem.core.exposed/src/test/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedContentAPICommonTests.kt diff --git a/postssystem.exposed/src/test/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsAPICommonTests.kt b/postssystem.core.exposed/src/test/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsAPICommonTests.kt similarity index 100% rename from postssystem.exposed/src/test/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsAPICommonTests.kt rename to postssystem.core.exposed/src/test/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsAPICommonTests.kt diff --git a/postssystem.core.publishing/build.gradle b/postssystem.core.publishing/build.gradle new file mode 100644 index 00000000..5373032e --- /dev/null +++ b/postssystem.core.publishing/build.gradle @@ -0,0 +1,44 @@ +buildscript { + repositories { + mavenLocal() + jcenter() + mavenCentral() + } + + 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" + } +} + +plugins { + id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version" +} + +project.version = "$core_version" +project.group = "com.insanusmokrassar" + +apply plugin: "java-library" +apply plugin: "kotlin" +apply from: "./publish.gradle" + +repositories { + mavenLocal() + jcenter() + mavenCentral() + maven { url "https://kotlin.bintray.com/kotlinx" } +} + +dependencies { + api "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + + if ((project.hasProperty('RELEASE_MODE') && project.property('RELEASE_MODE') == "true") || System.getenv('RELEASE_MODE') == "true") { + api "com.insanusmokrassar:postssystem.core:$core_version" + } else { + implementation project(":postssystem.core") + } + + testImplementation "org.jetbrains.kotlin:kotlin-test" + testImplementation "org.jetbrains.kotlin:kotlin-test-junit" +} diff --git a/postssystem.core.publishing/maven.publish.gradle b/postssystem.core.publishing/maven.publish.gradle new file mode 100644 index 00000000..87b6a8bf --- /dev/null +++ b/postssystem.core.publishing/maven.publish.gradle @@ -0,0 +1,53 @@ +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 = "Publishing subsystem with necessary functionality related to publish mechanism" + name = "PostsSystem Core Publishing subsystem" + url = "https://git.insanusmokrassar.com/PostsSystem/Core/" + + scm { + developerConnection = "scm:git:[fetch=]https://git.insanusmokrassar.com/PostsSystem/Core/.git[push=]https://git.insanusmokrassar.com/PostsSystem/Core/.git" + url = "https://git.insanusmokrassar.com/PostsSystem/Core/.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/Core/src/master/LICENSE" + } + + } + } + } +} \ No newline at end of file diff --git a/postssystem.core.publishing/publish.gradle b/postssystem.core.publishing/publish.gradle new file mode 100644 index 00000000..b8cf4528 --- /dev/null +++ b/postssystem.core.publishing/publish.gradle @@ -0,0 +1,55 @@ +apply plugin: 'com.jfrog.bintray' + +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(".", "/") + } + pkg { + repo = "InsanusMokrassar" + name = "${project.name}" + vcsUrl = "https://github.com/PostsSystem/PostsSystemCore" + 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') + } + } + } +} + +bintrayUpload.doFirst { + publications = publishing.publications.collect { + if (it.name.contains('kotlinMultiplatform')) { + null + } else { + it.name + } + } - null +} + +bintrayUpload.dependsOn publishToMavenLocal \ No newline at end of file diff --git a/postssystem.core.publishing/publish_config.kpsb b/postssystem.core.publishing/publish_config.kpsb new file mode 100644 index 00000000..cdabae19 --- /dev/null +++ b/postssystem.core.publishing/publish_config.kpsb @@ -0,0 +1 @@ +{"bintrayConfig":{"repo":"InsanusMokrassar","packageName":"${project.name}","packageVcs":"https://github.com/PostsSystem/PostsSystemCore"},"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://git.insanusmokrassar.com/PostsSystem/Core/src/master/LICENSE"}],"mavenConfig":{"name":"PostsSystem Core Publishing subsystem","description":"Publishing subsystem with necessary functionality related to publish mechanism","url":"https://git.insanusmokrassar.com/PostsSystem/Core/","vcsUrl":"https://git.insanusmokrassar.com/PostsSystem/Core/.git","developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}]},"type":"Multiplatform"} \ No newline at end of file diff --git a/postssystem.core.publishing/src/main/kotlin/com/insanusmokrassar/postssystem/core/publishing/PublishingRegistrator.kt b/postssystem.core.publishing/src/main/kotlin/com/insanusmokrassar/postssystem/core/publishing/PublishingRegistrator.kt new file mode 100644 index 00000000..33d408a0 --- /dev/null +++ b/postssystem.core.publishing/src/main/kotlin/com/insanusmokrassar/postssystem/core/publishing/PublishingRegistrator.kt @@ -0,0 +1,52 @@ +package com.insanusmokrassar.postssystem.core.publishing + +import com.insanusmokrassar.postssystem.core.post.PostId +import com.insanusmokrassar.postssystem.core.publishing.repos.PublishingKeysRepo +import kotlinx.coroutines.channels.BroadcastChannel +import kotlinx.coroutines.channels.Channel +import kotlinx.coroutines.flow.Flow + +typealias TriggerControlKey = String + +interface ReadPublishingRegistrator { + suspend fun getPostIdByTriggerControlKey( + key: TriggerControlKey + ): PostId? +} + +interface WritePublishingRegistrator { + val unregisteredKeysFlow: Flow + + suspend fun registerTriggerForPost( + key: TriggerControlKey, + postId: PostId + ): Boolean +} + +interface PublishingRegistrator : ReadPublishingRegistrator, WritePublishingRegistrator + +class BusinessPublishingRegistrator( + private val repo: PublishingKeysRepo +) : PublishingRegistrator { + private val unregisteredKeysChannel: BroadcastChannel = BroadcastChannel(Channel.BUFFERED) + override val unregisteredKeysFlow: Flow + get() = TODO("Not yet implemented") + + override suspend fun getPostIdByTriggerControlKey( + key: TriggerControlKey + ): PostId? = repo.getPostIdByTriggerControlKey(key) + + override suspend fun registerTriggerForPost( + key: TriggerControlKey, + postId: PostId + ): Boolean = repo.getTriggerControlKeyByPostId( + postId + ).let { previousKey -> + repo.setPostTriggerControlKey(postId, key).also { inserted -> + if (inserted && previousKey != null) { + unregisteredKeysChannel.send(previousKey) + } + } + } +} + diff --git a/postssystem.core.publishing/src/main/kotlin/com/insanusmokrassar/postssystem/core/publishing/PublishingTrigger.kt b/postssystem.core.publishing/src/main/kotlin/com/insanusmokrassar/postssystem/core/publishing/PublishingTrigger.kt new file mode 100644 index 00000000..43d55206 --- /dev/null +++ b/postssystem.core.publishing/src/main/kotlin/com/insanusmokrassar/postssystem/core/publishing/PublishingTrigger.kt @@ -0,0 +1,14 @@ +package com.insanusmokrassar.postssystem.core.publishing + +import com.insanusmokrassar.postssystem.core.post.PostId +import kotlinx.coroutines.flow.Flow + +interface PublishingTrigger { + val postingTriggeredFlow: Flow + + suspend fun triggerPosting( + triggerControlKey: TriggerControlKey + ): PostId? +} + + diff --git a/postssystem.core.publishing/src/main/kotlin/com/insanusmokrassar/postssystem/core/publishing/repos/PublishingKeysRepo.kt b/postssystem.core.publishing/src/main/kotlin/com/insanusmokrassar/postssystem/core/publishing/repos/PublishingKeysRepo.kt new file mode 100644 index 00000000..ca18657d --- /dev/null +++ b/postssystem.core.publishing/src/main/kotlin/com/insanusmokrassar/postssystem/core/publishing/repos/PublishingKeysRepo.kt @@ -0,0 +1,28 @@ +package com.insanusmokrassar.postssystem.core.publishing.repos + +import com.insanusmokrassar.postssystem.core.post.PostId +import com.insanusmokrassar.postssystem.core.publishing.TriggerControlKey +import kotlinx.coroutines.flow.Flow + +interface ReadPublishingKeysRepo { + suspend fun getPostIdByTriggerControlKey( + key: TriggerControlKey + ): PostId? + suspend fun getTriggerControlKeyByPostId( + postId: PostId + ): TriggerControlKey? +} + +interface WritePublishingKeysRepo { + val postTriggerControlKeyUpdated: Flow> + val postTriggerControlKeyUnset: Flow + suspend fun setPostTriggerControlKey( + postId: PostId, + key: TriggerControlKey + ): Boolean + suspend fun unsetPostTriggerControlKey( + postId: PostId + ) +} + +interface PublishingKeysRepo : ReadPublishingKeysRepo, WritePublishingKeysRepo diff --git a/postssystem.core/build.gradle b/postssystem.core/build.gradle index 18a32160..a0d67177 100644 --- a/postssystem.core/build.gradle +++ b/postssystem.core/build.gradle @@ -69,5 +69,10 @@ kotlin { api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$kotlin_serialisation_runtime_version" } } + jsTest { + dependencies { + implementation kotlin('test-junit-js') + } + } } } diff --git a/settings.gradle b/settings.gradle index 467f37c0..94a1f2c0 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,4 @@ rootProject.name='postssystem' include ':postssystem.core' -include ':postssystem.exposed' +include ':postssystem.core.exposed' +include ':postssystem.core.publishing'