Purity Ratchet

This commit is contained in:
Brian Neumann-Fopiano committed 2026-06-12 02:43:15 -04:00
1 parent 13002b04df
commit 3063801a3a
2 files changed
+298

No files matched your search

+39
View File
@@ -303,3 +303,42 @@ sourceSets {
}
}
}
tasks.register('bukkitPurityRatchet') {
group = 'verification'
description = 'Fails if files outside core/purity-allowlist.txt import org.bukkit (the allowlist only shrinks).'
File allowlistFile = project.file('purity-allowlist.txt')
File sourceRoot = project.file('src/main/java')
inputs.file(allowlistFile)
inputs.dir(sourceRoot)
doLast {
Set<String> allowed = allowlistFile.readLines().findAll { String line -> !line.isBlank() }.toSet()
List<String> offenders = new ArrayList<>()
List<String> coupled = new ArrayList<>()
sourceRoot.eachFileRecurse { File f ->
if (!f.name.endsWith('.java')) {
return
}
if (f.text.contains('org.bukkit')) {
String rel = sourceRoot.toPath().relativize(f.toPath()).toString()
coupled.add(rel)
if (!allowed.contains(rel)) {
offenders.add(rel)
}
}
}
if (!offenders.isEmpty()) {
throw new GradleException("Bukkit purity ratchet violated - new org.bukkit coupling in:\n " + offenders.join('\n ') + "\nDecouple these files or (only with strong justification) add them to core/purity-allowlist.txt")
}
int shrunk = allowed.size() - coupled.size()
if (shrunk > 0) {
println("Purity ratchet: " + coupled.size() + " coupled files (" + shrunk + " fewer than allowlist - consider tightening core/purity-allowlist.txt)")
} else {
println("Purity ratchet: " + coupled.size() + " coupled files (at allowlist ceiling)")
}
}
}
tasks.named('check').configure {
dependsOn('bukkitPurityRatchet')
}