Gradle/Mavenが持っているjarファイルのパスを表示するツール
修訂 | da961ec46cb2be86605ce97cbbb89ab1be284056 (tree) |
---|---|
時間 | 2022-04-10 07:19:04 |
作者 | kemono7h |
Commiter | kemono7h |
classファイルを持たないjarをグレー色で表示するようにした
@@ -18,6 +18,7 @@ | ||
18 | 18 | import javax.swing.event.HyperlinkListener; |
19 | 19 | |
20 | 20 | import jp.nanah.dnj.util.FileUtils; |
21 | +import jp.nanah.dnj.util.JarUtils; | |
21 | 22 | |
22 | 23 | public class DokonanJarMain { |
23 | 24 |
@@ -203,7 +204,15 @@ | ||
203 | 204 | for (int i=0; i<texts.length; i++) { |
204 | 205 | dispname = dispname.replaceAll(texts[i], "<b>"+texts[i]+"</b>"); |
205 | 206 | } |
206 | - return beforeLastFolder + "<a href='file:" + fullpath + "'>" + dispname + ".jar</a>"; | |
207 | + String html_line = beforeLastFolder + "<a href='file:" + fullpath + "'>" + dispname + ".jar</a>"; | |
208 | + | |
209 | + if (file.length() < 10000) { | |
210 | + boolean hasClass = JarUtils.hasDotClass(file); | |
211 | + if (hasClass == false) { | |
212 | + html_line = "<font color='silver'>" + html_line + "(※no-class)</font>"; | |
213 | + } | |
214 | + } | |
215 | + return html_line; | |
207 | 216 | } |
208 | 217 | |
209 | 218 | private String[] getSearchTexts(String path) { |
@@ -0,0 +1,56 @@ | ||
1 | +package jp.nanah.dnj.util; | |
2 | + | |
3 | +import java.io.File; | |
4 | +import java.io.FileInputStream; | |
5 | +import java.io.IOException; | |
6 | +import java.util.zip.ZipEntry; | |
7 | +import java.util.zip.ZipInputStream; | |
8 | + | |
9 | +public class JarUtils { | |
10 | + | |
11 | + //--------------------------------------------- | |
12 | + // Jar一覧を取得 | |
13 | + //--------------------------------------------- | |
14 | + | |
15 | + public static boolean hasDotClass(File file){ | |
16 | + ZipInputStream zistr = null; | |
17 | + try { | |
18 | + zistr = new ZipInputStream(new FileInputStream(file)); | |
19 | + ZipEntry zipEntry = null; | |
20 | + | |
21 | + while ((zipEntry = zistr.getNextEntry()) != null) { | |
22 | + String name = zipEntry.getName(); | |
23 | + System.out.println(name); | |
24 | + if (name.endsWith(".class")) { | |
25 | + return true; | |
26 | + } | |
27 | + //classList | |
28 | +// File uncompressFile = new File(zipEntry.getName()); | |
29 | +// System.out.println(""); | |
30 | + // | |
31 | +// if (zipEntry.isDirectory()) { | |
32 | +// uncompressFile.mkdirs(); | |
33 | +// } else { | |
34 | +// BufferedOutputStream bostr = new BufferedOutputStream(new FileOutputStream(uncompressFile)); | |
35 | +// while ((len = zistr.read(buf)) != -1) { | |
36 | +// bostr.write(buf, 0, len); | |
37 | +// } | |
38 | +// bostr.close(); | |
39 | +// } | |
40 | + } | |
41 | + } catch (IOException ex) { | |
42 | + ex.printStackTrace(); | |
43 | + } finally { | |
44 | + try { | |
45 | + if (zistr != null) { | |
46 | + zistr.close(); | |
47 | + } | |
48 | + } catch (Throwable th) { | |
49 | + | |
50 | + } | |
51 | + } | |
52 | + | |
53 | + return false; | |
54 | + } | |
55 | + | |
56 | +} |