fabric/gradle/validate-annotations.gradle
modmuss50 504944c854
Split test mods into client and common. (#3033)
* Split test mods.

Signed-off-by: modmuss50 <modmuss50@gmail.com>

* Fixes

Signed-off-by: modmuss50 <modmuss50@gmail.com>

* Fixe datagen client

Signed-off-by: modmuss50 <modmuss50@gmail.com>

---------

Signed-off-by: modmuss50 <modmuss50@gmail.com>
2023-05-01 13:55:19 +01:00

42 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)
}
}
}
}
}
}