Him188 5 tahun lalu
induk
melakukan
6b23d5ba27

+ 2 - 66
backend/mirai-console/build.gradle.kts

@@ -1,5 +1,4 @@
 import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
-import upload.Bintray
 import java.text.SimpleDateFormat
 import java.util.*
 
@@ -8,7 +7,7 @@ plugins {
     kotlin("plugin.serialization") version Versions.kotlin
     id("java")
     `maven-publish`
-    id("com.jfrog.bintray") version Versions.bintray
+    id("com.jfrog.bintray")
 }
 
 version = Versions.console
@@ -123,69 +122,6 @@ tasks {
 
 // region PUBLISHING
 
-tasks.register("ensureBintrayAvailable") {
-    doLast {
-        if (!Bintray.isBintrayAvailable(project)) {
-            error("bintray isn't available. ")
-        }
-    }
-}
-
-if (Bintray.isBintrayAvailable(project)) {
-    bintray {
-        val keyProps = Properties()
-        val keyFile = file("../keys.properties")
-        if (keyFile.exists()) keyFile.inputStream().use { keyProps.load(it) }
-        if (keyFile.exists()) keyFile.inputStream().use { keyProps.load(it) }
-
-        user = Bintray.getUser(project)
-        key = Bintray.getKey(project)
-        setPublications("mavenJava")
-        setConfigurations("archives")
-
-        pkg.apply {
-            repo = "mirai"
-            name = "mirai-console"
-            setLicenses("AGPLv3")
-            publicDownloadNumbers = true
-            vcsUrl = "https://github.com/mamoe/mirai-console"
-        }
-    }
-
-    @Suppress("DEPRECATION")
-    val sourcesJar by tasks.registering(Jar::class) {
-        classifier = "sources"
-        from(sourceSets.main.get().allSource)
-    }
-
-    publishing {
-        /*
-        repositories {
-            maven {
-                // change to point to your repo, e.g. http://my.org/repo
-                url = uri("$buildDir/repo")
-            }
-        }*/
-        publications {
-            register("mavenJava", MavenPublication::class) {
-                from(components["java"])
-
-                groupId = rootProject.group.toString()
-                artifactId = "mirai-console"
-                version = version
-
-                pom.withXml {
-                    val root = asNode()
-                    root.appendNode("description", description)
-                    root.appendNode("name", project.name)
-                    root.appendNode("url", "https://github.com/mamoe/mirai")
-                    root.children().last()
-                }
-
-                artifact(sourcesJar.get())
-            }
-        }
-    }
-} else println("bintray isn't available. NO PUBLICATIONS WILL BE SET")
+setupPublishing("mirai-console")
 
 // endregion

+ 3 - 1
build.gradle.kts

@@ -1,5 +1,7 @@
 @file:Suppress("UnstableApiUsage")
-
+plugins {
+    id("com.jfrog.bintray") version Versions.bintray apply false
+}
 tasks.withType(JavaCompile::class.java) {
     options.encoding = "UTF8"
 }

+ 2 - 2
buildSrc/build.gradle.kts

@@ -28,10 +28,10 @@ dependencies {
     api(ktor("client-cio", "1.3.2"))
     api(ktor("client-json", "1.3.2"))
 
-    //api(gradleApi())
+    compileOnly(gradleApi())
     //compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72")
     compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72")
     //runtimeOnly("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72")
-
+    compileOnly("com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5")
     api("com.github.jengelman.gradle.plugins:shadow:6.0.0")
 }

+ 126 - 0
buildSrc/src/main/kotlin/PublishingHelpers.kt

@@ -0,0 +1,126 @@
+@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
+
+import org.gradle.api.Project
+import org.gradle.api.Task
+import org.gradle.api.publish.maven.MavenPublication
+import org.gradle.api.tasks.TaskContainer
+import org.gradle.api.tasks.bundling.Jar
+import org.gradle.kotlin.dsl.*
+import upload.Bintray
+import java.util.*
+import kotlin.reflect.KProperty
+
+/*
+ * Copyright 2020 Mamoe Technologies and contributors.
+ *
+ * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
+ * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
+ *
+ * https://github.com/mamoe/mirai/blob/master/LICENSE
+ */
+
+/**
+ * Configures the [bintray][com.jfrog.bintray.gradle.BintrayExtension] extension.
+ */
+@PublishedApi
+internal fun org.gradle.api.Project.`bintray`(configure: com.jfrog.bintray.gradle.BintrayExtension.() -> Unit): Unit =
+    (this as org.gradle.api.plugins.ExtensionAware).extensions.configure("bintray", configure)
+
+@PublishedApi
+internal operator fun <U : Task> RegisteringDomainObjectDelegateProviderWithTypeAndAction<out TaskContainer, U>.provideDelegate(
+    receiver: Any?,
+    property: KProperty<*>
+) = ExistingDomainObjectDelegate.of(
+    delegateProvider.register(property.name, type.java, action)
+)
+
+@PublishedApi
+internal val org.gradle.api.Project.`sourceSets`: org.gradle.api.tasks.SourceSetContainer
+    get() =
+        (this as org.gradle.api.plugins.ExtensionAware).extensions.getByName("sourceSets") as org.gradle.api.tasks.SourceSetContainer
+
+@PublishedApi
+internal operator fun <T> ExistingDomainObjectDelegate<out T>.getValue(receiver: Any?, property: KProperty<*>): T =
+    delegate
+
+/**
+ * Configures the [publishing][org.gradle.api.publish.PublishingExtension] extension.
+ */
+@PublishedApi
+internal fun org.gradle.api.Project.`publishing`(configure: org.gradle.api.publish.PublishingExtension.() -> Unit): Unit =
+    (this as org.gradle.api.plugins.ExtensionAware).extensions.configure("publishing", configure)
+
+
+inline fun Project.setupPublishing(
+    artifactId: String,
+    bintrayRepo: String = "mirai",
+    bintrayPkgName: String = "mirai-console",
+    vcs: String = "https://github.com/mamoe/mirai-console"
+) {
+
+    tasks.register("ensureBintrayAvailable") {
+        doLast {
+            if (!Bintray.isBintrayAvailable(project)) {
+                error("bintray isn't available. ")
+            }
+        }
+    }
+
+    if (Bintray.isBintrayAvailable(project)) {
+        bintray {
+            val keyProps = Properties()
+            val keyFile = file("../keys.properties")
+            if (keyFile.exists()) keyFile.inputStream().use { keyProps.load(it) }
+            if (keyFile.exists()) keyFile.inputStream().use { keyProps.load(it) }
+
+            user = Bintray.getUser(project)
+            key = Bintray.getKey(project)
+            setPublications("mavenJava")
+            setConfigurations("archives")
+
+            pkg.apply {
+                repo = bintrayRepo
+                name = bintrayPkgName
+                setLicenses("AGPLv3")
+                publicDownloadNumbers = true
+                vcsUrl = vcs
+            }
+        }
+
+        @Suppress("DEPRECATION")
+        val sourcesJar by tasks.registering(Jar::class) {
+            classifier = "sources"
+            from(sourceSets["main"].allSource)
+        }
+
+        publishing {
+            /*
+            repositories {
+                maven {
+                    // change to point to your repo, e.g. http://my.org/repo
+                    url = uri("$buildDir/repo")
+                }
+            }*/
+            publications {
+                register("mavenJava", MavenPublication::class) {
+                    from(components["java"])
+
+                    groupId = rootProject.group.toString()
+                    this.artifactId = artifactId
+                    version = version
+
+                    pom.withXml {
+                        val root = asNode()
+                        root.appendNode("description", description)
+                        root.appendNode("name", project.name)
+                        root.appendNode("url", vcs)
+                        root.children().last()
+                    }
+
+                    artifact(sourcesJar.get())
+                }
+            }
+        }
+    } else println("bintray isn't available. NO PUBLICATIONS WILL BE SET")
+
+}

+ 1 - 1
buildSrc/src/main/kotlin/Versions.kt

@@ -21,5 +21,5 @@ object Versions {
 
     const val androidGradle = "3.6.2"
 
-    const val bintray = "1.8.4"
+    const val bintray = "1.8.5"
 }

+ 6 - 2
frontend/mirai-console-pure/build.gradle.kts

@@ -3,7 +3,7 @@ plugins {
     kotlin("plugin.serialization") version Versions.kotlin
     id("java")
     `maven-publish`
-    id("com.jfrog.bintray") version Versions.bintray
+    id("com.jfrog.bintray")
 }
 
 kotlin {
@@ -53,4 +53,8 @@ ext {
 
 version = Versions.consolePure
 
-description = "Console Pure CLI frontend for mirai"
+description = "Console Pure CLI frontend for mirai"
+
+setupPublishing("mirai-console-pure", bintrayPkgName = "mirai-console-pure")
+
+// endregion

+ 1 - 1
frontend/mirai-console-pure/src/main/kotlin/net/mamoe/mirai/console/pure/MiraiConsolePure.kt

@@ -48,7 +48,7 @@ class MiraiConsolePure @JvmOverloads constructor(
     override val rootDir: File = File("."),
     override val builtInPluginLoaders: List<PluginLoader<*, *>> = listOf(DeferredPluginLoader { JarPluginLoader }),
     override val frontEnd: MiraiConsoleFrontEnd = MiraiConsoleFrontEndPure,
-    override val mainLogger: MiraiLogger = frontEnd.loggerFor("Console"),
+    override val mainLogger: MiraiLogger = frontEnd.loggerFor("main"),
     override val consoleCommandSender: ConsoleCommandSender = ConsoleCommandSenderImpl,
     override val settingStorage: SettingStorage = MultiFileSettingStorage(rootDir)
 ) : IMiraiConsole, CoroutineScope by CoroutineScope(SupervisorJob()) {