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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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.
  69. Defaults to MM/DD/YYYY HH:MM AM_or_PM or MM/DD/YYYY HH:MM:SS AM_or_PM.
  70. <b>Since Ant 1.6.3</b></td>
  71. <td valign="top" align="center">No</td>
  72. </tr>
  73. <tr>
  74. <td valign="top">mkdirs</td>
  75. <td valign="top">Whether to create nonexistent parent
  76. directories when touching new files. <b>Since Ant 1.6.3</b></td>
  77. <td valign="top" align="center">No, default <i>false</i>.</td>
  78. </tr>
  79. <tr>
  80. <td valign="top">verbose</td>
  81. <td valign="top">Whether to log the creation of new files.
  82. <b>Since Ant 1.6.3</b></td>
  83. <td valign="top" align="center">No, default <i>true</i>.</td>
  84. </tr>
  85. </table>
  86. <h3>Parameters specified as nested elements</h3>
  87. <h4>any resource collection</h4>
  88. <p>You can use any number of nested resource collection elements to
  89. define the resources for this task and refer to resources defined
  90. elsewhere. <b>Note:</b> resources passed to this task must implement
  91. the <code>org.apache.tools.ant.types.resources.Touchable</code>
  92. interface, this is true for all filesystem-based resources like those
  93. returned by path, fileset ot filelist.</p>
  94. <p>For backwards compatibility directories matched by nested filesets
  95. will be "touched" as well, use a &lt;type&gt; selector to suppress
  96. this. This only applies to filesets nested into the task directly,
  97. not to filesets nested into a path or any other resource
  98. collection.</p>
  99. <h4>mapper</h4>
  100. <p><em>Since Ant 1.6.3,</em> a nested <a href="../Types/mapper.html">
  101. mapper</a> can be specified. Files specified via nested
  102. <code>fileset</code>s, <code>filelist</code>s, or the <code>file</code>
  103. attribute are mapped using the specified mapper. For each file mapped,
  104. the resulting files are touched. If no time has been specified and
  105. the original file exists its timestamp will be used.
  106. If no time has been specified and the original file does not exist the
  107. current time is used. Since Ant 1.8 the task settings (<code>millis</code>,
  108. and <code>datetime</code>) have priority over the timestamp of the original
  109. file.</p>
  110. <h3>Examples</h3>
  111. <pre> &lt;touch file=&quot;myfile&quot;/&gt;</pre>
  112. <p>creates <code>myfile</code> if it doesn't exist and changes the
  113. modification time to the current time.</p>
  114. <pre> &lt;touch file=&quot;myfile&quot; datetime=&quot;06/28/2000 2:02 pm&quot;/&gt;</pre>
  115. <p>creates <code>myfile</code> if it doesn't exist and changes the
  116. modification time to Jun, 28 2000 2:02 pm (14:02 for those used to 24
  117. hour times).</p>
  118. <pre> &lt;touch datetime=&quot;09/10/1974 4:30 pm&quot;&gt;
  119. &lt;fileset dir=&quot;src_dir&quot;/&gt;
  120. &lt;/touch&gt;</pre>
  121. <p>changes the modification time to Oct, 09 1974 4:30 pm of all files and directories
  122. found in <code>src_dir</code>. </p>
  123. <pre> &lt;touch file=&quot;myfile&quot; datetime=&quot;06/28/2000 2:02:17 pm&quot;/&gt;</pre>
  124. <p>creates <code>myfile</code> if it doesn't exist and changes the
  125. modification time to Jun, 28 2000 2:02:17 pm (14:02:17 for those used to 24
  126. hour times), if the filesystem allows a precision of one second - a
  127. time close to it otherwise.</p>
  128. <pre> &lt;touch file=&quot;foo&quot;&gt;
  129. &lt;mapper type=&quot;glob&quot; from=&quot;foo&quot; to=&quot;bar&quot; /&gt;
  130. &lt;/touch&gt;
  131. </pre>
  132. <p>creates <code>bar</code> if it doesn't exist and changes the
  133. modification time to that of <code>foo</code>.</p>
  134. <pre> &lt;touch file=&quot;foo&quot; datetime=&quot;now&quot;&gt;
  135. &lt;mapper type=&quot;regexp&quot; from=&quot;^src(.*)\.java&quot; to=&quot;shadow\1.empty&quot; /&gt;
  136. &lt;/touch&gt;
  137. </pre>
  138. <p>creates files in the <code>shadow</code> directory for every java file in the
  139. <code>src</code> directory if it doesn't exist and changes the modification
  140. time of those files to the current time.</p>
  141. </body>
  142. </html>