Intermediate step in refactoring the Quality package.
authorGunnar Wrobel <wrobel@temple.(none)>
Tue, 2 Mar 2010 12:49:51 +0000 (13:49 +0100)
committerGunnar Wrobel <p@rdus.de>
Mon, 23 Aug 2010 07:51:49 +0000 (09:51 +0200)
framework/Qc/lib/Horde/Qc/Config.php
framework/Qc/lib/Horde/Qc/Config/Cli.php
framework/Qc/lib/Horde/Qc/Module.php
framework/Qc/lib/Horde/Qc/Module/PearPackageXml.php
framework/Qc/package.xml
framework/Qc/script/horde-quality-control.php

index 267d247..e4b6d76 100644 (file)
  * @link     http://pear.horde.org/index.php?package=Qc
 erver
  */
-abstract class Horde_Qc_Config
+class Horde_Qc_Config
 {
+
+    private $configs;
+
+    public function __construct(Horde_Qc_Modules $modules)
+    {
+        $this->configs[] = new Horde_Qc_Config_Cli($modules);
+    }
 }
\ No newline at end of file
index c14ec1b..66f0ad9 100644 (file)
@@ -43,7 +43,7 @@ implements Horde_Qc_Config_Interface
      *
      * @param Horde_Qc_Modules $modules A list of modules.
      */
-    public function __construct(Horde_Modules $modules)
+    public function __construct(Horde_Qc_Modules $modules)
     {
         $options = array();
 
@@ -58,25 +58,5 @@ implements Horde_Qc_Config_Interface
             )
         );
         list($this->_opts, $this->_args) = $parser->parseArgs();
-        $this->_validate();
-
-        foreach ($modules as $module) {
-            $module->validateOptions($this->_opts, $this->_args);
-        }
-    }
-
-    private function _validate()
-    {
-        if (empty($this->_args[0])) {
-            print "Please specify the path to the package you want to release!\n\n";
-            $this->_parser->printUsage(STDERR);
-            exit(1);
-        }
-
-        if (!is_dir($this->_args[0])) {
-            print sprintf("%s specifies no directory!\n", $this->_args[0]);
-            exit(1);
-        }
     }
-
 }
index b2868f0..feb6cf2 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Horde_Qc_Module:: interface represents a single quality control module.
+ * Horde_Qc_Module:: represents a single quality control module.
  *
  * PHP version 5
  *
@@ -12,7 +12,7 @@
  */
 
 /**
- * Horde_Qc_Module:: interface represents a single quality control module.
+ * Horde_Qc_Module:: represents a single quality control module.
  *
  * Copyright 2010 The Horde Project (http://www.horde.org/)
  *
  * @link     http://pear.horde.org/index.php?package=Qc
 erver
  */
-interface Horde_Qc_Module
+abstract class Horde_Qc_Module
 {
-    public function getOptions();
+    /**
+     * The parent module.
+     *
+     * @var Horde_Qc_Module
+     */
+    private $_parent;
 
-    public function validateOptions(array $options, array $arguments);
+    public function __construct(Horde_Qc_Module $parent = null)
+    {
+        $this->_parent = $parent;
+    }
+
+    abstract public function getOptions();
+
+    abstract public function validateOptions();
+
+    abstract public function setup();
+
+    abstract public function run();
 }
\ No newline at end of file
index dcbcde1..225102b 100644 (file)
@@ -25,7 +25,8 @@
  * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
  * @link     http://pear.horde.org/index.php?package=Qc
  */
-interface Horde_Qc_Module
+class Horde_Qc_Module_PearPackageXml
+extends Horde_Qc_Module
 {
     public function getOptions()
     {
@@ -38,7 +39,78 @@ interface Horde_Qc_Module
         );
     }
 
-    public function validateOptions(array $options, array $arguments)
+    public function run()
     {
+
+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]
+        );
+        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;
+    }
+}
+
+if (!empty($opts['update_packagexml'])) {
+    $package->writePackageFile();
+} else {
+    $package->debugPackageFile();
+}
+
     }
 }
index e4452dd..3f99a8d 100644 (file)
@@ -51,7 +51,7 @@
     </dir> <!-- /lib/Horde -->
    </dir> <!-- /lib -->
    <dir name="script">
-    <file name="horde-pear-release.php" role="script" />
+    <file name="horde-quality-control.php" role="script" />
    </dir> <!-- /script -->
    <file name="COPYING" role="doc" />
   </dir> <!-- / -->
     <channel>pear.horde.org</channel>
    </package>
   </required>
+  <optional>
+   <package>
+    <name>Test</name>
+    <channel>pear.horde.org</channel>
+   </package>
+  </optional>
  </dependencies>
  <phprelease>
   <filelist>
index dc2cb6b..afa8f19 100755 (executable)
@@ -1,107 +1,4 @@
 #!/usr/bin/env php
 <?php
-
-require_once 'Horde/Core/Autoloader.php';
-
-PEAR::setErrorHandling(PEAR_ERROR_DIE);
-
-$options = array(
-    new Horde_Argv_Option(
-        '-u', '--update-packagexml', array('action' => 'store_true')
-    ),
-);
-$parser = new Horde_Argv_Parser(
-    array(
-        'optionList' => $options,
-        'usage' => '%prog ' . _("[options] PACKAGE_PATH")
-    )
-);
-list($opts, $args) = $parser->parseArgs();
-
-if (empty($args[0])) {
-    echo "Please specify the path to the package you want to release!\n\n";
-    $parser->printUsage(STDERR);
-    exit(1);
-}
-
-$package_path = $args[0];
-if (!is_dir($package_path)) {
-    printf("%s specifies no directory!\n", $package_path);
-    exit(1);
-}
-
-$package_file = $package_path . '/package.xml';
-
-if (!file_exists($package_file)) {
-    printf("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,
-        'ignore' => array('*~', 'conf.php', 'CVS/*'),
-        'include' => '*',
-        'dir_roles' =>
-        array(
-            'lib'       => 'php',
-            'doc'       => 'doc',
-            'example'   => 'doc',
-            'script'    => 'script',
-            'test'      => 'test',
-            'migration' => 'data',
-        ),
-    )
-);
-
-$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 'migration':
-        $components = explode('/', $components[1]);
-        array_splice($components, count($components) - 1, 0, 'migration');
-        $package->addInstallAs(
-            $file['attribs']['name'], implode('/', $components)
-        );
-        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;
-    }
-}
-
-if (!empty($opts['update_packagexml'])) {
-    $package->writePackageFile();
-} else {
-    $package->debugPackageFile();
-}
+require_once('Horde/Autoloader.php');
+Horde_Qc::main();