11package com.blankj.bus
22
3+ import com.blankj.util.JavassistUtils
4+ import com.blankj.util.LogUtils
35import com.blankj.util.ZipUtils
46import com.blankj.utilcode.util.BusUtils
57import groovy.io.FileType
68import javassist.CtClass
79import javassist.CtMethod
810import org.apache.commons.io.FileUtils
911
12+ import java.lang.reflect.Modifier
13+
1014class BusScan {
1115
1216 HashMap<String , String > busMap
@@ -20,9 +24,11 @@ class BusScan {
2024
2125 void scanJar (File jar ) {
2226 File tmp = new File (jar. getParent(), " temp_" + jar. getName())
23- ZipUtils . unzipFile(jar, tmp)
24- scanDir(tmp)
25- FileUtils . forceDelete(tmp)
27+ List<File > unzipFile = ZipUtils . unzipFile(jar, tmp)
28+ if (unzipFile != null && unzipFile. size() > 0 ) {
29+ scanDir(tmp)
30+ FileUtils . forceDelete(tmp)
31+ }
2632 }
2733
2834 void scanDir (File root ) {
@@ -47,14 +53,18 @@ class BusScan {
4753 // delete .class
4854 className = className. substring(0 , className. length() - 6 )
4955
50- CtClass ctClass = Config . mPool . get(className)
56+ CtClass ctClass = JavassistUtils . getPool() . get(className)
5157
5258 CtMethod [] methods = ctClass. getDeclaredMethods();
5359 for (CtMethod method : methods) {
5460 if (method. hasAnnotation(BusUtils.Subscribe )) {
55- String name = method. getAnnotation(BusUtils.Subscribe ). name()
56- String sign = method. getReturnType(). getName() + ' ' + method. getLongName()
57- busMap. put(name, sign)
61+ if (Modifier . isStatic(method. getModifiers())) {
62+ String name = method. getAnnotation(BusUtils.Subscribe ). name()
63+ String sign = method. getReturnType(). getName() + ' ' + method. getLongName()
64+ busMap. put(name, sign)
65+ } else {
66+ LogUtils . l(method. getLongName() + " is not static" )
67+ }
5868 }
5969 }
6070 }
0 commit comments