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

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