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",