From a660af995e66e3e51368898e6fe92bd3b66a900e Mon Sep 17 00:00:00 2001 From: xkball <45330674+xkball@users.noreply.github.com> Date: Tue, 15 Oct 2024 21:46:33 +0800 Subject: [PATCH] change format of artifacts add logs to annotation processor Took 11 minutes --- .github/workflows/build.yml | 2 +- .../CodecProviderProcessor.java | 46 ++++++++++--------- .../DataFieldProcessor.java | 3 ++ .../tin_tea_tech/util/CodecManager.java | 1 + 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4598fed..2cc66da 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,7 +36,7 @@ jobs: - name: Build id: build env: - VERSION_IDENTIFIER: SNAPSHOT+${{ steps.short-sha.outputs.sha }} + VERSION_IDENTIFIER: ${{ steps.short-sha.outputs.sha }} run: ./gradlew :build --stacktrace - name: GitHub Action Artifact diff --git a/TinTeaTechAnnotationProcessor/src/main/java/com/xkball/tin_tea_tech/annotation_processor/CodecProviderProcessor.java b/TinTeaTechAnnotationProcessor/src/main/java/com/xkball/tin_tea_tech/annotation_processor/CodecProviderProcessor.java index b53d5ee..6f0b254 100644 --- a/TinTeaTechAnnotationProcessor/src/main/java/com/xkball/tin_tea_tech/annotation_processor/CodecProviderProcessor.java +++ b/TinTeaTechAnnotationProcessor/src/main/java/com/xkball/tin_tea_tech/annotation_processor/CodecProviderProcessor.java @@ -27,7 +27,7 @@ public class CodecProviderProcessor extends AbstractProcessor { public static final String CODEC_PROVIDER = "com.xkball.tin_tea_tech.api.annotation.CodecProvider"; - + public static final String LOG_HEAD = "[TinTeaTechAnnotationProcessor.CodecProviderProcessor] "; private ProcessingEnvironment processingEnv; private Elements elementUtils; private Filer filer; @@ -64,34 +64,36 @@ public boolean process(Set annotations, RoundEnvironment public static void handleJCTree(String className, JCTree.JCClassDecl tree,boolean inAnnoProcessor){ if(!inAnnoProcessor){ if(sourceHandledClasses.contains(className)) return; + System.out.println(LOG_HEAD + "Scanning " + className); sourceHandledClasses.add(className); } else { if(processorHandledClasses.contains(className)) return; + System.out.println(LOG_HEAD + "Checking " + className); processorHandledClasses.add(className); } - JCTreeUtils.findFieldWithAnno(tree,CODEC_PROVIDER) - .forEach(def -> { - if(!JCTreeUtils.isPublicStatic(def)) return; - var codecType = StringUtils.splitTypeNameWithArg(def.vartype.toString()); - var typeName = StringUtils.fixTypeNameWithArgRecursive(className,codecType.snd); - var codecRef = className+"."+def.name.toString(); - var anno = Objects.requireNonNull(JCTreeUtils.findAnnotation(def,CODEC_PROVIDER)); - var codecInsOrder = 0; - var codecInsName = ""; - for(var arg : anno.args){ - if(arg instanceof JCTree.JCAssign assign){ - if(assign.lhs.toString().equals("name")) codecInsName = StringUtils.removeDoubleQuotes(assign.rhs.toString()); - if(assign.lhs.toString().equals("order")) codecInsOrder = Integer.parseInt(assign.rhs.toString()); - } - } - var data = new CodecManager.CodecProviderData(codecType.fst,typeName,codecRef,codecInsName,codecInsOrder); - if(!CodecManager.NEW_CODEC_PROVIDERS.contains(data)){ - if(inAnnoProcessor) - throw new IllegalArgumentException("Can not support codec provider from code generation!!! " + data); - CodecManager.NEW_CODEC_PROVIDERS.add(data); - CodecManager.addCodec(codecType.fst,typeName,codecRef,codecInsName,codecInsOrder); + JCTreeUtils.findFieldWithAnno(tree,CODEC_PROVIDER) + .forEach(def -> { + if(!JCTreeUtils.isPublicStatic(def)) return; + var codecType = StringUtils.splitTypeNameWithArg(def.vartype.toString()); + var typeName = StringUtils.fixTypeNameWithArgRecursive(className,codecType.snd); + var codecRef = className+"."+def.name.toString(); + var anno = Objects.requireNonNull(JCTreeUtils.findAnnotation(def,CODEC_PROVIDER)); + var codecInsOrder = 0; + var codecInsName = ""; + for(var arg : anno.args){ + if(arg instanceof JCTree.JCAssign assign){ + if(assign.lhs.toString().equals("name")) codecInsName = StringUtils.removeDoubleQuotes(assign.rhs.toString()); + if(assign.lhs.toString().equals("order")) codecInsOrder = Integer.parseInt(assign.rhs.toString()); } + } + var data = new CodecManager.CodecProviderData(codecType.fst,typeName,codecRef,codecInsName,codecInsOrder); + if(!CodecManager.NEW_CODEC_PROVIDERS.contains(data)){ + if(inAnnoProcessor) + throw new IllegalArgumentException("Can not support codec provider from code generation!!! " + data); + CodecManager.NEW_CODEC_PROVIDERS.add(data); + CodecManager.addCodec(codecType.fst,typeName,codecRef,codecInsName,codecInsOrder); + } }); } diff --git a/TinTeaTechAnnotationProcessor/src/main/java/com/xkball/tin_tea_tech/annotation_processor/DataFieldProcessor.java b/TinTeaTechAnnotationProcessor/src/main/java/com/xkball/tin_tea_tech/annotation_processor/DataFieldProcessor.java index addc9f4..f60606d 100644 --- a/TinTeaTechAnnotationProcessor/src/main/java/com/xkball/tin_tea_tech/annotation_processor/DataFieldProcessor.java +++ b/TinTeaTechAnnotationProcessor/src/main/java/com/xkball/tin_tea_tech/annotation_processor/DataFieldProcessor.java @@ -36,6 +36,7 @@ public class DataFieldProcessor extends AbstractProcessor { public static final String DATA_FIELD = "com.xkball.tin_tea_tech.api.annotation.DataField"; + public static final String LOG_HEAD = "[TinTeaTechAnnotationProcessor.DataFieldProcessor] "; public static final java.util.List handledClasses = new ArrayList<>(); private ProcessingEnvironment processingEnv; @@ -62,6 +63,7 @@ public boolean process(Set annotations, RoundEnvironment if (classSymbol == null) return; var fullName = classSymbol.getQualifiedName().toString(); var tree = trees.getTree(elementUtils.getTypeElement(fullName)); + handleClass(fullName, tree); } ); @@ -71,6 +73,7 @@ public boolean process(Set annotations, RoundEnvironment public static void handleClass(String className, JCTree.JCClassDecl tree) { if (handledClasses.contains(className)) return; handledClasses.add(className); + System.out.println(LOG_HEAD + "Processing " + className); JCTreeUtils.setPos(tree); var fields = JCTreeUtils.findFieldWithAnno(tree,DATA_FIELD); var fieldsData = fields.stream().map(f -> DataJCTreeUtils.DataFieldData.fromAnno(className,f)).toList(); diff --git a/TinTeaTechAnnotationProcessor/src/main/java/com/xkball/tin_tea_tech/util/CodecManager.java b/TinTeaTechAnnotationProcessor/src/main/java/com/xkball/tin_tea_tech/util/CodecManager.java index 2ac804a..faaf052 100644 --- a/TinTeaTechAnnotationProcessor/src/main/java/com/xkball/tin_tea_tech/util/CodecManager.java +++ b/TinTeaTechAnnotationProcessor/src/main/java/com/xkball/tin_tea_tech/util/CodecManager.java @@ -143,6 +143,7 @@ public static void writeToMETA_INF() { out.write(data.toString() + '\n'); } } + System.out.println("Writing Codec Providers to: "+file.toUri().toURL()); } catch (IOException e) { throw new RuntimeException(e); }