1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| package com.jeantessier.dependencyfinder.cli; |
34 |
| |
35 |
| import java.io.*; |
36 |
| import java.util.*; |
37 |
| |
38 |
| import com.jeantessier.diff.*; |
39 |
| import com.jeantessier.commandline.*; |
40 |
| |
41 |
| public class ListDiff extends Command { |
42 |
1
| protected void showSpecificUsage(PrintStream out) {
|
43 |
1
| out.println();
|
44 |
1
| out.println("Defaults is text output to the console.");
|
45 |
1
| out.println();
|
46 |
| } |
47 |
| |
48 |
8
| protected void populateCommandLineSwitches() {
|
49 |
8
| super.populateCommandLineSwitches();
|
50 |
8
| populateCommandLineSwitchesForXMLOutput(ListDiffPrinter.DEFAULT_ENCODING, ListDiffPrinter.DEFAULT_DTD_PREFIX, ListDiffPrinter.DEFAULT_INDENT_TEXT);
|
51 |
| |
52 |
8
| getCommandLine().addSingleValueSwitch("name");
|
53 |
8
| getCommandLine().addSingleValueSwitch("old-label");
|
54 |
8
| getCommandLine().addSingleValueSwitch("old", true);
|
55 |
8
| getCommandLine().addSingleValueSwitch("new-label");
|
56 |
8
| getCommandLine().addSingleValueSwitch("new", true);
|
57 |
8
| getCommandLine().addToggleSwitch("compress");
|
58 |
| } |
59 |
| |
60 |
7
| protected Collection<CommandLineException> parseCommandLine(String[] args) {
|
61 |
7
| Collection<CommandLineException> exceptions = super.parseCommandLine(args);
|
62 |
| |
63 |
7
| if (!getCommandLine().isPresent("old-label")) {
|
64 |
7
| getCommandLine().getSwitch("old-label").setValue(getCommandLine().getSingleSwitch("old"));
|
65 |
| } |
66 |
| |
67 |
7
| if (!getCommandLine().isPresent("new-label")) {
|
68 |
7
| getCommandLine().getSwitch("new-label").setValue(getCommandLine().getSingleSwitch("new"));
|
69 |
| } |
70 |
| |
71 |
7
| return exceptions;
|
72 |
| } |
73 |
| |
74 |
0
| protected void doProcessing() throws Exception {
|
75 |
0
| String line;
|
76 |
| |
77 |
0
| getVerboseListener().print("Loading old list ...");
|
78 |
0
| Collection<String> oldAPI = new TreeSet<String>();
|
79 |
0
| BufferedReader oldIn = new BufferedReader(new FileReader(getCommandLine().getSingleSwitch("old")));
|
80 |
0
| while((line = oldIn.readLine()) != null) {
|
81 |
0
| oldAPI.add(line);
|
82 |
| } |
83 |
0
| oldIn.close();
|
84 |
| |
85 |
0
| getVerboseListener().print("Loading new list ...");
|
86 |
0
| Collection<String> newAPI = new TreeSet<String>();
|
87 |
0
| BufferedReader newIn = new BufferedReader(new FileReader(getCommandLine().getSingleSwitch("new")));
|
88 |
0
| while((line = newIn.readLine()) != null) {
|
89 |
0
| newAPI.add(line);
|
90 |
| } |
91 |
0
| newIn.close();
|
92 |
| |
93 |
0
| ListDiffPrinter printer = new ListDiffPrinter(getCommandLine().getToggleSwitch("compress"), getCommandLine().getSingleSwitch("encoding"), getCommandLine().getSingleSwitch("dtd-prefix"));
|
94 |
0
| printer.setName(getCommandLine().getSingleSwitch("name"));
|
95 |
0
| printer.setOldVersion(getCommandLine().getSingleSwitch("old-label"));
|
96 |
0
| printer.setNewVersion(getCommandLine().getSingleSwitch("new-label"));
|
97 |
0
| if (getCommandLine().isPresent("indent-text")) {
|
98 |
0
| printer.setIndentText(getCommandLine().getSingleSwitch("indent-text"));
|
99 |
| } |
100 |
| |
101 |
0
| getVerboseListener().print("Computing removed elements ...");
|
102 |
0
| for (String name : oldAPI) {
|
103 |
0
| if (!newAPI.contains(name)) {
|
104 |
0
| printer.remove(name);
|
105 |
| } |
106 |
| } |
107 |
| |
108 |
0
| getVerboseListener().print("Computing added elements ...");
|
109 |
0
| for (String name : newAPI) {
|
110 |
0
| if (!oldAPI.contains(name)) {
|
111 |
0
| printer.add(name);
|
112 |
| } |
113 |
| } |
114 |
| |
115 |
0
| getVerboseListener().print("Printing results ...");
|
116 |
0
| getOut().print(printer);
|
117 |
| } |
118 |
| |
119 |
0
| public static void main(String[] args) throws Exception {
|
120 |
0
| new ListDiff().run(args);
|
121 |
| } |
122 |
| } |