mirror of
https://github.com/FabricMC/fabric.git
synced 2024-11-22 15:47:57 -05:00
47 lines
1.3 KiB
Groovy
47 lines
1.3 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")
|
|
source file("src/testmod/java")
|
|
source file("src/testmodClient/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',
|
|
'test'
|
|
]) {
|
|
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)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|