forked from nhnb/zipdiff
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZipDiffTask.java
More file actions
199 lines (152 loc) · 4.26 KB
/
Copy pathZipDiffTask.java
File metadata and controls
199 lines (152 loc) · 4.26 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/* zipdiff is available under the terms of the
* Apache License, version 2.0
*
* Link: http://www.apache.org/licenses/
*/
package zipdiff.ant;
import java.io.IOException;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import zipdiff.DifferenceCalculator;
import zipdiff.Differences;
import zipdiff.output.Builder;
import zipdiff.output.BuilderFactory;
/**
* Ant task for running zipdiff from a build.xml file
*
*
* @author Sean C. Sullivan
*/
public class ZipDiffTask extends Task {
private String filename1;
private String filename2;
private int numberOfOutputPrefixesToSkip;
private int skipPrefixes1 = 0;
private int SkipPrefixes2 = 0;
private String destfile;
private boolean ignoreTimestamps = false;
private boolean ignoreCVSFiles = false;
private boolean compareCRCValues = true;
public void setFilename1(String name) {
filename1 = name;
}
public void setFilename2(String name) {
filename2 = name;
}
public int getNumberOfOutputPrefixesToSkip() {
return numberOfOutputPrefixesToSkip;
}
public void setNumberOfOutputPrefixesToSkip(int numberOfOutputPrefixesToSkip) {
this.numberOfOutputPrefixesToSkip = numberOfOutputPrefixesToSkip;
}
public int getSkipPrefixes1() {
return skipPrefixes1;
}
public void setSkipPrefixes1(int numberOfPrefixesToSkip1) {
this.skipPrefixes1 = numberOfPrefixesToSkip1;
}
public int getSkipPrefixes2() {
return SkipPrefixes2;
}
public void setSkipPrefixes2(int numberOfPrefixesToSkip2) {
this.SkipPrefixes2 = numberOfPrefixesToSkip2;
}
public void setIgnoreTimestamps(boolean b) {
ignoreTimestamps = b;
}
public boolean getIgnoreTimestamps() {
return ignoreTimestamps;
}
public void setIgnoreCVSFiles(boolean b) {
ignoreCVSFiles = b;
}
public boolean getIgnoreCVSFiles() {
return ignoreCVSFiles;
}
public void setCompareCRCValues(boolean b) {
compareCRCValues = b;
}
public boolean getCompareCRCValues() {
return compareCRCValues;
}
@Override
public void execute() throws BuildException {
validate();
// this.log("Filename1=" + filename1, Project.MSG_DEBUG);
// this.log("Filename2=" + filename2, Project.MSG_DEBUG);
// this.log("destfile=" + getDestFile(), Project.MSG_DEBUG);
Differences d = calculateDifferences();
try {
writeDestFile(d);
} catch (java.io.IOException ex) {
throw new BuildException(ex);
}
}
/**
* writes the output file
*
* @param d set of Differences
* @throws IOException
*/
protected void writeDestFile(Differences d) throws IOException {
String destfilename = getDestFile();
Builder builder = BuilderFactory.create(destfilename);
builder.build(destfilename, numberOfOutputPrefixesToSkip, d);
}
/**
* gets the name of the target file
*
* @return target file
*/
public String getDestFile() {
return destfile;
}
/**
* sets the name of the target file
*
* @param name filename
*/
public void setDestFile(String name) {
destfile = name;
}
/**
* calculates the differences
*
* @return set of Differences
* @throws BuildException in case of an input/output error
*/
protected Differences calculateDifferences() throws BuildException {
DifferenceCalculator calculator;
Differences d = null;
try {
calculator = new DifferenceCalculator(filename1, filename2);
calculator.setNumberOfPrefixesToSkip1(skipPrefixes1);
calculator.setNumberOfPrefixesToSkip2(SkipPrefixes2);
calculator.setCompareCRCValues(getCompareCRCValues());
calculator.setIgnoreTimestamps(getIgnoreTimestamps());
calculator.setIgnoreCVSFiles(getIgnoreCVSFiles());
// todo : calculator.setFilenamesToIgnore(patterns);
d = calculator.getDifferences();
} catch (IOException ex) {
throw new BuildException(ex);
}
return d;
}
/**
* validates the parameters
*
* @throws BuildException in case of invalid parameters
*/
protected void validate() throws BuildException {
if ((filename1 == null) || (filename1.length() < 1)) {
throw new BuildException("filename1 is required");
}
if ((filename2 == null) || (filename2.length() < 1)) {
throw new BuildException("filename2 is required");
}
String destinationfile = getDestFile();
if ((destinationfile == null) || (destinationfile.length() < 1)) {
throw new BuildException("destfile is required");
}
}
}