diff options
author | xue <> | 2006-06-19 02:34:25 +0000 |
---|---|---|
committer | xue <> | 2006-06-19 02:34:25 +0000 |
commit | bf41d24477d0d13f2bdb1cc87f645ef9f1f4de7b (patch) | |
tree | c37ef0365d620724cf3301b3c8dc9005901d965a /buildscripts/phing/pear | |
parent | b59ab2490b1bb82dc1d0b58d89584182b405d0a0 (diff) |
Added phing
Diffstat (limited to 'buildscripts/phing/pear')
-rw-r--r-- | buildscripts/phing/pear/BuildPhingPEARPackageTask.php | 270 | ||||
-rw-r--r-- | buildscripts/phing/pear/build.xml | 156 |
2 files changed, 426 insertions, 0 deletions
diff --git a/buildscripts/phing/pear/BuildPhingPEARPackageTask.php b/buildscripts/phing/pear/BuildPhingPEARPackageTask.php new file mode 100644 index 00000000..6ac6ad51 --- /dev/null +++ b/buildscripts/phing/pear/BuildPhingPEARPackageTask.php @@ -0,0 +1,270 @@ +<?php +/* + * $Id$ + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This software consists of voluntary contributions made by many individuals + * and is licensed under the LGPL. For more information please see + * <http://phing.info>. + */ + +require_once 'phing/tasks/system/MatchingTask.php'; +include_once 'phing/types/FileSet.php'; +include_once 'phing/tasks/ext/pearpackage/Fileset.php'; + +/** + * + * @author Hans Lellelid <hans@xmpl.org> + * @package phing.tasks.ext + * @version $Revision$ + */ +class BuildPhingPEARPackageTask extends MatchingTask { + + /** Base directory for reading files. */ + private $dir; + + private $version; + private $state = 'stable'; + private $notes; + + private $filesets = array(); + + /** Package file */ + private $packageFile; + + public function init() { + include_once 'PEAR/PackageFileManager2.php'; + if (!class_exists('PEAR_PackageFileManager2')) { + throw new BuildException("You must have installed PEAR_PackageFileManager2 (PEAR_PackageFileManager >= 1.6.0) in order to create a PEAR package.xml file."); + } + } + + private function setOptions($pkg){ + + $options['baseinstalldir'] = 'phing'; + $options['packagedirectory'] = $this->dir->getAbsolutePath(); + + if (empty($this->filesets)) { + throw new BuildException("You must use a <fileset> tag to specify the files to include in the package.xml"); + } + + $options['filelistgenerator'] = 'Fileset'; + + // Some PHING-specific options needed by our Fileset reader + $options['phing_project'] = $this->getProject(); + $options['phing_filesets'] = $this->filesets; + + if ($this->packageFile !== null) { + // create one w/ full path + $f = new PhingFile($this->packageFile->getAbsolutePath()); + $options['packagefile'] = $f->getName(); + // must end in trailing slash + $options['outputdirectory'] = $f->getParent() . DIRECTORY_SEPARATOR; + $this->log("Creating package file: " . $f->getPath(), PROJECT_MSG_INFO); + } else { + $this->log("Creating [default] package.xml file in base directory.", PROJECT_MSG_INFO); + } + + // add install exceptions + $options['installexceptions'] = array( 'bin/phing.php' => '/', + 'bin/pear-phing' => '/', + 'bin/pear-phing.bat' => '/', + ); + + $options['dir_roles'] = array( 'phing_guide' => 'doc', + 'etc' => 'data', + 'example' => 'doc'); + + $options['exceptions'] = array( 'bin/pear-phing.bat' => 'script', + 'bin/pear-phing' => 'script', + 'CREDITS' => 'doc', + 'CHANGELOG' => 'doc', + 'README' => 'doc', + 'TODO' => 'doc'); + + $pkg->setOptions($options); + + } + + /** + * Main entry point. + * @return void + */ + public function main() { + + if ($this->dir === null) { + throw new BuildException("You must specify the \"dir\" attribute for PEAR package task."); + } + + if ($this->version === null) { + throw new BuildException("You must specify the \"version\" attribute for PEAR package task."); + } + + $package = new PEAR_PackageFileManager2(); + + $this->setOptions($package); + + // the hard-coded stuff + $package->setPackage('phing'); + $package->setSummary('PHP5 project build system based on Apache Ant'); + $package->setDescription('PHing Is Not GNU make; it\'s a project build system based on Apache Ant. +You can do anything with it that you could do with a traditional build system like GNU make, and its use of +simple XML build files and extensible PHP "task" classes make it an easy-to-use and highly flexible build framework. +Features include file transformations (e.g. token replacement, XSLT transformation, Smarty template transformations, +etc.), file system operations, interactive build support, SQL execution, and much more.'); + $package->setChannel('pear.phing.info'); + $package->setPackageType('php'); + + $package->setReleaseVersion($this->version); + $package->setAPIVersion($this->version); + + $package->setReleaseStability($this->state); + $package->setAPIStability($this->state); + + $package->setNotes($this->notes); + + $package->setLicense('LGPL', 'http://www.gnu.org/licenses/lgpl.html'); + + // Add package maintainers + $package->addMaintainer('lead', 'hans', 'Hans Lellelid', 'hans@xmpl.org'); + $package->addMaintainer('lead', 'mrook', 'Michiel Rook', 'michiel@trendserver.nl'); + + + + // (wow ... this is a poor design ...) + // + // note that the order of the method calls below is creating + // sub-"release" sections which have specific rules. This replaces + // the platformexceptions system in the older version of PEAR's package.xml + // + // Programmatically, I feel the need to re-iterate that this API for PEAR_PackageFileManager + // seems really wrong. Sub-sections should be encapsulated in objects instead of having + // a "flat" API that does not represent the structure being created.... + + + // creating a sub-section for 'windows' + $package->addRelease(); + $package->setOSInstallCondition('windows'); + $package->addInstallAs('bin/phing.php', 'phing.php'); + $package->addInstallAs('bin/pear-phing.bat', 'phing.bat'); + $package->addIgnoreToRelease('bin/pear-phing'); + + // creating a sub-section for non-windows + $package->addRelease(); + //$package->setOSInstallCondition('(*ix|*ux|darwin*|*BSD|SunOS*)'); + $package->addInstallAs('bin/phing.php', 'phing.php'); + $package->addInstallAs('bin/pear-phing', 'phing'); + $package->addIgnoreToRelease('bin/pear-phing.bat'); + + + // "core" dependencies + $package->setPhpDep('5.0.0'); + $package->setPearinstallerDep('1.4.0'); + + // "package" dependencies + $package->addPackageDepWithChannel( 'optional', 'VersionControl_SVN', 'pear.php.net', '0.3.0alpha1'); + $package->addPackageDepWithChannel( 'optional', 'PHPUnit2', 'pear.php.net', '2.3.0'); + $package->addPackageDepWithChannel( 'optional', 'PhpDocumentor', 'pear.php.net', '1.3.0RC3'); + $package->addPackageDepWithChannel( 'optional', 'Xdebug', 'pear.php.net', '2.0.0beta2'); + $package->addPackageDepWithChannel( 'optional', 'Archive_Tar', 'pear.php.net', '1.3.0'); + $package->addPackageDepWithChannel( 'optional', 'PEAR_PackageFileManager', 'pear.php.net', '1.5.2'); + + // now add the replacements .... + $package->addReplacement('Phing.php', 'pear-config', '@DATA-DIR@', 'data_dir'); + $package->addReplacement('bin/pear-phing.bat', 'pear-config', '@PHP-BIN@', 'php_bin'); + $package->addReplacement('bin/pear-phing.bat', 'pear-config', '@BIN-DIR@', 'bin_dir'); + $package->addReplacement('bin/pear-phing.bat', 'pear-config', '@PEAR-DIR@', 'php_dir'); + $package->addReplacement('bin/pear-phing', 'pear-config', '@PHP-BIN@', 'php_bin'); + $package->addReplacement('bin/pear-phing', 'pear-config', '@BIN-DIR@', 'bin_dir'); + $package->addReplacement('bin/pear-phing', 'pear-config', '@PEAR-DIR@', 'php_dir'); + + // now we run this weird generateContents() method that apparently + // is necessary before we can add replacements ... ? + $package->generateContents(); + + $e = $package->writePackageFile(); + + if (PEAR::isError($e)) { + throw new BuildException("Unable to write package file.", new Exception($e->getMessage())); + } + + } + + /** + * Used by the PEAR_PackageFileManager_PhingFileSet lister. + * @return array FileSet[] + */ + public function getFileSets() { + return $this->filesets; + } + + // ------------------------------- + // Set properties from XML + // ------------------------------- + + /** + * Nested creator, creates a FileSet for this task + * + * @return FileSet The created fileset object + */ + function createFileSet() { + $num = array_push($this->filesets, new FileSet()); + return $this->filesets[$num-1]; + } + + /** + * Set the version we are building. + * @param string $v + * @return void + */ + public function setVersion($v){ + $this->version = $v; + } + + /** + * Set the state we are building. + * @param string $v + * @return void + */ + public function setState($v) { + $this->state = $v; + } + + /** + * Sets release notes field. + * @param string $v + * @return void + */ + public function setNotes($v) { + $this->notes = $v; + } + /** + * Sets "dir" property from XML. + * @param PhingFile $f + * @return void + */ + public function setDir(PhingFile $f) { + $this->dir = $f; + } + + /** + * Sets the file to use for generated package.xml + */ + public function setDestFile(PhingFile $f) { + $this->packageFile = $f; + } + +} + + diff --git a/buildscripts/phing/pear/build.xml b/buildscripts/phing/pear/build.xml new file mode 100644 index 00000000..128dcd03 --- /dev/null +++ b/buildscripts/phing/pear/build.xml @@ -0,0 +1,156 @@ +<?xml version="1.0"?> +<!-- + This build file packages the phing files, builds a package.xml (version 2) for installation + using PEAR and creates the TAR and TGZ files. +--> +<project name="phing" basedir="." default="main"> + + <property name="phing.home" value=".."/> + <property name="build.base.dir" value="build"/> + <property name="pkgname" value="phing-${version}"/> + <property name="build.src.dir" value="${build.base.dir}/${pkgname}"/> + + <!-- some default properties --> + <property name="notes">This is the latest release of Phing.</property> + <property name="state" value="stable"/> + + <taskdef + name="pear-package" + classname="BuildPhingPEARPackageTask" classpath="."/> + + <fileset dir="${phing.home}/classes/phing" id="classes"> + <include name="**"/> + </fileset> + + <fileset dir="${phing.home}/docs" id="docs"> + <include name="example/**"/> + <include name="phing_guide/book/**"/> + </fileset> + + <fileset dir="${phing.home}" id="etc"> + <include name="etc/**"/> + <exclude name="etc/VERSION.TXT"/> + </fileset> + + <fileset dir="${phing.home}" id="scripts"> + <include name="bin/pear-*"/> + <include name="bin/phing.php"/> + </fileset> + + <fileset dir="${phing.home}" id="misc"> + <include name="CHANGELOG"/> + <include name="CREDITS"/> + <include name="README"/> + <include name="TODO"/> + <exclude name="INSTALL*"/> + </fileset> + + <!-- + ============================================== + Main entry point + ============================================== + --> + <target name="main" if="version" depends="versioncheck,copy-files,create-package-xml,tar"/> + + <!-- + =================================================================== + Target: checks if language was given, otherwise fail + =================================================================== + --> + <target name="versioncheck" unless="version"> + <echo message="====================================================="/> + <echo message="Version not specified. You must enter a version. In"/> + <echo message="the future you can add this to build.properties or"/> + <echo message="enter it on the command line: "/> + <echo message=" "/> + <echo message="-Dversion=2.0.0b1"/> + <echo message="====================================================="/> + <input propertyname="version" promptChar=":">Phing version for package</input> + + <property name="pkgname" value="phing-${version}" override="true"/> + <property name="build.src.dir" value="${build.base.dir}/${pkgname}" override="true"/> + + </target> + + <!-- + ============================================== + Copy the desired files into the build/ dir + making sure to put them in the directory + structure that will be needed for PEAR install + ============================================== + --> + <target name="copy-files"> + + <echo>-----------------------------</echo> + <echo>| Creating directory layout |</echo> + <echo>-----------------------------</echo> + + <delete dir="${build.base.dir}"/> + + <copy todir="${build.src.dir}"> + <fileset refid="classes"/> + <fileset refid="docs"/> + <fileset refid="etc"/> + <fileset refid="scripts"/> + <fileset refid="misc"/> + </copy> + + <append destFile="${build.src.dir}/etc/VERSION.TXT">Phing version ${version}</append> + + <chmod file="${build.src.dir}/bin/pear-phing" mode="755"/> + + </target> + + <!-- + ============================================== + Create a PEAR package.xml which will guide the + installation. + ============================================== + --> + <target name="create-package-xml" depends="versioncheck" if="version"> + + <echo>-----------------------------</echo> + <echo>| Creating PEAR package.xml |</echo> + <echo>-----------------------------</echo> + <echo></echo> + <echo>... (This step may take some time) ...</echo> + + <delete file="${tarfile}"/> + <pear-package dir="${build.src.dir}" destFile="${build.base.dir}/package.xml" version="${version}" state="${state}" notes="${notes}"> + + <fileset refid="classes"/> + <fileset refid="docs"/> + <fileset refid="etc"/> + <fileset refid="misc"/> + <fileset refid="scripts"/> + + <fileset dir="${build.src.dir}"> + <include name="etc/VERSION.TXT"/> + </fileset> + + </pear-package> + + </target> + + <!-- + ============================================== + Create a tar.gz of the files, which will be + installed by pear package manager. + ============================================== + --> + <target name="tar"> + <echo>-----------------------------</echo> + <echo>| Creating TAR packages |</echo> + <echo>-----------------------------</echo> + + <property name="tgzfile" value="${build.base.dir}/${pkgname}.tgz"/> + <delete file="${tgzfile}"/> + <tar compression="gzip" destFile="${tgzfile}" basedir="${build.base.dir}" /> + + <property name="tarfile" value="${build.base.dir}/${pkgname}.tar"/> + <delete file="${tarfile}"/> + <tar compression="none" destFile="${tarfile}" basedir="${build.base.dir}" /> + + </target> + +</project>
\ No newline at end of file |