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.

import.html 3.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Language" content="en-us">
  5. <title>Import Task</title>
  6. </head>
  7. <body>
  8. <h2><a name="import">Import</a></h2>
  9. <h3>Description</h3>
  10. <p>
  11. Imports another build file into the current project.
  12. </p>
  13. <p>
  14. On execution it will read another Ant file into
  15. the same Project. This means that it basically works like the
  16. <a href="http://ant.apache.org/faq.html#xml-entity-include">Entity
  17. Includes as explained in the Ant FAQ</a>, as if the imported file was
  18. contained in the importing file, minus the top <code>&lt;project&gt;</code>
  19. tag.
  20. </p>
  21. <p>
  22. The import task may only be used as a top-level task. This means that
  23. it may not be used in a target.
  24. </p>
  25. <p>
  26. There are two further functional aspects that pertain to this task and
  27. that are not possible with entity includes:
  28. <ul>
  29. <li>target overriding</li>
  30. <li>special properties</li>
  31. </ul>
  32. </p>
  33. <b>Target overriding<br>
  34. <br>
  35. </b>If a target in the main file is also present in at least one of the
  36. imported files, it takes precedence.<br>
  37. <br>
  38. So if I import for example a <i>docsbuild.xml</i> file named <b>builddocs</b>,
  39. that contains a "<b>docs</b>" target, I can redefine it in my main
  40. buildfile and that is the one that will be called. It makes it easy to
  41. keep the same target name, that has the same dependencies (so it is
  42. still called by the other targets), but use a different implementation.<br>
  43. <br>
  44. The original target is still available though, and is called <b>"builddocs</b><b>.docs"</b>.
  45. This means that in my new implementation, I can still call the old
  46. target, making it possible to <i>enhance </i>it with tasks called
  47. before or after it.<br>
  48. <b></b><b><br>
  49. Special Properties<br>
  50. <br>
  51. </b>Imported files are treated as they are present in the main
  52. buildfile. This makes it easy to understand, but it makes it impossible
  53. for them to reference files and resources relative to their path.
  54. Because of this, for every imported file, Ant adds a property that
  55. contains the path to the imported buildfile. With this path, the
  56. imported buildfile can keep resources and be able to reference them
  57. relative to its position.<br>
  58. <br>
  59. So if I import for example a <i>docsbuild.xml</i> file named <b>builddocs</b>,
  60. I can get its path as <b>ant.file.builddocs</b>, similarly to the <b>ant.file</b>
  61. property of the main buildfile.<br>
  62. Note that "builddocs" is not the filename, but the name attribute
  63. present in the imported project tag.<br>
  64. <br>
  65. <b>Important</b>: We have not finalized how relative file references
  66. will be resolved in deep/complex build hierarchies -such as what
  67. happens when an imported file imports another file. Use absolute
  68. references for enhanced build file stability, especially in the
  69. imported files.<br>
  70. &nbsp;<br>
  71. <h3>Parameters</h3>
  72. <table border="1" cellpadding="2" cellspacing="0">
  73. <tbody>
  74. <tr>
  75. <td valign="top"><b>Attribute</b></td>
  76. <td valign="top"><b>Description</b></td>
  77. <td align="center" valign="top"><b>Required</b></td>
  78. </tr>
  79. <tr>
  80. <td valign="top">file<br>
  81. </td>
  82. <td valign="top">The file to import.<br>
  83. </td>
  84. <td valign="top" align="center">Yes</td>
  85. </tr>
  86. <tr>
  87. <td valign="top">optional<br>
  88. </td>
  89. <td valign="top">
  90. if true, do not issue stop the build if the file does not exist,
  91. default is false.<br>
  92. </td>
  93. <td valign="top" align="center">No</td>
  94. </tr>
  95. </tbody>
  96. </table>
  97. <h3><br>
  98. </h3>
  99. <h3>Examples</h3>
  100. <pre>&nbsp; &lt;import file="../common-targets.xml" /&gt;<br></pre>
  101. <br>
  102. Imports targets from the common-targets.xml file that is in a parent
  103. directory.<br>
  104. <br>
  105. <pre>&nbsp; &lt;import file="${deploy-platform}.xml" /&gt;<br></pre>
  106. <br>
  107. Imports the project defined by the property deploy-platform<br>
  108. <br>
  109. <br>
  110. <hr>
  111. <p align="center">Copyright &copy; 2003-2004 Apache Software
  112. Foundation. All rights
  113. Reserved.</p>
  114. </body>
  115. </html>