MCPcopy Create free account
hub / github.com/0linlin0/CyberBox / AddPlugins

Class AddPlugins

Skay_Exp/src/tools/AddPlugins.java:19–59  ·  view source on GitHub ↗

@auther Skay @date 2021/4/20 15:05 @description

Source from the content-addressed store, hash-verified

17 * @description
18 */
19public class AddPlugins {
20 public static int scanClassX(URI uri, String packageName, Class<?> parentClass, Class<?> annotationClass, Map<String, Class<?>> destMap) {
21 String jarFileString;
22 int addNum = 0;
23
24 try {
25 File file = new File(uri);
26 File[] file2 = file.listFiles();
27
28 for(int i = 0; i < file2.length; ++i) {
29 File objectFile = file2[i];
30 if (objectFile.isDirectory()) {
31 File[] objectFiles = objectFile.listFiles();
32
33 for(int j = 0; j < objectFiles.length; ++j) {
34 File objectClassFile = objectFiles[j];
35 if (objectClassFile.getPath().endsWith(".class")) {
36 try {
37 String objectClassName = String.format("%s.%s.%s", packageName, objectFile.getName(), objectClassFile.getName().substring(0, objectClassFile.getName().length() - ".class".length()));
38 Class objectClass = Class.forName(objectClassName);
39 if (parentClass.isAssignableFrom(objectClass) && objectClass.isAnnotationPresent(annotationClass)) {
40 Annotation annotation = objectClass.getAnnotation(annotationClass);
41 String name = (String)annotation.annotationType().getMethod("Name").invoke(annotation, (Object[])null);
42 destMap.put(name, objectClass);
43 ++addNum;
44 }
45 } catch (Exception var19) {
46 var19.printStackTrace();
47 }
48 }
49 }
50 }
51 }
52 } catch (Exception var20) {
53 var20.printStackTrace();
54 }
55
56 return addNum;
57 }
58
59}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected