Add String variant of dependsOn.versionRequirement; Add ResolveContext.VERSION_REQUIREMENT

This commit is contained in:
Him188 2020-10-23 12:49:00 +08:00
parent 643ac52bc7
commit e303eae15a
3 changed files with 24 additions and 14 deletions

View File

@ -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

View File

@ -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))
}
/**

View File

@ -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