Révision 1270
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/devtools/RemoveUnusedKeys.java (revision 1270) | ||
---|---|---|
4 | 4 |
import java.io.FileNotFoundException; |
5 | 5 |
import java.io.IOException; |
6 | 6 |
import java.io.UnsupportedEncodingException; |
7 |
import java.util.ArrayList; |
|
7 | 8 |
import java.util.TreeMap; |
8 | 9 |
import java.util.TreeSet; |
9 | 10 |
|
... | ... | |
18 | 19 |
*/ |
19 | 20 |
public class RemoveUnusedKeys { |
20 | 21 |
|
21 |
|
|
22 |
public void run() throws UnsupportedEncodingException, FileNotFoundException, IOException { |
|
22 |
public static void main(String[] args) throws UnsupportedEncodingException, FileNotFoundException, IOException { |
|
23 | 23 |
WorkspaceMessagesManager wmm = new WorkspaceMessagesManager(); |
24 | 24 |
|
25 | 25 |
TreeMap<String, TreeSet<File>> usedKeys = wmm.getUsedKeysFilesIndex(); |
26 |
|
|
26 |
int total = 0; |
|
27 | 27 |
for (PluginMessages pm : wmm.getPluginMessages().values()) { |
28 |
int n = 0; |
|
29 |
ArrayList<String> keys = new ArrayList<String>(pm.getMessageKeys()); |
|
30 |
ArrayList<String> removedKeys = new ArrayList<String>(); |
|
28 | 31 |
|
29 |
for (String key : pm.getMessageKeys()) {
|
|
32 |
for (String key : keys) {
|
|
30 | 33 |
if (!usedKeys.containsKey(pm.getKeyFullName(key))) { |
31 | 34 |
pm.removeKey(key); |
35 |
n++; |
|
32 | 36 |
} |
33 | 37 |
} |
34 | 38 |
|
35 |
pm.saveChanges(true); |
|
39 |
if (n > 0) { |
|
40 |
System.out.println(pm.getMessageFullName()+" "+n+" key removed: "+removedKeys); |
|
41 |
pm.saveChanges(true); |
|
42 |
total += n; |
|
43 |
} |
|
36 | 44 |
} |
45 |
|
|
46 |
if (total > 0) { |
|
47 |
System.out.println("Done: "+total+ " changes."); |
|
48 |
} else { |
|
49 |
System.out.println("No change."); |
|
50 |
} |
|
37 | 51 |
} |
38 | 52 |
} |
Formats disponibles : Unified diff