Provide a reason when installing a package. Avoid installing optional PECL dependencies.
authorGunnar Wrobel <p@rdus.de>
Fri, 22 Oct 2010 22:50:13 +0000 (00:50 +0200)
committerGunnar Wrobel <p@rdus.de>
Fri, 22 Oct 2010 22:51:20 +0000 (00:51 +0200)
components/lib/Components/Helper/InstallationRun.php
components/lib/Components/Helper/Tree/Element.php
components/lib/Components/Pear/InstallLocation.php

index 5f833be..6449042 100644 (file)
@@ -67,13 +67,16 @@ class Components_Helper_InstallationRun
      * environment. The channels are only going to be installed once during the
      * installation run represented by this instance.
      *
+     * @param array  $channels The channels to install.
+     * @param string $reason   Optional reason for adding the channels.
+     *
      * @return NULL
      */
-    public function installChannelsOnce(array $channels)
+    public function installChannelsOnce(array $channels, $reason = '')
     {
         foreach ($channels as $channel) {
             if (!in_array($channel, $this->_installed_channels)) {
-                $this->_environment->provideChannel($channel);
+                $this->_environment->provideChannel($channel, $reason);
                 $this->_installed_channels[] = $channel;
             }
         }
@@ -86,15 +89,16 @@ class Components_Helper_InstallationRun
      *
      * @param string $package The package that should be installed.
      * @param string $channel The channel of the package.
+     * @param string $reason  Optional reason for adding the package.
      *
      * @return NULL
      */
-    public function installExternalPackageOnce($channel, $package)
+    public function installExternalPackageOnce($channel, $package, $reason = '')
     {
         $key = $channel . '/' . $package;
         if (!in_array($key, $this->_installed_packages)) {
             $this->_environment->addPackageFromPackage(
-                $channel, $package
+                $channel, $package, $reason
             );
             $this->_installed_packages[] = $key;
         }
@@ -107,14 +111,15 @@ class Components_Helper_InstallationRun
      *
      * @param string $package_file The package file indicating which Horde
      *                             source package should be installed.
+     * @param string $reason       Optional reason for adding the package.
      *
      * @return NULL
      */
-    public function installHordePackageOnce($package_file)
+    public function installHordePackageOnce($package_file, $reason = '')
     {
         if (!in_array($package_file, $this->_installed_packages)) {
             $this->_environment->addPackageFromSource(
-                $package_file
+                $package_file, $reason
             );
             $this->_installed_packages[] = $package_file;
         }
index 4013ad9..c515e26 100644 (file)
@@ -91,10 +91,17 @@ class Components_Helper_Tree_Element
             return;
         }
         $visited[] = $this->_package_file;
-        $run->installChannelsOnce($this->_package->listAllRequiredChannels());
+        $reason = sprintf(' [required by %s]', $this->_package->getName());
+        $run->installChannelsOnce($this->_package->listAllRequiredChannels(), $reason);
         foreach ($this->_package->listAllExternalDependencies() as $dependency) {
+            // Refrain from installing optional pecl packages
+            if (isset($dependency['optional'])
+                && $dependency['optional'] != 'no'
+                && $dependency['channel'] == 'pecl.php.net') {
+                continue;
+            }
             $run->installExternalPackageOnce(
-                $dependency['channel'], $dependency['name']
+                $dependency['channel'], $dependency['name'], $reason
             );
         }
         foreach (
@@ -104,7 +111,7 @@ class Components_Helper_Tree_Element
         ) {
             $child->installInTree($run, $visited);
         }
-        $run->installHordePackageOnce($this->_package_file);
+        $run->installHordePackageOnce($this->_package_file, $reason);
     }
 
     /**
index 75f952c..a2e0fe7 100644 (file)
@@ -230,10 +230,11 @@ class Components_Pear_InstallLocation
      * Add a channel within the install location.
      *
      * @param string $channel The channel name.
+     * @param string $reason  Optional reason for adding the channel.
      *
      * @return NULL
      */
-    public function addChannel($channel)
+    public function addChannel($channel, $reason = '')
     {
         $channel_handler = new PEAR_Command_Channels(
             new PEAR_Frontend_CLI(),
@@ -259,8 +260,9 @@ class Components_Pear_InstallLocation
         }
         $this->_output->ok(
             sprintf(
-                'Successfully added channel %s',
-                $channel
+                'Successfully added channel %s%s',
+                $channel,
+                $reason
             )
         );
     }
@@ -269,13 +271,14 @@ class Components_Pear_InstallLocation
      * Ensure the specified channel exists within the install location.
      *
      * @param string $channel The channel name.
+     * @param string $reason  Optional reason for adding the channel.
      *
      * @return NULL
      */
-    public function provideChannel($channel)
+    public function provideChannel($channel, $reason = '')
     {
         if (!$this->channelExists($channel)) {
-            $this->addChannel($channel);
+            $this->addChannel($channel, $reason);
         }
     }
 
@@ -283,13 +286,14 @@ class Components_Pear_InstallLocation
      * Ensure the specified channels exists within the install location.
      *
      * @param array $channels The list of channels.
+     * @param string $reason  Optional reason for adding the channels.
      *
      * @return NULL
      */
-    public function provideChannels(array $channels)
+    public function provideChannels(array $channels, $reason = '')
     {
         foreach ($channels as $channel) {
-            $this->provideChannel($channel);
+            $this->provideChannel($channel, $reason);
         }
     }
 
@@ -307,10 +311,11 @@ class Components_Pear_InstallLocation
      * Add a package based on a source directory.
      *
      * @param string $package The path to the package.xml in the source directory.
+     * @param string $reason  Optional reason for adding the package.
      *
      * @return NULL
      */
-    public function addPackageFromSource($package)
+    public function addPackageFromSource($package, $reason = '')
     {
         $installer = $this->getInstallationHandler();
         ob_start();
@@ -322,8 +327,9 @@ class Components_Pear_InstallLocation
         $this->_output->pear(ob_get_clean());
         $this->_output->ok(
             sprintf(
-                'Successfully added package %s',
-                $package
+                'Successfully added package %s%s',
+                $package,
+                $reason
             )
         );
     }
@@ -333,10 +339,11 @@ class Components_Pear_InstallLocation
      *
      * @param string $channel The channel name for the package.
      * @param string $package The name of the package of the path of the tarball.
+     * @param string $reason  Optional reason for adding the package.
      *
      * @return NULL
      */
-    public function addPackageFromPackage($channel, $package)
+    public function addPackageFromPackage($channel, $package, $reason = '')
     {
         $installer = $this->getInstallationHandler();
         if ($local = $this->_identifyMatchingLocalPackage($package)) {
@@ -368,8 +375,9 @@ class Components_Pear_InstallLocation
         }
         $this->_output->ok(
             sprintf(
-                'Successfully added package %s',
-                $package
+                'Successfully added package %s%s',
+                $package,
+                $reason
             )
         );
     }