Skip to content

Commit

Permalink
change format of artifacts add logs to annotation processor
Browse files Browse the repository at this point in the history
Took 11 minutes
  • Loading branch information
xkball committed Oct 15, 2024
1 parent 49d8e5f commit a660af9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,34 +64,36 @@ public boolean process(Set<? extends TypeElement> 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);
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> handledClasses = new ArrayList<>();

private ProcessingEnvironment processingEnv;
Expand All @@ -62,6 +63,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
if (classSymbol == null) return;
var fullName = classSymbol.getQualifiedName().toString();
var tree = trees.getTree(elementUtils.getTypeElement(fullName));

handleClass(fullName, tree);
}
);
Expand All @@ -71,6 +73,7 @@ public boolean process(Set<? extends TypeElement> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit a660af9

Please sign in to comment.