diff --git a/annotation-processors/build.gradle.kts b/annotation-processors/build.gradle.kts new file mode 100644 index 000000000..6f13c5321 --- /dev/null +++ b/annotation-processors/build.gradle.kts @@ -0,0 +1,13 @@ +plugins { + id("adventure.common-conventions") +} + +dependencies { + annotationProcessor(libs.autoService.processor) + compileOnlyApi(libs.autoService.annotations) + api(libs.jetbrainsAnnotations) +} + +tasks.withType(AbstractPublishToMaven::class) { + isEnabled = false +} diff --git a/annotation-processors/src/main/java/net/kyori/adventure/annotation/processing/PlatformAPIAnnotationProcessor.java b/annotation-processors/src/main/java/net/kyori/adventure/annotation/processing/PlatformAPIAnnotationProcessor.java new file mode 100644 index 000000000..b559feba9 --- /dev/null +++ b/annotation-processors/src/main/java/net/kyori/adventure/annotation/processing/PlatformAPIAnnotationProcessor.java @@ -0,0 +1,66 @@ +/* + * This file is part of adventure, licensed under the MIT License. + * + * Copyright (c) 2017-2022 KyoriPowered + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package net.kyori.adventure.annotation.processing; + +import com.google.auto.service.AutoService; +import java.util.Set; +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.Processor; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.Element; +import javax.lang.model.element.TypeElement; +import javax.tools.Diagnostic; +import org.jetbrains.annotations.ApiStatus; + +/** + * Validate that PlatformAPI annotations are used in tandem with the {@link ApiStatus.Internal} annotation. + * + * @since 4.12.0 + */ +@ApiStatus.Internal +@AutoService(Processor.class) +@SupportedAnnotationTypes(PlatformAPIAnnotationProcessor.ADVENTURE_PLATFORMAPI_ANNOTATION) +public class PlatformAPIAnnotationProcessor extends AbstractProcessor { + + public static final String ADVENTURE_PLATFORMAPI_ANNOTATION = "net.kyori.adventure.util.PlatformAPI"; + + @Override + public boolean process(final Set extends TypeElement> annotations, final RoundEnvironment roundEnv) { + for (final TypeElement annotation : annotations) { + for (final Element element : roundEnv.getElementsAnnotatedWith(annotation)) { + if (element.getAnnotation(ApiStatus.Internal.class) == null) { + this.processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, ADVENTURE_PLATFORMAPI_ANNOTATION + " needs to be used together with " + ApiStatus.Internal.class.getCanonicalName() + ", see PlatformAPI javadocs", element); + } + } + } + return false; + } + + @Override + public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latestSupported(); + } +} diff --git a/annotation-processors/src/main/java/net/kyori/adventure/annotation/processing/package-info.java b/annotation-processors/src/main/java/net/kyori/adventure/annotation/processing/package-info.java new file mode 100644 index 000000000..c73b4b1f5 --- /dev/null +++ b/annotation-processors/src/main/java/net/kyori/adventure/annotation/processing/package-info.java @@ -0,0 +1,30 @@ +/* + * This file is part of adventure, licensed under the MIT License. + * + * Copyright (c) 2017-2022 KyoriPowered + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/** + * Annotation processors used by other adventure modules. + */ +@ApiStatus.Internal +package net.kyori.adventure.annotation.processing; + +import org.jetbrains.annotations.ApiStatus; diff --git a/annotation-processors/src/main/resources/META-INF/gradle/incremental.annotation.processors b/annotation-processors/src/main/resources/META-INF/gradle/incremental.annotation.processors new file mode 100644 index 000000000..f292b0fef --- /dev/null +++ b/annotation-processors/src/main/resources/META-INF/gradle/incremental.annotation.processors @@ -0,0 +1 @@ +net.kyori.adventure.annotation.processing.PlatformAPIAnnotationProcessor,isolating diff --git a/api/build.gradle.kts b/api/build.gradle.kts index d6de41fdc..216a14159 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -15,6 +15,7 @@ dependencies { api(libs.examination.string) compileOnlyApi(libs.jetbrainsAnnotations) testImplementation(libs.guava) + annotationProcessor(projects.adventureAnnotationProcessors) } applyJarMetadata("net.kyori.adventure") diff --git a/api/src/main/java/net/kyori/adventure/bossbar/HackyBossBarPlatformBridge.java b/api/src/main/java/net/kyori/adventure/bossbar/HackyBossBarPlatformBridge.java index 564f80498..07c773425 100644 --- a/api/src/main/java/net/kyori/adventure/bossbar/HackyBossBarPlatformBridge.java +++ b/api/src/main/java/net/kyori/adventure/bossbar/HackyBossBarPlatformBridge.java @@ -23,6 +23,7 @@ */ package net.kyori.adventure.bossbar; +import net.kyori.adventure.util.PlatformAPI; import org.jetbrains.annotations.ApiStatus; /** @@ -31,7 +32,8 @@ * * @deprecated not an official API, and may disappear without warning */ -@Deprecated @ApiStatus.Internal +@Deprecated +@PlatformAPI abstract class HackyBossBarPlatformBridge { } diff --git a/api/src/main/java/net/kyori/adventure/util/PlatformAPI.java b/api/src/main/java/net/kyori/adventure/util/PlatformAPI.java new file mode 100644 index 000000000..652315819 --- /dev/null +++ b/api/src/main/java/net/kyori/adventure/util/PlatformAPI.java @@ -0,0 +1,47 @@ +/* + * This file is part of adventure, licensed under the MIT License. + * + * Copyright (c) 2017-2022 KyoriPowered + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package net.kyori.adventure.util; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import org.jetbrains.annotations.ApiStatus; + +/** + * Elements annotated with the {@link PlatformAPI} annotation are intended for platform implementations of the Adventure API + * only and should not be used by standard developers. They are not public API and may change or be removed without warning at any time. + * + *
This annotation should always be used in tandem with the {@link ApiStatus.Internal} annotation to more consistently produce + * warnings
+ * + * @since 4.12.0 + */ +@ApiStatus.Internal +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.PACKAGE, ElementType.ANNOTATION_TYPE}) +public @interface PlatformAPI { +} diff --git a/bom/build.gradle.kts b/bom/build.gradle.kts index 51c6a7f99..ac920132a 100644 --- a/bom/build.gradle.kts +++ b/bom/build.gradle.kts @@ -13,6 +13,7 @@ dependencies { constraints { sequenceOf( "api", + "annotation-processors", "extra-kotlin", "key", "nbt", diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 285fa65be..b360c6f96 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -51,6 +51,8 @@ truth-java8 = { module = "com.google.truth.extensions:truth-java8-extension", ve contractValidator = "ca.stellardrift:contract-validator:1.0.1" errorprone = { module = "com.google.errorprone:error_prone_core", version.ref = "errorprone" } stylecheck = "ca.stellardrift:stylecheck:0.2.0" +autoService-annotations = "com.google.auto.service:auto-service-annotations:1.0.1" +autoService-processor = "com.google.auto.service:auto-service:1.0.1" build-errorpronePlugin = "net.ltgt.gradle:gradle-errorprone-plugin:3.0.1" build-indra = { module = "net.kyori:indra-common", version.ref = "indra" } diff --git a/settings.gradle.kts b/settings.gradle.kts index 24b270f19..a69b587ad 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -28,6 +28,7 @@ rootProject.name = "adventure-parent" sequenceOf( "api", + "annotation-processors", "bom", "extra-kotlin", "key", diff --git a/text-minimessage/build.gradle.kts b/text-minimessage/build.gradle.kts index c8d66d7a7..62b4e4d97 100644 --- a/text-minimessage/build.gradle.kts +++ b/text-minimessage/build.gradle.kts @@ -8,6 +8,7 @@ description = "A string-based, user-friendly format for representing Minecraft: dependencies { api(projects.adventureApi) testImplementation(project(":adventure-text-serializer-plain")) + annotationProcessor(projects.adventureAnnotationProcessors) } tasks.checkstyleJmh { diff --git a/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/MiniMessage.java b/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/MiniMessage.java index ea3b98fac..55262d44c 100644 --- a/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/MiniMessage.java +++ b/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/MiniMessage.java @@ -30,6 +30,7 @@ import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import net.kyori.adventure.text.minimessage.tree.Node; import net.kyori.adventure.text.serializer.ComponentSerializer; +import net.kyori.adventure.util.PlatformAPI; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -299,6 +300,7 @@ interface Builder extends AbstractBuilder