From: Gunnar Wrobel Date: Thu, 28 Oct 2010 19:04:38 +0000 (+0200) Subject: Add a Horde specific repo layout handler that allows components to deal with all... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=d3a023730d83b7ee69cda2fb18c0e9218aba6985;p=horde.git Add a Horde specific repo layout handler that allows components to deal with all types of packages we currently offer. --- diff --git a/components/TODO b/components/TODO index 294802fb2..52a72db27 100644 --- a/components/TODO +++ b/components/TODO @@ -6,8 +6,6 @@ - Add module for generating component documentation. - - Allow handling various Horde package locations (horde/, horde/framework/, Horde_SQL -> horde/framework/SQL) - - Allow linking files during the installation. - Allow filtering (see http://github.com/horde/horde/commit/404e8d1ea7c0bf99373aec2ce7f2534a442149b3) diff --git a/components/lib/Components/Helper/Root.php b/components/lib/Components/Helper/Root.php new file mode 100644 index 000000000..2f350b5cf --- /dev/null +++ b/components/lib/Components/Helper/Root.php @@ -0,0 +1,93 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Components + */ + +/** + * Components_Helper_Root:: handles the root position for a tree of dependencies + * and takes the Horde component layout into account. + * + * 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_Helper_Root +{ + /** + * Root path of the Horde repository. + * + * @var string + */ + private $_root_path; + + /** + * Constructor. + * + * @param string $path The helper will try to determine the root of the + * Horde repository based on this path. + */ + public function __construct($path) + { + $i = 0; + $root = 0; + $current = $path; + while ($current != '/' || $i < 10) { + if (is_dir($current)) { + $objects = scandir($current); + if (in_array('framework', $objects) && in_array('horde', $objects)) { + $this->_root_path = $current; + break; + } + } + $current = dirname($current); + $i++; + } + if ($i >= 10) { + throw new Components_Exception(sprintf('Unable to determine Horde root from path %s!', $path)); + } + } + + /** + * Return the path to the package.xml for the package with the provided + * name. + * + * @param string $name The name of the package. + * + * @return string The path to the package.xml of the requested package. + */ + public function getPackageXml($name) + { + $package_file = $this->_root_path . DIRECTORY_SEPARATOR + . $name . DIRECTORY_SEPARATOR . 'package.xml'; + if (!file_exists($package_file)) { + $package_file = $this->_root_path . DIRECTORY_SEPARATOR + . 'framework' . DIRECTORY_SEPARATOR . $name + . DIRECTORY_SEPARATOR . 'package.xml'; + } + if (!file_exists($package_file) && substr($name, 0, 6) == 'Horde_') { + $package_file = $this->_root_path . DIRECTORY_SEPARATOR + . 'framework' . DIRECTORY_SEPARATOR . substr($name, 6) + . DIRECTORY_SEPARATOR . 'package.xml'; + } + if (!file_exists($package_file)) { + throw new Components_Exception(sprintf('Unknown package %s.', $name)); + } + return $package_file; + } +} \ No newline at end of file diff --git a/components/lib/Components/Helper/Tree.php b/components/lib/Components/Helper/Tree.php index 65b3e24d5..a3985f1f4 100644 --- a/components/lib/Components/Helper/Tree.php +++ b/components/lib/Components/Helper/Tree.php @@ -1,7 +1,6 @@ _factory = $factory; $this->_environment = $environment; - $this->_root_path = $root_path; + $this->_root = $root; } /** @@ -83,8 +81,8 @@ class Components_Helper_Tree public function installTreeInEnvironment( $package_file, Components_Output $output, - array $options) - { + array $options + ) { $run = new Components_Helper_InstallationRun($this->_environment, $this, $output, $options); $run->install($this->_getHordeChildElement($package_file)); } @@ -119,15 +117,8 @@ class Components_Helper_Tree { $children = array(); foreach ($dependencies as $dependency) { - $package_file = $this->_root_path . DIRECTORY_SEPARATOR - . $dependency->name() . DIRECTORY_SEPARATOR . 'package.xml'; - if (!file_exists($package_file)) { - $package_file = $this->_root_path . DIRECTORY_SEPARATOR - . 'framework' . DIRECTORY_SEPARATOR . $dependency->name() - . DIRECTORY_SEPARATOR . 'package.xml'; - } $children[$dependency->key()] = $this->_getHordeChildElement( - $package_file + $this->_root->getPackageXml($dependency->name()) ); } return $children; diff --git a/components/lib/Components/Pear/Factory.php b/components/lib/Components/Pear/Factory.php index 70d525eae..691792594 100644 --- a/components/lib/Components/Pear/Factory.php +++ b/components/lib/Components/Pear/Factory.php @@ -158,7 +158,9 @@ class Components_Pear_Factory basename($config_file) ); $environment->setResourceDirectories($options); - return new Components_Helper_Tree($this, $environment, $root_path); + return new Components_Helper_Tree( + $this, $environment, new Components_Helper_Root($root_path) + ); } /** @@ -170,12 +172,12 @@ class Components_Pear_Factory * * @return Components_Helper_Tree The tree helper. */ - public function createSimpleTreeHelper( $root_path) + public function createSimpleTreeHelper($root_path) { return new Components_Helper_Tree( $this, $this->_dependencies->createInstance('Components_Pear_InstallLocation'), - $root_path + new Components_Helper_Root($root_path) ); } diff --git a/components/lib/Components/Runner/Dependencies.php b/components/lib/Components/Runner/Dependencies.php index f5375eb25..131b0dc8a 100644 --- a/components/lib/Components/Runner/Dependencies.php +++ b/components/lib/Components/Runner/Dependencies.php @@ -72,7 +72,7 @@ class Components_Runner_Dependencies $options = $this->_config->getOptions(); $arguments = $this->_config->getArguments(); $this->_factory - ->createSimpleTreeHelper(dirname(realpath($arguments[0]))) + ->createSimpleTreeHelper(realpath($arguments[0])) ->listDependencyTree( realpath($arguments[0]) . DIRECTORY_SEPARATOR . 'package.xml', $this->_output diff --git a/components/lib/Components/Runner/Installer.php b/components/lib/Components/Runner/Installer.php index 16a79c79a..6296aaaff 100644 --- a/components/lib/Components/Runner/Installer.php +++ b/components/lib/Components/Runner/Installer.php @@ -79,7 +79,7 @@ class Components_Runner_Installer $arguments = $this->_config->getArguments(); $tree = $this->_factory ->createTreeHelper( - $environment, dirname(realpath($arguments[0])), $options + $environment, realpath($arguments[0]), $options ); $tree->getEnvironment()->provideChannel('pear.horde.org'); $tree->installTreeInEnvironment( diff --git a/components/test/Components/Integration/Components/Module/InstallerTest.php b/components/test/Components/Integration/Components/Module/InstallerTest.php index ced13e4f4..8d97fbcd2 100644 --- a/components/test/Components/Integration/Components/Module/InstallerTest.php +++ b/components/test/Components/Integration/Components/Module/InstallerTest.php @@ -55,6 +55,7 @@ extends Components_StoryTestCase ->then('the dummy PEAR package will be listed') ->and('the non-Horde dependencies of the component would be installed') ->and('the Horde dependencies of the component would be installed') + ->and('the old-style Horde dependencies of the component would be installed') ->and('the component will be listed'); } diff --git a/components/test/Components/StoryTestCase.php b/components/test/Components/StoryTestCase.php index 2bafe62a6..6e0e36934 100644 --- a/components/test/Components/StoryTestCase.php +++ b/components/test/Components/StoryTestCase.php @@ -461,6 +461,13 @@ extends PHPUnit_Extensions_Story_TestCase $trimmed ); break; + case 'the old-style Horde dependencies of the component would be installed': + $trimmed = strtr($world['output'], array(' ' => '', "\n" => '')); + $this->assertRegExp( + '#Wouldinstallpackage.*Old/package.xml#', + $trimmed + ); + break; case 'the Optional package will be listed': $trimmed = strtr($world['output'], array(' ' => '', "\n" => '')); $this->assertRegExp( diff --git a/components/test/Components/fixture/framework/Dependency/package.xml b/components/test/Components/fixture/framework/Dependency/package.xml index 720ec5713..4db725f08 100644 --- a/components/test/Components/fixture/framework/Dependency/package.xml +++ b/components/test/Components/fixture/framework/Dependency/package.xml @@ -46,6 +46,10 @@ pear.horde.org + Horde_Old + pear.horde.org + + Console_Getopt pear.php.net diff --git a/components/test/Components/fixture/framework/Old/lib/Old.php b/components/test/Components/fixture/framework/Old/lib/Old.php new file mode 100644 index 000000000..a81436628 --- /dev/null +++ b/components/test/Components/fixture/framework/Old/lib/Old.php @@ -0,0 +1 @@ + + + Horde_Old + pear.horde.org + Test fixture. + A dummy package.xml used for testing the Components package. + + Gunnar Wrobel + wrobel + p@rdus.de + yes + + 2010-08-22 + + + 0.0.1 + 0.0.1 + + + alpha + alpha + + LGPL + +* Initial release + + + + + + + + + + + + 5.0.0 + + + 1.7.0 + + + Console_Getopt + pear.php.net + + + + + PECL + pecl.php.net + + + + + + + + + + + + 0.0.1 + 0.0.1 + + + alpha + alpha + + 2010-08-22 + LGPL + +* Initial release + + + + diff --git a/components/test/Components/fixture/horde/.keep b/components/test/Components/fixture/horde/.keep new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/components/test/Components/fixture/horde/.keep @@ -0,0 +1 @@ +