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.0 kB

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