Skip to content
This repository was archived by the owner on Dec 7, 2024. It is now read-only.

Add validation for main class and api version #52

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
42dec2f
Add validation for main class and api version
rainbowdashlabs May 30, 2024
a8ca486
remove unused import
rainbowdashlabs May 30, 2024
121032b
Account for minor versions from 1.20.5 onwards
rainbowdashlabs Jun 4, 2024
4d06aae
Change group id
rainbowdashlabs Sep 1, 2024
8a8cc46
Setup automatic publishing
rainbowdashlabs Oct 31, 2024
78abe17
[skip ci] Update license and setup renovate config
rainbowdashlabs Oct 31, 2024
ed1a2ad
[skip ci] Move usage to the wiki
rainbowdashlabs Oct 31, 2024
753d7f4
Merge branch 'dev' into feature/main-and-api-validation
rainbowdashlabs Oct 31, 2024
020afd9
Update workflows (#3)
rainbowdashlabs Oct 31, 2024
a910989
Merge branch 'dev' into feature/main-and-api-validation
rainbowdashlabs Oct 31, 2024
02e4343
Trigger deployment
rainbowdashlabs Oct 31, 2024
f320ef8
Update workflows (#3)
rainbowdashlabs Oct 31, 2024
ea48a5b
Always run build
rainbowdashlabs Oct 31, 2024
0d036d7
chore(deps): update plugin com.diffplug.spotless to v6.25.0 (#5)
renovate[bot] Oct 31, 2024
b6bc9eb
chore(deps): update actions/setup-java action to v2.5.1 (#4)
renovate[bot] Oct 31, 2024
80478e0
fix(deps): update dependency com.fasterxml.jackson.dataformat:jackson…
renovate[bot] Oct 31, 2024
73b0771
chore(deps): update plugin com.gradle.plugin-publish to v1.3.0 (#7)
renovate[bot] Oct 31, 2024
14428b6
fix(deps): update dependency com.fasterxml.jackson.module:jackson-mod…
renovate[bot] Oct 31, 2024
f5111f4
chore(deps): update actions/checkout action to v4 (#10)
renovate[bot] Oct 31, 2024
06e0e3e
chore(deps): update actions/setup-java action to v4
renovate[bot] Oct 31, 2024
2945e68
chore(deps): update gradle/wrapper-validation-action action to v3 (#13)
renovate[bot] Oct 31, 2024
e60f01d
Merge branch 'dev' into feature/main-and-api-validation
rainbowdashlabs Oct 31, 2024
3ce1c73
Feature/main and api validation (#1)
rainbowdashlabs Oct 31, 2024
2480d0c
Update gradle.properties
rainbowdashlabs Oct 31, 2024
13c234a
Merge branch 'dev' into feature/main-and-api-validation
rainbowdashlabs Nov 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/main/kotlin/net/minecrell/pluginyml/bukkit/BukkitPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ import org.gradle.api.artifacts.result.ResolvedComponentResult
class BukkitPlugin : PlatformPlugin<BukkitPluginDescription>("Bukkit", "plugin.yml") {

companion object {
@JvmStatic private val VALID_NAME = Regex("^[A-Za-z0-9 _.-]+$")
@JvmStatic
private val VALID_NAME = Regex("^[A-Za-z0-9 _.-]+$")
@JvmStatic
private val VALID_API_VERSION = Regex("^1\\.[0-9]+$")
@JvmStatic
private val INVALID_NAMESPACES = listOf("net.minecraft.", "org.bukkit.", "io.papermc.", "com.destroystokoyo.paper.", "org.spigotmc")
}

override fun createExtension(project: Project) = BukkitPluginDescription(project)
Expand All @@ -53,12 +58,17 @@ class BukkitPlugin : PlatformPlugin<BukkitPluginDescription>("Bukkit", "plugin.y
override fun validate(description: BukkitPluginDescription) {
val name = description.name ?: throw InvalidPluginDescriptionException("Plugin name is not set")
if (!VALID_NAME.matches(name)) throw InvalidPluginDescriptionException("Invalid plugin name: should match $VALID_NAME")
if (description.apiVersion != null) {
val apiVersion = description.apiVersion!!
if (!VALID_API_VERSION.matches(apiVersion)) throw InvalidPluginDescriptionException("Invalid api version: should match $VALID_API_VERSION")
if (apiVersion < "1.13") throw InvalidPluginDescriptionException("Invalid api version: should be at least 1.13")
}

if (description.version.isNullOrEmpty()) throw InvalidPluginDescriptionException("Plugin version is not set")

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")
validateNamespace(main, "Main")

for (command in description.commands) {
if (command.name.contains(':')) throw InvalidPluginDescriptionException("Command '${command.name}' cannot contain ':'")
Expand All @@ -72,4 +82,11 @@ class BukkitPlugin : PlatformPlugin<BukkitPluginDescription>("Bukkit", "plugin.y
}
}

private fun validateNamespace(namespace: String, name: String) {
for (invalidNamespace in INVALID_NAMESPACES) {
if (namespace.startsWith(invalidNamespace)) {
throw InvalidPluginDescriptionException("$name may not be within the $invalidNamespace namespace")
}
}
}
}
Loading