private static void getPackageNamesFromDir(File base, File dir, List<String> pkgs) { boolean foundClass = false; for (File file : dir.listFiles()) { if (file.isDirectory()) { getPackageNamesFromDir(base, file, pkgs); } else if (!foundClass && file.getName().endsWith(".class")) { foundClass = true; String pkg = ""; file = dir; while (!file.equals(base)) { if (!"".equals(pkg)) { pkg = "." + pkg; } pkg = file.getName() + pkg; file = file.getParentFile(); } if (!pkgs.contains(pkg)) { pkgs.add(pkg); } } } }
private static void getPackageNamesFromDir(File base, File dir, List<String> pkgs) { boolean foundClass = false; for (File file : dir.listFiles()) { if (file.isDirectory()) { getPackageNamesFromDir(base, file, pkgs); } else if (!foundClass && file.getName().endsWith(".class")) { foundClass = true; String pkg = ""; file = dir; while (!file.equals(base)) { if (!"".equals(pkg)) { pkg = "." + pkg; } pkg = file.getName() + pkg; file = file.getParentFile(); } if (!pkgs.contains(pkg)) { pkgs.add(pkg); } } } }
private static void getPackageNamesFromDir(File base, File dir, List<String> pkgs) { boolean foundClass = false; for (File file : dir.listFiles()) { if (file.isDirectory()) { getPackageNamesFromDir(base, file, pkgs); } else if (!foundClass && file.getName().endsWith(".class")) { foundClass = true; String pkg = ""; file = dir; while (!file.equals(base)) { if (!"".equals(pkg)) { pkg = "." + pkg; } pkg = file.getName() + pkg; file = file.getParentFile(); } if (!pkgs.contains(pkg)) { pkgs.add(pkg); } } } }
public static List<String> getPackagesFromJar(File jarFile) throws IOException { List<String> packageNames = new ArrayList<String>(); if (jarFile.isDirectory()) { getPackageNamesFromDir(jarFile, jarFile, packageNames); } else { JarResource resource = new JarResource(); for (String item : resource.getJarContents(jarFile)) { if (!item.endsWith(".class")) { continue; } String packageName = getPackageName(item); if (!StringUtils.isEmpty(packageName) && !packageNames.contains(packageName)) { packageNames.add(packageName); } } } return packageNames; }
public static List<String> getPackagesFromJar(File jarFile) throws IOException { List<String> packageNames = new ArrayList<String>(); if (jarFile.isDirectory()) { getPackageNamesFromDir(jarFile, jarFile, packageNames); } else { JarResource resource = new JarResource(); for (String item : resource.getJarContents(jarFile)) { if (!item.endsWith(".class")) { continue; } String packageName = getPackageName(item); if (!StringUtils.isEmpty(packageName) && !packageNames.contains(packageName)) { packageNames.add(packageName); } } } return packageNames; }
public static List<String> getPackagesFromJar(File jarFile) throws IOException { List<String> packageNames = new ArrayList<String>(); if (jarFile.isDirectory()) { getPackageNamesFromDir(jarFile, jarFile, packageNames); } else { JarResource resource = new JarResource(); for (String item : resource.getJarContents(jarFile)) { if (!item.endsWith(".class")) { continue; } String packageName = getPackageName(item); if (!StringUtils.isEmpty(packageName) && !packageNames.contains(packageName)) { packageNames.add(packageName); } } } return packageNames; }