XML And Phing
<?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>
一個phing的構建文件通常以build.xml命名。如果沒有指定文件名,phing會將build.xml作為默認執行的文件。
屬性
|
含意
|
是否必須
|
name
|
項目名稱
|
否
|
basedir
|
當前項目的起始目錄,“.”表示當前目錄。
注意:如果未指定此參數,則構建文件的父目錄將被設為默認值。
|
否
|
default
|
指定默認的target。如果在調用當前文件時未指定target,
將執行默認target。
|
是
|
description | 項目描述 | 否 |
<target name="A" /> <target name="B" depends="A" /> <target name="C" depends="B" /> <target name="D" depends="C,B,A" />假定我們想執行target D。根據它的depends屬性,你可能會認為執行順序會是,C,B,A。錯!C依賴B,B依賴A,因此A會先執行,然后是B,接下來是C,最后是D。
<name attribute1="value1" attribute2="value2" ... />name是task名稱,attributeN是屬性名,valueN是屬性值。
<taskname id="taskID" ... />可以在其它task中通id引用這個task。
<?xml version="1.0" encoding="UTF-8" ?> <project name="testsite" basedir="." default="main"> <property file="./build.properties" /> <property name="package" value="${phing.project.name}" override="true" /> <property name="builddir" value="./build/testsite" override="true" /> <property name="srcdir" value="${project.basedir}" override="true" /> <!-- Fileset for all files --> <fileset dir="." id="allfiles"> <include name="**" /> </fileset> <!-- ============================================ --> <!-- (DEFAULT) Target: main --> <!-- ============================================ --> <target name="main" description="main target"> <copy todir="${builddir}"> <fileset refid="allfiles" /> </copy> </target> <!-- ============================================ --> <!-- Target: Rebuild --> <!-- ============================================ --> <target name="rebuild" description="rebuilds this package"> <delete dir="${builddir}" /> <phingcall target="main" /> </target> </project>
這份構建文件首先定義了一些property。然后定義了一個fileset和二個target。下面我們來快速解讀下這份文件。
**/*.phps表示當前目錄下,所有子目錄中的后綴為phps的文件。
phing -Dbuilddir=/tmp/system-test上例中的builddir值將不再是./build/testsite,而是/tmp/system-test。
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
