From 15673f7fc89ce595c7ae5cb1e6675aa744650ef8 Mon Sep 17 00:00:00 2001 From: Gugle Date: Wed, 11 Sep 2024 03:18:38 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=9F=20=E5=88=9B=E5=BB=BACodec=E6=B3=A8?= =?UTF-8?q?=E8=A7=A3=E5=8F=8A=E5=85=B6=E5=A4=84=E7=90=86=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 9 +++- gradle.properties | 2 +- .../java/dev/anvilcraft/lib/codec/Codec.java | 11 +++++ .../lib/codec/CodecAnnotationProcessor.java | 41 +++++++++++++++++++ .../javax.annotation.processing.Processor | 1 + 5 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 src/main/java/dev/anvilcraft/lib/codec/Codec.java create mode 100644 src/main/java/dev/anvilcraft/lib/codec/CodecAnnotationProcessor.java create mode 100644 src/main/resources/META-INF/services/javax.annotation.processing.Processor diff --git a/build.gradle b/build.gradle index 26540cd..6441dde 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,14 @@ plugins { id 'net.neoforged.moddev' version '2.0.27-beta' } -version = mod_version +String buildType = 'build' +String buildNumber +if (System.getenv("CI_BUILD") == 'false') buildNumber = null +else { + if (System.getenv("PR_BUILD") != 'false') buildType = 'pr' + buildNumber = System.getenv("GITHUB_RUN_NUMBER") +} +version = "${mod_version}" + (buildNumber != null ? "+${buildType}.${buildNumber}" : "") group = mod_group_id repositories { diff --git a/gradle.properties b/gradle.properties index 807100f..adca36f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -30,7 +30,7 @@ mod_name=AnvilLib # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=GNU LGPL 3.0 # The mod version. See https://semver.org/ -mod_version=1.0.0 +mod_version=1.1.0 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/src/main/java/dev/anvilcraft/lib/codec/Codec.java b/src/main/java/dev/anvilcraft/lib/codec/Codec.java new file mode 100644 index 0000000..b615eb9 --- /dev/null +++ b/src/main/java/dev/anvilcraft/lib/codec/Codec.java @@ -0,0 +1,11 @@ +package dev.anvilcraft.lib.codec; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.SOURCE) +public @interface Codec { +} diff --git a/src/main/java/dev/anvilcraft/lib/codec/CodecAnnotationProcessor.java b/src/main/java/dev/anvilcraft/lib/codec/CodecAnnotationProcessor.java new file mode 100644 index 0000000..871b23b --- /dev/null +++ b/src/main/java/dev/anvilcraft/lib/codec/CodecAnnotationProcessor.java @@ -0,0 +1,41 @@ +package dev.anvilcraft.lib.codec; + +import org.jetbrains.annotations.NotNull; + +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.Filer; +import javax.annotation.processing.ProcessingEnvironment; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.annotation.processing.SupportedSourceVersion; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.Element; +import javax.lang.model.element.TypeElement; +import javax.tools.Diagnostic; +import java.util.Set; + +@SupportedAnnotationTypes("dev.anvilcraft.lib.codec.Codec") +@SupportedSourceVersion(SourceVersion.RELEASE_21) +public class CodecAnnotationProcessor extends AbstractProcessor { + @Override + public synchronized void init(ProcessingEnvironment processingEnv) { + super.init(processingEnv); + } + + @Override + public boolean process(Set annotations, @NotNull RoundEnvironment roundEnv) { + for (Element element : roundEnv.getElementsAnnotatedWith(Codec.class)) { + TypeElement typeElem = (TypeElement) element; + String typeName = typeElem.getQualifiedName().toString(); + Filer filer = processingEnv.getFiler(); + } + return true; + } + + + private void log(String msg) { + if (processingEnv.getOptions().containsKey("debug")) { + processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, msg); + } + } +} diff --git a/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/src/main/resources/META-INF/services/javax.annotation.processing.Processor new file mode 100644 index 0000000..de40edd --- /dev/null +++ b/src/main/resources/META-INF/services/javax.annotation.processing.Processor @@ -0,0 +1 @@ +dev.anvilcraft.lib.codec.CodecAnnotationProcessor