diff --git a/backend/mirai-console/src/internal/plugin/PluginManagerImpl.kt b/backend/mirai-console/src/internal/plugin/PluginManagerImpl.kt index e93fdb365..70bbdd4c5 100644 --- a/backend/mirai-console/src/internal/plugin/PluginManagerImpl.kt +++ b/backend/mirai-console/src/internal/plugin/PluginManagerImpl.kt @@ -28,7 +28,7 @@ import net.mamoe.mirai.console.plugin.loader.PluginLoadException import net.mamoe.mirai.console.plugin.loader.PluginLoader import net.mamoe.mirai.console.plugin.name import net.mamoe.mirai.console.util.CoroutineScopeUtils.childScope -import net.mamoe.mirai.console.util.SemVersion.Companion.contains +import net.mamoe.mirai.console.util.SemVersion import net.mamoe.mirai.utils.info import java.io.File import java.nio.file.Path @@ -248,8 +248,8 @@ internal fun List.findDependency(dependency: PluginDependency } internal fun PluginDescription.checkSatisfies(dependency: PluginDependency, plugin: PluginDescription) { - val requirement = dependency.versionRequirement - if (requirement != null && this.version !in requirement) { + val requirement = dependency.versionRequirement ?: return + if (SemVersion.parseRangeRequirement(requirement).test(this.version)) { throw PluginLoadException("Plugin '${plugin.id}' ('${plugin.id}') requires '${dependency.id}' with version $requirement while the resolved is ${this.version}") } } diff --git a/backend/mirai-console/src/plugin/description/PluginDependency.kt b/backend/mirai-console/src/plugin/description/PluginDependency.kt index b5f4669cd..ff53a02aa 100644 --- a/backend/mirai-console/src/plugin/description/PluginDependency.kt +++ b/backend/mirai-console/src/plugin/description/PluginDependency.kt @@ -25,7 +25,7 @@ import net.mamoe.mirai.console.util.SemVersion * @see PluginDescription.dependencies */ @Serializable(with = PluginDependency.PluginDependencyAsStringSerializer::class) -public class PluginDependency @JvmOverloads constructor( +public data class PluginDependency @JvmOverloads constructor( /** * 依赖插件 ID, [PluginDescription.id] */ @@ -37,7 +37,7 @@ public class PluginDependency @JvmOverloads constructor( * * @see SemVersion.Requirement */ - public val versionRequirement: SemVersion.Requirement? = null, + public val versionRequirement: String? = null, /** * 若为 `false`, 插件在找不到此依赖时也能正常加载. */ @@ -63,32 +63,12 @@ public class PluginDependency @JvmOverloads constructor( public override fun toString(): String = buildString { append(id) - versionRequirement?.rule?.let(::append) + versionRequirement?.let(::append) if (isOptional) { append('?') } } - public override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as PluginDependency - - if (id != other.id) return false - if (versionRequirement?.rule != other.versionRequirement?.rule) return false - if (isOptional != other.isOptional) return false - - return true - } - - public override fun hashCode(): Int { - var result = id.hashCode() - result = 31 * result + (versionRequirement?.rule?.hashCode() ?: 0) - result = 31 * result + isOptional.hashCode() - return result - } - public companion object { /** * 解析 "$id:$versionRequirement?" @@ -101,7 +81,7 @@ public class PluginDependency @JvmOverloads constructor( val (id, version) = string.removeSuffix("?").let { it.substringBeforeLast(':') to it.substringAfterLast(':', "") } - return PluginDependency(id, SemVersion.parseRangeRequirement(version), optional) + return PluginDependency(id, version, optional) } } diff --git a/backend/mirai-console/src/plugin/jvm/JvmPluginDescription.kt b/backend/mirai-console/src/plugin/jvm/JvmPluginDescription.kt index 7aa466b3b..ee17ceef4 100644 --- a/backend/mirai-console/src/plugin/jvm/JvmPluginDescription.kt +++ b/backend/mirai-console/src/plugin/jvm/JvmPluginDescription.kt @@ -191,20 +191,6 @@ public class JvmPluginDescriptionBuilder( } } - /** - * isOptional = false - * - * @see PluginDependency - */ - @ILoveKuriyamaMiraiForever - public fun dependsOn( - @ResolveContext(PLUGIN_ID) pluginId: String, - versionRequirement: SemVersion.Requirement, - isOptional: Boolean = false, - ): JvmPluginDescriptionBuilder = apply { - this.dependencies.add(PluginDependency(pluginId, versionRequirement, isOptional)) - } - /** * @see PluginDependency */ @@ -214,7 +200,7 @@ public class JvmPluginDescriptionBuilder( @ResolveContext(VERSION_REQUIREMENT) versionRequirement: String, isOptional: Boolean = false, ): JvmPluginDescriptionBuilder = apply { - this.dependencies.add(PluginDependency(pluginId, SemVersion.parseRangeRequirement(versionRequirement), isOptional)) + this.dependencies.add(PluginDependency(pluginId, versionRequirement, isOptional)) } /** @@ -255,7 +241,7 @@ public class JvmPluginDescriptionBuilder( internal data class SimpleJvmPluginDescription @JvmOverloads constructor( override val id: String, - override val name: String = id, + override val name: String, override val version: SemVersion, override val author: String = "", override val info: String = "", diff --git a/tools/gradle-plugin/src/VersionConstants.kt b/tools/gradle-plugin/src/VersionConstants.kt index feb3369c6..1f9ccb633 100644 --- a/tools/gradle-plugin/src/VersionConstants.kt +++ b/tools/gradle-plugin/src/VersionConstants.kt @@ -10,6 +10,6 @@ package net.mamoe.mirai.console.gradle internal object VersionConstants { - const val CONSOLE_VERSION = "1.0-RC-1" // value is written here automatically during build + const val CONSOLE_VERSION = "1.0-RC2-dev-1" // value is written here automatically during build const val CORE_VERSION = "1.3.3" // value is written here automatically during build } \ No newline at end of file