mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-11 02:50:15 +08:00
Add shadowJarMd5 for shadowed files
This commit is contained in:
parent
7a8944b1d6
commit
2a6d98ba16
@ -14,7 +14,7 @@ import java.time.Instant
|
|||||||
|
|
||||||
internal object MiraiConsoleBuildConstants { // auto-filled on build (task :mirai-console:fillBuildConstants)
|
internal object MiraiConsoleBuildConstants { // auto-filled on build (task :mirai-console:fillBuildConstants)
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
val buildDate: Instant = Instant.ofEpochSecond(1600596035)
|
val buildDate: Instant = Instant.ofEpochSecond(1600663022)
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
val version: SemVersion = SemVersion("1.0-RC-dev-28")
|
val version: SemVersion = SemVersion("1.0-RC-dev-28")
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "NOTHING_TO_INLINE", "RemoveRedundantBackticks")
|
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "NOTHING_TO_INLINE", "RemoveRedundantBackticks")
|
||||||
|
|
||||||
|
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.Task
|
import org.gradle.api.Task
|
||||||
import org.gradle.api.publish.maven.MavenPublication
|
import org.gradle.api.publish.maven.MavenPublication
|
||||||
@ -7,6 +8,10 @@ import org.gradle.api.tasks.TaskContainer
|
|||||||
import org.gradle.api.tasks.bundling.Jar
|
import org.gradle.api.tasks.bundling.Jar
|
||||||
import org.gradle.kotlin.dsl.*
|
import org.gradle.kotlin.dsl.*
|
||||||
import upload.Bintray
|
import upload.Bintray
|
||||||
|
import java.io.File
|
||||||
|
import java.io.InputStream
|
||||||
|
import java.io.OutputStream
|
||||||
|
import java.security.MessageDigest
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
@ -51,6 +56,44 @@ internal fun org.gradle.api.Project.`publishing`(configure: org.gradle.api.publi
|
|||||||
(this as org.gradle.api.plugins.ExtensionAware).extensions.configure("publishing", configure)
|
(this as org.gradle.api.plugins.ExtensionAware).extensions.configure("publishing", configure)
|
||||||
|
|
||||||
|
|
||||||
|
fun InputStream.md5(): ByteArray {
|
||||||
|
val digest = MessageDigest.getInstance("md5")
|
||||||
|
digest.reset()
|
||||||
|
use { input ->
|
||||||
|
object : OutputStream() {
|
||||||
|
override fun write(b: Int) {
|
||||||
|
digest.update(b.toByte())
|
||||||
|
}
|
||||||
|
}.use { output ->
|
||||||
|
input.copyTo(output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return digest.digest()
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalUnsignedTypes::class)
|
||||||
|
@JvmOverloads
|
||||||
|
fun ByteArray.toUHexString(
|
||||||
|
separator: String = " ",
|
||||||
|
offset: Int = 0,
|
||||||
|
length: Int = this.size - offset
|
||||||
|
): String {
|
||||||
|
if (length == 0) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
val lastIndex = offset + length
|
||||||
|
return buildString(length * 2) {
|
||||||
|
this@toUHexString.forEachIndexed { index, it ->
|
||||||
|
if (index in offset until lastIndex) {
|
||||||
|
var ret = it.toUByte().toString(16).toUpperCase()
|
||||||
|
if (ret.length == 1) ret = "0$ret"
|
||||||
|
append(ret)
|
||||||
|
if (index < lastIndex - 1) append(separator)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline fun Project.setupPublishing(
|
inline fun Project.setupPublishing(
|
||||||
artifactId: String,
|
artifactId: String,
|
||||||
bintrayRepo: String = "mirai",
|
bintrayRepo: String = "mirai",
|
||||||
@ -66,6 +109,32 @@ inline fun Project.setupPublishing(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
afterEvaluate {
|
||||||
|
|
||||||
|
val shadowJar = tasks.filterIsInstance<ShadowJar>().firstOrNull() ?: return@afterEvaluate
|
||||||
|
|
||||||
|
tasks.register("shadowJarMd5") {
|
||||||
|
val outFiles = shadowJar.outputs.files.map { file ->
|
||||||
|
File(file.parentFile, file.name.removeSuffix(".jar").removeSuffix("-all") + "-all.jar.md5")
|
||||||
|
}
|
||||||
|
|
||||||
|
outFiles.forEach { file ->
|
||||||
|
outputs.files(file)
|
||||||
|
}
|
||||||
|
|
||||||
|
doLast {
|
||||||
|
for (file in outFiles) {
|
||||||
|
file
|
||||||
|
.also { it.createNewFile() }
|
||||||
|
.writeText(file.inputStream().md5().toUHexString().trim(Char::isWhitespace))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.getByName("publish").dependsOn(this)
|
||||||
|
tasks.getByName("bintrayUpload").dependsOn(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Bintray.isBintrayAvailable(project)) {
|
if (Bintray.isBintrayAvailable(project)) {
|
||||||
bintray {
|
bintray {
|
||||||
val keyProps = Properties()
|
val keyProps = Properties()
|
||||||
@ -104,6 +173,11 @@ inline fun Project.setupPublishing(
|
|||||||
publications {
|
publications {
|
||||||
register("mavenJava", MavenPublication::class) {
|
register("mavenJava", MavenPublication::class) {
|
||||||
from(components["java"])
|
from(components["java"])
|
||||||
|
afterEvaluate {
|
||||||
|
for (file in tasks.getByName("shadowJarMd5").outputs.files) {
|
||||||
|
artifact(provider { file })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
groupId = rootProject.group.toString()
|
groupId = rootProject.group.toString()
|
||||||
this.artifactId = artifactId
|
this.artifactId = artifactId
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
object Versions {
|
object Versions {
|
||||||
const val core = "1.3.0"
|
const val core = "1.3.0"
|
||||||
const val console = "1.0-RC-dev-28"
|
const val console = "1.0-RC-dev-29"
|
||||||
const val consoleGraphical = "0.0.7"
|
const val consoleGraphical = "0.0.7"
|
||||||
const val consoleTerminal = console
|
const val consoleTerminal = console
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user