Fix build tasks for buildDate, cleanup

This commit is contained in:
Him188 2020-08-22 20:13:05 +08:00
parent 218fb2bdcc
commit 98224cfe5e
4 changed files with 17 additions and 19 deletions

View File

@ -2,6 +2,7 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.text.SimpleDateFormat
import java.time.Instant
import java.util.Date
import java.util.TimeZone
@ -112,20 +113,14 @@ tasks {
.let { file ->
file.writeText(
file.readText()
.replace(Regex("""val buildDate: Date = Date\((.*)\) //(.*)""")) {
"""
val buildDate: Date = Date(${System.currentTimeMillis()}L) // ${
SimpleDateFormat("yyyy-MM-dd HH:mm:ss").apply {
timeZone = TimeZone.getTimeZone("GMT+8")
}.format(Date())
}
""".trimIndent()
}
.replace(Regex("""const val version: String = "(.*)"""")) {
"""
const val version: String = "${Versions.console}"
""".trimIndent()
}
.replace(
"""val buildDate: Instant = Instant.ofEpochSecond(0)""",
"""val buildDate: Instant = Instant.ofEpochSecond(${Instant.now().getEpochSecond()})"""
)
.replace(
"""val version: Semver = Semver("0", Semver.SemverType.LOOSE)""",
"""val version: Semver = Semver("${project.version}", Semver.SemverType.LOOSE)"""
)
)
}
}

View File

@ -14,8 +14,8 @@ import java.time.Instant
internal object MiraiConsoleBuildConstants { // auto-filled on build (task :mirai-console:fillBuildConstants)
@JvmStatic
val buildDate: Instant = Instant.ofEpochMilli(1597935352287L) // 2020-08-20 22:55:52
val buildDate: Instant = Instant.ofEpochSecond(0)
@JvmStatic
val version: Semver = Semver("1.0-M2-1")
val version: Semver = Semver("0", Semver.SemverType.LOOSE)
}

View File

@ -35,8 +35,9 @@ import net.mamoe.mirai.console.util.ConsoleInput
import net.mamoe.mirai.console.util.ConsoleInternalAPI
import net.mamoe.mirai.utils.*
import java.nio.file.Path
import java.text.SimpleDateFormat
import java.time.Instant
import java.time.ZoneId
import java.time.format.DateTimeFormatter
import kotlin.coroutines.CoroutineContext
/**
@ -75,7 +76,8 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI
@OptIn(ConsoleExperimentalAPI::class)
internal fun doStart() {
val buildDateFormatted = SimpleDateFormat("yyyy-MM-dd").format(buildDate)
val buildDateFormatted =
buildDate.atZone(ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
mainLogger.info { "Starting mirai-console..." }
mainLogger.info { "Backend: version $version, built on $buildDateFormatted." }
mainLogger.info { frontEndDescription.render() }
@ -83,6 +85,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI
if (coroutineContext[Job] == null) {
throw IllegalMiraiConsoleImplementationError("The coroutineContext given to MiraiConsole must have a Job in it.")
}
MiraiConsole.job.invokeOnCompletion {
Bot.botInstances.forEach { kotlin.runCatching { it.close() }.exceptionOrNull()?.let(mainLogger::error) }
}

View File

@ -33,7 +33,7 @@ import java.io.PrintStream
*/
object MiraiConsolePureLoader {
@JvmStatic
fun main(args: Array<String>?) {
fun main(args: Array<String>) {
startup()
}
}