(String dir, boolean recurse)
| 27 | } |
| 28 | //递归搜索目录和子目录下所有jar和zip文件 |
| 29 | protected void searchDir(String dir, boolean recurse) { |
| 30 | try { |
| 31 | File d = new File(dir); |
| 32 | if (!d.isDirectory()) { |
| 33 | return; |
| 34 | } |
| 35 | File[] files = d.listFiles(); |
| 36 | for (int i = 0; i < files.length; i++) { |
| 37 | if (recurse && files[i].isDirectory()) { |
| 38 | searchDir(files[i].getAbsolutePath(), true); |
| 39 | } else { |
| 40 | String filename = files[i].getAbsolutePath(); |
| 41 | if (filename.endsWith(".jar")||filename.endsWith(".zip")) { |
| 42 | System.out.println("---------------------扫描"+filename+"中----------------------------"); |
| 43 | ZipFile zip = new ZipFile(filename); |
| 44 | Enumeration entries = zip.entries(); |
| 45 | while (entries.hasMoreElements()) { |
| 46 | ZipEntry entry = (ZipEntry) entries.nextElement(); |
| 47 | String thisClassName = getClassName(entry); |
| 48 | if (wildcardEquals(this.className.toLowerCase(),thisClassName.toLowerCase()) || wildcardEquals(this.className.toLowerCase() + ".class",thisClassName.toLowerCase())) { |
| 49 | JarFileReader jarFileReader = new JarFileReader(); |
| 50 | className_temp = "/"+thisClassName.replaceAll("\.","/"); |
| 51 | className_final = className_temp.substring(0,className_temp.length()-5)+".java"; |
| 52 | jarFileReader.Test(filename,className_final); |
| 53 | totalNum++; |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | } catch (Exception e) { |
| 60 | e.printStackTrace(); |
| 61 | } |
| 62 | } |
| 63 | //通配符匹配 |
| 64 | private boolean wildcardEquals(String wildcard, String str) { |
| 65 | String regRule = WildcardToReg(wildcard); |
no test coverage detected