Make the package.xml handling functional again. Integrate all patches the action...
authorGunnar Wrobel <p@rdus.de>
Mon, 5 Jul 2010 03:44:04 +0000 (05:44 +0200)
committerGunnar Wrobel <p@rdus.de>
Mon, 23 Aug 2010 07:51:51 +0000 (09:51 +0200)
framework/Qc/lib/Horde/Qc.php
framework/Qc/lib/Horde/Qc/Module.php
framework/Qc/lib/Horde/Qc/Module/PearPackageXml.php
framework/Qc/test/Horde/Qc/StoryTestCase.php

index 50c7994..eedf26f 100644 (file)
@@ -46,14 +46,13 @@ class Horde_Qc
         $modules = self::_prepareModules();
         $config->handleModules($modules);
         try {
-            self::_validateArguments($config->getArguments());
+            self::_validateArguments($config);
         } catch (Horde_Qc_Exception $e) {
             $parser->parserError($e->getMessage());
             return;
         }
-        $options = $config->getOptions();
         foreach ($modules as $module) {
-            $module->handle($options);
+            $module->handle($config);
         }
     }
 
@@ -89,8 +88,9 @@ class Horde_Qc
         return $modules;
     }
 
-    static private function _validateArguments(array $arguments)
+    static private function _validateArguments(Horde_Qc_Config $config)
     {
+        $arguments = $config->getArguments();
         if (empty($arguments[0])) {
             throw new Horde_Qc_Exception('Please specify the path of the PEAR package!');
         }
index 14beed8..ac7886e 100644 (file)
@@ -33,7 +33,7 @@ interface Horde_Qc_Module
 
     public function getOptionGroupOptions();
 
-    public function handle(array $config);
+    public function handle(Horde_Qc_Config $config);
 
-    public function run();
+    public function run(Horde_Qc_Config $config);
 }
\ No newline at end of file
index ea7d5a7..bd8eacb 100644 (file)
@@ -61,82 +61,93 @@ implements Horde_Qc_Module
         );
     }
 
-    public function handle(array $config)
+    public function handle(Horde_Qc_Config $config)
     {
+        $options = $config->getOptions();
+        if (!empty($options['packagexml']) ||
+            !empty($options['updatexml'])) {
+            $this->run($config);
+        }
     }
 
-    public function run()
+    public function run(Horde_Qc_Config $config)
     {
-
-PEAR::setErrorHandling(PEAR_ERROR_DIE);
-
-
-        $package_file = $package_path . '/package.xml';
-
-if (!file_exists($package_file)) {
-    print sprintf("There is no package.xml at %s!\n", $package_path);
-    exit(1);
-}
-
-$package = PEAR_PackageFileManager2::importOptions(
-    $package_file,
-    array(
-        'packagedirectory' => $package_path,
-        'filelistgenerator' => 'file',
-        'clearcontents' => false,
-        'clearchangelog' => false,
-        'simpleoutput' => true,
-        'include' => '*',
-        'dir_roles' =>
-        array(
-            'lib'     => 'php',
-            'doc'     => 'doc',
-            'example' => 'doc',
-            'script'  => 'script',
-            'test'    => 'test',
-        ),
-    )
-);
-
-$package->generateContents();
-
-/**
- * This is required to clear the <phprelease><filelist></filelist></phprelease>
- * section.
- */
-$package->setPackageType('php');
-
-$contents = $package->getContents();
-$files = $contents['dir']['file'];
-
-foreach ($files as $file) {
-    $components = explode('/', $file['attribs']['name'], 2);
-    switch ($components[0]) {
-    case 'doc':
-    case 'example':
-    case 'lib':
-    case 'test':
-        $package->addInstallAs(
-            $file['attribs']['name'], $components[1]
+        $arguments = $config->getArguments();
+        $package_file = $arguments[0] . '/package.xml';
+
+        $pear = new PEAR();
+        $pear->setErrorHandling(PEAR_ERROR_DIE);
+
+        $package = PEAR_PackageFileManager2::importOptions(
+            $package_file,
+            array(
+                'packagedirectory' => $arguments[0],
+                'filelistgenerator' => 'file',
+                'clearcontents' => false,
+                'clearchangelog' => false,
+                'simpleoutput' => true,
+                'ignore' => array('*~', 'conf.php', 'CVS/*'),
+                'include' => '*',
+                'dir_roles' =>
+                array(
+                    'lib'       => 'php',
+                    'doc'       => 'doc',
+                    'example'   => 'doc',
+                    'script'    => 'script',
+                    'test'      => 'test',
+                    'migration' => 'data',
+                ),
+            )
         );
-        break;
-    case 'script':
-        $filename = basename($file['attribs']['name']);
-        if (substr($filename, strlen($filename) - 4)) {
-            $filename = substr($filename, 0, strlen($filename) - 4);
+
+        $package->generateContents();
+
+        /**
+         * This is required to clear the <phprelease><filelist></filelist></phprelease>
+         * section.
+         */
+        $package->setPackageType('php');
+
+        $contents = $package->getContents();
+        $files = $contents['dir']['file'];
+
+        foreach ($files as $file) {
+            $components = explode('/', $file['attribs']['name'], 2);
+            switch ($components[0]) {
+            case 'doc':
+            case 'example':
+            case 'lib':
+            case 'test':
+                $package->addInstallAs(
+                    $file['attribs']['name'], $components[1]
+                );
+            break;
+            case 'script':
+                $filename = basename($file['attribs']['name']);
+                if (substr($filename, strlen($filename) - 4)) {
+                    $filename = substr($filename, 0, strlen($filename) - 4);
+                }
+                $package->addInstallAs(
+                    $file['attribs']['name'], $filename
+                );
+                break;
+            case 'migration':
+                $components = explode('/', $components[1]);
+                array_splice($components, count($components) - 1, 0, 'migration');
+                $package->addInstallAs(
+                    $file['attribs']['name'], implode('/', $components)
+                );
+                break;
+            }
         }
-        $package->addInstallAs(
-            $file['attribs']['name'], $filename
-        );
-        break;
-    }
-}
 
-if (!empty($opts['update_packagexml'])) {
-    $package->writePackageFile();
-} else {
-    $package->debugPackageFile();
-}
+        $options = $config->getOptions();
+        if (!empty($options['packagexml'])) {
+            $package->debugPackageFile();
+        }
+        if (!empty($options['updatexml'])) {
+            $package->writePackageFile();
+        }
 
     }
 }
index 63c4329..428bd98 100644 (file)
@@ -65,7 +65,6 @@ extends PHPUnit_Extensions_Story_TestCase
             $_SERVER['argv'] = array(
                 'hqc',
                 '--help',
-                '--packagexml',
                 dirname(__FILE__) . '/fixture'
             );
             ob_start();