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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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="../CoreTypes/resources.html">resources</a> and
  27. resource collections (which also includes directories). Prior to Ant
  28. 1.7 only FileSet or <a href="../CoreTypes/filelist.html">Filelist</a>
  29. (since Ant 1.6) have been supported.</p>
  30. <h3>Parameters</h3>
  31. <table border="1" cellpadding="2" cellspacing="0">
  32. <tr>
  33. <td valign="top"><b>Attribute</b></td>
  34. <td valign="top"><b>Description</b></td>
  35. <td align="center" valign="top"><b>Required</b></td>
  36. </tr>
  37. <tr>
  38. <td valign="top">file</td>
  39. <td valign="top">The name of the file.</td>
  40. <td valign="top" align="center">Unless a nested resource collection element
  41. has been specified.</td>
  42. </tr>
  43. <tr>
  44. <td valign="top">millis</td>
  45. <td valign="top">Specifies the new modification time of the file
  46. in milliseconds since midnight Jan 1 1970.</td>
  47. <td valign="center" align="center" rowspan="2">No--datetime takes
  48. precedence, however if both are omitted the current time is assumed.</td>
  49. </tr>
  50. <tr>
  51. <td valign="top">datetime</td>
  52. <td valign="top">Specifies the new modification time of the file. The
  53. special value &quot;now&quot; indicates the current time
  54. (now supported since Ant 1.8).</td>
  55. </tr>
  56. <tr>
  57. <td valign="top">pattern</td>
  58. <td valign="top">SimpleDateFormat-compatible pattern string.
  59. Defaults to MM/DD/YYYY HH:MM AM_or_PM or MM/DD/YYYY HH:MM:SS AM_or_PM.
  60. <b>Since Ant 1.6.3</b></td>
  61. <td valign="top" align="center">No</td>
  62. </tr>
  63. <tr>
  64. <td valign="top">mkdirs</td>
  65. <td valign="top">Whether to create nonexistent parent
  66. directories when touching new files. <b>Since Ant 1.6.3</b></td>
  67. <td valign="top" align="center">No, default <i>false</i>.</td>
  68. </tr>
  69. <tr>
  70. <td valign="top">verbose</td>
  71. <td valign="top">Whether to log the creation of new files.
  72. <b>Since Ant 1.6.3</b></td>
  73. <td valign="top" align="center">No, default <i>true</i>.</td>
  74. </tr>
  75. </table>
  76. <h3>Parameters specified as nested elements</h3>
  77. <h4>any resource collection</h4>
  78. <p>You can use any number of nested resource collection elements to
  79. define the resources for this task and refer to resources defined
  80. elsewhere. <b>Note:</b> resources passed to this task must implement
  81. the <code>org.apache.tools.ant.types.resources.Touchable</code>
  82. interface, this is true for all filesystem-based resources like those
  83. returned by path, fileset ot filelist.</p>
  84. <p>For backwards compatibility directories matched by nested filesets
  85. will be "touched" as well, use a &lt;type&gt; selector to suppress
  86. this. This only applies to filesets nested into the task directly,
  87. not to filesets nested into a path or any other resource
  88. collection.</p>
  89. <h4>mapper</h4>
  90. <p><em>Since Ant 1.6.3,</em> a nested <a href="../CoreTypes/mapper.html">
  91. mapper</a> can be specified. Files specified via nested
  92. <code>fileset</code>s, <code>filelist</code>s, or the <code>file</code>
  93. attribute are mapped using the specified mapper. For each file mapped,
  94. the resulting files are touched. If no time has been specified and
  95. the original file exists its timestamp will be used.
  96. If no time has been specified and the original file does not exist the
  97. current time is used. Since Ant 1.8 the task settings (<code>millis</code>,
  98. and <code>datetime</code>) have priority over the timestamp of the original
  99. file.</p>
  100. <h3>Examples</h3>
  101. <pre> &lt;touch file=&quot;myfile&quot;/&gt;</pre>
  102. <p>creates <code>myfile</code> if it doesn't exist and changes the
  103. modification time to the current time.</p>
  104. <pre> &lt;touch file=&quot;myfile&quot; datetime=&quot;06/28/2000 2:02 pm&quot;/&gt;</pre>
  105. <p>creates <code>myfile</code> if it doesn't exist and changes the
  106. modification time to Jun, 28 2000 2:02 pm (14:02 for those used to 24
  107. hour times).</p>
  108. <pre> &lt;touch datetime=&quot;09/10/1974 4:30 pm&quot;&gt;
  109. &lt;fileset dir=&quot;src_dir&quot;/&gt;
  110. &lt;/touch&gt;</pre>
  111. <p>changes the modification time to Oct, 09 1974 4:30 pm of all files and directories
  112. found in <code>src_dir</code>. </p>
  113. <pre> &lt;touch file=&quot;myfile&quot; datetime=&quot;06/28/2000 2:02:17 pm&quot;/&gt;</pre>
  114. <p>creates <code>myfile</code> if it doesn't exist and changes the
  115. modification time to Jun, 28 2000 2:02:17 pm (14:02:17 for those used to 24
  116. hour times), if the filesystem allows a precision of one second - a
  117. time close to it otherwise.</p>
  118. <pre> &lt;touch file=&quot;foo&quot;&gt;
  119. &lt;mapper type=&quot;glob&quot; from=&quot;foo&quot; to=&quot;bar&quot; /&gt;
  120. &lt;/touch&gt;
  121. </pre>
  122. <p>creates <code>bar</code> if it doesn't exist and changes the
  123. modification time to that of <code>foo</code>.</p>
  124. <pre> &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;
  127. </pre>
  128. <p>creates files in the <code>shadow</code> directory for every java file in the
  129. <code>src</code> directory if it doesn't exist and changes the modification
  130. time of those files to the current time.</p>
  131. </body>
  132. </html>