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.

presetdef.html 3.4 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us"></meta>
  4. <title>PreSetDef Task</title>
  5. <style type="text/css">
  6. <!--
  7. .code { background: #EFEFEF; margin-top: }
  8. -->
  9. </style>
  10. </head>
  11. <body>
  12. <h2><a name="presetdef">PreSetDef</a></h2>
  13. <h3>Description</h3>
  14. <p>
  15. The preset definition generates a new definition
  16. based on a current definition with some attributes
  17. or elements preset.
  18. </p>
  19. <p>
  20. <em>since Ant 1.6</em>
  21. </p>
  22. <h3>Parameters</h3>
  23. <table border="1" cellpadding="2" cellspacing="0">
  24. <tr>
  25. <td valign="top"><b>Attribute</b></td>
  26. <td valign="top"><b>Description</b></td>
  27. <td align="center" valign="top"><b>Required</b></td>
  28. </tr>
  29. <tr>
  30. <td valign="top">name</td>
  31. <td valign="top">the name of the new definition</td>
  32. <td valign="top" align="center">Yes</td>
  33. </tr>
  34. <tr>
  35. <td valign="top">uri</td>
  36. <td valign="top">
  37. The uri that this definition should live in.
  38. </td>
  39. <td valign="top" align="center">No</td>
  40. </tr>
  41. </table>
  42. <h3>Parameters specified as nested elements</h3>
  43. <h4>another type with attributes or elements set</h4>
  44. <p>The &lt;presetdef&gt; task takes one nested element as a parameter.
  45. This nested element can be any other type or task. The attributes
  46. and elements that need to be preset are placed here.
  47. </p>
  48. <h3>Examples</h3>
  49. The following fragment defines a javac task with the debug, deprecation
  50. srcdir and destdir
  51. attributes set. It also has a src element to source files from a generated
  52. directory.
  53. <blockquote>
  54. <pre class="code">
  55. &lt;presetdef name="my.javac"&gt;
  56. &lt;javac debug="${debug}" deprecation="${deprecation}"
  57. srcdir="${src.dir}" destdir="${classes.dir}"&gt;
  58. &lt;src path="${gen.dir}"/&gt;
  59. &lt;/javac&gt;
  60. &lt;/presetdef&gt;
  61. </pre>
  62. </blockquote>
  63. This can be used as a normal javac task - example:
  64. <blockquote>
  65. <pre class="code">
  66. &lt;my.javac/&gt;
  67. </pre>
  68. </blockquote>
  69. The attributes specified in the preset task may be overridden - i.e.
  70. they may be seen as optional attributes - example:
  71. <blockquote>
  72. <pre class="code">
  73. &lt;my.javac srcdir="${test.src}" deprecation="no"/&gt;
  74. </pre>
  75. </blockquote>
  76. One may put a presetdef definition in an antlib.
  77. For example suppose the jar file antgoodies.jar has
  78. the antlib.xml as follows:
  79. <blockquote>
  80. <pre class="code">
  81. &lt;antlib&gt;
  82. &lt;taskdef resource="com/acme/antgoodies/tasks.properties"/&gt;
  83. &lt;!-- Implement the common use of the javac command --&gt;
  84. &lt;presetdef name="javac"&gt;
  85. &lt;javac deprecation="${deprecation}" debug="${debug}"
  86. srcdir="src" destdir="classes"/&gt;
  87. &lt;/presetdef&gt;
  88. &lt;/antlib&gt;
  89. </pre>
  90. </blockquote>
  91. One may then use this in a build file as follows:
  92. <blockquote>
  93. <pre class="code">
  94. &lt;project default="example" xmlns:antgoodies="antlib:com.acme.antgoodies"&gt;
  95. &lt;target name="example"&gt;
  96. &lt;!-- Compile source --&gt;
  97. &lt;antgoodies:javac srcdir="src/main"/&gt;
  98. &lt;!-- Compile test code --&gt;
  99. &lt;antgoodies:javac srcdir="src/test"/&gt;
  100. &lt;/target&gt;
  101. &lt;/project&gt;
  102. </pre>
  103. </blockquote>
  104. <hr></hr>
  105. <p align="center">Copyright &copy; 2003 Apache Software
  106. Foundation. All rights Reserved.</p>
  107. </body>
  108. </html>