mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-27 00:30:17 +08:00
Fix build, Fix code style
This commit is contained in:
parent
9514a5c3e8
commit
57c30e4689
@ -26,11 +26,6 @@ internal object SemVersionInternal {
|
|||||||
private val versionMathRange =
|
private val versionMathRange =
|
||||||
"""\[([0-9]+(\.[0-9]+)+(|[\-+].+))\s*\,\s*([0-9]+(\.[0-9]+)+(|[\-+].+))\]""".toRegex()
|
"""\[([0-9]+(\.[0-9]+)+(|[\-+].+))\s*\,\s*([0-9]+(\.[0-9]+)+(|[\-+].+))\]""".toRegex()
|
||||||
private val versionRule = """^((\>\=)|(\<\=)|(\=)|(\>)|(\<))\s*([0-9]+(\.[0-9]+)+(|[\-+].+))$""".toRegex()
|
private val versionRule = """^((\>\=)|(\<\=)|(\=)|(\>)|(\<))\s*([0-9]+(\.[0-9]+)+(|[\-+].+))$""".toRegex()
|
||||||
private fun Collection<*>.dump() {
|
|
||||||
forEachIndexed { index, value ->
|
|
||||||
println("$index, $value")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private val SEM_VERSION_REGEX =
|
private val SEM_VERSION_REGEX =
|
||||||
"""^(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$""".toRegex()
|
"""^(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$""".toRegex()
|
||||||
@ -86,18 +81,18 @@ internal object SemVersionInternal {
|
|||||||
val trimmed = trim()
|
val trimmed = trim()
|
||||||
if (directVersion.matches(trimmed)) {
|
if (directVersion.matches(trimmed)) {
|
||||||
val parsed = SemVersion.invoke(trimmed)
|
val parsed = SemVersion.invoke(trimmed)
|
||||||
return SemVersion.Requirement {
|
return object : SemVersion.Requirement {
|
||||||
it.compareTo(parsed) == 0
|
override fun test(version: SemVersion): Boolean = version.compareTo(parsed) == 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (versionSelect.matches(trimmed)) {
|
if (versionSelect.matches(trimmed)) {
|
||||||
val regex = ("^" +
|
val regex = ("^" +
|
||||||
trimmed.replace(".", "\\.")
|
trimmed.replace(".", "\\.")
|
||||||
.replace("x", ".+") +
|
.replace("x", ".+") +
|
||||||
"$"
|
"$"
|
||||||
).toRegex()
|
).toRegex()
|
||||||
return SemVersion.Requirement {
|
return object : SemVersion.Requirement {
|
||||||
regex.matches(it.toString())
|
override fun test(version: SemVersion): Boolean = regex.matches(version.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(versionRange.matchEntire(trimmed) ?: versionMathRange.matchEntire(trimmed))?.let { range ->
|
(versionRange.matchEntire(trimmed) ?: versionMathRange.matchEntire(trimmed))?.let { range ->
|
||||||
@ -109,44 +104,49 @@ internal object SemVersionInternal {
|
|||||||
start = c
|
start = c
|
||||||
}
|
}
|
||||||
val compareRange = start..end
|
val compareRange = start..end
|
||||||
return SemVersion.Requirement {
|
return object : SemVersion.Requirement {
|
||||||
it in compareRange
|
override fun test(version: SemVersion): Boolean = version in compareRange
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
versionRule.matchEntire(trimmed)?.let { result ->
|
versionRule.matchEntire(trimmed)?.let { result ->
|
||||||
val operator = result.groupValues[1]
|
val operator = result.groupValues[1]
|
||||||
val version = SemVersion.invoke(result.groupValues[7])
|
val version1 = SemVersion.invoke(result.groupValues[7])
|
||||||
return when (operator) {
|
return when (operator) {
|
||||||
">=" -> {
|
">=" -> {
|
||||||
SemVersion.Requirement { it >= version }
|
object : SemVersion.Requirement {
|
||||||
|
override fun test(version: SemVersion): Boolean = version >= version1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
">" -> {
|
">" -> {
|
||||||
SemVersion.Requirement { it > version }
|
object : SemVersion.Requirement {
|
||||||
|
override fun test(version: SemVersion): Boolean = version > version1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
"<=" -> {
|
"<=" -> {
|
||||||
SemVersion.Requirement { it <= version }
|
object : SemVersion.Requirement {
|
||||||
|
override fun test(version: SemVersion): Boolean = version <= version1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
"<" -> {
|
"<" -> {
|
||||||
SemVersion.Requirement { it < version }
|
object : SemVersion.Requirement {
|
||||||
|
override fun test(version: SemVersion): Boolean = version < version1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
"=" -> {
|
"=" -> {
|
||||||
SemVersion.Requirement { it.compareTo(version) == 0 }
|
object : SemVersion.Requirement {
|
||||||
|
override fun test(version: SemVersion): Boolean = version.compareTo(version1) == 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else -> throw AssertionError("operator=$operator, version=$version")
|
else -> error("operator=$operator, version=$version1")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw UnsupportedOperationException("Cannot parse $this")
|
throw IllegalArgumentException("Cannot parse $this")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun SemVersion.Requirement.withRule(rule: String): SemVersion.Requirement {
|
private fun SemVersion.Requirement.withRule(rule: String): SemVersion.Requirement {
|
||||||
return object : SemVersion.Requirement {
|
return object : SemVersion.Requirement {
|
||||||
override fun test(version: SemVersion): Boolean {
|
override fun test(version: SemVersion): Boolean = this@withRule.test(version)
|
||||||
return this@withRule.test(version)
|
override fun toString(): String = rule
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String {
|
|
||||||
return rule
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,11 +159,13 @@ internal object SemVersionInternal {
|
|||||||
it.parseRule().withRule(it)
|
it.parseRule().withRule(it)
|
||||||
}.let { checks ->
|
}.let { checks ->
|
||||||
if (checks.size == 1) return checks[0]
|
if (checks.size == 1) return checks[0]
|
||||||
SemVersion.Requirement {
|
object : SemVersion.Requirement {
|
||||||
checks.forEach { rule ->
|
override fun test(version: SemVersion): Boolean {
|
||||||
if (rule.test(it)) return@Requirement true
|
checks.forEach { rule ->
|
||||||
|
if (rule.test(version)) return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
return@Requirement false
|
|
||||||
}.withRule(requirement)
|
}.withRule(requirement)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user