Add a Horde specific repo layout handler that allows components to deal with all...
authorGunnar Wrobel <p@rdus.de>
Thu, 28 Oct 2010 19:04:38 +0000 (21:04 +0200)
committerGunnar Wrobel <p@rdus.de>
Thu, 28 Oct 2010 19:33:58 +0000 (21:33 +0200)
12 files changed:
components/TODO
components/lib/Components/Helper/Root.php [new file with mode: 0644]
components/lib/Components/Helper/Tree.php
components/lib/Components/Pear/Factory.php
components/lib/Components/Runner/Dependencies.php
components/lib/Components/Runner/Installer.php
components/test/Components/Integration/Components/Module/InstallerTest.php
components/test/Components/StoryTestCase.php
components/test/Components/fixture/framework/Dependency/package.xml
components/test/Components/fixture/framework/Old/lib/Old.php [new file with mode: 0644]
components/test/Components/fixture/framework/Old/package.xml [new file with mode: 0644]
components/test/Components/fixture/horde/.keep [new file with mode: 0644]

index 294802f..52a72db 100644 (file)
@@ -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 (file)
index 0000000..2f350b5
--- /dev/null
@@ -0,0 +1,93 @@
+<?php
+/**
+ * Components_Helper_Root:: handles the root position for a tree of dependencies
+ * and takes the Horde component layout into account.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package  Components
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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
index 65b3e24..a3985f1 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 /**
- * Components_Helper_Tree:: handles a tree of dependencies and takes the Horde
- * component layout into account.
+ * Components_Helper_Tree:: handles a tree of dependencies.
  *
  * PHP version 5
  *
@@ -13,8 +12,7 @@
  */
 
 /**
- * Components_Helper_Tree:: handles a tree of dependencies and takes the Horde
- * component layout into account.
+ * Components_Helper_Tree:: handles a tree of dependencies.
  *
  * Copyright 2010 The Horde Project (http://www.horde.org/)
  *
@@ -44,11 +42,11 @@ class Components_Helper_Tree
     private $_environment;
 
     /**
-     * The root path for the Horde package hierarchy.
+     * The root handler for the Horde package hierarchy.
      *
-     * @var string
+     * @var Components_Helper_Root
      */
-    private $_root_path;
+    private $_root;
 
     /**
      * Constructor.
@@ -56,18 +54,18 @@ class Components_Helper_Tree
      * @param Components_Pear_Factory         $factory     The factory for PEAR
      *                                                     dependencies.
      * @param Components_Pear_InstallLocation $environment The PEAR environment.
-     * @param string                          $root_path   The basic root path for
+     * @param Components_Helper_Root          $root        The root handler for
      *                                                     Horde packages.
      *
      */
     public function __construct(
         Components_Pear_Factory $factory,
         Components_Pear_InstallLocation $environment,
-        $root_path
+        Components_Helper_Root $root
     ) {
         $this->_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;
index 70d525e..6917925 100644 (file)
@@ -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)
         );
     }
 
index f5375eb..131b0dc 100644 (file)
@@ -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
index 16a79c7..6296aaa 100644 (file)
@@ -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(
index ced13e4..8d97fbc 100644 (file)
@@ -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');
     }
 
index 2bafe62..6e0e369 100644 (file)
@@ -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(
index 720ec57..4db725f 100644 (file)
     <channel>pear.horde.org</channel>
    </package>
    <package>
+    <name>Horde_Old</name>
+    <channel>pear.horde.org</channel>
+   </package>
+   <package>
     <name>Console_Getopt</name>
     <channel>pear.php.net</channel>
    </package>
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 (file)
index 0000000..a814366
--- /dev/null
@@ -0,0 +1 @@
+<?php
\ No newline at end of file
diff --git a/components/test/Components/fixture/framework/Old/package.xml b/components/test/Components/fixture/framework/Old/package.xml
new file mode 100644 (file)
index 0000000..388e5e7
--- /dev/null
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<package packagerversion="1.9.0" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
+ <name>Horde_Old</name>
+ <channel>pear.horde.org</channel>
+ <summary>Test fixture.</summary>
+ <description>A dummy package.xml used for testing the Components package.</description>
+ <lead>
+  <name>Gunnar Wrobel</name>
+  <user>wrobel</user>
+  <email>p@rdus.de</email>
+  <active>yes</active>
+ </lead>
+ <date>2010-08-22</date>
+ <time>21:12:03</time>
+ <version>
+  <release>0.0.1</release>
+  <api>0.0.1</api>
+ </version>
+ <stability>
+  <release>alpha</release>
+  <api>alpha</api>
+ </stability>
+ <license uri="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html">LGPL</license>
+ <notes>
+* Initial release
+ </notes>
+ <contents>
+  <dir baseinstalldir="/" name="/">
+   <dir name="lib">
+    <file name="Old.php" role="php" />
+   </dir> <!-- /lib -->
+  </dir> <!-- / -->
+ </contents>
+ <dependencies>
+  <required>
+   <php>
+    <min>5.0.0</min>
+   </php>
+   <pearinstaller>
+    <min>1.7.0</min>
+   </pearinstaller>
+   <package>
+    <name>Console_Getopt</name>
+    <channel>pear.php.net</channel>
+   </package>
+  </required>
+  <optional>
+   <package>
+    <name>PECL</name>
+    <channel>pecl.php.net</channel>
+   </package>
+  </optional>
+ </dependencies>
+ <phprelease>
+  <filelist>
+   <install as="Old.php" name="lib/Old.php" />
+  </filelist>
+ </phprelease>
+ <changelog>
+  <release>
+   <version>
+    <release>0.0.1</release>
+    <api>0.0.1</api>
+   </version>
+   <stability>
+    <release>alpha</release>
+    <api>alpha</api>
+   </stability>
+   <date>2010-08-22</date>
+   <license uri="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html">LGPL</license>
+   <notes>
+* Initial release
+   </notes>
+  </release>
+ </changelog>
+</package>
diff --git a/components/test/Components/fixture/horde/.keep b/components/test/Components/fixture/horde/.keep
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+