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 8.4 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. <h3>Parameters</h3>
  26. <table border="1" cellpadding="2" cellspacing="0">
  27. <tr>
  28. <td valign="top"><b>Attribute</b></td>
  29. <td valign="top"><b>Description</b></td>
  30. <td align="center" valign="top"><b>Required</b></td>
  31. </tr>
  32. <tr>
  33. <td valign="top">file</td>
  34. <td valign="top">The file to generate checksum for.</td>
  35. <td valign="top" align="center">One of either <var>file</var> or
  36. at least one nested fileset element.</td>
  37. </tr>
  38. <tr>
  39. <td valign="top">todir</td>
  40. <td valign="top">The root directory where checksums should be written.</td>
  41. <td valign="top" align="center">No. If not specified, checksum files
  42. will be written to the same directory as the files themselves.
  43. <em>since Ant 1.6</em>
  44. </td>
  45. </tr>
  46. <tr>
  47. <td valign="top">algorithm</td>
  48. <td valign="top">Specifies the algorithm to be used to
  49. compute the checksum. Defaults to &quot;MD5&quot;.
  50. Other popular algorithms like &quot;SHA&quot; may be used
  51. as well.
  52. </td>
  53. <td valign="top" align="center">No</td>
  54. </tr>
  55. <tr>
  56. <td valign="top">provider</td>
  57. <td valign="top">Specifies the provider of the algorithm.</td>
  58. <td valign="top" align="center">No</td>
  59. </tr>
  60. <tr>
  61. <td valign="top">fileext</td>
  62. <td valign="top">The generated checksum file's name will be the
  63. original filename with the fileext added to it.
  64. Defaults to a "." and the algorithm name being used.
  65. </td>
  66. <td valign="top" align="center">No</td>
  67. </tr>
  68. <tr>
  69. <td valign="top">property</td>
  70. <td valign="top">This attribute can mean two different things, it
  71. depends on the presence of the verifyproperty attribute.<br/>
  72. <b>If you don't set the verifyproperty attribute</b>, property
  73. specifies the name of the property to be set with the generated
  74. checksum value.<br/>
  75. <b>If you set the verifyproperty attribute</b>, property specifies
  76. the checksum you expect to be generated (the checksum itself, not
  77. a name of a property containing the checksum).<br/>
  78. This cannot be specified when fileext is being used or when the
  79. number of files for which checksums is to be generated is greater
  80. than 1.
  81. </td>
  82. <td valign="top" align="center">No</td>
  83. </tr>
  84. <tr>
  85. <td valign="top">pattern</td>
  86. <td valign="top">Specifies the pattern to use as a pattern
  87. suitable for <a
  88. href="http://java.sun.com/j2se/1.4.2/docs/api/java/text/MessageFormat.html">MessageFormat</a>
  89. where <code>{0}</code> is replaced with the checksum and
  90. <code>{1}</code> with the file name.</td>
  91. <td valign="top" align="center">No - default is &quot;{0}&quot;.</td>
  92. </tr>
  93. <tr>
  94. <td valign="top">format</td>
  95. <td valign="top">Specifies the pattern to use as one of a
  96. well-known format. Supported values are &quot;CHECKSUM&quot;
  97. (only the checksum itself, the default), &quot;MD5SUM&quot; the
  98. format of GNU textutils md5sum and &quot;SVF&quot; the format of
  99. *BSDs md5 command.</td>
  100. <td valign="top" align="center">No - default is &quot;CHECKSUM&quot;.</td>
  101. </tr>
  102. <tr>
  103. <td valign="top">totalproperty</td>
  104. <td valign="top">If specified, this attribute specifies the name of
  105. the property that will hold a checksum of all the checksums and
  106. file paths. The individual checksums and the relative paths to
  107. the files within the filesets they are defined in will be used to
  108. compute this checksum. (The file separators in the paths will be
  109. converted to '/' before computation to ensure platform portability).
  110. <em>since Ant 1.6</em>
  111. </td>
  112. <td valign="top" align="center">No</td>
  113. </tr>
  114. <tr>
  115. <td valign="top">forceoverwrite</td>
  116. <td valign="top">Overwrite existing files even if the destination
  117. files are newer. Defaults to &quot;no&quot;.</td>
  118. <td valign="top" align="center">No</td>
  119. </tr>
  120. <tr>
  121. <td valign="top">verifyproperty</td>
  122. <td valign="top">Specifies the name of the property to be set
  123. with &quot;true&quot; or &quot;false&quot; depending upon whether
  124. the generated checksum matches the existing checksum. When
  125. this is set, the generated checksum is not written to a file or
  126. property, but rather, the content of the file or property is used to
  127. check against the generated checksum.
  128. <td valign="top" align="center">No</td>
  129. </tr>
  130. <tr>
  131. <td valign="top">readbuffersize</td>
  132. <td valign="top">The size of the buffer (in bytes) to use when
  133. reading a file. Defaults to &quot;8192&quot; - you may get a
  134. better performance on big files if you increase this value.</td>
  135. <td valign="top" align="center">No</td>
  136. </tr>
  137. </table>
  138. <h3>Parameters specified as nested elements</h3>
  139. <h4>fileset</h4>
  140. <p>
  141. <a href="../CoreTypes/fileset.html">FileSets</a> are used to select files to
  142. generate checksums for.
  143. </p>
  144. <h3>Examples</h3>
  145. <p><b>Example 1</b></p>
  146. <blockquote><pre>&lt;checksum file=&quot;foo.bar&quot;/&gt;</pre></blockquote>
  147. Generates a MD5 checksum for foo.bar and stores the checksum in the destination file
  148. foo.bar.MD5. foo.bar.MD5 is overwritten only if foo.bar is newer than itself.
  149. <p><b>Example 2</b></p>
  150. <blockquote><pre>&lt;checksum file=&quot;foo.bar&quot; forceOverwrite=&quot;yes&quot;/&gt;</pre></blockquote>
  151. Generates a MD5 checksum for foo.bar and stores the checksum in foo.bar.MD5.
  152. If foo.bar.MD5 already exists, it is overwritten.
  153. <p><b>Example 3</b></p>
  154. <blockquote><pre>&lt;checksum file=&quot;foo.bar&quot; property=&quot;foobarMD5&quot;/&gt;</pre></blockquote>
  155. Generates a MD5 checksum for foo.bar and stores it in the Project Property foobarMD5.
  156. <p><b>Example 4</b></p>
  157. <blockquote><pre>&lt;checksum file=&quot;foo.bar&quot; verifyProperty=&quot;isMD5ok&quot;/&gt;</pre></blockquote>
  158. Generates a MD5 checksum for foo.bar, compares it against foo.bar.MD5 and sets
  159. isMD5ok to either true or false, depending upon the result.
  160. <p><b>Example 5</b></p>
  161. <blockquote><pre>&lt;checksum file=&quot;foo.bar&quot; algorithm=&quot;SHA&quot; fileext=&quot;asc&quot;/&gt;</pre></blockquote>
  162. Generates a SHA checksum for foo.bar and stores the checksum in the destination file
  163. foo.bar.asc. foo.bar.asc is overwritten only if foo.bar is newer than itself.
  164. <p><b>Example 6</b></p>
  165. <blockquote><pre>
  166. &lt;checksum file=&quot;foo.bar&quot; property=&quot;${md5}&quot; verifyProperty=&quot;isEqual&quot;/&gt;
  167. </pre></blockquote>
  168. Generates a MD5 checksum for foo.bar, compares it against the value of the property
  169. md5, and sets isEqual to either true or false, depending upon the result.
  170. <p><b>Example 7</b></p>
  171. <blockquote><pre>
  172. &lt;checksum&gt;
  173. &lt;fileset dir=&quot;.&quot;&gt;
  174. &lt;include name=&quot;foo*&quot;/&gt;
  175. &lt;/fileset&gt;
  176. &lt;/checksum&gt;
  177. </pre></blockquote>
  178. Works just like Example 1, but generates a .MD5 file for every file that begins with the name foo.
  179. <p><b>Example 8</b></p>
  180. <blockquote><pre>
  181. &lt;condition property=&quot;isChecksumEqual&quot;&gt;
  182. &lt;checksum&gt;
  183. &lt;fileset dir=&quot;.&quot;&gt;
  184. &lt;include name=&quot;foo.bar&quot;/&gt;
  185. &lt;/fileset&gt;
  186. &lt;/checksum&gt;
  187. &lt;/condition&gt;
  188. </pre></blockquote>
  189. Works like Example 4, but only sets isChecksumEqual to true, if the
  190. checksum matches - it will never be set to false. This example
  191. demonstrates use with the Condition task.
  192. <h3>Note:</h3>
  193. When working with more than one file, if condition and/or verifyproperty is used,
  194. the result will be true only if the checksums matched correctly for all files being
  195. considered.
  196. <hr><p align="center">Copyright &copy; 2001-2005 The Apache Software Foundation. All rights
  197. Reserved.</p>
  198. </body>
  199. </html>