From: Gunnar Wrobel Date: Fri, 22 Oct 2010 21:51:21 +0000 (+0200) Subject: Move snapshot packaging and package distribution into the Pear module of Components. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=3ce8301d03677cdde2761348823c723e724de48e;p=horde.git Move snapshot packaging and package distribution into the Pear module of Components. --- diff --git a/components/TODO b/components/TODO index e8bdc8aa3..8bce255ff 100644 --- a/components/TODO +++ b/components/TODO @@ -8,6 +8,9 @@ - Add module for an initial empty PEAR template + - Allow filtering (see http://github.com/horde/horde/commit/404e8d1ea7c0bf99373aec2ce7f2534a442149b3) + Potentially check with git if the file is relevant or not. + - Add a commit module that automatically adds a changelog entry in the notes section of the package.xml diff --git a/components/lib/Components/Dependencies.php b/components/lib/Components/Dependencies.php index c926bc3f5..bddd35a6d 100644 --- a/components/lib/Components/Dependencies.php +++ b/components/lib/Components/Dependencies.php @@ -53,6 +53,13 @@ interface Components_Dependencies public function getRunnerCiPrebuild(); /** + * Returns the snapshot packaging handler for a package. + * + * @return Components_Runner_DevPackage The snapshot handler. + */ + public function getRunnerDevPackage(); + + /** * Returns the distribution handler for a package. * * @return Components_Runner_Distribute The distribution handler. diff --git a/components/lib/Components/Dependencies/Injector.php b/components/lib/Components/Dependencies/Injector.php index 8825cec09..c31784ee9 100644 --- a/components/lib/Components/Dependencies/Injector.php +++ b/components/lib/Components/Dependencies/Injector.php @@ -83,6 +83,16 @@ implements Components_Dependencies } /** + * Returns the snapshot packaging handler for a package. + * + * @return Components_Runner_DevPackage The snapshot handler. + */ + public function getRunnerDevPackage() + { + return $this->getInstance('Components_Runner_DevPackage'); + } + + /** * Returns the dependency list handler for a package. * * @return Components_Runner_Dependencies The dependency handler. diff --git a/components/lib/Components/Module/DevPackage.php b/components/lib/Components/Module/DevPackage.php index 09f406faf..011645f96 100644 --- a/components/lib/Components/Module/DevPackage.php +++ b/components/lib/Components/Module/DevPackage.php @@ -28,7 +28,7 @@ * @link http://pear.horde.org/index.php?package=Components */ class Components_Module_DevPackage -implements Components_Module +extends Components_Module_Base { public function getOptionGroupTitle() { @@ -58,25 +58,7 @@ implements Components_Module { $options = $config->getOptions(); if (!empty($options['devpackage'])) { - $this->run($config); + $this->_dependencies->getRunnerDevPackage()->run(); } } - - public function run(Components_Config $config) - { - $options = $config->getOptions(); - - $pear = new PEAR(); - $pear->setErrorHandling(PEAR_ERROR_DIE); - - $arguments = $config->getArguments(); - $pkgfile = $arguments[0] . DIRECTORY_SEPARATOR . 'package.xml'; - - $pkg = new PEAR_PackageFile(new PEAR_Config()); - $pf = $pkg->fromPackageFile($pkgfile, PEAR_VALIDATE_NORMAL); - $pf->_packageInfo['version']['release'] = $pf->getVersion() - . 'dev' . strftime('%Y%m%d%H%M'); - $gen = $pf->getDefaultGenerator(); - $tgzfile = $gen->toTgz(new PEAR_Common()); - } } diff --git a/components/lib/Components/Pear/Package.php b/components/lib/Components/Pear/Package.php index b978607f2..576660677 100644 --- a/components/lib/Components/Pear/Package.php +++ b/components/lib/Components/Pear/Package.php @@ -199,6 +199,36 @@ class Components_Pear_Package } /** + * Return the version for this package. + * + * @return string The package version. + */ + public function getVersion() + { + return $this->_getPackageFile()->getVersion(); + } + + /** + * Return the license for this package. + * + * @return string The package license. + */ + public function getLicense() + { + return $this->_getPackageFile()->getLicense(); + } + + /** + * Return the summary for this package. + * + * @return string The package summary. + */ + public function getSummary() + { + return $this->_getPackageFile()->getSummary(); + } + + /** * Update the content listing of the provided package. * * @param PEAR_PackageFileManager2 $package The package to update. @@ -397,4 +427,28 @@ class Components_Pear_Package return $dependencies; } + /** + * Generate a snapshot of the package using the provided version number. + * + * @param string $varsion The snapshot version. + * + * @return string The path to the snapshot. + */ + public function generateSnapshot($version) + { + $pkg = $this->_getPackageFile(); + $pkg->_packageInfo['version']['release'] = $version; + $pkg->setDate(date('Y-m-d')); + $pkg->setTime(date('H:i:s')); + ob_start(); + $result = $pkg->getDefaultGenerator() + ->toTgz(new PEAR_Common()); + $this->_output->pear(ob_get_clean()); + if ($result instanceOf PEAR_Error) { + throw new Components_Exception($result->getMessage()); + } + $this->_output->ok('Generated snapshot ' . $result); + return $result; + } + } diff --git a/components/lib/Components/Runner/DevPackage.php b/components/lib/Components/Runner/DevPackage.php new file mode 100644 index 000000000..10fa8617d --- /dev/null +++ b/components/lib/Components/Runner/DevPackage.php @@ -0,0 +1,82 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Components + */ + +/** + * Components_Runner_DevPackage:: packages a snapshot. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Horde + * @package Components + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Components + */ +class Components_Runner_DevPackage +{ + /** + * The configuration for the current job. + * + * @var Components_Config + */ + private $_config; + + /** + * The factory for PEAR dependencies. + * + * @var Components_Pear_Factory + */ + private $_factory; + + /** + * The output handler. + * + * @param Component_Output + */ + private $_output; + + /** + * Constructor. + * + * @param Components_Config $config The configuration for the current + * job. + * @param Components_Pear_Factory $factory The factory for PEAR + * dependencies. + * @param Component_Output $output The output handler. + */ + public function __construct( + Components_Config $config, + Components_Pear_Factory $factory, + Components_Output $output + ) { + $this->_config = $config; + $this->_factory = $factory; + $this->_output = $output; + } + + public function run() + { + $options = $this->_config->getOptions(); + $arguments = $this->_config->getArguments(); + + $package = $this->_factory->createPackageForDefaultLocation( + $arguments[0] . DIRECTORY_SEPARATOR . 'package.xml' + ); + $package->generateSnapshot( + $package->getVersion() . 'dev' . strftime('%Y%m%d%H%M') + ); + } +} diff --git a/components/lib/Components/Runner/Distribute.php b/components/lib/Components/Runner/Distribute.php index e0f59761c..ec6f5ad61 100644 --- a/components/lib/Components/Runner/Distribute.php +++ b/components/lib/Components/Runner/Distribute.php @@ -73,7 +73,6 @@ class Components_Runner_Distribute { $options = $this->_config->getOptions(); $arguments = $this->_config->getArguments(); - $location = realpath($options['distribute']); $template = null; foreach ( @@ -99,13 +98,18 @@ class Components_Runner_Distribute ); } + $package = $this->_factory->createPackageForDefaultLocation( + $arguments[0] . DIRECTORY_SEPARATOR . 'package.xml' + ); + $version = $package->getVersion() . 'dev' . strftime('%Y%m%d%H%M'); + $package->generateSnapshot($version); + ob_start(); include $template->getPathname(); $packaging = ob_get_clean(); file_put_contents( - realpath($options['distribute']) . DIRECTORY_SEPARATOR - . substr($template->getBasename(), 11), + $options['distribute'], $packaging ); } diff --git a/components/test/Components/StoryTestCase.php b/components/test/Components/StoryTestCase.php index 2e6676843..1d0c5097d 100644 --- a/components/test/Components/StoryTestCase.php +++ b/components/test/Components/StoryTestCase.php @@ -211,7 +211,7 @@ extends PHPUnit_Extensions_Story_TestCase case 'calling the package with the distribute option and a path to a Horde framework component': $_SERVER['argv'] = array( 'horde-components', - '--distribute=' . $this->_getTemporaryDirectory(), + '--distribute=' . $this->_getTemporaryDirectory() . '/package.spec', dirname(__FILE__) . '/fixture/framework/Install' ); $world['output'] = $this->_callUnstrictComponents();