1 | <!--
|
---|
2 | Licensed to the Apache Software Foundation (ASF) under one or more
|
---|
3 | contributor license agreements. See the NOTICE file distributed with
|
---|
4 | this work for additional information regarding copyright ownership.
|
---|
5 | The ASF licenses this file to You under the Apache License, Version 2.0
|
---|
6 | (the "License"); you may not use this file except in compliance with
|
---|
7 | the License. You may obtain a copy of the License at
|
---|
8 |
|
---|
9 | http://www.apache.org/licenses/LICENSE-2.0
|
---|
10 |
|
---|
11 | Unless required by applicable law or agreed to in writing, software
|
---|
12 | distributed under the License is distributed on an "AS IS" BASIS,
|
---|
13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
14 | See the License for the specific language governing permissions and
|
---|
15 | limitations under the License.
|
---|
16 | -->
|
---|
17 | <html>
|
---|
18 |
|
---|
19 | <head>
|
---|
20 | <meta http-equiv="Content-Language" content="en-us">
|
---|
21 | <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
|
---|
22 | <title>Checksum Task</title>
|
---|
23 | </head>
|
---|
24 |
|
---|
25 | <body>
|
---|
26 |
|
---|
27 | <h2><a name="checksum">Checksum</a></h2>
|
---|
28 | <h3>Description</h3>
|
---|
29 | <p>
|
---|
30 | Generates checksum for files. This task can also be used to
|
---|
31 | perform checksum verifications.
|
---|
32 | </p>
|
---|
33 |
|
---|
34 | <p>Note that many popular message digest functions - including MD5 and
|
---|
35 | SHA-1 - have been broken recently. If you are going to use the task
|
---|
36 | to create checksums used in an environment where security is
|
---|
37 | important, please take some time to investigate the algorithms offered
|
---|
38 | by your JCE provider. Note also that some JCE providers like the one
|
---|
39 | by <a href="http://www.bouncycastle.org/">The Legion of the Bouncy
|
---|
40 | Castle</a>, the <a href="http://www.gnu.org/software/gnu-crypto/">GNU
|
---|
41 | project</a> or <a
|
---|
42 | href="http://jce.iaik.tugraz.at/products/01_jce/index.php">the
|
---|
43 | Technical University Graz</a> offer more digest algorithms than those
|
---|
44 | built-in into your JDK.</p>
|
---|
45 |
|
---|
46 | <p>
|
---|
47 | Warning: the case of the extension is that of the algorithm used.
|
---|
48 | If you ask for "SHA1", you get a .SHA1 extension; if you ask for "sha1", you
|
---|
49 | get a file ending in .sha1. The Java Crypto Engines are case-insensitive
|
---|
50 | in matching algorithms, so choose a name to match your desired output extension,
|
---|
51 | or set the <tt>fileext</tt> attribute.
|
---|
52 | </p>
|
---|
53 |
|
---|
54 | <h3>Parameters</h3>
|
---|
55 | <table border="1" cellpadding="2" cellspacing="0">
|
---|
56 | <tr>
|
---|
57 | <td valign="top"><b>Attribute</b></td>
|
---|
58 | <td valign="top"><b>Description</b></td>
|
---|
59 | <td align="center" valign="top"><b>Required</b></td>
|
---|
60 | </tr>
|
---|
61 | <tr>
|
---|
62 | <td valign="top">file</td>
|
---|
63 | <td valign="top">The file to generate checksum for.</td>
|
---|
64 | <td valign="top" align="center">One of either <var>file</var> or
|
---|
65 | at least one nested (filesystem-only) resource collection.</td>
|
---|
66 | </tr>
|
---|
67 | <tr>
|
---|
68 | <td valign="top">todir</td>
|
---|
69 | <td valign="top">The root directory where checksums should be written.</td>
|
---|
70 | <td valign="top" align="center">No. If not specified, checksum files
|
---|
71 | will be written to the same directory as the files themselves.
|
---|
72 | <em>since Ant 1.6</em>
|
---|
73 | </td>
|
---|
74 | </tr>
|
---|
75 | <tr>
|
---|
76 | <td valign="top">algorithm</td>
|
---|
77 | <td valign="top">Specifies the algorithm to be used to
|
---|
78 | compute the checksum. Defaults to "MD5".
|
---|
79 | Other popular algorithms like "SHA" may be used
|
---|
80 | as well.
|
---|
81 | </td>
|
---|
82 | <td valign="top" align="center">No</td>
|
---|
83 | </tr>
|
---|
84 | <tr>
|
---|
85 | <td valign="top">provider</td>
|
---|
86 | <td valign="top">Specifies the provider of the algorithm.</td>
|
---|
87 | <td valign="top" align="center">No</td>
|
---|
88 | </tr>
|
---|
89 | <tr>
|
---|
90 | <td valign="top">fileext</td>
|
---|
91 | <td valign="top">The generated checksum file's name will be the
|
---|
92 | original filename with the fileext added to it.
|
---|
93 | Defaults to a "." and the algorithm name being used.
|
---|
94 | </td>
|
---|
95 | <td valign="top" align="center">No</td>
|
---|
96 | </tr>
|
---|
97 | <tr>
|
---|
98 | <td valign="top">property</td>
|
---|
99 | <td valign="top">This attribute can mean two different things, it
|
---|
100 | depends on the presence of the verifyproperty attribute.<br>
|
---|
101 | <b>If you don't set the verifyproperty attribute</b>, property
|
---|
102 | specifies the name of the property to be set with the generated
|
---|
103 | checksum value.<br>
|
---|
104 | <b>If you set the verifyproperty attribute</b>, property specifies
|
---|
105 | the checksum you expect to be generated (the checksum itself, not
|
---|
106 | a name of a property containing the checksum).<br>
|
---|
107 | This cannot be specified when fileext is being used or when the
|
---|
108 | number of files for which checksums is to be generated is greater
|
---|
109 | than 1.
|
---|
110 | </td>
|
---|
111 | <td valign="top" align="center">No</td>
|
---|
112 | </tr>
|
---|
113 | <tr>
|
---|
114 | <td valign="top">pattern</td>
|
---|
115 | <td valign="top">Specifies the pattern to use as a pattern
|
---|
116 | suitable for <a
|
---|
117 | href="http://java.sun.com/j2se/1.4.2/docs/api/java/text/MessageFormat.html">MessageFormat</a>
|
---|
118 | where <code>{0}</code> is replaced with the checksum and
|
---|
119 | <code>{1}</code> with the file name.</td>
|
---|
120 | <td valign="top" align="center">No - default is "{0}".</td>
|
---|
121 | </tr>
|
---|
122 | <tr>
|
---|
123 | <td valign="top">format</td>
|
---|
124 | <td valign="top">Specifies the pattern to use as one of a
|
---|
125 | well-known format. Supported values are "CHECKSUM"
|
---|
126 | (only the checksum itself, the default), "MD5SUM" the
|
---|
127 | format of GNU textutils md5sum and "SVF" the format of
|
---|
128 | *BSDs md5 command.</td>
|
---|
129 | <td valign="top" align="center">No - default is "CHECKSUM".</td>
|
---|
130 | </tr>
|
---|
131 | <tr>
|
---|
132 | <td valign="top">totalproperty</td>
|
---|
133 | <td valign="top">If specified, this attribute specifies the name of
|
---|
134 | the property that will hold a checksum of all the checksums and
|
---|
135 | file paths. The individual checksums and the relative paths to the files
|
---|
136 | within the resource collections in which they are defined will be used to
|
---|
137 | compute this checksum. (The file separators in the paths will be
|
---|
138 | converted to '/' before computation to ensure platform portability).
|
---|
139 | <em>since Ant 1.6</em>
|
---|
140 | </td>
|
---|
141 | <td valign="top" align="center">No</td>
|
---|
142 | </tr>
|
---|
143 | <tr>
|
---|
144 | <td valign="top">forceoverwrite</td>
|
---|
145 | <td valign="top">Overwrite existing files even if the destination
|
---|
146 | files are newer. Defaults to "no".</td>
|
---|
147 | <td valign="top" align="center">No</td>
|
---|
148 | </tr>
|
---|
149 | <tr>
|
---|
150 | <td valign="top">verifyproperty</td>
|
---|
151 | <td valign="top">Specifies the name of the property to be set
|
---|
152 | with "true" or "false" depending upon whether
|
---|
153 | the generated checksum matches the existing checksum. When
|
---|
154 | this is set, the generated checksum is not written to a file or
|
---|
155 | property, but rather, the content of the file or property is used to
|
---|
156 | check against the generated checksum.
|
---|
157 | <td valign="top" align="center">No</td>
|
---|
158 | </tr>
|
---|
159 | <tr>
|
---|
160 | <td valign="top">readbuffersize</td>
|
---|
161 | <td valign="top">The size of the buffer (in bytes) to use when
|
---|
162 | reading a file. Defaults to "8192" - you may get a
|
---|
163 | better performance on big files if you increase this value.</td>
|
---|
164 | <td valign="top" align="center">No</td>
|
---|
165 | </tr>
|
---|
166 | </table>
|
---|
167 | <h3>Parameters specified as nested elements</h3>
|
---|
168 |
|
---|
169 | <h4>resource collection</h4>
|
---|
170 | <p>
|
---|
171 | <a href="../CoreTypes/resources.html#collection">Resource collections</a> are
|
---|
172 | used to select files for which checksums should be generated.
|
---|
173 | </p>
|
---|
174 |
|
---|
175 | <h3>Examples</h3>
|
---|
176 | <p><b>Example 1</b></p>
|
---|
177 | <blockquote><pre><checksum file="foo.bar"/></pre></blockquote>
|
---|
178 | Generates a MD5 checksum for foo.bar and stores the checksum in the destination file
|
---|
179 | foo.bar.MD5. foo.bar.MD5 is overwritten only if foo.bar is newer than itself.
|
---|
180 |
|
---|
181 | <p><b>Example 2</b></p>
|
---|
182 | <blockquote><pre><checksum file="foo.bar" forceOverwrite="yes"/></pre></blockquote>
|
---|
183 | Generates a MD5 checksum for foo.bar and stores the checksum in foo.bar.MD5.
|
---|
184 | If foo.bar.MD5 already exists, it is overwritten.
|
---|
185 |
|
---|
186 | <p><b>Example 3</b></p>
|
---|
187 | <blockquote><pre><checksum file="foo.bar" property="foobarMD5"/></pre></blockquote>
|
---|
188 | Generates a MD5 checksum for foo.bar and stores it in the Project Property foobarMD5.
|
---|
189 |
|
---|
190 | <p><b>Example 4</b></p>
|
---|
191 | <blockquote><pre><checksum file="foo.bar" verifyProperty="isMD5ok"/></pre></blockquote>
|
---|
192 | Generates a MD5 checksum for foo.bar, compares it against foo.bar.MD5 and sets
|
---|
193 | isMD5ok to either true or false, depending upon the result.
|
---|
194 |
|
---|
195 | <p><b>Example 5</b></p>
|
---|
196 | <blockquote><pre><checksum file="foo.bar" algorithm="SHA" fileext="asc"/></pre></blockquote>
|
---|
197 | Generates a SHA checksum for foo.bar and stores the checksum in the destination file
|
---|
198 | foo.bar.asc. foo.bar.asc is overwritten only if foo.bar is newer than itself.
|
---|
199 |
|
---|
200 | <p><b>Example 6</b></p>
|
---|
201 | <blockquote><pre>
|
---|
202 | <checksum file="foo.bar" property="${md5}" verifyProperty="isEqual"/>
|
---|
203 | </pre></blockquote>
|
---|
204 | Generates a MD5 checksum for foo.bar, compares it against the value of the property
|
---|
205 | md5, and sets isEqual to either true or false, depending upon the result.
|
---|
206 |
|
---|
207 | <p><b>Example 7</b></p>
|
---|
208 | <blockquote><pre>
|
---|
209 | <checksum>
|
---|
210 | <fileset dir=".">
|
---|
211 | <include name="foo*"/>
|
---|
212 | </fileset>
|
---|
213 | </checksum>
|
---|
214 | </pre></blockquote>
|
---|
215 | Works just like Example 1, but generates a .MD5 file for every file that begins with the name foo.
|
---|
216 |
|
---|
217 | <p><b>Example 8</b></p>
|
---|
218 | <blockquote><pre>
|
---|
219 | <condition property="isChecksumEqual">
|
---|
220 | <checksum>
|
---|
221 | <fileset dir=".">
|
---|
222 | <include name="foo.bar"/>
|
---|
223 | </fileset>
|
---|
224 | </checksum>
|
---|
225 | </condition>
|
---|
226 | </pre></blockquote>
|
---|
227 | Works like Example 4, but only sets isChecksumEqual to true, if the
|
---|
228 | checksum matches - it will never be set to false. This example
|
---|
229 | demonstrates use with the Condition task.
|
---|
230 |
|
---|
231 |
|
---|
232 | <h3>Note:</h3>
|
---|
233 | When working with more than one file, if condition and/or verifyproperty is used,
|
---|
234 | the result will be true only if the checksums matched correctly for all files being
|
---|
235 | considered.
|
---|
236 |
|
---|
237 |
|
---|
238 |
|
---|
239 | </body>
|
---|
240 | </html>
|
---|
241 |
|
---|