/vendor/phing/phing/docs/docbook5/en/output/chunkhtml/ch04s02.html
HTML | 202 lines | 152 code | 50 blank | 0 comment | 0 complexity | ea4cb6d96115cfb90c39ee83a8166bca MD5 | raw file
- <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>
-
- <p>The <code class="literal">Foobar</code> project installs some PHP files from a source location
- to a target location, creates an archive of this files and provides an optional clean-up
- of the build tree:</p>
- <pre class="programlisting"><?xml version="1.0" encoding="UTF-8"?>
- <project name="FooBar" default="dist">
- <!-- ============================================ -->
- <!-- Target: prepare -->
- <!-- ============================================ -->
- <target name="prepare">
- <echo msg="Making directory ./build" />
- <mkdir dir="./build" />
- </target>
- <!-- ============================================ -->
- <!-- Target: build -->
- <!-- ============================================ -->
- <target name="build" depends="prepare">
- <echo msg="Copying files to build directory..." />
- <echo msg="Copying ./about.php to ./build directory..." />
- <copy file="./about.php" tofile="./build/about.php" />
- <echo msg="Copying ./browsers.php to ./build directory..." />
- <copy file="./browsers.php" tofile="./build/browsers.php" />
- <echo msg="Copying ./contact.php to ./build directory..." />
- <copy file="./contact.php" tofile="./build/contact.php" />
- </target>
- <!-- ============================================ -->
- <!-- (DEFAULT) Target: dist -->
- <!-- ============================================ -->
- <target name="dist" depends="build">
- <echo msg="Creating archive..." />
- <tar destfile="./build/build.tar.gz" compression="gzip">
- <fileset dir="./build">
- <include name="*" />
- </fileset>
- </tar>
- <echo msg="Files copied and compressed in build directory OK!" />
- </target>
- </project></pre>
- <p>A phing build file is normally given the name <code class="filename">build.xml</code> which is
- the default file name that the Phing executable will look for if no other file name is
- specified.</p>
- <p>To run the above build file and execute the default target (assuming it is stored in
- the current directory with the default name) is only a matter of calling: <code class="code">$
- phing</code>
- </p>
- <p>This will then execute the <code class="filename">dist</code> target. While executing the build
- file each task performed will print some information on what actions and what files have
- been affected.</p>
- <p>To run any of the other target is only a matter of providing the name of the target on
- the command line. So for example to run the <code class="filename">build</code> target one would
- have to execute <code class="code"> $ phing build </code>
- </p>
- <p>It is also possible to specify a number of additional command line arguments as
- described in <a class="xref" href="app.factsheet.html" title="Appendix A. Fact Sheet">Appendix A, <i>Fact Sheet</i></a>
- </p>
- <div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="idp54327312"></a>4.2.1 Project Element </h3></div></div></div>
-
- <p>The first element after the document prolog is the root element named
- <code class="literal"><project></code> on line 3. This element is a container for all
- other elements and can/must have the following attributes: </p>
- <div class="table"><a name="idp54329456"></a><p class="formal-object-title"><span class="label">Table 4.1: </span><span class="title"><project> Attributes</span></p><div class="table-contents">
-
- <table summary="<project> 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
- the current directory. <span class="bold"><strong>Note:</strong></span> if
- none is specified, the parent directory of the build file is
- 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
- 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>
- </div></div><br class="table-break">
- <p>
- See <a class="xref" href="app.projcomponents.html#Project" title="H.1 Phing Projects">Section H.1, “Phing Projects”</a> for a complete reference.
- </p>
- </div>
- <div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="idp54348016"></a>4.2.2 Target Element </h3></div></div></div>
-
- <p>A target can <code class="literal">depend</code> on other targets. You might have a target
- for installing the files in the build tree, for example, and a target for creating a
- distributable tar.gz archive. You can only build a distributable when you have
- installed the files first, so the distribute target depends on the install target.
- Phing resolves these dependencies.</p>
- <p>It should be noted, however, that Phing's depends attribute only specifies the
- order in which targets should be executed - it does not affect whether the target
- that specifies the dependency(s) gets executed if the dependent target(s) did not
- (need to) run.</p>
- <p>Phing tries to execute the targets in the depends attribute in the order they
- appear (from left to right). Keep in mind that it is possible that a target can get
- executed earlier when an earlier target depends on it, in this case the dependent is
- only executed once:</p>
- <pre class="screen"><target name="A" />
- <target name="B" depends="A" />
- <target name="C" depends="B" />
- <target name="D" depends="C,B,A" /></pre>
- <p>Suppose we want to execute target <code class="literal">D</code>. Looking at its depends
- attribute, you might think that first target <code class="literal">C</code>, then
- <code class="literal">B</code> and then <code class="literal">A</code> is executed. Wrong!
- <code class="literal">C</code> depends on <code class="literal">B</code>, and <code class="literal">B</code>
- depends on <code class="literal">A</code>, so first <code class="literal">A</code> is executed, then
- <code class="literal">B</code>, then <code class="literal">C</code>, and finally
- <code class="literal">D</code>.</p>
- <p>A target gets executed only once, even when more than one target depends on it
- (see the previous example).</p>
- <p>The optional description attribute can be used to provide a one-line description
- of this target, which is printed by the <code class="literal">-projecthelp</code> command-line
- option.</p>
- <div class="sect3"><div class="titlepage"><div><div><h4 class="title"><a name="idp54360640"></a>Target attributes</h4></div></div></div>
-
- <p>You can specify one or more of the following attributes within the target
- element.</p>
- <div class="table"><a name="idp54361888"></a><p class="formal-object-title"><span class="label">Table 4.2: </span><span class="title"><target> Attributes</span></p><div class="table-contents">
-
- <table summary="<target> 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
- on.</td><td>No</td></tr><tr><td>if</td><td>The name of the <code class="literal">Property</code> that has to be
- 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
- <code class="literal">not</code> be set in order for this target to be
- executed.</td><td> </td></tr></tbody></table>
- </div></div><br class="table-break">
- </div>
- <p>
- See <a class="xref" href="Target.html" title="H.2 Targets">Section H.2, “Targets”</a> for a complete reference.
- </p>
- </div>
- <div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="idp54348272"></a>4.2.3 Task Elements </h3></div></div></div>
-
- <p> A <code class="literal">task</code> is a piece of PHP code that can be executed. This code
- implements a particular action to perform (i.e. install a file). Therefore it must
- be defined in the buildfile so that it is actually invoked by Phing.</p>
- <p>These references will be resolved before the task is executed.</p>
- <p>Tasks have a common structure:</p>
- <pre class="screen"><name attribute1="value1" attribute2="value2" ... /></pre>
- <p>where <code class="literal">name</code> is the name of the task,
- <code class="literal">attributeN</code> is the attribute name, and
- <code class="literal">valueN</code> is the value for this attribute.</p>
- <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
- 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>
- <p>Tasks can be assigned an <code class="literal">id</code> attribute: </p>
- <pre class="screen"><taskname id="taskID" ... /></pre>
- <p>By doing this you can refer to specific tasks later on in the code of other
- tasks.</p>
- </div>
- <div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="idp54380544"></a>4.2.4 Property Element </h3></div></div></div>
-
- <p><code class="literal">Properties</code> are essentially variables that can be used in the
- buildfile. These might be set in the buildfile by calling the <a class="link" href="PropertyTask.html" title="B.33 PropertyTask">property</a> task,
- or might be set outside Phing on the command line
- (properties set on the command line always override the ones in the buildfile). A
- property has a name and a value only. Properties may be used in the value of task
- attributes. This is done by placing the property name between "
- <code class="literal">${</code> " and " <code class="literal">}</code> " in the
- attribute value. For example, if there is a <code class="literal">BC_BUILD_DIR</code> property
- with the value 'build', then this could be used in an attribute like this:
- <code class="literal">${BC_BUILD_DIR}/en</code> . This is resolved to
- <code class="literal">build/en</code>.</p>
- <div class="sect3"><div class="titlepage"><div><div><h4 class="title"><a name="idp54394928"></a>Built-in Properties</h4></div></div></div>
-
- <p>Phing provides access to system properties as if they had been defined using a
- <code class="literal"><property></code> task. For example,
- <code class="literal">${os.name}</code> expands to the name of the operating system.
- 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>
- </div>
- </div>
- </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>