mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 18:40:15 +08:00
Rename SemVersion.Companion.parse to SemVersion.Companion.invoke
This commit is contained in:
parent
eb7cd3811d
commit
e26e98d030
@ -17,5 +17,5 @@ internal object MiraiConsoleBuildConstants { // auto-filled on build (task :mira
|
|||||||
val buildDate: Instant = Instant.ofEpochSecond(1600596035)
|
val buildDate: Instant = Instant.ofEpochSecond(1600596035)
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
val version: SemVersion = SemVersion.parse("1.0-RC-dev-28")
|
val version: SemVersion = SemVersion("1.0-RC-dev-28")
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ internal object SemVersionInternal {
|
|||||||
private fun String.parseRule(): SemVersion.RangeRequirement {
|
private fun String.parseRule(): SemVersion.RangeRequirement {
|
||||||
val trimmed = trim()
|
val trimmed = trim()
|
||||||
if (directVersion.matches(trimmed)) {
|
if (directVersion.matches(trimmed)) {
|
||||||
val parsed = SemVersion.parse(trimmed)
|
val parsed = SemVersion.invoke(trimmed)
|
||||||
return SemVersion.RangeRequirement {
|
return SemVersion.RangeRequirement {
|
||||||
it.compareTo(parsed) == 0
|
it.compareTo(parsed) == 0
|
||||||
}
|
}
|
||||||
@ -101,8 +101,8 @@ internal object SemVersionInternal {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
(versionRange.matchEntire(trimmed) ?: versionMathRange.matchEntire(trimmed))?.let { range ->
|
(versionRange.matchEntire(trimmed) ?: versionMathRange.matchEntire(trimmed))?.let { range ->
|
||||||
var start = SemVersion.parse(range.groupValues[1])
|
var start = SemVersion.invoke(range.groupValues[1])
|
||||||
var end = SemVersion.parse(range.groupValues[4])
|
var end = SemVersion.invoke(range.groupValues[4])
|
||||||
if (start > end) {
|
if (start > end) {
|
||||||
val c = end
|
val c = end
|
||||||
end = start
|
end = start
|
||||||
@ -115,7 +115,7 @@ internal object SemVersionInternal {
|
|||||||
}
|
}
|
||||||
versionRule.matchEntire(trimmed)?.let { result ->
|
versionRule.matchEntire(trimmed)?.let { result ->
|
||||||
val operator = result.groupValues[1]
|
val operator = result.groupValues[1]
|
||||||
val version = SemVersion.parse(result.groupValues[7])
|
val version = SemVersion.invoke(result.groupValues[7])
|
||||||
return when (operator) {
|
return when (operator) {
|
||||||
">=" -> {
|
">=" -> {
|
||||||
SemVersion.RangeRequirement { it >= version }
|
SemVersion.RangeRequirement { it >= version }
|
||||||
|
@ -105,7 +105,7 @@ public class JvmPluginDescriptionBuilder(
|
|||||||
public constructor(
|
public constructor(
|
||||||
@ResolveContext(PLUGIN_NAME) id: String,
|
@ResolveContext(PLUGIN_NAME) id: String,
|
||||||
@ResolveContext(PLUGIN_VERSION) version: String,
|
@ResolveContext(PLUGIN_VERSION) version: String,
|
||||||
) : this(id, SemVersion.parse(version))
|
) : this(id, SemVersion(version))
|
||||||
|
|
||||||
private var name: String = id
|
private var name: String = id
|
||||||
private var author: String = ""
|
private var author: String = ""
|
||||||
@ -118,7 +118,7 @@ public class JvmPluginDescriptionBuilder(
|
|||||||
|
|
||||||
@ILoveKuriyamaMiraiForever
|
@ILoveKuriyamaMiraiForever
|
||||||
public fun version(@ResolveContext(PLUGIN_VERSION) value: String): JvmPluginDescriptionBuilder =
|
public fun version(@ResolveContext(PLUGIN_VERSION) value: String): JvmPluginDescriptionBuilder =
|
||||||
apply { this.version = SemVersion.parse(value) }
|
apply { this.version = SemVersion(value) }
|
||||||
|
|
||||||
@ILoveKuriyamaMiraiForever
|
@ILoveKuriyamaMiraiForever
|
||||||
public fun version(@ResolveContext(PLUGIN_VERSION) value: SemVersion): JvmPluginDescriptionBuilder =
|
public fun version(@ResolveContext(PLUGIN_VERSION) value: SemVersion): JvmPluginDescriptionBuilder =
|
||||||
@ -281,7 +281,7 @@ public data class SimpleJvmPluginDescription
|
|||||||
author: String = "",
|
author: String = "",
|
||||||
info: String = "",
|
info: String = "",
|
||||||
dependencies: Set<PluginDependency> = setOf(),
|
dependencies: Set<PluginDependency> = setOf(),
|
||||||
) : this(name, SemVersion.parse(version), id, author, info, dependencies)
|
) : this(name, SemVersion(version), id, author, info, dependencies)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
require(!name.contains(':')) { "':' is forbidden in plugin name" }
|
require(!name.contains(':')) { "':' is forbidden in plugin name" }
|
||||||
|
@ -21,6 +21,7 @@ import kotlinx.serialization.Serializable
|
|||||||
import kotlinx.serialization.Transient
|
import kotlinx.serialization.Transient
|
||||||
import kotlinx.serialization.builtins.serializer
|
import kotlinx.serialization.builtins.serializer
|
||||||
import net.mamoe.mirai.console.compiler.common.ResolveContext
|
import net.mamoe.mirai.console.compiler.common.ResolveContext
|
||||||
|
import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.PLUGIN_VERSION
|
||||||
import net.mamoe.mirai.console.internal.data.map
|
import net.mamoe.mirai.console.internal.data.map
|
||||||
import net.mamoe.mirai.console.internal.util.SemVersionInternal
|
import net.mamoe.mirai.console.internal.util.SemVersionInternal
|
||||||
import net.mamoe.mirai.console.util.SemVersion.Companion.equals
|
import net.mamoe.mirai.console.util.SemVersion.Companion.equals
|
||||||
@ -44,15 +45,20 @@ import net.mamoe.mirai.console.util.SemVersion.RangeRequirement
|
|||||||
* 对于核心版本号, 此实现稍微比 semver 宽松一些, 允许 x.y 的存在.
|
* 对于核心版本号, 此实现稍微比 semver 宽松一些, 允许 x.y 的存在.
|
||||||
*
|
*
|
||||||
* @see RangeRequirement
|
* @see RangeRequirement
|
||||||
|
* @see SemVersion.invoke
|
||||||
*/
|
*/
|
||||||
@Serializable(with = SemVersion.SemVersionAsStringSerializer::class)
|
@Serializable(with = SemVersion.SemVersionAsStringSerializer::class)
|
||||||
public data class SemVersion internal constructor(
|
public data class SemVersion
|
||||||
|
/**
|
||||||
|
* @see SemVersion.invoke 字符串解析
|
||||||
|
*/
|
||||||
|
internal constructor(
|
||||||
/** 核心版本号, 由主版本号, 次版本号和修订号组成, 其中修订号不一定存在 */
|
/** 核心版本号, 由主版本号, 次版本号和修订号组成, 其中修订号不一定存在 */
|
||||||
public val mainVersion: IntArray,
|
public val mainVersion: IntArray,
|
||||||
/** 先行版本号识别符 */
|
/** 先行版本号识别符 */
|
||||||
public val identifier: String? = null,
|
public val identifier: String? = null,
|
||||||
/** 版本号元数据, 不参与版本号对比([compareTo]), 但是参与版本号严格对比([equals]) */
|
/** 版本号元数据, 不参与版本号对比([compareTo]), 但是参与版本号严格对比([equals]) */
|
||||||
public val metadata: String? = null
|
public val metadata: String? = null,
|
||||||
) : Comparable<SemVersion> {
|
) : Comparable<SemVersion> {
|
||||||
/**
|
/**
|
||||||
* 一条依赖规则
|
* 一条依赖规则
|
||||||
@ -65,7 +71,7 @@ public data class SemVersion internal constructor(
|
|||||||
|
|
||||||
public object SemVersionAsStringSerializer : KSerializer<SemVersion> by String.serializer().map(
|
public object SemVersionAsStringSerializer : KSerializer<SemVersion> by String.serializer().map(
|
||||||
serializer = { it.toString() },
|
serializer = { it.toString() },
|
||||||
deserializer = { parse(it) }
|
deserializer = { SemVersion(it) }
|
||||||
)
|
)
|
||||||
|
|
||||||
public companion object {
|
public companion object {
|
||||||
@ -90,7 +96,8 @@ public data class SemVersion internal constructor(
|
|||||||
*/
|
*/
|
||||||
@Throws(IllegalArgumentException::class, NumberFormatException::class)
|
@Throws(IllegalArgumentException::class, NumberFormatException::class)
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
public fun parse(@ResolveContext(ResolveContext.Kind.PLUGIN_VERSION) version: String): SemVersion = SemVersionInternal.parse(version)
|
@JvmName("parse")
|
||||||
|
public operator fun invoke(@ResolveContext(PLUGIN_VERSION) version: String): SemVersion = SemVersionInternal.parse(version)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析一条依赖需求描述, 在无法解析的时候抛出 [IllegalArgumentException]
|
* 解析一条依赖需求描述, 在无法解析的时候抛出 [IllegalArgumentException]
|
||||||
@ -121,7 +128,7 @@ public data class SemVersion internal constructor(
|
|||||||
|
|
||||||
/** @see [RangeRequirement.test] */
|
/** @see [RangeRequirement.test] */
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
public fun RangeRequirement.test(version: String): Boolean = test(parse(version))
|
public fun RangeRequirement.test(version: String): Boolean = test(invoke(version))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当满足 [requirement] 时返回 true, 否则返回 false
|
* 当满足 [requirement] 时返回 true, 否则返回 false
|
||||||
|
@ -44,7 +44,7 @@ fun initTestEnvironment() {
|
|||||||
override val vendor: String
|
override val vendor: String
|
||||||
get() = "Test"
|
get() = "Test"
|
||||||
override val version: SemVersion
|
override val version: SemVersion
|
||||||
get() = SemVersion.parse("1.0.0")
|
get() = SemVersion("1.0.0")
|
||||||
|
|
||||||
}
|
}
|
||||||
override val builtInPluginLoaders: List<Lazy<PluginLoader<*, *>>> = listOf(lazy { JvmPluginLoader })
|
override val builtInPluginLoaders: List<Lazy<PluginLoader<*, *>>> = listOf(lazy { JvmPluginLoader })
|
||||||
|
@ -20,7 +20,7 @@ import org.junit.jupiter.api.Test
|
|||||||
internal class TestSemVersion {
|
internal class TestSemVersion {
|
||||||
@Test
|
@Test
|
||||||
internal fun testCompare() {
|
internal fun testCompare() {
|
||||||
fun String.sem(): SemVersion = SemVersion.parse(this)
|
fun String.sem(): SemVersion = SemVersion.invoke(this)
|
||||||
assert("1.0".sem() < "1.0.1".sem())
|
assert("1.0".sem() < "1.0.1".sem())
|
||||||
assert("1.0.0".sem() == "1.0".sem())
|
assert("1.0.0".sem() == "1.0".sem())
|
||||||
assert("1.1".sem() > "1.0.0".sem())
|
assert("1.1".sem() > "1.0.0".sem())
|
||||||
@ -85,12 +85,12 @@ internal class TestSemVersion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun String.check() {
|
private fun String.check() {
|
||||||
val sem = SemVersion.parse(this)
|
val sem = SemVersion.invoke(this)
|
||||||
assert(this == sem.toString()) { "$this != $sem" }
|
assert(this == sem.toString()) { "$this != $sem" }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun String.checkInvalid() {
|
private fun String.checkInvalid() {
|
||||||
kotlin.runCatching { SemVersion.parse(this) }
|
kotlin.runCatching { SemVersion.invoke(this) }
|
||||||
.onSuccess { assert(false) { "$this not a invalid sem-version" } }
|
.onSuccess { assert(false) { "$this not a invalid sem-version" } }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user