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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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>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>java.io.File</code> to set the last modification time which has some
  30. limitations. For example, the timestamp granularity depends on the operating system and sometimes
  31. the operating system may allow a granularity smaller than milliseconds. If you need more control
  32. 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>Attribute</th>
  40. <th>Description</th>
  41. <th>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>org.apache.tools.ant.types.resources.Touchable</code> interface, this is
  84. true for all filesystem-based resources like those returned by path, fileset ot filelist.</p>
  85. <p>For backwards compatibility directories matched by nested filesets will be "touched" as well, use
  86. a <var>type</var> selector to suppress this. This only applies to filesets nested into the task
  87. directly, not to filesets nested into a path or any other resource collection.</p>
  88. <h4>mapper</h4>
  89. <p><em>Since Ant 1.6.3</em>, a nested <a href="../Types/mapper.html"> mapper</a> can be specified.
  90. Files specified via nested <code>fileset</code>s, <code>filelist</code>s, or the <code>file</code>
  91. attribute are mapped using the specified mapper. For each file mapped, the resulting files are
  92. touched. If no time has been specified and the original file exists its timestamp will be used. If
  93. no time has been specified and the original file does not exist the current time is used. <em>Since
  94. Ant 1.8</em>, the task settings (<var>millis</var>, and <var>datetime</var>) have priority over the
  95. timestamp of the original file.</p>
  96. <h3>Examples</h3>
  97. <pre>&lt;touch file=&quot;myfile&quot;/&gt;</pre>
  98. <p>creates <samp>myfile</samp> if it doesn't exist and changes the modification time to the current
  99. time.</p>
  100. <pre>&lt;touch file=&quot;myfile&quot; datetime=&quot;06/28/2000 2:02 pm&quot;/&gt;</pre>
  101. <p>creates <samp>myfile</samp> if it doesn't exist and changes the modification time to Jun, 28 2000
  102. 2:02 pm (14:02 for those used to 24 hour time).</p>
  103. <pre>
  104. &lt;touch datetime=&quot;09/10/1974 4:30 pm&quot;&gt;
  105. &lt;fileset dir=&quot;src_dir&quot;/&gt;
  106. &lt;/touch&gt;</pre>
  107. <p>changes the modification time to Oct, 09 1974 4:30 pm of all files and directories found
  108. in <samp>src_dir</samp>.</p>
  109. <pre>&lt;touch file=&quot;myfile&quot; datetime=&quot;06/28/2000 2:02:17 pm&quot;/&gt;</pre>
  110. <p>creates <samp>myfile</samp> if it doesn't exist and changes 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>
  114. &lt;touch file=&quot;foo&quot;&gt;
  115. &lt;mapper type=&quot;glob&quot; from=&quot;foo&quot; to=&quot;bar&quot;/&gt;
  116. &lt;/touch&gt;</pre>
  117. <p>creates <samp>bar</samp> if it doesn't exist and changes the modification time to that
  118. of <samp>foo</samp>.</p>
  119. <pre>
  120. &lt;touch file=&quot;foo&quot; datetime=&quot;now&quot;&gt;
  121. &lt;mapper type=&quot;regexp&quot; from=&quot;^src(.*)\.java&quot; to=&quot;shadow\1.empty&quot;/&gt;
  122. &lt;/touch&gt;</pre>
  123. <p>creates files in the <samp>shadow</samp> directory for every <samp>.java</samp> file in
  124. the <samp>src</samp> directory if it doesn't exist and changes the modification time of those files
  125. to the current time.</p>
  126. </body>
  127. </html>