mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-11 02:50:15 +08:00
delete SemVersionRangeRequirementBuilder
This commit is contained in:
parent
a434e6f569
commit
2520e4bb35
@ -16,7 +16,6 @@ import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.*
|
|||||||
import net.mamoe.mirai.console.plugin.description.PluginDependency
|
import net.mamoe.mirai.console.plugin.description.PluginDependency
|
||||||
import net.mamoe.mirai.console.plugin.description.PluginDescription
|
import net.mamoe.mirai.console.plugin.description.PluginDescription
|
||||||
import net.mamoe.mirai.console.util.SemVersion
|
import net.mamoe.mirai.console.util.SemVersion
|
||||||
import net.mamoe.mirai.console.util.SemVersionRangeRequirementBuilder
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JVM 插件的描述. 通常作为 `plugin.yml`
|
* JVM 插件的描述. 通常作为 `plugin.yml`
|
||||||
@ -187,31 +186,6 @@ public class JvmPluginDescriptionBuilder(
|
|||||||
this.dependencies.add(PluginDependency(pluginId, null, isOptional))
|
this.dependencies.add(PluginDependency(pluginId, null, isOptional))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 示例:
|
|
||||||
*
|
|
||||||
* ```
|
|
||||||
* dependsOn("org.example.test-plugin") { "1.0.0".."1.2.0" }
|
|
||||||
* dependsOn("org.example.test-plugin") { npmPattern("1.x || >=2.5.0 || 5.0.0 - 7.2.3") }
|
|
||||||
* dependsOn("org.example.test-plugin") { ivyPattern("[1.0,2.0[") }
|
|
||||||
* dependsOn("org.example.test-plugin") { custom { it.toString() == "1.0.0" } }
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* @see PluginDependency
|
|
||||||
* @see SemVersionRangeRequirementBuilder
|
|
||||||
*/
|
|
||||||
@ILoveKuriyamaMiraiForever
|
|
||||||
public fun dependsOn(
|
|
||||||
@ResolveContext(PLUGIN_ID) pluginId: String,
|
|
||||||
isOptional: Boolean = false,
|
|
||||||
versionRequirement: SemVersionRangeRequirementBuilder.() -> SemVersion.Requirement,
|
|
||||||
): JvmPluginDescriptionBuilder =
|
|
||||||
apply {
|
|
||||||
this.dependencies.add(PluginDependency(pluginId,
|
|
||||||
SemVersionRangeRequirementBuilder.run(versionRequirement),
|
|
||||||
isOptional))
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Suppress("DEPRECATION_ERROR")
|
@Suppress("DEPRECATION_ERROR")
|
||||||
public fun build(): JvmPluginDescription =
|
public fun build(): JvmPluginDescription =
|
||||||
|
@ -1,95 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2019-2020 Mamoe Technologies and contributors.
|
|
||||||
*
|
|
||||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
|
||||||
* Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link.
|
|
||||||
*
|
|
||||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package net.mamoe.mirai.console.util
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构造 [SemVersion.Requirement] 的 DSL
|
|
||||||
*/
|
|
||||||
public object SemVersionRangeRequirementBuilder {
|
|
||||||
/** @see [SemVersion.parseRangeRequirement] */
|
|
||||||
@ILoveHim188moeForever
|
|
||||||
public fun parse(rule: String): SemVersion.Requirement = SemVersion.parseRangeRequirement(rule)
|
|
||||||
|
|
||||||
@ILoveHim188moeForever
|
|
||||||
public infix fun SemVersion.Requirement.or(other: SemVersion.Requirement): SemVersion.Requirement {
|
|
||||||
return object : SemVersion.Requirement {
|
|
||||||
override fun test(version: SemVersion): Boolean {
|
|
||||||
return this@or.test(version) || other.test(version)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String {
|
|
||||||
return "{${this@or}} || {$other}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ILoveHim188moeForever
|
|
||||||
public infix fun String.or(other: String): SemVersion.Requirement = parse(this) or parse(other)
|
|
||||||
|
|
||||||
@ILoveHim188moeForever
|
|
||||||
public infix fun SemVersion.Requirement.or(other: String): SemVersion.Requirement = or(parse(other))
|
|
||||||
|
|
||||||
@ILoveHim188moeForever
|
|
||||||
public infix fun String.or(other: SemVersion.Requirement): SemVersion.Requirement = parse(this) or other
|
|
||||||
|
|
||||||
@ILoveHim188moeForever
|
|
||||||
public infix fun SemVersion.Requirement.and(other: SemVersion.Requirement): SemVersion.Requirement {
|
|
||||||
return object : SemVersion.Requirement {
|
|
||||||
override fun test(version: SemVersion): Boolean {
|
|
||||||
return this@and.test(version) && other.test(version)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String {
|
|
||||||
return "{${this@and}} && {$other}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ILoveHim188moeForever
|
|
||||||
public infix fun String.and(other: String): SemVersion.Requirement = parse(this) and parse(other)
|
|
||||||
|
|
||||||
@ILoveHim188moeForever
|
|
||||||
public infix fun SemVersion.Requirement.and(other: String): SemVersion.Requirement = and(parse(other))
|
|
||||||
|
|
||||||
@ILoveHim188moeForever
|
|
||||||
public infix fun String.and(other: SemVersion.Requirement): SemVersion.Requirement = parse(this) and other
|
|
||||||
|
|
||||||
@Suppress("NOTHING_TO_INLINE")
|
|
||||||
@ILoveHim188moeForever
|
|
||||||
public fun custom(rule: (SemVersion) -> Boolean): SemVersion.Requirement = object : SemVersion.Requirement {
|
|
||||||
override fun test(version: SemVersion): Boolean = rule(version)
|
|
||||||
override fun toString(): String {
|
|
||||||
return "Custom{$rule}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 标注一个 [SemVersionRangeRequirementBuilder] DSL
|
|
||||||
*/
|
|
||||||
@Suppress("SpellCheckingInspection")
|
|
||||||
@Retention(AnnotationRetention.BINARY)
|
|
||||||
@DslMarker
|
|
||||||
internal annotation class ILoveHim188moeForever
|
|
||||||
|
|
||||||
/** [SemVersionRangeRequirementBuilder] 的使用示例 */
|
|
||||||
@Suppress("unused")
|
|
||||||
private class ExampleOfBuilder {
|
|
||||||
val e1 = SemVersionRangeRequirementBuilder.run {
|
|
||||||
"1.0.0" or "1.1.5"
|
|
||||||
}
|
|
||||||
val e2 = SemVersionRangeRequirementBuilder.run {
|
|
||||||
parse("> 1.0.0") and parse("< 1.2.3")
|
|
||||||
}
|
|
||||||
val e3 = SemVersionRangeRequirementBuilder.run {
|
|
||||||
("> 1.0.0" and "< 1.2.3") or "2.0.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user