From: Gunnar Wrobel
Date: Mon, 25 Oct 2010 16:45:51 +0000 (+0200) Subject: Allow creating new package.xml files from scratch when using the -u option. Also... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=6ed3aaf10efd76798262c199c7e26160e9d4771a;p=horde.git Allow creating new package.xml files from scratch when using the -u option. Also add the horde role if required. --- diff --git a/components/TODO b/components/TODO index 8bce255ff..ba0716232 100644 --- a/components/TODO +++ b/components/TODO @@ -6,8 +6,6 @@ - Add module for generating component documentation. - - 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. diff --git a/components/lib/Components.php b/components/lib/Components.php index eb9ec43c1..3857768b4 100644 --- a/components/lib/Components.php +++ b/components/lib/Components.php @@ -110,9 +110,5 @@ class Components if (!is_dir($arguments[0])) { throw new Components_Exception(sprintf('%s specifies no directory!', $arguments[0])); } - - if (!file_exists($arguments[0] . '/package.xml')) { - throw new Components_Exception(sprintf('There is no package.xml at %s!', $arguments[0])); - } } } \ No newline at end of file diff --git a/components/lib/Components/Config.php b/components/lib/Components/Config.php index 02c9dcfe3..2b681cbce 100644 --- a/components/lib/Components/Config.php +++ b/components/lib/Components/Config.php @@ -50,4 +50,12 @@ interface Components_Config * @return array An array of arguments. */ public function getArguments(); + + /** + * Return the first argument - the package directory - provided by the + * configuration handlers. + * + * @return string The package directory. + */ + public function getPackageDirectory(); } \ No newline at end of file diff --git a/components/lib/Components/Config/Cli.php b/components/lib/Components/Config/Cli.php index 3b8b76890..c9968cf62 100644 --- a/components/lib/Components/Config/Cli.php +++ b/components/lib/Components/Config/Cli.php @@ -148,6 +148,18 @@ implements Components_Config } /** + * Return the first argument - the package directory - provided by the + * configuration handlers. + * + * @return string The package directory. + */ + public function getPackageDirectory() + { + $arguments = $this->getArguments(); + return $arguments[0]; + } + + /** * Add an option group from the provided module to the parser. * * @param Horde_Argv_Parser $parser The parser. diff --git a/components/lib/Components/Configs.php b/components/lib/Components/Configs.php index c66d84f81..11d89033c 100644 --- a/components/lib/Components/Configs.php +++ b/components/lib/Components/Configs.php @@ -105,4 +105,16 @@ implements Components_Config } return $arguments; } + + /** + * Return the first argument - the package directory - provided by the + * configuration handlers. + * + * @return string The package directory. + */ + public function getPackageDirectory() + { + $arguments = $this->getArguments(); + return $arguments[0]; + } } \ No newline at end of file diff --git a/components/lib/Components/Module/Base.php b/components/lib/Components/Module/Base.php index 2c37f4581..54091ddb9 100644 --- a/components/lib/Components/Module/Base.php +++ b/components/lib/Components/Module/Base.php @@ -46,4 +46,18 @@ implements Components_Module { $this->_dependencies = $dependencies; } + + /** + * Validate that there is a package.xml file in the provided directory. + * + * @param string $directory The package directory. + * + * @return NULL + */ + protected function requirePackageXml($directory) + { + if (!file_exists($directory . '/package.xml')) { + throw new Components_Exception(sprintf('There is no package.xml at %s!', $directory)); + } + } } \ No newline at end of file diff --git a/components/lib/Components/Module/CiSetup.php b/components/lib/Components/Module/CiSetup.php index f528b2a98..e3e0d638e 100644 --- a/components/lib/Components/Module/CiSetup.php +++ b/components/lib/Components/Module/CiSetup.php @@ -75,9 +75,11 @@ extends Components_Module_Base $options = $config->getOptions(); //@todo Split into two different runners here if (!empty($options['cisetup'])) { + $this->requirePackageXml($config->getPackageDirectory()); $this->_dependencies->getRunnerCiSetup()->run(); } if (!empty($options['ciprebuild'])) { + $this->requirePackageXml($config->getPackageDirectory()); $this->_dependencies->getRunnerCiPrebuild()->run(); } } diff --git a/components/lib/Components/Module/Dependencies.php b/components/lib/Components/Module/Dependencies.php index 449d83a6d..8cf4da79f 100644 --- a/components/lib/Components/Module/Dependencies.php +++ b/components/lib/Components/Module/Dependencies.php @@ -79,6 +79,7 @@ extends Components_Module_Base { $options = $config->getOptions(); if (!empty($options['list_deps'])) { + $this->requirePackageXml($config->getPackageDirectory()); $this->_dependencies->getRunnerDependencies()->run(); } } diff --git a/components/lib/Components/Module/DevPackage.php b/components/lib/Components/Module/DevPackage.php index 011645f96..e8cdacaa8 100644 --- a/components/lib/Components/Module/DevPackage.php +++ b/components/lib/Components/Module/DevPackage.php @@ -58,6 +58,7 @@ extends Components_Module_Base { $options = $config->getOptions(); if (!empty($options['devpackage'])) { + $this->requirePackageXml($config->getPackageDirectory()); $this->_dependencies->getRunnerDevPackage()->run(); } } diff --git a/components/lib/Components/Module/Distribute.php b/components/lib/Components/Module/Distribute.php index 547bb5906..f10ec8a59 100644 --- a/components/lib/Components/Module/Distribute.php +++ b/components/lib/Components/Module/Distribute.php @@ -79,6 +79,7 @@ extends Components_Module_Base { $options = $config->getOptions(); if (!empty($options['distribute'])) { + $this->requirePackageXml($config->getPackageDirectory()); $this->_dependencies->getRunnerDistribute()->run(); } } diff --git a/components/lib/Components/Module/Installer.php b/components/lib/Components/Module/Installer.php index 011d3666b..9b6f06e25 100644 --- a/components/lib/Components/Module/Installer.php +++ b/components/lib/Components/Module/Installer.php @@ -95,6 +95,7 @@ extends Components_Module_Base { $options = $config->getOptions(); if (!empty($options['install'])) { + $this->requirePackageXml($config->getPackageDirectory()); $this->_dependencies->getRunnerInstaller()->run(); } } diff --git a/components/lib/Components/Pear/Factory.php b/components/lib/Components/Pear/Factory.php index 3ed4f8305..f0c7e11ea 100644 --- a/components/lib/Components/Pear/Factory.php +++ b/components/lib/Components/Pear/Factory.php @@ -173,6 +173,56 @@ class Components_Pear_Factory } /** + * Create a new PEAR Package representation. + * + * @param string $package_xml_dir Path to the parent directory of the package.xml file. + * @param Components_Pear_InstallLocation $environment The PEAR environment. + * + * @return PEAR_PackageFile + */ + public function createPackageFile( + $package_xml_dir + ) + { + $environment = $this->_dependencies->getInstance('Components_Pear_InstallLocation'); + $pkg = new PEAR_PackageFile_v2_rw(); + $pkg->setPackage('REPLACE'); + $pkg->setDescription('REPLACE'); + $pkg->setSummary('REPLACE'); + $pkg->setReleaseVersion('0.0.1'); + $pkg->setApiVersion('0.0.1'); + $pkg->setReleaseStability('alpha'); + $pkg->setApiStability('alpha'); + $pkg->setChannel('pear.horde.org'); + $pkg->addMaintainer( + 'lead', + 'chuck', + 'Chuck Hagenbuch', + 'chuck@horde.org' + ); + $pkg->addMaintainer( + 'lead', + 'jan', + 'Jan Schneider', + 'jan@horde.org' + ); + $pkg->setLicense('REPLACE', 'REPLACE'); + $pkg->setNotes('* Initial release.'); + $pkg->clearContents(); + $pkg->clearDeps(); + $pkg->setPhpDep('5.2.0'); + $pkg->setPearinstallerDep('1.9.0'); + $pkg->setPackageType('php'); + new PEAR_Validate(); + $package_file = $pkg->getDefaultGenerator() + ->toPackageFile($package_xml_dir, 0); + if ($package_file instanceOf PEAR_Error) { + throw new Components_Exception($package_file->getMessage()); + }; + return $package_file; + } + + /** * Return a writeable PEAR Package representation. * * @param string $package_xml_path Path to the package.xml file. diff --git a/components/lib/Components/Pear/Package.php b/components/lib/Components/Pear/Package.php index 60450bb21..6de68a62d 100644 --- a/components/lib/Components/Pear/Package.php +++ b/components/lib/Components/Pear/Package.php @@ -317,6 +317,7 @@ class Components_Pear_Package $contents = $package->getContents(); $files = $contents['dir']['file']; + $horde_role = false; foreach ($files as $file) { $components = explode('/', $file['attribs']['name'], 2); @@ -331,6 +332,7 @@ class Components_Pear_Package ); break; case 'js': + $horde_role = true; case 'locale': $package->addInstallAs( $file['attribs']['name'], $file['attribs']['name'] @@ -355,6 +357,27 @@ class Components_Pear_Package break; } } + + if ($horde_role) { + $roles = $package->getUsesrole(); + if (!empty($roles)) { + if (isset($roles['role'])) { + $roles = array($roles); + } + foreach ($roles as $role) { + if (isset($role['role']) && $role['role'] == 'horde') { + $horde_role = false; + break; + } + } + } + if ($horde_role) { + $package->addUsesrole( + 'horde', 'Role', 'pear.horde.org' + ); + } + } + return $package; } diff --git a/components/lib/Components/Runner/PearPackageXml.php b/components/lib/Components/Runner/PearPackageXml.php index 708e5d8b7..c63985e9b 100644 --- a/components/lib/Components/Runner/PearPackageXml.php +++ b/components/lib/Components/Runner/PearPackageXml.php @@ -63,6 +63,10 @@ class Components_Runner_PearPackageXml $arguments = $this->_config->getArguments(); $options = $this->_config->getOptions(); + if (!file_exists($arguments[0] . '/package.xml')) { + $this->_factory->createPackageFile($arguments[0]); + } + if (isset($options['pearrc'])) { $package = $this->_factory->createPackageForInstallLocation( $arguments[0] . '/package.xml', diff --git a/components/test/Components/Integration/Components/Module/PearPackageXmlTest.php b/components/test/Components/Integration/Components/Module/PearPackageXmlTest.php index f0582b392..e579062eb 100644 --- a/components/test/Components/Integration/Components/Module/PearPackageXmlTest.php +++ b/components/test/Components/Integration/Components/Module/PearPackageXmlTest.php @@ -82,19 +82,6 @@ extends Components_StoryTestCase /** * @scenario */ - public function thePOptionFailsWithoutAValidPackage() - { - $this->given('the default Components setup') - ->when( - 'calling the package with the packagexml option and the path', - dirname(dirname(dirname(dirname(__FILE__)))) . '/fixture' - ) - ->then('the call will fail with', 'There is no package.xml at'); - } - - /** - * @scenario - */ public function thePOptionProvidesAnUpdatedPackageXml() { $this->given('the default Components setup')