mirror of
https://github.com/FabricMC/fabric.git
synced 2024-11-24 00:28:10 -05:00
1134c5b850
* Remove leftover `@ApiStatus.Internal` annotations and add annotation validation * Simplify * Simplify more * Update gradle/validate-annotations.gradle Co-authored-by: Juuz <6596629+Juuxel@users.noreply.github.com> Co-authored-by: Juuz <6596629+Juuxel@users.noreply.github.com>
40 lines
1.2 KiB
Groovy
40 lines
1.2 KiB
Groovy
task validateAnnotations(type: ValidateAnnotations) {
|
|
group = 'fabric'
|
|
description = "Validate annotations used in Fabric API code."
|
|
|
|
// Only apply to default source directories since there's also generated package-info files.
|
|
source file("src/client/java")
|
|
source file("src/main/java")
|
|
}
|
|
|
|
tasks.check.dependsOn validateAnnotations
|
|
|
|
class ValidateAnnotations extends SourceTask {
|
|
private static final def API_STATUS_INTERNAL = ~/@ApiStatus\.Internal/
|
|
private static final def ENVIRONMENT = ~/@Environment/
|
|
|
|
@TaskAction
|
|
def run() {
|
|
for (def dir in ['api', 'impl', 'mixin']) {
|
|
getSource().matching { include "net/fabricmc/fabric/$dir/" }.forEach {
|
|
if (it.isDirectory()) {
|
|
return
|
|
}
|
|
|
|
def contents = it.text
|
|
|
|
// @Environment is never allowed
|
|
if (ENVIRONMENT.matcher(contents).find()) {
|
|
throw new RuntimeException("Found @Environment annotation in file: $it")
|
|
}
|
|
|
|
// @ApiStatus.Internal is only allowed in api packages (it's auto-generated for impl and mixin packages)
|
|
if (dir != "api") {
|
|
if (API_STATUS_INTERNAL.matcher(contents).find()) {
|
|
throw new RuntimeException("Found @ApiStatus.Internal in implementation file: " + it)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|