PageRenderTime 46ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/phing/phing/docs/docbook5/en/output/chunkhtml/ch04s02.html

https://gitlab.com/Isaki/le331.fr
HTML | 202 lines | 152 code | 50 blank | 0 comment | 0 complexity | ea4cb6d96115cfb90c39ee83a8166bca MD5 | raw file
  1. <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>4.2 Writing A Simple Buildfile</title><link rel="stylesheet" type="text/css" href="book.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="Phing User Guide"><link rel="up" href="ch.gettingstarted.html" title="Chapter 4 Getting started"><link rel="prev" href="ch.gettingstarted.html" title="Chapter 4 Getting started"><link rel="next" href="ch04s03.html" title="4.3 More Complex Buildfile"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">4.2 Writing A Simple Buildfile </th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch.gettingstarted.html">Prev</a> </td><th width="60%" align="center">Chapter 4 Getting started</th><td width="20%" align="right"> <a accesskey="n" href="ch04s03.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="idp54316880"></a>4.2 Writing A Simple Buildfile </h2></div></div></div>
  2. <p>The <code class="literal">Foobar</code> project installs some PHP files from a source location
  3. to a target location, creates an archive of this files and provides an optional clean-up
  4. of the build tree:</p>
  5. <pre class="programlisting">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  6. &lt;project name="FooBar" default="dist"&gt;
  7. &lt;!-- ============================================ --&gt;
  8. &lt;!-- Target: prepare --&gt;
  9. &lt;!-- ============================================ --&gt;
  10. &lt;target name="prepare"&gt;
  11. &lt;echo msg="Making directory ./build" /&gt;
  12. &lt;mkdir dir="./build" /&gt;
  13. &lt;/target&gt;
  14. &lt;!-- ============================================ --&gt;
  15. &lt;!-- Target: build --&gt;
  16. &lt;!-- ============================================ --&gt;
  17. &lt;target name="build" depends="prepare"&gt;
  18. &lt;echo msg="Copying files to build directory..." /&gt;
  19. &lt;echo msg="Copying ./about.php to ./build directory..." /&gt;
  20. &lt;copy file="./about.php" tofile="./build/about.php" /&gt;
  21. &lt;echo msg="Copying ./browsers.php to ./build directory..." /&gt;
  22. &lt;copy file="./browsers.php" tofile="./build/browsers.php" /&gt;
  23. &lt;echo msg="Copying ./contact.php to ./build directory..." /&gt;
  24. &lt;copy file="./contact.php" tofile="./build/contact.php" /&gt;
  25. &lt;/target&gt;
  26. &lt;!-- ============================================ --&gt;
  27. &lt;!-- (DEFAULT) Target: dist --&gt;
  28. &lt;!-- ============================================ --&gt;
  29. &lt;target name="dist" depends="build"&gt;
  30. &lt;echo msg="Creating archive..." /&gt;
  31. &lt;tar destfile="./build/build.tar.gz" compression="gzip"&gt;
  32. &lt;fileset dir="./build"&gt;
  33. &lt;include name="*" /&gt;
  34. &lt;/fileset&gt;
  35. &lt;/tar&gt;
  36. &lt;echo msg="Files copied and compressed in build directory OK!" /&gt;
  37. &lt;/target&gt;
  38. &lt;/project&gt;</pre>
  39. <p>A phing build file is normally given the name <code class="filename">build.xml</code> which is
  40. the default file name that the Phing executable will look for if no other file name is
  41. specified.</p>
  42. <p>To run the above build file and execute the default target (assuming it is stored in
  43. the current directory with the default name) is only a matter of calling: <code class="code">$
  44. phing</code>
  45. </p>
  46. <p>This will then execute the <code class="filename">dist</code> target. While executing the build
  47. file each task performed will print some information on what actions and what files have
  48. been affected.</p>
  49. <p>To run any of the other target is only a matter of providing the name of the target on
  50. the command line. So for example to run the <code class="filename">build</code> target one would
  51. have to execute <code class="code"> $ phing build </code>
  52. </p>
  53. <p>It is also possible to specify a number of additional command line arguments as
  54. described in <a class="xref" href="app.factsheet.html" title="Appendix A. Fact Sheet">Appendix A, <i>Fact Sheet</i></a>
  55. </p>
  56. <div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="idp54327312"></a>4.2.1 Project Element </h3></div></div></div>
  57. <p>The first element after the document prolog is the root element named
  58. <code class="literal">&lt;project&gt;</code> on line 3. This element is a container for all
  59. other elements and can/must have the following attributes: </p>
  60. <div class="table"><a name="idp54329456"></a><p class="formal-object-title"><span class="label">Table 4.1: </span><span class="title">&lt;project&gt; Attributes</span></p><div class="table-contents">
  61. <table summary="&lt;project&gt; Attributes" border="1"><colgroup><col class="name"><col class="description"><col class="required"></colgroup><thead><tr><th>Attribute</th><th>Description</th><th>Required</th></tr></thead><tbody><tr><td><code class="literal">name</code></td><td>The name of the project</td><td>No</td></tr><tr><td><code class="literal">basedir</code></td><td>The base directory of the project, use "." do denote
  62. the current directory. <span class="bold"><strong>Note:</strong></span> if
  63. none is specified, the parent directory of the build file is
  64. used!</td><td>No</td></tr><tr><td><code class="literal">default</code></td><td>The default target that is to be executed if no target(s) are
  65. specified when calling this build file.</td><td>Yes</td></tr><tr><td><code class="literal">description</code></td><td>The description of the project.</td><td>No</td></tr></tbody></table>
  66. </div></div><br class="table-break">
  67. <p>
  68. See <a class="xref" href="app.projcomponents.html#Project" title="H.1 Phing Projects">Section H.1, Phing Projects</a> for a complete reference.
  69. </p>
  70. </div>
  71. <div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="idp54348016"></a>4.2.2 Target Element </h3></div></div></div>
  72. <p>A target can <code class="literal">depend</code> on other targets. You might have a target
  73. for installing the files in the build tree, for example, and a target for creating a
  74. distributable tar.gz archive. You can only build a distributable when you have
  75. installed the files first, so the distribute target depends on the install target.
  76. Phing resolves these dependencies.</p>
  77. <p>It should be noted, however, that Phing's depends attribute only specifies the
  78. order in which targets should be executed - it does not affect whether the target
  79. that specifies the dependency(s) gets executed if the dependent target(s) did not
  80. (need to) run.</p>
  81. <p>Phing tries to execute the targets in the depends attribute in the order they
  82. appear (from left to right). Keep in mind that it is possible that a target can get
  83. executed earlier when an earlier target depends on it, in this case the dependent is
  84. only executed once:</p>
  85. <pre class="screen">&lt;target name="A" /&gt;
  86. &lt;target name="B" depends="A" /&gt;
  87. &lt;target name="C" depends="B" /&gt;
  88. &lt;target name="D" depends="C,B,A" /&gt;</pre>
  89. <p>Suppose we want to execute target <code class="literal">D</code>. Looking at its depends
  90. attribute, you might think that first target <code class="literal">C</code>, then
  91. <code class="literal">B</code> and then <code class="literal">A</code> is executed. Wrong!
  92. <code class="literal">C</code> depends on <code class="literal">B</code>, and <code class="literal">B</code>
  93. depends on <code class="literal">A</code>, so first <code class="literal">A</code> is executed, then
  94. <code class="literal">B</code>, then <code class="literal">C</code>, and finally
  95. <code class="literal">D</code>.</p>
  96. <p>A target gets executed only once, even when more than one target depends on it
  97. (see the previous example).</p>
  98. <p>The optional description attribute can be used to provide a one-line description
  99. of this target, which is printed by the <code class="literal">-projecthelp</code> command-line
  100. option.</p>
  101. <div class="sect3"><div class="titlepage"><div><div><h4 class="title"><a name="idp54360640"></a>Target attributes</h4></div></div></div>
  102. <p>You can specify one or more of the following attributes within the target
  103. element.</p>
  104. <div class="table"><a name="idp54361888"></a><p class="formal-object-title"><span class="label">Table 4.2: </span><span class="title">&lt;target&gt; Attributes</span></p><div class="table-contents">
  105. <table summary="&lt;target&gt; Attributes" border="1"><colgroup><col class="name"><col class="description"><col class="required"></colgroup><thead><tr><th>Attribute</th><th>Description</th><th>Required</th></tr></thead><tbody><tr><td>name</td><td>The name of the target</td><td>Yes</td></tr><tr><td>depends</td><td>A comma-separated list of targets this target depends
  106. on.</td><td>No</td></tr><tr><td>if</td><td>The name of the <code class="literal">Property</code> that has to be
  107. set in order for this target to be executed</td><td>No</td></tr><tr><td>unless</td><td>The name of the <code class="literal">Property</code> that must
  108. <code class="literal">not</code> be set in order for this target to be
  109. executed.</td><td> </td></tr></tbody></table>
  110. </div></div><br class="table-break">
  111. </div>
  112. <p>
  113. See <a class="xref" href="Target.html" title="H.2 Targets">Section H.2, Targets</a> for a complete reference.
  114. </p>
  115. </div>
  116. <div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="idp54348272"></a>4.2.3 Task Elements </h3></div></div></div>
  117. <p> A <code class="literal">task</code> is a piece of PHP code that can be executed. This code
  118. implements a particular action to perform (i.e. install a file). Therefore it must
  119. be defined in the buildfile so that it is actually invoked by Phing.</p>
  120. <p>These references will be resolved before the task is executed.</p>
  121. <p>Tasks have a common structure:</p>
  122. <pre class="screen">&lt;name attribute1="value1" attribute2="value2" ... /&gt;</pre>
  123. <p>where <code class="literal">name</code> is the name of the task,
  124. <code class="literal">attributeN</code> is the attribute name, and
  125. <code class="literal">valueN</code> is the value for this attribute.</p>
  126. <p>There is a set of core tasks (see <a class="xref" href="app.coretasks.html" title="Appendix B. Core tasks">Appendix B, <i>Core tasks</i></a>) along with
  127. a number of optional tasks. It is also very easy to write your own tasks (see <a class="xref" href="ch.extending.html" title="Chapter 6 Extending Phing">Chapter 6, <i>Extending Phing</i></a>).</p>
  128. <p>Tasks can be assigned an <code class="literal">id</code> attribute: </p>
  129. <pre class="screen">&lt;taskname id="taskID" ... /&gt;</pre>
  130. <p>By doing this you can refer to specific tasks later on in the code of other
  131. tasks.</p>
  132. </div>
  133. <div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="idp54380544"></a>4.2.4 Property Element </h3></div></div></div>
  134. <p><code class="literal">Properties</code> are essentially variables that can be used in the
  135. buildfile. These might be set in the buildfile by calling the <a class="link" href="PropertyTask.html" title="B.33 PropertyTask">property</a> task,
  136. or might be set outside Phing on the command line
  137. (properties set on the command line always override the ones in the buildfile). A
  138. property has a name and a value only. Properties may be used in the value of task
  139. attributes. This is done by placing the property name between "
  140. <code class="literal">${</code> " and " <code class="literal">}</code> " in the
  141. attribute value. For example, if there is a <code class="literal">BC_BUILD_DIR</code> property
  142. with the value 'build', then this could be used in an attribute like this:
  143. <code class="literal">${BC_BUILD_DIR}/en</code> . This is resolved to
  144. <code class="literal">build/en</code>.</p>
  145. <div class="sect3"><div class="titlepage"><div><div><h4 class="title"><a name="idp54394928"></a>Built-in Properties</h4></div></div></div>
  146. <p>Phing provides access to system properties as if they had been defined using a
  147. <code class="literal">&lt;property&gt;</code> task. For example,
  148. <code class="literal">${os.name}</code> expands to the name of the operating system.
  149. See <a class="xref" href="app.factsheet.html" title="Appendix A. Fact Sheet">Appendix A, <i>Fact Sheet</i></a> for a complete list </p>
  150. </div>
  151. </div>
  152. </div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch.gettingstarted.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch.gettingstarted.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch04s03.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 4 Getting started </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 4.3 More Complex Buildfile </td></tr></table></div></body></html>