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.

touch.html 6.4 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <!DOCTYPE html>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one or more
  4. contributor license agreements. See the NOTICE file distributed with
  5. this work for additional information regarding copyright ownership.
  6. The ASF licenses this file to You under the Apache License, Version 2.0
  7. (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. https://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. -->
  16. <html lang="en">
  17. <head>
  18. <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  19. <title>Touch Task</title>
  20. </head>
  21. <body>
  22. <h2 id="touch">Touch</h2>
  23. <h3>Description</h3>
  24. <p>Changes the modification time of a resource and possibly creates it at the same time. In addition
  25. to working with a single file, this Task can also work
  26. on <a href="../Types/resources.html">resources</a> and resource collections (which also includes
  27. directories). Prior to Apache Ant 1.7 only FileSet or <a href="../Types/filelist.html">Filelist</a>
  28. (<em>since Ant 1.6</em>) were supported.</p>
  29. <p>Ant uses the API of <code class="code">java.io.File</code> to set the last modification time
  30. which has some limitations. For example, the timestamp granularity depends on the operating system
  31. and sometimes the operating system may allow a granularity smaller than milliseconds. If you need
  32. more control you have to fall back to the <code>&lt;exec&gt;</code> task and native commands.</p>
  33. <p><em>Since Ant 1.8.2</em>, a warning message is logged upon failure to change the file
  34. modification time. This will happen if you try to change the modification time of a file you do not
  35. own on many Unix systems, for example.</p>
  36. <h3>Parameters</h3>
  37. <table class="attr">
  38. <tr>
  39. <th scope="col">Attribute</th>
  40. <th scope="col">Description</th>
  41. <th scope="col">Required</th>
  42. </tr>
  43. <tr>
  44. <td>file</td>
  45. <td>The name of the file.</td>
  46. <td>Unless a nested resource collection element has been specified</td>
  47. </tr>
  48. <tr>
  49. <td>millis</td>
  50. <td>Specifies the new modification time of the file in milliseconds since midnight Jan 1
  51. 1970.</td>
  52. <td rowspan="2">No; <var>datetime</var> takes precedence, however if both are omitted then
  53. current time is assumed</td>
  54. </tr>
  55. <tr>
  56. <td>datetime</td>
  57. <td class="left">Specifies the new modification time of the file. <em>Since Ant 1.8</em>, the
  58. special value <q>now</q> indicates the current time.</td>
  59. </tr>
  60. <tr>
  61. <td>pattern</td>
  62. <td>SimpleDateFormat-compatible pattern string using the current locale. <em>Since Ant
  63. 1.6.3</em></td>
  64. <td>No; defaults to <q>MM/dd/YYYY hh:mm a</q> or <q>MM/dd/yyyy hh:mm:ss a</q> using the US
  65. locale.</td>
  66. </tr>
  67. <tr>
  68. <td>mkdirs</td>
  69. <td>Whether to create nonexistent parent directories when touching new files. <em>Since Ant
  70. 1.6.3</em></td>
  71. <td>No; default <q>false</q></td>
  72. </tr>
  73. <tr>
  74. <td>verbose</td>
  75. <td>Whether to log the creation of new files. <em>Since Ant 1.6.3</em></td>
  76. <td>No; default <q>true</q></td>
  77. </tr>
  78. </table>
  79. <h3>Parameters specified as nested elements</h3>
  80. <h4>any resource collection</h4>
  81. <p>You can use any number of nested resource collection elements to define the resources for this
  82. task and refer to resources defined elsewhere. <strong>Note</strong>: resources passed to this task
  83. must implement the <code class="code">org.apache.tools.ant.types.resources.Touchable</code>
  84. interface, this is true for all filesystem-based resources like those returned by path, fileset ot
  85. filelist.</p>
  86. <p>For backwards compatibility directories matched by nested filesets will be "touched" as well, use
  87. a <var>type</var> selector to suppress this. This only applies to filesets nested into the task
  88. directly, not to filesets nested into a path or any other resource collection.</p>
  89. <h4>mapper</h4>
  90. <p><em>Since Ant 1.6.3</em>, a nested <a href="../Types/mapper.html">mapper</a> can be specified.
  91. Files specified via nested <code>fileset</code>s, <code>filelist</code>s, or the <code>file</code>
  92. attribute are mapped using the specified mapper. For each file mapped, the resulting files are
  93. touched. If no time has been specified and the original file exists its timestamp will be used. If
  94. no time has been specified and the original file does not exist the current time is used. <em>Since
  95. Ant 1.8</em>, the task settings (<var>millis</var> and <var>datetime</var>) have priority over the
  96. timestamp of the original file.</p>
  97. <h3>Examples</h3>
  98. <p>Create <samp>myfile</samp> if it doesn't exist and change the modification time to the current
  99. time.</p>
  100. <pre>&lt;touch file=&quot;myfile&quot;/&gt;</pre>
  101. <p>Create <samp>myfile</samp> if it doesn't exist and change the modification time to Jun, 28 2000
  102. 2:02 pm (14:02 for those used to 24 hour time).</p>
  103. <pre>&lt;touch file=&quot;myfile&quot; datetime=&quot;06/28/2000 2:02 pm&quot;/&gt;</pre>
  104. <p>Change the modification time to Oct, 09 1974 4:30 pm of all files and directories found
  105. in <samp>src_dir</samp>.</p>
  106. <pre>
  107. &lt;touch datetime=&quot;09/10/1974 4:30 pm&quot;&gt;
  108. &lt;fileset dir=&quot;src_dir&quot;/&gt;
  109. &lt;/touch&gt;</pre>
  110. <p>Create <samp>myfile</samp> if it doesn't exist and change the modification time to Jun, 28 2000
  111. 2:02:17 pm (14:02:17 for those used to 24 hour time), if the filesystem allows a precision of one
  112. second&mdash;a time close to it otherwise.</p>
  113. <pre>&lt;touch file=&quot;myfile&quot; datetime=&quot;06/28/2000 2:02:17 pm&quot;/&gt;</pre>
  114. <p>Create <samp>bar</samp> if it doesn't exist and change the modification time to that
  115. of <samp>foo</samp>.</p>
  116. <pre>
  117. &lt;touch file=&quot;foo&quot;&gt;
  118. &lt;mapper type=&quot;glob&quot; from=&quot;foo&quot; to=&quot;bar&quot;/&gt;
  119. &lt;/touch&gt;</pre>
  120. <p>Create files in the <samp>shadow</samp> directory for every <samp>.java</samp> file in
  121. the <samp>src</samp> directory if it doesn't exist and change the modification time of those files
  122. to the current time.</p>
  123. <pre>
  124. &lt;touch file=&quot;foo&quot; datetime=&quot;now&quot;&gt;
  125. &lt;mapper type=&quot;regexp&quot; from=&quot;^src(.*)\.java&quot; to=&quot;shadow\1.empty&quot;/&gt;
  126. &lt;/touch&gt;</pre>
  127. </body>
  128. </html>