mirror of
https://github.com/InsanusMokrassar/KotlinPublicationScriptsBuilder.git
synced 2025-09-03 06:59:17 +00:00
rewrite on multiplatform
This commit is contained in:
20
core/build.gradle
Normal file
20
core/build.gradle
Normal file
@@ -0,0 +1,20 @@
|
||||
plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
id "org.jetbrains.kotlin.plugin.serialization"
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
|
||||
api "dev.inmo:micro_utils.coroutines:$micro_utils_version"
|
||||
|
||||
api "io.ktor:ktor-client-core:$ktor_version"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,69 @@
|
||||
package dev.inmo.kmppscriptbuilder.core.export.jvm_only
|
||||
|
||||
import dev.inmo.kmppscriptbuilder.core.models.*
|
||||
|
||||
fun MavenConfig.buildJvmOnlyMavenConfig(licenses: List<License>): String = """
|
||||
apply plugin: 'maven-publish'
|
||||
${if (includeGpgSigning) "apply plugin: 'signing'\n" else ""}
|
||||
|
||||
task javadocJar(type: Jar) {
|
||||
from javadoc
|
||||
classifier = 'javadoc'
|
||||
}
|
||||
task sourcesJar(type: Jar) {
|
||||
from sourceSets.main.allSource
|
||||
classifier = 'sources'
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
maven(MavenPublication) {
|
||||
from components.java
|
||||
|
||||
artifact javadocJar
|
||||
artifact sourcesJar
|
||||
|
||||
pom {
|
||||
resolveStrategy = Closure.DELEGATE_FIRST
|
||||
|
||||
description = "$description"
|
||||
name = "$name"
|
||||
url = "$url"
|
||||
|
||||
scm {
|
||||
developerConnection = "scm:git:[fetch=]${vcsUrl}[push=]${vcsUrl}"
|
||||
url = "$vcsUrl"
|
||||
}
|
||||
|
||||
developers {
|
||||
${developers.joinToString("\n") { """
|
||||
developer {
|
||||
id = "${it.id}"
|
||||
name = "${it.name}"
|
||||
email = "${it.eMail}"
|
||||
}
|
||||
""" }}
|
||||
}
|
||||
|
||||
licenses {
|
||||
${licenses.joinToString("\n") { """
|
||||
license {
|
||||
name = "${it.title}"
|
||||
url = "${it.url}"
|
||||
}
|
||||
""" }}
|
||||
}
|
||||
}
|
||||
repositories {
|
||||
${repositories.joinToString("\n ") { it.build(" ") }}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
${if (includeGpgSigning) """
|
||||
signing {
|
||||
useGpgCmd()
|
||||
sign publishing.publications
|
||||
}
|
||||
""" else ""}
|
||||
""".trimIndent()
|
@@ -0,0 +1,56 @@
|
||||
package dev.inmo.kmppscriptbuilder.core.export.mpp
|
||||
|
||||
import dev.inmo.kmppscriptbuilder.core.models.*
|
||||
|
||||
fun MavenConfig.buildMultiplatformMavenConfig(licenses: List<License>): String = """
|
||||
apply plugin: 'maven-publish'
|
||||
${if (includeGpgSigning) "apply plugin: 'signing'\n" else ""}
|
||||
task javadocsJar(type: Jar) {
|
||||
classifier = 'javadoc'
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications.all {
|
||||
artifact javadocsJar
|
||||
|
||||
pom {
|
||||
description = "$description"
|
||||
name = "$name"
|
||||
url = "$url"
|
||||
|
||||
scm {
|
||||
developerConnection = "scm:git:[fetch=]${vcsUrl}[push=]${vcsUrl}"
|
||||
url = "$vcsUrl"
|
||||
}
|
||||
|
||||
developers {
|
||||
${developers.joinToString("\n") { """
|
||||
developer {
|
||||
id = "${it.id}"
|
||||
name = "${it.name}"
|
||||
email = "${it.eMail}"
|
||||
}
|
||||
""" }}
|
||||
}
|
||||
|
||||
licenses {
|
||||
${licenses.joinToString("\n") { """
|
||||
license {
|
||||
name = "${it.title}"
|
||||
url = "${it.url}"
|
||||
}
|
||||
""" }}
|
||||
}
|
||||
}
|
||||
repositories {
|
||||
${repositories.joinToString("\n ") { it.build(" ") }}
|
||||
}
|
||||
}
|
||||
}
|
||||
${if (includeGpgSigning) """
|
||||
signing {
|
||||
useGpgCmd()
|
||||
sign publishing.publications
|
||||
}
|
||||
""" else ""}
|
||||
""".trimIndent()
|
@@ -0,0 +1,72 @@
|
||||
package dev.inmo.kmppscriptbuilder.core.models
|
||||
|
||||
import dev.inmo.kmppscriptbuilder.core.export.jvm_only.buildJvmOnlyMavenConfig
|
||||
import dev.inmo.kmppscriptbuilder.core.export.mpp.buildMultiplatformMavenConfig
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
|
||||
@Serializable(ProjectTypeSerializer::class)
|
||||
sealed class ProjectType {
|
||||
abstract val name: String
|
||||
// abstract fun buildBintrayGradleConfig(bintrayConfig: BintrayConfig, licenses: List<License>): String
|
||||
abstract fun buildMavenGradleConfig(mavenConfig: MavenConfig, licenses: List<License>): String
|
||||
}
|
||||
|
||||
@Serializer(ProjectType::class)
|
||||
object ProjectTypeSerializer : KSerializer<ProjectType> {
|
||||
override val descriptor: SerialDescriptor = String.serializer().descriptor
|
||||
override fun deserialize(decoder: Decoder): ProjectType {
|
||||
return when (decoder.decodeString()) {
|
||||
JVMProjectType.name -> JVMProjectType
|
||||
else -> MultiplatformProjectType
|
||||
}
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: ProjectType) {
|
||||
encoder.encodeString(value.name)
|
||||
}
|
||||
}
|
||||
|
||||
object MultiplatformProjectType : ProjectType() {
|
||||
override val name: String = "Multiplatform"
|
||||
// override fun buildBintrayGradleConfig(
|
||||
// bintrayConfig: BintrayConfig,
|
||||
// licenses: List<License>
|
||||
// ): String = bintrayConfig.buildMultiplatformGradleConfig(
|
||||
// licenses
|
||||
// )
|
||||
|
||||
override fun buildMavenGradleConfig(
|
||||
mavenConfig: MavenConfig,
|
||||
licenses: List<License>
|
||||
): String = mavenConfig.buildMultiplatformMavenConfig(
|
||||
licenses
|
||||
)
|
||||
}
|
||||
|
||||
object JVMProjectType : ProjectType() {
|
||||
override val name: String = "JVM"
|
||||
// override fun buildBintrayGradleConfig(
|
||||
// bintrayConfig: BintrayConfig,
|
||||
// licenses: List<License>
|
||||
// ): String = bintrayConfig.buildJvmOnlyGradleConfig(
|
||||
// licenses
|
||||
// )
|
||||
|
||||
override fun buildMavenGradleConfig(
|
||||
mavenConfig: MavenConfig,
|
||||
licenses: List<License>
|
||||
): String = mavenConfig.buildJvmOnlyMavenConfig(
|
||||
licenses
|
||||
)
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class Config(
|
||||
val licenses: List<License>,
|
||||
val mavenConfig: MavenConfig,
|
||||
val type: ProjectType = MultiplatformProjectType
|
||||
)
|
@@ -0,0 +1,10 @@
|
||||
package dev.inmo.kmppscriptbuilder.core.models
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class Developer(
|
||||
val id: String,
|
||||
val name: String,
|
||||
val eMail: String
|
||||
)
|
@@ -0,0 +1,48 @@
|
||||
package dev.inmo.kmppscriptbuilder.core.models
|
||||
|
||||
import dev.inmo.kmppscriptbuilder.core.utils.serialFormat
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.request.get
|
||||
import io.ktor.client.request.url
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.builtins.MapSerializer
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
|
||||
@Serializable
|
||||
data class License(
|
||||
val id: String,
|
||||
val title: String,
|
||||
val url: String? = null
|
||||
)
|
||||
|
||||
private val commonLicensesListDeserializer = MapSerializer(String.serializer(), License.serializer())
|
||||
|
||||
private var licenses: Map<String, License>? = null
|
||||
|
||||
suspend fun HttpClient.getLicenses(): Map<String, License> {
|
||||
val answer = get<String> {
|
||||
url("https://licenses.opendefinition.org/licenses/groups/all.json")
|
||||
}
|
||||
return serialFormat.decodeFromString(commonLicensesListDeserializer, answer).also { gotLicenses ->
|
||||
licenses = gotLicenses
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun HttpClient.searchLicense(name: String): List<License> {
|
||||
val licenses = licenses ?: getLicenses()
|
||||
val lowerCase = name.toLowerCase()
|
||||
val upperCase = name.toUpperCase()
|
||||
return licenses.values.filter {
|
||||
it.title.toLowerCase().contains(lowerCase) || it.title.toUpperCase().contains(upperCase) || it.title.contains(name)
|
||||
|| it.id.toLowerCase().contains(lowerCase) || it.id.toUpperCase().contains(upperCase) || it.id.contains(name)
|
||||
}
|
||||
}
|
||||
|
||||
fun Map<String, License>.searchLicense(name: String): List<License> {
|
||||
val lowerCase = name.toLowerCase()
|
||||
val upperCase = name.toUpperCase()
|
||||
return values.filter {
|
||||
it.title.toLowerCase().contains(lowerCase) || it.title.toUpperCase().contains(upperCase) || it.title.contains(name)
|
||||
|| it.id.toLowerCase().contains(lowerCase) || it.id.toUpperCase().contains(upperCase) || it.id.contains(name)
|
||||
}
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
package dev.inmo.kmppscriptbuilder.core.models
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class MavenConfig(
|
||||
val name: String,
|
||||
val description: String,
|
||||
val url: String,
|
||||
val vcsUrl: String,
|
||||
val includeGpgSigning: Boolean = false,
|
||||
val developers: List<Developer>,
|
||||
val repositories: List<MavenPublishingRepository> = emptyList()
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class MavenPublishingRepository(
|
||||
val name: String,
|
||||
val url: String
|
||||
) {
|
||||
private val nameCapitalized by lazy {
|
||||
name.toUpperCase()
|
||||
}
|
||||
|
||||
fun build(indent: String) = """maven {
|
||||
name = "$name"
|
||||
url = uri("$url")
|
||||
credentials {
|
||||
username = project.hasProperty('${nameCapitalized}_USER') ? project.property('${nameCapitalized}_USER') : System.getenv('${nameCapitalized}_USER')
|
||||
password = project.hasProperty('${nameCapitalized}_PASSWORD') ? project.property('${nameCapitalized}_PASSWORD') : System.getenv('${nameCapitalized}_PASSWORD')
|
||||
}
|
||||
}""".replace("\n", "\n$indent")
|
||||
}
|
||||
|
||||
val SonatypeRepository = MavenPublishingRepository("sonatype", "https://oss.sonatype.org/service/local/staging/deploy/maven2/")
|
@@ -0,0 +1,7 @@
|
||||
package dev.inmo.kmppscriptbuilder.core.utils
|
||||
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
val serialFormat = Json {
|
||||
ignoreUnknownKeys = true
|
||||
}
|
1
core/src/main/AndroidManifest.xml
Normal file
1
core/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1 @@
|
||||
<manifest package="dev.inmo.KotlinPublicationScriptsBuilder.core"/>
|
Reference in New Issue
Block a user