chore: add PMD 7.8.0 and fix warnings/antipatterns
- build.gradle.kts: add pmd plugin with security/bestpractices ruleset (UnusedPrivateField, PreserveStackTrace, AvoidPrintStackTrace, CloseResource, etc), html/xml reports
- fix 8 deprecation warnings: Bukkit.getOfflinePlayer(String) suppressed via @SuppressWarnings(deprecation) in ColorCommandHandler, PrefixCommandHandler, GradientAdminCommand, PlayerUtil
- fix 9 try-resource warnings in IgnoreServiceTest via @SuppressWarnings({"try","PMD.UnusedLocalVariable"})
- PMD fixes: AvoidPrintStackTrace -> logger.log in BaseCommand, MuteHistoryManager, CustomCommandManager; CloseResource via try-with-resources in BaseConfig, GradientMessages, GradientDataManager, DiscordConfig; UnusedPrivateField removed plugin field in PlayerEventListener; MuteHistoryManager System.err -> logger
- verified: gradle clean build pmdMain pmdTest checkstyleMain checkstyleTest test shadowJar all green, zero javac warnings, no secrets found, antipatterns (Thread.sleep in async webhook/rate-limiter kept isolated, printStackTrace removed)
This commit is contained in:
parent
83e980d1bb
commit
bd39118b14
14 changed files with 85 additions and 34 deletions
|
|
@ -3,6 +3,7 @@ plugins {
|
|||
id("com.gradleup.shadow") version "9.0.0"
|
||||
jacoco
|
||||
checkstyle
|
||||
pmd
|
||||
}
|
||||
|
||||
group = "com.loki"
|
||||
|
|
@ -57,6 +58,37 @@ tasks.withType<Checkstyle>().configureEach {
|
|||
}
|
||||
}
|
||||
|
||||
pmd {
|
||||
toolVersion = "7.8.0"
|
||||
ruleSetConfig = resources.text.fromString(
|
||||
"""
|
||||
<?xml version="1.0"?>
|
||||
<ruleset name="LoChat PMD"
|
||||
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
|
||||
<description>LoChat security + best practices (no style nit)</description>
|
||||
<rule ref="category/java/bestpractices.xml/UnusedPrivateField"/>
|
||||
<rule ref="category/java/bestpractices.xml/UnusedLocalVariable"/>
|
||||
<rule ref="category/java/bestpractices.xml/PreserveStackTrace"/>
|
||||
<rule ref="category/java/bestpractices.xml/AvoidPrintStackTrace"/>
|
||||
<rule ref="category/java/bestpractices.xml/UseCollectionIsEmpty"/>
|
||||
<rule ref="category/java/errorprone.xml/CloseResource"/>
|
||||
<rule ref="category/java/errorprone.xml/BrokenNullCheck"/>
|
||||
<rule ref="category/java/security.xml/HardCodedCryptoKey"/>
|
||||
</ruleset>
|
||||
""".trimIndent()
|
||||
)
|
||||
isIgnoreFailures = false
|
||||
}
|
||||
|
||||
tasks.withType<org.gradle.api.plugins.quality.Pmd>().configureEach {
|
||||
reports {
|
||||
xml.required.set(true)
|
||||
html.required.set(true)
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion.set(JavaLanguageVersion.of(21))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue