From 36efb9106bdc94e8965b5c38869b4065802d6b5a Mon Sep 17 00:00:00 2001 From: KingSimon <19822231+KingOfSquares@users.noreply.github.com> Date: Thu, 9 Jun 2022 12:57:41 +0200 Subject: [PATCH 1/6] Add PlatformAPI Annotation --- .../bossbar/HackyBossBarPlatformBridge.java | 4 +- .../net/kyori/adventure/util/PlatformAPI.java | 42 +++++++++++++++++++ .../text/minimessage/MiniMessage.java | 8 ++-- .../gson/GsonComponentSerializer.java | 10 ++--- .../legacy/LegacyComponentSerializer.java | 10 ++--- .../plain/PlainTextComponentSerializer.java | 8 ++-- 6 files changed, 62 insertions(+), 20 deletions(-) create mode 100644 api/src/main/java/net/kyori/adventure/util/PlatformAPI.java 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..fa482d72c 100644 --- a/api/src/main/java/net/kyori/adventure/bossbar/HackyBossBarPlatformBridge.java +++ b/api/src/main/java/net/kyori/adventure/bossbar/HackyBossBarPlatformBridge.java @@ -23,7 +23,7 @@ */ package net.kyori.adventure.bossbar; -import org.jetbrains.annotations.ApiStatus; +import net.kyori.adventure.util.PlatformAPI; /** * This class is a major hack, intended to allow certain platforms a way @@ -32,6 +32,6 @@ * @deprecated not an official API, and may disappear without warning */ @Deprecated -@ApiStatus.Internal +@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..1cc714ef9 --- /dev/null +++ b/api/src/main/java/net/kyori/adventure/util/PlatformAPI.java @@ -0,0 +1,42 @@ +/* + * 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.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 {@code @PlatformAPI} annotation are intended for platform implementations of the Adventure api + * only. + * + * @since 4.12.0 + */ +@ApiStatus.Internal +@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.PACKAGE}) +@Retention(RetentionPolicy.RUNTIME) +public @interface PlatformAPI { +} 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..c49ade6d6 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,7 +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 org.jetbrains.annotations.ApiStatus; +import net.kyori.adventure.util.PlatformAPI; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -298,7 +298,7 @@ interface Builder extends AbstractBuilder { * @since 4.10.0 * @hidden */ - @ApiStatus.Internal + @PlatformAPI interface Provider { /** * Provides a standard {@link MiniMessage} instance. @@ -306,7 +306,7 @@ interface Provider { * @return a {@link MiniMessage} instance * @since 4.10.0 */ - @ApiStatus.Internal + @PlatformAPI @NotNull MiniMessage miniMessage(); /** @@ -315,7 +315,7 @@ interface Provider { * @return a {@link Consumer} modifying a {@link Builder} * @since 4.10.0 */ - @ApiStatus.Internal + @PlatformAPI @NotNull Consumer builder(); } } diff --git a/text-serializer-gson/src/main/java/net/kyori/adventure/text/serializer/gson/GsonComponentSerializer.java b/text-serializer-gson/src/main/java/net/kyori/adventure/text/serializer/gson/GsonComponentSerializer.java index d84be117b..40bc90ea3 100644 --- a/text-serializer-gson/src/main/java/net/kyori/adventure/text/serializer/gson/GsonComponentSerializer.java +++ b/text-serializer-gson/src/main/java/net/kyori/adventure/text/serializer/gson/GsonComponentSerializer.java @@ -32,7 +32,7 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.ComponentSerializer; import net.kyori.adventure.util.Buildable; -import org.jetbrains.annotations.ApiStatus; +import net.kyori.adventure.util.PlatformAPI; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -162,7 +162,7 @@ interface Builder extends AbstractBuilder, Buildable.Bu * * @since 4.8.0 */ - @ApiStatus.Internal + @PlatformAPI interface Provider { /** * Provides a standard {@link GsonComponentSerializer}. @@ -170,7 +170,7 @@ interface Provider { * @return a {@link GsonComponentSerializer} * @since 4.8.0 */ - @ApiStatus.Internal + @PlatformAPI @NotNull GsonComponentSerializer gson(); /** @@ -179,7 +179,7 @@ interface Provider { * @return a {@link GsonComponentSerializer} * @since 4.8.0 */ - @ApiStatus.Internal + @PlatformAPI @NotNull GsonComponentSerializer gsonLegacy(); /** @@ -188,7 +188,7 @@ interface Provider { * @return a {@link Consumer} * @since 4.8.0 */ - @ApiStatus.Internal + @PlatformAPI @NotNull Consumer builder(); } } diff --git a/text-serializer-legacy/src/main/java/net/kyori/adventure/text/serializer/legacy/LegacyComponentSerializer.java b/text-serializer-legacy/src/main/java/net/kyori/adventure/text/serializer/legacy/LegacyComponentSerializer.java index 8765ae5a9..ab630eae7 100644 --- a/text-serializer-legacy/src/main/java/net/kyori/adventure/text/serializer/legacy/LegacyComponentSerializer.java +++ b/text-serializer-legacy/src/main/java/net/kyori/adventure/text/serializer/legacy/LegacyComponentSerializer.java @@ -34,7 +34,7 @@ import net.kyori.adventure.text.format.Style; import net.kyori.adventure.text.serializer.ComponentSerializer; import net.kyori.adventure.util.Buildable; -import org.jetbrains.annotations.ApiStatus; +import net.kyori.adventure.util.PlatformAPI; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -271,7 +271,7 @@ interface Builder extends AbstractBuilder, Buildable. * * @since 4.8.0 */ - @ApiStatus.Internal + @PlatformAPI interface Provider { /** * Provides a {@link LegacyComponentSerializer} using {@link #AMPERSAND_CHAR}. @@ -279,7 +279,7 @@ interface Provider { * @return a {@link LegacyComponentSerializer} * @since 4.8.0 */ - @ApiStatus.Internal + @PlatformAPI @NotNull LegacyComponentSerializer legacyAmpersand(); /** @@ -288,7 +288,7 @@ interface Provider { * @return a {@link LegacyComponentSerializer} * @since 4.8.0 */ - @ApiStatus.Internal + @PlatformAPI @NotNull LegacyComponentSerializer legacySection(); /** @@ -297,7 +297,7 @@ interface Provider { * @return a {@link Consumer} * @since 4.8.0 */ - @ApiStatus.Internal + @PlatformAPI @NotNull Consumer legacy(); } } diff --git a/text-serializer-plain/src/main/java/net/kyori/adventure/text/serializer/plain/PlainTextComponentSerializer.java b/text-serializer-plain/src/main/java/net/kyori/adventure/text/serializer/plain/PlainTextComponentSerializer.java index 323e1ee9c..b39e01452 100644 --- a/text-serializer-plain/src/main/java/net/kyori/adventure/text/serializer/plain/PlainTextComponentSerializer.java +++ b/text-serializer-plain/src/main/java/net/kyori/adventure/text/serializer/plain/PlainTextComponentSerializer.java @@ -32,7 +32,7 @@ import net.kyori.adventure.text.flattener.ComponentFlattener; import net.kyori.adventure.text.serializer.ComponentSerializer; import net.kyori.adventure.util.Buildable; -import org.jetbrains.annotations.ApiStatus; +import net.kyori.adventure.util.PlatformAPI; import org.jetbrains.annotations.NotNull; /** @@ -108,7 +108,7 @@ interface Builder extends AbstractBuilder, Buildab * * @since 4.8.0 */ - @ApiStatus.Internal + @PlatformAPI interface Provider { /** * Provides a {@link PlainTextComponentSerializer}. @@ -116,7 +116,7 @@ interface Provider { * @return a {@link PlainTextComponentSerializer} * @since 4.8.0 */ - @ApiStatus.Internal + @PlatformAPI @NotNull PlainTextComponentSerializer plainTextSimple(); /** @@ -125,7 +125,7 @@ interface Provider { * @return a {@link Consumer} * @since 4.8.0 */ - @ApiStatus.Internal + @PlatformAPI @NotNull Consumer plainText(); } } From 9630a8a22b9f79af26988ec692677aa18bc612aa Mon Sep 17 00:00:00 2001 From: KingSimon <19822231+KingOfSquares@users.noreply.github.com> Date: Sat, 11 Jun 2022 17:26:40 +0200 Subject: [PATCH 2/6] Tweak @PlatformAPI implementation and use @ApiStatus.Internal to produce warnings --- .../adventure/bossbar/HackyBossBarPlatformBridge.java | 2 ++ .../java/net/kyori/adventure/util/PlatformAPI.java | 11 ++++++++--- .../kyori/adventure/text/minimessage/MiniMessage.java | 4 ++++ .../text/serializer/gson/GsonComponentSerializer.java | 5 +++++ .../serializer/legacy/LegacyComponentSerializer.java | 5 +++++ .../plain/PlainTextComponentSerializer.java | 4 ++++ 6 files changed, 28 insertions(+), 3 deletions(-) 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 fa482d72c..07c773425 100644 --- a/api/src/main/java/net/kyori/adventure/bossbar/HackyBossBarPlatformBridge.java +++ b/api/src/main/java/net/kyori/adventure/bossbar/HackyBossBarPlatformBridge.java @@ -24,6 +24,7 @@ package net.kyori.adventure.bossbar; import net.kyori.adventure.util.PlatformAPI; +import org.jetbrains.annotations.ApiStatus; /** * This class is a major hack, intended to allow certain platforms a way @@ -31,6 +32,7 @@ * * @deprecated not an official API, and may disappear without warning */ +@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 index 1cc714ef9..652315819 100644 --- a/api/src/main/java/net/kyori/adventure/util/PlatformAPI.java +++ b/api/src/main/java/net/kyori/adventure/util/PlatformAPI.java @@ -23,6 +23,7 @@ */ 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; @@ -30,13 +31,17 @@ import org.jetbrains.annotations.ApiStatus; /** - * Elements annotated with the {@code @PlatformAPI} annotation are intended for platform implementations of the Adventure api - * only. + * 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 -@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.PACKAGE}) +@Documented @Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.PACKAGE, ElementType.ANNOTATION_TYPE}) public @interface PlatformAPI { } 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 c49ade6d6..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 @@ -31,6 +31,7 @@ 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; @@ -298,6 +299,7 @@ interface Builder extends AbstractBuilder { * @since 4.10.0 * @hidden */ + @ApiStatus.Internal @PlatformAPI interface Provider { /** @@ -306,6 +308,7 @@ interface Provider { * @return a {@link MiniMessage} instance * @since 4.10.0 */ + @ApiStatus.Internal @PlatformAPI @NotNull MiniMessage miniMessage(); @@ -315,6 +318,7 @@ interface Provider { * @return a {@link Consumer} modifying a {@link Builder} * @since 4.10.0 */ + @ApiStatus.Internal @PlatformAPI @NotNull Consumer builder(); } diff --git a/text-serializer-gson/src/main/java/net/kyori/adventure/text/serializer/gson/GsonComponentSerializer.java b/text-serializer-gson/src/main/java/net/kyori/adventure/text/serializer/gson/GsonComponentSerializer.java index 40bc90ea3..838e2d8d0 100644 --- a/text-serializer-gson/src/main/java/net/kyori/adventure/text/serializer/gson/GsonComponentSerializer.java +++ b/text-serializer-gson/src/main/java/net/kyori/adventure/text/serializer/gson/GsonComponentSerializer.java @@ -33,6 +33,7 @@ import net.kyori.adventure.text.serializer.ComponentSerializer; import net.kyori.adventure.util.Buildable; import net.kyori.adventure.util.PlatformAPI; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -162,6 +163,7 @@ interface Builder extends AbstractBuilder, Buildable.Bu * * @since 4.8.0 */ + @ApiStatus.Internal @PlatformAPI interface Provider { /** @@ -170,6 +172,7 @@ interface Provider { * @return a {@link GsonComponentSerializer} * @since 4.8.0 */ + @ApiStatus.Internal @PlatformAPI @NotNull GsonComponentSerializer gson(); @@ -179,6 +182,7 @@ interface Provider { * @return a {@link GsonComponentSerializer} * @since 4.8.0 */ + @ApiStatus.Internal @PlatformAPI @NotNull GsonComponentSerializer gsonLegacy(); @@ -188,6 +192,7 @@ interface Provider { * @return a {@link Consumer} * @since 4.8.0 */ + @ApiStatus.Internal @PlatformAPI @NotNull Consumer builder(); } diff --git a/text-serializer-legacy/src/main/java/net/kyori/adventure/text/serializer/legacy/LegacyComponentSerializer.java b/text-serializer-legacy/src/main/java/net/kyori/adventure/text/serializer/legacy/LegacyComponentSerializer.java index ab630eae7..4f2294c23 100644 --- a/text-serializer-legacy/src/main/java/net/kyori/adventure/text/serializer/legacy/LegacyComponentSerializer.java +++ b/text-serializer-legacy/src/main/java/net/kyori/adventure/text/serializer/legacy/LegacyComponentSerializer.java @@ -35,6 +35,7 @@ import net.kyori.adventure.text.serializer.ComponentSerializer; import net.kyori.adventure.util.Buildable; import net.kyori.adventure.util.PlatformAPI; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -271,6 +272,7 @@ interface Builder extends AbstractBuilder, Buildable. * * @since 4.8.0 */ + @ApiStatus.Internal @PlatformAPI interface Provider { /** @@ -279,6 +281,7 @@ interface Provider { * @return a {@link LegacyComponentSerializer} * @since 4.8.0 */ + @ApiStatus.Internal @PlatformAPI @NotNull LegacyComponentSerializer legacyAmpersand(); @@ -288,6 +291,7 @@ interface Provider { * @return a {@link LegacyComponentSerializer} * @since 4.8.0 */ + @ApiStatus.Internal @PlatformAPI @NotNull LegacyComponentSerializer legacySection(); @@ -297,6 +301,7 @@ interface Provider { * @return a {@link Consumer} * @since 4.8.0 */ + @ApiStatus.Internal @PlatformAPI @NotNull Consumer legacy(); } diff --git a/text-serializer-plain/src/main/java/net/kyori/adventure/text/serializer/plain/PlainTextComponentSerializer.java b/text-serializer-plain/src/main/java/net/kyori/adventure/text/serializer/plain/PlainTextComponentSerializer.java index b39e01452..87b027a18 100644 --- a/text-serializer-plain/src/main/java/net/kyori/adventure/text/serializer/plain/PlainTextComponentSerializer.java +++ b/text-serializer-plain/src/main/java/net/kyori/adventure/text/serializer/plain/PlainTextComponentSerializer.java @@ -33,6 +33,7 @@ import net.kyori.adventure.text.serializer.ComponentSerializer; import net.kyori.adventure.util.Buildable; import net.kyori.adventure.util.PlatformAPI; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; /** @@ -108,6 +109,7 @@ interface Builder extends AbstractBuilder, Buildab * * @since 4.8.0 */ + @ApiStatus.Internal @PlatformAPI interface Provider { /** @@ -116,6 +118,7 @@ interface Provider { * @return a {@link PlainTextComponentSerializer} * @since 4.8.0 */ + @ApiStatus.Internal @PlatformAPI @NotNull PlainTextComponentSerializer plainTextSimple(); @@ -125,6 +128,7 @@ interface Provider { * @return a {@link Consumer} * @since 4.8.0 */ + @ApiStatus.Internal @PlatformAPI @NotNull Consumer plainText(); } From 5e17bfd4c59cd10cba86c8964453e0277c022833 Mon Sep 17 00:00:00 2001 From: KingSimon <19822231+KingOfSquares@users.noreply.github.com> Date: Thu, 10 Nov 2022 23:13:58 +0100 Subject: [PATCH 3/6] non-working annotation processor --- annotation-processors/build.gradle.kts | 7 ++ .../PlatformAPIAnnotationProcessor.java | 65 +++++++++++++++++++ .../annotation/processing/package-info.java | 30 +++++++++ api/build.gradle.kts | 7 ++ settings.gradle.kts | 1 + 5 files changed, 110 insertions(+) create mode 100644 annotation-processors/build.gradle.kts create mode 100644 annotation-processors/src/main/java/net/kyori/adventure/annotation/processing/PlatformAPIAnnotationProcessor.java create mode 100644 annotation-processors/src/main/java/net/kyori/adventure/annotation/processing/package-info.java diff --git a/annotation-processors/build.gradle.kts b/annotation-processors/build.gradle.kts new file mode 100644 index 000000000..9bb665d91 --- /dev/null +++ b/annotation-processors/build.gradle.kts @@ -0,0 +1,7 @@ +plugins { + id("adventure.common-conventions") +} + +dependencies { + compileOnlyApi(libs.jetbrainsAnnotations) +} 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..cb27c0fbd --- /dev/null +++ b/annotation-processors/src/main/java/net/kyori/adventure/annotation/processing/PlatformAPIAnnotationProcessor.java @@ -0,0 +1,65 @@ +/* + * 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 java.util.Set; +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.lang.model.SourceVersion; +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 +@SupportedAnnotationTypes("net.kyori.adventure.util.PlatformAPI") +public class PlatformAPIAnnotationProcessor extends AbstractProcessor { + + @Override + public boolean process(final Set annotations, final RoundEnvironment roundEnv) { + processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Please"); + return false; + } + + @Override + public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latestSupported(); + } + + private static int getVersion() { + String version = System.getProperty("java.version"); + if(version.startsWith("1.")) { + version = version.substring(2, 3); + } else { + int dot = version.indexOf("."); + if(dot != -1) { version = version.substring(0, dot); } + } return Integer.parseInt(version); + } +} 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/api/build.gradle.kts b/api/build.gradle.kts index d6de41fdc..b604eb739 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -9,12 +9,19 @@ configurations { } } +tasks.withType { + doFirst { + println( "AnnotationProcessorPath for $name is ${options.annotationProcessorPath?.files}") + } +} + dependencies { api(projects.adventureKey) api(libs.examination.api) api(libs.examination.string) compileOnlyApi(libs.jetbrainsAnnotations) testImplementation(libs.guava) + annotationProcessor(projects.adventureAnnotationProcessors) } applyJarMetadata("net.kyori.adventure") 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", From 1079d4b795a9b226789218daf4974801aab54f26 Mon Sep 17 00:00:00 2001 From: KingSimon <19822231+KingOfSquares@users.noreply.github.com> Date: Fri, 11 Nov 2022 15:53:17 +0100 Subject: [PATCH 4/6] Fix annotation processor and apply it to relevant projects --- annotation-processors/build.gradle.kts | 4 ++- .../PlatformAPIAnnotationProcessor.java | 28 ++++++++++--------- .../gradle/incremental.annotation.processors | 1 + api/build.gradle.kts | 6 ---- bom/build.gradle.kts | 1 + gradle/libs.versions.toml | 2 ++ text-minimessage/build.gradle.kts | 1 + text-serializer-gson/build.gradle.kts | 1 + text-serializer-legacy/build.gradle.kts | 1 + text-serializer-plain/build.gradle.kts | 1 + 10 files changed, 26 insertions(+), 20 deletions(-) create mode 100644 annotation-processors/src/main/resources/META-INF/gradle/incremental.annotation.processors diff --git a/annotation-processors/build.gradle.kts b/annotation-processors/build.gradle.kts index 9bb665d91..3791e5d38 100644 --- a/annotation-processors/build.gradle.kts +++ b/annotation-processors/build.gradle.kts @@ -3,5 +3,7 @@ plugins { } dependencies { - compileOnlyApi(libs.jetbrainsAnnotations) + annotationProcessor(libs.autoService.processor) + compileOnlyApi(libs.autoService.annotations) + api(libs.jetbrainsAnnotations) } 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 index cb27c0fbd..5d125094f 100644 --- 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 @@ -23,14 +23,17 @@ */ 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.AnnotationMirror; +import javax.lang.model.element.Element; import javax.lang.model.element.TypeElement; import javax.tools.Diagnostic; - import org.jetbrains.annotations.ApiStatus; /** @@ -39,12 +42,21 @@ * @since 4.12.0 */ @ApiStatus.Internal -@SupportedAnnotationTypes("net.kyori.adventure.util.PlatformAPI") +@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 annotations, final RoundEnvironment roundEnv) { - processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Please"); + 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; } @@ -52,14 +64,4 @@ public boolean process(final Set annotations, final Round public SourceVersion getSupportedSourceVersion() { return SourceVersion.latestSupported(); } - - private static int getVersion() { - String version = System.getProperty("java.version"); - if(version.startsWith("1.")) { - version = version.substring(2, 3); - } else { - int dot = version.indexOf("."); - if(dot != -1) { version = version.substring(0, dot); } - } return Integer.parseInt(version); - } } 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 b604eb739..216a14159 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -9,12 +9,6 @@ configurations { } } -tasks.withType { - doFirst { - println( "AnnotationProcessorPath for $name is ${options.annotationProcessorPath?.files}") - } -} - dependencies { api(projects.adventureKey) api(libs.examination.api) 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/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-serializer-gson/build.gradle.kts b/text-serializer-gson/build.gradle.kts index e15553751..04e83fd62 100644 --- a/text-serializer-gson/build.gradle.kts +++ b/text-serializer-gson/build.gradle.kts @@ -7,6 +7,7 @@ dependencies { api(projects.adventureApi) api(libs.gson) testImplementation(projects.adventureNbt) + annotationProcessor(projects.adventureAnnotationProcessors) } applyJarMetadata("net.kyori.adventure.text.serializer.gson") diff --git a/text-serializer-legacy/build.gradle.kts b/text-serializer-legacy/build.gradle.kts index 9a12a5ccd..cd498b73d 100644 --- a/text-serializer-legacy/build.gradle.kts +++ b/text-serializer-legacy/build.gradle.kts @@ -4,6 +4,7 @@ plugins { dependencies { api(projects.adventureApi) + annotationProcessor(projects.adventureAnnotationProcessors) } applyJarMetadata("net.kyori.adventure.text.serializer.legacy") diff --git a/text-serializer-plain/build.gradle.kts b/text-serializer-plain/build.gradle.kts index 9c3b9ae2f..02bc22929 100644 --- a/text-serializer-plain/build.gradle.kts +++ b/text-serializer-plain/build.gradle.kts @@ -4,6 +4,7 @@ plugins { dependencies { api(projects.adventureApi) + annotationProcessor(projects.adventureAnnotationProcessors) } applyJarMetadata("net.kyori.adventure.text.serializer.plain") From 07cff37cc42e7bebf4e6ce16ccac8f79e3709d9c Mon Sep 17 00:00:00 2001 From: KingSimon <19822231+KingOfSquares@users.noreply.github.com> Date: Fri, 11 Nov 2022 15:56:28 +0100 Subject: [PATCH 5/6] formatting --- .../annotation/processing/PlatformAPIAnnotationProcessor.java | 1 - 1 file changed, 1 deletion(-) 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 index 5d125094f..b559feba9 100644 --- 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 @@ -30,7 +30,6 @@ import javax.annotation.processing.RoundEnvironment; import javax.annotation.processing.SupportedAnnotationTypes; import javax.lang.model.SourceVersion; -import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; import javax.lang.model.element.TypeElement; import javax.tools.Diagnostic; From ecdf9431763e2c42352716dd1f81c5bd49899760 Mon Sep 17 00:00:00 2001 From: KingSimon <19822231+KingOfSquares@users.noreply.github.com> Date: Sat, 12 Nov 2022 23:43:08 +0100 Subject: [PATCH 6/6] Prevent annotation processor module being published --- annotation-processors/build.gradle.kts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/annotation-processors/build.gradle.kts b/annotation-processors/build.gradle.kts index 3791e5d38..6f13c5321 100644 --- a/annotation-processors/build.gradle.kts +++ b/annotation-processors/build.gradle.kts @@ -7,3 +7,7 @@ dependencies { compileOnlyApi(libs.autoService.annotations) api(libs.jetbrainsAnnotations) } + +tasks.withType(AbstractPublishToMaven::class) { + isEnabled = false +}