1
2
3
4
5
6 package zipdiff.ant;
7
8 import zipdiff.DifferenceCalculator;
9 import zipdiff.Differences;
10 import zipdiff.output.*;
11 import org.apache.tools.ant.Task;
12 import org.apache.tools.ant.BuildException;
13
14 /***
15 *
16 *
17 * @author Sean C. Sullivan
18 *
19 *
20 */
21 public class ZipDiffTask extends Task {
22 private String filename1;
23 private String filename2;
24 private String destfile;
25 private boolean ignoreTimestamps = false;
26 private boolean ignoreCVSFiles = false;
27 private boolean compareCRCValues = true;
28
29 public void setFilename1(String name) {
30 filename1 = name;
31 }
32
33 public void setFilename2(String name) {
34 filename2 = name;
35 }
36
37 public void setIgnoreTimestamps(boolean b) {
38 ignoreTimestamps = b;
39 }
40
41 public boolean getIgnoreTimestamps() {
42 return ignoreTimestamps;
43 }
44
45 public void setIgnoreCVSFiles(boolean b)
46 {
47 ignoreCVSFiles = b;
48 }
49
50 public boolean getIgnoreCVSFiles() {
51 return ignoreCVSFiles;
52 }
53
54 public void setCompareCRCValues(boolean b) {
55 compareCRCValues = b;
56 }
57
58 public boolean getCompareCRCValues() {
59 return compareCRCValues;
60 }
61
62 public void execute() throws BuildException {
63 validate();
64
65
66
67
68
69 Differences d = calculateDifferences();
70
71 try {
72 writeDestFile(d);
73 } catch (java.io.IOException ex) {
74 throw new BuildException(ex);
75 }
76
77 }
78
79 protected void writeDestFile(Differences d) throws java.io.IOException {
80 String destfilename = getDestFile();
81
82 Builder builder = null;
83
84 if (destfilename.endsWith(".html")) {
85 builder = new HtmlBuilder();
86 } else if (destfilename.endsWith(".xml")) {
87 builder = new XmlBuilder();
88 } else {
89 builder = new TextBuilder();
90 }
91
92 builder.build(destfilename, d);
93 }
94
95 public String getDestFile() {
96 return destfile;
97 }
98
99 public void setDestFile(String name) {
100 destfile = name;
101 }
102
103 protected Differences calculateDifferences() throws BuildException {
104 DifferenceCalculator calculator;
105
106 Differences d = null;
107
108 try {
109 calculator = new DifferenceCalculator(filename1, filename2);
110 calculator.setCompareCRCValues(getCompareCRCValues());
111 calculator.setIgnoreTimestamps(getIgnoreTimestamps());
112 calculator.setIgnoreCVSFiles(getIgnoreCVSFiles());
113
114
115
116 d = calculator.getDifferences();
117 } catch (java.io.IOException ex) {
118 throw new BuildException(ex);
119 }
120
121 return d;
122 }
123
124 protected void validate() throws BuildException {
125 if ((filename1 == null) || (filename1.length() < 1)) {
126 throw new BuildException("filename1 is required");
127 }
128
129 if ((filename2 == null) || (filename2.length() < 1)) {
130 throw new BuildException("filename2 is required");
131 }
132
133 String destinationfile = getDestFile();
134
135 if ((destinationfile == null) || (destinationfile.length() < 1)) {
136 throw new BuildException("destfile is required");
137 }
138 }
139
140 }