From: Gunnar Wrobel
Date: Wed, 13 Oct 2010 08:47:44 +0000 (+0200) Subject: Extract parts of the installer into the PEAR module. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=76eefccc3f4871d1c15d827230045a7c7d6be070;p=horde.git Extract parts of the installer into the PEAR module. --- diff --git a/components/lib/Components/Pear/Factory.php b/components/lib/Components/Pear/Factory.php index f6a0421f6..04e0f9ed7 100644 --- a/components/lib/Components/Pear/Factory.php +++ b/components/lib/Components/Pear/Factory.php @@ -53,7 +53,7 @@ class Components_Pear_Factory */ public function createInstallLocation($config_file) { - $install_location = $this->_dependencies->getInstance('Components_Pear_InstallLocation'); + $install_location = $this->_dependencies->createInstance('Components_Pear_InstallLocation'); $install_location->setLocation( dirname($config_file), basename($config_file) @@ -64,6 +64,25 @@ class Components_Pear_Factory /** * Create a package representation for a specific PEAR environment. * + * @param string $package_file The path of the package XML file. + * @param Components_Pear_InstallLocation $environment The PEAR environment. + * + * @return NULL + */ + public function createPackageForEnvironment( + $package_file, + Components_Pear_InstallLocation $environment + ) { + $package = $this->_dependencies->createInstance('Components_Pear_Package'); + $package->setFactory($this); + $package->setEnvironment($environment); + $package->setPackageXml($package_file); + return $package; + } + + /** + * Create a package representation for a specific PEAR environment. + * * @param string $package_file The path of the package XML file. * @param string $config_file The path to the configuration file. * @@ -71,7 +90,7 @@ class Components_Pear_Factory */ public function createPackageForInstallLocation($package_file, $config_file) { - $package = $this->_dependencies->getInstance('Components_Pear_Package'); + $package = $this->_dependencies->createInstance('Components_Pear_Package'); $package->setFactory($this); $package->setEnvironment($this->createInstallLocation($config_file)); $package->setPackageXml($package_file); @@ -87,7 +106,7 @@ class Components_Pear_Factory */ public function createPackageForDefaultLocation($package_file) { - $package = $this->_dependencies->getInstance('Components_Pear_Package'); + $package = $this->_dependencies->createInstance('Components_Pear_Package'); $package->setFactory($this); $package->setEnvironment($this->_dependencies->getInstance('Components_Pear_InstallLocation')); $package->setPackageXml($package_file); diff --git a/components/lib/Components/Pear/InstallLocation.php b/components/lib/Components/Pear/InstallLocation.php index 81b42334e..52987203b 100644 --- a/components/lib/Components/Pear/InstallLocation.php +++ b/components/lib/Components/Pear/InstallLocation.php @@ -275,6 +275,20 @@ class Components_Pear_InstallLocation } } + /** + * Ensure the specified channels exists within the install location. + * + * @param array $channels The list of channels. + * + * @return NULL + */ + public function provideChannels(array $channels) + { + foreach ($channels as $channel) { + $this->provideChannel($channel); + } + } + private function getInstallationHandler() { $installer = new PEAR_Command_Install( diff --git a/components/lib/Components/Pear/Package.php b/components/lib/Components/Pear/Package.php index 44eaa0f00..89126c8dd 100644 --- a/components/lib/Components/Pear/Package.php +++ b/components/lib/Components/Pear/Package.php @@ -336,4 +336,54 @@ class Components_Pear_Package $this->_getUpdatedPackageFile()->writePackageFile(); $this->_output->ok('Successfully updated ' . $this->_package_xml_path); } + + /** + * Return all channels required for this package and its dependencies. + * + * @return array The list of channels. + */ + public function listAllRequiredChannels() + { + $dependencies = array(); + foreach ($this->_getPackageFile()->getDeps() as $dependency) { + if (isset($dependency['channel'])) { + $dependencies[] = $dependency['channel']; + } + } + $dependencies[] = $this->_getPackageFile()->getChannel(); + return array_unique($dependencies); + } + + /** + * Return all channels required for this package and its dependencies. + * + * @return array The list of channels. + */ + public function listAllExternalDependencies() + { + $dependencies = array(); + foreach ($this->_getPackageFile()->getDeps() as $dependency) { + if (isset($dependency['channel']) && $dependency['channel'] != 'pear.horde.org') { + $dependencies[] = $dependency; + } + } + return $dependencies; + } + + /** + * Return all channels required for this package and its dependencies. + * + * @return array The list of channels. + */ + public function listAllHordeDependencies() + { + $dependencies = array(); + foreach ($this->_getPackageFile()->getDeps() as $dependency) { + if (isset($dependency['channel']) && $dependency['channel'] == 'pear.horde.org') { + $dependencies[] = $dependency; + } + } + return $dependencies; + } + } diff --git a/components/lib/Components/Runner/Installer.php b/components/lib/Components/Runner/Installer.php index 04b32625d..48c1c3103 100644 --- a/components/lib/Components/Runner/Installer.php +++ b/components/lib/Components/Runner/Installer.php @@ -101,37 +101,30 @@ class Components_Runner_Installer . $dependency . DIRECTORY_SEPARATOR . 'package.xml'; } - $parser = new PEAR_PackageFile_Parser_v2(); - $parser->setConfig($environment->getPearConfig()); - $pkg = $parser->parse(file_get_contents($package_file), $package_file); - - $dependencies = $pkg->getDeps(); - foreach ($dependencies as $dependency) { - if (isset($dependency['channel']) && $dependency['channel'] != 'pear.horde.org') { - $environment->provideChannel($dependency['channel']); - $key = $dependency['channel'] . '/' . $dependency['name']; - if (in_array($key, $this->_run)) { - continue; - } - $environment->addPackageFromPackage( - $dependency['channel'], $dependency['name'] - ); - $this->_run[] = $key; - } else if (isset($dependency['channel'])) { - $environment->provideChannel($dependency['channel']); - $key = $dependency['channel'] . '/' . $dependency['name']; - if (in_array($key, $this->_run)) { - continue; - } - $this->_run[] = $key; - $this->_installHordeDependency($environment, $root_path, $dependency['name']); + $pkg = $this->_factory->createPackageForEnvironment($package_file, $environment); + $environment->provideChannels($pkg->listAllRequiredChannels()); + foreach ($pkg->listAllExternalDependencies() as $dependency) { + $key = $dependency['channel'] . '/' . $dependency['name']; + if (in_array($key, $this->_run)) { + continue; + } + $environment->addPackageFromPackage( + $dependency['channel'], $dependency['name'] + ); + $this->_run[] = $key; + } + foreach ($pkg->listAllHordeDependencies() as $dependency) { + $key = $dependency['channel'] . '/' . $dependency['name']; + if (in_array($key, $this->_run)) { + continue; } + $this->_run[] = $key; + $this->_installHordeDependency($environment, $root_path, $dependency['name']); } if (in_array($package_file, $this->_run)) { return; } - $environment->provideChannel($pkg->getChannel()); $environment->addPackageFromSource( $package_file );