Skip to content
Browse files

phing now supports phar package creation so removing custom task

git-svn-id: http://mongodb-morph.googlecode.com/svn/trunk@67 406649b4-5d4b-11de-8abc-d1c337b90d21
  • Loading branch information...
1 parent a47885b commit 8a141c15161ee0e39fb626c68ecbe5d49890559d XirisR committed Jan 18, 2010
View
10 mongodb-morph/build.xml
@@ -1,8 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="Mongo Object" default="doc" basedir=".">
- <taskdef classname="phar.PharPackageTask2" name="pharpackage2"/>
-
<fileset dir="unit-tests" id="unit-tests">
<include name="**/Test*.php" />
</fileset>
@@ -38,7 +36,7 @@
<target name="unit-test" description="Runs Morph unit tests">
<echo msg="Starting Unit Test Suite" />
- <phpunit haltonfailure="false" haltonerror="false">
+ <phpunit haltonfailure="false" haltonerror="false" printsummary="true">
<formatter type="xml" outfile="test-report.xml" />
<batchtest>
<fileset refid="unit-tests" />
@@ -77,15 +75,15 @@
<format property="date.build" pattern="%s" />
</tstamp>
- <pharpackage2 basedir="./src/Morph" destfile="Morph.phar"
- compression="gzip" customStub="./src/Bootstrap.php" alias="Morph">
+ <pharpackage basedir="./src/Morph" destfile="Morph.phar"
+ compression="gzip" stub="./src/Bootstrap.php" alias="Morph">
<fileset refid="classes" />
<metadata>
<element name="Created Date" value="${date.created}" />
<element name="Copyright" value="Jonathan Moss (c) 2008-${date.year}" />
<element name="Build" value="${date.build}" />
</metadata>
- </pharpackage2>
+ </pharpackage>
</target>
<target name="all" description="builds everything" depends="unit-test, coverage, doc, package" />
View
56 mongodb-morph/phar/IterableFileSet.php
@@ -1,56 +0,0 @@
-<?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>.
- */
-
-/**
- * FileSet adapter to SPL's Iterator.
- *
- * @package phing.tasks.ext.phar
- * @author Alexey Shockov <alexey@shockov.com>
- * @since 2.4.0
- * @internal
- */
-class IterableFileSet
- extends FileSet
- implements IteratorAggregate
-{
- /**
- * @return Iterator
- */
- public function getIterator()
- {
- return new ArrayIterator($this->getFiles());
- }
- /**
- * @return array
- */
- private function getFiles()
- {
- $directoryScanner = $this->getDirectoryScanner($this->getProject());
- $files = $directoryScanner->getIncludedFiles();
-
- $baseDirectory = $directoryScanner->getBasedir();
- foreach ($files as $index => $file) {
- $files[$index] = realpath($baseDirectory.'/'.$file);
- }
-
- return $files;
- }
-}
View
55 mongodb-morph/phar/PharMetadata.php
@@ -1,55 +0,0 @@
-<?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 'phar/PharMetadataElement.php';
-
-/**
- * @package phing.tasks.ext.phar
- * @author Alexey Shockov <alexey@shockov.com>
- * @since 2.4.0
- */
-class PharMetadata
-{
- /**
- * @var array
- */
- protected $elements = array();
- /**
- * @return PharMetadataElement
- */
- public function createElement()
- {
- return ($this->elements[] = new PharMetadataElement());
- }
- /**
- * @return array
- */
- public function toArray()
- {
- $metadata = array();
-
- foreach ($this->elements as $element) {
- $metadata[$element->getName()] = $element->toArray();
- }
-
- return $metadata;
- }
-}
View
80 mongodb-morph/phar/PharMetadataElement.php
@@ -1,80 +0,0 @@
-<?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 'phar/PharMetadata.php';
-
-/**
- * @package phing.tasks.ext.phar
- * @author Alexey Shockov <alexey@shockov.com>
- * @since 2.4.0
- */
-class PharMetadataElement
- extends PharMetadata
-{
- /**
- * @var string
- */
- private $name;
- /**
- * @var string
- */
- private $value;
- /**
- * @param string $value
- */
- public function setValue($value)
- {
- $this->value = $value;
- }
- /**
- * @param string $name
- */
- public function setName($name)
- {
- $this->name = $name;
- }
- /**
- * @return string
- */
- public function getName()
- {
- return $this->name;
- }
- /**
- * Return array of
- *
- * @return string|array
- */
- public function getValue()
- {
- /*
- * Elements first!
- */
- return (empty($this->elements) ? $this->value : $this->elements);
- }
- /**
- * @return string|array
- */
- public function toArray()
- {
- return (empty($this->elements) ? $this->value : parent::toArray());
- }
-}
View
302 mongodb-morph/phar/PharPackageTask2.php
@@ -1,302 +0,0 @@
-<?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';
-//require_once 'phar/IterableFileSet.php';
-//require_once 'phar/PharMetadata.php';
-
-/**
- * Package task for {@link http://ru.php.net/manual/en/book.phar.php Phar technology}.
- *
- * @package phing.tasks.ext
- * @author Alexey Shockov <alexey@shockov.com>
- * @since 2.4.0
- */
-class PharPackageTask2
-extends MatchingTask
-{
- /**
- * @var PhingFile
- */
- private $destinationFile;
- /**
- * @var int
- */
- private $compression = Phar::NONE;
- /**
- * Base directory, from where local package paths will be calculated.
- *
- * @var PhingFile
- */
- private $baseDirectory;
- /**
- * @var PhingFile
- */
- private $cliStubFile;
- /**
- * @var PhingFile
- */
- private $webStubFile;
- /**
- * @var string
- */
- private $customStubPath;
- /**
- * @var int
- */
- private $signatureAlgorithm = Phar::SHA1;
- /**
- * @var array
- */
- private $filesets = array();
- /**
- * @var PharMetadata
- */
- private $metadata;
- /**
- * @var string
- */
- private $alias;
-
- /**
- * @return PharMetadata
- */
- public function createMetadata()
- {
- return ($this->metadata = new PharMetadata());
- }
- /**
- * @return FileSet
- */
- public function createFileSet()
- {
- $this->fileset = new IterableFileSet();
- $this->filesets[] = $this->fileset;
- return $this->fileset;
- }
- /**
- * @param string $algorithm
- */
- public function setSignature($algorithm)
- {
- /*
- * If we don't support passed algprithm, leave old one.
- */
- if (in_array($algorithm, array('md5', 'sha1', 'sha256', 'sha512'))) {
- switch ($algorithm) {
- case 'md5':
- $this->compression = Phar::MD5;
- break;
- case 'sha1':
- $this->compression = Phar::SHA1;
- break;
- case 'sha256':
- $this->compression = Phar::SHA256;
- break;
- case 'sha512':
- $this->compression = Phar::SHA512;
- break;
- }
- }
- }
- /**
- * @param string $compression
- */
- public function setCompression($compression)
- {
- /*
- * If we don't support passed compression, leave old one.
- */
- if (in_array($compression, array('gzip', 'bzip2'))) {
- switch ($compression) {
- case 'gzip':
- $this->compression = Phar::GZ;
- break;
- case 'bzip2':
- $this->compression = Phar::BZ2;
- break;
- }
- }
- }
- /**
- * @param PhingFile $destinationFile
- */
- public function setDestFile(PhingFile $destinationFile)
- {
- $this->destinationFile = $destinationFile;
- }
- /**
- * @param PhingFile $baseDirectory
- */
- public function setBaseDir(PhingFile $baseDirectory)
- {
- $this->baseDirectory = $baseDirectory;
- }
- /**
- * @param PhingFile $stubFile
- */
- public function setCliStub(PhingFile $stubFile)
- {
- $this->cliStubFile = $stubFile;
- }
- /**
- * @param PhingFile $stubFile
- */
- public function setWebStub(PhingFile $stubFile)
- {
- $this->webStubFile = $stubFile;
- }
- /**
- *
- * @param PhingFile$stubFile
- */
- public function setCustomStub($stubPath)
- {
- $this->customStubPath = $stubPath;
- }
- /**
- * @param $alias
- */
- public function setAlias($alias)
- {
- $this->alias = $alias;
- }
-
- /**
- * @throws BuildException
- */
- public function main()
- {
- $this->checkPreconditions();
-
- try {
- $this->log(
- 'Building package: '.$this->destinationFile->__toString(),
- Project::MSG_INFO
- );
-
- /*
- * Delete old package, if exists.
- */
- if ($this->destinationFile->exists()) {
- /*
- * TODO Check operation for errors...
- */
- $this->destinationFile->delete();
- }
-
- $phar = $this->buildPhar();
- $phar->startBuffering();
-
- $baseDirectory = realpath($this->baseDirectory->getPath());
-
- foreach ($this->filesets as $fileset) {
- foreach ($fileset as $realFileName) {
- /*
- * Calculate local file name.
- */
- $localFileName = $realFileName;
- if (0 === strpos($realFileName, $baseDirectory)) {
- $localFileName = substr(
- $realFileName,
- strlen($baseDirectory)
- );
- }
-
- $this->log(
- 'Adding '.$realFileName.' as '.$localFileName.' to package',
- Project::MSG_VERBOSE
- );
-
- $phar->addFile($realFileName, $localFileName);
- }
- }
-
- $phar->stopBuffering();
- } catch (Exception $e) {
- throw new BuildException(
- 'Problem creating package: '.$e->getMessage(),
- $e,
- $this->getLocation()
- );
- }
- }
- /**
- * @throws BuildException
- */
- private function checkPreconditions()
- {
- if (is_null($this->destinationFile)) {
- throw new BuildException("destfile attribute must be set!", $this->getLocation());
- }
-
- if ($this->destinationFile->exists() && $this->destinationFile->isDirectory()) {
- throw new BuildException("destfile is a directory!", $this->getLocation());
- }
-
- if (!$this->destinationFile->canWrite()) {
- throw new BuildException("Can not write to the specified destfile!", $this->getLocation());
- }
- if (!is_null($this->baseDirectory)) {
- if (!$this->baseDirectory->exists()) {
- throw new BuildException("basedir does not exist!", $this->getLocation());
- }
- }
- }
- /**
- * Build and configure Phar object.
- *
- * @return Phar
- */
- private function buildPhar()
- {
- $phar = new Phar($this->destinationFile,0, $this->alias);
-
- $phar->setSignatureAlgorithm($this->signatureAlgorithm);
-
- /*
- * File compression, if needed.
- */
- if (Phar::NONE != $this->compression) {
- $phar->compressFiles($this->compression);
- }
-
- if(isset($this->customStubPath)){
- $phar->setStub(file_get_contents($this->customStubPath));
- }else{
- $phar->setDefaultStub(
- $this->cliStubFile,
- $this->webStubFile
- );
- }
-
-
- if ($metadata = $this->metadata->toArray()) {
- $phar->setMetadata($metadata);
- }
-
- if(!empty($this->alias)){
- $phar->setAlias($this->alias);
- }
-
- return $phar;
- }
-}

0 comments on commit 8a141c1

Please sign in to comment.
Something went wrong with that request. Please try again.