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

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