mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-25 15:40:28 +08:00
Add String variant of dependsOn.versionRequirement; Add ResolveContext.VERSION_REQUIREMENT
This commit is contained in:
parent
643ac52bc7
commit
e303eae15a
@ -40,6 +40,8 @@ public annotation class ResolveContext(
|
||||
PLUGIN_NAME, // ILLEGAL_PLUGIN_DESCRIPTION
|
||||
PLUGIN_VERSION, // ILLEGAL_PLUGIN_DESCRIPTION
|
||||
|
||||
VERSION_REQUIREMENT, // ILLEGAL_VERSION_REQUIREMENT // TODO
|
||||
|
||||
COMMAND_NAME, // ILLEGAL_COMMAND_NAME
|
||||
|
||||
PERMISSION_NAMESPACE, // ILLEGAL_COMMAND_NAMESPACE
|
||||
|
@ -148,18 +148,6 @@ public class JvmPluginDescriptionBuilder(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see PluginDependency
|
||||
*/
|
||||
@ILoveKuriyamaMiraiForever
|
||||
public fun dependsOn(
|
||||
@ResolveContext(PLUGIN_ID) pluginId: String,
|
||||
isOptional: Boolean = false,
|
||||
versionRequirement: SemVersion.Requirement,
|
||||
): JvmPluginDescriptionBuilder = apply {
|
||||
this.dependencies.add(PluginDependency(pluginId, versionRequirement, isOptional))
|
||||
}
|
||||
|
||||
/**
|
||||
* isOptional = false
|
||||
*
|
||||
@ -169,8 +157,21 @@ public class JvmPluginDescriptionBuilder(
|
||||
public fun dependsOn(
|
||||
@ResolveContext(PLUGIN_ID) pluginId: String,
|
||||
versionRequirement: SemVersion.Requirement,
|
||||
isOptional: Boolean = false,
|
||||
): JvmPluginDescriptionBuilder = apply {
|
||||
this.dependencies.add(PluginDependency(pluginId, versionRequirement, false))
|
||||
this.dependencies.add(PluginDependency(pluginId, versionRequirement, isOptional))
|
||||
}
|
||||
|
||||
/**
|
||||
* @see PluginDependency
|
||||
*/
|
||||
@ILoveKuriyamaMiraiForever
|
||||
public fun dependsOn(
|
||||
@ResolveContext(PLUGIN_ID) pluginId: String,
|
||||
@ResolveContext(VERSION_REQUIREMENT) versionRequirement: String,
|
||||
isOptional: Boolean = false,
|
||||
): JvmPluginDescriptionBuilder = apply {
|
||||
this.dependencies.add(PluginDependency(pluginId, SemVersion.parseRangeRequirement(versionRequirement), isOptional))
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -22,6 +22,7 @@ import kotlinx.serialization.Transient
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
import net.mamoe.mirai.console.compiler.common.ResolveContext
|
||||
import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.PLUGIN_VERSION
|
||||
import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.VERSION_REQUIREMENT
|
||||
import net.mamoe.mirai.console.internal.data.map
|
||||
import net.mamoe.mirai.console.internal.util.semver.SemVersionInternal
|
||||
import net.mamoe.mirai.console.util.SemVersion.Companion.equals
|
||||
@ -139,7 +140,7 @@ internal constructor(
|
||||
*/
|
||||
@Throws(IllegalArgumentException::class)
|
||||
@JvmStatic
|
||||
public fun parseRangeRequirement(requirement: String): Requirement =
|
||||
public fun parseRangeRequirement(@ResolveContext(VERSION_REQUIREMENT) requirement: String): Requirement =
|
||||
SemVersionInternal.parseRangeRequirement(requirement)
|
||||
|
||||
/** @see [Requirement.test] */
|
||||
@ -152,6 +153,12 @@ internal constructor(
|
||||
@JvmStatic
|
||||
public fun SemVersion.satisfies(requirement: Requirement): Boolean = requirement.test(this)
|
||||
|
||||
/**
|
||||
* 当满足 [requirement] 时返回 true, 否则返回 false
|
||||
*/
|
||||
@JvmStatic
|
||||
public fun SemVersion.satisfies(@ResolveContext(VERSION_REQUIREMENT) requirement: String): Boolean = parseRangeRequirement(requirement).test(this)
|
||||
|
||||
/** for Kotlin only */
|
||||
@JvmStatic
|
||||
@JvmSynthetic
|
||||
|
Loading…
Reference in New Issue
Block a user