• R/O
  • SSH

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Gradle/Mavenが持っているjarファイルのパスを表示するツール


Commit MetaInfo

Revisãoe80d5eb4194d6b15552f3599a9e60cd7fdba34d4 (tree)
Hora2022-02-26 10:14:08
Autorkemono7h
Commiterkemono7h

Mensagem de Log

Maven対応

Mudança Sumário

Diff

diff -r 98918c47b0c2 -r e80d5eb4194d src/jp/nanah/dnj/DokonanFrame.java
--- a/src/jp/nanah/dnj/DokonanFrame.java Sat Feb 26 08:54:41 2022 +0900
+++ b/src/jp/nanah/dnj/DokonanFrame.java Sat Feb 26 10:14:08 2022 +0900
@@ -1,9 +1,11 @@
11 package jp.nanah.dnj;
22
33 import java.awt.BorderLayout;
4+import java.awt.FlowLayout;
45 import java.awt.Font;
56
67 import javax.swing.JButton;
8+import javax.swing.JCheckBox;
79 import javax.swing.JFrame;
810 import javax.swing.JPanel;
911 import javax.swing.JScrollPane;
@@ -29,6 +31,12 @@
2931 private JFrame frame;
3032
3133 /**
34+ * チェックボックス
35+ */
36+ private JCheckBox cbGradle;
37+ private JCheckBox cbMaven;
38+
39+ /**
3240 * 結果表示エリア
3341 */
3442 private JTextArea resultArea;
@@ -49,16 +57,42 @@
4957
5058 Font font = new Font("Meiryo UI", Font.PLAIN, 12);
5159
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+
5383 {
5484 JTextField txtField = new JTextField();
85+ //入力エリア
5586 txtField.getDocument().addDocumentListener(new FiDocumentListener());
5687 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);
6296 }
6397
6498 //結果出力エリア
@@ -86,15 +120,21 @@
86120 }
87121 }
88122
123+ public JFrame getFrame() {
124+ return frame;
125+ }
126+ public JCheckBox getGradleCheckBox() {
127+ return cbGradle;
128+ }
129+ public JCheckBox getMavenCheckBox() {
130+ return cbMaven;
131+ }
89132 public JButton getCopyButton() {
90133 return copyButton;
91134 }
92135 public JTextArea getResultArea() {
93136 return resultArea;
94137 }
95- public JFrame getFrame() {
96- return frame;
97- }
98138
99139 /**
100140 * クリック最新時刻
diff -r 98918c47b0c2 -r e80d5eb4194d src/jp/nanah/dnj/DokonanJar.java
--- a/src/jp/nanah/dnj/DokonanJar.java Sat Feb 26 08:54:41 2022 +0900
+++ b/src/jp/nanah/dnj/DokonanJar.java Sat Feb 26 10:14:08 2022 +0900
@@ -9,7 +9,8 @@
99
1010 private String userHome;
1111
12- private List<File> allJarList;
12+ private List<File> gradleJarList;
13+ private List<File> mavenJarList;
1314
1415 public DokonanJar(Properties prop) {
1516 userHome = System.getProperty("user.home");
@@ -19,10 +20,11 @@
1920 }
2021 }
2122
22- public List<File> initSearch() {
23- allJarList = getAllJarForGradle();
23+ public int[] initSearch() {
24+ gradleJarList = getAllJarForGradle();
25+ mavenJarList = getAllJarForMaven();
2426 //System.out.println("全" + allJarList.size() + "ファイル");
25- return allJarList;
27+ return new int[] {gradleJarList.size(), mavenJarList.size()};
2628 }
2729
2830 public List<File> getAllJarForGradle(){
@@ -40,6 +42,18 @@
4042 return fileList;
4143 }
4244
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+
4357 public List<File> searchFiles(File dir, String path, List<File> fileList) {
4458 if (fileList == null) {
4559 fileList = new ArrayList<File>();
@@ -67,14 +81,32 @@
6781 return fileList;
6882 }
6983
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){
7193 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)) {
7496 fileList.add(f);
7597 }
7698 }
7799 return fileList;
78100 }
79101
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+
80112 }
diff -r 98918c47b0c2 -r e80d5eb4194d src/jp/nanah/dnj/DokonanJarMain.java
--- a/src/jp/nanah/dnj/DokonanJarMain.java Sat Feb 26 08:54:41 2022 +0900
+++ b/src/jp/nanah/dnj/DokonanJarMain.java Sat Feb 26 10:14:08 2022 +0900
@@ -4,6 +4,7 @@
44 import java.awt.event.ActionListener;
55 import java.io.File;
66 import java.io.FileInputStream;
7+import java.util.ArrayList;
78 import java.util.List;
89 import java.util.Properties;
910
@@ -18,7 +19,7 @@
1819 /**
1920 * ConfigurationFile
2021 */
21- public static final String CONFIG_FILE = "doko.conf";
22+ public static final String CONFIG_FILE = "dokonan.conf";
2223
2324 /**
2425 * 設定ファイル
@@ -76,8 +77,9 @@
7677 public void run(){
7778 button.setEnabled(false);
7879 dokoJar = new DokonanJar(prop);
79- dokoJar.initSearch();
80+ int[] counts = dokoJar.initSearch();
8081 button.setEnabled(true);
82+ dokoFrame.getResultArea().setText(String.format("Gradle: %dファイル, Maven: %dファイル", counts[0], counts[1]));
8183 }
8284 };
8385 thread.start();
@@ -115,18 +117,38 @@
115117
116118
117119 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);
127126 }
128127 }
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+ }
129142 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;
130152 }
131153
132154 public static void main(String[] args) {