mirror of
https://github.com/plexusorg/plugin-yml.git
synced 2024-12-22 16:25:06 +00:00
Extend validation of plugin descriptions
This commit is contained in:
parent
17d042ee9b
commit
85b60f7cb6
3 changed files with 19 additions and 26 deletions
|
@ -30,6 +30,10 @@ import org.gradle.api.Project
|
||||||
|
|
||||||
class BukkitPlugin : PlatformPlugin<BukkitPluginDescription>("Bukkit", "plugin.yml") {
|
class BukkitPlugin : PlatformPlugin<BukkitPluginDescription>("Bukkit", "plugin.yml") {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@JvmStatic private val VALID_NAME = Regex("^[A-Za-z0-9 _.-]+$")
|
||||||
|
}
|
||||||
|
|
||||||
override fun createExtension(project: Project) = BukkitPluginDescription(project)
|
override fun createExtension(project: Project) = BukkitPluginDescription(project)
|
||||||
|
|
||||||
override fun setDefaults(project: Project, description: BukkitPluginDescription) {
|
override fun setDefaults(project: Project, description: BukkitPluginDescription) {
|
||||||
|
@ -41,13 +45,14 @@ class BukkitPlugin : PlatformPlugin<BukkitPluginDescription>("Bukkit", "plugin.y
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun validate(description: BukkitPluginDescription) {
|
override fun validate(description: BukkitPluginDescription) {
|
||||||
if (description.name == null) {
|
val name = description.name ?: throw InvalidPluginDescriptionException("Plugin name is not set")
|
||||||
throw InvalidPluginDescriptionException("Plugin name is not set")
|
if (!VALID_NAME.matches(name)) throw InvalidPluginDescriptionException("Invalid plugin name: should match $VALID_NAME")
|
||||||
}
|
|
||||||
|
|
||||||
if (description.main == null) {
|
if (description.version.isNullOrEmpty()) throw InvalidPluginDescriptionException("Plugin version is not set")
|
||||||
throw InvalidPluginDescriptionException("Main class is not defined")
|
|
||||||
}
|
val main = description.main ?: throw InvalidPluginDescriptionException("Main class is not defined")
|
||||||
|
if (main.isEmpty()) throw InvalidPluginDescriptionException("Main class cannot be empty")
|
||||||
|
if (main.startsWith("org.bukkit.")) throw InvalidPluginDescriptionException("Main may not be within the org.bukkit namespace")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,13 +40,8 @@ class BungeePlugin : PlatformPlugin<BungeePluginDescription>("Bungee", "bungee.y
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun validate(description: BungeePluginDescription) {
|
override fun validate(description: BungeePluginDescription) {
|
||||||
if (description.name == null) {
|
if (description.name.isNullOrEmpty()) throw InvalidPluginDescriptionException("Plugin name is not set")
|
||||||
throw InvalidPluginDescriptionException("Plugin name is not set")
|
if (description.main.isNullOrEmpty()) throw InvalidPluginDescriptionException("Main class is not defined")
|
||||||
}
|
|
||||||
|
|
||||||
if (description.main == null) {
|
|
||||||
throw InvalidPluginDescriptionException("Main class is not defined")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,21 +40,14 @@ class NukkitPlugin : PlatformPlugin<NukkitPluginDescription>("Nukkit", "nukkit.y
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun validate(description: NukkitPluginDescription) {
|
override fun validate(description: NukkitPluginDescription) {
|
||||||
if (description.name == null) {
|
if (description.name.isNullOrEmpty()) throw InvalidPluginDescriptionException("Plugin name is not set")
|
||||||
throw InvalidPluginDescriptionException("Plugin name is not set")
|
if (description.version.isNullOrEmpty()) throw InvalidPluginDescriptionException("Plugin version class is not set")
|
||||||
}
|
|
||||||
|
|
||||||
if (description.main == null) {
|
val main = description.main ?: throw InvalidPluginDescriptionException("Main class is not defined")
|
||||||
throw InvalidPluginDescriptionException("Main class is not defined")
|
if (main.isEmpty()) throw InvalidPluginDescriptionException("Main class cannot be empty")
|
||||||
}
|
if (main.startsWith("cn.nukkit.")) throw InvalidPluginDescriptionException("Main class cannot be within cn.nukkit. package")
|
||||||
|
|
||||||
if (description.version == null) {
|
if (description.api?.isEmpty() != false) throw InvalidPluginDescriptionException("Nukkit API version is not set")
|
||||||
throw InvalidPluginDescriptionException("Plugin version class is not set")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (description.api == null || description.api!!.isEmpty()) {
|
|
||||||
throw InvalidPluginDescriptionException("Nukkit API version is not set")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue