You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

checksum.html 9.9 KiB

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