mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-09 18:00:33 +08:00
Setup sonatype remote
This commit is contained in:
parent
cd47c60e76
commit
0750e81b45
@ -13,6 +13,7 @@
|
|||||||
)
|
)
|
||||||
|
|
||||||
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
|
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
|
||||||
|
import keys.SecretKeys
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.publish.maven.MavenPublication
|
import org.gradle.api.publish.maven.MavenPublication
|
||||||
import org.gradle.api.tasks.bundling.Jar
|
import org.gradle.api.tasks.bundling.Jar
|
||||||
@ -21,16 +22,6 @@ import org.gradle.kotlin.dsl.get
|
|||||||
import org.gradle.kotlin.dsl.register
|
import org.gradle.kotlin.dsl.register
|
||||||
import org.gradle.kotlin.dsl.registering
|
import org.gradle.kotlin.dsl.registering
|
||||||
|
|
||||||
/*
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
fun Project.configureRemoteRepos() {
|
fun Project.configureRemoteRepos() {
|
||||||
tasks.register("ensureBintrayAvailable") {
|
tasks.register("ensureBintrayAvailable") {
|
||||||
doLast {
|
doLast {
|
||||||
@ -39,10 +30,27 @@ fun Project.configureRemoteRepos() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
publishing {
|
||||||
|
// sonatype
|
||||||
|
val keys = SecretKeys.getCache(project)
|
||||||
|
repositories {
|
||||||
|
val sonatype = keys.loadKey("sonatype")
|
||||||
|
if (sonatype.isValid) {
|
||||||
|
maven {
|
||||||
|
// Maven Central
|
||||||
|
setUrl("https://oss.sonatype.org/service/local/staging/deploy/maven2")
|
||||||
|
|
||||||
|
credentials {
|
||||||
|
username = sonatype.user
|
||||||
|
password = sonatype.password
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println("SonaType is not available")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (isBintrayAvailable()) {
|
if (isBintrayAvailable()) {
|
||||||
publishing {
|
|
||||||
repositories {
|
|
||||||
maven {
|
maven {
|
||||||
setUrl("https://api.bintray.com/maven/him188moe/mirai/mirai-core/;publish=1;override=1")
|
setUrl("https://api.bintray.com/maven/him188moe/mirai/mirai-core/;publish=1;override=1")
|
||||||
|
|
||||||
@ -51,7 +59,10 @@ fun Project.configureRemoteRepos() {
|
|||||||
password = Bintray.getKey(project)
|
password = Bintray.getKey(project)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
println("bintray isn't available.")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,11 +77,7 @@ inline fun Project.configurePublishing(
|
|||||||
configureRemoteRepos()
|
configureRemoteRepos()
|
||||||
apply<ShadowPlugin>()
|
apply<ShadowPlugin>()
|
||||||
|
|
||||||
if (!project.isBintrayAvailable()) {
|
if (project.isBintrayAvailable()) {
|
||||||
println("bintray isn't available. NO PUBLICATIONS WILL BE SET")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
bintray {
|
bintray {
|
||||||
user = Bintray.getUser(project)
|
user = Bintray.getUser(project)
|
||||||
key = Bintray.getKey(project)
|
key = Bintray.getKey(project)
|
||||||
@ -89,11 +96,16 @@ inline fun Project.configurePublishing(
|
|||||||
vcsUrl = vcs
|
vcsUrl = vcs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val sourcesJar by tasks.registering(Jar::class) {
|
val sourcesJar by tasks.registering(Jar::class) {
|
||||||
archiveClassifier.set("sources")
|
archiveClassifier.set("sources")
|
||||||
from(sourceSets["main"].allSource)
|
from(sourceSets["main"].allSource)
|
||||||
}
|
}
|
||||||
|
val stubJavadoc = tasks.register("javadocJar", Jar::class) {
|
||||||
|
@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
|
||||||
|
archiveClassifier.set("javadoc")
|
||||||
|
}
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
publications {
|
publications {
|
||||||
@ -110,6 +122,7 @@ inline fun Project.configurePublishing(
|
|||||||
)
|
)
|
||||||
|
|
||||||
artifact(sourcesJar.get())
|
artifact(sourcesJar.get())
|
||||||
|
artifact(stubJavadoc.get())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
configGpgSign(this@configurePublishing)
|
configGpgSign(this@configurePublishing)
|
||||||
|
114
buildSrc/src/main/kotlin/keys/SecretKeys.kt
Normal file
114
buildSrc/src/main/kotlin/keys/SecretKeys.kt
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019-2021 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
package keys
|
||||||
|
|
||||||
|
import org.gradle.api.Project
|
||||||
|
|
||||||
|
open class SecretKeys(
|
||||||
|
val type: String,
|
||||||
|
val user: String,
|
||||||
|
val password: String
|
||||||
|
) {
|
||||||
|
class Invalid(
|
||||||
|
type: String,
|
||||||
|
override val isDisabled: Boolean = false
|
||||||
|
) : SecretKeys(type, "", "") {
|
||||||
|
override val isValid: Boolean get() = false
|
||||||
|
override fun requireNotInvalid(): Nothing {
|
||||||
|
error(
|
||||||
|
"""
|
||||||
|
Key $type not found.
|
||||||
|
Please lease specify by creating a file $type.key in projectDir/build-secret-keys
|
||||||
|
or by providing JVM parameter '$type.user', `$type.password`
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val keyCaches = mutableMapOf<Project, ProjectKeysCache>()
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun getCache(project: Project): ProjectKeysCache =
|
||||||
|
keyCaches.computeIfAbsent(project, SecretKeys::ProjectKeysCache)
|
||||||
|
}
|
||||||
|
|
||||||
|
class ProjectKeysCache(val project: Project) {
|
||||||
|
val keys = mutableMapOf<String, SecretKeys>()
|
||||||
|
fun loadKey(type: String) = keys.computeIfAbsent(type, this::loadKey0)
|
||||||
|
|
||||||
|
private fun loadKey0(type: String): SecretKeys {
|
||||||
|
|
||||||
|
project.parent?.let { parent ->
|
||||||
|
getCache(parent).loadKey(type).takeIf {
|
||||||
|
it.isValid || it.isDisabled
|
||||||
|
}?.let { return it }
|
||||||
|
}
|
||||||
|
|
||||||
|
val secretKeys = project.projectDir.resolve("build-secret-keys")
|
||||||
|
|
||||||
|
kotlin.run {
|
||||||
|
val secretKeyFile = secretKeys.resolve("$type.disable").takeIf { it.isFile }
|
||||||
|
?: secretKeys.resolve("$type.disable.txt")
|
||||||
|
if (secretKeyFile.isFile) return Invalid(type, true) // Disabled
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load from secretKeys/$type.key
|
||||||
|
kotlin.run {
|
||||||
|
val secretKeyFile = secretKeys.resolve("$type.key").takeIf { it.isFile }
|
||||||
|
?: secretKeys.resolve("$type.key.txt")
|
||||||
|
if (secretKeyFile.isFile) {
|
||||||
|
secretKeyFile.bufferedReader().use {
|
||||||
|
return SecretKeys(type, it.readLine().trim(), it.readLine().trim())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Load from project/%type.key, user
|
||||||
|
kotlin.run {
|
||||||
|
val userFile = project.projectDir.resolve("$type.user.txt")
|
||||||
|
val keyFile = project.projectDir.resolve("$type.key.txt")
|
||||||
|
if (userFile.isFile && keyFile.isFile) {
|
||||||
|
return SecretKeys(type, userFile.readText().trim(), keyFile.readText().trim())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Load from property $type.user, $type.password
|
||||||
|
|
||||||
|
fun findProperty(type: String): String? {
|
||||||
|
val p = project.findProperty(type)
|
||||||
|
?: System.getProperty(type)
|
||||||
|
?: System.getenv(type)
|
||||||
|
|
||||||
|
return p?.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
val tUser = findProperty("$type.user")
|
||||||
|
?: findProperty("${type}_user")
|
||||||
|
|
||||||
|
val tPassword = findProperty("$type.password")
|
||||||
|
?: findProperty("$type.passwd")
|
||||||
|
?: findProperty("$type.key")
|
||||||
|
?: findProperty("${type}_password")
|
||||||
|
?: findProperty("${type}_passwd")
|
||||||
|
?: findProperty("${type}_key")
|
||||||
|
|
||||||
|
if (tUser != null && tPassword != null) {
|
||||||
|
return SecretKeys(type, tUser, tPassword)
|
||||||
|
}
|
||||||
|
|
||||||
|
return Invalid(type)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
open val isValid: Boolean get() = true
|
||||||
|
open val isDisabled: Boolean get() = false
|
||||||
|
open fun requireNotInvalid(): SecretKeys = this
|
||||||
|
}
|
@ -7,18 +7,9 @@
|
|||||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import keys.SecretKeys
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.kotlin.dsl.provideDelegate
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright 2019-2020 Mamoe Technologies and contributors.
|
|
||||||
*
|
|
||||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 with Mamoe Exceptions 许可证的约束, 可以在以下链接找到该许可证.
|
|
||||||
* Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 with Mamoe Exceptions license that can be found via the following link.
|
|
||||||
*
|
|
||||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
|
||||||
*/
|
|
||||||
fun Project.isBintrayAvailable() = Bintray.isBintrayAvailable(project)
|
fun Project.isBintrayAvailable() = Bintray.isBintrayAvailable(project)
|
||||||
|
|
||||||
@Suppress("DuplicatedCode")
|
@Suppress("DuplicatedCode")
|
||||||
@ -34,76 +25,18 @@ object Bintray {
|
|||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun getUser(project: Project): String {
|
fun getUser(project: Project): String {
|
||||||
kotlin.runCatching {
|
return SecretKeys.getCache(project)
|
||||||
@Suppress("UNUSED_VARIABLE", "LocalVariableName")
|
.loadKey("bintray")
|
||||||
val bintray_user: String by project
|
.requireNotInvalid()
|
||||||
return bintray_user
|
.user
|
||||||
}
|
|
||||||
|
|
||||||
kotlin.runCatching {
|
|
||||||
@Suppress("UNUSED_VARIABLE", "LocalVariableName")
|
|
||||||
val bintray_user: String by project.rootProject
|
|
||||||
return bintray_user
|
|
||||||
}
|
|
||||||
|
|
||||||
System.getProperty("bintray_user", null)?.let {
|
|
||||||
return it.trim()
|
|
||||||
}
|
|
||||||
|
|
||||||
File(File(System.getProperty("user.dir")).parent, "/bintray.user.txt").let { local ->
|
|
||||||
if (local.exists()) {
|
|
||||||
return local.readText().trim()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
File(File(System.getProperty("user.dir")), "/bintray.user.txt").let { local ->
|
|
||||||
if (local.exists()) {
|
|
||||||
return local.readText().trim()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
error(
|
|
||||||
"Cannot find bintray user, " +
|
|
||||||
"please specify by creating a file bintray.user.txt in project dir, " +
|
|
||||||
"or by providing JVM parameter 'bintray_user'"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun getKey(project: Project): String {
|
fun getKey(project: Project): String {
|
||||||
kotlin.runCatching {
|
return SecretKeys.getCache(project)
|
||||||
@Suppress("UNUSED_VARIABLE", "LocalVariableName")
|
.loadKey("bintray")
|
||||||
val bintray_key: String by project
|
.requireNotInvalid()
|
||||||
return bintray_key
|
.password
|
||||||
}
|
|
||||||
|
|
||||||
kotlin.runCatching {
|
|
||||||
@Suppress("UNUSED_VARIABLE", "LocalVariableName")
|
|
||||||
val bintray_key: String by project.rootProject
|
|
||||||
return bintray_key
|
|
||||||
}
|
|
||||||
|
|
||||||
System.getProperty("bintray_key", null)?.let {
|
|
||||||
return it.trim()
|
|
||||||
}
|
|
||||||
|
|
||||||
File(File(System.getProperty("user.dir")).parent, "/bintray.key.txt").let { local ->
|
|
||||||
if (local.exists()) {
|
|
||||||
return local.readText().trim()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
File(File(System.getProperty("user.dir")), "/bintray.key.txt").let { local ->
|
|
||||||
if (local.exists()) {
|
|
||||||
return local.readText().trim()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
error(
|
|
||||||
"Cannot find bintray key, " +
|
|
||||||
"please specify by creating a file bintray.key.txt in project dir, " +
|
|
||||||
"or by providing JVM parameter 'bintray_key'"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user