diff --git a/JavaFx-Plus.iml b/JavaFx-Plus.iml deleted file mode 100644 index 1f364cd..0000000 --- a/JavaFx-Plus.iml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/pom.xml b/pom.xml index b1b011b..e7f2e04 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ javafx-plus com.gitee.Biubiuyuyu javafx-plus - 1.0.0-RELEASE + 1.1.1-RELEASE jar @@ -78,56 +78,56 @@ - release - - - - - org.apache.maven.plugins - maven-source-plugin - 2.2.1 - - - package - - jar-no-fork - - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9.1 - - - package - - jar - - - -Xdoclint:none - - - - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.5 - - - sign-artifacts - verify - - sign - - - - - + release + + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + package + + jar-no-fork + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + package + + jar + + + -Xdoclint:none + + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.5 + + + sign-artifacts + verify + + sign + + + + + diff --git a/src/main/java/cn/edu/scau/biubiusuisui/utils/ClassUtils.java b/src/main/java/cn/edu/scau/biubiusuisui/utils/ClassUtils.java index f30884a..780e35b 100644 --- a/src/main/java/cn/edu/scau/biubiusuisui/utils/ClassUtils.java +++ b/src/main/java/cn/edu/scau/biubiusuisui/utils/ClassUtils.java @@ -1,12 +1,13 @@ package cn.edu.scau.biubiusuisui.utils; import java.io.File; +import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.net.URL; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; +import java.util.*; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; /** * @Author jack @@ -24,12 +25,16 @@ public class ClassUtils { URL url = classLoader.getResource(splashPath); String filePath = StringUtils.getRootPath(url); List names = null; - names = readFromDirectory(filePath); - for (String name : names) { - if (isClassFile(name)) { - nameList.add(toFullyQualifiedName(name, base)); - } else if (isDirectory(name)) { - nameList = getAllFXControllerClassName(base + "." + name, nameList); + if(filePath.endsWith("jar")){ + nameList = readFromJarDirectory(filePath,base); + }else { + names = readFromDirectory(filePath); + for (String name : names) { + if (isClassFile(name)) { + nameList.add(toFullyQualifiedName(name, base)); + } else if (isDirectory(name)) { + nameList = getAllFXControllerClassName(base + "." + name, nameList); + } } } return nameList; @@ -55,6 +60,37 @@ public class ClassUtils { } private static List readFromDirectory(String path) { + if (path == null) return null; + return readFromFileDirectory(path); + } + + private static List readFromJarDirectory(String path,String packageName) { + JarFile jarFile = null; + try { + jarFile = new JarFile(path); + } catch (IOException e) { + e.printStackTrace(); + } + Enumeration entrys = jarFile.entries(); + List classNames = new ArrayList<>(); + while (entrys.hasMoreElements()) { + JarEntry jarEntry = entrys.nextElement(); + if(!jarEntry.getName().endsWith(".class"))continue; + int packageNameIndex = jarEntry.getName().indexOf("/"); + if("".equals(packageName)){ + classNames.add(jarEntry.getName()); + }else { + if(packageNameIndex == -1) continue; + String baseName = jarEntry.getName().substring(0, packageNameIndex); + if (baseName.equals(packageName)) { + classNames.add(StringUtils.trimExtension(jarEntry.getName()).replaceAll("/",".")); + } + } + } + return classNames; + } + + private static List readFromFileDirectory(String path) { File file = new File(path); String[] names = file.list(); if (null == names) { @@ -107,8 +143,6 @@ public class ClassUtils { Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { field.setAccessible(true); - -// Field field1 = targetClass.getField(field.getName()); } } } diff --git a/src/test/java/cn/edu/scau/biubiusuisui/utils/ClassUtilsTest.java b/src/test/java/cn/edu/scau/biubiusuisui/utils/ClassUtilsTest.java new file mode 100644 index 0000000..607366f --- /dev/null +++ b/src/test/java/cn/edu/scau/biubiusuisui/utils/ClassUtilsTest.java @@ -0,0 +1,29 @@ +package cn.edu.scau.biubiusuisui.utils; + + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; + +public class ClassUtilsTest { + + public static void main(String[] args) { + JarFile jarFile = null; + try { + jarFile = new JarFile("/Users/Jack/test.jar"); + } catch (IOException e) { + e.printStackTrace(); + } + Enumeration entrys = jarFile.entries(); + List classNames = new ArrayList<>(); + while (entrys.hasMoreElements()) { + JarEntry jarEntry = entrys.nextElement(); + classNames.add(jarEntry.getName()); + } + classNames.forEach(System.out::println); + } + +}