2023-01-05 07:50:15 -05:00
|
|
|
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")
|
2023-05-01 08:55:19 -04:00
|
|
|
source file("src/testmod/java")
|
|
|
|
source file("src/testmodClient/java")
|
2023-01-05 07:50:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
2023-05-30 08:07:11 -04:00
|
|
|
for (def dir in [
|
|
|
|
'api',
|
|
|
|
'impl',
|
|
|
|
'mixin',
|
|
|
|
'test'
|
|
|
|
]) {
|
2023-01-05 07:50:15 -05:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|