Gradle/Mavenが持っているjarファイルのパスを表示するツール
Revisão | e80d5eb4194d6b15552f3599a9e60cd7fdba34d4 (tree) |
---|---|
Hora | 2022-02-26 10:14:08 |
Autor | kemono7h |
Commiter | kemono7h |
Maven対応
@@ -1,9 +1,11 @@ | ||
1 | 1 | package jp.nanah.dnj; |
2 | 2 | |
3 | 3 | import java.awt.BorderLayout; |
4 | +import java.awt.FlowLayout; | |
4 | 5 | import java.awt.Font; |
5 | 6 | |
6 | 7 | import javax.swing.JButton; |
8 | +import javax.swing.JCheckBox; | |
7 | 9 | import javax.swing.JFrame; |
8 | 10 | import javax.swing.JPanel; |
9 | 11 | import javax.swing.JScrollPane; |
@@ -29,6 +31,12 @@ | ||
29 | 31 | private JFrame frame; |
30 | 32 | |
31 | 33 | /** |
34 | + * チェックボックス | |
35 | + */ | |
36 | + private JCheckBox cbGradle; | |
37 | + private JCheckBox cbMaven; | |
38 | + | |
39 | + /** | |
32 | 40 | * 結果表示エリア |
33 | 41 | */ |
34 | 42 | private JTextArea resultArea; |
@@ -49,16 +57,42 @@ | ||
49 | 57 | |
50 | 58 | Font font = new Font("Meiryo UI", Font.PLAIN, 12); |
51 | 59 | |
52 | - //入力エリア | |
60 | + //入力コンポーネントの配置領域 | |
61 | + JPanel topPanel = new JPanel(); | |
62 | + topPanel.setBorder(new EmptyBorder(0,4,0,4)); | |
63 | + topPanel.setLayout(new BorderLayout()); | |
64 | + //topPanel.setBackground(Color.blue); | |
65 | + //topPanel.setOpaque(true); | |
66 | + frame.getContentPane().add(topPanel, BorderLayout.NORTH); | |
67 | + | |
68 | + //チェックボックス | |
69 | + { | |
70 | + cbGradle = new JCheckBox("Gradle"); | |
71 | + cbMaven = new JCheckBox("Maven"); | |
72 | + cbGradle.setSelected(true); | |
73 | + cbMaven.setSelected(false); | |
74 | + //cbMaven.setFont(font); | |
75 | + //cbGradle.setFont(font); | |
76 | + JPanel panel = new JPanel(); | |
77 | + panel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); | |
78 | + panel.add(cbGradle); | |
79 | + panel.add(cbMaven); | |
80 | + topPanel.add(panel, BorderLayout.NORTH); | |
81 | + } | |
82 | + | |
53 | 83 | { |
54 | 84 | JTextField txtField = new JTextField(); |
85 | + //入力エリア | |
55 | 86 | txtField.getDocument().addDocumentListener(new FiDocumentListener()); |
56 | 87 | txtField.setToolTipText("ここに入力した文字列を含むファイルを探します。空白区切りで複数条件"); |
57 | - JPanel panel = new JPanel(); | |
58 | - panel.setBorder(new EmptyBorder(4,4,4,4)); | |
59 | - panel.setLayout(new BorderLayout()); | |
60 | - panel.add(txtField); | |
61 | - frame.getContentPane().add(panel, BorderLayout.NORTH); | |
88 | + //txtField.setBackground(Color.green); | |
89 | + //txtField.setOpaque(true); | |
90 | + //JPanel panel = new JPanel(); | |
91 | + //panel.setBorder(new EmptyBorder(4,4,4,4)); | |
92 | + //panel.setLayout(new BorderLayout()); | |
93 | + //panel.add(txtField); | |
94 | + //frame.getContentPane().add(panel, BorderLayout.NORTH); | |
95 | + topPanel.add(txtField, BorderLayout.SOUTH); | |
62 | 96 | } |
63 | 97 | |
64 | 98 | //結果出力エリア |
@@ -86,15 +120,21 @@ | ||
86 | 120 | } |
87 | 121 | } |
88 | 122 | |
123 | + public JFrame getFrame() { | |
124 | + return frame; | |
125 | + } | |
126 | + public JCheckBox getGradleCheckBox() { | |
127 | + return cbGradle; | |
128 | + } | |
129 | + public JCheckBox getMavenCheckBox() { | |
130 | + return cbMaven; | |
131 | + } | |
89 | 132 | public JButton getCopyButton() { |
90 | 133 | return copyButton; |
91 | 134 | } |
92 | 135 | public JTextArea getResultArea() { |
93 | 136 | return resultArea; |
94 | 137 | } |
95 | - public JFrame getFrame() { | |
96 | - return frame; | |
97 | - } | |
98 | 138 | |
99 | 139 | /** |
100 | 140 | * クリック最新時刻 |
@@ -9,7 +9,8 @@ | ||
9 | 9 | |
10 | 10 | private String userHome; |
11 | 11 | |
12 | - private List<File> allJarList; | |
12 | + private List<File> gradleJarList; | |
13 | + private List<File> mavenJarList; | |
13 | 14 | |
14 | 15 | public DokonanJar(Properties prop) { |
15 | 16 | userHome = System.getProperty("user.home"); |
@@ -19,10 +20,11 @@ | ||
19 | 20 | } |
20 | 21 | } |
21 | 22 | |
22 | - public List<File> initSearch() { | |
23 | - allJarList = getAllJarForGradle(); | |
23 | + public int[] initSearch() { | |
24 | + gradleJarList = getAllJarForGradle(); | |
25 | + mavenJarList = getAllJarForMaven(); | |
24 | 26 | //System.out.println("全" + allJarList.size() + "ファイル"); |
25 | - return allJarList; | |
27 | + return new int[] {gradleJarList.size(), mavenJarList.size()}; | |
26 | 28 | } |
27 | 29 | |
28 | 30 | public List<File> getAllJarForGradle(){ |
@@ -40,6 +42,18 @@ | ||
40 | 42 | return fileList; |
41 | 43 | } |
42 | 44 | |
45 | + public List<File> getAllJarForMaven(){ | |
46 | + List<File> fileList = new ArrayList<File>(); | |
47 | + File gradleDir = new File(userHome, ".m2"); | |
48 | + File[] dirs = gradleDir.listFiles(); | |
49 | + if (dirs != null) { | |
50 | + for (File f : dirs) { | |
51 | + searchFiles(f, null, fileList); | |
52 | + } | |
53 | + } | |
54 | + return fileList; | |
55 | + } | |
56 | + | |
43 | 57 | public List<File> searchFiles(File dir, String path, List<File> fileList) { |
44 | 58 | if (fileList == null) { |
45 | 59 | fileList = new ArrayList<File>(); |
@@ -67,14 +81,32 @@ | ||
67 | 81 | return fileList; |
68 | 82 | } |
69 | 83 | |
70 | - public List<File> searchJarForGradle(String path){ | |
84 | + public List<File> searchJarForGradle(String[] paths){ | |
85 | + return searchJar(paths, gradleJarList); | |
86 | + } | |
87 | + | |
88 | + public List<File> searchJarForMaven(String[] paths){ | |
89 | + return searchJar(paths, mavenJarList); | |
90 | + } | |
91 | + | |
92 | + public List<File> searchJar(String[] paths, List<File> targetFiles){ | |
71 | 93 | List<File> fileList = new ArrayList<File>(); |
72 | - for (File f : allJarList) { | |
73 | - if (f.getName().contains(path)) { | |
94 | + for (File f : targetFiles) { | |
95 | + if (isContainsAll(f.getName(), paths)) { | |
74 | 96 | fileList.add(f); |
75 | 97 | } |
76 | 98 | } |
77 | 99 | return fileList; |
78 | 100 | } |
79 | 101 | |
102 | + public static boolean isContainsAll(String s, String[] members) { | |
103 | + for (int i=0; i<members.length; i++) { | |
104 | + if (s.contains(members[i]) == false) { | |
105 | + return false; | |
106 | + } | |
107 | + } | |
108 | + return true; | |
109 | + } | |
110 | + | |
111 | + | |
80 | 112 | } |
@@ -4,6 +4,7 @@ | ||
4 | 4 | import java.awt.event.ActionListener; |
5 | 5 | import java.io.File; |
6 | 6 | import java.io.FileInputStream; |
7 | +import java.util.ArrayList; | |
7 | 8 | import java.util.List; |
8 | 9 | import java.util.Properties; |
9 | 10 |
@@ -18,7 +19,7 @@ | ||
18 | 19 | /** |
19 | 20 | * ConfigurationFile |
20 | 21 | */ |
21 | - public static final String CONFIG_FILE = "doko.conf"; | |
22 | + public static final String CONFIG_FILE = "dokonan.conf"; | |
22 | 23 | |
23 | 24 | /** |
24 | 25 | * 設定ファイル |
@@ -76,8 +77,9 @@ | ||
76 | 77 | public void run(){ |
77 | 78 | button.setEnabled(false); |
78 | 79 | dokoJar = new DokonanJar(prop); |
79 | - dokoJar.initSearch(); | |
80 | + int[] counts = dokoJar.initSearch(); | |
80 | 81 | button.setEnabled(true); |
82 | + dokoFrame.getResultArea().setText(String.format("Gradle: %dファイル, Maven: %dファイル", counts[0], counts[1])); | |
81 | 83 | } |
82 | 84 | }; |
83 | 85 | thread.start(); |
@@ -115,18 +117,38 @@ | ||
115 | 117 | |
116 | 118 | |
117 | 119 | public void searchFiles(String path) { |
118 | - resultFile = dokoJar.searchJarForGradle(path); | |
119 | - StringBuilder sb = new StringBuilder(); | |
120 | - if (resultFile != null) { | |
121 | - for (File f : resultFile) { | |
122 | - //System.out.println(">>" + f.getAbsolutePath()); | |
123 | - if (sb.length() > 0) { | |
124 | - sb.append("\n"); | |
125 | - } | |
126 | - sb.append(f.getAbsolutePath()); | |
120 | + String[] texts = getSearchTexts(path); | |
121 | + List<File> allList = new ArrayList<File>(); | |
122 | + if (dokoFrame.getGradleCheckBox().isSelected()) { | |
123 | + List<File> tempList = dokoJar.searchJarForGradle(texts); | |
124 | + if (tempList != null) { | |
125 | + allList.addAll(tempList); | |
127 | 126 | } |
128 | 127 | } |
128 | + if (dokoFrame.getMavenCheckBox().isSelected()) { | |
129 | + List<File> tempList = dokoJar.searchJarForMaven(texts); | |
130 | + if (tempList != null) { | |
131 | + allList.addAll(tempList); | |
132 | + } | |
133 | + } | |
134 | + StringBuilder sb = new StringBuilder(); | |
135 | + for (File f : allList) { | |
136 | + //System.out.println(">>" + f.getAbsolutePath()); | |
137 | + if (sb.length() > 0) { | |
138 | + sb.append("\n"); | |
139 | + } | |
140 | + sb.append(f.getAbsolutePath()); | |
141 | + } | |
129 | 142 | dokoFrame.getResultArea().setText(sb.toString()); |
143 | + resultFile = allList; | |
144 | + } | |
145 | + | |
146 | + private String[] getSearchTexts(String path) { | |
147 | + String[] texts = path.split(" "); | |
148 | + for (int i=0; i<texts.length; i++) { | |
149 | + texts[i] = texts[i].trim(); | |
150 | + } | |
151 | + return texts; | |
130 | 152 | } |
131 | 153 | |
132 | 154 | public static void main(String[] args) { |