Extract parts of the installer into the PEAR module.
authorGunnar Wrobel <p@rdus.de>
Wed, 13 Oct 2010 08:47:44 +0000 (10:47 +0200)
committerGunnar Wrobel <p@rdus.de>
Wed, 13 Oct 2010 19:14:44 +0000 (21:14 +0200)
components/lib/Components/Pear/Factory.php
components/lib/Components/Pear/InstallLocation.php
components/lib/Components/Pear/Package.php
components/lib/Components/Runner/Installer.php

index f6a0421..04e0f9e 100644 (file)
@@ -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);
index 81b4233..5298720 100644 (file)
@@ -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(
index 44eaa0f..89126c8 100644 (file)
@@ -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;
+    }    
+
 }
index 04b3262..48c1c31 100644 (file)
@@ -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
         );