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.8 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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><a name="touch">Touch</a></h2>
  23. <h3>Description</h3>
  24. <p>Changes the modification time of a resource and possibly creates it
  25. at the same time. In addition to working with a single file, this Task
  26. can also work on <a href="../Types/resources.html">resources</a> and
  27. resource collections (which also includes directories). Prior to Apache Ant
  28. 1.7 only FileSet or <a href="../Types/filelist.html">Filelist</a>
  29. (since Ant 1.6) have been supported.</p>
  30. <p>Ant uses the API of <code>java.io.File</code> to set the last
  31. modification time which has some limitations. For example the
  32. timestamp granularity depends on the operating system and sometimes
  33. the operating system may allow a granularity smaller than
  34. milliseconds. If you need more control you have to fall back to
  35. the <code>&lt;exec&gt;</code> task and native commands.</p>
  36. <p>Starting with Ant 1.8.2 Ant will log a warning message if it fails
  37. to change the file modification time. This will happen if you try
  38. to change the modification time of a file you do not own on many
  39. Unix systems, for example.</p>
  40. <h3>Parameters</h3>
  41. <table border="1" cellpadding="2" cellspacing="0">
  42. <tr>
  43. <td valign="top"><b>Attribute</b></td>
  44. <td valign="top"><b>Description</b></td>
  45. <td align="center" valign="top"><b>Required</b></td>
  46. </tr>
  47. <tr>
  48. <td valign="top">file</td>
  49. <td valign="top">The name of the file.</td>
  50. <td valign="top" align="center">Unless a nested resource collection element
  51. has been specified.</td>
  52. </tr>
  53. <tr>
  54. <td valign="top">millis</td>
  55. <td valign="top">Specifies the new modification time of the file
  56. in milliseconds since midnight Jan 1 1970.</td>
  57. <td valign="center" align="center" rowspan="2">No--datetime takes
  58. precedence, however if both are omitted the current time is assumed.</td>
  59. </tr>
  60. <tr>
  61. <td valign="top">datetime</td>
  62. <td valign="top">Specifies the new modification time of the file. The
  63. special value &quot;now&quot; indicates the current time
  64. (now supported since Ant 1.8).</td>
  65. </tr>
  66. <tr>
  67. <td valign="top">pattern</td>
  68. <td valign="top">SimpleDateFormat-compatible pattern string using
  69. the current locale.
  70. Defaults to "MM/dd/YYYY hh:mm a" or "MM/dd/yyyy hh:mm:ss a"
  71. using the US locale.
  72. <b>Since Ant 1.6.3</b></td>
  73. <td valign="top" align="center">No</td>
  74. </tr>
  75. <tr>
  76. <td valign="top">mkdirs</td>
  77. <td valign="top">Whether to create nonexistent parent
  78. directories when touching new files. <b>Since Ant 1.6.3</b></td>
  79. <td valign="top" align="center">No, default <i>false</i>.</td>
  80. </tr>
  81. <tr>
  82. <td valign="top">verbose</td>
  83. <td valign="top">Whether to log the creation of new files.
  84. <b>Since Ant 1.6.3</b></td>
  85. <td valign="top" align="center">No, default <i>true</i>.</td>
  86. </tr>
  87. </table>
  88. <h3>Parameters specified as nested elements</h3>
  89. <h4>any resource collection</h4>
  90. <p>You can use any number of nested resource collection elements to
  91. define the resources for this task and refer to resources defined
  92. elsewhere. <b>Note:</b> resources passed to this task must implement
  93. the <code>org.apache.tools.ant.types.resources.Touchable</code>
  94. interface, this is true for all filesystem-based resources like those
  95. returned by path, fileset ot filelist.</p>
  96. <p>For backwards compatibility directories matched by nested filesets
  97. will be "touched" as well, use a &lt;type&gt; selector to suppress
  98. this. This only applies to filesets nested into the task directly,
  99. not to filesets nested into a path or any other resource
  100. collection.</p>
  101. <h4>mapper</h4>
  102. <p><em>Since Ant 1.6.3,</em> a nested <a href="../Types/mapper.html">
  103. mapper</a> can be specified. Files specified via nested
  104. <code>fileset</code>s, <code>filelist</code>s, or the <code>file</code>
  105. attribute are mapped using the specified mapper. For each file mapped,
  106. the resulting files are touched. If no time has been specified and
  107. the original file exists its timestamp will be used.
  108. If no time has been specified and the original file does not exist the
  109. current time is used. Since Ant 1.8 the task settings (<code>millis</code>,
  110. and <code>datetime</code>) have priority over the timestamp of the original
  111. file.</p>
  112. <h3>Examples</h3>
  113. <pre> &lt;touch file=&quot;myfile&quot;/&gt;</pre>
  114. <p>creates <code>myfile</code> if it doesn't exist and changes the
  115. modification time to the current time.</p>
  116. <pre> &lt;touch file=&quot;myfile&quot; datetime=&quot;06/28/2000 2:02 pm&quot;/&gt;</pre>
  117. <p>creates <code>myfile</code> if it doesn't exist and changes the
  118. modification time to Jun, 28 2000 2:02 pm (14:02 for those used to 24
  119. hour times).</p>
  120. <pre> &lt;touch datetime=&quot;09/10/1974 4:30 pm&quot;&gt;
  121. &lt;fileset dir=&quot;src_dir&quot;/&gt;
  122. &lt;/touch&gt;</pre>
  123. <p>changes the modification time to Oct, 09 1974 4:30 pm of all files and directories
  124. found in <code>src_dir</code>. </p>
  125. <pre> &lt;touch file=&quot;myfile&quot; datetime=&quot;06/28/2000 2:02:17 pm&quot;/&gt;</pre>
  126. <p>creates <code>myfile</code> if it doesn't exist and changes the
  127. modification time to Jun, 28 2000 2:02:17 pm (14:02:17 for those used to 24
  128. hour times), if the filesystem allows a precision of one second - a
  129. time close to it otherwise.</p>
  130. <pre> &lt;touch file=&quot;foo&quot;&gt;
  131. &lt;mapper type=&quot;glob&quot; from=&quot;foo&quot; to=&quot;bar&quot; /&gt;
  132. &lt;/touch&gt;
  133. </pre>
  134. <p>creates <code>bar</code> if it doesn't exist and changes the
  135. modification time to that of <code>foo</code>.</p>
  136. <pre> &lt;touch file=&quot;foo&quot; datetime=&quot;now&quot;&gt;
  137. &lt;mapper type=&quot;regexp&quot; from=&quot;^src(.*)\.java&quot; to=&quot;shadow\1.empty&quot; /&gt;
  138. &lt;/touch&gt;
  139. </pre>
  140. <p>creates files in the <code>shadow</code> directory for every java file in the
  141. <code>src</code> directory if it doesn't exist and changes the modification
  142. time of those files to the current time.</p>
  143. </body>
  144. </html>