From 94798dc81432ea6b831fe2bd4276f22e47fbc336 Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel Date: Wed, 13 Oct 2010 23:54:11 +0200 Subject: [PATCH] Add the packaging tool. --- components/TODO | 4 -- components/data/distribute_package.spec | 2 + components/lib/Components/Module/Distribute.php | 4 +- components/lib/Components/Runner/Distribute.php | 59 +++++++++++++++++++--- components/package.xml | 28 ++++++++-- .../Components/Module/DistributeTest.php | 57 +++++++++++++++++++++ components/test/Components/StoryTestCase.php | 16 ++++++ 7 files changed, 154 insertions(+), 16 deletions(-) create mode 100644 components/data/distribute_package.spec create mode 100644 components/test/Components/Integration/Components/Module/DistributeTest.php diff --git a/components/TODO b/components/TODO index 01bc3494d..e8bdc8aa3 100644 --- a/components/TODO +++ b/components/TODO @@ -4,8 +4,6 @@ - Document usage - - Do the distribution runner. - - Add module for generating component documentation. - Add module for an initial empty PEAR template @@ -21,6 +19,4 @@ - Allow absolute/relative paths as arguments - - Fail on missing dependencies in a decent way - - WWW frontend diff --git a/components/data/distribute_package.spec b/components/data/distribute_package.spec new file mode 100644 index 000000000..38e9b831c --- /dev/null +++ b/components/data/distribute_package.spec @@ -0,0 +1,2 @@ + 'store', - 'help' => 'Prepare the component package in the specified DISTRIBUTE location' + 'help' => 'Prepare the package definition for the component in the specified DISTRIBUTE location' ) ), ); diff --git a/components/lib/Components/Runner/Distribute.php b/components/lib/Components/Runner/Distribute.php index e437e36ac..e0f59761c 100644 --- a/components/lib/Components/Runner/Distribute.php +++ b/components/lib/Components/Runner/Distribute.php @@ -37,24 +37,36 @@ class Components_Runner_Distribute private $_config; /** - * The package handler. + * The application configuration. * - * @var Components_Pear_Package + * @var Components_Config_Application */ - private $_package; + private $_config_application; + + /** + * The factory for PEAR dependencies. + * + * @var Components_Pear_Factory + */ + private $_factory; /** * Constructor. * - * @param Components_Config $config The configuration for the current job. - * @param Components_Pear_Package $package Package handler. + * @param Components_Config $config The configuration for the current job. + * @param Components_Config_Application $cfgapp The application + * configuration. + * @param Components_Pear_Factory $factory The factory for PEAR + * dependencies. */ public function __construct( Components_Config $config, - Components_Pear_Package $package + Components_Config_Application $cfgapp, + Components_Pear_Factory $factory ) { $this->_config = $config; - $this->_package = $package; + $this->_config_application = $cfgapp; + $this->_factory = $factory; } public function run() @@ -63,5 +75,38 @@ class Components_Runner_Distribute $arguments = $this->_config->getArguments(); $location = realpath($options['distribute']); + $template = null; + foreach ( + new RecursiveIteratorIterator( + new RecursiveDirectoryIterator( + $this->_config_application->getTemplateDirectory() + ), + RecursiveIteratorIterator::CHILD_FIRST + ) + as $file + ) { + if (strpos($file->getBasename(), 'distribute_') === 0) { + $template = $file; + break; + } + } + if (empty($template)) { + throw new Components_Exception( + sprintf( + 'No packaging template starting with "distribute_" was found in the template directoy %s!', + $this->_config_application->getTemplateDirectory() + ) + ); + } + + ob_start(); + include $template->getPathname(); + $packaging = ob_get_clean(); + + file_put_contents( + realpath($options['distribute']) . DIRECTORY_SEPARATOR + . substr($template->getBasename(), 11), + $packaging + ); } } diff --git a/components/package.xml b/components/package.xml index d14185ea6..fd11f2f1a 100644 --- a/components/package.xml +++ b/components/package.xml @@ -24,8 +24,8 @@ jan@horde.org yes - 2010-10-12 - + 2010-10-13 + 0.0.1 0.0.1 @@ -41,6 +41,7 @@ + @@ -54,9 +55,18 @@ + + + + + + + + + @@ -70,6 +80,7 @@ + @@ -156,6 +167,8 @@ + + @@ -218,6 +231,7 @@ + @@ -233,8 +247,13 @@ + + + + + @@ -244,6 +263,7 @@ + @@ -274,6 +294,8 @@ + + @@ -290,7 +312,7 @@ alpha alpha - 2010-10-12 + 2010-10-13 LGPL * Initial release diff --git a/components/test/Components/Integration/Components/Module/DistributeTest.php b/components/test/Components/Integration/Components/Module/DistributeTest.php new file mode 100644 index 000000000..0cfd6296d --- /dev/null +++ b/components/test/Components/Integration/Components/Module/DistributeTest.php @@ -0,0 +1,57 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Components + */ + +/** + * Prepare the test setup. + */ +require_once dirname(__FILE__) . '/../../../Autoload.php'; + +/** + * Test the Distribute module. + * + * 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 + * @subpackage UnitTests + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Components + */ +class Components_Integration_Components_Module_DistributeTest +extends Components_StoryTestCase +{ + /** + * @scenario + */ + public function theDistributeModuleAddsTheDOptionInTheHelpOutput() + { + $this->given('the default Components setup') + ->when('calling the package with the help option') + ->then('the help will contain the option', '-D\s*DISTRIBUTE,\s*--distribute=DISTRIBUTE'); + } + + /** + * @scenario + */ + public function theTheDOptionGeneratesAPackageDefinitionFile() + { + $this->given('the default Components setup') + ->when('calling the package with the distribute option and a path to a Horde framework component') + ->then('a package definition will be generated at the indicated location'); + } +} \ No newline at end of file diff --git a/components/test/Components/StoryTestCase.php b/components/test/Components/StoryTestCase.php index 4f9fa0c5b..2e6676843 100644 --- a/components/test/Components/StoryTestCase.php +++ b/components/test/Components/StoryTestCase.php @@ -208,6 +208,14 @@ extends PHPUnit_Extensions_Story_TestCase ); $world['output'] = $this->_callUnstrictComponents(); break; + case 'calling the package with the distribute option and a path to a Horde framework component': + $_SERVER['argv'] = array( + 'horde-components', + '--distribute=' . $this->_getTemporaryDirectory(), + dirname(__FILE__) . '/fixture/framework/Install' + ); + $world['output'] = $this->_callUnstrictComponents(); + break; default: return $this->notImplemented($action); } @@ -406,6 +414,14 @@ extends PHPUnit_Extensions_Story_TestCase $world['output'] ); break; + case 'a package definition will be generated at the indicated location': + $this->assertTrue( + file_exists( + $this->_temp_dir . DIRECTORY_SEPARATOR + . 'package.spec' + ) + ); + break; default: return $this->notImplemented($action); } -- 2.11.0