1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
public static List<String> getDescriptorClassNameByPackage(
String packageName, String[] jarFileNames) {
if (packageName == null || packageName.equals("")) {
packageName = "org.openscience.cdk.qsar.descriptors.molecular";
}
String[] jars;
if (jarFileNames == null) {
String classPath = System.getProperty("java.class.path");
jars = classPath.split(File.pathSeparator);
}
else {
jars = jarFileNames;
}
List<String> classlist = new ArrayList<String>();
for (String jar : jars) {
System.out.println("Checking jar file " + jar);
JarFile jarFile;
try {
jarFile = new JarFile(jar);
Enumeration enumeration = jarFile.entries();
while (enumeration.hasMoreElements()) {
JarEntry jarEntry = (JarEntry) enumeration.nextElement();
if (jarEntry.toString().indexOf(".class") != -1) {
String tmp = jarEntry.toString().replace('/', '.').replaceAll(
".class", "");
if (!(tmp.indexOf(packageName) != -1)) {
continue;
}
if (tmp.indexOf('$') != -1) {
continue;
}
if (tmp.indexOf("Test") != -1) {
continue;
}
if (!classlist.contains(tmp)) {
classlist.add(tmp);
}
}
}
}
catch (IOException e) {
}
}
return classlist;
} |
Partager