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.

uptodate.html 7.0 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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>Uptodate Task</title>
  20. </head>
  21. <body>
  22. <h2><a name="uptodate">Uptodate</a></h2>
  23. <h3>Description</h3>
  24. <p>Sets a property if a target file or set of target files is more up-to-date
  25. than a source file or set of source files. A single source file is specified
  26. using the <code>srcfile</code> attribute. A set of source files is specified
  27. using the nested <code>&lt;srcfiles&gt;</code>
  28. elements. These are <a href="../CoreTypes/fileset.html">FileSet</a>s,
  29. whereas multiple target files are specified using a nested
  30. <a href="../CoreTypes/mapper.html"><code>&lt;mapper&gt;</code></a> element.</p>
  31. <p>By default, the value of the property is set to <code>true</code> if
  32. the timestamp of the source file(s) is not more recent than the timestamp of
  33. the corresponding target file(s). You can set the value to something other
  34. than the default by specifying the <code>value</code> attribute.</p>
  35. <p>If a <code>&lt;srcfiles&gt;</code> element is used, without also specifying
  36. a <code>&lt;mapper&gt;</code> element, the default behavior is to use a
  37. <a href="../CoreTypes/mapper.html#merge-mapper">merge mapper</a>, with the
  38. <code>to</code> attribute set to the value of the
  39. <code>targetfile</code> attribute.</p>
  40. <p>Normally, this task is used to set properties that are useful to avoid
  41. target execution depending on the relative age of the specified files.</p>
  42. <h3>Parameters</h3>
  43. <table border="1" cellpadding="2" cellspacing="0">
  44. <tr>
  45. <td valign="top"><b>Attribute</b></td>
  46. <td valign="top"><b>Description</b></td>
  47. <td align="center" valign="top"><b>Required</b></td>
  48. </tr>
  49. <tr>
  50. <td valign="top">property</td>
  51. <td valign="top">The name of the property to set.</td>
  52. <td valign="top" align="center">Yes</td>
  53. </tr>
  54. <tr>
  55. <td valign="top">value</td>
  56. <td valign="top">The value to set the property to.</td>
  57. <td valign="top" align="center">No; defaults to <code>true</code>.</td>
  58. </tr>
  59. <tr>
  60. <td valign="top">srcfile</td>
  61. <td valign="top">The file to check against the target file(s).</td>
  62. <td valign="top" align="center">Yes, unless a nested
  63. <code>&lt;srcfiles&gt;</code> or <code>&lt;srcresources&gt;</code>
  64. element is present.</td>
  65. </tr>
  66. <tr>
  67. <td valign="top">targetfile</td>
  68. <td valign="top">The file for which we want to determine the status.</td>
  69. <td valign="top" align="center">Yes, unless a nested
  70. <code>&lt;mapper&gt;</code> element is present.</td>
  71. </tr>
  72. </table>
  73. <h3>Parameters specified as nested elements</h3>
  74. <h4><a name="srcfiles">srcfiles</a></h4>
  75. <p>The nested <code>&lt;srcfiles&gt;</code> element allows you to specify a
  76. set of files to check against the target file(s).</p>
  77. <p><strong>Note:</strong> You can specify either the <code>srcfile</code>
  78. attribute or nested <code>&lt;srcfiles&gt;</code> elements, but not both.
  79. <h4><a name="srcresources">srcresources</a></h4>
  80. <p>The nested <code>&lt;srcresources&gt;</code> element is a <a
  81. href="../CoreTypes/resources.html#union">union</a> and allows you to
  82. specify a collection of resources to check against the target file(s).
  83. <em>Since Ant 1.7</em></p>
  84. <h4><a name="mapper">mapper</a></h4>
  85. <p>The nested <code>&lt;mapper&gt;</code> element allows you to specify
  86. a set of target files to check for being up-to-date with respect to a
  87. set of source files.</p>
  88. <p>
  89. The mapper "to" attribute is relative to the target file, or to
  90. the "dir" attribute of the nested srcfiles element.
  91. </p>
  92. <p>
  93. <em>Since Ant 1.6.3</em>,
  94. one can use a filenamemapper type in place of the mapper element.
  95. </p>
  96. <h3>Examples</h3>
  97. <pre> &lt;uptodate property=&quot;xmlBuild.notRequired&quot; targetfile=&quot;${deploy}\xmlClasses.jar&quot; &gt;
  98. &lt;srcfiles dir= &quot;${src}/xml&quot; includes=&quot;**/*.dtd&quot;/&gt;
  99. &lt;/uptodate&gt;</pre>
  100. <p>sets the property <code>xmlBuild.notRequired</code> to <code>true</code>
  101. if the <code>${deploy}/xmlClasses.jar</code> file is more up-to-date than
  102. any of the DTD files in the <code>${src}/xml</code> directory.</p>
  103. <p>This can be written as:</p>
  104. <pre> &lt;uptodate property=&quot;xmlBuild.notRequired&quot;&gt;
  105. &lt;srcfiles dir= &quot;${src}/xml&quot; includes=&quot;**/*.dtd&quot;/&gt;
  106. &lt;mapper type=&quot;merge&quot; to=&quot;${deploy}\xmlClasses.jar&quot;/&gt;
  107. &lt;/uptodate&gt;</pre>
  108. as well.
  109. The <code>xmlBuild.notRequired</code> property can then be used in a
  110. <code>&lt;target&gt;</code> tag's <code>unless</code> attribute to
  111. conditionally run that target. For example, running the following target:</p>
  112. <pre>
  113. &lt;target name=&quot;xmlBuild&quot; depends=&quot;chkXmlBuild&quot; unless=&quot;xmlBuild.notRequired&quot;&gt;
  114. ...
  115. &lt;/target&gt;
  116. </pre>
  117. will first run the <code>chkXmlBuild</code> target, which contains
  118. the <code>&lt;uptodate&gt;</code> task that determines whether
  119. <code>xmlBuild.notRequired</code> gets set. The property named in
  120. the <code>unless</code> attribute is then checked for being set/not set.
  121. If it did get set (ie., the jar file is up-to-date),
  122. then the <code>xmlBuild</code> target won't be run.
  123. </p>
  124. <p> The following example shows a single source file being checked
  125. against a single target file:</p>
  126. <pre> &lt;uptodate property=&quot;isUpToDate&quot;
  127. srcfile=&quot;/usr/local/bin/testit&quot;
  128. targetfile=&quot;${build}/.flagfile&quot;/&gt;
  129. </pre>
  130. <p>sets the property <code>isUpToDate</code> to <code>true</code>
  131. if <code>/usr/local/bin/testit</code> is not newer than
  132. <code>${build}/.flagfile</code>.</p>
  133. </p>
  134. <p>
  135. The following shows usage of a relative mapper.
  136. </p>
  137. <pre>
  138. &lt;uptodate property="checkUptodate.uptodate"&gt;
  139. &lt;srcfiles dir="src" includes="*"/&gt;
  140. &lt;mapper type="merge" to="../dest/output.done"/&gt;
  141. &lt;/uptodate&gt;
  142. &lt;echo message="checkUptodate result: ${checkUptodate.uptodate}"/&gt;
  143. </pre>
  144. <p>
  145. The previous example can be a bit confusing, so it may be better to
  146. use absolute paths:
  147. </p>
  148. <pre>
  149. &lt;property name="dest.dir" location="dest"/&gt;
  150. &lt;uptodate property="checkUptodate.uptodate"&gt;
  151. &lt;srcfiles dir="src" includes="*"/&gt;
  152. &lt;mapper type="merge" to="${dest.dir}/output.done"/&gt;
  153. &lt;/uptodate&gt;
  154. </pre>
  155. </body>
  156. </html>