10 |
10 |
import java.io.UnsupportedEncodingException;
|
11 |
11 |
import java.util.ArrayList;
|
12 |
12 |
import java.util.Arrays;
|
13 |
|
import java.util.Collection;
|
14 |
13 |
import java.util.Collections;
|
15 |
14 |
import java.util.HashMap;
|
16 |
15 |
import java.util.LinkedHashSet;
|
17 |
16 |
import java.util.Map;
|
18 |
17 |
import java.util.Properties;
|
19 |
18 |
import java.util.TreeSet;
|
20 |
|
import java.util.regex.Pattern;
|
21 |
19 |
|
22 |
20 |
import org.apache.commons.io.FilenameUtils;
|
23 |
21 |
import org.apache.commons.lang.StringUtils;
|
... | ... | |
29 |
27 |
* Check any missing key in both of messages.properties and Message.java files
|
30 |
28 |
*
|
31 |
29 |
* @author mdecorde
|
|
30 |
* @author sjacquot
|
32 |
31 |
*
|
33 |
32 |
*/
|
34 |
33 |
public class PluginMessages {
|
35 |
34 |
|
36 |
|
|
|
35 |
/**
|
|
36 |
* Files encoding.
|
|
37 |
*/
|
37 |
38 |
public static String ENCODING = "UTF-8";
|
|
39 |
|
|
40 |
/**
|
|
41 |
* Debug state.
|
|
42 |
*/
|
38 |
43 |
public boolean debug = true;
|
39 |
44 |
|
40 |
45 |
/**
|
... | ... | |
60 |
65 |
/**
|
61 |
66 |
* Global REGEX containing all keys to later use for search in files.
|
62 |
67 |
*/
|
63 |
|
protected Pattern keysGlobalREGEX;
|
|
68 |
//protected Pattern keysGlobalREGEX;
|
64 |
69 |
|
65 |
70 |
/**
|
66 |
71 |
* Index of the keys used and their associated files.
|
67 |
72 |
*/
|
68 |
|
protected HashMap<String, TreeSet<File>> usedKeysIndex;
|
|
73 |
protected HashMap<String, TreeSet<File>> usedKeysFilesIndex;
|
69 |
74 |
|
70 |
75 |
|
71 |
76 |
|
... | ... | |
131 |
136 |
this.createSourceFilesList();
|
132 |
137 |
|
133 |
138 |
//this.createKeysGlobalREGEX();
|
134 |
|
this.createUsedKeysIndex();
|
135 |
|
}
|
136 |
|
|
137 |
|
/**
|
138 |
|
* Creates a global REGEX containing all keys to later search in files.
|
139 |
|
*/
|
140 |
|
public void createKeysGlobalREGEX() {
|
141 |
|
StringBuffer buffer = new StringBuffer();
|
142 |
|
for (String key : messageKeys) {
|
143 |
|
buffer.append("|" + key);
|
144 |
|
}
|
|
139 |
this.createUsedKeysFilesIndex();
|
145 |
140 |
|
146 |
|
// remove first pipe
|
147 |
|
buffer.deleteCharAt(0);
|
148 |
|
|
149 |
|
this.keysGlobalREGEX = Pattern.compile("(" + buffer + ")");
|
150 |
|
|
151 |
141 |
if(debug) {
|
152 |
|
System.out.println("PluginMessages.createKeysGlobalREGEX(): REGEX created: " + this.keysGlobalREGEX + ".");
|
|
142 |
this.dumpUsedKeysFilesIndex();
|
153 |
143 |
}
|
154 |
|
|
155 |
144 |
}
|
156 |
145 |
|
|
146 |
// /**
|
|
147 |
// * Creates a global REGEX containing all keys to later search in files.
|
|
148 |
// */
|
|
149 |
// public void createKeysGlobalREGEX() {
|
|
150 |
// StringBuffer buffer = new StringBuffer();
|
|
151 |
// for (String key : messageKeys) {
|
|
152 |
// buffer.append("|" + key);
|
|
153 |
// }
|
|
154 |
//
|
|
155 |
// // remove first pipe
|
|
156 |
// buffer.deleteCharAt(0);
|
|
157 |
//
|
|
158 |
// this.keysGlobalREGEX = Pattern.compile("(" + buffer + ")");
|
|
159 |
//
|
|
160 |
// if(debug) {
|
|
161 |
// System.out.println("PluginMessages.createKeysGlobalREGEX(): REGEX created: " + this.keysGlobalREGEX + ".");
|
|
162 |
// }
|
|
163 |
//
|
|
164 |
// }
|
|
165 |
|
157 |
166 |
/**
|
158 |
167 |
* Creates the index of the keys used and their associated files.
|
159 |
168 |
*/
|
160 |
|
public void createUsedKeysIndex() {
|
161 |
|
this.usedKeysIndex = new HashMap<String, TreeSet<File>>();
|
|
169 |
public void createUsedKeysFilesIndex() {
|
|
170 |
this.usedKeysFilesIndex = new HashMap<String, TreeSet<File>>();
|
162 |
171 |
|
163 |
172 |
for (String key : messageKeys) {
|
164 |
173 |
|
165 |
174 |
TreeSet<File> files = new TreeSet<File>();
|
166 |
|
this.usedKeysIndex.put(key, files);
|
|
175 |
this.usedKeysFilesIndex.put(key, files);
|
167 |
176 |
|
168 |
177 |
if(debug) {
|
169 |
178 |
System.out.println("PluginMessages.createUsedKeysIndex(): looking for key " + this.getKeyFullName(key) + " in project source files...");
|
... | ... | |
180 |
189 |
}
|
181 |
190 |
}
|
182 |
191 |
}
|
183 |
|
this.dumpUsedKeysIndex();
|
184 |
192 |
}
|
185 |
193 |
|
186 |
194 |
|
187 |
195 |
/**
|
188 |
196 |
* Dumps the index of the keys used and their associated files.
|
189 |
197 |
*/
|
190 |
|
public void dumpUsedKeysIndex() {
|
|
198 |
public void dumpUsedKeysFilesIndex() {
|
191 |
199 |
|
192 |
200 |
System.out.println("PluginMessages.dumpUsedKeysIndex(): dumping used keys files index...");
|
193 |
201 |
|
194 |
|
for (Map.Entry<String, TreeSet<File>> entry : this.usedKeysIndex.entrySet()) {
|
|
202 |
for (Map.Entry<String, TreeSet<File>> entry : this.usedKeysFilesIndex.entrySet()) {
|
195 |
203 |
System.out.println("key: " + this.getKeyFullName(entry.getKey()));
|
196 |
204 |
if(entry.getValue().isEmpty()) {
|
197 |
205 |
System.out.println(" file(s): -not used in any file of the project " + this.getProjectDirectory() + "-");
|
... | ... | |
210 |
218 |
* @return
|
211 |
219 |
*/
|
212 |
220 |
public TreeSet<File> getFilesUsingKey(String key) {
|
213 |
|
return this.usedKeysIndex.get(key);
|
|
221 |
return this.usedKeysFilesIndex.get(key);
|
214 |
222 |
}
|
215 |
223 |
|
216 |
224 |
|
... | ... | |
220 |
228 |
*/
|
221 |
229 |
public ArrayList<String> getUnusedKeys() {
|
222 |
230 |
ArrayList<String> unusedKeys = new ArrayList<String>();
|
223 |
|
for (Map.Entry<String, TreeSet<File>> entry : this.usedKeysIndex.entrySet()) {
|
|
231 |
for (Map.Entry<String, TreeSet<File>> entry : this.usedKeysFilesIndex.entrySet()) {
|
224 |
232 |
if(entry.getValue().isEmpty()) {
|
225 |
233 |
|
226 |
234 |
if(debug) {
|
... | ... | |
412 |
420 |
/**
|
413 |
421 |
* Parses the project and stores a list of the source files.
|
414 |
422 |
*/
|
415 |
|
private void loadSourceFilesList(File path) {
|
|
423 |
private void createSourceFilesList(File path) {
|
416 |
424 |
File[] list = path.listFiles();
|
417 |
425 |
|
418 |
426 |
if (list == null) {
|
... | ... | |
421 |
429 |
|
422 |
430 |
for (File file : list) {
|
423 |
431 |
if (file.isDirectory()) {
|
424 |
|
this.loadSourceFilesList(file);
|
|
432 |
this.createSourceFilesList(file);
|
425 |
433 |
}
|
426 |
434 |
else if (!file.equals(this.javaMessageFile)
|
427 |
435 |
&& Arrays.asList(this.srcFilesExtensions).contains(FilenameUtils.getExtension(file.getName()))
|
428 |
436 |
) {
|
429 |
437 |
|
430 |
438 |
if(debug) {
|
431 |
|
System.out.println("PluginMessages.loadSourceFilesList(): adding source files " + file + ".");
|
|
439 |
System.out.println("PluginMessages.createSourceFilesList(): adding source files " + file + ".");
|
432 |
440 |
}
|
433 |
441 |
|
434 |
442 |
this.srcFiles.add(file);
|
... | ... | |
441 |
449 |
*/
|
442 |
450 |
public void createSourceFilesList() {
|
443 |
451 |
|
444 |
|
if(debug) {
|
445 |
|
System.out.println("PluginMessages.loadSourceFilesList(): creating source files list for extensions [" + StringUtils.join(this.srcFilesExtensions, ", ") + "]...");
|
446 |
|
}
|
|
452 |
System.out.println("PluginMessages.loadSourceFilesList(): creating source files list for extensions [" + StringUtils.join(this.srcFilesExtensions, ", ") + "]...");
|
447 |
453 |
|
448 |
|
this.loadSourceFilesList(this.projectDirectory);
|
|
454 |
this.createSourceFilesList(this.projectDirectory);
|
449 |
455 |
|
450 |
|
if(debug) {
|
451 |
|
System.out.println("PluginMessages.loadSourceFilesList(): done. Source files count = " + this.srcFiles.size() + ".");
|
452 |
|
}
|
453 |
|
|
|
456 |
System.out.println("PluginMessages.loadSourceFilesList(): done. Source files count = " + this.srcFiles.size() + ".");
|
454 |
457 |
}
|
455 |
458 |
|
456 |
459 |
|
... | ... | |
526 |
529 |
/**
|
527 |
530 |
* @return the usedKeysIndex
|
528 |
531 |
*/
|
529 |
|
public HashMap<String, TreeSet<File>> getUsedKeysIndex() {
|
530 |
|
return usedKeysIndex;
|
|
532 |
public HashMap<String, TreeSet<File>> getUsedKeysFilesIndex() {
|
|
533 |
return usedKeysFilesIndex;
|
531 |
534 |
}
|
532 |
535 |
|
533 |
536 |
|