1 | <html>
|
---|
2 |
|
---|
3 | <head>
|
---|
4 | <meta http-equiv="Content-Language" content="en-us">
|
---|
5 | <title>Checksum Task</title>
|
---|
6 | <link rel="stylesheet" type="text/css" href="../stylesheets/antmanual.css">
|
---|
7 | </head>
|
---|
8 |
|
---|
9 | <body>
|
---|
10 |
|
---|
11 | <h2><a name="checksum">Checksum</a></h2>
|
---|
12 | <h3>Description</h3>
|
---|
13 | <p>
|
---|
14 | Generates checksum for files. This task can also be used to
|
---|
15 | perform checksum verifications.
|
---|
16 | </p>
|
---|
17 |
|
---|
18 | <p>Note that many popular message digest functions - including MD5 and
|
---|
19 | SHA-1 - have been broken recently. If you are going to use the task
|
---|
20 | to create checksums used in an environment where security is
|
---|
21 | important, please take some time to investigate the algorithms offered
|
---|
22 | by your JCE provider. Note also that some JCE providers like the one
|
---|
23 | by <a href="http://www.bouncycastle.org/">The Legion of the Bouncy
|
---|
24 | Castle</a>, the <a href="http://www.gnu.org/software/gnu-crypto/">GNU
|
---|
25 | project</a> or <a
|
---|
26 | href="http://jce.iaik.tugraz.at/products/01_jce/index.php">the
|
---|
27 | Technical University Graz</a> offer more digest algorithms than those
|
---|
28 | built-in into your JDK.</p>
|
---|
29 |
|
---|
30 | <h3>Parameters</h3>
|
---|
31 | <table border="1" cellpadding="2" cellspacing="0">
|
---|
32 | <tr>
|
---|
33 | <td valign="top"><b>Attribute</b></td>
|
---|
34 | <td valign="top"><b>Description</b></td>
|
---|
35 | <td align="center" valign="top"><b>Required</b></td>
|
---|
36 | </tr>
|
---|
37 | <tr>
|
---|
38 | <td valign="top">file</td>
|
---|
39 | <td valign="top">The file to generate checksum for.</td>
|
---|
40 | <td valign="top" align="center">One of either <var>file</var> or
|
---|
41 | at least one nested fileset element.</td>
|
---|
42 | </tr>
|
---|
43 | <tr>
|
---|
44 | <td valign="top">todir</td>
|
---|
45 | <td valign="top">The root directory where checksums should be written.</td>
|
---|
46 | <td valign="top" align="center">No. If not specified, checksum files
|
---|
47 | will be written to the same directory as the files themselves.
|
---|
48 | <em>since Ant 1.6</em>
|
---|
49 | </td>
|
---|
50 | </tr>
|
---|
51 | <tr>
|
---|
52 | <td valign="top">algorithm</td>
|
---|
53 | <td valign="top">Specifies the algorithm to be used to
|
---|
54 | compute the checksum. Defaults to "MD5".
|
---|
55 | Other popular algorithms like "SHA" may be used
|
---|
56 | as well.
|
---|
57 | </td>
|
---|
58 | <td valign="top" align="center">No</td>
|
---|
59 | </tr>
|
---|
60 | <tr>
|
---|
61 | <td valign="top">provider</td>
|
---|
62 | <td valign="top">Specifies the provider of the algorithm.</td>
|
---|
63 | <td valign="top" align="center">No</td>
|
---|
64 | </tr>
|
---|
65 | <tr>
|
---|
66 | <td valign="top">fileext</td>
|
---|
67 | <td valign="top">The generated checksum file's name will be the
|
---|
68 | original filename with the fileext added to it.
|
---|
69 | Defaults to a "." and the algorithm name being used.
|
---|
70 | </td>
|
---|
71 | <td valign="top" align="center">No</td>
|
---|
72 | </tr>
|
---|
73 | <tr>
|
---|
74 | <td valign="top">property</td>
|
---|
75 | <td valign="top">This attribute can mean two different things, it
|
---|
76 | depends on the presence of the verifyproperty attribute.<br/>
|
---|
77 | <b>If you don't set the verifyproperty attribute</b>, property
|
---|
78 | specifies the name of the property to be set with the generated
|
---|
79 | checksum value.<br/>
|
---|
80 | <b>If you set the verifyproperty attribute</b>, property specifies
|
---|
81 | the checksum you expect to be generated (the checksum itself, not
|
---|
82 | a name of a property containing the checksum).<br/>
|
---|
83 | This cannot be specified when fileext is being used or when the
|
---|
84 | number of files for which checksums is to be generated is greater
|
---|
85 | than 1.
|
---|
86 | </td>
|
---|
87 | <td valign="top" align="center">No</td>
|
---|
88 | </tr>
|
---|
89 | <tr>
|
---|
90 | <td valign="top">totalproperty</td>
|
---|
91 | <td valign="top">If specified, this attribute specifies the name of
|
---|
92 | the property that will hold a checksum of all the checksums and
|
---|
93 | file paths. The individual checksums and the relative paths to
|
---|
94 | the files within the filesets they are defined in will be used to
|
---|
95 | compute this checksum. (The file separators in the paths will be
|
---|
96 | converted to '/' before computation to ensure platform portability).
|
---|
97 | <em>since Ant 1.6</em>
|
---|
98 | </td>
|
---|
99 | <td valign="top" align="center">No</td>
|
---|
100 | </tr>
|
---|
101 | <tr>
|
---|
102 | <td valign="top">forceoverwrite</td>
|
---|
103 | <td valign="top">Overwrite existing files even if the destination
|
---|
104 | files are newer. Defaults to "no".</td>
|
---|
105 | <td valign="top" align="center">No</td>
|
---|
106 | </tr>
|
---|
107 | <tr>
|
---|
108 | <td valign="top">verifyproperty</td>
|
---|
109 | <td valign="top">Specifies the name of the property to be set
|
---|
110 | with "true" or "false" depending upon whether
|
---|
111 | the generated checksum matches the existing checksum. When
|
---|
112 | this is set, the generated checksum is not written to a file or
|
---|
113 | property, but rather, the content of the file or property is used to
|
---|
114 | check against the generated checksum.
|
---|
115 | <td valign="top" align="center">No</td>
|
---|
116 | </tr>
|
---|
117 | <tr>
|
---|
118 | <td valign="top">readbuffersize</td>
|
---|
119 | <td valign="top">The size of the buffer (in bytes) to use when
|
---|
120 | reading a file. Defaults to "8192" - you may get a
|
---|
121 | better performance on big files if you increase this value.</td>
|
---|
122 | <td valign="top" align="center">No</td>
|
---|
123 | </tr>
|
---|
124 | </table>
|
---|
125 | <h3>Parameters specified as nested elements</h3>
|
---|
126 |
|
---|
127 | <h4>fileset</h4>
|
---|
128 | <p>
|
---|
129 | <a href="../CoreTypes/fileset.html">FileSets</a> are used to select files to
|
---|
130 | generate checksums for.
|
---|
131 | </p>
|
---|
132 |
|
---|
133 | <h3>Examples</h3>
|
---|
134 | <p><b>Example 1</b></p>
|
---|
135 | <blockquote><pre><checksum file="foo.bar"/></pre></blockquote>
|
---|
136 | Generates a MD5 checksum for foo.bar and stores the checksum in the destination file
|
---|
137 | foo.bar.MD5. foo.bar.MD5 is overwritten only if foo.bar is newer than itself.
|
---|
138 |
|
---|
139 | <p><b>Example 2</b></p>
|
---|
140 | <blockquote><pre><checksum file="foo.bar" forceOverwrite="yes"/></pre></blockquote>
|
---|
141 | Generates a MD5 checksum for foo.bar and stores the checksum in foo.bar.MD5.
|
---|
142 | If foo.bar.MD5 already exists, it is overwritten.
|
---|
143 |
|
---|
144 | <p><b>Example 3</b></p>
|
---|
145 | <blockquote><pre><checksum file="foo.bar" property="foobarMD5"/></pre></blockquote>
|
---|
146 | Generates a MD5 checksum for foo.bar and stores it in the Project Property foobarMD5.
|
---|
147 |
|
---|
148 | <p><b>Example 4</b></p>
|
---|
149 | <blockquote><pre><checksum file="foo.bar" verifyProperty="isMD5ok"/></pre></blockquote>
|
---|
150 | Generates a MD5 checksum for foo.bar, compares it against foo.bar.MD5 and sets
|
---|
151 | isMD5ok to either true or false, depending upon the result.
|
---|
152 |
|
---|
153 | <p><b>Example 5</b></p>
|
---|
154 | <blockquote><pre><checksum file="foo.bar" algorithm="SHA" fileext="asc"/></pre></blockquote>
|
---|
155 | Generates a SHA checksum for foo.bar and stores the checksum in the destination file
|
---|
156 | foo.bar.asc. foo.bar.asc is overwritten only if foo.bar is newer than itself.
|
---|
157 |
|
---|
158 | <p><b>Example 6</b></p>
|
---|
159 | <blockquote><pre>
|
---|
160 | <checksum file="foo.bar" property="${md5}" verifyProperty="isEqual"/>
|
---|
161 | </pre></blockquote>
|
---|
162 | Generates a MD5 checksum for foo.bar, compares it against the value of the property
|
---|
163 | md5, and sets isEqual to either true or false, depending upon the result.
|
---|
164 |
|
---|
165 | <p><b>Example 7</b></p>
|
---|
166 | <blockquote><pre>
|
---|
167 | <checksum>
|
---|
168 | <fileset dir=".">
|
---|
169 | <include name="foo*"/>
|
---|
170 | </fileset>
|
---|
171 | </checksum>
|
---|
172 | </pre></blockquote>
|
---|
173 | Works just like Example 1, but generates a .MD5 file for every file that begins with the name foo.
|
---|
174 |
|
---|
175 | <p><b>Example 8</b></p>
|
---|
176 | <blockquote><pre>
|
---|
177 | <condition property="isChecksumEqual">
|
---|
178 | <checksum>
|
---|
179 | <fileset dir=".">
|
---|
180 | <include name="foo.bar"/>
|
---|
181 | </fileset>
|
---|
182 | </checksum>
|
---|
183 | </condition>
|
---|
184 | </pre></blockquote>
|
---|
185 | Works like Example 4, but only sets isChecksumEqual to true, if the
|
---|
186 | checksum matches - it will never be set to false. This example
|
---|
187 | demonstrates use with the Condition task.
|
---|
188 |
|
---|
189 |
|
---|
190 | <h3>Note:</h3>
|
---|
191 | When working with more than one file, if condition and/or verifyproperty is used,
|
---|
192 | the result will be true only if the checksums matched correctly for all files being
|
---|
193 | considered.
|
---|
194 |
|
---|
195 | <hr><p align="center">Copyright © 2001-2005 The Apache Software Foundation. All rights
|
---|
196 | Reserved.</p>
|
---|
197 |
|
---|
198 | </body>
|
---|
199 | </html>
|
---|
200 |
|
---|